Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 1 | /* |
| 2 | * tsi108/109 device setup code |
| 3 | * |
| 4 | * Maintained by Roy Zang < tie-fei.zang@freescale.com > |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2 of the License, or (at your |
| 9 | * option) any later version. |
| 10 | */ |
| 11 | |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 12 | #include <linux/stddef.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/major.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/irq.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/device.h> |
| 21 | #include <linux/platform_device.h> |
David Daney | 4b6ba8a | 2010-10-26 15:07:13 -0700 | [diff] [blame] | 22 | #include <linux/of_net.h> |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 23 | #include <asm/tsi108.h> |
| 24 | |
| 25 | #include <asm/system.h> |
Arun Sharma | 6006349 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 26 | #include <linux/atomic.h> |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 27 | #include <asm/io.h> |
| 28 | #include <asm/irq.h> |
| 29 | #include <asm/prom.h> |
| 30 | #include <mm/mmu_decl.h> |
| 31 | |
| 32 | #undef DEBUG |
| 33 | |
| 34 | #ifdef DEBUG |
| 35 | #define DBG(fmt...) do { printk(fmt); } while(0) |
| 36 | #else |
| 37 | #define DBG(fmt...) do { } while(0) |
| 38 | #endif |
| 39 | |
| 40 | static phys_addr_t tsi108_csr_base = -1; |
| 41 | |
| 42 | phys_addr_t get_csrbase(void) |
| 43 | { |
| 44 | struct device_node *tsi; |
| 45 | |
| 46 | if (tsi108_csr_base != -1) |
| 47 | return tsi108_csr_base; |
| 48 | |
| 49 | tsi = of_find_node_by_type(NULL, "tsi-bridge"); |
| 50 | if (tsi) { |
| 51 | unsigned int size; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 52 | const void *prop = of_get_property(tsi, "reg", &size); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 53 | tsi108_csr_base = of_translate_address(tsi, prop); |
| 54 | of_node_put(tsi); |
| 55 | }; |
| 56 | return tsi108_csr_base; |
| 57 | } |
| 58 | |
| 59 | u32 get_vir_csrbase(void) |
| 60 | { |
| 61 | return (u32) (ioremap(get_csrbase(), 0x10000)); |
| 62 | } |
| 63 | |
| 64 | EXPORT_SYMBOL(get_csrbase); |
| 65 | EXPORT_SYMBOL(get_vir_csrbase); |
| 66 | |
| 67 | static int __init tsi108_eth_of_init(void) |
| 68 | { |
| 69 | struct device_node *np; |
Cyrill Gorcunov | 26cb7d8 | 2007-11-30 06:44:36 +1100 | [diff] [blame] | 70 | unsigned int i = 0; |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 71 | struct platform_device *tsi_eth_dev; |
| 72 | struct resource res; |
| 73 | int ret; |
| 74 | |
Cyrill Gorcunov | 26cb7d8 | 2007-11-30 06:44:36 +1100 | [diff] [blame] | 75 | for_each_compatible_node(np, "network", "tsi108-ethernet") { |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 76 | struct resource r[2]; |
David Gibson | e58ca3d | 2007-06-13 14:53:00 +1000 | [diff] [blame] | 77 | struct device_node *phy, *mdio; |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 78 | hw_info tsi_eth_data; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 79 | const unsigned int *phy_id; |
Zang Roy-r61911 | c3386e4 | 2006-10-18 11:18:58 +0800 | [diff] [blame] | 80 | const void *mac_addr; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 81 | const phandle *ph; |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 82 | |
| 83 | memset(r, 0, sizeof(r)); |
| 84 | memset(&tsi_eth_data, 0, sizeof(tsi_eth_data)); |
| 85 | |
| 86 | ret = of_address_to_resource(np, 0, &r[0]); |
Joe Perches | 518fdae | 2010-11-12 14:49:19 +0000 | [diff] [blame] | 87 | DBG("%s: name:start->end = %s:%pR\n", |
| 88 | __func__, r[0].name, &r[0]); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 89 | if (ret) |
| 90 | goto err; |
| 91 | |
| 92 | r[1].name = "tx"; |
Zang Roy-r61911 | c4342ff | 2006-08-23 10:19:50 +0800 | [diff] [blame] | 93 | r[1].start = irq_of_parse_and_map(np, 0); |
| 94 | r[1].end = irq_of_parse_and_map(np, 0); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 95 | r[1].flags = IORESOURCE_IRQ; |
Joe Perches | 518fdae | 2010-11-12 14:49:19 +0000 | [diff] [blame] | 96 | DBG("%s: name:start->end = %s:%pR\n", |
| 97 | __func__, r[1].name, &r[1]); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 98 | |
| 99 | tsi_eth_dev = |
Cyrill Gorcunov | 26cb7d8 | 2007-11-30 06:44:36 +1100 | [diff] [blame] | 100 | platform_device_register_simple("tsi-ethernet", i++, &r[0], |
Zang Roy-r61911 | c4342ff | 2006-08-23 10:19:50 +0800 | [diff] [blame] | 101 | 1); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 102 | |
| 103 | if (IS_ERR(tsi_eth_dev)) { |
| 104 | ret = PTR_ERR(tsi_eth_dev); |
| 105 | goto err; |
| 106 | } |
| 107 | |
Josh Boyer | c1b78d0 | 2007-05-08 07:26:22 +1000 | [diff] [blame] | 108 | mac_addr = of_get_mac_address(np); |
| 109 | if (mac_addr) |
| 110 | memcpy(tsi_eth_data.mac_addr, mac_addr, 6); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 111 | |
David Gibson | e58ca3d | 2007-06-13 14:53:00 +1000 | [diff] [blame] | 112 | ph = of_get_property(np, "mdio-handle", NULL); |
| 113 | mdio = of_find_node_by_phandle(*ph); |
| 114 | ret = of_address_to_resource(mdio, 0, &res); |
| 115 | of_node_put(mdio); |
| 116 | if (ret) |
| 117 | goto unreg; |
| 118 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 119 | ph = of_get_property(np, "phy-handle", NULL); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 120 | phy = of_find_node_by_phandle(*ph); |
| 121 | |
| 122 | if (phy == NULL) { |
| 123 | ret = -ENODEV; |
| 124 | goto unreg; |
| 125 | } |
| 126 | |
David Gibson | e58ca3d | 2007-06-13 14:53:00 +1000 | [diff] [blame] | 127 | phy_id = of_get_property(phy, "reg", NULL); |
| 128 | |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 129 | tsi_eth_data.regs = r[0].start; |
| 130 | tsi_eth_data.phyregs = res.start; |
| 131 | tsi_eth_data.phy = *phy_id; |
Zang Roy-r61911 | c4342ff | 2006-08-23 10:19:50 +0800 | [diff] [blame] | 132 | tsi_eth_data.irq_num = irq_of_parse_and_map(np, 0); |
David Gibson | e58ca3d | 2007-06-13 14:53:00 +1000 | [diff] [blame] | 133 | |
| 134 | /* Some boards with the TSI108 bridge (e.g. Holly) |
| 135 | * have a miswiring of the ethernet PHYs which |
| 136 | * requires a workaround. The special |
| 137 | * "txc-rxc-delay-disable" property enables this |
| 138 | * workaround. FIXME: Need to port the tsi108_eth |
| 139 | * driver itself to phylib and use a non-misleading |
| 140 | * name for the workaround flag - it's not actually to |
| 141 | * do with the model of PHY in use */ |
| 142 | if (of_get_property(phy, "txc-rxc-delay-disable", NULL)) |
Josh Boyer | c1b78d0 | 2007-05-08 07:26:22 +1000 | [diff] [blame] | 143 | tsi_eth_data.phy_type = TSI108_PHY_BCM54XX; |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 144 | of_node_put(phy); |
David Gibson | e58ca3d | 2007-06-13 14:53:00 +1000 | [diff] [blame] | 145 | |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 146 | ret = |
| 147 | platform_device_add_data(tsi_eth_dev, &tsi_eth_data, |
| 148 | sizeof(hw_info)); |
| 149 | if (ret) |
| 150 | goto unreg; |
| 151 | } |
| 152 | return 0; |
| 153 | unreg: |
| 154 | platform_device_unregister(tsi_eth_dev); |
| 155 | err: |
Cyrill Gorcunov | 26cb7d8 | 2007-11-30 06:44:36 +1100 | [diff] [blame] | 156 | of_node_put(np); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | arch_initcall(tsi108_eth_of_init); |