1 /* $NetBSD: bt3c.c,v 1.19 2009/05/12 13:18:04 cegger Exp $ */
4 * Copyright (c) 2005 Iain D. Hibbert,
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * Driver for the 3Com Bluetooth PC Card 3CRWB6096, written with reference to
32 * FreeBSD and BlueZ drivers for same, with credit for those going to:
34 * Maksim Yevmenkin <m_evmenkin@yahoo.com> (FreeBSD)
35 * Marcel Holtmann <marcel@holtmann.org> (BlueZ)
36 * Jose Orlando Pereira <jop@di.uminho.pt> (BlueZ)
37 * David Hinds <dahinds@users.sourceforge.net> (Original Code)
41 * The CIS info from my card:
43 * pcmcia1: CIS tuple chain:
44 * CISTPL_DEVICE type=null speed=null
47 * 15 24 05 00 33 43 4f 4d 00 33 43 52 57 42 36 30
48 * 2d 41 00 42 6c 75 65 74 6f 6f 74 68 20 50 43 20
55 * 1a 06 05 30 20 03 17 00
56 * CISTPL_CFTABLE_ENTRY
57 * 1b 09 f0 41 18 a0 40 07 30 ff ff
59 * 80 0a 02 01 40 00 2d 00 00 00 00 ff
64 * pcmcia1: CIS version PC Card Standard 5.0
65 * pcmcia1: CIS info: 3COM, 3CRWB60-A, Bluetooth PC Card
66 * pcmcia1: Manufacturer code 0x101, product 0x40
67 * pcmcia1: function 0: serial port, ccr addr 320 mask 17
68 * pcmcia1: function 0, config table entry 48: I/O card; irq mask ffff; iomask 0, iospace 0-7; rdybsy_active io8 irqlevel
71 #include <sys/cdefs.h>
72 __KERNEL_RCSID(0, "$NetBSD: bt3c.c,v 1.19 2009/05/12 13:18:04 cegger Exp $");
74 #include <sys/param.h>
75 #include <sys/device.h>
77 #include <sys/systm.h>
83 #include <dev/pcmcia/pcmciareg.h>
84 #include <dev/pcmcia/pcmciavar.h>
85 #include <dev/pcmcia/pcmciadevs.h>
87 #include <netbt/bluetooth.h>
88 #include <netbt/hci.h>
90 #include <dev/firmload.h>
91 #define BT3C_FIRMWARE_FILE "BT3CPCC.bin"
93 /**************************************************************************
95 * bt3c autoconfig glue
101 struct pcmcia_function
*sc_pf
; /* our PCMCIA function */
102 struct pcmcia_io_handle sc_pcioh
; /* PCMCIA i/o space info */
103 int sc_iow
; /* our i/o window */
104 int sc_flags
; /* flags */
106 struct hci_unit
*sc_unit
; /* Bluetooth HCI Unit */
107 struct bt_stats sc_stats
; /* HCI stats */
109 /* hardware interrupt */
110 void *sc_intr
; /* cookie */
111 int sc_state
; /* receive state */
112 int sc_want
; /* how much we want */
113 struct mbuf
*sc_rxp
; /* incoming packet */
114 struct mbuf
*sc_txp
; /* outgoing packet */
116 /* transmit queues */
117 MBUFQ_HEAD() sc_cmdq
; /* commands */
118 MBUFQ_HEAD() sc_aclq
; /* ACL data */
119 MBUFQ_HEAD() sc_scoq
; /* SCO data */
122 /* sc_state */ /* receiving */
123 #define BT3C_RECV_PKT_TYPE 0 /* packet type */
124 #define BT3C_RECV_ACL_HDR 1 /* acl header */
125 #define BT3C_RECV_SCO_HDR 2 /* sco header */
126 #define BT3C_RECV_EVENT_HDR 3 /* event header */
127 #define BT3C_RECV_ACL_DATA 4 /* acl packet data */
128 #define BT3C_RECV_SCO_DATA 5 /* sco packet data */
129 #define BT3C_RECV_EVENT_DATA 6 /* event packet data */
132 #define BT3C_XMIT (1 << 1) /* transmit active */
133 #define BT3C_ENABLED (1 << 2) /* enabled */
135 static int bt3c_match(device_t
, cfdata_t
, void *);
136 static void bt3c_attach(device_t
, device_t
, void *);
137 static int bt3c_detach(device_t
, int);
138 static bool bt3c_suspend(device_t
, pmf_qual_t
);
139 static bool bt3c_resume(device_t
, pmf_qual_t
);
141 CFATTACH_DECL_NEW(bt3c
, sizeof(struct bt3c_softc
),
142 bt3c_match
, bt3c_attach
, bt3c_detach
, NULL
);
144 static int bt3c_enable(device_t
);
145 static void bt3c_disable(device_t
);
146 static void bt3c_output_cmd(device_t
, struct mbuf
*);
147 static void bt3c_output_acl(device_t
, struct mbuf
*);
148 static void bt3c_output_sco(device_t
, struct mbuf
*);
149 static void bt3c_stats(device_t
, struct bt_stats
*, int);
151 static const struct hci_if bt3c_hci
= {
152 .enable
= bt3c_enable
,
153 .disable
= bt3c_disable
,
154 .output_cmd
= bt3c_output_cmd
,
155 .output_acl
= bt3c_output_acl
,
156 .output_sco
= bt3c_output_sco
,
157 .get_stats
= bt3c_stats
,
161 static void bt3c_start(struct bt3c_softc
*);
163 /**************************************************************************
165 * Hardware Definitions & IO routines
167 * I made up the names for most of these defs since we dont have
168 * manufacturers recommendations, but I dont like raw numbers..
170 * all hardware routines are running at IPL_TTY
173 #define BT3C_ISR 0x7001 /* Interrupt Status Register */
174 #define BT3C_ISR_RXRDY (1<<0) /* Device has data */
175 #define BT3C_ISR_TXRDY (1<<1) /* Finished sending data */
176 #define BT3C_ISR_ANTENNA (1<<5) /* Antenna position changed */
178 #define BT3C_CSR 0x7002 /* Card Status Register */
179 #define BT3C_CSR_ANTENNA (1<<4) /* Antenna position */
181 #define BT3C_TX_COUNT 0x7005 /* Tx fifo contents */
182 #define BT3C_TX_FIFO 0x7080 /* Transmit Fifo */
183 #define BT3C_RX_COUNT 0x7006 /* Rx fifo contents */
184 #define BT3C_RX_FIFO 0x7480 /* Receive Fifo */
185 #define BT3C_FIFO_SIZE 256
188 #define BT3C_IOR_DATA_L 0x00 /* data low byte */
189 #define BT3C_IOR_DATA_H 0x01 /* data high byte */
190 #define BT3C_IOR_ADDR_L 0x02 /* address low byte */
191 #define BT3C_IOR_ADDR_H 0x03 /* address high byte */
192 #define BT3C_IOR_CNTL 0x04 /* control byte */
193 #define BT3C_IOR_CNTL_BOOT (1<<6) /* Boot Card */
194 #define BT3C_IOR_CNTL_INTR (1<<7) /* Interrupt Requested */
195 #define BT3C_IOR_LEN 0x05
197 static inline uint16_t
198 bt3c_get(struct bt3c_softc
*sc
)
202 bus_space_barrier(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
203 0, BT3C_IOR_LEN
, BUS_SPACE_BARRIER_READ
);
204 data
= bus_space_read_1(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
206 data
|= bus_space_read_1(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
207 BT3C_IOR_DATA_H
) << 8;
213 bt3c_put(struct bt3c_softc
*sc
, uint16_t data
)
216 bus_space_barrier(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
217 0, BT3C_IOR_LEN
, BUS_SPACE_BARRIER_WRITE
);
218 bus_space_write_1(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
219 BT3C_IOR_DATA_L
, data
& 0xff);
220 bus_space_write_1(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
221 BT3C_IOR_DATA_H
, (data
>> 8) & 0xff);
224 static inline uint8_t
225 bt3c_read_control(struct bt3c_softc
*sc
)
228 bus_space_barrier(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
229 0, BT3C_IOR_LEN
, BUS_SPACE_BARRIER_READ
);
230 return bus_space_read_1(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
235 bt3c_write_control(struct bt3c_softc
*sc
, uint8_t data
)
238 bus_space_barrier(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
239 0, BT3C_IOR_LEN
, BUS_SPACE_BARRIER_WRITE
);
240 bus_space_write_1(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
241 BT3C_IOR_CNTL
, data
);
245 bt3c_set_address(struct bt3c_softc
*sc
, uint16_t addr
)
248 bus_space_barrier(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
249 0, BT3C_IOR_LEN
, BUS_SPACE_BARRIER_WRITE
);
250 bus_space_write_1(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
251 BT3C_IOR_ADDR_L
, addr
& 0xff);
252 bus_space_write_1(sc
->sc_pcioh
.iot
, sc
->sc_pcioh
.ioh
,
253 BT3C_IOR_ADDR_H
, (addr
>> 8) & 0xff);
256 static inline uint16_t
257 bt3c_read(struct bt3c_softc
*sc
, uint16_t addr
)
260 bt3c_set_address(sc
, addr
);
265 bt3c_write(struct bt3c_softc
*sc
, uint16_t addr
, uint16_t data
)
268 bt3c_set_address(sc
, addr
);
273 * receive incoming data from device, store in mbuf chain and
274 * pass on complete packets to bt device
277 bt3c_receive(struct bt3c_softc
*sc
)
279 struct mbuf
*m
= sc
->sc_rxp
;
285 * If we already started a packet, find the
286 * trailing end of it.
292 space
= M_TRAILINGSPACE(m
);
295 count
= bt3c_read(sc
, BT3C_RX_COUNT
);
296 bt3c_set_address(sc
, BT3C_RX_FIFO
);
302 MGETHDR(m
, M_DONTWAIT
, MT_DATA
);
304 aprint_error_dev(sc
->sc_dev
,
306 sc
->sc_stats
.err_rx
++;
307 goto out
; /* (lost sync) */
311 m
->m_pkthdr
.len
= m
->m_len
= 0;
314 sc
->sc_state
= BT3C_RECV_PKT_TYPE
;
318 MGET(m
->m_next
, M_DONTWAIT
, MT_DATA
);
319 if (m
->m_next
== NULL
) {
320 aprint_error_dev(sc
->sc_dev
,
322 sc
->sc_stats
.err_rx
++;
323 goto out
; /* (lost sync) */
330 if (sc
->sc_want
> MINCLSIZE
) {
331 MCLGET(m
, M_DONTWAIT
);
332 if (m
->m_flags
& M_EXT
)
339 mtod(m
, uint8_t *)[m
->m_len
++] = b
;
342 sc
->sc_rxp
->m_pkthdr
.len
++;
343 sc
->sc_stats
.byte_rx
++;
347 continue; /* want more */
349 switch (sc
->sc_state
) {
350 case BT3C_RECV_PKT_TYPE
: /* Got packet type */
353 case HCI_ACL_DATA_PKT
:
354 sc
->sc_state
= BT3C_RECV_ACL_HDR
;
355 sc
->sc_want
= sizeof(hci_acldata_hdr_t
) - 1;
358 case HCI_SCO_DATA_PKT
:
359 sc
->sc_state
= BT3C_RECV_SCO_HDR
;
360 sc
->sc_want
= sizeof(hci_scodata_hdr_t
) - 1;
364 sc
->sc_state
= BT3C_RECV_EVENT_HDR
;
365 sc
->sc_want
= sizeof(hci_event_hdr_t
) - 1;
369 aprint_error_dev(sc
->sc_dev
,
370 "Unknown packet type=%#x!\n", b
);
371 sc
->sc_stats
.err_rx
++;
374 goto out
; /* (lost sync) */
380 * we assume (correctly of course :) that the packet headers
381 * all fit into a single pkthdr mbuf
383 case BT3C_RECV_ACL_HDR
: /* Got ACL Header */
384 sc
->sc_state
= BT3C_RECV_ACL_DATA
;
385 sc
->sc_want
= mtod(m
, hci_acldata_hdr_t
*)->length
;
386 sc
->sc_want
= le16toh(sc
->sc_want
);
389 case BT3C_RECV_SCO_HDR
: /* Got SCO Header */
390 sc
->sc_state
= BT3C_RECV_SCO_DATA
;
391 sc
->sc_want
= mtod(m
, hci_scodata_hdr_t
*)->length
;
394 case BT3C_RECV_EVENT_HDR
: /* Got Event Header */
395 sc
->sc_state
= BT3C_RECV_EVENT_DATA
;
396 sc
->sc_want
= mtod(m
, hci_event_hdr_t
*)->length
;
399 case BT3C_RECV_ACL_DATA
: /* ACL Packet Complete */
400 if (!hci_input_acl(sc
->sc_unit
, sc
->sc_rxp
))
401 sc
->sc_stats
.err_rx
++;
403 sc
->sc_stats
.acl_rx
++;
404 sc
->sc_rxp
= m
= NULL
;
408 case BT3C_RECV_SCO_DATA
: /* SCO Packet Complete */
409 if (!hci_input_sco(sc
->sc_unit
, sc
->sc_rxp
))
410 sc
->sc_stats
.err_rx
++;
412 sc
->sc_stats
.sco_rx
++;
413 sc
->sc_rxp
= m
= NULL
;
417 case BT3C_RECV_EVENT_DATA
: /* Event Packet Complete */
418 if (!hci_input_event(sc
->sc_unit
, sc
->sc_rxp
))
419 sc
->sc_stats
.err_rx
++;
421 sc
->sc_stats
.evt_rx
++;
422 sc
->sc_rxp
= m
= NULL
;
427 panic("%s: invalid state %d!\n",
428 device_xname(sc
->sc_dev
), sc
->sc_state
);
433 bt3c_write(sc
, BT3C_RX_COUNT
, 0x0000);
437 * write data from current packet to Transmit FIFO.
441 bt3c_transmit(struct bt3c_softc
*sc
)
449 sc
->sc_flags
&= ~BT3C_XMIT
;
456 rptr
= mtod(m
, uint8_t *);
458 bt3c_set_address(sc
, BT3C_TX_FIFO
);
461 if (rlen
>= m
->m_len
) {
467 if (M_GETCTX(m
, void *) == NULL
)
469 else if (!hci_complete_sco(sc
->sc_unit
, m
))
470 sc
->sc_stats
.err_tx
++;
476 rptr
= mtod(m
, uint8_t *);
480 if (count
>= BT3C_FIFO_SIZE
) {
485 bt3c_put(sc
, *rptr
++);
490 bt3c_write(sc
, BT3C_TX_COUNT
, count
);
491 sc
->sc_stats
.byte_tx
+= count
;
500 struct bt3c_softc
*sc
= arg
;
501 uint16_t control
, isr
;
503 control
= bt3c_read_control(sc
);
504 if (control
& BT3C_IOR_CNTL_INTR
) {
505 isr
= bt3c_read(sc
, BT3C_ISR
);
506 if ((isr
& 0xff) == 0x7f) {
507 aprint_error_dev(sc
->sc_dev
, "strange ISR=%04x\n", isr
);
508 } else if ((isr
& 0xff) != 0xff) {
510 if (isr
& BT3C_ISR_RXRDY
)
513 if (isr
& BT3C_ISR_TXRDY
)
517 if (isr
& BT3C_ISR_ANTENNA
) {
518 if (bt3c_read(sc
, BT3C_CSR
) & BT3C_CSR_ANTENNA
)
519 aprint_verbose_dev(sc
->sc_dev
,
522 aprint_verbose_dev(sc
->sc_dev
,
527 bt3c_write(sc
, BT3C_ISR
, 0x0000);
528 bt3c_write_control(sc
, control
);
530 return 1; /* handled */
534 return 0; /* not handled */
538 * load firmware for the device
540 * The firmware file is a plain ASCII file in the Motorola S-Record format,
541 * with lines in the format:
543 * S<Digit><Len><Address><Data1><Data2>...<DataN><Checksum>
546 * 3 data record (4 byte address)
547 * 7 boot record (4 byte address)
549 * <Len>: 1 byte, and is the number of bytes in the rest of the line
550 * <Address>: 4 byte address (only 2 bytes are valid for bt3c I think)
551 * <Data>: 2 byte data word to be written to the address
552 * <Checksum>: checksum of all bytes in the line including <Len>
554 * all bytes are in hexadecimal
556 static inline int32_t
557 hex(const uint8_t *p
, int n
)
564 if ('0' <= *p
&& *p
<= '9')
566 else if ('a' <= *p
&& *p
<= 'f')
567 val
+= (*p
- 'a' + 0xa);
568 else if ('A' <= *p
&& *p
<= 'F')
569 val
+= (*p
- 'A' + 0xa);
581 bt3c_load_firmware(struct bt3c_softc
*sc
)
583 uint8_t *buf
, *line
, *next
, *p
;
586 firmware_handle_t fh
;
587 cfdata_t cf
= device_cfdata(sc
->sc_dev
);
590 err
= firmware_open(cf
->cf_name
,
591 BT3C_FIRMWARE_FILE
, &fh
);
593 aprint_error_dev(sc
->sc_dev
, "Cannot open firmware %s/%s\n",
594 cf
->cf_name
, BT3C_FIRMWARE_FILE
);
598 size
= (size_t)firmware_get_size(fh
);
600 if (size
> 10 * 1024) { /* sanity check */
601 aprint_error_dev(sc
->sc_dev
, "insane firmware file size!\n");
607 buf
= firmware_malloc(size
);
608 KASSERT(buf
!= NULL
);
610 err
= firmware_read(fh
, 0, buf
, size
);
612 aprint_error_dev(sc
->sc_dev
, "Firmware read failed (%d)\n", err
);
617 bt3c_write(sc
, 0x8040, 0x0404);
618 bt3c_write(sc
, 0x8040, 0x0400);
620 bt3c_write(sc
, 0x8040, 0x0404);
626 while (next
< buf
+ size
) {
629 while (*next
!= '\r' && *next
!= '\n') {
630 if (next
>= buf
+ size
)
636 /* 14 covers address and checksum minimum */
637 if (next
- line
< 14)
643 /* verify line length */
644 len
= hex(line
+ 2, 2);
645 if (len
< 0 || next
- line
!= len
* 2 + 4)
648 /* checksum the line */
650 for (p
= line
+ 2 ; p
< next
; p
+= 2)
653 if ((sum
& 0xff) != 0xff)
656 /* extract relevant data */
659 /* we ignore the header */
663 /* find number of data words */
668 addr
= hex(line
+ 8, 4);
672 bt3c_set_address(sc
, addr
);
674 for (p
= line
+ 12 ; p
+ 4 < next
; p
+= 4) {
685 * for some reason we ignore this record
686 * and boot from 0x3000 which happens to
687 * be the first record in the file.
695 /* skip to start of next line */
696 while (next
< buf
+ size
&& (*next
== '\r' || *next
== '\n'))
704 bt3c_set_address(sc
, 0x3000);
705 bt3c_write_control(sc
, (bt3c_read_control(sc
) | BT3C_IOR_CNTL_BOOT
));
708 /* Clear Registers */
709 bt3c_write(sc
, BT3C_RX_COUNT
, 0x0000);
710 bt3c_write(sc
, BT3C_TX_COUNT
, 0x0000);
711 bt3c_write(sc
, BT3C_ISR
, 0x0000);
715 firmware_free(buf
, size
);
720 /**************************************************************************
722 * bt device callbacks
726 * start sending on bt3c
727 * should be called at spltty() when BT3C_XMIT is not set
730 bt3c_start(struct bt3c_softc
*sc
)
734 KASSERT((sc
->sc_flags
& BT3C_XMIT
) == 0);
735 KASSERT(sc
->sc_txp
== NULL
);
737 if (MBUFQ_FIRST(&sc
->sc_cmdq
)) {
738 MBUFQ_DEQUEUE(&sc
->sc_cmdq
, m
);
739 sc
->sc_stats
.cmd_tx
++;
743 if (MBUFQ_FIRST(&sc
->sc_scoq
)) {
744 MBUFQ_DEQUEUE(&sc
->sc_scoq
, m
);
745 sc
->sc_stats
.sco_tx
++;
749 if (MBUFQ_FIRST(&sc
->sc_aclq
)) {
750 MBUFQ_DEQUEUE(&sc
->sc_aclq
, m
);
751 sc
->sc_stats
.acl_tx
++;
755 /* Nothing to send */
760 sc
->sc_flags
|= BT3C_XMIT
;
765 bt3c_output_cmd(device_t self
, struct mbuf
*m
)
767 struct bt3c_softc
*sc
= device_private(self
);
770 KASSERT(sc
->sc_flags
& BT3C_ENABLED
);
775 MBUFQ_ENQUEUE(&sc
->sc_cmdq
, m
);
776 if ((sc
->sc_flags
& BT3C_XMIT
) == 0)
783 bt3c_output_acl(device_t self
, struct mbuf
*m
)
785 struct bt3c_softc
*sc
= device_private(self
);
788 KASSERT(sc
->sc_flags
& BT3C_ENABLED
);
793 MBUFQ_ENQUEUE(&sc
->sc_aclq
, m
);
794 if ((sc
->sc_flags
& BT3C_XMIT
) == 0)
801 bt3c_output_sco(device_t self
, struct mbuf
*m
)
803 struct bt3c_softc
*sc
= device_private(self
);
806 KASSERT(sc
->sc_flags
& BT3C_ENABLED
);
809 MBUFQ_ENQUEUE(&sc
->sc_scoq
, m
);
810 if ((sc
->sc_flags
& BT3C_XMIT
) == 0)
820 * establish interrupts
823 bt3c_enable(device_t self
)
825 struct bt3c_softc
*sc
= device_private(self
);
828 if (sc
->sc_flags
& BT3C_ENABLED
)
833 sc
->sc_intr
= pcmcia_intr_establish(sc
->sc_pf
, IPL_TTY
, bt3c_intr
, sc
);
834 if (sc
->sc_intr
== NULL
) {
839 err
= pcmcia_function_enable(sc
->sc_pf
);
843 err
= bt3c_load_firmware(sc
);
847 sc
->sc_flags
|= BT3C_ENABLED
;
848 sc
->sc_flags
&= ~BT3C_XMIT
;
855 pcmcia_function_disable(sc
->sc_pf
);
857 pcmcia_intr_disestablish(sc
->sc_pf
, sc
->sc_intr
);
867 * disestablish interrupts
871 bt3c_disable(device_t self
)
873 struct bt3c_softc
*sc
= device_private(self
);
876 if ((sc
->sc_flags
& BT3C_ENABLED
) == 0)
881 pcmcia_function_disable(sc
->sc_pf
);
884 pcmcia_intr_disestablish(sc
->sc_pf
, sc
->sc_intr
);
898 MBUFQ_DRAIN(&sc
->sc_cmdq
);
899 MBUFQ_DRAIN(&sc
->sc_aclq
);
900 MBUFQ_DRAIN(&sc
->sc_scoq
);
902 sc
->sc_flags
&= ~BT3C_ENABLED
;
907 bt3c_stats(device_t self
, struct bt_stats
*dest
, int flush
)
909 struct bt3c_softc
*sc
= device_private(self
);
913 memcpy(dest
, &sc
->sc_stats
, sizeof(struct bt_stats
));
916 memset(&sc
->sc_stats
, 0, sizeof(struct bt_stats
));
921 /**************************************************************************
923 * bt3c PCMCIA autoconfig glue
927 bt3c_match(device_t parent
, cfdata_t match
, void *aux
)
929 struct pcmcia_attach_args
*pa
= aux
;
931 if (pa
->manufacturer
== PCMCIA_VENDOR_3COM
&&
932 pa
->product
== PCMCIA_PRODUCT_3COM_3CRWB6096
)
933 return 10; /* 'com' also claims this, so trump them */
939 bt3c_attach(device_t parent
, device_t self
, void *aux
)
941 struct bt3c_softc
*sc
= device_private(self
);
942 struct pcmcia_attach_args
*pa
= aux
;
943 struct pcmcia_config_entry
*cfe
;
948 MBUFQ_INIT(&sc
->sc_cmdq
);
949 MBUFQ_INIT(&sc
->sc_aclq
);
950 MBUFQ_INIT(&sc
->sc_scoq
);
952 /* Find a PCMCIA config entry we can use */
953 SIMPLEQ_FOREACH(cfe
, &pa
->pf
->cfe_head
, cfe_list
) {
954 if (cfe
->num_memspace
!= 0)
957 if (cfe
->num_iospace
!= 1)
960 if (pcmcia_io_alloc(pa
->pf
, cfe
->iospace
[0].start
,
961 cfe
->iospace
[0].length
, 0, &sc
->sc_pcioh
) == 0)
966 aprint_error_dev(self
, "cannot allocate io space\n");
967 goto no_config_entry
;
971 pcmcia_function_init(pa
->pf
, cfe
);
973 /* Map in the io space */
974 if (pcmcia_io_map(pa
->pf
, PCMCIA_WIDTH_AUTO
,
975 &sc
->sc_pcioh
, &sc
->sc_iow
)) {
976 aprint_error_dev(self
, "cannot map io space\n");
980 /* Attach Bluetooth unit */
981 sc
->sc_unit
= hci_attach(&bt3c_hci
, self
, BTF_POWER_UP_NOOP
);
982 if (sc
->sc_unit
== NULL
)
983 aprint_error_dev(self
, "HCI attach failed\n");
985 if (!pmf_device_register(self
, bt3c_suspend
, bt3c_resume
))
986 aprint_error_dev(self
, "couldn't establish power handler\n");
992 pcmcia_io_free(pa
->pf
, &sc
->sc_pcioh
);
999 bt3c_detach(device_t self
, int flags
)
1001 struct bt3c_softc
*sc
= device_private(self
);
1004 pmf_device_deregister(self
);
1008 hci_detach(sc
->sc_unit
);
1012 if (sc
->sc_iow
!= -1) {
1013 pcmcia_io_unmap(sc
->sc_pf
, sc
->sc_iow
);
1014 pcmcia_io_free(sc
->sc_pf
, &sc
->sc_pcioh
);
1022 bt3c_suspend(device_t self
, pmf_qual_t qual
)
1024 struct bt3c_softc
*sc
= device_private(self
);
1027 hci_detach(sc
->sc_unit
);
1035 bt3c_resume(device_t self
, pmf_qual_t qual
)
1037 struct bt3c_softc
*sc
= device_private(self
);
1039 KASSERT(sc
->sc_unit
== NULL
);
1041 sc
->sc_unit
= hci_attach(&bt3c_hci
, self
, BTF_POWER_UP_NOOP
);
1042 if (sc
->sc_unit
== NULL
)