Commit | Line | Data |
---|---|---|
2b9d7467 ZR |
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 | ||
2b9d7467 ZR |
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> | |
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 | ||
39 | static phys_addr_t tsi108_csr_base = -1; | |
40 | ||
41 | phys_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; | |
e2eb6392 | 51 | const void *prop = of_get_property(tsi, "reg", &size); |
2b9d7467 ZR |
52 | tsi108_csr_base = of_translate_address(tsi, prop); |
53 | of_node_put(tsi); | |
54 | }; | |
55 | return tsi108_csr_base; | |
56 | } | |
57 | ||
58 | u32 get_vir_csrbase(void) | |
59 | { | |
60 | return (u32) (ioremap(get_csrbase(), 0x10000)); | |
61 | } | |
62 | ||
63 | EXPORT_SYMBOL(get_csrbase); | |
64 | EXPORT_SYMBOL(get_vir_csrbase); | |
65 | ||
66 | static 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; | |
75 | (np = of_find_compatible_node(np, "network", "tsi-ethernet")) != NULL; | |
76 | i++) { | |
77 | struct resource r[2]; | |
78 | struct device_node *phy; | |
79 | hw_info tsi_eth_data; | |
e2eb6392 SR |
80 | const unsigned int *id; |
81 | const unsigned int *phy_id; | |
c3386e40 | 82 | const void *mac_addr; |
e2eb6392 | 83 | const phandle *ph; |
2b9d7467 ZR |
84 | |
85 | memset(r, 0, sizeof(r)); | |
86 | memset(&tsi_eth_data, 0, sizeof(tsi_eth_data)); | |
87 | ||
88 | ret = of_address_to_resource(np, 0, &r[0]); | |
89 | DBG("%s: name:start->end = %s:0x%lx-> 0x%lx\n", | |
90 | __FUNCTION__,r[0].name, r[0].start, r[0].end); | |
91 | if (ret) | |
92 | goto err; | |
93 | ||
94 | r[1].name = "tx"; | |
c4342ff9 ZR |
95 | r[1].start = irq_of_parse_and_map(np, 0); |
96 | r[1].end = irq_of_parse_and_map(np, 0); | |
2b9d7467 | 97 | r[1].flags = IORESOURCE_IRQ; |
c4342ff9 ZR |
98 | DBG("%s: name:start->end = %s:0x%lx-> 0x%lx\n", |
99 | __FUNCTION__,r[1].name, r[1].start, r[1].end); | |
2b9d7467 ZR |
100 | |
101 | tsi_eth_dev = | |
102 | platform_device_register_simple("tsi-ethernet", i, &r[0], | |
c4342ff9 | 103 | 1); |
2b9d7467 ZR |
104 | |
105 | if (IS_ERR(tsi_eth_dev)) { | |
106 | ret = PTR_ERR(tsi_eth_dev); | |
107 | goto err; | |
108 | } | |
109 | ||
c1b78d05 JB |
110 | mac_addr = of_get_mac_address(np); |
111 | if (mac_addr) | |
112 | memcpy(tsi_eth_data.mac_addr, mac_addr, 6); | |
2b9d7467 | 113 | |
e2eb6392 | 114 | ph = of_get_property(np, "phy-handle", NULL); |
2b9d7467 ZR |
115 | phy = of_find_node_by_phandle(*ph); |
116 | ||
117 | if (phy == NULL) { | |
118 | ret = -ENODEV; | |
119 | goto unreg; | |
120 | } | |
121 | ||
e2eb6392 SR |
122 | id = of_get_property(phy, "reg", NULL); |
123 | phy_id = of_get_property(phy, "phy-id", NULL); | |
2b9d7467 ZR |
124 | ret = of_address_to_resource(phy, 0, &res); |
125 | if (ret) { | |
126 | of_node_put(phy); | |
127 | goto unreg; | |
128 | } | |
129 | tsi_eth_data.regs = r[0].start; | |
130 | tsi_eth_data.phyregs = res.start; | |
131 | tsi_eth_data.phy = *phy_id; | |
c4342ff9 | 132 | tsi_eth_data.irq_num = irq_of_parse_and_map(np, 0); |
c1b78d05 JB |
133 | if (of_device_is_compatible(phy, "bcm54xx")) |
134 | tsi_eth_data.phy_type = TSI108_PHY_BCM54XX; | |
2b9d7467 ZR |
135 | of_node_put(phy); |
136 | ret = | |
137 | platform_device_add_data(tsi_eth_dev, &tsi_eth_data, | |
138 | sizeof(hw_info)); | |
139 | if (ret) | |
140 | goto unreg; | |
141 | } | |
142 | return 0; | |
143 | unreg: | |
144 | platform_device_unregister(tsi_eth_dev); | |
145 | err: | |
146 | return ret; | |
147 | } | |
148 | ||
149 | arch_initcall(tsi108_eth_of_init); |