| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * powr1220.c - Driver for the Lattice POWR1220 programmable power supply |
|---|
| 3 | 4 | * and monitor. Users can read all ADC inputs along with their labels |
|---|
| 4 | 5 | * using the sysfs nodes. |
|---|
| 5 | 6 | * |
|---|
| 6 | | - * Copyright (c) 2014 Echo360 http://www.echo360.com |
|---|
| 7 | + * Copyright (c) 2014 Echo360 https://www.echo360.com |
|---|
| 7 | 8 | * Scott Kanowitz <skanowitz@echo360.com> <scott.kanowitz@gmail.com> |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 10 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 11 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 | | - * (at your option) any later version. |
|---|
| 13 | | - * |
|---|
| 14 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 15 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | | - * GNU General Public License for more details. |
|---|
| 18 | 9 | */ |
|---|
| 19 | 10 | |
|---|
| 20 | 11 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 177 | 168 | } |
|---|
| 178 | 169 | |
|---|
| 179 | 170 | /* Shows the voltage associated with the specified ADC channel */ |
|---|
| 180 | | -static ssize_t powr1220_show_voltage(struct device *dev, |
|---|
| 181 | | - struct device_attribute *dev_attr, char *buf) |
|---|
| 171 | +static ssize_t powr1220_voltage_show(struct device *dev, |
|---|
| 172 | + struct device_attribute *dev_attr, |
|---|
| 173 | + char *buf) |
|---|
| 182 | 174 | { |
|---|
| 183 | 175 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
|---|
| 184 | 176 | int adc_val = powr1220_read_adc(dev, attr->index); |
|---|
| .. | .. |
|---|
| 190 | 182 | } |
|---|
| 191 | 183 | |
|---|
| 192 | 184 | /* Shows the maximum setting associated with the specified ADC channel */ |
|---|
| 193 | | -static ssize_t powr1220_show_max(struct device *dev, |
|---|
| 194 | | - struct device_attribute *dev_attr, char *buf) |
|---|
| 185 | +static ssize_t powr1220_max_show(struct device *dev, |
|---|
| 186 | + struct device_attribute *dev_attr, char *buf) |
|---|
| 195 | 187 | { |
|---|
| 196 | 188 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
|---|
| 197 | 189 | struct powr1220_data *data = dev_get_drvdata(dev); |
|---|
| .. | .. |
|---|
| 200 | 192 | } |
|---|
| 201 | 193 | |
|---|
| 202 | 194 | /* Shows the label associated with the specified ADC channel */ |
|---|
| 203 | | -static ssize_t powr1220_show_label(struct device *dev, |
|---|
| 204 | | - struct device_attribute *dev_attr, char *buf) |
|---|
| 195 | +static ssize_t powr1220_label_show(struct device *dev, |
|---|
| 196 | + struct device_attribute *dev_attr, |
|---|
| 197 | + char *buf) |
|---|
| 205 | 198 | { |
|---|
| 206 | 199 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
|---|
| 207 | 200 | |
|---|
| 208 | 201 | return sprintf(buf, "%s\n", input_names[attr->index]); |
|---|
| 209 | 202 | } |
|---|
| 210 | 203 | |
|---|
| 211 | | -static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 212 | | - VMON1); |
|---|
| 213 | | -static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 214 | | - VMON2); |
|---|
| 215 | | -static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 216 | | - VMON3); |
|---|
| 217 | | -static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 218 | | - VMON4); |
|---|
| 219 | | -static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 220 | | - VMON5); |
|---|
| 221 | | -static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 222 | | - VMON6); |
|---|
| 223 | | -static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 224 | | - VMON7); |
|---|
| 225 | | -static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 226 | | - VMON8); |
|---|
| 227 | | -static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 228 | | - VMON9); |
|---|
| 229 | | -static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 230 | | - VMON10); |
|---|
| 231 | | -static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 232 | | - VMON11); |
|---|
| 233 | | -static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 234 | | - VMON12); |
|---|
| 235 | | -static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 236 | | - VCCA); |
|---|
| 237 | | -static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, powr1220_show_voltage, NULL, |
|---|
| 238 | | - VCCINP); |
|---|
| 204 | +static SENSOR_DEVICE_ATTR_RO(in0_input, powr1220_voltage, VMON1); |
|---|
| 205 | +static SENSOR_DEVICE_ATTR_RO(in1_input, powr1220_voltage, VMON2); |
|---|
| 206 | +static SENSOR_DEVICE_ATTR_RO(in2_input, powr1220_voltage, VMON3); |
|---|
| 207 | +static SENSOR_DEVICE_ATTR_RO(in3_input, powr1220_voltage, VMON4); |
|---|
| 208 | +static SENSOR_DEVICE_ATTR_RO(in4_input, powr1220_voltage, VMON5); |
|---|
| 209 | +static SENSOR_DEVICE_ATTR_RO(in5_input, powr1220_voltage, VMON6); |
|---|
| 210 | +static SENSOR_DEVICE_ATTR_RO(in6_input, powr1220_voltage, VMON7); |
|---|
| 211 | +static SENSOR_DEVICE_ATTR_RO(in7_input, powr1220_voltage, VMON8); |
|---|
| 212 | +static SENSOR_DEVICE_ATTR_RO(in8_input, powr1220_voltage, VMON9); |
|---|
| 213 | +static SENSOR_DEVICE_ATTR_RO(in9_input, powr1220_voltage, VMON10); |
|---|
| 214 | +static SENSOR_DEVICE_ATTR_RO(in10_input, powr1220_voltage, VMON11); |
|---|
| 215 | +static SENSOR_DEVICE_ATTR_RO(in11_input, powr1220_voltage, VMON12); |
|---|
| 216 | +static SENSOR_DEVICE_ATTR_RO(in12_input, powr1220_voltage, VCCA); |
|---|
| 217 | +static SENSOR_DEVICE_ATTR_RO(in13_input, powr1220_voltage, VCCINP); |
|---|
| 239 | 218 | |
|---|
| 240 | | -static SENSOR_DEVICE_ATTR(in0_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 241 | | - VMON1); |
|---|
| 242 | | -static SENSOR_DEVICE_ATTR(in1_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 243 | | - VMON2); |
|---|
| 244 | | -static SENSOR_DEVICE_ATTR(in2_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 245 | | - VMON3); |
|---|
| 246 | | -static SENSOR_DEVICE_ATTR(in3_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 247 | | - VMON4); |
|---|
| 248 | | -static SENSOR_DEVICE_ATTR(in4_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 249 | | - VMON5); |
|---|
| 250 | | -static SENSOR_DEVICE_ATTR(in5_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 251 | | - VMON6); |
|---|
| 252 | | -static SENSOR_DEVICE_ATTR(in6_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 253 | | - VMON7); |
|---|
| 254 | | -static SENSOR_DEVICE_ATTR(in7_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 255 | | - VMON8); |
|---|
| 256 | | -static SENSOR_DEVICE_ATTR(in8_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 257 | | - VMON9); |
|---|
| 258 | | -static SENSOR_DEVICE_ATTR(in9_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 259 | | - VMON10); |
|---|
| 260 | | -static SENSOR_DEVICE_ATTR(in10_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 261 | | - VMON11); |
|---|
| 262 | | -static SENSOR_DEVICE_ATTR(in11_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 263 | | - VMON12); |
|---|
| 264 | | -static SENSOR_DEVICE_ATTR(in12_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 265 | | - VCCA); |
|---|
| 266 | | -static SENSOR_DEVICE_ATTR(in13_highest, S_IRUGO, powr1220_show_max, NULL, |
|---|
| 267 | | - VCCINP); |
|---|
| 219 | +static SENSOR_DEVICE_ATTR_RO(in0_highest, powr1220_max, VMON1); |
|---|
| 220 | +static SENSOR_DEVICE_ATTR_RO(in1_highest, powr1220_max, VMON2); |
|---|
| 221 | +static SENSOR_DEVICE_ATTR_RO(in2_highest, powr1220_max, VMON3); |
|---|
| 222 | +static SENSOR_DEVICE_ATTR_RO(in3_highest, powr1220_max, VMON4); |
|---|
| 223 | +static SENSOR_DEVICE_ATTR_RO(in4_highest, powr1220_max, VMON5); |
|---|
| 224 | +static SENSOR_DEVICE_ATTR_RO(in5_highest, powr1220_max, VMON6); |
|---|
| 225 | +static SENSOR_DEVICE_ATTR_RO(in6_highest, powr1220_max, VMON7); |
|---|
| 226 | +static SENSOR_DEVICE_ATTR_RO(in7_highest, powr1220_max, VMON8); |
|---|
| 227 | +static SENSOR_DEVICE_ATTR_RO(in8_highest, powr1220_max, VMON9); |
|---|
| 228 | +static SENSOR_DEVICE_ATTR_RO(in9_highest, powr1220_max, VMON10); |
|---|
| 229 | +static SENSOR_DEVICE_ATTR_RO(in10_highest, powr1220_max, VMON11); |
|---|
| 230 | +static SENSOR_DEVICE_ATTR_RO(in11_highest, powr1220_max, VMON12); |
|---|
| 231 | +static SENSOR_DEVICE_ATTR_RO(in12_highest, powr1220_max, VCCA); |
|---|
| 232 | +static SENSOR_DEVICE_ATTR_RO(in13_highest, powr1220_max, VCCINP); |
|---|
| 268 | 233 | |
|---|
| 269 | | -static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 270 | | - VMON1); |
|---|
| 271 | | -static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 272 | | - VMON2); |
|---|
| 273 | | -static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 274 | | - VMON3); |
|---|
| 275 | | -static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 276 | | - VMON4); |
|---|
| 277 | | -static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 278 | | - VMON5); |
|---|
| 279 | | -static SENSOR_DEVICE_ATTR(in5_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 280 | | - VMON6); |
|---|
| 281 | | -static SENSOR_DEVICE_ATTR(in6_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 282 | | - VMON7); |
|---|
| 283 | | -static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 284 | | - VMON8); |
|---|
| 285 | | -static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 286 | | - VMON9); |
|---|
| 287 | | -static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 288 | | - VMON10); |
|---|
| 289 | | -static SENSOR_DEVICE_ATTR(in10_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 290 | | - VMON11); |
|---|
| 291 | | -static SENSOR_DEVICE_ATTR(in11_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 292 | | - VMON12); |
|---|
| 293 | | -static SENSOR_DEVICE_ATTR(in12_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 294 | | - VCCA); |
|---|
| 295 | | -static SENSOR_DEVICE_ATTR(in13_label, S_IRUGO, powr1220_show_label, NULL, |
|---|
| 296 | | - VCCINP); |
|---|
| 234 | +static SENSOR_DEVICE_ATTR_RO(in0_label, powr1220_label, VMON1); |
|---|
| 235 | +static SENSOR_DEVICE_ATTR_RO(in1_label, powr1220_label, VMON2); |
|---|
| 236 | +static SENSOR_DEVICE_ATTR_RO(in2_label, powr1220_label, VMON3); |
|---|
| 237 | +static SENSOR_DEVICE_ATTR_RO(in3_label, powr1220_label, VMON4); |
|---|
| 238 | +static SENSOR_DEVICE_ATTR_RO(in4_label, powr1220_label, VMON5); |
|---|
| 239 | +static SENSOR_DEVICE_ATTR_RO(in5_label, powr1220_label, VMON6); |
|---|
| 240 | +static SENSOR_DEVICE_ATTR_RO(in6_label, powr1220_label, VMON7); |
|---|
| 241 | +static SENSOR_DEVICE_ATTR_RO(in7_label, powr1220_label, VMON8); |
|---|
| 242 | +static SENSOR_DEVICE_ATTR_RO(in8_label, powr1220_label, VMON9); |
|---|
| 243 | +static SENSOR_DEVICE_ATTR_RO(in9_label, powr1220_label, VMON10); |
|---|
| 244 | +static SENSOR_DEVICE_ATTR_RO(in10_label, powr1220_label, VMON11); |
|---|
| 245 | +static SENSOR_DEVICE_ATTR_RO(in11_label, powr1220_label, VMON12); |
|---|
| 246 | +static SENSOR_DEVICE_ATTR_RO(in12_label, powr1220_label, VCCA); |
|---|
| 247 | +static SENSOR_DEVICE_ATTR_RO(in13_label, powr1220_label, VCCINP); |
|---|
| 297 | 248 | |
|---|
| 298 | 249 | static struct attribute *powr1220_attrs[] = { |
|---|
| 299 | 250 | &sensor_dev_attr_in0_input.dev_attr.attr, |
|---|
| .. | .. |
|---|
| 346 | 297 | |
|---|
| 347 | 298 | ATTRIBUTE_GROUPS(powr1220); |
|---|
| 348 | 299 | |
|---|
| 349 | | -static int powr1220_probe(struct i2c_client *client, |
|---|
| 350 | | - const struct i2c_device_id *id) |
|---|
| 300 | +static int powr1220_probe(struct i2c_client *client) |
|---|
| 351 | 301 | { |
|---|
| 352 | 302 | struct powr1220_data *data; |
|---|
| 353 | 303 | struct device *hwmon_dev; |
|---|
| .. | .. |
|---|
| 380 | 330 | .driver = { |
|---|
| 381 | 331 | .name = "powr1220", |
|---|
| 382 | 332 | }, |
|---|
| 383 | | - .probe = powr1220_probe, |
|---|
| 333 | + .probe_new = powr1220_probe, |
|---|
| 384 | 334 | .id_table = powr1220_ids, |
|---|
| 385 | 335 | }; |
|---|
| 386 | 336 | |
|---|