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) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Generic Bluetooth SDIO driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2007  Cambridge Silicon Radio Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (C) 2007  Marcel Holtmann <marcel@holtmann.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mmc/host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/mmc/sdio_ids.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/mmc/sdio_func.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <net/bluetooth/bluetooth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/bluetooth/hci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define VERSION "0.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static const struct sdio_device_id btsdio_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	/* Generic Bluetooth Type-A SDIO device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	{ SDIO_DEVICE_CLASS(SDIO_CLASS_BT_A) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	/* Generic Bluetooth Type-B SDIO device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	{ SDIO_DEVICE_CLASS(SDIO_CLASS_BT_B) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	/* Generic Bluetooth AMP controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	{ SDIO_DEVICE_CLASS(SDIO_CLASS_BT_AMP) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	{ }	/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) MODULE_DEVICE_TABLE(sdio, btsdio_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) struct btsdio_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct hci_dev   *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct sdio_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct sk_buff_head txq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define REG_RDAT     0x00	/* Receiver Data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define REG_TDAT     0x00	/* Transmitter Data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define REG_PC_RRT   0x10	/* Read Packet Control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define REG_PC_WRT   0x11	/* Write Packet Control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define REG_RTC_STAT 0x12	/* Retry Control Status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define REG_RTC_SET  0x12	/* Retry Control Set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define REG_INTRD    0x13	/* Interrupt Indication */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define REG_CL_INTRD 0x13	/* Interrupt Clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define REG_EN_INTRD 0x14	/* Interrupt Enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define REG_MD_STAT  0x20	/* Bluetooth Mode Status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define REG_MD_SET   0x20	/* Bluetooth Mode Set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static int btsdio_tx_packet(struct btsdio_data *data, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	BT_DBG("%s", data->hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/* Prepend Type-A header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	skb_push(skb, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	skb->data[0] = (skb->len & 0x0000ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	skb->data[1] = (skb->len & 0x00ff00) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	skb->data[2] = (skb->len & 0xff0000) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	skb->data[3] = hci_skb_pkt_type(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	err = sdio_writesb(data->func, REG_TDAT, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		skb_pull(skb, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		sdio_writeb(data->func, 0x01, REG_PC_WRT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	data->hdev->stat.byte_tx += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static void btsdio_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct btsdio_data *data = container_of(work, struct btsdio_data, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	BT_DBG("%s", data->hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	sdio_claim_host(data->func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	while ((skb = skb_dequeue(&data->txq))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		err = btsdio_tx_packet(data, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			data->hdev->stat.err_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			skb_queue_head(&data->txq, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			break;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	sdio_release_host(data->func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int btsdio_rx_packet(struct btsdio_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	u8 hdr[4] __attribute__ ((aligned(4)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	int err, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	BT_DBG("%s", data->hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	err = sdio_readsb(data->func, hdr, REG_RDAT, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	len = hdr[0] | (hdr[1] << 8) | (hdr[2] << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (len < 4 || len > 65543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		return -EILSEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	skb = bt_skb_alloc(len - 4, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		/* Out of memory. Prepare a read retry and just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		 * return with the expectation that the next time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		 * we're called we'll have more memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	skb_put(skb, len - 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	err = sdio_readsb(data->func, skb->data, REG_RDAT, len - 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		return err;
^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) 	data->hdev->stat.byte_rx += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	switch (hdr[3]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	case HCI_EVENT_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	case HCI_ACLDATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	case HCI_SCODATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	case HCI_ISODATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		hci_skb_pkt_type(skb) = hdr[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		err = hci_recv_frame(data->hdev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	sdio_writeb(data->func, 0x00, REG_PC_RRT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static void btsdio_interrupt(struct sdio_func *func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct btsdio_data *data = sdio_get_drvdata(func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	int intrd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	BT_DBG("%s", data->hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	intrd = sdio_readb(func, REG_INTRD, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (intrd & 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		sdio_writeb(func, 0x01, REG_CL_INTRD, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		if (btsdio_rx_packet(data) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			data->hdev->stat.err_rx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			sdio_writeb(data->func, 0x01, REG_PC_RRT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		}
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static int btsdio_open(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct btsdio_data *data = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	BT_DBG("%s", hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	sdio_claim_host(data->func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	err = sdio_enable_func(data->func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		goto release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	err = sdio_claim_irq(data->func, btsdio_interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		sdio_disable_func(data->func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		goto release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (data->func->class == SDIO_CLASS_BT_B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		sdio_writeb(data->func, 0x00, REG_MD_SET, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	sdio_writeb(data->func, 0x01, REG_EN_INTRD, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	sdio_release_host(data->func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return err;
^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 int btsdio_close(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct btsdio_data *data = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	BT_DBG("%s", hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	sdio_claim_host(data->func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	sdio_writeb(data->func, 0x00, REG_EN_INTRD, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	sdio_release_irq(data->func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	sdio_disable_func(data->func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	sdio_release_host(data->func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static int btsdio_flush(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct btsdio_data *data = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	BT_DBG("%s", hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	skb_queue_purge(&data->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	return 0;
^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) static int btsdio_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	struct btsdio_data *data = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	BT_DBG("%s", hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	switch (hci_skb_pkt_type(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	case HCI_COMMAND_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		hdev->stat.cmd_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	case HCI_ACLDATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		hdev->stat.acl_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	case HCI_SCODATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		hdev->stat.sco_tx++;
^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) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		return -EILSEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	skb_queue_tail(&data->txq, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	schedule_work(&data->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static int btsdio_probe(struct sdio_func *func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 				const struct sdio_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct btsdio_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	struct sdio_func_tuple *tuple = func->tuples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	BT_DBG("func %p id %p class 0x%04x", func, id, func->class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	while (tuple) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		BT_DBG("code 0x%x size %d", tuple->code, tuple->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		tuple = tuple->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	/* Broadcom devices soldered onto the PCB (non-removable) use an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	 * UART connection for Bluetooth, ignore the BT SDIO interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (func->vendor == SDIO_VENDOR_ID_BROADCOM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	    !mmc_card_is_removable(func->card->host)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		switch (func->device) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		case SDIO_DEVICE_ID_BROADCOM_43341:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		case SDIO_DEVICE_ID_BROADCOM_43430:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		case SDIO_DEVICE_ID_BROADCOM_4356:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	data = devm_kzalloc(&func->dev, sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	data->func = func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	INIT_WORK(&data->work, btsdio_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	skb_queue_head_init(&data->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	hdev = hci_alloc_dev();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (!hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	hdev->bus = HCI_SDIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	hci_set_drvdata(hdev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (id->class == SDIO_CLASS_BT_AMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		hdev->dev_type = HCI_AMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		hdev->dev_type = HCI_PRIMARY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	data->hdev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	SET_HCIDEV_DEV(hdev, &func->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	hdev->open     = btsdio_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	hdev->close    = btsdio_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	hdev->flush    = btsdio_flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	hdev->send     = btsdio_send_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (func->vendor == 0x0104 && func->device == 0x00c5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	err = hci_register_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	sdio_set_drvdata(func, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static void btsdio_remove(struct sdio_func *func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	struct btsdio_data *data = sdio_get_drvdata(func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	BT_DBG("func %p", func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	hdev = data->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	sdio_set_drvdata(func, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	hci_unregister_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static struct sdio_driver btsdio_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	.name		= "btsdio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	.probe		= btsdio_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	.remove		= btsdio_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	.id_table	= btsdio_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) module_sdio_driver(btsdio_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) MODULE_DESCRIPTION("Generic Bluetooth SDIO driver ver " VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) MODULE_VERSION(VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) MODULE_LICENSE("GPL");