4 * Maintained by Kumar Gala (see MAINTAINERS for contact information)
6 * 2006 (c) MontaVista Software, Inc.
7 * Vitaly Bordug <vbordug@ru.mvista.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/errno.h>
19 #include <linux/major.h>
20 #include <linux/delay.h>
21 #include <linux/irq.h>
22 #include <linux/module.h>
23 #include <linux/device.h>
24 #include <linux/platform_device.h>
25 #include <linux/fsl_devices.h>
26 #include <linux/fs_enet_pd.h>
27 #include <linux/fs_uart_pd.h>
29 #include <asm/system.h>
30 #include <asm/atomic.h>
35 #include <sysdev/fsl_soc.h>
36 #include <mm/mmu_decl.h>
39 static phys_addr_t immrbase = -1;
41 phys_addr_t get_immrbase(void)
43 struct device_node *soc;
48 soc = of_find_node_by_type(NULL, "soc");
51 const void *prop = get_property(soc, "reg", &size);
54 immrbase = of_translate_address(soc, prop);
61 EXPORT_SYMBOL(get_immrbase);
65 static u32 brgfreq = -1;
69 struct device_node *node;
74 node = of_find_node_by_type(NULL, "cpm");
77 const unsigned int *prop = get_property(node, "brg-frequency",
88 EXPORT_SYMBOL(get_brgfreq);
90 static u32 fs_baudrate = -1;
92 u32 get_baudrate(void)
94 struct device_node *node;
96 if (fs_baudrate != -1)
99 node = of_find_node_by_type(NULL, "serial");
102 const unsigned int *prop = get_property(node, "current-speed",
113 EXPORT_SYMBOL(get_baudrate);
114 #endif /* CONFIG_CPM2 */
116 static int __init gfar_mdio_of_init(void)
118 struct device_node *np;
120 struct platform_device *mdio_dev;
124 for (np = NULL, i = 0;
125 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
128 struct device_node *child = NULL;
129 struct gianfar_mdio_data mdio_data;
131 memset(&res, 0, sizeof(res));
132 memset(&mdio_data, 0, sizeof(mdio_data));
134 ret = of_address_to_resource(np, 0, &res);
139 platform_device_register_simple("fsl-gianfar_mdio",
141 if (IS_ERR(mdio_dev)) {
142 ret = PTR_ERR(mdio_dev);
146 for (k = 0; k < 32; k++)
147 mdio_data.irq[k] = -1;
149 while ((child = of_get_next_child(np, child)) != NULL) {
150 int irq = irq_of_parse_and_map(child, 0);
152 const u32 *id = get_property(child, "reg", NULL);
153 mdio_data.irq[*id] = irq;
158 platform_device_add_data(mdio_dev, &mdio_data,
159 sizeof(struct gianfar_mdio_data));
167 platform_device_unregister(mdio_dev);
172 arch_initcall(gfar_mdio_of_init);
174 static const char *gfar_tx_intr = "tx";
175 static const char *gfar_rx_intr = "rx";
176 static const char *gfar_err_intr = "error";
178 static int __init gfar_of_init(void)
180 struct device_node *np;
182 struct platform_device *gfar_dev;
186 for (np = NULL, i = 0;
187 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
189 struct resource r[4];
190 struct device_node *phy, *mdio;
191 struct gianfar_platform_data gfar_data;
192 const unsigned int *id;
194 const void *mac_addr;
198 memset(r, 0, sizeof(r));
199 memset(&gfar_data, 0, sizeof(gfar_data));
201 ret = of_address_to_resource(np, 0, &r[0]);
205 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
206 r[1].flags = IORESOURCE_IRQ;
208 model = get_property(np, "model", NULL);
210 /* If we aren't the FEC we have multiple interrupts */
211 if (model && strcasecmp(model, "FEC")) {
212 r[1].name = gfar_tx_intr;
214 r[2].name = gfar_rx_intr;
215 r[2].start = r[2].end = irq_of_parse_and_map(np, 1);
216 r[2].flags = IORESOURCE_IRQ;
218 r[3].name = gfar_err_intr;
219 r[3].start = r[3].end = irq_of_parse_and_map(np, 2);
220 r[3].flags = IORESOURCE_IRQ;
226 platform_device_register_simple("fsl-gianfar", i, &r[0],
229 if (IS_ERR(gfar_dev)) {
230 ret = PTR_ERR(gfar_dev);
234 mac_addr = get_property(np, "local-mac-address", NULL);
235 if (mac_addr == NULL)
236 mac_addr = get_property(np, "mac-address", NULL);
237 if (mac_addr == NULL) {
239 mac_addr = get_property(np, "address", NULL);
243 memcpy(gfar_data.mac_addr, mac_addr, 6);
245 if (model && !strcasecmp(model, "TSEC"))
246 gfar_data.device_flags =
247 FSL_GIANFAR_DEV_HAS_GIGABIT |
248 FSL_GIANFAR_DEV_HAS_COALESCE |
249 FSL_GIANFAR_DEV_HAS_RMON |
250 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
251 if (model && !strcasecmp(model, "eTSEC"))
252 gfar_data.device_flags =
253 FSL_GIANFAR_DEV_HAS_GIGABIT |
254 FSL_GIANFAR_DEV_HAS_COALESCE |
255 FSL_GIANFAR_DEV_HAS_RMON |
256 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
257 FSL_GIANFAR_DEV_HAS_CSUM |
258 FSL_GIANFAR_DEV_HAS_VLAN |
259 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
261 ph = get_property(np, "phy-handle", NULL);
262 phy = of_find_node_by_phandle(*ph);
269 mdio = of_get_parent(phy);
271 id = get_property(phy, "reg", NULL);
272 ret = of_address_to_resource(mdio, 0, &res);
279 gfar_data.phy_id = *id;
280 gfar_data.bus_id = res.start;
286 platform_device_add_data(gfar_dev, &gfar_data,
288 gianfar_platform_data));
296 platform_device_unregister(gfar_dev);
301 arch_initcall(gfar_of_init);
303 static int __init fsl_i2c_of_init(void)
305 struct device_node *np;
307 struct platform_device *i2c_dev;
310 for (np = NULL, i = 0;
311 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
313 struct resource r[2];
314 struct fsl_i2c_platform_data i2c_data;
315 const unsigned char *flags = NULL;
317 memset(&r, 0, sizeof(r));
318 memset(&i2c_data, 0, sizeof(i2c_data));
320 ret = of_address_to_resource(np, 0, &r[0]);
324 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
325 r[1].flags = IORESOURCE_IRQ;
327 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
328 if (IS_ERR(i2c_dev)) {
329 ret = PTR_ERR(i2c_dev);
333 i2c_data.device_flags = 0;
334 flags = get_property(np, "dfsrr", NULL);
336 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
338 flags = get_property(np, "fsl5200-clocking", NULL);
340 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
343 platform_device_add_data(i2c_dev, &i2c_data,
345 fsl_i2c_platform_data));
353 platform_device_unregister(i2c_dev);
358 arch_initcall(fsl_i2c_of_init);
360 #ifdef CONFIG_PPC_83xx
361 static int __init mpc83xx_wdt_init(void)
364 struct device_node *soc, *np;
365 struct platform_device *dev;
366 const unsigned int *freq;
369 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
376 soc = of_find_node_by_type(NULL, "soc");
383 freq = get_property(soc, "bus-frequency", NULL);
389 memset(&r, 0, sizeof(r));
391 ret = of_address_to_resource(np, 0, &r);
395 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
401 ret = platform_device_add_data(dev, freq, sizeof(int));
411 platform_device_unregister(dev);
420 arch_initcall(mpc83xx_wdt_init);
423 static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
426 return FSL_USB2_PHY_NONE;
427 if (!strcasecmp(phy_type, "ulpi"))
428 return FSL_USB2_PHY_ULPI;
429 if (!strcasecmp(phy_type, "utmi"))
430 return FSL_USB2_PHY_UTMI;
431 if (!strcasecmp(phy_type, "utmi_wide"))
432 return FSL_USB2_PHY_UTMI_WIDE;
433 if (!strcasecmp(phy_type, "serial"))
434 return FSL_USB2_PHY_SERIAL;
436 return FSL_USB2_PHY_NONE;
439 static int __init fsl_usb_of_init(void)
441 struct device_node *np;
443 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL;
446 for (np = NULL, i = 0;
447 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
449 struct resource r[2];
450 struct fsl_usb2_platform_data usb_data;
451 const unsigned char *prop = NULL;
453 memset(&r, 0, sizeof(r));
454 memset(&usb_data, 0, sizeof(usb_data));
456 ret = of_address_to_resource(np, 0, &r[0]);
460 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
461 r[1].flags = IORESOURCE_IRQ;
464 platform_device_register_simple("fsl-ehci", i, r, 2);
465 if (IS_ERR(usb_dev_mph)) {
466 ret = PTR_ERR(usb_dev_mph);
470 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
471 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
473 usb_data.operating_mode = FSL_USB2_MPH_HOST;
475 prop = get_property(np, "port0", NULL);
477 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
479 prop = get_property(np, "port1", NULL);
481 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
483 prop = get_property(np, "phy_type", NULL);
484 usb_data.phy_mode = determine_usb_phy(prop);
487 platform_device_add_data(usb_dev_mph, &usb_data,
489 fsl_usb2_platform_data));
495 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
497 struct resource r[2];
498 struct fsl_usb2_platform_data usb_data;
499 const unsigned char *prop = NULL;
501 memset(&r, 0, sizeof(r));
502 memset(&usb_data, 0, sizeof(usb_data));
504 ret = of_address_to_resource(np, 0, &r[0]);
508 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
509 r[1].flags = IORESOURCE_IRQ;
512 platform_device_register_simple("fsl-ehci", i, r, 2);
513 if (IS_ERR(usb_dev_dr)) {
514 ret = PTR_ERR(usb_dev_dr);
518 usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
519 usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
521 usb_data.operating_mode = FSL_USB2_DR_HOST;
523 prop = get_property(np, "phy_type", NULL);
524 usb_data.phy_mode = determine_usb_phy(prop);
527 platform_device_add_data(usb_dev_dr, &usb_data,
529 fsl_usb2_platform_data));
537 platform_device_unregister(usb_dev_dr);
540 platform_device_unregister(usb_dev_mph);
545 arch_initcall(fsl_usb_of_init);
549 static const char fcc_regs[] = "fcc_regs";
550 static const char fcc_regs_c[] = "fcc_regs_c";
551 static const char fcc_pram[] = "fcc_pram";
552 static char bus_id[9][BUS_ID_SIZE];
554 static int __init fs_enet_of_init(void)
556 struct device_node *np;
558 struct platform_device *fs_enet_dev;
562 for (np = NULL, i = 0;
563 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
565 struct resource r[4];
566 struct device_node *phy, *mdio;
567 struct fs_platform_info fs_enet_data;
568 const unsigned int *id, *phy_addr;
569 const void *mac_addr;
573 memset(r, 0, sizeof(r));
574 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
576 ret = of_address_to_resource(np, 0, &r[0]);
579 r[0].name = fcc_regs;
581 ret = of_address_to_resource(np, 1, &r[1]);
584 r[1].name = fcc_pram;
586 ret = of_address_to_resource(np, 2, &r[2]);
589 r[2].name = fcc_regs_c;
591 r[3].start = r[3].end = irq_of_parse_and_map(np, 0);
592 r[3].flags = IORESOURCE_IRQ;
595 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
597 if (IS_ERR(fs_enet_dev)) {
598 ret = PTR_ERR(fs_enet_dev);
602 model = get_property(np, "model", NULL);
608 mac_addr = get_property(np, "mac-address", NULL);
609 memcpy(fs_enet_data.macaddr, mac_addr, 6);
611 ph = get_property(np, "phy-handle", NULL);
612 phy = of_find_node_by_phandle(*ph);
619 phy_addr = get_property(phy, "reg", NULL);
620 fs_enet_data.phy_addr = *phy_addr;
622 id = get_property(np, "device-id", NULL);
623 fs_enet_data.fs_no = *id;
625 mdio = of_get_parent(phy);
626 ret = of_address_to_resource(mdio, 0, &res);
633 if (strstr(model, "FCC")) {
634 int fcc_index = fs_get_fcc_index(*id);
636 fs_enet_data.dpram_offset = (u32)cpm2_immr->im_dprambase;
637 fs_enet_data.rx_ring = 32;
638 fs_enet_data.tx_ring = 32;
639 fs_enet_data.rx_copybreak = 240;
640 fs_enet_data.use_napi = 0;
641 fs_enet_data.napi_weight = 17;
642 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
643 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
644 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
646 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
647 (u32)res.start, fs_enet_data.phy_addr);
648 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
654 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
663 platform_device_unregister(fs_enet_dev);
668 arch_initcall(fs_enet_of_init);
670 static const char scc_regs[] = "regs";
671 static const char scc_pram[] = "pram";
673 static int __init cpm_uart_of_init(void)
675 struct device_node *np;
677 struct platform_device *cpm_uart_dev;
680 for (np = NULL, i = 0;
681 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
683 struct resource r[3];
684 struct fs_uart_platform_info cpm_uart_data;
687 memset(r, 0, sizeof(r));
688 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
690 ret = of_address_to_resource(np, 0, &r[0]);
694 r[0].name = scc_regs;
696 ret = of_address_to_resource(np, 1, &r[1]);
699 r[1].name = scc_pram;
701 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
702 r[2].flags = IORESOURCE_IRQ;
705 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
707 if (IS_ERR(cpm_uart_dev)) {
708 ret = PTR_ERR(cpm_uart_dev);
712 id = get_property(np, "device-id", NULL);
713 cpm_uart_data.fs_no = *id;
714 cpm_uart_data.uart_clk = ppc_proc_freq;
716 cpm_uart_data.tx_num_fifo = 4;
717 cpm_uart_data.tx_buf_size = 32;
718 cpm_uart_data.rx_num_fifo = 4;
719 cpm_uart_data.rx_buf_size = 32;
722 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
724 fs_uart_platform_info));
732 platform_device_unregister(cpm_uart_dev);
737 arch_initcall(cpm_uart_of_init);
738 #endif /* CONFIG_CPM2 */