diff options
Diffstat (limited to 'drivers/net/chelsio/my3126.c')
-rw-r--r-- | drivers/net/chelsio/my3126.c | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/drivers/net/chelsio/my3126.c b/drivers/net/chelsio/my3126.c new file mode 100644 index 000000000000..0b90014d5b3e --- /dev/null +++ b/drivers/net/chelsio/my3126.c | |||
@@ -0,0 +1,204 @@ | |||
1 | /* $Date: 2005/11/12 02:13:49 $ $RCSfile: my3126.c,v $ $Revision: 1.15 $ */ | ||
2 | #include "cphy.h" | ||
3 | #include "elmer0.h" | ||
4 | #include "suni1x10gexp_regs.h" | ||
5 | |||
6 | /* Port Reset */ | ||
7 | static int my3126_reset(struct cphy *cphy, int wait) | ||
8 | { | ||
9 | /* | ||
10 | * This can be done through registers. It is not required since | ||
11 | * a full chip reset is used. | ||
12 | */ | ||
13 | return (0); | ||
14 | } | ||
15 | |||
16 | static int my3126_interrupt_enable(struct cphy *cphy) | ||
17 | { | ||
18 | schedule_delayed_work(&cphy->phy_update, HZ/30); | ||
19 | t1_tpi_read(cphy->adapter, A_ELMER0_GPO, &cphy->elmer_gpo); | ||
20 | return (0); | ||
21 | } | ||
22 | |||
23 | static int my3126_interrupt_disable(struct cphy *cphy) | ||
24 | { | ||
25 | cancel_rearming_delayed_work(&cphy->phy_update); | ||
26 | return (0); | ||
27 | } | ||
28 | |||
29 | static int my3126_interrupt_clear(struct cphy *cphy) | ||
30 | { | ||
31 | return (0); | ||
32 | } | ||
33 | |||
34 | #define OFFSET(REG_ADDR) (REG_ADDR << 2) | ||
35 | |||
36 | static int my3126_interrupt_handler(struct cphy *cphy) | ||
37 | { | ||
38 | u32 val; | ||
39 | u16 val16; | ||
40 | u16 status; | ||
41 | u32 act_count; | ||
42 | adapter_t *adapter; | ||
43 | adapter = cphy->adapter; | ||
44 | |||
45 | if (cphy->count == 50) { | ||
46 | mdio_read(cphy, 0x1, 0x1, &val); | ||
47 | val16 = (u16) val; | ||
48 | status = cphy->bmsr ^ val16; | ||
49 | |||
50 | if (status & BMSR_LSTATUS) | ||
51 | t1_link_changed(adapter, 0); | ||
52 | cphy->bmsr = val16; | ||
53 | |||
54 | /* We have only enabled link change interrupts so it | ||
55 | must be that | ||
56 | */ | ||
57 | cphy->count = 0; | ||
58 | } | ||
59 | |||
60 | t1_tpi_write(adapter, OFFSET(SUNI1x10GEXP_REG_MSTAT_CONTROL), | ||
61 | SUNI1x10GEXP_BITMSK_MSTAT_SNAP); | ||
62 | t1_tpi_read(adapter, | ||
63 | OFFSET(SUNI1x10GEXP_REG_MSTAT_COUNTER_1_LOW), &act_count); | ||
64 | t1_tpi_read(adapter, | ||
65 | OFFSET(SUNI1x10GEXP_REG_MSTAT_COUNTER_33_LOW), &val); | ||
66 | act_count += val; | ||
67 | |||
68 | /* Populate elmer_gpo with the register value */ | ||
69 | t1_tpi_read(adapter, A_ELMER0_GPO, &val); | ||
70 | cphy->elmer_gpo = val; | ||
71 | |||
72 | if ( (val & (1 << 8)) || (val & (1 << 19)) || | ||
73 | (cphy->act_count == act_count) || cphy->act_on ) { | ||
74 | if (is_T2(adapter)) | ||
75 | val |= (1 << 9); | ||
76 | else if (t1_is_T1B(adapter)) | ||
77 | val |= (1 << 20); | ||
78 | cphy->act_on = 0; | ||
79 | } else { | ||
80 | if (is_T2(adapter)) | ||
81 | val &= ~(1 << 9); | ||
82 | else if (t1_is_T1B(adapter)) | ||
83 | val &= ~(1 << 20); | ||
84 | cphy->act_on = 1; | ||
85 | } | ||
86 | |||
87 | t1_tpi_write(adapter, A_ELMER0_GPO, val); | ||
88 | |||
89 | cphy->elmer_gpo = val; | ||
90 | cphy->act_count = act_count; | ||
91 | cphy->count++; | ||
92 | |||
93 | return cphy_cause_link_change; | ||
94 | } | ||
95 | |||
96 | static void my3216_poll(void *arg) | ||
97 | { | ||
98 | my3126_interrupt_handler(arg); | ||
99 | } | ||
100 | |||
101 | static int my3126_set_loopback(struct cphy *cphy, int on) | ||
102 | { | ||
103 | return (0); | ||
104 | } | ||
105 | |||
106 | /* To check the activity LED */ | ||
107 | static int my3126_get_link_status(struct cphy *cphy, | ||
108 | int *link_ok, int *speed, int *duplex, int *fc) | ||
109 | { | ||
110 | u32 val; | ||
111 | u16 val16; | ||
112 | adapter_t *adapter; | ||
113 | |||
114 | adapter = cphy->adapter; | ||
115 | mdio_read(cphy, 0x1, 0x1, &val); | ||
116 | val16 = (u16) val; | ||
117 | |||
118 | /* Populate elmer_gpo with the register value */ | ||
119 | t1_tpi_read(adapter, A_ELMER0_GPO, &val); | ||
120 | cphy->elmer_gpo = val; | ||
121 | |||
122 | *link_ok = (val16 & BMSR_LSTATUS); | ||
123 | |||
124 | if (*link_ok) { | ||
125 | /* Turn on the LED. */ | ||
126 | if (is_T2(adapter)) | ||
127 | val &= ~(1 << 8); | ||
128 | else if (t1_is_T1B(adapter)) | ||
129 | val &= ~(1 << 19); | ||
130 | } else { | ||
131 | /* Turn off the LED. */ | ||
132 | if (is_T2(adapter)) | ||
133 | val |= (1 << 8); | ||
134 | else if (t1_is_T1B(adapter)) | ||
135 | val |= (1 << 19); | ||
136 | } | ||
137 | |||
138 | t1_tpi_write(adapter, A_ELMER0_GPO, val); | ||
139 | cphy->elmer_gpo = val; | ||
140 | *speed = SPEED_10000; | ||
141 | *duplex = DUPLEX_FULL; | ||
142 | |||
143 | /* need to add flow control */ | ||
144 | if (fc) | ||
145 | *fc = PAUSE_RX | PAUSE_TX; | ||
146 | |||
147 | return (0); | ||
148 | } | ||
149 | |||
150 | static void my3126_destroy(struct cphy *cphy) | ||
151 | { | ||
152 | kfree(cphy); | ||
153 | } | ||
154 | |||
155 | static struct cphy_ops my3126_ops = { | ||
156 | .destroy = my3126_destroy, | ||
157 | .reset = my3126_reset, | ||
158 | .interrupt_enable = my3126_interrupt_enable, | ||
159 | .interrupt_disable = my3126_interrupt_disable, | ||
160 | .interrupt_clear = my3126_interrupt_clear, | ||
161 | .interrupt_handler = my3126_interrupt_handler, | ||
162 | .get_link_status = my3126_get_link_status, | ||
163 | .set_loopback = my3126_set_loopback, | ||
164 | }; | ||
165 | |||
166 | static struct cphy *my3126_phy_create(adapter_t *adapter, | ||
167 | int phy_addr, struct mdio_ops *mdio_ops) | ||
168 | { | ||
169 | struct cphy *cphy = kzalloc(sizeof (*cphy), GFP_KERNEL); | ||
170 | |||
171 | if (cphy) | ||
172 | cphy_init(cphy, adapter, phy_addr, &my3126_ops, mdio_ops); | ||
173 | |||
174 | INIT_WORK(&cphy->phy_update, my3216_poll, cphy); | ||
175 | cphy->bmsr = 0; | ||
176 | |||
177 | return (cphy); | ||
178 | } | ||
179 | |||
180 | /* Chip Reset */ | ||
181 | static int my3126_phy_reset(adapter_t * adapter) | ||
182 | { | ||
183 | u32 val; | ||
184 | |||
185 | t1_tpi_read(adapter, A_ELMER0_GPO, &val); | ||
186 | val &= ~4; | ||
187 | t1_tpi_write(adapter, A_ELMER0_GPO, val); | ||
188 | msleep(100); | ||
189 | |||
190 | t1_tpi_write(adapter, A_ELMER0_GPO, val | 4); | ||
191 | msleep(1000); | ||
192 | |||
193 | /* Now lets enable the Laser. Delay 100us */ | ||
194 | t1_tpi_read(adapter, A_ELMER0_GPO, &val); | ||
195 | val |= 0x8000; | ||
196 | t1_tpi_write(adapter, A_ELMER0_GPO, val); | ||
197 | udelay(100); | ||
198 | return (0); | ||
199 | } | ||
200 | |||
201 | struct gphy t1_my3126_ops = { | ||
202 | my3126_phy_create, | ||
203 | my3126_phy_reset | ||
204 | }; | ||