Orange Pi5 kernel

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

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright (C) 2012 ROCKCHIP, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * This software is licensed under the terms of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * License version 2, as published by the Free Software Foundation, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * may be copied, distributed, and modified under those terms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) /* Rock-chips rfkill driver for bluetooth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/kernel.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/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/rfkill.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/rfkill-bt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/rfkill-wlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/wakelock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <dt-bindings/gpio/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <uapi/linux/rfkill.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define DBG(x...) pr_info("[BT_RFKILL]: " x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define DBG(x...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define LOG(x...) pr_info("[BT_RFKILL]: " x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define BT_WAKEUP_TIMEOUT 10000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define BT_IRQ_WAKELOCK_TIMEOUT (10 * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define BT_BLOCKED true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define BT_UNBLOCK false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define BT_SLEEP true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define BT_WAKEUP false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	IOMUX_FNORMAL = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	IOMUX_FGPIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	IOMUX_FMUX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) struct rfkill_rk_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct rfkill_rk_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct rfkill *rfkill_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct wake_lock bt_irq_wl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct delayed_work bt_sleep_delay_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	int irq_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static struct rfkill_rk_data *g_rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static const char bt_name[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #if defined(CONFIG_BCM4330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #if defined(CONFIG_BT_MODULE_NH660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	"nh660"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	"bcm4330"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) #elif defined(CONFIG_RK903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #if defined(CONFIG_RKWIFI_26M)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	"rk903_26M"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	"rk903"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #elif defined(CONFIG_BCM4329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	"bcm4329"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #elif defined(CONFIG_MV8787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	"mv8787"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #elif defined(CONFIG_AP6210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #if defined(CONFIG_RKWIFI_26M)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	"ap6210"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	"ap6210_24M"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #elif defined(CONFIG_AP6330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	"ap6330"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #elif defined(CONFIG_AP6476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	"ap6476"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #elif defined(CONFIG_AP6493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	"ap6493"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #elif defined(CONFIG_AP6441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	"ap6441"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #elif defined(CONFIG_AP6335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	"ap6335"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #elif defined(CONFIG_GB86302I)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	"gb86302i"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	"bt_default"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static irqreturn_t rfkill_rk_wake_host_irq(int irq, void *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct rfkill_rk_data *rfkill = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	LOG("BT_WAKE_HOST IRQ fired\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	DBG("BT IRQ wakeup, request %dms wakelock\n", BT_IRQ_WAKELOCK_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	wake_lock_timeout(&rfkill->bt_irq_wl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			  msecs_to_jiffies(BT_IRQ_WAKELOCK_TIMEOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int rfkill_rk_setup_gpio(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				struct rfkill_rk_gpio *gpio, const char *prefix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 				const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (gpio_is_valid(gpio->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		sprintf(gpio->name, "%s_%s", prefix, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		ret = devm_gpio_request(&pdev->dev, gpio->io, gpio->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			LOG("Failed to get %s gpio.\n", gpio->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static int rfkill_rk_setup_wake_irq(struct rfkill_rk_data *rfkill, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct rfkill_rk_irq *irq = &rfkill->pdata->wake_host_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (!flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		rfkill->irq_req = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		ret = rfkill_rk_setup_gpio(rfkill->pdev, &irq->gpio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 					   rfkill->pdata->name, "wake_host");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (gpio_is_valid(irq->gpio.io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (rfkill->irq_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			rfkill->irq_req = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			free_irq(irq->irq, rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		LOG("Request irq for bt wakeup host\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		irq->irq = gpio_to_irq(irq->gpio.io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		sprintf(irq->name, "%s_irq", irq->gpio.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		ret = request_irq(irq->irq, rfkill_rk_wake_host_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				  (irq->gpio.enable == GPIO_ACTIVE_LOW) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 					  IRQF_TRIGGER_FALLING :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 					  IRQF_TRIGGER_RISING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				  irq->name, rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		rfkill->irq_req = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		LOG("** disable irq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		disable_irq(irq->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		ret = enable_irq_wake(irq->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			goto fail3;
^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) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) fail3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	free_irq(irq->irq, rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) fail2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	gpio_free(irq->gpio.io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) fail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static inline void rfkill_rk_sleep_bt_internal(struct rfkill_rk_data *rfkill,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 					       bool sleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	struct rfkill_rk_gpio *wake = &rfkill->pdata->wake_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	DBG("*** bt sleep: %d ***\n", sleep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #ifndef CONFIG_BK3515A_COMBO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	gpio_direction_output(wake->io, sleep ? !wake->enable : wake->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (!sleep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		DBG("HOST_UART0_TX pull down 10us\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		if (rfkill_rk_setup_gpio(rfkill->pdev, wake,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 					 rfkill->pdata->name, "wake") != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		gpio_direction_output(wake->io, wake->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		usleep_range(10, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		gpio_direction_output(wake->io, !wake->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		gpio_free(wake->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static void rfkill_rk_delay_sleep_bt(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct rfkill_rk_data *rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	DBG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	rfkill = container_of(work, struct rfkill_rk_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			      bt_sleep_delay_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	rfkill_rk_sleep_bt_internal(rfkill, BT_SLEEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) void rfkill_rk_sleep_bt(bool sleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct rfkill_rk_data *rfkill = g_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct rfkill_rk_gpio *wake;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	DBG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (!rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		LOG("*** RFKILL is empty???\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	wake = &rfkill->pdata->wake_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (!gpio_is_valid(wake->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		DBG("*** Not support bt wakeup and sleep\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		return;
^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) 	cancel_delayed_work_sync(&rfkill->bt_sleep_delay_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	rfkill_rk_sleep_bt_internal(rfkill, sleep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #ifdef CONFIG_BT_AUTOSLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (sleep == BT_WAKEUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		schedule_delayed_work(&rfkill->bt_sleep_delay_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				      msecs_to_jiffies(BT_WAKEUP_TIMEOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) EXPORT_SYMBOL(rfkill_rk_sleep_bt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int bt_power_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int rfkill_get_bt_power_state(int *power, bool *toggle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	struct rfkill_rk_data *mrfkill = g_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (!mrfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		LOG("%s: rfkill-bt driver has not Successful initialized\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		    __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	*toggle = mrfkill->pdata->power_toggle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	*power = bt_power_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static int proc_rk_set_power(void *data, bool blocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct rfkill_rk_data *rfkill = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	struct rfkill_rk_gpio *wake_host = &rfkill->pdata->wake_host_irq.gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	struct rfkill_rk_gpio *poweron = &rfkill->pdata->poweron_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	struct rfkill_rk_gpio *reset = &rfkill->pdata->reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	struct rfkill_rk_gpio *rts = &rfkill->pdata->rts_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	struct pinctrl *pinctrl = rfkill->pdata->pinctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	int wifi_power = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	bool toggle = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	DBG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	DBG("Set blocked:%d\n", blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	toggle = rfkill->pdata->power_toggle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (toggle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		if (rfkill_get_wifi_power_state(&wifi_power)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			LOG("%s: cannot get wifi power state!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	DBG("%s: toggle = %s\n", __func__, toggle ? "true" : "false");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (!blocked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		if (toggle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			rfkill_set_wifi_bt_power(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		rfkill_rk_sleep_bt(BT_WAKEUP); // ensure bt is wakeup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		if (gpio_is_valid(wake_host->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			LOG("%s: set bt wake_host high!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			gpio_direction_output(wake_host->io, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		if (gpio_is_valid(poweron->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			if (gpio_get_value(poweron->io) == !poweron->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 				gpio_direction_output(poweron->io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 						      !poweron->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 				msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 				gpio_direction_output(poweron->io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 						      poweron->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 				msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 				if (gpio_is_valid(wake_host->io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 					gpio_direction_input(wake_host->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		if (gpio_is_valid(reset->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			if (gpio_get_value(reset->io) == !reset->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 				gpio_direction_output(reset->io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 						      !reset->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 				msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 				gpio_direction_output(reset->io, reset->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		if (pinctrl && gpio_is_valid(rts->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			pinctrl_select_state(pinctrl, rts->gpio_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			LOG("ENABLE UART_RTS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			gpio_direction_output(rts->io, rts->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			LOG("DISABLE UART_RTS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			gpio_direction_output(rts->io, !rts->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			pinctrl_select_state(pinctrl, rts->default_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		bt_power_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		LOG("bt turn on power\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		rfkill_rk_setup_wake_irq(rfkill, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		if (gpio_is_valid(poweron->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			if (gpio_get_value(poweron->io) == poweron->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 				gpio_direction_output(poweron->io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 						      !poweron->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 				msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		bt_power_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		LOG("bt shut off power\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		if (gpio_is_valid(reset->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			if (gpio_get_value(reset->io) == reset->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 				gpio_direction_output(reset->io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 						      !reset->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 				msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		if (toggle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			if (!wifi_power) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 				LOG("%s: bt will set vbat to low\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 				rfkill_set_wifi_bt_power(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 				LOG("%s: bt shouldn't control the vbat\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static int rfkill_rk_set_power(void *data, bool blocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	struct rfkill_rk_data *rfkill = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	struct rfkill_rk_gpio *wake_host = &rfkill->pdata->wake_host_irq.gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	struct rfkill_rk_gpio *poweron = &rfkill->pdata->poweron_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	struct rfkill_rk_gpio *reset = &rfkill->pdata->reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	struct rfkill_rk_gpio *rts = &rfkill->pdata->rts_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	struct pinctrl *pinctrl = rfkill->pdata->pinctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	int wifi_power = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	bool toggle = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	DBG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	DBG("Set blocked:%d\n", blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	toggle = rfkill->pdata->power_toggle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	if (toggle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		if (rfkill_get_wifi_power_state(&wifi_power)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			LOG("%s: cannot get wifi power state!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	DBG("%s: toggle = %s\n", __func__, toggle ? "true" : "false");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (!blocked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		if (toggle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			rfkill_set_wifi_bt_power(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		rfkill_rk_sleep_bt(BT_WAKEUP); // ensure bt is wakeup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		if (gpio_is_valid(wake_host->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			LOG("%s: set bt wake_host high!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			gpio_direction_output(wake_host->io, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 			msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		if (gpio_is_valid(poweron->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			if (gpio_get_value(poweron->io) == !poweron->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 				gpio_direction_output(poweron->io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 						      !poweron->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 				msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 				gpio_direction_output(poweron->io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 						      poweron->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 				msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 				if (gpio_is_valid(wake_host->io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 					gpio_direction_input(wake_host->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		if (gpio_is_valid(reset->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			if (gpio_get_value(reset->io) == !reset->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 				gpio_direction_output(reset->io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 						      !reset->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 				msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 				gpio_direction_output(reset->io, reset->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		if (pinctrl && gpio_is_valid(rts->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 			pinctrl_select_state(pinctrl, rts->gpio_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			LOG("ENABLE UART_RTS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 			gpio_direction_output(rts->io, rts->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 			LOG("DISABLE UART_RTS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 			gpio_direction_output(rts->io, !rts->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 			pinctrl_select_state(pinctrl, rts->default_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		bt_power_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		LOG("bt turn on power\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		rfkill_rk_setup_wake_irq(rfkill, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		if (gpio_is_valid(poweron->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 			if (gpio_get_value(poweron->io) == poweron->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 				gpio_direction_output(poweron->io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 						      poweron->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 				msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		bt_power_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		LOG("bt shut off power\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		if (gpio_is_valid(reset->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			if (gpio_get_value(reset->io) == reset->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 				gpio_direction_output(reset->io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 						      reset->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 				msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		if (toggle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 			if (!wifi_power) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 				LOG("%s: bt will set vbat to low\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 				rfkill_set_wifi_bt_power(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 				LOG("%s: bt shouldn't control the vbat\n", __func__);
^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) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static int rfkill_rk_pm_prepare(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	struct rfkill_rk_data *rfkill = g_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	struct rfkill_rk_gpio *rts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	struct rfkill_rk_irq *wake_host_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	DBG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	if (!rfkill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	rts = &rfkill->pdata->rts_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	wake_host_irq = &rfkill->pdata->wake_host_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	//To prevent uart to receive bt data when suspended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	if (rfkill->pdata->pinctrl && gpio_is_valid(rts->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		DBG("Disable UART_RTS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		pinctrl_select_state(rfkill->pdata->pinctrl, rts->gpio_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		gpio_direction_output(rts->io, !rts->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) #ifdef CONFIG_BT_AUTOSLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	rfkill_rk_sleep_bt(BT_SLEEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	// enable bt wakeup host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	if (gpio_is_valid(wake_host_irq->gpio.io) && bt_power_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		DBG("enable irq for bt wakeup host\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		enable_irq(wake_host_irq->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) #ifdef CONFIG_RFKILL_RESET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	rfkill_init_sw_state(rfkill->rfkill_dev, BT_BLOCKED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	rfkill_set_sw_state(rfkill->rfkill_dev, BT_BLOCKED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	rfkill_set_hw_state(rfkill->rfkill_dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	rfkill_rk_set_power(rfkill, BT_BLOCKED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static void rfkill_rk_pm_complete(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	struct rfkill_rk_data *rfkill = g_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	struct rfkill_rk_irq *wake_host_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	struct rfkill_rk_gpio *rts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	DBG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	if (!rfkill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	wake_host_irq = &rfkill->pdata->wake_host_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	rts = &rfkill->pdata->rts_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	if (gpio_is_valid(wake_host_irq->gpio.io) && bt_power_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		LOG("** disable irq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		disable_irq(wake_host_irq->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	if (rfkill->pdata->pinctrl && gpio_is_valid(rts->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		DBG("Enable UART_RTS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		gpio_direction_output(rts->io, rts->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		pinctrl_select_state(rfkill->pdata->pinctrl, rts->default_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static const struct rfkill_ops rfkill_rk_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	.set_block = rfkill_rk_set_power,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) #define PROC_DIR "bluetooth/sleep"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) static struct proc_dir_entry *bluetooth_dir, *sleep_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static ssize_t bluesleep_read_proc_lpm(struct file *file, char __user *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 				       size_t count, loff_t *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	return sprintf(buffer, "unsupported to read\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static ssize_t bluesleep_write_proc_lpm(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 					const char __user *buffer, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 					loff_t *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static ssize_t bluesleep_read_proc_btwrite(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 					   char __user *buffer, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 					   loff_t *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	return sprintf(buffer, "unsupported to read\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static ssize_t bluesleep_write_proc_btwrite(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 					    const char __user *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 					    size_t count, loff_t *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	char b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	if (count < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	if (copy_from_user(&b, buffer, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	DBG("btwrite %c\n", b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	/* HCI_DEV_WRITE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	if (b != '0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 		proc_rk_set_power(g_rfkill, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		proc_rk_set_power(g_rfkill, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) static int bluetooth_platdata_parse_dt(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 				       struct rfkill_rk_platform_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	struct device_node *node = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	int gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	enum of_gpio_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	memset(data, 0, sizeof(*data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	if (of_find_property(node, "wifi-bt-power-toggle", NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		data->power_toggle = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		LOG("%s: get property wifi-bt-power-toggle.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		data->power_toggle = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	gpio = of_get_named_gpio_flags(node, "uart_rts_gpios", 0, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	if (gpio_is_valid(gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		data->rts_gpio.io = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		data->rts_gpio.enable = (flags == GPIO_ACTIVE_HIGH) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		LOG("%s: get property: uart_rts_gpios = %d.\n", __func__, gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		data->pinctrl = devm_pinctrl_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		if (!IS_ERR(data->pinctrl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 			data->rts_gpio.default_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 				pinctrl_lookup_state(data->pinctrl, "default");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 			data->rts_gpio.gpio_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 				pinctrl_lookup_state(data->pinctrl, "rts_gpio");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 			data->pinctrl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 			LOG("%s: dts does't define the uart rts iomux.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 			    __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		data->pinctrl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		data->rts_gpio.io = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 		LOG("%s: uart_rts_gpios is no-in-use.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	gpio = of_get_named_gpio_flags(node, "BT,power_gpio", 0, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	if (gpio_is_valid(gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 		data->poweron_gpio.io = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 		data->poweron_gpio.enable = (flags == GPIO_ACTIVE_HIGH) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		LOG("%s: get property: BT,power_gpio = %d.\n", __func__, gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 		data->poweron_gpio.io = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	gpio = of_get_named_gpio_flags(node, "BT,reset_gpio", 0, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	if (gpio_is_valid(gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		data->reset_gpio.io = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		data->reset_gpio.enable = (flags == GPIO_ACTIVE_HIGH) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		LOG("%s: get property: BT,reset_gpio = %d.\n", __func__, gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		data->reset_gpio.io = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	gpio = of_get_named_gpio_flags(node, "BT,wake_gpio", 0, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	if (gpio_is_valid(gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 		data->wake_gpio.io = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		data->wake_gpio.enable = (flags == GPIO_ACTIVE_HIGH) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 		LOG("%s: get property: BT,wake_gpio = %d.\n", __func__, gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		data->wake_gpio.io = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	gpio = of_get_named_gpio_flags(node, "BT,wake_host_irq", 0, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	if (gpio_is_valid(gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		data->wake_host_irq.gpio.io = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		data->wake_host_irq.gpio.enable = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		LOG("%s: get property: BT,wake_host_irq = %d.\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		    gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		data->wake_host_irq.gpio.io = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	data->ext_clk = devm_clk_get(dev, "ext_clock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	if (IS_ERR(data->ext_clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 		LOG("%s: clk_get failed!!!.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 		clk_prepare_enable(data->ext_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) #endif //CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) static const struct proc_ops bluesleep_lpm = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	.proc_read = bluesleep_read_proc_lpm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	.proc_write = bluesleep_write_proc_lpm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static const struct proc_ops bluesleep_btwrite = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	.proc_read = bluesleep_read_proc_btwrite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	.proc_write = bluesleep_write_proc_btwrite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) static int rfkill_rk_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	struct rfkill_rk_data *rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	struct rfkill_rk_platform_data *pdata = pdev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	struct proc_dir_entry *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	DBG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	if (!pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		pdata = devm_kzalloc(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 				     sizeof(struct rfkill_rk_platform_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 				     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 		if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 		ret = bluetooth_platdata_parse_dt(&pdev->dev, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 			LOG("%s: No platform data specified\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) #endif
^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) 	pdata->name = (char *)bt_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	pdata->type = RFKILL_TYPE_BLUETOOTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	rfkill = devm_kzalloc(&pdev->dev, sizeof(*rfkill), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	if (!rfkill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	rfkill->pdata = pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	rfkill->pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	g_rfkill = rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	bluetooth_dir = proc_mkdir("bluetooth", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	if (!bluetooth_dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 		LOG("Unable to create /proc/bluetooth directory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	sleep_dir = proc_mkdir("sleep", bluetooth_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	if (!sleep_dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 		LOG("Unable to create /proc/%s directory", PROC_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	/* read/write proc entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	ent = proc_create("lpm", 0444, sleep_dir, &bluesleep_lpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	if (!ent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 		LOG("Unable to create /proc/%s/lpm entry", PROC_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 		goto fail_alloc;
^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) 	/* read/write proc entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	ent = proc_create("btwrite", 0444, sleep_dir, &bluesleep_btwrite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	if (!ent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 		LOG("Unable to create /proc/%s/btwrite entry", PROC_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 		goto fail_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	DBG("init gpio\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	ret = rfkill_rk_setup_gpio(pdev, &pdata->poweron_gpio, pdata->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 				   "poweron");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 		goto fail_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	ret = rfkill_rk_setup_gpio(pdev, &pdata->reset_gpio, pdata->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 				   "reset");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 		goto fail_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	ret = rfkill_rk_setup_gpio(pdev, &pdata->wake_gpio, pdata->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 				   "wake");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 		goto fail_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	ret = rfkill_rk_setup_gpio(pdev, &pdata->rts_gpio, rfkill->pdata->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 				   "rts");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 		goto fail_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 	wake_lock_init(&rfkill->bt_irq_wl, WAKE_LOCK_SUSPEND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 		       "rfkill_rk_irq_wl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	ret = rfkill_rk_setup_wake_irq(rfkill, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 		goto fail_setup_wake_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	DBG("setup rfkill\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	rfkill->rfkill_dev = rfkill_alloc(pdata->name, &pdev->dev, pdata->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 					  &rfkill_rk_ops, rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	if (!rfkill->rfkill_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 		goto fail_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 	rfkill_init_sw_state(rfkill->rfkill_dev, BT_BLOCKED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 	rfkill_set_sw_state(rfkill->rfkill_dev, BT_BLOCKED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	rfkill_set_hw_state(rfkill->rfkill_dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 	ret = rfkill_register(rfkill->rfkill_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 		goto fail_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	INIT_DELAYED_WORK(&rfkill->bt_sleep_delay_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 			  rfkill_rk_delay_sleep_bt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	//rfkill_rk_set_power(rfkill, BT_BLOCKED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 	// bt turn off power
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	if (gpio_is_valid(pdata->poweron_gpio.io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 		gpio_direction_output(pdata->poweron_gpio.io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 				      !pdata->poweron_gpio.enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	if (gpio_is_valid(pdata->reset_gpio.io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 		gpio_direction_output(pdata->reset_gpio.io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 				      !pdata->reset_gpio.enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	platform_set_drvdata(pdev, rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	LOG("%s device registered.\n", pdata->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) fail_rfkill:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	rfkill_destroy(rfkill->rfkill_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) fail_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 	remove_proc_entry("btwrite", sleep_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	remove_proc_entry("lpm", sleep_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) fail_setup_wake_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	wake_lock_destroy(&rfkill->bt_irq_wl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) fail_gpio:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 	g_rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) static int rfkill_rk_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	struct rfkill_rk_data *rfkill = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	LOG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	rfkill_unregister(rfkill->rfkill_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	rfkill_destroy(rfkill->rfkill_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 	cancel_delayed_work_sync(&rfkill->bt_sleep_delay_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 	// free gpio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	if (gpio_is_valid(rfkill->pdata->rts_gpio.io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 		gpio_free(rfkill->pdata->rts_gpio.io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 	if (gpio_is_valid(rfkill->pdata->wake_host_irq.gpio.io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 		free_irq(rfkill->pdata->wake_host_irq.irq, rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) #ifndef CONFIG_BK3515A_COMBO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 		gpio_free(rfkill->pdata->wake_host_irq.gpio.io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) #ifndef CONFIG_BK3515A_COMBO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 	if (gpio_is_valid(rfkill->pdata->wake_gpio.io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 		gpio_free(rfkill->pdata->wake_gpio.io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 	if (gpio_is_valid(rfkill->pdata->reset_gpio.io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 		gpio_free(rfkill->pdata->reset_gpio.io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 	if (gpio_is_valid(rfkill->pdata->poweron_gpio.io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 		gpio_free(rfkill->pdata->poweron_gpio.io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 	clk_disable_unprepare(rfkill->pdata->ext_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 	wake_lock_destroy(&rfkill->bt_irq_wl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 	g_rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) static const struct dev_pm_ops rfkill_rk_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 	.prepare = rfkill_rk_pm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 	.complete = rfkill_rk_pm_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) static struct of_device_id bt_platdata_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 	{ .compatible = "bluetooth-platdata" },
^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) MODULE_DEVICE_TABLE(of, bt_platdata_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) #endif //CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) static struct platform_driver rfkill_rk_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 	.probe = rfkill_rk_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 	.remove = rfkill_rk_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 		.name = "rfkill_bt",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 		.pm = &rfkill_rk_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)         .of_match_table = of_match_ptr(bt_platdata_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) static int __init rfkill_rk_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 	LOG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) 	err = rfkill_wlan_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) 	return platform_driver_register(&rfkill_rk_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) static void __exit rfkill_rk_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) 	LOG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) 	platform_driver_unregister(&rfkill_rk_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) 	rfkill_wlan_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) module_init(rfkill_rk_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) module_exit(rfkill_rk_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) MODULE_DESCRIPTION("rock-chips rfkill for Bluetooth v0.3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) MODULE_AUTHOR("cmy@rock-chips.com, gwl@rock-chips.com");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) MODULE_LICENSE("GPL");