Skip to content

Commit ae640fc

Browse files
macromorgansre
authored andcommitted
power: supply: axp20x_usb_power: Make VBUS and IIO config per device
Make reading of the vbus value and configuring of the iio channels device specific, to allow additional devices (such as the AXP717) to be supported by this driver. Signed-off-by: Chris Morgan <[email protected]> Acked-by: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent db97fec commit ae640fc

File tree

1 file changed

+54
-33
lines changed

1 file changed

+54
-33
lines changed

drivers/power/supply/axp20x_usb_power.c

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
*/
4646
#define DEBOUNCE_TIME msecs_to_jiffies(50)
4747

48+
struct axp20x_usb_power;
49+
4850
struct axp_data {
4951
const struct power_supply_desc *power_desc;
5052
const char * const *irq_names;
@@ -58,6 +60,10 @@ struct axp_data {
5860
struct reg_field usb_bc_det_fld;
5961
struct reg_field vbus_disable_bit;
6062
bool vbus_needs_polling: 1;
63+
void (*axp20x_read_vbus)(struct work_struct *work);
64+
int (*axp20x_cfg_iio_chan)(struct platform_device *pdev,
65+
struct axp20x_usb_power *power);
66+
int (*axp20x_cfg_adc_reg)(struct axp20x_usb_power *power);
6167
};
6268

6369
struct axp20x_usb_power {
@@ -385,6 +391,36 @@ static int axp20x_usb_power_prop_writeable(struct power_supply *psy,
385391
psp == POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT;
386392
}
387393

394+
static int axp20x_configure_iio_channels(struct platform_device *pdev,
395+
struct axp20x_usb_power *power)
396+
{
397+
power->vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v");
398+
if (IS_ERR(power->vbus_v)) {
399+
if (PTR_ERR(power->vbus_v) == -ENODEV)
400+
return -EPROBE_DEFER;
401+
return PTR_ERR(power->vbus_v);
402+
}
403+
404+
power->vbus_i = devm_iio_channel_get(&pdev->dev, "vbus_i");
405+
if (IS_ERR(power->vbus_i)) {
406+
if (PTR_ERR(power->vbus_i) == -ENODEV)
407+
return -EPROBE_DEFER;
408+
return PTR_ERR(power->vbus_i);
409+
}
410+
411+
return 0;
412+
}
413+
414+
static int axp20x_configure_adc_registers(struct axp20x_usb_power *power)
415+
{
416+
/* Enable vbus voltage and current measurement */
417+
return regmap_update_bits(power->regmap, AXP20X_ADC_EN1,
418+
AXP20X_ADC_EN1_VBUS_CURR |
419+
AXP20X_ADC_EN1_VBUS_VOLT,
420+
AXP20X_ADC_EN1_VBUS_CURR |
421+
AXP20X_ADC_EN1_VBUS_VOLT);
422+
}
423+
388424
static enum power_supply_property axp20x_usb_power_properties[] = {
389425
POWER_SUPPLY_PROP_HEALTH,
390426
POWER_SUPPLY_PROP_PRESENT,
@@ -505,6 +541,9 @@ static const struct axp_data axp192_data = {
505541
.curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1),
506542
.vbus_valid_bit = REG_FIELD(AXP192_USB_OTG_STATUS, 2, 2),
507543
.vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3),
544+
.axp20x_read_vbus = &axp20x_usb_power_poll_vbus,
545+
.axp20x_cfg_iio_chan = axp20x_configure_iio_channels,
546+
.axp20x_cfg_adc_reg = axp20x_configure_adc_registers,
508547
};
509548

510549
static const struct axp_data axp202_data = {
@@ -516,6 +555,9 @@ static const struct axp_data axp202_data = {
516555
.curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1),
517556
.vbus_valid_bit = REG_FIELD(AXP20X_USB_OTG_STATUS, 2, 2),
518557
.vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3),
558+
.axp20x_read_vbus = &axp20x_usb_power_poll_vbus,
559+
.axp20x_cfg_iio_chan = axp20x_configure_iio_channels,
560+
.axp20x_cfg_adc_reg = axp20x_configure_adc_registers,
519561
};
520562

