adm1025.c revision 90d6619a916062cb75a176aacb318d108758b4a5
11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * adm1025.c 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2000 Chen-Yuan Wu <gwu@esoft.com> 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The ADM1025 is a sensor chip made by Analog Devices. It reports up to 6 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * voltages (including its own power source) and up to two temperatures 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (its own plus up to one external one). Voltages are scaled internally 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (which is not the common way) with ratios such that the nominal value 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * of each voltage correspond to a register value of 192 (which means a 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * resolution of about 0.5% of the nominal value). Temperature values are 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * reported with a 1 deg resolution and a 3 deg accuracy. Complete 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * datasheet can be obtained from Analog's website at: 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * http://www.analog.com/Analog_Root/productPage/productHome/0,2121,ADM1025,00.html 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This driver also supports the ADM1025A, which differs from the ADM1025 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * only in that it has "open-drain VID inputs while the ADM1025 has 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * on-chip 100k pull-ups on the VID inputs". It doesn't make any 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * difference for us. 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This driver also supports the NE1619, a sensor chip made by Philips. 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * That chip is similar to the ADM1025A, with a few differences. The only 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * difference that matters to us is that the NE1619 has only two possible 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * addresses while the ADM1025A has a third one. Complete datasheet can be 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * obtained from Philips's website at: 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * http://www.semiconductors.philips.com/pip/NE1619DS.html 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Since the ADM1025 was the first chipset supported by this driver, most 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * comments will refer to this chipset, but are actually general and 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * concern all supported chipsets, unless mentioned otherwise. 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is free software; you can redistribute it and/or modify 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it under the terms of the GNU General Public License as published by 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (at your option) any later version. 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is distributed in the hope that it will be useful, 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * GNU General Public License for more details. 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * You should have received a copy of the GNU General Public License 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * along with this program; if not, write to the Free Software 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h> 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h> 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/slab.h> 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/jiffies.h> 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/i2c.h> 53943b0830cebe4711354945ed3cb44e84152aaca0Mark M. Hoffman#include <linux/hwmon.h> 54303760b44a7a142cb9f4c9df4609fb63bbda98dbJean Delvare#include <linux/hwmon-vid.h> 55943b0830cebe4711354945ed3cb44e84152aaca0Mark M. Hoffman#include <linux/err.h> 569a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar#include <linux/mutex.h> 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Addresses to scan 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ADM1025 and ADM1025A have three possible addresses: 0x2c, 0x2d and 0x2e. 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * NE1619 has two possible addresses: 0x2c and 0x2d. 621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Insmod parameters 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 70f4b50261207c987913f076d867c2e154d71fd012Jean DelvareI2C_CLIENT_INSMOD_2(adm1025, ne1619); 711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The ADM1025 registers 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_MAN_ID 0x3E 771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_CHIP_ID 0x3F 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_CONFIG 0x40 791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_STATUS1 0x41 801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_STATUS2 0x42 811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_IN(nr) (0x20 + (nr)) 821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_IN_MAX(nr) (0x2B + (nr) * 2) 831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_IN_MIN(nr) (0x2C + (nr) * 2) 841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_TEMP(nr) (0x26 + (nr)) 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_TEMP_HIGH(nr) (0x37 + (nr) * 2) 861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_TEMP_LOW(nr) (0x38 + (nr) * 2) 871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_VID 0x47 881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADM1025_REG_VID4 0x49 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Conversions and various macros 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The ADM1025 uses signed 8-bit values for temperatures. 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 }; 961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192) 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \ 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (val) * 192 >= (scale) * 255 ? 255 : \ 1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ((val) * 192 + (scale)/2) / (scale)) 1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define TEMP_FROM_REG(reg) ((reg) * 1000) 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \ 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (val) >= 126500 ? 127 : \ 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((val) < 0 ? (val)-500 : (val)+500) / 1000)) 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Functions declaration 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int adm1025_attach_adapter(struct i2c_adapter *adapter); 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int adm1025_detect(struct i2c_adapter *adapter, int address, int kind); 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void adm1025_init_client(struct i2c_client *client); 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int adm1025_detach_client(struct i2c_client *client); 1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct adm1025_data *adm1025_update_device(struct device *dev); 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Driver data (common to all clients) 1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct i2c_driver adm1025_driver = { 122cdaf79349c7d24e1d33acb6497849c9e956a33eaLaurent Riffard .driver = { 123cdaf79349c7d24e1d33acb6497849c9e956a33eaLaurent Riffard .name = "adm1025", 124cdaf79349c7d24e1d33acb6497849c9e956a33eaLaurent Riffard }, 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .id = I2C_DRIVERID_ADM1025, 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .attach_adapter = adm1025_attach_adapter, 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .detach_client = adm1025_detach_client, 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Client data (each client gets its own) 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct adm1025_data { 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct i2c_client client; 1361beeffe43311f64df8dd0ab08ff6b1858c58363fTony Jones struct device *hwmon_dev; 1379a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar struct mutex update_lock; 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char valid; /* zero until following fields are valid */ 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long last_updated; /* in jiffies */ 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 in[6]; /* register value */ 1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 in_max[6]; /* register value */ 1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 in_min[6]; /* register value */ 1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds s8 temp[2]; /* register value */ 1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds s8 temp_min[2]; /* register value */ 1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds s8 temp_max[2]; /* register value */ 1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u16 alarms; /* register values, combined */ 1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 vid; /* register values, combined */ 1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 vrm; 1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Sysfs stuff 1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define show_in(offset) \ 15774880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t show_in##offset(struct device *dev, struct device_attribute *attr, char *buf) \ 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = adm1025_update_device(dev); \ 1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \ 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds in_scale[offset])); \ 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 16374880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = adm1025_update_device(dev); \ 1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \ 1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds in_scale[offset])); \ 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 16974880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ 1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = adm1025_update_device(dev); \ 1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \ 1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds in_scale[offset])); \ 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_in(0); 1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_in(1); 1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_in(2); 1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_in(3); 1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_in(4); 1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_in(5); 1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define show_temp(offset) \ 18474880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t show_temp##offset(struct device *dev, struct device_attribute *attr, char *buf) \ 1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = adm1025_update_device(dev); \ 1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \ 1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 18974880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 1911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = adm1025_update_device(dev); \ 1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \ 1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 19474880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ 1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = adm1025_update_device(dev); \ 1971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \ 1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}\ 1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp##offset, NULL); 2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_temp(1); 2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_temp(2); 2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define set_in(offset) \ 20474880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ 2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size_t count) \ 2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct i2c_client *client = to_i2c_client(dev); \ 2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = i2c_get_clientdata(client); \ 2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds long val = simple_strtol(buf, NULL, 10); \ 2101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 2119a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar mutex_lock(&data->update_lock); \ 2121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \ 2131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \ 2141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->in_min[offset]); \ 2159a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar mutex_unlock(&data->update_lock); \ 2161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; \ 2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 21874880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ 2191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size_t count) \ 2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct i2c_client *client = to_i2c_client(dev); \ 2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = i2c_get_clientdata(client); \ 2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds long val = simple_strtol(buf, NULL, 10); \ 2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 2259a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar mutex_lock(&data->update_lock); \ 2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \ 2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \ 2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->in_max[offset]); \ 2299a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar mutex_unlock(&data->update_lock); \ 2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; \ 2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \ 2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_in##offset##_min, set_in##offset##_min); \ 2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \ 2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_in##offset##_max, set_in##offset##_max); 2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsset_in(0); 2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsset_in(1); 2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsset_in(2); 2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsset_in(3); 2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsset_in(4); 2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsset_in(5); 2421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define set_temp(offset) \ 24474880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ 2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size_t count) \ 2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct i2c_client *client = to_i2c_client(dev); \ 2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = i2c_get_clientdata(client); \ 2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds long val = simple_strtol(buf, NULL, 10); \ 2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 2519a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar mutex_lock(&data->update_lock); \ 2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->temp_min[offset-1] = TEMP_TO_REG(val); \ 2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \ 2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->temp_min[offset-1]); \ 2559a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar mutex_unlock(&data->update_lock); \ 2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; \ 2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 25874880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ 2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size_t count) \ 2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct i2c_client *client = to_i2c_client(dev); \ 2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = i2c_get_clientdata(client); \ 2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds long val = simple_strtol(buf, NULL, 10); \ 2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 2659a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar mutex_lock(&data->update_lock); \ 2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->temp_max[offset-1] = TEMP_TO_REG(val); \ 2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \ 2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->temp_max[offset-1]); \ 2699a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar mutex_unlock(&data->update_lock); \ 2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; \ 2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ 2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_temp##offset##_min, set_temp##offset##_min); \ 2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \ 2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_temp##offset##_max, set_temp##offset##_max); 2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsset_temp(1); 2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsset_temp(2); 2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 27974880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = adm1025_update_device(dev); 2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return sprintf(buf, "%u\n", data->alarms); 2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 2851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 28674880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = adm1025_update_device(dev); 2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); 2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 291937df8df907ce63b0f7e19adf6e3cdef1687fac3Grant Coadystatic DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 29374880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 29590d6619a916062cb75a176aacb318d108758b4a5Jean Delvare struct adm1025_data *data = dev_get_drvdata(dev); 2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return sprintf(buf, "%u\n", data->vrm); 2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 29874880c063b06efd103c924abfe19d9d8fa4864c4Yani Ioannoustatic ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct i2c_client *client = to_i2c_client(dev); 3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = i2c_get_clientdata(client); 3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->vrm = simple_strtoul(buf, NULL, 10); 3031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; 3041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 3061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 3081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Real code 3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int adm1025_attach_adapter(struct i2c_adapter *adapter) 3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!(adapter->class & I2C_CLASS_HWMON)) 3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 3152ed2dc3c116d26fc6a9384e83d136b15cc203b6cJean Delvare return i2c_probe(adapter, &addr_data, adm1025_detect); 3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 318681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffmanstatic struct attribute *adm1025_attributes[] = { 319681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in0_input.attr, 320681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in1_input.attr, 321681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in2_input.attr, 322681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in3_input.attr, 323681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in5_input.attr, 324681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in0_min.attr, 325681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in1_min.attr, 326681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in2_min.attr, 327681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in3_min.attr, 328681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in5_min.attr, 329681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in0_max.attr, 330681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in1_max.attr, 331681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in2_max.attr, 332681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in3_max.attr, 333681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in5_max.attr, 334681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_temp1_input.attr, 335681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_temp2_input.attr, 336681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_temp1_min.attr, 337681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_temp2_min.attr, 338681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_temp1_max.attr, 339681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_temp2_max.attr, 340681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_alarms.attr, 341681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_cpu0_vid.attr, 342681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_vrm.attr, 343681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman NULL 344681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman}; 345681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman 346681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffmanstatic const struct attribute_group adm1025_group = { 347681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman .attrs = adm1025_attributes, 348681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman}; 349681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman 350681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffmanstatic struct attribute *adm1025_attributes_opt[] = { 351681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in4_input.attr, 352681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in4_min.attr, 353681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in4_max.attr, 354681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman NULL 355681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman}; 356681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman 357681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffmanstatic const struct attribute_group adm1025_group_opt = { 358681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman .attrs = adm1025_attributes_opt, 359681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman}; 360681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman 3611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 3621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The following function does more than just detection. If detection 3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * succeeds, it also registers the new chip. 3641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) 3661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct i2c_client *new_client; 3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data; 3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err = 0; 3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const char *name = ""; 3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 config; 3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto exit; 3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 376ba9c2e8d15da029ea3051c95e446b2d638ef02e2Deepak Saxena if (!(data = kzalloc(sizeof(struct adm1025_data), GFP_KERNEL))) { 3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds err = -ENOMEM; 3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto exit; 3791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* The common I2C client data is placed right before the 3821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025-specific data. */ 3831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds new_client = &data->client; 3841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i2c_set_clientdata(new_client, data); 3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds new_client->addr = address; 3861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds new_client->adapter = adapter; 3871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds new_client->driver = &adm1025_driver; 3881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds new_client->flags = 0; 3891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 3911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Now we do the remaining detection. A negative kind means that 3921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the driver was loaded with no force parameter (default), so we 3931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * must both detect and identify the chip. A zero kind means that 3941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the driver was loaded with the force parameter, the detection 3951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * step shall be skipped. A positive kind means that the driver 3961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * was loaded with the force parameter and a given kind of chip is 3971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * requested, so both the detection and the identification steps 3981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * are skipped. 3991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 4001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds config = i2c_smbus_read_byte_data(new_client, ADM1025_REG_CONFIG); 4011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (kind < 0) { /* detection */ 4021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((config & 0x80) != 0x00 4031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds || (i2c_smbus_read_byte_data(new_client, 4041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_STATUS1) & 0xC0) != 0x00 4051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds || (i2c_smbus_read_byte_data(new_client, 4061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_STATUS2) & 0xBC) != 0x00) { 4071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev_dbg(&adapter->dev, 4081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "ADM1025 detection failed at 0x%02x.\n", 4091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds address); 4101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto exit_free; 4111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (kind <= 0) { /* identification */ 4151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 man_id, chip_id; 4161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds man_id = i2c_smbus_read_byte_data(new_client, 4181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_MAN_ID); 4191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds chip_id = i2c_smbus_read_byte_data(new_client, 4201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_CHIP_ID); 4211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (man_id == 0x41) { /* Analog Devices */ 4231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((chip_id & 0xF0) == 0x20) { /* ADM1025/ADM1025A */ 4241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kind = adm1025; 4251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else 4271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (man_id == 0xA1) { /* Philips */ 4281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (address != 0x2E 4291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds && (chip_id & 0xF0) == 0x20) { /* NE1619 */ 4301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kind = ne1619; 4311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (kind <= 0) { /* identification failed */ 4351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev_info(&adapter->dev, 4361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "Unsupported chip (man_id=0x%02X, " 4371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "chip_id=0x%02X).\n", man_id, chip_id); 4381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto exit_free; 4391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (kind == adm1025) { 4431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds name = "adm1025"; 4441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else if (kind == ne1619) { 4451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds name = "ne1619"; 4461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* We can fill in the remaining client fields */ 4491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds strlcpy(new_client->name, name, I2C_NAME_SIZE); 4501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->valid = 0; 4519a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar mutex_init(&data->update_lock); 4521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Tell the I2C layer a new client has arrived */ 4541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((err = i2c_attach_client(new_client))) 4551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto exit_free; 4561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Initialize the ADM1025 chip */ 4581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds adm1025_init_client(new_client); 4591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Register sysfs hooks */ 461681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1025_group))) 462943b0830cebe4711354945ed3cb44e84152aaca0Mark M. Hoffman goto exit_detach; 4631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Pin 11 is either in4 (+12V) or VID4 */ 4651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!(config & 0x20)) { 466681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman if ((err = device_create_file(&new_client->dev, 467681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in4_input)) 468681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman || (err = device_create_file(&new_client->dev, 469681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in4_min)) 470681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman || (err = device_create_file(&new_client->dev, 471681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman &dev_attr_in4_max))) 472681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman goto exit_remove; 473681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman } 474681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman 4751beeffe43311f64df8dd0ab08ff6b1858c58363fTony Jones data->hwmon_dev = hwmon_device_register(&new_client->dev); 4761beeffe43311f64df8dd0ab08ff6b1858c58363fTony Jones if (IS_ERR(data->hwmon_dev)) { 4771beeffe43311f64df8dd0ab08ff6b1858c58363fTony Jones err = PTR_ERR(data->hwmon_dev); 478681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman goto exit_remove; 4791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 4821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 483681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffmanexit_remove: 484681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman sysfs_remove_group(&new_client->dev.kobj, &adm1025_group); 485681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman sysfs_remove_group(&new_client->dev.kobj, &adm1025_group_opt); 486943b0830cebe4711354945ed3cb44e84152aaca0Mark M. Hoffmanexit_detach: 487943b0830cebe4711354945ed3cb44e84152aaca0Mark M. Hoffman i2c_detach_client(new_client); 4881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsexit_free: 4891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(data); 4901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsexit: 4911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 4921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 4931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void adm1025_init_client(struct i2c_client *client) 4951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 4961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 reg; 4971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = i2c_get_clientdata(client); 4981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i; 4991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 500303760b44a7a142cb9f4c9df4609fb63bbda98dbJean Delvare data->vrm = vid_which_vrm(); 5011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 5031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Set high limits 5041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Usually we avoid setting limits on driver init, but it happens 5051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * that the ADM1025 comes with stupid default limits (all registers 5061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * set to 0). In case the chip has not gone through any limit 5071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * setting yet, we better set the high limits to the max so that 5081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * no alarm triggers. 5091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 5101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i=0; i<6; i++) { 5111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds reg = i2c_smbus_read_byte_data(client, 5121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_IN_MAX(i)); 5131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (reg == 0) 5141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i2c_smbus_write_byte_data(client, 5151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_IN_MAX(i), 5161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 0xFF); 5171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i=0; i<2; i++) { 5191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds reg = i2c_smbus_read_byte_data(client, 5201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_TEMP_HIGH(i)); 5211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (reg == 0) 5221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i2c_smbus_write_byte_data(client, 5231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_TEMP_HIGH(i), 5241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 0x7F); 5251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 5281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Start the conversions 5291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 5301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds reg = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG); 5311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!(reg & 0x01)) 5321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i2c_smbus_write_byte_data(client, ADM1025_REG_CONFIG, 5331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (reg&0x7E)|0x01); 5341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int adm1025_detach_client(struct i2c_client *client) 5371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 538943b0830cebe4711354945ed3cb44e84152aaca0Mark M. Hoffman struct adm1025_data *data = i2c_get_clientdata(client); 5391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int err; 5401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5411beeffe43311f64df8dd0ab08ff6b1858c58363fTony Jones hwmon_device_unregister(data->hwmon_dev); 542681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman sysfs_remove_group(&client->dev.kobj, &adm1025_group); 543681c6f7a6702f208d48b501c8829dbc03a2ca238Mark M. Hoffman sysfs_remove_group(&client->dev.kobj, &adm1025_group_opt); 544943b0830cebe4711354945ed3cb44e84152aaca0Mark M. Hoffman 5457bef559455fc71f66f8573cc1aafe1dd33966c1cJean Delvare if ((err = i2c_detach_client(client))) 5461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return err; 5471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 548943b0830cebe4711354945ed3cb44e84152aaca0Mark M. Hoffman kfree(data); 5491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 5501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct adm1025_data *adm1025_update_device(struct device *dev) 5531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 5541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct i2c_client *client = to_i2c_client(dev); 5551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct adm1025_data *data = i2c_get_clientdata(client); 5561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5579a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar mutex_lock(&data->update_lock); 5581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 5601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i; 5611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev_dbg(&client->dev, "Updating data.\n"); 5631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i=0; i<6; i++) { 5641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->in[i] = i2c_smbus_read_byte_data(client, 5651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_IN(i)); 5661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->in_min[i] = i2c_smbus_read_byte_data(client, 5671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_IN_MIN(i)); 5681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->in_max[i] = i2c_smbus_read_byte_data(client, 5691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_IN_MAX(i)); 5701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i=0; i<2; i++) { 5721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->temp[i] = i2c_smbus_read_byte_data(client, 5731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_TEMP(i)); 5741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->temp_min[i] = i2c_smbus_read_byte_data(client, 5751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_TEMP_LOW(i)); 5761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->temp_max[i] = i2c_smbus_read_byte_data(client, 5771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_TEMP_HIGH(i)); 5781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->alarms = i2c_smbus_read_byte_data(client, 5801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_STATUS1) 5811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds | (i2c_smbus_read_byte_data(client, 5821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_STATUS2) << 8); 5831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->vid = (i2c_smbus_read_byte_data(client, 5841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_VID) & 0x0f) 5851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds | ((i2c_smbus_read_byte_data(client, 5861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ADM1025_REG_VID4) & 0x01) << 4); 5871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->last_updated = jiffies; 5891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data->valid = 1; 5901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5929a61bf6300533d3b64d7ff29adfec00e596de67dIngo Molnar mutex_unlock(&data->update_lock); 5931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return data; 5951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int __init sensors_adm1025_init(void) 5981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 5991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return i2c_add_driver(&adm1025_driver); 6001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void __exit sensors_adm1025_exit(void) 6031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i2c_del_driver(&adm1025_driver); 6051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 6081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_DESCRIPTION("ADM1025 driver"); 6091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL"); 6101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_init(sensors_adm1025_init); 6121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_exit(sensors_adm1025_exit); 613