rk3288:bq24296:add dc_det_pin func,support power on when no usb
author张晴 <zhangqing@rock-chips.com>
Sat, 22 Mar 2014 13:23:52 +0000 (21:23 +0800)
committer张晴 <zhangqing@rock-chips.com>
Sat, 22 Mar 2014 13:23:52 +0000 (21:23 +0800)
arch/arm/boot/dts/rk3288-tb.dts
drivers/power/bq24296_charger.c
include/linux/power/bq24296_charger.h

index e8f0d202aeb0ed8cf2e8f561c4b506e230cd641f..8921f2c827fc6faf1a79104681b70c42fdd5f299 100755 (executable)
        bq24296: bq24296@6b {
                compatible = "ti,bq24296";
                reg = <0x6b>;
-               gpios = <&gpio0 GPIO_A7 GPIO_ACTIVE_HIGH>;
+               gpios = <&gpio0 GPIO_A7 GPIO_ACTIVE_HIGH>,<&gpio0 GPIO_B0 GPIO_ACTIVE_HIGH>;
                bq24296,chg_current = <1000 500 3000>;
                status = "okay";
        };
index b544431bc698a5a07167ae64b64b344c0efd3351..b25919de39461211ac88ebe792967ab9976d500a 100755 (executable)
@@ -383,6 +383,24 @@ static void usb_detect_work_func(struct work_struct *work)
 
        DBG("%s: retval = %08x bq24296_chag_down = %d\n", __func__,retval,bq24296_chag_down);
        
+       #ifdef CONFIG_OF
+       if (gpio_is_valid(bq24296_pdata->dc_det_pin)){
+                       ret = gpio_request(bq24296_pdata->dc_det_pin, "bq24296_dc_det");
+                       if (ret < 0) {
+                               DBG("Failed to request gpio %d with ret:""%d\n",bq24296_pdata->dc_det_pin, ret);
+                       }
+                       gpio_direction_input(bq24296_pdata->dc_det_pin);
+                       ret = gpio_get_value(bq24296_pdata->dc_det_pin);
+                       if (ret ==0){
+                               bq24296_update_input_current_limit(bq24296_di->adp_input_current);
+                               bq24296_set_charge_current(bq24296_di->chg_current);
+                               bq24296_charge_mode_config(0);
+                       }
+                       gpio_free(bq24296_pdata->dc_det_pin);
+                       DBG("%s: bq24296_di->dc_det_pin=%x\n", __func__, ret);
+       }       
+       #endif
+       
        mutex_lock(&pi->var_lock);
        DBG("%s: dwc_otg_check_dpdm %d\n", __func__, dwc_otg_check_dpdm(0));
        switch(dwc_otg_check_dpdm(0))
@@ -457,6 +475,11 @@ static struct bq24296_board *bq24296_parse_dt(struct bq24296_device_info *di)
        if (!gpio_is_valid(pdata->chg_irq_pin)) {
                printk("invalid gpio: %d\n",  pdata->chg_irq_pin);
        }
+
+       pdata->dc_det_pin = of_get_named_gpio(bq24296_np,"gpios",1);
+       if (!gpio_is_valid(pdata->dc_det_pin)) {
+               printk("invalid gpio: %d\n",  pdata->dc_det_pin);
+       }
        
        return pdata;
 }
index 79fac3d8d2830a98874f082c8d8fb78c6d1d773e..12358ed048c3dd95e0b3837e6f8af841d23bd5ef 100755 (executable)
@@ -153,6 +153,7 @@ struct bq24296_platform_data {
 struct bq24296_board {
        unsigned int otg_usb_pin;
        unsigned int chg_irq_pin;
+       unsigned int dc_det_pin;
        unsigned int psel_pin;
        struct device_node *of_node;
        unsigned int chg_current[3];