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_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 prop = of_get_property(node, "brg-frequency", &size);
105 if (prop && size == 4)
114 EXPORT_SYMBOL(get_brgfreq);
116 static u32 fs_baudrate = -1;
118 u32 get_baudrate(void)
120 struct device_node *node;
122 if (fs_baudrate != -1)
125 node = of_find_node_by_type(NULL, "serial");
128 const unsigned int *prop = of_get_property(node,
129 "current-speed", &size);
139 EXPORT_SYMBOL(get_baudrate);
140 #endif /* CONFIG_CPM2 */
142 #ifdef CONFIG_FIXED_PHY
143 static int __init of_add_fixed_phys(void)
146 struct device_node *np;
148 struct fixed_phy_status status = {};
150 for_each_node_by_name(np, "ethernet") {
151 fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
156 status.duplex = fixed_link[1];
157 status.speed = fixed_link[2];
158 status.pause = fixed_link[3];
159 status.asym_pause = fixed_link[4];
161 ret = fixed_phy_add(PHY_POLL, fixed_link[0], &status);
170 arch_initcall(of_add_fixed_phys);
171 #endif /* CONFIG_FIXED_PHY */
173 static int __init gfar_mdio_of_init(void)
175 struct device_node *np = NULL;
176 struct platform_device *mdio_dev;
180 np = of_find_compatible_node(np, NULL, "fsl,gianfar-mdio");
182 /* try the deprecated version */
184 np = of_find_compatible_node(np, "mdio", "gianfar");
188 struct device_node *child = NULL;
189 struct gianfar_mdio_data mdio_data;
191 memset(&res, 0, sizeof(res));
192 memset(&mdio_data, 0, sizeof(mdio_data));
194 ret = of_address_to_resource(np, 0, &res);
199 platform_device_register_simple("fsl-gianfar_mdio",
201 if (IS_ERR(mdio_dev)) {
202 ret = PTR_ERR(mdio_dev);
206 for (k = 0; k < 32; k++)
207 mdio_data.irq[k] = PHY_POLL;
209 while ((child = of_get_next_child(np, child)) != NULL) {
210 int irq = irq_of_parse_and_map(child, 0);
212 const u32 *id = of_get_property(child,
214 mdio_data.irq[*id] = irq;
219 platform_device_add_data(mdio_dev, &mdio_data,
220 sizeof(struct gianfar_mdio_data));
229 platform_device_unregister(mdio_dev);
235 arch_initcall(gfar_mdio_of_init);
237 static const char *gfar_tx_intr = "tx";
238 static const char *gfar_rx_intr = "rx";
239 static const char *gfar_err_intr = "error";
241 static int __init gfar_of_init(void)
243 struct device_node *np;
245 struct platform_device *gfar_dev;
249 for (np = NULL, i = 0;
250 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
252 struct resource r[4];
253 struct device_node *phy, *mdio;
254 struct gianfar_platform_data gfar_data;
255 const unsigned int *id;
258 const void *mac_addr;
262 memset(r, 0, sizeof(r));
263 memset(&gfar_data, 0, sizeof(gfar_data));
265 ret = of_address_to_resource(np, 0, &r[0]);
269 of_irq_to_resource(np, 0, &r[1]);
271 model = of_get_property(np, "model", NULL);
273 /* If we aren't the FEC we have multiple interrupts */
274 if (model && strcasecmp(model, "FEC")) {
275 r[1].name = gfar_tx_intr;
277 r[2].name = gfar_rx_intr;
278 of_irq_to_resource(np, 1, &r[2]);
280 r[3].name = gfar_err_intr;
281 of_irq_to_resource(np, 2, &r[3]);
287 platform_device_register_simple("fsl-gianfar", i, &r[0],
290 if (IS_ERR(gfar_dev)) {
291 ret = PTR_ERR(gfar_dev);
295 mac_addr = of_get_mac_address(np);
297 memcpy(gfar_data.mac_addr, mac_addr, 6);
299 if (model && !strcasecmp(model, "TSEC"))
300 gfar_data.device_flags =
301 FSL_GIANFAR_DEV_HAS_GIGABIT |
302 FSL_GIANFAR_DEV_HAS_COALESCE |
303 FSL_GIANFAR_DEV_HAS_RMON |
304 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
305 if (model && !strcasecmp(model, "eTSEC"))
306 gfar_data.device_flags =
307 FSL_GIANFAR_DEV_HAS_GIGABIT |
308 FSL_GIANFAR_DEV_HAS_COALESCE |
309 FSL_GIANFAR_DEV_HAS_RMON |
310 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
311 FSL_GIANFAR_DEV_HAS_CSUM |
312 FSL_GIANFAR_DEV_HAS_VLAN |
313 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
315 ctype = of_get_property(np, "phy-connection-type", NULL);
317 /* We only care about rgmii-id. The rest are autodetected */
318 if (ctype && !strcmp(ctype, "rgmii-id"))
319 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
321 gfar_data.interface = PHY_INTERFACE_MODE_MII;
323 ph = of_get_property(np, "phy-handle", NULL);
327 fixed_link = (u32 *)of_get_property(np, "fixed-link",
334 gfar_data.bus_id = 0;
335 gfar_data.phy_id = fixed_link[0];
337 phy = of_find_node_by_phandle(*ph);
344 mdio = of_get_parent(phy);
346 id = of_get_property(phy, "reg", NULL);
347 ret = of_address_to_resource(mdio, 0, &res);
354 gfar_data.phy_id = *id;
355 gfar_data.bus_id = res.start;
362 platform_device_add_data(gfar_dev, &gfar_data,
364 gianfar_platform_data));
372 platform_device_unregister(gfar_dev);
377 arch_initcall(gfar_of_init);
379 #ifdef CONFIG_I2C_BOARDINFO
380 #include <linux/i2c.h>
381 struct i2c_driver_device {
387 static struct i2c_driver_device i2c_devices[] __initdata = {
388 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
389 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
390 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
391 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
392 {"dallas,ds1307", "rtc-ds1307", "ds1307",},
393 {"dallas,ds1337", "rtc-ds1307", "ds1337",},
394 {"dallas,ds1338", "rtc-ds1307", "ds1338",},
395 {"dallas,ds1339", "rtc-ds1307", "ds1339",},
396 {"dallas,ds1340", "rtc-ds1307", "ds1340",},
397 {"stm,m41t00", "rtc-ds1307", "m41t00"},
398 {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",},
401 static int __init of_find_i2c_driver(struct device_node *node,
402 struct i2c_board_info *info)
406 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
407 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
409 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
410 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
411 strlcpy(info->type, i2c_devices[i].i2c_type,
412 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
419 static void __init of_register_i2c_devices(struct device_node *adap_node,
422 struct device_node *node = NULL;
424 while ((node = of_get_next_child(adap_node, node))) {
425 struct i2c_board_info info = {};
429 addr = of_get_property(node, "reg", &len);
430 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
431 printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
435 info.irq = irq_of_parse_and_map(node, 0);
436 if (info.irq == NO_IRQ)
439 if (of_find_i2c_driver(node, &info) < 0)
444 i2c_register_board_info(bus_num, &info, 1);
448 static int __init fsl_i2c_of_init(void)
450 struct device_node *np;
452 struct platform_device *i2c_dev;
455 for_each_compatible_node(np, NULL, "fsl-i2c") {
456 struct resource r[2];
457 struct fsl_i2c_platform_data i2c_data;
458 const unsigned char *flags = NULL;
460 memset(&r, 0, sizeof(r));
461 memset(&i2c_data, 0, sizeof(i2c_data));
463 ret = of_address_to_resource(np, 0, &r[0]);
467 of_irq_to_resource(np, 0, &r[1]);
469 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
470 if (IS_ERR(i2c_dev)) {
471 ret = PTR_ERR(i2c_dev);
475 i2c_data.device_flags = 0;
476 flags = of_get_property(np, "dfsrr", NULL);
478 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
480 flags = of_get_property(np, "fsl5200-clocking", NULL);
482 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
485 platform_device_add_data(i2c_dev, &i2c_data,
487 fsl_i2c_platform_data));
491 of_register_i2c_devices(np, i++);
497 platform_device_unregister(i2c_dev);
502 arch_initcall(fsl_i2c_of_init);
505 #ifdef CONFIG_PPC_83xx
506 static int __init mpc83xx_wdt_init(void)
509 struct device_node *soc, *np;
510 struct platform_device *dev;
511 const unsigned int *freq;
514 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
521 soc = of_find_node_by_type(NULL, "soc");
528 freq = of_get_property(soc, "bus-frequency", NULL);
534 memset(&r, 0, sizeof(r));
536 ret = of_address_to_resource(np, 0, &r);
540 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
546 ret = platform_device_add_data(dev, freq, sizeof(int));
556 platform_device_unregister(dev);
565 arch_initcall(mpc83xx_wdt_init);
568 static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
571 return FSL_USB2_PHY_NONE;
572 if (!strcasecmp(phy_type, "ulpi"))
573 return FSL_USB2_PHY_ULPI;
574 if (!strcasecmp(phy_type, "utmi"))
575 return FSL_USB2_PHY_UTMI;
576 if (!strcasecmp(phy_type, "utmi_wide"))
577 return FSL_USB2_PHY_UTMI_WIDE;
578 if (!strcasecmp(phy_type, "serial"))
579 return FSL_USB2_PHY_SERIAL;
581 return FSL_USB2_PHY_NONE;
584 static int __init fsl_usb_of_init(void)
586 struct device_node *np;
588 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
589 *usb_dev_dr_client = NULL;
592 for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
593 struct resource r[2];
594 struct fsl_usb2_platform_data usb_data;
595 const unsigned char *prop = NULL;
597 memset(&r, 0, sizeof(r));
598 memset(&usb_data, 0, sizeof(usb_data));
600 ret = of_address_to_resource(np, 0, &r[0]);
604 of_irq_to_resource(np, 0, &r[1]);
607 platform_device_register_simple("fsl-ehci", i, r, 2);
608 if (IS_ERR(usb_dev_mph)) {
609 ret = PTR_ERR(usb_dev_mph);
613 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
614 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
616 usb_data.operating_mode = FSL_USB2_MPH_HOST;
618 prop = of_get_property(np, "port0", NULL);
620 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
622 prop = of_get_property(np, "port1", NULL);
624 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
626 prop = of_get_property(np, "phy_type", NULL);
627 usb_data.phy_mode = determine_usb_phy(prop);
630 platform_device_add_data(usb_dev_mph, &usb_data,
632 fsl_usb2_platform_data));
638 for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
639 struct resource r[2];
640 struct fsl_usb2_platform_data usb_data;
641 const unsigned char *prop = NULL;
643 memset(&r, 0, sizeof(r));
644 memset(&usb_data, 0, sizeof(usb_data));
646 ret = of_address_to_resource(np, 0, &r[0]);
650 of_irq_to_resource(np, 0, &r[1]);
652 prop = of_get_property(np, "dr_mode", NULL);
654 if (!prop || !strcmp(prop, "host")) {
655 usb_data.operating_mode = FSL_USB2_DR_HOST;
656 usb_dev_dr_host = platform_device_register_simple(
657 "fsl-ehci", i, r, 2);
658 if (IS_ERR(usb_dev_dr_host)) {
659 ret = PTR_ERR(usb_dev_dr_host);
662 } else if (prop && !strcmp(prop, "peripheral")) {
663 usb_data.operating_mode = FSL_USB2_DR_DEVICE;
664 usb_dev_dr_client = platform_device_register_simple(
665 "fsl-usb2-udc", i, r, 2);
666 if (IS_ERR(usb_dev_dr_client)) {
667 ret = PTR_ERR(usb_dev_dr_client);
670 } else if (prop && !strcmp(prop, "otg")) {
671 usb_data.operating_mode = FSL_USB2_DR_OTG;
672 usb_dev_dr_host = platform_device_register_simple(
673 "fsl-ehci", i, r, 2);
674 if (IS_ERR(usb_dev_dr_host)) {
675 ret = PTR_ERR(usb_dev_dr_host);
678 usb_dev_dr_client = platform_device_register_simple(
679 "fsl-usb2-udc", i, r, 2);
680 if (IS_ERR(usb_dev_dr_client)) {
681 ret = PTR_ERR(usb_dev_dr_client);
689 prop = of_get_property(np, "phy_type", NULL);
690 usb_data.phy_mode = determine_usb_phy(prop);
692 if (usb_dev_dr_host) {
693 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
694 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
695 dev.coherent_dma_mask;
696 if ((ret = platform_device_add_data(usb_dev_dr_host,
697 &usb_data, sizeof(struct
698 fsl_usb2_platform_data))))
701 if (usb_dev_dr_client) {
702 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
703 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
704 dev.coherent_dma_mask;
705 if ((ret = platform_device_add_data(usb_dev_dr_client,
706 &usb_data, sizeof(struct
707 fsl_usb2_platform_data))))
716 platform_device_unregister(usb_dev_dr_host);
717 if (usb_dev_dr_client)
718 platform_device_unregister(usb_dev_dr_client);
721 platform_device_unregister(usb_dev_mph);
726 arch_initcall(fsl_usb_of_init);
728 #ifndef CONFIG_PPC_CPM_NEW_BINDING
731 extern void init_scc_ioports(struct fs_uart_platform_info*);
733 static const char fcc_regs[] = "fcc_regs";
734 static const char fcc_regs_c[] = "fcc_regs_c";
735 static const char fcc_pram[] = "fcc_pram";
736 static char bus_id[9][BUS_ID_SIZE];
738 static int __init fs_enet_of_init(void)
740 struct device_node *np;
742 struct platform_device *fs_enet_dev;
746 for (np = NULL, i = 0;
747 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
749 struct resource r[4];
750 struct device_node *phy, *mdio;
751 struct fs_platform_info fs_enet_data;
752 const unsigned int *id, *phy_addr, *phy_irq;
753 const void *mac_addr;
757 memset(r, 0, sizeof(r));
758 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
760 ret = of_address_to_resource(np, 0, &r[0]);
763 r[0].name = fcc_regs;
765 ret = of_address_to_resource(np, 1, &r[1]);
768 r[1].name = fcc_pram;
770 ret = of_address_to_resource(np, 2, &r[2]);
773 r[2].name = fcc_regs_c;
774 fs_enet_data.fcc_regs_c = r[2].start;
776 of_irq_to_resource(np, 0, &r[3]);
779 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
781 if (IS_ERR(fs_enet_dev)) {
782 ret = PTR_ERR(fs_enet_dev);
786 model = of_get_property(np, "model", NULL);
792 mac_addr = of_get_mac_address(np);
794 memcpy(fs_enet_data.macaddr, mac_addr, 6);
796 ph = of_get_property(np, "phy-handle", NULL);
797 phy = of_find_node_by_phandle(*ph);
804 phy_addr = of_get_property(phy, "reg", NULL);
805 fs_enet_data.phy_addr = *phy_addr;
807 phy_irq = of_get_property(phy, "interrupts", NULL);
809 id = of_get_property(np, "device-id", NULL);
810 fs_enet_data.fs_no = *id;
811 strcpy(fs_enet_data.fs_type, model);
813 mdio = of_get_parent(phy);
814 ret = of_address_to_resource(mdio, 0, &res);
821 fs_enet_data.clk_rx = *((u32 *)of_get_property(np,
823 fs_enet_data.clk_tx = *((u32 *)of_get_property(np,
826 if (strstr(model, "FCC")) {
827 int fcc_index = *id - 1;
828 const unsigned char *mdio_bb_prop;
830 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
831 fs_enet_data.rx_ring = 32;
832 fs_enet_data.tx_ring = 32;
833 fs_enet_data.rx_copybreak = 240;
834 fs_enet_data.use_napi = 0;
835 fs_enet_data.napi_weight = 17;
836 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
837 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
838 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
840 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
841 (u32)res.start, fs_enet_data.phy_addr);
842 fs_enet_data.bus_id = (char*)&bus_id[(*id)];
843 fs_enet_data.init_ioports = init_fcc_ioports;
845 mdio_bb_prop = of_get_property(phy, "bitbang", NULL);
847 struct platform_device *fs_enet_mdio_bb_dev;
848 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
850 fs_enet_mdio_bb_dev =
851 platform_device_register_simple("fsl-bb-mdio",
853 memset(&fs_enet_mdio_bb_data, 0,
854 sizeof(struct fs_mii_bb_platform_info));
855 fs_enet_mdio_bb_data.mdio_dat.bit =
857 fs_enet_mdio_bb_data.mdio_dir.bit =
859 fs_enet_mdio_bb_data.mdc_dat.bit =
861 fs_enet_mdio_bb_data.mdio_port =
863 fs_enet_mdio_bb_data.mdc_port =
865 fs_enet_mdio_bb_data.delay =
868 fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
869 fs_enet_mdio_bb_data.irq[1] = -1;
870 fs_enet_mdio_bb_data.irq[2] = -1;
871 fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
872 fs_enet_mdio_bb_data.irq[31] = -1;
874 fs_enet_mdio_bb_data.mdio_dat.offset =
875 (u32)&cpm2_immr->im_ioport.iop_pdatc;
876 fs_enet_mdio_bb_data.mdio_dir.offset =
877 (u32)&cpm2_immr->im_ioport.iop_pdirc;
878 fs_enet_mdio_bb_data.mdc_dat.offset =
879 (u32)&cpm2_immr->im_ioport.iop_pdatc;
881 ret = platform_device_add_data(
883 &fs_enet_mdio_bb_data,
884 sizeof(struct fs_mii_bb_platform_info));
892 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
902 platform_device_unregister(fs_enet_dev);
907 arch_initcall(fs_enet_of_init);
909 static const char scc_regs[] = "regs";
910 static const char scc_pram[] = "pram";
912 static int __init cpm_uart_of_init(void)
914 struct device_node *np;
916 struct platform_device *cpm_uart_dev;
919 for (np = NULL, i = 0;
920 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
922 struct resource r[3];
923 struct fs_uart_platform_info cpm_uart_data;
927 memset(r, 0, sizeof(r));
928 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
930 ret = of_address_to_resource(np, 0, &r[0]);
934 r[0].name = scc_regs;
936 ret = of_address_to_resource(np, 1, &r[1]);
939 r[1].name = scc_pram;
941 of_irq_to_resource(np, 0, &r[2]);
944 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
946 if (IS_ERR(cpm_uart_dev)) {
947 ret = PTR_ERR(cpm_uart_dev);
951 id = of_get_property(np, "device-id", NULL);
952 cpm_uart_data.fs_no = *id;
954 model = of_get_property(np, "model", NULL);
955 strcpy(cpm_uart_data.fs_type, model);
957 cpm_uart_data.uart_clk = ppc_proc_freq;
959 cpm_uart_data.tx_num_fifo = 4;
960 cpm_uart_data.tx_buf_size = 32;
961 cpm_uart_data.rx_num_fifo = 4;
962 cpm_uart_data.rx_buf_size = 32;
963 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np,
965 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np,
969 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
971 fs_uart_platform_info));
979 platform_device_unregister(cpm_uart_dev);
984 arch_initcall(cpm_uart_of_init);
985 #endif /* CONFIG_CPM2 */
989 extern void init_scc_ioports(struct fs_platform_info*);
990 extern int platform_device_skip(const char *model, int id);
992 static int __init fs_enet_mdio_of_init(void)
994 struct device_node *np;
996 struct platform_device *mdio_dev;
1000 for (np = NULL, i = 0;
1001 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
1003 struct fs_mii_fec_platform_info mdio_data;
1005 memset(&res, 0, sizeof(res));
1006 memset(&mdio_data, 0, sizeof(mdio_data));
1008 ret = of_address_to_resource(np, 0, &res);
1013 platform_device_register_simple("fsl-cpm-fec-mdio",
1014 res.start, &res, 1);
1015 if (IS_ERR(mdio_dev)) {
1016 ret = PTR_ERR(mdio_dev);
1020 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
1023 platform_device_add_data(mdio_dev, &mdio_data,
1024 sizeof(struct fs_mii_fec_platform_info));
1031 platform_device_unregister(mdio_dev);
1036 arch_initcall(fs_enet_mdio_of_init);
1038 static const char *enet_regs = "regs";
1039 static const char *enet_pram = "pram";
1040 static const char *enet_irq = "interrupt";
1041 static char bus_id[9][BUS_ID_SIZE];
1043 static int __init fs_enet_of_init(void)
1045 struct device_node *np;
1047 struct platform_device *fs_enet_dev = NULL;
1048 struct resource res;
1051 for (np = NULL, i = 0;
1052 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
1054 struct resource r[4];
1055 struct device_node *phy = NULL, *mdio = NULL;
1056 struct fs_platform_info fs_enet_data;
1057 const unsigned int *id;
1058 const unsigned int *phy_addr;
1059 const void *mac_addr;
1063 memset(r, 0, sizeof(r));
1064 memset(&fs_enet_data, 0, sizeof(fs_enet_data));
1066 model = of_get_property(np, "model", NULL);
1067 if (model == NULL) {
1072 id = of_get_property(np, "device-id", NULL);
1073 fs_enet_data.fs_no = *id;
1075 if (platform_device_skip(model, *id))
1078 ret = of_address_to_resource(np, 0, &r[0]);
1081 r[0].name = enet_regs;
1083 mac_addr = of_get_mac_address(np);
1085 memcpy(fs_enet_data.macaddr, mac_addr, 6);
1087 ph = of_get_property(np, "phy-handle", NULL);
1089 phy = of_find_node_by_phandle(*ph);
1092 phy_addr = of_get_property(phy, "reg", NULL);
1093 fs_enet_data.phy_addr = *phy_addr;
1094 fs_enet_data.has_phy = 1;
1096 mdio = of_get_parent(phy);
1097 ret = of_address_to_resource(mdio, 0, &res);
1105 model = of_get_property(np, "model", NULL);
1106 strcpy(fs_enet_data.fs_type, model);
1108 if (strstr(model, "FEC")) {
1109 r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
1110 r[1].flags = IORESOURCE_IRQ;
1111 r[1].name = enet_irq;
1114 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
1116 if (IS_ERR(fs_enet_dev)) {
1117 ret = PTR_ERR(fs_enet_dev);
1121 fs_enet_data.rx_ring = 128;
1122 fs_enet_data.tx_ring = 16;
1123 fs_enet_data.rx_copybreak = 240;
1124 fs_enet_data.use_napi = 1;
1125 fs_enet_data.napi_weight = 17;
1127 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
1128 (u32)res.start, fs_enet_data.phy_addr);
1129 fs_enet_data.bus_id = (char*)&bus_id[i];
1130 fs_enet_data.init_ioports = init_fec_ioports;
1132 if (strstr(model, "SCC")) {
1133 ret = of_address_to_resource(np, 1, &r[1]);
1136 r[1].name = enet_pram;
1138 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1139 r[2].flags = IORESOURCE_IRQ;
1140 r[2].name = enet_irq;
1143 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
1145 if (IS_ERR(fs_enet_dev)) {
1146 ret = PTR_ERR(fs_enet_dev);
1150 fs_enet_data.rx_ring = 64;
1151 fs_enet_data.tx_ring = 8;
1152 fs_enet_data.rx_copybreak = 240;
1153 fs_enet_data.use_napi = 1;
1154 fs_enet_data.napi_weight = 17;
1156 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
1157 fs_enet_data.bus_id = (char*)&bus_id[i];
1158 fs_enet_data.init_ioports = init_scc_ioports;
1164 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
1173 platform_device_unregister(fs_enet_dev);
1178 arch_initcall(fs_enet_of_init);
1180 static int __init fsl_pcmcia_of_init(void)
1182 struct device_node *np;
1184 * Register all the devices which type is "pcmcia"
1186 for_each_compatible_node(np, "pcmcia", "fsl,pq-pcmcia")
1187 of_platform_device_create(np, "m8xx-pcmcia", NULL);
1191 arch_initcall(fsl_pcmcia_of_init);
1193 static const char *smc_regs = "regs";
1194 static const char *smc_pram = "pram";
1196 static int __init cpm_smc_uart_of_init(void)
1198 struct device_node *np;
1200 struct platform_device *cpm_uart_dev;
1203 for (np = NULL, i = 0;
1204 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
1206 struct resource r[3];
1207 struct fs_uart_platform_info cpm_uart_data;
1211 memset(r, 0, sizeof(r));
1212 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
1214 ret = of_address_to_resource(np, 0, &r[0]);
1218 r[0].name = smc_regs;
1220 ret = of_address_to_resource(np, 1, &r[1]);
1223 r[1].name = smc_pram;
1225 r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
1226 r[2].flags = IORESOURCE_IRQ;
1229 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
1231 if (IS_ERR(cpm_uart_dev)) {
1232 ret = PTR_ERR(cpm_uart_dev);
1236 model = of_get_property(np, "model", NULL);
1237 strcpy(cpm_uart_data.fs_type, model);
1239 id = of_get_property(np, "device-id", NULL);
1240 cpm_uart_data.fs_no = *id;
1241 cpm_uart_data.uart_clk = ppc_proc_freq;
1243 cpm_uart_data.tx_num_fifo = 4;
1244 cpm_uart_data.tx_buf_size = 32;
1245 cpm_uart_data.rx_num_fifo = 4;
1246 cpm_uart_data.rx_buf_size = 32;
1249 platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
1251 fs_uart_platform_info));
1259 platform_device_unregister(cpm_uart_dev);
1264 arch_initcall(cpm_smc_uart_of_init);
1266 #endif /* CONFIG_8xx */
1267 #endif /* CONFIG_PPC_CPM_NEW_BINDING */
1269 int __init fsl_spi_init(struct spi_board_info *board_infos,
1270 unsigned int num_board_infos,
1271 void (*activate_cs)(u8 cs, u8 polarity),
1272 void (*deactivate_cs)(u8 cs, u8 polarity))
1274 struct device_node *np;
1278 /* SPI controller is either clocked from QE or SoC clock */
1279 np = of_find_compatible_node(NULL, NULL, "fsl,qe");
1281 np = of_find_node_by_type(NULL, "qe");
1284 np = of_find_node_by_type(NULL, "soc");
1289 sysclk = of_get_property(np, "bus-frequency", NULL);
1293 for (np = NULL, i = 1;
1294 (np = of_find_compatible_node(np, "spi", "fsl_spi")) != NULL;
1299 struct resource res[2];
1300 struct platform_device *pdev;
1301 struct fsl_spi_platform_data pdata = {
1302 .activate_cs = activate_cs,
1303 .deactivate_cs = deactivate_cs,
1306 memset(res, 0, sizeof(res));
1308 pdata.sysclk = *sysclk;
1310 prop = of_get_property(np, "reg", NULL);
1313 pdata.bus_num = *(u32 *)prop;
1315 prop = of_get_property(np, "mode", NULL);
1316 if (prop && !strcmp(prop, "cpu-qe"))
1319 for (j = 0; j < num_board_infos; j++) {
1320 if (board_infos[j].bus_num == pdata.bus_num)
1321 pdata.max_chipselect++;
1324 if (!pdata.max_chipselect)
1327 ret = of_address_to_resource(np, 0, &res[0]);
1331 ret = of_irq_to_resource(np, 0, &res[1]);
1335 pdev = platform_device_alloc("mpc83xx_spi", i);
1339 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
1343 ret = platform_device_add_resources(pdev, res,
1348 ret = platform_device_register(pdev);
1354 platform_device_del(pdev);
1359 return spi_register_board_info(board_infos, num_board_infos);
1362 #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
1363 static __be32 __iomem *rstcr;
1365 static int __init setup_rstcr(void)
1367 struct device_node *np;
1368 np = of_find_node_by_name(NULL, "global-utilities");
1369 if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
1370 const u32 *prop = of_get_property(np, "reg", NULL);
1372 /* map reset control register
1373 * 0xE00B0 is offset of reset control register
1375 rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
1377 printk (KERN_EMERG "Error: reset control "
1378 "register not mapped!\n");
1381 printk (KERN_INFO "rstcr compatible register does not exist!\n");
1387 arch_initcall(setup_rstcr);
1389 void fsl_rstcr_restart(char *cmd)
1391 local_irq_disable();
1393 /* set reset control register */
1394 out_be32(rstcr, 0x2); /* HRESET_REQ */