Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

power: supply: bq25890: Add support for registering the Vbus boost converter as a regulator

The bq25890_charger code supports enabling/disabling the boost converter
based on usb-phy notifications. But the usb-phy framework is not used on
all boards/platforms. At support for registering the Vbus boost converter
as a standard regulator when there is no usb-phy on the board.

Also add support for providing regulator_init_data through platform_data
for use on boards where device-tree is not used and the platform code must
thus provide the regulator_init_data.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Hans de Goede and committed by
Sebastian Reichel
79d35365 5575802d

+95
+80
drivers/power/supply/bq25890_charger.c
··· 8 8 #include <linux/module.h> 9 9 #include <linux/i2c.h> 10 10 #include <linux/power_supply.h> 11 + #include <linux/power/bq25890_charger.h> 11 12 #include <linux/regmap.h> 13 + #include <linux/regulator/driver.h> 12 14 #include <linux/types.h> 13 15 #include <linux/gpio/consumer.h> 14 16 #include <linux/interrupt.h> ··· 878 876 return NOTIFY_OK; 879 877 } 880 878 879 + #ifdef CONFIG_REGULATOR 880 + static int bq25890_vbus_enable(struct regulator_dev *rdev) 881 + { 882 + struct bq25890_device *bq = rdev_get_drvdata(rdev); 883 + 884 + return bq25890_set_otg_cfg(bq, 1); 885 + } 886 + 887 + static int bq25890_vbus_disable(struct regulator_dev *rdev) 888 + { 889 + struct bq25890_device *bq = rdev_get_drvdata(rdev); 890 + 891 + return bq25890_set_otg_cfg(bq, 0); 892 + } 893 + 894 + static int bq25890_vbus_is_enabled(struct regulator_dev *rdev) 895 + { 896 + struct bq25890_device *bq = rdev_get_drvdata(rdev); 897 + 898 + return bq25890_field_read(bq, F_OTG_CFG); 899 + } 900 + 901 + static const struct regulator_ops bq25890_vbus_ops = { 902 + .enable = bq25890_vbus_enable, 903 + .disable = bq25890_vbus_disable, 904 + .is_enabled = bq25890_vbus_is_enabled, 905 + }; 906 + 907 + static const struct regulator_desc bq25890_vbus_desc = { 908 + .name = "usb_otg_vbus", 909 + .of_match = "usb-otg-vbus", 910 + .type = REGULATOR_VOLTAGE, 911 + .owner = THIS_MODULE, 912 + .ops = &bq25890_vbus_ops, 913 + .fixed_uV = 5000000, 914 + .n_voltages = 1, 915 + }; 916 + #endif 917 + 881 918 static int bq25890_get_chip_version(struct bq25890_device *bq) 882 919 { 883 920 int id, rev; ··· 1116 1075 bq->usb_nb.notifier_call = bq25890_usb_notifier; 1117 1076 usb_register_notifier(bq->usb_phy, &bq->usb_nb); 1118 1077 } 1078 + #ifdef CONFIG_REGULATOR 1079 + else { 1080 + struct bq25890_platform_data *pdata = dev_get_platdata(dev); 1081 + struct regulator_config cfg = { }; 1082 + struct regulator_dev *reg; 1083 + 1084 + cfg.dev = dev; 1085 + cfg.driver_data = bq; 1086 + if (pdata) 1087 + cfg.init_data = pdata->regulator_init_data; 1088 + 1089 + reg = devm_regulator_register(dev, &bq25890_vbus_desc, &cfg); 1090 + if (IS_ERR(reg)) 1091 + return dev_err_probe(dev, PTR_ERR(reg), "registering regulator"); 1092 + } 1093 + #endif 1119 1094 1120 1095 ret = bq25890_power_supply_init(bq); 1121 1096 if (ret < 0) { ··· 1168 1111 } 1169 1112 1170 1113 return 0; 1114 + } 1115 + 1116 + static void bq25890_shutdown(struct i2c_client *client) 1117 + { 1118 + struct bq25890_device *bq = i2c_get_clientdata(client); 1119 + 1120 + /* 1121 + * TODO this if + return should probably be removed, but that would 1122 + * introduce a function change for boards using the usb-phy framework. 1123 + * This needs to be tested on such a board before making this change. 1124 + */ 1125 + if (!IS_ERR_OR_NULL(bq->usb_phy)) 1126 + return; 1127 + 1128 + /* 1129 + * Turn off the 5v Boost regulator which outputs Vbus to the device's 1130 + * Micro-USB or Type-C USB port. Leaving this on drains power and 1131 + * this avoids the PMIC on some device-models seeing this as Vbus 1132 + * getting inserted after shutdown, causing the device to immediately 1133 + * power-up again. 1134 + */ 1135 + bq25890_set_otg_cfg(bq, 0); 1171 1136 } 1172 1137 1173 1138 #ifdef CONFIG_PM_SLEEP ··· 1271 1192 }, 1272 1193 .probe = bq25890_probe, 1273 1194 .remove = bq25890_remove, 1195 + .shutdown = bq25890_shutdown, 1274 1196 .id_table = bq25890_i2c_ids, 1275 1197 }; 1276 1198 module_i2c_driver(bq25890_driver);
+15
include/linux/power/bq25890_charger.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Platform data for the TI bq25890 battery charger driver. 4 + */ 5 + 6 + #ifndef _BQ25890_CHARGER_H_ 7 + #define _BQ25890_CHARGER_H_ 8 + 9 + struct regulator_init_data; 10 + 11 + struct bq25890_platform_data { 12 + const struct regulator_init_data *regulator_init_data; 13 + }; 14 + 15 + #endif