21 #include <linux/kernel.h>
22 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/i2c.h>
32 #define LTC2978_MFR_VOUT_PEAK 0xdd
33 #define LTC2978_MFR_VIN_PEAK 0xde
34 #define LTC2978_MFR_TEMPERATURE_PEAK 0xdf
35 #define LTC2978_MFR_SPECIAL_ID 0xe7
38 #define LTC2978_MFR_VOUT_MIN 0xfb
39 #define LTC2978_MFR_VIN_MIN 0xfc
40 #define LTC2978_MFR_TEMPERATURE_MIN 0xfd
43 #define LTC3880_MFR_IOUT_PEAK 0xd7
44 #define LTC3880_MFR_CLEAR_PEAKS 0xe3
45 #define LTC3880_MFR_TEMPERATURE2_PEAK 0xf4
47 #define LTC2978_ID_REV1 0x0121
48 #define LTC2978_ID_REV2 0x0122
49 #define LTC3880_ID 0x4000
50 #define LTC3880_ID_MASK 0xff00
69 #define to_ltc2978_data(x) container_of(x, struct ltc2978_data, info)
71 static inline int lin11_to_val(
int data)
74 s32 m = (((
s16)(data << 5)) >> 5);
81 return (e < 0 ? m >> -e : m << e);
95 if (lin11_to_val(ret) > lin11_to_val(data->
vin_max))
116 if (lin11_to_val(ret) > lin11_to_val(data->
temp_max))
133 static int ltc2978_read_word_data(
struct i2c_client *client,
int page,
int reg)
143 if (lin11_to_val(ret) < lin11_to_val(data->
vin_min))
168 if (lin11_to_val(ret)
181 ret = ltc2978_read_word_data_common(client, page, reg);
187 static int ltc3880_read_word_data(
struct i2c_client *client,
int page,
int reg)
197 if (lin11_to_val(ret)
198 > lin11_to_val(data->
iout_max[page]))
207 if (lin11_to_val(ret)
223 ret = ltc2978_read_word_data_common(client, page, reg);
229 static int ltc2978_clear_peaks(
struct i2c_client *client,
int page,
242 static int ltc2978_write_word_data(
struct i2c_client *client,
int page,
252 ret = ltc2978_clear_peaks(client, page, data->
id);
256 ret = ltc2978_clear_peaks(client, page, data->
id);
261 ret = ltc2978_clear_peaks(client, page, data->
id);
266 ret = ltc2978_clear_peaks(client, page, data->
id);
271 ret = ltc2978_clear_peaks(client, page, data->
id);
287 static int ltc2978_probe(
struct i2c_client *client,
294 if (!i2c_check_functionality(client->
adapter,
312 dev_err(&client->
dev,
"Unsupported chip ID 0x%x\n", chip_id);
315 if (data->
id != id->driver_data)
317 "Device mismatch: Configured %s, detected %s\n",
319 ltc2978_id[data->
id].
name);
329 switch (id->driver_data) {
336 for (i = 1; i < 8; i++) {
369 .probe = ltc2978_probe,
371 .id_table = ltc2978_id,