^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 wifi
^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) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/rfkill.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/regulator/consumer.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-wlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/rfkill-bt.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 <dt-bindings/gpio/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/rockchip/grf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/mmc/host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <linux/soc/rockchip/rk_vendor_storage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include "../../drivers/mmc/core/pwrseq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define DBG(x...) pr_info("[WLAN_RFKILL]: " x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define DBG(x...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define LOG(x...) pr_info("[WLAN_RFKILL]: " x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct rfkill_wlan_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct rksdmmc_gpio_wifi_moudle *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct wake_lock wlan_irq_wl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static struct rfkill_wlan_data *g_rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static int power_set_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static int wifi_bt_vbat_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int wifi_power_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static const char wlan_name[] = "rkwifi";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static char wifi_chip_type_string[64];
^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) * Broadcom Wifi Static Memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) **********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #ifdef CONFIG_RKWIFI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define BCM_STATIC_MEMORY_SUPPORT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define BCM_STATIC_MEMORY_SUPPORT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) //===========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #if BCM_STATIC_MEMORY_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define PREALLOC_WLAN_SEC_NUM 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define PREALLOC_WLAN_BUF_NUM 160
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define PREALLOC_WLAN_SECTION_HEADER 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define WLAN_SKB_BUF_NUM 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define WLAN_SECTION_SIZE_0 (12 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define WLAN_SECTION_SIZE_1 (12 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define WLAN_SECTION_SIZE_2 (32 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define WLAN_SECTION_SIZE_3 (136 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define WLAN_SECTION_SIZE_4 (4 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define WLAN_SECTION_SIZE_5 (64 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define WLAN_SECTION_SIZE_6 (4 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define WLAN_SECTION_SIZE_7 (4 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct wifi_mem_prealloc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) void *mem_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static struct wifi_mem_prealloc wifi_mem_array[8] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) { NULL, (WLAN_SECTION_SIZE_0) }, { NULL, (WLAN_SECTION_SIZE_1) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) { NULL, (WLAN_SECTION_SIZE_2) }, { NULL, (WLAN_SECTION_SIZE_3) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) { NULL, (WLAN_SECTION_SIZE_4) }, { NULL, (WLAN_SECTION_SIZE_5) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) { NULL, (WLAN_SECTION_SIZE_6) }, { NULL, (WLAN_SECTION_SIZE_7) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int rockchip_init_wifi_mem(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) for (i = 0; i < WLAN_SKB_BUF_NUM; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) wlan_static_skb[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) dev_alloc_skb(((i < (WLAN_SKB_BUF_NUM / 2)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) (PAGE_SIZE * 1) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) (PAGE_SIZE * 2)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (!wlan_static_skb[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) goto err_skb_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) wlan_static_skb[i] = dev_alloc_skb((PAGE_SIZE * 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (!wlan_static_skb[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) goto err_skb_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) for (i = 0; i <= 7; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) wifi_mem_array[i].mem_ptr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (!wifi_mem_array[i].mem_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) goto err_mem_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) err_mem_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) pr_err("Failed to mem_alloc for WLAN\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) for (j = 0; j < i; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) kfree(wifi_mem_array[j].mem_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) i = WLAN_SKB_BUF_NUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) err_skb_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) pr_err("Failed to skb_alloc for WLAN\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) for (j = 0; j < i; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) dev_kfree_skb(wlan_static_skb[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) dev_kfree_skb(wlan_static_skb[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) void *rockchip_mem_prealloc(int section, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (section == PREALLOC_WLAN_SEC_NUM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return wlan_static_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (section < 0 || section > 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (wifi_mem_array[section].size < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return wifi_mem_array[section].mem_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) void *rockchip_mem_prealloc(int section, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) EXPORT_SYMBOL(rockchip_mem_prealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) int rfkill_set_wifi_bt_power(int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct rfkill_wlan_data *mrfkill = g_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct rksdmmc_gpio *vbat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) LOG("%s: %d\n", __func__, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!mrfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) LOG("%s: rfkill-wlan driver has not Successful initialized\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) vbat = &mrfkill->pdata->vbat_n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (gpio_is_valid(vbat->io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) gpio_direction_output(vbat->io, vbat->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (gpio_is_valid(vbat->io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) gpio_direction_output(vbat->io, !(vbat->enable));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) wifi_bt_vbat_state = on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return 0;
^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) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * get wifi power state Func
^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) int rfkill_get_wifi_power_state(int *power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct rfkill_wlan_data *mrfkill = g_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!mrfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) LOG("%s: rfkill-wlan driver has not Successful initialized\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) *power = wifi_power_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) EXPORT_SYMBOL(rfkill_get_wifi_power_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^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) * Wifi Power Control Func
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * 0 -> power off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * 1 -> power on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int rockchip_wifi_power(int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct rfkill_wlan_data *mrfkill = g_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct rksdmmc_gpio *poweron, *reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct regulator *ldo = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) int bt_power = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) bool toggle = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) LOG("%s: %d\n", __func__, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (!mrfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) LOG("%s: rfkill-wlan driver has not Successful initialized\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (mrfkill->pdata->wifi_power_remain && power_set_time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) LOG("%s: wifi power is setted to be remain on.", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) power_set_time++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (!rfkill_get_bt_power_state(&bt_power, &toggle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) LOG("%s: toggle = %s\n", __func__, toggle ? "true" : "false");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (mrfkill->pdata->mregulator.power_ctrl_by_pmu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) char *ldostr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int level = mrfkill->pdata->mregulator.enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) ldostr = mrfkill->pdata->mregulator.pmu_regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (!ldostr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ldo = regulator_get(NULL, ldostr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (!ldo || IS_ERR(ldo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) LOG("\n\n\n%s get ldo error,please mod this\n\n\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (on == level) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) regulator_set_voltage(ldo, 3000000, 3000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) LOG("%s: %s enabled\n", __func__, ldostr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ret = regulator_enable(ldo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) LOG("ldo enable failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) wifi_power_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) LOG("wifi turn on power.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) LOG("%s: %s disabled\n", __func__, ldostr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) while (regulator_is_enabled(ldo) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) ret = regulator_disable(ldo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) LOG("ldo disable failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) wifi_power_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) LOG("wifi shut off power.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) regulator_put(ldo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) poweron = &mrfkill->pdata->power_n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) reset = &mrfkill->pdata->reset_n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (toggle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) rfkill_set_wifi_bt_power(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) msleep(100);
^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) if (gpio_is_valid(poweron->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) gpio_direction_output(poweron->io, poweron->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (gpio_is_valid(reset->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) gpio_direction_output(reset->io, reset->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) wifi_power_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) LOG("wifi turn on power [GPIO%d-%d]\n", poweron->io, poweron->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (gpio_is_valid(poweron->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) printk("wifi power off\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) gpio_direction_output(poweron->io, !(poweron->enable));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) msleep(100);
^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(reset->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) gpio_direction_output(reset->io, !(reset->enable));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) wifi_power_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (toggle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (!bt_power) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) LOG("%s: wifi will set vbat to low\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) rfkill_set_wifi_bt_power(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) LOG("%s: wifi shouldn't control the vbat\n", __func__);
^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) LOG("wifi shut off power [GPIO%d-%d]\n", poweron->io, !poweron->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) EXPORT_SYMBOL(rockchip_wifi_power);
^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) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * Wifi Sdio Detect Func
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) int rockchip_wifi_set_carddetect(int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) EXPORT_SYMBOL(rockchip_wifi_set_carddetect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * Wifi Get Interrupt irq Func
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) int rockchip_wifi_get_oob_irq(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct rfkill_wlan_data *mrfkill = g_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct rksdmmc_gpio *wifi_int_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) LOG("%s: Enter\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (!mrfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) LOG("%s: rfkill-wlan driver has not Successful initialized\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) wifi_int_irq = &mrfkill->pdata->wifi_int_b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (gpio_is_valid(wifi_int_irq->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return gpio_to_irq(wifi_int_irq->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) //return wifi_int_irq->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) LOG("%s: wifi OOB pin isn't defined.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) EXPORT_SYMBOL(rockchip_wifi_get_oob_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) int rockchip_wifi_get_oob_irq_flag(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct rfkill_wlan_data *mrfkill = g_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) struct rksdmmc_gpio *wifi_int_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int gpio_flags = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (mrfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) wifi_int_irq = &mrfkill->pdata->wifi_int_b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (gpio_is_valid(wifi_int_irq->io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) gpio_flags = wifi_int_irq->enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return gpio_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) EXPORT_SYMBOL(rockchip_wifi_get_oob_irq_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * Wifi Reset Func
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) int rockchip_wifi_reset(int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) EXPORT_SYMBOL(rockchip_wifi_reset);
^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) * Wifi MAC custom Func
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) u8 wifi_custom_mac_addr[6] = { 0, 0, 0, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) //#define RANDOM_ADDRESS_SAVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static int get_wifi_addr_vendor(unsigned char *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) int count = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) while (count-- > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (is_rk_vendor_ready())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* sleep 500ms wait rk vendor driver ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) msleep(500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) ret = rk_vendor_read(WIFI_MAC_ID, addr, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (ret != 6 || is_zero_ether_addr(addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) LOG("%s: rk_vendor_read wifi mac address failed (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) #ifdef CONFIG_WIFI_GENERATE_RANDOM_MAC_ADDR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) random_ether_addr(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) LOG("%s: generate random wifi mac address: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) "%02x:%02x:%02x:%02x:%02x:%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) __func__, addr[0], addr[1], addr[2], addr[3], addr[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) addr[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) ret = rk_vendor_write(WIFI_MAC_ID, addr, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) LOG("%s: rk_vendor_write failed %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) memset(addr, 0, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) LOG("%s: rk_vendor_read wifi mac address: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) "%02x:%02x:%02x:%02x:%02x:%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) __func__, addr[0], addr[1], addr[2], addr[3], addr[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) addr[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return 0;
^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) int rockchip_wifi_mac_addr(unsigned char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) char mac_buf[20] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) LOG("%s: enter.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) // from vendor storage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (is_zero_ether_addr(wifi_custom_mac_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (get_wifi_addr_vendor(wifi_custom_mac_addr) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) return -1;
^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) sprintf(mac_buf, "%02x:%02x:%02x:%02x:%02x:%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) wifi_custom_mac_addr[0], wifi_custom_mac_addr[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) wifi_custom_mac_addr[2], wifi_custom_mac_addr[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) wifi_custom_mac_addr[4], wifi_custom_mac_addr[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) LOG("falsh wifi_custom_mac_addr=[%s]\n", mac_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (is_valid_ether_addr(wifi_custom_mac_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (!strncmp(wifi_chip_type_string, "rtl", 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) wifi_custom_mac_addr[0] &= ~0x2; // for p2p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) LOG("This mac address is not valid, ignored...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) memcpy(buf, wifi_custom_mac_addr, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) EXPORT_SYMBOL(rockchip_wifi_mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^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) * wifi get country code func
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) struct cntry_locales_custom {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) char iso_abbrev[4]; /* ISO 3166-1 country abbreviation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) char custom_locale[4]; /* Custom firmware locale */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) int custom_locale_rev; /* Custom local revisin default -1 */
^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 struct cntry_locales_custom country_cloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) void *rockchip_wifi_country_code(char *ccode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) struct cntry_locales_custom *mcloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) LOG("%s: set country code [%s]\n", __func__, ccode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) mcloc = &country_cloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) memcpy(mcloc->custom_locale, ccode, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) mcloc->custom_locale_rev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return mcloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) EXPORT_SYMBOL(rockchip_wifi_country_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /**************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static int rfkill_rk_setup_gpio(struct rksdmmc_gpio *gpio, const char *prefix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if (gpio_is_valid(gpio->io)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) sprintf(gpio->name, "%s_%s", prefix, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) ret = gpio_request(gpio->io, gpio->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) LOG("Failed to get %s gpio.\n", gpio->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static int wlan_platdata_parse_dt(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) struct rksdmmc_gpio_wifi_moudle *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) struct device_node *node = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) const char *strings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) int gpio, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) enum of_gpio_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) u32 ext_clk_value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) memset(data, 0, sizeof(*data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) #ifdef CONFIG_MFD_SYSCON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) data->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (IS_ERR(data->grf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) LOG("can't find rockchip,grf property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) //return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) ret = of_property_read_string(node, "wifi_chip_type", &strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) LOG("%s: Can not read wifi_chip_type, set default to rkwifi.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) strcpy(wifi_chip_type_string, "rkwifi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (strings && strlen(strings) < 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) strcpy(wifi_chip_type_string, strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) LOG("%s: wifi_chip_type = %s\n", __func__, wifi_chip_type_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (of_find_property(node, "keep_wifi_power_on", NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) data->wifi_power_remain = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) LOG("%s: wifi power remain\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) data->wifi_power_remain = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) LOG("%s: enable wifi power control.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (of_find_property(node, "power_ctrl_by_pmu", NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) data->mregulator.power_ctrl_by_pmu = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) ret = of_property_read_string(node, "power_pmu_regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) &strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) LOG("%s: Can not read property: power_pmu_regulator.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) data->mregulator.power_ctrl_by_pmu = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) LOG("%s: wifi power controlled by pmu(%s).\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) sprintf(data->mregulator.pmu_regulator, "%s", strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) ret = of_property_read_u32(node, "power_pmu_enable_level",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) LOG("%s: Can not read: power_pmu_enable_level.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) data->mregulator.power_ctrl_by_pmu = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) LOG("%s: wifi power controlled by pmu(level = %s).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) __func__, (value == 1) ? "HIGH" : "LOW");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) data->mregulator.enable = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) data->mregulator.power_ctrl_by_pmu = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) LOG("%s: wifi power controled by gpio.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) gpio = of_get_named_gpio_flags(node, "WIFI,poweren_gpio", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (gpio_is_valid(gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) data->power_n.io = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) data->power_n.enable =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) (flags == GPIO_ACTIVE_HIGH) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) LOG("%s: WIFI,poweren_gpio = %d flags = %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) __func__, gpio, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) data->power_n.io = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) gpio = of_get_named_gpio_flags(node, "WIFI,vbat_gpio", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (gpio_is_valid(gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) data->vbat_n.io = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) data->vbat_n.enable =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) (flags == GPIO_ACTIVE_HIGH) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) LOG("%s: WIFI,vbat_gpio = %d, flags = %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) __func__, gpio, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) data->vbat_n.io = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) gpio = of_get_named_gpio_flags(node, "WIFI,reset_gpio", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (gpio_is_valid(gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) data->reset_n.io = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) data->reset_n.enable =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) (flags == GPIO_ACTIVE_HIGH) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) LOG("%s: WIFI,reset_gpio = %d, flags = %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) __func__, gpio, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) data->reset_n.io = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) gpio = of_get_named_gpio_flags(node, "WIFI,host_wake_irq", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (gpio_is_valid(gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) data->wifi_int_b.io = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) data->wifi_int_b.enable = !flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) LOG("%s: WIFI,host_wake_irq = %d, flags = %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) __func__, gpio, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) data->wifi_int_b.io = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) data->ext_clk = devm_clk_get(dev, "clk_wifi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if (IS_ERR(data->ext_clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) LOG("%s: The ref_wifi_clk not found !\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) of_property_read_u32(node, "ref-clock-frequency",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) &ext_clk_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) if (ext_clk_value > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) ret = clk_set_rate(data->ext_clk, ext_clk_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) LOG("%s: set ref clk error!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) ret = clk_prepare_enable(data->ext_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) LOG("%s: enable ref clk error!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) /* WIFI clock (REF_CLKOUT) output enable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * 1'b0: drive disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * 1'b1: output enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (of_machine_is_compatible("rockchip,rk3308"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) regmap_write(data->grf, 0x0314, 0x00020002);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) #endif //CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) #if defined(CONFIG_HAS_EARLYSUSPEND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) #include <linux/earlysuspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) static void wlan_early_suspend(struct early_suspend *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) LOG("%s :enter\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) static void wlan_late_resume(struct early_suspend *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) LOG("%s :enter\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) return;
^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) struct early_suspend wlan_early_suspend {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) .level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) .suspend = wlan_early_suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) .resume = wlan_late_resume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) rfkill_wlan_early_suspend(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) //LOG("%s :enter\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) static void rfkill_wlan_later_resume(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) //LOG("%s :enter\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) static int rfkill_wlan_fb_event_notify(struct notifier_block *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) unsigned long action, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) struct fb_event *event = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) int blank_mode = *((int *)event->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) switch (blank_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) case FB_BLANK_UNBLANK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) rfkill_wlan_later_resume();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) case FB_BLANK_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) rfkill_wlan_early_suspend();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) rfkill_wlan_early_suspend();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) static struct notifier_block rfkill_wlan_fb_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) .notifier_call = rfkill_wlan_fb_event_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) static ssize_t wifi_power_show(struct class *cls, struct class_attribute *attr, char *_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) return sprintf(_buf, "%d\n", wifi_power_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) static ssize_t wifi_power_store(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) long poweren = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (kstrtol(_buf, 10, &poweren) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) LOG("%s: poweren = %ld\n", __func__, poweren);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (poweren > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) rockchip_wifi_power(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) rockchip_wifi_power(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) return _count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) static CLASS_ATTR_RW(wifi_power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) static ssize_t wifi_bt_vbat_show(struct class *cls, struct class_attribute *attr, char *_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) return sprintf(_buf, "%d\n", wifi_bt_vbat_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) static ssize_t wifi_bt_vbat_store(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) long vbat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (kstrtol(_buf, 10, &vbat) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) LOG("%s: vbat = %ld\n", __func__, vbat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) if (vbat > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) rfkill_set_wifi_bt_power(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) rfkill_set_wifi_bt_power(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) return _count;
^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) static CLASS_ATTR_RW(wifi_bt_vbat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) static ssize_t wifi_set_carddetect_store(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) long val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (kstrtol(_buf, 10, &val) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) LOG("%s: val = %ld\n", __func__, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) if (val > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) rockchip_wifi_set_carddetect(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) rockchip_wifi_set_carddetect(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) return _count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) static CLASS_ATTR_WO(wifi_set_carddetect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) static struct attribute *rkwifi_power_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) &class_attr_wifi_power.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) &class_attr_wifi_bt_vbat.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) &class_attr_wifi_set_carddetect.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) ATTRIBUTE_GROUPS(rkwifi_power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) /** Device model classes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) static struct class rkwifi_power = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) .name = "rkwifi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) .class_groups = rkwifi_power_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) static int rfkill_wlan_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) struct rfkill_wlan_data *rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) struct rksdmmc_gpio_wifi_moudle *pdata = pdev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) int ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) LOG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) class_register(&rkwifi_power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (!pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) ret = wlan_platdata_parse_dt(&pdev->dev, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) LOG("%s: No platform data specified\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) #endif
^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) rfkill = kzalloc(sizeof(*rfkill), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) if (!rfkill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) goto rfkill_alloc_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) rfkill->pdata = pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) g_rfkill = rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) LOG("%s: init gpio\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) if (!pdata->mregulator.power_ctrl_by_pmu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) ret = rfkill_rk_setup_gpio(&pdata->vbat_n, wlan_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) "wlan_vbat");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) goto fail_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) ret = rfkill_rk_setup_gpio(&pdata->reset_n, wlan_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) "wlan_reset");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) goto fail_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) wake_lock_init(&rfkill->wlan_irq_wl, WAKE_LOCK_SUSPEND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) "rfkill_wlan_wake");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) rfkill_set_wifi_bt_power(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) #ifdef CONFIG_SDIO_KEEPALIVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) if (gpio_is_valid(pdata->power_n.io) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) gpio_direction_output(pdata->power_n.io, pdata->power_n.enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (pdata->wifi_power_remain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) rockchip_wifi_power(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) #if BCM_STATIC_MEMORY_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) rockchip_init_wifi_mem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) #if defined(CONFIG_HAS_EARLYSUSPEND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) register_early_suspend(wlan_early_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) fb_register_client(&rfkill_wlan_fb_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) LOG("Exit %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) fail_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) kfree(rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) rfkill_alloc_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) kfree(pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) g_rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) static int rfkill_wlan_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) struct rfkill_wlan_data *rfkill = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) LOG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) wake_lock_destroy(&rfkill->wlan_irq_wl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) fb_unregister_client(&rfkill_wlan_fb_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) if (gpio_is_valid(rfkill->pdata->power_n.io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) gpio_free(rfkill->pdata->power_n.io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) if (gpio_is_valid(rfkill->pdata->reset_n.io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) gpio_free(rfkill->pdata->reset_n.io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) kfree(rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) g_rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) return 0;
^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) static void rfkill_wlan_shutdown(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) LOG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) rockchip_wifi_power(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) rfkill_set_wifi_bt_power(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 rfkill_wlan_suspend(struct platform_device *pdev, pm_message_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) LOG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) static int rfkill_wlan_resume(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) LOG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) static struct of_device_id wlan_platdata_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) { .compatible = "wlan-platdata" },
^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) MODULE_DEVICE_TABLE(of, wlan_platdata_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) #endif //CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) static struct platform_driver rfkill_wlan_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) .probe = rfkill_wlan_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) .remove = rfkill_wlan_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) .shutdown = rfkill_wlan_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) .suspend = rfkill_wlan_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) .resume = rfkill_wlan_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) .name = "wlan-platdata",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) .of_match_table = of_match_ptr(wlan_platdata_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) int __init rfkill_wlan_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) LOG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) return platform_driver_register(&rfkill_wlan_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) void __exit rfkill_wlan_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) LOG("Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) platform_driver_unregister(&rfkill_wlan_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) MODULE_DESCRIPTION("rock-chips rfkill for wifi v0.1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) MODULE_AUTHOR("gwl@rock-chips.com");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) MODULE_LICENSE("GPL");