Merge tag 'kvm-s390-next-5.6-1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / arch / arm / mach-pxa / palmz72.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Hardware definitions for Palm Zire72
4  *
5  * Authors:
6  *      Vladimir "Farcaller" Pouzanov <farcaller@gmail.com>
7  *      Sergey Lapin <slapin@ossfans.org>
8  *      Alex Osborne <bobofdoom@gmail.com>
9  *      Jan Herman <2hp@seznam.cz>
10  *
11  * Rewrite for mainline:
12  *      Marek Vasut <marek.vasut@gmail.com>
13  *
14  * (find more info at www.hackndev.com)
15  */
16
17 #include <linux/platform_device.h>
18 #include <linux/syscore_ops.h>
19 #include <linux/delay.h>
20 #include <linux/irq.h>
21 #include <linux/gpio_keys.h>
22 #include <linux/input.h>
23 #include <linux/pda_power.h>
24 #include <linux/pwm_backlight.h>
25 #include <linux/gpio.h>
26 #include <linux/wm97xx.h>
27 #include <linux/power_supply.h>
28 #include <linux/platform_data/i2c-gpio.h>
29 #include <linux/gpio/machine.h>
30
31 #include <asm/mach-types.h>
32 #include <asm/suspend.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35
36 #include "pxa27x.h"
37 #include <mach/audio.h>
38 #include "palmz72.h"
39 #include <linux/platform_data/mmc-pxamci.h>
40 #include <linux/platform_data/video-pxafb.h>
41 #include <linux/platform_data/irda-pxaficp.h>
42 #include <linux/platform_data/keypad-pxa27x.h>
43 #include "udc.h"
44 #include <linux/platform_data/asoc-palm27x.h>
45 #include "palm27x.h"
46
47 #include "pm.h"
48 #include <linux/platform_data/media/camera-pxa.h>
49
50 #include <media/soc_camera.h>
51
52 #include "generic.h"
53 #include "devices.h"
54
55 /******************************************************************************
56  * Pin configuration
57  ******************************************************************************/
58 static unsigned long palmz72_pin_config[] __initdata = {
59         /* MMC */
60         GPIO32_MMC_CLK,
61         GPIO92_MMC_DAT_0,
62         GPIO109_MMC_DAT_1,
63         GPIO110_MMC_DAT_2,
64         GPIO111_MMC_DAT_3,
65         GPIO112_MMC_CMD,
66         GPIO14_GPIO,    /* SD detect */
67         GPIO115_GPIO,   /* SD RO */
68         GPIO98_GPIO,    /* SD power */
69
70         /* AC97 */
71         GPIO28_AC97_BITCLK,
72         GPIO29_AC97_SDATA_IN_0,
73         GPIO30_AC97_SDATA_OUT,
74         GPIO31_AC97_SYNC,
75         GPIO89_AC97_SYSCLK,
76         GPIO113_AC97_nRESET,
77
78         /* IrDA */
79         GPIO49_GPIO,    /* ir disable */
80         GPIO46_FICP_RXD,
81         GPIO47_FICP_TXD,
82
83         /* PWM */
84         GPIO16_PWM0_OUT,
85
86         /* USB */
87         GPIO15_GPIO,    /* usb detect */
88         GPIO95_GPIO,    /* usb pullup */
89
90         /* Matrix keypad */
91         GPIO100_KP_MKIN_0       | WAKEUP_ON_LEVEL_HIGH,
92         GPIO101_KP_MKIN_1       | WAKEUP_ON_LEVEL_HIGH,
93         GPIO102_KP_MKIN_2       | WAKEUP_ON_LEVEL_HIGH,
94         GPIO97_KP_MKIN_3        | WAKEUP_ON_LEVEL_HIGH,
95         GPIO103_KP_MKOUT_0,
96         GPIO104_KP_MKOUT_1,
97         GPIO105_KP_MKOUT_2,
98
99         /* LCD */
100         GPIOxx_LCD_TFT_16BPP,
101
102         GPIO20_GPIO,    /* bl power */
103         GPIO21_GPIO,    /* LCD border switch */
104         GPIO22_GPIO,    /* LCD border color */
105         GPIO96_GPIO,    /* lcd power */
106
107         /* PXA Camera */
108         GPIO81_CIF_DD_0,
109         GPIO48_CIF_DD_5,
110         GPIO50_CIF_DD_3,
111         GPIO51_CIF_DD_2,
112         GPIO52_CIF_DD_4,
113         GPIO53_CIF_MCLK,
114         GPIO54_CIF_PCLK,
115         GPIO55_CIF_DD_1,
116         GPIO84_CIF_FV,
117         GPIO85_CIF_LV,
118         GPIO93_CIF_DD_6,
119         GPIO108_CIF_DD_7,
120
121         GPIO56_GPIO,    /* OV9640 Powerdown */
122         GPIO57_GPIO,    /* OV9640 Reset */
123         GPIO91_GPIO,    /* OV9640 Power */
124
125         /* I2C */
126         GPIO117_GPIO,   /* I2C_SCL */
127         GPIO118_GPIO,   /* I2C_SDA */
128
129         /* Misc. */
130         GPIO0_GPIO      | WAKEUP_ON_LEVEL_HIGH, /* power detect */
131         GPIO88_GPIO,                            /* green led */
132         GPIO27_GPIO,                            /* WM9712 IRQ */
133 };
134
135 /******************************************************************************
136  * GPIO keyboard
137  ******************************************************************************/
138 #if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
139 static const unsigned int palmz72_matrix_keys[] = {
140         KEY(0, 0, KEY_POWER),
141         KEY(0, 1, KEY_F1),
142         KEY(0, 2, KEY_ENTER),
143
144         KEY(1, 0, KEY_F2),
145         KEY(1, 1, KEY_F3),
146         KEY(1, 2, KEY_F4),
147
148         KEY(2, 0, KEY_UP),
149         KEY(2, 2, KEY_DOWN),
150
151         KEY(3, 0, KEY_RIGHT),
152         KEY(3, 2, KEY_LEFT),
153 };
154
155 static struct matrix_keymap_data almz72_matrix_keymap_data = {
156         .keymap                 = palmz72_matrix_keys,
157         .keymap_size            = ARRAY_SIZE(palmz72_matrix_keys),
158 };
159
160 static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = {
161         .matrix_key_rows        = 4,
162         .matrix_key_cols        = 3,
163         .matrix_keymap_data     = &almz72_matrix_keymap_data,
164
165         .debounce_interval      = 30,
166 };
167
168 static void __init palmz72_kpc_init(void)
169 {
170         pxa_set_keypad_info(&palmz72_keypad_platform_data);
171 }
172 #else
173 static inline void palmz72_kpc_init(void) {}
174 #endif
175
176 /******************************************************************************
177  * LEDs
178  ******************************************************************************/
179 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
180 static struct gpio_led gpio_leds[] = {
181         {
182                 .name                   = "palmz72:green:led",
183                 .default_trigger        = "none",
184                 .gpio                   = GPIO_NR_PALMZ72_LED_GREEN,
185         },
186 };
187
188 static struct gpio_led_platform_data gpio_led_info = {
189         .leds           = gpio_leds,
190         .num_leds       = ARRAY_SIZE(gpio_leds),
191 };
192
193 static struct platform_device palmz72_leds = {
194         .name   = "leds-gpio",
195         .id     = -1,
196         .dev    = {
197                 .platform_data  = &gpio_led_info,
198         }
199 };
200
201 static void __init palmz72_leds_init(void)
202 {
203         platform_device_register(&palmz72_leds);
204 }
205 #else
206 static inline void palmz72_leds_init(void) {}
207 #endif
208
209 #ifdef CONFIG_PM
210
211 /* We have some black magic here
212  * PalmOS ROM on recover expects special struct physical address
213  * to be transferred via PSPR. Using this struct PalmOS restores
214  * its state after sleep. As for Linux, we need to setup it the
215  * same way. More than that, PalmOS ROM changes some values in memory.
216  * For now only one location is found, which needs special treatment.
217  * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
218  * for reading backtraces for me :)
219  */
220
221 #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
222
223 static struct palmz72_resume_info palmz72_resume_info = {
224         .magic0 = 0xb4e6,
225         .magic1 = 1,
226
227         /* reset state, MMU off etc */
228         .arm_control = 0,
229         .aux_control = 0,
230         .ttb = 0,
231         .domain_access = 0,
232         .process_id = 0,
233 };
234
235 static unsigned long store_ptr;
236
237 /* syscore_ops for Palm Zire 72 PM */
238
239 static int palmz72_pm_suspend(void)
240 {
241         /* setup the resume_info struct for the original bootloader */
242         palmz72_resume_info.resume_addr = (u32) cpu_resume;
243
244         /* Storing memory touched by ROM */
245         store_ptr = *PALMZ72_SAVE_DWORD;
246
247         /* Setting PSPR to a proper value */
248         PSPR = __pa_symbol(&palmz72_resume_info);
249
250         return 0;
251 }
252
253 static void palmz72_pm_resume(void)
254 {
255         *PALMZ72_SAVE_DWORD = store_ptr;
256 }
257
258 static struct syscore_ops palmz72_pm_syscore_ops = {
259         .suspend = palmz72_pm_suspend,
260         .resume = palmz72_pm_resume,
261 };
262
263 static int __init palmz72_pm_init(void)
264 {
265         if (machine_is_palmz72()) {
266                 register_syscore_ops(&palmz72_pm_syscore_ops);
267                 return 0;
268         }
269         return -ENODEV;
270 }
271
272 device_initcall(palmz72_pm_init);
273 #endif
274
275 /******************************************************************************
276  * SoC Camera
277  ******************************************************************************/
278 #if defined(CONFIG_SOC_CAMERA_OV9640) || \
279         defined(CONFIG_SOC_CAMERA_OV9640_MODULE)
280 static struct pxacamera_platform_data palmz72_pxacamera_platform_data = {
281         .flags          = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 |
282                         PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN,
283         .mclk_10khz     = 2600,
284 };
285
286 /* Board I2C devices. */
287 static struct i2c_board_info palmz72_i2c_device[] = {
288         {
289                 I2C_BOARD_INFO("ov9640", 0x30),
290         }
291 };
292
293 static int palmz72_camera_power(struct device *dev, int power)
294 {
295         gpio_set_value(GPIO_NR_PALMZ72_CAM_PWDN, !power);
296         mdelay(50);
297         return 0;
298 }
299
300 static int palmz72_camera_reset(struct device *dev)
301 {
302         gpio_set_value(GPIO_NR_PALMZ72_CAM_RESET, 1);
303         mdelay(50);
304         gpio_set_value(GPIO_NR_PALMZ72_CAM_RESET, 0);
305         mdelay(50);
306         return 0;
307 }
308
309 static struct soc_camera_link palmz72_iclink = {
310         .bus_id         = 0, /* Match id in pxa27x_device_camera in device.c */
311         .board_info     = &palmz72_i2c_device[0],
312         .i2c_adapter_id = 0,
313         .module_name    = "ov96xx",
314         .power          = &palmz72_camera_power,
315         .reset          = &palmz72_camera_reset,
316         .flags          = SOCAM_DATAWIDTH_8,
317 };
318
319 static struct gpiod_lookup_table palmz72_i2c_gpiod_table = {
320         .dev_id         = "i2c-gpio.0",
321         .table          = {
322                 GPIO_LOOKUP_IDX("gpio-pxa", 118, NULL, 0,
323                                 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
324                 GPIO_LOOKUP_IDX("gpio-pxa", 117, NULL, 1,
325                                 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
326         },
327 };
328
329 static struct i2c_gpio_platform_data palmz72_i2c_bus_data = {
330         .udelay         = 10,
331         .timeout        = 100,
332 };
333
334 static struct platform_device palmz72_i2c_bus_device = {
335         .name           = "i2c-gpio",
336         .id             = 0, /* we use this as a replacement for i2c-pxa */
337         .dev            = {
338                 .platform_data  = &palmz72_i2c_bus_data,
339         }
340 };
341
342 static struct platform_device palmz72_camera = {
343         .name   = "soc-camera-pdrv",
344         .id     = -1,
345         .dev    = {
346                 .platform_data  = &palmz72_iclink,
347         },
348 };
349
350 /* Here we request the camera GPIOs and configure them. We power up the camera
351  * module, deassert the reset pin, but put it into powerdown (low to no power
352  * consumption) mode. This allows us to later bring the module up fast. */
353 static struct gpio palmz72_camera_gpios[] = {
354         { GPIO_NR_PALMZ72_CAM_POWER,    GPIOF_INIT_HIGH,"Camera DVDD" },
355         { GPIO_NR_PALMZ72_CAM_RESET,    GPIOF_INIT_LOW, "Camera RESET" },
356         { GPIO_NR_PALMZ72_CAM_PWDN,     GPIOF_INIT_LOW, "Camera PWDN" },
357 };
358
359 static inline void __init palmz72_cam_gpio_init(void)
360 {
361         int ret;
362
363         ret = gpio_request_array(ARRAY_AND_SIZE(palmz72_camera_gpios));
364         if (!ret)
365                 gpio_free_array(ARRAY_AND_SIZE(palmz72_camera_gpios));
366         else
367                 printk(KERN_ERR "Camera GPIO init failed!\n");
368
369         return;
370 }
371
372 static void __init palmz72_camera_init(void)
373 {
374         palmz72_cam_gpio_init();
375         pxa_set_camera_info(&palmz72_pxacamera_platform_data);
376         gpiod_add_lookup_table(&palmz72_i2c_gpiod_table);
377         platform_device_register(&palmz72_i2c_bus_device);
378         platform_device_register(&palmz72_camera);
379 }
380 #else
381 static inline void palmz72_camera_init(void) {}
382 #endif
383
384 static struct gpiod_lookup_table palmz72_mci_gpio_table = {
385         .dev_id = "pxa2xx-mci.0",
386         .table = {
387                 GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMZ72_SD_DETECT_N,
388                             "cd", GPIO_ACTIVE_LOW),
389                 GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMZ72_SD_RO,
390                             "wp", GPIO_ACTIVE_LOW),
391                 GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMZ72_SD_POWER_N,
392                             "power", GPIO_ACTIVE_LOW),
393                 { },
394         },
395 };
396
397 /******************************************************************************
398  * Machine init
399  ******************************************************************************/
400 static void __init palmz72_init(void)
401 {
402         pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
403         pxa_set_ffuart_info(NULL);
404         pxa_set_btuart_info(NULL);
405         pxa_set_stuart_info(NULL);
406
407         palm27x_mmc_init(&palmz72_mci_gpio_table);
408         palm27x_lcd_init(-1, &palm_320x320_lcd_mode);
409         palm27x_udc_init(GPIO_NR_PALMZ72_USB_DETECT_N,
410                         GPIO_NR_PALMZ72_USB_PULLUP, 0);
411         palm27x_irda_init(GPIO_NR_PALMZ72_IR_DISABLE);
412         palm27x_ac97_init(PALMZ72_BAT_MIN_VOLTAGE, PALMZ72_BAT_MAX_VOLTAGE,
413                         -1, 113);
414         palm27x_pwm_init(-1, -1);
415         palm27x_power_init(-1, -1);
416         palm27x_pmic_init();
417         palmz72_kpc_init();
418         palmz72_leds_init();
419         palmz72_camera_init();
420 }
421
422 MACHINE_START(PALMZ72, "Palm Zire72")
423         .atag_offset    = 0x100,
424         .map_io         = pxa27x_map_io,
425         .nr_irqs        = PXA_NR_IRQS,
426         .init_irq       = pxa27x_init_irq,
427         .handle_irq     = pxa27x_handle_irq,
428         .init_time      = pxa_timer_init,
429         .init_machine   = palmz72_init,
430         .restart        = pxa_restart,
431 MACHINE_END