blob: 2e0711a956cc903ee8d3868766c17beb38c00e34 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: lmc_media.c,v 1.13 2000/04/11 05:25:26 asj Exp $ */
2
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#include <linux/kernel.h>
4#include <linux/string.h>
5#include <linux/timer.h>
6#include <linux/ptrace.h>
7#include <linux/errno.h>
8#include <linux/ioport.h>
9#include <linux/slab.h>
10#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/in.h>
12#include <linux/if_arp.h>
13#include <linux/netdevice.h>
14#include <linux/etherdevice.h>
15#include <linux/skbuff.h>
16#include <linux/inet.h>
17#include <linux/bitops.h>
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/processor.h> /* Processor type for cache alignment. */
20#include <asm/io.h>
21#include <asm/dma.h>
22
23#include <asm/uaccess.h>
24
25#include "lmc.h"
26#include "lmc_var.h"
27#include "lmc_ioctl.h"
28#include "lmc_debug.h"
29
30#define CONFIG_LMC_IGNORE_HARDWARE_HANDSHAKE 1
31
32 /*
33 * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
34 * All rights reserved. www.lanmedia.com
35 *
36 * This code is written by:
37 * Andrew Stanley-Jones (asj@cban.com)
38 * Rob Braun (bbraun@vix.com),
39 * Michael Graff (explorer@vix.com) and
40 * Matt Thomas (matt@3am-software.com).
41 *
42 * This software may be used and distributed according to the terms
43 * of the GNU General Public License version 2, incorporated herein by reference.
44 */
45
46/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 * protocol independent method.
48 */
49static void lmc_set_protocol (lmc_softc_t * const, lmc_ctl_t *);
50
51/*
52 * media independent methods to check on media status, link, light LEDs,
53 * etc.
54 */
55static void lmc_ds3_init (lmc_softc_t * const);
56static void lmc_ds3_default (lmc_softc_t * const);
57static void lmc_ds3_set_status (lmc_softc_t * const, lmc_ctl_t *);
58static void lmc_ds3_set_100ft (lmc_softc_t * const, int);
59static int lmc_ds3_get_link_status (lmc_softc_t * const);
60static void lmc_ds3_set_crc_length (lmc_softc_t * const, int);
61static void lmc_ds3_set_scram (lmc_softc_t * const, int);
62static void lmc_ds3_watchdog (lmc_softc_t * const);
63
64static void lmc_hssi_init (lmc_softc_t * const);
65static void lmc_hssi_default (lmc_softc_t * const);
66static void lmc_hssi_set_status (lmc_softc_t * const, lmc_ctl_t *);
67static void lmc_hssi_set_clock (lmc_softc_t * const, int);
68static int lmc_hssi_get_link_status (lmc_softc_t * const);
69static void lmc_hssi_set_link_status (lmc_softc_t * const, int);
70static void lmc_hssi_set_crc_length (lmc_softc_t * const, int);
71static void lmc_hssi_watchdog (lmc_softc_t * const);
72
73static void lmc_ssi_init (lmc_softc_t * const);
74static void lmc_ssi_default (lmc_softc_t * const);
75static void lmc_ssi_set_status (lmc_softc_t * const, lmc_ctl_t *);
76static void lmc_ssi_set_clock (lmc_softc_t * const, int);
77static void lmc_ssi_set_speed (lmc_softc_t * const, lmc_ctl_t *);
78static int lmc_ssi_get_link_status (lmc_softc_t * const);
79static void lmc_ssi_set_link_status (lmc_softc_t * const, int);
80static void lmc_ssi_set_crc_length (lmc_softc_t * const, int);
81static void lmc_ssi_watchdog (lmc_softc_t * const);
82
83static void lmc_t1_init (lmc_softc_t * const);
84static void lmc_t1_default (lmc_softc_t * const);
85static void lmc_t1_set_status (lmc_softc_t * const, lmc_ctl_t *);
86static int lmc_t1_get_link_status (lmc_softc_t * const);
87static void lmc_t1_set_circuit_type (lmc_softc_t * const, int);
88static void lmc_t1_set_crc_length (lmc_softc_t * const, int);
89static void lmc_t1_set_clock (lmc_softc_t * const, int);
90static void lmc_t1_watchdog (lmc_softc_t * const);
91
92static void lmc_dummy_set_1 (lmc_softc_t * const, int);
93static void lmc_dummy_set2_1 (lmc_softc_t * const, lmc_ctl_t *);
94
95static inline void write_av9110_bit (lmc_softc_t *, int);
96static void write_av9110 (lmc_softc_t *, u_int32_t, u_int32_t, u_int32_t,
97 u_int32_t, u_int32_t);
98
99lmc_media_t lmc_ds3_media = {
100 lmc_ds3_init, /* special media init stuff */
101 lmc_ds3_default, /* reset to default state */
102 lmc_ds3_set_status, /* reset status to state provided */
103 lmc_dummy_set_1, /* set clock source */
104 lmc_dummy_set2_1, /* set line speed */
105 lmc_ds3_set_100ft, /* set cable length */
106 lmc_ds3_set_scram, /* set scrambler */
107 lmc_ds3_get_link_status, /* get link status */
108 lmc_dummy_set_1, /* set link status */
109 lmc_ds3_set_crc_length, /* set CRC length */
110 lmc_dummy_set_1, /* set T1 or E1 circuit type */
111 lmc_ds3_watchdog
112};
113
114lmc_media_t lmc_hssi_media = {
115 lmc_hssi_init, /* special media init stuff */
116 lmc_hssi_default, /* reset to default state */
117 lmc_hssi_set_status, /* reset status to state provided */
118 lmc_hssi_set_clock, /* set clock source */
119 lmc_dummy_set2_1, /* set line speed */
120 lmc_dummy_set_1, /* set cable length */
121 lmc_dummy_set_1, /* set scrambler */
122 lmc_hssi_get_link_status, /* get link status */
123 lmc_hssi_set_link_status, /* set link status */
124 lmc_hssi_set_crc_length, /* set CRC length */
125 lmc_dummy_set_1, /* set T1 or E1 circuit type */
126 lmc_hssi_watchdog
127};
128
129lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
130 lmc_ssi_default, /* reset to default state */
131 lmc_ssi_set_status, /* reset status to state provided */
132 lmc_ssi_set_clock, /* set clock source */
133 lmc_ssi_set_speed, /* set line speed */
134 lmc_dummy_set_1, /* set cable length */
135 lmc_dummy_set_1, /* set scrambler */
136 lmc_ssi_get_link_status, /* get link status */
137 lmc_ssi_set_link_status, /* set link status */
138 lmc_ssi_set_crc_length, /* set CRC length */
139 lmc_dummy_set_1, /* set T1 or E1 circuit type */
140 lmc_ssi_watchdog
141};
142
143lmc_media_t lmc_t1_media = {
144 lmc_t1_init, /* special media init stuff */
145 lmc_t1_default, /* reset to default state */
146 lmc_t1_set_status, /* reset status to state provided */
147 lmc_t1_set_clock, /* set clock source */
148 lmc_dummy_set2_1, /* set line speed */
149 lmc_dummy_set_1, /* set cable length */
150 lmc_dummy_set_1, /* set scrambler */
151 lmc_t1_get_link_status, /* get link status */
152 lmc_dummy_set_1, /* set link status */
153 lmc_t1_set_crc_length, /* set CRC length */
154 lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
155 lmc_t1_watchdog
156};
157
158static void
159lmc_dummy_set_1 (lmc_softc_t * const sc, int a)
160{
161}
162
163static void
164lmc_dummy_set2_1 (lmc_softc_t * const sc, lmc_ctl_t * a)
165{
166}
167
168/*
169 * HSSI methods
170 */
171
172static void
173lmc_hssi_init (lmc_softc_t * const sc)
174{
175 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC5200;
176
177 lmc_gpio_mkoutput (sc, LMC_GEP_HSSI_CLOCK);
178}
179
180static void
181lmc_hssi_default (lmc_softc_t * const sc)
182{
183 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
184
185 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
186 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
187 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
188}
189
190/*
191 * Given a user provided state, set ourselves up to match it. This will
192 * always reset the card if needed.
193 */
194static void
195lmc_hssi_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
196{
197 if (ctl == NULL)
198 {
199 sc->lmc_media->set_clock_source (sc, sc->ictl.clock_source);
200 lmc_set_protocol (sc, NULL);
201
202 return;
203 }
204
205 /*
206 * check for change in clock source
207 */
208 if (ctl->clock_source && !sc->ictl.clock_source)
209 {
210 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_INT);
211 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_INT;
212 }
213 else if (!ctl->clock_source && sc->ictl.clock_source)
214 {
215 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
216 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
217 }
218
219 lmc_set_protocol (sc, ctl);
220}
221
222/*
223 * 1 == internal, 0 == external
224 */
225static void
226lmc_hssi_set_clock (lmc_softc_t * const sc, int ie)
227{
228 int old;
229 old = sc->ictl.clock_source;
230 if (ie == LMC_CTL_CLOCK_SOURCE_EXT)
231 {
232 sc->lmc_gpio |= LMC_GEP_HSSI_CLOCK;
233 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
234 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_EXT;
235 if(old != ie)
236 printk (LMC_PRINTF_FMT ": clock external\n", LMC_PRINTF_ARGS);
237 }
238 else
239 {
240 sc->lmc_gpio &= ~(LMC_GEP_HSSI_CLOCK);
241 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
242 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
243 if(old != ie)
244 printk (LMC_PRINTF_FMT ": clock internal\n", LMC_PRINTF_ARGS);
245 }
246}
247
248/*
249 * return hardware link status.
250 * 0 == link is down, 1 == link is up.
251 */
252static int
253lmc_hssi_get_link_status (lmc_softc_t * const sc)
254{
255 /*
256 * We're using the same code as SSI since
257 * they're practically the same
258 */
259 return lmc_ssi_get_link_status(sc);
260}
261
262static void
263lmc_hssi_set_link_status (lmc_softc_t * const sc, int state)
264{
265 if (state == LMC_LINK_UP)
266 sc->lmc_miireg16 |= LMC_MII16_HSSI_TA;
267 else
268 sc->lmc_miireg16 &= ~LMC_MII16_HSSI_TA;
269
270 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
271}
272
273/*
274 * 0 == 16bit, 1 == 32bit
275 */
276static void
277lmc_hssi_set_crc_length (lmc_softc_t * const sc, int state)
278{
279 if (state == LMC_CTL_CRC_LENGTH_32)
280 {
281 /* 32 bit */
282 sc->lmc_miireg16 |= LMC_MII16_HSSI_CRC;
283 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
284 }
285 else
286 {
287 /* 16 bit */
288 sc->lmc_miireg16 &= ~LMC_MII16_HSSI_CRC;
289 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
290 }
291
292 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
293}
294
295static void
296lmc_hssi_watchdog (lmc_softc_t * const sc)
297{
298 /* HSSI is blank */
299}
300
301/*
302 * DS3 methods
303 */
304
305/*
306 * Set cable length
307 */
308static void
309lmc_ds3_set_100ft (lmc_softc_t * const sc, int ie)
310{
311 if (ie == LMC_CTL_CABLE_LENGTH_GT_100FT)
312 {
313 sc->lmc_miireg16 &= ~LMC_MII16_DS3_ZERO;
314 sc->ictl.cable_length = LMC_CTL_CABLE_LENGTH_GT_100FT;
315 }
316 else if (ie == LMC_CTL_CABLE_LENGTH_LT_100FT)
317 {
318 sc->lmc_miireg16 |= LMC_MII16_DS3_ZERO;
319 sc->ictl.cable_length = LMC_CTL_CABLE_LENGTH_LT_100FT;
320 }
321 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
322}
323
324static void
325lmc_ds3_default (lmc_softc_t * const sc)
326{
327 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
328
329 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
330 sc->lmc_media->set_cable_length (sc, LMC_CTL_CABLE_LENGTH_LT_100FT);
331 sc->lmc_media->set_scrambler (sc, LMC_CTL_OFF);
332 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
333}
334
335/*
336 * Given a user provided state, set ourselves up to match it. This will
337 * always reset the card if needed.
338 */
339static void
340lmc_ds3_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
341{
342 if (ctl == NULL)
343 {
344 sc->lmc_media->set_cable_length (sc, sc->ictl.cable_length);
345 sc->lmc_media->set_scrambler (sc, sc->ictl.scrambler_onoff);
346 lmc_set_protocol (sc, NULL);
347
348 return;
349 }
350
351 /*
352 * check for change in cable length setting
353 */
354 if (ctl->cable_length && !sc->ictl.cable_length)
355 lmc_ds3_set_100ft (sc, LMC_CTL_CABLE_LENGTH_GT_100FT);
356 else if (!ctl->cable_length && sc->ictl.cable_length)
357 lmc_ds3_set_100ft (sc, LMC_CTL_CABLE_LENGTH_LT_100FT);
358
359 /*
360 * Check for change in scrambler setting (requires reset)
361 */
362 if (ctl->scrambler_onoff && !sc->ictl.scrambler_onoff)
363 lmc_ds3_set_scram (sc, LMC_CTL_ON);
364 else if (!ctl->scrambler_onoff && sc->ictl.scrambler_onoff)
365 lmc_ds3_set_scram (sc, LMC_CTL_OFF);
366
367 lmc_set_protocol (sc, ctl);
368}
369
370static void
371lmc_ds3_init (lmc_softc_t * const sc)
372{
373 int i;
374
375 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC5245;
376
377 /* writes zeros everywhere */
378 for (i = 0; i < 21; i++)
379 {
380 lmc_mii_writereg (sc, 0, 17, i);
381 lmc_mii_writereg (sc, 0, 18, 0);
382 }
383
384 /* set some essential bits */
385 lmc_mii_writereg (sc, 0, 17, 1);
386 lmc_mii_writereg (sc, 0, 18, 0x25); /* ser, xtx */
387
388 lmc_mii_writereg (sc, 0, 17, 5);
389 lmc_mii_writereg (sc, 0, 18, 0x80); /* emode */
390
391 lmc_mii_writereg (sc, 0, 17, 14);
392 lmc_mii_writereg (sc, 0, 18, 0x30); /* rcgen, tcgen */
393
394 /* clear counters and latched bits */
395 for (i = 0; i < 21; i++)
396 {
397 lmc_mii_writereg (sc, 0, 17, i);
398 lmc_mii_readreg (sc, 0, 18);
399 }
400}
401
402/*
403 * 1 == DS3 payload scrambled, 0 == not scrambled
404 */
405static void
406lmc_ds3_set_scram (lmc_softc_t * const sc, int ie)
407{
408 if (ie == LMC_CTL_ON)
409 {
410 sc->lmc_miireg16 |= LMC_MII16_DS3_SCRAM;
411 sc->ictl.scrambler_onoff = LMC_CTL_ON;
412 }
413 else
414 {
415 sc->lmc_miireg16 &= ~LMC_MII16_DS3_SCRAM;
416 sc->ictl.scrambler_onoff = LMC_CTL_OFF;
417 }
418 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
419}
420
421/*
422 * return hardware link status.
423 * 0 == link is down, 1 == link is up.
424 */
425static int
426lmc_ds3_get_link_status (lmc_softc_t * const sc)
427{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200428 u16 link_status, link_status_11;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 int ret = 1;
430
431 lmc_mii_writereg (sc, 0, 17, 7);
432 link_status = lmc_mii_readreg (sc, 0, 18);
433
434 /* LMC5245 (DS3) & LMC1200 (DS1) LED definitions
435 * led0 yellow = far-end adapter is in Red alarm condition
436 * led1 blue = received an Alarm Indication signal
437 * (upstream failure)
438 * led2 Green = power to adapter, Gate Array loaded & driver
439 * attached
440 * led3 red = Loss of Signal (LOS) or out of frame (OOF)
441 * conditions detected on T3 receive signal
442 */
443
444 lmc_led_on(sc, LMC_DS3_LED2);
445
446 if ((link_status & LMC_FRAMER_REG0_DLOS) ||
447 (link_status & LMC_FRAMER_REG0_OOFS)){
448 ret = 0;
449 if(sc->last_led_err[3] != 1){
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200450 u16 r1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 lmc_mii_writereg (sc, 0, 17, 01); /* Turn on Xbit error as our cisco does */
452 r1 = lmc_mii_readreg (sc, 0, 18);
453 r1 &= 0xfe;
454 lmc_mii_writereg(sc, 0, 18, r1);
455 printk(KERN_WARNING "%s: Red Alarm - Loss of Signal or Loss of Framing\n", sc->name);
456 }
457 lmc_led_on(sc, LMC_DS3_LED3); /* turn on red LED */
458 sc->last_led_err[3] = 1;
459 }
460 else {
461 lmc_led_off(sc, LMC_DS3_LED3); /* turn on red LED */
462 if(sc->last_led_err[3] == 1){
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200463 u16 r1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 lmc_mii_writereg (sc, 0, 17, 01); /* Turn off Xbit error */
465 r1 = lmc_mii_readreg (sc, 0, 18);
466 r1 |= 0x01;
467 lmc_mii_writereg(sc, 0, 18, r1);
468 }
469 sc->last_led_err[3] = 0;
470 }
471
472 lmc_mii_writereg(sc, 0, 17, 0x10);
473 link_status_11 = lmc_mii_readreg(sc, 0, 18);
474 if((link_status & LMC_FRAMER_REG0_AIS) ||
475 (link_status_11 & LMC_FRAMER_REG10_XBIT)) {
476 ret = 0;
477 if(sc->last_led_err[0] != 1){
478 printk(KERN_WARNING "%s: AIS Alarm or XBit Error\n", sc->name);
479 printk(KERN_WARNING "%s: Remote end has loss of signal or framing\n", sc->name);
480 }
481 lmc_led_on(sc, LMC_DS3_LED0);
482 sc->last_led_err[0] = 1;
483 }
484 else {
485 lmc_led_off(sc, LMC_DS3_LED0);
486 sc->last_led_err[0] = 0;
487 }
488
489 lmc_mii_writereg (sc, 0, 17, 9);
490 link_status = lmc_mii_readreg (sc, 0, 18);
491
492 if(link_status & LMC_FRAMER_REG9_RBLUE){
493 ret = 0;
494 if(sc->last_led_err[1] != 1){
495 printk(KERN_WARNING "%s: Blue Alarm - Receiving all 1's\n", sc->name);
496 }
497 lmc_led_on(sc, LMC_DS3_LED1);
498 sc->last_led_err[1] = 1;
499 }
500 else {
501 lmc_led_off(sc, LMC_DS3_LED1);
502 sc->last_led_err[1] = 0;
503 }
504
505 return ret;
506}
507
508/*
509 * 0 == 16bit, 1 == 32bit
510 */
511static void
512lmc_ds3_set_crc_length (lmc_softc_t * const sc, int state)
513{
514 if (state == LMC_CTL_CRC_LENGTH_32)
515 {
516 /* 32 bit */
517 sc->lmc_miireg16 |= LMC_MII16_DS3_CRC;
518 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
519 }
520 else
521 {
522 /* 16 bit */
523 sc->lmc_miireg16 &= ~LMC_MII16_DS3_CRC;
524 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
525 }
526
527 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
528}
529
530static void
531lmc_ds3_watchdog (lmc_softc_t * const sc)
532{
533
534}
535
536
537/*
538 * SSI methods
539 */
540
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200541static void lmc_ssi_init(lmc_softc_t * const sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200543 u16 mii17;
544 int cable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200546 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200548 mii17 = lmc_mii_readreg(sc, 0, 17);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200550 cable = (mii17 & LMC_MII17_SSI_CABLE_MASK) >> LMC_MII17_SSI_CABLE_SHIFT;
551 sc->ictl.cable_type = cable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200553 lmc_gpio_mkoutput(sc, LMC_GEP_SSI_TXCLOCK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554}
555
556static void
557lmc_ssi_default (lmc_softc_t * const sc)
558{
559 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
560
561 /*
562 * make TXCLOCK always be an output
563 */
564 lmc_gpio_mkoutput (sc, LMC_GEP_SSI_TXCLOCK);
565
566 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
567 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
568 sc->lmc_media->set_speed (sc, NULL);
569 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
570}
571
572/*
573 * Given a user provided state, set ourselves up to match it. This will
574 * always reset the card if needed.
575 */
576static void
577lmc_ssi_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
578{
579 if (ctl == NULL)
580 {
581 sc->lmc_media->set_clock_source (sc, sc->ictl.clock_source);
582 sc->lmc_media->set_speed (sc, &sc->ictl);
583 lmc_set_protocol (sc, NULL);
584
585 return;
586 }
587
588 /*
589 * check for change in clock source
590 */
591 if (ctl->clock_source == LMC_CTL_CLOCK_SOURCE_INT
592 && sc->ictl.clock_source == LMC_CTL_CLOCK_SOURCE_EXT)
593 {
594 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_INT);
595 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_INT;
596 }
597 else if (ctl->clock_source == LMC_CTL_CLOCK_SOURCE_EXT
598 && sc->ictl.clock_source == LMC_CTL_CLOCK_SOURCE_INT)
599 {
600 sc->lmc_media->set_clock_source (sc, LMC_CTL_CLOCK_SOURCE_EXT);
601 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
602 }
603
604 if (ctl->clock_rate != sc->ictl.clock_rate)
605 sc->lmc_media->set_speed (sc, ctl);
606
607 lmc_set_protocol (sc, ctl);
608}
609
610/*
611 * 1 == internal, 0 == external
612 */
613static void
614lmc_ssi_set_clock (lmc_softc_t * const sc, int ie)
615{
616 int old;
617 old = ie;
618 if (ie == LMC_CTL_CLOCK_SOURCE_EXT)
619 {
620 sc->lmc_gpio &= ~(LMC_GEP_SSI_TXCLOCK);
621 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
622 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_EXT;
623 if(ie != old)
624 printk (LMC_PRINTF_FMT ": clock external\n", LMC_PRINTF_ARGS);
625 }
626 else
627 {
628 sc->lmc_gpio |= LMC_GEP_SSI_TXCLOCK;
629 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
630 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
631 if(ie != old)
632 printk (LMC_PRINTF_FMT ": clock internal\n", LMC_PRINTF_ARGS);
633 }
634}
635
636static void
637lmc_ssi_set_speed (lmc_softc_t * const sc, lmc_ctl_t * ctl)
638{
639 lmc_ctl_t *ictl = &sc->ictl;
640 lmc_av9110_t *av;
641
642 /* original settings for clock rate of:
643 * 100 Khz (8,25,0,0,2) were incorrect
644 * they should have been 80,125,1,3,3
645 * There are 17 param combinations to produce this freq.
646 * For 1.5 Mhz use 120,100,1,1,2 (226 param. combinations)
647 */
648 if (ctl == NULL)
649 {
650 av = &ictl->cardspec.ssi;
651 ictl->clock_rate = 1500000;
652 av->f = ictl->clock_rate;
653 av->n = 120;
654 av->m = 100;
655 av->v = 1;
656 av->x = 1;
657 av->r = 2;
658
659 write_av9110 (sc, av->n, av->m, av->v, av->x, av->r);
660 return;
661 }
662
663 av = &ctl->cardspec.ssi;
664
665 if (av->f == 0)
666 return;
667
668 ictl->clock_rate = av->f; /* really, this is the rate we are */
669 ictl->cardspec.ssi = *av;
670
671 write_av9110 (sc, av->n, av->m, av->v, av->x, av->r);
672}
673
674/*
675 * return hardware link status.
676 * 0 == link is down, 1 == link is up.
677 */
678static int
679lmc_ssi_get_link_status (lmc_softc_t * const sc)
680{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200681 u16 link_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 u_int32_t ticks;
683 int ret = 1;
684 int hw_hdsk = 1;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 /*
687 * missing CTS? Hmm. If we require CTS on, we may never get the
688 * link to come up, so omit it in this test.
689 *
690 * Also, it seems that with a loopback cable, DCD isn't asserted,
691 * so just check for things like this:
692 * DSR _must_ be asserted.
693 * One of DCD or CTS must be asserted.
694 */
695
696 /* LMC 1000 (SSI) LED definitions
697 * led0 Green = power to adapter, Gate Array loaded &
698 * driver attached
699 * led1 Green = DSR and DTR and RTS and CTS are set
700 * led2 Green = Cable detected
701 * led3 red = No timing is available from the
702 * cable or the on-board frequency
703 * generator.
704 */
705
706 link_status = lmc_mii_readreg (sc, 0, 16);
707
708 /* Is the transmit clock still available */
709 ticks = LMC_CSR_READ (sc, csr_gp_timer);
710 ticks = 0x0000ffff - (ticks & 0x0000ffff);
711
712 lmc_led_on (sc, LMC_MII16_LED0);
713
714 /* ====== transmit clock determination ===== */
715 if (sc->lmc_timing == LMC_CTL_CLOCK_SOURCE_INT) {
716 lmc_led_off(sc, LMC_MII16_LED3);
717 }
718 else if (ticks == 0 ) { /* no clock found ? */
719 ret = 0;
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200720 if (sc->last_led_err[3] != 1) {
721 sc->extra_stats.tx_lossOfClockCnt++;
722 printk(KERN_WARNING "%s: Lost Clock, Link Down\n", sc->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
724 sc->last_led_err[3] = 1;
725 lmc_led_on (sc, LMC_MII16_LED3); /* turn ON red LED */
726 }
727 else {
728 if(sc->last_led_err[3] == 1)
729 printk(KERN_WARNING "%s: Clock Returned\n", sc->name);
730 sc->last_led_err[3] = 0;
731 lmc_led_off (sc, LMC_MII16_LED3); /* turn OFF red LED */
732 }
733
734 if ((link_status & LMC_MII16_SSI_DSR) == 0) { /* Also HSSI CA */
735 ret = 0;
736 hw_hdsk = 0;
737 }
738
739#ifdef CONFIG_LMC_IGNORE_HARDWARE_HANDSHAKE
740 if ((link_status & (LMC_MII16_SSI_CTS | LMC_MII16_SSI_DCD)) == 0){
741 ret = 0;
742 hw_hdsk = 0;
743 }
744#endif
745
746 if(hw_hdsk == 0){
747 if(sc->last_led_err[1] != 1)
748 printk(KERN_WARNING "%s: DSR not asserted\n", sc->name);
749 sc->last_led_err[1] = 1;
750 lmc_led_off(sc, LMC_MII16_LED1);
751 }
752 else {
753 if(sc->last_led_err[1] != 0)
754 printk(KERN_WARNING "%s: DSR now asserted\n", sc->name);
755 sc->last_led_err[1] = 0;
756 lmc_led_on(sc, LMC_MII16_LED1);
757 }
758
759 if(ret == 1) {
760 lmc_led_on(sc, LMC_MII16_LED2); /* Over all good status? */
761 }
762
763 return ret;
764}
765
766static void
767lmc_ssi_set_link_status (lmc_softc_t * const sc, int state)
768{
769 if (state == LMC_LINK_UP)
770 {
771 sc->lmc_miireg16 |= (LMC_MII16_SSI_DTR | LMC_MII16_SSI_RTS);
772 printk (LMC_PRINTF_FMT ": asserting DTR and RTS\n", LMC_PRINTF_ARGS);
773 }
774 else
775 {
776 sc->lmc_miireg16 &= ~(LMC_MII16_SSI_DTR | LMC_MII16_SSI_RTS);
777 printk (LMC_PRINTF_FMT ": deasserting DTR and RTS\n", LMC_PRINTF_ARGS);
778 }
779
780 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
781
782}
783
784/*
785 * 0 == 16bit, 1 == 32bit
786 */
787static void
788lmc_ssi_set_crc_length (lmc_softc_t * const sc, int state)
789{
790 if (state == LMC_CTL_CRC_LENGTH_32)
791 {
792 /* 32 bit */
793 sc->lmc_miireg16 |= LMC_MII16_SSI_CRC;
794 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
795 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_4;
796
797 }
798 else
799 {
800 /* 16 bit */
801 sc->lmc_miireg16 &= ~LMC_MII16_SSI_CRC;
802 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
803 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_2;
804 }
805
806 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
807}
808
809/*
810 * These are bits to program the ssi frequency generator
811 */
812static inline void
813write_av9110_bit (lmc_softc_t * sc, int c)
814{
815 /*
816 * set the data bit as we need it.
817 */
818 sc->lmc_gpio &= ~(LMC_GEP_CLK);
819 if (c & 0x01)
820 sc->lmc_gpio |= LMC_GEP_DATA;
821 else
822 sc->lmc_gpio &= ~(LMC_GEP_DATA);
823 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
824
825 /*
826 * set the clock to high
827 */
828 sc->lmc_gpio |= LMC_GEP_CLK;
829 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
830
831 /*
832 * set the clock to low again.
833 */
834 sc->lmc_gpio &= ~(LMC_GEP_CLK);
835 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
836}
837
838static void
839write_av9110 (lmc_softc_t * sc, u_int32_t n, u_int32_t m, u_int32_t v,
840 u_int32_t x, u_int32_t r)
841{
842 int i;
843
844#if 0
845 printk (LMC_PRINTF_FMT ": speed %u, %d %d %d %d %d\n",
846 LMC_PRINTF_ARGS, sc->ictl.clock_rate, n, m, v, x, r);
847#endif
848
849 sc->lmc_gpio |= LMC_GEP_SSI_GENERATOR;
850 sc->lmc_gpio &= ~(LMC_GEP_DATA | LMC_GEP_CLK);
851 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
852
853 /*
854 * Set the TXCLOCK, GENERATOR, SERIAL, and SERIALCLK
855 * as outputs.
856 */
857 lmc_gpio_mkoutput (sc, (LMC_GEP_DATA | LMC_GEP_CLK
858 | LMC_GEP_SSI_GENERATOR));
859
860 sc->lmc_gpio &= ~(LMC_GEP_SSI_GENERATOR);
861 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
862
863 /*
864 * a shifting we will go...
865 */
866 for (i = 0; i < 7; i++)
867 write_av9110_bit (sc, n >> i);
868 for (i = 0; i < 7; i++)
869 write_av9110_bit (sc, m >> i);
870 for (i = 0; i < 1; i++)
871 write_av9110_bit (sc, v >> i);
872 for (i = 0; i < 2; i++)
873 write_av9110_bit (sc, x >> i);
874 for (i = 0; i < 2; i++)
875 write_av9110_bit (sc, r >> i);
876 for (i = 0; i < 5; i++)
877 write_av9110_bit (sc, 0x17 >> i);
878
879 /*
880 * stop driving serial-related signals
881 */
882 lmc_gpio_mkinput (sc,
883 (LMC_GEP_DATA | LMC_GEP_CLK
884 | LMC_GEP_SSI_GENERATOR));
885}
886
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200887static void lmc_ssi_watchdog(lmc_softc_t * const sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200889 u16 mii17 = lmc_mii_readreg(sc, 0, 17);
890 if (((mii17 >> 3) & 7) == 7)
891 lmc_led_off(sc, LMC_MII16_LED2);
892 else
893 lmc_led_on(sc, LMC_MII16_LED2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894}
895
896/*
897 * T1 methods
898 */
899
900/*
901 * The framer regs are multiplexed through MII regs 17 & 18
902 * write the register address to MII reg 17 and the * data to MII reg 18. */
903static void
904lmc_t1_write (lmc_softc_t * const sc, int a, int d)
905{
906 lmc_mii_writereg (sc, 0, 17, a);
907 lmc_mii_writereg (sc, 0, 18, d);
908}
909
910/* Save a warning
911static int
912lmc_t1_read (lmc_softc_t * const sc, int a)
913{
914 lmc_mii_writereg (sc, 0, 17, a);
915 return lmc_mii_readreg (sc, 0, 18);
916}
917*/
918
919
920static void
921lmc_t1_init (lmc_softc_t * const sc)
922{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +0200923 u16 mii16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 int i;
925
926 sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC1200;
927 mii16 = lmc_mii_readreg (sc, 0, 16);
928
929 /* reset 8370 */
930 mii16 &= ~LMC_MII16_T1_RST;
931 lmc_mii_writereg (sc, 0, 16, mii16 | LMC_MII16_T1_RST);
932 lmc_mii_writereg (sc, 0, 16, mii16);
933
934 /* set T1 or E1 line. Uses sc->lmcmii16 reg in function so update it */
935 sc->lmc_miireg16 = mii16;
936 lmc_t1_set_circuit_type(sc, LMC_CTL_CIRCUIT_TYPE_T1);
937 mii16 = sc->lmc_miireg16;
938
939 lmc_t1_write (sc, 0x01, 0x1B); /* CR0 - primary control */
940 lmc_t1_write (sc, 0x02, 0x42); /* JAT_CR - jitter atten config */
941 lmc_t1_write (sc, 0x14, 0x00); /* LOOP - loopback config */
942 lmc_t1_write (sc, 0x15, 0x00); /* DL3_TS - external data link timeslot */
943 lmc_t1_write (sc, 0x18, 0xFF); /* PIO - programmable I/O */
944 lmc_t1_write (sc, 0x19, 0x30); /* POE - programmable OE */
945 lmc_t1_write (sc, 0x1A, 0x0F); /* CMUX - clock input mux */
946 lmc_t1_write (sc, 0x20, 0x41); /* LIU_CR - RX LIU config */
947 lmc_t1_write (sc, 0x22, 0x76); /* RLIU_CR - RX LIU config */
948 lmc_t1_write (sc, 0x40, 0x03); /* RCR0 - RX config */
949 lmc_t1_write (sc, 0x45, 0x00); /* RALM - RX alarm config */
950 lmc_t1_write (sc, 0x46, 0x05); /* LATCH - RX alarm/err/cntr latch */
951 lmc_t1_write (sc, 0x68, 0x40); /* TLIU_CR - TX LIU config */
952 lmc_t1_write (sc, 0x70, 0x0D); /* TCR0 - TX framer config */
953 lmc_t1_write (sc, 0x71, 0x05); /* TCR1 - TX config */
954 lmc_t1_write (sc, 0x72, 0x0B); /* TFRM - TX frame format */
955 lmc_t1_write (sc, 0x73, 0x00); /* TERROR - TX error insert */
956 lmc_t1_write (sc, 0x74, 0x00); /* TMAN - TX manual Sa/FEBE config */
957 lmc_t1_write (sc, 0x75, 0x00); /* TALM - TX alarm signal config */
958 lmc_t1_write (sc, 0x76, 0x00); /* TPATT - TX test pattern config */
959 lmc_t1_write (sc, 0x77, 0x00); /* TLB - TX inband loopback config */
960 lmc_t1_write (sc, 0x90, 0x05); /* CLAD_CR - clock rate adapter config */
961 lmc_t1_write (sc, 0x91, 0x05); /* CSEL - clad freq sel */
962 lmc_t1_write (sc, 0xA6, 0x00); /* DL1_CTL - DL1 control */
963 lmc_t1_write (sc, 0xB1, 0x00); /* DL2_CTL - DL2 control */
964 lmc_t1_write (sc, 0xD0, 0x47); /* SBI_CR - sys bus iface config */
965 lmc_t1_write (sc, 0xD1, 0x70); /* RSB_CR - RX sys bus config */
966 lmc_t1_write (sc, 0xD4, 0x30); /* TSB_CR - TX sys bus config */
967 for (i = 0; i < 32; i++)
968 {
969 lmc_t1_write (sc, 0x0E0 + i, 0x00); /* SBCn - sys bus per-channel ctl */
970 lmc_t1_write (sc, 0x100 + i, 0x00); /* TPCn - TX per-channel ctl */
971 lmc_t1_write (sc, 0x180 + i, 0x00); /* RPCn - RX per-channel ctl */
972 }
973 for (i = 1; i < 25; i++)
974 {
975 lmc_t1_write (sc, 0x0E0 + i, 0x0D); /* SBCn - sys bus per-channel ctl */
976 }
977
978 mii16 |= LMC_MII16_T1_XOE;
979 lmc_mii_writereg (sc, 0, 16, mii16);
980 sc->lmc_miireg16 = mii16;
981}
982
983static void
984lmc_t1_default (lmc_softc_t * const sc)
985{
986 sc->lmc_miireg16 = LMC_MII16_LED_ALL;
987 sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN);
988 sc->lmc_media->set_circuit_type (sc, LMC_CTL_CIRCUIT_TYPE_T1);
989 sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16);
990 /* Right now we can only clock from out internal source */
991 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
992}
993/* * Given a user provided state, set ourselves up to match it. This will * always reset the card if needed.
994 */
995static void
996lmc_t1_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl)
997{
998 if (ctl == NULL)
999 {
1000 sc->lmc_media->set_circuit_type (sc, sc->ictl.circuit_type);
1001 lmc_set_protocol (sc, NULL);
1002
1003 return;
1004 }
1005 /*
1006 * check for change in circuit type */
1007 if (ctl->circuit_type == LMC_CTL_CIRCUIT_TYPE_T1
1008 && sc->ictl.circuit_type ==
1009 LMC_CTL_CIRCUIT_TYPE_E1) sc->lmc_media->set_circuit_type (sc,
1010 LMC_CTL_CIRCUIT_TYPE_E1);
1011 else if (ctl->circuit_type == LMC_CTL_CIRCUIT_TYPE_E1
1012 && sc->ictl.circuit_type == LMC_CTL_CIRCUIT_TYPE_T1)
1013 sc->lmc_media->set_circuit_type (sc, LMC_CTL_CIRCUIT_TYPE_T1);
1014 lmc_set_protocol (sc, ctl);
1015}
1016/*
1017 * return hardware link status.
1018 * 0 == link is down, 1 == link is up.
1019 */ static int
1020lmc_t1_get_link_status (lmc_softc_t * const sc)
1021{
Krzysztof Hałasa64bef762008-07-02 20:46:21 +02001022 u16 link_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 int ret = 1;
1024
1025 /* LMC5245 (DS3) & LMC1200 (DS1) LED definitions
1026 * led0 yellow = far-end adapter is in Red alarm condition
1027 * led1 blue = received an Alarm Indication signal
1028 * (upstream failure)
1029 * led2 Green = power to adapter, Gate Array loaded & driver
1030 * attached
1031 * led3 red = Loss of Signal (LOS) or out of frame (OOF)
1032 * conditions detected on T3 receive signal
1033 */
1034 lmc_trace(sc->lmc_device, "lmc_t1_get_link_status in");
1035 lmc_led_on(sc, LMC_DS3_LED2);
1036
1037 lmc_mii_writereg (sc, 0, 17, T1FRAMER_ALARM1_STATUS);
1038 link_status = lmc_mii_readreg (sc, 0, 18);
1039
1040
1041 if (link_status & T1F_RAIS) { /* turn on blue LED */
1042 ret = 0;
1043 if(sc->last_led_err[1] != 1){
1044 printk(KERN_WARNING "%s: Receive AIS/Blue Alarm. Far end in RED alarm\n", sc->name);
1045 }
1046 lmc_led_on(sc, LMC_DS3_LED1);
1047 sc->last_led_err[1] = 1;
1048 }
1049 else {
1050 if(sc->last_led_err[1] != 0){
1051 printk(KERN_WARNING "%s: End AIS/Blue Alarm\n", sc->name);
1052 }
1053 lmc_led_off (sc, LMC_DS3_LED1);
1054 sc->last_led_err[1] = 0;
1055 }
1056
1057 /*
1058 * Yellow Alarm is nasty evil stuff, looks at data patterns
1059 * inside the channel and confuses it with HDLC framing
1060 * ignore all yellow alarms.
1061 *
1062 * Do listen to MultiFrame Yellow alarm which while implemented
1063 * different ways isn't in the channel and hence somewhat
1064 * more reliable
1065 */
1066
1067 if (link_status & T1F_RMYEL) {
1068 ret = 0;
1069 if(sc->last_led_err[0] != 1){
1070 printk(KERN_WARNING "%s: Receive Yellow AIS Alarm\n", sc->name);
1071 }
1072 lmc_led_on(sc, LMC_DS3_LED0);
1073 sc->last_led_err[0] = 1;
1074 }
1075 else {
1076 if(sc->last_led_err[0] != 0){
1077 printk(KERN_WARNING "%s: End of Yellow AIS Alarm\n", sc->name);
1078 }
1079 lmc_led_off(sc, LMC_DS3_LED0);
1080 sc->last_led_err[0] = 0;
1081 }
1082
1083 /*
1084 * Loss of signal and los of frame
1085 * Use the green bit to identify which one lit the led
1086 */
1087 if(link_status & T1F_RLOF){
1088 ret = 0;
1089 if(sc->last_led_err[3] != 1){
1090 printk(KERN_WARNING "%s: Local Red Alarm: Loss of Framing\n", sc->name);
1091 }
1092 lmc_led_on(sc, LMC_DS3_LED3);
1093 sc->last_led_err[3] = 1;
1094
1095 }
1096 else {
1097 if(sc->last_led_err[3] != 0){
1098 printk(KERN_WARNING "%s: End Red Alarm (LOF)\n", sc->name);
1099 }
1100 if( ! (link_status & T1F_RLOS))
1101 lmc_led_off(sc, LMC_DS3_LED3);
1102 sc->last_led_err[3] = 0;
1103 }
1104
1105 if(link_status & T1F_RLOS){
1106 ret = 0;
1107 if(sc->last_led_err[2] != 1){
1108 printk(KERN_WARNING "%s: Local Red Alarm: Loss of Signal\n", sc->name);
1109 }
1110 lmc_led_on(sc, LMC_DS3_LED3);
1111 sc->last_led_err[2] = 1;
1112
1113 }
1114 else {
1115 if(sc->last_led_err[2] != 0){
1116 printk(KERN_WARNING "%s: End Red Alarm (LOS)\n", sc->name);
1117 }
1118 if( ! (link_status & T1F_RLOF))
1119 lmc_led_off(sc, LMC_DS3_LED3);
1120 sc->last_led_err[2] = 0;
1121 }
1122
1123 sc->lmc_xinfo.t1_alarm1_status = link_status;
1124
1125 lmc_mii_writereg (sc, 0, 17, T1FRAMER_ALARM2_STATUS);
1126 sc->lmc_xinfo.t1_alarm2_status = lmc_mii_readreg (sc, 0, 18);
1127
1128
1129 lmc_trace(sc->lmc_device, "lmc_t1_get_link_status out");
1130
1131 return ret;
1132}
1133
1134/*
1135 * 1 == T1 Circuit Type , 0 == E1 Circuit Type
1136 */
1137static void
1138lmc_t1_set_circuit_type (lmc_softc_t * const sc, int ie)
1139{
1140 if (ie == LMC_CTL_CIRCUIT_TYPE_T1) {
1141 sc->lmc_miireg16 |= LMC_MII16_T1_Z;
1142 sc->ictl.circuit_type = LMC_CTL_CIRCUIT_TYPE_T1;
1143 printk(KERN_INFO "%s: In T1 Mode\n", sc->name);
1144 }
1145 else {
1146 sc->lmc_miireg16 &= ~LMC_MII16_T1_Z;
1147 sc->ictl.circuit_type = LMC_CTL_CIRCUIT_TYPE_E1;
1148 printk(KERN_INFO "%s: In E1 Mode\n", sc->name);
1149 }
1150
1151 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
1152
1153}
1154
1155/*
1156 * 0 == 16bit, 1 == 32bit */
1157static void
1158lmc_t1_set_crc_length (lmc_softc_t * const sc, int state)
1159{
1160 if (state == LMC_CTL_CRC_LENGTH_32)
1161 {
1162 /* 32 bit */
1163 sc->lmc_miireg16 |= LMC_MII16_T1_CRC;
1164 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32;
1165 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_4;
1166
1167 }
1168 else
1169 {
1170 /* 16 bit */ sc->lmc_miireg16 &= ~LMC_MII16_T1_CRC;
1171 sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16;
1172 sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_2;
1173
1174 }
1175
1176 lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);
1177}
1178
1179/*
1180 * 1 == internal, 0 == external
1181 */
1182static void
1183lmc_t1_set_clock (lmc_softc_t * const sc, int ie)
1184{
1185 int old;
1186 old = ie;
1187 if (ie == LMC_CTL_CLOCK_SOURCE_EXT)
1188 {
1189 sc->lmc_gpio &= ~(LMC_GEP_SSI_TXCLOCK);
1190 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
1191 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_EXT;
1192 if(old != ie)
1193 printk (LMC_PRINTF_FMT ": clock external\n", LMC_PRINTF_ARGS);
1194 }
1195 else
1196 {
1197 sc->lmc_gpio |= LMC_GEP_SSI_TXCLOCK;
1198 LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);
1199 sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;
1200 if(old != ie)
1201 printk (LMC_PRINTF_FMT ": clock internal\n", LMC_PRINTF_ARGS);
1202 }
1203}
1204
1205static void
1206lmc_t1_watchdog (lmc_softc_t * const sc)
1207{
1208}
1209
1210static void
1211lmc_set_protocol (lmc_softc_t * const sc, lmc_ctl_t * ctl)
1212{
Al Viro79ea13c2008-01-24 02:06:46 -08001213 if (!ctl)
1214 sc->ictl.keepalive_onoff = LMC_CTL_ON;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}