static void bluesleep_tx_data_wakeup(void)
{
    if (test_bit(BT_ASLEEP, &flags)) {
        BT_DBG("waking up from BT Write...");

        wake_lock(&bsi->wake_lock);
        /* Start the timer */
        mod_timer(&tx_timer,
                  jiffies + msecs_to_jiffies(TX_TIMER_INTERVAL * 1000));
        if (bsi->has_ext_wake == 1) {
            int ret;
            ret = ice_gpiox_set(bsi->ext_wake, 1);
            if (ret)
            {
                int retry_cnt;
                BT_ERR("(bluesleep_tx_data_wakeup) failed to set ext_wake 1.");
                for(retry_cnt=0 ; retry_cnt < 5 ; retry_cnt ++){
                    usleep(5000);
                    ret = ice_gpiox_set(bsi->ext_wake, 1);
                    BT_ERR("retry_cnt = %d", retry_cnt);
                    if(ret == 0)
                        break;
                }
            }
        }
        set_bit(BT_EXT_WAKE, &flags);
        clear_bit(BT_ASLEEP, &flags);
    }
    else {
        BT_DBG("bluesleep_tx_data_wakeup : already wake up, so start timer...");
        mod_timer(&tx_timer,
                  jiffies + msecs_to_jiffies(TX_TIMER_INTERVAL * 1000));
    }
}
void bluesleep_sleep_wakeup(void)
{
    if (test_bit(BT_ASLEEP, &flags)) {
        BT_DBG("waking up...");
        /*Activating UART */
        hsuart_power(1);
        wake_lock(&bsi->wake_lock);
        /* Start the timer */
        mod_timer(&tx_timer,
                  jiffies + msecs_to_jiffies(TX_TIMER_INTERVAL * 1000));
        if (bsi->has_ext_wake == 1) {
            int ret;
            ret = ice_gpiox_set(bsi->ext_wake, 1);
            if (ret)
            {
                BT_ERR("(bluesleep_sleep_wakeup) failed to set ext_wake 1.");
                ret = ice_gpiox_set(bsi->ext_wake, 1);
                BT_ERR("ret = %d", ret);
            }
        }
        set_bit(BT_EXT_WAKE, &flags);
        clear_bit(BT_ASLEEP, &flags);
    }
    else {
        BT_DBG("bluesleep_sleep_wakeup : already wake up, so start timer...");
        mod_timer(&tx_timer,
                  jiffies + msecs_to_jiffies(TX_TIMER_INTERVAL * 1000));
    }
}
static int bcm4335_bt_rfkill_set_power(void *data, bool blocked)
{
	/* rfkill_ops callback. Turn transmitter on when blocked is false */
#ifdef BT_UART_CFG
	int pin, rc = 0;
#endif
	int ret = -1;

	if (!blocked) {
		pr_err("[BT] Bluetooth Power On.\n");

		ret = ice_gpiox_set(FPGA_GPIO_BT_WAKE, 1);
		if (ret)
			pr_err("[BT] failed to set ext_wake to high.\n");

#ifdef BT_UART_CFG
	for (pin = 0; pin < ARRAY_SIZE(bt_uart_on_table); pin++) {
			rc = gpio_tlmm_config(bt_uart_on_table[pin],
					      GPIO_CFG_ENABLE);
		if (rc < 0)
			pr_err("[BT] %s: gpio_tlmm_config(%#x)=%d\n",
			       __func__, bt_uart_on_table[pin], rc);
	}
#endif
		ret = ice_gpiox_set(FPGA_GPIO_BT_EN, 1);
		if (ret)
			pr_err("[BT] failed to set BT_EN.\n");
#if defined(CONFIG_BCM4335) || defined(CONFIG_BCM4335_MODULE)
		else
			bt_is_running = 1;
#endif
	} else {
#ifdef BT_UART_CFG
	for (pin = 0; pin < ARRAY_SIZE(bt_uart_off_table); pin++) {
			rc = gpio_tlmm_config(bt_uart_off_table[pin],
					      GPIO_CFG_ENABLE);
		if (rc < 0)
				pr_err("%s: gpio_tlmm_config(%#x)=%d\n",
				       __func__, bt_uart_off_table[pin], rc);
	}
#endif
		pr_err("[BT] Bluetooth Power Off.\n");

		ret = ice_gpiox_set(FPGA_GPIO_BT_EN, 0);
		if (ret)
			pr_err("[BT] failed to set BT_EN.\n");
#if defined(CONFIG_BCM4335) || defined(CONFIG_BCM4335_MODULE)
		else
			bt_is_running = 0;
#endif
	}
	return 0;
}
/**
 * Stops the Sleep-Mode Protocol on the Host.
 */
