Create platform_device.h to contain all the platform device details.
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-pxa / spitz.c
1 /*
2  * Support for Sharp SL-Cxx00 Series of PDAs
3  * Models: SL-C3000 (Spitz), SL-C1000 (Akita) and SL-C3100 (Borzoi)
4  *
5  * Copyright (c) 2005 Richard Purdie
6  *
7  * Based on Sharp's 2.4 kernel patches/lubbock.c
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  *
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/major.h>
20 #include <linux/fs.h>
21 #include <linux/interrupt.h>
22 #include <linux/mmc/host.h>
23
24 #include <asm/setup.h>
25 #include <asm/memory.h>
26 #include <asm/mach-types.h>
27 #include <asm/hardware.h>
28 #include <asm/irq.h>
29 #include <asm/io.h>
30
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33 #include <asm/mach/irq.h>
34
35 #include <asm/arch/pxa-regs.h>
36 #include <asm/arch/irq.h>
37 #include <asm/arch/mmc.h>
38 #include <asm/arch/udc.h>
39 #include <asm/arch/pxafb.h>
40 #include <asm/arch/akita.h>
41 #include <asm/arch/spitz.h>
42 #include <asm/arch/sharpsl.h>
43
44 #include <asm/mach/sharpsl_param.h>
45 #include <asm/hardware/scoop.h>
46
47 #include "generic.h"
48 #include "sharpsl.h"
49
50 /*
51  * Spitz SCOOP Device #1
52  */
53 static struct resource spitz_scoop_resources[] = {
54         [0] = {
55                 .start          = 0x10800000,
56                 .end            = 0x10800fff,
57                 .flags          = IORESOURCE_MEM,
58         },
59 };
60
61 static struct scoop_config spitz_scoop_setup = {
62         .io_dir         = SPITZ_SCP_IO_DIR,
63         .io_out         = SPITZ_SCP_IO_OUT,
64         .suspend_clr = SPITZ_SCP_SUS_CLR,
65         .suspend_set = SPITZ_SCP_SUS_SET,
66 };
67
68 struct platform_device spitzscoop_device = {
69         .name           = "sharp-scoop",
70         .id             = 0,
71         .dev            = {
72                 .platform_data  = &spitz_scoop_setup,
73         },
74         .num_resources  = ARRAY_SIZE(spitz_scoop_resources),
75         .resource       = spitz_scoop_resources,
76 };
77
78 /*
79  * Spitz SCOOP Device #2
80  */
81 static struct resource spitz_scoop2_resources[] = {
82         [0] = {
83                 .start          = 0x08800040,
84                 .end            = 0x08800fff,
85                 .flags          = IORESOURCE_MEM,
86         },
87 };
88
89 static struct scoop_config spitz_scoop2_setup = {
90         .io_dir         = SPITZ_SCP2_IO_DIR,
91         .io_out         = SPITZ_SCP2_IO_OUT,
92         .suspend_clr = SPITZ_SCP2_SUS_CLR,
93         .suspend_set = SPITZ_SCP2_SUS_SET,
94 };
95
96 struct platform_device spitzscoop2_device = {
97         .name           = "sharp-scoop",
98         .id             = 1,
99         .dev            = {
100                 .platform_data  = &spitz_scoop2_setup,
101         },
102         .num_resources  = ARRAY_SIZE(spitz_scoop2_resources),
103         .resource       = spitz_scoop2_resources,
104 };
105
106 static struct scoop_pcmcia_dev spitz_pcmcia_scoop[] = {
107 {
108         .dev        = &spitzscoop_device.dev,
109         .irq        = SPITZ_IRQ_GPIO_CF_IRQ,
110         .cd_irq     = SPITZ_IRQ_GPIO_CF_CD,
111         .cd_irq_str = "PCMCIA0 CD",
112 },{
113         .dev        = &spitzscoop2_device.dev,
114         .irq        = SPITZ_IRQ_GPIO_CF2_IRQ,
115         .cd_irq     = -1,
116 },
117 };
118
119
120 /*
121  * Spitz SSP Device
122  *
123  * Set the parent as the scoop device because a lot of SSP devices
124  * also use scoop functions and this makes the power up/down order
125  * work correctly.
126  */
127 struct platform_device spitzssp_device = {
128         .name           = "corgi-ssp",
129         .dev            = {
130                 .parent = &spitzscoop_device.dev,
131         },
132         .id             = -1,
133 };
134
135 struct corgissp_machinfo spitz_ssp_machinfo = {
136         .port           = 2,
137         .cs_lcdcon      = SPITZ_GPIO_LCDCON_CS,
138         .cs_ads7846     = SPITZ_GPIO_ADS7846_CS,
139         .cs_max1111     = SPITZ_GPIO_MAX1111_CS,
140         .clk_lcdcon     = 520,
141         .clk_ads7846    = 14,
142         .clk_max1111    = 56,
143 };
144
145
146 /*
147  * Spitz Backlight Device
148  */
149 static struct corgibl_machinfo spitz_bl_machinfo = {
150         .max_intensity = 0x2f,
151 };
152
153 static struct platform_device spitzbl_device = {
154         .name           = "corgi-bl",
155         .dev            = {
156                 .platform_data  = &spitz_bl_machinfo,
157         },
158         .id             = -1,
159 };
160
161
162 /*
163  * Spitz Keyboard Device
164  */
165 static struct platform_device spitzkbd_device = {
166         .name           = "spitz-keyboard",
167         .id             = -1,
168 };
169
170
171 /*
172  * Spitz Touch Screen Device
173  */
174 static struct resource spitzts_resources[] = {
175         [0] = {
176                 .start          = SPITZ_IRQ_GPIO_TP_INT,
177                 .end            = SPITZ_IRQ_GPIO_TP_INT,
178                 .flags          = IORESOURCE_IRQ,
179         },
180 };
181
182 static struct corgits_machinfo  spitz_ts_machinfo = {
183         .get_hsync_len   = spitz_get_hsync_len,
184         .put_hsync       = spitz_put_hsync,
185         .wait_hsync      = spitz_wait_hsync,
186 };
187
188 static struct platform_device spitzts_device = {
189         .name           = "corgi-ts",
190         .dev            = {
191                 .parent = &spitzssp_device.dev,
192                 .platform_data  = &spitz_ts_machinfo,
193         },
194         .id             = -1,
195         .num_resources  = ARRAY_SIZE(spitzts_resources),
196         .resource       = spitzts_resources,
197 };
198
199
200 /*
201  * MMC/SD Device
202  *
203  * The card detect interrupt isn't debounced so we delay it by 250ms
204  * to give the card a chance to fully insert/eject.
205  */
206
207 static struct pxamci_platform_data spitz_mci_platform_data;
208
209 static int spitz_mci_init(struct device *dev, irqreturn_t (*spitz_detect_int)(int, void *, struct pt_regs *), void *data)
210 {
211         int err;
212
213         /* setup GPIO for PXA27x MMC controller */
214         pxa_gpio_mode(GPIO32_MMCCLK_MD);
215         pxa_gpio_mode(GPIO112_MMCCMD_MD);
216         pxa_gpio_mode(GPIO92_MMCDAT0_MD);
217         pxa_gpio_mode(GPIO109_MMCDAT1_MD);
218         pxa_gpio_mode(GPIO110_MMCDAT2_MD);
219         pxa_gpio_mode(GPIO111_MMCDAT3_MD);
220         pxa_gpio_mode(SPITZ_GPIO_nSD_DETECT | GPIO_IN);
221         pxa_gpio_mode(SPITZ_GPIO_nSD_WP | GPIO_IN);
222
223         spitz_mci_platform_data.detect_delay = msecs_to_jiffies(250);
224
225         err = request_irq(SPITZ_IRQ_GPIO_nSD_DETECT, spitz_detect_int, SA_INTERRUPT,
226                              "MMC card detect", data);
227         if (err) {
228                 printk(KERN_ERR "spitz_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
229                 return -1;
230         }
231
232         set_irq_type(SPITZ_IRQ_GPIO_nSD_DETECT, IRQT_BOTHEDGE);
233
234         return 0;
235 }
236
237 /* Power control is shared with one of the CF slots so we have a mess */
238 static void spitz_mci_setpower(struct device *dev, unsigned int vdd)
239 {
240         struct pxamci_platform_data* p_d = dev->platform_data;
241
242         unsigned short cpr = read_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR);
243
244         if (( 1 << vdd) & p_d->ocr_mask) {
245                 /* printk(KERN_DEBUG "%s: on\n", __FUNCTION__); */
246                 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_CF_POWER);
247                 mdelay(2);
248                 write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, cpr | 0x04);
249         } else {
250                 /* printk(KERN_DEBUG "%s: off\n", __FUNCTION__); */
251                 write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, cpr & ~0x04);
252
253                 if (!(cpr | 0x02)) {
254                         mdelay(1);
255                         reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_CF_POWER);
256                 }
257         }
258 }
259
260 static int spitz_mci_get_ro(struct device *dev)
261 {
262         return GPLR(SPITZ_GPIO_nSD_WP) & GPIO_bit(SPITZ_GPIO_nSD_WP);
263 }
264
265 static void spitz_mci_exit(struct device *dev, void *data)
266 {
267         free_irq(SPITZ_IRQ_GPIO_nSD_DETECT, data);
268 }
269
270 static struct pxamci_platform_data spitz_mci_platform_data = {
271         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
272         .init           = spitz_mci_init,
273         .get_ro         = spitz_mci_get_ro,
274         .setpower       = spitz_mci_setpower,
275         .exit           = spitz_mci_exit,
276 };
277
278
279 /*
280  * Spitz PXA Framebuffer
281  */
282 static struct pxafb_mach_info spitz_pxafb_info __initdata = {
283         .pixclock       = 19231,
284         .xres           = 480,
285         .yres           = 640,
286         .bpp            = 16,
287         .hsync_len      = 40,
288         .left_margin    = 46,
289         .right_margin   = 125,
290         .vsync_len      = 3,
291         .upper_margin   = 1,
292         .lower_margin   = 0,
293         .sync           = 0,
294         .lccr0          = LCCR0_Color | LCCR0_Sngl | LCCR0_Act | LCCR0_LDDALT | LCCR0_OUC | LCCR0_CMDIM | LCCR0_RDSTM,
295         .lccr3          = LCCR3_PixRsEdg | LCCR3_OutEnH,
296         .pxafb_lcd_power = spitz_lcd_power,
297 };
298
299
300 static struct platform_device *devices[] __initdata = {
301         &spitzscoop_device,
302         &spitzssp_device,
303         &spitzkbd_device,
304         &spitzts_device,
305         &spitzbl_device,
306 };
307
308 static void __init common_init(void)
309 {
310         PMCR = 0x00;
311
312         /* setup sleep mode values */
313         PWER  = 0x00000002;
314         PFER  = 0x00000000;
315         PRER  = 0x00000002;
316         PGSR0 = 0x0158C000;
317         PGSR1 = 0x00FF0080;
318         PGSR2 = 0x0001C004;
319
320         /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
321         PCFR |= PCFR_OPDE;
322
323         corgi_ssp_set_machinfo(&spitz_ssp_machinfo);
324
325         pxa_gpio_mode(SPITZ_GPIO_HSYNC | GPIO_IN);
326
327         platform_add_devices(devices, ARRAY_SIZE(devices));
328         pxa_set_mci_info(&spitz_mci_platform_data);
329         set_pxa_fb_parent(&spitzssp_device.dev);
330         set_pxa_fb_info(&spitz_pxafb_info);
331 }
332
333 static void __init spitz_init(void)
334 {
335         scoop_num = 2;
336         scoop_devs = &spitz_pcmcia_scoop[0];
337         spitz_bl_machinfo.set_bl_intensity = spitz_bl_set_intensity;
338
339         common_init();
340
341         platform_device_register(&spitzscoop2_device);
342 }
343
344 static void __init fixup_spitz(struct machine_desc *desc,
345                 struct tag *tags, char **cmdline, struct meminfo *mi)
346 {
347         sharpsl_save_param();
348         mi->nr_banks = 1;
349         mi->bank[0].start = 0xa0000000;
350         mi->bank[0].node = 0;
351         mi->bank[0].size = (64*1024*1024);
352 }
353
354 #ifdef CONFIG_MACH_SPITZ
355 MACHINE_START(SPITZ, "SHARP Spitz")
356         .phys_ram       = 0xa0000000,
357         .phys_io        = 0x40000000,
358         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
359         .fixup          = fixup_spitz,
360         .map_io         = pxa_map_io,
361         .init_irq       = pxa_init_irq,
362         .init_machine   = spitz_init,
363         .timer          = &pxa_timer,
364 MACHINE_END
365 #endif
366
367 #ifdef CONFIG_MACH_BORZOI
368 MACHINE_START(BORZOI, "SHARP Borzoi")
369         .phys_ram       = 0xa0000000,
370         .phys_io        = 0x40000000,
371         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
372         .fixup          = fixup_spitz,
373         .map_io         = pxa_map_io,
374         .init_irq       = pxa_init_irq,
375         .init_machine   = spitz_init,
376         .timer          = &pxa_timer,
377 MACHINE_END
378 #endif