Skip to content

Commit ad8cccc

Browse files
committed
Fix Intel Dollar Cove TI battery driver 32-bit build error
The driver is doing a 64-bit divide, rather than using the proper helpers, causing link errors on i386 allyesconfig builds: x86_64-linux-ld: drivers/power/supply/intel_dc_ti_battery.o: in function `dc_ti_battery_get_voltage_and_current_now': intel_dc_ti_battery.c:(.text+0x5c): undefined reference to `__udivdi3' x86_64-linux-ld: intel_dc_ti_battery.c:(.text+0x96): undefined reference to `__udivdi3' and while fixing that, fix the double rounding: keep the timing difference in nanoseconds ('ktime'), and then just convert to usecs at the end. Not because the timing precision is likely to matter, but because doing it right also makes the code simpler. Reported-by: Guenter Roeck <linux@roeck-us.net> Cc: Hans de Goede <hansg@kernel.org> Cc: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3211573 commit ad8cccc

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

drivers/power/supply/intel_dc_ti_battery.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ struct dc_ti_battery_chip {
127127
static int dc_ti_battery_get_voltage_and_current_now(struct power_supply *psy, int *volt, int *curr)
128128
{
129129
struct dc_ti_battery_chip *chip = power_supply_get_drvdata(psy);
130-
s64 cnt_start_usec, now_usec, sleep_usec;
130+
ktime_t ktime;
131+
s64 sleep_usec;
131132
unsigned int reg_val;
132133
s32 acc, smpl_ctr;
133134
int ret;
@@ -141,16 +142,17 @@ static int dc_ti_battery_get_voltage_and_current_now(struct power_supply *psy, i
141142
if (ret)
142143
goto out_err;
143144

144-
cnt_start_usec = ktime_get_ns() / NSEC_PER_USEC;
145+
ktime = ktime_get();
145146

146147
/* Read Vbat, convert IIO mV to power-supply ųV */
147148
ret = iio_read_channel_processed_scale(chip->vbat_channel, volt, 1000);
148149
if (ret < 0)
149150
goto out_err;
150151

152+
ktime = ktime_sub(ktime_get(), ktime);
153+
151154
/* Sleep at least 3 sample-times + slack to get 3+ CC samples */
152-
now_usec = ktime_get_ns() / NSEC_PER_USEC;
153-
sleep_usec = 3 * SMPL_INTVL_US + SLEEP_SLACK_US - (now_usec - cnt_start_usec);
155+
sleep_usec = 3 * SMPL_INTVL_US + SLEEP_SLACK_US - ktime_to_us(ktime);
154156
if (sleep_usec > 0 && sleep_usec < 1000000)
155157
usleep_range(sleep_usec, sleep_usec + SLEEP_SLACK_US);
156158

0 commit comments

Comments
 (0)