/* * Driver for Linear Technology LTC4151 High Voltage I2C Current * and Voltage Monitor * * Copyright (C) 2011 AppearTV AS * * Derived from: * * Driver for Linear Technology LTC4261 I2C Negative Voltage Hot * Swap Controller * Copyright (C) 2010 Ericsson AB. * * Datasheet: http://www.linear.com/docs/Datasheet/4151fc.pdf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include #include #include #include #include #include #include #include #include /* chip registers */ #define LTC4151_SENSE_H 0x00 #define LTC4151_SENSE_L 0x01 #define LTC4151_VIN_H 0x02 #define LTC4151_VIN_L 0x03 #define LTC4151_ADIN_H 0x04 #define LTC4151_ADIN_L 0x05 struct ltc4151_data { struct i2c_client *client; struct mutex update_lock; bool valid; unsigned long last_updated; /* in jiffies */ /* Registers */ u8 regs[6]; }; static struct ltc4151_data *ltc4151_update_device(struct device *dev) { struct ltc4151_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; struct ltc4151_data *ret = data; mutex_lock(&data->update_lock); /* * The chip's A/D updates 6 times per second * (Conversion Rate 6 - 9 Hz) */ if (time_after(jiffies, data->last_updated + HZ / 6) || !data->valid) { int i; dev_dbg(&client->dev, "Starting ltc4151 update\n"); /* Read all registers */ for (i = 0; i < ARRAY_SIZE(data->regs); i++) { int val; val = i2c_smbus_read_byte_data(client, i); if (unlikely(val < 0)) { dev_dbg(dev, "Failed to read ADC value: error %d\n", val); ret = ERR_PTR(val); goto abort; } data->regs[i] = val; } data->last_updated = jiffies; data->valid = 1; } abort: mutex_unlock(&data->update_lock); return ret; } /* Return the voltage from the given register in mV */ static int ltc4151_get_value(struct ltc4151_data *data, u8 reg) { u32 val; val = (data->regs[reg] << 4) + (data->regs[reg + 1] >> 4); switch (reg) { case LTC4151_ADIN_H: /* 500uV resolution. Convert to mV. */ val = val * 500 / 1000; break; case LTC4151_SENSE_H: /* * 20uV resolution. Convert to current as measured with * an 1 mOhm sense resistor, in mA. */ val = val * 20; break; case LTC4151_VIN_H: /* 25 mV per increment */ val = val * 25; break; default: /* If we get here, the developer messed up */ WARN_ON_ONCE(1); val = 0; break; } return val; } static ssize_t ltc4151_show_value(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct ltc4151_data *data = ltc4151_update_device(dev); int value; if (IS_ERR(data)) return PTR_ERR(data); value = ltc4151_get_value(data, attr->index); return snprintf(buf, PAGE_SIZE, "%d\n", value); } /* * Input voltages. */ static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ltc4151_show_value, NULL, LTC4151_VIN_H); static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, ltc4151_show_value, NULL, LTC4151_ADIN_H); /* Currents (via sense resistor) */ static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4151_show_value, NULL, LTC4151_SENSE_H); /* * Finally, construct an array of pointers to members of the above objects, * as required for sysfs_create_group() */ static struct attribute *ltc4151_attrs[] = { &sensor_dev_attr_in1_input.dev_attr.attr, &sensor_dev_attr_in2_input.dev_attr.attr, &sensor_dev_attr_curr1_input.dev_attr.attr, NULL, }; ATTRIBUTE_GROUPS(ltc4151); static int ltc4151_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_adapter *adapter = client->adapter; struct device *dev = &client->dev; struct ltc4151_data *data; struct device *hwmon_dev; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; data->client = client; mutex_init(&data->update_lock); hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, data, ltc4151_groups); return PTR_ERR_OR_ZERO(hwmon_dev); } static const struct i2c_device_id ltc4151_id[] = { { "ltc4151", 0 }, { } }; MODULE_DEVICE_TABLE(i2c, ltc4151_id); /* This is the driver that will be inserted */ static struct i2c_driver ltc4151_driver = { .driver = { .name = "ltc4151", }, .probe = ltc4151_probe, .id_table = ltc4151_id, }; module_i2c_driver(ltc4151_driver); MODULE_AUTHOR("Per Dalen "); MODULE_DESCRIPTION("LTC4151 driver"); MODULE_LICENSE("GPL"); /net-next.git/tree/?id=3ddc76dfc786cc6f87852693227fb0b1f124f807'>8192b4721e05cf6823087f9696db8c0c8f144b02 /tools/virtio/vringh_test.c parentb272f732f888d4cf43c943a40c9aaa836f9b7431 (diff)parent1f3a8e49d8f28f498b8694464623ac20aebfe62a (diff)
Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer type cleanups from Thomas Gleixner: "This series does a tree wide cleanup of types related to timers/timekeeping. - Get rid of cycles_t and use a plain u64. The type is not really helpful and caused more confusion than clarity - Get rid of the ktime union. The union has become useless as we use the scalar nanoseconds storage unconditionally now. The 32bit timespec alike storage got removed due to the Y2038 limitations some time ago. That leaves the odd union access around for no reason. Clean it up. Both changes have been done with coccinelle and a small amount of manual mopping up" * 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: ktime: Get rid of ktime_equal() ktime: Cleanup ktime_set() usage ktime: Get rid of the union clocksource: Use a plain u64 instead of cycle_t
Diffstat (limited to 'tools/virtio/vringh_test.c')