SFFSDR: Update to board code to support FPGA and lyrvpss drivers
[linux-davinci-sffsdr.git] / arch / arm / mach-davinci / devices.c
bloba5c274e1002370c32ff86ea57e86e5bcecef6dc5
1 /*
2 * mach-davinci/devices.c
4 * DaVinci platform device setup/initialization
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/io.h>
18 #include <linux/random.h>
19 #include <linux/etherdevice.h>
21 #include <asm/io.h>
22 #include <asm/mach-types.h>
23 #include <asm/mach/map.h>
25 #include <mach/hardware.h>
26 #include <mach/edma.h>
27 #include <mach/emac.h>
28 #include <mach/i2c.h>
29 #include <mach/cpu.h>
30 #include <mach/mux.h>
31 #include <mach/mmc.h>
33 #include "clock.h"
36 #define DAVINCI_I2C_BASE 0x01C21000
37 #define DAVINCI_EMAC_CNTRL_REGS_BASE 0x01C80000
38 #define DAVINCI_EMAC_CNTRL_MOD_REGS_BASE 0x01C81000
39 #define DAVINCI_EMAC_CNTRL_RAM_BASE 0x01C82000
40 #define DAVINCI_EMAC_MDIO_REGS_BASE 0x01C84000
41 #define DAVINCI_MMCSD0_BASE 0x01E10000
42 #define DM355_MMCSD0_BASE 0x01E11000
43 #define DM355_MMCSD1_BASE 0x01E00000
45 static struct resource i2c_resources[] = {
47 .start = DAVINCI_I2C_BASE,
48 .end = DAVINCI_I2C_BASE + 0x40,
49 .flags = IORESOURCE_MEM,
52 .start = IRQ_I2C,
53 .flags = IORESOURCE_IRQ,
57 static struct platform_device davinci_i2c_device = {
58 .name = "i2c_davinci",
59 .id = 1,
60 .num_resources = ARRAY_SIZE(i2c_resources),
61 .resource = i2c_resources,
64 void __init davinci_init_i2c(struct davinci_i2c_platform_data *pdata)
66 if (cpu_is_davinci_dm644x())
67 davinci_cfg_reg(DM644X_I2C);
69 davinci_i2c_device.dev.platform_data = pdata;
70 (void) platform_device_register(&davinci_i2c_device);
73 #if defined(CONFIG_MMC_DAVINCI) || defined(CONFIG_MMC_DAVINCI_MODULE)
75 static u64 mmcsd0_dma_mask = DMA_32BIT_MASK;
77 static struct resource mmcsd0_resources[] = {
79 /* different on dm355 */
80 .start = DAVINCI_MMCSD0_BASE,
81 .end = DAVINCI_MMCSD0_BASE + SZ_4K - 1,
82 .flags = IORESOURCE_MEM,
84 /* IRQs: MMC/SD, then SDIO */
86 .start = IRQ_MMCINT,
87 .flags = IORESOURCE_IRQ,
88 }, {
89 /* different on dm355 */
90 .start = IRQ_SDIOINT,
91 .flags = IORESOURCE_IRQ,
93 /* DMA channels: RX, then TX */
95 .start = DAVINCI_DMA_MMCRXEVT,
96 .flags = IORESOURCE_DMA,
97 }, {
98 .start = DAVINCI_DMA_MMCTXEVT,
99 .flags = IORESOURCE_DMA,
103 static struct platform_device davinci_mmcsd0_device = {
104 .name = "davinci_mmc",
105 .id = 0,
106 .dev = {
107 .dma_mask = &mmcsd0_dma_mask,
108 .coherent_dma_mask = DMA_32BIT_MASK,
110 .num_resources = ARRAY_SIZE(mmcsd0_resources),
111 .resource = mmcsd0_resources,
114 static u64 mmcsd1_dma_mask = DMA_32BIT_MASK;
116 static struct resource mmcsd1_resources[] = {
118 .start = DM355_MMCSD1_BASE,
119 .end = DM355_MMCSD1_BASE + SZ_4K - 1,
120 .flags = IORESOURCE_MEM,
122 /* IRQs: MMC/SD, then SDIO */
124 .start = IRQ_DM355_MMCINT1,
125 .flags = IORESOURCE_IRQ,
126 }, {
127 .start = IRQ_DM355_SDIOINT1,
128 .flags = IORESOURCE_IRQ,
130 /* DMA channels: RX, then TX */
132 .start = 30, /* rx */
133 .flags = IORESOURCE_DMA,
134 }, {
135 .start = 31, /* tx */
136 .flags = IORESOURCE_DMA,
140 static struct platform_device davinci_mmcsd1_device = {
141 .name = "davinci_mmc",
142 .id = 1,
143 .dev = {
144 .dma_mask = &mmcsd1_dma_mask,
145 .coherent_dma_mask = DMA_32BIT_MASK,
147 .num_resources = ARRAY_SIZE(mmcsd1_resources),
148 .resource = mmcsd1_resources,
152 void __init davinci_setup_mmc(int module, struct davinci_mmc_config *config)
154 struct platform_device *pdev = NULL;
156 if (WARN_ON(cpu_is_davinci_dm646x()))
157 return;
159 /* REVISIT: update PINMUX, ARM_IRQMUX, and EDMA_EVTMUX here too;
160 * for example if MMCSD1 is used for SDIO, maybe DAT2 is unused.
162 * FIXME dm6441 (no MMC/SD), dm357 (one), and dm335 (two) are
163 * not handled right here ...
165 switch (module) {
166 case 1:
167 if (!cpu_is_davinci_dm355())
168 break;
170 /* REVISIT we may not need all these pins if e.g. this
171 * is a hard-wired SDIO device...
173 davinci_cfg_reg(DM355_SD1_CMD);
174 davinci_cfg_reg(DM355_SD1_CLK);
175 davinci_cfg_reg(DM355_SD1_DATA0);
176 davinci_cfg_reg(DM355_SD1_DATA1);
177 davinci_cfg_reg(DM355_SD1_DATA2);
178 davinci_cfg_reg(DM355_SD1_DATA3);
180 pdev = &davinci_mmcsd1_device;
181 break;
182 case 0:
183 if (cpu_is_davinci_dm355()) {
184 mmcsd0_resources[0].start = DM355_MMCSD0_BASE;
185 mmcsd0_resources[0].end = DM355_MMCSD0_BASE + SZ_4K - 1;
186 mmcsd0_resources[2].start = IRQ_DM355_SDIOINT0;
188 /* expose all 6 MMC0 signals: CLK, CMD, DATA[0..3] */
189 davinci_cfg_reg(DM355_MMCSD0);
191 /* enable RX EDMA */
192 davinci_cfg_reg(DM355_EVT26_MMC0_RX);
195 else if (cpu_is_davinci_dm644x()) {
196 /* REVISIT: should this be in board-init code? */
197 void __iomem *base =
198 IO_ADDRESS(DAVINCI_SYSTEM_MODULE_BASE);
200 /* Power-on 3.3V IO cells */
201 __raw_writel(0, base + DM64XX_VDD3P3V_PWDN);
202 /*Set up the pull regiter for MMC */
203 davinci_cfg_reg(DM644X_MSTK);
206 pdev = &davinci_mmcsd0_device;
207 break;
210 if (WARN_ON(!pdev))
211 return;
213 pdev->dev.platform_data = config;
214 platform_device_register(pdev);
217 #else
219 void __init davinci_setup_mmc(int module, struct davinci_mmc_config *config)
223 #endif
225 /*-------------------------------------------------------------------------*/
227 static struct resource wdt_resources[] = {
229 .start = 0x01c21c00,
230 .end = 0x01c21fff,
231 .flags = IORESOURCE_MEM,
235 static struct platform_device davinci_wdt_device = {
236 .name = "watchdog",
237 .id = -1,
238 .num_resources = ARRAY_SIZE(wdt_resources),
239 .resource = wdt_resources,
242 static void davinci_init_wdt(void)
244 platform_device_register(&davinci_wdt_device);
247 /*-------------------------------------------------------------------------*/
249 #if defined(CONFIG_TI_DAVINCI_EMAC) || defined(CONFIG_TI_DAVINCI_EMAC_MODULE)
251 static struct resource emac_resources[] = {
253 .start = DAVINCI_EMAC_CNTRL_REGS_BASE,
254 .end = DAVINCI_EMAC_CNTRL_REGS_BASE + 0x0fff,
255 .flags = IORESOURCE_MEM,
256 .name = "ctrl_regs"
259 .start = DAVINCI_EMAC_CNTRL_MOD_REGS_BASE,
260 .end = DAVINCI_EMAC_CNTRL_MOD_REGS_BASE + 0x0fff,
261 .flags = IORESOURCE_MEM,
262 .name = "ctrl_module_regs"
265 .start = DAVINCI_EMAC_CNTRL_RAM_BASE,
266 .end = DAVINCI_EMAC_CNTRL_RAM_BASE + 0x1fff,
267 .flags = IORESOURCE_MEM,
268 .name = "ctrl_ram"
271 .start = DAVINCI_EMAC_MDIO_REGS_BASE,
272 .end = DAVINCI_EMAC_MDIO_REGS_BASE + 0x07ff,
273 .flags = IORESOURCE_MEM,
274 .name = "mdio_regs"
277 .start = IRQ_EMACINT,
278 .end = IRQ_EMACINT,
279 .flags = IORESOURCE_IRQ,
283 static struct emac_platform_data emac_pdata;
285 static struct platform_device davinci_emac_device = {
286 .name = "davinci_emac",
287 .id = 1,
288 .num_resources = ARRAY_SIZE(emac_resources),
289 .resource = emac_resources,
290 .dev = {
291 .platform_data = &emac_pdata,
295 static struct resource dm646x_emac_resources[] = {
297 .start = DAVINCI_EMAC_CNTRL_REGS_BASE,
298 .end = DAVINCI_EMAC_CNTRL_REGS_BASE + 0x0fff,
299 .flags = IORESOURCE_MEM,
300 .name = "ctrl_regs"
303 .start = DAVINCI_EMAC_CNTRL_MOD_REGS_BASE,
304 .end = DAVINCI_EMAC_CNTRL_MOD_REGS_BASE + 0x0fff,
305 .flags = IORESOURCE_MEM,
306 .name = "ctrl_module_regs"
309 .start = DAVINCI_EMAC_CNTRL_RAM_BASE,
310 .end = DAVINCI_EMAC_CNTRL_RAM_BASE + 0x1fff,
311 .flags = IORESOURCE_MEM,
312 .name = "ctrl_ram"
315 .start = DAVINCI_EMAC_MDIO_REGS_BASE,
316 .end = DAVINCI_EMAC_MDIO_REGS_BASE + 0x07ff,
317 .flags = IORESOURCE_MEM,
318 .name = "mdio_regs"
321 .start = IRQ_DM646X_EMACRXTHINT,
322 .end = IRQ_DM646X_EMACRXTHINT,
323 .flags = IORESOURCE_IRQ,
326 .start = IRQ_DM646X_EMACRXINT,
327 .end = IRQ_DM646X_EMACRXINT,
328 .flags = IORESOURCE_IRQ,
331 .start = IRQ_DM646X_EMACTXINT,
332 .end = IRQ_DM646X_EMACTXINT,
333 .flags = IORESOURCE_IRQ,
336 .start = IRQ_DM646X_EMACMISCINT,
337 .end = IRQ_DM646X_EMACMISCINT,
338 .flags = IORESOURCE_IRQ,
342 static struct platform_device dm646x_emac_device = {
343 .name = "davinci_emac",
344 .id = 1,
345 .num_resources = ARRAY_SIZE(dm646x_emac_resources),
346 .resource = dm646x_emac_resources,
347 .dev = {
348 .platform_data = &emac_pdata,
352 /* Get Ethernet address from kernel boot params */
353 static u8 davinci_bootloader_mac_addr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
355 static int /*__init */ davinci_bootloader_mac_setup(char *str)
357 int i;
359 if (str == NULL)
360 return 0;
362 /* Conversion of a MAC address from a string (AA:BB:CC:DD:EE:FF)
363 * to a 6 bytes array. */
364 for (i = 0; i < 6; i++)
365 davinci_bootloader_mac_addr[i] =
366 simple_strtol(&str[i*3], (char **)NULL, 16);
368 return 1;
370 /* Get MAC address from kernel boot parameter eth=AA:BB:CC:DD:EE:FF */
371 __setup("eth=", davinci_bootloader_mac_setup);
373 void davinci_init_emac(char *mac_addr)
375 DECLARE_MAC_BUF(buf);
377 if (!(cpu_is_davinci_dm644x() || cpu_is_davinci_dm646x()))
378 return;
380 /* if valid MAC exists, don't re-register */
381 if (is_valid_ether_addr(emac_pdata.mac_addr))
382 return;
384 if (mac_addr && is_valid_ether_addr(mac_addr))
385 memcpy(emac_pdata.mac_addr, mac_addr, 6);
386 else if (is_valid_ether_addr(davinci_bootloader_mac_addr))
387 memcpy(emac_pdata.mac_addr, davinci_bootloader_mac_addr, 6);
388 else {
389 /* Use random MAC if none passed */
390 random_ether_addr(emac_pdata.mac_addr);
392 printk(KERN_WARNING "%s: using random MAC addr: %s\n",
393 __func__, print_mac(buf, emac_pdata.mac_addr));
395 if ((cpu_is_davinci_dm644x()))
396 (void) platform_device_register(&davinci_emac_device);
397 else
398 (void) platform_device_register(&dm646x_emac_device);
401 #else
403 void davinci_init_emac(char *unused) {}
405 #endif
407 /*-------------------------------------------------------------------------*/
409 static int __init davinci_init_devices(void)
411 /* please keep these calls, and their implementations above,
412 * in alphabetical order so they're easier to sort through.
414 davinci_init_wdt();
416 return 0;
418 arch_initcall(davinci_init_devices);
420 static int __init davinci_init_devices_late(void)
422 /* This is a backup call in case board code did not call init func */
423 davinci_init_emac(NULL);
425 return 0;
427 late_initcall(davinci_init_devices_late);