521563
static const struct axp_data axp221_data = {
@@ -526,6 +568,9 @@ static const struct axp_data axp221_data = {
526568
.curr_lim_table_size = ARRAY_SIZE(axp221_usb_curr_lim_table),
527569
.curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1),
528570
.vbus_needs_polling = true,
571+
.axp20x_read_vbus = &axp20x_usb_power_poll_vbus,
572+
.axp20x_cfg_iio_chan = axp20x_configure_iio_channels,
573+
.axp20x_cfg_adc_reg = axp20x_configure_adc_registers,
529574
};
530575

531576
static const struct axp_data axp223_data = {
@@ -536,6 +581,9 @@ static const struct axp_data axp223_data = {
536581
.curr_lim_table_size = ARRAY_SIZE(axp20x_usb_curr_lim_table),
537582
.curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1),
538583
.vbus_needs_polling = true,
584+
.axp20x_read_vbus = &axp20x_usb_power_poll_vbus,
585+
.axp20x_cfg_iio_chan = axp20x_configure_iio_channels,
586+
.axp20x_cfg_adc_reg = axp20x_configure_adc_registers,
539587
};
540588

541589
static const struct axp_data axp813_data = {
@@ -549,6 +597,9 @@ static const struct axp_data axp813_data = {
549597
.usb_bc_det_fld = REG_FIELD(AXP288_BC_DET_STAT, 5, 7),
550598
.vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7),
551599
.vbus_needs_polling = true,
600+
.axp20x_read_vbus = &axp20x_usb_power_poll_vbus,
601+
.axp20x_cfg_iio_chan = axp20x_configure_iio_channels,
602+
.axp20x_cfg_adc_reg = axp20x_configure_adc_registers,
552603
};
553604

554605
#ifdef CONFIG_PM_SLEEP
@@ -590,36 +641,6 @@ static int axp20x_usb_power_resume(struct device *dev)
590641
static SIMPLE_DEV_PM_OPS(axp20x_usb_power_pm_ops, axp20x_usb_power_suspend,
591642
axp20x_usb_power_resume);
592643

593-
static int configure_iio_channels(struct platform_device *pdev,
594-
struct axp20x_usb_power *power)
595-
{
596-
power->vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v");
597-
if (IS_ERR(power->vbus_v)) {
598-
if (PTR_ERR(power->vbus_v) == -ENODEV)
599-
return -EPROBE_DEFER;
600-
return PTR_ERR(power->vbus_v);
601-
}
602-
603-
power->vbus_i = devm_iio_channel_get(&pdev->dev, "vbus_i");
604-
if (IS_ERR(power->vbus_i)) {
605-
if (PTR_ERR(power->vbus_i) == -ENODEV)
606-
return -EPROBE_DEFER;
607-
return PTR_ERR(power->vbus_i);
608-
}
609-
610-
return 0;
611-
}
612-
613-
static int configure_adc_registers(struct axp20x_usb_power *power)
614-
{
615-
/* Enable vbus voltage and current measurement */
616-
return regmap_update_bits(power->regmap, AXP20X_ADC_EN1,
617-
AXP20X_ADC_EN1_VBUS_CURR |
618-
AXP20X_ADC_EN1_VBUS_VOLT,
619-
AXP20X_ADC_EN1_VBUS_CURR |
620-
AXP20X_ADC_EN1_VBUS_VOLT);
621-
}
622-
623644
static int axp20x_regmap_field_alloc_optional(struct device *dev,
624645
struct regmap *regmap,
625646
struct reg_field fdesc,
@@ -707,7 +728,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
707728
return ret;
708729

709730
ret = devm_delayed_work_autocancel(&pdev->dev, &power->vbus_detect,
710-
axp20x_usb_power_poll_vbus);
731+
axp_data->axp20x_read_vbus);
711732
if (ret)
712733
return ret;
713734

@@ -718,9 +739,9 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
718739
return ret;
719740

720741
if (IS_ENABLED(CONFIG_AXP20X_ADC))
721-
ret = configure_iio_channels(pdev, power);
742+
ret = axp_data->axp20x_cfg_iio_chan(pdev, power);
722743
else
723-
ret = configure_adc_registers(power);
744+
ret = axp_data->axp20x_cfg_adc_reg(power);
724745

725746
if (ret)
726747
return ret;

0 commit comments

Comments
 (0)