Skip to content

Commit 66b6bef

Browse files
jwrdegoedesre
authored andcommitted
power: supply: bq24190_charger: Export 5V boost converter as regulator
Register the 5V boost converter as a regulator named "usb_otg_vbus". This commit also adds support for bq24190_platform_data, through which non device-tree platforms can pass the regulator_init_data (containing mappings for the consumer amongst other things). Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
1 parent 14e1a13 commit 66b6bef

2 files changed

Lines changed: 130 additions & 0 deletions

File tree

‎drivers/power/supply/bq24190_charger.c‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <linux/of_device.h>
1717
#include <linux/pm_runtime.h>
1818
#include <linux/power_supply.h>
19+
#include <linux/power/bq24190_charger.h>
20+
#include <linux/regulator/driver.h>
21+
#include <linux/regulator/machine.h>
1922
#include <linux/workqueue.h>
2023
#include <linux/gpio.h>
2124
#include <linux/i2c.h>
@@ -513,6 +516,111 @@ static int bq24190_sysfs_create_group(struct bq24190_dev_info *bdi)
513516
static inline void bq24190_sysfs_remove_group(struct bq24190_dev_info *bdi) {}
514517
#endif
515518

519+
#ifdef CONFIG_REGULATOR
520+
static int bq24190_set_charge_mode(struct regulator_dev *dev, u8 val)
521+
{
522+
struct bq24190_dev_info *bdi = rdev_get_drvdata(dev);
523+
int ret;
524+
525+
ret = pm_runtime_get_sync(bdi->dev);
526+
if (ret < 0) {
527+
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret);
528+
pm_runtime_put_noidle(bdi->dev);
529+
return ret;
530+
}
531+
532+
ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
533+
BQ24190_REG_POC_CHG_CONFIG_MASK,
534+
BQ24190_REG_POC_CHG_CONFIG_SHIFT, val);
535+
536+
pm_runtime_mark_last_busy(bdi->dev);
537+
pm_runtime_put_autosuspend(bdi->dev);
538+
539+
return ret;
540+
}
541+
542+
static int bq24190_vbus_enable(struct regulator_dev *dev)
543+
{
544+
return bq24190_set_charge_mode(dev, BQ24190_REG_POC_CHG_CONFIG_OTG);
545+
}
546+
547+
static int bq24190_vbus_disable(struct regulator_dev *dev)
548+
{
549+
return bq24190_set_charge_mode(dev, BQ24190_REG_POC_CHG_CONFIG_CHARGE);
550+
}
551+
552+
static int bq24190_vbus_is_enabled(struct regulator_dev *dev)
553+
{
554+
struct bq24190_dev_info *bdi = rdev_get_drvdata(dev);
555+
int ret;
556+
u8 val;
557+
558+
ret = pm_runtime_get_sync(bdi->dev);
559+
if (ret < 0) {
560+
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret);
561+
pm_runtime_put_noidle(bdi->dev);
562+
return ret;
563+
}
564+
565+
ret = bq24190_read_mask(bdi, BQ24190_REG_POC,
566+
BQ24190_REG_POC_CHG_CONFIG_MASK,
567+
BQ24190_REG_POC_CHG_CONFIG_SHIFT, &val);
568+
569+
pm_runtime_mark_last_busy(bdi->dev);
570+
pm_runtime_put_autosuspend(bdi->dev);
571+
572+
return ret ? ret : val == BQ24190_REG_POC_CHG_CONFIG_OTG;
573+
}
574+
575+
static const struct regulator_ops bq24190_vbus_ops = {
576+
.enable = bq24190_vbus_enable,
577+
.disable = bq24190_vbus_disable,
578+
.is_enabled = bq24190_vbus_is_enabled,
579+
};
580+
581+
static const struct regulator_desc bq24190_vbus_desc = {
582+
.name = "usb_otg_vbus",
583+
.type = REGULATOR_VOLTAGE,
584+
.owner = THIS_MODULE,
585+
.ops = &bq24190_vbus_ops,
586+
.fixed_uV = 5000000,
587+
.n_voltages = 1,
588+
};
589+
590+
static const struct regulator_init_data bq24190_vbus_init_data = {
591+
.constraints = {
592+
.valid_ops_mask = REGULATOR_CHANGE_STATUS,
593+
},
594+
};
595+
596+
static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi)
597+
{
598+
struct bq24190_platform_data *pdata = bdi->dev->platform_data;
599+
struct regulator_config cfg = { };
600+
struct regulator_dev *reg;
601+
int ret = 0;
602+
603+
cfg.dev = bdi->dev;
604+
if (pdata && pdata->regulator_init_data)
605+
cfg.init_data = pdata->regulator_init_data;
606+
else
607+
cfg.init_data = &bq24190_vbus_init_data;
608+
cfg.driver_data = bdi;
609+
reg = devm_regulator_register(bdi->dev, &bq24190_vbus_desc, &cfg);
610+
if (IS_ERR(reg)) {
611+
ret = PTR_ERR(reg);
612+
dev_err(bdi->dev, "Can't register regulator: %d\n", ret);
613+
}
614+
615+
return ret;
616+
}
617+
#else
618+
static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi)
619+
{
620+
return 0;
621+
}
622+
#endif
623+
516624
static int bq24190_set_config(struct bq24190_dev_info *bdi)
517625
{
518626
int ret;
@@ -1740,6 +1848,10 @@ static int bq24190_probe(struct i2c_client *client,
17401848
goto out_sysfs;
17411849
}
17421850

1851+
ret = bq24190_register_vbus_regulator(bdi);
1852+
if (ret < 0)
1853+
goto out_sysfs;
1854+
17431855
if (bdi->extcon) {
17441856
INIT_DELAYED_WORK(&bdi->extcon_work, bq24190_extcon_work);
17451857
bdi->extcon_nb.notifier_call = bq24190_extcon_event;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Platform data for the TI bq24190 battery charger driver.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*/
8+
9+
#ifndef _BQ24190_CHARGER_H_
10+
#define _BQ24190_CHARGER_H_
11+
12+
#include <linux/regulator/machine.h>
13+
14+
struct bq24190_platform_data {
15+
const struct regulator_init_data *regulator_init_data;
16+
};
17+
18+
#endif

0 commit comments

Comments
 (0)