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>
This commit is contained in:
Linus Torvalds
2025-11-26 12:31:48 -08:00
parent 32115734c0
commit ad8cccc248

View File

@@ -127,7 +127,8 @@ struct dc_ti_battery_chip {
static int dc_ti_battery_get_voltage_and_current_now(struct power_supply *psy, int *volt, int *curr) static int dc_ti_battery_get_voltage_and_current_now(struct power_supply *psy, int *volt, int *curr)
{ {
struct dc_ti_battery_chip *chip = power_supply_get_drvdata(psy); struct dc_ti_battery_chip *chip = power_supply_get_drvdata(psy);
s64 cnt_start_usec, now_usec, sleep_usec; ktime_t ktime;
s64 sleep_usec;
unsigned int reg_val; unsigned int reg_val;
s32 acc, smpl_ctr; s32 acc, smpl_ctr;
int ret; int ret;
@@ -141,16 +142,17 @@ static int dc_ti_battery_get_voltage_and_current_now(struct power_supply *psy, i
if (ret) if (ret)
goto out_err; goto out_err;
cnt_start_usec = ktime_get_ns() / NSEC_PER_USEC; ktime = ktime_get();
/* Read Vbat, convert IIO mV to power-supply ųV */ /* Read Vbat, convert IIO mV to power-supply ųV */
ret = iio_read_channel_processed_scale(chip->vbat_channel, volt, 1000); ret = iio_read_channel_processed_scale(chip->vbat_channel, volt, 1000);
if (ret < 0) if (ret < 0)
goto out_err; goto out_err;
ktime = ktime_sub(ktime_get(), ktime);
/* Sleep at least 3 sample-times + slack to get 3+ CC samples */ /* Sleep at least 3 sample-times + slack to get 3+ CC samples */
now_usec = ktime_get_ns() / NSEC_PER_USEC; sleep_usec = 3 * SMPL_INTVL_US + SLEEP_SLACK_US - ktime_to_us(ktime);
sleep_usec = 3 * SMPL_INTVL_US + SLEEP_SLACK_US - (now_usec - cnt_start_usec);
if (sleep_usec > 0 && sleep_usec < 1000000) if (sleep_usec > 0 && sleep_usec < 1000000)
usleep_range(sleep_usec, sleep_usec + SLEEP_SLACK_US); usleep_range(sleep_usec, sleep_usec + SLEEP_SLACK_US);