static void bluesleep_stop(void)
{
	if (!test_bit(BT_PROTO, &flags)) {
		BT_ERR("(bluesleep_stop_wq) proto is not set. Failed to stop bluesleep");
		bsi->uport = NULL;
		return;
	}
	/* assert BT_WAKE */
	if (bsi->has_ext_wake == 1) {
		int ret;
		ret = ice_gpiox_set(bsi->ext_wake, 1);
		if (ret)
			BT_ERR("(bluesleep_stop) failed to set ext_wake 1.");
	}
	set_bit(BT_EXT_WAKE, &flags);
	del_timer(&tx_timer);
	clear_bit(BT_PROTO, &flags);

	if (test_bit(BT_ASLEEP, &flags)) {
		clear_bit(BT_ASLEEP, &flags);
		hsuart_power(1);
	}

	if (disable_irq_wake(bsi->host_wake_irq))
		BT_ERR("Couldn't disable hostwake IRQ wakeup mode\n");
	wake_lock_timeout(&bsi->wake_lock, msecs_to_jiffies(125));

	bsi->uport = NULL;
}
/**
 * Starts the Sleep-Mode Protocol on the Host.
 */
static void bluesleep_start(void)
{
	int retval;

	if (test_bit(BT_PROTO, &flags)) {
		return;
	}

	/* start the timer */
	mod_timer(&tx_timer, jiffies + msecs_to_jiffies(TX_TIMER_INTERVAL * 1000));

	/* assert BT_WAKE */
	if (bsi->has_ext_wake == 1) {
		int ret;
		ret = ice_gpiox_set(bsi->ext_wake, 1);
		if (ret)
			BT_ERR("(bluesleep_start) failed to set ext_wake 1.");
	}
	set_bit(BT_EXT_WAKE, &flags);
	retval = enable_irq_wake(bsi->host_wake_irq);
	if (retval < 0) {
		BT_ERR("Couldn't enable BT_HOST_WAKE as wakeup interrupt");
		goto fail;
	}
	set_bit(BT_PROTO, &flags);
	wake_lock(&bsi->wake_lock);
	return;
fail:
	del_timer(&tx_timer);

	return;
}
static void bluesleep_ext_wake_set_wq(struct work_struct *work)
{
	int ret;
	ret = ice_gpiox_set(bsi->ext_wake, 0);
	if (ret)
		BT_ERR("(bluesleep_ext_wake_set_wq) failed to set ext_wake 0.");
}
/**
 * Cleans up the module.
 */
