bq24022: Add support for bq2407x family
v2 cover bq24022: Add support for bq2407x family
The bq2407x family is quite similar to the bq24022 charger. As suggested by MyungJoo Ham it should be possible to implement support for it inside the bq24022 driver instead of adding a new one.
The first three patches fix small things Mark Brown identified in my submission of a separate bq2407x driver that also exist in the bq24022 while the fourth implements the bq2407x specifics.
This second version fixes some glitches found by Mark Brown and introduces the new second patch fixing the other dev_dbg invocations where dev_err would be appropriate.
Heiko Stuebner (4):
bq24022: Evaluate returns of gpio_direction_output-calls
bq24022: Use dev_err instead of dev_dbg for error messages to make
them visible
bq24022: Keep track of gpio states
bq24022: Add support for the bq2407x family
drivers/regulator/Kconfig | 7 +- drivers/regulator/bq24022.c | 144 ++++++++++++++++++++++++++++++------- include/linux/regulator/bq24022.h | 7 ++ 3 files changed, 128 insertions(+), 30 deletions(-)
Signature · 1 line
1.7.2.3
PATCH v2 1/4 bq24022: Evaluate returns of gpio_direction_output-calls
It wasn't done before.
---
Changes since v1: use dev_err instead of dev_dbg
drivers/regulator/bq24022.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/regulator/bq24022.c +10 -0
@@ -104,7 +104,17 @@ static int __init bq24022_probe(struct platform_device *pdev) goto err_iset2; } ret =gpio_direction_output (pdata->gpio_iset2,0 ); +if (ret) { +dev_err (&pdev->dev,"couldn't set ISET2 GPIO: %d\n" , + pdata->gpio_iset2); + goto err_reg; + } ret =gpio_direction_output (pdata->gpio_nce,1 ); +if (ret) { +dev_err (&pdev->dev,"couldn't set nCE GPIO: %d\n" , + pdata->gpio_nce); + goto err_reg; + } bq24022 =regulator_register (&bq24022_desc, &pdev->dev, pdata->init_data, pdata);
Signature · 1 line
1.7.2.3
Re: [PATCH v2 1/4] bq24022: Evaluate returns of gpio_direction_output-calls
Quoted 3 lines · Heiko Stübner
It wasn't done before.
Signed-off-by Heiko Stuebner <[email protected]>
PATCH v2 2/4 bq24022: Use dev_err instead of dev_dbg for error messages
In reply to Heiko StübnerThis makes error messages visible to the user,
so he/she can eventually fix them.
--- drivers/regulator/bq24022.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/regulator/bq24022.c +3 -3
@@ -93,13 +93,13 @@ static int __init bq24022_probe(struct platform_device *pdev) ret =gpio_request (pdata->gpio_nce,"ncharge_en" );if (ret) { -dev_dbg (&pdev->dev,"couldn't request nCE GPIO: %d\n" , +dev_err (&pdev->dev,"couldn't request nCE GPIO: %d\n" , pdata->gpio_nce); goto err_ce; } ret =gpio_request (pdata->gpio_iset2,"charge_mode" );if (ret) { -dev_dbg (&pdev->dev,"couldn't request ISET2 GPIO: %d\n" , +dev_err (&pdev->dev,"couldn't request ISET2 GPIO: %d\n" , pdata->gpio_iset2); goto err_iset2; }
@@ -119,7 +119,7 @@ static int __init bq24022_probe(struct platform_device *pdev) bq24022 =regulator_register (&bq24022_desc, &pdev->dev, pdata->init_data, pdata);if (IS_ERR (bq24022)) { -dev_dbg (&pdev->dev,"couldn't register regulator\n" ); +dev_err (&pdev->dev,"couldn't register regulator\n" ); ret =PTR_ERR (bq24022); goto err_reg; }
Signature · 1 line
1.7.2.3
Re: [PATCH 2/4] bq24022: Use dev_err instead of dev_dbg for error messages
Quoted 4 lines · Heiko Stübner
This makes error messages visible to the user,
so he/she can eventually fix them.Signed-off-by Heiko Stuebner <[email protected]>
PATCH v2 3/4 bq24022: Keep track of gpio states
In reply to Heiko Stübnergpio_get_value is not definied for output-gpios and can therefore not be used for the is_enabled and get_current_limit methods of the bq24022.
This patch introduces a private struct to keep track of the values set.
--- drivers/regulator/bq24022.c | 67 +++++++++++++++++++++++++++++------------- 1 files changed, 46 insertions(+), 21 deletions(-)
drivers/regulator/bq24022.c +46 -21
@@ -15,56 +15,69 @@#include <linux/platform_device.h> #include <linux/err.h> #include <linux/module.h> +#include <linux/slab.h> #include <linux/gpio.h> #include <linux/regulator/bq24022.h> #include <linux/regulator/driver.h> +struct bq24022 { +struct regulator_dev *rdev; + +int gpio_nce; +int gpio_iset2; + +int state_nce; +int state_iset2; +};static int bq24022_set_current_limit (struct regulator_dev *rdev,int min_uA,int max_uA) { -struct bq24022_mach_info *pdata =rdev_get_drvdata (rdev); +struct bq24022 *bq =rdev_get_drvdata (rdev);dev_dbg (rdev_get_dev (rdev),"setting current limit to %s mA\n" , max_uA >=500000 ?"500" :"100" );/* REVISIT: maybe return error if min_uA != 0 ? */ -gpio_set_value (pdata->gpio_iset2, max_uA >=500000 ); + bq->state_iset2 = (max_uA >=500000 ); +gpio_set_value (bq->gpio_iset2, bq->state_iset2);return 0 ; }static int bq24022_get_current_limit (struct regulator_dev *rdev) { -struct bq24022_mach_info *pdata =rdev_get_drvdata (rdev); +struct bq24022 *bq =rdev_get_drvdata (rdev); -return gpio_get_value (pdata->gpio_iset2) ?500000 :100000 ; +return bq->state_iset2 ?500000 :100000 ; }static int bq24022_enable (struct regulator_dev *rdev) { -struct bq24022_mach_info *pdata =rdev_get_drvdata (rdev); +struct bq24022 *bq =rdev_get_drvdata (rdev);dev_dbg (rdev_get_dev (rdev),"enabling charger\n" ); -gpio_set_value (pdata->gpio_nce,0 ); +gpio_set_value (bq->gpio_nce,0 ); + bq->state_nce =0 ;return 0 ; }static int bq24022_disable (struct regulator_dev *rdev) { -struct bq24022_mach_info *pdata =rdev_get_drvdata (rdev); +struct bq24022 *bq =rdev_get_drvdata (rdev);dev_dbg (rdev_get_dev (rdev),"disabling charger\n" ); -gpio_set_value (pdata->gpio_nce,1 ); +gpio_set_value (bq->gpio_nce,1 ); + bq->state_nce =1 ;return 0 ; }static int bq24022_is_enabled (struct regulator_dev *rdev) { -struct bq24022_mach_info *pdata =rdev_get_drvdata (rdev); +struct bq24022 *bq =rdev_get_drvdata (rdev); -return !gpio_get_value (pdata->gpio_nce); +return !bq->state_nce; }static struct regulator_ops bq24022_ops = {
@@ -85,12 +98,18 @@ static struct regulator_desc bq24022_desc = {static int __init bq24022_probe (struct platform_device *pdev) {struct bq24022_mach_info *pdata = pdev->dev.platform_data; -struct regulator_dev *bq24022; +struct bq24022 *bq;int ret;if (!pdata || !pdata->gpio_nce || !pdata->gpio_iset2)return -EINVAL ; + bq =kzalloc (sizeof (struct bq24022 ),GFP_KERNEL ); +if (!bq) { +dev_err (&pdev->dev,"cannot allocate memory\n" ); +return -ENOMEM ; + } + ret =gpio_request (pdata->gpio_nce,"ncharge_en" );if (ret) { dev_err(&pdev->dev, "couldn't request nCE GPIO: %d\n",
@@ -103,27 +122,32 @@ static int __init bq24022_probe(struct platform_device *pdev) pdata->gpio_iset2); goto err_iset2; } + +/* set initial current to 100mA and disable regulator */ ret =gpio_direction_output (pdata->gpio_iset2,0 );if (ret) {dev_err (&pdev->dev,"couldn't set ISET2 GPIO: %d\n" , pdata->gpio_iset2); goto err_reg; } + bq->gpio_iset2 = pdata->gpio_iset2; ret =gpio_direction_output (pdata->gpio_nce,1 );if (ret) {dev_err (&pdev->dev,"couldn't set nCE GPIO: %d\n" , pdata->gpio_nce); goto err_reg; } + bq->gpio_nce = pdata->gpio_nce; + bq->state_nce =1 ; - bq24022 =regulator_register (&bq24022_desc, &pdev->dev, - pdata->init_data, pdata); -if (IS_ERR (bq24022)) { + bq->rdev =regulator_register (&bq24022_desc, &pdev->dev, + pdata->init_data, bq); +if (IS_ERR (bq->rdev)) {dev_err (&pdev->dev,"couldn't register regulator\n" ); - ret =PTR_ERR (bq24022); + ret =PTR_ERR (bq->rdev); goto err_reg; } -platform_set_drvdata (pdev, bq24022); +platform_set_drvdata (pdev, bq);dev_dbg (&pdev->dev,"registered regulator\n" );return 0 ;
@@ -137,12 +161,13 @@ err_ce: static int __devexit bq24022_remove(struct platform_device *pdev) { -struct bq24022_mach_info *pdata = pdev->dev.platform_data; -struct regulator_dev *bq24022 =platform_get_drvdata (pdev); +struct bq24022 *bq =platform_get_drvdata (pdev); -regulator_unregister (bq24022); -gpio_free (pdata->gpio_iset2); -gpio_free (pdata->gpio_nce); +regulator_unregister (bq->rdev); +gpio_free (bq->gpio_iset2); +gpio_free (bq->gpio_nce); + +kfree (bq);return 0 ; }
Signature · 1 line
1.7.2.3
PATCH v2 4/4 bq24022: Add support for the bq2407x family
In reply to Heiko StübnerThe bq2407x family of charger ICs simply supports another machine specific charging current above 500mA. To use this setting a second gpio pin is used while the rest of the pins stay the same.
---
Changes since v1: use dev_err instead of dev_dbg in fatal places
drivers/regulator/Kconfig | 7 ++-- drivers/regulator/bq24022.c | 65 ++++++++++++++++++++++++++++++++++--- include/linux/regulator/bq24022.h | 7 ++++ 3 files changed, 71 insertions(+), 8 deletions(-)
drivers/regulator/Kconfig +4 -3
@@ -67,10 +67,11 @@ config REGULATOR_USERSPACE_CONSUMER config REGULATOR_BQ24022 tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" help - This driver controls a TI bq24022 Charger attached via - GPIOs. The provided current regulator can enable/disable + This driver controls a TI bq24022 or bq2407x Charger attached + via GPIOs. The provided current regulator can enable/disable charging select between 100 mA and 500 mA charging current - limit. + limit. The bq2407x family also supports a machine specific + current limit above 500 mA. config REGULATOR_MAX1586 tristate "Maxim 1586/1587 voltage regulator"
drivers/regulator/bq24022.c +60 -5
120 lines not on this page · raw message
include/linux/regulator/bq24022.h +7 -0
@@ -16,9 +16,16 @@ struct regulator_init_data;* bq24022_mach_info - platform data for bq24022 * @gpio_nce: GPIO line connected to the nCE pin, used to enable / disable charging * @gpio_iset2: GPIO line connected to the ISET2 pin, used to limit charging current to 100 mA / 500 mA +* @gpio_2407x_en2: GPIO line connected to the en2 pin of the bq2407x family +* Modes of operation for bq2407x: +* EN2 = 0, ISET2 = 0: 100mA +* EN2 = 0, ISET2 = 1: 500mA +* EN2 = 1, ISET2 = 0: max_current +* EN2 = 1, ISET2 = 1: Standby (usb suspend) */ struct bq24022_mach_info {int gpio_nce;int gpio_iset2; +int gpio_2407x_en2;struct regulator_init_data *init_data; };
Signature · 1 line
1.7.2.3
Re: [PATCH v2 4/4] bq24022: Add support for the bq2407x family
Quoted 5 lines · Heiko Stübner
The bq2407x family of charger ICs simply supports another machine specific charging current above 500mA. To use this setting a second gpio pin is used while the rest of the pins stay the same.
Signed-off-by Heiko Stuebner <[email protected]>