1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/mach-pxa/z2.c
5 * Support for the Zipit Z2 Handheld device.
7 * Copyright (C) 2009-2010 Marek Vasut <marek.vasut@gmail.com>
9 * Based on research and code by: Ken McGuire
10 * Based on mainstone.c as modified for the Zipit Z2.
13 #include <linux/platform_device.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/partitions.h>
16 #include <linux/pwm.h>
17 #include <linux/pwm_backlight.h>
18 #include <linux/z2_battery.h>
19 #include <linux/dma-mapping.h>
20 #include <linux/spi/spi.h>
21 #include <linux/spi/pxa2xx_spi.h>
22 #include <linux/spi/libertas_spi.h>
23 #include <linux/power_supply.h>
24 #include <linux/mtd/physmap.h>
25 #include <linux/gpio.h>
26 #include <linux/gpio/machine.h>
27 #include <linux/gpio_keys.h>
28 #include <linux/delay.h>
29 #include <linux/regulator/machine.h>
30 #include <linux/platform_data/i2c-pxa.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
36 #include "mfp-pxa27x.h"
38 #include <linux/platform_data/video-pxafb.h>
39 #include <linux/platform_data/mmc-pxamci.h>
40 #include <linux/platform_data/keypad-pxa27x.h>
46 /******************************************************************************
48 ******************************************************************************/
49 static unsigned long z2_pin_config[] = {
51 /* LCD - 16bpp Active TFT */
72 GPIO19_GPIO, /* LCD reset */
73 GPIO88_GPIO, /* LCD chipselect */
76 GPIO115_PWM1_OUT, /* Keypad Backlight */
77 GPIO11_PWM2_OUT, /* LCD Backlight */
86 GPIO96_GPIO, /* SD detect */
114 GPIO23_SSP1_SCLK, /* SSP1_SCK */
115 GPIO25_SSP1_TXD, /* SSP1_TXD */
116 GPIO26_SSP1_RXD, /* SSP1_RXD */
119 GPIO22_SSP2_SCLK, /* SSP2_SCK */
120 GPIO13_SSP2_TXD, /* SSP2_TXD */
121 GPIO40_SSP2_RXD, /* SSP2_RXD */
124 GPIO10_GPIO, /* WiFi LED */
125 GPIO83_GPIO, /* Charging LED */
126 GPIO85_GPIO, /* Charged LED */
129 GPIO28_I2S_BITCLK_OUT,
131 GPIO30_I2S_SDATA_OUT,
136 GPIO0_GPIO, /* AC power detect */
137 GPIO1_GPIO, /* Power button */
138 GPIO37_GPIO, /* Headphone detect */
139 GPIO98_GPIO, /* Lid switch */
140 GPIO14_GPIO, /* WiFi Power */
141 GPIO24_GPIO, /* WiFi CS */
142 GPIO36_GPIO, /* WiFi IRQ */
143 GPIO88_GPIO, /* LCD CS */
146 /******************************************************************************
148 ******************************************************************************/
149 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
150 static struct resource z2_flash_resource = {
151 .start = PXA_CS0_PHYS,
152 .end = PXA_CS0_PHYS + SZ_8M - 1,
153 .flags = IORESOURCE_MEM,
156 static struct mtd_partition z2_flash_parts[] = {
158 .name = "U-Boot Bootloader",
162 .name = "U-Boot Environment",
168 .size = MTDPART_SIZ_FULL,
172 static struct physmap_flash_data z2_flash_data = {
174 .parts = z2_flash_parts,
175 .nr_parts = ARRAY_SIZE(z2_flash_parts),
178 static struct platform_device z2_flash = {
179 .name = "physmap-flash",
181 .resource = &z2_flash_resource,
184 .platform_data = &z2_flash_data,
188 static void __init z2_nor_init(void)
190 platform_device_register(&z2_flash);
193 static inline void z2_nor_init(void) {}
196 /******************************************************************************
198 ******************************************************************************/
199 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
200 static struct pwm_lookup z2_pwm_lookup[] = {
201 PWM_LOOKUP("pxa27x-pwm.1", 0, "pwm-backlight.0", NULL, 1260320,
202 PWM_POLARITY_NORMAL),
203 PWM_LOOKUP("pxa27x-pwm.0", 1, "pwm-backlight.1", NULL, 1260320,
204 PWM_POLARITY_NORMAL),
207 static struct platform_pwm_backlight_data z2_backlight_data[] = {
209 /* Keypad Backlight */
210 .max_brightness = 1023,
215 .max_brightness = 1023,
216 .dft_brightness = 512,
220 static struct platform_device z2_backlight_devices[2] = {
222 .name = "pwm-backlight",
225 .platform_data = &z2_backlight_data[1],
229 .name = "pwm-backlight",
232 .platform_data = &z2_backlight_data[0],
236 static void __init z2_pwm_init(void)
238 pwm_add_table(z2_pwm_lookup, ARRAY_SIZE(z2_pwm_lookup));
239 platform_device_register(&z2_backlight_devices[0]);
240 platform_device_register(&z2_backlight_devices[1]);
243 static inline void z2_pwm_init(void) {}
246 /******************************************************************************
248 ******************************************************************************/
249 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
250 static struct pxafb_mode_info z2_lcd_modes[] = {
267 static struct pxafb_mach_info z2_lcd_screen = {
268 .modes = z2_lcd_modes,
269 .num_modes = ARRAY_SIZE(z2_lcd_modes),
270 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_BIAS_ACTIVE_LOW |
271 LCD_ALTERNATE_MAPPING,
274 static void __init z2_lcd_init(void)
276 pxa_set_fb_info(NULL, &z2_lcd_screen);
279 static inline void z2_lcd_init(void) {}
282 /******************************************************************************
283 * SD/MMC card controller
284 ******************************************************************************/
285 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
286 static struct pxamci_platform_data z2_mci_platform_data = {
287 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
288 .detect_delay_ms = 200,
291 static struct gpiod_lookup_table z2_mci_gpio_table = {
292 .dev_id = "pxa2xx-mci.0",
294 GPIO_LOOKUP("gpio-pxa", GPIO96_ZIPITZ2_SD_DETECT,
295 "cd", GPIO_ACTIVE_LOW),
300 static void __init z2_mmc_init(void)
302 gpiod_add_lookup_table(&z2_mci_gpio_table);
303 pxa_set_mci_info(&z2_mci_platform_data);
306 static inline void z2_mmc_init(void) {}
309 /******************************************************************************
311 ******************************************************************************/
312 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
313 struct gpio_led z2_gpio_leds[] = {
315 .name = "z2:green:wifi",
316 .default_trigger = "none",
317 .gpio = GPIO10_ZIPITZ2_LED_WIFI,
320 .name = "z2:green:charged",
321 .default_trigger = "mmc0",
322 .gpio = GPIO85_ZIPITZ2_LED_CHARGED,
325 .name = "z2:amber:charging",
326 .default_trigger = "Z2-charging-or-full",
327 .gpio = GPIO83_ZIPITZ2_LED_CHARGING,
332 static struct gpio_led_platform_data z2_gpio_led_info = {
333 .leds = z2_gpio_leds,
334 .num_leds = ARRAY_SIZE(z2_gpio_leds),
337 static struct platform_device z2_leds = {
341 .platform_data = &z2_gpio_led_info,
345 static void __init z2_leds_init(void)
347 platform_device_register(&z2_leds);
350 static inline void z2_leds_init(void) {}
353 /******************************************************************************
355 ******************************************************************************/
356 #if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
357 static const unsigned int z2_matrix_keys[] = {
358 KEY(0, 0, KEY_OPTION),
362 KEY(4, 0, KEY_RIGHT),
364 KEY(6, 0, KEY_KPPLUS),
371 KEY(5, 1, KEY_ENTER),
372 KEY(6, 1, KEY_KPMINUS),
374 KEY(0, 2, KEY_PAGEUP),
379 KEY(5, 2, KEY_LEFTALT),
381 KEY(0, 3, KEY_PAGEDOWN),
386 KEY(5, 3, KEY_LEFTSHIFT),
393 KEY(5, 4, KEY_LEFTCTRL),
400 KEY(5, 5, KEY_SPACE),
402 KEY(0, 6, KEY_STOPCD),
405 KEY(3, 6, KEY_BACKSPACE),
407 KEY(5, 6, KEY_COMMA),
409 KEY(0, 7, KEY_PLAYCD),
413 KEY(4, 7, KEY_SEMICOLON),
417 static struct matrix_keymap_data z2_matrix_keymap_data = {
418 .keymap = z2_matrix_keys,
419 .keymap_size = ARRAY_SIZE(z2_matrix_keys),
422 static struct pxa27x_keypad_platform_data z2_keypad_platform_data = {
423 .matrix_key_rows = 7,
424 .matrix_key_cols = 8,
425 .matrix_keymap_data = &z2_matrix_keymap_data,
427 .debounce_interval = 30,
430 static void __init z2_mkp_init(void)
432 pxa_set_keypad_info(&z2_keypad_platform_data);
435 static inline void z2_mkp_init(void) {}
438 /******************************************************************************
440 ******************************************************************************/
441 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
442 static struct gpio_keys_button z2_pxa_buttons[] = {
445 .gpio = GPIO1_ZIPITZ2_POWER_BUTTON,
447 .desc = "Power Button",
453 .gpio = GPIO98_ZIPITZ2_LID_BUTTON,
455 .desc = "Lid Switch",
461 static struct gpio_keys_platform_data z2_pxa_keys_data = {
462 .buttons = z2_pxa_buttons,
463 .nbuttons = ARRAY_SIZE(z2_pxa_buttons),
466 static struct platform_device z2_pxa_keys = {
470 .platform_data = &z2_pxa_keys_data,
474 static void __init z2_keys_init(void)
476 platform_device_register(&z2_pxa_keys);
479 static inline void z2_keys_init(void) {}
482 /******************************************************************************
484 ******************************************************************************/
485 #if defined(CONFIG_I2C_PXA) || defined(CONFIG_I2C_PXA_MODULE)
486 static struct z2_battery_info batt_chip_info = {
488 .batt_I2C_addr = 0x55,
490 .min_voltage = 3475000,
491 .max_voltage = 4190000,
493 .batt_mult = 1000000,
494 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LION,
498 static struct gpiod_lookup_table z2_battery_gpio_table = {
501 GPIO_LOOKUP("gpio-pxa", GPIO0_ZIPITZ2_AC_DETECT,
502 NULL, GPIO_ACTIVE_HIGH),
507 static struct i2c_board_info __initdata z2_i2c_board_info[] = {
509 I2C_BOARD_INFO("aer915", 0x55),
510 .dev_name = "aer915",
511 .platform_data = &batt_chip_info,
513 I2C_BOARD_INFO("wm8750", 0x1b),
518 static void __init z2_i2c_init(void)
520 pxa_set_i2c_info(NULL);
521 gpiod_add_lookup_table(&z2_battery_gpio_table);
522 i2c_register_board_info(0, ARRAY_AND_SIZE(z2_i2c_board_info));
525 static inline void z2_i2c_init(void) {}
528 /******************************************************************************
529 * SSP Devices - WiFi and LCD control
530 ******************************************************************************/
531 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
533 static int z2_lbs_spi_setup(struct spi_device *spi)
537 ret = gpio_request(GPIO14_ZIPITZ2_WIFI_POWER, "WiFi Power");
541 ret = gpio_direction_output(GPIO14_ZIPITZ2_WIFI_POWER, 1);
545 /* Wait until card is powered on */
548 spi->bits_per_word = 16;
549 spi->mode = SPI_MODE_2,
556 gpio_free(GPIO14_ZIPITZ2_WIFI_POWER);
561 static int z2_lbs_spi_teardown(struct spi_device *spi)
563 gpio_set_value(GPIO14_ZIPITZ2_WIFI_POWER, 0);
564 gpio_free(GPIO14_ZIPITZ2_WIFI_POWER);
569 static struct pxa2xx_spi_chip z2_lbs_chip_info = {
575 static struct libertas_spi_platform_data z2_lbs_pdata = {
576 .use_dummy_writes = 1,
577 .setup = z2_lbs_spi_setup,
578 .teardown = z2_lbs_spi_teardown,
582 static struct pxa2xx_spi_chip lms283_chip_info = {
588 static struct gpiod_lookup_table lms283_gpio_table = {
589 .dev_id = "spi2.0", /* SPI bus 2 chip select 0 */
591 GPIO_LOOKUP("gpio-pxa", GPIO19_ZIPITZ2_LCD_RESET,
592 "reset", GPIO_ACTIVE_LOW),
597 static struct spi_board_info spi_board_info[] __initdata = {
599 .modalias = "libertas_spi",
600 .platform_data = &z2_lbs_pdata,
601 .controller_data = &z2_lbs_chip_info,
602 .irq = PXA_GPIO_TO_IRQ(GPIO36_ZIPITZ2_WIFI_IRQ),
603 .max_speed_hz = 13000000,
608 .modalias = "lms283gf05",
609 .controller_data = &lms283_chip_info,
610 .max_speed_hz = 400000,
616 static struct pxa2xx_spi_controller pxa_ssp1_master_info = {
621 static struct pxa2xx_spi_controller pxa_ssp2_master_info = {
625 static struct gpiod_lookup_table pxa_ssp1_gpio_table = {
628 GPIO_LOOKUP_IDX("gpio-pxa", GPIO24_ZIPITZ2_WIFI_CS, "cs", 0, GPIO_ACTIVE_LOW),
633 static struct gpiod_lookup_table pxa_ssp2_gpio_table = {
636 GPIO_LOOKUP_IDX("gpio-pxa", GPIO88_ZIPITZ2_LCD_CS, "cs", 0, GPIO_ACTIVE_LOW),
641 static void __init z2_spi_init(void)
643 gpiod_add_lookup_table(&pxa_ssp1_gpio_table);
644 gpiod_add_lookup_table(&pxa_ssp2_gpio_table);
645 pxa2xx_set_spi_info(1, &pxa_ssp1_master_info);
646 pxa2xx_set_spi_info(2, &pxa_ssp2_master_info);
647 gpiod_add_lookup_table(&lms283_gpio_table);
648 spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
651 static inline void z2_spi_init(void) {}
654 static struct gpiod_lookup_table z2_audio_gpio_table = {
655 .dev_id = "soc-audio",
657 GPIO_LOOKUP("gpio-pxa", GPIO37_ZIPITZ2_HEADSET_DETECT,
658 "hsdet-gpio", GPIO_ACTIVE_HIGH),
663 /******************************************************************************
664 * Core power regulator
665 ******************************************************************************/
666 #if defined(CONFIG_REGULATOR_TPS65023) || \
667 defined(CONFIG_REGULATOR_TPS65023_MODULE)
668 static struct regulator_consumer_supply z2_tps65021_consumers[] = {
669 REGULATOR_SUPPLY("vcc_core", NULL),
672 static struct regulator_init_data z2_tps65021_info[] = {
675 .name = "vcc_core range",
679 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
681 .consumer_supplies = z2_tps65021_consumers,
682 .num_consumer_supplies = ARRAY_SIZE(z2_tps65021_consumers),
714 static struct i2c_board_info __initdata z2_pi2c_board_info[] = {
716 I2C_BOARD_INFO("tps65021", 0x48),
717 .platform_data = &z2_tps65021_info,
721 static void __init z2_pmic_init(void)
723 pxa27x_set_i2c_power_info(NULL);
724 i2c_register_board_info(1, ARRAY_AND_SIZE(z2_pi2c_board_info));
727 static inline void z2_pmic_init(void) {}
731 static void z2_power_off(void)
733 /* We're using deep sleep as poweroff, so clear PSPR to ensure that
734 * bootloader will jump to its entry point in resume handler
738 pxa27x_set_pwrmode(PWRMODE_DEEPSLEEP);
739 pxa27x_cpu_pm_enter(PM_SUSPEND_MEM);
742 #define z2_power_off NULL
745 /******************************************************************************
747 ******************************************************************************/
748 static void __init z2_init(void)
750 pxa2xx_mfp_config(ARRAY_AND_SIZE(z2_pin_config));
752 pxa_set_ffuart_info(NULL);
753 pxa_set_btuart_info(NULL);
754 pxa_set_stuart_info(NULL);
767 gpiod_add_lookup_table(&z2_audio_gpio_table);
769 pm_power_off = z2_power_off;
772 MACHINE_START(ZIPIT2, "Zipit Z2")
773 .atag_offset = 0x100,
774 .map_io = pxa27x_map_io,
775 .nr_irqs = PXA_NR_IRQS,
776 .init_irq = pxa27x_init_irq,
777 .handle_irq = pxa27x_handle_irq,
778 .init_time = pxa_timer_init,
779 .init_machine = z2_init,
780 .restart = pxa_restart,