static void __exit bluesleep_exit(void)
{
	if (bsi == NULL)
		return;

	/* assert bt wake */
	if (bsi->has_ext_wake == 1) {
		int ret;
		ret = ice_gpiox_set(bsi->ext_wake, 1);
		if (ret)
			BT_ERR("(bluesleep_exit) failed to set ext_wake 1.");
	}
	set_bit(BT_EXT_WAKE, &flags);
	if (test_bit(BT_PROTO, &flags)) {
		if (disable_irq_wake(bsi->host_wake_irq))
			BT_ERR("Couldn't disable hostwake IRQ wakeup mode\n");
		free_irq(bsi->host_wake_irq, NULL);
		del_timer(&tx_timer);
		if (test_bit(BT_ASLEEP, &flags))
			hsuart_power(1);
	}

	platform_driver_unregister(&bluesleep_driver);

	remove_proc_entry("btwrite", sleep_dir);
	remove_proc_entry("lpm", sleep_dir);
	remove_proc_entry("asleep", sleep_dir);
	remove_proc_entry("proto", sleep_dir);
	remove_proc_entry("hostwake", sleep_dir);
	remove_proc_entry("btwake", sleep_dir);
	remove_proc_entry("sleep", bluetooth_dir);
	remove_proc_entry("bluetooth", 0);

	mutex_destroy(&bluesleep_mutex);
}
/**
 * Write the <code>BT_WAKE</code> GPIO pin value via the proc interface.
 * @param file Not used.
 * @param buffer The buffer to read from.
 * @param count The number of bytes to be written.
 * @param data Not used.
 * @return On success, the number of bytes written. On error, -1, and
 * <code>errno</code> is set appropriately.
 */
