diff options
author | Stephen Rothwell <sfr@canb.auug.org.au> | 2011-04-08 13:21:15 +1000 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2011-04-08 13:21:15 +1000 |
commit | 7f9860097183edee17a5f5c865c873f0fc0e97c4 (patch) | |
tree | fa96223dcda3adaa86c8cd72819288833692b356 | |
parent | 41c8efa5e12d9e596be35ed447eefd0da77ce96a (diff) | |
parent | 66158d6e466b6c04ec2b7923bfb3c8c19a855e72 (diff) |
Merge remote-tracking branch 'hwmon-staging/hwmon-next'
-rw-r--r-- | Documentation/hwmon/max6642 | 21 | ||||
-rw-r--r-- | drivers/hwmon/Kconfig | 43 | ||||
-rw-r--r-- | drivers/hwmon/Makefile | 4 | ||||
-rw-r--r-- | drivers/hwmon/adm1275.c | 121 | ||||
-rw-r--r-- | drivers/hwmon/max34440.c | 6 | ||||
-rw-r--r-- | drivers/hwmon/max6642.c | 356 | ||||
-rw-r--r-- | drivers/hwmon/max8688.c | 4 | ||||
-rw-r--r-- | drivers/hwmon/pmbus.h | 10 | ||||
-rw-r--r-- | drivers/hwmon/pmbus_core.c | 971 | ||||
-rw-r--r-- | drivers/hwmon/ucd9000.c | 278 | ||||
-rw-r--r-- | drivers/hwmon/ucd9200.c | 210 |
11 files changed, 1483 insertions, 541 deletions
diff --git a/Documentation/hwmon/max6642 b/Documentation/hwmon/max6642 new file mode 100644 index 000000000000..afbd3e4942e2 --- /dev/null +++ b/Documentation/hwmon/max6642 @@ -0,0 +1,21 @@ +Kernel driver max6642 +===================== + +Supported chips: + * Maxim MAX6642 + Prefix: 'max6642' + Addresses scanned: I2C 0x48-0x4f + Datasheet: Publicly available at the Maxim website + http://datasheets.maxim-ic.com/en/ds/MAX6642.pdf + +Authors: + Per Dalen <per.dalen@appeartv.com> + +Description +----------- + +The MAX6642 is a digital temperature sensor. It senses its own temperature as +well as the temperature on one external diode. + +All temperature values are given in degrees Celsius. Resolution +is 0.25 degree for the local temperature and for the remote temperature. diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 0d67ec3227e9..cd283f33de13 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -728,6 +728,17 @@ config SENSORS_MAX6639 This driver can also be built as a module. If so, the module will be called max6639. +config SENSORS_MAX6642 + tristate "Maxim MAX6642 sensor chip" + depends on I2C && EXPERIMENTAL + help + If you say yes here you get support for MAX6642 sensor chip. + MAX6642 is a SMBus-Compatible Remote/Local Temperature Sensor + with Overtemperature Alarm from Maxim. + + This driver can also be built as a module. If so, the module + will be called max6642. + config SENSORS_MAX6650 tristate "Maxim MAX6650 sensor chip" depends on I2C && EXPERIMENTAL @@ -801,6 +812,16 @@ config SENSORS_PMBUS This driver can also be built as a module. If so, the module will be called pmbus. +config SENSORS_ADM1275 + tristate "Analog Devices ADM1275" + default n + help + If you say yes here you get hardware monitoring support for Analog + Devices ADM1275 Hot-Swap Controller and Digital Power Monitor. + + This driver can also be built as a module. If so, the module will + be called adm1275. + config SENSORS_MAX16064 tristate "Maxim MAX16064" default n @@ -831,6 +852,28 @@ config SENSORS_MAX8688 This driver can also be built as a module. If so, the module will be called max8688. +config SENSORS_UCD9000 + tristate "TI UCD90120, UCD90124, UCD9090, UCD90910" + default n + help + If you say yes here you get hardware monitoring support for TI + UCD90120, UCD90124, UCD9090, UCD90910 Sequencer and System Health + Controllers. + + This driver can also be built as a module. If so, the module will + be called ucd9000. + +config SENSORS_UCD9200 + tristate "TI UCD9220, UCD9222, UCD9224, UCD9240, UCD9244, UCD9246, UCD9248" + default n + help + If you say yes here you get hardware monitoring support for TI + UCD9220, UCD9222, UCD9224, UCD9240, UCD9244, UCD9246, and UCD9248 + Digital PWM System Controllers. + + This driver can also be built as a module. If so, the module will + be called ucd9200. + endif # PMBUS config SENSORS_SHT15 diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 967d0ea9447f..a6174b36818e 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -85,6 +85,7 @@ obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o obj-$(CONFIG_SENSORS_MAX1111) += max1111.o obj-$(CONFIG_SENSORS_MAX1619) += max1619.o obj-$(CONFIG_SENSORS_MAX6639) += max6639.o +obj-$(CONFIG_SENSORS_MAX6642) += max6642.o obj-$(CONFIG_SENSORS_MAX6650) += max6650.o obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o obj-$(CONFIG_SENSORS_PC87360) += pc87360.o @@ -118,9 +119,12 @@ obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o # PMBus drivers obj-$(CONFIG_PMBUS) += pmbus_core.o obj-$(CONFIG_SENSORS_PMBUS) += pmbus.o +obj-$(CONFIG_SENSORS_ADM1275) += adm1275.o obj-$(CONFIG_SENSORS_MAX16064) += max16064.o obj-$(CONFIG_SENSORS_MAX34440) += max34440.o obj-$(CONFIG_SENSORS_MAX8688) += max8688.o +obj-$(CONFIG_SENSORS_UCD9000) += ucd9000.o +obj-$(CONFIG_SENSORS_UCD9200) += ucd9200.o ccflags-$(CONFIG_HWMON_DEBUG_CHIP) := -DDEBUG diff --git a/drivers/hwmon/adm1275.c b/drivers/hwmon/adm1275.c new file mode 100644 index 000000000000..c2ee2048ab91 --- /dev/null +++ b/drivers/hwmon/adm1275.c @@ -0,0 +1,121 @@ +/* + * Hardware monitoring driver for Analog Devices ADM1275 Hot-Swap Controller + * and Digital Power Monitor + * + * Copyright (c) 2011 Ericsson AB. + * + * 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. + */ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/err.h> +#include <linux/slab.h> +#include <linux/i2c.h> +#include "pmbus.h" + +#define ADM1275_PMON_CONFIG 0xd4 + +#define ADM1275_VIN_VOUT_SELECT (1 << 6) +#define ADM1275_VRANGE (1 << 5) + +static int adm1275_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int config; + struct pmbus_driver_info *info; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_READ_BYTE_DATA)) + return -ENODEV; + + info = kzalloc(sizeof(struct pmbus_driver_info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG); + if (config < 0) + return config; + + info->pages = 1; + info->direct[PSC_VOLTAGE_IN] = true; + info->direct[PSC_VOLTAGE_OUT] = true; + info->direct[PSC_CURRENT_OUT] = true; + info->m[PSC_CURRENT_OUT] = 800; + info->b[PSC_CURRENT_OUT] = 20475; + info->R[PSC_CURRENT_OUT] = -1; + info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; + + if (config & ADM1275_VRANGE) { + info->m[PSC_VOLTAGE_IN] = 19045; + info->b[PSC_VOLTAGE_IN] = 0; + info->R[PSC_VOLTAGE_IN] = -2; + info->m[PSC_VOLTAGE_OUT] = 19045; + info->b[PSC_VOLTAGE_OUT] = 0; + info->R[PSC_VOLTAGE_OUT] = -2; + } else { + info->m[PSC_VOLTAGE_IN] = 6666; + info->b[PSC_VOLTAGE_IN] = 0; + info->R[PSC_VOLTAGE_IN] = -1; + info->m[PSC_VOLTAGE_OUT] = 6666; + info->b[PSC_VOLTAGE_OUT] = 0; + info->R[PSC_VOLTAGE_OUT] = -1; + } + + if (config & ADM1275_VIN_VOUT_SELECT) + info->func[0] |= PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; + else + info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT; + + return pmbus_do_probe(client, id, info); +} + +static int adm1275_remove(struct i2c_client *client) +{ + const struct pmbus_driver_info *info = pmbus_get_driver_info(client); + int ret; + + ret = pmbus_do_remove(client); + kfree(info); + return ret; +} + +static const struct i2c_device_id adm1275_id[] = { + {"adm1275", 0}, + { } +}; +MODULE_DEVICE_TABLE(i2c, adm1275_id); + +static struct i2c_driver adm1275_driver = { + .driver = { + .name = "adm1275", + }, + .probe = adm1275_probe, + .remove = adm1275_remove, + .id_table = adm1275_id, +}; + +static int __init adm1275_init(void) +{ + return i2c_add_driver(&adm1275_driver); +} + +static void __exit adm1275_exit(void) +{ + i2c_del_driver(&adm1275_driver); +} + +MODULE_AUTHOR("Guenter Roeck"); +MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275"); +MODULE_LICENSE("GPL"); +module_init(adm1275_init); +module_exit(adm1275_exit); diff --git a/drivers/hwmon/max34440.c b/drivers/hwmon/max34440.c index 992b701b4c5e..db11e1a175b2 100644 --- a/drivers/hwmon/max34440.c +++ b/drivers/hwmon/max34440.c @@ -32,7 +32,7 @@ enum chips { max34440, max34441 }; #define MAX34440_STATUS_OT_FAULT (1 << 5) #define MAX34440_STATUS_OT_WARN (1 << 6) -static int max34440_get_status(struct i2c_client *client, int page, int reg) +static int max34440_read_byte_data(struct i2c_client *client, int page, int reg) { int ret; int mfg_status; @@ -108,7 +108,7 @@ static struct pmbus_driver_info max34440_info[] = { .func[11] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, .func[12] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, .func[13] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, - .get_status = max34440_get_status, + .read_byte_data = max34440_read_byte_data, }, [max34441] = { .pages = 12, @@ -149,7 +149,7 @@ static struct pmbus_driver_info max34440_info[] = { .func[9] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, .func[10] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, .func[11] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP, - .get_status = max34440_get_status, + .read_byte_data = max34440_read_byte_data, }, }; diff --git a/drivers/hwmon/max6642.c b/drivers/hwmon/max6642.c new file mode 100644 index 000000000000..0f9fc40379cd --- /dev/null +++ b/drivers/hwmon/max6642.c @@ -0,0 +1,356 @@ +/* + * Driver for +/-1 degree C, SMBus-Compatible Remote/Local Temperature Sensor + * with Overtemperature Alarm + * + * Copyright (C) 2011 AppearTV AS + * + * Derived from: + * + * Based on the max1619 driver. + * Copyright (C) 2003-2004 Alexey Fisher <fishor@mail.ru> + * Jean Delvare <khali@linux-fr.org> + * + * The MAX6642 is a sensor chip made by Maxim. + * It reports up to two temperatures (its own plus up to + * one external one). Complete datasheet can be + * obtained from Maxim's website at: + * http://datasheets.maxim-ic.com/en/ds/MAX6642.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 <linux/module.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/jiffies.h> +#include <linux/i2c.h> +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> +#include <linux/err.h> +#include <linux/mutex.h> +#include <linux/sysfs.h> + +static const unsigned short normal_i2c[] = { + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; + +/* + * The MAX6642 registers + */ + +#define MAX6642_REG_R_MAN_ID 0xFE +#define MAX6642_REG_R_CONFIG 0x03 +#define MAX6642_REG_W_CONFIG 0x09 +#define MAX6642_REG_R_STATUS 0x02 +#define MAX6642_REG_R_LOCAL_TEMP 0x00 +#define MAX6642_REG_R_LOCAL_TEMPL 0x11 +#define MAX6642_REG_R_LOCAL_HIGH 0x05 +#define MAX6642_REG_W_LOCAL_HIGH 0x0B +#define MAX6642_REG_R_REMOTE_TEMP 0x01 +#define MAX6642_REG_R_REMOTE_TEMPL 0x10 +#define MAX6642_REG_R_REMOTE_HIGH 0x07 +#define MAX6642_REG_W_REMOTE_HIGH 0x0D + +/* + * Conversions + */ + +static int temp_from_reg10(int val) +{ + return val * 250; +} + +static int temp_from_reg(int val) +{ + return val * 1000; +} + +static int temp_to_reg(int val) +{ + return val / 1000; +} + +/* + * Client data (each client gets its own) + */ + +struct max6642_data { + struct device *hwmon_dev; + struct mutex update_lock; + bool valid; /* zero until following fields are valid */ + unsigned long last_updated; /* in jiffies */ + + /* registers values */ + u16 temp_input[2]; /* local/remote */ + u16 temp_high[2]; /* local/remote */ + u8 alarms; +}; + +/* + * Real code + */ + +static void max6642_init_client(struct i2c_client *client) +{ + u8 config; + struct max6642_data *data = i2c_get_clientdata(client); + + /* + * Start the conversions. + */ + config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG); + if (config & 0x40) + i2c_smbus_write_byte_data(client, MAX6642_REG_W_CONFIG, + config & 0xBF); /* run */ + + data->temp_high[0] = i2c_smbus_read_byte_data(client, + MAX6642_REG_R_LOCAL_HIGH); + data->temp_high[1] = i2c_smbus_read_byte_data(client, + MAX6642_REG_R_REMOTE_HIGH); +} + +/* Return 0 if detection is successful, -ENODEV otherwise */ +static int max6642_detect(struct i2c_client *client, + struct i2c_board_info *info) +{ + struct i2c_adapter *adapter = client->adapter; + u8 reg_config, reg_status, man_id; + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + return -ENODEV; + + /* identification */ + man_id = i2c_smbus_read_byte_data(client, MAX6642_REG_R_MAN_ID); + if (man_id != 0x4D) + return -ENODEV; + + /* + * We read the config and status register, the 4 lower bits in the + * config register should be zero and bit 5, 3, 1 and 0 should be + * zero in the status register. + */ + reg_config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG); + reg_status = i2c_smbus_read_byte_data(client, MAX6642_REG_R_STATUS); + if (((reg_config & 0x0f) != 0x00) || + ((reg_status & 0x2b) != 0x00)) + return -ENODEV; + + strlcpy(info->type, "max6642", I2C_NAME_SIZE); + + return 0; +} + +static struct max6642_data *max6642_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct max6642_data *data = i2c_get_clientdata(client); + u16 val, tmp; + + mutex_lock(&data->update_lock); + + if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { + dev_dbg(&client->dev, "Updating max6642 data.\n"); + val = i2c_smbus_read_byte_data(client, + MAX6642_REG_R_LOCAL_TEMPL); + tmp = (val >> 6) & 3; + val = i2c_smbus_read_byte_data(client, + MAX6642_REG_R_LOCAL_TEMP); + val = (val << 2) | tmp; + data->temp_input[0] = val; + val = i2c_smbus_read_byte_data(client, + MAX6642_REG_R_REMOTE_TEMPL); + tmp = (val >> 6) & 3; + val = i2c_smbus_read_byte_data(client, + MAX6642_REG_R_REMOTE_TEMP); + val = (val << 2) | tmp; + data->temp_input[1] = val; + data->alarms = i2c_smbus_read_byte_data(client, + MAX6642_REG_R_STATUS); + + data->last_updated = jiffies; + data->valid = 1; + } + + mutex_unlock(&data->update_lock); + + return data; +} + +/* + * Sysfs stuff + */ + +static ssize_t show_temp_max10(struct device *dev, + struct device_attribute *dev_attr, char *buf) +{ + struct max6642_data *data = max6642_update_device(dev); + struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); + + return sprintf(buf, "%d\n", + temp_from_reg10(data->temp_input[attr->index])); +} + +static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct max6642_data *data = max6642_update_device(dev); + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); + + return sprintf(buf, "%d\n", temp_from_reg(data->temp_high[attr2->nr])); +} + +static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long val; + int err; + struct i2c_client *client = to_i2c_client(dev); + struct max6642_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); + + err = strict_strtoul(buf, 10, &val); + if (err < 0) + return err; + + mutex_lock(&data->update_lock); + data->temp_high[attr2->nr] = SENSORS_LIMIT(temp_to_reg(val), 0, 255); + i2c_smbus_write_byte_data(client, attr2->index, + data->temp_high[attr2->nr]); + mutex_unlock(&data->update_lock); + return count; +} + +static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, + char *buf) +{ + int bitnr = to_sensor_dev_attr(attr)->index; + struct max6642_data *data = max6642_update_device(dev); + return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); +} + +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_max10, NULL, 0); +static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_max10, NULL, 1); +static SENSOR_DEVICE_ATTR_2(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, + set_temp_max, 0, MAX6642_REG_W_LOCAL_HIGH); +static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, + set_temp_max, 1, MAX6642_REG_W_REMOTE_HIGH); +static SENSOR_DEVICE_ATTR(temp_fault, S_IRUGO, show_alarm, NULL, 2); +static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); +static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); + +static struct attribute *max6642_attributes[] = { + &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_temp2_input.dev_attr.attr, + &sensor_dev_attr_temp1_max.dev_attr.attr, + &sensor_dev_attr_temp2_max.dev_attr.attr, + + &sensor_dev_attr_temp_fault.dev_attr.attr, + &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, + &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, + NULL +}; + +static const struct attribute_group max6642_group = { + .attrs = max6642_attributes, +}; + +static int max6642_probe(struct i2c_client *new_client, + const struct i2c_device_id *id) +{ + struct max6642_data *data; + int err; + + data = kzalloc(sizeof(struct max6642_data), GFP_KERNEL); + if (!data) { + err = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(new_client, data); + mutex_init(&data->update_lock); + + /* Initialize the MAX6642 chip */ + max6642_init_client(new_client); + + /* Register sysfs hooks */ + err = sysfs_create_group(&new_client->dev.kobj, &max6642_group); + if (err) + goto exit_free; + + data->hwmon_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->hwmon_dev)) { + err = PTR_ERR(data->hwmon_dev); + goto exit_remove_files; + } + + return 0; + +exit_remove_files: + sysfs_remove_group(&new_client->dev.kobj, &max6642_group); +exit_free: + kfree(data); +exit: + return err; +} + +static int max6642_remove(struct i2c_client *client) +{ + struct max6642_data *data = i2c_get_clientdata(client); + + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &max6642_group); + + kfree(data); + return 0; +} + +/* + * Driver data (common to all clients) + */ + +static const struct i2c_device_id max6642_id[] = { + { "max6642", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, max6642_id); + +static struct i2c_driver max6642_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "max6642", + }, + .probe = max6642_probe, + .remove = max6642_remove, + .id_table = max6642_id, + .detect = max6642_detect, + .address_list = normal_i2c, +}; + +static int __init max6642_init(void) +{ + return i2c_add_driver(&max6642_driver); +} + +static void __exit max6642_exit(void) +{ + i2c_del_driver(&max6642_driver); +} + +MODULE_AUTHOR("Per Dalen <per.dalen@appeartv.com>"); +MODULE_DESCRIPTION("MAX6642 sensor driver"); +MODULE_LICENSE("GPL"); + +module_init(max6642_init); +module_exit(max6642_exit); diff --git a/drivers/hwmon/max8688.c b/drivers/hwmon/max8688.c index 8ebfef2ecf26..7fb93f4e9f21 100644 --- a/drivers/hwmon/max8688.c +++ b/drivers/hwmon/max8688.c @@ -37,7 +37,7 @@ #define MAX8688_STATUS_OT_FAULT (1 << 13) #define MAX8688_STATUS_OT_WARNING (1 << 14) -static int max8688_get_status(struct i2c_client *client, int page, int reg) +static int max8688_read_byte_data(struct i2c_client *client, int page, int reg) { int ret = 0; int mfg_status; @@ -110,7 +110,7 @@ static struct pmbus_driver_info max8688_info = { .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_TEMP, - .get_status = max8688_get_status, + .read_byte_data = max8688_read_byte_data, }; static int max8688_probe(struct i2c_client *client, diff --git a/drivers/hwmon/pmbus.h b/drivers/hwmon/pmbus.h index a81f7f228762..50647ab7235a 100644 --- a/drivers/hwmon/pmbus.h +++ b/drivers/hwmon/pmbus.h @@ -281,13 +281,11 @@ struct pmbus_driver_info { u32 func[PMBUS_PAGES]; /* Functionality, per page */ /* - * The get_status function maps manufacturing specific status values - * into PMBus standard status values. - * This function is optional and only necessary if chip specific status - * register values have to be mapped into standard PMBus status register - * values. + * The following functions map manufacturing specific register values + * to PMBus standard register values. Specify only if mapping is + * necessary. */ - int (*get_status)(struct i2c_client *client, int page, int reg); + int (*read_byte_data)(struct i2c_client *client, int page, int reg); /* * The identify function determines supported PMBus functionality. * This function is only necessary if a chip driver supports multiple diff --git a/drivers/hwmon/pmbus_core.c b/drivers/hwmon/pmbus_core.c index edfb92e41735..98799bab69ce 100644 --- a/drivers/hwmon/pmbus_core.c +++ b/drivers/hwmon/pmbus_core.c @@ -139,7 +139,6 @@ struct pmbus_data { * A single status register covers multiple attributes, * so we keep them all together. */ - u8 status_bits; u8 status[PB_NUM_STATUS_REG]; u8 currpage; @@ -271,18 +270,22 @@ const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client *client) } EXPORT_SYMBOL_GPL(pmbus_get_driver_info); -static int pmbus_get_status(struct i2c_client *client, int page, int reg) +/* + * _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if + * a device specific mapping funcion exists and calls it if necessary. + */ +static int _pmbus_read_byte_data(struct i2c_client *client, int page, int reg) { struct pmbus_data *data = i2c_get_clientdata(client); const struct pmbus_driver_info *info = data->info; int status; - if (info->get_status) { - status = info->get_status(client, page, reg); + if (info->read_byte_data) { + status = info->read_byte_data(client, page, reg); if (status != -ENODATA) return status; } - return pmbus_read_byte_data(client, page, reg); + return pmbus_read_byte_data(client, page, reg); } static struct pmbus_data *pmbus_update_device(struct device *dev) @@ -303,38 +306,41 @@ static struct pmbus_data *pmbus_update_device(struct device *dev) if (!(info->func[i] & PMBUS_HAVE_STATUS_VOUT)) continue; data->status[PB_STATUS_VOUT_BASE + i] - = pmbus_get_status(client, i, PMBUS_STATUS_VOUT); + = _pmbus_read_byte_data(client, i, PMBUS_STATUS_VOUT); } for (i = 0; i < info->pages; i++) { if (!(info->func[i] & PMBUS_HAVE_STATUS_IOUT)) continue; data->status[PB_STATUS_IOUT_BASE + i] - = pmbus_get_status(client, i, PMBUS_STATUS_IOUT); + = _pmbus_read_byte_data(client, i, PMBUS_STATUS_IOUT); } for (i = 0; i < info->pages; i++) { if (!(info->func[i] & PMBUS_HAVE_STATUS_TEMP)) continue; data->status[PB_STATUS_TEMP_BASE + i] - = pmbus_get_status(client, i, - PMBUS_STATUS_TEMPERATURE); + = _pmbus_read_byte_data(client, i, + PMBUS_STATUS_TEMPERATURE); } for (i = 0; i < info->pages; i++) { if (!(info->func[i] & PMBUS_HAVE_STATUS_FAN12)) continue; data->status[PB_STATUS_FAN_BASE + i] - = pmbus_get_status(client, i, PMBUS_STATUS_FAN_12); + = _pmbus_read_byte_data(client, i, + PMBUS_STATUS_FAN_12); } for (i = 0; i < info->pages; i++) { if (!(info->func[i] & PMBUS_HAVE_STATUS_FAN34)) continue; data->status[PB_STATUS_FAN34_BASE + i] - = pmbus_get_status(client, i, PMBUS_STATUS_FAN_34); + = _pmbus_read_byte_data(client, i, + PMBUS_STATUS_FAN_34); } if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) data->status[PB_STATUS_INPUT_BASE] - = pmbus_get_status(client, 0, PMBUS_STATUS_INPUT); + = _pmbus_read_byte_data(client, 0, + PMBUS_STATUS_INPUT); for (i = 0; i < data->num_sensors; i++) { struct pmbus_sensor *sensor = &data->sensors[i]; @@ -794,53 +800,6 @@ static void pmbus_add_label(struct pmbus_data *data, data->num_labels++; } -static const int pmbus_temp_registers[] = { - PMBUS_READ_TEMPERATURE_1, - PMBUS_READ_TEMPERATURE_2, - PMBUS_READ_TEMPERATURE_3 -}; - -static const int pmbus_temp_flags[] = { - PMBUS_HAVE_TEMP, - PMBUS_HAVE_TEMP2, - PMBUS_HAVE_TEMP3 -}; - -static const int pmbus_fan_registers[] = { - PMBUS_READ_FAN_SPEED_1, - PMBUS_READ_FAN_SPEED_2, - PMBUS_READ_FAN_SPEED_3, - PMBUS_READ_FAN_SPEED_4 -}; - -static const int pmbus_fan_config_registers[] = { - PMBUS_FAN_CONFIG_12, - PMBUS_FAN_CONFIG_12, - PMBUS_FAN_CONFIG_34, - PMBUS_FAN_CONFIG_34 -}; - -static const int pmbus_fan_status_registers[] = { - PMBUS_STATUS_FAN_12, - PMBUS_STATUS_FAN_12, - PMBUS_STATUS_FAN_34, - PMBUS_STATUS_FAN_34 -}; - -static const u32 pmbus_fan_flags[] = { - PMBUS_HAVE_FAN12, - PMBUS_HAVE_FAN12, - PMBUS_HAVE_FAN34, - PMBUS_HAVE_FAN34 -}; - -static const u32 pmbus_fan_status_flags[] = { - PMBUS_HAVE_STATUS_FAN12, - PMBUS_HAVE_STATUS_FAN12, - PMBUS_HAVE_STATUS_FAN34, - PMBUS_HAVE_STATUS_FAN34 -}; - /* * Determine maximum number of sensors, booleans, and labels. * To keep things simple, only make a rough high estimate. @@ -901,499 +860,431 @@ static void pmbus_find_max_attr(struct i2c_client *client, /* * Search for attributes. Allocate sensors, booleans, and labels as needed. */ -static void pmbus_find_attributes(struct i2c_client *client, - struct pmbus_data *data) -{ - const struct pmbus_driver_info *info = data->info; - int page, i0, i1, in_index; - /* - * Input voltage sensors - */ - in_index = 1; - if (info->func[0] & PMBUS_HAVE_VIN) { - bool have_alarm = false; - - i0 = data->num_sensors; - pmbus_add_label(data, "in", in_index, "vin", 0); - pmbus_add_sensor(data, "in", "input", in_index, 0, - PMBUS_READ_VIN, PSC_VOLTAGE_IN, true, true); - if (pmbus_check_word_register(client, 0, - PMBUS_VIN_UV_WARN_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "in", "min", in_index, - 0, PMBUS_VIN_UV_WARN_LIMIT, - PSC_VOLTAGE_IN, false, false); - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) { - pmbus_add_boolean_reg(data, "in", "min_alarm", - in_index, - PB_STATUS_INPUT_BASE, - PB_VOLTAGE_UV_WARNING); - have_alarm = true; - } - } - if (pmbus_check_word_register(client, 0, - PMBUS_VIN_UV_FAULT_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "in", "lcrit", in_index, - 0, PMBUS_VIN_UV_FAULT_LIMIT, - PSC_VOLTAGE_IN, false, false); - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) { - pmbus_add_boolean_reg(data, "in", "lcrit_alarm", - in_index, - PB_STATUS_INPUT_BASE, - PB_VOLTAGE_UV_FAULT); - have_alarm = true; - } - } - if (pmbus_check_word_register(client, 0, - PMBUS_VIN_OV_WARN_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "in", "max", in_index, - 0, PMBUS_VIN_OV_WARN_LIMIT, - PSC_VOLTAGE_IN, false, false); - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) { - pmbus_add_boolean_reg(data, "in", "max_alarm", - in_index, - PB_STATUS_INPUT_BASE, - PB_VOLTAGE_OV_WARNING); - have_alarm = true; - } - } - if (pmbus_check_word_register(client, 0, - PMBUS_VIN_OV_FAULT_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "in", "crit", in_index, - 0, PMBUS_VIN_OV_FAULT_LIMIT, - PSC_VOLTAGE_IN, false, false); - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) { - pmbus_add_boolean_reg(data, "in", "crit_alarm", - in_index, - PB_STATUS_INPUT_BASE, - PB_VOLTAGE_OV_FAULT); +/* + * The pmbus_limit_attr structure describes a single limit attribute + * and its associated alarm attribute. + */ +struct pmbus_limit_attr { + u8 reg; /* Limit register */ + const char *attr; /* Attribute name */ + const char *alarm; /* Alarm attribute name */ + u32 sbit; /* Alarm attribute status bit */ +}; + +/* + * The pmbus_sensor_attr structure describes one sensor attribute. This + * description includes a reference to the associated limit attributes. + */ +struct pmbus_sensor_attr { + u8 reg; /* sensor register */ + enum pmbus_sensor_classes class;/* sensor class */ + const char *label; /* sensor label */ + bool paged; /* true if paged sensor */ + bool update; /* true if update needed */ + bool compare; /* true if compare function needed */ + u32 func; /* sensor mask */ + u32 sfunc; /* sensor status mask */ + int sbase; /* status base register */ + u32 gbit; /* generic status bit */ + const struct pmbus_limit_attr *limit;/* limit registers */ + int nlimit; /* # of limit registers */ +}; + +/* + * Add a set of limit attributes and, if supported, the associated + * alarm attributes. + */ +static bool pmbus_add_limit_attrs(struct i2c_client *client, + struct pmbus_data *data, + const struct pmbus_driver_info *info, + const char *name, int index, int page, + int cbase, + const struct pmbus_sensor_attr *attr) +{ + const struct pmbus_limit_attr *l = attr->limit; + int nlimit = attr->nlimit; + bool have_alarm = false; + int i, cindex; + + for (i = 0; i < nlimit; i++) { + if (pmbus_check_word_register(client, page, l->reg)) { + cindex = data->num_sensors; + pmbus_add_sensor(data, name, l->attr, index, page, + l->reg, attr->class, attr->update, + false); + if (info->func[page] & attr->sfunc) { + if (attr->compare) { + pmbus_add_boolean_cmp(data, name, + l->alarm, index, + cbase, cindex, + attr->sbase + page, l->sbit); + } else { + pmbus_add_boolean_reg(data, name, + l->alarm, index, + attr->sbase + page, l->sbit); + } have_alarm = true; } } - /* - * Add generic alarm attribute only if there are no individual - * attributes. - */ - if (!have_alarm) - pmbus_add_boolean_reg(data, "in", "alarm", - in_index, - PB_STATUS_BASE, - PB_STATUS_VIN_UV); - in_index++; - } - if (info->func[0] & PMBUS_HAVE_VCAP) { - pmbus_add_label(data, "in", in_index, "vcap", 0); - pmbus_add_sensor(data, "in", "input", in_index, 0, - PMBUS_READ_VCAP, PSC_VOLTAGE_IN, true, true); - in_index++; + l++; } + return have_alarm; +} - /* - * Output voltage sensors - */ - for (page = 0; page < info->pages; page++) { - bool have_alarm = false; - - if (!(info->func[page] & PMBUS_HAVE_VOUT)) - continue; - - i0 = data->num_sensors; - pmbus_add_label(data, "in", in_index, "vout", page + 1); - pmbus_add_sensor(data, "in", "input", in_index, page, - PMBUS_READ_VOUT, PSC_VOLTAGE_OUT, true, true); - if (pmbus_check_word_register(client, page, - PMBUS_VOUT_UV_WARN_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "in", "min", in_index, page, - PMBUS_VOUT_UV_WARN_LIMIT, - PSC_VOLTAGE_OUT, false, false); - if (info->func[page] & PMBUS_HAVE_STATUS_VOUT) { - pmbus_add_boolean_reg(data, "in", "min_alarm", - in_index, - PB_STATUS_VOUT_BASE + - page, - PB_VOLTAGE_UV_WARNING); - have_alarm = true; - } - } - if (pmbus_check_word_register(client, page, - PMBUS_VOUT_UV_FAULT_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "in", "lcrit", in_index, page, - PMBUS_VOUT_UV_FAULT_LIMIT, - PSC_VOLTAGE_OUT, false, false); - if (info->func[page] & PMBUS_HAVE_STATUS_VOUT) { - pmbus_add_boolean_reg(data, "in", "lcrit_alarm", - in_index, - PB_STATUS_VOUT_BASE + - page, - PB_VOLTAGE_UV_FAULT); - have_alarm = true; - } - } - if (pmbus_check_word_register(client, page, - PMBUS_VOUT_OV_WARN_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "in", "max", in_index, page, - PMBUS_VOUT_OV_WARN_LIMIT, - PSC_VOLTAGE_OUT, false, false); - if (info->func[page] & PMBUS_HAVE_STATUS_VOUT) { - pmbus_add_boolean_reg(data, "in", "max_alarm", - in_index, - PB_STATUS_VOUT_BASE + - page, - PB_VOLTAGE_OV_WARNING); - have_alarm = true; - } - } - if (pmbus_check_word_register(client, page, - PMBUS_VOUT_OV_FAULT_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "in", "crit", in_index, page, - PMBUS_VOUT_OV_FAULT_LIMIT, - PSC_VOLTAGE_OUT, false, false); - if (info->func[page] & PMBUS_HAVE_STATUS_VOUT) { - pmbus_add_boolean_reg(data, "in", "crit_alarm", - in_index, - PB_STATUS_VOUT_BASE + - page, - PB_VOLTAGE_OV_FAULT); - have_alarm = true; - } - } +static void pmbus_add_sensor_attrs_one(struct i2c_client *client, + struct pmbus_data *data, + const struct pmbus_driver_info *info, + const char *name, + int index, int page, + const struct pmbus_sensor_attr *attr) +{ + bool have_alarm; + int cbase = data->num_sensors; + + if (attr->label) + pmbus_add_label(data, name, index, attr->label, + attr->paged ? page + 1 : 0); + pmbus_add_sensor(data, name, "input", index, page, attr->reg, + attr->class, true, true); + if (attr->sfunc) { + have_alarm = pmbus_add_limit_attrs(client, data, info, name, + index, page, cbase, attr); /* * Add generic alarm attribute only if there are no individual - * attributes. + * alarm attributes, and if there is a global alarm bit. */ - if (!have_alarm) - pmbus_add_boolean_reg(data, "in", "alarm", - in_index, + if (!have_alarm && attr->gbit) + pmbus_add_boolean_reg(data, name, "alarm", index, PB_STATUS_BASE + page, - PB_STATUS_VOUT_OV); - in_index++; + attr->gbit); } +} - /* - * Current sensors - */ +static void pmbus_add_sensor_attrs(struct i2c_client *client, + struct pmbus_data *data, + const char *name, + const struct pmbus_sensor_attr *attrs, + int nattrs) +{ + const struct pmbus_driver_info *info = data->info; + int index, i; - /* - * Input current sensors - */ - in_index = 1; - if (info->func[0] & PMBUS_HAVE_IIN) { - i0 = data->num_sensors; - pmbus_add_label(data, "curr", in_index, "iin", 0); - pmbus_add_sensor(data, "curr", "input", in_index, 0, - PMBUS_READ_IIN, PSC_CURRENT_IN, true, true); - if (pmbus_check_word_register(client, 0, - PMBUS_IIN_OC_WARN_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "curr", "max", in_index, - 0, PMBUS_IIN_OC_WARN_LIMIT, - PSC_CURRENT_IN, false, false); - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) { - pmbus_add_boolean_reg(data, "curr", "max_alarm", - in_index, - PB_STATUS_INPUT_BASE, - PB_IIN_OC_WARNING); - } - } - if (pmbus_check_word_register(client, 0, - PMBUS_IIN_OC_FAULT_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "curr", "crit", in_index, - 0, PMBUS_IIN_OC_FAULT_LIMIT, - PSC_CURRENT_IN, false, false); - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) - pmbus_add_boolean_reg(data, "curr", - "crit_alarm", - in_index, - PB_STATUS_INPUT_BASE, - PB_IIN_OC_FAULT); + index = 1; + for (i = 0; i < nattrs; i++) { + int page, pages; + + pages = attrs->paged ? info->pages : 1; + for (page = 0; page < pages; page++) { + if (!(info->func[page] & attrs->func)) + continue; + pmbus_add_sensor_attrs_one(client, data, info, name, + index, page, attrs); + index++; } - in_index++; + attrs++; } +} - /* - * Output current sensors - */ - for (page = 0; page < info->pages; page++) { - bool have_alarm = false; - - if (!(info->func[page] & PMBUS_HAVE_IOUT)) - continue; - - i0 = data->num_sensors; - pmbus_add_label(data, "curr", in_index, "iout", page + 1); - pmbus_add_sensor(data, "curr", "input", in_index, page, - PMBUS_READ_IOUT, PSC_CURRENT_OUT, true, true); - if (pmbus_check_word_register(client, page, - PMBUS_IOUT_OC_WARN_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "curr", "max", in_index, page, - PMBUS_IOUT_OC_WARN_LIMIT, - PSC_CURRENT_OUT, false, false); - if (info->func[page] & PMBUS_HAVE_STATUS_IOUT) { - pmbus_add_boolean_reg(data, "curr", "max_alarm", - in_index, - PB_STATUS_IOUT_BASE + - page, PB_IOUT_OC_WARNING); - have_alarm = true; - } - } - if (pmbus_check_word_register(client, page, - PMBUS_IOUT_UC_FAULT_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "curr", "lcrit", in_index, page, - PMBUS_IOUT_UC_FAULT_LIMIT, - PSC_CURRENT_OUT, false, false); - if (info->func[page] & PMBUS_HAVE_STATUS_IOUT) { - pmbus_add_boolean_reg(data, "curr", - "lcrit_alarm", - in_index, - PB_STATUS_IOUT_BASE + - page, PB_IOUT_UC_FAULT); - have_alarm = true; - } - } - if (pmbus_check_word_register(client, page, - PMBUS_IOUT_OC_FAULT_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "curr", "crit", in_index, page, - PMBUS_IOUT_OC_FAULT_LIMIT, - PSC_CURRENT_OUT, false, false); - if (info->func[page] & PMBUS_HAVE_STATUS_IOUT) { - pmbus_add_boolean_reg(data, "curr", - "crit_alarm", - in_index, - PB_STATUS_IOUT_BASE + - page, PB_IOUT_OC_FAULT); - have_alarm = true; - } - } - /* - * Add generic alarm attribute only if there are no individual - * attributes. - */ - if (!have_alarm) - pmbus_add_boolean_reg(data, "curr", "alarm", - in_index, - PB_STATUS_BASE + page, - PB_STATUS_IOUT_OC); - in_index++; +static const struct pmbus_limit_attr vin_limit_attrs[] = { + { + .reg = PMBUS_VIN_UV_WARN_LIMIT, + .attr = "min", + .alarm = "min_alarm", + .sbit = PB_VOLTAGE_UV_WARNING, + }, { + .reg = PMBUS_VIN_UV_FAULT_LIMIT, + .attr = "lcrit", + .alarm = "lcrit_alarm", + .sbit = PB_VOLTAGE_UV_FAULT, + }, { + .reg = PMBUS_VIN_OV_WARN_LIMIT, + .attr = "max", + .alarm = "max_alarm", + .sbit = PB_VOLTAGE_OV_WARNING, + }, { + .reg = PMBUS_VIN_OV_FAULT_LIMIT, + .attr = "crit", + .alarm = "crit_alarm", + .sbit = PB_VOLTAGE_OV_FAULT, + }, +}; + +static const struct pmbus_limit_attr vout_limit_attrs[] = { + { + .reg = PMBUS_VOUT_UV_WARN_LIMIT, + .attr = "min", + .alarm = "min_alarm", + .sbit = PB_VOLTAGE_UV_WARNING, + }, { + .reg = PMBUS_VOUT_UV_FAULT_LIMIT, + .attr = "lcrit", + .alarm = "lcrit_alarm", + .sbit = PB_VOLTAGE_UV_FAULT, + }, { + .reg = PMBUS_VOUT_OV_WARN_LIMIT, + .attr = "max", + .alarm = "max_alarm", + .sbit = PB_VOLTAGE_OV_WARNING, + }, { + .reg = PMBUS_VOUT_OV_FAULT_LIMIT, + .attr = "crit", + .alarm = "crit_alarm", + .sbit = PB_VOLTAGE_OV_FAULT, } +}; - /* - * Power sensors - */ - /* - * Input Power sensors - */ - in_index = 1; - if (info->func[0] & PMBUS_HAVE_PIN) { - i0 = data->num_sensors; - pmbus_add_label(data, "power", in_index, "pin", 0); - pmbus_add_sensor(data, "power", "input", in_index, - 0, PMBUS_READ_PIN, PSC_POWER, true, true); - if (pmbus_check_word_register(client, 0, - PMBUS_PIN_OP_WARN_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "power", "max", in_index, - 0, PMBUS_PIN_OP_WARN_LIMIT, PSC_POWER, - false, false); - if (info->func[0] & PMBUS_HAVE_STATUS_INPUT) - pmbus_add_boolean_reg(data, "power", - "alarm", - in_index, - PB_STATUS_INPUT_BASE, - PB_PIN_OP_WARNING); - } - in_index++; +static const struct pmbus_sensor_attr voltage_attributes[] = { + { + .reg = PMBUS_READ_VIN, + .class = PSC_VOLTAGE_IN, + .label = "vin", + .func = PMBUS_HAVE_VIN, + .sfunc = PMBUS_HAVE_STATUS_INPUT, + .sbase = PB_STATUS_INPUT_BASE, + .gbit = PB_STATUS_VIN_UV, + .limit = vin_limit_attrs, + .nlimit = ARRAY_SIZE(vin_limit_attrs), + }, { + .reg = PMBUS_READ_VCAP, + .class = PSC_VOLTAGE_IN, + .label = "vcap", + .func = PMBUS_HAVE_VCAP, + }, { + .reg = PMBUS_READ_VOUT, + .class = PSC_VOLTAGE_OUT, + .label = "vout", + .paged = true, + .func = PMBUS_HAVE_VOUT, + .sfunc = PMBUS_HAVE_STATUS_VOUT, + .sbase = PB_STATUS_VOUT_BASE, + .gbit = PB_STATUS_VOUT_OV, + .limit = vout_limit_attrs, + .nlimit = ARRAY_SIZE(vout_limit_attrs), } +}; - /* - * Output Power sensors - */ - for (page = 0; page < info->pages; page++) { - bool need_alarm = false; +/* Current attributes */ + +static const struct pmbus_limit_attr iin_limit_attrs[] = { + { + .reg = PMBUS_IIN_OC_WARN_LIMIT, + .attr = "max", + .alarm = "max_alarm", + .sbit = PB_IIN_OC_WARNING, + }, { + .reg = PMBUS_IIN_OC_FAULT_LIMIT, + .attr = "crit", + .alarm = "crit_alarm", + .sbit = PB_IIN_OC_FAULT, + } +}; - if (!(info->func[page] & PMBUS_HAVE_POUT)) - continue; +static const struct pmbus_limit_attr iout_limit_attrs[] = { + { + .reg = PMBUS_IOUT_OC_WARN_LIMIT, + .attr = "max", + .alarm = "max_alarm", + .sbit = PB_IOUT_OC_WARNING, + }, { + .reg = PMBUS_IOUT_UC_FAULT_LIMIT, + .attr = "lcrit", + .alarm = "lcrit_alarm", + .sbit = PB_IOUT_UC_FAULT, + }, { + .reg = PMBUS_IOUT_OC_FAULT_LIMIT, + .attr = "crit", + .alarm = "crit_alarm", + .sbit = PB_IOUT_OC_FAULT, + } +}; - i0 = data->num_sensors; - pmbus_add_label(data, "power", in_index, "pout", page + 1); - pmbus_add_sensor(data, "power", "input", in_index, page, - PMBUS_READ_POUT, PSC_POWER, true, true); - /* - * Per hwmon sysfs API, power_cap is to be used to limit output - * power. - * We have two registers related to maximum output power, - * PMBUS_POUT_MAX and PMBUS_POUT_OP_WARN_LIMIT. - * PMBUS_POUT_MAX matches the powerX_cap attribute definition. - * There is no attribute in the API to match - * PMBUS_POUT_OP_WARN_LIMIT. We use powerX_max for now. - */ - if (pmbus_check_word_register(client, page, PMBUS_POUT_MAX)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "power", "cap", in_index, page, - PMBUS_POUT_MAX, PSC_POWER, - false, false); - need_alarm = true; - } - if (pmbus_check_word_register(client, page, - PMBUS_POUT_OP_WARN_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "power", "max", in_index, page, - PMBUS_POUT_OP_WARN_LIMIT, PSC_POWER, - false, false); - need_alarm = true; - } - if (need_alarm && (info->func[page] & PMBUS_HAVE_STATUS_IOUT)) - pmbus_add_boolean_reg(data, "power", "alarm", - in_index, - PB_STATUS_IOUT_BASE + page, - PB_POUT_OP_WARNING - | PB_POWER_LIMITING); - - if (pmbus_check_word_register(client, page, - PMBUS_POUT_OP_FAULT_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "power", "crit", in_index, page, - PMBUS_POUT_OP_FAULT_LIMIT, PSC_POWER, - false, false); - if (info->func[page] & PMBUS_HAVE_STATUS_IOUT) - pmbus_add_boolean_reg(data, "power", - "crit_alarm", - in_index, - PB_STATUS_IOUT_BASE - + page, - PB_POUT_OP_FAULT); - } - in_index++; +static const struct pmbus_sensor_attr current_attributes[] = { + { + .reg = PMBUS_READ_IIN, + .class = PSC_CURRENT_IN, + .label = "iin", + .func = PMBUS_HAVE_IIN, + .sfunc = PMBUS_HAVE_STATUS_INPUT, + .sbase = PB_STATUS_INPUT_BASE, + .limit = iin_limit_attrs, + .nlimit = ARRAY_SIZE(iin_limit_attrs), + }, { + .reg = PMBUS_READ_IOUT, + .class = PSC_CURRENT_OUT, + .label = "iout", + .paged = true, + .func = PMBUS_HAVE_IOUT, + .sfunc = PMBUS_HAVE_STATUS_IOUT, + .sbase = PB_STATUS_IOUT_BASE, + .gbit = PB_STATUS_IOUT_OC, + .limit = iout_limit_attrs, + .nlimit = ARRAY_SIZE(iout_limit_attrs), } +}; - /* - * Temperature sensors - */ - in_index = 1; - for (page = 0; page < info->pages; page++) { - int t; +/* Power attributes */ - for (t = 0; t < ARRAY_SIZE(pmbus_temp_registers); t++) { - bool have_alarm = false; +static const struct pmbus_limit_attr pin_limit_attrs[] = { + { + .reg = PMBUS_PIN_OP_WARN_LIMIT, + .attr = "max", + .alarm = "alarm", + .sbit = PB_PIN_OP_WARNING, + } +}; - /* - * A PMBus chip may support any combination of - * temperature registers on any page. So we can not - * abort after a failure to detect a register, but have - * to continue checking for all registers on all pages. - */ - if (!(info->func[page] & pmbus_temp_flags[t])) - continue; +static const struct pmbus_limit_attr pout_limit_attrs[] = { + { + .reg = PMBUS_POUT_MAX, + .attr = "cap", + .alarm = "cap_alarm", + .sbit = PB_POWER_LIMITING, + }, { + .reg = PMBUS_POUT_OP_WARN_LIMIT, + .attr = "max", + .alarm = "max_alarm", + .sbit = PB_POUT_OP_WARNING, + }, { + .reg = PMBUS_POUT_OP_FAULT_LIMIT, + .attr = "crit", + .alarm = "crit_alarm", + .sbit = PB_POUT_OP_FAULT, + } +}; - if (!pmbus_check_word_register - (client, page, pmbus_temp_registers[t])) - continue; +static const struct pmbus_sensor_attr power_attributes[] = { + { + .reg = PMBUS_READ_PIN, + .class = PSC_POWER, + .label = "pin", + .func = PMBUS_HAVE_PIN, + .sfunc = PMBUS_HAVE_STATUS_INPUT, + .sbase = PB_STATUS_INPUT_BASE, + .limit = pin_limit_attrs, + .nlimit = ARRAY_SIZE(pin_limit_attrs), + }, { + .reg = PMBUS_READ_POUT, + .class = PSC_POWER, + .label = "pout", + .paged = true, + .func = PMBUS_HAVE_POUT, + .sfunc = PMBUS_HAVE_STATUS_IOUT, + .sbase = PB_STATUS_IOUT_BASE, + .limit = pout_limit_attrs, + .nlimit = ARRAY_SIZE(pout_limit_attrs), + } +}; - i0 = data->num_sensors; - pmbus_add_sensor(data, "temp", "input", in_index, page, - pmbus_temp_registers[t], - PSC_TEMPERATURE, true, true); +/* Temperature atributes */ + +static const struct pmbus_limit_attr temp_limit_attrs[] = { + { + .reg = PMBUS_UT_WARN_LIMIT, + .attr = "min", + .alarm = "min_alarm", + .sbit = PB_TEMP_UT_WARNING, + }, { + .reg = PMBUS_UT_FAULT_LIMIT, + .attr = "lcrit", + .alarm = "lcrit_alarm", + .sbit = PB_TEMP_UT_FAULT, + }, { + .reg = PMBUS_OT_WARN_LIMIT, + .attr = "max", + .alarm = "max_alarm", + .sbit = PB_TEMP_OT_WARNING, + }, { + .reg = PMBUS_OT_FAULT_LIMIT, + .attr = "crit", + .alarm = "crit_alarm", + .sbit = PB_TEMP_OT_FAULT, + } +}; - /* - * PMBus provides only one status register for TEMP1-3. - * Thus, we can not use the status register to determine - * which of the three sensors actually caused an alarm. - * Always compare current temperature against the limit - * registers to determine alarm conditions for a - * specific sensor. - * - * Since there is only one set of limit registers for - * up to three temperature sensors, we need to update - * all limit registers after the limit was changed for - * one of the sensors. This ensures that correct limits - * are reported for all temperature sensors. - */ - if (pmbus_check_word_register - (client, page, PMBUS_UT_WARN_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "temp", "min", in_index, - page, PMBUS_UT_WARN_LIMIT, - PSC_TEMPERATURE, true, false); - if (info->func[page] & PMBUS_HAVE_STATUS_TEMP) { - pmbus_add_boolean_cmp(data, "temp", - "min_alarm", in_index, i1, i0, - PB_STATUS_TEMP_BASE + page, - PB_TEMP_UT_WARNING); - have_alarm = true; - } - } - if (pmbus_check_word_register(client, page, - PMBUS_UT_FAULT_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "temp", "lcrit", - in_index, page, - PMBUS_UT_FAULT_LIMIT, - PSC_TEMPERATURE, true, false); - if (info->func[page] & PMBUS_HAVE_STATUS_TEMP) { - pmbus_add_boolean_cmp(data, "temp", - "lcrit_alarm", in_index, i1, i0, - PB_STATUS_TEMP_BASE + page, - PB_TEMP_UT_FAULT); - have_alarm = true; - } - } - if (pmbus_check_word_register - (client, page, PMBUS_OT_WARN_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "temp", "max", in_index, - page, PMBUS_OT_WARN_LIMIT, - PSC_TEMPERATURE, true, false); - if (info->func[page] & PMBUS_HAVE_STATUS_TEMP) { - pmbus_add_boolean_cmp(data, "temp", - "max_alarm", in_index, i0, i1, - PB_STATUS_TEMP_BASE + page, - PB_TEMP_OT_WARNING); - have_alarm = true; - } - } - if (pmbus_check_word_register(client, page, - PMBUS_OT_FAULT_LIMIT)) { - i1 = data->num_sensors; - pmbus_add_sensor(data, "temp", "crit", in_index, - page, PMBUS_OT_FAULT_LIMIT, - PSC_TEMPERATURE, true, false); - if (info->func[page] & PMBUS_HAVE_STATUS_TEMP) { - pmbus_add_boolean_cmp(data, "temp", - "crit_alarm", in_index, i0, i1, - PB_STATUS_TEMP_BASE + page, - PB_TEMP_OT_FAULT); - have_alarm = true; - } - } - /* - * Last resort - we were not able to create any alarm - * registers. Report alarm for all sensors using the - * status register temperature alarm bit. - */ - if (!have_alarm) - pmbus_add_boolean_reg(data, "temp", "alarm", - in_index, - PB_STATUS_BASE + page, - PB_STATUS_TEMPERATURE); - in_index++; - } +static const struct pmbus_sensor_attr temp_attributes[] = { + { + .reg = PMBUS_READ_TEMPERATURE_1, + .class = PSC_TEMPERATURE, + .paged = true, + .update = true, + .compare = true, + .func = PMBUS_HAVE_TEMP, + .sfunc = PMBUS_HAVE_STATUS_TEMP, + .sbase = PB_STATUS_TEMP_BASE, + .gbit = PB_STATUS_TEMPERATURE, + .limit = temp_limit_attrs, + .nlimit = ARRAY_SIZE(temp_limit_attrs), + }, { + .reg = PMBUS_READ_TEMPERATURE_2, + .class = PSC_TEMPERATURE, + .paged = true, + .update = true, + .compare = true, + .func = PMBUS_HAVE_TEMP2, + .sfunc = PMBUS_HAVE_STATUS_TEMP, + .sbase = PB_STATUS_TEMP_BASE, + .gbit = PB_STATUS_TEMPERATURE, + .limit = temp_limit_attrs, + .nlimit = ARRAY_SIZE(temp_limit_attrs), + }, { + .reg = PMBUS_READ_TEMPERATURE_3, + .class = PSC_TEMPERATURE, + .paged = true, + .update = true, + .compare = true, + .func = PMBUS_HAVE_TEMP3, + .sfunc = PMBUS_HAVE_STATUS_TEMP, + .sbase = PB_STATUS_TEMP_BASE, + .gbit = PB_STATUS_TEMPERATURE, + .limit = temp_limit_attrs, + .nlimit = ARRAY_SIZE(temp_limit_attrs), } +}; + +static const int pmbus_fan_registers[] = { + PMBUS_READ_FAN_SPEED_1, + PMBUS_READ_FAN_SPEED_2, + PMBUS_READ_FAN_SPEED_3, + PMBUS_READ_FAN_SPEED_4 +}; + +static const int pmbus_fan_config_registers[] = { + PMBUS_FAN_CONFIG_12, + PMBUS_FAN_CONFIG_12, + PMBUS_FAN_CONFIG_34, + PMBUS_FAN_CONFIG_34 +}; + +static const int pmbus_fan_status_registers[] = { + PMBUS_STATUS_FAN_12, + PMBUS_STATUS_FAN_12, + PMBUS_STATUS_FAN_34, + PMBUS_STATUS_FAN_34 +}; + +static const u32 pmbus_fan_flags[] = { + PMBUS_HAVE_FAN12, + PMBUS_HAVE_FAN12, + PMBUS_HAVE_FAN34, + PMBUS_HAVE_FAN34 +}; + +static const u32 pmbus_fan_status_flags[] = { + PMBUS_HAVE_STATUS_FAN12, + PMBUS_HAVE_STATUS_FAN12, + PMBUS_HAVE_STATUS_FAN34, + PMBUS_HAVE_STATUS_FAN34 +}; + +/* Fans */ +static void pmbus_add_fan_attributes(struct i2c_client *client, + struct pmbus_data *data) +{ + const struct pmbus_driver_info *info = data->info; + int index = 1; + int page; - /* - * Fans - */ - in_index = 1; for (page = 0; page < info->pages; page++) { int f; @@ -1404,9 +1295,7 @@ static void pmbus_find_attributes(struct i2c_client *client, break; if (!pmbus_check_word_register(client, page, - pmbus_fan_registers[f]) - || !pmbus_check_byte_register(client, page, - pmbus_fan_config_registers[f])) + pmbus_fan_registers[f])) break; /* @@ -1414,14 +1303,13 @@ static void pmbus_find_attributes(struct i2c_client *client, * Each fan configuration register covers multiple fans, * so we have to do some magic. */ - regval = pmbus_read_byte_data(client, page, + regval = _pmbus_read_byte_data(client, page, pmbus_fan_config_registers[f]); if (regval < 0 || (!(regval & (PB_FAN_1_INSTALLED >> ((f & 1) * 4))))) continue; - i0 = data->num_sensors; - pmbus_add_sensor(data, "fan", "input", in_index, page, + pmbus_add_sensor(data, "fan", "input", index, page, pmbus_fan_registers[f], PSC_FAN, true, true); @@ -1439,17 +1327,40 @@ static void pmbus_find_attributes(struct i2c_client *client, else base = PB_STATUS_FAN_BASE + page; pmbus_add_boolean_reg(data, "fan", "alarm", - in_index, base, + index, base, PB_FAN_FAN1_WARNING >> (f & 1)); pmbus_add_boolean_reg(data, "fan", "fault", - in_index, base, + index, base, PB_FAN_FAN1_FAULT >> (f & 1)); } - in_index++; + index++; } } } +static void pmbus_find_attributes(struct i2c_client *client, + struct pmbus_data *data) +{ + /* Voltage sensors */ + pmbus_add_sensor_attrs(client, data, "in", voltage_attributes, + ARRAY_SIZE(voltage_attributes)); + + /* Current sensors */ + pmbus_add_sensor_attrs(client, data, "curr", current_attributes, + ARRAY_SIZE(current_attributes)); + + /* Power sensors */ + pmbus_add_sensor_attrs(client, data, "power", power_attributes, + ARRAY_SIZE(power_attributes)); + + /* Temperature sensors */ + pmbus_add_sensor_attrs(client, data, "temp", temp_attributes, + ARRAY_SIZE(temp_attributes)); + + /* Fans */ + pmbus_add_fan_attributes(client, data); +} + /* * Identify chip parameters. * This function is called for all chips. diff --git a/drivers/hwmon/ucd9000.c b/drivers/hwmon/ucd9000.c new file mode 100644 index 000000000000..ace1c7319734 --- /dev/null +++ b/drivers/hwmon/ucd9000.c @@ -0,0 +1,278 @@ +/* + * Hardware monitoring driver for UCD90xxx Sequencer and System Health + * Controller series + * + * Copyright (C) 2011 Ericsson AB. + * + * 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 <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/err.h> +#include <linux/slab.h> +#include <linux/i2c.h> +#include <linux/i2c/pmbus.h> +#include "pmbus.h" + +enum chips { ucd9000, ucd90120, ucd90124, ucd9090, ucd90910 }; + +#define UCD9000_MONITOR_CONFIG 0xd5 +#define UCD9000_NUM_PAGES 0xd6 +#define UCD9000_FAN_CONFIG_INDEX 0xe7 +#define UCD9000_FAN_CONFIG 0xe8 +#define UCD9000_DEVICE_ID 0xfd + +#define UCD9000_MON_TYPE(x) (((x) >> 5) & 0x07) +#define UCD9000_MON_PAGE(x) ((x) & 0x0f) + +#define UCD9000_MON_VOLTAGE 1 +#define UCD9000_MON_TEMPERATURE 2 +#define UCD9000_MON_CURRENT 3 +#define UCD9000_MON_VOLTAGE_HW 4 + +#define UCD9000_NUM_FAN 4 + +struct ucd9000_data { + u8 fan_data[UCD9000_NUM_FAN][I2C_SMBUS_BLOCK_MAX]; + struct pmbus_driver_info info; +}; +#define to_ucd9000_data(_info) container_of(_info, struct ucd9000_data, info) + +static int ucd9000_get_fan_config(struct i2c_client *client, int fan) +{ + int fan_config = 0; + struct ucd9000_data *data + = to_ucd9000_data(pmbus_get_driver_info(client)); + + if (data->fan_data[fan][3] & 1) + fan_config |= PB_FAN_2_INSTALLED; /* Use lower bit position */ + + /* Pulses/revolution */ + fan_config |= (data->fan_data[fan][3] & 0x06) >> 1; + + return fan_config; +} + +static int ucd9000_read_byte_data(struct i2c_client *client, int page, int reg) +{ + int ret = 0; + int fan_config; + + switch (reg) { + case PMBUS_FAN_CONFIG_12: + if (page) + return -EINVAL; + + ret = ucd9000_get_fan_config(client, 0); + if (ret < 0) + return ret; + fan_config = ret << 4; + ret = ucd9000_get_fan_config(client, 1); + if (ret < 0) + return ret; + fan_config |= ret; + ret = fan_config; + break; + case PMBUS_FAN_CONFIG_34: + if (page) + return -EINVAL; + + ret = ucd9000_get_fan_config(client, 2); + if (ret < 0) + return ret; + fan_config = ret << 4; + ret = ucd9000_get_fan_config(client, 3); + if (ret < 0) + return ret; + fan_config |= ret; + ret = fan_config; + break; + default: + ret = -ENODATA; + break; + } + return ret; +} + +static const struct i2c_device_id ucd9000_id[] = { + {"ucd9000", ucd9000}, + {"ucd90120", ucd90120}, + {"ucd90124", ucd90124}, + {"ucd9090", ucd9090}, + {"ucd90910", ucd90910}, + {} +}; +MODULE_DEVICE_TABLE(i2c, ucd9000_id); + +static int ucd9000_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; + struct ucd9000_data *data; + struct pmbus_driver_info *info; + const struct i2c_device_id *mid; + int i, ret; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_BLOCK_DATA)) + return -ENODEV; + + ret = i2c_smbus_read_block_data(client, UCD9000_DEVICE_ID, + block_buffer); + if (ret < 0) { + dev_err(&client->dev, "Failed to read device ID\n"); + return ret; + } + block_buffer[ret] = '\0'; + dev_info(&client->dev, "Device ID %s\n", block_buffer); + + mid = NULL; + for (i = 0; i < ARRAY_SIZE(ucd9000_id); i++) { + mid = &ucd9000_id[i]; + if (!strncasecmp(mid->name, block_buffer, strlen(mid->name))) + break; + } + if (!mid || !strlen(mid->name)) { + dev_err(&client->dev, "Unsupported device\n"); + return -ENODEV; + } + + if (id->driver_data != ucd9000 && id->driver_data != mid->driver_data) + dev_notice(&client->dev, + "Device mismatch: Configured %s, detected %s\n", + id->name, mid->name); + + data = kzalloc(sizeof(struct ucd9000_data), GFP_KERNEL); + if (!data) + return -ENOMEM; + info = &data->info; + + ret = i2c_smbus_read_byte_data(client, UCD9000_NUM_PAGES); + if (ret < 0) { + dev_err(&client->dev, + "Failed to read number of active pages\n"); + goto out; + } + info->pages = ret; + if (!info->pages) { + dev_err(&client->dev, "No pages configured\n"); + ret = -ENODEV; + goto out; + } + + /* The internal temperature sensor is always active */ + info->func[0] = PMBUS_HAVE_TEMP; + + /* Everything else is configurable */ + ret = i2c_smbus_read_block_data(client, UCD9000_MONITOR_CONFIG, + block_buffer); + if (ret <= 0) { + dev_err(&client->dev, "Failed to read configuration data\n"); + ret = -ENODEV; + goto out; + } + for (i = 0; i < ret; i++) { + int page = UCD9000_MON_PAGE(block_buffer[i]); + + if (page >= info->pages) + continue; + + switch (UCD9000_MON_TYPE(block_buffer[i])) { + case UCD9000_MON_VOLTAGE: + case UCD9000_MON_VOLTAGE_HW: + info->func[page] |= PMBUS_HAVE_VOUT + | PMBUS_HAVE_STATUS_VOUT; + break; + case UCD9000_MON_TEMPERATURE: + info->func[page] |= PMBUS_HAVE_TEMP2 + | PMBUS_HAVE_STATUS_TEMP; + break; + case UCD9000_MON_CURRENT: + info->func[page] |= PMBUS_HAVE_IOUT + | PMBUS_HAVE_STATUS_IOUT; + break; + default: + break; + } + } + + /* Fan configuration */ + if (mid->driver_data == ucd90124) { + for (i = 0; i < UCD9000_NUM_FAN; i++) { + i2c_smbus_write_byte_data(client, + UCD9000_FAN_CONFIG_INDEX, i); + ret = i2c_smbus_read_block_data(client, + UCD9000_FAN_CONFIG, + data->fan_data[i]); + if (ret < 0) + goto out; + } + i2c_smbus_write_byte_data(client, UCD9000_FAN_CONFIG_INDEX, 0); + + info->read_byte_data = ucd9000_read_byte_data; + info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12 + | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34; + } + + ret = pmbus_do_probe(client, mid, info); + if (ret < 0) + goto out; + return 0; + +out: + kfree(data); + return ret; +} + +static int ucd9000_remove(struct i2c_client *client) +{ + int ret; + struct ucd9000_data *data; + + data = to_ucd9000_data(pmbus_get_driver_info(client)); + ret = pmbus_do_remove(client); + kfree(data); + return ret; +} + + +/* This is the driver that will be inserted */ +static struct i2c_driver ucd9000_driver = { + .driver = { + .name = "ucd9000", + }, + .probe = ucd9000_probe, + .remove = ucd9000_remove, + .id_table = ucd9000_id, +}; + +static int __init ucd9000_init(void) +{ + return i2c_add_driver(&ucd9000_driver); +} + +static void __exit ucd9000_exit(void) +{ + i2c_del_driver(&ucd9000_driver); +} + +MODULE_AUTHOR("Guenter Roeck"); +MODULE_DESCRIPTION("PMBus driver for TI UCD90xxx"); +MODULE_LICENSE("GPL"); +module_init(ucd9000_init); +module_exit(ucd9000_exit); diff --git a/drivers/hwmon/ucd9200.c b/drivers/hwmon/ucd9200.c new file mode 100644 index 000000000000..ffcc1cf3609d --- /dev/null +++ b/drivers/hwmon/ucd9200.c @@ -0,0 +1,210 @@ +/* + * Hardware monitoring driver for ucd9200 series Digital PWM System Controllers + * + * Copyright (C) 2011 Ericsson AB. + * + * 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 <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/err.h> +#include <linux/slab.h> +#include <linux/i2c.h> +#include <linux/i2c/pmbus.h> +#include "pmbus.h" + +#define UCD9200_PHASE_INFO 0xd2 +#define UCD9200_DEVICE_ID 0xfd + +enum chips { ucd9200, ucd9220, ucd9222, ucd9224, ucd9240, ucd9244, ucd9246, + ucd9248 }; + +static const struct i2c_device_id ucd9200_id[] = { + {"ucd9200", ucd9200}, + {"ucd9220", ucd9220}, + {"ucd9222", ucd9222}, + {"ucd9224", ucd9224}, + {"ucd9240", ucd9240}, + {"ucd9244", ucd9244}, + {"ucd9246", ucd9246}, + {"ucd9248", ucd9248}, + {} +}; +MODULE_DEVICE_TABLE(i2c, ucd9200_id); + +static int ucd9200_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; + struct pmbus_driver_info *info; + const struct i2c_device_id *mid; + int i, j, ret; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_BLOCK_DATA)) + return -ENODEV; + + ret = i2c_smbus_read_block_data(client, UCD9200_DEVICE_ID, + block_buffer); + if (ret < 0) { + dev_err(&client->dev, "Failed to read device ID\n"); + return ret; + } + block_buffer[ret] = '\0'; + dev_info(&client->dev, "Device ID %s\n", block_buffer); + + mid = NULL; + for (i = 0; i < ARRAY_SIZE(ucd9200_id); i++) { + mid = &ucd9200_id[i]; + if (!strncasecmp(mid->name, block_buffer, strlen(mid->name))) + break; + } + if (!mid || !strlen(mid->name)) { + dev_err(&client->dev, "Unsupported device\n"); + return -ENODEV; + } + if (id->driver_data != ucd9200 && id->driver_data != mid->driver_data) + dev_notice(&client->dev, + "Device mismatch: Configured %s, detected %s\n", + id->name, mid->name); + + info = kzalloc(sizeof(struct pmbus_driver_info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + ret = i2c_smbus_read_block_data(client, UCD9200_PHASE_INFO, + block_buffer); + if (ret < 0) { + dev_err(&client->dev, "Failed to read phase information\n"); + goto out; + } + + /* + * Calculate number of configured pages (rails) from PHASE_INFO + * register. + * Rails have to be sequential, so we can abort after finding + * the first unconfigured rail. + */ + info->pages = 0; + for (i = 0; i < ret; i++) { + if (!block_buffer[i]) + break; + info->pages++; + } + if (!info->pages) { + dev_err(&client->dev, "No rails configured\n"); + ret = -ENODEV; + goto out; + } + dev_info(&client->dev, "%d rails configured\n", info->pages); + + /* + * Set PHASE registers on all pages to 0xff to ensure that phase + * specific commands will apply to all phases of a given page (rail). + * This only affects the READ_IOUT and READ_TEMPERATURE2 registers. + * READ_IOUT will return the sum of currents of all phases of a rail, + * and READ_TEMPERATURE2 will return the maximum temperature detected + * for the the phases of the rail. + */ + for (i = 0; i < info->pages; i++) { + /* + * Setting PAGE & PHASE fails once in a while for no obvious + * reason, so we need to retry a couple of times. + */ + for (j = 0; j < 3; j++) { + ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, i); + if (ret < 0) + continue; + ret = i2c_smbus_write_byte_data(client, PMBUS_PHASE, + 0xff); + if (ret < 0) + continue; + break; + } + if (ret < 0) { + dev_err(&client->dev, + "Failed to initialize PHASE registers\n"); + goto out; + } + } + if (info->pages > 1) + i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0); + + info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT | + PMBUS_HAVE_IIN | PMBUS_HAVE_PIN | + PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | + PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | + PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP | + PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP; + + for (i = 1; i < info->pages; i++) + info->func[i] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | + PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | + PMBUS_HAVE_POUT | + PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP; + + /* ucd9240 supports a single fan */ + if (mid->driver_data == ucd9240) + info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12; + + ret = pmbus_do_probe(client, mid, info); + if (ret < 0) + goto out; + return 0; +out: + kfree(info); + return ret; +} + +static int ucd9200_remove(struct i2c_client *client) +{ + int ret; + const struct pmbus_driver_info *info; + + info = pmbus_get_driver_info(client); + ret = pmbus_do_remove(client); + kfree(info); + return ret; +} + + +/* This is the driver that will be inserted */ +static struct i2c_driver ucd9200_driver = { + .driver = { + .name = "ucd9200", + }, + .probe = ucd9200_probe, + .remove = ucd9200_remove, + .id_table = ucd9200_id, +}; + +static int __init ucd9200_init(void) +{ + return i2c_add_driver(&ucd9200_driver); +} + +static void __exit ucd9200_exit(void) +{ + i2c_del_driver(&ucd9200_driver); +} + +MODULE_AUTHOR("Guenter Roeck"); +MODULE_DESCRIPTION("PMBus driver for TI UCD922x, UCD924x"); +MODULE_LICENSE("GPL"); +module_init(ucd9200_init); +module_exit(ucd9200_exit); |