arm:lpc32xx:spi/pl022 Add spi->mode support AMBA SPI driver
[linux-2.6.34-lpc32xx.git] / arch / arm / mach-ux500 / board-mop500.c
1 /*
2  * Copyright (C) 2008-2009 ST-Ericsson
3  *
4  * Author: Srinidhi KASAGAR <srinidhi.kasagar@stericsson.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2, as
8  * published by the Free Software Foundation.
9  *
10  */
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
14 #include <linux/platform_device.h>
15 #include <linux/io.h>
16 #include <linux/amba/bus.h>
17 #include <linux/amba/pl022.h>
18 #include <linux/spi/spi.h>
19
20 #include <asm/localtimer.h>
21 #include <asm/mach-types.h>
22 #include <asm/mach/arch.h>
23
24 #include <plat/mtu.h>
25 #include <plat/i2c.h>
26
27 #include <mach/hardware.h>
28 #include <mach/setup.h>
29
30 #define __MEM_4K_RESOURCE(x) \
31         .res = {.start = (x), .end = (x) + SZ_4K - 1, .flags = IORESOURCE_MEM}
32
33 /* These are active devices on this board */
34 static struct amba_device uart0_device = {
35         .dev = { .init_name = "uart0" },
36         __MEM_4K_RESOURCE(U8500_UART0_BASE),
37         .irq = {IRQ_UART0, NO_IRQ},
38 };
39
40 static struct amba_device uart1_device = {
41         .dev = { .init_name = "uart1" },
42         __MEM_4K_RESOURCE(U8500_UART1_BASE),
43         .irq = {IRQ_UART1, NO_IRQ},
44 };
45
46 static struct amba_device uart2_device = {
47         .dev = { .init_name = "uart2" },
48         __MEM_4K_RESOURCE(U8500_UART2_BASE),
49         .irq = {IRQ_UART2, NO_IRQ},
50 };
51
52 static void ab4500_spi_cs_control(u32 command)
53 {
54         /* set the FRM signal, which is CS  - TODO */
55 }
56
57 struct pl022_config_chip ab4500_chip_info = {
58         .com_mode = INTERRUPT_TRANSFER,
59         .iface = SSP_INTERFACE_MOTOROLA_SPI,
60         /* we can act as master only */
61         .hierarchy = SSP_MASTER,
62         .slave_tx_disable = 0,
63         .rx_lev_trig = SSP_RX_1_OR_MORE_ELEM,
64         .tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC,
65         .cs_control = ab4500_spi_cs_control,
66 };
67
68 static struct spi_board_info u8500_spi_devices[] = {
69         {
70                 .modalias = "ab4500",
71                 .controller_data = &ab4500_chip_info,
72                 .max_speed_hz = 12000000,
73                 .bus_num = 0,
74                 .chip_select = 0,
75                 .mode = SPI_MODE_3,
76                 .irq = IRQ_AB4500,
77         },
78 };
79
80 static struct pl022_ssp_controller ssp0_platform_data = {
81         .bus_id = 0,
82         /* pl022 not yet supports dma */
83         .enable_dma = 0,
84         /* on this platform, gpio 31,142,144,214 &
85          * 224 are connected as chip selects
86          */
87         .num_chipselect = 5,
88 };
89
90 static struct amba_device pl022_device = {
91         .dev = {
92                 .coherent_dma_mask = ~0,
93                 .init_name = "pl022",
94                 .platform_data = &ssp0_platform_data,
95         },
96         .res = {
97                 .start = U8500_SSP0_BASE,
98                 .end   = U8500_SSP0_BASE + SZ_4K - 1,
99                 .flags = IORESOURCE_MEM,
100         },
101         .irq = {IRQ_SSP0, NO_IRQ },
102         /* ST-Ericsson modified id */
103         .periphid = SSP_PER_ID,
104 };
105
106 static struct amba_device pl031_device = {
107         .dev = {
108                 .init_name = "pl031",
109         },
110         .res = {
111                 .start = U8500_RTC_BASE,
112                 .end = U8500_RTC_BASE + SZ_4K - 1,
113                 .flags = IORESOURCE_MEM,
114         },
115         .irq = {IRQ_RTC_RTT, NO_IRQ},
116 };
117
118 #define U8500_I2C_RESOURCES(id, size)           \
119 static struct resource u8500_i2c_resources_##id[] = {   \
120         [0] = {                                 \
121                 .start  = U8500_I2C##id##_BASE, \
122                 .end    = U8500_I2C##id##_BASE + size - 1, \
123                 .flags  = IORESOURCE_MEM,       \
124         },                                      \
125         [1] = {                                 \
126                 .start  = IRQ_I2C##id,          \
127                 .end    = IRQ_I2C##id,          \
128                 .flags  = IORESOURCE_IRQ        \
129         }                                       \
130 }
131
132 U8500_I2C_RESOURCES(0, SZ_4K);
133 U8500_I2C_RESOURCES(1, SZ_4K);
134 U8500_I2C_RESOURCES(2, SZ_4K);
135 U8500_I2C_RESOURCES(3, SZ_4K);
136
137 #define U8500_I2C_CONTROLLER(id, _slsu, _tft, _rft, clk, _sm) \
138 static struct nmk_i2c_controller u8500_i2c_##id = { \
139         /*                              \
140          * slave data setup time, which is      \
141          * 250 ns,100ns,10ns which is 14,6,2    \
142          * respectively for a 48 Mhz    \
143          * i2c clock                    \
144          */                             \
145         .slsu           = _slsu,        \
146         /* Tx FIFO threshold */         \
147         .tft            = _tft,         \
148         /* Rx FIFO threshold */         \
149         .rft            = _rft,         \
150         /* std. mode operation */       \
151         .clk_freq       = clk,          \
152         .sm             = _sm,          \
153 }
154
155 /*
156  * The board uses 4 i2c controllers, initialize all of
157  * them with slave data setup time of 250 ns,
158  * Tx & Rx FIFO threshold values as 1 and standard
159  * mode of operation
160  */
161 U8500_I2C_CONTROLLER(0, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD);
162 U8500_I2C_CONTROLLER(1, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD);
163 U8500_I2C_CONTROLLER(2, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD);
164 U8500_I2C_CONTROLLER(3, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD);
165
166 #define U8500_I2C_PDEVICE(cid)          \
167 static struct platform_device i2c_controller##cid = { \
168         .name = "nmk-i2c",              \
169         .id      = cid,                 \
170         .num_resources = 2,             \
171         .resource = u8500_i2c_resources_##cid,  \
172         .dev = {                        \
173                 .platform_data = &u8500_i2c_##cid \
174         }                               \
175 }
176
177 U8500_I2C_PDEVICE(0);
178 U8500_I2C_PDEVICE(1);
179 U8500_I2C_PDEVICE(2);
180 U8500_I2C_PDEVICE(3);
181
182 static struct amba_device *amba_devs[] __initdata = {
183         &uart0_device,
184         &uart1_device,
185         &uart2_device,
186         &pl022_device,
187         &pl031_device,
188 };
189
190 /* add any platform devices here - TODO */
191 static struct platform_device *platform_devs[] __initdata = {
192         &i2c_controller0,
193         &i2c_controller1,
194         &i2c_controller2,
195         &i2c_controller3,
196 };
197
198 static void __init u8500_timer_init(void)
199 {
200 #ifdef CONFIG_LOCAL_TIMERS
201         /* Setup the local timer base */
202         twd_base = __io_address(U8500_TWD_BASE);
203 #endif
204         /* Setup the MTU base */
205         mtu_base = __io_address(U8500_MTU0_BASE);
206
207         nmdk_timer_init();
208 }
209
210 static struct sys_timer u8500_timer = {
211         .init   = u8500_timer_init,
212 };
213
214 static void __init u8500_init_machine(void)
215 {
216         int i;
217
218         /* Register the active AMBA devices on this board */
219         for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
220                 amba_device_register(amba_devs[i], &iomem_resource);
221
222         platform_add_devices(platform_devs, ARRAY_SIZE(platform_devs));
223
224         spi_register_board_info(u8500_spi_devices,
225                         ARRAY_SIZE(u8500_spi_devices));
226
227         u8500_init_devices();
228 }
229
230 MACHINE_START(U8500, "ST-Ericsson MOP500 platform")
231         /* Maintainer: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com> */
232         .phys_io        = U8500_UART2_BASE,
233         .io_pg_offst    = (IO_ADDRESS(U8500_UART2_BASE) >> 18) & 0xfffc,
234         .boot_params    = 0x100,
235         .map_io         = u8500_map_io,
236         .init_irq       = u8500_init_irq,
237         /* we re-use nomadik timer here */
238         .timer          = &u8500_timer,
239         .init_machine   = u8500_init_machine,
240 MACHINE_END