| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Driver for Linear Technology LTC4215 I2C Hot Swap Controller |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2009 Ira W. Snyder <iws@ovro.caltech.edu> |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 8 | | - * the Free Software Foundation; version 2 of the License. |
|---|
| 9 | 6 | * |
|---|
| 10 | 7 | * Datasheet: |
|---|
| 11 | 8 | * http://www.linear.com/pc/downloadDocument.do?navId=H0,C1,C1003,C1006,C1163,P17572,D12697 |
|---|
| .. | .. |
|---|
| 136 | 133 | return curr; |
|---|
| 137 | 134 | } |
|---|
| 138 | 135 | |
|---|
| 139 | | -static ssize_t ltc4215_show_voltage(struct device *dev, |
|---|
| 140 | | - struct device_attribute *da, |
|---|
| 141 | | - char *buf) |
|---|
| 136 | +static ssize_t ltc4215_voltage_show(struct device *dev, |
|---|
| 137 | + struct device_attribute *da, char *buf) |
|---|
| 142 | 138 | { |
|---|
| 143 | 139 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 144 | 140 | const int voltage = ltc4215_get_voltage(dev, attr->index); |
|---|
| .. | .. |
|---|
| 146 | 142 | return snprintf(buf, PAGE_SIZE, "%d\n", voltage); |
|---|
| 147 | 143 | } |
|---|
| 148 | 144 | |
|---|
| 149 | | -static ssize_t ltc4215_show_current(struct device *dev, |
|---|
| 150 | | - struct device_attribute *da, |
|---|
| 151 | | - char *buf) |
|---|
| 145 | +static ssize_t ltc4215_current_show(struct device *dev, |
|---|
| 146 | + struct device_attribute *da, char *buf) |
|---|
| 152 | 147 | { |
|---|
| 153 | 148 | const unsigned int curr = ltc4215_get_current(dev); |
|---|
| 154 | 149 | |
|---|
| 155 | 150 | return snprintf(buf, PAGE_SIZE, "%u\n", curr); |
|---|
| 156 | 151 | } |
|---|
| 157 | 152 | |
|---|
| 158 | | -static ssize_t ltc4215_show_power(struct device *dev, |
|---|
| 159 | | - struct device_attribute *da, |
|---|
| 160 | | - char *buf) |
|---|
| 153 | +static ssize_t ltc4215_power_show(struct device *dev, |
|---|
| 154 | + struct device_attribute *da, char *buf) |
|---|
| 161 | 155 | { |
|---|
| 162 | 156 | const unsigned int curr = ltc4215_get_current(dev); |
|---|
| 163 | 157 | const int output_voltage = ltc4215_get_voltage(dev, LTC4215_ADIN); |
|---|
| .. | .. |
|---|
| 168 | 162 | return snprintf(buf, PAGE_SIZE, "%u\n", power); |
|---|
| 169 | 163 | } |
|---|
| 170 | 164 | |
|---|
| 171 | | -static ssize_t ltc4215_show_alarm(struct device *dev, |
|---|
| 172 | | - struct device_attribute *da, |
|---|
| 173 | | - char *buf) |
|---|
| 165 | +static ssize_t ltc4215_alarm_show(struct device *dev, |
|---|
| 166 | + struct device_attribute *da, char *buf) |
|---|
| 174 | 167 | { |
|---|
| 175 | 168 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 176 | 169 | struct ltc4215_data *data = ltc4215_update_device(dev); |
|---|
| .. | .. |
|---|
| 189 | 182 | /* Construct a sensor_device_attribute structure for each register */ |
|---|
| 190 | 183 | |
|---|
| 191 | 184 | /* Current */ |
|---|
| 192 | | -static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4215_show_current, NULL, 0); |
|---|
| 193 | | -static SENSOR_DEVICE_ATTR(curr1_max_alarm, S_IRUGO, ltc4215_show_alarm, NULL, |
|---|
| 194 | | - 1 << 2); |
|---|
| 185 | +static SENSOR_DEVICE_ATTR_RO(curr1_input, ltc4215_current, 0); |
|---|
| 186 | +static SENSOR_DEVICE_ATTR_RO(curr1_max_alarm, ltc4215_alarm, 1 << 2); |
|---|
| 195 | 187 | |
|---|
| 196 | 188 | /* Power (virtual) */ |
|---|
| 197 | | -static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ltc4215_show_power, NULL, 0); |
|---|
| 189 | +static SENSOR_DEVICE_ATTR_RO(power1_input, ltc4215_power, 0); |
|---|
| 198 | 190 | |
|---|
| 199 | 191 | /* Input Voltage */ |
|---|
| 200 | | -static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ltc4215_show_voltage, NULL, |
|---|
| 201 | | - LTC4215_ADIN); |
|---|
| 202 | | -static SENSOR_DEVICE_ATTR(in1_max_alarm, S_IRUGO, ltc4215_show_alarm, NULL, |
|---|
| 203 | | - 1 << 0); |
|---|
| 204 | | -static SENSOR_DEVICE_ATTR(in1_min_alarm, S_IRUGO, ltc4215_show_alarm, NULL, |
|---|
| 205 | | - 1 << 1); |
|---|
| 192 | +static SENSOR_DEVICE_ATTR_RO(in1_input, ltc4215_voltage, LTC4215_ADIN); |
|---|
| 193 | +static SENSOR_DEVICE_ATTR_RO(in1_max_alarm, ltc4215_alarm, 1 << 0); |
|---|
| 194 | +static SENSOR_DEVICE_ATTR_RO(in1_min_alarm, ltc4215_alarm, 1 << 1); |
|---|
| 206 | 195 | |
|---|
| 207 | 196 | /* Output Voltage */ |
|---|
| 208 | | -static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, ltc4215_show_voltage, NULL, |
|---|
| 209 | | - LTC4215_SOURCE); |
|---|
| 210 | | -static SENSOR_DEVICE_ATTR(in2_min_alarm, S_IRUGO, ltc4215_show_alarm, NULL, |
|---|
| 211 | | - 1 << 3); |
|---|
| 197 | +static SENSOR_DEVICE_ATTR_RO(in2_input, ltc4215_voltage, LTC4215_SOURCE); |
|---|
| 198 | +static SENSOR_DEVICE_ATTR_RO(in2_min_alarm, ltc4215_alarm, 1 << 3); |
|---|
| 212 | 199 | |
|---|
| 213 | 200 | /* |
|---|
| 214 | 201 | * Finally, construct an array of pointers to members of the above objects, |
|---|
| .. | .. |
|---|
| 231 | 218 | }; |
|---|
| 232 | 219 | ATTRIBUTE_GROUPS(ltc4215); |
|---|
| 233 | 220 | |
|---|
| 234 | | -static int ltc4215_probe(struct i2c_client *client, |
|---|
| 235 | | - const struct i2c_device_id *id) |
|---|
| 221 | +static int ltc4215_probe(struct i2c_client *client) |
|---|
| 236 | 222 | { |
|---|
| 237 | 223 | struct i2c_adapter *adapter = client->adapter; |
|---|
| 238 | 224 | struct device *dev = &client->dev; |
|---|
| .. | .. |
|---|
| 269 | 255 | .driver = { |
|---|
| 270 | 256 | .name = "ltc4215", |
|---|
| 271 | 257 | }, |
|---|
| 272 | | - .probe = ltc4215_probe, |
|---|
| 258 | + .probe_new = ltc4215_probe, |
|---|
| 273 | 259 | .id_table = ltc4215_id, |
|---|
| 274 | 260 | }; |
|---|
| 275 | 261 | |
|---|