| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * thmc50.c - Part of lm_sensors, Linux kernel modules for hardware |
|---|
| 3 | 4 | * monitoring |
|---|
| 4 | 5 | * Copyright (C) 2007 Krzysztof Helt <krzysztof.h1@wp.pl> |
|---|
| 5 | 6 | * Based on 2.4 driver by Frodo Looijaard <frodol@dds.nl> and |
|---|
| 6 | 7 | * Philip Edelbrock <phil@netroedge.com> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 10 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | | - * (at your option) any later version. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | | - * GNU General Public License for more details. |
|---|
| 17 | | - * |
|---|
| 18 | | - * You should have received a copy of the GNU General Public License |
|---|
| 19 | | - * along with this program; if not, write to the Free Software |
|---|
| 20 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 21 | 8 | */ |
|---|
| 22 | 9 | |
|---|
| 23 | 10 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 128 | 115 | return data; |
|---|
| 129 | 116 | } |
|---|
| 130 | 117 | |
|---|
| 131 | | -static ssize_t show_analog_out(struct device *dev, |
|---|
| 118 | +static ssize_t analog_out_show(struct device *dev, |
|---|
| 132 | 119 | struct device_attribute *attr, char *buf) |
|---|
| 133 | 120 | { |
|---|
| 134 | 121 | struct thmc50_data *data = thmc50_update_device(dev); |
|---|
| 135 | 122 | return sprintf(buf, "%d\n", data->analog_out); |
|---|
| 136 | 123 | } |
|---|
| 137 | 124 | |
|---|
| 138 | | -static ssize_t set_analog_out(struct device *dev, |
|---|
| 139 | | - struct device_attribute *attr, |
|---|
| 140 | | - const char *buf, size_t count) |
|---|
| 125 | +static ssize_t analog_out_store(struct device *dev, |
|---|
| 126 | + struct device_attribute *attr, |
|---|
| 127 | + const char *buf, size_t count) |
|---|
| 141 | 128 | { |
|---|
| 142 | 129 | struct thmc50_data *data = dev_get_drvdata(dev); |
|---|
| 143 | 130 | struct i2c_client *client = data->client; |
|---|
| .. | .. |
|---|
| 166 | 153 | } |
|---|
| 167 | 154 | |
|---|
| 168 | 155 | /* There is only one PWM mode = DC */ |
|---|
| 169 | | -static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr, |
|---|
| 170 | | - char *buf) |
|---|
| 156 | +static ssize_t pwm_mode_show(struct device *dev, |
|---|
| 157 | + struct device_attribute *attr, char *buf) |
|---|
| 171 | 158 | { |
|---|
| 172 | 159 | return sprintf(buf, "0\n"); |
|---|
| 173 | 160 | } |
|---|
| 174 | 161 | |
|---|
| 175 | 162 | /* Temperatures */ |
|---|
| 176 | | -static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
|---|
| 163 | +static ssize_t temp_show(struct device *dev, struct device_attribute *attr, |
|---|
| 177 | 164 | char *buf) |
|---|
| 178 | 165 | { |
|---|
| 179 | 166 | int nr = to_sensor_dev_attr(attr)->index; |
|---|
| .. | .. |
|---|
| 181 | 168 | return sprintf(buf, "%d\n", data->temp_input[nr] * 1000); |
|---|
| 182 | 169 | } |
|---|
| 183 | 170 | |
|---|
| 184 | | -static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, |
|---|
| 185 | | - char *buf) |
|---|
| 171 | +static ssize_t temp_min_show(struct device *dev, |
|---|
| 172 | + struct device_attribute *attr, char *buf) |
|---|
| 186 | 173 | { |
|---|
| 187 | 174 | int nr = to_sensor_dev_attr(attr)->index; |
|---|
| 188 | 175 | struct thmc50_data *data = thmc50_update_device(dev); |
|---|
| 189 | 176 | return sprintf(buf, "%d\n", data->temp_min[nr] * 1000); |
|---|
| 190 | 177 | } |
|---|
| 191 | 178 | |
|---|
| 192 | | -static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
|---|
| 193 | | - const char *buf, size_t count) |
|---|
| 179 | +static ssize_t temp_min_store(struct device *dev, |
|---|
| 180 | + struct device_attribute *attr, const char *buf, |
|---|
| 181 | + size_t count) |
|---|
| 194 | 182 | { |
|---|
| 195 | 183 | int nr = to_sensor_dev_attr(attr)->index; |
|---|
| 196 | 184 | struct thmc50_data *data = dev_get_drvdata(dev); |
|---|
| .. | .. |
|---|
| 210 | 198 | return count; |
|---|
| 211 | 199 | } |
|---|
| 212 | 200 | |
|---|
| 213 | | -static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
|---|
| 214 | | - char *buf) |
|---|
| 201 | +static ssize_t temp_max_show(struct device *dev, |
|---|
| 202 | + struct device_attribute *attr, char *buf) |
|---|
| 215 | 203 | { |
|---|
| 216 | 204 | int nr = to_sensor_dev_attr(attr)->index; |
|---|
| 217 | 205 | struct thmc50_data *data = thmc50_update_device(dev); |
|---|
| 218 | 206 | return sprintf(buf, "%d\n", data->temp_max[nr] * 1000); |
|---|
| 219 | 207 | } |
|---|
| 220 | 208 | |
|---|
| 221 | | -static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
|---|
| 222 | | - const char *buf, size_t count) |
|---|
| 209 | +static ssize_t temp_max_store(struct device *dev, |
|---|
| 210 | + struct device_attribute *attr, const char *buf, |
|---|
| 211 | + size_t count) |
|---|
| 223 | 212 | { |
|---|
| 224 | 213 | int nr = to_sensor_dev_attr(attr)->index; |
|---|
| 225 | 214 | struct thmc50_data *data = dev_get_drvdata(dev); |
|---|
| .. | .. |
|---|
| 239 | 228 | return count; |
|---|
| 240 | 229 | } |
|---|
| 241 | 230 | |
|---|
| 242 | | -static ssize_t show_temp_critical(struct device *dev, |
|---|
| 243 | | - struct device_attribute *attr, |
|---|
| 244 | | - char *buf) |
|---|
| 231 | +static ssize_t temp_critical_show(struct device *dev, |
|---|
| 232 | + struct device_attribute *attr, char *buf) |
|---|
| 245 | 233 | { |
|---|
| 246 | 234 | int nr = to_sensor_dev_attr(attr)->index; |
|---|
| 247 | 235 | struct thmc50_data *data = thmc50_update_device(dev); |
|---|
| 248 | 236 | return sprintf(buf, "%d\n", data->temp_critical[nr] * 1000); |
|---|
| 249 | 237 | } |
|---|
| 250 | 238 | |
|---|
| 251 | | -static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
|---|
| 239 | +static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, |
|---|
| 252 | 240 | char *buf) |
|---|
| 253 | 241 | { |
|---|
| 254 | 242 | int index = to_sensor_dev_attr(attr)->index; |
|---|
| .. | .. |
|---|
| 257 | 245 | return sprintf(buf, "%u\n", (data->alarms >> index) & 1); |
|---|
| 258 | 246 | } |
|---|
| 259 | 247 | |
|---|
| 260 | | -#define temp_reg(offset) \ |
|---|
| 261 | | -static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp, \ |
|---|
| 262 | | - NULL, offset - 1); \ |
|---|
| 263 | | -static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
|---|
| 264 | | - show_temp_min, set_temp_min, offset - 1); \ |
|---|
| 265 | | -static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
|---|
| 266 | | - show_temp_max, set_temp_max, offset - 1); \ |
|---|
| 267 | | -static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO, \ |
|---|
| 268 | | - show_temp_critical, NULL, offset - 1); |
|---|
| 248 | +static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0); |
|---|
| 249 | +static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0); |
|---|
| 250 | +static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0); |
|---|
| 251 | +static SENSOR_DEVICE_ATTR_RO(temp1_crit, temp_critical, 0); |
|---|
| 252 | +static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1); |
|---|
| 253 | +static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1); |
|---|
| 254 | +static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1); |
|---|
| 255 | +static SENSOR_DEVICE_ATTR_RO(temp2_crit, temp_critical, 1); |
|---|
| 256 | +static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2); |
|---|
| 257 | +static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2); |
|---|
| 258 | +static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2); |
|---|
| 259 | +static SENSOR_DEVICE_ATTR_RO(temp3_crit, temp_critical, 2); |
|---|
| 269 | 260 | |
|---|
| 270 | | -temp_reg(1); |
|---|
| 271 | | -temp_reg(2); |
|---|
| 272 | | -temp_reg(3); |
|---|
| 261 | +static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 0); |
|---|
| 262 | +static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 5); |
|---|
| 263 | +static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 1); |
|---|
| 264 | +static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 7); |
|---|
| 265 | +static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 2); |
|---|
| 273 | 266 | |
|---|
| 274 | | -static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0); |
|---|
| 275 | | -static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5); |
|---|
| 276 | | -static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 1); |
|---|
| 277 | | -static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 7); |
|---|
| 278 | | -static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 2); |
|---|
| 279 | | - |
|---|
| 280 | | -static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_analog_out, |
|---|
| 281 | | - set_analog_out, 0); |
|---|
| 282 | | -static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0); |
|---|
| 267 | +static SENSOR_DEVICE_ATTR_RW(pwm1, analog_out, 0); |
|---|
| 268 | +static SENSOR_DEVICE_ATTR_RO(pwm1_mode, pwm_mode, 0); |
|---|
| 283 | 269 | |
|---|
| 284 | 270 | static struct attribute *thmc50_attributes[] = { |
|---|
| 285 | 271 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
|---|
| .. | .. |
|---|
| 391 | 377 | i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config); |
|---|
| 392 | 378 | } |
|---|
| 393 | 379 | |
|---|
| 394 | | -static int thmc50_probe(struct i2c_client *client, |
|---|
| 395 | | - const struct i2c_device_id *id) |
|---|
| 380 | +static const struct i2c_device_id thmc50_id[]; |
|---|
| 381 | + |
|---|
| 382 | +static int thmc50_probe(struct i2c_client *client) |
|---|
| 396 | 383 | { |
|---|
| 397 | 384 | struct device *dev = &client->dev; |
|---|
| 398 | 385 | struct thmc50_data *data; |
|---|
| .. | .. |
|---|
| 404 | 391 | return -ENOMEM; |
|---|
| 405 | 392 | |
|---|
| 406 | 393 | data->client = client; |
|---|
| 407 | | - data->type = id->driver_data; |
|---|
| 394 | + data->type = i2c_match_id(thmc50_id, client)->driver_data; |
|---|
| 408 | 395 | mutex_init(&data->update_lock); |
|---|
| 409 | 396 | |
|---|
| 410 | 397 | thmc50_init_client(data); |
|---|
| .. | .. |
|---|
| 433 | 420 | .driver = { |
|---|
| 434 | 421 | .name = "thmc50", |
|---|
| 435 | 422 | }, |
|---|
| 436 | | - .probe = thmc50_probe, |
|---|
| 423 | + .probe_new = thmc50_probe, |
|---|
| 437 | 424 | .id_table = thmc50_id, |
|---|
| 438 | 425 | .detect = thmc50_detect, |
|---|
| 439 | 426 | .address_list = normal_i2c, |
|---|