Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * pc87360.c - Part of lm_sensors, Linux kernel modules |
| 4 | * for hardware monitoring |
Jean Delvare | 7c81c60f | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 5 | * Copyright (C) 2004, 2007 Jean Delvare <jdelvare@suse.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * Copied from smsc47m1.c: |
| 8 | * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> |
| 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * Supports the following chips: |
| 11 | * |
| 12 | * Chip #vin #fan #pwm #temp devid |
| 13 | * PC87360 - 2 2 - 0xE1 |
| 14 | * PC87363 - 2 2 - 0xE8 |
| 15 | * PC87364 - 3 3 - 0xE4 |
| 16 | * PC87365 11 3 3 2 0xE5 |
| 17 | * PC87366 11 3 3 3-4 0xE9 |
| 18 | * |
| 19 | * This driver assumes that no more than one chip is present, and one of |
| 20 | * the standard Super-I/O addresses is used (0x2E/0x2F or 0x4E/0x4F). |
| 21 | */ |
| 22 | |
Joe Perches | 9e991c6 | 2011-01-12 21:55:11 +0100 | [diff] [blame] | 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/jiffies.h> |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 29 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 30 | #include <linux/hwmon.h> |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 31 | #include <linux/hwmon-sysfs.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 32 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 33 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 34 | #include <linux/mutex.h> |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 35 | #include <linux/acpi.h> |
H Hartley Sweeten | 6055fae | 2009-09-15 17:18:13 +0200 | [diff] [blame] | 36 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static u8 devid; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 39 | static struct platform_device *pdev; |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 40 | static unsigned short extra_isa[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | static u8 confreg[4]; |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | static int init = 1; |
| 44 | module_param(init, int, 0); |
| 45 | MODULE_PARM_DESC(init, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 46 | "Chip initialization level:\n" |
| 47 | " 0: None\n" |
| 48 | "*1: Forcibly enable internal voltage and temperature channels, except in9\n" |
| 49 | " 2: Forcibly enable all voltage and temperature channels, except in9\n" |
| 50 | " 3: Forcibly enable all voltage and temperature channels, including in9"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 52 | static unsigned short force_id; |
| 53 | module_param(force_id, ushort, 0); |
| 54 | MODULE_PARM_DESC(force_id, "Override the detected device ID"); |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* |
| 57 | * Super-I/O registers and operations |
| 58 | */ |
| 59 | |
| 60 | #define DEV 0x07 /* Register: Logical device select */ |
| 61 | #define DEVID 0x20 /* Register: Device ID */ |
| 62 | #define ACT 0x30 /* Register: Device activation */ |
| 63 | #define BASE 0x60 /* Register: Base address */ |
| 64 | |
| 65 | #define FSCM 0x09 /* Logical device: fans */ |
| 66 | #define VLM 0x0d /* Logical device: voltages */ |
| 67 | #define TMS 0x0e /* Logical device: temperatures */ |
Jim Cromie | 2a32ec2 | 2008-10-18 20:27:33 -0700 | [diff] [blame] | 68 | #define LDNI_MAX 3 |
| 69 | static const u8 logdev[LDNI_MAX] = { FSCM, VLM, TMS }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | #define LD_FAN 0 |
| 72 | #define LD_IN 1 |
| 73 | #define LD_TEMP 2 |
| 74 | |
| 75 | static inline void superio_outb(int sioaddr, int reg, int val) |
| 76 | { |
| 77 | outb(reg, sioaddr); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 78 | outb(val, sioaddr + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static inline int superio_inb(int sioaddr, int reg) |
| 82 | { |
| 83 | outb(reg, sioaddr); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 84 | return inb(sioaddr + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static inline void superio_exit(int sioaddr) |
| 88 | { |
| 89 | outb(0x02, sioaddr); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 90 | outb(0x02, sioaddr + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Logical devices |
| 95 | */ |
| 96 | |
| 97 | #define PC87360_EXTENT 0x10 |
| 98 | #define PC87365_REG_BANK 0x09 |
| 99 | #define NO_BANK 0xff |
| 100 | |
| 101 | /* |
| 102 | * Fan registers and conversions |
| 103 | */ |
| 104 | |
| 105 | /* nr has to be 0 or 1 (PC87360/87363) or 2 (PC87364/87365/87366) */ |
| 106 | #define PC87360_REG_PRESCALE(nr) (0x00 + 2 * (nr)) |
| 107 | #define PC87360_REG_PWM(nr) (0x01 + 2 * (nr)) |
| 108 | #define PC87360_REG_FAN_MIN(nr) (0x06 + 3 * (nr)) |
| 109 | #define PC87360_REG_FAN(nr) (0x07 + 3 * (nr)) |
| 110 | #define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr)) |
| 111 | |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 112 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : \ |
| 113 | 480000 / ((val) * (div))) |
| 114 | #define FAN_TO_REG(val, div) ((val) <= 100 ? 0 : \ |
| 115 | 480000 / ((val) * (div))) |
| 116 | #define FAN_DIV_FROM_REG(val) (1 << (((val) >> 5) & 0x03)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #define FAN_STATUS_FROM_REG(val) ((val) & 0x07) |
| 118 | |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 119 | #define FAN_CONFIG_MONITOR(val, nr) (((val) >> (2 + (nr) * 3)) & 1) |
| 120 | #define FAN_CONFIG_CONTROL(val, nr) (((val) >> (3 + (nr) * 3)) & 1) |
| 121 | #define FAN_CONFIG_INVERT(val, nr) (((val) >> (4 + (nr) * 3)) & 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 123 | #define PWM_FROM_REG(val, inv) ((inv) ? 255 - (val) : (val)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | static inline u8 PWM_TO_REG(int val, int inv) |
| 125 | { |
| 126 | if (inv) |
| 127 | val = 255 - val; |
| 128 | if (val < 0) |
| 129 | return 0; |
| 130 | if (val > 255) |
| 131 | return 255; |
| 132 | return val; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Voltage registers and conversions |
| 137 | */ |
| 138 | |
| 139 | #define PC87365_REG_IN_CONVRATE 0x07 |
| 140 | #define PC87365_REG_IN_CONFIG 0x08 |
| 141 | #define PC87365_REG_IN 0x0B |
| 142 | #define PC87365_REG_IN_MIN 0x0D |
| 143 | #define PC87365_REG_IN_MAX 0x0C |
| 144 | #define PC87365_REG_IN_STATUS 0x0A |
| 145 | #define PC87365_REG_IN_ALARMS1 0x00 |
| 146 | #define PC87365_REG_IN_ALARMS2 0x01 |
| 147 | #define PC87365_REG_VID 0x06 |
| 148 | |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 149 | #define IN_FROM_REG(val, ref) (((val) * (ref) + 128) / 256) |
| 150 | #define IN_TO_REG(val, ref) ((val) < 0 ? 0 : \ |
| 151 | (val) * 256 >= (ref) * 255 ? 255 : \ |
| 152 | ((val) * 256 + (ref) / 2) / (ref)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * Temperature registers and conversions |
| 156 | */ |
| 157 | |
| 158 | #define PC87365_REG_TEMP_CONFIG 0x08 |
| 159 | #define PC87365_REG_TEMP 0x0B |
| 160 | #define PC87365_REG_TEMP_MIN 0x0D |
| 161 | #define PC87365_REG_TEMP_MAX 0x0C |
| 162 | #define PC87365_REG_TEMP_CRIT 0x0E |
| 163 | #define PC87365_REG_TEMP_STATUS 0x0A |
| 164 | #define PC87365_REG_TEMP_ALARMS 0x00 |
| 165 | |
| 166 | #define TEMP_FROM_REG(val) ((val) * 1000) |
| 167 | #define TEMP_TO_REG(val) ((val) < -55000 ? -55 : \ |
| 168 | (val) > 127000 ? 127 : \ |
| 169 | (val) < 0 ? ((val) - 500) / 1000 : \ |
| 170 | ((val) + 500) / 1000) |
| 171 | |
| 172 | /* |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 173 | * Device data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | */ |
| 175 | |
| 176 | struct pc87360_data { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 177 | const char *name; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 178 | struct device *hwmon_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 179 | struct mutex lock; |
| 180 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | char valid; /* !=0 if following fields are valid */ |
| 182 | unsigned long last_updated; /* In jiffies */ |
| 183 | |
| 184 | int address[3]; |
| 185 | |
| 186 | u8 fannr, innr, tempnr; |
| 187 | |
| 188 | u8 fan[3]; /* Register value */ |
| 189 | u8 fan_min[3]; /* Register value */ |
| 190 | u8 fan_status[3]; /* Register value */ |
| 191 | u8 pwm[3]; /* Register value */ |
| 192 | u16 fan_conf; /* Configuration register values, combined */ |
| 193 | |
| 194 | u16 in_vref; /* 1 mV/bit */ |
| 195 | u8 in[14]; /* Register value */ |
| 196 | u8 in_min[14]; /* Register value */ |
| 197 | u8 in_max[14]; /* Register value */ |
| 198 | u8 in_crit[3]; /* Register value */ |
| 199 | u8 in_status[14]; /* Register value */ |
| 200 | u16 in_alarms; /* Register values, combined, masked */ |
| 201 | u8 vid_conf; /* Configuration register value */ |
| 202 | u8 vrm; |
| 203 | u8 vid; /* Register value */ |
| 204 | |
| 205 | s8 temp[3]; /* Register value */ |
| 206 | s8 temp_min[3]; /* Register value */ |
| 207 | s8 temp_max[3]; /* Register value */ |
| 208 | s8 temp_crit[3]; /* Register value */ |
| 209 | u8 temp_status[3]; /* Register value */ |
| 210 | u8 temp_alarms; /* Register value, masked */ |
| 211 | }; |
| 212 | |
| 213 | /* |
| 214 | * Functions declaration |
| 215 | */ |
| 216 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 217 | static int pc87360_probe(struct platform_device *pdev); |
Bill Pemberton | 281dfd0 | 2012-11-19 13:25:51 -0500 | [diff] [blame] | 218 | static int pc87360_remove(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 221 | u8 reg); |
| 222 | static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 223 | u8 reg, u8 value); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 224 | static void pc87360_init_device(struct platform_device *pdev, |
| 225 | int use_thermistors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | static struct pc87360_data *pc87360_update_device(struct device *dev); |
| 227 | |
| 228 | /* |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 229 | * Driver data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | */ |
| 231 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 232 | static struct platform_driver pc87360_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 233 | .driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 234 | .name = "pc87360", |
| 235 | }, |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 236 | .probe = pc87360_probe, |
Bill Pemberton | 9e5e9b7 | 2012-11-19 13:21:20 -0500 | [diff] [blame] | 237 | .remove = pc87360_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | /* |
| 241 | * Sysfs stuff |
| 242 | */ |
| 243 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 244 | static ssize_t fan_input_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 245 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 246 | { |
| 247 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 248 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 249 | return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[attr->index], |
| 250 | FAN_DIV_FROM_REG(data->fan_status[attr->index]))); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 251 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 252 | static ssize_t fan_min_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 253 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 254 | { |
| 255 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 256 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 257 | return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[attr->index], |
| 258 | FAN_DIV_FROM_REG(data->fan_status[attr->index]))); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 259 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 260 | static ssize_t fan_div_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 261 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 262 | { |
| 263 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 264 | struct pc87360_data *data = pc87360_update_device(dev); |
| 265 | return sprintf(buf, "%u\n", |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 266 | FAN_DIV_FROM_REG(data->fan_status[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 267 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 268 | static ssize_t fan_status_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 269 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 270 | { |
| 271 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 272 | struct pc87360_data *data = pc87360_update_device(dev); |
| 273 | return sprintf(buf, "%u\n", |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 274 | FAN_STATUS_FROM_REG(data->fan_status[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 275 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 276 | static ssize_t fan_min_store(struct device *dev, |
| 277 | struct device_attribute *devattr, |
| 278 | const char *buf, size_t count) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 279 | { |
| 280 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 281 | struct pc87360_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 282 | long fan_min; |
| 283 | int err; |
| 284 | |
| 285 | err = kstrtol(buf, 10, &fan_min); |
| 286 | if (err) |
| 287 | return err; |
Jim Cromie | 11be27e | 2005-09-02 23:05:07 +0200 | [diff] [blame] | 288 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 289 | mutex_lock(&data->update_lock); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 290 | fan_min = FAN_TO_REG(fan_min, |
| 291 | FAN_DIV_FROM_REG(data->fan_status[attr->index])); |
Jim Cromie | 11be27e | 2005-09-02 23:05:07 +0200 | [diff] [blame] | 292 | |
| 293 | /* If it wouldn't fit, change clock divisor */ |
| 294 | while (fan_min > 255 |
| 295 | && (data->fan_status[attr->index] & 0x60) != 0x60) { |
| 296 | fan_min >>= 1; |
| 297 | data->fan[attr->index] >>= 1; |
| 298 | data->fan_status[attr->index] += 0x20; |
| 299 | } |
| 300 | data->fan_min[attr->index] = fan_min > 255 ? 255 : fan_min; |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 301 | pc87360_write_value(data, LD_FAN, NO_BANK, |
| 302 | PC87360_REG_FAN_MIN(attr->index), |
Jim Cromie | 11be27e | 2005-09-02 23:05:07 +0200 | [diff] [blame] | 303 | data->fan_min[attr->index]); |
| 304 | |
| 305 | /* Write new divider, preserve alarm bits */ |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 306 | pc87360_write_value(data, LD_FAN, NO_BANK, |
| 307 | PC87360_REG_FAN_STATUS(attr->index), |
Jim Cromie | 11be27e | 2005-09-02 23:05:07 +0200 | [diff] [blame] | 308 | data->fan_status[attr->index] & 0xF9); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 309 | mutex_unlock(&data->update_lock); |
Jim Cromie | 11be27e | 2005-09-02 23:05:07 +0200 | [diff] [blame] | 310 | |
| 311 | return count; |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 314 | static struct sensor_device_attribute fan_input[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 315 | SENSOR_ATTR_RO(fan1_input, fan_input, 0), |
| 316 | SENSOR_ATTR_RO(fan2_input, fan_input, 1), |
| 317 | SENSOR_ATTR_RO(fan3_input, fan_input, 2), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 318 | }; |
| 319 | static struct sensor_device_attribute fan_status[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 320 | SENSOR_ATTR_RO(fan1_status, fan_status, 0), |
| 321 | SENSOR_ATTR_RO(fan2_status, fan_status, 1), |
| 322 | SENSOR_ATTR_RO(fan3_status, fan_status, 2), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 323 | }; |
| 324 | static struct sensor_device_attribute fan_div[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 325 | SENSOR_ATTR_RO(fan1_div, fan_div, 0), |
| 326 | SENSOR_ATTR_RO(fan2_div, fan_div, 1), |
| 327 | SENSOR_ATTR_RO(fan3_div, fan_div, 2), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 328 | }; |
| 329 | static struct sensor_device_attribute fan_min[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 330 | SENSOR_ATTR_RW(fan1_min, fan_min, 0), |
| 331 | SENSOR_ATTR_RW(fan2_min, fan_min, 1), |
| 332 | SENSOR_ATTR_RW(fan3_min, fan_min, 2), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 333 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 335 | #define FAN_UNIT_ATTRS(X) \ |
| 336 | { &fan_input[X].dev_attr.attr, \ |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 337 | &fan_status[X].dev_attr.attr, \ |
| 338 | &fan_div[X].dev_attr.attr, \ |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 339 | &fan_min[X].dev_attr.attr, \ |
| 340 | NULL \ |
| 341 | } |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 342 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 343 | static ssize_t pwm_show(struct device *dev, struct device_attribute *devattr, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 344 | char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 345 | { |
| 346 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 347 | struct pc87360_data *data = pc87360_update_device(dev); |
| 348 | return sprintf(buf, "%u\n", |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 349 | PWM_FROM_REG(data->pwm[attr->index], |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 350 | FAN_CONFIG_INVERT(data->fan_conf, |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 351 | attr->index))); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 352 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 353 | static ssize_t pwm_store(struct device *dev, struct device_attribute *devattr, |
| 354 | const char *buf, size_t count) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 355 | { |
| 356 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 357 | struct pc87360_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 358 | long val; |
| 359 | int err; |
| 360 | |
| 361 | err = kstrtol(buf, 10, &val); |
| 362 | if (err) |
| 363 | return err; |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 364 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 365 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 366 | data->pwm[attr->index] = PWM_TO_REG(val, |
| 367 | FAN_CONFIG_INVERT(data->fan_conf, attr->index)); |
| 368 | pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(attr->index), |
| 369 | data->pwm[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 370 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 371 | return count; |
| 372 | } |
| 373 | |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 374 | static struct sensor_device_attribute pwm[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 375 | SENSOR_ATTR_RW(pwm1, pwm, 0), |
| 376 | SENSOR_ATTR_RW(pwm2, pwm, 1), |
| 377 | SENSOR_ATTR_RW(pwm3, pwm, 2), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 378 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 380 | static struct attribute *pc8736x_fan_attr[][5] = { |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 381 | FAN_UNIT_ATTRS(0), |
| 382 | FAN_UNIT_ATTRS(1), |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 383 | FAN_UNIT_ATTRS(2) |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 384 | }; |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 385 | |
| 386 | static const struct attribute_group pc8736x_fan_attr_group[] = { |
| 387 | { .attrs = pc8736x_fan_attr[0], }, |
| 388 | { .attrs = pc8736x_fan_attr[1], }, |
| 389 | { .attrs = pc8736x_fan_attr[2], }, |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 390 | }; |
| 391 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 392 | static ssize_t in_input_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 393 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 394 | { |
| 395 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 396 | struct pc87360_data *data = pc87360_update_device(dev); |
| 397 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], |
| 398 | data->in_vref)); |
| 399 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 400 | static ssize_t in_min_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 401 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 402 | { |
| 403 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 404 | struct pc87360_data *data = pc87360_update_device(dev); |
| 405 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], |
| 406 | data->in_vref)); |
| 407 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 408 | static ssize_t in_max_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 409 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 410 | { |
| 411 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 412 | struct pc87360_data *data = pc87360_update_device(dev); |
| 413 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], |
| 414 | data->in_vref)); |
| 415 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 416 | static ssize_t in_status_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 417 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 418 | { |
| 419 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 420 | struct pc87360_data *data = pc87360_update_device(dev); |
| 421 | return sprintf(buf, "%u\n", data->in_status[attr->index]); |
| 422 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 423 | static ssize_t in_min_store(struct device *dev, |
| 424 | struct device_attribute *devattr, const char *buf, |
| 425 | size_t count) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 426 | { |
| 427 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 428 | struct pc87360_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 429 | long val; |
| 430 | int err; |
| 431 | |
| 432 | err = kstrtol(buf, 10, &val); |
| 433 | if (err) |
| 434 | return err; |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 435 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 436 | mutex_lock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 437 | data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); |
| 438 | pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MIN, |
| 439 | data->in_min[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 440 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 441 | return count; |
| 442 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 443 | static ssize_t in_max_store(struct device *dev, |
| 444 | struct device_attribute *devattr, const char *buf, |
| 445 | size_t count) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 446 | { |
| 447 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 448 | struct pc87360_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 449 | long val; |
| 450 | int err; |
| 451 | |
| 452 | err = kstrtol(buf, 10, &val); |
| 453 | if (err) |
| 454 | return err; |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 455 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 456 | mutex_lock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 457 | data->in_max[attr->index] = IN_TO_REG(val, |
| 458 | data->in_vref); |
| 459 | pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MAX, |
| 460 | data->in_max[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 461 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 462 | return count; |
| 463 | } |
| 464 | |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 465 | static struct sensor_device_attribute in_input[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 466 | SENSOR_ATTR_RO(in0_input, in_input, 0), |
| 467 | SENSOR_ATTR_RO(in1_input, in_input, 1), |
| 468 | SENSOR_ATTR_RO(in2_input, in_input, 2), |
| 469 | SENSOR_ATTR_RO(in3_input, in_input, 3), |
| 470 | SENSOR_ATTR_RO(in4_input, in_input, 4), |
| 471 | SENSOR_ATTR_RO(in5_input, in_input, 5), |
| 472 | SENSOR_ATTR_RO(in6_input, in_input, 6), |
| 473 | SENSOR_ATTR_RO(in7_input, in_input, 7), |
| 474 | SENSOR_ATTR_RO(in8_input, in_input, 8), |
| 475 | SENSOR_ATTR_RO(in9_input, in_input, 9), |
| 476 | SENSOR_ATTR_RO(in10_input, in_input, 10), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 477 | }; |
| 478 | static struct sensor_device_attribute in_status[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 479 | SENSOR_ATTR_RO(in0_status, in_status, 0), |
| 480 | SENSOR_ATTR_RO(in1_status, in_status, 1), |
| 481 | SENSOR_ATTR_RO(in2_status, in_status, 2), |
| 482 | SENSOR_ATTR_RO(in3_status, in_status, 3), |
| 483 | SENSOR_ATTR_RO(in4_status, in_status, 4), |
| 484 | SENSOR_ATTR_RO(in5_status, in_status, 5), |
| 485 | SENSOR_ATTR_RO(in6_status, in_status, 6), |
| 486 | SENSOR_ATTR_RO(in7_status, in_status, 7), |
| 487 | SENSOR_ATTR_RO(in8_status, in_status, 8), |
| 488 | SENSOR_ATTR_RO(in9_status, in_status, 9), |
| 489 | SENSOR_ATTR_RO(in10_status, in_status, 10), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 490 | }; |
| 491 | static struct sensor_device_attribute in_min[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 492 | SENSOR_ATTR_RW(in0_min, in_min, 0), |
| 493 | SENSOR_ATTR_RW(in1_min, in_min, 1), |
| 494 | SENSOR_ATTR_RW(in2_min, in_min, 2), |
| 495 | SENSOR_ATTR_RW(in3_min, in_min, 3), |
| 496 | SENSOR_ATTR_RW(in4_min, in_min, 4), |
| 497 | SENSOR_ATTR_RW(in5_min, in_min, 5), |
| 498 | SENSOR_ATTR_RW(in6_min, in_min, 6), |
| 499 | SENSOR_ATTR_RW(in7_min, in_min, 7), |
| 500 | SENSOR_ATTR_RW(in8_min, in_min, 8), |
| 501 | SENSOR_ATTR_RW(in9_min, in_min, 9), |
| 502 | SENSOR_ATTR_RW(in10_min, in_min, 10), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 503 | }; |
| 504 | static struct sensor_device_attribute in_max[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 505 | SENSOR_ATTR_RW(in0_max, in_max, 0), |
| 506 | SENSOR_ATTR_RW(in1_max, in_max, 1), |
| 507 | SENSOR_ATTR_RW(in2_max, in_max, 2), |
| 508 | SENSOR_ATTR_RW(in3_max, in_max, 3), |
| 509 | SENSOR_ATTR_RW(in4_max, in_max, 4), |
| 510 | SENSOR_ATTR_RW(in5_max, in_max, 5), |
| 511 | SENSOR_ATTR_RW(in6_max, in_max, 6), |
| 512 | SENSOR_ATTR_RW(in7_max, in_max, 7), |
| 513 | SENSOR_ATTR_RW(in8_max, in_max, 8), |
| 514 | SENSOR_ATTR_RW(in9_max, in_max, 9), |
| 515 | SENSOR_ATTR_RW(in10_max, in_max, 10), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 516 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 518 | /* (temp & vin) channel status register alarm bits (pdf sec.11.5.12) */ |
| 519 | #define CHAN_ALM_MIN 0x02 /* min limit crossed */ |
| 520 | #define CHAN_ALM_MAX 0x04 /* max limit exceeded */ |
| 521 | #define TEMP_ALM_CRIT 0x08 /* temp crit exceeded (temp only) */ |
| 522 | |
Guenter Roeck | 3af2861 | 2012-01-19 11:02:22 -0800 | [diff] [blame] | 523 | /* |
| 524 | * show_in_min/max_alarm() reads data from the per-channel status |
| 525 | * register (sec 11.5.12), not the vin event status registers (sec |
| 526 | * 11.5.2) that (legacy) show_in_alarm() resds (via data->in_alarms) |
| 527 | */ |
Jim Cromie | 492e965 | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 528 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 529 | static ssize_t in_min_alarm_show(struct device *dev, |
| 530 | struct device_attribute *devattr, char *buf) |
Jim Cromie | 492e965 | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 531 | { |
| 532 | struct pc87360_data *data = pc87360_update_device(dev); |
| 533 | unsigned nr = to_sensor_dev_attr(devattr)->index; |
| 534 | |
| 535 | return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MIN)); |
| 536 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 537 | static ssize_t in_max_alarm_show(struct device *dev, |
| 538 | struct device_attribute *devattr, char *buf) |
Jim Cromie | 492e965 | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 539 | { |
| 540 | struct pc87360_data *data = pc87360_update_device(dev); |
| 541 | unsigned nr = to_sensor_dev_attr(devattr)->index; |
| 542 | |
| 543 | return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MAX)); |
| 544 | } |
| 545 | |
| 546 | static struct sensor_device_attribute in_min_alarm[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 547 | SENSOR_ATTR_RO(in0_min_alarm, in_min_alarm, 0), |
| 548 | SENSOR_ATTR_RO(in1_min_alarm, in_min_alarm, 1), |
| 549 | SENSOR_ATTR_RO(in2_min_alarm, in_min_alarm, 2), |
| 550 | SENSOR_ATTR_RO(in3_min_alarm, in_min_alarm, 3), |
| 551 | SENSOR_ATTR_RO(in4_min_alarm, in_min_alarm, 4), |
| 552 | SENSOR_ATTR_RO(in5_min_alarm, in_min_alarm, 5), |
| 553 | SENSOR_ATTR_RO(in6_min_alarm, in_min_alarm, 6), |
| 554 | SENSOR_ATTR_RO(in7_min_alarm, in_min_alarm, 7), |
| 555 | SENSOR_ATTR_RO(in8_min_alarm, in_min_alarm, 8), |
| 556 | SENSOR_ATTR_RO(in9_min_alarm, in_min_alarm, 9), |
| 557 | SENSOR_ATTR_RO(in10_min_alarm, in_min_alarm, 10), |
Jim Cromie | 492e965 | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 558 | }; |
| 559 | static struct sensor_device_attribute in_max_alarm[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 560 | SENSOR_ATTR_RO(in0_max_alarm, in_max_alarm, 0), |
| 561 | SENSOR_ATTR_RO(in1_max_alarm, in_max_alarm, 1), |
| 562 | SENSOR_ATTR_RO(in2_max_alarm, in_max_alarm, 2), |
| 563 | SENSOR_ATTR_RO(in3_max_alarm, in_max_alarm, 3), |
| 564 | SENSOR_ATTR_RO(in4_max_alarm, in_max_alarm, 4), |
| 565 | SENSOR_ATTR_RO(in5_max_alarm, in_max_alarm, 5), |
| 566 | SENSOR_ATTR_RO(in6_max_alarm, in_max_alarm, 6), |
| 567 | SENSOR_ATTR_RO(in7_max_alarm, in_max_alarm, 7), |
| 568 | SENSOR_ATTR_RO(in8_max_alarm, in_max_alarm, 8), |
| 569 | SENSOR_ATTR_RO(in9_max_alarm, in_max_alarm, 9), |
| 570 | SENSOR_ATTR_RO(in10_max_alarm, in_max_alarm, 10), |
Jim Cromie | 492e965 | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 571 | }; |
| 572 | |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 573 | #define VIN_UNIT_ATTRS(X) \ |
| 574 | &in_input[X].dev_attr.attr, \ |
| 575 | &in_status[X].dev_attr.attr, \ |
| 576 | &in_min[X].dev_attr.attr, \ |
Jim Cromie | 492e965 | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 577 | &in_max[X].dev_attr.attr, \ |
| 578 | &in_min_alarm[X].dev_attr.attr, \ |
| 579 | &in_max_alarm[X].dev_attr.attr |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 580 | |
Julia Lawall | e33110d | 2016-12-22 13:05:24 +0100 | [diff] [blame] | 581 | static ssize_t cpu0_vid_show(struct device *dev, |
| 582 | struct device_attribute *attr, char *buf) |
Jim Cromie | 44646c1 | 2006-09-24 21:01:56 +0200 | [diff] [blame] | 583 | { |
| 584 | struct pc87360_data *data = pc87360_update_device(dev); |
| 585 | return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); |
| 586 | } |
Julia Lawall | e33110d | 2016-12-22 13:05:24 +0100 | [diff] [blame] | 587 | static DEVICE_ATTR_RO(cpu0_vid); |
Jim Cromie | 44646c1 | 2006-09-24 21:01:56 +0200 | [diff] [blame] | 588 | |
Julia Lawall | e33110d | 2016-12-22 13:05:24 +0100 | [diff] [blame] | 589 | static ssize_t vrm_show(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 590 | char *buf) |
Jim Cromie | 44646c1 | 2006-09-24 21:01:56 +0200 | [diff] [blame] | 591 | { |
Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 592 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | 44646c1 | 2006-09-24 21:01:56 +0200 | [diff] [blame] | 593 | return sprintf(buf, "%u\n", data->vrm); |
| 594 | } |
Julia Lawall | e33110d | 2016-12-22 13:05:24 +0100 | [diff] [blame] | 595 | static ssize_t vrm_store(struct device *dev, struct device_attribute *attr, |
| 596 | const char *buf, size_t count) |
Jim Cromie | 44646c1 | 2006-09-24 21:01:56 +0200 | [diff] [blame] | 597 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 598 | struct pc87360_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 599 | unsigned long val; |
| 600 | int err; |
| 601 | |
| 602 | err = kstrtoul(buf, 10, &val); |
| 603 | if (err) |
| 604 | return err; |
| 605 | |
Axel Lin | 5e3b561 | 2014-08-06 08:24:54 +0800 | [diff] [blame] | 606 | if (val > 255) |
| 607 | return -EINVAL; |
| 608 | |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 609 | data->vrm = val; |
Jim Cromie | 44646c1 | 2006-09-24 21:01:56 +0200 | [diff] [blame] | 610 | return count; |
| 611 | } |
Julia Lawall | e33110d | 2016-12-22 13:05:24 +0100 | [diff] [blame] | 612 | static DEVICE_ATTR_RW(vrm); |
Jim Cromie | 44646c1 | 2006-09-24 21:01:56 +0200 | [diff] [blame] | 613 | |
Julia Lawall | e33110d | 2016-12-22 13:05:24 +0100 | [diff] [blame] | 614 | static ssize_t alarms_in_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 615 | struct device_attribute *attr, char *buf) |
Jim Cromie | 44646c1 | 2006-09-24 21:01:56 +0200 | [diff] [blame] | 616 | { |
| 617 | struct pc87360_data *data = pc87360_update_device(dev); |
| 618 | return sprintf(buf, "%u\n", data->in_alarms); |
| 619 | } |
Julia Lawall | e33110d | 2016-12-22 13:05:24 +0100 | [diff] [blame] | 620 | static DEVICE_ATTR_RO(alarms_in); |
Jim Cromie | 44646c1 | 2006-09-24 21:01:56 +0200 | [diff] [blame] | 621 | |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 622 | static struct attribute *pc8736x_vin_attr_array[] = { |
| 623 | VIN_UNIT_ATTRS(0), |
| 624 | VIN_UNIT_ATTRS(1), |
| 625 | VIN_UNIT_ATTRS(2), |
| 626 | VIN_UNIT_ATTRS(3), |
| 627 | VIN_UNIT_ATTRS(4), |
| 628 | VIN_UNIT_ATTRS(5), |
| 629 | VIN_UNIT_ATTRS(6), |
| 630 | VIN_UNIT_ATTRS(7), |
| 631 | VIN_UNIT_ATTRS(8), |
| 632 | VIN_UNIT_ATTRS(9), |
| 633 | VIN_UNIT_ATTRS(10), |
| 634 | &dev_attr_cpu0_vid.attr, |
| 635 | &dev_attr_vrm.attr, |
| 636 | &dev_attr_alarms_in.attr, |
| 637 | NULL |
| 638 | }; |
| 639 | static const struct attribute_group pc8736x_vin_group = { |
| 640 | .attrs = pc8736x_vin_attr_array, |
| 641 | }; |
| 642 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 643 | static ssize_t therm_input_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 644 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 645 | { |
| 646 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 647 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 648 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 649 | data->in_vref)); |
| 650 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 651 | static ssize_t therm_min_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 652 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 653 | { |
| 654 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 655 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 656 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 657 | data->in_vref)); |
| 658 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 659 | static ssize_t therm_max_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 660 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 661 | { |
| 662 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 663 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 664 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 665 | data->in_vref)); |
| 666 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 667 | static ssize_t therm_crit_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 668 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 669 | { |
| 670 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 671 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 672 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11], |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 673 | data->in_vref)); |
| 674 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 675 | static ssize_t therm_status_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 676 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 677 | { |
| 678 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 679 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 680 | return sprintf(buf, "%u\n", data->in_status[attr->index]); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 681 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 682 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 683 | static ssize_t therm_min_store(struct device *dev, |
| 684 | struct device_attribute *devattr, |
| 685 | const char *buf, size_t count) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 686 | { |
| 687 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 688 | struct pc87360_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 689 | long val; |
| 690 | int err; |
| 691 | |
| 692 | err = kstrtol(buf, 10, &val); |
| 693 | if (err) |
| 694 | return err; |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 695 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 696 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 697 | data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); |
| 698 | pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MIN, |
| 699 | data->in_min[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 700 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 701 | return count; |
| 702 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 703 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 704 | static ssize_t therm_max_store(struct device *dev, |
| 705 | struct device_attribute *devattr, |
| 706 | const char *buf, size_t count) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 707 | { |
| 708 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 709 | struct pc87360_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 710 | long val; |
| 711 | int err; |
| 712 | |
| 713 | err = kstrtol(buf, 10, &val); |
| 714 | if (err) |
| 715 | return err; |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 716 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 717 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 718 | data->in_max[attr->index] = IN_TO_REG(val, data->in_vref); |
| 719 | pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MAX, |
| 720 | data->in_max[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 721 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 722 | return count; |
| 723 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 724 | static ssize_t therm_crit_store(struct device *dev, |
| 725 | struct device_attribute *devattr, |
| 726 | const char *buf, size_t count) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 727 | { |
| 728 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 729 | struct pc87360_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 730 | long val; |
| 731 | int err; |
| 732 | |
| 733 | err = kstrtol(buf, 10, &val); |
| 734 | if (err) |
| 735 | return err; |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 736 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 737 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 738 | data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref); |
| 739 | pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_CRIT, |
| 740 | data->in_crit[attr->index-11]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 741 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 742 | return count; |
| 743 | } |
| 744 | |
Guenter Roeck | 3af2861 | 2012-01-19 11:02:22 -0800 | [diff] [blame] | 745 | /* |
| 746 | * the +11 term below reflects the fact that VLM units 11,12,13 are |
| 747 | * used in the chip to measure voltage across the thermistors |
| 748 | */ |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 749 | static struct sensor_device_attribute therm_input[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 750 | SENSOR_ATTR_RO(temp4_input, therm_input, 0 + 11), |
| 751 | SENSOR_ATTR_RO(temp5_input, therm_input, 1 + 11), |
| 752 | SENSOR_ATTR_RO(temp6_input, therm_input, 2 + 11), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 753 | }; |
| 754 | static struct sensor_device_attribute therm_status[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 755 | SENSOR_ATTR_RO(temp4_status, therm_status, 0 + 11), |
| 756 | SENSOR_ATTR_RO(temp5_status, therm_status, 1 + 11), |
| 757 | SENSOR_ATTR_RO(temp6_status, therm_status, 2 + 11), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 758 | }; |
| 759 | static struct sensor_device_attribute therm_min[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 760 | SENSOR_ATTR_RW(temp4_min, therm_min, 0 + 11), |
| 761 | SENSOR_ATTR_RW(temp5_min, therm_min, 1 + 11), |
| 762 | SENSOR_ATTR_RW(temp6_min, therm_min, 2 + 11), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 763 | }; |
| 764 | static struct sensor_device_attribute therm_max[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 765 | SENSOR_ATTR_RW(temp4_max, therm_max, 0 + 11), |
| 766 | SENSOR_ATTR_RW(temp5_max, therm_max, 1 + 11), |
| 767 | SENSOR_ATTR_RW(temp6_max, therm_max, 2 + 11), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 768 | }; |
| 769 | static struct sensor_device_attribute therm_crit[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 770 | SENSOR_ATTR_RW(temp4_crit, therm_crit, 0 + 11), |
| 771 | SENSOR_ATTR_RW(temp5_crit, therm_crit, 1 + 11), |
| 772 | SENSOR_ATTR_RW(temp6_crit, therm_crit, 2 + 11), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 773 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Guenter Roeck | 3af2861 | 2012-01-19 11:02:22 -0800 | [diff] [blame] | 775 | /* |
| 776 | * show_therm_min/max_alarm() reads data from the per-channel voltage |
| 777 | * status register (sec 11.5.12) |
| 778 | */ |
Jim Cromie | 865c295 | 2008-10-18 20:27:35 -0700 | [diff] [blame] | 779 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 780 | static ssize_t therm_min_alarm_show(struct device *dev, |
| 781 | struct device_attribute *devattr, |
| 782 | char *buf) |
Jim Cromie | 865c295 | 2008-10-18 20:27:35 -0700 | [diff] [blame] | 783 | { |
| 784 | struct pc87360_data *data = pc87360_update_device(dev); |
| 785 | unsigned nr = to_sensor_dev_attr(devattr)->index; |
| 786 | |
| 787 | return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MIN)); |
| 788 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 789 | static ssize_t therm_max_alarm_show(struct device *dev, |
| 790 | struct device_attribute *devattr, |
| 791 | char *buf) |
Jim Cromie | 865c295 | 2008-10-18 20:27:35 -0700 | [diff] [blame] | 792 | { |
| 793 | struct pc87360_data *data = pc87360_update_device(dev); |
| 794 | unsigned nr = to_sensor_dev_attr(devattr)->index; |
| 795 | |
| 796 | return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MAX)); |
| 797 | } |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 798 | static ssize_t therm_crit_alarm_show(struct device *dev, |
| 799 | struct device_attribute *devattr, |
| 800 | char *buf) |
Jim Cromie | 865c295 | 2008-10-18 20:27:35 -0700 | [diff] [blame] | 801 | { |
| 802 | struct pc87360_data *data = pc87360_update_device(dev); |
| 803 | unsigned nr = to_sensor_dev_attr(devattr)->index; |
| 804 | |
| 805 | return sprintf(buf, "%u\n", !!(data->in_status[nr] & TEMP_ALM_CRIT)); |
| 806 | } |
| 807 | |
| 808 | static struct sensor_device_attribute therm_min_alarm[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 809 | SENSOR_ATTR_RO(temp4_min_alarm, therm_min_alarm, 0 + 11), |
| 810 | SENSOR_ATTR_RO(temp5_min_alarm, therm_min_alarm, 1 + 11), |
| 811 | SENSOR_ATTR_RO(temp6_min_alarm, therm_min_alarm, 2 + 11), |
Jim Cromie | 865c295 | 2008-10-18 20:27:35 -0700 | [diff] [blame] | 812 | }; |
| 813 | static struct sensor_device_attribute therm_max_alarm[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 814 | SENSOR_ATTR_RO(temp4_max_alarm, therm_max_alarm, 0 + 11), |
| 815 | SENSOR_ATTR_RO(temp5_max_alarm, therm_max_alarm, 1 + 11), |
| 816 | SENSOR_ATTR_RO(temp6_max_alarm, therm_max_alarm, 2 + 11), |
Jim Cromie | 865c295 | 2008-10-18 20:27:35 -0700 | [diff] [blame] | 817 | }; |
| 818 | static struct sensor_device_attribute therm_crit_alarm[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 819 | SENSOR_ATTR_RO(temp4_crit_alarm, therm_crit_alarm, 0 + 11), |
| 820 | SENSOR_ATTR_RO(temp5_crit_alarm, therm_crit_alarm, 1 + 11), |
| 821 | SENSOR_ATTR_RO(temp6_crit_alarm, therm_crit_alarm, 2 + 11), |
Jim Cromie | 865c295 | 2008-10-18 20:27:35 -0700 | [diff] [blame] | 822 | }; |
| 823 | |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 824 | #define THERM_UNIT_ATTRS(X) \ |
| 825 | &therm_input[X].dev_attr.attr, \ |
| 826 | &therm_status[X].dev_attr.attr, \ |
| 827 | &therm_min[X].dev_attr.attr, \ |
| 828 | &therm_max[X].dev_attr.attr, \ |
Jim Cromie | 865c295 | 2008-10-18 20:27:35 -0700 | [diff] [blame] | 829 | &therm_crit[X].dev_attr.attr, \ |
| 830 | &therm_min_alarm[X].dev_attr.attr, \ |
| 831 | &therm_max_alarm[X].dev_attr.attr, \ |
| 832 | &therm_crit_alarm[X].dev_attr.attr |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 833 | |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 834 | static struct attribute *pc8736x_therm_attr_array[] = { |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 835 | THERM_UNIT_ATTRS(0), |
| 836 | THERM_UNIT_ATTRS(1), |
| 837 | THERM_UNIT_ATTRS(2), |
| 838 | NULL |
| 839 | }; |
| 840 | static const struct attribute_group pc8736x_therm_group = { |
| 841 | .attrs = pc8736x_therm_attr_array, |
| 842 | }; |
| 843 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 844 | static ssize_t temp_input_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 845 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 846 | { |
| 847 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 848 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 849 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 850 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 851 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 852 | static ssize_t temp_min_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 853 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 854 | { |
| 855 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 856 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 857 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 858 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 859 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 860 | static ssize_t temp_max_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 861 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 862 | { |
| 863 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 864 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 865 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 866 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 867 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 868 | static ssize_t temp_crit_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 869 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 870 | { |
| 871 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 872 | struct pc87360_data *data = pc87360_update_device(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 873 | return sprintf(buf, "%d\n", |
| 874 | TEMP_FROM_REG(data->temp_crit[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 875 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 876 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 877 | static ssize_t temp_status_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 878 | struct device_attribute *devattr, char *buf) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 879 | { |
| 880 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 881 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 882 | return sprintf(buf, "%d\n", data->temp_status[attr->index]); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 883 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 884 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 885 | static ssize_t temp_min_store(struct device *dev, |
| 886 | struct device_attribute *devattr, |
| 887 | const char *buf, size_t count) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 888 | { |
| 889 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 890 | struct pc87360_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 891 | long val; |
| 892 | int err; |
| 893 | |
| 894 | err = kstrtol(buf, 10, &val); |
| 895 | if (err) |
| 896 | return err; |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 897 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 898 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 899 | data->temp_min[attr->index] = TEMP_TO_REG(val); |
| 900 | pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MIN, |
| 901 | data->temp_min[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 902 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 903 | return count; |
| 904 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 905 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 906 | static ssize_t temp_max_store(struct device *dev, |
| 907 | struct device_attribute *devattr, |
| 908 | const char *buf, size_t count) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 909 | { |
| 910 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 911 | struct pc87360_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 912 | long val; |
| 913 | int err; |
| 914 | |
| 915 | err = kstrtol(buf, 10, &val); |
| 916 | if (err) |
| 917 | return err; |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 918 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 919 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 920 | data->temp_max[attr->index] = TEMP_TO_REG(val); |
| 921 | pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MAX, |
| 922 | data->temp_max[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 923 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 924 | return count; |
| 925 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 926 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 927 | static ssize_t temp_crit_store(struct device *dev, |
| 928 | struct device_attribute *devattr, |
| 929 | const char *buf, size_t count) |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 930 | { |
| 931 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 932 | struct pc87360_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 933 | long val; |
| 934 | int err; |
| 935 | |
| 936 | err = kstrtol(buf, 10, &val); |
| 937 | if (err) |
| 938 | return err; |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 939 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 940 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 941 | data->temp_crit[attr->index] = TEMP_TO_REG(val); |
| 942 | pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_CRIT, |
| 943 | data->temp_crit[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 944 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 945 | return count; |
| 946 | } |
| 947 | |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 948 | static struct sensor_device_attribute temp_input[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 949 | SENSOR_ATTR_RO(temp1_input, temp_input, 0), |
| 950 | SENSOR_ATTR_RO(temp2_input, temp_input, 1), |
| 951 | SENSOR_ATTR_RO(temp3_input, temp_input, 2), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 952 | }; |
| 953 | static struct sensor_device_attribute temp_status[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 954 | SENSOR_ATTR_RO(temp1_status, temp_status, 0), |
| 955 | SENSOR_ATTR_RO(temp2_status, temp_status, 1), |
| 956 | SENSOR_ATTR_RO(temp3_status, temp_status, 2), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 957 | }; |
| 958 | static struct sensor_device_attribute temp_min[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 959 | SENSOR_ATTR_RW(temp1_min, temp_min, 0), |
| 960 | SENSOR_ATTR_RW(temp2_min, temp_min, 1), |
| 961 | SENSOR_ATTR_RW(temp3_min, temp_min, 2), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 962 | }; |
| 963 | static struct sensor_device_attribute temp_max[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 964 | SENSOR_ATTR_RW(temp1_max, temp_max, 0), |
| 965 | SENSOR_ATTR_RW(temp2_max, temp_max, 1), |
| 966 | SENSOR_ATTR_RW(temp3_max, temp_max, 2), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 967 | }; |
| 968 | static struct sensor_device_attribute temp_crit[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 969 | SENSOR_ATTR_RW(temp1_crit, temp_crit, 0), |
| 970 | SENSOR_ATTR_RW(temp2_crit, temp_crit, 1), |
| 971 | SENSOR_ATTR_RW(temp3_crit, temp_crit, 2), |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 972 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | |
Julia Lawall | e33110d | 2016-12-22 13:05:24 +0100 | [diff] [blame] | 974 | static ssize_t alarms_temp_show(struct device *dev, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 975 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | { |
| 977 | struct pc87360_data *data = pc87360_update_device(dev); |
| 978 | return sprintf(buf, "%u\n", data->temp_alarms); |
| 979 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 980 | |
Julia Lawall | e33110d | 2016-12-22 13:05:24 +0100 | [diff] [blame] | 981 | static DEVICE_ATTR_RO(alarms_temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
Guenter Roeck | 3af2861 | 2012-01-19 11:02:22 -0800 | [diff] [blame] | 983 | /* |
| 984 | * show_temp_min/max_alarm() reads data from the per-channel status |
| 985 | * register (sec 12.3.7), not the temp event status registers (sec |
| 986 | * 12.3.2) that show_temp_alarm() reads (via data->temp_alarms) |
| 987 | */ |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 988 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 989 | static ssize_t temp_min_alarm_show(struct device *dev, |
| 990 | struct device_attribute *devattr, |
| 991 | char *buf) |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 992 | { |
| 993 | struct pc87360_data *data = pc87360_update_device(dev); |
| 994 | unsigned nr = to_sensor_dev_attr(devattr)->index; |
| 995 | |
| 996 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MIN)); |
| 997 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 998 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 999 | static ssize_t temp_max_alarm_show(struct device *dev, |
| 1000 | struct device_attribute *devattr, |
| 1001 | char *buf) |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 1002 | { |
| 1003 | struct pc87360_data *data = pc87360_update_device(dev); |
| 1004 | unsigned nr = to_sensor_dev_attr(devattr)->index; |
| 1005 | |
| 1006 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MAX)); |
| 1007 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1008 | |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 1009 | static ssize_t temp_crit_alarm_show(struct device *dev, |
| 1010 | struct device_attribute *devattr, |
| 1011 | char *buf) |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 1012 | { |
| 1013 | struct pc87360_data *data = pc87360_update_device(dev); |
| 1014 | unsigned nr = to_sensor_dev_attr(devattr)->index; |
| 1015 | |
| 1016 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & TEMP_ALM_CRIT)); |
| 1017 | } |
| 1018 | |
| 1019 | static struct sensor_device_attribute temp_min_alarm[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 1020 | SENSOR_ATTR_RO(temp1_min_alarm, temp_min_alarm, 0), |
| 1021 | SENSOR_ATTR_RO(temp2_min_alarm, temp_min_alarm, 1), |
| 1022 | SENSOR_ATTR_RO(temp3_min_alarm, temp_min_alarm, 2), |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 1023 | }; |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1024 | |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 1025 | static struct sensor_device_attribute temp_max_alarm[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 1026 | SENSOR_ATTR_RO(temp1_max_alarm, temp_max_alarm, 0), |
| 1027 | SENSOR_ATTR_RO(temp2_max_alarm, temp_max_alarm, 1), |
| 1028 | SENSOR_ATTR_RO(temp3_max_alarm, temp_max_alarm, 2), |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 1029 | }; |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1030 | |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 1031 | static struct sensor_device_attribute temp_crit_alarm[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 1032 | SENSOR_ATTR_RO(temp1_crit_alarm, temp_crit_alarm, 0), |
| 1033 | SENSOR_ATTR_RO(temp2_crit_alarm, temp_crit_alarm, 1), |
| 1034 | SENSOR_ATTR_RO(temp3_crit_alarm, temp_crit_alarm, 2), |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 1035 | }; |
| 1036 | |
| 1037 | #define TEMP_FAULT 0x40 /* open diode */ |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 1038 | static ssize_t temp_fault_show(struct device *dev, |
| 1039 | struct device_attribute *devattr, char *buf) |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 1040 | { |
| 1041 | struct pc87360_data *data = pc87360_update_device(dev); |
| 1042 | unsigned nr = to_sensor_dev_attr(devattr)->index; |
| 1043 | |
| 1044 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & TEMP_FAULT)); |
| 1045 | } |
| 1046 | static struct sensor_device_attribute temp_fault[] = { |
Guenter Roeck | eba42d3 | 2018-12-10 14:02:18 -0800 | [diff] [blame] | 1047 | SENSOR_ATTR_RO(temp1_fault, temp_fault, 0), |
| 1048 | SENSOR_ATTR_RO(temp2_fault, temp_fault, 1), |
| 1049 | SENSOR_ATTR_RO(temp3_fault, temp_fault, 2), |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 1050 | }; |
| 1051 | |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 1052 | #define TEMP_UNIT_ATTRS(X) \ |
| 1053 | { &temp_input[X].dev_attr.attr, \ |
| 1054 | &temp_status[X].dev_attr.attr, \ |
| 1055 | &temp_min[X].dev_attr.attr, \ |
| 1056 | &temp_max[X].dev_attr.attr, \ |
| 1057 | &temp_crit[X].dev_attr.attr, \ |
| 1058 | &temp_min_alarm[X].dev_attr.attr, \ |
| 1059 | &temp_max_alarm[X].dev_attr.attr, \ |
| 1060 | &temp_crit_alarm[X].dev_attr.attr, \ |
| 1061 | &temp_fault[X].dev_attr.attr, \ |
| 1062 | NULL \ |
| 1063 | } |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 1064 | |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 1065 | static struct attribute *pc8736x_temp_attr[][10] = { |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 1066 | TEMP_UNIT_ATTRS(0), |
| 1067 | TEMP_UNIT_ATTRS(1), |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 1068 | TEMP_UNIT_ATTRS(2) |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 1069 | }; |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1070 | |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 1071 | static const struct attribute_group pc8736x_temp_attr_group[] = { |
| 1072 | { .attrs = pc8736x_temp_attr[0] }, |
| 1073 | { .attrs = pc8736x_temp_attr[1] }, |
| 1074 | { .attrs = pc8736x_temp_attr[2] } |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 1075 | }; |
| 1076 | |
Julia Lawall | e33110d | 2016-12-22 13:05:24 +0100 | [diff] [blame] | 1077 | static ssize_t name_show(struct device *dev, |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 1078 | struct device_attribute *devattr, char *buf) |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1079 | { |
| 1080 | struct pc87360_data *data = dev_get_drvdata(dev); |
| 1081 | return sprintf(buf, "%s\n", data->name); |
| 1082 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1083 | |
Julia Lawall | e33110d | 2016-12-22 13:05:24 +0100 | [diff] [blame] | 1084 | static DEVICE_ATTR_RO(name); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | /* |
| 1087 | * Device detection, registration and update |
| 1088 | */ |
| 1089 | |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1090 | static int __init pc87360_find(int sioaddr, u8 *devid, |
| 1091 | unsigned short *addresses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | { |
| 1093 | u16 val; |
| 1094 | int i; |
| 1095 | int nrdev; /* logical device count */ |
| 1096 | |
| 1097 | /* No superio_enter */ |
| 1098 | |
| 1099 | /* Identify device */ |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 1100 | val = force_id ? force_id : superio_inb(sioaddr, DEVID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | switch (val) { |
| 1102 | case 0xE1: /* PC87360 */ |
| 1103 | case 0xE8: /* PC87363 */ |
| 1104 | case 0xE4: /* PC87364 */ |
| 1105 | nrdev = 1; |
| 1106 | break; |
| 1107 | case 0xE5: /* PC87365 */ |
| 1108 | case 0xE9: /* PC87366 */ |
| 1109 | nrdev = 3; |
| 1110 | break; |
| 1111 | default: |
| 1112 | superio_exit(sioaddr); |
| 1113 | return -ENODEV; |
| 1114 | } |
| 1115 | /* Remember the device id */ |
| 1116 | *devid = val; |
| 1117 | |
| 1118 | for (i = 0; i < nrdev; i++) { |
| 1119 | /* select logical device */ |
| 1120 | superio_outb(sioaddr, DEV, logdev[i]); |
| 1121 | |
| 1122 | val = superio_inb(sioaddr, ACT); |
| 1123 | if (!(val & 0x01)) { |
Joe Perches | 9e991c6 | 2011-01-12 21:55:11 +0100 | [diff] [blame] | 1124 | pr_info("Device 0x%02x not activated\n", logdev[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | continue; |
| 1126 | } |
| 1127 | |
| 1128 | val = (superio_inb(sioaddr, BASE) << 8) |
| 1129 | | superio_inb(sioaddr, BASE + 1); |
| 1130 | if (!val) { |
Joe Perches | 9e991c6 | 2011-01-12 21:55:11 +0100 | [diff] [blame] | 1131 | pr_info("Base address not set for device 0x%02x\n", |
| 1132 | logdev[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | continue; |
| 1134 | } |
| 1135 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 1136 | addresses[i] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1138 | if (i == 0) { /* Fans */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | confreg[0] = superio_inb(sioaddr, 0xF0); |
| 1140 | confreg[1] = superio_inb(sioaddr, 0xF1); |
| 1141 | |
Joe Perches | 9e991c6 | 2011-01-12 21:55:11 +0100 | [diff] [blame] | 1142 | pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 1, |
| 1143 | (confreg[0] >> 2) & 1, (confreg[0] >> 3) & 1, |
| 1144 | (confreg[0] >> 4) & 1); |
| 1145 | pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 2, |
| 1146 | (confreg[0] >> 5) & 1, (confreg[0] >> 6) & 1, |
| 1147 | (confreg[0] >> 7) & 1); |
| 1148 | pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 3, |
| 1149 | confreg[1] & 1, (confreg[1] >> 1) & 1, |
| 1150 | (confreg[1] >> 2) & 1); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1151 | } else if (i == 1) { /* Voltages */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | /* Are we using thermistors? */ |
| 1153 | if (*devid == 0xE9) { /* PC87366 */ |
Guenter Roeck | 3af2861 | 2012-01-19 11:02:22 -0800 | [diff] [blame] | 1154 | /* |
| 1155 | * These registers are not logical-device |
| 1156 | * specific, just that we won't need them if |
| 1157 | * we don't use the VLM device |
| 1158 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | confreg[2] = superio_inb(sioaddr, 0x2B); |
| 1160 | confreg[3] = superio_inb(sioaddr, 0x25); |
| 1161 | |
| 1162 | if (confreg[2] & 0x40) { |
Guenter Roeck | b55f375 | 2013-01-10 10:01:24 -0800 | [diff] [blame] | 1163 | pr_info("Using thermistors for temperature monitoring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | } |
| 1165 | if (confreg[3] & 0xE0) { |
Joe Perches | 9e991c6 | 2011-01-12 21:55:11 +0100 | [diff] [blame] | 1166 | pr_info("VID inputs routed (mode %u)\n", |
| 1167 | confreg[3] >> 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | superio_exit(sioaddr); |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 1177 | static void pc87360_remove_files(struct device *dev) |
| 1178 | { |
| 1179 | int i; |
| 1180 | |
| 1181 | device_remove_file(dev, &dev_attr_name); |
| 1182 | device_remove_file(dev, &dev_attr_alarms_temp); |
| 1183 | for (i = 0; i < ARRAY_SIZE(pc8736x_temp_attr_group); i++) |
| 1184 | sysfs_remove_group(&dev->kobj, &pc8736x_temp_attr_group[i]); |
| 1185 | for (i = 0; i < ARRAY_SIZE(pc8736x_fan_attr_group); i++) { |
| 1186 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_attr_group[i]); |
| 1187 | device_remove_file(dev, &pwm[i].dev_attr); |
| 1188 | } |
| 1189 | sysfs_remove_group(&dev->kobj, &pc8736x_therm_group); |
| 1190 | sysfs_remove_group(&dev->kobj, &pc8736x_vin_group); |
| 1191 | } |
| 1192 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 1193 | static int pc87360_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | { |
| 1195 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | struct pc87360_data *data; |
| 1197 | int err = 0; |
Jean Delvare | 5b58157 | 2014-04-04 18:01:34 +0200 | [diff] [blame] | 1198 | const char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | int use_thermistors = 0; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1200 | struct device *dev = &pdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1202 | data = devm_kzalloc(dev, sizeof(struct pc87360_data), GFP_KERNEL); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1203 | if (!data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | switch (devid) { |
Jean Delvare | 5b58157 | 2014-04-04 18:01:34 +0200 | [diff] [blame] | 1207 | default: |
| 1208 | name = "pc87360"; |
| 1209 | data->fannr = 2; |
| 1210 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | case 0xe8: |
| 1212 | name = "pc87363"; |
Jean Delvare | 5b58157 | 2014-04-04 18:01:34 +0200 | [diff] [blame] | 1213 | data->fannr = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | break; |
| 1215 | case 0xe4: |
| 1216 | name = "pc87364"; |
| 1217 | data->fannr = 3; |
| 1218 | break; |
| 1219 | case 0xe5: |
| 1220 | name = "pc87365"; |
| 1221 | data->fannr = extra_isa[0] ? 3 : 0; |
| 1222 | data->innr = extra_isa[1] ? 11 : 0; |
| 1223 | data->tempnr = extra_isa[2] ? 2 : 0; |
| 1224 | break; |
| 1225 | case 0xe9: |
| 1226 | name = "pc87366"; |
| 1227 | data->fannr = extra_isa[0] ? 3 : 0; |
| 1228 | data->innr = extra_isa[1] ? 14 : 0; |
| 1229 | data->tempnr = extra_isa[2] ? 3 : 0; |
| 1230 | break; |
| 1231 | } |
| 1232 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1233 | data->name = name; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1234 | mutex_init(&data->lock); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1235 | mutex_init(&data->update_lock); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1236 | platform_set_drvdata(pdev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | |
Jim Cromie | 2a32ec2 | 2008-10-18 20:27:33 -0700 | [diff] [blame] | 1238 | for (i = 0; i < LDNI_MAX; i++) { |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1239 | data->address[i] = extra_isa[i]; |
| 1240 | if (data->address[i] |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1241 | && !devm_request_region(dev, extra_isa[i], PC87360_EXTENT, |
| 1242 | pc87360_driver.driver.name)) { |
Guenter Roeck | b55f375 | 2013-01-10 10:01:24 -0800 | [diff] [blame] | 1243 | dev_err(dev, |
| 1244 | "Region 0x%x-0x%x already in use!\n", |
| 1245 | extra_isa[i], extra_isa[i]+PC87360_EXTENT-1); |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1246 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | /* Retrieve the fans configuration from Super-I/O space */ |
| 1251 | if (data->fannr) |
| 1252 | data->fan_conf = confreg[0] | (confreg[1] << 8); |
| 1253 | |
Guenter Roeck | 3af2861 | 2012-01-19 11:02:22 -0800 | [diff] [blame] | 1254 | /* |
| 1255 | * Use the correct reference voltage |
| 1256 | * Unless both the VLM and the TMS logical devices agree to |
| 1257 | * use an external Vref, the internal one is used. |
| 1258 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | if (data->innr) { |
| 1260 | i = pc87360_read_value(data, LD_IN, NO_BANK, |
| 1261 | PC87365_REG_IN_CONFIG); |
| 1262 | if (data->tempnr) { |
| 1263 | i &= pc87360_read_value(data, LD_TEMP, NO_BANK, |
| 1264 | PC87365_REG_TEMP_CONFIG); |
| 1265 | } |
| 1266 | data->in_vref = (i&0x02) ? 3025 : 2966; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1267 | dev_dbg(dev, "Using %s reference voltage\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | (i&0x02) ? "external" : "internal"); |
| 1269 | |
| 1270 | data->vid_conf = confreg[3]; |
Jim Cromie | 3d7f9a8 | 2006-12-12 18:18:28 +0100 | [diff] [blame] | 1271 | data->vrm = vid_which_vrm(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | /* Fan clock dividers may be needed before any data is read */ |
| 1275 | for (i = 0; i < data->fannr; i++) { |
| 1276 | if (FAN_CONFIG_MONITOR(data->fan_conf, i)) |
| 1277 | data->fan_status[i] = pc87360_read_value(data, |
| 1278 | LD_FAN, NO_BANK, |
| 1279 | PC87360_REG_FAN_STATUS(i)); |
| 1280 | } |
| 1281 | |
| 1282 | if (init > 0) { |
| 1283 | if (devid == 0xe9 && data->address[1]) /* PC87366 */ |
| 1284 | use_thermistors = confreg[2] & 0x40; |
| 1285 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1286 | pc87360_init_device(pdev, use_thermistors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
Jim Cromie | f3722d5b | 2006-09-24 21:03:25 +0200 | [diff] [blame] | 1289 | /* Register all-or-nothing sysfs groups */ |
| 1290 | |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1291 | if (data->innr) { |
| 1292 | err = sysfs_create_group(&dev->kobj, &pc8736x_vin_group); |
| 1293 | if (err) |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1294 | goto error; |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1295 | } |
Jim Cromie | f3722d5b | 2006-09-24 21:03:25 +0200 | [diff] [blame] | 1296 | |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1297 | if (data->innr == 14) { |
| 1298 | err = sysfs_create_group(&dev->kobj, &pc8736x_therm_group); |
| 1299 | if (err) |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1300 | goto error; |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1301 | } |
Jim Cromie | f3722d5b | 2006-09-24 21:03:25 +0200 | [diff] [blame] | 1302 | |
| 1303 | /* create device attr-files for varying sysfs groups */ |
| 1304 | |
| 1305 | if (data->tempnr) { |
| 1306 | for (i = 0; i < data->tempnr; i++) { |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 1307 | err = sysfs_create_group(&dev->kobj, |
| 1308 | &pc8736x_temp_attr_group[i]); |
| 1309 | if (err) |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1310 | goto error; |
Jim Cromie | f3722d5b | 2006-09-24 21:03:25 +0200 | [diff] [blame] | 1311 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1312 | err = device_create_file(dev, &dev_attr_alarms_temp); |
| 1313 | if (err) |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1314 | goto error; |
Jim Cromie | f3722d5b | 2006-09-24 21:03:25 +0200 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | for (i = 0; i < data->fannr; i++) { |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 1318 | if (FAN_CONFIG_MONITOR(data->fan_conf, i)) { |
| 1319 | err = sysfs_create_group(&dev->kobj, |
| 1320 | &pc8736x_fan_attr_group[i]); |
| 1321 | if (err) |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1322 | goto error; |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 1323 | } |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1324 | if (FAN_CONFIG_CONTROL(data->fan_conf, i)) { |
| 1325 | err = device_create_file(dev, &pwm[i].dev_attr); |
| 1326 | if (err) |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1327 | goto error; |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1328 | } |
Jim Cromie | f3722d5b | 2006-09-24 21:03:25 +0200 | [diff] [blame] | 1329 | } |
| 1330 | |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1331 | err = device_create_file(dev, &dev_attr_name); |
| 1332 | if (err) |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1333 | goto error; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1334 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1335 | data->hwmon_dev = hwmon_device_register(dev); |
| 1336 | if (IS_ERR(data->hwmon_dev)) { |
| 1337 | err = PTR_ERR(data->hwmon_dev); |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1338 | goto error; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1339 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | return 0; |
| 1341 | |
Guenter Roeck | 61d4d17 | 2012-06-02 11:20:19 -0700 | [diff] [blame] | 1342 | error: |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 1343 | pc87360_remove_files(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | return err; |
| 1345 | } |
| 1346 | |
Bill Pemberton | 281dfd0 | 2012-11-19 13:25:51 -0500 | [diff] [blame] | 1347 | static int pc87360_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1349 | struct pc87360_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1351 | hwmon_device_unregister(data->hwmon_dev); |
Guenter Roeck | bce2778 | 2012-01-19 20:50:57 -0800 | [diff] [blame] | 1352 | pc87360_remove_files(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | |
| 1354 | return 0; |
| 1355 | } |
| 1356 | |
Guenter Roeck | 3af2861 | 2012-01-19 11:02:22 -0800 | [diff] [blame] | 1357 | /* |
| 1358 | * ldi is the logical device index |
| 1359 | * bank is for voltages and temperatures only |
| 1360 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 1362 | u8 reg) |
| 1363 | { |
| 1364 | int res; |
| 1365 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1366 | mutex_lock(&(data->lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | if (bank != NO_BANK) |
| 1368 | outb_p(bank, data->address[ldi] + PC87365_REG_BANK); |
| 1369 | res = inb_p(data->address[ldi] + reg); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1370 | mutex_unlock(&(data->lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
| 1372 | return res; |
| 1373 | } |
| 1374 | |
| 1375 | static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 1376 | u8 reg, u8 value) |
| 1377 | { |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1378 | mutex_lock(&(data->lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | if (bank != NO_BANK) |
| 1380 | outb_p(bank, data->address[ldi] + PC87365_REG_BANK); |
| 1381 | outb_p(value, data->address[ldi] + reg); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1382 | mutex_unlock(&(data->lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1385 | /* (temp & vin) channel conversion status register flags (pdf sec.11.5.12) */ |
| 1386 | #define CHAN_CNVRTD 0x80 /* new data ready */ |
| 1387 | #define CHAN_ENA 0x01 /* enabled channel (temp or vin) */ |
| 1388 | #define CHAN_ALM_ENA 0x10 /* propagate to alarms-reg ?? (chk val!) */ |
| 1389 | #define CHAN_READY (CHAN_ENA|CHAN_CNVRTD) /* sample ready mask */ |
| 1390 | |
Jim Cromie | b267e8c | 2008-10-18 20:27:32 -0700 | [diff] [blame] | 1391 | #define TEMP_OTS_OE 0x20 /* OTS Output Enable */ |
| 1392 | #define VIN_RW1C_MASK (CHAN_READY|CHAN_ALM_MAX|CHAN_ALM_MIN) /* 0x87 */ |
| 1393 | #define TEMP_RW1C_MASK (VIN_RW1C_MASK|TEMP_ALM_CRIT|TEMP_FAULT) /* 0xCF */ |
| 1394 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1395 | static void pc87360_init_device(struct platform_device *pdev, |
| 1396 | int use_thermistors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1398 | struct pc87360_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | int i, nr; |
| 1400 | const u8 init_in[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 }; |
| 1401 | const u8 init_temp[3] = { 2, 2, 1 }; |
| 1402 | u8 reg; |
| 1403 | |
| 1404 | if (init >= 2 && data->innr) { |
| 1405 | reg = pc87360_read_value(data, LD_IN, NO_BANK, |
| 1406 | PC87365_REG_IN_CONVRATE); |
Guenter Roeck | b55f375 | 2013-01-10 10:01:24 -0800 | [diff] [blame] | 1407 | dev_info(&pdev->dev, |
| 1408 | "VLM conversion set to 1s period, 160us delay\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | pc87360_write_value(data, LD_IN, NO_BANK, |
| 1410 | PC87365_REG_IN_CONVRATE, |
| 1411 | (reg & 0xC0) | 0x11); |
| 1412 | } |
| 1413 | |
| 1414 | nr = data->innr < 11 ? data->innr : 11; |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 1415 | for (i = 0; i < nr; i++) { |
Jim Cromie | 8ca1367 | 2008-10-18 20:27:34 -0700 | [diff] [blame] | 1416 | reg = pc87360_read_value(data, LD_IN, i, |
| 1417 | PC87365_REG_IN_STATUS); |
| 1418 | dev_dbg(&pdev->dev, "bios in%d status:0x%02x\n", i, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | if (init >= init_in[i]) { |
| 1420 | /* Forcibly enable voltage channel */ |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1421 | if (!(reg & CHAN_ENA)) { |
Guenter Roeck | b55f375 | 2013-01-10 10:01:24 -0800 | [diff] [blame] | 1422 | dev_dbg(&pdev->dev, "Forcibly enabling in%d\n", |
| 1423 | i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | pc87360_write_value(data, LD_IN, i, |
| 1425 | PC87365_REG_IN_STATUS, |
| 1426 | (reg & 0x68) | 0x87); |
| 1427 | } |
| 1428 | } |
| 1429 | } |
| 1430 | |
Guenter Roeck | 3af2861 | 2012-01-19 11:02:22 -0800 | [diff] [blame] | 1431 | /* |
| 1432 | * We can't blindly trust the Super-I/O space configuration bit, |
| 1433 | * most BIOS won't set it properly |
| 1434 | */ |
Jim Cromie | 8ca1367 | 2008-10-18 20:27:34 -0700 | [diff] [blame] | 1435 | dev_dbg(&pdev->dev, "bios thermistors:%d\n", use_thermistors); |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 1436 | for (i = 11; i < data->innr; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | reg = pc87360_read_value(data, LD_IN, i, |
| 1438 | PC87365_REG_TEMP_STATUS); |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1439 | use_thermistors = use_thermistors || (reg & CHAN_ENA); |
Jim Cromie | 8ca1367 | 2008-10-18 20:27:34 -0700 | [diff] [blame] | 1440 | /* thermistors are temp[4-6], measured on vin[11-14] */ |
| 1441 | dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i-7, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | } |
Jim Cromie | 8ca1367 | 2008-10-18 20:27:34 -0700 | [diff] [blame] | 1443 | dev_dbg(&pdev->dev, "using thermistors:%d\n", use_thermistors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | |
| 1445 | i = use_thermistors ? 2 : 0; |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 1446 | for (; i < data->tempnr; i++) { |
Jim Cromie | 8ca1367 | 2008-10-18 20:27:34 -0700 | [diff] [blame] | 1447 | reg = pc87360_read_value(data, LD_TEMP, i, |
| 1448 | PC87365_REG_TEMP_STATUS); |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1449 | dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i + 1, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | if (init >= init_temp[i]) { |
| 1451 | /* Forcibly enable temperature channel */ |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1452 | if (!(reg & CHAN_ENA)) { |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1453 | dev_dbg(&pdev->dev, |
| 1454 | "Forcibly enabling temp%d\n", i + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | pc87360_write_value(data, LD_TEMP, i, |
| 1456 | PC87365_REG_TEMP_STATUS, |
| 1457 | 0xCF); |
| 1458 | } |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | if (use_thermistors) { |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 1463 | for (i = 11; i < data->innr; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | if (init >= init_in[i]) { |
Guenter Roeck | 3af2861 | 2012-01-19 11:02:22 -0800 | [diff] [blame] | 1465 | /* |
| 1466 | * The pin may already be used by thermal |
| 1467 | * diodes |
| 1468 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | reg = pc87360_read_value(data, LD_TEMP, |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1470 | (i - 11) / 2, PC87365_REG_TEMP_STATUS); |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1471 | if (reg & CHAN_ENA) { |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1472 | dev_dbg(&pdev->dev, |
| 1473 | "Skipping temp%d, pin already in use by temp%d\n", |
| 1474 | i - 7, (i - 11) / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | continue; |
| 1476 | } |
| 1477 | |
| 1478 | /* Forcibly enable thermistor channel */ |
| 1479 | reg = pc87360_read_value(data, LD_IN, i, |
| 1480 | PC87365_REG_IN_STATUS); |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1481 | if (!(reg & CHAN_ENA)) { |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1482 | dev_dbg(&pdev->dev, |
| 1483 | "Forcibly enabling temp%d\n", |
| 1484 | i - 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | pc87360_write_value(data, LD_IN, i, |
| 1486 | PC87365_REG_TEMP_STATUS, |
| 1487 | (reg & 0x60) | 0x8F); |
| 1488 | } |
| 1489 | } |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | if (data->innr) { |
| 1494 | reg = pc87360_read_value(data, LD_IN, NO_BANK, |
| 1495 | PC87365_REG_IN_CONFIG); |
Jim Cromie | 8ca1367 | 2008-10-18 20:27:34 -0700 | [diff] [blame] | 1496 | dev_dbg(&pdev->dev, "bios vin-cfg:0x%02x\n", reg); |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1497 | if (reg & CHAN_ENA) { |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1498 | dev_dbg(&pdev->dev, |
| 1499 | "Forcibly enabling monitoring (VLM)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | pc87360_write_value(data, LD_IN, NO_BANK, |
| 1501 | PC87365_REG_IN_CONFIG, |
| 1502 | reg & 0xFE); |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | if (data->tempnr) { |
| 1507 | reg = pc87360_read_value(data, LD_TEMP, NO_BANK, |
| 1508 | PC87365_REG_TEMP_CONFIG); |
Jim Cromie | 8ca1367 | 2008-10-18 20:27:34 -0700 | [diff] [blame] | 1509 | dev_dbg(&pdev->dev, "bios temp-cfg:0x%02x\n", reg); |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1510 | if (reg & CHAN_ENA) { |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1511 | dev_dbg(&pdev->dev, |
| 1512 | "Forcibly enabling monitoring (TMS)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | pc87360_write_value(data, LD_TEMP, NO_BANK, |
| 1514 | PC87365_REG_TEMP_CONFIG, |
| 1515 | reg & 0xFE); |
| 1516 | } |
| 1517 | |
| 1518 | if (init >= 2) { |
| 1519 | /* Chip config as documented by National Semi. */ |
| 1520 | pc87360_write_value(data, LD_TEMP, 0xF, 0xA, 0x08); |
Guenter Roeck | 3af2861 | 2012-01-19 11:02:22 -0800 | [diff] [blame] | 1521 | /* |
| 1522 | * We voluntarily omit the bank here, in case the |
| 1523 | * sequence itself matters. It shouldn't be a problem, |
| 1524 | * since nobody else is supposed to access the |
| 1525 | * device at that point. |
| 1526 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xB, 0x04); |
| 1528 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xC, 0x35); |
| 1529 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xD, 0x05); |
| 1530 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xE, 0x05); |
| 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1535 | static void pc87360_autodiv(struct device *dev, int nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1537 | struct pc87360_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | u8 old_min = data->fan_min[nr]; |
| 1539 | |
| 1540 | /* Increase clock divider if needed and possible */ |
| 1541 | if ((data->fan_status[nr] & 0x04) /* overflow flag */ |
| 1542 | || (data->fan[nr] >= 224)) { /* next to overflow */ |
| 1543 | if ((data->fan_status[nr] & 0x60) != 0x60) { |
| 1544 | data->fan_status[nr] += 0x20; |
| 1545 | data->fan_min[nr] >>= 1; |
| 1546 | data->fan[nr] >>= 1; |
Guenter Roeck | b55f375 | 2013-01-10 10:01:24 -0800 | [diff] [blame] | 1547 | dev_dbg(dev, |
| 1548 | "Increasing clock divider to %d for fan %d\n", |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1549 | FAN_DIV_FROM_REG(data->fan_status[nr]), nr + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | } |
| 1551 | } else { |
| 1552 | /* Decrease clock divider if possible */ |
| 1553 | while (!(data->fan_min[nr] & 0x80) /* min "nails" divider */ |
| 1554 | && data->fan[nr] < 85 /* bad accuracy */ |
| 1555 | && (data->fan_status[nr] & 0x60) != 0x00) { |
| 1556 | data->fan_status[nr] -= 0x20; |
| 1557 | data->fan_min[nr] <<= 1; |
| 1558 | data->fan[nr] <<= 1; |
Guenter Roeck | b55f375 | 2013-01-10 10:01:24 -0800 | [diff] [blame] | 1559 | dev_dbg(dev, |
| 1560 | "Decreasing clock divider to %d for fan %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | FAN_DIV_FROM_REG(data->fan_status[nr]), |
Guenter Roeck | 449a7a0 | 2012-01-14 21:49:53 -0800 | [diff] [blame] | 1562 | nr + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | /* Write new fan min if it changed */ |
| 1567 | if (old_min != data->fan_min[nr]) { |
| 1568 | pc87360_write_value(data, LD_FAN, NO_BANK, |
| 1569 | PC87360_REG_FAN_MIN(nr), |
| 1570 | data->fan_min[nr]); |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | static struct pc87360_data *pc87360_update_device(struct device *dev) |
| 1575 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1576 | struct pc87360_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | u8 i; |
| 1578 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1579 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | |
| 1581 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1582 | dev_dbg(dev, "Data update\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | |
| 1584 | /* Fans */ |
| 1585 | for (i = 0; i < data->fannr; i++) { |
| 1586 | if (FAN_CONFIG_MONITOR(data->fan_conf, i)) { |
| 1587 | data->fan_status[i] = |
| 1588 | pc87360_read_value(data, LD_FAN, |
| 1589 | NO_BANK, PC87360_REG_FAN_STATUS(i)); |
| 1590 | data->fan[i] = pc87360_read_value(data, LD_FAN, |
| 1591 | NO_BANK, PC87360_REG_FAN(i)); |
| 1592 | data->fan_min[i] = pc87360_read_value(data, |
| 1593 | LD_FAN, NO_BANK, |
| 1594 | PC87360_REG_FAN_MIN(i)); |
| 1595 | /* Change clock divider if needed */ |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1596 | pc87360_autodiv(dev, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | /* Clear bits and write new divider */ |
| 1598 | pc87360_write_value(data, LD_FAN, NO_BANK, |
| 1599 | PC87360_REG_FAN_STATUS(i), |
| 1600 | data->fan_status[i]); |
| 1601 | } |
| 1602 | if (FAN_CONFIG_CONTROL(data->fan_conf, i)) |
| 1603 | data->pwm[i] = pc87360_read_value(data, LD_FAN, |
| 1604 | NO_BANK, PC87360_REG_PWM(i)); |
| 1605 | } |
| 1606 | |
| 1607 | /* Voltages */ |
| 1608 | for (i = 0; i < data->innr; i++) { |
| 1609 | data->in_status[i] = pc87360_read_value(data, LD_IN, i, |
| 1610 | PC87365_REG_IN_STATUS); |
| 1611 | /* Clear bits */ |
| 1612 | pc87360_write_value(data, LD_IN, i, |
| 1613 | PC87365_REG_IN_STATUS, |
| 1614 | data->in_status[i]); |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1615 | if ((data->in_status[i] & CHAN_READY) == CHAN_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | data->in[i] = pc87360_read_value(data, LD_IN, |
| 1617 | i, PC87365_REG_IN); |
| 1618 | } |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1619 | if (data->in_status[i] & CHAN_ENA) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | data->in_min[i] = pc87360_read_value(data, |
| 1621 | LD_IN, i, |
| 1622 | PC87365_REG_IN_MIN); |
| 1623 | data->in_max[i] = pc87360_read_value(data, |
| 1624 | LD_IN, i, |
| 1625 | PC87365_REG_IN_MAX); |
| 1626 | if (i >= 11) |
| 1627 | data->in_crit[i-11] = |
| 1628 | pc87360_read_value(data, LD_IN, |
| 1629 | i, PC87365_REG_TEMP_CRIT); |
| 1630 | } |
| 1631 | } |
| 1632 | if (data->innr) { |
| 1633 | data->in_alarms = pc87360_read_value(data, LD_IN, |
| 1634 | NO_BANK, PC87365_REG_IN_ALARMS1) |
| 1635 | | ((pc87360_read_value(data, LD_IN, |
| 1636 | NO_BANK, PC87365_REG_IN_ALARMS2) |
| 1637 | & 0x07) << 8); |
| 1638 | data->vid = (data->vid_conf & 0xE0) ? |
| 1639 | pc87360_read_value(data, LD_IN, |
| 1640 | NO_BANK, PC87365_REG_VID) : 0x1F; |
| 1641 | } |
| 1642 | |
| 1643 | /* Temperatures */ |
| 1644 | for (i = 0; i < data->tempnr; i++) { |
| 1645 | data->temp_status[i] = pc87360_read_value(data, |
| 1646 | LD_TEMP, i, |
| 1647 | PC87365_REG_TEMP_STATUS); |
| 1648 | /* Clear bits */ |
| 1649 | pc87360_write_value(data, LD_TEMP, i, |
| 1650 | PC87365_REG_TEMP_STATUS, |
| 1651 | data->temp_status[i]); |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1652 | if ((data->temp_status[i] & CHAN_READY) == CHAN_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | data->temp[i] = pc87360_read_value(data, |
| 1654 | LD_TEMP, i, |
| 1655 | PC87365_REG_TEMP); |
| 1656 | } |
Jim Cromie | 28f74e7 | 2008-10-18 20:27:30 -0700 | [diff] [blame] | 1657 | if (data->temp_status[i] & CHAN_ENA) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | data->temp_min[i] = pc87360_read_value(data, |
| 1659 | LD_TEMP, i, |
| 1660 | PC87365_REG_TEMP_MIN); |
| 1661 | data->temp_max[i] = pc87360_read_value(data, |
| 1662 | LD_TEMP, i, |
| 1663 | PC87365_REG_TEMP_MAX); |
| 1664 | data->temp_crit[i] = pc87360_read_value(data, |
| 1665 | LD_TEMP, i, |
| 1666 | PC87365_REG_TEMP_CRIT); |
| 1667 | } |
| 1668 | } |
| 1669 | if (data->tempnr) { |
| 1670 | data->temp_alarms = pc87360_read_value(data, LD_TEMP, |
| 1671 | NO_BANK, PC87365_REG_TEMP_ALARMS) |
| 1672 | & 0x3F; |
| 1673 | } |
| 1674 | |
| 1675 | data->last_updated = jiffies; |
| 1676 | data->valid = 1; |
| 1677 | } |
| 1678 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1679 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | |
| 1681 | return data; |
| 1682 | } |
| 1683 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1684 | static int __init pc87360_device_add(unsigned short address) |
| 1685 | { |
Jean Delvare | b9783dc | 2010-08-14 21:08:48 +0200 | [diff] [blame] | 1686 | struct resource res[3]; |
| 1687 | int err, i, res_count; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1688 | |
| 1689 | pdev = platform_device_alloc("pc87360", address); |
| 1690 | if (!pdev) { |
| 1691 | err = -ENOMEM; |
Joe Perches | 9e991c6 | 2011-01-12 21:55:11 +0100 | [diff] [blame] | 1692 | pr_err("Device allocation failed\n"); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1693 | goto exit; |
| 1694 | } |
| 1695 | |
Jean Delvare | b9783dc | 2010-08-14 21:08:48 +0200 | [diff] [blame] | 1696 | memset(res, 0, 3 * sizeof(struct resource)); |
| 1697 | res_count = 0; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1698 | for (i = 0; i < 3; i++) { |
| 1699 | if (!extra_isa[i]) |
| 1700 | continue; |
Jean Delvare | b9783dc | 2010-08-14 21:08:48 +0200 | [diff] [blame] | 1701 | res[res_count].start = extra_isa[i]; |
| 1702 | res[res_count].end = extra_isa[i] + PC87360_EXTENT - 1; |
Zheng Yongjun | 94c08e0 | 2020-12-14 21:31:14 +0800 | [diff] [blame] | 1703 | res[res_count].name = "pc87360"; |
| 1704 | res[res_count].flags = IORESOURCE_IO; |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 1705 | |
Jean Delvare | b9783dc | 2010-08-14 21:08:48 +0200 | [diff] [blame] | 1706 | err = acpi_check_resource_conflict(&res[res_count]); |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 1707 | if (err) |
| 1708 | goto exit_device_put; |
| 1709 | |
Jean Delvare | b9783dc | 2010-08-14 21:08:48 +0200 | [diff] [blame] | 1710 | res_count++; |
| 1711 | } |
| 1712 | |
| 1713 | err = platform_device_add_resources(pdev, res, res_count); |
| 1714 | if (err) { |
Joe Perches | 9e991c6 | 2011-01-12 21:55:11 +0100 | [diff] [blame] | 1715 | pr_err("Device resources addition failed (%d)\n", err); |
Jean Delvare | b9783dc | 2010-08-14 21:08:48 +0200 | [diff] [blame] | 1716 | goto exit_device_put; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | err = platform_device_add(pdev); |
| 1720 | if (err) { |
Joe Perches | 9e991c6 | 2011-01-12 21:55:11 +0100 | [diff] [blame] | 1721 | pr_err("Device addition failed (%d)\n", err); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1722 | goto exit_device_put; |
| 1723 | } |
| 1724 | |
| 1725 | return 0; |
| 1726 | |
| 1727 | exit_device_put: |
| 1728 | platform_device_put(pdev); |
| 1729 | exit: |
| 1730 | return err; |
| 1731 | } |
| 1732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | static int __init pc87360_init(void) |
| 1734 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1735 | int err, i; |
| 1736 | unsigned short address = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | |
| 1738 | if (pc87360_find(0x2e, &devid, extra_isa) |
| 1739 | && pc87360_find(0x4e, &devid, extra_isa)) { |
Joe Perches | 9e991c6 | 2011-01-12 21:55:11 +0100 | [diff] [blame] | 1740 | pr_warn("PC8736x not detected, module not inserted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | return -ENODEV; |
| 1742 | } |
| 1743 | |
| 1744 | /* Arbitrarily pick one of the addresses */ |
| 1745 | for (i = 0; i < 3; i++) { |
| 1746 | if (extra_isa[i] != 0x0000) { |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 1747 | address = extra_isa[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | break; |
| 1749 | } |
| 1750 | } |
| 1751 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 1752 | if (address == 0x0000) { |
Joe Perches | 9e991c6 | 2011-01-12 21:55:11 +0100 | [diff] [blame] | 1753 | pr_warn("No active logical device, module not inserted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | return -ENODEV; |
| 1755 | } |
| 1756 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1757 | err = platform_driver_register(&pc87360_driver); |
| 1758 | if (err) |
| 1759 | goto exit; |
| 1760 | |
| 1761 | /* Sets global pdev as a side effect */ |
| 1762 | err = pc87360_device_add(address); |
| 1763 | if (err) |
| 1764 | goto exit_driver; |
| 1765 | |
| 1766 | return 0; |
| 1767 | |
| 1768 | exit_driver: |
| 1769 | platform_driver_unregister(&pc87360_driver); |
| 1770 | exit: |
| 1771 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | static void __exit pc87360_exit(void) |
| 1775 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1776 | platform_device_unregister(pdev); |
| 1777 | platform_driver_unregister(&pc87360_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | |
Jean Delvare | 7c81c60f | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1781 | MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | MODULE_DESCRIPTION("PC8736x hardware monitor"); |
| 1783 | MODULE_LICENSE("GPL"); |
| 1784 | |
| 1785 | module_init(pc87360_init); |
| 1786 | module_exit(pc87360_exit); |