Skip to content

Commit 2202e1f

Browse files
Marek Beliskosre
authored andcommitted
drivers: power: twl4030_charger: fix link problems when building as module
If either twl4030_charger or twl4030_madc is configured as MODULE, we get build (link) errors. To solve, the direct call of twl4030_get_madc_conversion() is replaced by a call to iio_read_channel_processed(). Signed-off-by: H. Nikolaus Schaller <[email protected]> Signed-off-by: Marek Belisko <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent af19161 commit 2202e1f

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

drivers/power/twl4030_charger.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <linux/power_supply.h>
2323
#include <linux/notifier.h>
2424
#include <linux/usb/otg.h>
25-
#include <linux/i2c/twl4030-madc.h>
25+
#include <linux/iio/consumer.h>
2626

2727
#define TWL4030_BCIMDEN 0x00
2828
#define TWL4030_BCIMDKEY 0x01
@@ -91,21 +91,23 @@
9191
#define TWL4030_MSTATEC_COMPLETE1 0x0b
9292
#define TWL4030_MSTATEC_COMPLETE4 0x0e
9393

94-
#if IS_REACHABLE(CONFIG_TWL4030_MADC)
9594
/*
9695
* If AC (Accessory Charger) voltage exceeds 4.5V (MADC 11)
9796
* then AC is available.
9897
*/
99-
static inline int ac_available(void)
98+
static inline int ac_available(struct iio_channel *channel_vac)
10099
{
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;
107109
}
108-
#endif
110+
109111
static bool allow_usb;
110112
module_param(allow_usb, bool, 0644);
111113
MODULE_PARM_DESC(allow_usb, "Allow USB charge drawing default current");
@@ -128,6 +130,7 @@ struct twl4030_bci {
128130
*/
129131
unsigned int ichg_eoc, ichg_lo, ichg_hi;
130132
unsigned int usb_cur, ac_cur;
133+
struct iio_channel *channel_vac;
131134
bool ac_is_active;
132135
int usb_mode, ac_mode; /* charging mode requested */
133136
#define CHARGE_OFF 0
@@ -278,7 +281,7 @@ static int twl4030_charger_update_current(struct twl4030_bci *bci)
278281
* If AC (Accessory Charger) voltage exceeds 4.5V (MADC 11)
279282
* and AC is enabled, set current for 'ac'
280283
*/
281-
if (ac_available()) {
284+
if (ac_available(bci->channel_vac)) {
282285
cur = bci->ac_cur;
283286
bci->ac_is_active = true;
284287
} else {
@@ -1048,6 +1051,12 @@ static int twl4030_bci_probe(struct platform_device *pdev)
10481051
return ret;
10491052
}
10501053

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+
10511060
INIT_WORK(&bci->work, twl4030_bci_usb_work);
10521061
INIT_DELAYED_WORK(&bci->current_worker, twl4030_current_worker);
10531062

@@ -1069,7 +1078,7 @@ static int twl4030_bci_probe(struct platform_device *pdev)
10691078
TWL4030_INTERRUPTS_BCIIMR1A);
10701079
if (ret < 0) {
10711080
dev_err(&pdev->dev, "failed to unmask interrupts: %d\n", ret);
1072-
return ret;
1081+
goto fail;
10731082
}
10741083

10751084
reg = ~(u32)(TWL4030_VBATOV | TWL4030_VBUSOV | TWL4030_ACCHGOV);
@@ -1102,6 +1111,10 @@ static int twl4030_bci_probe(struct platform_device *pdev)
11021111
twl4030_charger_enable_backup(0, 0);
11031112

11041113
return 0;
1114+
fail:
1115+
iio_channel_release(bci->channel_vac);
1116+
1117+
return ret;
11051118
}
11061119

11071120
static int __exit twl4030_bci_remove(struct platform_device *pdev)
@@ -1112,6 +1125,8 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
11121125
twl4030_charger_enable_usb(bci, false);
11131126
twl4030_charger_enable_backup(0, 0);
11141127

1128+
iio_channel_release(bci->channel_vac);
1129+
11151130
device_remove_file(&bci->usb->dev, &dev_attr_max_current);
11161131
device_remove_file(&bci->usb->dev, &dev_attr_mode);
11171132
device_remove_file(&bci->ac->dev, &dev_attr_max_current);

0 commit comments

Comments
 (0)