16 #include <linux/kernel.h>
17 #include <linux/module.h>
20 #include <linux/slab.h>
21 #include <linux/i2c.h>
78 static void ltc4245_update_gpios(
struct device *
dev)
82 u8 gpio_curr, gpio_next, gpio_reg;
96 dev_dbg(&client->
dev,
"Marking GPIOs invalid\n");
142 dev_dbg(&client->
dev,
"Starting ltc4245 update\n");
163 ltc4245_update_gpios(dev);
175 static int ltc4245_get_voltage(
struct device *dev,
u8 reg)
184 voltage = regval * 55;
188 voltage = regval * 22;
192 voltage = regval * 15;
196 voltage = regval * -55;
199 voltage = regval * 10;
211 static unsigned int ltc4245_get_current(
struct device *dev,
u8 reg)
214 const u8 regval = data->
vregs[reg - 0x10];
215 unsigned int voltage;
235 voltage = regval * 250;
239 voltage = regval * 125;
240 curr = (voltage * 10) / 35;
243 voltage = regval * 125;
244 curr = (voltage * 10) / 25;
247 voltage = regval * 250;
248 curr = voltage / 100;
265 const int voltage = ltc4245_get_voltage(dev, attr->
index);
275 const unsigned int curr = ltc4245_get_current(dev, attr->
index);
285 const unsigned int curr = ltc4245_get_current(dev, attr->
index);
286 const int output_voltage = ltc4245_get_voltage(dev, attr->
index+1);
289 const unsigned int power =
abs(output_voltage * curr);
328 #define LTC4245_VOLTAGE(name, ltc4245_cmd_idx) \
329 static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
330 ltc4245_show_voltage, NULL, ltc4245_cmd_idx)
332 #define LTC4245_CURRENT(name, ltc4245_cmd_idx) \
333 static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
334 ltc4245_show_current, NULL, ltc4245_cmd_idx)
336 #define LTC4245_POWER(name, ltc4245_cmd_idx) \
337 static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
338 ltc4245_show_power, NULL, ltc4245_cmd_idx)
340 #define LTC4245_ALARM(name, mask, reg) \
341 static SENSOR_DEVICE_ATTR_2(name, S_IRUGO, \
342 ltc4245_show_alarm, NULL, (mask), reg)
344 #define LTC4245_GPIO_VOLTAGE(name, gpio_num) \
345 static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
346 ltc4245_show_gpio, NULL, gpio_num)
401 static struct attribute *ltc4245_std_attributes[] = {
402 &sensor_dev_attr_in1_input.dev_attr.attr,
403 &sensor_dev_attr_in2_input.dev_attr.attr,
404 &sensor_dev_attr_in3_input.dev_attr.attr,
405 &sensor_dev_attr_in4_input.dev_attr.attr,
407 &sensor_dev_attr_in1_min_alarm.dev_attr.attr,
408 &sensor_dev_attr_in2_min_alarm.dev_attr.attr,
409 &sensor_dev_attr_in3_min_alarm.dev_attr.attr,
410 &sensor_dev_attr_in4_min_alarm.dev_attr.attr,
412 &sensor_dev_attr_curr1_input.dev_attr.attr,
413 &sensor_dev_attr_curr2_input.dev_attr.attr,
414 &sensor_dev_attr_curr3_input.dev_attr.attr,
415 &sensor_dev_attr_curr4_input.dev_attr.attr,
417 &sensor_dev_attr_curr1_max_alarm.dev_attr.attr,
418 &sensor_dev_attr_curr2_max_alarm.dev_attr.attr,
419 &sensor_dev_attr_curr3_max_alarm.dev_attr.attr,
420 &sensor_dev_attr_curr4_max_alarm.dev_attr.attr,
422 &sensor_dev_attr_in5_input.dev_attr.attr,
423 &sensor_dev_attr_in6_input.dev_attr.attr,
424 &sensor_dev_attr_in7_input.dev_attr.attr,
425 &sensor_dev_attr_in8_input.dev_attr.attr,
427 &sensor_dev_attr_in5_min_alarm.dev_attr.attr,
428 &sensor_dev_attr_in6_min_alarm.dev_attr.attr,
429 &sensor_dev_attr_in7_min_alarm.dev_attr.attr,
430 &sensor_dev_attr_in8_min_alarm.dev_attr.attr,
432 &sensor_dev_attr_in9_input.dev_attr.attr,
434 &sensor_dev_attr_power1_input.dev_attr.attr,
435 &sensor_dev_attr_power2_input.dev_attr.attr,
436 &sensor_dev_attr_power3_input.dev_attr.attr,
437 &sensor_dev_attr_power4_input.dev_attr.attr,
442 static struct attribute *ltc4245_gpio_attributes[] = {
443 &sensor_dev_attr_in10_input.dev_attr.attr,
444 &sensor_dev_attr_in11_input.dev_attr.attr,
449 .attrs = ltc4245_std_attributes,
453 .attrs = ltc4245_gpio_attributes,
456 static int ltc4245_sysfs_create_groups(
struct i2c_client *client)
465 dev_err(dev,
"unable to register standard attributes\n");
473 dev_err(dev,
"unable to register gpio attributes\n");
482 static void ltc4245_sysfs_remove_groups(
struct i2c_client *client)
493 static bool ltc4245_use_extra_gpios(
struct i2c_client *client)
513 static int ltc4245_probe(
struct i2c_client *client,
527 i2c_set_clientdata(client, data);
536 ret = ltc4245_sysfs_create_groups(client);
543 goto out_hwmon_device_register;
548 out_hwmon_device_register:
549 ltc4245_sysfs_remove_groups(client);
553 static int ltc4245_remove(
struct i2c_client *client)
558 ltc4245_sysfs_remove_groups(client);
574 .probe = ltc4245_probe,
575 .remove = ltc4245_remove,
576 .id_table = ltc4245_id,