static int bluepower_write_proc_btwake(struct file *file, const char *buffer,
					unsigned long count, void *data)
{
	char *buf;

	if (count < 1)
		return -EINVAL;

	buf = kmalloc(count, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

	if (copy_from_user(buf, buffer, count)) {
		kfree(buf);
		return -EFAULT;
	}
	if (buf[0] == '0') {
		if (bsi->has_ext_wake == 1) {
			int ret;
			ret = ice_gpiox_set(bsi->ext_wake, 0);
			if (ret)
				BT_ERR("(bluepower_write_proc_btwake) failed to set ext_wake 0.");
		}
		clear_bit(BT_EXT_WAKE, &flags);
	} else if (buf[0] == '1') {
		if (bsi->has_ext_wake == 1) {
			int ret;
			ret = ice_gpiox_set(bsi->ext_wake, 1);
			if (ret)
				BT_ERR("(bluepower_write_proc_btwake) failed to set ext_wake 1.");
		}
		set_bit(BT_EXT_WAKE, &flags);
	} else {
		kfree(buf);
		return -EINVAL;
	}

	kfree(buf);
	return count;
}
static int brcm_wlan_power(int onoff)
{
	printk(KERN_INFO"------------------------------------------------");
	printk(KERN_INFO"------------------------------------------------\n");
	printk(KERN_INFO"%s Enter: power %s\n", __func__, onoff ? "on" : "off");

	if (onoff) {
		/*
		if (gpio_request(GPIO_WL_REG_ON, "WL_REG_ON"))
		{
			printk("Failed to request for WL_REG_ON\n");
		}
		*/
#if defined(CONFIG_SEC_H_PROJECT) || defined(CONFIG_SEC_MONTBLANC_PROJECT)\
	|| defined(CONFIG_SEC_VIENNA_PROJECT) || defined(CONFIG_MACH_KS01SKT)\
	|| defined(CONFIG_TIZEN_R_PROJECT) || defined(CONFIG_MACH_B3)
		printk(KERN_INFO"WL_REG_ON on-step : [%d]\n" , gpio_get_value(GPIO_WL_REG_ON));
		if (gpio_direction_output(GPIO_WL_REG_ON, 1)) {
			printk(KERN_ERR "%s: check WL_REG_ON pin for H\n", __func__);
#else
		if (ice_gpiox_set(FPGA_GPIO_WLAN_EN, 1)) {		// yhcha-patch
#endif /* defined CONFIG_SEC_H_PROJECT */
			printk(KERN_ERR "%s: WL_REG_ON  failed to pull up\n",
				__func__);
			return -EIO;
		}

#if defined(CONFIG_SEC_H_PROJECT) || defined(CONFIG_SEC_MONTBLANC_PROJECT)\
	|| defined(CONFIG_SEC_VIENNA_PROJECT) || defined(CONFIG_MACH_KS01SKT)\
	|| defined(CONFIG_TIZEN_R_PROJECT) || defined(CONFIG_MACH_B3)
		if(gpio_get_value(GPIO_WL_REG_ON)){
			printk(KERN_INFO"WL_REG_ON on-step-2 : [%d]\n" , gpio_get_value(GPIO_WL_REG_ON));
			printk("[%s] gpio ok!!!\n",__func__);
		}
		else
		{
			printk("[%s] gpio value is 0. We need reinit.\n",__func__);
			if (gpio_tlmm_config(config_gpio_wl_reg_on[0], GPIO_CFG_ENABLE))
				printk(KERN_ERR "%s: Failed to configure GPIO"
						" - WL_REG_ON\n", __func__);

			if (gpio_direction_output(GPIO_WL_REG_ON, 1))
				printk(KERN_ERR "%s: WL_REG_ON  "
						"failed to pull down\n", __func__);
		}
#endif /* defined CONFIG_SEC_H_PROJECT */

#if defined(CONFIG_BCM4339) || defined(CONFIG_BCM4335) || defined(CONFIG_BCM4354) || defined(CONFIG_BCM4334)
	/* Power on/off SDIO host */
	sdio_ctrl_power((struct mmc_host *)wifi_mmc_host, onoff);
#endif /* CONFIG_BCM4339 || CONFIG_BCM4335  || CONFIG_BCM4354 */
	} else {
#if defined(CONFIG_BCM4339) || defined(CONFIG_BCM4335) || defined(CONFIG_BCM4354) || defined(CONFIG_BCM4334)
	/* Power on/off SDIO host */
	sdio_ctrl_power((struct mmc_host *)wifi_mmc_host, onoff);
#endif /* CONFIG_BCM4339 || CONFIG_BCM4335  || CONFIG_BCM4354 */
		/*
		if (gpio_request(GPIO_WL_REG_ON, "WL_REG_ON"))
		{
			printk("Failed to request for WL_REG_ON\n");
		}
		*/
#if defined(CONFIG_SEC_H_PROJECT) || defined(CONFIG_SEC_MONTBLANC_PROJECT)\
	|| defined(CONFIG_SEC_VIENNA_PROJECT) || defined(CONFIG_MACH_KS01SKT)\
	|| defined(CONFIG_TIZEN_R_PROJECT) || defined(CONFIG_MACH_B3)
		if (gpio_direction_output(GPIO_WL_REG_ON, 0)) {
#else
		if (ice_gpiox_set(FPGA_GPIO_WLAN_EN, 0)) {		// yhcha-patch
#endif /* defined CONFIG_SEC_H_PROJECT */
			printk(KERN_ERR "%s: WL_REG_ON  failed to pull down\n",
				__func__);
			return -EIO;
		}
	}
	return 0;
}

static int brcm_wlan_reset(int onoff)
{
  /*
	gpio_set_value(GPIO_WLAN_ENABLE,
			onoff ? GPIO_LEVEL_HIGH : GPIO_LEVEL_LOW);
  */
	return 0;
}

int brcm_wifi_status_register(
	void (*callback)(int card_present, void *dev_id),
	void *dev_id, void *mmc_host)
{
	if (wifi_status_cb)
		return -EAGAIN;
	wifi_status_cb = callback;
	wifi_status_cb_devid = dev_id;
	wifi_mmc_host = mmc_host;
	printk(KERN_ERR "%s: callback is %p, devid is %p\n",
		__func__, wifi_status_cb, dev_id);
	return 0;
}

unsigned int brcm_wifi_status(struct device *dev)
{
	printk("%s:%d status %d\n",__func__,__LINE__,brcm_wifi_cd);
	return brcm_wifi_cd;
}

static int brcm_wlan_set_carddetect(int val)
{
	pr_warning("%s: wifi_status_cb : %p, devid : %p, val : %d\n",
		__func__, wifi_status_cb, wifi_status_cb_devid, val);
	brcm_wifi_cd = val;
	if (wifi_status_cb)
		wifi_status_cb(val, wifi_status_cb_devid);
	else
		pr_warning("%s: Nobody to notify\n", __func__);

	/* msleep(200); wait for carddetect */

	return 0;
}
/**
 * @brief@  main sleep work handling function which update the flags
 * and activate and deactivate UART ,check FIFO.
 */
static void bluesleep_sleep_work(struct work_struct *work)
{
    if (mutex_is_locked(&bluesleep_mutex))
        BT_DBG("Wait for mutex unlock in bluesleep_sleep_work");

    mutex_lock(&bluesleep_mutex);

    if (bluesleep_can_sleep()) {
        /* already asleep, this is an error case */
        if (test_bit(BT_ASLEEP, &flags)) {
            BT_DBG("already asleep");
            mutex_unlock(&bluesleep_mutex);
            return;
        }

        if (msm_hs_tx_empty(bsi->uport)) {
            if (test_bit(BT_TXDATA, &flags)) {
                BT_DBG("TXDATA remained. Wait until timer expires.");

                mod_timer(&tx_timer,
                          jiffies + msecs_to_jiffies(TX_TIMER_INTERVAL * 1000));
                mutex_unlock(&bluesleep_mutex);
                return;
            }

            BT_DBG("going to sleep...");

            set_bit(BT_ASLEEP, &flags);
            /*Deactivating UART */
            hsuart_power(0);

            /* Moved from Timer expired */
            if (bsi->has_ext_wake == 1) {
                int ret;
                ret = ice_gpiox_set(bsi->ext_wake, 0);
                if (ret)
                    BT_ERR("(bluesleep_sleep_work) failed to set ext_wake.");
            }
            clear_bit(BT_EXT_WAKE, &flags);

            /*Deactivating UART */
            /* UART clk is not turned off immediately. Release
            * wakelock after 500 ms.
            */
            wake_lock_timeout(&bsi->wake_lock, msecs_to_jiffies(125));
        } else {
            BT_DBG("host can enter sleep but some tx remained.");

            mod_timer(&tx_timer,
                      jiffies + msecs_to_jiffies(TX_TIMER_INTERVAL * 1000));
            mutex_unlock(&bluesleep_mutex);
            return;
        }
    } else if (!test_bit(BT_EXT_WAKE, &flags)
            && !test_bit(BT_ASLEEP, &flags)) {
        BT_DBG("host_wake high and BT_EXT_WAKE & BT_ASLEEP already freed.");
        mod_timer(&tx_timer,
                  jiffies + msecs_to_jiffies(TX_TIMER_INTERVAL * 1000));
        if (bsi->has_ext_wake == 1) {
            int ret;
            ret = ice_gpiox_set(bsi->ext_wake, 1);
            if (ret)
                BT_ERR("(bluesleep_sleep_work) failed to set ext_wake 1.");
        }
        set_bit(BT_EXT_WAKE, &flags);
    } else {
        bluesleep_sleep_wakeup();
    }
    mutex_unlock(&bluesleep_mutex);
}
示例#11
0
/******************************************************************************
 *    function:   tuner_drv_ctl_power
 *    brief   :   power control of a driver
 *    date    :   2011.08.26
 *    author  :   M.Takahashi(*)
 *
 *    return  :    0                   normal exit
 *            :   -1                   error exit
 *    input   :   data                 setting data
 *    output  :   none
 ******************************************************************************/
int tuner_drv_ctl_power( int data )
{	
	int ret = 0;
	int result = 0;
	static struct regulator *tmm_vreg_l15;
	static struct regulator *tmm_vreg_l27;
	
	/* Get Power ON 1.8V Reulator */
	if ( NULL == tmm_vreg_l15 )
	{
		tmm_vreg_l15 = regulator_get ( NULL, "8921_l15" );
		if ( IS_ERR ( tmm_vreg_l15 )) 
		{
			ERROR_PRINT("could not get 8921_l15, rc = %ld",
						PTR_ERR(tmm_vreg_l15));

			tmm_vreg_l15 = NULL;
			return ret;
		}
		ret = regulator_set_voltage(tmm_vreg_l15, 1800000, 1800000 );
		if ( ret ) 
		{
			ERROR_PRINT("set voltage l15 failed, rc=%d", ret);
			tmm_vreg_l15 = NULL;
			return ret;
		}
	}
	
	/* Get Power ON 1.1V Reulator */
	if ( NULL == tmm_vreg_l27 )
	{
		tmm_vreg_l27 = regulator_get(NULL, "8921_l27");
		if ( IS_ERR ( tmm_vreg_l27 )) 
		{
			ERROR_PRINT("could not get 8921_l27, rc = %ld",
						PTR_ERR(tmm_vreg_l27));
			
			tmm_vreg_l27 = NULL;
			return ret;
		}
		ret = regulator_set_voltage(tmm_vreg_l27, 1100000, 1100000 );
		if ( ret ) 
		{
			ERROR_PRINT("set voltage l27 failed, rc=%d", ret);
			tmm_vreg_l27 = NULL;
			return ret;
		}
	}
	
	/* power on */
	if( data == TUNER_DRV_CTL_POWON )
	{
		DEBUG_PRINT("tuner_drv_ctl_power poweron");
		
		/* poweron gpio config setting */
		tuner_drv_gpio_config_poweron();
		
		/* P.ON = 1.8V */
		if ( NULL != tmm_vreg_l15 ) 
		{
			ret = regulator_enable(tmm_vreg_l15);
			if ( ret ) 
			{
				ERROR_PRINT("enable l15 failed, rc=%d", ret);
				return ret;
			}
		}
		
		/* P.ON = 1.1V */
		if ( NULL != tmm_vreg_l27 ) 
		{
			ret = regulator_enable(tmm_vreg_l27);
			if ( ret ) 
			{
				ERROR_PRINT("enable l27 failed, rc=%d", ret);
				return ret;
			}
		}
		
		/* TMM_PWR_EN high */
		ret = ice_gpiox_set(FPGA_GPIO_TMM_PWR_EN, 1);
		if (ret < 0)
		{
			ERROR_PRINT("FPGA_GPIO_TMM_PWR_EN high set error");
			return ret;
		}
		/* 15ms sleep */
		usleep_range(15000, 15000);
		
		/* TMM_RST high */
		ret = ice_gpiox_set(FPGA_GPIO_TMM_RST, 1);
		if (ret < 0)
		{
			ERROR_PRINT("FPGA_GPIO_TMM_RST high set error");
			return ret;
		}
		/* 2ms sleep */
		usleep_range(2000, 2000);
	}
	/* power off */
	else
	{
		DEBUG_PRINT("tuner_drv_ctl_power poweroff");
		
		/* poweroff gpio config setting */
		tuner_drv_gpio_config_poweroff();
		
		/* 1ms sleep */
		usleep_range(1000, 1000);
		
		/* TMM_RST low */
		ret = ice_gpiox_set(FPGA_GPIO_TMM_RST, 0);
		if (ret < 0)
		{
			ERROR_PRINT("FPGA_GPIO_TMM_RST low set error");
			result = ret;
		}
		/* 2ms sleep */
		usleep_range(2000, 2000);
		
		/* TMM_PWR_EN low */
		ret = ice_gpiox_set(FPGA_GPIO_TMM_PWR_EN, 0);
		if (ret < 0)
		{
			ERROR_PRINT("FPGA_GPIO_TMM_PWR_EN low set error");
			result = ret;
		}
		
		/* P.OFF = 1.8V */
		if (regulator_is_enabled(tmm_vreg_l15))
		{
			ret = regulator_disable(tmm_vreg_l15);
			if ( ret ) 
			{
				ERROR_PRINT("disable l15 failed, rc=%d", ret);
				result = -1;
			}
		}
		
		/* P.OFF = 1.1V */
		if (regulator_is_enabled(tmm_vreg_l27))
		{
			ret = regulator_disable(tmm_vreg_l27);
			if ( ret ) 
			{
				ERROR_PRINT("disable l27 failed, rc=%d", ret);
				result = -1;
			}
		}
	}
	return ( result );
}
static int brcm_wlan_power(int onoff)
{
	printk(KERN_INFO"------------------------------------------------");
	printk(KERN_INFO"------------------------------------------------\n");
	printk(KERN_INFO"%s Enter: power %s\n", __func__, onoff ? "on" : "off");

	if (onoff) {
		/*
		if (gpio_request(GPIO_WL_REG_ON, "WL_REG_ON"))
		{
			printk("Failed to request for WL_REG_ON\n");
		}
		*/

#ifdef CONFIG_SEC_KS01_PROJECT
		if (ice_gpiox_set(FPGA_GPIO_WLAN_EN, 1)) {
			printk(KERN_ERR "%s: WL_REG_ON  failed to pull up\n", __func__);
				return -EIO;
		}
#else
		printk(KERN_INFO"WL_REG_ON on-step : [%d]\n" , gpio_get_value(GPIO_WL_REG_ON));
		if (gpio_direction_output(GPIO_WL_REG_ON, 1)) {
			printk(KERN_ERR "%s: check WL_REG_ON pin for H\n", __func__);
			printk(KERN_ERR "%s: WL_REG_ON  failed to pull up\n", __func__);
				return -EIO;
		}

		if(gpio_get_value(GPIO_WL_REG_ON)){
			printk(KERN_INFO"WL_REG_ON on-step-2 : [%d]\n" , gpio_get_value(GPIO_WL_REG_ON));
		}
		else
		{
			printk("[%s] gpio value is 0. We need reinit.\n",__func__);
#if !defined(CONFIG_SEC_K_PROJECT) && !defined(CONFIG_SEC_KACTIVE_PROJECT)
			if (gpio_tlmm_config(config_gpio_wl_reg_on[0], GPIO_CFG_ENABLE))
				printk(KERN_ERR "%s: Failed to configure GPIO"
						" - WL_REG_ON\n", __func__);
#endif /* not defined CONFIG_SEC_K_PROJECT and CONFIG_SEC_KACTIVE_PROJECT*/

			if (gpio_direction_output(GPIO_WL_REG_ON, 1))
				printk(KERN_ERR "%s: WL_REG_ON  "
						"failed to pull down\n", __func__);
		}
#endif /* defined CONFIG_SEC_KS01_PROJECT */
	} else {
/*
		if (gpio_request(GPIO_WL_REG_ON, "WL_REG_ON"))
		{
			printk("Failed to request for WL_REG_ON\n");
		}
*/

#ifdef CONFIG_SEC_KS01_PROJECT
		if (ice_gpiox_set(FPGA_GPIO_WLAN_EN, 0)) {
			printk(KERN_ERR "%s: WL_REG_ON  failed to pull down\n", __func__);
				return -EIO;
		}
#else
		printk(KERN_INFO"WL_REG_ON off-step : [%d]\n" , gpio_get_value(GPIO_WL_REG_ON));

		if (gpio_direction_output(GPIO_WL_REG_ON, 0)) {
			printk(KERN_ERR "%s: WL_REG_ON  failed to pull down\n", __func__);
				return -EIO;
		}

		printk(KERN_INFO"WL_REG_ON off-step-2 : [%d]\n" , gpio_get_value(GPIO_WL_REG_ON));
#endif
	}
	return 0;
}
static int brcm_wlan_power(int onoff)
#endif
{
	int ret = 0;
	printk(KERN_INFO"------------------------------------------------");
	printk(KERN_INFO"------------------------------------------------\n");
	printk(KERN_INFO"%s Enter: power %s\n", __func__, onoff ? "on" : "off");

	if (onoff) {
#if defined(ENABLE_4335BT_WAR) || defined(ENABLE_4339BT_WAR)
		if(b0rev == true && gpio_get_value(FPGA_GPIO_BT_EN) == 0)
		{
			bt_off = 1;
			gpio_direction_output(FPGA_GPIO_BT_EN, 1);
			printk("[brcm_wlan_power] Bluetooth Power On.\n");
			msleep(50);
		}
		else {
			bt_off = 0;
		}
#endif

#if defined(CONFIG_SEC_KS01_PROJECT) || defined(CONFIG_SEC_JACTIVE_PROJECT)
		if (ice_gpiox_set(FPGA_GPIO_WLAN_EN, 1)) {
			printk(KERN_ERR "%s: WL_REG_ON  failed to pull up\n", __func__);
			ret =  -EIO;
		}
#else
		printk(KERN_INFO"WL_REG_ON on-step : [%d]\n" , gpio_get_value(GPIO_WL_REG_ON));
		if (gpio_direction_output(GPIO_WL_REG_ON, 1)) {
			printk(KERN_ERR "%s: check WL_REG_ON pin for H\n", __func__);
			printk(KERN_ERR "%s: WL_REG_ON  failed to pull up\n", __func__);
			ret =  -EIO;
		}

		if(gpio_get_value(GPIO_WL_REG_ON)){
			printk(KERN_INFO"WL_REG_ON on-step-2 : [%d]\n" , gpio_get_value(GPIO_WL_REG_ON));
		}
		else
		{
			printk("[%s] gpio value is 0. We need reinit.\n",__func__);
#if !defined(CONFIG_SEC_K_PROJECT) && !defined(CONFIG_SEC_KACTIVE_PROJECT) && !defined(CONFIG_SEC_PATEK_PROJECT)
			if (gpio_tlmm_config(config_gpio_wl_reg_on[0], GPIO_CFG_ENABLE))
				printk(KERN_ERR "%s: Failed to configure GPIO"
						" - WL_REG_ON\n", __func__);
#endif /* not defined CONFIG_SEC_K_PROJECT and CONFIG_SEC_KACTIVE_PROJECT*/

			if (gpio_direction_output(GPIO_WL_REG_ON, 1))
				printk(KERN_ERR "%s: WL_REG_ON  "
						"failed to pull down\n", __func__);
		}
#endif /* defined CONFIG_SEC_KS01_PROJECT */

#if defined(CONFIG_BCM4339) || defined(CONFIG_BCM4335) || defined(CONFIG_BCM4354)
	/* Power on/off SDIO host */
	sdio_ctrl_power((struct mmc_host *)wifi_mmc_host, onoff);
#endif /* CONFIG_BCM4339 || CONFIG_BCM4335  || CONFIG_BCM4354 */
	} else {
#if defined(CONFIG_BCM4339) || defined(CONFIG_BCM4335) || defined(CONFIG_BCM4354)
	/* Power on/off SDIO host */
	sdio_ctrl_power((struct mmc_host *)wifi_mmc_host, onoff);
#endif /* CONFIG_BCM4339 || CONFIG_BCM4335  || CONFIG_BCM4354 */
/*
		if (gpio_request(GPIO_WL_REG_ON, "WL_REG_ON"))
		{
			printk("Failed to request for WL_REG_ON\n");
		}
*/

#if defined(CONFIG_SEC_KS01_PROJECT) || defined(CONFIG_SEC_JACTIVE_PROJECT)
		if (ice_gpiox_set(FPGA_GPIO_WLAN_EN, 0)) {
			printk(KERN_ERR "%s: WL_REG_ON  failed to pull down\n", __func__);
			ret = -EIO;
		}
#else
		printk(KERN_INFO"WL_REG_ON off-step : [%d]\n" , gpio_get_value(GPIO_WL_REG_ON));

		if (gpio_direction_output(GPIO_WL_REG_ON, 0)) {
			printk(KERN_ERR "%s: WL_REG_ON  failed to pull down\n", __func__);
			ret = -EIO;
		}

		printk(KERN_INFO"WL_REG_ON off-step-2 : [%d]\n" , gpio_get_value(GPIO_WL_REG_ON));
#endif
	}
#if defined(ENABLE_4335BT_WAR) || defined(ENABLE_4339BT_WAR)
	if(onoff && (bt_off == 1) && (bt_is_running == 0)) {
		msleep(100);
		gpio_direction_output(FPGA_GPIO_BT_EN, 0);
		printk("[brcm_wlan_power] BT_REG_OFF.\n");
	}
#endif
	return ret;
}