diff options
| -rw-r--r-- | drivers/hwmon/vexpress.c | 82 |
1 files changed, 28 insertions, 54 deletions
diff --git a/drivers/hwmon/vexpress.c b/drivers/hwmon/vexpress.c index 611f34c7333d..c53619086f33 100644 --- a/drivers/hwmon/vexpress.c +++ b/drivers/hwmon/vexpress.c | |||
| @@ -27,17 +27,8 @@ | |||
| 27 | struct vexpress_hwmon_data { | 27 | struct vexpress_hwmon_data { |
| 28 | struct device *hwmon_dev; | 28 | struct device *hwmon_dev; |
| 29 | struct regmap *reg; | 29 | struct regmap *reg; |
| 30 | const char *name; | ||
| 31 | }; | 30 | }; |
| 32 | 31 | ||
| 33 | static ssize_t vexpress_hwmon_name_show(struct device *dev, | ||
| 34 | struct device_attribute *dev_attr, char *buffer) | ||
| 35 | { | ||
| 36 | struct vexpress_hwmon_data *data = dev_get_drvdata(dev); | ||
| 37 | |||
| 38 | return sprintf(buffer, "%s\n", data->name); | ||
| 39 | } | ||
| 40 | |||
| 41 | static ssize_t vexpress_hwmon_label_show(struct device *dev, | 32 | static ssize_t vexpress_hwmon_label_show(struct device *dev, |
| 42 | struct device_attribute *dev_attr, char *buffer) | 33 | struct device_attribute *dev_attr, char *buffer) |
| 43 | { | 34 | { |
| @@ -95,16 +86,6 @@ static umode_t vexpress_hwmon_attr_is_visible(struct kobject *kobj, | |||
| 95 | return attr->mode; | 86 | return attr->mode; |
| 96 | } | 87 | } |
| 97 | 88 | ||
| 98 | static DEVICE_ATTR(name, S_IRUGO, vexpress_hwmon_name_show, NULL); | ||
| 99 | |||
| 100 | #define VEXPRESS_HWMON_ATTRS(_name, _label_attr, _input_attr) \ | ||
| 101 | struct attribute *vexpress_hwmon_attrs_##_name[] = { \ | ||
| 102 | &dev_attr_name.attr, \ | ||
| 103 | &dev_attr_##_label_attr.attr, \ | ||
| 104 | &sensor_dev_attr_##_input_attr.dev_attr.attr, \ | ||
| 105 | NULL \ | ||
| 106 | } | ||
| 107 | |||
| 108 | struct vexpress_hwmon_type { | 89 | struct vexpress_hwmon_type { |
| 109 | const char *name; | 90 | const char *name; |
| 110 | const struct attribute_group **attr_groups; | 91 | const struct attribute_group **attr_groups; |
| @@ -114,7 +95,11 @@ struct vexpress_hwmon_type { | |||
| 114 | static DEVICE_ATTR(in1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); | 95 | static DEVICE_ATTR(in1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); |
| 115 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, vexpress_hwmon_u32_show, | 96 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, vexpress_hwmon_u32_show, |
| 116 | NULL, 1000); | 97 | NULL, 1000); |
| 117 | static VEXPRESS_HWMON_ATTRS(volt, in1_label, in1_input); | 98 | static struct attribute *vexpress_hwmon_attrs_volt[] = { |
| 99 | &dev_attr_in1_label.attr, | ||
| 100 | &sensor_dev_attr_in1_input.dev_attr.attr, | ||
| 101 | NULL | ||
| 102 | }; | ||
| 118 | static struct attribute_group vexpress_hwmon_group_volt = { | 103 | static struct attribute_group vexpress_hwmon_group_volt = { |
| 119 | .is_visible = vexpress_hwmon_attr_is_visible, | 104 | .is_visible = vexpress_hwmon_attr_is_visible, |
| 120 | .attrs = vexpress_hwmon_attrs_volt, | 105 | .attrs = vexpress_hwmon_attrs_volt, |
| @@ -131,7 +116,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_volt = { | |||
| 131 | static DEVICE_ATTR(curr1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); | 116 | static DEVICE_ATTR(curr1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); |
| 132 | static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, vexpress_hwmon_u32_show, | 117 | static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, vexpress_hwmon_u32_show, |
| 133 | NULL, 1000); | 118 | NULL, 1000); |
| 134 | static VEXPRESS_HWMON_ATTRS(amp, curr1_label, curr1_input); | 119 | static struct attribute *vexpress_hwmon_attrs_amp[] = { |
| 120 | &dev_attr_curr1_label.attr, | ||
| 121 | &sensor_dev_attr_curr1_input.dev_attr.attr, | ||
| 122 | NULL | ||
| 123 | }; | ||
| 135 | static struct attribute_group vexpress_hwmon_group_amp = { | 124 | static struct attribute_group vexpress_hwmon_group_amp = { |
| 136 | .is_visible = vexpress_hwmon_attr_is_visible, | 125 | .is_visible = vexpress_hwmon_attr_is_visible, |
| 137 | .attrs = vexpress_hwmon_attrs_amp, | 126 | .attrs = vexpress_hwmon_attrs_amp, |
| @@ -147,7 +136,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_amp = { | |||
| 147 | static DEVICE_ATTR(temp1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); | 136 | static DEVICE_ATTR(temp1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); |
| 148 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, vexpress_hwmon_u32_show, | 137 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, vexpress_hwmon_u32_show, |
| 149 | NULL, 1000); | 138 | NULL, 1000); |
| 150 | static VEXPRESS_HWMON_ATTRS(temp, temp1_label, temp1_input); | 139 | static struct attribute *vexpress_hwmon_attrs_temp[] = { |
| 140 | &dev_attr_temp1_label.attr, | ||
| 141 | &sensor_dev_attr_temp1_input.dev_attr.attr, | ||
| 142 | NULL | ||
| 143 | }; | ||
| 151 | static struct attribute_group vexpress_hwmon_group_temp = { | 144 | static struct attribute_group vexpress_hwmon_group_temp = { |
| 152 | .is_visible = vexpress_hwmon_attr_is_visible, | 145 | .is_visible = vexpress_hwmon_attr_is_visible, |
| 153 | .attrs = vexpress_hwmon_attrs_temp, | 146 | .attrs = vexpress_hwmon_attrs_temp, |
| @@ -163,7 +156,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_temp = { | |||
| 163 | static DEVICE_ATTR(power1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); | 156 | static DEVICE_ATTR(power1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); |
| 164 | static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, vexpress_hwmon_u32_show, | 157 | static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, vexpress_hwmon_u32_show, |
| 165 | NULL, 1); | 158 | NULL, 1); |
| 166 | static VEXPRESS_HWMON_ATTRS(power, power1_label, power1_input); | 159 | static struct attribute *vexpress_hwmon_attrs_power[] = { |
| 160 | &dev_attr_power1_label.attr, | ||
| 161 | &sensor_dev_attr_power1_input.dev_attr.attr, | ||
| 162 | NULL | ||
| 163 | }; | ||
| 167 | static struct attribute_group vexpress_hwmon_group_power = { | 164 | static struct attribute_group vexpress_hwmon_group_power = { |
| 168 | .is_visible = vexpress_hwmon_attr_is_visible, | 165 | .is_visible = vexpress_hwmon_attr_is_visible, |
| 169 | .attrs = vexpress_hwmon_attrs_power, | 166 | .attrs = vexpress_hwmon_attrs_power, |
| @@ -179,7 +176,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_power = { | |||
| 179 | static DEVICE_ATTR(energy1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); | 176 | static DEVICE_ATTR(energy1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); |
| 180 | static SENSOR_DEVICE_ATTR(energy1_input, S_IRUGO, vexpress_hwmon_u64_show, | 177 | static SENSOR_DEVICE_ATTR(energy1_input, S_IRUGO, vexpress_hwmon_u64_show, |
| 181 | NULL, 1); | 178 | NULL, 1); |
| 182 | static VEXPRESS_HWMON_ATTRS(energy, energy1_label, energy1_input); | 179 | static struct attribute *vexpress_hwmon_attrs_energy[] = { |
| 180 | &dev_attr_energy1_label.attr, | ||
| 181 | &sensor_dev_attr_energy1_input.dev_attr.attr, | ||
| 182 | NULL | ||
| 183 | }; | ||
| 183 | static struct attribute_group vexpress_hwmon_group_energy = { | 184 | static struct attribute_group vexpress_hwmon_group_energy = { |
| 184 | .is_visible = vexpress_hwmon_attr_is_visible, | 185 | .is_visible = vexpress_hwmon_attr_is_visible, |
| 185 | .attrs = vexpress_hwmon_attrs_energy, | 186 | .attrs = vexpress_hwmon_attrs_energy, |
| @@ -218,7 +219,6 @@ MODULE_DEVICE_TABLE(of, vexpress_hwmon_of_match); | |||
| 218 | 219 | ||
| 219 | static int vexpress_hwmon_probe(struct platform_device *pdev) | 220 | static int vexpress_hwmon_probe(struct platform_device *pdev) |
| 220 | { | 221 | { |
| 221 | int err; | ||
| 222 | const struct of_device_id *match; | 222 | const struct of_device_id *match; |
| 223 | struct vexpress_hwmon_data *data; | 223 | struct vexpress_hwmon_data *data; |
| 224 | const struct vexpress_hwmon_type *type; | 224 | const struct vexpress_hwmon_type *type; |
| @@ -232,45 +232,19 @@ static int vexpress_hwmon_probe(struct platform_device *pdev) | |||
| 232 | if (!match) | 232 | if (!match) |
| 233 | return -ENODEV; | 233 | return -ENODEV; |
| 234 | type = match->data; | 234 | type = match->data; |
| 235 | data->name = type->name; | ||
| 236 | 235 | ||
| 237 | data->reg = devm_regmap_init_vexpress_config(&pdev->dev); | 236 | data->reg = devm_regmap_init_vexpress_config(&pdev->dev); |
| 238 | if (IS_ERR(data->reg)) | 237 | if (IS_ERR(data->reg)) |
| 239 | return PTR_ERR(data->reg); | 238 | return PTR_ERR(data->reg); |
| 240 | 239 | ||
| 241 | err = sysfs_create_groups(&pdev->dev.kobj, type->attr_groups); | 240 | data->hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, |
| 242 | if (err) | 241 | type->name, data, type->attr_groups); |
| 243 | goto error; | ||
| 244 | |||
| 245 | data->hwmon_dev = hwmon_device_register(&pdev->dev); | ||
| 246 | if (IS_ERR(data->hwmon_dev)) { | ||
| 247 | err = PTR_ERR(data->hwmon_dev); | ||
| 248 | goto error; | ||
| 249 | } | ||
| 250 | |||
| 251 | return 0; | ||
| 252 | |||
| 253 | error: | ||
| 254 | sysfs_remove_group(&pdev->dev.kobj, match->data); | ||
| 255 | return err; | ||
| 256 | } | ||
| 257 | |||
| 258 | static int vexpress_hwmon_remove(struct platform_device *pdev) | ||
| 259 | { | ||
| 260 | struct vexpress_hwmon_data *data = platform_get_drvdata(pdev); | ||
| 261 | const struct of_device_id *match; | ||
| 262 | |||
| 263 | hwmon_device_unregister(data->hwmon_dev); | ||
| 264 | |||
| 265 | match = of_match_device(vexpress_hwmon_of_match, &pdev->dev); | ||
| 266 | sysfs_remove_group(&pdev->dev.kobj, match->data); | ||
| 267 | 242 | ||
| 268 | return 0; | 243 | return PTR_ERR_OR_ZERO(data->hwmon_dev); |
| 269 | } | 244 | } |
| 270 | 245 | ||
| 271 | static struct platform_driver vexpress_hwmon_driver = { | 246 | static struct platform_driver vexpress_hwmon_driver = { |
| 272 | .probe = vexpress_hwmon_probe, | 247 | .probe = vexpress_hwmon_probe, |
| 273 | .remove = vexpress_hwmon_remove, | ||
| 274 | .driver = { | 248 | .driver = { |
| 275 | .name = DRVNAME, | 249 | .name = DRVNAME, |
| 276 | .owner = THIS_MODULE, | 250 | .owner = THIS_MODULE, |
