Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging

Pull hwmon updates from Jean Delvare:
"We have support for the MCP3021, MC13892 and GMT G781, automatic fan
speed control for LM63/LM64 chips, and a few clean-ups."

* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging:
hwmon: Add MCP3021 ADC driver
hwmon: (mc13783-adc) Add support for the MC13892 PMIC
hwmon: (mc13783-adc) Remove space before tab
hwmon: (lm63) Let the user adjust the lookup table
hwmon: (lm63) Make fan speed control strategy changeable
hwmon: (lm63) Reorganize the code
hwmon: (lm90) Restore original configuration if probe function fails
hwmon: (lm90) Add support for GMT G781
hwmon: (lm90) Fix multi-line comments
hwmon: (w83795) Fix multi-line comments
hwmon: (w83795) Unconditionally support manual fan speed control
hwmon: (fam15h_power) Increase output resolution
hwmon: (fam15h_power) Correct sign extension of running_avg_capture

+827 -380
+4
Documentation/hwmon/lm90
··· 118 118 Addresses scanned: I2C 0x48 through 0x4F 119 119 Datasheet: Publicly available at NXP website 120 120 http://ics.nxp.com/products/interface/datasheet/sa56004x.pdf 121 + * GMT G781 122 + Prefix: 'g781' 123 + Addresses scanned: I2C 0x4c, 0x4d 124 + Datasheet: Not publicly available from GMT 121 125 122 126 Author: Jean Delvare <khali@linux-fr.org> 123 127
+37 -13
Documentation/hwmon/mc13783-adc
··· 3 3 4 4 Supported chips: 5 5 * Freescale Atlas MC13783 6 - Prefix: 'mc13783_adc' 6 + Prefix: 'mc13783' 7 7 Datasheet: http://www.freescale.com/files/rf_if/doc/data_sheet/MC13783.pdf?fsrch=1 8 + * Freescale Atlas MC13892 9 + Prefix: 'mc13892' 10 + Datasheet: http://cache.freescale.com/files/analog/doc/data_sheet/MC13892.pdf?fsrch=1&sr=1 8 11 9 12 Authors: 10 13 Sascha Hauer <s.hauer@pengutronix.de> ··· 16 13 Description 17 14 ----------- 18 15 19 - The Freescale MC13783 is a Power Management and Audio Circuit. Among 20 - other things it contains a 10-bit A/D converter. The converter has 16 21 - channels which can be used in different modes. 22 - The A/D converter has a resolution of 2.25mV. Channels 0-4 have 23 - a dedicated meaning with chip internal scaling applied. Channels 5-7 24 - can be used as general purpose inputs or alternatively in a dedicated 25 - mode. Channels 12-15 are occupied by the touchscreen if it's active. 16 + The Freescale MC13783 and MC13892 are Power Management and Audio Circuits. 17 + Among other things they contain a 10-bit A/D converter. The converter has 16 18 + (MC13783) resp. 12 (MC13892) channels which can be used in different modes. The 19 + A/D converter has a resolution of 2.25mV. 26 20 27 - Currently the driver only supports channels 2 and 5-15 with no alternative 28 - modes for channels 5-7. 21 + Some channels can be used as General Purpose inputs or in a dedicated mode with 22 + a chip internal scaling applied . 29 23 30 - See this table for the meaning of the different channels and their chip 31 - internal scaling: 24 + Currently the driver only supports the Application Supply channel (BP / BPSNS), 25 + the General Purpose inputs and touchscreen. 32 26 27 + See the following tables for the meaning of the different channels and their 28 + chip internal scaling: 29 + 30 + MC13783: 33 31 Channel Signal Input Range Scaling 34 32 ------------------------------------------------------------------------------- 35 33 0 Battery Voltage (BATT) 2.50 - 4.65V -2.40V ··· 38 34 2 Application Supply (BP) 2.50 - 4.65V -2.40V 39 35 3 Charger Voltage (CHRGRAW) 0 - 10V / /5 40 36 0 - 20V /10 41 - 4 Charger Current (CHRGISNSP-CHRGISNSN) -0.25V - 0.25V x4 37 + 4 Charger Current (CHRGISNSP-CHRGISNSN) -0.25 - 0.25V x4 42 38 5 General Purpose ADIN5 / Battery Pack Thermistor 0 - 2.30V No 43 39 6 General Purpose ADIN6 / Backup Voltage (LICELL) 0 - 2.30V / No / 44 40 1.50 - 3.50V -1.20V ··· 52 48 13 General Purpose TSX2 / Touchscreen X-plate 2 0 - 2.30V No 53 49 14 General Purpose TSY1 / Touchscreen Y-plate 1 0 - 2.30V No 54 50 15 General Purpose TSY2 / Touchscreen Y-plate 2 0 - 2.30V No 51 + 52 + MC13892: 53 + Channel Signal Input Range Scaling 54 + ------------------------------------------------------------------------------- 55 + 0 Battery Voltage (BATT) 0 - 4.8V /2 56 + 1 Battery Current (BATT - BATTISNSCC) -60 - 60 mV x20 57 + 2 Application Supply (BPSNS) 0 - 4.8V /2 58 + 3 Charger Voltage (CHRGRAW) 0 - 12V / /5 59 + 0 - 20V /10 60 + 4 Charger Current (CHRGISNS-BPSNS) / -0.3 - 0.3V / x4 / 61 + Touchscreen X-plate 1 0 - 2.4V No 62 + 5 General Purpose ADIN5 / Battery Pack Thermistor 0 - 2.4V No 63 + 6 General Purpose ADIN6 / Backup Voltage (LICELL) 0 - 2.4V / No 64 + Backup Voltage (LICELL) 0 - 3.6V x2/3 65 + 7 General Purpose ADIN7 / UID / Die Temperature 0 - 2.4V / No / 66 + 0 - 4.8V /2 67 + 12 General Purpose TSX1 / Touchscreen X-plate 1 0 - 2.4V No 68 + 13 General Purpose TSX2 / Touchscreen X-plate 2 0 - 2.4V No 69 + 14 General Purpose TSY1 / Touchscreen Y-plate 1 0 - 2.4V No 70 + 15 General Purpose TSY2 / Touchscreen Y-plate 2 0 - 2.4V No
+22
Documentation/hwmon/mcp3021
··· 1 + Kernel driver MCP3021 2 + ====================== 3 + 4 + Supported chips: 5 + * Microchip Technology MCP3021 6 + Prefix: 'mcp3021' 7 + Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21805a.pdf 8 + 9 + Author: Mingkai Hu 10 + 11 + Description 12 + ----------- 13 + 14 + This driver implements support for the Microchip Technology MCP3021 chip. 15 + 16 + The Microchip Technology Inc. MCP3021 is a successive approximation A/D 17 + converter (ADC) with 10-bit resolution. 18 + This device provides one single-ended input with very low power consumption. 19 + Communication to the MCP3021 is performed using a 2-wire I2C compatible 20 + interface. Standard (100 kHz) and Fast (400 kHz) I2C modes are available. 21 + The default I2C device address is 0x4d (contact the Microchip factory for 22 + additional address options).
+20 -8
drivers/hwmon/Kconfig
··· 648 648 LM86, LM89 and LM99, Analog Devices ADM1032, ADT7461, and ADT7461A, 649 649 Maxim MAX6646, MAX6647, MAX6648, MAX6649, MAX6657, MAX6658, MAX6659, 650 650 MAX6680, MAX6681, MAX6692, MAX6695, MAX6696, ON Semiconductor NCT1008, 651 - Winbond/Nuvoton W83L771W/G/AWG/ASG and Philips SA56004 sensor chips. 651 + Winbond/Nuvoton W83L771W/G/AWG/ASG, Philips SA56004, and GMT G781 652 + sensor chips. 652 653 653 654 This driver can also be built as a module. If so, the module 654 655 will be called lm90. ··· 812 811 813 812 This driver can also be built as a module. If so, the module 814 813 will be called max6650. 814 + 815 + config SENSORS_MCP3021 816 + tristate "Microchip MCP3021" 817 + depends on I2C && EXPERIMENTAL 818 + help 819 + If you say yes here you get support for the MCP3021 chip 820 + that is a A/D converter (ADC) with 10-bit resolution. 821 + 822 + This driver can also be built as a module. If so, the module 823 + will be called mcp3021. 815 824 816 825 config SENSORS_NTC_THERMISTOR 817 826 tristate "NTC thermistor support" ··· 1240 1229 depends on I2C && EXPERIMENTAL 1241 1230 help 1242 1231 If you say yes here you get support for the Winbond W83795G and 1243 - W83795ADG hardware monitoring chip. 1232 + W83795ADG hardware monitoring chip, including manual fan speed 1233 + control. 1244 1234 1245 1235 This driver can also be built as a module. If so, the module 1246 1236 will be called w83795. 1247 1237 1248 1238 config SENSORS_W83795_FANCTRL 1249 - boolean "Include fan control support (DANGEROUS)" 1239 + boolean "Include automatic fan control support (DANGEROUS)" 1250 1240 depends on SENSORS_W83795 && EXPERIMENTAL 1251 1241 default n 1252 1242 help 1253 - If you say yes here, support for the both manual and automatic 1254 - fan control features will be included in the driver. 1243 + If you say yes here, support for automatic fan speed control 1244 + will be included in the driver. 1255 1245 1256 1246 This part of the code wasn't carefully reviewed and tested yet, 1257 1247 so enabling this option is strongly discouraged on production ··· 1370 1358 the awesome power of applesmc. 1371 1359 1372 1360 config SENSORS_MC13783_ADC 1373 - tristate "Freescale MC13783 ADC" 1374 - depends on MFD_MC13783 1361 + tristate "Freescale MC13783/MC13892 ADC" 1362 + depends on MFD_MC13XXX 1375 1363 help 1376 - Support for the A/D converter on MC13783 PMIC. 1364 + Support for the A/D converter on MC13783 and MC13892 PMIC. 1377 1365 1378 1366 if ACPI 1379 1367
+1
drivers/hwmon/Makefile
··· 95 95 obj-$(CONFIG_SENSORS_MAX6642) += max6642.o 96 96 obj-$(CONFIG_SENSORS_MAX6650) += max6650.o 97 97 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o 98 + obj-$(CONFIG_SENSORS_MCP3021) += mcp3021.o 98 99 obj-$(CONFIG_SENSORS_NTC_THERMISTOR) += ntc_thermistor.o 99 100 obj-$(CONFIG_SENSORS_PC87360) += pc87360.o 100 101 obj-$(CONFIG_SENSORS_PC87427) += pc87427.o
+5 -5
drivers/hwmon/fam15h_power.c
··· 60 60 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5), 61 61 REG_TDP_RUNNING_AVERAGE, &val); 62 62 running_avg_capture = (val >> 4) & 0x3fffff; 63 - running_avg_capture = sign_extend32(running_avg_capture, 22); 64 - running_avg_range = val & 0xf; 63 + running_avg_capture = sign_extend32(running_avg_capture, 21); 64 + running_avg_range = (val & 0xf) + 1; 65 65 66 66 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5), 67 67 REG_TDP_LIMIT3, &val); 68 68 69 69 tdp_limit = val >> 16; 70 - curr_pwr_watts = tdp_limit + data->base_tdp - 71 - (s32)(running_avg_capture >> (running_avg_range + 1)); 70 + curr_pwr_watts = (tdp_limit + data->base_tdp) << running_avg_range; 71 + curr_pwr_watts -= running_avg_capture; 72 72 curr_pwr_watts *= data->tdp_to_watts; 73 73 74 74 /* ··· 78 78 * scaling factor 1/(2^16). For conversion we use 79 79 * (10^6)/(2^16) = 15625/(2^10) 80 80 */ 81 - curr_pwr_watts = (curr_pwr_watts * 15625) >> 10; 81 + curr_pwr_watts = (curr_pwr_watts * 15625) >> (10 + running_avg_range); 82 82 return sprintf(buf, "%u\n", (unsigned int) curr_pwr_watts); 83 83 } 84 84 static DEVICE_ATTR(power1_input, S_IRUGO, show_power, NULL);
+338 -250
drivers/hwmon/lm63.c
··· 148 148 #define UPDATE_INTERVAL(max, rate) \ 149 149 ((1000 << (LM63_MAX_CONVRATE - (rate))) / (max)) 150 150 151 - /* 152 - * Functions declaration 153 - */ 154 - 155 - static int lm63_probe(struct i2c_client *client, 156 - const struct i2c_device_id *id); 157 - static int lm63_remove(struct i2c_client *client); 158 - 159 - static struct lm63_data *lm63_update_device(struct device *dev); 160 - 161 - static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info); 162 - static void lm63_init_client(struct i2c_client *client); 163 - 164 151 enum chips { lm63, lm64, lm96163 }; 165 - 166 - /* 167 - * Driver data (common to all clients) 168 - */ 169 - 170 - static const struct i2c_device_id lm63_id[] = { 171 - { "lm63", lm63 }, 172 - { "lm64", lm64 }, 173 - { "lm96163", lm96163 }, 174 - { } 175 - }; 176 - MODULE_DEVICE_TABLE(i2c, lm63_id); 177 - 178 - static struct i2c_driver lm63_driver = { 179 - .class = I2C_CLASS_HWMON, 180 - .driver = { 181 - .name = "lm63", 182 - }, 183 - .probe = lm63_probe, 184 - .remove = lm63_remove, 185 - .id_table = lm63_id, 186 - .detect = lm63_detect, 187 - .address_list = normal_i2c, 188 - }; 189 152 190 153 /* 191 154 * Client data (each client gets its own) ··· 205 242 return data->temp8[nr] * (data->lut_temp_highres ? 500 : 1000); 206 243 } 207 244 245 + static inline int lut_temp_to_reg(struct lm63_data *data, long val) 246 + { 247 + val -= data->temp2_offset; 248 + if (data->lut_temp_highres) 249 + return DIV_ROUND_CLOSEST(SENSORS_LIMIT(val, 0, 127500), 500); 250 + else 251 + return DIV_ROUND_CLOSEST(SENSORS_LIMIT(val, 0, 127000), 1000); 252 + } 253 + 254 + /* 255 + * Update the lookup table register cache. 256 + * client->update_lock must be held when calling this function. 257 + */ 258 + static void lm63_update_lut(struct i2c_client *client) 259 + { 260 + struct lm63_data *data = i2c_get_clientdata(client); 261 + int i; 262 + 263 + if (time_after(jiffies, data->lut_last_updated + 5 * HZ) || 264 + !data->lut_valid) { 265 + for (i = 0; i < data->lut_size; i++) { 266 + data->pwm1[1 + i] = i2c_smbus_read_byte_data(client, 267 + LM63_REG_LUT_PWM(i)); 268 + data->temp8[3 + i] = i2c_smbus_read_byte_data(client, 269 + LM63_REG_LUT_TEMP(i)); 270 + } 271 + data->lut_temp_hyst = i2c_smbus_read_byte_data(client, 272 + LM63_REG_LUT_TEMP_HYST); 273 + 274 + data->lut_last_updated = jiffies; 275 + data->lut_valid = 1; 276 + } 277 + } 278 + 279 + static struct lm63_data *lm63_update_device(struct device *dev) 280 + { 281 + struct i2c_client *client = to_i2c_client(dev); 282 + struct lm63_data *data = i2c_get_clientdata(client); 283 + unsigned long next_update; 284 + 285 + mutex_lock(&data->update_lock); 286 + 287 + next_update = data->last_updated 288 + + msecs_to_jiffies(data->update_interval) + 1; 289 + 290 + if (time_after(jiffies, next_update) || !data->valid) { 291 + if (data->config & 0x04) { /* tachometer enabled */ 292 + /* order matters for fan1_input */ 293 + data->fan[0] = i2c_smbus_read_byte_data(client, 294 + LM63_REG_TACH_COUNT_LSB) & 0xFC; 295 + data->fan[0] |= i2c_smbus_read_byte_data(client, 296 + LM63_REG_TACH_COUNT_MSB) << 8; 297 + data->fan[1] = (i2c_smbus_read_byte_data(client, 298 + LM63_REG_TACH_LIMIT_LSB) & 0xFC) 299 + | (i2c_smbus_read_byte_data(client, 300 + LM63_REG_TACH_LIMIT_MSB) << 8); 301 + } 302 + 303 + data->pwm1_freq = i2c_smbus_read_byte_data(client, 304 + LM63_REG_PWM_FREQ); 305 + if (data->pwm1_freq == 0) 306 + data->pwm1_freq = 1; 307 + data->pwm1[0] = i2c_smbus_read_byte_data(client, 308 + LM63_REG_PWM_VALUE); 309 + 310 + data->temp8[0] = i2c_smbus_read_byte_data(client, 311 + LM63_REG_LOCAL_TEMP); 312 + data->temp8[1] = i2c_smbus_read_byte_data(client, 313 + LM63_REG_LOCAL_HIGH); 314 + 315 + /* order matters for temp2_input */ 316 + data->temp11[0] = i2c_smbus_read_byte_data(client, 317 + LM63_REG_REMOTE_TEMP_MSB) << 8; 318 + data->temp11[0] |= i2c_smbus_read_byte_data(client, 319 + LM63_REG_REMOTE_TEMP_LSB); 320 + data->temp11[1] = (i2c_smbus_read_byte_data(client, 321 + LM63_REG_REMOTE_LOW_MSB) << 8) 322 + | i2c_smbus_read_byte_data(client, 323 + LM63_REG_REMOTE_LOW_LSB); 324 + data->temp11[2] = (i2c_smbus_read_byte_data(client, 325 + LM63_REG_REMOTE_HIGH_MSB) << 8) 326 + | i2c_smbus_read_byte_data(client, 327 + LM63_REG_REMOTE_HIGH_LSB); 328 + data->temp11[3] = (i2c_smbus_read_byte_data(client, 329 + LM63_REG_REMOTE_OFFSET_MSB) << 8) 330 + | i2c_smbus_read_byte_data(client, 331 + LM63_REG_REMOTE_OFFSET_LSB); 332 + 333 + if (data->kind == lm96163) 334 + data->temp11u = (i2c_smbus_read_byte_data(client, 335 + LM96163_REG_REMOTE_TEMP_U_MSB) << 8) 336 + | i2c_smbus_read_byte_data(client, 337 + LM96163_REG_REMOTE_TEMP_U_LSB); 338 + 339 + data->temp8[2] = i2c_smbus_read_byte_data(client, 340 + LM63_REG_REMOTE_TCRIT); 341 + data->temp2_crit_hyst = i2c_smbus_read_byte_data(client, 342 + LM63_REG_REMOTE_TCRIT_HYST); 343 + 344 + data->alarms = i2c_smbus_read_byte_data(client, 345 + LM63_REG_ALERT_STATUS) & 0x7F; 346 + 347 + data->last_updated = jiffies; 348 + data->valid = 1; 349 + } 350 + 351 + lm63_update_lut(client); 352 + 353 + mutex_unlock(&data->update_lock); 354 + 355 + return data; 356 + } 357 + 358 + /* 359 + * Trip points in the lookup table should be in ascending order for both 360 + * temperatures and PWM output values. 361 + */ 362 + static int lm63_lut_looks_bad(struct i2c_client *client) 363 + { 364 + struct lm63_data *data = i2c_get_clientdata(client); 365 + int i; 366 + 367 + mutex_lock(&data->update_lock); 368 + lm63_update_lut(client); 369 + 370 + for (i = 1; i < data->lut_size; i++) { 371 + if (data->pwm1[1 + i - 1] > data->pwm1[1 + i] 372 + || data->temp8[3 + i - 1] > data->temp8[3 + i]) { 373 + dev_warn(&client->dev, 374 + "Lookup table doesn't look sane (check entries %d and %d)\n", 375 + i, i + 1); 376 + break; 377 + } 378 + } 379 + mutex_unlock(&data->update_lock); 380 + 381 + return i == data->lut_size ? 0 : 1; 382 + } 383 + 208 384 /* 209 385 * Sysfs callback functions and files 210 386 */ ··· 396 294 return sprintf(buf, "%d\n", pwm); 397 295 } 398 296 399 - static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy, 297 + static ssize_t set_pwm1(struct device *dev, struct device_attribute *devattr, 400 298 const char *buf, size_t count) 401 299 { 300 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 402 301 struct i2c_client *client = to_i2c_client(dev); 403 302 struct lm63_data *data = i2c_get_clientdata(client); 303 + int nr = attr->index; 404 304 unsigned long val; 405 305 int err; 306 + u8 reg; 406 307 407 308 if (!(data->config_fan & 0x20)) /* register is read-only */ 408 309 return -EPERM; ··· 414 309 if (err) 415 310 return err; 416 311 312 + reg = nr ? LM63_REG_LUT_PWM(nr - 1) : LM63_REG_PWM_VALUE; 417 313 val = SENSORS_LIMIT(val, 0, 255); 314 + 418 315 mutex_lock(&data->update_lock); 419 - data->pwm1[0] = data->pwm_highres ? val : 316 + data->pwm1[nr] = data->pwm_highres ? val : 420 317 (val * data->pwm1_freq * 2 + 127) / 255; 421 - i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1[0]); 318 + i2c_smbus_write_byte_data(client, reg, data->pwm1[nr]); 422 319 mutex_unlock(&data->update_lock); 423 320 return count; 424 321 } ··· 430 323 { 431 324 struct lm63_data *data = lm63_update_device(dev); 432 325 return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2); 326 + } 327 + 328 + static ssize_t set_pwm1_enable(struct device *dev, 329 + struct device_attribute *dummy, 330 + const char *buf, size_t count) 331 + { 332 + struct i2c_client *client = to_i2c_client(dev); 333 + struct lm63_data *data = i2c_get_clientdata(client); 334 + unsigned long val; 335 + int err; 336 + 337 + err = kstrtoul(buf, 10, &val); 338 + if (err) 339 + return err; 340 + if (val < 1 || val > 2) 341 + return -EINVAL; 342 + 343 + /* 344 + * Only let the user switch to automatic mode if the lookup table 345 + * looks sane. 346 + */ 347 + if (val == 2 && lm63_lut_looks_bad(client)) 348 + return -EPERM; 349 + 350 + mutex_lock(&data->update_lock); 351 + data->config_fan = i2c_smbus_read_byte_data(client, 352 + LM63_REG_CONFIG_FAN); 353 + if (val == 1) 354 + data->config_fan |= 0x20; 355 + else 356 + data->config_fan &= ~0x20; 357 + i2c_smbus_write_byte_data(client, LM63_REG_CONFIG_FAN, 358 + data->config_fan); 359 + mutex_unlock(&data->update_lock); 360 + return count; 433 361 } 434 362 435 363 /* ··· 509 367 struct i2c_client *client = to_i2c_client(dev); 510 368 struct lm63_data *data = i2c_get_clientdata(client); 511 369 int nr = attr->index; 512 - int reg = nr == 2 ? LM63_REG_REMOTE_TCRIT : LM63_REG_LOCAL_HIGH; 513 370 long val; 514 371 int err; 515 372 int temp; 373 + u8 reg; 516 374 517 375 err = kstrtol(buf, 10, &val); 518 376 if (err) 519 377 return err; 520 378 521 379 mutex_lock(&data->update_lock); 522 - if (nr == 2) { 380 + switch (nr) { 381 + case 2: 382 + reg = LM63_REG_REMOTE_TCRIT; 523 383 if (data->remote_unsigned) 524 384 temp = TEMP8U_TO_REG(val - data->temp2_offset); 525 385 else 526 386 temp = TEMP8_TO_REG(val - data->temp2_offset); 527 - } else { 387 + break; 388 + case 1: 389 + reg = LM63_REG_LOCAL_HIGH; 528 390 temp = TEMP8_TO_REG(val); 391 + break; 392 + default: /* lookup table */ 393 + reg = LM63_REG_LUT_TEMP(nr - 3); 394 + temp = lut_temp_to_reg(data, val); 529 395 } 530 396 data->temp8[nr] = temp; 531 397 i2c_smbus_write_byte_data(client, reg, temp); ··· 763 613 set_fan, 1); 764 614 765 615 static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1, 0); 766 - static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL); 767 - static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO, show_pwm1, NULL, 1); 768 - static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp, S_IRUGO, 769 - show_lut_temp, NULL, 3); 616 + static DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, 617 + show_pwm1_enable, set_pwm1_enable); 618 + static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO, 619 + show_pwm1, set_pwm1, 1); 620 + static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp, S_IWUSR | S_IRUGO, 621 + show_lut_temp, set_temp8, 3); 770 622 static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp_hyst, S_IRUGO, 771 623 show_lut_temp_hyst, NULL, 3); 772 - static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO, show_pwm1, NULL, 2); 773 - static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp, S_IRUGO, 774 - show_lut_temp, NULL, 4); 624 + static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO, 625 + show_pwm1, set_pwm1, 2); 626 + static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp, S_IWUSR | S_IRUGO, 627 + show_lut_temp, set_temp8, 4); 775 628 static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp_hyst, S_IRUGO, 776 629 show_lut_temp_hyst, NULL, 4); 777 - static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO, show_pwm1, NULL, 3); 778 - static SENSOR_DEVICE_ATTR(pwm1_auto_point3_temp, S_IRUGO, 779 - show_lut_temp, NULL, 5); 630 + static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IWUSR | S_IRUGO, 631 + show_pwm1, set_pwm1, 3); 632 + static SENSOR_DEVICE_ATTR(pwm1_auto_point3_temp, S_IWUSR | S_IRUGO, 633 + show_lut_temp, set_temp8, 5); 780 634 static SENSOR_DEVICE_ATTR(pwm1_auto_point3_temp_hyst, S_IRUGO, 781 635 show_lut_temp_hyst, NULL, 5); 782 - static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO, show_pwm1, NULL, 4); 783 - static SENSOR_DEVICE_ATTR(pwm1_auto_point4_temp, S_IRUGO, 784 - show_lut_temp, NULL, 6); 636 + static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IWUSR | S_IRUGO, 637 + show_pwm1, set_pwm1, 4); 638 + static SENSOR_DEVICE_ATTR(pwm1_auto_point4_temp, S_IWUSR | S_IRUGO, 639 + show_lut_temp, set_temp8, 6); 785 640 static SENSOR_DEVICE_ATTR(pwm1_auto_point4_temp_hyst, S_IRUGO, 786 641 show_lut_temp_hyst, NULL, 6); 787 - static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO, show_pwm1, NULL, 5); 788 - static SENSOR_DEVICE_ATTR(pwm1_auto_point5_temp, S_IRUGO, 789 - show_lut_temp, NULL, 7); 642 + static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IWUSR | S_IRUGO, 643 + show_pwm1, set_pwm1, 5); 644 + static SENSOR_DEVICE_ATTR(pwm1_auto_point5_temp, S_IWUSR | S_IRUGO, 645 + show_lut_temp, set_temp8, 7); 790 646 static SENSOR_DEVICE_ATTR(pwm1_auto_point5_temp_hyst, S_IRUGO, 791 647 show_lut_temp_hyst, NULL, 7); 792 - static SENSOR_DEVICE_ATTR(pwm1_auto_point6_pwm, S_IRUGO, show_pwm1, NULL, 6); 793 - static SENSOR_DEVICE_ATTR(pwm1_auto_point6_temp, S_IRUGO, 794 - show_lut_temp, NULL, 8); 648 + static SENSOR_DEVICE_ATTR(pwm1_auto_point6_pwm, S_IWUSR | S_IRUGO, 649 + show_pwm1, set_pwm1, 6); 650 + static SENSOR_DEVICE_ATTR(pwm1_auto_point6_temp, S_IWUSR | S_IRUGO, 651 + show_lut_temp, set_temp8, 8); 795 652 static SENSOR_DEVICE_ATTR(pwm1_auto_point6_temp_hyst, S_IRUGO, 796 653 show_lut_temp_hyst, NULL, 8); 797 - static SENSOR_DEVICE_ATTR(pwm1_auto_point7_pwm, S_IRUGO, show_pwm1, NULL, 7); 798 - static SENSOR_DEVICE_ATTR(pwm1_auto_point7_temp, S_IRUGO, 799 - show_lut_temp, NULL, 9); 654 + static SENSOR_DEVICE_ATTR(pwm1_auto_point7_pwm, S_IWUSR | S_IRUGO, 655 + show_pwm1, set_pwm1, 7); 656 + static SENSOR_DEVICE_ATTR(pwm1_auto_point7_temp, S_IWUSR | S_IRUGO, 657 + show_lut_temp, set_temp8, 9); 800 658 static SENSOR_DEVICE_ATTR(pwm1_auto_point7_temp_hyst, S_IRUGO, 801 659 show_lut_temp_hyst, NULL, 9); 802 - static SENSOR_DEVICE_ATTR(pwm1_auto_point8_pwm, S_IRUGO, show_pwm1, NULL, 8); 803 - static SENSOR_DEVICE_ATTR(pwm1_auto_point8_temp, S_IRUGO, 804 - show_lut_temp, NULL, 10); 660 + static SENSOR_DEVICE_ATTR(pwm1_auto_point8_pwm, S_IWUSR | S_IRUGO, 661 + show_pwm1, set_pwm1, 8); 662 + static SENSOR_DEVICE_ATTR(pwm1_auto_point8_temp, S_IWUSR | S_IRUGO, 663 + show_lut_temp, set_temp8, 10); 805 664 static SENSOR_DEVICE_ATTR(pwm1_auto_point8_temp_hyst, S_IRUGO, 806 665 show_lut_temp_hyst, NULL, 10); 807 - static SENSOR_DEVICE_ATTR(pwm1_auto_point9_pwm, S_IRUGO, show_pwm1, NULL, 9); 808 - static SENSOR_DEVICE_ATTR(pwm1_auto_point9_temp, S_IRUGO, 809 - show_lut_temp, NULL, 11); 666 + static SENSOR_DEVICE_ATTR(pwm1_auto_point9_pwm, S_IWUSR | S_IRUGO, 667 + show_pwm1, set_pwm1, 9); 668 + static SENSOR_DEVICE_ATTR(pwm1_auto_point9_temp, S_IWUSR | S_IRUGO, 669 + show_lut_temp, set_temp8, 11); 810 670 static SENSOR_DEVICE_ATTR(pwm1_auto_point9_temp_hyst, S_IRUGO, 811 671 show_lut_temp_hyst, NULL, 11); 812 - static SENSOR_DEVICE_ATTR(pwm1_auto_point10_pwm, S_IRUGO, show_pwm1, NULL, 10); 813 - static SENSOR_DEVICE_ATTR(pwm1_auto_point10_temp, S_IRUGO, 814 - show_lut_temp, NULL, 12); 672 + static SENSOR_DEVICE_ATTR(pwm1_auto_point10_pwm, S_IWUSR | S_IRUGO, 673 + show_pwm1, set_pwm1, 10); 674 + static SENSOR_DEVICE_ATTR(pwm1_auto_point10_temp, S_IWUSR | S_IRUGO, 675 + show_lut_temp, set_temp8, 12); 815 676 static SENSOR_DEVICE_ATTR(pwm1_auto_point10_temp_hyst, S_IRUGO, 816 677 show_lut_temp_hyst, NULL, 12); 817 - static SENSOR_DEVICE_ATTR(pwm1_auto_point11_pwm, S_IRUGO, show_pwm1, NULL, 11); 818 - static SENSOR_DEVICE_ATTR(pwm1_auto_point11_temp, S_IRUGO, 819 - show_lut_temp, NULL, 13); 678 + static SENSOR_DEVICE_ATTR(pwm1_auto_point11_pwm, S_IWUSR | S_IRUGO, 679 + show_pwm1, set_pwm1, 11); 680 + static SENSOR_DEVICE_ATTR(pwm1_auto_point11_temp, S_IWUSR | S_IRUGO, 681 + show_lut_temp, set_temp8, 13); 820 682 static SENSOR_DEVICE_ATTR(pwm1_auto_point11_temp_hyst, S_IRUGO, 821 683 show_lut_temp_hyst, NULL, 13); 822 - static SENSOR_DEVICE_ATTR(pwm1_auto_point12_pwm, S_IRUGO, show_pwm1, NULL, 12); 823 - static SENSOR_DEVICE_ATTR(pwm1_auto_point12_temp, S_IRUGO, 824 - show_lut_temp, NULL, 14); 684 + static SENSOR_DEVICE_ATTR(pwm1_auto_point12_pwm, S_IWUSR | S_IRUGO, 685 + show_pwm1, set_pwm1, 12); 686 + static SENSOR_DEVICE_ATTR(pwm1_auto_point12_temp, S_IWUSR | S_IRUGO, 687 + show_lut_temp, set_temp8, 14); 825 688 static SENSOR_DEVICE_ATTR(pwm1_auto_point12_temp_hyst, S_IRUGO, 826 689 show_lut_temp_hyst, NULL, 14); 827 690 ··· 980 817 */ 981 818 982 819 /* Return 0 if detection is successful, -ENODEV otherwise */ 983 - static int lm63_detect(struct i2c_client *new_client, 820 + static int lm63_detect(struct i2c_client *client, 984 821 struct i2c_board_info *info) 985 822 { 986 - struct i2c_adapter *adapter = new_client->adapter; 823 + struct i2c_adapter *adapter = client->adapter; 987 824 u8 man_id, chip_id, reg_config1, reg_config2; 988 825 u8 reg_alert_status, reg_alert_mask; 989 - int address = new_client->addr; 826 + int address = client->addr; 990 827 991 828 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 992 829 return -ENODEV; 993 830 994 - man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID); 995 - chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CHIP_ID); 831 + man_id = i2c_smbus_read_byte_data(client, LM63_REG_MAN_ID); 832 + chip_id = i2c_smbus_read_byte_data(client, LM63_REG_CHIP_ID); 996 833 997 - reg_config1 = i2c_smbus_read_byte_data(new_client, 998 - LM63_REG_CONFIG1); 999 - reg_config2 = i2c_smbus_read_byte_data(new_client, 1000 - LM63_REG_CONFIG2); 1001 - reg_alert_status = i2c_smbus_read_byte_data(new_client, 834 + reg_config1 = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); 835 + reg_config2 = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG2); 836 + reg_alert_status = i2c_smbus_read_byte_data(client, 1002 837 LM63_REG_ALERT_STATUS); 1003 - reg_alert_mask = i2c_smbus_read_byte_data(new_client, 1004 - LM63_REG_ALERT_MASK); 838 + reg_alert_mask = i2c_smbus_read_byte_data(client, LM63_REG_ALERT_MASK); 1005 839 1006 840 if (man_id != 0x01 /* National Semiconductor */ 1007 841 || (reg_config1 & 0x18) != 0x00 ··· 1021 861 return -ENODEV; 1022 862 1023 863 return 0; 1024 - } 1025 - 1026 - static int lm63_probe(struct i2c_client *new_client, 1027 - const struct i2c_device_id *id) 1028 - { 1029 - struct lm63_data *data; 1030 - int err; 1031 - 1032 - data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL); 1033 - if (!data) { 1034 - err = -ENOMEM; 1035 - goto exit; 1036 - } 1037 - 1038 - i2c_set_clientdata(new_client, data); 1039 - data->valid = 0; 1040 - mutex_init(&data->update_lock); 1041 - 1042 - /* Set the device type */ 1043 - data->kind = id->driver_data; 1044 - if (data->kind == lm64) 1045 - data->temp2_offset = 16000; 1046 - 1047 - /* Initialize chip */ 1048 - lm63_init_client(new_client); 1049 - 1050 - /* Register sysfs hooks */ 1051 - err = sysfs_create_group(&new_client->dev.kobj, &lm63_group); 1052 - if (err) 1053 - goto exit_free; 1054 - if (data->config & 0x04) { /* tachometer enabled */ 1055 - err = sysfs_create_group(&new_client->dev.kobj, 1056 - &lm63_group_fan1); 1057 - if (err) 1058 - goto exit_remove_files; 1059 - } 1060 - if (data->kind == lm96163) { 1061 - err = device_create_file(&new_client->dev, 1062 - &dev_attr_temp2_type); 1063 - if (err) 1064 - goto exit_remove_files; 1065 - 1066 - err = sysfs_create_group(&new_client->dev.kobj, 1067 - &lm63_group_extra_lut); 1068 - if (err) 1069 - goto exit_remove_files; 1070 - } 1071 - 1072 - data->hwmon_dev = hwmon_device_register(&new_client->dev); 1073 - if (IS_ERR(data->hwmon_dev)) { 1074 - err = PTR_ERR(data->hwmon_dev); 1075 - goto exit_remove_files; 1076 - } 1077 - 1078 - return 0; 1079 - 1080 - exit_remove_files: 1081 - sysfs_remove_group(&new_client->dev.kobj, &lm63_group); 1082 - sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); 1083 - if (data->kind == lm96163) { 1084 - device_remove_file(&new_client->dev, &dev_attr_temp2_type); 1085 - sysfs_remove_group(&new_client->dev.kobj, 1086 - &lm63_group_extra_lut); 1087 - } 1088 - exit_free: 1089 - kfree(data); 1090 - exit: 1091 - return err; 1092 864 } 1093 865 1094 866 /* ··· 1102 1010 (data->config_fan & 0x20) ? "manual" : "auto"); 1103 1011 } 1104 1012 1013 + static int lm63_probe(struct i2c_client *client, 1014 + const struct i2c_device_id *id) 1015 + { 1016 + struct lm63_data *data; 1017 + int err; 1018 + 1019 + data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL); 1020 + if (!data) { 1021 + err = -ENOMEM; 1022 + goto exit; 1023 + } 1024 + 1025 + i2c_set_clientdata(client, data); 1026 + data->valid = 0; 1027 + mutex_init(&data->update_lock); 1028 + 1029 + /* Set the device type */ 1030 + data->kind = id->driver_data; 1031 + if (data->kind == lm64) 1032 + data->temp2_offset = 16000; 1033 + 1034 + /* Initialize chip */ 1035 + lm63_init_client(client); 1036 + 1037 + /* Register sysfs hooks */ 1038 + err = sysfs_create_group(&client->dev.kobj, &lm63_group); 1039 + if (err) 1040 + goto exit_free; 1041 + if (data->config & 0x04) { /* tachometer enabled */ 1042 + err = sysfs_create_group(&client->dev.kobj, &lm63_group_fan1); 1043 + if (err) 1044 + goto exit_remove_files; 1045 + } 1046 + if (data->kind == lm96163) { 1047 + err = device_create_file(&client->dev, &dev_attr_temp2_type); 1048 + if (err) 1049 + goto exit_remove_files; 1050 + 1051 + err = sysfs_create_group(&client->dev.kobj, 1052 + &lm63_group_extra_lut); 1053 + if (err) 1054 + goto exit_remove_files; 1055 + } 1056 + 1057 + data->hwmon_dev = hwmon_device_register(&client->dev); 1058 + if (IS_ERR(data->hwmon_dev)) { 1059 + err = PTR_ERR(data->hwmon_dev); 1060 + goto exit_remove_files; 1061 + } 1062 + 1063 + return 0; 1064 + 1065 + exit_remove_files: 1066 + sysfs_remove_group(&client->dev.kobj, &lm63_group); 1067 + sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); 1068 + if (data->kind == lm96163) { 1069 + device_remove_file(&client->dev, &dev_attr_temp2_type); 1070 + sysfs_remove_group(&client->dev.kobj, &lm63_group_extra_lut); 1071 + } 1072 + exit_free: 1073 + kfree(data); 1074 + exit: 1075 + return err; 1076 + } 1077 + 1105 1078 static int lm63_remove(struct i2c_client *client) 1106 1079 { 1107 1080 struct lm63_data *data = i2c_get_clientdata(client); ··· 1183 1026 return 0; 1184 1027 } 1185 1028 1186 - static struct lm63_data *lm63_update_device(struct device *dev) 1187 - { 1188 - struct i2c_client *client = to_i2c_client(dev); 1189 - struct lm63_data *data = i2c_get_clientdata(client); 1190 - unsigned long next_update; 1191 - int i; 1029 + /* 1030 + * Driver data (common to all clients) 1031 + */ 1192 1032 1193 - mutex_lock(&data->update_lock); 1033 + static const struct i2c_device_id lm63_id[] = { 1034 + { "lm63", lm63 }, 1035 + { "lm64", lm64 }, 1036 + { "lm96163", lm96163 }, 1037 + { } 1038 + }; 1039 + MODULE_DEVICE_TABLE(i2c, lm63_id); 1194 1040 1195 - next_update = data->last_updated 1196 - + msecs_to_jiffies(data->update_interval) + 1; 1197 - 1198 - if (time_after(jiffies, next_update) || !data->valid) { 1199 - if (data->config & 0x04) { /* tachometer enabled */ 1200 - /* order matters for fan1_input */ 1201 - data->fan[0] = i2c_smbus_read_byte_data(client, 1202 - LM63_REG_TACH_COUNT_LSB) & 0xFC; 1203 - data->fan[0] |= i2c_smbus_read_byte_data(client, 1204 - LM63_REG_TACH_COUNT_MSB) << 8; 1205 - data->fan[1] = (i2c_smbus_read_byte_data(client, 1206 - LM63_REG_TACH_LIMIT_LSB) & 0xFC) 1207 - | (i2c_smbus_read_byte_data(client, 1208 - LM63_REG_TACH_LIMIT_MSB) << 8); 1209 - } 1210 - 1211 - data->pwm1_freq = i2c_smbus_read_byte_data(client, 1212 - LM63_REG_PWM_FREQ); 1213 - if (data->pwm1_freq == 0) 1214 - data->pwm1_freq = 1; 1215 - data->pwm1[0] = i2c_smbus_read_byte_data(client, 1216 - LM63_REG_PWM_VALUE); 1217 - 1218 - data->temp8[0] = i2c_smbus_read_byte_data(client, 1219 - LM63_REG_LOCAL_TEMP); 1220 - data->temp8[1] = i2c_smbus_read_byte_data(client, 1221 - LM63_REG_LOCAL_HIGH); 1222 - 1223 - /* order matters for temp2_input */ 1224 - data->temp11[0] = i2c_smbus_read_byte_data(client, 1225 - LM63_REG_REMOTE_TEMP_MSB) << 8; 1226 - data->temp11[0] |= i2c_smbus_read_byte_data(client, 1227 - LM63_REG_REMOTE_TEMP_LSB); 1228 - data->temp11[1] = (i2c_smbus_read_byte_data(client, 1229 - LM63_REG_REMOTE_LOW_MSB) << 8) 1230 - | i2c_smbus_read_byte_data(client, 1231 - LM63_REG_REMOTE_LOW_LSB); 1232 - data->temp11[2] = (i2c_smbus_read_byte_data(client, 1233 - LM63_REG_REMOTE_HIGH_MSB) << 8) 1234 - | i2c_smbus_read_byte_data(client, 1235 - LM63_REG_REMOTE_HIGH_LSB); 1236 - data->temp11[3] = (i2c_smbus_read_byte_data(client, 1237 - LM63_REG_REMOTE_OFFSET_MSB) << 8) 1238 - | i2c_smbus_read_byte_data(client, 1239 - LM63_REG_REMOTE_OFFSET_LSB); 1240 - 1241 - if (data->kind == lm96163) 1242 - data->temp11u = (i2c_smbus_read_byte_data(client, 1243 - LM96163_REG_REMOTE_TEMP_U_MSB) << 8) 1244 - | i2c_smbus_read_byte_data(client, 1245 - LM96163_REG_REMOTE_TEMP_U_LSB); 1246 - 1247 - data->temp8[2] = i2c_smbus_read_byte_data(client, 1248 - LM63_REG_REMOTE_TCRIT); 1249 - data->temp2_crit_hyst = i2c_smbus_read_byte_data(client, 1250 - LM63_REG_REMOTE_TCRIT_HYST); 1251 - 1252 - data->alarms = i2c_smbus_read_byte_data(client, 1253 - LM63_REG_ALERT_STATUS) & 0x7F; 1254 - 1255 - data->last_updated = jiffies; 1256 - data->valid = 1; 1257 - } 1258 - 1259 - if (time_after(jiffies, data->lut_last_updated + 5 * HZ) || 1260 - !data->lut_valid) { 1261 - for (i = 0; i < data->lut_size; i++) { 1262 - data->pwm1[1 + i] = i2c_smbus_read_byte_data(client, 1263 - LM63_REG_LUT_PWM(i)); 1264 - data->temp8[3 + i] = i2c_smbus_read_byte_data(client, 1265 - LM63_REG_LUT_TEMP(i)); 1266 - } 1267 - data->lut_temp_hyst = i2c_smbus_read_byte_data(client, 1268 - LM63_REG_LUT_TEMP_HYST); 1269 - 1270 - data->lut_last_updated = jiffies; 1271 - data->lut_valid = 1; 1272 - } 1273 - 1274 - mutex_unlock(&data->update_lock); 1275 - 1276 - return data; 1277 - } 1041 + static struct i2c_driver lm63_driver = { 1042 + .class = I2C_CLASS_HWMON, 1043 + .driver = { 1044 + .name = "lm63", 1045 + }, 1046 + .probe = lm63_probe, 1047 + .remove = lm63_remove, 1048 + .id_table = lm63_id, 1049 + .detect = lm63_detect, 1050 + .address_list = normal_i2c, 1051 + }; 1278 1052 1279 1053 module_i2c_driver(lm63_driver); 1280 1054
+65 -33
drivers/hwmon/lm90.c
··· 57 57 * This driver also supports the SA56004 from Philips. This device is 58 58 * pin-compatible with the LM86, the ED/EDP parts are also address-compatible. 59 59 * 60 + * This driver also supports the G781 from GMT. This device is compatible 61 + * with the ADM1032. 62 + * 60 63 * Since the LM90 was the first chipset supported by this driver, most 61 64 * comments will refer to this chipset, but are actually general and 62 65 * concern all supported chipsets, unless mentioned otherwise. ··· 110 107 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 111 108 112 109 enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, 113 - max6646, w83l771, max6696, sa56004 }; 110 + max6646, w83l771, max6696, sa56004, g781 }; 114 111 115 112 /* 116 113 * The LM90 registers ··· 187 184 { "adm1032", adm1032 }, 188 185 { "adt7461", adt7461 }, 189 186 { "adt7461a", adt7461 }, 187 + { "g781", g781 }, 190 188 { "lm90", lm90 }, 191 189 { "lm86", lm86 }, 192 190 { "lm89", lm86 }, ··· 232 228 | LM90_HAVE_BROKEN_ALERT, 233 229 .alert_alarms = 0x7c, 234 230 .max_convrate = 10, 231 + }, 232 + [g781] = { 233 + .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT 234 + | LM90_HAVE_BROKEN_ALERT, 235 + .alert_alarms = 0x7c, 236 + .max_convrate = 8, 235 237 }, 236 238 [lm86] = { 237 239 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, ··· 318 308 319 309 /* registers values */ 320 310 s8 temp8[8]; /* 0: local low limit 321 - 1: local high limit 322 - 2: local critical limit 323 - 3: remote critical limit 324 - 4: local emergency limit (max6659 and max6695/96) 325 - 5: remote emergency limit (max6659 and max6695/96) 326 - 6: remote 2 critical limit (max6695/96 only) 327 - 7: remote 2 emergency limit (max6695/96 only) */ 311 + * 1: local high limit 312 + * 2: local critical limit 313 + * 3: remote critical limit 314 + * 4: local emergency limit (max6659 and max6695/96) 315 + * 5: remote emergency limit (max6659 and max6695/96) 316 + * 6: remote 2 critical limit (max6695/96 only) 317 + * 7: remote 2 emergency limit (max6695/96 only) 318 + */ 328 319 s16 temp11[8]; /* 0: remote input 329 - 1: remote low limit 330 - 2: remote high limit 331 - 3: remote offset (except max6646, max6657/58/59, 332 - and max6695/96) 333 - 4: local input 334 - 5: remote 2 input (max6695/96 only) 335 - 6: remote 2 low limit (max6695/96 only) 336 - 7: remote 2 high limit (ma6695/96 only) */ 320 + * 1: remote low limit 321 + * 2: remote high limit 322 + * 3: remote offset (except max6646, max6657/58/59, 323 + * and max6695/96) 324 + * 4: local input 325 + * 5: remote 2 input (max6695/96 only) 326 + * 6: remote 2 low limit (max6695/96 only) 327 + * 7: remote 2 high limit (max6695/96 only) 328 + */ 337 329 u8 temp_hyst; 338 330 u16 alarms; /* bitvector (upper 8 bits for max6695/96) */ 339 331 }; ··· 545 533 data->alarms |= alarms << 8; 546 534 } 547 535 548 - /* Re-enable ALERT# output if it was originally enabled and 549 - * relevant alarms are all clear */ 536 + /* 537 + * Re-enable ALERT# output if it was originally enabled and 538 + * relevant alarms are all clear 539 + */ 550 540 if ((data->config_orig & 0x80) == 0 551 541 && (data->alarms & data->alert_alarms) == 0) { 552 542 u8 config; ··· 1176 1162 && (config1 & 0x3F) == 0x00 1177 1163 && convrate <= 0x0A) { 1178 1164 name = "adm1032"; 1179 - /* The ADM1032 supports PEC, but only if combined 1180 - transactions are not used. */ 1165 + /* 1166 + * The ADM1032 supports PEC, but only if combined 1167 + * transactions are not used. 1168 + */ 1181 1169 if (i2c_check_functionality(adapter, 1182 1170 I2C_FUNC_SMBUS_BYTE)) 1183 1171 info->flags |= I2C_CLIENT_PEC; ··· 1299 1283 && convrate <= 0x09) { 1300 1284 name = "sa56004"; 1301 1285 } 1286 + } else 1287 + if ((address == 0x4C || address == 0x4D) 1288 + && man_id == 0x47) { /* GMT */ 1289 + if (chip_id == 0x01 /* G781 */ 1290 + && (config1 & 0x3F) == 0x00 1291 + && convrate <= 0x08) 1292 + name = "g781"; 1302 1293 } 1303 1294 1304 1295 if (!name) { /* identification failed */ ··· 1334 1311 device_remove_file(dev, &sensor_dev_attr_temp2_offset.dev_attr); 1335 1312 device_remove_file(dev, &dev_attr_pec); 1336 1313 sysfs_remove_group(&dev->kobj, &lm90_group); 1314 + } 1315 + 1316 + static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data) 1317 + { 1318 + /* Restore initial configuration */ 1319 + i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, 1320 + data->convrate_orig); 1321 + i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, 1322 + data->config_orig); 1337 1323 } 1338 1324 1339 1325 static void lm90_init_client(struct i2c_client *client) ··· 1414 1382 client->flags &= ~I2C_CLIENT_PEC; 1415 1383 } 1416 1384 1417 - /* Different devices have different alarm bits triggering the 1418 - * ALERT# output */ 1385 + /* 1386 + * Different devices have different alarm bits triggering the 1387 + * ALERT# output 1388 + */ 1419 1389 data->alert_alarms = lm90_params[data->kind].alert_alarms; 1420 1390 1421 1391 /* Set chip capabilities */ ··· 1433 1399 /* Register sysfs hooks */ 1434 1400 err = sysfs_create_group(&dev->kobj, &lm90_group); 1435 1401 if (err) 1436 - goto exit_free; 1402 + goto exit_restore; 1437 1403 if (client->flags & I2C_CLIENT_PEC) { 1438 1404 err = device_create_file(dev, &dev_attr_pec); 1439 1405 if (err) ··· 1472 1438 1473 1439 exit_remove_files: 1474 1440 lm90_remove_files(client, data); 1475 - exit_free: 1441 + exit_restore: 1442 + lm90_restore_conf(client, data); 1476 1443 kfree(data); 1477 1444 exit: 1478 1445 return err; ··· 1485 1450 1486 1451 hwmon_device_unregister(data->hwmon_dev); 1487 1452 lm90_remove_files(client, data); 1488 - 1489 - /* Restore initial configuration */ 1490 - i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, 1491 - data->convrate_orig); 1492 - i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, 1493 - data->config_orig); 1453 + lm90_restore_conf(client, data); 1494 1454 1495 1455 kfree(data); 1496 1456 return 0; ··· 1518 1488 dev_warn(&client->dev, 1519 1489 "temp%d out of range, please check!\n", 3); 1520 1490 1521 - /* Disable ALERT# output, because these chips don't implement 1522 - SMBus alert correctly; they should only hold the alert line 1523 - low briefly. */ 1491 + /* 1492 + * Disable ALERT# output, because these chips don't implement 1493 + * SMBus alert correctly; they should only hold the alert line 1494 + * low briefly. 1495 + */ 1524 1496 if ((data->flags & LM90_HAVE_BROKEN_ALERT) 1525 1497 && (alarms & data->alert_alarms)) { 1526 1498 dev_dbg(&client->dev, "Disabling ALERT#\n");
+78 -25
drivers/hwmon/mc13783-adc.c
··· 1 1 /* 2 - * Driver for the Freescale Semiconductor MC13783 adc. 2 + * Driver for the ADC on Freescale Semiconductor MC13783 and MC13892 PMICs. 3 3 * 4 4 * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved. 5 5 * Copyright (C) 2009 Sascha Hauer, Pengutronix ··· 18 18 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 19 */ 20 20 21 - #include <linux/mfd/mc13783.h> 21 + #include <linux/mfd/mc13xxx.h> 22 22 #include <linux/platform_device.h> 23 23 #include <linux/hwmon-sysfs.h> 24 24 #include <linux/kernel.h> ··· 28 28 #include <linux/init.h> 29 29 #include <linux/err.h> 30 30 31 - #define MC13783_ADC_NAME "mc13783-adc" 31 + #define DRIVER_NAME "mc13783-adc" 32 + 33 + /* platform device id driver data */ 34 + #define MC13783_ADC_16CHANS 1 35 + #define MC13783_ADC_BPDIV2 2 32 36 33 37 struct mc13783_adc_priv { 34 38 struct mc13xxx *mc13xxx; 35 39 struct device *hwmon_dev; 40 + char name[10]; 36 41 }; 37 42 38 43 static ssize_t mc13783_adc_show_name(struct device *dev, struct device_attribute 39 44 *devattr, char *buf) 40 45 { 41 - return sprintf(buf, "mc13783_adc\n"); 46 + struct mc13783_adc_priv *priv = dev_get_drvdata(dev); 47 + 48 + return sprintf(buf, "%s\n", priv->name); 42 49 } 43 50 44 51 static int mc13783_adc_read(struct device *dev, 45 52 struct device_attribute *devattr, unsigned int *val) 46 53 { 47 - struct platform_device *pdev = to_platform_device(dev); 48 - struct mc13783_adc_priv *priv = platform_get_drvdata(pdev); 54 + struct mc13783_adc_priv *priv = dev_get_drvdata(dev); 49 55 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 50 56 unsigned int channel = attr->index; 51 57 unsigned int sample[4]; ··· 74 68 struct device_attribute *devattr, char *buf) 75 69 { 76 70 unsigned val; 71 + struct platform_device *pdev = to_platform_device(dev); 72 + kernel_ulong_t driver_data = platform_get_device_id(pdev)->driver_data; 77 73 int ret = mc13783_adc_read(dev, devattr, &val); 78 74 79 75 if (ret) 80 76 return ret; 81 77 82 - /* 83 - * BP (channel 2) reports with offset 2.4V to the actual value to fit 84 - * the input range of the ADC. unit = 2.25mV = 9/4 mV. 85 - */ 86 - val = DIV_ROUND_CLOSEST(val * 9, 4) + 2400; 78 + if (driver_data & MC13783_ADC_BPDIV2) 79 + val = DIV_ROUND_CLOSEST(val * 9, 2); 80 + else 81 + /* 82 + * BP (channel 2) reports with offset 2.4V to the actual value 83 + * to fit the input range of the ADC. unit = 2.25mV = 9/4 mV. 84 + */ 85 + val = DIV_ROUND_CLOSEST(val * 9, 4) + 2400; 87 86 88 87 return sprintf(buf, "%u\n", val); 89 88 } ··· 125 114 static SENSOR_DEVICE_ATTR(in14_input, S_IRUGO, mc13783_adc_read_gp, NULL, 14); 126 115 static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, mc13783_adc_read_gp, NULL, 15); 127 116 128 - static struct attribute *mc13783_attr[] = { 117 + static struct attribute *mc13783_attr_base[] = { 129 118 &dev_attr_name.attr, 130 119 &sensor_dev_attr_in2_input.dev_attr.attr, 131 120 &sensor_dev_attr_in5_input.dev_attr.attr, 132 121 &sensor_dev_attr_in6_input.dev_attr.attr, 133 122 &sensor_dev_attr_in7_input.dev_attr.attr, 123 + NULL 124 + }; 125 + 126 + static const struct attribute_group mc13783_group_base = { 127 + .attrs = mc13783_attr_base, 128 + }; 129 + 130 + /* these are only used if MC13783_ADC_16CHANS is provided in driver data */ 131 + static struct attribute *mc13783_attr_16chans[] = { 134 132 &sensor_dev_attr_in8_input.dev_attr.attr, 135 133 &sensor_dev_attr_in9_input.dev_attr.attr, 136 134 &sensor_dev_attr_in10_input.dev_attr.attr, ··· 147 127 NULL 148 128 }; 149 129 150 - static const struct attribute_group mc13783_group = { 151 - .attrs = mc13783_attr, 130 + static const struct attribute_group mc13783_group_16chans = { 131 + .attrs = mc13783_attr_16chans, 152 132 }; 153 133 154 134 /* last four channels may be occupied by the touchscreen */ ··· 176 156 { 177 157 struct mc13783_adc_priv *priv; 178 158 int ret; 159 + const struct platform_device_id *id = platform_get_device_id(pdev); 160 + char *dash; 179 161 180 162 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 181 163 if (!priv) 182 164 return -ENOMEM; 183 165 184 166 priv->mc13xxx = dev_get_drvdata(pdev->dev.parent); 167 + snprintf(priv->name, ARRAY_SIZE(priv->name), "%s", id->name); 168 + dash = strchr(priv->name, '-'); 169 + if (dash) 170 + *dash = '\0'; 185 171 186 172 platform_set_drvdata(pdev, priv); 187 173 188 174 /* Register sysfs hooks */ 189 - ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group); 175 + ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_base); 190 176 if (ret) 191 - goto out_err_create1; 177 + goto out_err_create_base; 178 + 179 + if (id->driver_data & MC13783_ADC_16CHANS) { 180 + ret = sysfs_create_group(&pdev->dev.kobj, 181 + &mc13783_group_16chans); 182 + if (ret) 183 + goto out_err_create_16chans; 184 + } 192 185 193 186 if (!mc13783_adc_use_touchscreen(pdev)) { 194 187 ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_ts); 195 188 if (ret) 196 - goto out_err_create2; 189 + goto out_err_create_ts; 197 190 } 198 191 199 192 priv->hwmon_dev = hwmon_device_register(&pdev->dev); ··· 217 184 goto out_err_register; 218 185 } 219 186 220 - 221 187 return 0; 222 188 223 189 out_err_register: 224 190 225 191 if (!mc13783_adc_use_touchscreen(pdev)) 226 192 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts); 227 - out_err_create2: 193 + out_err_create_ts: 228 194 229 - sysfs_remove_group(&pdev->dev.kobj, &mc13783_group); 230 - out_err_create1: 195 + if (id->driver_data & MC13783_ADC_16CHANS) 196 + sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_16chans); 197 + out_err_create_16chans: 198 + 199 + sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_base); 200 + out_err_create_base: 231 201 232 202 platform_set_drvdata(pdev, NULL); 233 203 kfree(priv); ··· 241 205 static int __devexit mc13783_adc_remove(struct platform_device *pdev) 242 206 { 243 207 struct mc13783_adc_priv *priv = platform_get_drvdata(pdev); 208 + kernel_ulong_t driver_data = platform_get_device_id(pdev)->driver_data; 244 209 245 210 hwmon_device_unregister(priv->hwmon_dev); 246 211 247 212 if (!mc13783_adc_use_touchscreen(pdev)) 248 213 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts); 249 214 250 - sysfs_remove_group(&pdev->dev.kobj, &mc13783_group); 215 + if (driver_data & MC13783_ADC_16CHANS) 216 + sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_16chans); 217 + 218 + sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_base); 251 219 252 220 platform_set_drvdata(pdev, NULL); 253 221 kfree(priv); ··· 259 219 return 0; 260 220 } 261 221 222 + static const struct platform_device_id mc13783_adc_idtable[] = { 223 + { 224 + .name = "mc13783-adc", 225 + .driver_data = MC13783_ADC_16CHANS, 226 + }, { 227 + .name = "mc13892-adc", 228 + .driver_data = MC13783_ADC_BPDIV2, 229 + }, { 230 + /* sentinel */ 231 + } 232 + }; 233 + MODULE_DEVICE_TABLE(platform, mc13783_adc_idtable); 234 + 262 235 static struct platform_driver mc13783_adc_driver = { 263 - .remove = __devexit_p(mc13783_adc_remove), 236 + .remove = __devexit_p(mc13783_adc_remove), 264 237 .driver = { 265 238 .owner = THIS_MODULE, 266 - .name = MC13783_ADC_NAME, 239 + .name = DRIVER_NAME, 267 240 }, 241 + .id_table = mc13783_adc_idtable, 268 242 }; 269 243 270 244 static int __init mc13783_adc_init(void) ··· 297 243 MODULE_DESCRIPTION("MC13783 ADC driver"); 298 244 MODULE_AUTHOR("Luotao Fu <l.fu@pengutronix.de>"); 299 245 MODULE_LICENSE("GPL"); 300 - MODULE_ALIAS("platform:" MC13783_ADC_NAME);
+171
drivers/hwmon/mcp3021.c
··· 1 + /* 2 + * mcp3021.c - driver for the Microchip MCP3021 chip 3 + * 4 + * Copyright (C) 2008-2009, 2012 Freescale Semiconductor, Inc. 5 + * Author: Mingkai Hu <Mingkai.hu@freescale.com> 6 + * 7 + * This driver export the value of analog input voltage to sysfs, the 8 + * voltage unit is mV. Through the sysfs interface, lm-sensors tool 9 + * can also display the input voltage. 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + */ 16 + 17 + #include <linux/kernel.h> 18 + #include <linux/module.h> 19 + #include <linux/hwmon.h> 20 + #include <linux/slab.h> 21 + #include <linux/i2c.h> 22 + #include <linux/err.h> 23 + #include <linux/device.h> 24 + 25 + /* Vdd info */ 26 + #define MCP3021_VDD_MAX 5500 27 + #define MCP3021_VDD_MIN 2700 28 + #define MCP3021_VDD_REF 3300 29 + 30 + /* output format */ 31 + #define MCP3021_SAR_SHIFT 2 32 + #define MCP3021_SAR_MASK 0x3ff 33 + 34 + #define MCP3021_OUTPUT_RES 10 /* 10-bit resolution */ 35 + #define MCP3021_OUTPUT_SCALE 4 36 + 37 + /* 38 + * Client data (each client gets its own) 39 + */ 40 + struct mcp3021_data { 41 + struct device *hwmon_dev; 42 + u32 vdd; /* device power supply */ 43 + }; 44 + 45 + static int mcp3021_read16(struct i2c_client *client) 46 + { 47 + int ret; 48 + u16 reg; 49 + __be16 buf; 50 + 51 + ret = i2c_master_recv(client, (char *)&buf, 2); 52 + if (ret < 0) 53 + return ret; 54 + if (ret != 2) 55 + return -EIO; 56 + 57 + /* The output code of the MCP3021 is transmitted with MSB first. */ 58 + reg = be16_to_cpu(buf); 59 + 60 + /* 61 + * The ten-bit output code is composed of the lower 4-bit of the 62 + * first byte and the upper 6-bit of the second byte. 63 + */ 64 + reg = (reg >> MCP3021_SAR_SHIFT) & MCP3021_SAR_MASK; 65 + 66 + return reg; 67 + } 68 + 69 + static inline u16 volts_from_reg(u16 vdd, u16 val) 70 + { 71 + if (val == 0) 72 + return 0; 73 + 74 + val = val * MCP3021_OUTPUT_SCALE - MCP3021_OUTPUT_SCALE / 2; 75 + 76 + return val * DIV_ROUND_CLOSEST(vdd, 77 + (1 << MCP3021_OUTPUT_RES) * MCP3021_OUTPUT_SCALE); 78 + } 79 + 80 + static ssize_t show_in_input(struct device *dev, struct device_attribute *attr, 81 + char *buf) 82 + { 83 + struct i2c_client *client = to_i2c_client(dev); 84 + struct mcp3021_data *data = i2c_get_clientdata(client); 85 + int reg, in_input; 86 + 87 + reg = mcp3021_read16(client); 88 + if (reg < 0) 89 + return reg; 90 + 91 + in_input = volts_from_reg(data->vdd, reg); 92 + return sprintf(buf, "%d\n", in_input); 93 + } 94 + 95 + static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input, NULL); 96 + 97 + static int mcp3021_probe(struct i2c_client *client, 98 + const struct i2c_device_id *id) 99 + { 100 + int err; 101 + struct mcp3021_data *data = NULL; 102 + 103 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 104 + return -ENODEV; 105 + 106 + data = kzalloc(sizeof(struct mcp3021_data), GFP_KERNEL); 107 + if (!data) 108 + return -ENOMEM; 109 + 110 + i2c_set_clientdata(client, data); 111 + 112 + if (client->dev.platform_data) { 113 + data->vdd = *(u32 *)client->dev.platform_data; 114 + if (data->vdd > MCP3021_VDD_MAX || 115 + data->vdd < MCP3021_VDD_MIN) { 116 + err = -EINVAL; 117 + goto exit_free; 118 + } 119 + } else 120 + data->vdd = MCP3021_VDD_REF; 121 + 122 + err = sysfs_create_file(&client->dev.kobj, &dev_attr_in0_input.attr); 123 + if (err) 124 + goto exit_free; 125 + 126 + data->hwmon_dev = hwmon_device_register(&client->dev); 127 + if (IS_ERR(data->hwmon_dev)) { 128 + err = PTR_ERR(data->hwmon_dev); 129 + goto exit_remove; 130 + } 131 + 132 + return 0; 133 + 134 + exit_remove: 135 + sysfs_remove_file(&client->dev.kobj, &dev_attr_in0_input.attr); 136 + exit_free: 137 + kfree(data); 138 + return err; 139 + } 140 + 141 + static int mcp3021_remove(struct i2c_client *client) 142 + { 143 + struct mcp3021_data *data = i2c_get_clientdata(client); 144 + 145 + hwmon_device_unregister(data->hwmon_dev); 146 + sysfs_remove_file(&client->dev.kobj, &dev_attr_in0_input.attr); 147 + kfree(data); 148 + 149 + return 0; 150 + } 151 + 152 + static const struct i2c_device_id mcp3021_id[] = { 153 + { "mcp3021", 0 }, 154 + { } 155 + }; 156 + MODULE_DEVICE_TABLE(i2c, mcp3021_id); 157 + 158 + static struct i2c_driver mcp3021_driver = { 159 + .driver = { 160 + .name = "mcp3021", 161 + }, 162 + .probe = mcp3021_probe, 163 + .remove = mcp3021_remove, 164 + .id_table = mcp3021_id, 165 + }; 166 + 167 + module_i2c_driver(mcp3021_driver); 168 + 169 + MODULE_AUTHOR("Mingkai Hu <Mingkai.hu@freescale.com>"); 170 + MODULE_DESCRIPTION("Microchip MCP3021 driver"); 171 + MODULE_LICENSE("GPL");
+86 -46
drivers/hwmon/w83795.c
··· 72 72 #define TEMP_CRIT_HYST 2 73 73 #define TEMP_WARN 3 74 74 #define TEMP_WARN_HYST 4 75 - /* only crit and crit_hyst affect real-time alarm status 76 - * current crit crit_hyst warn warn_hyst */ 75 + /* 76 + * only crit and crit_hyst affect real-time alarm status 77 + * current crit crit_hyst warn warn_hyst 78 + */ 77 79 static const u16 W83795_REG_TEMP[][5] = { 78 80 {0x21, 0x96, 0x97, 0x98, 0x99}, /* TD1/TR1 */ 79 81 {0x22, 0x9a, 0x9b, 0x9c, 0x9d}, /* TD2/TR2 */ ··· 356 354 u8 temp_mode; /* Bit vector, 0 = TR, 1 = TD */ 357 355 u8 temp_src[3]; /* Register value */ 358 356 359 - u8 enable_dts; /* Enable PECI and SB-TSI, 357 + u8 enable_dts; /* 358 + * Enable PECI and SB-TSI, 360 359 * bit 0: =1 enable, =0 disable, 361 - * bit 1: =1 AMD SB-TSI, =0 Intel PECI */ 360 + * bit 1: =1 AMD SB-TSI, =0 Intel PECI 361 + */ 362 362 u8 has_dts; /* Enable monitor DTS temp */ 363 363 s8 dts[8]; /* Register value */ 364 364 u8 dts_read_vrlsb[8]; /* Register value */ 365 365 s8 dts_ext[4]; /* Register value */ 366 366 367 - u8 has_pwm; /* 795g supports 8 pwm, 795adg only supports 2, 367 + u8 has_pwm; /* 368 + * 795g supports 8 pwm, 795adg only supports 2, 368 369 * no config register, only affected by chip 369 - * type */ 370 - u8 pwm[8][5]; /* Register value, output, freq, start, 371 - * non stop, stop time */ 370 + * type 371 + */ 372 + u8 pwm[8][5]; /* 373 + * Register value, output, freq, start, 374 + * non stop, stop time 375 + */ 372 376 u16 clkin; /* CLKIN frequency in kHz */ 373 377 u8 pwm_fcms[2]; /* Register value */ 374 378 u8 pwm_tfmr[6]; /* Register value */ 375 379 u8 pwm_fomc; /* Register value */ 376 380 377 - u16 target_speed[8]; /* Register value, target speed for speed 378 - * cruise */ 381 + u16 target_speed[8]; /* 382 + * Register value, target speed for speed 383 + * cruise 384 + */ 379 385 u8 tol_speed; /* tolerance of target speed */ 380 386 u8 pwm_temp[6][4]; /* TTTI, CTFS, HCT, HOT */ 381 387 u8 sf4_reg[6][2][7]; /* 6 temp, temp/dcpwm, 7 registers */ ··· 492 482 /* Read the fan limits */ 493 483 lsb = 0; /* Silent false gcc warning */ 494 484 for (i = 0; i < ARRAY_SIZE(data->fan); i++) { 495 - /* Each register contains LSB for 2 fans, but we want to 496 - * read it only once to save time */ 485 + /* 486 + * Each register contains LSB for 2 fans, but we want to 487 + * read it only once to save time 488 + */ 497 489 if ((i & 1) == 0 && (data->has_fan & (3 << i))) 498 490 lsb = w83795_read(client, W83795_REG_FAN_MIN_LSB(i)); 499 491 ··· 677 665 w83795_read(client, W83795_REG_PWM(i, PWM_OUTPUT)); 678 666 } 679 667 680 - /* Update intrusion and alarms 668 + /* 669 + * Update intrusion and alarms 681 670 * It is important to read intrusion first, because reading from 682 - * register SMI STS6 clears the interrupt status temporarily. */ 671 + * register SMI STS6 clears the interrupt status temporarily. 672 + */ 683 673 tmp = w83795_read(client, W83795_REG_ALARM_CTRL); 684 674 /* Switch to interrupt status for intrusion if needed */ 685 675 if (tmp & ALARM_CTRL_RTSACS) ··· 942 928 return -EINVAL; 943 929 if (val < 1 || val > 2) 944 930 return -EINVAL; 931 + 932 + #ifndef CONFIG_SENSORS_W83795_FANCTRL 933 + if (val > 1) { 934 + dev_warn(dev, "Automatic fan speed control support disabled\n"); 935 + dev_warn(dev, "Build with CONFIG_SENSORS_W83795_FANCTRL=y if you want it\n"); 936 + return -EOPNOTSUPP; 937 + } 938 + #endif 945 939 946 940 mutex_lock(&data->update_lock); 947 941 switch (val) { ··· 1617 1595 1618 1596 #define NOT_USED -1 1619 1597 1620 - /* Don't change the attribute order, _max, _min and _beep are accessed by index 1621 - * somewhere else in the code */ 1598 + /* 1599 + * Don't change the attribute order, _max, _min and _beep are accessed by index 1600 + * somewhere else in the code 1601 + */ 1622 1602 #define SENSOR_ATTR_IN(index) { \ 1623 1603 SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \ 1624 1604 IN_READ, index), \ ··· 1634 1610 show_alarm_beep, store_beep, BEEP_ENABLE, \ 1635 1611 index + ((index > 14) ? 1 : 0)) } 1636 1612 1637 - /* Don't change the attribute order, _beep is accessed by index 1638 - * somewhere else in the code */ 1613 + /* 1614 + * Don't change the attribute order, _beep is accessed by index 1615 + * somewhere else in the code 1616 + */ 1639 1617 #define SENSOR_ATTR_FAN(index) { \ 1640 1618 SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \ 1641 1619 NULL, FAN_INPUT, index - 1), \ ··· 1651 1625 #define SENSOR_ATTR_PWM(index) { \ 1652 1626 SENSOR_ATTR_2(pwm##index, S_IWUSR | S_IRUGO, show_pwm, \ 1653 1627 store_pwm, PWM_OUTPUT, index - 1), \ 1628 + SENSOR_ATTR_2(pwm##index##_enable, S_IWUSR | S_IRUGO, \ 1629 + show_pwm_enable, store_pwm_enable, NOT_USED, index - 1), \ 1630 + SENSOR_ATTR_2(pwm##index##_mode, S_IRUGO, \ 1631 + show_pwm_mode, NULL, NOT_USED, index - 1), \ 1632 + SENSOR_ATTR_2(pwm##index##_freq, S_IWUSR | S_IRUGO, \ 1633 + show_pwm, store_pwm, PWM_FREQ, index - 1), \ 1654 1634 SENSOR_ATTR_2(pwm##index##_nonstop, S_IWUSR | S_IRUGO, \ 1655 1635 show_pwm, store_pwm, PWM_NONSTOP, index - 1), \ 1656 1636 SENSOR_ATTR_2(pwm##index##_start, S_IWUSR | S_IRUGO, \ 1657 1637 show_pwm, store_pwm, PWM_START, index - 1), \ 1658 1638 SENSOR_ATTR_2(pwm##index##_stop_time, S_IWUSR | S_IRUGO, \ 1659 1639 show_pwm, store_pwm, PWM_STOP_TIME, index - 1), \ 1660 - SENSOR_ATTR_2(pwm##index##_freq, S_IWUSR | S_IRUGO, \ 1661 - show_pwm, store_pwm, PWM_FREQ, index - 1), \ 1662 - SENSOR_ATTR_2(pwm##index##_enable, S_IWUSR | S_IRUGO, \ 1663 - show_pwm_enable, store_pwm_enable, NOT_USED, index - 1), \ 1664 - SENSOR_ATTR_2(pwm##index##_mode, S_IRUGO, \ 1665 - show_pwm_mode, NULL, NOT_USED, index - 1), \ 1666 1640 SENSOR_ATTR_2(fan##index##_target, S_IWUSR | S_IRUGO, \ 1667 1641 show_fanin, store_fanin, FANIN_TARGET, index - 1) } 1668 1642 1669 - /* Don't change the attribute order, _beep is accessed by index 1670 - * somewhere else in the code */ 1643 + /* 1644 + * Don't change the attribute order, _beep is accessed by index 1645 + * somewhere else in the code 1646 + */ 1671 1647 #define SENSOR_ATTR_DTS(index) { \ 1672 1648 SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \ 1673 1649 show_dts_mode, NULL, NOT_USED, index - 7), \ ··· 1688 1660 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ 1689 1661 show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) } 1690 1662 1691 - /* Don't change the attribute order, _beep is accessed by index 1692 - * somewhere else in the code */ 1663 + /* 1664 + * Don't change the attribute order, _beep is accessed by index 1665 + * somewhere else in the code 1666 + */ 1693 1667 #define SENSOR_ATTR_TEMP(index) { \ 1694 1668 SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \ 1695 1669 show_temp_mode, store_temp_mode, NOT_USED, index - 1), \ ··· 1897 1867 1898 1868 device_id = i2c_smbus_read_byte_data(client, W83795_REG_DEVICEID); 1899 1869 1900 - /* Special case for rev. A chips; can't be checked first because later 1901 - revisions emulate this for compatibility */ 1870 + /* 1871 + * Special case for rev. A chips; can't be checked first because later 1872 + * revisions emulate this for compatibility 1873 + */ 1902 1874 if (device_id < 0 || (device_id & 0xf0) != 0x50) { 1903 1875 int alt_id; 1904 1876 ··· 1952 1920 return -ENODEV; 1953 1921 } 1954 1922 1955 - /* If Nuvoton chip, address of chip and W83795_REG_I2C_ADDR 1956 - should match */ 1923 + /* 1924 + * If Nuvoton chip, address of chip and W83795_REG_I2C_ADDR 1925 + * should match 1926 + */ 1957 1927 if ((bank & 0x07) == 0) { 1958 1928 i2c_addr = i2c_smbus_read_byte_data(client, 1959 1929 W83795_REG_I2C_ADDR); ··· 1967 1933 } 1968 1934 } 1969 1935 1970 - /* Check 795 chip type: 795G or 795ADG 1971 - Usually we don't write to chips during detection, but here we don't 1972 - quite have the choice; hopefully it's OK, we are about to return 1973 - success anyway */ 1936 + /* 1937 + * Check 795 chip type: 795G or 795ADG 1938 + * Usually we don't write to chips during detection, but here we don't 1939 + * quite have the choice; hopefully it's OK, we are about to return 1940 + * success anyway 1941 + */ 1974 1942 if ((bank & 0x07) != 0) 1975 1943 i2c_smbus_write_byte_data(client, W83795_REG_BANKSEL, 1976 1944 bank & ~0x07); ··· 1988 1952 1989 1953 return 0; 1990 1954 } 1955 + 1956 + #ifdef CONFIG_SENSORS_W83795_FANCTRL 1957 + #define NUM_PWM_ATTRIBUTES ARRAY_SIZE(w83795_pwm[0]) 1958 + #define NUM_TEMP_ATTRIBUTES ARRAY_SIZE(w83795_temp[0]) 1959 + #else 1960 + #define NUM_PWM_ATTRIBUTES 4 1961 + #define NUM_TEMP_ATTRIBUTES 8 1962 + #endif 1991 1963 1992 1964 static int w83795_handle_files(struct device *dev, int (*fn)(struct device *, 1993 1965 const struct device_attribute *)) ··· 2050 2006 } 2051 2007 } 2052 2008 2053 - #ifdef CONFIG_SENSORS_W83795_FANCTRL 2054 2009 for (i = 0; i < data->has_pwm; i++) { 2055 - for (j = 0; j < ARRAY_SIZE(w83795_pwm[0]); j++) { 2010 + for (j = 0; j < NUM_PWM_ATTRIBUTES; j++) { 2056 2011 err = fn(dev, &w83795_pwm[i][j].dev_attr); 2057 2012 if (err) 2058 2013 return err; 2059 2014 } 2060 2015 } 2061 - #endif 2062 2016 2063 2017 for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) { 2064 2018 if (!(data->has_temp & (1 << i))) 2065 2019 continue; 2066 - #ifdef CONFIG_SENSORS_W83795_FANCTRL 2067 - for (j = 0; j < ARRAY_SIZE(w83795_temp[0]); j++) { 2068 - #else 2069 - for (j = 0; j < 8; j++) { 2070 - #endif 2020 + for (j = 0; j < NUM_TEMP_ATTRIBUTES; j++) { 2071 2021 if (j == 7 && !data->enable_beep) 2072 2022 continue; 2073 2023 err = fn(dev, &w83795_temp[i][j].dev_attr); ··· 2221 2183 /* The W83795G has a dedicated BEEP pin */ 2222 2184 data->enable_beep = 1; 2223 2185 } else { 2224 - /* The W83795ADG has a shared pin for OVT# and BEEP, so you 2225 - * can't have both */ 2186 + /* 2187 + * The W83795ADG has a shared pin for OVT# and BEEP, so you 2188 + * can't have both 2189 + */ 2226 2190 tmp = w83795_read(client, W83795_REG_OVT_CFG); 2227 2191 if ((tmp & OVT_CFG_SEL) == 0) 2228 2192 data->enable_beep = 1;