| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Driver for Linear Technology LTC4222 Dual Hot Swap controller |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (c) 2014 Guenter Roeck |
|---|
| 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; either version 2 of the License, or |
|---|
| 9 | | - * (at your option) any later version. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | 6 | */ |
|---|
| 16 | 7 | |
|---|
| 17 | 8 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 94 | 85 | return val; |
|---|
| 95 | 86 | } |
|---|
| 96 | 87 | |
|---|
| 97 | | -static ssize_t ltc4222_show_value(struct device *dev, |
|---|
| 88 | +static ssize_t ltc4222_value_show(struct device *dev, |
|---|
| 98 | 89 | struct device_attribute *da, char *buf) |
|---|
| 99 | 90 | { |
|---|
| 100 | 91 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| .. | .. |
|---|
| 106 | 97 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
|---|
| 107 | 98 | } |
|---|
| 108 | 99 | |
|---|
| 109 | | -static ssize_t ltc4222_show_bool(struct device *dev, |
|---|
| 100 | +static ssize_t ltc4222_bool_show(struct device *dev, |
|---|
| 110 | 101 | struct device_attribute *da, char *buf) |
|---|
| 111 | 102 | { |
|---|
| 112 | 103 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(da); |
|---|
| .. | .. |
|---|
| 125 | 116 | } |
|---|
| 126 | 117 | |
|---|
| 127 | 118 | /* Voltages */ |
|---|
| 128 | | -static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ltc4222_show_value, NULL, |
|---|
| 129 | | - LTC4222_SOURCE1); |
|---|
| 130 | | -static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, ltc4222_show_value, NULL, |
|---|
| 131 | | - LTC4222_ADIN1); |
|---|
| 132 | | -static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, ltc4222_show_value, NULL, |
|---|
| 133 | | - LTC4222_SOURCE2); |
|---|
| 134 | | -static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, ltc4222_show_value, NULL, |
|---|
| 135 | | - LTC4222_ADIN2); |
|---|
| 119 | +static SENSOR_DEVICE_ATTR_RO(in1_input, ltc4222_value, LTC4222_SOURCE1); |
|---|
| 120 | +static SENSOR_DEVICE_ATTR_RO(in2_input, ltc4222_value, LTC4222_ADIN1); |
|---|
| 121 | +static SENSOR_DEVICE_ATTR_RO(in3_input, ltc4222_value, LTC4222_SOURCE2); |
|---|
| 122 | +static SENSOR_DEVICE_ATTR_RO(in4_input, ltc4222_value, LTC4222_ADIN2); |
|---|
| 136 | 123 | |
|---|
| 137 | 124 | /* |
|---|
| 138 | 125 | * Voltage alarms |
|---|
| 139 | 126 | * UV/OV faults are associated with the input voltage, and power bad and fet |
|---|
| 140 | 127 | * faults are associated with the output voltage. |
|---|
| 141 | 128 | */ |
|---|
| 142 | | -static SENSOR_DEVICE_ATTR_2(in1_min_alarm, S_IRUGO, ltc4222_show_bool, NULL, |
|---|
| 143 | | - LTC4222_FAULT1, FAULT_UV); |
|---|
| 144 | | -static SENSOR_DEVICE_ATTR_2(in1_max_alarm, S_IRUGO, ltc4222_show_bool, NULL, |
|---|
| 145 | | - LTC4222_FAULT1, FAULT_OV); |
|---|
| 146 | | -static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, ltc4222_show_bool, NULL, |
|---|
| 147 | | - LTC4222_FAULT1, FAULT_POWER_BAD | FAULT_FET_BAD); |
|---|
| 129 | +static SENSOR_DEVICE_ATTR_2_RO(in1_min_alarm, ltc4222_bool, LTC4222_FAULT1, |
|---|
| 130 | + FAULT_UV); |
|---|
| 131 | +static SENSOR_DEVICE_ATTR_2_RO(in1_max_alarm, ltc4222_bool, LTC4222_FAULT1, |
|---|
| 132 | + FAULT_OV); |
|---|
| 133 | +static SENSOR_DEVICE_ATTR_2_RO(in2_alarm, ltc4222_bool, LTC4222_FAULT1, |
|---|
| 134 | + FAULT_POWER_BAD | FAULT_FET_BAD); |
|---|
| 148 | 135 | |
|---|
| 149 | | -static SENSOR_DEVICE_ATTR_2(in3_min_alarm, S_IRUGO, ltc4222_show_bool, NULL, |
|---|
| 150 | | - LTC4222_FAULT2, FAULT_UV); |
|---|
| 151 | | -static SENSOR_DEVICE_ATTR_2(in3_max_alarm, S_IRUGO, ltc4222_show_bool, NULL, |
|---|
| 152 | | - LTC4222_FAULT2, FAULT_OV); |
|---|
| 153 | | -static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, ltc4222_show_bool, NULL, |
|---|
| 154 | | - LTC4222_FAULT2, FAULT_POWER_BAD | FAULT_FET_BAD); |
|---|
| 136 | +static SENSOR_DEVICE_ATTR_2_RO(in3_min_alarm, ltc4222_bool, LTC4222_FAULT2, |
|---|
| 137 | + FAULT_UV); |
|---|
| 138 | +static SENSOR_DEVICE_ATTR_2_RO(in3_max_alarm, ltc4222_bool, LTC4222_FAULT2, |
|---|
| 139 | + FAULT_OV); |
|---|
| 140 | +static SENSOR_DEVICE_ATTR_2_RO(in4_alarm, ltc4222_bool, LTC4222_FAULT2, |
|---|
| 141 | + FAULT_POWER_BAD | FAULT_FET_BAD); |
|---|
| 155 | 142 | |
|---|
| 156 | 143 | /* Current (via sense resistor) */ |
|---|
| 157 | | -static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4222_show_value, NULL, |
|---|
| 158 | | - LTC4222_SENSE1); |
|---|
| 159 | | -static SENSOR_DEVICE_ATTR(curr2_input, S_IRUGO, ltc4222_show_value, NULL, |
|---|
| 160 | | - LTC4222_SENSE2); |
|---|
| 144 | +static SENSOR_DEVICE_ATTR_RO(curr1_input, ltc4222_value, LTC4222_SENSE1); |
|---|
| 145 | +static SENSOR_DEVICE_ATTR_RO(curr2_input, ltc4222_value, LTC4222_SENSE2); |
|---|
| 161 | 146 | |
|---|
| 162 | 147 | /* Overcurrent alarm */ |
|---|
| 163 | | -static SENSOR_DEVICE_ATTR_2(curr1_max_alarm, S_IRUGO, ltc4222_show_bool, NULL, |
|---|
| 164 | | - LTC4222_FAULT1, FAULT_OC); |
|---|
| 165 | | -static SENSOR_DEVICE_ATTR_2(curr2_max_alarm, S_IRUGO, ltc4222_show_bool, NULL, |
|---|
| 166 | | - LTC4222_FAULT2, FAULT_OC); |
|---|
| 148 | +static SENSOR_DEVICE_ATTR_2_RO(curr1_max_alarm, ltc4222_bool, LTC4222_FAULT1, |
|---|
| 149 | + FAULT_OC); |
|---|
| 150 | +static SENSOR_DEVICE_ATTR_2_RO(curr2_max_alarm, ltc4222_bool, LTC4222_FAULT2, |
|---|
| 151 | + FAULT_OC); |
|---|
| 167 | 152 | |
|---|
| 168 | 153 | static struct attribute *ltc4222_attrs[] = { |
|---|
| 169 | 154 | &sensor_dev_attr_in1_input.dev_attr.attr, |
|---|
| .. | .. |
|---|
| 192 | 177 | .max_register = LTC4222_ADC_CONTROL, |
|---|
| 193 | 178 | }; |
|---|
| 194 | 179 | |
|---|
| 195 | | -static int ltc4222_probe(struct i2c_client *client, |
|---|
| 196 | | - const struct i2c_device_id *id) |
|---|
| 180 | +static int ltc4222_probe(struct i2c_client *client) |
|---|
| 197 | 181 | { |
|---|
| 198 | 182 | struct device *dev = &client->dev; |
|---|
| 199 | 183 | struct device *hwmon_dev; |
|---|
| .. | .. |
|---|
| 226 | 210 | .driver = { |
|---|
| 227 | 211 | .name = "ltc4222", |
|---|
| 228 | 212 | }, |
|---|
| 229 | | - .probe = ltc4222_probe, |
|---|
| 213 | + .probe_new = ltc4222_probe, |
|---|
| 230 | 214 | .id_table = ltc4222_id, |
|---|
| 231 | 215 | }; |
|---|
| 232 | 216 | |
|---|