mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 11:26:02 +09:00
net: rfkill: coding style fix of rfkill-bt.c and rfkill-wlan.c
Change-Id: I8ccd3623431cad27fabed8241ad8f7bf59b2e175 Signed-off-by: Weiguo Hu <hwg@rock-chips.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -48,16 +48,16 @@
|
||||
#include "../../drivers/mmc/core/pwrseq.h"
|
||||
|
||||
#if 0
|
||||
#define DBG(x...) printk(KERN_INFO "[WLAN_RFKILL]: "x)
|
||||
#define DBG(x...) pr_info("[WLAN_RFKILL]: " x)
|
||||
#else
|
||||
#define DBG(x...)
|
||||
#endif
|
||||
|
||||
#define LOG(x...) printk(KERN_INFO "[WLAN_RFKILL]: "x)
|
||||
#define LOG(x...) pr_info("[WLAN_RFKILL]: " x)
|
||||
|
||||
struct rfkill_wlan_data {
|
||||
struct rksdmmc_gpio_wifi_moudle *pdata;
|
||||
struct wake_lock wlan_irq_wl;
|
||||
struct wake_lock wlan_irq_wl;
|
||||
};
|
||||
|
||||
static struct rfkill_wlan_data *g_rfkill = NULL;
|
||||
@@ -78,94 +78,94 @@ static char wifi_chip_type_string[64];
|
||||
#endif
|
||||
//===========================
|
||||
#if BCM_STATIC_MEMORY_SUPPORT
|
||||
#define PREALLOC_WLAN_SEC_NUM 4
|
||||
#define PREALLOC_WLAN_BUF_NUM 160
|
||||
#define PREALLOC_WLAN_SECTION_HEADER 0
|
||||
#define WLAN_SKB_BUF_NUM 16
|
||||
#define PREALLOC_WLAN_SEC_NUM 4
|
||||
#define PREALLOC_WLAN_BUF_NUM 160
|
||||
#define PREALLOC_WLAN_SECTION_HEADER 0
|
||||
#define WLAN_SKB_BUF_NUM 16
|
||||
|
||||
#define WLAN_SECTION_SIZE_0 (12 * 1024)
|
||||
#define WLAN_SECTION_SIZE_1 (12 * 1024)
|
||||
#define WLAN_SECTION_SIZE_2 (32 * 1024)
|
||||
#define WLAN_SECTION_SIZE_3 (136* 1024)
|
||||
#define WLAN_SECTION_SIZE_4 (4 * 1024)
|
||||
#define WLAN_SECTION_SIZE_5 (64 * 1024)
|
||||
#define WLAN_SECTION_SIZE_6 (4 * 1024)
|
||||
#define WLAN_SECTION_SIZE_7 (4 * 1024)
|
||||
#define WLAN_SECTION_SIZE_0 (12 * 1024)
|
||||
#define WLAN_SECTION_SIZE_1 (12 * 1024)
|
||||
#define WLAN_SECTION_SIZE_2 (32 * 1024)
|
||||
#define WLAN_SECTION_SIZE_3 (136 * 1024)
|
||||
#define WLAN_SECTION_SIZE_4 (4 * 1024)
|
||||
#define WLAN_SECTION_SIZE_5 (64 * 1024)
|
||||
#define WLAN_SECTION_SIZE_6 (4 * 1024)
|
||||
#define WLAN_SECTION_SIZE_7 (4 * 1024)
|
||||
|
||||
static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM+1];
|
||||
static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM + 1];
|
||||
|
||||
struct wifi_mem_prealloc {
|
||||
void *mem_ptr;
|
||||
unsigned long size;
|
||||
void *mem_ptr;
|
||||
unsigned long size;
|
||||
};
|
||||
|
||||
static struct wifi_mem_prealloc wifi_mem_array[8] = {
|
||||
{NULL, (WLAN_SECTION_SIZE_0)},
|
||||
{NULL, (WLAN_SECTION_SIZE_1)},
|
||||
{NULL, (WLAN_SECTION_SIZE_2)},
|
||||
{NULL, (WLAN_SECTION_SIZE_3)},
|
||||
{NULL, (WLAN_SECTION_SIZE_4)},
|
||||
{NULL, (WLAN_SECTION_SIZE_5)},
|
||||
{NULL, (WLAN_SECTION_SIZE_6)},
|
||||
{NULL, (WLAN_SECTION_SIZE_7)}
|
||||
{ NULL, (WLAN_SECTION_SIZE_0) }, { NULL, (WLAN_SECTION_SIZE_1) },
|
||||
{ NULL, (WLAN_SECTION_SIZE_2) }, { NULL, (WLAN_SECTION_SIZE_3) },
|
||||
{ NULL, (WLAN_SECTION_SIZE_4) }, { NULL, (WLAN_SECTION_SIZE_5) },
|
||||
{ NULL, (WLAN_SECTION_SIZE_6) }, { NULL, (WLAN_SECTION_SIZE_7) }
|
||||
};
|
||||
|
||||
static int rockchip_init_wifi_mem(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
|
||||
wlan_static_skb[i] = dev_alloc_skb(
|
||||
((i < (WLAN_SKB_BUF_NUM / 2)) ? (PAGE_SIZE*1) : (PAGE_SIZE*2)));
|
||||
for (i = 0; i < WLAN_SKB_BUF_NUM; i++) {
|
||||
wlan_static_skb[i] =
|
||||
dev_alloc_skb(((i < (WLAN_SKB_BUF_NUM / 2)) ?
|
||||
(PAGE_SIZE * 1) :
|
||||
(PAGE_SIZE * 2)));
|
||||
|
||||
if (!wlan_static_skb[i])
|
||||
goto err_skb_alloc;
|
||||
}
|
||||
if (!wlan_static_skb[i])
|
||||
goto err_skb_alloc;
|
||||
}
|
||||
|
||||
wlan_static_skb[i] = dev_alloc_skb((PAGE_SIZE*4));
|
||||
if (!wlan_static_skb[i])
|
||||
goto err_skb_alloc;
|
||||
wlan_static_skb[i] = dev_alloc_skb((PAGE_SIZE * 4));
|
||||
if (!wlan_static_skb[i])
|
||||
goto err_skb_alloc;
|
||||
|
||||
for (i = 0 ; i <= 7; i++) {
|
||||
wifi_mem_array[i].mem_ptr =
|
||||
kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
|
||||
for (i = 0; i <= 7; i++) {
|
||||
wifi_mem_array[i].mem_ptr =
|
||||
kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
|
||||
|
||||
if (!wifi_mem_array[i].mem_ptr)
|
||||
goto err_mem_alloc;
|
||||
}
|
||||
return 0;
|
||||
if (!wifi_mem_array[i].mem_ptr)
|
||||
goto err_mem_alloc;
|
||||
}
|
||||
return 0;
|
||||
|
||||
err_mem_alloc:
|
||||
pr_err("Failed to mem_alloc for WLAN\n");
|
||||
for (j = 0 ; j < i ; j++)
|
||||
kfree(wifi_mem_array[j].mem_ptr);
|
||||
i = WLAN_SKB_BUF_NUM;
|
||||
pr_err("Failed to mem_alloc for WLAN\n");
|
||||
for (j = 0; j < i; j++)
|
||||
kfree(wifi_mem_array[j].mem_ptr);
|
||||
i = WLAN_SKB_BUF_NUM;
|
||||
err_skb_alloc:
|
||||
pr_err("Failed to skb_alloc for WLAN\n");
|
||||
for (j = 0 ; j < i ; j++)
|
||||
dev_kfree_skb(wlan_static_skb[j]);
|
||||
dev_kfree_skb(wlan_static_skb[j]);
|
||||
pr_err("Failed to skb_alloc for WLAN\n");
|
||||
for (j = 0; j < i; j++)
|
||||
dev_kfree_skb(wlan_static_skb[j]);
|
||||
dev_kfree_skb(wlan_static_skb[j]);
|
||||
|
||||
return -ENOMEM;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
void *rockchip_mem_prealloc(int section, unsigned long size)
|
||||
{
|
||||
//printk("rockchip_mem_prealloc: section = %d, size = %d\n", section, size);
|
||||
if (section == PREALLOC_WLAN_SEC_NUM)
|
||||
return wlan_static_skb;
|
||||
if (section == PREALLOC_WLAN_SEC_NUM)
|
||||
return wlan_static_skb;
|
||||
|
||||
if ((section < 0) || (section > 7))
|
||||
return NULL;
|
||||
if (section < 0 || section > 7)
|
||||
return NULL;
|
||||
|
||||
if (wifi_mem_array[section].size < size)
|
||||
return NULL;
|
||||
if (wifi_mem_array[section].size < size)
|
||||
return NULL;
|
||||
|
||||
return wifi_mem_array[section].mem_ptr;
|
||||
return wifi_mem_array[section].mem_ptr;
|
||||
}
|
||||
#else
|
||||
void *rockchip_mem_prealloc(int section, unsigned long size) { return NULL;}
|
||||
void *rockchip_mem_prealloc(int section, unsigned long size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
EXPORT_SYMBOL(rockchip_mem_prealloc);
|
||||
|
||||
@@ -177,16 +177,17 @@ EXPORT_SYMBOL(rockchip_mem_prealloc);
|
||||
static int wifi_power_state = 0;
|
||||
int rfkill_get_wifi_power_state(int *power, int *vref_ctrl_enable)
|
||||
{
|
||||
struct rfkill_wlan_data *mrfkill = g_rfkill;
|
||||
struct rfkill_wlan_data *mrfkill = g_rfkill;
|
||||
|
||||
if (mrfkill == NULL) {
|
||||
LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
if (!mrfkill) {
|
||||
LOG("%s: rfkill-wlan driver has not Successful initialized\n",
|
||||
__func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*power = wifi_power_state;
|
||||
*power = wifi_power_state;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
@@ -199,70 +200,70 @@ int rfkill_get_wifi_power_state(int *power, int *vref_ctrl_enable)
|
||||
int rockchip_wifi_power(int on)
|
||||
{
|
||||
struct rfkill_wlan_data *mrfkill = g_rfkill;
|
||||
struct rksdmmc_gpio *poweron, *reset;
|
||||
struct regulator *ldo = NULL;
|
||||
int power = 0;
|
||||
bool toggle = false;
|
||||
struct rksdmmc_gpio *poweron, *reset;
|
||||
struct regulator *ldo = NULL;
|
||||
int power = 0;
|
||||
bool toggle = false;
|
||||
|
||||
LOG("%s: %d\n", __func__, on);
|
||||
LOG("%s: %d\n", __func__, on);
|
||||
|
||||
if (!on && primary_sdio_host)
|
||||
mmc_pwrseq_power_off(primary_sdio_host);
|
||||
|
||||
if (mrfkill == NULL) {
|
||||
LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
if (!mrfkill) {
|
||||
LOG("%s: rfkill-wlan driver has not Successful initialized\n",
|
||||
__func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mrfkill->pdata->wifi_power_remain && power_set_time) {
|
||||
LOG("%s: wifi power is setted to be remain on. skip anything to the power control", __func__);
|
||||
return 0;
|
||||
} else power_set_time++;
|
||||
if (mrfkill->pdata->wifi_power_remain && power_set_time) {
|
||||
LOG("%s: wifi power is setted to be remain on.", __func__);
|
||||
return 0;
|
||||
}
|
||||
power_set_time++;
|
||||
|
||||
if (!rfkill_get_bt_power_state(&power, &toggle)) {
|
||||
if (toggle == true && power == 1) {
|
||||
LOG("%s: wifi shouldn't control the power, it was enabled by BT!\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (mrfkill->pdata->mregulator.power_ctrl_by_pmu) {
|
||||
int ret = -1;
|
||||
char *ldostr;
|
||||
int level = mrfkill->pdata->mregulator.enable;
|
||||
|
||||
ldostr = mrfkill->pdata->mregulator.pmu_regulator;
|
||||
if (ldostr == NULL) {
|
||||
LOG("%s: wifi power set to be controled by pmic, but which one?\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
ldo = regulator_get(NULL, ldostr);
|
||||
if (ldo == NULL || IS_ERR(ldo)) {
|
||||
LOG("\n\n\n%s get ldo error,please mod this\n\n\n", __func__);
|
||||
return -1;
|
||||
} else {
|
||||
if (on == level) {
|
||||
regulator_set_voltage(ldo, 3000000, 3000000);
|
||||
LOG("%s: %s enabled\n", __func__, ldostr);
|
||||
ret = regulator_enable(ldo);
|
||||
wifi_power_state = 1;
|
||||
LOG("wifi turn on power.\n");
|
||||
} else {
|
||||
LOG("%s: %s disabled\n", __func__, ldostr);
|
||||
while (regulator_is_enabled(ldo) > 0) {
|
||||
ret = regulator_disable(ldo);
|
||||
}
|
||||
wifi_power_state = 0;
|
||||
LOG("wifi shut off power.\n");
|
||||
}
|
||||
regulator_put(ldo);
|
||||
msleep(100);
|
||||
if (!rfkill_get_bt_power_state(&power, &toggle)) {
|
||||
if (toggle && power == 1) {
|
||||
LOG("%s: wifi shouldn't control the power\n",
|
||||
__func__);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if (mrfkill->pdata->mregulator.power_ctrl_by_pmu) {
|
||||
int ret = -1;
|
||||
char *ldostr;
|
||||
int level = mrfkill->pdata->mregulator.enable;
|
||||
|
||||
ldostr = mrfkill->pdata->mregulator.pmu_regulator;
|
||||
if (!ldostr)
|
||||
return -1;
|
||||
ldo = regulator_get(NULL, ldostr);
|
||||
if (!ldo || IS_ERR(ldo)) {
|
||||
LOG("\n\n\n%s get ldo error,please mod this\n\n\n",
|
||||
__func__);
|
||||
return -1;
|
||||
}
|
||||
if (on == level) {
|
||||
regulator_set_voltage(ldo, 3000000, 3000000);
|
||||
LOG("%s: %s enabled\n", __func__, ldostr);
|
||||
ret = regulator_enable(ldo);
|
||||
wifi_power_state = 1;
|
||||
LOG("wifi turn on power.\n");
|
||||
} else {
|
||||
LOG("%s: %s disabled\n", __func__, ldostr);
|
||||
while (regulator_is_enabled(ldo) > 0)
|
||||
ret = regulator_disable(ldo);
|
||||
wifi_power_state = 0;
|
||||
LOG("wifi shut off power.\n");
|
||||
}
|
||||
regulator_put(ldo);
|
||||
msleep(100);
|
||||
} else {
|
||||
poweron = &mrfkill->pdata->power_n;
|
||||
reset = &mrfkill->pdata->reset_n;
|
||||
|
||||
if (on){
|
||||
if (on) {
|
||||
if (gpio_is_valid(poweron->io)) {
|
||||
gpio_set_value(poweron->io, poweron->enable);
|
||||
msleep(100);
|
||||
@@ -273,9 +274,9 @@ int rockchip_wifi_power(int on)
|
||||
msleep(100);
|
||||
}
|
||||
|
||||
wifi_power_state = 1;
|
||||
wifi_power_state = 1;
|
||||
LOG("wifi turn on power. %d\n", poweron->io);
|
||||
}else{
|
||||
} else {
|
||||
if (gpio_is_valid(poweron->io)) {
|
||||
gpio_set_value(poweron->io, !(poweron->enable));
|
||||
msleep(100);
|
||||
@@ -285,12 +286,12 @@ int rockchip_wifi_power(int on)
|
||||
gpio_set_value(reset->io, !(reset->enable));
|
||||
}
|
||||
|
||||
wifi_power_state = 0;
|
||||
wifi_power_state = 0;
|
||||
LOG("wifi shut off power.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(rockchip_wifi_power);
|
||||
|
||||
@@ -313,25 +314,26 @@ EXPORT_SYMBOL(rockchip_wifi_set_carddetect);
|
||||
*************************************************************************/
|
||||
int rockchip_wifi_get_oob_irq(void)
|
||||
{
|
||||
struct rfkill_wlan_data *mrfkill = g_rfkill;
|
||||
struct rksdmmc_gpio *wifi_int_irq;
|
||||
struct rfkill_wlan_data *mrfkill = g_rfkill;
|
||||
struct rksdmmc_gpio *wifi_int_irq;
|
||||
|
||||
LOG("%s: Enter\n", __func__);
|
||||
LOG("%s: Enter\n", __func__);
|
||||
|
||||
if (mrfkill == NULL) {
|
||||
LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
wifi_int_irq = &mrfkill->pdata->wifi_int_b;
|
||||
if (gpio_is_valid(wifi_int_irq->io)) {
|
||||
return gpio_to_irq(wifi_int_irq->io);
|
||||
//return wifi_int_irq->io;
|
||||
} else {
|
||||
LOG("%s: wifi OOB pin isn't defined.\n", __func__);
|
||||
}
|
||||
|
||||
return -1;
|
||||
if (!mrfkill) {
|
||||
LOG("%s: rfkill-wlan driver has not Successful initialized\n",
|
||||
__func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
wifi_int_irq = &mrfkill->pdata->wifi_int_b;
|
||||
if (gpio_is_valid(wifi_int_irq->io)) {
|
||||
return gpio_to_irq(wifi_int_irq->io);
|
||||
//return wifi_int_irq->io;
|
||||
} else {
|
||||
LOG("%s: wifi OOB pin isn't defined.\n", __func__);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
EXPORT_SYMBOL(rockchip_wifi_get_oob_irq);
|
||||
|
||||
@@ -358,7 +360,7 @@ EXPORT_SYMBOL(rockchip_wifi_get_oob_irq_flag);
|
||||
*************************************************************************/
|
||||
int rockchip_wifi_reset(int on)
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(rockchip_wifi_reset);
|
||||
|
||||
@@ -369,7 +371,7 @@ EXPORT_SYMBOL(rockchip_wifi_reset);
|
||||
*************************************************************************/
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/errno.h>
|
||||
u8 wifi_custom_mac_addr[6] = {0,0,0,0,0,0};
|
||||
u8 wifi_custom_mac_addr[6] = { 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
//#define RANDOM_ADDRESS_SAVE
|
||||
static int get_wifi_addr_vendor(unsigned char *addr)
|
||||
@@ -391,13 +393,12 @@ static int get_wifi_addr_vendor(unsigned char *addr)
|
||||
random_ether_addr(addr);
|
||||
LOG("%s: generate random wifi mac address: "
|
||||
"%02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
__func__, addr[0], addr[1], addr[2],
|
||||
addr[3], addr[4], addr[5]);
|
||||
__func__, addr[0], addr[1], addr[2], addr[3], addr[4],
|
||||
addr[5]);
|
||||
ret = rk_vendor_write(WIFI_MAC_ID, addr, 6);
|
||||
if (ret != 0) {
|
||||
LOG("%s: rk_vendor_write"
|
||||
" wifi mac address failed (%d)\n",
|
||||
__func__, ret);
|
||||
LOG("%s: rk_vendor_write failed %d\n"
|
||||
__func__, ret);
|
||||
memset(addr, 0, 6);
|
||||
return -1;
|
||||
}
|
||||
@@ -407,15 +408,15 @@ static int get_wifi_addr_vendor(unsigned char *addr)
|
||||
} else {
|
||||
LOG("%s: rk_vendor_read wifi mac address: "
|
||||
"%02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
__func__, addr[0], addr[1], addr[2],
|
||||
addr[3], addr[4], addr[5]);
|
||||
__func__, addr[0], addr[1], addr[2], addr[3], addr[4],
|
||||
addr[5]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rockchip_wifi_mac_addr(unsigned char *buf)
|
||||
{
|
||||
char mac_buf[20] = {0};
|
||||
char mac_buf[20] = { 0 };
|
||||
|
||||
LOG("%s: enter.\n", __func__);
|
||||
|
||||
@@ -451,130 +452,156 @@ EXPORT_SYMBOL(rockchip_wifi_mac_addr);
|
||||
*
|
||||
*************************************************************************/
|
||||
struct cntry_locales_custom {
|
||||
char iso_abbrev[4]; /* ISO 3166-1 country abbreviation */
|
||||
char custom_locale[4]; /* Custom firmware locale */
|
||||
int custom_locale_rev; /* Custom local revisin default -1 */
|
||||
char iso_abbrev[4]; /* ISO 3166-1 country abbreviation */
|
||||
char custom_locale[4]; /* Custom firmware locale */
|
||||
int custom_locale_rev; /* Custom local revisin default -1 */
|
||||
};
|
||||
|
||||
static struct cntry_locales_custom country_cloc;
|
||||
|
||||
void *rockchip_wifi_country_code(char *ccode)
|
||||
{
|
||||
struct cntry_locales_custom *mcloc;
|
||||
struct cntry_locales_custom *mcloc;
|
||||
|
||||
LOG("%s: set country code [%s]\n", __func__, ccode);
|
||||
mcloc = &country_cloc;
|
||||
memcpy(mcloc->custom_locale, ccode, 4);
|
||||
mcloc->custom_locale_rev = 0;
|
||||
LOG("%s: set country code [%s]\n", __func__, ccode);
|
||||
mcloc = &country_cloc;
|
||||
memcpy(mcloc->custom_locale, ccode, 4);
|
||||
mcloc->custom_locale_rev = 0;
|
||||
|
||||
return mcloc;
|
||||
return mcloc;
|
||||
}
|
||||
EXPORT_SYMBOL(rockchip_wifi_country_code);
|
||||
/**************************************************************************/
|
||||
|
||||
static int rfkill_rk_setup_gpio(struct rksdmmc_gpio *gpio, const char* prefix, const char* name)
|
||||
static int rfkill_rk_setup_gpio(struct rksdmmc_gpio *gpio, const char *prefix,
|
||||
const char *name)
|
||||
{
|
||||
if (gpio_is_valid(gpio->io)) {
|
||||
int ret=0;
|
||||
sprintf(gpio->name, "%s_%s", prefix, name);
|
||||
ret = gpio_request(gpio->io, gpio->name);
|
||||
if (ret) {
|
||||
LOG("Failed to get %s gpio.\n", gpio->name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (gpio_is_valid(gpio->io)) {
|
||||
int ret = 0;
|
||||
|
||||
return 0;
|
||||
sprintf(gpio->name, "%s_%s", prefix, name);
|
||||
ret = gpio_request(gpio->io, gpio->name);
|
||||
if (ret) {
|
||||
LOG("Failed to get %s gpio.\n", gpio->name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
static int wlan_platdata_parse_dt(struct device *dev,
|
||||
struct rksdmmc_gpio_wifi_moudle *data)
|
||||
struct rksdmmc_gpio_wifi_moudle *data)
|
||||
{
|
||||
struct device_node *node = dev->of_node;
|
||||
const char *strings;
|
||||
u32 value;
|
||||
int gpio,ret;
|
||||
enum of_gpio_flags flags;
|
||||
struct device_node *node = dev->of_node;
|
||||
const char *strings;
|
||||
u32 value;
|
||||
int gpio, ret;
|
||||
enum of_gpio_flags flags;
|
||||
u32 ext_clk_value = 0;
|
||||
|
||||
if (!node)
|
||||
return -ENODEV;
|
||||
if (!node)
|
||||
return -ENODEV;
|
||||
|
||||
memset(data, 0, sizeof(*data));
|
||||
memset(data, 0, sizeof(*data));
|
||||
|
||||
#ifdef CONFIG_MFD_SYSCON
|
||||
data->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf");
|
||||
if (IS_ERR(data->grf)) {
|
||||
LOG("can't find rockchip,grf property\n");
|
||||
//return -1;
|
||||
}
|
||||
data->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf");
|
||||
if (IS_ERR(data->grf)) {
|
||||
LOG("can't find rockchip,grf property\n");
|
||||
//return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = of_property_read_string(node, "wifi_chip_type", &strings);
|
||||
if (ret) {
|
||||
LOG("%s: Can not read wifi_chip_type, set default to rkwifi.\n", __func__);
|
||||
strcpy(wifi_chip_type_string, "rkwifi");
|
||||
} else {
|
||||
strcpy(wifi_chip_type_string, strings);
|
||||
}
|
||||
LOG("%s: wifi_chip_type = %s\n", __func__, wifi_chip_type_string);
|
||||
ret = of_property_read_string(node, "wifi_chip_type", &strings);
|
||||
if (ret) {
|
||||
LOG("%s: Can not read wifi_chip_type, set default to rkwifi.\n",
|
||||
__func__);
|
||||
strcpy(wifi_chip_type_string, "rkwifi");
|
||||
} else {
|
||||
strcpy(wifi_chip_type_string, strings);
|
||||
}
|
||||
LOG("%s: wifi_chip_type = %s\n", __func__, wifi_chip_type_string);
|
||||
|
||||
if (of_find_property(node, "keep_wifi_power_on", NULL)) {
|
||||
data->wifi_power_remain = true;
|
||||
LOG("%s: wifi power will enabled while kernel starting and keep on.\n", __func__);
|
||||
} else {
|
||||
data->wifi_power_remain = false;
|
||||
LOG("%s: enable wifi power control.\n", __func__);
|
||||
}
|
||||
if (of_find_property(node, "keep_wifi_power_on", NULL)) {
|
||||
data->wifi_power_remain = true;
|
||||
LOG("%s: wifi power remain\n", __func__);
|
||||
} else {
|
||||
data->wifi_power_remain = false;
|
||||
LOG("%s: enable wifi power control.\n", __func__);
|
||||
}
|
||||
|
||||
if (of_find_property(node, "power_ctrl_by_pmu", NULL)) {
|
||||
data->mregulator.power_ctrl_by_pmu = true;
|
||||
ret = of_property_read_string(node, "power_pmu_regulator", &strings);
|
||||
if (ret) {
|
||||
LOG("%s: Can not read property: power_pmu_regulator.\n", __func__);
|
||||
data->mregulator.power_ctrl_by_pmu = false;
|
||||
} else {
|
||||
LOG("%s: wifi power controled by pmu(%s).\n", __func__, strings);
|
||||
sprintf(data->mregulator.pmu_regulator, "%s", strings);
|
||||
}
|
||||
ret = of_property_read_u32(node, "power_pmu_enable_level", &value);
|
||||
if (ret) {
|
||||
LOG("%s: Can not read property: power_pmu_enable_level.\n", __func__);
|
||||
data->mregulator.power_ctrl_by_pmu = false;
|
||||
} else {
|
||||
LOG("%s: wifi power controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
|
||||
data->mregulator.enable = value;
|
||||
}
|
||||
if (of_find_property(node, "power_ctrl_by_pmu", NULL)) {
|
||||
data->mregulator.power_ctrl_by_pmu = true;
|
||||
ret = of_property_read_string(node, "power_pmu_regulator",
|
||||
&strings);
|
||||
if (ret) {
|
||||
LOG("%s: Can not read property: power_pmu_regulator.\n",
|
||||
__func__);
|
||||
data->mregulator.power_ctrl_by_pmu = false;
|
||||
} else {
|
||||
LOG("%s: wifi power controlled by pmu(%s).\n", __func__,
|
||||
strings);
|
||||
sprintf(data->mregulator.pmu_regulator, "%s", strings);
|
||||
}
|
||||
ret = of_property_read_u32(node, "power_pmu_enable_level",
|
||||
&value);
|
||||
if (ret) {
|
||||
LOG("%s: Can not read: power_pmu_enable_level.\n",
|
||||
__func__);
|
||||
data->mregulator.power_ctrl_by_pmu = false;
|
||||
} else {
|
||||
LOG("%s: wifi power controlled by pmu(level = %s).\n",
|
||||
__func__, (value == 1) ? "HIGH" : "LOW");
|
||||
data->mregulator.enable = value;
|
||||
}
|
||||
} else {
|
||||
data->mregulator.power_ctrl_by_pmu = false;
|
||||
LOG("%s: wifi power controled by gpio.\n", __func__);
|
||||
gpio = of_get_named_gpio_flags(node, "WIFI,poweren_gpio", 0, &flags);
|
||||
if (gpio_is_valid(gpio)){
|
||||
gpio = of_get_named_gpio_flags(node, "WIFI,poweren_gpio", 0,
|
||||
&flags);
|
||||
if (gpio_is_valid(gpio)) {
|
||||
data->power_n.io = gpio;
|
||||
data->power_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
|
||||
LOG("%s: get property: WIFI,poweren_gpio = %d, flags = %d.\n", __func__, gpio, flags);
|
||||
} else data->power_n.io = -1;
|
||||
gpio = of_get_named_gpio_flags(node, "WIFI,vbat_gpio", 0, &flags);
|
||||
if (gpio_is_valid(gpio)) {
|
||||
data->power_n.enable =
|
||||
(flags == GPIO_ACTIVE_HIGH) ? 1 : 0;
|
||||
LOG("%s: WIFI,poweren_gpio = %d flags = %d.\n",
|
||||
__func__, gpio, flags);
|
||||
} else {
|
||||
data->power_n.io = -1;
|
||||
}
|
||||
gpio = of_get_named_gpio_flags(node, "WIFI,vbat_gpio", 0,
|
||||
&flags);
|
||||
if (gpio_is_valid(gpio)) {
|
||||
data->vbat_n.io = gpio;
|
||||
data->vbat_n.enable = (flags == GPIO_ACTIVE_HIGH) ? 1:0;
|
||||
LOG("%s: get property: WIFI,vbat_gpio = %d, flags = %d.\n", __func__, gpio, flags);
|
||||
} else {
|
||||
data->vbat_n.io = -1;
|
||||
}
|
||||
gpio = of_get_named_gpio_flags(node, "WIFI,reset_gpio", 0, &flags);
|
||||
if (gpio_is_valid(gpio)){
|
||||
data->vbat_n.enable =
|
||||
(flags == GPIO_ACTIVE_HIGH) ? 1 : 0;
|
||||
LOG("%s: WIFI,vbat_gpio = %d, flags = %d.\n",
|
||||
__func__, gpio, flags);
|
||||
} else {
|
||||
data->vbat_n.io = -1;
|
||||
}
|
||||
gpio = of_get_named_gpio_flags(node, "WIFI,reset_gpio", 0,
|
||||
&flags);
|
||||
if (gpio_is_valid(gpio)) {
|
||||
data->reset_n.io = gpio;
|
||||
data->reset_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
|
||||
LOG("%s: get property: WIFI,reset_gpio = %d, flags = %d.\n", __func__, gpio, flags);
|
||||
} else data->reset_n.io = -1;
|
||||
gpio = of_get_named_gpio_flags(node, "WIFI,host_wake_irq", 0, &flags);
|
||||
if (gpio_is_valid(gpio)){
|
||||
data->reset_n.enable =
|
||||
(flags == GPIO_ACTIVE_HIGH) ? 1 : 0;
|
||||
LOG("%s: WIFI,reset_gpio = %d, flags = %d.\n",
|
||||
__func__, gpio, flags);
|
||||
} else {
|
||||
data->reset_n.io = -1;
|
||||
}
|
||||
gpio = of_get_named_gpio_flags(node, "WIFI,host_wake_irq", 0,
|
||||
&flags);
|
||||
if (gpio_is_valid(gpio)) {
|
||||
data->wifi_int_b.io = gpio;
|
||||
data->wifi_int_b.enable = !flags;
|
||||
LOG("%s: get property: WIFI,host_wake_irq = %d, flags = %d.\n", __func__, gpio, flags);
|
||||
} else data->wifi_int_b.io = -1;
|
||||
LOG("%s: WIFI,host_wake_irq = %d, flags = %d.\n",
|
||||
__func__, gpio, flags);
|
||||
} else {
|
||||
data->wifi_int_b.io = -1;
|
||||
}
|
||||
}
|
||||
|
||||
data->ext_clk = devm_clk_get(dev, "clk_wifi");
|
||||
@@ -599,7 +626,7 @@ static int wlan_platdata_parse_dt(struct device *dev,
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif //CONFIG_OF
|
||||
|
||||
@@ -608,149 +635,149 @@ static int wlan_platdata_parse_dt(struct device *dev,
|
||||
|
||||
static void wlan_early_suspend(struct early_suspend *h)
|
||||
{
|
||||
LOG("%s :enter\n", __func__);
|
||||
LOG("%s :enter\n", __func__);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
static void wlan_late_resume(struct early_suspend *h)
|
||||
{
|
||||
LOG("%s :enter\n", __func__);
|
||||
LOG("%s :enter\n", __func__);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
struct early_suspend wlan_early_suspend {
|
||||
.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
|
||||
.suspend = wlan_early_suspend;
|
||||
.resume = wlan_late_resume;
|
||||
.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
|
||||
.suspend = wlan_early_suspend;
|
||||
.resume = wlan_late_resume;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void rfkill_wlan_early_suspend(void)
|
||||
static void
|
||||
rfkill_wlan_early_suspend(void)
|
||||
{
|
||||
//LOG("%s :enter\n", __func__);
|
||||
//LOG("%s :enter\n", __func__);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
static void rfkill_wlan_later_resume(void)
|
||||
{
|
||||
//LOG("%s :enter\n", __func__);
|
||||
//LOG("%s :enter\n", __func__);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
static int rfkill_wlan_fb_event_notify(struct notifier_block *self,
|
||||
unsigned long action, void *data)
|
||||
unsigned long action, void *data)
|
||||
{
|
||||
struct fb_event *event = data;
|
||||
int blank_mode = *((int *)event->data);
|
||||
|
||||
struct fb_event *event = data;
|
||||
int blank_mode = *((int *)event->data);
|
||||
switch (blank_mode) {
|
||||
case FB_BLANK_UNBLANK:
|
||||
rfkill_wlan_later_resume();
|
||||
break;
|
||||
case FB_BLANK_NORMAL:
|
||||
rfkill_wlan_early_suspend();
|
||||
break;
|
||||
default:
|
||||
rfkill_wlan_early_suspend();
|
||||
break;
|
||||
}
|
||||
|
||||
switch (blank_mode) {
|
||||
case FB_BLANK_UNBLANK:
|
||||
rfkill_wlan_later_resume();
|
||||
break;
|
||||
case FB_BLANK_NORMAL:
|
||||
rfkill_wlan_early_suspend();
|
||||
break;
|
||||
default:
|
||||
rfkill_wlan_early_suspend();
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct notifier_block rfkill_wlan_fb_notifier = {
|
||||
.notifier_call = rfkill_wlan_fb_event_notify,
|
||||
.notifier_call = rfkill_wlan_fb_event_notify,
|
||||
};
|
||||
|
||||
|
||||
static int rfkill_wlan_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct rfkill_wlan_data *rfkill;
|
||||
struct rksdmmc_gpio_wifi_moudle *pdata = pdev->dev.platform_data;
|
||||
int ret = -1;
|
||||
|
||||
LOG("Enter %s\n", __func__);
|
||||
LOG("Enter %s\n", __func__);
|
||||
|
||||
if (!pdata) {
|
||||
#ifdef CONFIG_OF
|
||||
pdata = kzalloc(sizeof(struct rksdmmc_gpio_wifi_moudle), GFP_KERNEL);
|
||||
if (!pdata)
|
||||
return -ENOMEM;
|
||||
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
|
||||
if (!pdata)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = wlan_platdata_parse_dt(&pdev->dev, pdata);
|
||||
if (ret < 0) {
|
||||
ret = wlan_platdata_parse_dt(&pdev->dev, pdata);
|
||||
if (ret < 0) {
|
||||
#endif
|
||||
LOG("%s: No platform data specified\n", __func__);
|
||||
return ret;
|
||||
LOG("%s: No platform data specified\n", __func__);
|
||||
return ret;
|
||||
#ifdef CONFIG_OF
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
rfkill = kzalloc(sizeof(*rfkill), GFP_KERNEL);
|
||||
if (!rfkill)
|
||||
goto rfkill_alloc_fail;
|
||||
goto rfkill_alloc_fail;
|
||||
|
||||
rfkill->pdata = pdata;
|
||||
g_rfkill = rfkill;
|
||||
g_rfkill = rfkill;
|
||||
|
||||
LOG("%s: init gpio\n", __func__);
|
||||
LOG("%s: init gpio\n", __func__);
|
||||
|
||||
if (!pdata->mregulator.power_ctrl_by_pmu) {
|
||||
ret = rfkill_rk_setup_gpio(&pdata->vbat_n, wlan_name, "wlan_vbat");
|
||||
if (ret)
|
||||
goto fail_alloc;
|
||||
if (!pdata->mregulator.power_ctrl_by_pmu) {
|
||||
ret = rfkill_rk_setup_gpio(&pdata->vbat_n, wlan_name,
|
||||
"wlan_vbat");
|
||||
if (ret)
|
||||
goto fail_alloc;
|
||||
|
||||
ret = rfkill_rk_setup_gpio(&pdata->power_n, wlan_name, "wlan_poweren");
|
||||
if (ret)
|
||||
goto fail_alloc;
|
||||
ret = rfkill_rk_setup_gpio(&pdata->power_n, wlan_name,
|
||||
"wlan_poweren");
|
||||
if (ret)
|
||||
goto fail_alloc;
|
||||
|
||||
ret = rfkill_rk_setup_gpio(&pdata->reset_n, wlan_name, "wlan_reset");
|
||||
if (ret)
|
||||
goto fail_alloc;
|
||||
}
|
||||
ret = rfkill_rk_setup_gpio(&pdata->reset_n, wlan_name,
|
||||
"wlan_reset");
|
||||
if (ret)
|
||||
goto fail_alloc;
|
||||
}
|
||||
|
||||
wake_lock_init(&(rfkill->wlan_irq_wl), WAKE_LOCK_SUSPEND, "rfkill_wlan_wake");
|
||||
wake_lock_init(&rfkill->wlan_irq_wl, WAKE_LOCK_SUSPEND,
|
||||
"rfkill_wlan_wake");
|
||||
|
||||
if (gpio_is_valid(pdata->vbat_n.io)) {
|
||||
gpio_direction_output(pdata->vbat_n.io, pdata->vbat_n.enable);
|
||||
}
|
||||
// Turn off wifi power as default
|
||||
if (gpio_is_valid(pdata->power_n.io))
|
||||
{
|
||||
gpio_direction_output(pdata->power_n.io, !pdata->power_n.enable);
|
||||
}
|
||||
if (gpio_is_valid(pdata->vbat_n.io))
|
||||
gpio_direction_output(pdata->vbat_n.io, pdata->vbat_n.enable);
|
||||
|
||||
if (pdata->wifi_power_remain)
|
||||
{
|
||||
rockchip_wifi_power(1);
|
||||
}
|
||||
// Turn off wifi power as default
|
||||
if (gpio_is_valid(pdata->power_n.io))
|
||||
gpio_direction_output(pdata->power_n.io,
|
||||
!pdata->power_n.enable);
|
||||
|
||||
if (pdata->wifi_power_remain)
|
||||
rockchip_wifi_power(1);
|
||||
|
||||
#if BCM_STATIC_MEMORY_SUPPORT
|
||||
rockchip_init_wifi_mem();
|
||||
rockchip_init_wifi_mem();
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_HAS_EARLYSUSPEND)
|
||||
register_early_suspend(wlan_early_suspend);
|
||||
register_early_suspend(wlan_early_suspend);
|
||||
#endif
|
||||
|
||||
fb_register_client(&rfkill_wlan_fb_notifier);
|
||||
|
||||
LOG("Exit %s\n", __func__);
|
||||
fb_register_client(&rfkill_wlan_fb_notifier);
|
||||
|
||||
LOG("Exit %s\n", __func__);
|
||||
|
||||
return 0;
|
||||
|
||||
fail_alloc:
|
||||
kfree(rfkill);
|
||||
rfkill_alloc_fail:
|
||||
kfree(pdata);
|
||||
kfree(pdata);
|
||||
|
||||
g_rfkill = NULL;
|
||||
g_rfkill = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -759,40 +786,40 @@ static int rfkill_wlan_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct rfkill_wlan_data *rfkill = platform_get_drvdata(pdev);
|
||||
|
||||
LOG("Enter %s\n", __func__);
|
||||
LOG("Enter %s\n", __func__);
|
||||
|
||||
wake_lock_destroy(&rfkill->wlan_irq_wl);
|
||||
wake_lock_destroy(&rfkill->wlan_irq_wl);
|
||||
|
||||
fb_unregister_client(&rfkill_wlan_fb_notifier);
|
||||
|
||||
if (gpio_is_valid(rfkill->pdata->power_n.io))
|
||||
gpio_free(rfkill->pdata->power_n.io);
|
||||
|
||||
if (gpio_is_valid(rfkill->pdata->reset_n.io))
|
||||
gpio_free(rfkill->pdata->reset_n.io);
|
||||
fb_unregister_client(&rfkill_wlan_fb_notifier);
|
||||
|
||||
kfree(rfkill);
|
||||
g_rfkill = NULL;
|
||||
if (gpio_is_valid(rfkill->pdata->power_n.io))
|
||||
gpio_free(rfkill->pdata->power_n.io);
|
||||
|
||||
if (gpio_is_valid(rfkill->pdata->reset_n.io))
|
||||
gpio_free(rfkill->pdata->reset_n.io);
|
||||
|
||||
kfree(rfkill);
|
||||
g_rfkill = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rfkill_wlan_suspend(struct platform_device *pdev, pm_message_t state)
|
||||
{
|
||||
LOG("Enter %s\n", __func__);
|
||||
return 0;
|
||||
LOG("Enter %s\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rfkill_wlan_resume(struct platform_device *pdev)
|
||||
{
|
||||
LOG("Enter %s\n", __func__);
|
||||
return 0;
|
||||
LOG("Enter %s\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
static struct of_device_id wlan_platdata_of_match[] = {
|
||||
{ .compatible = "wlan-platdata" },
|
||||
{ }
|
||||
{ .compatible = "wlan-platdata" },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, wlan_platdata_of_match);
|
||||
#endif //CONFIG_OF
|
||||
@@ -811,13 +838,13 @@ static struct platform_driver rfkill_wlan_driver = {
|
||||
|
||||
static int __init rfkill_wlan_init(void)
|
||||
{
|
||||
LOG("Enter %s\n", __func__);
|
||||
LOG("Enter %s\n", __func__);
|
||||
return platform_driver_register(&rfkill_wlan_driver);
|
||||
}
|
||||
|
||||
static void __exit rfkill_wlan_exit(void)
|
||||
{
|
||||
LOG("Enter %s\n", __func__);
|
||||
LOG("Enter %s\n", __func__);
|
||||
platform_driver_unregister(&rfkill_wlan_driver);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user