]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-pxa/em-x270.c
1269ac991505e410470af4f15b7063a59747fc87
[linux-2.6-omap-h63xx.git] / arch / arm / mach-pxa / em-x270.c
1 /*
2  * Support for CompuLab EM-x270 platform
3  *
4  * Copyright (C) 2007 CompuLab, Ltd.
5  * Author: Mike Rapoport <mike@compulab.co.il>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/irq.h>
13 #include <linux/platform_device.h>
14
15 #include <linux/dm9000.h>
16 #include <linux/rtc-v3020.h>
17
18 #include <linux/mtd/nand.h>
19 #include <linux/mtd/partitions.h>
20
21 #include <asm/mach-types.h>
22
23 #include <asm/mach/arch.h>
24
25 #include <asm/arch/pxa-regs.h>
26 #include <asm/arch/pxa2xx-gpio.h>
27 #include <asm/arch/pxa27x-udc.h>
28 #include <asm/arch/pxafb.h>
29 #include <asm/arch/ohci.h>
30 #include <asm/arch/mmc.h>
31 #include <asm/arch/bitfield.h>
32
33 #include "generic.h"
34
35 /* GPIO IRQ usage */
36 #define EM_X270_MMC_PD          (105)
37 #define EM_X270_ETHIRQ          IRQ_GPIO(41)
38 #define EM_X270_MMC_IRQ         IRQ_GPIO(13)
39
40 static struct resource em_x270_dm9k_resource[] = {
41         [0] = {
42                 .start = PXA_CS2_PHYS,
43                 .end   = PXA_CS2_PHYS + 3,
44                 .flags = IORESOURCE_MEM,
45         },
46         [1] = {
47                 .start = PXA_CS2_PHYS + 8,
48                 .end   = PXA_CS2_PHYS + 8 + 0x3f,
49                 .flags = IORESOURCE_MEM,
50         },
51         [2] = {
52                 .start = EM_X270_ETHIRQ,
53                 .end   = EM_X270_ETHIRQ,
54                 .flags = IORESOURCE_IRQ,
55         }
56 };
57
58 /* for the moment we limit ourselves to 32bit IO until some
59  * better IO routines can be written and tested
60  */
61 static struct dm9000_plat_data em_x270_dm9k_platdata = {
62         .flags          = DM9000_PLATF_32BITONLY,
63 };
64
65 /* Ethernet device */
66 static struct platform_device em_x270_dm9k = {
67         .name           = "dm9000",
68         .id             = 0,
69         .num_resources  = ARRAY_SIZE(em_x270_dm9k_resource),
70         .resource       = em_x270_dm9k_resource,
71         .dev            = {
72                 .platform_data = &em_x270_dm9k_platdata,
73         }
74 };
75
76 /* audio device */
77 static struct platform_device em_x270_audio = {
78         .name           = "pxa2xx-ac97",
79         .id             = -1,
80 };
81
82 /* WM9712 touchscreen controller. Hopefully the driver will make it to
83  * the mainstream sometime */
84 static struct platform_device em_x270_ts = {
85         .name           = "wm97xx-ts",
86         .id             = -1,
87 };
88
89 /* RTC */
90 static struct resource em_x270_v3020_resource[] = {
91         [0] = {
92                 .start = PXA_CS4_PHYS,
93                 .end   = PXA_CS4_PHYS + 3,
94                 .flags = IORESOURCE_MEM,
95         },
96 };
97
98 static struct v3020_platform_data em_x270_v3020_platdata = {
99         .leftshift = 0,
100 };
101
102 static struct platform_device em_x270_rtc = {
103         .name           = "v3020",
104         .num_resources  = ARRAY_SIZE(em_x270_v3020_resource),
105         .resource       = em_x270_v3020_resource,
106         .id             = -1,
107         .dev            = {
108                 .platform_data = &em_x270_v3020_platdata,
109         }
110 };
111
112 /* NAND flash */
113 #define GPIO_NAND_CS    (11)
114 #define GPIO_NAND_RB    (56)
115
116 static inline void nand_cs_on(void)
117 {
118         GPCR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS);
119 }
120
121 static void nand_cs_off(void)
122 {
123         dsb();
124
125         GPSR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS);
126 }
127
128 /* hardware specific access to control-lines */
129 static void em_x270_nand_cmd_ctl(struct mtd_info *mtd, int dat,
130                                  unsigned int ctrl)
131 {
132         struct nand_chip *this = mtd->priv;
133         unsigned long nandaddr = (unsigned long)this->IO_ADDR_W;
134
135         dsb();
136
137         if (ctrl & NAND_CTRL_CHANGE) {
138                 if (ctrl & NAND_ALE)
139                         nandaddr |=  (1 << 3);
140                 else
141                         nandaddr &= ~(1 << 3);
142                 if (ctrl & NAND_CLE)
143                         nandaddr |=  (1 << 2);
144                 else
145                         nandaddr &= ~(1 << 2);
146                 if (ctrl & NAND_NCE)
147                         nand_cs_on();
148                 else
149                         nand_cs_off();
150         }
151
152         dsb();
153         this->IO_ADDR_W = (void __iomem *)nandaddr;
154         if (dat != NAND_CMD_NONE)
155                 writel(dat, this->IO_ADDR_W);
156
157         dsb();
158 }
159
160 /* read device ready pin */
161 static int em_x270_nand_device_ready(struct mtd_info *mtd)
162 {
163         dsb();
164
165         return GPLR(GPIO_NAND_RB) & GPIO_bit(GPIO_NAND_RB);
166 }
167
168 static struct mtd_partition em_x270_partition_info[] = {
169         [0] = {
170                 .name   = "em_x270-0",
171                 .offset = 0,
172                 .size   = SZ_4M,
173         },
174         [1] = {
175                 .name   = "em_x270-1",
176                 .offset = MTDPART_OFS_APPEND,
177                 .size   = MTDPART_SIZ_FULL
178         },
179 };
180
181 static const char *em_x270_part_probes[] = { "cmdlinepart", NULL };
182
183 struct platform_nand_data em_x270_nand_platdata = {
184         .chip = {
185                 .nr_chips = 1,
186                 .chip_offset = 0,
187                 .nr_partitions = ARRAY_SIZE(em_x270_partition_info),
188                 .partitions = em_x270_partition_info,
189                 .chip_delay = 20,
190                 .part_probe_types = em_x270_part_probes,
191         },
192         .ctrl = {
193                 .hwcontrol = 0,
194                 .dev_ready = em_x270_nand_device_ready,
195                 .select_chip = 0,
196                 .cmd_ctrl = em_x270_nand_cmd_ctl,
197         },
198 };
199
200 static struct resource em_x270_nand_resource[] = {
201         [0] = {
202                 .start = PXA_CS1_PHYS,
203                 .end   = PXA_CS1_PHYS + 12,
204                 .flags = IORESOURCE_MEM,
205         },
206 };
207
208 static struct platform_device em_x270_nand = {
209         .name           = "gen_nand",
210         .num_resources  = ARRAY_SIZE(em_x270_nand_resource),
211         .resource       = em_x270_nand_resource,
212         .id             = -1,
213         .dev            = {
214                 .platform_data = &em_x270_nand_platdata,
215         }
216 };
217
218 /* platform devices */
219 static struct platform_device *platform_devices[] __initdata = {
220         &em_x270_dm9k,
221         &em_x270_audio,
222         &em_x270_ts,
223         &em_x270_rtc,
224         &em_x270_nand,
225 };
226
227
228 /* PXA27x OHCI controller setup */
229 static int em_x270_ohci_init(struct device *dev)
230 {
231         /* Set the Power Control Polarity Low */
232         UHCHR = (UHCHR | UHCHR_PCPL) &
233                 ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE);
234
235         /* enable port 2 transiever */
236         UP2OCR = UP2OCR_HXS | UP2OCR_HXOE;
237
238         return 0;
239 }
240
241 static struct pxaohci_platform_data em_x270_ohci_platform_data = {
242         .port_mode      = PMM_PERPORT_MODE,
243         .init           = em_x270_ohci_init,
244 };
245
246
247 static int em_x270_mci_init(struct device *dev,
248                             irq_handler_t em_x270_detect_int,
249                             void *data)
250 {
251         int err;
252
253         /* setup GPIO for PXA27x MMC controller */
254         pxa_gpio_mode(GPIO32_MMCCLK_MD);
255         pxa_gpio_mode(GPIO112_MMCCMD_MD);
256         pxa_gpio_mode(GPIO92_MMCDAT0_MD);
257         pxa_gpio_mode(GPIO109_MMCDAT1_MD);
258         pxa_gpio_mode(GPIO110_MMCDAT2_MD);
259         pxa_gpio_mode(GPIO111_MMCDAT3_MD);
260
261         /* EM-X270 uses GPIO13 as SD power enable */
262         pxa_gpio_mode(EM_X270_MMC_PD | GPIO_OUT);
263
264         err = request_irq(EM_X270_MMC_IRQ, em_x270_detect_int,
265                           IRQF_DISABLED | IRQF_TRIGGER_FALLING,
266                           "MMC card detect", data);
267         if (err) {
268                 printk(KERN_ERR "%s: can't request MMC card detect IRQ: %d\n",
269                        __func__, err);
270                 return err;
271         }
272
273         return 0;
274 }
275
276 static void em_x270_mci_setpower(struct device *dev, unsigned int vdd)
277 {
278         /*
279            FIXME: current hardware implementation does not allow to
280            enable/disable MMC power. This will be fixed in next HW releases,
281            and we'll need to add implmentation here.
282         */
283         return;
284 }
285
286 static void em_x270_mci_exit(struct device *dev, void *data)
287 {
288         free_irq(EM_X270_MMC_IRQ, data);
289 }
290
291 static struct pxamci_platform_data em_x270_mci_platform_data = {
292         .ocr_mask       = MMC_VDD_28_29|MMC_VDD_29_30|MMC_VDD_30_31,
293         .init           = em_x270_mci_init,
294         .setpower       = em_x270_mci_setpower,
295         .exit           = em_x270_mci_exit,
296 };
297
298 /* LCD 480x640 */
299 static struct pxafb_mode_info em_x270_lcd_mode = {
300         .pixclock       = 50000,
301         .bpp            = 16,
302         .xres           = 480,
303         .yres           = 640,
304         .hsync_len      = 8,
305         .vsync_len      = 2,
306         .left_margin    = 8,
307         .upper_margin   = 0,
308         .right_margin   = 24,
309         .lower_margin   = 4,
310         .cmap_greyscale = 0,
311 };
312
313 static struct pxafb_mach_info em_x270_lcd = {
314         .modes          = &em_x270_lcd_mode,
315         .num_modes      = 1,
316         .cmap_inverse   = 0,
317         .cmap_static    = 0,
318         .lccr0          = LCCR0_PAS,
319         .lccr3          = LCCR3_PixClkDiv(0x01) | LCCR3_Acb(0xff),
320 };
321
322 static void __init em_x270_init(void)
323 {
324         /* setup LCD */
325         set_pxa_fb_info(&em_x270_lcd);
326
327         /* register EM-X270 platform devices */
328         platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
329
330         /* set MCI and OHCI platform parameters */
331         pxa_set_mci_info(&em_x270_mci_platform_data);
332         pxa_set_ohci_info(&em_x270_ohci_platform_data);
333
334         /* setup STUART GPIOs */
335         pxa_gpio_mode(GPIO46_STRXD_MD);
336         pxa_gpio_mode(GPIO47_STTXD_MD);
337
338         /* setup BTUART GPIOs */
339         pxa_gpio_mode(GPIO42_BTRXD_MD);
340         pxa_gpio_mode(GPIO43_BTTXD_MD);
341         pxa_gpio_mode(GPIO44_BTCTS_MD);
342         pxa_gpio_mode(GPIO45_BTRTS_MD);
343
344         /* Setup interrupt for dm9000 */
345         set_irq_type(EM_X270_ETHIRQ, IRQT_RISING);
346 }
347
348 MACHINE_START(EM_X270, "Compulab EM-x270")
349         .boot_params    = 0xa0000100,
350         .phys_io        = 0x40000000,
351         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
352         .map_io         = pxa_map_io,
353         .init_irq       = pxa27x_init_irq,
354         .timer          = &pxa_timer,
355         .init_machine   = em_x270_init,
356 MACHINE_END