Home | History | Annotate | Line # | Download | only in maple
maple.c revision 1.3
      1  1.3  marcus /*	$NetBSD: maple.c,v 1.3 2001/01/21 22:45:57 marcus Exp $	*/
      2  1.1  marcus 
      3  1.3  marcus /*-
      4  1.1  marcus  * Copyright (c) 2001 Marcus Comstedt
      5  1.1  marcus  * All rights reserved.
      6  1.1  marcus  *
      7  1.1  marcus  * Redistribution and use in source and binary forms, with or without
      8  1.1  marcus  * modification, are permitted provided that the following conditions
      9  1.1  marcus  * are met:
     10  1.1  marcus  * 1. Redistributions of source code must retain the above copyright
     11  1.1  marcus  *    notice, this list of conditions and the following disclaimer.
     12  1.1  marcus  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  marcus  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  marcus  *    documentation and/or other materials provided with the distribution.
     15  1.1  marcus  * 3. All advertising materials mentioning features or use of this software
     16  1.1  marcus  *    must display the following acknowledgement:
     17  1.3  marcus  *	This product includes software developed by Marcus Comstedt.
     18  1.3  marcus  * 4. Neither the name of The NetBSD Foundation nor the names of its
     19  1.3  marcus  *    contributors may be used to endorse or promote products derived
     20  1.3  marcus  *    from this software without specific prior written permission.
     21  1.1  marcus  *
     22  1.3  marcus  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     23  1.3  marcus  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     24  1.3  marcus  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     25  1.3  marcus  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     26  1.3  marcus  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27  1.3  marcus  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28  1.3  marcus  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29  1.3  marcus  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30  1.3  marcus  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31  1.3  marcus  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32  1.3  marcus  * POSSIBILITY OF SUCH DAMAGE.
     33  1.1  marcus  */
     34  1.1  marcus 
     35  1.1  marcus #include <sys/param.h>
     36  1.1  marcus #include <sys/device.h>
     37  1.1  marcus #include <sys/fcntl.h>
     38  1.1  marcus #include <sys/poll.h>
     39  1.1  marcus #include <sys/select.h>
     40  1.1  marcus #include <sys/proc.h>
     41  1.1  marcus #include <sys/signalvar.h>
     42  1.1  marcus #include <sys/systm.h>
     43  1.1  marcus 
     44  1.1  marcus #include <uvm/uvm_extern.h>
     45  1.1  marcus 
     46  1.1  marcus #include <machine/cpu.h>
     47  1.1  marcus #include <machine/bus.h>
     48  1.1  marcus #include <sh3/shbvar.h>
     49  1.1  marcus #include <sh3/pmap.h>
     50  1.1  marcus 
     51  1.1  marcus 
     52  1.1  marcus #include <dreamcast/dev/maple/maple.h>
     53  1.1  marcus #include <dreamcast/dev/maple/mapleconf.h>
     54  1.1  marcus #include <dreamcast/dev/maple/maplevar.h>
     55  1.1  marcus #include <dreamcast/dev/maple/maplereg.h>
     56  1.1  marcus 
     57  1.1  marcus 
     58  1.1  marcus #define MAPLE_CALLOUT_TICKS 1
     59  1.1  marcus 
     60  1.1  marcus /*
     61  1.1  marcus  * Function declarations.
     62  1.1  marcus  */
     63  1.1  marcus static int	maplematch __P((struct device *, struct cfdata *, void *));
     64  1.1  marcus static void	mapleattach __P((struct device *, struct device *, void *));
     65  1.1  marcus static int	mapleprint __P((void *, const char *));
     66  1.1  marcus static void	maple_attach_dev __P((struct maple_softc *, int, int));
     67  1.1  marcus static void	maple_begin_txbuf __P((struct maple_softc *));
     68  1.1  marcus static int	maple_end_txbuf __P((struct maple_softc *));
     69  1.1  marcus static void	maple_write_command __P((struct maple_softc *, int, int,
     70  1.1  marcus 					 int, int, void *));
     71  1.1  marcus static void	maple_scanbus __P((struct maple_softc *));
     72  1.1  marcus static void	maple_callout __P((void *));
     73  1.1  marcus static void	maple_send_commands __P((struct maple_softc *));
     74  1.1  marcus static void	maple_check_responses __P((struct maple_softc *));
     75  1.1  marcus 
     76  1.2  marcus int maple_alloc_dma __P((size_t, vaddr_t *, paddr_t *));
     77  1.2  marcus void maple_free_dma __P((paddr_t, size_t));
     78  1.2  marcus 
     79  1.1  marcus 
     80  1.1  marcus /*
     81  1.1  marcus  * Global variables.
     82  1.1  marcus  */
     83  1.1  marcus int	maple_polling = 0;	/* Are we polling?  (Debugger mode) */
     84  1.1  marcus 
     85  1.1  marcus /*
     86  1.1  marcus  * Driver definition.
     87  1.1  marcus  */
     88  1.1  marcus struct cfattach maple_ca = {
     89  1.1  marcus 	sizeof(struct maple_softc), maplematch, mapleattach
     90  1.1  marcus };
     91  1.1  marcus 
     92  1.1  marcus int	maplesearch __P((struct device *, struct cfdata *, void *));
     93  1.1  marcus 
     94  1.1  marcus static int
     95  1.1  marcus maplematch(parent, cf, aux)
     96  1.1  marcus 	struct device *parent;
     97  1.1  marcus 	struct cfdata *cf;
     98  1.1  marcus 	void *aux;
     99  1.1  marcus {
    100  1.1  marcus 	struct shb_attach_args *sa = aux;
    101  1.1  marcus 
    102  1.1  marcus 	if (strcmp("maple", cf->cf_driver->cd_name))
    103  1.1  marcus 	  return (0);
    104  1.1  marcus 
    105  1.1  marcus 	sa->ia_iosize = 0 /* 0x100 */;
    106  1.1  marcus 	return (1);
    107  1.1  marcus }
    108  1.1  marcus 
    109  1.1  marcus 
    110  1.1  marcus static void
    111  1.1  marcus maple_attach_dev(sc, port, subunit)
    112  1.1  marcus 	struct maple_softc *sc;
    113  1.1  marcus 	int port;
    114  1.1  marcus 	int subunit;
    115  1.1  marcus {
    116  1.1  marcus 	struct maple_attach_args ma;
    117  1.1  marcus 	ma.ma_port = port;
    118  1.1  marcus 	ma.ma_subunit = subunit;
    119  1.1  marcus 	ma.ma_devinfo = &sc->sc_unit[port][subunit].devinfo;
    120  1.1  marcus 	config_search(maplesearch, &sc->sc_dev, &ma);
    121  1.1  marcus }
    122  1.1  marcus 
    123  1.1  marcus static void
    124  1.1  marcus maple_begin_txbuf(sc)
    125  1.1  marcus 	struct maple_softc *sc;
    126  1.1  marcus {
    127  1.1  marcus 	sc->sc_txlink = sc->sc_txpos = sc->sc_txbuf;
    128  1.1  marcus }
    129  1.1  marcus 
    130  1.1  marcus static int
    131  1.1  marcus maple_end_txbuf(sc)
    132  1.1  marcus 	struct maple_softc *sc;
    133  1.1  marcus {
    134  1.1  marcus 	/* if no frame have been written, we can't mark the
    135  1.1  marcus 	   list end, and so the DMA must not be activated   */
    136  1.1  marcus   	if (sc->sc_txpos == sc->sc_txbuf)
    137  1.1  marcus 	  return (0);
    138  1.1  marcus 
    139  1.1  marcus 	*sc->sc_txlink |= 0x80000000;
    140  1.1  marcus 
    141  1.1  marcus 	return (1);
    142  1.1  marcus }
    143  1.1  marcus 
    144  1.1  marcus static int8_t subunit_code[] = { 0x20, 0x01, 0x02, 0x04, 0x08, 0x10 };
    145  1.1  marcus 
    146  1.1  marcus static void
    147  1.1  marcus maple_write_command(sc, port, subunit, command, datalen, dataaddr)
    148  1.1  marcus 	struct maple_softc *sc;
    149  1.1  marcus 	int port;
    150  1.1  marcus 	int subunit;
    151  1.1  marcus 	int command;
    152  1.1  marcus 	int datalen;
    153  1.1  marcus 	void *dataaddr;
    154  1.1  marcus {
    155  1.1  marcus 	int to, from;
    156  1.1  marcus 	u_int32_t *p = sc->sc_txpos;
    157  1.1  marcus 
    158  1.1  marcus 	if ((port & ~(MAPLE_PORTS-1)) != 0 ||
    159  1.1  marcus 	    subunit < 0 || subunit >= MAPLE_SUBUNITS)
    160  1.1  marcus 	  return;
    161  1.1  marcus 
    162  1.1  marcus 	/* Compute sender and recipient address */
    163  1.1  marcus 	from = port << 6;
    164  1.1  marcus 	to = from | subunit_code[subunit];
    165  1.1  marcus 
    166  1.1  marcus 	/* Max data length = 255 longs = 1020 bytes */
    167  1.1  marcus 	if(datalen > 255)
    168  1.1  marcus 	  datalen = 255;
    169  1.1  marcus 	else if(datalen < 0)
    170  1.1  marcus 	  datalen = 0;
    171  1.1  marcus 
    172  1.1  marcus 	sc->sc_txlink = p;
    173  1.1  marcus 
    174  1.1  marcus 	/* Set length of packet and destination port (A-D) */
    175  1.1  marcus 	*p++ = datalen | (port << 16);
    176  1.1  marcus 
    177  1.1  marcus 	/* Write address to receive buffer where the response
    178  1.1  marcus 	   frame should be put */
    179  1.1  marcus 	*p++ = sc->sc_rxbuf_phys[port][subunit];
    180  1.1  marcus 
    181  1.1  marcus 	/* Create the frame header.  The fields are assembled "backwards"
    182  1.1  marcus 	   because of the Maple Bus big-endianness.                       */
    183  1.1  marcus 	*p++ = (command & 0xff) | (to << 8) | (from << 16) | (datalen << 24);
    184  1.1  marcus 
    185  1.1  marcus 	/* Copy parameter data, if any */
    186  1.1  marcus 	if (datalen > 0) {
    187  1.1  marcus 	  u_int32_t *param = dataaddr;
    188  1.1  marcus 	  int i;
    189  1.1  marcus 	  for (i = 0; i < datalen; i++)
    190  1.1  marcus 	    *p++ = *param++;
    191  1.1  marcus 	}
    192  1.1  marcus 
    193  1.1  marcus 	sc->sc_txpos = p;
    194  1.1  marcus }
    195  1.1  marcus 
    196  1.1  marcus static void
    197  1.1  marcus maple_scanbus(sc)
    198  1.1  marcus 	struct maple_softc *sc;
    199  1.1  marcus {
    200  1.1  marcus 	int p;
    201  1.1  marcus 
    202  1.1  marcus 	maple_polling = 1;
    203  1.1  marcus 
    204  1.1  marcus 	maple_begin_txbuf(sc);
    205  1.1  marcus 
    206  1.1  marcus 	for (p = 0; p < MAPLE_PORTS; p++) {
    207  1.1  marcus 	  maple_write_command(sc, p, 0, MAPLE_COMMAND_DEVINFO, 0, NULL);
    208  1.1  marcus 	}
    209  1.1  marcus 
    210  1.1  marcus 	if (maple_end_txbuf(sc)) {
    211  1.1  marcus 
    212  1.1  marcus 	  MAPLE_DMAADDR = sc->sc_txbuf_phys;
    213  1.1  marcus 	  MAPLE_STATE = 1;
    214  1.1  marcus 	  while (MAPLE_STATE != 0)
    215  1.1  marcus 	    ;
    216  1.1  marcus 
    217  1.1  marcus 	  for (p = 0; p < MAPLE_PORTS; p++)
    218  1.1  marcus 	    if ((sc->sc_rxbuf[p][0][0] & 0xff) == MAPLE_RESPONSE_DEVINFO) {
    219  1.1  marcus 
    220  1.1  marcus 	      u_int32_t *to_swap;
    221  1.1  marcus 	      int i;
    222  1.1  marcus 
    223  1.1  marcus 	      bcopy(sc->sc_rxbuf[p][0]+1,
    224  1.1  marcus 		    (to_swap = &sc->sc_unit[p][0].devinfo.di_func),
    225  1.1  marcus 		    sizeof(struct maple_devinfo));
    226  1.1  marcus 
    227  1.1  marcus 	      for (i = 0; i < 4; i++, to_swap++)
    228  1.1  marcus 		*to_swap = ntohl(*to_swap);
    229  1.1  marcus 
    230  1.1  marcus 	      maple_attach_dev(sc, p, 0);
    231  1.1  marcus 	    }
    232  1.1  marcus 
    233  1.1  marcus 	}
    234  1.1  marcus 
    235  1.1  marcus 	maple_polling = 0;
    236  1.1  marcus 
    237  1.1  marcus }
    238  1.1  marcus 
    239  1.1  marcus static void
    240  1.1  marcus maple_send_commands(sc)
    241  1.1  marcus 	struct maple_softc *sc;
    242  1.1  marcus {
    243  1.1  marcus 	int p;
    244  1.1  marcus 
    245  1.1  marcus 	if (sc->maple_commands_pending || MAPLE_STATE != 0)
    246  1.1  marcus 	  return;
    247  1.1  marcus 
    248  1.1  marcus 	maple_begin_txbuf(sc);
    249  1.1  marcus 
    250  1.1  marcus 	for (p = 0; p < MAPLE_PORTS; p++) {
    251  1.1  marcus 
    252  1.1  marcus 	  if (sc->sc_unit[p][0].getcond_callback != NULL) {
    253  1.1  marcus 
    254  1.1  marcus 	    u_int32_t func = ntohl(sc->sc_unit[p][0].getcond_func);
    255  1.1  marcus 
    256  1.1  marcus 	    maple_write_command(sc, p, 0, MAPLE_COMMAND_GETCOND, 1, &func);
    257  1.1  marcus 
    258  1.1  marcus 	  }
    259  1.1  marcus 
    260  1.1  marcus 	}
    261  1.1  marcus 
    262  1.1  marcus 	if (!maple_end_txbuf(sc))
    263  1.1  marcus 	  return;
    264  1.1  marcus 
    265  1.1  marcus 	MAPLE_DMAADDR = sc->sc_txbuf_phys;
    266  1.1  marcus 	MAPLE_STATE = 1;
    267  1.1  marcus 
    268  1.1  marcus 	sc->maple_commands_pending = 1;
    269  1.1  marcus }
    270  1.1  marcus 
    271  1.1  marcus static void
    272  1.1  marcus maple_check_responses(sc)
    273  1.1  marcus 	struct maple_softc *sc;
    274  1.1  marcus {
    275  1.1  marcus 	int p;
    276  1.1  marcus 
    277  1.1  marcus 	if (!sc->maple_commands_pending || MAPLE_STATE != 0)
    278  1.1  marcus 	  return;
    279  1.1  marcus 
    280  1.1  marcus 	for (p = 0; p < MAPLE_PORTS; p++) {
    281  1.1  marcus 	  struct maple_unit * u = &sc->sc_unit[p][0];
    282  1.1  marcus 	  if (u->getcond_callback != NULL &&
    283  1.1  marcus 	      (sc->sc_rxbuf[p][0][0] & 0xff) == MAPLE_RESPONSE_DATATRF &&
    284  1.1  marcus 	      (sc->sc_rxbuf[p][0][0]>>24) >= 1 &&
    285  1.1  marcus 	      htonl(sc->sc_rxbuf[p][0][1]) == u->getcond_func) {
    286  1.1  marcus 	    (*u->getcond_callback)(u->getcond_data,
    287  1.1  marcus 				   (void *)(sc->sc_rxbuf[p][0]+2),
    288  1.1  marcus 				   ((sc->sc_rxbuf[p][0][0]>>22)&1020)-4);
    289  1.1  marcus 	  }
    290  1.1  marcus 	}
    291  1.1  marcus 
    292  1.1  marcus 	sc->maple_commands_pending = 0;
    293  1.1  marcus }
    294  1.1  marcus 
    295  1.1  marcus void
    296  1.1  marcus maple_run_polling(dev)
    297  1.1  marcus 	struct device *dev;
    298  1.1  marcus {
    299  1.1  marcus 	struct maple_softc *sc;
    300  1.1  marcus 
    301  1.1  marcus 	sc = (struct maple_softc *)dev;
    302  1.1  marcus 
    303  1.1  marcus 	if (MAPLE_STATE != 0)
    304  1.1  marcus 	  return;
    305  1.1  marcus 
    306  1.1  marcus 	maple_send_commands(sc);
    307  1.1  marcus 
    308  1.1  marcus 	while (MAPLE_STATE != 0)
    309  1.1  marcus 	  ;
    310  1.1  marcus 
    311  1.1  marcus 	maple_check_responses(sc);
    312  1.1  marcus }
    313  1.1  marcus 
    314  1.1  marcus void
    315  1.1  marcus maple_set_condition_callback(dev, port, subunit, func, callback, data)
    316  1.1  marcus 	struct device *dev;
    317  1.1  marcus 	int port;
    318  1.1  marcus 	int subunit;
    319  1.1  marcus 	u_int32_t func;
    320  1.1  marcus 	void (*callback)(void *, void *, int);
    321  1.1  marcus 	void *data;
    322  1.1  marcus {
    323  1.1  marcus 	struct maple_softc *sc;
    324  1.1  marcus 
    325  1.1  marcus 	sc = (struct maple_softc *)dev;
    326  1.1  marcus 
    327  1.1  marcus 	if ((port & ~(MAPLE_PORTS-1)) != 0 ||
    328  1.1  marcus 	    subunit < 0 || subunit >= MAPLE_SUBUNITS)
    329  1.1  marcus 	  return;
    330  1.1  marcus 
    331  1.1  marcus 	sc->sc_unit[port][subunit].getcond_func = func;
    332  1.1  marcus 	sc->sc_unit[port][subunit].getcond_callback = callback;
    333  1.1  marcus 	sc->sc_unit[port][subunit].getcond_data = data;
    334  1.1  marcus }
    335  1.1  marcus 
    336  1.1  marcus static void
    337  1.1  marcus maple_callout(ctx)
    338  1.1  marcus 	void *ctx;
    339  1.1  marcus {
    340  1.1  marcus 	struct maple_softc *sc = ctx;
    341  1.1  marcus 
    342  1.1  marcus 	if(!maple_polling) {
    343  1.1  marcus 
    344  1.1  marcus 	  maple_check_responses(sc);
    345  1.1  marcus 
    346  1.1  marcus 	  maple_send_commands(sc);
    347  1.1  marcus 
    348  1.1  marcus 	}
    349  1.1  marcus 
    350  1.1  marcus 	callout_reset(&sc->maple_callout_ch, MAPLE_CALLOUT_TICKS,
    351  1.1  marcus 		      (void *)maple_callout, sc);
    352  1.1  marcus }
    353  1.1  marcus 
    354  1.2  marcus int
    355  1.2  marcus maple_alloc_dma(size, vap, pap)
    356  1.2  marcus 	size_t size;
    357  1.2  marcus 	vaddr_t *vap;
    358  1.2  marcus 	paddr_t *pap;
    359  1.2  marcus {
    360  1.2  marcus 	extern paddr_t avail_start, avail_end;	/* from pmap.c */
    361  1.2  marcus 
    362  1.2  marcus 	struct pglist mlist;
    363  1.2  marcus 	vm_page_t m;
    364  1.2  marcus 	int error;
    365  1.2  marcus 
    366  1.2  marcus 	size = round_page(size);
    367  1.2  marcus 
    368  1.2  marcus 	TAILQ_INIT(&mlist);
    369  1.2  marcus 	error = uvm_pglistalloc(size, avail_start, avail_end - PAGE_SIZE,
    370  1.2  marcus 	    0, 0, &mlist, 1, 0);
    371  1.2  marcus 	if (error)
    372  1.2  marcus 		return (error);
    373  1.2  marcus 
    374  1.2  marcus 	m = TAILQ_FIRST(&mlist);
    375  1.2  marcus 	*pap = VM_PAGE_TO_PHYS(m);
    376  1.2  marcus 	*vap = SH3_PHYS_TO_P2SEG(VM_PAGE_TO_PHYS(m));
    377  1.2  marcus 
    378  1.2  marcus 	return (0);
    379  1.2  marcus }
    380  1.2  marcus 
    381  1.2  marcus void
    382  1.2  marcus maple_free_dma(paddr, size)
    383  1.2  marcus 	paddr_t paddr;
    384  1.2  marcus 	size_t size;
    385  1.2  marcus {
    386  1.2  marcus 	struct pglist mlist;
    387  1.2  marcus 	vm_page_t m;
    388  1.2  marcus 	bus_addr_t addr;
    389  1.2  marcus 
    390  1.2  marcus 	TAILQ_INIT(&mlist);
    391  1.2  marcus 	for (addr = paddr; addr < paddr + size; addr += PAGE_SIZE) {
    392  1.2  marcus 		m = PHYS_TO_VM_PAGE(addr);
    393  1.2  marcus 		TAILQ_INSERT_TAIL(&mlist, m, pageq);
    394  1.2  marcus 	}
    395  1.2  marcus 	uvm_pglistfree(&mlist);
    396  1.2  marcus }
    397  1.2  marcus 
    398  1.2  marcus 
    399  1.1  marcus static void
    400  1.1  marcus mapleattach(parent, self, aux)
    401  1.1  marcus 	struct device *parent, *self;
    402  1.1  marcus 	void *aux;
    403  1.1  marcus {
    404  1.1  marcus 	struct maple_softc *sc;
    405  1.1  marcus 	vaddr_t dmabuffer;
    406  1.2  marcus 	paddr_t dmabuffer_phys;
    407  1.1  marcus 	u_int32_t *p;
    408  1.1  marcus 	int i, j;
    409  1.1  marcus 
    410  1.1  marcus 	sc = (struct maple_softc *)self;
    411  1.1  marcus 
    412  1.1  marcus 	printf("\n");
    413  1.1  marcus 
    414  1.2  marcus 	if (maple_alloc_dma(MAPLE_DMABUF_SIZE, &dmabuffer, &dmabuffer_phys)) {
    415  1.2  marcus 	  printf("%s: unable to allocate DMA buffers.\n", sc->sc_dev.dv_xname);
    416  1.2  marcus 	  return;
    417  1.2  marcus 	}
    418  1.1  marcus 
    419  1.2  marcus 	p = (u_int32_t *) dmabuffer;
    420  1.1  marcus 
    421  1.1  marcus 	for (i = 0; i < MAPLE_PORTS; i++)
    422  1.1  marcus 	  for (j = 0; j < MAPLE_SUBUNITS; j++) {
    423  1.1  marcus 
    424  1.1  marcus 	    sc->sc_rxbuf[i][j] = p;
    425  1.1  marcus 	    sc->sc_rxbuf_phys[i][j] = SH3_P2SEG_TO_PHYS(p);
    426  1.1  marcus 	    p += 256;
    427  1.1  marcus 
    428  1.1  marcus 	  }
    429  1.1  marcus 
    430  1.1  marcus 	sc->sc_txbuf = p;
    431  1.1  marcus 	sc->sc_txbuf_phys = SH3_P2SEG_TO_PHYS(p);
    432  1.1  marcus 
    433  1.1  marcus 	sc->maple_commands_pending = 0;
    434  1.1  marcus 
    435  1.1  marcus 	MAPLE_RESET = RESET_MAGIC;
    436  1.1  marcus 	MAPLE_RESET2 = 0;
    437  1.1  marcus 
    438  1.1  marcus 	MAPLE_SPEED = SPEED_2MBPS | TIMEOUT(50000);
    439  1.1  marcus 
    440  1.1  marcus 	MAPLE_ENABLE = 1;
    441  1.1  marcus 
    442  1.1  marcus 	maple_scanbus(sc);
    443  1.1  marcus 
    444  1.1  marcus 	bzero(&sc->maple_callout_ch, sizeof(sc->maple_callout_ch));
    445  1.1  marcus 
    446  1.1  marcus 	callout_reset(&sc->maple_callout_ch, MAPLE_CALLOUT_TICKS,
    447  1.1  marcus 		      (void *)maple_callout, sc);
    448  1.1  marcus }
    449  1.1  marcus 
    450  1.1  marcus int
    451  1.1  marcus mapleprint(aux, pnp)
    452  1.1  marcus 	void *aux;
    453  1.1  marcus 	const char *pnp;
    454  1.1  marcus {
    455  1.1  marcus 	struct maple_attach_args *ma = aux;
    456  1.1  marcus 
    457  1.1  marcus 	if (pnp != NULL)
    458  1.1  marcus 		printf("%s", pnp);
    459  1.1  marcus 
    460  1.1  marcus 	printf(" port %c", ma->ma_port+'A');
    461  1.1  marcus 
    462  1.1  marcus 	if (ma->ma_subunit != 0)
    463  1.1  marcus 	  printf("%d", ma->ma_subunit);
    464  1.1  marcus 
    465  1.1  marcus 	return (UNCONF);
    466  1.1  marcus }
    467  1.1  marcus 
    468  1.1  marcus int
    469  1.1  marcus maplesearch(parent, cf, aux)
    470  1.1  marcus 	struct device *parent;
    471  1.1  marcus 	struct cfdata *cf;
    472  1.1  marcus 	void *aux;
    473  1.1  marcus {
    474  1.1  marcus 	if ((*cf->cf_attach->ca_match)(parent, cf, aux) > 0)
    475  1.1  marcus 	  config_attach(parent, cf, aux, mapleprint);
    476  1.1  marcus 
    477  1.1  marcus 	return (0);
    478  1.1  marcus }
    479  1.1  marcus 
    480  1.1  marcus u_int32_t
    481  1.1  marcus maple_get_function_data(devinfo, function_code)
    482  1.1  marcus 	struct maple_devinfo *devinfo;
    483  1.1  marcus 	u_int32_t function_code;
    484  1.1  marcus {
    485  1.1  marcus 	int i, p = 0;
    486  1.1  marcus 
    487  1.1  marcus 	for (i = 31; i >= 0; --i)
    488  1.1  marcus 	  if (devinfo->di_func & (1U<<i))
    489  1.1  marcus 	    if (function_code & (1U<<i))
    490  1.1  marcus 	      return devinfo->di_function_data[p];
    491  1.1  marcus 	    else
    492  1.1  marcus 	      if (++p >= 3)
    493  1.1  marcus 		break;
    494  1.1  marcus 	return (0);
    495  1.1  marcus }
    496  1.1  marcus 
    497