22
22
#include <linux/power_supply.h>
23
23
#include <linux/notifier.h>
24
24
#include <linux/usb/otg.h>
25
- #include <linux/i2c/twl4030-madc .h>
25
+ #include <linux/iio/consumer .h>
26
26
27
27
#define TWL4030_BCIMDEN 0x00
28
28
#define TWL4030_BCIMDKEY 0x01
91
91
#define TWL4030_MSTATEC_COMPLETE1 0x0b
92
92
#define TWL4030_MSTATEC_COMPLETE4 0x0e
93
93
94
- #if IS_REACHABLE (CONFIG_TWL4030_MADC )
95
94
/*
96
95
* If AC (Accessory Charger) voltage exceeds 4.5V (MADC 11)
97
96
* then AC is available.
98
97
*/
99
- static inline int ac_available (void )
98
+ static inline int ac_available (struct iio_channel * channel_vac )
100
99
{
101
- return twl4030_get_madc_conversion (11 ) > 4500 ;
102
- }
103
- #else
104
- static inline int ac_available (void )
105
- {
106
- return 0 ;
100
+ int val , err ;
101
+
102
+ if (!channel_vac )
103
+ return 0 ;
104
+
105
+ err = iio_read_channel_processed (channel_vac , & val );
106
+ if (err < 0 )
107
+ return 0 ;
108
+ return val > 4500 ;
107
109
}
108
- #endif
110
+
109
111
static bool allow_usb ;
110
112
module_param (allow_usb , bool , 0644 );
111
113
MODULE_PARM_DESC (allow_usb , "Allow USB charge drawing default current" );
@@ -128,6 +130,7 @@ struct twl4030_bci {
128
130
*/
129
131
unsigned int ichg_eoc , ichg_lo , ichg_hi ;
130
132
unsigned int usb_cur , ac_cur ;
133
+ struct iio_channel * channel_vac ;
131
134
bool ac_is_active ;
132
135
int usb_mode , ac_mode ; /* charging mode requested */
133
136
#define CHARGE_OFF 0
@@ -278,7 +281,7 @@ static int twl4030_charger_update_current(struct twl4030_bci *bci)
278
281
* If AC (Accessory Charger) voltage exceeds 4.5V (MADC 11)
279
282
* and AC is enabled, set current for 'ac'
280
283
*/
281
- if (ac_available ()) {
284
+ if (ac_available (bci -> channel_vac )) {
282
285
cur = bci -> ac_cur ;
283
286
bci -> ac_is_active = true;
284
287
} else {
@@ -1048,6 +1051,12 @@ static int twl4030_bci_probe(struct platform_device *pdev)
1048
1051
return ret ;
1049
1052
}
1050
1053
1054
+ bci -> channel_vac = iio_channel_get (& pdev -> dev , "vac" );
1055
+ if (IS_ERR (bci -> channel_vac )) {
1056
+ bci -> channel_vac = NULL ;
1057
+ dev_warn (& pdev -> dev , "could not request vac iio channel" );
1058
+ }
1059
+
1051
1060
INIT_WORK (& bci -> work , twl4030_bci_usb_work );
1052
1061
INIT_DELAYED_WORK (& bci -> current_worker , twl4030_current_worker );
1053
1062
@@ -1069,7 +1078,7 @@ static int twl4030_bci_probe(struct platform_device *pdev)
1069
1078
TWL4030_INTERRUPTS_BCIIMR1A );
1070
1079
if (ret < 0 ) {
1071
1080
dev_err (& pdev -> dev , "failed to unmask interrupts: %d\n" , ret );
1072
- return ret ;
1081
+ goto fail ;
1073
1082
}
1074
1083
1075
1084
reg = ~(u32 )(TWL4030_VBATOV | TWL4030_VBUSOV | TWL4030_ACCHGOV );
@@ -1102,6 +1111,10 @@ static int twl4030_bci_probe(struct platform_device *pdev)
1102
1111
twl4030_charger_enable_backup (0 , 0 );
1103
1112
1104
1113
return 0 ;
1114
+ fail :
1115
+ iio_channel_release (bci -> channel_vac );
1116
+
1117
+ return ret ;
1105
1118
}
1106
1119
1107
1120
static int __exit twl4030_bci_remove (struct platform_device * pdev )
@@ -1112,6 +1125,8 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
1112
1125
twl4030_charger_enable_usb (bci , false);
1113
1126
twl4030_charger_enable_backup (0 , 0 );
1114
1127
1128
+ iio_channel_release (bci -> channel_vac );
1129
+
1115
1130
device_remove_file (& bci -> usb -> dev , & dev_attr_max_current );
1116
1131
device_remove_file (& bci -> usb -> dev , & dev_attr_mode );
1117
1132
device_remove_file (& bci -> ac -> dev , & dev_attr_max_current );
0 commit comments