Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1 | /* |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2 | * dme1737.c - Driver for the SMSC DME1737, Asus A8000, SMSC SCH311x, SCH5027, |
| 3 | * and SCH5127 Super-I/O chips integrated hardware monitoring |
| 4 | * features. |
| 5 | * Copyright (c) 2007, 2008, 2009, 2010 Juerg Haefliger <juergh@gmail.com> |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 6 | * |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 7 | * This driver is an I2C/ISA hybrid, meaning that it uses the I2C bus to access |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 8 | * the chip registers if a DME1737, A8000, or SCH5027 is found and the ISA bus |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 9 | * if a SCH311x or SCH5127 chip is found. Both types of chips have very |
| 10 | * similar hardware monitoring capabilities but differ in the way they can be |
| 11 | * accessed. |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | */ |
| 27 | |
Joe Perches | 9c6e13b | 2010-10-20 06:51:32 +0000 | [diff] [blame] | 28 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 29 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/jiffies.h> |
| 34 | #include <linux/i2c.h> |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 35 | #include <linux/platform_device.h> |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 36 | #include <linux/hwmon.h> |
| 37 | #include <linux/hwmon-sysfs.h> |
| 38 | #include <linux/hwmon-vid.h> |
| 39 | #include <linux/err.h> |
| 40 | #include <linux/mutex.h> |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 41 | #include <linux/acpi.h> |
H Hartley Sweeten | 6055fae | 2009-09-15 17:18:13 +0200 | [diff] [blame] | 42 | #include <linux/io.h> |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 43 | |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 44 | /* ISA device, if found */ |
| 45 | static struct platform_device *pdev; |
| 46 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 47 | /* Module load parameters */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 48 | static bool force_start; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 49 | module_param(force_start, bool, 0); |
| 50 | MODULE_PARM_DESC(force_start, "Force the chip to start monitoring inputs"); |
| 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 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 56 | static bool probe_all_addr; |
Juerg Haefliger | 92430b6 | 2008-04-03 21:34:19 -0700 | [diff] [blame] | 57 | module_param(probe_all_addr, bool, 0); |
| 58 | MODULE_PARM_DESC(probe_all_addr, "Include probing of non-standard LPC " |
| 59 | "addresses"); |
| 60 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 61 | /* Addresses to scan */ |
Mark M. Hoffman | 25e9c86 | 2008-02-17 22:28:03 -0500 | [diff] [blame] | 62 | static const unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END}; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 63 | |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 64 | enum chips { dme1737, sch5027, sch311x, sch5127 }; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 65 | |
| 66 | /* --------------------------------------------------------------------- |
| 67 | * Registers |
| 68 | * |
| 69 | * The sensors are defined as follows: |
| 70 | * |
| 71 | * Voltages Temperatures |
| 72 | * -------- ------------ |
| 73 | * in0 +5VTR (+5V stdby) temp1 Remote diode 1 |
| 74 | * in1 Vccp (proc core) temp2 Internal temp |
| 75 | * in2 VCC (internal +3.3V) temp3 Remote diode 2 |
| 76 | * in3 +5V |
| 77 | * in4 +12V |
| 78 | * in5 VTR (+3.3V stby) |
| 79 | * in6 Vbat |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 80 | * in7 Vtrip (sch5127 only) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 81 | * |
| 82 | * --------------------------------------------------------------------- */ |
| 83 | |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 84 | /* Voltages (in) numbered 0-7 (ix) */ |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 85 | #define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) : \ |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 86 | (ix) < 7 ? 0x94 + (ix) : \ |
| 87 | 0x1f) |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 88 | #define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 89 | : 0x91 + (ix) * 2) |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 90 | #define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 91 | : 0x92 + (ix) * 2) |
| 92 | |
| 93 | /* Temperatures (temp) numbered 0-2 (ix) */ |
| 94 | #define DME1737_REG_TEMP(ix) (0x25 + (ix)) |
| 95 | #define DME1737_REG_TEMP_MIN(ix) (0x4e + (ix) * 2) |
| 96 | #define DME1737_REG_TEMP_MAX(ix) (0x4f + (ix) * 2) |
| 97 | #define DME1737_REG_TEMP_OFFSET(ix) ((ix) == 0 ? 0x1f \ |
| 98 | : 0x1c + (ix)) |
| 99 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 100 | /* |
| 101 | * Voltage and temperature LSBs |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 102 | * The LSBs (4 bits each) are stored in 5 registers with the following layouts: |
| 103 | * IN_TEMP_LSB(0) = [in5, in6] |
| 104 | * IN_TEMP_LSB(1) = [temp3, temp1] |
| 105 | * IN_TEMP_LSB(2) = [in4, temp2] |
| 106 | * IN_TEMP_LSB(3) = [in3, in0] |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 107 | * IN_TEMP_LSB(4) = [in2, in1] |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 108 | * IN_TEMP_LSB(5) = [res, in7] |
| 109 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 110 | #define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix)) |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 111 | static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0, 5}; |
| 112 | static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4, 4}; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 113 | static const u8 DME1737_REG_TEMP_LSB[] = {1, 2, 1}; |
| 114 | static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0}; |
| 115 | |
| 116 | /* Fans numbered 0-5 (ix) */ |
| 117 | #define DME1737_REG_FAN(ix) ((ix) < 4 ? 0x28 + (ix) * 2 \ |
| 118 | : 0xa1 + (ix) * 2) |
| 119 | #define DME1737_REG_FAN_MIN(ix) ((ix) < 4 ? 0x54 + (ix) * 2 \ |
| 120 | : 0xa5 + (ix) * 2) |
| 121 | #define DME1737_REG_FAN_OPT(ix) ((ix) < 4 ? 0x90 + (ix) \ |
| 122 | : 0xb2 + (ix)) |
| 123 | #define DME1737_REG_FAN_MAX(ix) (0xb4 + (ix)) /* only for fan[4-5] */ |
| 124 | |
| 125 | /* PWMs numbered 0-2, 4-5 (ix) */ |
| 126 | #define DME1737_REG_PWM(ix) ((ix) < 3 ? 0x30 + (ix) \ |
| 127 | : 0xa1 + (ix)) |
| 128 | #define DME1737_REG_PWM_CONFIG(ix) (0x5c + (ix)) /* only for pwm[0-2] */ |
| 129 | #define DME1737_REG_PWM_MIN(ix) (0x64 + (ix)) /* only for pwm[0-2] */ |
| 130 | #define DME1737_REG_PWM_FREQ(ix) ((ix) < 3 ? 0x5f + (ix) \ |
| 131 | : 0xa3 + (ix)) |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 132 | /* |
| 133 | * The layout of the ramp rate registers is different from the other pwm |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 134 | * registers. The bits for the 3 PWMs are stored in 2 registers: |
| 135 | * PWM_RR(0) = [OFF3, OFF2, OFF1, RES, RR1E, RR1-2, RR1-1, RR1-0] |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 136 | * PWM_RR(1) = [RR2E, RR2-2, RR2-1, RR2-0, RR3E, RR3-2, RR3-1, RR3-0] |
| 137 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 138 | #define DME1737_REG_PWM_RR(ix) (0x62 + (ix)) /* only for pwm[0-2] */ |
| 139 | |
| 140 | /* Thermal zones 0-2 */ |
| 141 | #define DME1737_REG_ZONE_LOW(ix) (0x67 + (ix)) |
| 142 | #define DME1737_REG_ZONE_ABS(ix) (0x6a + (ix)) |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 143 | /* |
| 144 | * The layout of the hysteresis registers is different from the other zone |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 145 | * registers. The bits for the 3 zones are stored in 2 registers: |
| 146 | * ZONE_HYST(0) = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0] |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 147 | * ZONE_HYST(1) = [H3-3, H3-2, H3-1, H3-0, RES, RES, RES, RES] |
| 148 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 149 | #define DME1737_REG_ZONE_HYST(ix) (0x6d + (ix)) |
| 150 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 151 | /* |
| 152 | * Alarm registers and bit mapping |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 153 | * The 3 8-bit alarm registers will be concatenated to a single 32-bit |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 154 | * alarm value [0, ALARM3, ALARM2, ALARM1]. |
| 155 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 156 | #define DME1737_REG_ALARM1 0x41 |
| 157 | #define DME1737_REG_ALARM2 0x42 |
| 158 | #define DME1737_REG_ALARM3 0x83 |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 159 | static const u8 DME1737_BIT_ALARM_IN[] = {0, 1, 2, 3, 8, 16, 17, 18}; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 160 | static const u8 DME1737_BIT_ALARM_TEMP[] = {4, 5, 6}; |
| 161 | static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23}; |
| 162 | |
| 163 | /* Miscellaneous registers */ |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 164 | #define DME1737_REG_DEVICE 0x3d |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 165 | #define DME1737_REG_COMPANY 0x3e |
| 166 | #define DME1737_REG_VERSTEP 0x3f |
| 167 | #define DME1737_REG_CONFIG 0x40 |
| 168 | #define DME1737_REG_CONFIG2 0x7f |
| 169 | #define DME1737_REG_VID 0x43 |
| 170 | #define DME1737_REG_TACH_PWM 0x81 |
| 171 | |
| 172 | /* --------------------------------------------------------------------- |
| 173 | * Misc defines |
| 174 | * --------------------------------------------------------------------- */ |
| 175 | |
| 176 | /* Chip identification */ |
| 177 | #define DME1737_COMPANY_SMSC 0x5c |
| 178 | #define DME1737_VERSTEP 0x88 |
| 179 | #define DME1737_VERSTEP_MASK 0xf8 |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 180 | #define SCH311X_DEVICE 0x8c |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 181 | #define SCH5027_VERSTEP 0x69 |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 182 | #define SCH5127_DEVICE 0x8e |
| 183 | |
| 184 | /* Device ID values (global configuration register index 0x20) */ |
| 185 | #define DME1737_ID_1 0x77 |
| 186 | #define DME1737_ID_2 0x78 |
| 187 | #define SCH3112_ID 0x7c |
| 188 | #define SCH3114_ID 0x7d |
| 189 | #define SCH3116_ID 0x7f |
| 190 | #define SCH5027_ID 0x89 |
| 191 | #define SCH5127_ID 0x86 |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 192 | |
| 193 | /* Length of ISA address segment */ |
| 194 | #define DME1737_EXTENT 2 |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 195 | |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 196 | /* chip-dependent features */ |
| 197 | #define HAS_TEMP_OFFSET (1 << 0) /* bit 0 */ |
| 198 | #define HAS_VID (1 << 1) /* bit 1 */ |
| 199 | #define HAS_ZONE3 (1 << 2) /* bit 2 */ |
| 200 | #define HAS_ZONE_HYST (1 << 3) /* bit 3 */ |
| 201 | #define HAS_PWM_MIN (1 << 4) /* bit 4 */ |
| 202 | #define HAS_FAN(ix) (1 << ((ix) + 5)) /* bits 5-10 */ |
| 203 | #define HAS_PWM(ix) (1 << ((ix) + 11)) /* bits 11-16 */ |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 204 | #define HAS_IN7 (1 << 17) /* bit 17 */ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 205 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 206 | /* --------------------------------------------------------------------- |
| 207 | * Data structures and manipulation thereof |
| 208 | * --------------------------------------------------------------------- */ |
| 209 | |
| 210 | struct dme1737_data { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 211 | struct i2c_client *client; /* for I2C devices only */ |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 212 | struct device *hwmon_dev; |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 213 | const char *name; |
| 214 | unsigned int addr; /* for ISA devices only */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 215 | |
| 216 | struct mutex update_lock; |
| 217 | int valid; /* !=0 if following fields are valid */ |
| 218 | unsigned long last_update; /* in jiffies */ |
| 219 | unsigned long last_vbat; /* in jiffies */ |
Juerg Haefliger | f994fb2 | 2008-03-25 21:49:15 -0700 | [diff] [blame] | 220 | enum chips type; |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 221 | const int *in_nominal; /* pointer to IN_NOMINAL array */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 222 | |
| 223 | u8 vid; |
| 224 | u8 pwm_rr_en; |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 225 | u32 has_features; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 226 | |
| 227 | /* Register values */ |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 228 | u16 in[8]; |
| 229 | u8 in_min[8]; |
| 230 | u8 in_max[8]; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 231 | s16 temp[3]; |
| 232 | s8 temp_min[3]; |
| 233 | s8 temp_max[3]; |
| 234 | s8 temp_offset[3]; |
| 235 | u8 config; |
| 236 | u8 config2; |
| 237 | u8 vrm; |
| 238 | u16 fan[6]; |
| 239 | u16 fan_min[6]; |
| 240 | u8 fan_max[2]; |
| 241 | u8 fan_opt[6]; |
| 242 | u8 pwm[6]; |
| 243 | u8 pwm_min[3]; |
| 244 | u8 pwm_config[3]; |
| 245 | u8 pwm_acz[3]; |
| 246 | u8 pwm_freq[6]; |
| 247 | u8 pwm_rr[2]; |
| 248 | u8 zone_low[3]; |
| 249 | u8 zone_abs[3]; |
| 250 | u8 zone_hyst[2]; |
| 251 | u32 alarms; |
| 252 | }; |
| 253 | |
| 254 | /* Nominal voltage values */ |
Juerg Haefliger | f994fb2 | 2008-03-25 21:49:15 -0700 | [diff] [blame] | 255 | static const int IN_NOMINAL_DME1737[] = {5000, 2250, 3300, 5000, 12000, 3300, |
| 256 | 3300}; |
| 257 | static const int IN_NOMINAL_SCH311x[] = {2500, 1500, 3300, 5000, 12000, 3300, |
| 258 | 3300}; |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 259 | static const int IN_NOMINAL_SCH5027[] = {5000, 2250, 3300, 1125, 1125, 3300, |
| 260 | 3300}; |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 261 | static const int IN_NOMINAL_SCH5127[] = {2500, 2250, 3300, 1125, 1125, 3300, |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 262 | 3300, 1500}; |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 263 | #define IN_NOMINAL(type) ((type) == sch311x ? IN_NOMINAL_SCH311x : \ |
| 264 | (type) == sch5027 ? IN_NOMINAL_SCH5027 : \ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 265 | (type) == sch5127 ? IN_NOMINAL_SCH5127 : \ |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 266 | IN_NOMINAL_DME1737) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 267 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 268 | /* |
| 269 | * Voltage input |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 270 | * Voltage inputs have 16 bits resolution, limit values have 8 bits |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 271 | * resolution. |
| 272 | */ |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 273 | static inline int IN_FROM_REG(int reg, int nominal, int res) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 274 | { |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 275 | return (reg * nominal + (3 << (res - 3))) / (3 << (res - 2)); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 276 | } |
| 277 | |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 278 | static inline int IN_TO_REG(int val, int nominal) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 279 | { |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame^] | 280 | return clamp_val((val * 192 + nominal / 2) / nominal, 0, 255); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 281 | } |
| 282 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 283 | /* |
| 284 | * Temperature input |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 285 | * The register values represent temperatures in 2's complement notation from |
| 286 | * -127 degrees C to +127 degrees C. Temp inputs have 16 bits resolution, limit |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 287 | * values have 8 bits resolution. |
| 288 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 289 | static inline int TEMP_FROM_REG(int reg, int res) |
| 290 | { |
| 291 | return (reg * 1000) >> (res - 8); |
| 292 | } |
| 293 | |
| 294 | static inline int TEMP_TO_REG(int val) |
| 295 | { |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame^] | 296 | return clamp_val((val < 0 ? val - 500 : val + 500) / 1000, -128, 127); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /* Temperature range */ |
| 300 | static const int TEMP_RANGE[] = {2000, 2500, 3333, 4000, 5000, 6666, 8000, |
| 301 | 10000, 13333, 16000, 20000, 26666, 32000, |
| 302 | 40000, 53333, 80000}; |
| 303 | |
| 304 | static inline int TEMP_RANGE_FROM_REG(int reg) |
| 305 | { |
| 306 | return TEMP_RANGE[(reg >> 4) & 0x0f]; |
| 307 | } |
| 308 | |
| 309 | static int TEMP_RANGE_TO_REG(int val, int reg) |
| 310 | { |
| 311 | int i; |
| 312 | |
| 313 | for (i = 15; i > 0; i--) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 314 | if (val > (TEMP_RANGE[i] + TEMP_RANGE[i - 1] + 1) / 2) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 315 | break; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | return (reg & 0x0f) | (i << 4); |
| 319 | } |
| 320 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 321 | /* |
| 322 | * Temperature hysteresis |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 323 | * Register layout: |
| 324 | * reg[0] = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0] |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 325 | * reg[1] = [H3-3, H3-2, H3-1, H3-0, xxxx, xxxx, xxxx, xxxx] |
| 326 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 327 | static inline int TEMP_HYST_FROM_REG(int reg, int ix) |
| 328 | { |
| 329 | return (((ix == 1) ? reg : reg >> 4) & 0x0f) * 1000; |
| 330 | } |
| 331 | |
| 332 | static inline int TEMP_HYST_TO_REG(int val, int ix, int reg) |
| 333 | { |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame^] | 334 | int hyst = clamp_val((val + 500) / 1000, 0, 15); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 335 | |
| 336 | return (ix == 1) ? (reg & 0xf0) | hyst : (reg & 0x0f) | (hyst << 4); |
| 337 | } |
| 338 | |
| 339 | /* Fan input RPM */ |
| 340 | static inline int FAN_FROM_REG(int reg, int tpc) |
| 341 | { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 342 | if (tpc) |
Juerg Haefliger | ff8421f | 2008-01-27 16:39:46 -0800 | [diff] [blame] | 343 | return tpc * reg; |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 344 | else |
Juerg Haefliger | ff8421f | 2008-01-27 16:39:46 -0800 | [diff] [blame] | 345 | return (reg == 0 || reg == 0xffff) ? 0 : 90000 * 60 / reg; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static inline int FAN_TO_REG(int val, int tpc) |
| 349 | { |
Juerg Haefliger | ff8421f | 2008-01-27 16:39:46 -0800 | [diff] [blame] | 350 | if (tpc) { |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame^] | 351 | return clamp_val(val / tpc, 0, 0xffff); |
Juerg Haefliger | ff8421f | 2008-01-27 16:39:46 -0800 | [diff] [blame] | 352 | } else { |
| 353 | return (val <= 0) ? 0xffff : |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame^] | 354 | clamp_val(90000 * 60 / val, 0, 0xfffe); |
Juerg Haefliger | ff8421f | 2008-01-27 16:39:46 -0800 | [diff] [blame] | 355 | } |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 356 | } |
| 357 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 358 | /* |
| 359 | * Fan TPC (tach pulse count) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 360 | * Converts a register value to a TPC multiplier or returns 0 if the tachometer |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 361 | * is configured in legacy (non-tpc) mode |
| 362 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 363 | static inline int FAN_TPC_FROM_REG(int reg) |
| 364 | { |
| 365 | return (reg & 0x20) ? 0 : 60 >> (reg & 0x03); |
| 366 | } |
| 367 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 368 | /* |
| 369 | * Fan type |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 370 | * The type of a fan is expressed in number of pulses-per-revolution that it |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 371 | * emits |
| 372 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 373 | static inline int FAN_TYPE_FROM_REG(int reg) |
| 374 | { |
| 375 | int edge = (reg >> 1) & 0x03; |
| 376 | |
| 377 | return (edge > 0) ? 1 << (edge - 1) : 0; |
| 378 | } |
| 379 | |
| 380 | static inline int FAN_TYPE_TO_REG(int val, int reg) |
| 381 | { |
| 382 | int edge = (val == 4) ? 3 : val; |
| 383 | |
| 384 | return (reg & 0xf9) | (edge << 1); |
| 385 | } |
| 386 | |
| 387 | /* Fan max RPM */ |
| 388 | static const int FAN_MAX[] = {0x54, 0x38, 0x2a, 0x21, 0x1c, 0x18, 0x15, 0x12, |
| 389 | 0x11, 0x0f, 0x0e}; |
| 390 | |
| 391 | static int FAN_MAX_FROM_REG(int reg) |
| 392 | { |
| 393 | int i; |
| 394 | |
| 395 | for (i = 10; i > 0; i--) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 396 | if (reg == FAN_MAX[i]) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 397 | break; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | return 1000 + i * 500; |
| 401 | } |
| 402 | |
| 403 | static int FAN_MAX_TO_REG(int val) |
| 404 | { |
| 405 | int i; |
| 406 | |
| 407 | for (i = 10; i > 0; i--) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 408 | if (val > (1000 + (i - 1) * 500)) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 409 | break; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | return FAN_MAX[i]; |
| 413 | } |
| 414 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 415 | /* |
| 416 | * PWM enable |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 417 | * Register to enable mapping: |
| 418 | * 000: 2 fan on zone 1 auto |
| 419 | * 001: 2 fan on zone 2 auto |
| 420 | * 010: 2 fan on zone 3 auto |
| 421 | * 011: 0 fan full on |
| 422 | * 100: -1 fan disabled |
| 423 | * 101: 2 fan on hottest of zones 2,3 auto |
| 424 | * 110: 2 fan on hottest of zones 1,2,3 auto |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 425 | * 111: 1 fan in manual mode |
| 426 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 427 | static inline int PWM_EN_FROM_REG(int reg) |
| 428 | { |
| 429 | static const int en[] = {2, 2, 2, 0, -1, 2, 2, 1}; |
| 430 | |
| 431 | return en[(reg >> 5) & 0x07]; |
| 432 | } |
| 433 | |
| 434 | static inline int PWM_EN_TO_REG(int val, int reg) |
| 435 | { |
| 436 | int en = (val == 1) ? 7 : 3; |
| 437 | |
| 438 | return (reg & 0x1f) | ((en & 0x07) << 5); |
| 439 | } |
| 440 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 441 | /* |
| 442 | * PWM auto channels zone |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 443 | * Register to auto channels zone mapping (ACZ is a bitfield with bit x |
| 444 | * corresponding to zone x+1): |
| 445 | * 000: 001 fan on zone 1 auto |
| 446 | * 001: 010 fan on zone 2 auto |
| 447 | * 010: 100 fan on zone 3 auto |
| 448 | * 011: 000 fan full on |
| 449 | * 100: 000 fan disabled |
| 450 | * 101: 110 fan on hottest of zones 2,3 auto |
| 451 | * 110: 111 fan on hottest of zones 1,2,3 auto |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 452 | * 111: 000 fan in manual mode |
| 453 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 454 | static inline int PWM_ACZ_FROM_REG(int reg) |
| 455 | { |
| 456 | static const int acz[] = {1, 2, 4, 0, 0, 6, 7, 0}; |
| 457 | |
| 458 | return acz[(reg >> 5) & 0x07]; |
| 459 | } |
| 460 | |
| 461 | static inline int PWM_ACZ_TO_REG(int val, int reg) |
| 462 | { |
| 463 | int acz = (val == 4) ? 2 : val - 1; |
| 464 | |
| 465 | return (reg & 0x1f) | ((acz & 0x07) << 5); |
| 466 | } |
| 467 | |
| 468 | /* PWM frequency */ |
| 469 | static const int PWM_FREQ[] = {11, 15, 22, 29, 35, 44, 59, 88, |
| 470 | 15000, 20000, 30000, 25000, 0, 0, 0, 0}; |
| 471 | |
| 472 | static inline int PWM_FREQ_FROM_REG(int reg) |
| 473 | { |
| 474 | return PWM_FREQ[reg & 0x0f]; |
| 475 | } |
| 476 | |
| 477 | static int PWM_FREQ_TO_REG(int val, int reg) |
| 478 | { |
| 479 | int i; |
| 480 | |
| 481 | /* the first two cases are special - stupid chip design! */ |
| 482 | if (val > 27500) { |
| 483 | i = 10; |
| 484 | } else if (val > 22500) { |
| 485 | i = 11; |
| 486 | } else { |
| 487 | for (i = 9; i > 0; i--) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 488 | if (val > (PWM_FREQ[i] + PWM_FREQ[i - 1] + 1) / 2) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 489 | break; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
| 493 | return (reg & 0xf0) | i; |
| 494 | } |
| 495 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 496 | /* |
| 497 | * PWM ramp rate |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 498 | * Register layout: |
| 499 | * reg[0] = [OFF3, OFF2, OFF1, RES, RR1-E, RR1-2, RR1-1, RR1-0] |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 500 | * reg[1] = [RR2-E, RR2-2, RR2-1, RR2-0, RR3-E, RR3-2, RR3-1, RR3-0] |
| 501 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 502 | static const u8 PWM_RR[] = {206, 104, 69, 41, 26, 18, 10, 5}; |
| 503 | |
| 504 | static inline int PWM_RR_FROM_REG(int reg, int ix) |
| 505 | { |
| 506 | int rr = (ix == 1) ? reg >> 4 : reg; |
| 507 | |
| 508 | return (rr & 0x08) ? PWM_RR[rr & 0x07] : 0; |
| 509 | } |
| 510 | |
| 511 | static int PWM_RR_TO_REG(int val, int ix, int reg) |
| 512 | { |
| 513 | int i; |
| 514 | |
| 515 | for (i = 0; i < 7; i++) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 516 | if (val > (PWM_RR[i] + PWM_RR[i + 1] + 1) / 2) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 517 | break; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | return (ix == 1) ? (reg & 0x8f) | (i << 4) : (reg & 0xf8) | i; |
| 521 | } |
| 522 | |
| 523 | /* PWM ramp rate enable */ |
| 524 | static inline int PWM_RR_EN_FROM_REG(int reg, int ix) |
| 525 | { |
| 526 | return PWM_RR_FROM_REG(reg, ix) ? 1 : 0; |
| 527 | } |
| 528 | |
| 529 | static inline int PWM_RR_EN_TO_REG(int val, int ix, int reg) |
| 530 | { |
| 531 | int en = (ix == 1) ? 0x80 : 0x08; |
| 532 | |
| 533 | return val ? reg | en : reg & ~en; |
| 534 | } |
| 535 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 536 | /* |
| 537 | * PWM min/off |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 538 | * The PWM min/off bits are part of the PMW ramp rate register 0 (see above for |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 539 | * the register layout). |
| 540 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 541 | static inline int PWM_OFF_FROM_REG(int reg, int ix) |
| 542 | { |
| 543 | return (reg >> (ix + 5)) & 0x01; |
| 544 | } |
| 545 | |
| 546 | static inline int PWM_OFF_TO_REG(int val, int ix, int reg) |
| 547 | { |
| 548 | return (reg & ~(1 << (ix + 5))) | ((val & 0x01) << (ix + 5)); |
| 549 | } |
| 550 | |
| 551 | /* --------------------------------------------------------------------- |
| 552 | * Device I/O access |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 553 | * |
| 554 | * ISA access is performed through an index/data register pair and needs to |
| 555 | * be protected by a mutex during runtime (not required for initialization). |
| 556 | * We use data->update_lock for this and need to ensure that we acquire it |
| 557 | * before calling dme1737_read or dme1737_write. |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 558 | * --------------------------------------------------------------------- */ |
| 559 | |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 560 | static u8 dme1737_read(const struct dme1737_data *data, u8 reg) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 561 | { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 562 | struct i2c_client *client = data->client; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 563 | s32 val; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 564 | |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 565 | if (client) { /* I2C device */ |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 566 | val = i2c_smbus_read_byte_data(client, reg); |
| 567 | |
| 568 | if (val < 0) { |
| 569 | dev_warn(&client->dev, "Read from register " |
| 570 | "0x%02x failed! Please report to the driver " |
| 571 | "maintainer.\n", reg); |
| 572 | } |
| 573 | } else { /* ISA device */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 574 | outb(reg, data->addr); |
| 575 | val = inb(data->addr + 1); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | return val; |
| 579 | } |
| 580 | |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 581 | static s32 dme1737_write(const struct dme1737_data *data, u8 reg, u8 val) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 582 | { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 583 | struct i2c_client *client = data->client; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 584 | s32 res = 0; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 585 | |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 586 | if (client) { /* I2C device */ |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 587 | res = i2c_smbus_write_byte_data(client, reg, val); |
| 588 | |
| 589 | if (res < 0) { |
| 590 | dev_warn(&client->dev, "Write to register " |
| 591 | "0x%02x failed! Please report to the driver " |
| 592 | "maintainer.\n", reg); |
| 593 | } |
| 594 | } else { /* ISA device */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 595 | outb(reg, data->addr); |
| 596 | outb(val, data->addr + 1); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | return res; |
| 600 | } |
| 601 | |
| 602 | static struct dme1737_data *dme1737_update_device(struct device *dev) |
| 603 | { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 604 | struct dme1737_data *data = dev_get_drvdata(dev); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 605 | int ix; |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 606 | u8 lsb[6]; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 607 | |
| 608 | mutex_lock(&data->update_lock); |
| 609 | |
| 610 | /* Enable a Vbat monitoring cycle every 10 mins */ |
| 611 | if (time_after(jiffies, data->last_vbat + 600 * HZ) || !data->valid) { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 612 | dme1737_write(data, DME1737_REG_CONFIG, dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 613 | DME1737_REG_CONFIG) | 0x10); |
| 614 | data->last_vbat = jiffies; |
| 615 | } |
| 616 | |
| 617 | /* Sample register contents every 1 sec */ |
| 618 | if (time_after(jiffies, data->last_update + HZ) || !data->valid) { |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 619 | if (data->has_features & HAS_VID) { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 620 | data->vid = dme1737_read(data, DME1737_REG_VID) & |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 621 | 0x3f; |
| 622 | } |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 623 | |
| 624 | /* In (voltage) registers */ |
| 625 | for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 626 | /* |
| 627 | * Voltage inputs are stored as 16 bit values even |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 628 | * though they have only 12 bits resolution. This is |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 629 | * to make it consistent with the temp inputs. |
| 630 | */ |
| 631 | if (ix == 7 && !(data->has_features & HAS_IN7)) |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 632 | continue; |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 633 | data->in[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 634 | DME1737_REG_IN(ix)) << 8; |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 635 | data->in_min[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 636 | DME1737_REG_IN_MIN(ix)); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 637 | data->in_max[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 638 | DME1737_REG_IN_MAX(ix)); |
| 639 | } |
| 640 | |
| 641 | /* Temp registers */ |
| 642 | for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 643 | /* |
| 644 | * Temp inputs are stored as 16 bit values even |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 645 | * though they have only 12 bits resolution. This is |
| 646 | * to take advantage of implicit conversions between |
| 647 | * register values (2's complement) and temp values |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 648 | * (signed decimal). |
| 649 | */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 650 | data->temp[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 651 | DME1737_REG_TEMP(ix)) << 8; |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 652 | data->temp_min[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 653 | DME1737_REG_TEMP_MIN(ix)); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 654 | data->temp_max[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 655 | DME1737_REG_TEMP_MAX(ix)); |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 656 | if (data->has_features & HAS_TEMP_OFFSET) { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 657 | data->temp_offset[ix] = dme1737_read(data, |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 658 | DME1737_REG_TEMP_OFFSET(ix)); |
| 659 | } |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 660 | } |
| 661 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 662 | /* |
| 663 | * In and temp LSB registers |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 664 | * The LSBs are latched when the MSBs are read, so the order in |
| 665 | * which the registers are read (MSB first, then LSB) is |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 666 | * important! |
| 667 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 668 | for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 669 | if (ix == 5 && !(data->has_features & HAS_IN7)) |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 670 | continue; |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 671 | lsb[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 672 | DME1737_REG_IN_TEMP_LSB(ix)); |
| 673 | } |
| 674 | for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 675 | if (ix == 7 && !(data->has_features & HAS_IN7)) |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 676 | continue; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 677 | data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] << |
| 678 | DME1737_REG_IN_LSB_SHL[ix]) & 0xf0; |
| 679 | } |
| 680 | for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) { |
| 681 | data->temp[ix] |= (lsb[DME1737_REG_TEMP_LSB[ix]] << |
| 682 | DME1737_REG_TEMP_LSB_SHL[ix]) & 0xf0; |
| 683 | } |
| 684 | |
| 685 | /* Fan registers */ |
| 686 | for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 687 | /* |
| 688 | * Skip reading registers if optional fans are not |
| 689 | * present |
| 690 | */ |
| 691 | if (!(data->has_features & HAS_FAN(ix))) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 692 | continue; |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 693 | data->fan[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 694 | DME1737_REG_FAN(ix)); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 695 | data->fan[ix] |= dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 696 | DME1737_REG_FAN(ix) + 1) << 8; |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 697 | data->fan_min[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 698 | DME1737_REG_FAN_MIN(ix)); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 699 | data->fan_min[ix] |= dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 700 | DME1737_REG_FAN_MIN(ix) + 1) << 8; |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 701 | data->fan_opt[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 702 | DME1737_REG_FAN_OPT(ix)); |
| 703 | /* fan_max exists only for fan[5-6] */ |
| 704 | if (ix > 3) { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 705 | data->fan_max[ix - 4] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 706 | DME1737_REG_FAN_MAX(ix)); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | /* PWM registers */ |
| 711 | for (ix = 0; ix < ARRAY_SIZE(data->pwm); ix++) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 712 | /* |
| 713 | * Skip reading registers if optional PWMs are not |
| 714 | * present |
| 715 | */ |
| 716 | if (!(data->has_features & HAS_PWM(ix))) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 717 | continue; |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 718 | data->pwm[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 719 | DME1737_REG_PWM(ix)); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 720 | data->pwm_freq[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 721 | DME1737_REG_PWM_FREQ(ix)); |
| 722 | /* pwm_config and pwm_min exist only for pwm[1-3] */ |
| 723 | if (ix < 3) { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 724 | data->pwm_config[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 725 | DME1737_REG_PWM_CONFIG(ix)); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 726 | data->pwm_min[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 727 | DME1737_REG_PWM_MIN(ix)); |
| 728 | } |
| 729 | } |
| 730 | for (ix = 0; ix < ARRAY_SIZE(data->pwm_rr); ix++) { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 731 | data->pwm_rr[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 732 | DME1737_REG_PWM_RR(ix)); |
| 733 | } |
| 734 | |
| 735 | /* Thermal zone registers */ |
| 736 | for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 737 | /* Skip reading registers if zone3 is not present */ |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 738 | if ((ix == 2) && !(data->has_features & HAS_ZONE3)) |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 739 | continue; |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 740 | /* sch5127 zone2 registers are special */ |
| 741 | if ((ix == 1) && (data->type == sch5127)) { |
| 742 | data->zone_low[1] = dme1737_read(data, |
| 743 | DME1737_REG_ZONE_LOW(2)); |
| 744 | data->zone_abs[1] = dme1737_read(data, |
| 745 | DME1737_REG_ZONE_ABS(2)); |
| 746 | } else { |
| 747 | data->zone_low[ix] = dme1737_read(data, |
| 748 | DME1737_REG_ZONE_LOW(ix)); |
| 749 | data->zone_abs[ix] = dme1737_read(data, |
| 750 | DME1737_REG_ZONE_ABS(ix)); |
| 751 | } |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 752 | } |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 753 | if (data->has_features & HAS_ZONE_HYST) { |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 754 | for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 755 | data->zone_hyst[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 756 | DME1737_REG_ZONE_HYST(ix)); |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 757 | } |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /* Alarm registers */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 761 | data->alarms = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 762 | DME1737_REG_ALARM1); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 763 | /* |
| 764 | * Bit 7 tells us if the other alarm registers are non-zero and |
| 765 | * therefore also need to be read |
| 766 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 767 | if (data->alarms & 0x80) { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 768 | data->alarms |= dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 769 | DME1737_REG_ALARM2) << 8; |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 770 | data->alarms |= dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 771 | DME1737_REG_ALARM3) << 16; |
| 772 | } |
| 773 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 774 | /* |
| 775 | * The ISA chips require explicit clearing of alarm bits. |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 776 | * Don't worry, an alarm will come back if the condition |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 777 | * that causes it still exists |
| 778 | */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 779 | if (!data->client) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 780 | if (data->alarms & 0xff0000) |
| 781 | dme1737_write(data, DME1737_REG_ALARM3, 0xff); |
| 782 | if (data->alarms & 0xff00) |
| 783 | dme1737_write(data, DME1737_REG_ALARM2, 0xff); |
| 784 | if (data->alarms & 0xff) |
| 785 | dme1737_write(data, DME1737_REG_ALARM1, 0xff); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 788 | data->last_update = jiffies; |
| 789 | data->valid = 1; |
| 790 | } |
| 791 | |
| 792 | mutex_unlock(&data->update_lock); |
| 793 | |
| 794 | return data; |
| 795 | } |
| 796 | |
| 797 | /* --------------------------------------------------------------------- |
| 798 | * Voltage sysfs attributes |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 799 | * ix = [0-7] |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 800 | * --------------------------------------------------------------------- */ |
| 801 | |
| 802 | #define SYS_IN_INPUT 0 |
| 803 | #define SYS_IN_MIN 1 |
| 804 | #define SYS_IN_MAX 2 |
| 805 | #define SYS_IN_ALARM 3 |
| 806 | |
| 807 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
| 808 | char *buf) |
| 809 | { |
| 810 | struct dme1737_data *data = dme1737_update_device(dev); |
| 811 | struct sensor_device_attribute_2 |
| 812 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 813 | int ix = sensor_attr_2->index; |
| 814 | int fn = sensor_attr_2->nr; |
| 815 | int res; |
| 816 | |
| 817 | switch (fn) { |
| 818 | case SYS_IN_INPUT: |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 819 | res = IN_FROM_REG(data->in[ix], data->in_nominal[ix], 16); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 820 | break; |
| 821 | case SYS_IN_MIN: |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 822 | res = IN_FROM_REG(data->in_min[ix], data->in_nominal[ix], 8); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 823 | break; |
| 824 | case SYS_IN_MAX: |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 825 | res = IN_FROM_REG(data->in_max[ix], data->in_nominal[ix], 8); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 826 | break; |
| 827 | case SYS_IN_ALARM: |
| 828 | res = (data->alarms >> DME1737_BIT_ALARM_IN[ix]) & 0x01; |
| 829 | break; |
| 830 | default: |
| 831 | res = 0; |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 832 | dev_dbg(dev, "Unknown function %d.\n", fn); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | return sprintf(buf, "%d\n", res); |
| 836 | } |
| 837 | |
| 838 | static ssize_t set_in(struct device *dev, struct device_attribute *attr, |
| 839 | const char *buf, size_t count) |
| 840 | { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 841 | struct dme1737_data *data = dev_get_drvdata(dev); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 842 | struct sensor_device_attribute_2 |
| 843 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 844 | int ix = sensor_attr_2->index; |
| 845 | int fn = sensor_attr_2->nr; |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 846 | long val; |
| 847 | int err; |
| 848 | |
| 849 | err = kstrtol(buf, 10, &val); |
| 850 | if (err) |
| 851 | return err; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 852 | |
| 853 | mutex_lock(&data->update_lock); |
| 854 | switch (fn) { |
| 855 | case SYS_IN_MIN: |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 856 | data->in_min[ix] = IN_TO_REG(val, data->in_nominal[ix]); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 857 | dme1737_write(data, DME1737_REG_IN_MIN(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 858 | data->in_min[ix]); |
| 859 | break; |
| 860 | case SYS_IN_MAX: |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 861 | data->in_max[ix] = IN_TO_REG(val, data->in_nominal[ix]); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 862 | dme1737_write(data, DME1737_REG_IN_MAX(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 863 | data->in_max[ix]); |
| 864 | break; |
| 865 | default: |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 866 | dev_dbg(dev, "Unknown function %d.\n", fn); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 867 | } |
| 868 | mutex_unlock(&data->update_lock); |
| 869 | |
| 870 | return count; |
| 871 | } |
| 872 | |
| 873 | /* --------------------------------------------------------------------- |
| 874 | * Temperature sysfs attributes |
| 875 | * ix = [0-2] |
| 876 | * --------------------------------------------------------------------- */ |
| 877 | |
| 878 | #define SYS_TEMP_INPUT 0 |
| 879 | #define SYS_TEMP_MIN 1 |
| 880 | #define SYS_TEMP_MAX 2 |
| 881 | #define SYS_TEMP_OFFSET 3 |
| 882 | #define SYS_TEMP_ALARM 4 |
| 883 | #define SYS_TEMP_FAULT 5 |
| 884 | |
| 885 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
| 886 | char *buf) |
| 887 | { |
| 888 | struct dme1737_data *data = dme1737_update_device(dev); |
| 889 | struct sensor_device_attribute_2 |
| 890 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 891 | int ix = sensor_attr_2->index; |
| 892 | int fn = sensor_attr_2->nr; |
| 893 | int res; |
| 894 | |
| 895 | switch (fn) { |
| 896 | case SYS_TEMP_INPUT: |
| 897 | res = TEMP_FROM_REG(data->temp[ix], 16); |
| 898 | break; |
| 899 | case SYS_TEMP_MIN: |
| 900 | res = TEMP_FROM_REG(data->temp_min[ix], 8); |
| 901 | break; |
| 902 | case SYS_TEMP_MAX: |
| 903 | res = TEMP_FROM_REG(data->temp_max[ix], 8); |
| 904 | break; |
| 905 | case SYS_TEMP_OFFSET: |
| 906 | res = TEMP_FROM_REG(data->temp_offset[ix], 8); |
| 907 | break; |
| 908 | case SYS_TEMP_ALARM: |
| 909 | res = (data->alarms >> DME1737_BIT_ALARM_TEMP[ix]) & 0x01; |
| 910 | break; |
| 911 | case SYS_TEMP_FAULT: |
Juerg Haefliger | c0f3140 | 2007-07-20 14:16:47 -0700 | [diff] [blame] | 912 | res = (((u16)data->temp[ix] & 0xff00) == 0x8000); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 913 | break; |
| 914 | default: |
| 915 | res = 0; |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 916 | dev_dbg(dev, "Unknown function %d.\n", fn); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | return sprintf(buf, "%d\n", res); |
| 920 | } |
| 921 | |
| 922 | static ssize_t set_temp(struct device *dev, struct device_attribute *attr, |
| 923 | const char *buf, size_t count) |
| 924 | { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 925 | struct dme1737_data *data = dev_get_drvdata(dev); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 926 | struct sensor_device_attribute_2 |
| 927 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 928 | int ix = sensor_attr_2->index; |
| 929 | int fn = sensor_attr_2->nr; |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 930 | long val; |
| 931 | int err; |
| 932 | |
| 933 | err = kstrtol(buf, 10, &val); |
| 934 | if (err) |
| 935 | return err; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 936 | |
| 937 | mutex_lock(&data->update_lock); |
| 938 | switch (fn) { |
| 939 | case SYS_TEMP_MIN: |
| 940 | data->temp_min[ix] = TEMP_TO_REG(val); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 941 | dme1737_write(data, DME1737_REG_TEMP_MIN(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 942 | data->temp_min[ix]); |
| 943 | break; |
| 944 | case SYS_TEMP_MAX: |
| 945 | data->temp_max[ix] = TEMP_TO_REG(val); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 946 | dme1737_write(data, DME1737_REG_TEMP_MAX(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 947 | data->temp_max[ix]); |
| 948 | break; |
| 949 | case SYS_TEMP_OFFSET: |
| 950 | data->temp_offset[ix] = TEMP_TO_REG(val); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 951 | dme1737_write(data, DME1737_REG_TEMP_OFFSET(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 952 | data->temp_offset[ix]); |
| 953 | break; |
| 954 | default: |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 955 | dev_dbg(dev, "Unknown function %d.\n", fn); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 956 | } |
| 957 | mutex_unlock(&data->update_lock); |
| 958 | |
| 959 | return count; |
| 960 | } |
| 961 | |
| 962 | /* --------------------------------------------------------------------- |
| 963 | * Zone sysfs attributes |
| 964 | * ix = [0-2] |
| 965 | * --------------------------------------------------------------------- */ |
| 966 | |
| 967 | #define SYS_ZONE_AUTO_CHANNELS_TEMP 0 |
| 968 | #define SYS_ZONE_AUTO_POINT1_TEMP_HYST 1 |
| 969 | #define SYS_ZONE_AUTO_POINT1_TEMP 2 |
| 970 | #define SYS_ZONE_AUTO_POINT2_TEMP 3 |
| 971 | #define SYS_ZONE_AUTO_POINT3_TEMP 4 |
| 972 | |
| 973 | static ssize_t show_zone(struct device *dev, struct device_attribute *attr, |
| 974 | char *buf) |
| 975 | { |
| 976 | struct dme1737_data *data = dme1737_update_device(dev); |
| 977 | struct sensor_device_attribute_2 |
| 978 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 979 | int ix = sensor_attr_2->index; |
| 980 | int fn = sensor_attr_2->nr; |
| 981 | int res; |
| 982 | |
| 983 | switch (fn) { |
| 984 | case SYS_ZONE_AUTO_CHANNELS_TEMP: |
| 985 | /* check config2 for non-standard temp-to-zone mapping */ |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 986 | if ((ix == 1) && (data->config2 & 0x02)) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 987 | res = 4; |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 988 | else |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 989 | res = 1 << ix; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 990 | break; |
| 991 | case SYS_ZONE_AUTO_POINT1_TEMP_HYST: |
| 992 | res = TEMP_FROM_REG(data->zone_low[ix], 8) - |
| 993 | TEMP_HYST_FROM_REG(data->zone_hyst[ix == 2], ix); |
| 994 | break; |
| 995 | case SYS_ZONE_AUTO_POINT1_TEMP: |
| 996 | res = TEMP_FROM_REG(data->zone_low[ix], 8); |
| 997 | break; |
| 998 | case SYS_ZONE_AUTO_POINT2_TEMP: |
| 999 | /* pwm_freq holds the temp range bits in the upper nibble */ |
| 1000 | res = TEMP_FROM_REG(data->zone_low[ix], 8) + |
| 1001 | TEMP_RANGE_FROM_REG(data->pwm_freq[ix]); |
| 1002 | break; |
| 1003 | case SYS_ZONE_AUTO_POINT3_TEMP: |
| 1004 | res = TEMP_FROM_REG(data->zone_abs[ix], 8); |
| 1005 | break; |
| 1006 | default: |
| 1007 | res = 0; |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1008 | dev_dbg(dev, "Unknown function %d.\n", fn); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | return sprintf(buf, "%d\n", res); |
| 1012 | } |
| 1013 | |
| 1014 | static ssize_t set_zone(struct device *dev, struct device_attribute *attr, |
| 1015 | const char *buf, size_t count) |
| 1016 | { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1017 | struct dme1737_data *data = dev_get_drvdata(dev); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1018 | struct sensor_device_attribute_2 |
| 1019 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 1020 | int ix = sensor_attr_2->index; |
| 1021 | int fn = sensor_attr_2->nr; |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1022 | long val; |
| 1023 | int err; |
| 1024 | |
| 1025 | err = kstrtol(buf, 10, &val); |
| 1026 | if (err) |
| 1027 | return err; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1028 | |
| 1029 | mutex_lock(&data->update_lock); |
| 1030 | switch (fn) { |
| 1031 | case SYS_ZONE_AUTO_POINT1_TEMP_HYST: |
| 1032 | /* Refresh the cache */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1033 | data->zone_low[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1034 | DME1737_REG_ZONE_LOW(ix)); |
| 1035 | /* Modify the temp hyst value */ |
| 1036 | data->zone_hyst[ix == 2] = TEMP_HYST_TO_REG( |
| 1037 | TEMP_FROM_REG(data->zone_low[ix], 8) - |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1038 | val, ix, dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1039 | DME1737_REG_ZONE_HYST(ix == 2))); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1040 | dme1737_write(data, DME1737_REG_ZONE_HYST(ix == 2), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1041 | data->zone_hyst[ix == 2]); |
| 1042 | break; |
| 1043 | case SYS_ZONE_AUTO_POINT1_TEMP: |
| 1044 | data->zone_low[ix] = TEMP_TO_REG(val); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1045 | dme1737_write(data, DME1737_REG_ZONE_LOW(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1046 | data->zone_low[ix]); |
| 1047 | break; |
| 1048 | case SYS_ZONE_AUTO_POINT2_TEMP: |
| 1049 | /* Refresh the cache */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1050 | data->zone_low[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1051 | DME1737_REG_ZONE_LOW(ix)); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1052 | /* |
| 1053 | * Modify the temp range value (which is stored in the upper |
| 1054 | * nibble of the pwm_freq register) |
| 1055 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1056 | data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val - |
| 1057 | TEMP_FROM_REG(data->zone_low[ix], 8), |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1058 | dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1059 | DME1737_REG_PWM_FREQ(ix))); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1060 | dme1737_write(data, DME1737_REG_PWM_FREQ(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1061 | data->pwm_freq[ix]); |
| 1062 | break; |
| 1063 | case SYS_ZONE_AUTO_POINT3_TEMP: |
| 1064 | data->zone_abs[ix] = TEMP_TO_REG(val); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1065 | dme1737_write(data, DME1737_REG_ZONE_ABS(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1066 | data->zone_abs[ix]); |
| 1067 | break; |
| 1068 | default: |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1069 | dev_dbg(dev, "Unknown function %d.\n", fn); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1070 | } |
| 1071 | mutex_unlock(&data->update_lock); |
| 1072 | |
| 1073 | return count; |
| 1074 | } |
| 1075 | |
| 1076 | /* --------------------------------------------------------------------- |
| 1077 | * Fan sysfs attributes |
| 1078 | * ix = [0-5] |
| 1079 | * --------------------------------------------------------------------- */ |
| 1080 | |
| 1081 | #define SYS_FAN_INPUT 0 |
| 1082 | #define SYS_FAN_MIN 1 |
| 1083 | #define SYS_FAN_MAX 2 |
| 1084 | #define SYS_FAN_ALARM 3 |
| 1085 | #define SYS_FAN_TYPE 4 |
| 1086 | |
| 1087 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
| 1088 | char *buf) |
| 1089 | { |
| 1090 | struct dme1737_data *data = dme1737_update_device(dev); |
| 1091 | struct sensor_device_attribute_2 |
| 1092 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 1093 | int ix = sensor_attr_2->index; |
| 1094 | int fn = sensor_attr_2->nr; |
| 1095 | int res; |
| 1096 | |
| 1097 | switch (fn) { |
| 1098 | case SYS_FAN_INPUT: |
| 1099 | res = FAN_FROM_REG(data->fan[ix], |
| 1100 | ix < 4 ? 0 : |
| 1101 | FAN_TPC_FROM_REG(data->fan_opt[ix])); |
| 1102 | break; |
| 1103 | case SYS_FAN_MIN: |
| 1104 | res = FAN_FROM_REG(data->fan_min[ix], |
| 1105 | ix < 4 ? 0 : |
| 1106 | FAN_TPC_FROM_REG(data->fan_opt[ix])); |
| 1107 | break; |
| 1108 | case SYS_FAN_MAX: |
| 1109 | /* only valid for fan[5-6] */ |
| 1110 | res = FAN_MAX_FROM_REG(data->fan_max[ix - 4]); |
| 1111 | break; |
| 1112 | case SYS_FAN_ALARM: |
| 1113 | res = (data->alarms >> DME1737_BIT_ALARM_FAN[ix]) & 0x01; |
| 1114 | break; |
| 1115 | case SYS_FAN_TYPE: |
| 1116 | /* only valid for fan[1-4] */ |
| 1117 | res = FAN_TYPE_FROM_REG(data->fan_opt[ix]); |
| 1118 | break; |
| 1119 | default: |
| 1120 | res = 0; |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1121 | dev_dbg(dev, "Unknown function %d.\n", fn); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | return sprintf(buf, "%d\n", res); |
| 1125 | } |
| 1126 | |
| 1127 | static ssize_t set_fan(struct device *dev, struct device_attribute *attr, |
| 1128 | const char *buf, size_t count) |
| 1129 | { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1130 | struct dme1737_data *data = dev_get_drvdata(dev); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1131 | struct sensor_device_attribute_2 |
| 1132 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 1133 | int ix = sensor_attr_2->index; |
| 1134 | int fn = sensor_attr_2->nr; |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1135 | long val; |
| 1136 | int err; |
| 1137 | |
| 1138 | err = kstrtol(buf, 10, &val); |
| 1139 | if (err) |
| 1140 | return err; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1141 | |
| 1142 | mutex_lock(&data->update_lock); |
| 1143 | switch (fn) { |
| 1144 | case SYS_FAN_MIN: |
| 1145 | if (ix < 4) { |
| 1146 | data->fan_min[ix] = FAN_TO_REG(val, 0); |
| 1147 | } else { |
| 1148 | /* Refresh the cache */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1149 | data->fan_opt[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1150 | DME1737_REG_FAN_OPT(ix)); |
| 1151 | /* Modify the fan min value */ |
| 1152 | data->fan_min[ix] = FAN_TO_REG(val, |
| 1153 | FAN_TPC_FROM_REG(data->fan_opt[ix])); |
| 1154 | } |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1155 | dme1737_write(data, DME1737_REG_FAN_MIN(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1156 | data->fan_min[ix] & 0xff); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1157 | dme1737_write(data, DME1737_REG_FAN_MIN(ix) + 1, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1158 | data->fan_min[ix] >> 8); |
| 1159 | break; |
| 1160 | case SYS_FAN_MAX: |
| 1161 | /* Only valid for fan[5-6] */ |
| 1162 | data->fan_max[ix - 4] = FAN_MAX_TO_REG(val); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1163 | dme1737_write(data, DME1737_REG_FAN_MAX(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1164 | data->fan_max[ix - 4]); |
| 1165 | break; |
| 1166 | case SYS_FAN_TYPE: |
| 1167 | /* Only valid for fan[1-4] */ |
| 1168 | if (!(val == 1 || val == 2 || val == 4)) { |
| 1169 | count = -EINVAL; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 1170 | dev_warn(dev, "Fan type value %ld not " |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1171 | "supported. Choose one of 1, 2, or 4.\n", |
| 1172 | val); |
| 1173 | goto exit; |
| 1174 | } |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1175 | data->fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1176 | DME1737_REG_FAN_OPT(ix))); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1177 | dme1737_write(data, DME1737_REG_FAN_OPT(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1178 | data->fan_opt[ix]); |
| 1179 | break; |
| 1180 | default: |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1181 | dev_dbg(dev, "Unknown function %d.\n", fn); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1182 | } |
| 1183 | exit: |
| 1184 | mutex_unlock(&data->update_lock); |
| 1185 | |
| 1186 | return count; |
| 1187 | } |
| 1188 | |
| 1189 | /* --------------------------------------------------------------------- |
| 1190 | * PWM sysfs attributes |
| 1191 | * ix = [0-4] |
| 1192 | * --------------------------------------------------------------------- */ |
| 1193 | |
| 1194 | #define SYS_PWM 0 |
| 1195 | #define SYS_PWM_FREQ 1 |
| 1196 | #define SYS_PWM_ENABLE 2 |
| 1197 | #define SYS_PWM_RAMP_RATE 3 |
| 1198 | #define SYS_PWM_AUTO_CHANNELS_ZONE 4 |
| 1199 | #define SYS_PWM_AUTO_PWM_MIN 5 |
| 1200 | #define SYS_PWM_AUTO_POINT1_PWM 6 |
| 1201 | #define SYS_PWM_AUTO_POINT2_PWM 7 |
| 1202 | |
| 1203 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, |
| 1204 | char *buf) |
| 1205 | { |
| 1206 | struct dme1737_data *data = dme1737_update_device(dev); |
| 1207 | struct sensor_device_attribute_2 |
| 1208 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 1209 | int ix = sensor_attr_2->index; |
| 1210 | int fn = sensor_attr_2->nr; |
| 1211 | int res; |
| 1212 | |
| 1213 | switch (fn) { |
| 1214 | case SYS_PWM: |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1215 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 0) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1216 | res = 255; |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1217 | else |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1218 | res = data->pwm[ix]; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1219 | break; |
| 1220 | case SYS_PWM_FREQ: |
| 1221 | res = PWM_FREQ_FROM_REG(data->pwm_freq[ix]); |
| 1222 | break; |
| 1223 | case SYS_PWM_ENABLE: |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1224 | if (ix >= 3) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1225 | res = 1; /* pwm[5-6] hard-wired to manual mode */ |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1226 | else |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1227 | res = PWM_EN_FROM_REG(data->pwm_config[ix]); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1228 | break; |
| 1229 | case SYS_PWM_RAMP_RATE: |
| 1230 | /* Only valid for pwm[1-3] */ |
| 1231 | res = PWM_RR_FROM_REG(data->pwm_rr[ix > 0], ix); |
| 1232 | break; |
| 1233 | case SYS_PWM_AUTO_CHANNELS_ZONE: |
| 1234 | /* Only valid for pwm[1-3] */ |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1235 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1236 | res = PWM_ACZ_FROM_REG(data->pwm_config[ix]); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1237 | else |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1238 | res = data->pwm_acz[ix]; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1239 | break; |
| 1240 | case SYS_PWM_AUTO_PWM_MIN: |
| 1241 | /* Only valid for pwm[1-3] */ |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1242 | if (PWM_OFF_FROM_REG(data->pwm_rr[0], ix)) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1243 | res = data->pwm_min[ix]; |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1244 | else |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1245 | res = 0; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1246 | break; |
| 1247 | case SYS_PWM_AUTO_POINT1_PWM: |
| 1248 | /* Only valid for pwm[1-3] */ |
| 1249 | res = data->pwm_min[ix]; |
| 1250 | break; |
| 1251 | case SYS_PWM_AUTO_POINT2_PWM: |
| 1252 | /* Only valid for pwm[1-3] */ |
| 1253 | res = 255; /* hard-wired */ |
| 1254 | break; |
| 1255 | default: |
| 1256 | res = 0; |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1257 | dev_dbg(dev, "Unknown function %d.\n", fn); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | return sprintf(buf, "%d\n", res); |
| 1261 | } |
| 1262 | |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1263 | static struct attribute *dme1737_pwm_chmod_attr[]; |
Al Viro | 48176a9 | 2011-07-24 03:40:40 -0400 | [diff] [blame] | 1264 | static void dme1737_chmod_file(struct device*, struct attribute*, umode_t); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1265 | |
| 1266 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
| 1267 | const char *buf, size_t count) |
| 1268 | { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1269 | struct dme1737_data *data = dev_get_drvdata(dev); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1270 | struct sensor_device_attribute_2 |
| 1271 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 1272 | int ix = sensor_attr_2->index; |
| 1273 | int fn = sensor_attr_2->nr; |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1274 | long val; |
| 1275 | int err; |
| 1276 | |
| 1277 | err = kstrtol(buf, 10, &val); |
| 1278 | if (err) |
| 1279 | return err; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1280 | |
| 1281 | mutex_lock(&data->update_lock); |
| 1282 | switch (fn) { |
| 1283 | case SYS_PWM: |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame^] | 1284 | data->pwm[ix] = clamp_val(val, 0, 255); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1285 | dme1737_write(data, DME1737_REG_PWM(ix), data->pwm[ix]); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1286 | break; |
| 1287 | case SYS_PWM_FREQ: |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1288 | data->pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1289 | DME1737_REG_PWM_FREQ(ix))); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1290 | dme1737_write(data, DME1737_REG_PWM_FREQ(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1291 | data->pwm_freq[ix]); |
| 1292 | break; |
| 1293 | case SYS_PWM_ENABLE: |
| 1294 | /* Only valid for pwm[1-3] */ |
| 1295 | if (val < 0 || val > 2) { |
| 1296 | count = -EINVAL; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 1297 | dev_warn(dev, "PWM enable %ld not " |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1298 | "supported. Choose one of 0, 1, or 2.\n", |
| 1299 | val); |
| 1300 | goto exit; |
| 1301 | } |
| 1302 | /* Refresh the cache */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1303 | data->pwm_config[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1304 | DME1737_REG_PWM_CONFIG(ix)); |
| 1305 | if (val == PWM_EN_FROM_REG(data->pwm_config[ix])) { |
| 1306 | /* Bail out if no change */ |
| 1307 | goto exit; |
| 1308 | } |
| 1309 | /* Do some housekeeping if we are currently in auto mode */ |
| 1310 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { |
| 1311 | /* Save the current zone channel assignment */ |
| 1312 | data->pwm_acz[ix] = PWM_ACZ_FROM_REG( |
| 1313 | data->pwm_config[ix]); |
| 1314 | /* Save the current ramp rate state and disable it */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1315 | data->pwm_rr[ix > 0] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1316 | DME1737_REG_PWM_RR(ix > 0)); |
| 1317 | data->pwm_rr_en &= ~(1 << ix); |
| 1318 | if (PWM_RR_EN_FROM_REG(data->pwm_rr[ix > 0], ix)) { |
| 1319 | data->pwm_rr_en |= (1 << ix); |
| 1320 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix, |
| 1321 | data->pwm_rr[ix > 0]); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1322 | dme1737_write(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1323 | DME1737_REG_PWM_RR(ix > 0), |
| 1324 | data->pwm_rr[ix > 0]); |
| 1325 | } |
| 1326 | } |
| 1327 | /* Set the new PWM mode */ |
| 1328 | switch (val) { |
| 1329 | case 0: |
| 1330 | /* Change permissions of pwm[ix] to read-only */ |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1331 | dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix], |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1332 | S_IRUGO); |
| 1333 | /* Turn fan fully on */ |
| 1334 | data->pwm_config[ix] = PWM_EN_TO_REG(0, |
| 1335 | data->pwm_config[ix]); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1336 | dme1737_write(data, DME1737_REG_PWM_CONFIG(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1337 | data->pwm_config[ix]); |
| 1338 | break; |
| 1339 | case 1: |
| 1340 | /* Turn on manual mode */ |
| 1341 | data->pwm_config[ix] = PWM_EN_TO_REG(1, |
| 1342 | data->pwm_config[ix]); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1343 | dme1737_write(data, DME1737_REG_PWM_CONFIG(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1344 | data->pwm_config[ix]); |
| 1345 | /* Change permissions of pwm[ix] to read-writeable */ |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1346 | dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix], |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1347 | S_IRUGO | S_IWUSR); |
| 1348 | break; |
| 1349 | case 2: |
| 1350 | /* Change permissions of pwm[ix] to read-only */ |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1351 | dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix], |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1352 | S_IRUGO); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1353 | /* |
| 1354 | * Turn on auto mode using the saved zone channel |
| 1355 | * assignment |
| 1356 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1357 | data->pwm_config[ix] = PWM_ACZ_TO_REG( |
| 1358 | data->pwm_acz[ix], |
| 1359 | data->pwm_config[ix]); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1360 | dme1737_write(data, DME1737_REG_PWM_CONFIG(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1361 | data->pwm_config[ix]); |
| 1362 | /* Enable PWM ramp rate if previously enabled */ |
| 1363 | if (data->pwm_rr_en & (1 << ix)) { |
| 1364 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix, |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1365 | dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1366 | DME1737_REG_PWM_RR(ix > 0))); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1367 | dme1737_write(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1368 | DME1737_REG_PWM_RR(ix > 0), |
| 1369 | data->pwm_rr[ix > 0]); |
| 1370 | } |
| 1371 | break; |
| 1372 | } |
| 1373 | break; |
| 1374 | case SYS_PWM_RAMP_RATE: |
| 1375 | /* Only valid for pwm[1-3] */ |
| 1376 | /* Refresh the cache */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1377 | data->pwm_config[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1378 | DME1737_REG_PWM_CONFIG(ix)); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1379 | data->pwm_rr[ix > 0] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1380 | DME1737_REG_PWM_RR(ix > 0)); |
| 1381 | /* Set the ramp rate value */ |
| 1382 | if (val > 0) { |
| 1383 | data->pwm_rr[ix > 0] = PWM_RR_TO_REG(val, ix, |
| 1384 | data->pwm_rr[ix > 0]); |
| 1385 | } |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1386 | /* |
| 1387 | * Enable/disable the feature only if the associated PWM |
| 1388 | * output is in automatic mode. |
| 1389 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1390 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { |
| 1391 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix, |
| 1392 | data->pwm_rr[ix > 0]); |
| 1393 | } |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1394 | dme1737_write(data, DME1737_REG_PWM_RR(ix > 0), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1395 | data->pwm_rr[ix > 0]); |
| 1396 | break; |
| 1397 | case SYS_PWM_AUTO_CHANNELS_ZONE: |
| 1398 | /* Only valid for pwm[1-3] */ |
| 1399 | if (!(val == 1 || val == 2 || val == 4 || |
| 1400 | val == 6 || val == 7)) { |
| 1401 | count = -EINVAL; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 1402 | dev_warn(dev, "PWM auto channels zone %ld " |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1403 | "not supported. Choose one of 1, 2, 4, 6, " |
| 1404 | "or 7.\n", val); |
| 1405 | goto exit; |
| 1406 | } |
| 1407 | /* Refresh the cache */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1408 | data->pwm_config[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1409 | DME1737_REG_PWM_CONFIG(ix)); |
| 1410 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1411 | /* |
| 1412 | * PWM is already in auto mode so update the temp |
| 1413 | * channel assignment |
| 1414 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1415 | data->pwm_config[ix] = PWM_ACZ_TO_REG(val, |
| 1416 | data->pwm_config[ix]); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1417 | dme1737_write(data, DME1737_REG_PWM_CONFIG(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1418 | data->pwm_config[ix]); |
| 1419 | } else { |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1420 | /* |
| 1421 | * PWM is not in auto mode so we save the temp |
| 1422 | * channel assignment for later use |
| 1423 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1424 | data->pwm_acz[ix] = val; |
| 1425 | } |
| 1426 | break; |
| 1427 | case SYS_PWM_AUTO_PWM_MIN: |
| 1428 | /* Only valid for pwm[1-3] */ |
| 1429 | /* Refresh the cache */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1430 | data->pwm_min[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1431 | DME1737_REG_PWM_MIN(ix)); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1432 | /* |
| 1433 | * There are only 2 values supported for the auto_pwm_min |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1434 | * value: 0 or auto_point1_pwm. So if the temperature drops |
| 1435 | * below the auto_point1_temp_hyst value, the fan either turns |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1436 | * off or runs at auto_point1_pwm duty-cycle. |
| 1437 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1438 | if (val > ((data->pwm_min[ix] + 1) / 2)) { |
| 1439 | data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1440 | dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1441 | DME1737_REG_PWM_RR(0))); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1442 | } else { |
| 1443 | data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1444 | dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1445 | DME1737_REG_PWM_RR(0))); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1446 | } |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1447 | dme1737_write(data, DME1737_REG_PWM_RR(0), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1448 | data->pwm_rr[0]); |
| 1449 | break; |
| 1450 | case SYS_PWM_AUTO_POINT1_PWM: |
| 1451 | /* Only valid for pwm[1-3] */ |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame^] | 1452 | data->pwm_min[ix] = clamp_val(val, 0, 255); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1453 | dme1737_write(data, DME1737_REG_PWM_MIN(ix), |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1454 | data->pwm_min[ix]); |
| 1455 | break; |
| 1456 | default: |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1457 | dev_dbg(dev, "Unknown function %d.\n", fn); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1458 | } |
| 1459 | exit: |
| 1460 | mutex_unlock(&data->update_lock); |
| 1461 | |
| 1462 | return count; |
| 1463 | } |
| 1464 | |
| 1465 | /* --------------------------------------------------------------------- |
| 1466 | * Miscellaneous sysfs attributes |
| 1467 | * --------------------------------------------------------------------- */ |
| 1468 | |
| 1469 | static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, |
| 1470 | char *buf) |
| 1471 | { |
| 1472 | struct i2c_client *client = to_i2c_client(dev); |
| 1473 | struct dme1737_data *data = i2c_get_clientdata(client); |
| 1474 | |
| 1475 | return sprintf(buf, "%d\n", data->vrm); |
| 1476 | } |
| 1477 | |
| 1478 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, |
| 1479 | const char *buf, size_t count) |
| 1480 | { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1481 | struct dme1737_data *data = dev_get_drvdata(dev); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1482 | long val; |
| 1483 | int err; |
| 1484 | |
| 1485 | err = kstrtol(buf, 10, &val); |
| 1486 | if (err) |
| 1487 | return err; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1488 | |
| 1489 | data->vrm = val; |
| 1490 | return count; |
| 1491 | } |
| 1492 | |
| 1493 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, |
| 1494 | char *buf) |
| 1495 | { |
| 1496 | struct dme1737_data *data = dme1737_update_device(dev); |
| 1497 | |
| 1498 | return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); |
| 1499 | } |
| 1500 | |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 1501 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, |
| 1502 | char *buf) |
| 1503 | { |
| 1504 | struct dme1737_data *data = dev_get_drvdata(dev); |
| 1505 | |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 1506 | return sprintf(buf, "%s\n", data->name); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1509 | /* --------------------------------------------------------------------- |
| 1510 | * Sysfs device attribute defines and structs |
| 1511 | * --------------------------------------------------------------------- */ |
| 1512 | |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 1513 | /* Voltages 0-7 */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1514 | |
| 1515 | #define SENSOR_DEVICE_ATTR_IN(ix) \ |
| 1516 | static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1517 | show_in, NULL, SYS_IN_INPUT, ix); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1518 | static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1519 | show_in, set_in, SYS_IN_MIN, ix); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1520 | static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1521 | show_in, set_in, SYS_IN_MAX, ix); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1522 | static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1523 | show_in, NULL, SYS_IN_ALARM, ix) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1524 | |
| 1525 | SENSOR_DEVICE_ATTR_IN(0); |
| 1526 | SENSOR_DEVICE_ATTR_IN(1); |
| 1527 | SENSOR_DEVICE_ATTR_IN(2); |
| 1528 | SENSOR_DEVICE_ATTR_IN(3); |
| 1529 | SENSOR_DEVICE_ATTR_IN(4); |
| 1530 | SENSOR_DEVICE_ATTR_IN(5); |
| 1531 | SENSOR_DEVICE_ATTR_IN(6); |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 1532 | SENSOR_DEVICE_ATTR_IN(7); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1533 | |
| 1534 | /* Temperatures 1-3 */ |
| 1535 | |
| 1536 | #define SENSOR_DEVICE_ATTR_TEMP(ix) \ |
| 1537 | static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1538 | show_temp, NULL, SYS_TEMP_INPUT, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1539 | static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1540 | show_temp, set_temp, SYS_TEMP_MIN, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1541 | static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1542 | show_temp, set_temp, SYS_TEMP_MAX, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1543 | static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1544 | show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1545 | static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1546 | show_temp, NULL, SYS_TEMP_ALARM, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1547 | static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1548 | show_temp, NULL, SYS_TEMP_FAULT, ix-1) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1549 | |
| 1550 | SENSOR_DEVICE_ATTR_TEMP(1); |
| 1551 | SENSOR_DEVICE_ATTR_TEMP(2); |
| 1552 | SENSOR_DEVICE_ATTR_TEMP(3); |
| 1553 | |
| 1554 | /* Zones 1-3 */ |
| 1555 | |
| 1556 | #define SENSOR_DEVICE_ATTR_ZONE(ix) \ |
| 1557 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1558 | show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1559 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1560 | show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1561 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1562 | show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1563 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1564 | show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1565 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1566 | show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1567 | |
| 1568 | SENSOR_DEVICE_ATTR_ZONE(1); |
| 1569 | SENSOR_DEVICE_ATTR_ZONE(2); |
| 1570 | SENSOR_DEVICE_ATTR_ZONE(3); |
| 1571 | |
| 1572 | /* Fans 1-4 */ |
| 1573 | |
| 1574 | #define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \ |
| 1575 | static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1576 | show_fan, NULL, SYS_FAN_INPUT, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1577 | static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1578 | show_fan, set_fan, SYS_FAN_MIN, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1579 | static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1580 | show_fan, NULL, SYS_FAN_ALARM, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1581 | static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1582 | show_fan, set_fan, SYS_FAN_TYPE, ix-1) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1583 | |
| 1584 | SENSOR_DEVICE_ATTR_FAN_1TO4(1); |
| 1585 | SENSOR_DEVICE_ATTR_FAN_1TO4(2); |
| 1586 | SENSOR_DEVICE_ATTR_FAN_1TO4(3); |
| 1587 | SENSOR_DEVICE_ATTR_FAN_1TO4(4); |
| 1588 | |
| 1589 | /* Fans 5-6 */ |
| 1590 | |
| 1591 | #define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \ |
| 1592 | static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1593 | show_fan, NULL, SYS_FAN_INPUT, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1594 | static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1595 | show_fan, set_fan, SYS_FAN_MIN, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1596 | static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1597 | show_fan, NULL, SYS_FAN_ALARM, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1598 | static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1599 | show_fan, set_fan, SYS_FAN_MAX, ix-1) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1600 | |
| 1601 | SENSOR_DEVICE_ATTR_FAN_5TO6(5); |
| 1602 | SENSOR_DEVICE_ATTR_FAN_5TO6(6); |
| 1603 | |
| 1604 | /* PWMs 1-3 */ |
| 1605 | |
| 1606 | #define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \ |
| 1607 | static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1608 | show_pwm, set_pwm, SYS_PWM, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1609 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1610 | show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1611 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1612 | show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1613 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1614 | show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1615 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1616 | show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1617 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1618 | show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1619 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1620 | show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1621 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1622 | show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1623 | |
| 1624 | SENSOR_DEVICE_ATTR_PWM_1TO3(1); |
| 1625 | SENSOR_DEVICE_ATTR_PWM_1TO3(2); |
| 1626 | SENSOR_DEVICE_ATTR_PWM_1TO3(3); |
| 1627 | |
| 1628 | /* PWMs 5-6 */ |
| 1629 | |
| 1630 | #define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \ |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1631 | static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1632 | show_pwm, set_pwm, SYS_PWM, ix-1); \ |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1633 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1634 | show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1635 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1636 | show_pwm, NULL, SYS_PWM_ENABLE, ix-1) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1637 | |
| 1638 | SENSOR_DEVICE_ATTR_PWM_5TO6(5); |
| 1639 | SENSOR_DEVICE_ATTR_PWM_5TO6(6); |
| 1640 | |
| 1641 | /* Misc */ |
| 1642 | |
| 1643 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); |
| 1644 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 1645 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); /* for ISA devices */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1646 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1647 | /* |
| 1648 | * This struct holds all the attributes that are always present and need to be |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1649 | * created unconditionally. The attributes that need modification of their |
| 1650 | * permissions are created read-only and write permissions are added or removed |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1651 | * on the fly when required |
| 1652 | */ |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 1653 | static struct attribute *dme1737_attr[] = { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1654 | /* Voltages */ |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1655 | &sensor_dev_attr_in0_input.dev_attr.attr, |
| 1656 | &sensor_dev_attr_in0_min.dev_attr.attr, |
| 1657 | &sensor_dev_attr_in0_max.dev_attr.attr, |
| 1658 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
| 1659 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 1660 | &sensor_dev_attr_in1_min.dev_attr.attr, |
| 1661 | &sensor_dev_attr_in1_max.dev_attr.attr, |
| 1662 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
| 1663 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 1664 | &sensor_dev_attr_in2_min.dev_attr.attr, |
| 1665 | &sensor_dev_attr_in2_max.dev_attr.attr, |
| 1666 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
| 1667 | &sensor_dev_attr_in3_input.dev_attr.attr, |
| 1668 | &sensor_dev_attr_in3_min.dev_attr.attr, |
| 1669 | &sensor_dev_attr_in3_max.dev_attr.attr, |
| 1670 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
| 1671 | &sensor_dev_attr_in4_input.dev_attr.attr, |
| 1672 | &sensor_dev_attr_in4_min.dev_attr.attr, |
| 1673 | &sensor_dev_attr_in4_max.dev_attr.attr, |
| 1674 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
| 1675 | &sensor_dev_attr_in5_input.dev_attr.attr, |
| 1676 | &sensor_dev_attr_in5_min.dev_attr.attr, |
| 1677 | &sensor_dev_attr_in5_max.dev_attr.attr, |
| 1678 | &sensor_dev_attr_in5_alarm.dev_attr.attr, |
| 1679 | &sensor_dev_attr_in6_input.dev_attr.attr, |
| 1680 | &sensor_dev_attr_in6_min.dev_attr.attr, |
| 1681 | &sensor_dev_attr_in6_max.dev_attr.attr, |
| 1682 | &sensor_dev_attr_in6_alarm.dev_attr.attr, |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1683 | /* Temperatures */ |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1684 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 1685 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
| 1686 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 1687 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
| 1688 | &sensor_dev_attr_temp1_fault.dev_attr.attr, |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1689 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 1690 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 1691 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 1692 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
| 1693 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1694 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
| 1695 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
| 1696 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
| 1697 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
| 1698 | &sensor_dev_attr_temp3_fault.dev_attr.attr, |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 1699 | /* Zones */ |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1700 | &sensor_dev_attr_zone1_auto_point1_temp.dev_attr.attr, |
| 1701 | &sensor_dev_attr_zone1_auto_point2_temp.dev_attr.attr, |
| 1702 | &sensor_dev_attr_zone1_auto_point3_temp.dev_attr.attr, |
| 1703 | &sensor_dev_attr_zone1_auto_channels_temp.dev_attr.attr, |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1704 | &sensor_dev_attr_zone2_auto_point1_temp.dev_attr.attr, |
| 1705 | &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr, |
| 1706 | &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr, |
| 1707 | &sensor_dev_attr_zone2_auto_channels_temp.dev_attr.attr, |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1708 | NULL |
| 1709 | }; |
| 1710 | |
| 1711 | static const struct attribute_group dme1737_group = { |
| 1712 | .attrs = dme1737_attr, |
| 1713 | }; |
| 1714 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1715 | /* |
| 1716 | * The following struct holds temp offset attributes, which are not available |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1717 | * in all chips. The following chips support them: |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1718 | * DME1737, SCH311x |
| 1719 | */ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1720 | static struct attribute *dme1737_temp_offset_attr[] = { |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1721 | &sensor_dev_attr_temp1_offset.dev_attr.attr, |
| 1722 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
| 1723 | &sensor_dev_attr_temp3_offset.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1724 | NULL |
| 1725 | }; |
| 1726 | |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1727 | static const struct attribute_group dme1737_temp_offset_group = { |
| 1728 | .attrs = dme1737_temp_offset_attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1729 | }; |
| 1730 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1731 | /* |
| 1732 | * The following struct holds VID related attributes, which are not available |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1733 | * in all chips. The following chips support them: |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1734 | * DME1737 |
| 1735 | */ |
Jean Delvare | 9d09144 | 2009-10-24 13:28:46 +0200 | [diff] [blame] | 1736 | static struct attribute *dme1737_vid_attr[] = { |
| 1737 | &dev_attr_vrm.attr, |
| 1738 | &dev_attr_cpu0_vid.attr, |
| 1739 | NULL |
| 1740 | }; |
| 1741 | |
| 1742 | static const struct attribute_group dme1737_vid_group = { |
| 1743 | .attrs = dme1737_vid_attr, |
| 1744 | }; |
| 1745 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1746 | /* |
| 1747 | * The following struct holds temp zone 3 related attributes, which are not |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1748 | * available in all chips. The following chips support them: |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1749 | * DME1737, SCH311x, SCH5027 |
| 1750 | */ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1751 | static struct attribute *dme1737_zone3_attr[] = { |
| 1752 | &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr, |
| 1753 | &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr, |
| 1754 | &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr, |
| 1755 | &sensor_dev_attr_zone3_auto_channels_temp.dev_attr.attr, |
| 1756 | NULL |
| 1757 | }; |
| 1758 | |
| 1759 | static const struct attribute_group dme1737_zone3_group = { |
| 1760 | .attrs = dme1737_zone3_attr, |
| 1761 | }; |
| 1762 | |
| 1763 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1764 | /* |
| 1765 | * The following struct holds temp zone hysteresis related attributes, which |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1766 | * are not available in all chips. The following chips support them: |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1767 | * DME1737, SCH311x |
| 1768 | */ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1769 | static struct attribute *dme1737_zone_hyst_attr[] = { |
| 1770 | &sensor_dev_attr_zone1_auto_point1_temp_hyst.dev_attr.attr, |
| 1771 | &sensor_dev_attr_zone2_auto_point1_temp_hyst.dev_attr.attr, |
| 1772 | &sensor_dev_attr_zone3_auto_point1_temp_hyst.dev_attr.attr, |
| 1773 | NULL |
| 1774 | }; |
| 1775 | |
| 1776 | static const struct attribute_group dme1737_zone_hyst_group = { |
| 1777 | .attrs = dme1737_zone_hyst_attr, |
| 1778 | }; |
| 1779 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1780 | /* |
| 1781 | * The following struct holds voltage in7 related attributes, which |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 1782 | * are not available in all chips. The following chips support them: |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1783 | * SCH5127 |
| 1784 | */ |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 1785 | static struct attribute *dme1737_in7_attr[] = { |
| 1786 | &sensor_dev_attr_in7_input.dev_attr.attr, |
| 1787 | &sensor_dev_attr_in7_min.dev_attr.attr, |
| 1788 | &sensor_dev_attr_in7_max.dev_attr.attr, |
| 1789 | &sensor_dev_attr_in7_alarm.dev_attr.attr, |
| 1790 | NULL |
| 1791 | }; |
| 1792 | |
| 1793 | static const struct attribute_group dme1737_in7_group = { |
| 1794 | .attrs = dme1737_in7_attr, |
| 1795 | }; |
| 1796 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1797 | /* |
| 1798 | * The following structs hold the PWM attributes, some of which are optional. |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1799 | * Their creation depends on the chip configuration which is determined during |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1800 | * module load. |
| 1801 | */ |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1802 | static struct attribute *dme1737_pwm1_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1803 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 1804 | &sensor_dev_attr_pwm1_freq.dev_attr.attr, |
| 1805 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
| 1806 | &sensor_dev_attr_pwm1_ramp_rate.dev_attr.attr, |
| 1807 | &sensor_dev_attr_pwm1_auto_channels_zone.dev_attr.attr, |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1808 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, |
| 1809 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1810 | NULL |
| 1811 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1812 | static struct attribute *dme1737_pwm2_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1813 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 1814 | &sensor_dev_attr_pwm2_freq.dev_attr.attr, |
| 1815 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 1816 | &sensor_dev_attr_pwm2_ramp_rate.dev_attr.attr, |
| 1817 | &sensor_dev_attr_pwm2_auto_channels_zone.dev_attr.attr, |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1818 | &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, |
| 1819 | &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1820 | NULL |
| 1821 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1822 | static struct attribute *dme1737_pwm3_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1823 | &sensor_dev_attr_pwm3.dev_attr.attr, |
| 1824 | &sensor_dev_attr_pwm3_freq.dev_attr.attr, |
| 1825 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
| 1826 | &sensor_dev_attr_pwm3_ramp_rate.dev_attr.attr, |
| 1827 | &sensor_dev_attr_pwm3_auto_channels_zone.dev_attr.attr, |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1828 | &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, |
| 1829 | &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1830 | NULL |
| 1831 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1832 | static struct attribute *dme1737_pwm5_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1833 | &sensor_dev_attr_pwm5.dev_attr.attr, |
| 1834 | &sensor_dev_attr_pwm5_freq.dev_attr.attr, |
| 1835 | &sensor_dev_attr_pwm5_enable.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1836 | NULL |
| 1837 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1838 | static struct attribute *dme1737_pwm6_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1839 | &sensor_dev_attr_pwm6.dev_attr.attr, |
| 1840 | &sensor_dev_attr_pwm6_freq.dev_attr.attr, |
| 1841 | &sensor_dev_attr_pwm6_enable.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1842 | NULL |
| 1843 | }; |
| 1844 | |
| 1845 | static const struct attribute_group dme1737_pwm_group[] = { |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1846 | { .attrs = dme1737_pwm1_attr }, |
| 1847 | { .attrs = dme1737_pwm2_attr }, |
| 1848 | { .attrs = dme1737_pwm3_attr }, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1849 | { .attrs = NULL }, |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1850 | { .attrs = dme1737_pwm5_attr }, |
| 1851 | { .attrs = dme1737_pwm6_attr }, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1852 | }; |
| 1853 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1854 | /* |
| 1855 | * The following struct holds auto PWM min attributes, which are not available |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1856 | * in all chips. Their creation depends on the chip type which is determined |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1857 | * during module load. |
| 1858 | */ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1859 | static struct attribute *dme1737_auto_pwm_min_attr[] = { |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1860 | &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr, |
| 1861 | &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr, |
| 1862 | &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr, |
| 1863 | }; |
| 1864 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1865 | /* |
| 1866 | * The following structs hold the fan attributes, some of which are optional. |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1867 | * Their creation depends on the chip configuration which is determined during |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1868 | * module load. |
| 1869 | */ |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1870 | static struct attribute *dme1737_fan1_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1871 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 1872 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 1873 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 1874 | &sensor_dev_attr_fan1_type.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1875 | NULL |
| 1876 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1877 | static struct attribute *dme1737_fan2_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1878 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 1879 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
| 1880 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 1881 | &sensor_dev_attr_fan2_type.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1882 | NULL |
| 1883 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1884 | static struct attribute *dme1737_fan3_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1885 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
| 1886 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
| 1887 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
| 1888 | &sensor_dev_attr_fan3_type.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1889 | NULL |
| 1890 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1891 | static struct attribute *dme1737_fan4_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1892 | &sensor_dev_attr_fan4_input.dev_attr.attr, |
| 1893 | &sensor_dev_attr_fan4_min.dev_attr.attr, |
| 1894 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
| 1895 | &sensor_dev_attr_fan4_type.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1896 | NULL |
| 1897 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1898 | static struct attribute *dme1737_fan5_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1899 | &sensor_dev_attr_fan5_input.dev_attr.attr, |
| 1900 | &sensor_dev_attr_fan5_min.dev_attr.attr, |
| 1901 | &sensor_dev_attr_fan5_alarm.dev_attr.attr, |
| 1902 | &sensor_dev_attr_fan5_max.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1903 | NULL |
| 1904 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1905 | static struct attribute *dme1737_fan6_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1906 | &sensor_dev_attr_fan6_input.dev_attr.attr, |
| 1907 | &sensor_dev_attr_fan6_min.dev_attr.attr, |
| 1908 | &sensor_dev_attr_fan6_alarm.dev_attr.attr, |
| 1909 | &sensor_dev_attr_fan6_max.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1910 | NULL |
| 1911 | }; |
| 1912 | |
| 1913 | static const struct attribute_group dme1737_fan_group[] = { |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1914 | { .attrs = dme1737_fan1_attr }, |
| 1915 | { .attrs = dme1737_fan2_attr }, |
| 1916 | { .attrs = dme1737_fan3_attr }, |
| 1917 | { .attrs = dme1737_fan4_attr }, |
| 1918 | { .attrs = dme1737_fan5_attr }, |
| 1919 | { .attrs = dme1737_fan6_attr }, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1920 | }; |
| 1921 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1922 | /* |
| 1923 | * The permissions of the following zone attributes are changed to read- |
| 1924 | * writeable if the chip is *not* locked. Otherwise they stay read-only. |
| 1925 | */ |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1926 | static struct attribute *dme1737_zone_chmod_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1927 | &sensor_dev_attr_zone1_auto_point1_temp.dev_attr.attr, |
| 1928 | &sensor_dev_attr_zone1_auto_point2_temp.dev_attr.attr, |
| 1929 | &sensor_dev_attr_zone1_auto_point3_temp.dev_attr.attr, |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1930 | &sensor_dev_attr_zone2_auto_point1_temp.dev_attr.attr, |
| 1931 | &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr, |
| 1932 | &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr, |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1933 | NULL |
| 1934 | }; |
| 1935 | |
| 1936 | static const struct attribute_group dme1737_zone_chmod_group = { |
| 1937 | .attrs = dme1737_zone_chmod_attr, |
| 1938 | }; |
| 1939 | |
| 1940 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1941 | /* |
| 1942 | * The permissions of the following zone 3 attributes are changed to read- |
| 1943 | * writeable if the chip is *not* locked. Otherwise they stay read-only. |
| 1944 | */ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1945 | static struct attribute *dme1737_zone3_chmod_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1946 | &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr, |
| 1947 | &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr, |
| 1948 | &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1949 | NULL |
| 1950 | }; |
| 1951 | |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 1952 | static const struct attribute_group dme1737_zone3_chmod_group = { |
| 1953 | .attrs = dme1737_zone3_chmod_attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1954 | }; |
| 1955 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1956 | /* |
| 1957 | * The permissions of the following PWM attributes are changed to read- |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1958 | * writeable if the chip is *not* locked and the respective PWM is available. |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 1959 | * Otherwise they stay read-only. |
| 1960 | */ |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1961 | static struct attribute *dme1737_pwm1_chmod_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1962 | &sensor_dev_attr_pwm1_freq.dev_attr.attr, |
| 1963 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
| 1964 | &sensor_dev_attr_pwm1_ramp_rate.dev_attr.attr, |
| 1965 | &sensor_dev_attr_pwm1_auto_channels_zone.dev_attr.attr, |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1966 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1967 | NULL |
| 1968 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1969 | static struct attribute *dme1737_pwm2_chmod_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1970 | &sensor_dev_attr_pwm2_freq.dev_attr.attr, |
| 1971 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 1972 | &sensor_dev_attr_pwm2_ramp_rate.dev_attr.attr, |
| 1973 | &sensor_dev_attr_pwm2_auto_channels_zone.dev_attr.attr, |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1974 | &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1975 | NULL |
| 1976 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1977 | static struct attribute *dme1737_pwm3_chmod_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1978 | &sensor_dev_attr_pwm3_freq.dev_attr.attr, |
| 1979 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
| 1980 | &sensor_dev_attr_pwm3_ramp_rate.dev_attr.attr, |
| 1981 | &sensor_dev_attr_pwm3_auto_channels_zone.dev_attr.attr, |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1982 | &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1983 | NULL |
| 1984 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1985 | static struct attribute *dme1737_pwm5_chmod_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1986 | &sensor_dev_attr_pwm5.dev_attr.attr, |
| 1987 | &sensor_dev_attr_pwm5_freq.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1988 | NULL |
| 1989 | }; |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1990 | static struct attribute *dme1737_pwm6_chmod_attr[] = { |
Juerg Haefliger | 9b25771 | 2008-03-25 21:49:02 -0700 | [diff] [blame] | 1991 | &sensor_dev_attr_pwm6.dev_attr.attr, |
| 1992 | &sensor_dev_attr_pwm6_freq.dev_attr.attr, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1993 | NULL |
| 1994 | }; |
| 1995 | |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 1996 | static const struct attribute_group dme1737_pwm_chmod_group[] = { |
| 1997 | { .attrs = dme1737_pwm1_chmod_attr }, |
| 1998 | { .attrs = dme1737_pwm2_chmod_attr }, |
| 1999 | { .attrs = dme1737_pwm3_chmod_attr }, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2000 | { .attrs = NULL }, |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2001 | { .attrs = dme1737_pwm5_chmod_attr }, |
| 2002 | { .attrs = dme1737_pwm6_chmod_attr }, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2003 | }; |
| 2004 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2005 | /* |
| 2006 | * Pwm[1-3] are read-writeable if the associated pwm is in manual mode and the |
| 2007 | * chip is not locked. Otherwise they are read-only. |
| 2008 | */ |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2009 | static struct attribute *dme1737_pwm_chmod_attr[] = { |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2010 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 2011 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 2012 | &sensor_dev_attr_pwm3.dev_attr.attr, |
| 2013 | }; |
| 2014 | |
| 2015 | /* --------------------------------------------------------------------- |
| 2016 | * Super-IO functions |
| 2017 | * --------------------------------------------------------------------- */ |
| 2018 | |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2019 | static inline void dme1737_sio_enter(int sio_cip) |
| 2020 | { |
| 2021 | outb(0x55, sio_cip); |
| 2022 | } |
| 2023 | |
| 2024 | static inline void dme1737_sio_exit(int sio_cip) |
| 2025 | { |
| 2026 | outb(0xaa, sio_cip); |
| 2027 | } |
| 2028 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2029 | static inline int dme1737_sio_inb(int sio_cip, int reg) |
| 2030 | { |
| 2031 | outb(reg, sio_cip); |
| 2032 | return inb(sio_cip + 1); |
| 2033 | } |
| 2034 | |
| 2035 | static inline void dme1737_sio_outb(int sio_cip, int reg, int val) |
| 2036 | { |
| 2037 | outb(reg, sio_cip); |
| 2038 | outb(val, sio_cip + 1); |
| 2039 | } |
| 2040 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2041 | /* --------------------------------------------------------------------- |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2042 | * Device initialization |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2043 | * --------------------------------------------------------------------- */ |
| 2044 | |
Juerg Haefliger | 67e2f32 | 2007-10-01 21:20:28 -0700 | [diff] [blame] | 2045 | static int dme1737_i2c_get_features(int, struct dme1737_data*); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2046 | |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2047 | static void dme1737_chmod_file(struct device *dev, |
Al Viro | 48176a9 | 2011-07-24 03:40:40 -0400 | [diff] [blame] | 2048 | struct attribute *attr, umode_t mode) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2049 | { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2050 | if (sysfs_chmod_file(&dev->kobj, attr, mode)) { |
| 2051 | dev_warn(dev, "Failed to change permissions of %s.\n", |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2052 | attr->name); |
| 2053 | } |
| 2054 | } |
| 2055 | |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2056 | static void dme1737_chmod_group(struct device *dev, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2057 | const struct attribute_group *group, |
Al Viro | 48176a9 | 2011-07-24 03:40:40 -0400 | [diff] [blame] | 2058 | umode_t mode) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2059 | { |
| 2060 | struct attribute **attr; |
| 2061 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2062 | for (attr = group->attrs; *attr; attr++) |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2063 | dme1737_chmod_file(dev, *attr, mode); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2064 | } |
| 2065 | |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2066 | static void dme1737_remove_files(struct device *dev) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2067 | { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2068 | struct dme1737_data *data = dev_get_drvdata(dev); |
| 2069 | int ix; |
| 2070 | |
| 2071 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2072 | if (data->has_features & HAS_FAN(ix)) { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2073 | sysfs_remove_group(&dev->kobj, |
| 2074 | &dme1737_fan_group[ix]); |
| 2075 | } |
| 2076 | } |
| 2077 | |
| 2078 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2079 | if (data->has_features & HAS_PWM(ix)) { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2080 | sysfs_remove_group(&dev->kobj, |
| 2081 | &dme1737_pwm_group[ix]); |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2082 | if ((data->has_features & HAS_PWM_MIN) && ix < 3) { |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2083 | sysfs_remove_file(&dev->kobj, |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2084 | dme1737_auto_pwm_min_attr[ix]); |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2085 | } |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2086 | } |
| 2087 | } |
| 2088 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2089 | if (data->has_features & HAS_TEMP_OFFSET) |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2090 | sysfs_remove_group(&dev->kobj, &dme1737_temp_offset_group); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2091 | if (data->has_features & HAS_VID) |
Jean Delvare | 9d09144 | 2009-10-24 13:28:46 +0200 | [diff] [blame] | 2092 | sysfs_remove_group(&dev->kobj, &dme1737_vid_group); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2093 | if (data->has_features & HAS_ZONE3) |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2094 | sysfs_remove_group(&dev->kobj, &dme1737_zone3_group); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2095 | if (data->has_features & HAS_ZONE_HYST) |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2096 | sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2097 | if (data->has_features & HAS_IN7) |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2098 | sysfs_remove_group(&dev->kobj, &dme1737_in7_group); |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2099 | sysfs_remove_group(&dev->kobj, &dme1737_group); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2100 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2101 | if (!data->client) |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2102 | sysfs_remove_file(&dev->kobj, &dev_attr_name.attr); |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | static int dme1737_create_files(struct device *dev) |
| 2106 | { |
| 2107 | struct dme1737_data *data = dev_get_drvdata(dev); |
| 2108 | int err, ix; |
| 2109 | |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2110 | /* Create a name attribute for ISA devices */ |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2111 | if (!data->client) { |
| 2112 | err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2113 | if (err) |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2114 | goto exit; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2117 | /* Create standard sysfs attributes */ |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2118 | err = sysfs_create_group(&dev->kobj, &dme1737_group); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2119 | if (err) |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2120 | goto exit_remove; |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2121 | |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2122 | /* Create chip-dependent sysfs attributes */ |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2123 | if (data->has_features & HAS_TEMP_OFFSET) { |
| 2124 | err = sysfs_create_group(&dev->kobj, |
| 2125 | &dme1737_temp_offset_group); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2126 | if (err) |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2127 | goto exit_remove; |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2128 | } |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2129 | if (data->has_features & HAS_VID) { |
| 2130 | err = sysfs_create_group(&dev->kobj, &dme1737_vid_group); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2131 | if (err) |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2132 | goto exit_remove; |
Jean Delvare | 9d09144 | 2009-10-24 13:28:46 +0200 | [diff] [blame] | 2133 | } |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2134 | if (data->has_features & HAS_ZONE3) { |
| 2135 | err = sysfs_create_group(&dev->kobj, &dme1737_zone3_group); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2136 | if (err) |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2137 | goto exit_remove; |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2138 | } |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2139 | if (data->has_features & HAS_ZONE_HYST) { |
| 2140 | err = sysfs_create_group(&dev->kobj, &dme1737_zone_hyst_group); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2141 | if (err) |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2142 | goto exit_remove; |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2143 | } |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2144 | if (data->has_features & HAS_IN7) { |
| 2145 | err = sysfs_create_group(&dev->kobj, &dme1737_in7_group); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2146 | if (err) |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2147 | goto exit_remove; |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2148 | } |
Jean Delvare | 9d09144 | 2009-10-24 13:28:46 +0200 | [diff] [blame] | 2149 | |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2150 | /* Create fan sysfs attributes */ |
| 2151 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2152 | if (data->has_features & HAS_FAN(ix)) { |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2153 | err = sysfs_create_group(&dev->kobj, |
| 2154 | &dme1737_fan_group[ix]); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2155 | if (err) |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2156 | goto exit_remove; |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2157 | } |
| 2158 | } |
| 2159 | |
| 2160 | /* Create PWM sysfs attributes */ |
| 2161 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2162 | if (data->has_features & HAS_PWM(ix)) { |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2163 | err = sysfs_create_group(&dev->kobj, |
| 2164 | &dme1737_pwm_group[ix]); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2165 | if (err) |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2166 | goto exit_remove; |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2167 | if ((data->has_features & HAS_PWM_MIN) && (ix < 3)) { |
| 2168 | err = sysfs_create_file(&dev->kobj, |
| 2169 | dme1737_auto_pwm_min_attr[ix]); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2170 | if (err) |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2171 | goto exit_remove; |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2172 | } |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2173 | } |
| 2174 | } |
| 2175 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2176 | /* |
| 2177 | * Inform if the device is locked. Otherwise change the permissions of |
| 2178 | * selected attributes from read-only to read-writeable. |
| 2179 | */ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2180 | if (data->config & 0x02) { |
| 2181 | dev_info(dev, "Device is locked. Some attributes " |
| 2182 | "will be read-only.\n"); |
| 2183 | } else { |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2184 | /* Change permissions of zone sysfs attributes */ |
| 2185 | dme1737_chmod_group(dev, &dme1737_zone_chmod_group, |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2186 | S_IRUGO | S_IWUSR); |
| 2187 | |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2188 | /* Change permissions of chip-dependent sysfs attributes */ |
| 2189 | if (data->has_features & HAS_TEMP_OFFSET) { |
| 2190 | dme1737_chmod_group(dev, &dme1737_temp_offset_group, |
| 2191 | S_IRUGO | S_IWUSR); |
| 2192 | } |
| 2193 | if (data->has_features & HAS_ZONE3) { |
| 2194 | dme1737_chmod_group(dev, &dme1737_zone3_chmod_group, |
| 2195 | S_IRUGO | S_IWUSR); |
| 2196 | } |
| 2197 | if (data->has_features & HAS_ZONE_HYST) { |
| 2198 | dme1737_chmod_group(dev, &dme1737_zone_hyst_group, |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2199 | S_IRUGO | S_IWUSR); |
| 2200 | } |
| 2201 | |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2202 | /* Change permissions of PWM sysfs attributes */ |
| 2203 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_chmod_group); ix++) { |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2204 | if (data->has_features & HAS_PWM(ix)) { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2205 | dme1737_chmod_group(dev, |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2206 | &dme1737_pwm_chmod_group[ix], |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2207 | S_IRUGO | S_IWUSR); |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2208 | if ((data->has_features & HAS_PWM_MIN) && |
| 2209 | ix < 3) { |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2210 | dme1737_chmod_file(dev, |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2211 | dme1737_auto_pwm_min_attr[ix], |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2212 | S_IRUGO | S_IWUSR); |
| 2213 | } |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | /* Change permissions of pwm[1-3] if in manual mode */ |
| 2218 | for (ix = 0; ix < 3; ix++) { |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2219 | if ((data->has_features & HAS_PWM(ix)) && |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2220 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) { |
| 2221 | dme1737_chmod_file(dev, |
Juerg Haefliger | 73ce48f | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2222 | dme1737_pwm_chmod_attr[ix], |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2223 | S_IRUGO | S_IWUSR); |
| 2224 | } |
| 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | return 0; |
| 2229 | |
| 2230 | exit_remove: |
| 2231 | dme1737_remove_files(dev); |
| 2232 | exit: |
| 2233 | return err; |
| 2234 | } |
| 2235 | |
| 2236 | static int dme1737_init_device(struct device *dev) |
| 2237 | { |
| 2238 | struct dme1737_data *data = dev_get_drvdata(dev); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2239 | struct i2c_client *client = data->client; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2240 | int ix; |
| 2241 | u8 reg; |
| 2242 | |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2243 | /* Point to the right nominal voltages array */ |
| 2244 | data->in_nominal = IN_NOMINAL(data->type); |
| 2245 | |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2246 | data->config = dme1737_read(data, DME1737_REG_CONFIG); |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2247 | /* Inform if part is not monitoring/started */ |
| 2248 | if (!(data->config & 0x01)) { |
| 2249 | if (!force_start) { |
| 2250 | dev_err(dev, "Device is not monitoring. " |
| 2251 | "Use the force_start load parameter to " |
| 2252 | "override.\n"); |
| 2253 | return -EFAULT; |
| 2254 | } |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2255 | |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2256 | /* Force monitoring */ |
| 2257 | data->config |= 0x01; |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2258 | dme1737_write(data, DME1737_REG_CONFIG, data->config); |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2259 | } |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2260 | /* Inform if part is not ready */ |
| 2261 | if (!(data->config & 0x04)) { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2262 | dev_err(dev, "Device is not ready.\n"); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2263 | return -EFAULT; |
| 2264 | } |
| 2265 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2266 | /* |
| 2267 | * Determine which optional fan and pwm features are enabled (only |
| 2268 | * valid for I2C devices) |
| 2269 | */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2270 | if (client) { /* I2C chip */ |
| 2271 | data->config2 = dme1737_read(data, DME1737_REG_CONFIG2); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2272 | /* Check if optional fan3 input is enabled */ |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2273 | if (data->config2 & 0x04) |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2274 | data->has_features |= HAS_FAN(2); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2275 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2276 | /* |
| 2277 | * Fan4 and pwm3 are only available if the client's I2C address |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2278 | * is the default 0x2e. Otherwise the I/Os associated with |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2279 | * these functions are used for addr enable/select. |
| 2280 | */ |
| 2281 | if (client->addr == 0x2e) |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2282 | data->has_features |= HAS_FAN(3) | HAS_PWM(2); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2283 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2284 | /* |
| 2285 | * Determine which of the optional fan[5-6] and pwm[5-6] |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2286 | * features are enabled. For this, we need to query the runtime |
| 2287 | * registers through the Super-IO LPC interface. Try both |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2288 | * config ports 0x2e and 0x4e. |
| 2289 | */ |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2290 | if (dme1737_i2c_get_features(0x2e, data) && |
| 2291 | dme1737_i2c_get_features(0x4e, data)) { |
| 2292 | dev_warn(dev, "Failed to query Super-IO for optional " |
| 2293 | "features.\n"); |
| 2294 | } |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2295 | } |
| 2296 | |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2297 | /* Fan[1-2] and pwm[1-2] are present in all chips */ |
| 2298 | data->has_features |= HAS_FAN(0) | HAS_FAN(1) | HAS_PWM(0) | HAS_PWM(1); |
| 2299 | |
| 2300 | /* Chip-dependent features */ |
| 2301 | switch (data->type) { |
| 2302 | case dme1737: |
| 2303 | data->has_features |= HAS_TEMP_OFFSET | HAS_VID | HAS_ZONE3 | |
| 2304 | HAS_ZONE_HYST | HAS_PWM_MIN; |
| 2305 | break; |
| 2306 | case sch311x: |
| 2307 | data->has_features |= HAS_TEMP_OFFSET | HAS_ZONE3 | |
| 2308 | HAS_ZONE_HYST | HAS_PWM_MIN | HAS_FAN(2) | HAS_PWM(2); |
| 2309 | break; |
| 2310 | case sch5027: |
| 2311 | data->has_features |= HAS_ZONE3; |
| 2312 | break; |
| 2313 | case sch5127: |
Juerg Haefliger | d4b94e1 | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2314 | data->has_features |= HAS_FAN(2) | HAS_PWM(2) | HAS_IN7; |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2315 | break; |
| 2316 | default: |
| 2317 | break; |
| 2318 | } |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2319 | |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2320 | dev_info(dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, " |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2321 | "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n", |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2322 | (data->has_features & HAS_PWM(2)) ? "yes" : "no", |
| 2323 | (data->has_features & HAS_PWM(4)) ? "yes" : "no", |
| 2324 | (data->has_features & HAS_PWM(5)) ? "yes" : "no", |
| 2325 | (data->has_features & HAS_FAN(2)) ? "yes" : "no", |
| 2326 | (data->has_features & HAS_FAN(3)) ? "yes" : "no", |
| 2327 | (data->has_features & HAS_FAN(4)) ? "yes" : "no", |
| 2328 | (data->has_features & HAS_FAN(5)) ? "yes" : "no"); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2329 | |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2330 | reg = dme1737_read(data, DME1737_REG_TACH_PWM); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2331 | /* Inform if fan-to-pwm mapping differs from the default */ |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2332 | if (client && reg != 0xa4) { /* I2C chip */ |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2333 | dev_warn(dev, "Non-standard fan to pwm mapping: " |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2334 | "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " |
| 2335 | "fan4->pwm%d. Please report to the driver " |
| 2336 | "maintainer.\n", |
| 2337 | (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1, |
| 2338 | ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2339 | } else if (!client && reg != 0x24) { /* ISA chip */ |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2340 | dev_warn(dev, "Non-standard fan to pwm mapping: " |
| 2341 | "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. " |
| 2342 | "Please report to the driver maintainer.\n", |
| 2343 | (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1, |
| 2344 | ((reg >> 4) & 0x03) + 1); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2345 | } |
| 2346 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2347 | /* |
| 2348 | * Switch pwm[1-3] to manual mode if they are currently disabled and |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2349 | * set the duty-cycles to 0% (which is identical to the PWMs being |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2350 | * disabled). |
| 2351 | */ |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2352 | if (!(data->config & 0x02)) { |
| 2353 | for (ix = 0; ix < 3; ix++) { |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2354 | data->pwm_config[ix] = dme1737_read(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2355 | DME1737_REG_PWM_CONFIG(ix)); |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2356 | if ((data->has_features & HAS_PWM(ix)) && |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2357 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2358 | dev_info(dev, "Switching pwm%d to " |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2359 | "manual mode.\n", ix + 1); |
| 2360 | data->pwm_config[ix] = PWM_EN_TO_REG(1, |
| 2361 | data->pwm_config[ix]); |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2362 | dme1737_write(data, DME1737_REG_PWM(ix), 0); |
| 2363 | dme1737_write(data, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2364 | DME1737_REG_PWM_CONFIG(ix), |
| 2365 | data->pwm_config[ix]); |
| 2366 | } |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | /* Initialize the default PWM auto channels zone (acz) assignments */ |
| 2371 | data->pwm_acz[0] = 1; /* pwm1 -> zone1 */ |
| 2372 | data->pwm_acz[1] = 2; /* pwm2 -> zone2 */ |
| 2373 | data->pwm_acz[2] = 4; /* pwm3 -> zone3 */ |
| 2374 | |
| 2375 | /* Set VRM */ |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2376 | if (data->has_features & HAS_VID) |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2377 | data->vrm = vid_which_vrm(); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2378 | |
| 2379 | return 0; |
| 2380 | } |
| 2381 | |
Juerg Haefliger | 67e2f32 | 2007-10-01 21:20:28 -0700 | [diff] [blame] | 2382 | /* --------------------------------------------------------------------- |
| 2383 | * I2C device detection and registration |
| 2384 | * --------------------------------------------------------------------- */ |
| 2385 | |
| 2386 | static struct i2c_driver dme1737_i2c_driver; |
| 2387 | |
| 2388 | static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data) |
| 2389 | { |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2390 | int err = 0, reg; |
| 2391 | u16 addr; |
| 2392 | |
Juerg Haefliger | 67e2f32 | 2007-10-01 21:20:28 -0700 | [diff] [blame] | 2393 | dme1737_sio_enter(sio_cip); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2394 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2395 | /* |
| 2396 | * Check device ID |
| 2397 | * We currently know about two kinds of DME1737 and SCH5027. |
| 2398 | */ |
Juerg Haefliger | 345a222 | 2008-01-26 08:54:24 -0800 | [diff] [blame] | 2399 | reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20); |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2400 | if (!(reg == DME1737_ID_1 || reg == DME1737_ID_2 || |
| 2401 | reg == SCH5027_ID)) { |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2402 | err = -ENODEV; |
| 2403 | goto exit; |
| 2404 | } |
| 2405 | |
| 2406 | /* Select logical device A (runtime registers) */ |
| 2407 | dme1737_sio_outb(sio_cip, 0x07, 0x0a); |
| 2408 | |
| 2409 | /* Get the base address of the runtime registers */ |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2410 | addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | |
| 2411 | dme1737_sio_inb(sio_cip, 0x61); |
| 2412 | if (!addr) { |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2413 | err = -ENODEV; |
| 2414 | goto exit; |
| 2415 | } |
| 2416 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2417 | /* |
| 2418 | * Read the runtime registers to determine which optional features |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2419 | * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2420 | * to '10' if the respective feature is enabled. |
| 2421 | */ |
| 2422 | if ((inb(addr + 0x43) & 0x0c) == 0x08) /* fan6 */ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2423 | data->has_features |= HAS_FAN(5); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2424 | if ((inb(addr + 0x44) & 0x0c) == 0x08) /* pwm6 */ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2425 | data->has_features |= HAS_PWM(5); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2426 | if ((inb(addr + 0x45) & 0x0c) == 0x08) /* fan5 */ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2427 | data->has_features |= HAS_FAN(4); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2428 | if ((inb(addr + 0x46) & 0x0c) == 0x08) /* pwm5 */ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2429 | data->has_features |= HAS_PWM(4); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2430 | |
| 2431 | exit: |
Juerg Haefliger | 67e2f32 | 2007-10-01 21:20:28 -0700 | [diff] [blame] | 2432 | dme1737_sio_exit(sio_cip); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2433 | |
| 2434 | return err; |
| 2435 | } |
| 2436 | |
Jean Delvare | 67a3730 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2437 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 2438 | static int dme1737_i2c_detect(struct i2c_client *client, |
Jean Delvare | 67a3730 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2439 | struct i2c_board_info *info) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2440 | { |
Jean Delvare | 67a3730 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2441 | struct i2c_adapter *adapter = client->adapter; |
| 2442 | struct device *dev = &adapter->dev; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2443 | u8 company, verstep = 0; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2444 | const char *name; |
| 2445 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2446 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
Jean Delvare | 67a3730 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2447 | return -ENODEV; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2448 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 2449 | company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY); |
| 2450 | verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2451 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 2452 | if (company == DME1737_COMPANY_SMSC && |
| 2453 | verstep == SCH5027_VERSTEP) { |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2454 | name = "sch5027"; |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 2455 | } else if (company == DME1737_COMPANY_SMSC && |
| 2456 | (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) { |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2457 | name = "dme1737"; |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 2458 | } else { |
| 2459 | return -ENODEV; |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2460 | } |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2461 | |
Juerg Haefliger | 549edb8 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2462 | dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n", |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 2463 | verstep == SCH5027_VERSTEP ? "SCH5027" : "DME1737", |
| 2464 | client->addr, verstep); |
Jean Delvare | 67a3730 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2465 | strlcpy(info->type, name, I2C_NAME_SIZE); |
| 2466 | |
| 2467 | return 0; |
| 2468 | } |
| 2469 | |
| 2470 | static int dme1737_i2c_probe(struct i2c_client *client, |
| 2471 | const struct i2c_device_id *id) |
| 2472 | { |
| 2473 | struct dme1737_data *data; |
| 2474 | struct device *dev = &client->dev; |
| 2475 | int err; |
| 2476 | |
Guenter Roeck | 805fd8c | 2012-06-02 09:58:03 -0700 | [diff] [blame] | 2477 | data = devm_kzalloc(dev, sizeof(struct dme1737_data), GFP_KERNEL); |
| 2478 | if (!data) |
| 2479 | return -ENOMEM; |
Jean Delvare | 67a3730 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2480 | |
| 2481 | i2c_set_clientdata(client, data); |
| 2482 | data->type = id->driver_data; |
| 2483 | data->client = client; |
| 2484 | data->name = client->name; |
| 2485 | mutex_init(&data->update_lock); |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2486 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2487 | /* Initialize the DME1737 chip */ |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2488 | err = dme1737_init_device(dev); |
| 2489 | if (err) { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2490 | dev_err(dev, "Failed to initialize device.\n"); |
Guenter Roeck | 805fd8c | 2012-06-02 09:58:03 -0700 | [diff] [blame] | 2491 | return err; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2492 | } |
| 2493 | |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2494 | /* Create sysfs files */ |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2495 | err = dme1737_create_files(dev); |
| 2496 | if (err) { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2497 | dev_err(dev, "Failed to create sysfs files.\n"); |
Guenter Roeck | 805fd8c | 2012-06-02 09:58:03 -0700 | [diff] [blame] | 2498 | return err; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | /* Register device */ |
Mark M. Hoffman | 62ee3e1 | 2007-10-10 22:32:50 -0400 | [diff] [blame] | 2502 | data->hwmon_dev = hwmon_device_register(dev); |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 2503 | if (IS_ERR(data->hwmon_dev)) { |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2504 | dev_err(dev, "Failed to register device.\n"); |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 2505 | err = PTR_ERR(data->hwmon_dev); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2506 | goto exit_remove; |
| 2507 | } |
| 2508 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2509 | return 0; |
| 2510 | |
| 2511 | exit_remove: |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2512 | dme1737_remove_files(dev); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2513 | return err; |
| 2514 | } |
| 2515 | |
Jean Delvare | 67a3730 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2516 | static int dme1737_i2c_remove(struct i2c_client *client) |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2517 | { |
| 2518 | struct dme1737_data *data = i2c_get_clientdata(client); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2519 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 2520 | hwmon_device_unregister(data->hwmon_dev); |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2521 | dme1737_remove_files(&client->dev); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2522 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2523 | return 0; |
| 2524 | } |
| 2525 | |
Jean Delvare | 67a3730 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2526 | static const struct i2c_device_id dme1737_id[] = { |
| 2527 | { "dme1737", dme1737 }, |
| 2528 | { "sch5027", sch5027 }, |
| 2529 | { } |
| 2530 | }; |
| 2531 | MODULE_DEVICE_TABLE(i2c, dme1737_id); |
| 2532 | |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2533 | static struct i2c_driver dme1737_i2c_driver = { |
Jean Delvare | 67a3730 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2534 | .class = I2C_CLASS_HWMON, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2535 | .driver = { |
| 2536 | .name = "dme1737", |
| 2537 | }, |
Jean Delvare | 67a3730 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2538 | .probe = dme1737_i2c_probe, |
| 2539 | .remove = dme1737_i2c_remove, |
| 2540 | .id_table = dme1737_id, |
| 2541 | .detect = dme1737_i2c_detect, |
Jean Delvare | c3813d6 | 2009-12-14 21:17:25 +0100 | [diff] [blame] | 2542 | .address_list = normal_i2c, |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2543 | }; |
| 2544 | |
Juerg Haefliger | 67e2f32 | 2007-10-01 21:20:28 -0700 | [diff] [blame] | 2545 | /* --------------------------------------------------------------------- |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2546 | * ISA device detection and registration |
| 2547 | * --------------------------------------------------------------------- */ |
| 2548 | |
| 2549 | static int __init dme1737_isa_detect(int sio_cip, unsigned short *addr) |
| 2550 | { |
| 2551 | int err = 0, reg; |
| 2552 | unsigned short base_addr; |
| 2553 | |
| 2554 | dme1737_sio_enter(sio_cip); |
| 2555 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2556 | /* |
| 2557 | * Check device ID |
| 2558 | * We currently know about SCH3112, SCH3114, SCH3116, and SCH5127 |
| 2559 | */ |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 2560 | reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20); |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2561 | if (!(reg == SCH3112_ID || reg == SCH3114_ID || reg == SCH3116_ID || |
| 2562 | reg == SCH5127_ID)) { |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2563 | err = -ENODEV; |
| 2564 | goto exit; |
| 2565 | } |
| 2566 | |
| 2567 | /* Select logical device A (runtime registers) */ |
| 2568 | dme1737_sio_outb(sio_cip, 0x07, 0x0a); |
| 2569 | |
| 2570 | /* Get the base address of the runtime registers */ |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2571 | base_addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | |
| 2572 | dme1737_sio_inb(sio_cip, 0x61); |
| 2573 | if (!base_addr) { |
Joe Perches | 9c6e13b | 2010-10-20 06:51:32 +0000 | [diff] [blame] | 2574 | pr_err("Base address not set\n"); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2575 | err = -ENODEV; |
| 2576 | goto exit; |
| 2577 | } |
| 2578 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2579 | /* |
| 2580 | * Access to the hwmon registers is through an index/data register |
| 2581 | * pair located at offset 0x70/0x71. |
| 2582 | */ |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2583 | *addr = base_addr + 0x70; |
| 2584 | |
| 2585 | exit: |
| 2586 | dme1737_sio_exit(sio_cip); |
| 2587 | return err; |
| 2588 | } |
| 2589 | |
| 2590 | static int __init dme1737_isa_device_add(unsigned short addr) |
| 2591 | { |
| 2592 | struct resource res = { |
| 2593 | .start = addr, |
| 2594 | .end = addr + DME1737_EXTENT - 1, |
| 2595 | .name = "dme1737", |
| 2596 | .flags = IORESOURCE_IO, |
| 2597 | }; |
| 2598 | int err; |
| 2599 | |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 2600 | err = acpi_check_resource_conflict(&res); |
| 2601 | if (err) |
| 2602 | goto exit; |
| 2603 | |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2604 | pdev = platform_device_alloc("dme1737", addr); |
| 2605 | if (!pdev) { |
Joe Perches | 9c6e13b | 2010-10-20 06:51:32 +0000 | [diff] [blame] | 2606 | pr_err("Failed to allocate device\n"); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2607 | err = -ENOMEM; |
| 2608 | goto exit; |
| 2609 | } |
| 2610 | |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2611 | err = platform_device_add_resources(pdev, &res, 1); |
| 2612 | if (err) { |
Joe Perches | 9c6e13b | 2010-10-20 06:51:32 +0000 | [diff] [blame] | 2613 | pr_err("Failed to add device resource (err = %d)\n", err); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2614 | goto exit_device_put; |
| 2615 | } |
| 2616 | |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2617 | err = platform_device_add(pdev); |
| 2618 | if (err) { |
Joe Perches | 9c6e13b | 2010-10-20 06:51:32 +0000 | [diff] [blame] | 2619 | pr_err("Failed to add device (err = %d)\n", err); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2620 | goto exit_device_put; |
| 2621 | } |
| 2622 | |
| 2623 | return 0; |
| 2624 | |
| 2625 | exit_device_put: |
| 2626 | platform_device_put(pdev); |
| 2627 | pdev = NULL; |
| 2628 | exit: |
| 2629 | return err; |
| 2630 | } |
| 2631 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 2632 | static int dme1737_isa_probe(struct platform_device *pdev) |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2633 | { |
| 2634 | u8 company, device; |
| 2635 | struct resource *res; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2636 | struct dme1737_data *data; |
| 2637 | struct device *dev = &pdev->dev; |
| 2638 | int err; |
| 2639 | |
| 2640 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
Guenter Roeck | 805fd8c | 2012-06-02 09:58:03 -0700 | [diff] [blame] | 2641 | if (!devm_request_region(dev, res->start, DME1737_EXTENT, "dme1737")) { |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2642 | dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n", |
| 2643 | (unsigned short)res->start, |
| 2644 | (unsigned short)res->start + DME1737_EXTENT - 1); |
Guenter Roeck | 805fd8c | 2012-06-02 09:58:03 -0700 | [diff] [blame] | 2645 | return -EBUSY; |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2646 | } |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2647 | |
Guenter Roeck | 805fd8c | 2012-06-02 09:58:03 -0700 | [diff] [blame] | 2648 | data = devm_kzalloc(dev, sizeof(struct dme1737_data), GFP_KERNEL); |
| 2649 | if (!data) |
| 2650 | return -ENOMEM; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2651 | |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2652 | data->addr = res->start; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2653 | platform_set_drvdata(pdev, data); |
| 2654 | |
Juerg Haefliger | 55d68d7 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2655 | /* Skip chip detection if module is loaded with force_id parameter */ |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2656 | switch (force_id) { |
| 2657 | case SCH3112_ID: |
| 2658 | case SCH3114_ID: |
| 2659 | case SCH3116_ID: |
| 2660 | data->type = sch311x; |
| 2661 | break; |
| 2662 | case SCH5127_ID: |
| 2663 | data->type = sch5127; |
| 2664 | break; |
| 2665 | default: |
Jean Delvare | dbc2bc2 | 2008-10-14 17:30:04 +0200 | [diff] [blame] | 2666 | company = dme1737_read(data, DME1737_REG_COMPANY); |
| 2667 | device = dme1737_read(data, DME1737_REG_DEVICE); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2668 | |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2669 | if ((company == DME1737_COMPANY_SMSC) && |
| 2670 | (device == SCH311X_DEVICE)) { |
| 2671 | data->type = sch311x; |
| 2672 | } else if ((company == DME1737_COMPANY_SMSC) && |
| 2673 | (device == SCH5127_DEVICE)) { |
| 2674 | data->type = sch5127; |
| 2675 | } else { |
Guenter Roeck | 805fd8c | 2012-06-02 09:58:03 -0700 | [diff] [blame] | 2676 | return -ENODEV; |
Juerg Haefliger | 55d68d7 | 2008-08-06 22:41:03 +0200 | [diff] [blame] | 2677 | } |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2680 | if (data->type == sch5127) |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2681 | data->name = "sch5127"; |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2682 | else |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2683 | data->name = "sch311x"; |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2684 | |
| 2685 | /* Initialize the mutex */ |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2686 | mutex_init(&data->update_lock); |
| 2687 | |
Juerg Haefliger | ea69443 | 2010-05-27 19:59:01 +0200 | [diff] [blame] | 2688 | dev_info(dev, "Found a %s chip at 0x%04x\n", |
| 2689 | data->type == sch5127 ? "SCH5127" : "SCH311x", data->addr); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2690 | |
| 2691 | /* Initialize the chip */ |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2692 | err = dme1737_init_device(dev); |
| 2693 | if (err) { |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2694 | dev_err(dev, "Failed to initialize device.\n"); |
Guenter Roeck | 805fd8c | 2012-06-02 09:58:03 -0700 | [diff] [blame] | 2695 | return err; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | /* Create sysfs files */ |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2699 | err = dme1737_create_files(dev); |
| 2700 | if (err) { |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2701 | dev_err(dev, "Failed to create sysfs files.\n"); |
Guenter Roeck | 805fd8c | 2012-06-02 09:58:03 -0700 | [diff] [blame] | 2702 | return err; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | /* Register device */ |
| 2706 | data->hwmon_dev = hwmon_device_register(dev); |
| 2707 | if (IS_ERR(data->hwmon_dev)) { |
| 2708 | dev_err(dev, "Failed to register device.\n"); |
| 2709 | err = PTR_ERR(data->hwmon_dev); |
| 2710 | goto exit_remove_files; |
| 2711 | } |
| 2712 | |
| 2713 | return 0; |
| 2714 | |
| 2715 | exit_remove_files: |
| 2716 | dme1737_remove_files(dev); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2717 | return err; |
| 2718 | } |
| 2719 | |
Bill Pemberton | 281dfd0 | 2012-11-19 13:25:51 -0500 | [diff] [blame] | 2720 | static int dme1737_isa_remove(struct platform_device *pdev) |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2721 | { |
| 2722 | struct dme1737_data *data = platform_get_drvdata(pdev); |
| 2723 | |
| 2724 | hwmon_device_unregister(data->hwmon_dev); |
| 2725 | dme1737_remove_files(&pdev->dev); |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2726 | |
| 2727 | return 0; |
| 2728 | } |
| 2729 | |
| 2730 | static struct platform_driver dme1737_isa_driver = { |
| 2731 | .driver = { |
| 2732 | .owner = THIS_MODULE, |
| 2733 | .name = "dme1737", |
| 2734 | }, |
| 2735 | .probe = dme1737_isa_probe, |
Bill Pemberton | 9e5e9b7 | 2012-11-19 13:21:20 -0500 | [diff] [blame] | 2736 | .remove = dme1737_isa_remove, |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2737 | }; |
| 2738 | |
| 2739 | /* --------------------------------------------------------------------- |
Juerg Haefliger | 67e2f32 | 2007-10-01 21:20:28 -0700 | [diff] [blame] | 2740 | * Module initialization and cleanup |
| 2741 | * --------------------------------------------------------------------- */ |
| 2742 | |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2743 | static int __init dme1737_init(void) |
| 2744 | { |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2745 | int err; |
| 2746 | unsigned short addr; |
| 2747 | |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2748 | err = i2c_add_driver(&dme1737_i2c_driver); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2749 | if (err) |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2750 | goto exit; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2751 | |
| 2752 | if (dme1737_isa_detect(0x2e, &addr) && |
Juerg Haefliger | 92430b6 | 2008-04-03 21:34:19 -0700 | [diff] [blame] | 2753 | dme1737_isa_detect(0x4e, &addr) && |
| 2754 | (!probe_all_addr || |
| 2755 | (dme1737_isa_detect(0x162e, &addr) && |
| 2756 | dme1737_isa_detect(0x164e, &addr)))) { |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2757 | /* Return 0 if we didn't find an ISA device */ |
| 2758 | return 0; |
| 2759 | } |
| 2760 | |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2761 | err = platform_driver_register(&dme1737_isa_driver); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2762 | if (err) |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2763 | goto exit_del_i2c_driver; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2764 | |
| 2765 | /* Sets global pdev as a side effect */ |
Juerg Haefliger | 06f3d9f | 2011-01-12 21:55:13 +0100 | [diff] [blame] | 2766 | err = dme1737_isa_device_add(addr); |
Guenter Roeck | c8de836 | 2012-01-14 13:25:01 -0800 | [diff] [blame] | 2767 | if (err) |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2768 | goto exit_del_isa_driver; |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2769 | |
| 2770 | return 0; |
| 2771 | |
| 2772 | exit_del_isa_driver: |
| 2773 | platform_driver_unregister(&dme1737_isa_driver); |
| 2774 | exit_del_i2c_driver: |
| 2775 | i2c_del_driver(&dme1737_i2c_driver); |
| 2776 | exit: |
| 2777 | return err; |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | static void __exit dme1737_exit(void) |
| 2781 | { |
Juerg Haefliger | e95c237 | 2007-10-07 21:27:35 -0700 | [diff] [blame] | 2782 | if (pdev) { |
| 2783 | platform_device_unregister(pdev); |
| 2784 | platform_driver_unregister(&dme1737_isa_driver); |
| 2785 | } |
| 2786 | |
Juerg Haefliger | b237eb2 | 2007-10-01 21:19:04 -0700 | [diff] [blame] | 2787 | i2c_del_driver(&dme1737_i2c_driver); |
Juerg Haefliger | 9431996 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>"); |
| 2791 | MODULE_DESCRIPTION("DME1737 sensors"); |
| 2792 | MODULE_LICENSE("GPL"); |
| 2793 | |
| 2794 | module_init(dme1737_init); |
| 2795 | module_exit(dme1737_exit); |