45
45
*/
46
46
#define DEBOUNCE_TIME msecs_to_jiffies(50)
47
47
48
+ struct axp20x_usb_power ;
49
+
48
50
struct axp_data {
49
51
const struct power_supply_desc * power_desc ;
50
52
const char * const * irq_names ;
@@ -58,6 +60,10 @@ struct axp_data {
58
60
struct reg_field usb_bc_det_fld ;
59
61
struct reg_field vbus_disable_bit ;
60
62
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 );
61
67
};
62
68
63
69
struct axp20x_usb_power {
@@ -385,6 +391,36 @@ static int axp20x_usb_power_prop_writeable(struct power_supply *psy,
385
391
psp == POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT ;
386
392
}
387
393
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
+
388
424
static enum power_supply_property axp20x_usb_power_properties [] = {
389
425
POWER_SUPPLY_PROP_HEALTH ,
390
426
POWER_SUPPLY_PROP_PRESENT ,
@@ -505,6 +541,9 @@ static const struct axp_data axp192_data = {
505
541
.curr_lim_fld = REG_FIELD (AXP20X_VBUS_IPSOUT_MGMT , 0 , 1 ),
506
542
.vbus_valid_bit = REG_FIELD (AXP192_USB_OTG_STATUS , 2 , 2 ),
507
543
.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 ,
508
547
};
509
548
510
549
static const struct axp_data axp202_data = {
@@ -516,6 +555,9 @@ static const struct axp_data axp202_data = {
516
555
.curr_lim_fld = REG_FIELD (AXP20X_VBUS_IPSOUT_MGMT , 0 , 1 ),
517
556
.vbus_valid_bit = REG_FIELD (AXP20X_USB_OTG_STATUS , 2 , 2 ),
518
557
.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 ,
519
561
};
520
562
521
563
static const struct axp_data axp221_data = {
@@ -526,6 +568,9 @@ static const struct axp_data axp221_data = {
526
568
.curr_lim_table_size = ARRAY_SIZE (axp221_usb_curr_lim_table ),
527
569
.curr_lim_fld = REG_FIELD (AXP20X_VBUS_IPSOUT_MGMT , 0 , 1 ),
528
570
.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 ,
529
574
};
530
575
531
576
static const struct axp_data axp223_data = {
@@ -536,6 +581,9 @@ static const struct axp_data axp223_data = {
536
581
.curr_lim_table_size = ARRAY_SIZE (axp20x_usb_curr_lim_table ),
537
582
.curr_lim_fld = REG_FIELD (AXP20X_VBUS_IPSOUT_MGMT , 0 , 1 ),
538
583
.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 ,
539
587
};
540
588
541
589
static const struct axp_data axp813_data = {
@@ -549,6 +597,9 @@ static const struct axp_data axp813_data = {
549
597
.usb_bc_det_fld = REG_FIELD (AXP288_BC_DET_STAT , 5 , 7 ),
550
598
.vbus_disable_bit = REG_FIELD (AXP20X_VBUS_IPSOUT_MGMT , 7 , 7 ),
551
599
.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 ,
552
603
};
553
604
554
605
#ifdef CONFIG_PM_SLEEP
@@ -590,36 +641,6 @@ static int axp20x_usb_power_resume(struct device *dev)
590
641
static SIMPLE_DEV_PM_OPS (axp20x_usb_power_pm_ops , axp20x_usb_power_suspend ,
591
642
axp20x_usb_power_resume ) ;
592
643
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
-
623
644
static int axp20x_regmap_field_alloc_optional (struct device * dev ,
624
645
struct regmap * regmap ,
625
646
struct reg_field fdesc ,
@@ -707,7 +728,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
707
728
return ret ;
708
729
709
730
ret = devm_delayed_work_autocancel (& pdev -> dev , & power -> vbus_detect ,
710
- axp20x_usb_power_poll_vbus );
731
+ axp_data -> axp20x_read_vbus );
711
732
if (ret )
712
733
return ret ;
713
734
@@ -718,9 +739,9 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
718
739
return ret ;
719
740
720
741
if (IS_ENABLED (CONFIG_AXP20X_ADC ))
721
- ret = configure_iio_channels (pdev , power );
742
+ ret = axp_data -> axp20x_cfg_iio_chan (pdev , power );
722
743
else
723
- ret = configure_adc_registers (power );
744
+ ret = axp_data -> axp20x_cfg_adc_reg (power );
724
745
725
746
if (ret )
726
747
return ret ;
0 commit comments