Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Driver for the 3Com Bluetooth PCMCIA card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2001-2002  Marcel Holtmann <marcel@holtmann.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *                           Jose Orlando Pereira <jop@di.uminho.pt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  it under the terms of the GNU General Public License version 2 as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  published by the Free Software Foundation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *  Software distributed under the License is distributed on an "AS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *  implied. See the License for the specific language governing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *  rights and limitations under the License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *  The initial developer of the original code is David A. Hinds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *  <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *  are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/serial.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/serial_reg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <pcmcia/cistpl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <pcmcia/ciscode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include <pcmcia/ds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #include <pcmcia/cisreg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include <net/bluetooth/bluetooth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #include <net/bluetooth/hci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /* ======================== Module parameters ======================== */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) MODULE_DESCRIPTION("Bluetooth driver for the 3Com Bluetooth PCMCIA card");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) MODULE_FIRMWARE("BT3CPCC.bin");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /* ======================== Local structures ======================== */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) struct bt3c_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct pcmcia_device *p_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	spinlock_t lock;		/* For serializing operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct sk_buff_head txq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	unsigned long tx_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	unsigned long rx_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	unsigned long rx_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct sk_buff *rx_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static int bt3c_config(struct pcmcia_device *link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static void bt3c_release(struct pcmcia_device *link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static void bt3c_detach(struct pcmcia_device *p_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /* Transmit states  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #define XMIT_SENDING  1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #define XMIT_WAKEUP   2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #define XMIT_WAITING  8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) /* Receiver states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #define RECV_WAIT_PACKET_TYPE   0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #define RECV_WAIT_EVENT_HEADER  1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define RECV_WAIT_ACL_HEADER    2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define RECV_WAIT_SCO_HEADER    3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define RECV_WAIT_DATA          4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* ======================== Special I/O functions ======================== */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define DATA_L   0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define DATA_H   1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define ADDR_L   2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define ADDR_H   3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define CONTROL  4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static inline void bt3c_address(unsigned int iobase, unsigned short addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	outb(addr & 0xff, iobase + ADDR_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	outb((addr >> 8) & 0xff, iobase + ADDR_H);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static inline void bt3c_put(unsigned int iobase, unsigned short value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	outb(value & 0xff, iobase + DATA_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	outb((value >> 8) & 0xff, iobase + DATA_H);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static inline void bt3c_io_write(unsigned int iobase, unsigned short addr, unsigned short value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	bt3c_address(iobase, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	bt3c_put(iobase, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static inline unsigned short bt3c_get(unsigned int iobase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	unsigned short value = inb(iobase + DATA_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	value |= inb(iobase + DATA_H) << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static inline unsigned short bt3c_read(unsigned int iobase, unsigned short addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	bt3c_address(iobase, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return bt3c_get(iobase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* ======================== Interrupt handling ======================== */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static int bt3c_write(unsigned int iobase, int fifo_size, __u8 *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	int actual = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	bt3c_address(iobase, 0x7080);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	/* Fill FIFO with current frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	while (actual < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		/* Transmit next byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		bt3c_put(iobase, buf[actual]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		actual++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	bt3c_io_write(iobase, 0x7005, actual);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	return actual;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void bt3c_write_wakeup(struct bt3c_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (!info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		BT_ERR("Unknown device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (test_and_set_bit(XMIT_SENDING, &(info->tx_state)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		unsigned int iobase = info->p_dev->resource[0]->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		register struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (!pcmcia_dev_present(info->p_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		skb = skb_dequeue(&(info->txq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			clear_bit(XMIT_SENDING, &(info->tx_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		/* Send frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		len = bt3c_write(iobase, 256, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		if (len != skb->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			BT_ERR("Very strange");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		info->hdev->stat.byte_tx += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	} while (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static void bt3c_receive(struct bt3c_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	unsigned int iobase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	int size = 0, avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (!info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		BT_ERR("Unknown device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	iobase = info->p_dev->resource[0]->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	avail = bt3c_read(iobase, 0x7006);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	bt3c_address(iobase, 0x7480);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	while (size < avail) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		info->hdev->stat.byte_rx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		/* Allocate packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (!info->rx_skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			info->rx_state = RECV_WAIT_PACKET_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			info->rx_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			if (!info->rx_skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				BT_ERR("Can't allocate mem for new packet");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			hci_skb_pkt_type(info->rx_skb) = inb(iobase + DATA_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			inb(iobase + DATA_H);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			switch (hci_skb_pkt_type(info->rx_skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			case HCI_EVENT_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				info->rx_state = RECV_WAIT_EVENT_HEADER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 				info->rx_count = HCI_EVENT_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			case HCI_ACLDATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 				info->rx_state = RECV_WAIT_ACL_HEADER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 				info->rx_count = HCI_ACL_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			case HCI_SCODATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 				info->rx_state = RECV_WAIT_SCO_HEADER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 				info->rx_count = HCI_SCO_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				/* Unknown packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				BT_ERR("Unknown HCI packet with type 0x%02x received",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				       hci_skb_pkt_type(info->rx_skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				info->hdev->stat.err_rx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 				kfree_skb(info->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 				info->rx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			__u8 x = inb(iobase + DATA_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			skb_put_u8(info->rx_skb, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			inb(iobase + DATA_H);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			info->rx_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			if (info->rx_count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 				int dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 				struct hci_event_hdr *eh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 				struct hci_acl_hdr *ah;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 				struct hci_sco_hdr *sh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 				switch (info->rx_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 				case RECV_WAIT_EVENT_HEADER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 					eh = hci_event_hdr(info->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 					info->rx_state = RECV_WAIT_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 					info->rx_count = eh->plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 				case RECV_WAIT_ACL_HEADER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 					ah = hci_acl_hdr(info->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 					dlen = __le16_to_cpu(ah->dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 					info->rx_state = RECV_WAIT_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 					info->rx_count = dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 				case RECV_WAIT_SCO_HEADER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 					sh = hci_sco_hdr(info->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 					info->rx_state = RECV_WAIT_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 					info->rx_count = sh->dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 				case RECV_WAIT_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 					hci_recv_frame(info->hdev, info->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 					info->rx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	bt3c_io_write(iobase, 0x7006, 0x0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static irqreturn_t bt3c_interrupt(int irq, void *dev_inst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct bt3c_info *info = dev_inst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	unsigned int iobase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	int iir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	irqreturn_t r = IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (!info || !info->hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		/* our irq handler is shared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	iobase = info->p_dev->resource[0]->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	spin_lock(&(info->lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	iir = inb(iobase + CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (iir & 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		int stat = bt3c_read(iobase, 0x7001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		if ((stat & 0xff) == 0x7f) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			BT_ERR("Very strange (stat=0x%04x)", stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		} else if ((stat & 0xff) != 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			if (stat & 0x0020) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 				int status = bt3c_read(iobase, 0x7002) & 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 				bt_dev_info(info->hdev, "Antenna %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 							status ? "out" : "in");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			if (stat & 0x0001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 				bt3c_receive(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			if (stat & 0x0002) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 				clear_bit(XMIT_SENDING, &(info->tx_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 				bt3c_write_wakeup(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 			bt3c_io_write(iobase, 0x7001, 0x0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			outb(iir, iobase + CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		r = IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	spin_unlock(&(info->lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) /* ======================== HCI interface ======================== */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) static int bt3c_hci_flush(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	struct bt3c_info *info = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	/* Drop TX queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	skb_queue_purge(&(info->txq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static int bt3c_hci_open(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static int bt3c_hci_close(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	bt3c_hci_flush(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static int bt3c_hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	struct bt3c_info *info = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	switch (hci_skb_pkt_type(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	case HCI_COMMAND_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		hdev->stat.cmd_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	case HCI_ACLDATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		hdev->stat.acl_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	case HCI_SCODATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		hdev->stat.sco_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	/* Prepend skb with frame type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	skb_queue_tail(&(info->txq), skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	spin_lock_irqsave(&(info->lock), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	bt3c_write_wakeup(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	spin_unlock_irqrestore(&(info->lock), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /* ======================== Card services HCI interaction ======================== */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static int bt3c_load_firmware(struct bt3c_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 			      const unsigned char *firmware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 			      int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	char *ptr = (char *) firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	char b[9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	unsigned int iobase, tmp, tn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	unsigned long size, addr, fcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	int i, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	iobase = info->p_dev->resource[0]->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	/* Reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	bt3c_io_write(iobase, 0x8040, 0x0404);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	bt3c_io_write(iobase, 0x8040, 0x0400);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	bt3c_io_write(iobase, 0x8040, 0x0404);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	udelay(17);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	/* Load */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		if (ptr[0] != 'S') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 			BT_ERR("Bad address in firmware");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		memset(b, 0, sizeof(b));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		memcpy(b, ptr + 2, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		if (kstrtoul(b, 16, &size) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		memset(b, 0, sizeof(b));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		memcpy(b, ptr + 4, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		if (kstrtoul(b, 16, &addr) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		memset(b, 0, sizeof(b));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		memcpy(b, ptr + (size * 2) + 2, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		if (kstrtoul(b, 16, &fcs) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		memset(b, 0, sizeof(b));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		for (tmp = 0, i = 0; i < size; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 			memcpy(b, ptr + (i * 2) + 2, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 			if (kstrtouint(b, 16, &tn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 			tmp += tn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		if (((tmp + fcs) & 0xff) != 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			BT_ERR("Checksum error in firmware");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			err = -EILSEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		if (ptr[1] == '3') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 			bt3c_address(iobase, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			memset(b, 0, sizeof(b));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 			for (i = 0; i < (size - 4) / 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 				memcpy(b, ptr + (i * 4) + 12, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 				if (kstrtouint(b, 16, &tmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 					return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 				bt3c_put(iobase, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		ptr   += (size * 2) + 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		count -= (size * 2) + 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	udelay(17);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	/* Boot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	bt3c_address(iobase, 0x3000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	outb(inb(iobase + CONTROL) | 0x40, iobase + CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	udelay(17);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	/* Clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	bt3c_io_write(iobase, 0x7006, 0x0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	bt3c_io_write(iobase, 0x7005, 0x0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	bt3c_io_write(iobase, 0x7001, 0x0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static int bt3c_open(struct bt3c_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	const struct firmware *firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	spin_lock_init(&(info->lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	skb_queue_head_init(&(info->txq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	info->rx_state = RECV_WAIT_PACKET_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	info->rx_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	info->rx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	/* Initialize HCI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	hdev = hci_alloc_dev();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		BT_ERR("Can't allocate HCI device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	info->hdev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	hdev->bus = HCI_PCCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	hci_set_drvdata(hdev, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	SET_HCIDEV_DEV(hdev, &info->p_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	hdev->open  = bt3c_hci_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	hdev->close = bt3c_hci_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	hdev->flush = bt3c_hci_flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	hdev->send  = bt3c_hci_send_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	/* Load firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	err = request_firmware(&firmware, "BT3CPCC.bin", &info->p_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		BT_ERR("Firmware request failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	err = bt3c_load_firmware(info, firmware->data, firmware->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	release_firmware(firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		BT_ERR("Firmware loading failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	/* Timeout before it is safe to send the first HCI packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	/* Register HCI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	err = hci_register_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		BT_ERR("Can't register HCI device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	info->hdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static int bt3c_close(struct bt3c_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	struct hci_dev *hdev = info->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	if (!hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	bt3c_hci_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	hci_unregister_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) static int bt3c_probe(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	struct bt3c_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	/* Create new info device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	info = devm_kzalloc(&link->dev, sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	info->p_dev = link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	link->priv = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		CONF_AUTO_SET_IO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	return bt3c_config(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) static void bt3c_detach(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	bt3c_release(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static int bt3c_check_config(struct pcmcia_device *p_dev, void *priv_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	int *try = priv_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	if (!try)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		p_dev->io_lines = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	if ((p_dev->resource[0]->end != 8) || (p_dev->resource[0]->start == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	p_dev->resource[0]->end = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	return pcmcia_request_io(p_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) static int bt3c_check_config_notpicky(struct pcmcia_device *p_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 				      void *priv_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	if (p_dev->io_lines > 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	p_dev->resource[0]->end = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	for (j = 0; j < 5; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		p_dev->resource[0]->start = base[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		p_dev->io_lines = base[j] ? 16 : 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		if (!pcmcia_request_io(p_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) static int bt3c_config(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	struct bt3c_info *info = link->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	unsigned long try;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	/* First pass: look for a config entry that looks normal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	 * Two tries: without IO aliases, then with aliases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	for (try = 0; try < 2; try++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 		if (!pcmcia_loop_config(link, bt3c_check_config, (void *) try))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 			goto found_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	/* Second pass: try to find an entry that isn't picky about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	 * its base address, then try to grab any standard serial port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	 * address, and finally try to get any free port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	if (!pcmcia_loop_config(link, bt3c_check_config_notpicky, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 		goto found_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	BT_ERR("No usable port range found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) found_port:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	i = pcmcia_request_irq(link, &bt3c_interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	if (i != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	i = pcmcia_enable_device(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	if (i != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	if (bt3c_open(info) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	bt3c_release(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) static void bt3c_release(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	struct bt3c_info *info = link->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	bt3c_close(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	pcmcia_disable_device(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) static const struct pcmcia_device_id bt3c_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	PCMCIA_DEVICE_PROD_ID13("3COM", "Bluetooth PC Card", 0xefce0a31, 0xd4ce9b02),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	PCMCIA_DEVICE_NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) MODULE_DEVICE_TABLE(pcmcia, bt3c_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) static struct pcmcia_driver bt3c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	.name		= "bt3c_cs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	.probe		= bt3c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	.remove		= bt3c_detach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	.id_table	= bt3c_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) module_pcmcia_driver(bt3c_driver);