blob: a113d800cbf0eba4e5ac235fafa9e0bf363b425b [file] [log] [blame]
Zang Roy-r619112b9d7462006-06-13 15:07:23 +08001/*
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-r619112b9d7462006-06-13 15:07:23 +080012#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>
22#include <asm/tsi108.h>
23
24#include <asm/system.h>
25#include <asm/atomic.h>
26#include <asm/io.h>
27#include <asm/irq.h>
28#include <asm/prom.h>
29#include <mm/mmu_decl.h>
30
31#undef DEBUG
32
33#ifdef DEBUG
34#define DBG(fmt...) do { printk(fmt); } while(0)
35#else
36#define DBG(fmt...) do { } while(0)
37#endif
38
39static phys_addr_t tsi108_csr_base = -1;
40
41phys_addr_t get_csrbase(void)
42{
43 struct device_node *tsi;
44
45 if (tsi108_csr_base != -1)
46 return tsi108_csr_base;
47
48 tsi = of_find_node_by_type(NULL, "tsi-bridge");
49 if (tsi) {
50 unsigned int size;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100051 const void *prop = of_get_property(tsi, "reg", &size);
Zang Roy-r619112b9d7462006-06-13 15:07:23 +080052 tsi108_csr_base = of_translate_address(tsi, prop);
53 of_node_put(tsi);
54 };
55 return tsi108_csr_base;
56}
57
58u32 get_vir_csrbase(void)
59{
60 return (u32) (ioremap(get_csrbase(), 0x10000));
61}
62
63EXPORT_SYMBOL(get_csrbase);
64EXPORT_SYMBOL(get_vir_csrbase);
65
66static int __init tsi108_eth_of_init(void)
67{
68 struct device_node *np;
69 unsigned int i;
70 struct platform_device *tsi_eth_dev;
71 struct resource res;
72 int ret;
73
74 for (np = NULL, i = 0;
David Gibsone58ca3d2007-06-13 14:53:00 +100075 (np = of_find_compatible_node(np, "network", "tsi108-ethernet")) != NULL;
Zang Roy-r619112b9d7462006-06-13 15:07:23 +080076 i++) {
77 struct resource r[2];
David Gibsone58ca3d2007-06-13 14:53:00 +100078 struct device_node *phy, *mdio;
Zang Roy-r619112b9d7462006-06-13 15:07:23 +080079 hw_info tsi_eth_data;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100080 const unsigned int *phy_id;
Zang Roy-r61911c3386e42006-10-18 11:18:58 +080081 const void *mac_addr;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100082 const phandle *ph;
Zang Roy-r619112b9d7462006-06-13 15:07:23 +080083
84 memset(r, 0, sizeof(r));
85 memset(&tsi_eth_data, 0, sizeof(tsi_eth_data));
86
87 ret = of_address_to_resource(np, 0, &r[0]);
88 DBG("%s: name:start->end = %s:0x%lx-> 0x%lx\n",
89 __FUNCTION__,r[0].name, r[0].start, r[0].end);
90 if (ret)
91 goto err;
92
93 r[1].name = "tx";
Zang Roy-r61911c4342ff2006-08-23 10:19:50 +080094 r[1].start = irq_of_parse_and_map(np, 0);
95 r[1].end = irq_of_parse_and_map(np, 0);
Zang Roy-r619112b9d7462006-06-13 15:07:23 +080096 r[1].flags = IORESOURCE_IRQ;
Zang Roy-r61911c4342ff2006-08-23 10:19:50 +080097 DBG("%s: name:start->end = %s:0x%lx-> 0x%lx\n",
98 __FUNCTION__,r[1].name, r[1].start, r[1].end);
Zang Roy-r619112b9d7462006-06-13 15:07:23 +080099
100 tsi_eth_dev =
101 platform_device_register_simple("tsi-ethernet", i, &r[0],
Zang Roy-r61911c4342ff2006-08-23 10:19:50 +0800102 1);
Zang Roy-r619112b9d7462006-06-13 15:07:23 +0800103
104 if (IS_ERR(tsi_eth_dev)) {
105 ret = PTR_ERR(tsi_eth_dev);
106 goto err;
107 }
108
Josh Boyerc1b78d02007-05-08 07:26:22 +1000109 mac_addr = of_get_mac_address(np);
110 if (mac_addr)
111 memcpy(tsi_eth_data.mac_addr, mac_addr, 6);
Zang Roy-r619112b9d7462006-06-13 15:07:23 +0800112
David Gibsone58ca3d2007-06-13 14:53:00 +1000113 ph = of_get_property(np, "mdio-handle", NULL);
114 mdio = of_find_node_by_phandle(*ph);
115 ret = of_address_to_resource(mdio, 0, &res);
116 of_node_put(mdio);
117 if (ret)
118 goto unreg;
119
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000120 ph = of_get_property(np, "phy-handle", NULL);
Zang Roy-r619112b9d7462006-06-13 15:07:23 +0800121 phy = of_find_node_by_phandle(*ph);
122
123 if (phy == NULL) {
124 ret = -ENODEV;
125 goto unreg;
126 }
127
David Gibsone58ca3d2007-06-13 14:53:00 +1000128 phy_id = of_get_property(phy, "reg", NULL);
129
Zang Roy-r619112b9d7462006-06-13 15:07:23 +0800130 tsi_eth_data.regs = r[0].start;
131 tsi_eth_data.phyregs = res.start;
132 tsi_eth_data.phy = *phy_id;
Zang Roy-r61911c4342ff2006-08-23 10:19:50 +0800133 tsi_eth_data.irq_num = irq_of_parse_and_map(np, 0);
David Gibsone58ca3d2007-06-13 14:53:00 +1000134
135 /* Some boards with the TSI108 bridge (e.g. Holly)
136 * have a miswiring of the ethernet PHYs which
137 * requires a workaround. The special
138 * "txc-rxc-delay-disable" property enables this
139 * workaround. FIXME: Need to port the tsi108_eth
140 * driver itself to phylib and use a non-misleading
141 * name for the workaround flag - it's not actually to
142 * do with the model of PHY in use */
143 if (of_get_property(phy, "txc-rxc-delay-disable", NULL))
Josh Boyerc1b78d02007-05-08 07:26:22 +1000144 tsi_eth_data.phy_type = TSI108_PHY_BCM54XX;
Zang Roy-r619112b9d7462006-06-13 15:07:23 +0800145 of_node_put(phy);
David Gibsone58ca3d2007-06-13 14:53:00 +1000146
Zang Roy-r619112b9d7462006-06-13 15:07:23 +0800147 ret =
148 platform_device_add_data(tsi_eth_dev, &tsi_eth_data,
149 sizeof(hw_info));
150 if (ret)
151 goto unreg;
152 }
153 return 0;
154unreg:
155 platform_device_unregister(tsi_eth_dev);
156err:
157 return ret;
158}
159
160arch_initcall(tsi108_eth_of_init);