From 3e7a8bc24e8667938ef94d574eb2893f1219fdc3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=BC=A0=E6=99=B4?= Date: Sat, 22 Mar 2014 21:23:52 +0800 Subject: [PATCH] rk3288:bq24296:add dc_det_pin func,support power on when no usb --- arch/arm/boot/dts/rk3288-tb.dts | 2 +- drivers/power/bq24296_charger.c | 23 +++++++++++++++++++++++ include/linux/power/bq24296_charger.h | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/arch/arm/boot/dts/rk3288-tb.dts b/arch/arm/boot/dts/rk3288-tb.dts index e8f0d202aeb0..8921f2c827fc 100755 --- a/arch/arm/boot/dts/rk3288-tb.dts +++ b/arch/arm/boot/dts/rk3288-tb.dts @@ -221,7 +221,7 @@ 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"; }; diff --git a/drivers/power/bq24296_charger.c b/drivers/power/bq24296_charger.c index b544431bc698..b25919de3946 100755 --- a/drivers/power/bq24296_charger.c +++ b/drivers/power/bq24296_charger.c @@ -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; } diff --git a/include/linux/power/bq24296_charger.h b/include/linux/power/bq24296_charger.h index 79fac3d8d283..12358ed048c3 100755 --- a/include/linux/power/bq24296_charger.h +++ b/include/linux/power/bq24296_charger.h @@ -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]; -- 2.34.1