mhzc.c revision 1.34.8.3 1 /* $NetBSD: mhzc.c,v 1.34.8.3 2006/09/14 12:31:39 yamt Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2000, 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, and by Charles M. Hannum.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Device driver for the Megaherz X-JACK Ethernet/Modem combo cards.
42 *
43 * Many thanks to Chuck Cranor for having the patience to sift through
44 * the Linux smc91c92_cs.c driver to find the magic details to get this
45 * working!
46 */
47
48 #include <sys/cdefs.h>
49 __KERNEL_RCSID(0, "$NetBSD: mhzc.c,v 1.34.8.3 2006/09/14 12:31:39 yamt Exp $");
50
51 #include "opt_inet.h"
52 #include "bpfilter.h"
53
54 #include <sys/param.h>
55 #include <sys/systm.h>
56 #include <sys/mbuf.h>
57 #include <sys/socket.h>
58 #include <sys/ioctl.h>
59 #include <sys/errno.h>
60 #include <sys/syslog.h>
61 #include <sys/select.h>
62 #include <sys/tty.h>
63 #include <sys/device.h>
64 #include <sys/kernel.h>
65 #include <sys/proc.h>
66
67 #include <net/if.h>
68 #include <net/if_dl.h>
69 #include <net/if_ether.h>
70 #include <net/if_media.h>
71
72 #ifdef INET
73 #include <netinet/in.h>
74 #include <netinet/in_systm.h>
75 #include <netinet/in_var.h>
76 #include <netinet/ip.h>
77 #include <netinet/if_inarp.h>
78 #endif
79
80
81 #if NBPFILTER > 0
82 #include <net/bpf.h>
83 #include <net/bpfdesc.h>
84 #endif
85
86 #include <machine/intr.h>
87 #include <machine/bus.h>
88
89 #include <dev/ic/comreg.h>
90 #include <dev/ic/comvar.h>
91
92 #include <dev/mii/mii.h>
93 #include <dev/mii/miivar.h>
94
95 #include <dev/ic/smc91cxxreg.h>
96 #include <dev/ic/smc91cxxvar.h>
97
98 #include <dev/pcmcia/pcmciareg.h>
99 #include <dev/pcmcia/pcmciavar.h>
100 #include <dev/pcmcia/pcmciadevs.h>
101
102 #include "mhzc.h"
103
104 struct mhzc_softc {
105 struct device sc_dev; /* generic device glue */
106
107 struct pcmcia_function *sc_pf; /* our PCMCIA function */
108 void *sc_ih; /* interrupt handle */
109
110 const struct mhzc_product *sc_product;
111
112 /*
113 * Data for the Modem portion.
114 */
115 struct device *sc_modem;
116 struct pcmcia_io_handle sc_modem_pcioh;
117 int sc_modem_io_window;
118
119 /*
120 * Data for the Ethernet portion.
121 */
122 struct device *sc_ethernet;
123 struct pcmcia_io_handle sc_ethernet_pcioh;
124 int sc_ethernet_io_window;
125
126 int sc_flags;
127 };
128
129 /* sc_flags */
130 #define MHZC_MODEM_MAPPED 0x01
131 #define MHZC_ETHERNET_MAPPED 0x02
132 #define MHZC_MODEM_ENABLED 0x04
133 #define MHZC_ETHERNET_ENABLED 0x08
134 #define MHZC_MODEM_ALLOCED 0x10
135 #define MHZC_ETHERNET_ALLOCED 0x20
136
137 int mhzc_match(struct device *, struct cfdata *, void *);
138 void mhzc_attach(struct device *, struct device *, void *);
139 int mhzc_detach(struct device *, int);
140 int mhzc_activate(struct device *, enum devact);
141
142 CFATTACH_DECL(mhzc, sizeof(struct mhzc_softc),
143 mhzc_match, mhzc_attach, mhzc_detach, mhzc_activate);
144
145 int mhzc_em3336_enaddr(struct mhzc_softc *, u_int8_t *);
146 int mhzc_em3336_enable(struct mhzc_softc *);
147
148 const struct mhzc_product {
149 struct pcmcia_product mp_product;
150
151 /* Get the Ethernet address for this card. */
152 int (*mp_enaddr)(struct mhzc_softc *, u_int8_t *);
153
154 /* Perform any special `enable' magic. */
155 int (*mp_enable)(struct mhzc_softc *);
156 } mhzc_products[] = {
157 { { PCMCIA_VENDOR_MEGAHERTZ, PCMCIA_PRODUCT_MEGAHERTZ_EM3336,
158 PCMCIA_CIS_INVALID },
159 mhzc_em3336_enaddr, mhzc_em3336_enable },
160 };
161 static const size_t mhzc_nproducts =
162 sizeof(mhzc_products) / sizeof(mhzc_products[0]);
163
164 int mhzc_print(void *, const char *);
165
166 int mhzc_check_cfe(struct mhzc_softc *, struct pcmcia_config_entry *);
167 int mhzc_alloc_ethernet(struct mhzc_softc *, struct pcmcia_config_entry *);
168
169 int mhzc_enable(struct mhzc_softc *, int);
170 void mhzc_disable(struct mhzc_softc *, int);
171
172 int mhzc_intr(void *);
173
174 int
175 mhzc_match(parent, match, aux)
176 struct device *parent;
177 struct cfdata *match;
178 void *aux;
179 {
180 struct pcmcia_attach_args *pa = aux;
181
182 if (pcmcia_product_lookup(pa, mhzc_products, mhzc_nproducts,
183 sizeof(mhzc_products[0]), NULL))
184 return (2); /* beat `com' */
185 return (0);
186 }
187
188 void
189 mhzc_attach(parent, self, aux)
190 struct device *parent, *self;
191 void *aux;
192 {
193 struct mhzc_softc *sc = (void *)self;
194 struct pcmcia_attach_args *pa = aux;
195 struct pcmcia_config_entry *cfe;
196 int error;
197
198 sc->sc_pf = pa->pf;
199
200 sc->sc_product = pcmcia_product_lookup(pa, mhzc_products,
201 mhzc_nproducts, sizeof(mhzc_products[0]), NULL);
202 if (!sc->sc_product)
203 panic("mhzc_attach: impossible");
204
205 /*
206 * The address decoders on these cards are wacky. The configuration
207 * entries are set up to look like serial ports, and have no
208 * information about the Ethernet portion. In order to talk to
209 * the Modem portion, the I/O address must have bit 0x80 set.
210 * In order to talk to the Ethernet portion, the I/O address must
211 * have the 0x80 bit clear.
212 *
213 * The standard configuration entries conveniently have 0x80 set
214 * in them, and have a length of 8 (a 16550's size, convenient!),
215 * so we use those to set up the Modem portion.
216 *
217 * Once we have the Modem's address established, we search for
218 * an address suitable for the Ethernet portion. We do this by
219 * rounding up to the next 16-byte aligned address where 0x80
220 * isn't set (the SMC Ethernet chip has a 16-byte address size)
221 * and attemping to allocate a 16-byte region until we succeed.
222 *
223 * Sure would have been nice if Megahertz had made the card a
224 * proper multi-function device.
225 */
226 SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
227 if (mhzc_check_cfe(sc, cfe)) {
228 /* Found one! */
229 break;
230 }
231 }
232 if (cfe == NULL) {
233 aprint_error("%s: unable to find suitable config table entry\n",
234 self->dv_xname);
235 goto fail;
236 }
237
238 if (mhzc_alloc_ethernet(sc, cfe) == 0) {
239 aprint_error("%s: unable to allocate space for Ethernet portion\n",
240 self->dv_xname);
241 goto fail;
242 }
243
244 /* Enable the card. */
245 pcmcia_function_init(pa->pf, cfe);
246
247 if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_IO8, &sc->sc_modem_pcioh,
248 &sc->sc_modem_io_window)) {
249 aprint_error("%s: unable to map I/O space\n",
250 sc->sc_dev.dv_xname);
251 goto fail;
252 }
253 sc->sc_flags |= MHZC_MODEM_MAPPED;
254
255 if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_AUTO, &sc->sc_ethernet_pcioh,
256 &sc->sc_ethernet_io_window)) {
257 aprint_error("%s: unable to map I/O space\n",
258 sc->sc_dev.dv_xname);
259 goto fail;
260 }
261 sc->sc_flags |= MHZC_ETHERNET_MAPPED;
262
263 error = mhzc_enable(sc, MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED);
264 if (error)
265 goto fail;
266
267 /*XXXUNCONST*/
268 sc->sc_modem = config_found(self, __UNCONST("com"), mhzc_print);
269 /*XXXUNCONST*/
270 sc->sc_ethernet = config_found(self, __UNCONST("sm"), mhzc_print);
271
272 mhzc_disable(sc, MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED);
273 return;
274
275 fail:
276 /* I/O spaces will be freed by detach. */
277 ;
278 }
279
280 int
281 mhzc_check_cfe(sc, cfe)
282 struct mhzc_softc *sc;
283 struct pcmcia_config_entry *cfe;
284 {
285
286 if (cfe->num_memspace != 0)
287 return (0);
288
289 if (cfe->num_iospace != 1)
290 return (0);
291
292 if (pcmcia_io_alloc(sc->sc_pf,
293 cfe->iospace[0].start,
294 cfe->iospace[0].length,
295 cfe->iospace[0].length,
296 &sc->sc_modem_pcioh) == 0) {
297 /* Found one for the modem! */
298 sc->sc_flags |= MHZC_MODEM_ALLOCED;
299 return (1);
300 }
301
302 return (0);
303 }
304
305 int
306 mhzc_alloc_ethernet(sc, cfe)
307 struct mhzc_softc *sc;
308 struct pcmcia_config_entry *cfe;
309 {
310 bus_addr_t addr, maxaddr;
311
312 addr = cfe->iospace[0].start + cfe->iospace[0].length;
313 maxaddr = 0x1000;
314
315 /*
316 * Now round it up so that it starts on a 16-byte boundary.
317 */
318 addr = roundup(addr, 0x10);
319
320 for (; (addr + 0x10) < maxaddr; addr += 0x10) {
321 if (addr & 0x80)
322 continue;
323 if (pcmcia_io_alloc(sc->sc_pf, addr, 0x10, 0x10,
324 &sc->sc_ethernet_pcioh) == 0) {
325 /* Found one for the ethernet! */
326 sc->sc_flags |= MHZC_ETHERNET_ALLOCED;
327 return (1);
328 }
329 }
330
331 return (0);
332 }
333
334 int
335 mhzc_print(aux, pnp)
336 void *aux;
337 const char *pnp;
338 {
339 const char *name = aux;
340
341 if (pnp)
342 aprint_normal("%s at %s(*)", name, pnp);
343
344 return (UNCONF);
345 }
346
347 int
348 mhzc_detach(self, flags)
349 struct device *self;
350 int flags;
351 {
352 struct mhzc_softc *sc = (void *)self;
353 int rv;
354
355 if (sc->sc_ethernet != NULL) {
356 rv = config_detach(sc->sc_ethernet, flags);
357 if (rv != 0)
358 return (rv);
359 sc->sc_ethernet = NULL;
360 }
361
362 if (sc->sc_modem != NULL) {
363 rv = config_detach(sc->sc_modem, flags);
364 if (rv != 0)
365 return (rv);
366 sc->sc_modem = NULL;
367 }
368
369 /* Unmap our i/o windows. */
370 if (sc->sc_flags & MHZC_MODEM_MAPPED)
371 pcmcia_io_unmap(sc->sc_pf, sc->sc_modem_io_window);
372 if (sc->sc_flags & MHZC_ETHERNET_MAPPED)
373 pcmcia_io_unmap(sc->sc_pf, sc->sc_ethernet_io_window);
374
375 /* Free our i/o spaces. */
376 if (sc->sc_flags & MHZC_ETHERNET_ALLOCED)
377 pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
378 if (sc->sc_flags & MHZC_MODEM_ALLOCED)
379 pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh);
380
381 sc->sc_flags = 0;
382
383 return (0);
384 }
385
386 int
387 mhzc_activate(self, act)
388 struct device *self;
389 enum devact act;
390 {
391 struct mhzc_softc *sc = (void *)self;
392 int s, rv = 0;
393
394 s = splhigh();
395 switch (act) {
396 case DVACT_ACTIVATE:
397 rv = EOPNOTSUPP;
398 break;
399
400 case DVACT_DEACTIVATE:
401 if (sc->sc_ethernet != NULL) {
402 rv = config_deactivate(sc->sc_ethernet);
403 if (rv != 0)
404 goto out;
405 }
406
407 if (sc->sc_modem != NULL) {
408 rv = config_deactivate(sc->sc_modem);
409 if (rv != 0)
410 goto out;
411 }
412 break;
413 }
414 out:
415 splx(s);
416 return (rv);
417 }
418
419 int
420 mhzc_intr(arg)
421 void *arg;
422 {
423 struct mhzc_softc *sc = arg;
424 int rval = 0;
425
426 #if NCOM_MHZC > 0
427 if (sc->sc_modem != NULL &&
428 (sc->sc_flags & MHZC_MODEM_ENABLED) != 0)
429 rval |= comintr(sc->sc_modem);
430 #endif
431
432 #if NSM_MHZC > 0
433 if (sc->sc_ethernet != NULL &&
434 (sc->sc_flags & MHZC_ETHERNET_ENABLED) != 0)
435 rval |= smc91cxx_intr(sc->sc_ethernet);
436 #endif
437
438 return (rval);
439 }
440
441 int
442 mhzc_enable(sc, flag)
443 struct mhzc_softc *sc;
444 int flag;
445 {
446 int error;
447
448 if ((sc->sc_flags & flag) == flag) {
449 printf("%s: already enabled\n", sc->sc_dev.dv_xname);
450 return (0);
451 }
452
453 if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0) {
454 sc->sc_flags |= flag;
455 return (0);
456 }
457
458 /*
459 * Establish our interrupt handler.
460 *
461 * XXX Note, we establish this at IPL_NET. This is suboptimal
462 * XXX the Modem portion, but is necessary to make the Ethernet
463 * XXX portion have the correct interrupt level semantics.
464 *
465 * XXX Eventually we should use the `enabled' bits in the
466 * XXX flags word to determine which level we should be at.
467 */
468 sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET,
469 mhzc_intr, sc);
470 if (!sc->sc_ih)
471 return (EIO);
472
473 error = pcmcia_function_enable(sc->sc_pf);
474 if (error) {
475 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
476 sc->sc_ih = 0;
477 return (error);
478 }
479
480 /*
481 * Perform any special enable magic necessary.
482 */
483 if (sc->sc_product->mp_enable != NULL &&
484 (*sc->sc_product->mp_enable)(sc) != 0) {
485 pcmcia_function_disable(sc->sc_pf);
486 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
487 return (1);
488 }
489
490 sc->sc_flags |= flag;
491 return (0);
492 }
493
494 void
495 mhzc_disable(sc, flag)
496 struct mhzc_softc *sc;
497 int flag;
498 {
499
500 if ((sc->sc_flags & flag) == 0) {
501 printf("%s: already disabled\n", sc->sc_dev.dv_xname);
502 return;
503 }
504
505 sc->sc_flags &= ~flag;
506 if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0)
507 return;
508
509 pcmcia_function_disable(sc->sc_pf);
510 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
511 sc->sc_ih = 0;
512 }
513
514 /*****************************************************************************
515 * Megahertz EM3336 (and compatibles) support
516 *****************************************************************************/
517
518 int mhzc_em3336_lannid_ciscallback(struct pcmcia_tuple *, void *);
519 int mhzc_em3336_ascii_enaddr(const char *cisstr, u_int8_t *);
520
521 int
522 mhzc_em3336_enaddr(sc, myla)
523 struct mhzc_softc *sc;
524 u_int8_t *myla;
525 {
526
527 /* Get the station address from CIS tuple 0x81. */
528 if (pcmcia_scan_cis(device_parent(&sc->sc_dev),
529 mhzc_em3336_lannid_ciscallback, myla) != 1) {
530 printf("%s: unable to get Ethernet address from CIS\n",
531 sc->sc_dev.dv_xname);
532 return (0);
533 }
534
535 return (1);
536 }
537
538 int
539 mhzc_em3336_enable(sc)
540 struct mhzc_softc *sc;
541 {
542 struct pcmcia_mem_handle memh;
543 bus_size_t memoff;
544 int memwin, reg;
545
546 /*
547 * Bring the chip to live by touching its registers in the correct
548 * way (as per my reference... the Linux smc91c92_cs.c driver by
549 * David A. Hinds).
550 */
551
552 /* Map the ISRPOWEREG. */
553 if (pcmcia_mem_alloc(sc->sc_pf, 0x1000, &memh) != 0) {
554 printf("%s: unable to allocate memory space\n",
555 sc->sc_dev.dv_xname);
556 return (1);
557 }
558
559 if (pcmcia_mem_map(sc->sc_pf, PCMCIA_MEM_ATTR, 0, 0x1000,
560 &memh, &memoff, &memwin)) {
561 printf("%s: unable to map memory space\n",
562 sc->sc_dev.dv_xname);
563 pcmcia_mem_free(sc->sc_pf, &memh);
564 return (1);
565 }
566
567 /*
568 * The magic sequence:
569 *
570 * - read/write the CCR option register.
571 * - read the ISRPOWEREG 2 times.
572 * - read/write the CCR option register again.
573 */
574
575 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
576 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
577
578 reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
579 delay(5);
580 reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
581
582 tsleep(&mhzc_em3336_enable, PWAIT, "mhz3en", hz * 200 / 1000);
583
584 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
585 delay(5);
586 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
587
588 pcmcia_mem_unmap(sc->sc_pf, memwin);
589 pcmcia_mem_free(sc->sc_pf, &memh);
590
591 return (0);
592 }
593
594 int
595 mhzc_em3336_lannid_ciscallback(tuple, arg)
596 struct pcmcia_tuple *tuple;
597 void *arg;
598 {
599 u_int8_t *myla = arg, addr_str[ETHER_ADDR_LEN * 2];
600 int i;
601
602 if (tuple->code == 0x81) {
603 /*
604 * We have a string-encoded address. Length includes
605 * terminating 0xff.
606 */
607 if (tuple->length != (ETHER_ADDR_LEN * 2) + 1)
608 return (0);
609
610 for (i = 0; i < tuple->length - 1; i++)
611 addr_str[i] = pcmcia_tuple_read_1(tuple, i);
612
613 /*
614 * Decode the string into `myla'.
615 */
616 return (mhzc_em3336_ascii_enaddr(addr_str, myla));
617 }
618 return (0);
619 }
620
621 /* XXX This should be shared w/ if_sm_pcmcia.c */
622 int
623 mhzc_em3336_ascii_enaddr(cisstr, myla)
624 const char *cisstr;
625 u_int8_t *myla;
626 {
627 u_int8_t digit;
628 int i;
629
630 memset(myla, 0, ETHER_ADDR_LEN);
631
632 for (i = 0, digit = 0; i < (ETHER_ADDR_LEN * 2); i++) {
633 if (cisstr[i] >= '0' && cisstr[i] <= '9')
634 digit |= cisstr[i] - '0';
635 else if (cisstr[i] >= 'a' && cisstr[i] <= 'f')
636 digit |= (cisstr[i] - 'a') + 10;
637 else if (cisstr[i] >= 'A' && cisstr[i] <= 'F')
638 digit |= (cisstr[i] - 'A') + 10;
639 else {
640 /* Bogus digit!! */
641 return (0);
642 }
643
644 /* Compensate for ordering of digits. */
645 if (i & 1) {
646 myla[i >> 1] = digit;
647 digit = 0;
648 } else
649 digit <<= 4;
650 }
651
652 return (1);
653 }
654
655 /****** Here begins the com attachment code. ******/
656
657 #if NCOM_MHZC > 0
658 int com_mhzc_match(struct device *, struct cfdata *, void *);
659 void com_mhzc_attach(struct device *, struct device *, void *);
660 int com_mhzc_detach(struct device *, int);
661
662 /* No mhzc-specific goo in the softc; it's all in the parent. */
663 CFATTACH_DECL(com_mhzc, sizeof(struct com_softc),
664 com_mhzc_match, com_mhzc_attach, com_detach, com_activate);
665
666 int com_mhzc_enable(struct com_softc *);
667 void com_mhzc_disable(struct com_softc *);
668
669 int
670 com_mhzc_match(parent, match, aux)
671 struct device *parent;
672 struct cfdata *match;
673 void *aux;
674 {
675 extern struct cfdriver com_cd;
676 const char *name = aux;
677
678 /* Device is always present. */
679 if (strcmp(name, com_cd.cd_name) == 0)
680 return (1);
681
682 return (0);
683 }
684
685 void
686 com_mhzc_attach(parent, self, aux)
687 struct device *parent, *self;
688 void *aux;
689 {
690 struct com_softc *sc = (void *)self;
691 struct mhzc_softc *msc = (void *)parent;
692
693 aprint_normal("\n");
694
695 COM_INIT_REGS(sc->sc_regs,
696 msc->sc_modem_pcioh.iot,
697 msc->sc_modem_pcioh.ioh,
698 -1);
699
700 sc->enabled = 1;
701
702 sc->sc_frequency = COM_FREQ;
703
704 sc->enable = com_mhzc_enable;
705 sc->disable = com_mhzc_disable;
706
707 aprint_normal("%s", sc->sc_dev.dv_xname);
708
709 com_attach_subr(sc);
710
711 sc->enabled = 0;
712 }
713
714 int
715 com_mhzc_enable(sc)
716 struct com_softc *sc;
717 {
718
719 return (mhzc_enable((struct mhzc_softc *)device_parent(&sc->sc_dev),
720 MHZC_MODEM_ENABLED));
721 }
722
723 void
724 com_mhzc_disable(sc)
725 struct com_softc *sc;
726 {
727
728 mhzc_disable((struct mhzc_softc *)device_parent(&sc->sc_dev),
729 MHZC_MODEM_ENABLED);
730 }
731
732 #endif /* NCOM_MHZC > 0 */
733
734 /****** Here begins the sm attachment code. ******/
735
736 #if NSM_MHZC > 0
737 int sm_mhzc_match(struct device *, struct cfdata *, void *);
738 void sm_mhzc_attach(struct device *, struct device *, void *);
739
740 /* No mhzc-specific goo in the softc; it's all in the parent. */
741 CFATTACH_DECL(sm_mhzc, sizeof(struct smc91cxx_softc),
742 sm_mhzc_match, sm_mhzc_attach, smc91cxx_detach, smc91cxx_activate);
743
744 int sm_mhzc_enable(struct smc91cxx_softc *);
745 void sm_mhzc_disable(struct smc91cxx_softc *);
746
747 int
748 sm_mhzc_match(parent, match, aux)
749 struct device *parent;
750 struct cfdata *match;
751 void *aux;
752 {
753 extern struct cfdriver sm_cd;
754 const char *name = aux;
755
756 /* Device is always present. */
757 if (strcmp(name, sm_cd.cd_name) == 0)
758 return (1);
759
760 return (0);
761 }
762
763 void
764 sm_mhzc_attach(parent, self, aux)
765 struct device *parent, *self;
766 void *aux;
767 {
768 struct smc91cxx_softc *sc = (void *)self;
769 struct mhzc_softc *msc = (void *)parent;
770 u_int8_t myla[ETHER_ADDR_LEN];
771
772 aprint_normal("\n");
773
774 sc->sc_bst = msc->sc_ethernet_pcioh.iot;
775 sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
776
777 sc->sc_enable = sm_mhzc_enable;
778 sc->sc_disable = sm_mhzc_disable;
779
780 if ((*msc->sc_product->mp_enaddr)(msc, myla) != 1)
781 return;
782
783 /* Perform generic initialization. */
784 smc91cxx_attach(sc, myla);
785 }
786
787 int
788 sm_mhzc_enable(sc)
789 struct smc91cxx_softc *sc;
790 {
791
792 return (mhzc_enable((struct mhzc_softc *)device_parent(&sc->sc_dev),
793 MHZC_ETHERNET_ENABLED));
794 }
795
796 void
797 sm_mhzc_disable(sc)
798 struct smc91cxx_softc *sc;
799 {
800
801 mhzc_disable((struct mhzc_softc *)device_parent(&sc->sc_dev),
802 MHZC_ETHERNET_ENABLED);
803 }
804
805 #endif /* NSM_MHZC > 0 */
806