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)  *  Bluetooth HCI UART driver for Broadcom devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *  Copyright (C) 2015  Intel Corporation
^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) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/of_irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/property.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/platform_data/x86/apple.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/serdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <net/bluetooth/bluetooth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <net/bluetooth/hci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include "btbcm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include "hci_uart.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #define BCM_NULL_PKT 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #define BCM_NULL_SIZE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #define BCM_LM_DIAG_PKT 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #define BCM_LM_DIAG_SIZE 63
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #define BCM_TYPE49_PKT 0x31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #define BCM_TYPE49_SIZE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define BCM_TYPE52_PKT 0x34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #define BCM_TYPE52_SIZE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #define BCM_AUTOSUSPEND_DELAY	5000 /* default autosleep delay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #define BCM_NUM_SUPPLIES 2
^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)  * struct bcm_device_data - device specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53)  * @no_early_set_baudrate: Disallow set baudrate before driver setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) struct bcm_device_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	bool	no_early_set_baudrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	bool	drive_rts_on_open;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61)  * struct bcm_device - device driver resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)  * @serdev_hu: HCI UART controller struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)  * @list: bcm_device_list node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  * @dev: physical UART slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65)  * @name: device name logged by bt_dev_*() functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66)  * @device_wakeup: BT_WAKE pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  *	assert = Bluetooth device must wake up or remain awake,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  *	deassert = Bluetooth device may sleep when sleep criteria are met
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  * @shutdown: BT_REG_ON pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  *	power up or power down Bluetooth device internal regulators
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  * @set_device_wakeup: callback to toggle BT_WAKE pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  *	either by accessing @device_wakeup or by calling @btlp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)  * @set_shutdown: callback to toggle BT_REG_ON pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74)  *	either by accessing @shutdown or by calling @btpu/@btpd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  * @btlp: Apple ACPI method to toggle BT_WAKE pin ("Bluetooth Low Power")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  * @btpu: Apple ACPI method to drive BT_REG_ON pin high ("Bluetooth Power Up")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)  * @btpd: Apple ACPI method to drive BT_REG_ON pin low ("Bluetooth Power Down")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78)  * @txco_clk: external reference frequency clock used by Bluetooth device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79)  * @lpo_clk: external LPO clock used by Bluetooth device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)  * @supplies: VBAT and VDDIO supplies used by Bluetooth device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)  * @res_enabled: whether clocks and supplies are prepared and enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)  * @init_speed: default baudrate of Bluetooth device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)  *	the host UART is initially set to this baudrate so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  *	it can configure the Bluetooth device for @oper_speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)  * @oper_speed: preferred baudrate of Bluetooth device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86)  *	set to 0 if @init_speed is already the preferred baudrate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87)  * @irq: interrupt triggered by HOST_WAKE_BT pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88)  * @irq_active_low: whether @irq is active low
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)  * @hu: pointer to HCI UART controller struct,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  *	used to disable flow control during runtime suspend and system sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * @is_suspended: whether flow control is currently disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  * @no_early_set_baudrate: don't set_baudrate before setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) struct bcm_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	/* Must be the first member, hci_serdev.c expects this. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	struct hci_uart		serdev_hu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	struct list_head	list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	struct device		*dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	const char		*name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	struct gpio_desc	*device_wakeup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	struct gpio_desc	*shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	int			(*set_device_wakeup)(struct bcm_device *, bool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	int			(*set_shutdown)(struct bcm_device *, bool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	acpi_handle		btlp, btpu, btpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	int			gpio_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	int			gpio_int_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	struct clk		*txco_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	struct clk		*lpo_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	struct regulator_bulk_data supplies[BCM_NUM_SUPPLIES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	bool			res_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	u32			init_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	u32			oper_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	int			irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	bool			irq_active_low;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	bool			irq_acquired;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	struct hci_uart		*hu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	bool			is_suspended;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	bool			no_early_set_baudrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	bool			drive_rts_on_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	u8			pcm_int_params[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) /* generic bcm uart resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) struct bcm_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	struct sk_buff		*rx_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	struct sk_buff_head	txq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	struct bcm_device	*dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) /* List of BCM BT UART devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) static DEFINE_MUTEX(bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) static LIST_HEAD(bcm_device_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static int irq_polarity = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) module_param(irq_polarity, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) MODULE_PARM_DESC(irq_polarity, "IRQ polarity 0: active-high 1: active-low");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	if (hu->serdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		serdev_device_set_baudrate(hu->serdev, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 		hci_uart_set_baudrate(hu, speed);
^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) static int bcm_set_baudrate(struct hci_uart *hu, unsigned int speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	struct hci_dev *hdev = hu->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	struct bcm_update_uart_baud_rate param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	if (speed > 3000000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 		struct bcm_write_uart_clock_setting clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 		clock.type = BCM_UART_CLOCK_48MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		bt_dev_dbg(hdev, "Set Controller clock (%d)", clock.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 		/* This Broadcom specific command changes the UART's controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 		 * clock for baud rate > 3000000.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		skb = __hci_cmd_sync(hdev, 0xfc45, 1, &clock, HCI_INIT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		if (IS_ERR(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 			int err = PTR_ERR(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 			bt_dev_err(hdev, "BCM: failed to write clock (%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 				   err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	bt_dev_dbg(hdev, "Set Controller UART speed to %d bit/s", speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	param.zero = cpu_to_le16(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	param.baud_rate = cpu_to_le32(speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	/* This Broadcom specific command changes the UART's controller baud
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	 * rate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	skb = __hci_cmd_sync(hdev, 0xfc18, sizeof(param), &param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 			     HCI_INIT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	if (IS_ERR(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 		int err = PTR_ERR(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 		bt_dev_err(hdev, "BCM: failed to write update baudrate (%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 			   err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	return 0;
^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) /* bcm_device_exists should be protected by bcm_device_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) static bool bcm_device_exists(struct bcm_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	struct list_head *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	/* Devices using serdev always exist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	if (device && device->hu && device->hu->serdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	list_for_each(p, &bcm_device_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 		struct bcm_device *dev = list_entry(p, struct bcm_device, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		if (device == dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	return false;
^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) static int bcm_gpio_set_power(struct bcm_device *dev, bool powered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	if (powered && !dev->res_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		/* Intel Macs use bcm_apple_get_resources() and don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 		 * have regulator supplies configured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		if (dev->supplies[0].supply) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 			err = regulator_bulk_enable(BCM_NUM_SUPPLIES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 						    dev->supplies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		/* LPO clock needs to be 32.768 kHz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		err = clk_set_rate(dev->lpo_clk, 32768);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 			dev_err(dev->dev, "Could not set LPO clock rate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 			goto err_regulator_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		err = clk_prepare_enable(dev->lpo_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 			goto err_regulator_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		err = clk_prepare_enable(dev->txco_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 			goto err_lpo_clk_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	err = dev->set_shutdown(dev, powered);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		goto err_txco_clk_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	err = dev->set_device_wakeup(dev, powered);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		goto err_revert_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	if (!powered && dev->res_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 		clk_disable_unprepare(dev->txco_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 		clk_disable_unprepare(dev->lpo_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		/* Intel Macs use bcm_apple_get_resources() and don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		 * have regulator supplies configured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 		if (dev->supplies[0].supply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 			regulator_bulk_disable(BCM_NUM_SUPPLIES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 					       dev->supplies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	/* wait for device to power on and come out of reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	usleep_range(100000, 120000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	dev->res_enabled = powered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) err_revert_shutdown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	dev->set_shutdown(dev, !powered);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) err_txco_clk_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	if (powered && !dev->res_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		clk_disable_unprepare(dev->txco_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) err_lpo_clk_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	if (powered && !dev->res_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		clk_disable_unprepare(dev->lpo_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) err_regulator_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	if (powered && !dev->res_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		regulator_bulk_disable(BCM_NUM_SUPPLIES, dev->supplies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) static irqreturn_t bcm_host_wake(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	struct bcm_device *bdev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	bt_dev_dbg(bdev, "Host wake IRQ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	pm_runtime_get(bdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	pm_runtime_mark_last_busy(bdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	pm_runtime_put_autosuspend(bdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) static int bcm_request_irq(struct bcm_data *bcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	struct bcm_device *bdev = bcm->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	mutex_lock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	if (!bcm_device_exists(bdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		goto unlock;
^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) 	if (bdev->irq <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		goto unlock;
^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) 	err = devm_request_irq(bdev->dev, bdev->irq, bcm_host_wake,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 			       bdev->irq_active_low ? IRQF_TRIGGER_FALLING :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 						      IRQF_TRIGGER_RISING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 			       "host_wake", bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		bdev->irq = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	bdev->irq_acquired = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	device_init_wakeup(bdev->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	pm_runtime_set_autosuspend_delay(bdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 					 BCM_AUTOSUSPEND_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	pm_runtime_use_autosuspend(bdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	pm_runtime_set_active(bdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	pm_runtime_enable(bdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	mutex_unlock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) static const struct bcm_set_sleep_mode default_sleep_params = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	.sleep_mode = 1,	/* 0=Disabled, 1=UART, 2=Reserved, 3=USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	.idle_host = 2,		/* idle threshold HOST, in 300ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	.idle_dev = 2,		/* idle threshold device, in 300ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	.bt_wake_active = 1,	/* BT_WAKE active mode: 1 = high, 0 = low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	.host_wake_active = 0,	/* HOST_WAKE active mode: 1 = high, 0 = low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	.allow_host_sleep = 1,	/* Allow host sleep in SCO flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	.combine_modes = 1,	/* Combine sleep and LPM flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	.tristate_control = 0,	/* Allow tri-state control of UART tx flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	/* Irrelevant USB flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	.usb_auto_sleep = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	.usb_resume_timeout = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	.break_to_host = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	.pulsed_host_wake = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) static int bcm_setup_sleep(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	struct bcm_data *bcm = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	struct bcm_set_sleep_mode sleep_params = default_sleep_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	sleep_params.host_wake_active = !bcm->dev->irq_active_low;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	skb = __hci_cmd_sync(hu->hdev, 0xfc27, sizeof(sleep_params),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 			     &sleep_params, HCI_INIT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	if (IS_ERR(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		int err = PTR_ERR(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		bt_dev_err(hu->hdev, "Sleep VSC failed (%d)", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	bt_dev_dbg(hu->hdev, "Set Sleep Parameters VSC succeeded");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) static inline int bcm_request_irq(struct bcm_data *bcm) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) static inline int bcm_setup_sleep(struct hci_uart *hu) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) static int bcm_set_diag(struct hci_dev *hdev, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	struct hci_uart *hu = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	struct bcm_data *bcm = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	if (!test_bit(HCI_RUNNING, &hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		return -ENETDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	skb = bt_skb_alloc(3, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	skb_put_u8(skb, BCM_LM_DIAG_PKT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	skb_put_u8(skb, 0xf0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	skb_put_u8(skb, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	skb_queue_tail(&bcm->txq, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	hci_uart_tx_wakeup(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) static int bcm_open(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	struct bcm_data *bcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	struct list_head *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	bt_dev_dbg(hu->hdev, "hu %p", hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	if (!hci_uart_has_flow_control(hu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	bcm = kzalloc(sizeof(*bcm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	if (!bcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	skb_queue_head_init(&bcm->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	hu->priv = bcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	mutex_lock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	if (hu->serdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		bcm->dev = serdev_device_get_drvdata(hu->serdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	if (!hu->tty->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	list_for_each(p, &bcm_device_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		struct bcm_device *dev = list_entry(p, struct bcm_device, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		/* Retrieve saved bcm_device based on parent of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		 * platform device (saved during device probe) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		 * parent of tty device used by hci_uart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		if (hu->tty->dev->parent == dev->dev->parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			bcm->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 			dev->hu = hu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	if (bcm->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		if (bcm->dev->drive_rts_on_open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 			hci_uart_set_flow_control(hu, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		hu->init_speed = bcm->dev->init_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		/* If oper_speed is set, ldisc/serdev will set the baudrate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		 * before calling setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		if (!bcm->dev->no_early_set_baudrate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 			hu->oper_speed = bcm->dev->oper_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		err = bcm_gpio_set_power(bcm->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		if (bcm->dev->drive_rts_on_open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 			hci_uart_set_flow_control(hu, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 			goto err_unset_hu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	mutex_unlock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) err_unset_hu:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	if (!hu->serdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		bcm->dev->hu = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	mutex_unlock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	hu->priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	kfree(bcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) static int bcm_close(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	struct bcm_data *bcm = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	struct bcm_device *bdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	bt_dev_dbg(hu->hdev, "hu %p", hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	/* Protect bcm->dev against removal of the device or driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	mutex_lock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	if (hu->serdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		bdev = serdev_device_get_drvdata(hu->serdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	} else if (bcm_device_exists(bcm->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		bdev = bcm->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		bdev->hu = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	if (bdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		if (IS_ENABLED(CONFIG_PM) && bdev->irq_acquired) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 			devm_free_irq(bdev->dev, bdev->irq, bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 			device_init_wakeup(bdev->dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 			pm_runtime_disable(bdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		err = bcm_gpio_set_power(bdev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			bt_dev_err(hu->hdev, "Failed to power down");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 			pm_runtime_set_suspended(bdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	mutex_unlock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	skb_queue_purge(&bcm->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	kfree_skb(bcm->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	kfree(bcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	hu->priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) static int bcm_flush(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	struct bcm_data *bcm = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	bt_dev_dbg(hu->hdev, "hu %p", hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	skb_queue_purge(&bcm->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) static int bcm_setup(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	struct bcm_data *bcm = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	bool fw_load_done = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	unsigned int speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	bt_dev_dbg(hu->hdev, "hu %p", hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	hu->hdev->set_diag = bcm_set_diag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	hu->hdev->set_bdaddr = btbcm_set_bdaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	err = btbcm_initialize(hu->hdev, &fw_load_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	if (!fw_load_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	/* Init speed if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	if (hu->init_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		speed = hu->init_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	else if (hu->proto->init_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		speed = hu->proto->init_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	if (speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		host_set_baudrate(hu, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	/* Operational speed if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	if (hu->oper_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		speed = hu->oper_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	else if (bcm->dev && bcm->dev->oper_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		speed = bcm->dev->oper_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	else if (hu->proto->oper_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		speed = hu->proto->oper_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	if (speed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		err = bcm_set_baudrate(hu, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 			host_set_baudrate(hu, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	/* PCM parameters if provided */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	if (bcm->dev && bcm->dev->pcm_int_params[0] != 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		struct bcm_set_pcm_int_params params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		btbcm_read_pcm_int_params(hu->hdev, &params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		memcpy(&params, bcm->dev->pcm_int_params, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		btbcm_write_pcm_int_params(hu->hdev, &params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	err = btbcm_finalize(hu->hdev, &fw_load_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	/* Some devices ship with the controller default address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	 * Allow the bootloader to set a valid address through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	 * device tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hu->hdev->quirks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	if (!bcm_request_irq(bcm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		err = bcm_setup_sleep(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) #define BCM_RECV_LM_DIAG \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	.type = BCM_LM_DIAG_PKT, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	.hlen = BCM_LM_DIAG_SIZE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	.loff = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	.lsize = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	.maxlen = BCM_LM_DIAG_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) #define BCM_RECV_NULL \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	.type = BCM_NULL_PKT, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	.hlen = BCM_NULL_SIZE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	.loff = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	.lsize = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	.maxlen = BCM_NULL_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) #define BCM_RECV_TYPE49 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	.type = BCM_TYPE49_PKT, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	.hlen = BCM_TYPE49_SIZE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	.loff = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	.lsize = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	.maxlen = BCM_TYPE49_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) #define BCM_RECV_TYPE52 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	.type = BCM_TYPE52_PKT, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	.hlen = BCM_TYPE52_SIZE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	.loff = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	.lsize = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	.maxlen = BCM_TYPE52_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) static const struct h4_recv_pkt bcm_recv_pkts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	{ H4_RECV_ACL,      .recv = hci_recv_frame },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	{ H4_RECV_SCO,      .recv = hci_recv_frame },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	{ H4_RECV_EVENT,    .recv = hci_recv_frame },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	{ H4_RECV_ISO,      .recv = hci_recv_frame },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	{ BCM_RECV_LM_DIAG, .recv = hci_recv_diag  },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	{ BCM_RECV_NULL,    .recv = hci_recv_diag  },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	{ BCM_RECV_TYPE49,  .recv = hci_recv_diag  },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	{ BCM_RECV_TYPE52,  .recv = hci_recv_diag  },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) static int bcm_recv(struct hci_uart *hu, const void *data, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	struct bcm_data *bcm = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		return -EUNATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	bcm->rx_skb = h4_recv_buf(hu->hdev, bcm->rx_skb, data, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 				  bcm_recv_pkts, ARRAY_SIZE(bcm_recv_pkts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	if (IS_ERR(bcm->rx_skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		int err = PTR_ERR(bcm->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		bcm->rx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	} else if (!bcm->rx_skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		/* Delay auto-suspend when receiving completed packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		mutex_lock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		if (bcm->dev && bcm_device_exists(bcm->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 			pm_runtime_get(bcm->dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 			pm_runtime_mark_last_busy(bcm->dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 			pm_runtime_put_autosuspend(bcm->dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		mutex_unlock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) static int bcm_enqueue(struct hci_uart *hu, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	struct bcm_data *bcm = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	bt_dev_dbg(hu->hdev, "hu %p skb %p", hu, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	/* Prepend skb with frame type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	skb_queue_tail(&bcm->txq, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) static struct sk_buff *bcm_dequeue(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	struct bcm_data *bcm = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	struct sk_buff *skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	struct bcm_device *bdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	mutex_lock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	if (bcm_device_exists(bcm->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		bdev = bcm->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		pm_runtime_get_sync(bdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		/* Shall be resumed here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	skb = skb_dequeue(&bcm->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	if (bdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		pm_runtime_mark_last_busy(bdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		pm_runtime_put_autosuspend(bdev->dev);
^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) 	mutex_unlock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) static int bcm_suspend_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	struct bcm_device *bdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	bt_dev_dbg(bdev, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	if (!bdev->is_suspended && bdev->hu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		hci_uart_set_flow_control(bdev->hu, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		/* Once this returns, driver suspends BT via GPIO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		bdev->is_suspended = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	/* Suspend the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	err = bdev->set_device_wakeup(bdev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		if (bdev->is_suspended && bdev->hu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 			bdev->is_suspended = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 			hci_uart_set_flow_control(bdev->hu, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	bt_dev_dbg(bdev, "suspend, delaying 15 ms");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	msleep(15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) static int bcm_resume_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	struct bcm_device *bdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	bt_dev_dbg(bdev, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	err = bdev->set_device_wakeup(bdev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		dev_err(dev, "Failed to power up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	bt_dev_dbg(bdev, "resume, delaying 15 ms");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	msleep(15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	/* When this executes, the device has woken up already */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	if (bdev->is_suspended && bdev->hu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		bdev->is_suspended = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		hci_uart_set_flow_control(bdev->hu, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) /* suspend callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) static int bcm_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	struct bcm_device *bdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	bt_dev_dbg(bdev, "suspend: is_suspended %d", bdev->is_suspended);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	 * When used with a device instantiated as platform_device, bcm_suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	 * can be called at any time as long as the platform device is bound,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	 * so it should use bcm_device_lock to protect access to hci_uart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	 * and device_wake-up GPIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	mutex_lock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	if (!bdev->hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	if (pm_runtime_active(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		bcm_suspend_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	if (device_may_wakeup(dev) && bdev->irq > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		error = enable_irq_wake(bdev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 			bt_dev_dbg(bdev, "BCM irq: enabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	mutex_unlock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) /* resume callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) static int bcm_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	struct bcm_device *bdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	bt_dev_dbg(bdev, "resume: is_suspended %d", bdev->is_suspended);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	 * When used with a device instantiated as platform_device, bcm_resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	 * can be called at any time as long as platform device is bound,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	 * so it should use bcm_device_lock to protect access to hci_uart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	 * and device_wake-up GPIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	mutex_lock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	if (!bdev->hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	if (device_may_wakeup(dev) && bdev->irq > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		disable_irq_wake(bdev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		bt_dev_dbg(bdev, "BCM irq: disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	err = bcm_resume_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	mutex_unlock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		pm_runtime_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		pm_runtime_set_active(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		pm_runtime_enable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) /* Some firmware reports an IRQ which does not work (wrong pin in fw table?) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) static const struct dmi_system_id bcm_broken_irq_dmi_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		.ident = "Meegopad T08",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		.matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 			DMI_EXACT_MATCH(DMI_BOARD_VENDOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 					"To be filled by OEM."),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "T3 MRD"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 			DMI_EXACT_MATCH(DMI_BOARD_VERSION, "V1.1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) static const struct acpi_gpio_params first_gpio = { 0, 0, false };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) static const struct acpi_gpio_params second_gpio = { 1, 0, false };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) static const struct acpi_gpio_params third_gpio = { 2, 0, false };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) static const struct acpi_gpio_mapping acpi_bcm_int_last_gpios[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	{ "device-wakeup-gpios", &first_gpio, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	{ "shutdown-gpios", &second_gpio, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	{ "host-wakeup-gpios", &third_gpio, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) static const struct acpi_gpio_mapping acpi_bcm_int_first_gpios[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	{ "host-wakeup-gpios", &first_gpio, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	{ "device-wakeup-gpios", &second_gpio, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	{ "shutdown-gpios", &third_gpio, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) static int bcm_resource(struct acpi_resource *ares, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	struct bcm_device *dev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	struct acpi_resource_extended_irq *irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	struct acpi_resource_gpio *gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	struct acpi_resource_uart_serialbus *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	switch (ares->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		irq = &ares->data.extended_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		if (irq->polarity != ACPI_ACTIVE_LOW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 			dev_info(dev->dev, "ACPI Interrupt resource is active-high, this is usually wrong, treating the IRQ as active-low\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		dev->irq_active_low = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	case ACPI_RESOURCE_TYPE_GPIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		gpio = &ares->data.gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		if (gpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 			dev->gpio_int_idx = dev->gpio_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 			dev->irq_active_low = gpio->polarity == ACPI_ACTIVE_LOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		dev->gpio_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	case ACPI_RESOURCE_TYPE_SERIAL_BUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		sb = &ares->data.uart_serial_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_UART) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 			dev->init_speed = sb->default_baud_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			dev->oper_speed = 4000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) static int bcm_apple_set_device_wakeup(struct bcm_device *dev, bool awake)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	if (ACPI_FAILURE(acpi_execute_simple_method(dev->btlp, NULL, !awake)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) static int bcm_apple_set_shutdown(struct bcm_device *dev, bool powered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	if (ACPI_FAILURE(acpi_evaluate_object(powered ? dev->btpu : dev->btpd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 					      NULL, NULL, NULL)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) static int bcm_apple_get_resources(struct bcm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	struct acpi_device *adev = ACPI_COMPANION(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	const union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	if (!adev ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	    ACPI_FAILURE(acpi_get_handle(adev->handle, "BTLP", &dev->btlp)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	    ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPU", &dev->btpu)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	    ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPD", &dev->btpd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	if (!acpi_dev_get_property(adev, "baud", ACPI_TYPE_BUFFER, &obj) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	    obj->buffer.length == 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		dev->init_speed = *(u64 *)obj->buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	dev->set_device_wakeup = bcm_apple_set_device_wakeup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	dev->set_shutdown = bcm_apple_set_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) static inline int bcm_apple_get_resources(struct bcm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) #endif /* CONFIG_ACPI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) static int bcm_gpio_set_device_wakeup(struct bcm_device *dev, bool awake)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	gpiod_set_value_cansleep(dev->device_wakeup, awake);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) static int bcm_gpio_set_shutdown(struct bcm_device *dev, bool powered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	gpiod_set_value_cansleep(dev->shutdown, powered);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) /* Try a bunch of names for TXCO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) static struct clk *bcm_get_txco(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	/* New explicit name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	clk = devm_clk_get(dev, "txco");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		return clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	/* Deprecated name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	clk = devm_clk_get(dev, "extclk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		return clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	/* Original code used no name at all */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	return devm_clk_get(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) static int bcm_get_resources(struct bcm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	const struct dmi_system_id *dmi_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	dev->name = dev_name(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	if (x86_apple_machine && !bcm_apple_get_resources(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	dev->txco_clk = bcm_get_txco(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	/* Handle deferred probing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	if (dev->txco_clk == ERR_PTR(-EPROBE_DEFER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		return PTR_ERR(dev->txco_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	/* Ignore all other errors as before */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	if (IS_ERR(dev->txco_clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		dev->txco_clk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	dev->lpo_clk = devm_clk_get(dev->dev, "lpo");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	if (dev->lpo_clk == ERR_PTR(-EPROBE_DEFER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		return PTR_ERR(dev->lpo_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	if (IS_ERR(dev->lpo_clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		dev->lpo_clk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	/* Check if we accidentally fetched the lpo clock twice */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	if (dev->lpo_clk && clk_is_match(dev->lpo_clk, dev->txco_clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		devm_clk_put(dev->dev, dev->txco_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		dev->txco_clk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	dev->device_wakeup = devm_gpiod_get_optional(dev->dev, "device-wakeup",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 						     GPIOD_OUT_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	if (IS_ERR(dev->device_wakeup))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		return PTR_ERR(dev->device_wakeup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	dev->shutdown = devm_gpiod_get_optional(dev->dev, "shutdown",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 						GPIOD_OUT_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	if (IS_ERR(dev->shutdown))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		return PTR_ERR(dev->shutdown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	dev->set_device_wakeup = bcm_gpio_set_device_wakeup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	dev->set_shutdown = bcm_gpio_set_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	dev->supplies[0].supply = "vbat";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	dev->supplies[1].supply = "vddio";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	err = devm_regulator_bulk_get(dev->dev, BCM_NUM_SUPPLIES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 				      dev->supplies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	/* IRQ can be declared in ACPI table as Interrupt or GpioInt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	if (dev->irq <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		struct gpio_desc *gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		gpio = devm_gpiod_get_optional(dev->dev, "host-wakeup",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 					       GPIOD_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		if (IS_ERR(gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 			return PTR_ERR(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		dev->irq = gpiod_to_irq(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	dmi_id = dmi_first_match(bcm_broken_irq_dmi_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	if (dmi_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		dev_info(dev->dev, "%s: Has a broken IRQ config, disabling IRQ support / runtime-pm\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 			 dmi_id->ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		dev->irq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	dev_dbg(dev->dev, "BCM irq: %d\n", dev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) static int bcm_acpi_probe(struct bcm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	LIST_HEAD(resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	const struct acpi_gpio_mapping *gpio_mapping = acpi_bcm_int_last_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	struct resource_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	/* Retrieve UART ACPI info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	dev->gpio_int_idx = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	ret = acpi_dev_get_resources(ACPI_COMPANION(dev->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 				     &resources, bcm_resource, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	resource_list_for_each_entry(entry, &resources) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		if (resource_type(entry->res) == IORESOURCE_IRQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			dev->irq = entry->res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	acpi_dev_free_resource_list(&resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	/* If the DSDT uses an Interrupt resource for the IRQ, then there are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	 * only 2 GPIO resources, we use the irq-last mapping for this, since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	 * we already have an irq the 3th / last mapping will not be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	if (dev->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		gpio_mapping = acpi_bcm_int_last_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	else if (dev->gpio_int_idx == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 		gpio_mapping = acpi_bcm_int_first_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	else if (dev->gpio_int_idx == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		gpio_mapping = acpi_bcm_int_last_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		dev_warn(dev->dev, "Unexpected ACPI gpio_int_idx: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 			 dev->gpio_int_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	/* Warn if our expectations are not met. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	if (dev->gpio_count != (dev->irq ? 2 : 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		dev_warn(dev->dev, "Unexpected number of ACPI GPIOs: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 			 dev->gpio_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	ret = devm_acpi_dev_add_driver_gpios(dev->dev, gpio_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	if (irq_polarity != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 		dev->irq_active_low = irq_polarity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		dev_warn(dev->dev, "Overwriting IRQ polarity to active %s by module-param\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 			 dev->irq_active_low ? "low" : "high");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) static int bcm_acpi_probe(struct bcm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) #endif /* CONFIG_ACPI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) static int bcm_of_probe(struct bcm_device *bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	device_property_read_u32(bdev->dev, "max-speed", &bdev->oper_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	device_property_read_u8_array(bdev->dev, "brcm,bt-pcm-int-params",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 				      bdev->pcm_int_params, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	bdev->irq = of_irq_get_byname(bdev->dev->of_node, "host-wakeup");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	bdev->irq_active_low = irq_get_trigger_type(bdev->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 			     & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static int bcm_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	struct bcm_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	dev->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	ret = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	dev->irq = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	/* Initialize routing field to an unused value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	dev->pcm_int_params[0] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	if (has_acpi_companion(&pdev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		ret = bcm_acpi_probe(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	ret = bcm_get_resources(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	platform_set_drvdata(pdev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	dev_info(&pdev->dev, "%s device registered.\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	/* Place this instance on the device list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	mutex_lock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	list_add_tail(&dev->list, &bcm_device_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	mutex_unlock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	ret = bcm_gpio_set_power(dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		dev_err(&pdev->dev, "Failed to power down\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) static int bcm_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	struct bcm_device *dev = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	mutex_lock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	list_del(&dev->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	mutex_unlock(&bcm_device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	dev_info(&pdev->dev, "%s device unregistered.\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) static const struct hci_uart_proto bcm_proto = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	.id		= HCI_UART_BCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	.name		= "Broadcom",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	.manufacturer	= 15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	.init_speed	= 115200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	.open		= bcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	.close		= bcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	.flush		= bcm_flush,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	.setup		= bcm_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	.set_baudrate	= bcm_set_baudrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	.recv		= bcm_recv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	.enqueue	= bcm_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	.dequeue	= bcm_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) static const struct acpi_device_id bcm_acpi_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	{ "BCM2E00" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	{ "BCM2E01" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	{ "BCM2E02" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	{ "BCM2E03" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	{ "BCM2E04" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	{ "BCM2E05" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	{ "BCM2E06" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	{ "BCM2E07" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	{ "BCM2E08" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	{ "BCM2E09" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	{ "BCM2E0A" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	{ "BCM2E0B" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	{ "BCM2E0C" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	{ "BCM2E0D" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	{ "BCM2E0E" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	{ "BCM2E0F" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	{ "BCM2E10" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	{ "BCM2E11" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	{ "BCM2E12" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	{ "BCM2E13" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	{ "BCM2E14" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	{ "BCM2E15" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	{ "BCM2E16" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	{ "BCM2E17" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	{ "BCM2E18" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	{ "BCM2E19" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	{ "BCM2E1A" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	{ "BCM2E1B" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	{ "BCM2E1C" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	{ "BCM2E1D" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	{ "BCM2E1F" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	{ "BCM2E20" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	{ "BCM2E21" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	{ "BCM2E22" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	{ "BCM2E23" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	{ "BCM2E24" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	{ "BCM2E25" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	{ "BCM2E26" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	{ "BCM2E27" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	{ "BCM2E28" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	{ "BCM2E29" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	{ "BCM2E2A" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	{ "BCM2E2B" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	{ "BCM2E2C" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	{ "BCM2E2D" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	{ "BCM2E2E" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	{ "BCM2E2F" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	{ "BCM2E30" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	{ "BCM2E31" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	{ "BCM2E32" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	{ "BCM2E33" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	{ "BCM2E34" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	{ "BCM2E35" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	{ "BCM2E36" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	{ "BCM2E37" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	{ "BCM2E38" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	{ "BCM2E39" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	{ "BCM2E3A" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	{ "BCM2E3B" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	{ "BCM2E3C" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	{ "BCM2E3D" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	{ "BCM2E3E" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	{ "BCM2E3F" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	{ "BCM2E40" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	{ "BCM2E41" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	{ "BCM2E42" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	{ "BCM2E43" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	{ "BCM2E44" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	{ "BCM2E45" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	{ "BCM2E46" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	{ "BCM2E47" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	{ "BCM2E48" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	{ "BCM2E49" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	{ "BCM2E4A" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	{ "BCM2E4B" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	{ "BCM2E4C" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	{ "BCM2E4D" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	{ "BCM2E4E" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	{ "BCM2E4F" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	{ "BCM2E50" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	{ "BCM2E51" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	{ "BCM2E52" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	{ "BCM2E53" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	{ "BCM2E54" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	{ "BCM2E55" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	{ "BCM2E56" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	{ "BCM2E57" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	{ "BCM2E58" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	{ "BCM2E59" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	{ "BCM2E5A" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	{ "BCM2E5B" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	{ "BCM2E5C" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	{ "BCM2E5D" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	{ "BCM2E5E" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	{ "BCM2E5F" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	{ "BCM2E60" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	{ "BCM2E61" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	{ "BCM2E62" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	{ "BCM2E63" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	{ "BCM2E64" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	{ "BCM2E65" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	{ "BCM2E66" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	{ "BCM2E67" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	{ "BCM2E68" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	{ "BCM2E69" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	{ "BCM2E6B" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	{ "BCM2E6D" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	{ "BCM2E6E" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	{ "BCM2E6F" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	{ "BCM2E70" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	{ "BCM2E71" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	{ "BCM2E72" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	{ "BCM2E73" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	{ "BCM2E74" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	{ "BCM2E75" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	{ "BCM2E76" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	{ "BCM2E77" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	{ "BCM2E78" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	{ "BCM2E79" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	{ "BCM2E7A" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	{ "BCM2E7B" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	{ "BCM2E7C" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	{ "BCM2E7D" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	{ "BCM2E7E" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	{ "BCM2E7F" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	{ "BCM2E80" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	{ "BCM2E81" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	{ "BCM2E82" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	{ "BCM2E83" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	{ "BCM2E84" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	{ "BCM2E85" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	{ "BCM2E86" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	{ "BCM2E87" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	{ "BCM2E88" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	{ "BCM2E89" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	{ "BCM2E8A" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	{ "BCM2E8B" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	{ "BCM2E8C" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	{ "BCM2E8D" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	{ "BCM2E8E" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	{ "BCM2E90" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	{ "BCM2E92" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	{ "BCM2E93" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	{ "BCM2E94" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	{ "BCM2E95" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	{ "BCM2E96" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	{ "BCM2E97" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	{ "BCM2E98" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	{ "BCM2E99" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	{ "BCM2E9A" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	{ "BCM2E9B" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	{ "BCM2E9C" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	{ "BCM2E9D" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	{ "BCM2EA0" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	{ "BCM2EA1" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	{ "BCM2EA2" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	{ "BCM2EA3" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	{ "BCM2EA4" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	{ "BCM2EA5" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	{ "BCM2EA6" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	{ "BCM2EA7" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	{ "BCM2EA8" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	{ "BCM2EA9" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	{ "BCM2EAA" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	{ "BCM2EAB" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	{ "BCM2EAC" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) MODULE_DEVICE_TABLE(acpi, bcm_acpi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) /* suspend and resume callbacks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) static const struct dev_pm_ops bcm_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	SET_SYSTEM_SLEEP_PM_OPS(bcm_suspend, bcm_resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	SET_RUNTIME_PM_OPS(bcm_suspend_device, bcm_resume_device, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) static struct platform_driver bcm_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	.probe = bcm_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	.remove = bcm_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		.name = "hci_bcm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 		.acpi_match_table = ACPI_PTR(bcm_acpi_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 		.pm = &bcm_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) static int bcm_serdev_probe(struct serdev_device *serdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 	struct bcm_device *bcmdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	const struct bcm_device_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	bcmdev = devm_kzalloc(&serdev->dev, sizeof(*bcmdev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	if (!bcmdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	bcmdev->dev = &serdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	bcmdev->hu = &bcmdev->serdev_hu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	bcmdev->serdev_hu.serdev = serdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	serdev_device_set_drvdata(serdev, bcmdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	/* Initialize routing field to an unused value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	bcmdev->pcm_int_params[0] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	if (has_acpi_companion(&serdev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 		err = bcm_acpi_probe(bcmdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		err = bcm_of_probe(bcmdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	err = bcm_get_resources(bcmdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	if (!bcmdev->shutdown) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 		dev_warn(&serdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 			 "No reset resource, using default baud rate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 		bcmdev->oper_speed = bcmdev->init_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	err = bcm_gpio_set_power(bcmdev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 		dev_err(&serdev->dev, "Failed to power down\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	data = device_get_match_data(bcmdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	if (data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 		bcmdev->no_early_set_baudrate = data->no_early_set_baudrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 		bcmdev->drive_rts_on_open = data->drive_rts_on_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) static void bcm_serdev_remove(struct serdev_device *serdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	struct bcm_device *bcmdev = serdev_device_get_drvdata(serdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	hci_uart_unregister_device(&bcmdev->serdev_hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) static struct bcm_device_data bcm4354_device_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	.no_early_set_baudrate = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) static struct bcm_device_data bcm43438_device_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	.drive_rts_on_open = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) static const struct of_device_id bcm_bluetooth_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	{ .compatible = "brcm,bcm20702a1" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	{ .compatible = "brcm,bcm4329-bt" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	{ .compatible = "brcm,bcm4345c5" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	{ .compatible = "brcm,bcm4330-bt" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	{ .compatible = "brcm,bcm43438-bt", .data = &bcm43438_device_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	{ .compatible = "brcm,bcm43540-bt", .data = &bcm4354_device_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	{ .compatible = "brcm,bcm4335a0" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) MODULE_DEVICE_TABLE(of, bcm_bluetooth_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) static struct serdev_device_driver bcm_serdev_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	.probe = bcm_serdev_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	.remove = bcm_serdev_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 		.name = "hci_uart_bcm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 		.of_match_table = of_match_ptr(bcm_bluetooth_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 		.acpi_match_table = ACPI_PTR(bcm_acpi_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 		.pm = &bcm_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) int __init bcm_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	/* For now, we need to keep both platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	 * driver (ACPI generated) and serdev driver (DT).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	platform_driver_register(&bcm_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	serdev_device_driver_register(&bcm_serdev_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	return hci_uart_register_proto(&bcm_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) int __exit bcm_deinit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	platform_driver_unregister(&bcm_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	serdev_device_driver_unregister(&bcm_serdev_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	return hci_uart_unregister_proto(&bcm_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) }