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/of_platform.h>
26 #include <linux/phy.h>
27 #include <linux/phy_fixed.h>
28 #include <linux/spi/spi.h>
29 #include <linux/fsl_devices.h>
30 #include <linux/fs_enet_pd.h>
31 #include <linux/fs_uart_pd.h>
33 #include <asm/system.h>
34 #include <asm/atomic.h>
39 #include <sysdev/fsl_soc.h>
40 #include <mm/mmu_decl.h>
43 extern void init_fcc_ioports(struct fs_platform_info*);
44 extern void init_fec_ioports(struct fs_platform_info*);
45 extern void init_smc_ioports(struct fs_uart_platform_info*);
46 static phys_addr_t immrbase = -1;
48 phys_addr_t get_immrbase(void)
50 struct device_node *soc;
55 soc = of_find_node_by_type(NULL, "soc");
59 const u32 *prop = of_get_property(soc, "#address-cells", &size);
61 if (prop && size == 4)
66 prop = of_get_property(soc, "ranges", &size);
68 immrbase = of_translate_address(soc, prop + naddr);
76 EXPORT_SYMBOL(get_immrbase);
78 #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
80 static u32 brgfreq = -1;
84 struct device_node *node;
85 const unsigned int *prop;
91 node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
93 prop = of_get_property(node, "clock-frequency", &size);
94 if (prop && size == 4)
101 /* Legacy device binding -- will go away when no users are left. */
102 node = of_find_node_by_type(NULL, "cpm");
104 node = of_find_compatible_node(NULL, NULL, "fsl,qe");
106 node = of_find_node_by_type(NULL, "qe");
109 prop = of_get_property(node, "brg-frequency", &size);
110 if (prop && size == 4)
113 if (brgfreq == -1 || brgfreq == 0) {
114 prop = of_get_property(node, "bus-frequency", &size);
115 if (prop && size == 4)
124 EXPORT_SYMBOL(get_brgfreq);
126 static u32 fs_baudrate = -1;
128 u32 get_baudrate(void)
130 struct device_node *node;
132 if (fs_baudrate != -1)
135 node = of_find_node_by_type(NULL, "serial");
138 const unsigned int *prop = of_get_property(node,
139 "current-speed", &size);
149 EXPORT_SYMBOL(get_baudrate);
150 #endif /* CONFIG_CPM2 */
152 #ifdef CONFIG_FIXED_PHY
153 static int __init of_add_fixed_phys(void)
156 struct device_node *np;
158 struct fixed_phy_status status = {};
160 for_each_node_by_name(np, "ethernet") {
161 fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
166 status.duplex = fixed_link[1];
167 status.speed = fixed_link[2];
168 status.pause = fixed_link[3];
169 status.asym_pause = fixed_link[4];
171 ret = fixed_phy_add(PHY_POLL, fixed_link[0], &status);
180 arch_initcall(of_add_fixed_phys);
181 #endif /* CONFIG_FIXED_PHY */
183 static int __init gfar_mdio_of_init(void)
185 struct device_node *np = NULL;
186 struct platform_device *mdio_dev;
190 np = of_find_compatible_node(np, NULL, "fsl,gianfar-mdio");
192 /* try the deprecated version */
194 np = of_find_compatible_node(np, "mdio", "gianfar");
198 struct device_node *child = NULL;
199 struct gianfar_mdio_data mdio_data;
201 memset(&res, 0, sizeof(res));
202 memset(&mdio_data, 0, sizeof(mdio_data));
204 ret = of_address_to_resource(np, 0, &res);
209 platform_device_register_simple("fsl-gianfar_mdio",
211 if (IS_ERR(mdio_dev)) {
212 ret = PTR_ERR(mdio_dev);
216 for (k = 0; k < 32; k++)
217 mdio_data.irq[k] = PHY_POLL;
219 while ((child = of_get_next_child(np, child)) != NULL) {
220 int irq = irq_of_parse_and_map(child, 0);
222 const u32 *id = of_get_property(child,
224 mdio_data.irq[*id] = irq;
229 platform_device_add_data(mdio_dev, &mdio_data,
230 sizeof(struct gianfar_mdio_data));
239 platform_device_unregister(mdio_dev);
245 arch_initcall(gfar_mdio_of_init);
247 static const char *gfar_tx_intr = "tx";
248 static const char *gfar_rx_intr = "rx";
249 static const char *gfar_err_intr = "error";
251 static int __init gfar_of_init(void)
253 struct device_node *np;
255 struct platform_device *gfar_dev;
259 for (np = NULL, i = 0;
260 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
262 struct resource r[4];
263 struct device_node *phy, *mdio;
264 struct gianfar_platform_data gfar_data;
265 const unsigned int *id;
268 const void *mac_addr;
272 memset(r, 0, sizeof(r));
273 memset(&gfar_data, 0, sizeof(gfar_data));
275 ret = of_address_to_resource(np, 0, &r[0]);
279 of_irq_to_resource(np, 0, &r[1]);
281 model = of_get_property(np, "model", NULL);
283 /* If we aren't the FEC we have multiple interrupts */
284 if (model && strcasecmp(model, "FEC")) {
285 r[1].name = gfar_tx_intr;
287 r[2].name = gfar_rx_intr;
288 of_irq_to_resource(np, 1, &r[2]);
290 r[3].name = gfar_err_intr;
291 of_irq_to_resource(np, 2, &r[3]);
297 platform_device_register_simple("fsl-gianfar", i, &r[0],
300 if (IS_ERR(gfar_dev)) {
301 ret = PTR_ERR(gfar_dev);
305 mac_addr = of_get_mac_address(np);
307 memcpy(gfar_data.mac_addr, mac_addr, 6);
309 if (model && !strcasecmp(model, "TSEC"))
310 gfar_data.device_flags =
311 FSL_GIANFAR_DEV_HAS_GIGABIT |
312 FSL_GIANFAR_DEV_HAS_COALESCE |
313 FSL_GIANFAR_DEV_HAS_RMON |
314 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
315 if (model && !strcasecmp(model, "eTSEC"))
316 gfar_data.device_flags =
317 FSL_GIANFAR_DEV_HAS_GIGABIT |
318 FSL_GIANFAR_DEV_HAS_COALESCE |
319 FSL_GIANFAR_DEV_HAS_RMON |
320 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
321 FSL_GIANFAR_DEV_HAS_CSUM |
322 FSL_GIANFAR_DEV_HAS_VLAN |
323 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
325 ctype = of_get_property(np, "phy-connection-type", NULL);
327 /* We only care about rgmii-id. The rest are autodetected */
328 if (ctype && !strcmp(ctype, "rgmii-id"))
329 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
331 gfar_data.interface = PHY_INTERFACE_MODE_MII;
333 ph = of_get_property(np, "phy-handle", NULL);
337 fixed_link = (u32 *)of_get_property(np, "fixed-link",
344 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "0");
345 gfar_data.phy_id = fixed_link[0];
347 phy = of_find_node_by_phandle(*ph);
354 mdio = of_get_parent(phy);
356 id = of_get_property(phy, "reg", NULL);
357 ret = of_address_to_resource(mdio, 0, &res);
364 gfar_data.phy_id = *id;
365 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%x",
373 platform_device_add_data(gfar_dev, &gfar_data,
375 gianfar_platform_data));
383 platform_device_unregister(gfar_dev);
388 arch_initcall(gfar_of_init);
390 #ifdef CONFIG_I2C_BOARDINFO
391 #include <linux/i2c.h>
392 struct i2c_driver_device {
398 static struct i2c_driver_device i2c_devices[] __initdata = {
399 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
400 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
401 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
402 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
403 {"dallas,ds1307", "rtc-ds1307", "ds1307",},
404 {"dallas,ds1337", "rtc-ds1307", "ds1337",},
405 {"dallas,ds1338", "rtc-ds1307", "ds1338",},
406 {"dallas,ds1339", "rtc-ds1307", "ds1339",},
407 {"dallas,ds1340", "rtc-ds1307", "ds1340",},
408 {"stm,m41t00", "rtc-ds1307", "m41t00"},
409 {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",},
412 static int __init of_find_i2c_driver(struct device_node *node,
413 struct i2c_board_info *info)
417 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
418 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
420 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
421 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
422 strlcpy(info->type, i2c_devices[i].i2c_type,
423 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
430 static void __init of_register_i2c_devices(struct device_node *adap_node,
433 struct device_node *node = NULL;
435 while ((node = of_get_next_child(adap_node, node))) {
436 struct i2c_board_info info = {};
440 addr = of_get_property(node, "reg", &len);
441 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
442 printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
446 info.irq = irq_of_parse_and_map(node, 0);
447 if (info.irq == NO_IRQ)
450 if (of_find_i2c_driver(node, &info) < 0)
455 i2c_register_board_info(bus_num, &info, 1);
459 static int __init fsl_i2c_of_init(void)
461 struct device_node *np;
463 struct platform_device *i2c_dev;
466 for_each_compatible_node(np, NULL, "fsl-i2c") {
467 struct resource r[2];
468 struct fsl_i2c_platform_data i2c_data;
469 const unsigned char *flags = NULL;
471 memset(&r, 0, sizeof(r));
472 memset(&i2c_data, 0, sizeof(i2c_data));
474 ret = of_address_to_resource(np, 0, &r[0]);
478 of_irq_to_resource(np, 0, &r[1]);
480 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
481 if (IS_ERR(i2c_dev)) {
482 ret = PTR_ERR(i2c_dev);
486 i2c_data.device_flags = 0;
487 flags = of_get_property(np, "dfsrr", NULL);
489 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
491 flags = of_get_property(np, "fsl5200-clocking", NULL);
493 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
496 platform_device_add_data(i2c_dev, &i2c_data,
498 fsl_i2c_platform_data));
502 of_register_i2c_devices(np, i++);
508 platform_device_unregister(i2c_dev);
513 arch_initcall(fsl_i2c_of_init);
516 #ifdef CONFIG_PPC_83xx
517 static int __init mpc83xx_wdt_init(void)
520 struct device_node *soc, *np;
521 struct platform_device *dev;
522 const unsigned int *freq;
525 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
532 soc = of_find_node_by_type(NULL, "soc");
539 freq = of_get_property(soc, "bus-frequency", NULL);
545 memset(&r, 0, sizeof(r));
547 ret = of_address_to_resource(np, 0, &r);
551 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
557 ret = platform_device_add_data(dev, freq, sizeof(int));
567 platform_device_unregister(dev);
576 arch_initcall(mpc83xx_wdt_init);
579 static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
582 return FSL_USB2_PHY_NONE;
583 if (!strcasecmp(phy_type, "ulpi"))
584 return FSL_USB2_PHY_ULPI;
585 if (!strcasecmp(phy_type, "utmi"))
586 return FSL_USB2_PHY_UTMI;
587 if (!strcasecmp(phy_type, "utmi_wide"))
588 return FSL_USB2_PHY_UTMI_WIDE;
589 if (!strcasecmp(phy_type, "serial"))
590 return FSL_USB2_PHY_SERIAL;
592 return FSL_USB2_PHY_NONE;
595 static int __init fsl_usb_of_init(void)
597 struct device_node *np;
599 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
600 *usb_dev_dr_client = NULL;
603 for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
604 struct resource r[2];
605 struct fsl_usb2_platform_data usb_data;
606 const unsigned char *prop = NULL;
608 memset(&r, 0, sizeof(r));
609 memset(&usb_data, 0, sizeof(usb_data));
611 ret = of_address_to_resource(np, 0, &r[0]);
615 of_irq_to_resource(np, 0, &r[1]);
618 platform_device_register_simple("fsl-ehci", i, r, 2);
619 if (IS_ERR(usb_dev_mph)) {
620 ret = PTR_ERR(usb_dev_mph);
624 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
625 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
627 usb_data.operating_mode = FSL_USB2_MPH_HOST;
629 prop = of_get_property(np, "port0", NULL);
631 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
633 prop = of_get_property(np, "port1", NULL);
635 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
637 prop = of_get_property(np, "phy_type", NULL);
638 usb_data.phy_mode = determine_usb_phy(prop);
641 platform_device_add_data(usb_dev_mph, &usb_data,
643 fsl_usb2_platform_data));
649 for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
650 struct resource r[2];
651 struct fsl_usb2_platform_data usb_data;
652 const unsigned char *prop = NULL;
654 memset(&r, 0, sizeof(r));
655 memset(&usb_data, 0, sizeof(usb_data));
657 ret = of_address_to_resource(np, 0, &r[0]);
661 of_irq_to_resource(np, 0, &r[1]);
663 prop = of_get_property(np, "dr_mode", NULL);
665 if (!prop || !strcmp(prop, "host")) {
666 usb_data.operating_mode = FSL_USB2_DR_HOST;
667 usb_dev_dr_host = platform_device_register_simple(
668 "fsl-ehci", i, r, 2);
669 if (IS_ERR(usb_dev_dr_host)) {
670 ret = PTR_ERR(usb_dev_dr_host);
673 } else if (prop && !strcmp(prop, "peripheral")) {
674 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
675 usb_dev_dr_client = platform_device_register_simple(
676 "fsl-usb2-udc", i, r, 2);
677 if (IS_ERR(usb_dev_dr_client)) {
678 ret = PTR_ERR(usb_dev_dr_client);
681 } else if (prop && !strcmp(prop, "otg")) {
682 usb_data.operating_mode = FSL_USB2_DR_OTG;
683 usb_dev_dr_host = platform_device_register_simple(
684 "fsl-ehci", i, r, 2);
685 if (IS_ERR(usb_dev_dr_host)) {
686 ret = PTR_ERR(usb_dev_dr_host);
689 usb_dev_dr_client = platform_device_register_simple(
690 "fsl-usb2-udc", i, r, 2);
691 if (IS_ERR(usb_dev_dr_client)) {
692 ret = PTR_ERR(usb_dev_dr_client);
700 prop = of_get_property(np, "phy_type", NULL);
701 usb_data.phy_mode = determine_usb_phy(prop);
703 if (usb_dev_dr_host) {
704 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
705 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
706 dev.coherent_dma_mask;
707 if ((ret = platform_device_add_data(usb_dev_dr_host,
708 &usb_data, sizeof(struct
709 fsl_usb2_platform_data))))
712 if (usb_dev_dr_client) {
713 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
714 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
715 dev.coherent_dma_mask;
716 if ((ret = platform_device_add_data(usb_dev_dr_client,
717 &usb_data, sizeof(struct
718 fsl_usb2_platform_data))))
727 platform_device_unregister(usb_dev_dr_host);
728 if (usb_dev_dr_client)
729 platform_device_unregister(usb_dev_dr_client);
732 platform_device_unregister(usb_dev_mph);
737 arch_initcall(fsl_usb_of_init);
739 #ifndef CONFIG_PPC_CPM_NEW_BINDING
742 extern void init_scc_ioports(struct fs_uart_platform_info*);
744 static const char fcc_regs[] = "fcc_regs";
745 static const char fcc_regs_c[] = "fcc_regs_c";
746 static const char fcc_pram[] = "fcc_pram";
747 static char bus_id[9][BUS_ID_SIZE];
749 static int __init fs_enet_of_init(void)
751 struct device_node *np;
753 struct platform_device *fs_enet_dev;
757 for (np = NULL, i = 0;
758 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
760 struct resource r[4];
761 struct device_node *phy, *mdio;
762 struct fs_platform_info fs_enet_data;
763 const unsigned int *id, *phy_addr, *phy_irq;
764 const void *mac_addr;
768 memset(r, 0, sizeof(r));
769 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
771 ret = of_address_to_resource(np, 0, &r[0]);
774 r[0].name = fcc_regs;
776 ret = of_address_to_resource(np, 1, &r[1]);
779 r[1].name = fcc_pram;
781 ret = of_address_to_resource(np, 2, &r[2]);
784 r[2].name = fcc_regs_c;
785 fs_enet_data.fcc_regs_c = r[2].start;
787 of_irq_to_resource(np, 0, &r[3]);
790 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
792 if (IS_ERR(fs_enet_dev)) {
793 ret = PTR_ERR(fs_enet_dev);
797 model = of_get_property(np, "model", NULL);
803 mac_addr = of_get_mac_address(np);
805 memcpy(fs_enet_data.macaddr, mac_addr, 6);
807 ph = of_get_property(np, "phy-handle", NULL);
808 phy = of_find_node_by_phandle(*ph);
815 phy_addr = of_get_property(phy, "reg", NULL);
816 fs_enet_data.phy_addr = *phy_addr;
818 phy_irq = of_get_property(phy, "interrupts", NULL);
820 id = of_get_property(np, "device-id", NULL);
821 fs_enet_data.fs_no = *id;
822 strcpy(fs_enet_data.fs_type, model);
824 mdio = of_get_parent(phy);
825 ret = of_address_to_resource(mdio, 0, &res);
832 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
834 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
837 if (strstr(model, "FCC")) {
838 int fcc_index = *id - 1;
839 const unsigned char *mdio_bb_prop;
841 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
842 fs_enet_data.rx_ring = 32;
843 fs_enet_data.tx_ring = 32;
844 fs_enet_data.rx_copybreak = 240;
845 fs_enet_data.use_napi = 0;
846 fs_enet_data.napi_weight = 17;
847 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
848 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
849 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
851 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
852 (u32)res.start, fs_enet_data.phy_addr);
853 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
854 fs_enet_data.init_ioports = init_fcc_ioports;
856 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
858 struct platform_device *fs_enet_mdio_bb_dev;
859 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
861 fs_enet_mdio_bb_dev =
862 platform_device_register_simple("fsl-bb-mdio",
864 memset(&fs_enet_mdio_bb_data, 0,
865 sizeof(struct fs_mii_bb_platform_info));
866 fs_enet_mdio_bb_data.mdio_dat.bit =
868 fs_enet_mdio_bb_data.mdio_dir.bit =
870 fs_enet_mdio_bb_data.mdc_dat.bit =
872 fs_enet_mdio_bb_data.mdio_port =
874 fs_enet_mdio_bb_data.mdc_port =
876 fs_enet_mdio_bb_data.delay =
879 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
880 fs_enet_mdio_bb_data.irq[1] = -1;
881 fs_enet_mdio_bb_data.irq[2] = -1;
882 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
883 fs_enet_mdio_bb_data.irq[31] = -1;
885 fs_enet_mdio_bb_data.mdio_dat.offset =
886 (u32)&cpm2_immr->im_ioport.iop_pdatc;
887 fs_enet_mdio_bb_data.mdio_dir.offset =
888 (u32)&cpm2_immr->im_ioport.iop_pdirc;
889 fs_enet_mdio_bb_data.mdc_dat.offset =
890 (u32)&cpm2_immr->im_ioport.iop_pdatc;
892 ret = platform_device_add_data(
894 &fs_enet_mdio_bb_data,
895 sizeof(struct fs_mii_bb_platform_info));
903 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
913 platform_device_unregister(fs_enet_dev);
918 arch_initcall(fs_enet_of_init);
920 static const char scc_regs[] = "regs";
921 static const char scc_pram[] = "pram";
923 static int __init cpm_uart_of_init(void)
925 struct device_node *np;
927 struct platform_device *cpm_uart_dev;
930 for (np = NULL, i = 0;
931 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
933 struct resource r[3];
934 struct fs_uart_platform_info cpm_uart_data;
938 memset(r, 0, sizeof(r));
939 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
941 ret = of_address_to_resource(np, 0, &r[0]);
945 r[0].name = scc_regs;
947 ret = of_address_to_resource(np, 1, &r[1]);
950 r[1].name = scc_pram;
952 of_irq_to_resource(np, 0, &r[2]);
955 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
957 if (IS_ERR(cpm_uart_dev)) {
958 ret = PTR_ERR(cpm_uart_dev);
962 id = of_get_property(np, "device-id", NULL);
963 cpm_uart_data.fs_no = *id;
965 model = of_get_property(np, "model", NULL);
966 strcpy(cpm_uart_data.fs_type, model);
968 cpm_uart_data.uart_clk = ppc_proc_freq;
970 cpm_uart_data.tx_num_fifo = 4;
971 cpm_uart_data.tx_buf_size = 32;
972 cpm_uart_data.rx_num_fifo = 4;
973 cpm_uart_data.rx_buf_size = 32;
974 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
976 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
980 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
982 fs_uart_platform_info));
990 platform_device_unregister(cpm_uart_dev);
995 arch_initcall(cpm_uart_of_init);
996 #endif /* CONFIG_CPM2 */
1000 extern void init_scc_ioports(struct fs_platform_info*);
1001 extern int platform_device_skip(const char *model, int id);
1003 static int __init fs_enet_mdio_of_init(void)
1005 struct device_node *np;
1007 struct platform_device *mdio_dev;
1008 struct resource res;
1011 for (np = NULL, i = 0;
1012 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
1014 struct fs_mii_fec_platform_info mdio_data;
1016 memset(&res, 0, sizeof(res));
1017 memset(&mdio_data, 0, sizeof(mdio_data));
1019 ret = of_address_to_resource(np, 0, &res);
1024 platform_device_register_simple("fsl-cpm-fec-mdio",
1025 res.start, &res, 1);
1026 if (IS_ERR(mdio_dev)) {
1027 ret = PTR_ERR(mdio_dev);
1031 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
1034 platform_device_add_data(mdio_dev, &mdio_data,
1035 sizeof(struct fs_mii_fec_platform_info));
1042 platform_device_unregister(mdio_dev);
1047 arch_initcall(fs_enet_mdio_of_init);
1049 static const char *enet_regs = "regs";
1050 static const char *enet_pram = "pram";
1051 static const char *enet_irq = "interrupt";
1052 static char bus_id[9][BUS_ID_SIZE];
1054 static int __init fs_enet_of_init(void)
1056 struct device_node *np;
1058 struct platform_device *fs_enet_dev = NULL;
1059 struct resource res;
1062 for (np = NULL, i = 0;
1063 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
1065 struct resource r[4];
1066 struct device_node *phy = NULL, *mdio = NULL;
1067 struct fs_platform_info fs_enet_data;
1068 const unsigned int *id;
1069 const unsigned int *phy_addr;
1070 const void *mac_addr;
1074 memset(r, 0, sizeof(r));
1075 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
1077 model = of_get_property(np, "model", NULL);
1078 if (model == NULL) {
1083 id = of_get_property(np, "device-id", NULL);
1084 fs_enet_data.fs_no = *id;
1086 if (platform_device_skip(model, *id))
1089 ret = of_address_to_resource(np, 0, &r[0]);
1092 r[0].name = enet_regs;
1094 mac_addr = of_get_mac_address(np);
1096 memcpy(fs_enet_data.macaddr, mac_addr, 6);
1098 ph = of_get_property(np, "phy-handle", NULL);
1100 phy = of_find_node_by_phandle(*ph);
1103 phy_addr = of_get_property(phy, "reg", NULL);
1104 fs_enet_data.phy_addr = *phy_addr;
1105 fs_enet_data.has_phy = 1;
1107 mdio = of_get_parent(phy);
1108 ret = of_address_to_resource(mdio, 0, &res);
1116 model = of_get_property(np, "model", NULL);
1117 strcpy(fs_enet_data.fs_type, model);
1119 if (strstr(model, "FEC")) {
1120 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1121 r[1].flags = IORESOURCE_IRQ;
1122 r[1].name = enet_irq;
1125 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1127 if (IS_ERR(fs_enet_dev)) {
1128 ret = PTR_ERR(fs_enet_dev);
1132 fs_enet_data.rx_ring = 128;
1133 fs_enet_data.tx_ring = 16;
1134 fs_enet_data.rx_copybreak = 240;
1135 fs_enet_data.use_napi = 1;
1136 fs_enet_data.napi_weight = 17;
1138 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1139 (u32)res.start, fs_enet_data.phy_addr);
1140 fs_enet_data.bus_id = (char*)&bus_id[i];
1141 fs_enet_data.init_ioports = init_fec_ioports;
1143 if (strstr(model, "SCC")) {
1144 ret = of_address_to_resource(np, 1, &r[1]);
1147 r[1].name = enet_pram;
1149 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1150 r[2].flags = IORESOURCE_IRQ;
1151 r[2].name = enet_irq;
1154 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1156 if (IS_ERR(fs_enet_dev)) {
1157 ret = PTR_ERR(fs_enet_dev);
1161 fs_enet_data.rx_ring = 64;
1162 fs_enet_data.tx_ring = 8;
1163 fs_enet_data.rx_copybreak = 240;
1164 fs_enet_data.use_napi = 1;
1165 fs_enet_data.napi_weight = 17;
1167 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1168 fs_enet_data.bus_id = (char*)&bus_id[i];
1169 fs_enet_data.init_ioports = init_scc_ioports;
1175 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1184 platform_device_unregister(fs_enet_dev);
1189 arch_initcall(fs_enet_of_init);
1191 static int __init fsl_pcmcia_of_init(void)
1193 struct device_node *np;
1195 * Register all the devices which type is "pcmcia"
1197 for_each_compatible_node(np, "pcmcia", "fsl,pq-pcmcia")
1198 of_platform_device_create(np, "m8xx-pcmcia", NULL);
1202 arch_initcall(fsl_pcmcia_of_init);
1204 static const char *smc_regs = "regs";
1205 static const char *smc_pram = "pram";
1207 static int __init cpm_smc_uart_of_init(void)
1209 struct device_node *np;
1211 struct platform_device *cpm_uart_dev;
1214 for (np = NULL, i = 0;
1215 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1217 struct resource r[3];
1218 struct fs_uart_platform_info cpm_uart_data;
1222 memset(r, 0, sizeof(r));
1223 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1225 ret = of_address_to_resource(np, 0, &r[0]);
1229 r[0].name = smc_regs;
1231 ret = of_address_to_resource(np, 1, &r[1]);
1234 r[1].name = smc_pram;
1236 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1237 r[2].flags = IORESOURCE_IRQ;
1240 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1242 if (IS_ERR(cpm_uart_dev)) {
1243 ret = PTR_ERR(cpm_uart_dev);
1247 model = of_get_property(np, "model", NULL);
1248 strcpy(cpm_uart_data.fs_type, model);
1250 id = of_get_property(np, "device-id", NULL);
1251 cpm_uart_data.fs_no = *id;
1252 cpm_uart_data.uart_clk = ppc_proc_freq;
1254 cpm_uart_data.tx_num_fifo = 4;
1255 cpm_uart_data.tx_buf_size = 32;
1256 cpm_uart_data.rx_num_fifo = 4;
1257 cpm_uart_data.rx_buf_size = 32;
1260 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1262 fs_uart_platform_info));
1270 platform_device_unregister(cpm_uart_dev);
1275 arch_initcall(cpm_smc_uart_of_init);
1277 #endif /* CONFIG_8xx */
1278 #endif /* CONFIG_PPC_CPM_NEW_BINDING */
1280 static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
1281 struct spi_board_info *board_infos,
1282 unsigned int num_board_infos,
1283 void (*activate_cs)(u8 cs, u8 polarity),
1284 void (*deactivate_cs)(u8 cs, u8 polarity))
1286 struct device_node *np;
1289 for_each_compatible_node(np, type, compatible) {
1293 struct resource res[2];
1294 struct platform_device *pdev;
1295 struct fsl_spi_platform_data pdata = {
1296 .activate_cs = activate_cs,
1297 .deactivate_cs = deactivate_cs,
1300 memset(res, 0, sizeof(res));
1302 pdata.sysclk = sysclk;
1304 prop = of_get_property(np, "reg", NULL);
1307 pdata.bus_num = *(u32 *)prop;
1309 prop = of_get_property(np, "cell-index", NULL);
1313 prop = of_get_property(np, "mode", NULL);
1314 if (prop && !strcmp(prop, "cpu-qe"))
1317 for (j = 0; j < num_board_infos; j++) {
1318 if (board_infos[j].bus_num == pdata.bus_num)
1319 pdata.max_chipselect++;
1322 if (!pdata.max_chipselect)
1325 ret = of_address_to_resource(np, 0, &res[0]);
1329 ret = of_irq_to_resource(np, 0, &res[1]);
1333 pdev = platform_device_alloc("mpc83xx_spi", i);
1337 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
1341 ret = platform_device_add_resources(pdev, res,
1346 ret = platform_device_add(pdev);
1352 platform_device_del(pdev);
1354 pr_err("%s: registration failed\n", np->full_name);
1362 int __init fsl_spi_init(struct spi_board_info *board_infos,
1363 unsigned int num_board_infos,
1364 void (*activate_cs)(u8 cs, u8 polarity),
1365 void (*deactivate_cs)(u8 cs, u8 polarity))
1370 #ifdef CONFIG_QUICC_ENGINE
1371 /* SPI controller is either clocked from QE or SoC clock */
1372 sysclk = get_brgfreq();
1375 struct device_node *np;
1379 np = of_find_node_by_type(NULL, "soc");
1383 freq = of_get_property(np, "clock-frequency", &size);
1384 if (!freq || size != sizeof(*freq) || *freq == 0) {
1385 freq = of_get_property(np, "bus-frequency", &size);
1386 if (!freq || size != sizeof(*freq) || *freq == 0) {
1396 ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
1397 num_board_infos, activate_cs, deactivate_cs);
1399 of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,
1400 num_board_infos, activate_cs, deactivate_cs);
1402 return spi_register_board_info(board_infos, num_board_infos);
1405 #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
1406 static __be32 __iomem *rstcr;
1408 static int __init setup_rstcr(void)
1410 struct device_node *np;
1411 np = of_find_node_by_name(NULL, "global-utilities");
1412 if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
1413 const u32 *prop = of_get_property(np, "reg", NULL);
1415 /* map reset control register
1416 * 0xE00B0 is offset of reset control register
1418 rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
1420 printk (KERN_EMERG "Error: reset control "
1421 "register not mapped!\n");
1424 printk (KERN_INFO "rstcr compatible register does not exist!\n");
1430 arch_initcall(setup_rstcr);
1432 void fsl_rstcr_restart(char *cmd)
1434 local_irq_disable();
1436 /* set reset control register */
1437 out_be32(rstcr, 0x2); /* HRESET_REQ */