aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/sysdev/tsi108_dev.c
diff options
context:
space:
mode:
authorZang Roy-r61911 <tie-fei.zang@freescale.com>2006-06-13 03:07:23 -0400
committerPaul Mackerras <paulus@samba.org>2006-06-29 02:20:36 -0400
commit2b9d7467a6dbc41872c605511e105cbde1eda100 (patch)
treeefdf8f5ee5194ee2ac5c13a196e0910a877f00fd /arch/powerpc/sysdev/tsi108_dev.c
parentc5d56332fd6c2f0c7cf9d1f65416076f2711ea28 (diff)
[POWERPC] Add tsi108 pci and platform device data register function
Add Tundra Semiconductor tsi108 pci and platform device data register function support. Signed-off-by: Alexandre Bounine <alexandreb@tundra.com> Signed-off-by: Roy Zang <tie-fei.zang@freescale.com> --- Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/sysdev/tsi108_dev.c')
-rw-r--r--arch/powerpc/sysdev/tsi108_dev.c145
1 files changed, 145 insertions, 0 deletions
diff --git a/arch/powerpc/sysdev/tsi108_dev.c b/arch/powerpc/sysdev/tsi108_dev.c
new file mode 100644
index 000000000000..26a0cc820cde
--- /dev/null
+++ b/arch/powerpc/sysdev/tsi108_dev.c
@@ -0,0 +1,145 @@
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
12#include <linux/config.h>
13#include <linux/stddef.h>
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/errno.h>
17#include <linux/major.h>
18#include <linux/delay.h>
19#include <linux/irq.h>
20#include <linux/module.h>
21#include <linux/device.h>
22#include <linux/platform_device.h>
23#include <asm/tsi108.h>
24
25#include <asm/system.h>
26#include <asm/atomic.h>
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
40static phys_addr_t tsi108_csr_base = -1;
41
42phys_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;
52 void *prop = get_property(tsi, "reg", &size);
53 tsi108_csr_base = of_translate_address(tsi, prop);
54 of_node_put(tsi);
55 };
56 return tsi108_csr_base;
57}
58
59u32 get_vir_csrbase(void)
60{
61 return (u32) (ioremap(get_csrbase(), 0x10000));
62}
63
64EXPORT_SYMBOL(get_csrbase);
65EXPORT_SYMBOL(get_vir_csrbase);
66
67static int __init tsi108_eth_of_init(void)
68{
69 struct device_node *np;
70 unsigned int i;
71 struct platform_device *tsi_eth_dev;
72 struct resource res;
73 int ret;
74
75 for (np = NULL, i = 0;
76 (np = of_find_compatible_node(np, "network", "tsi-ethernet")) != NULL;
77 i++) {
78 struct resource r[2];
79 struct device_node *phy;
80 hw_info tsi_eth_data;
81 unsigned int *id;
82 unsigned int *phy_id;
83 void *mac_addr;
84 phandle *ph;
85
86 memset(r, 0, sizeof(r));
87 memset(&tsi_eth_data, 0, sizeof(tsi_eth_data));
88
89 ret = of_address_to_resource(np, 0, &r[0]);
90 DBG("%s: name:start->end = %s:0x%lx-> 0x%lx\n",
91 __FUNCTION__,r[0].name, r[0].start, r[0].end);
92 if (ret)
93 goto err;
94
95 r[1].name = "tx";
96 r[1].start = np->intrs[0].line;
97 r[1].end = np->intrs[0].line;
98 r[1].flags = IORESOURCE_IRQ;
99
100 tsi_eth_dev =
101 platform_device_register_simple("tsi-ethernet", i, &r[0],
102 np->n_intrs + 1);
103
104 if (IS_ERR(tsi_eth_dev)) {
105 ret = PTR_ERR(tsi_eth_dev);
106 goto err;
107 }
108
109 mac_addr = get_property(np, "address", NULL);
110 memcpy(tsi_eth_data.mac_addr, mac_addr, 6);
111
112 ph = (phandle *) get_property(np, "phy-handle", NULL);
113 phy = of_find_node_by_phandle(*ph);
114
115 if (phy == NULL) {
116 ret = -ENODEV;
117 goto unreg;
118 }
119
120 id = (u32 *) get_property(phy, "reg", NULL);
121 phy_id = (u32 *) get_property(phy, "phy-id", NULL);
122 ret = of_address_to_resource(phy, 0, &res);
123 if (ret) {
124 of_node_put(phy);
125 goto unreg;
126 }
127 tsi_eth_data.regs = r[0].start;
128 tsi_eth_data.phyregs = res.start;
129 tsi_eth_data.phy = *phy_id;
130 tsi_eth_data.irq_num = np->intrs[0].line;
131 of_node_put(phy);
132 ret =
133 platform_device_add_data(tsi_eth_dev, &tsi_eth_data,
134 sizeof(hw_info));
135 if (ret)
136 goto unreg;
137 }
138 return 0;
139unreg:
140 platform_device_unregister(tsi_eth_dev);
141err:
142 return ret;
143}
144
145arch_initcall(tsi108_eth_of_init);