Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+6 -4
+6 -4
drivers/power/supply/intel_dc_ti_battery.c
··· 127 127 static int dc_ti_battery_get_voltage_and_current_now(struct power_supply *psy, int *volt, int *curr) 128 128 { 129 129 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; 131 132 unsigned int reg_val; 132 133 s32 acc, smpl_ctr; 133 134 int ret; ··· 142 141 if (ret) 143 142 goto out_err; 144 143 145 - cnt_start_usec = ktime_get_ns() / NSEC_PER_USEC; 144 + ktime = ktime_get(); 146 145 147 146 /* Read Vbat, convert IIO mV to power-supply ųV */ 148 147 ret = iio_read_channel_processed_scale(chip->vbat_channel, volt, 1000); 149 148 if (ret < 0) 150 149 goto out_err; 151 150 151 + ktime = ktime_sub(ktime_get(), ktime); 152 + 152 153 /* Sleep at least 3 sample-times + slack to get 3+ CC samples */ 153 - now_usec = ktime_get_ns() / NSEC_PER_USEC; 154 - sleep_usec = 3 * SMPL_INTVL_US + SLEEP_SLACK_US - (now_usec - cnt_start_usec); 154 + sleep_usec = 3 * SMPL_INTVL_US + SLEEP_SLACK_US - ktime_to_us(ktime); 155 155 if (sleep_usec > 0 && sleep_usec < 1000000) 156 156 usleep_range(sleep_usec, sleep_usec + SLEEP_SLACK_US); 157 157