diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-04-06 00:44:47 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-05-21 19:02:20 -0400 |
commit | aa9bcddada9e6e6538ac44b3623bb23b802ba689 (patch) | |
tree | c6cc3112900c4f111f962149c49d4d0a0b6429a5 /drivers/hwmon/lm70.c | |
parent | 4b660a7f5c8099d88d1a43d8ae138965112592c7 (diff) |
hwmon: (lm70) Convert to use devm_hwmon_device_register_with_groups
Use devm_hwmon_device_register_with_groups API to attach attributes
to hwmon device, simplify code, and reduce code size.
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/lm70.c')
-rw-r--r-- | drivers/hwmon/lm70.c | 62 |
1 files changed, 14 insertions, 48 deletions
diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c index 505a59e100b0..97204dce162d 100644 --- a/drivers/hwmon/lm70.c +++ b/drivers/hwmon/lm70.c | |||
@@ -47,7 +47,7 @@ | |||
47 | #define LM70_CHIP_LM74 3 /* NS LM74 */ | 47 | #define LM70_CHIP_LM74 3 /* NS LM74 */ |
48 | 48 | ||
49 | struct lm70 { | 49 | struct lm70 { |
50 | struct device *hwmon_dev; | 50 | struct spi_device *spi; |
51 | struct mutex lock; | 51 | struct mutex lock; |
52 | unsigned int chip; | 52 | unsigned int chip; |
53 | }; | 53 | }; |
@@ -56,11 +56,11 @@ struct lm70 { | |||
56 | static ssize_t lm70_sense_temp(struct device *dev, | 56 | static ssize_t lm70_sense_temp(struct device *dev, |
57 | struct device_attribute *attr, char *buf) | 57 | struct device_attribute *attr, char *buf) |
58 | { | 58 | { |
59 | struct spi_device *spi = to_spi_device(dev); | 59 | struct lm70 *p_lm70 = dev_get_drvdata(dev); |
60 | struct spi_device *spi = p_lm70->spi; | ||
60 | int status, val = 0; | 61 | int status, val = 0; |
61 | u8 rxbuf[2]; | 62 | u8 rxbuf[2]; |
62 | s16 raw = 0; | 63 | s16 raw = 0; |
63 | struct lm70 *p_lm70 = spi_get_drvdata(spi); | ||
64 | 64 | ||
65 | if (mutex_lock_interruptible(&p_lm70->lock)) | 65 | if (mutex_lock_interruptible(&p_lm70->lock)) |
66 | return -ERESTARTSYS; | 66 | return -ERESTARTSYS; |
@@ -121,21 +121,20 @@ out: | |||
121 | 121 | ||
122 | static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL); | 122 | static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL); |
123 | 123 | ||
124 | static ssize_t lm70_show_name(struct device *dev, struct device_attribute | 124 | static struct attribute *lm70_attrs[] = { |
125 | *devattr, char *buf) | 125 | &dev_attr_temp1_input.attr, |
126 | { | 126 | NULL |
127 | return sprintf(buf, "%s\n", to_spi_device(dev)->modalias); | 127 | }; |
128 | } | ||
129 | 128 | ||
130 | static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL); | 129 | ATTRIBUTE_GROUPS(lm70); |
131 | 130 | ||
132 | /*----------------------------------------------------------------------*/ | 131 | /*----------------------------------------------------------------------*/ |
133 | 132 | ||
134 | static int lm70_probe(struct spi_device *spi) | 133 | static int lm70_probe(struct spi_device *spi) |
135 | { | 134 | { |
136 | int chip = spi_get_device_id(spi)->driver_data; | 135 | int chip = spi_get_device_id(spi)->driver_data; |
136 | struct device *hwmon_dev; | ||
137 | struct lm70 *p_lm70; | 137 | struct lm70 *p_lm70; |
138 | int status; | ||
139 | 138 | ||
140 | /* signaling is SPI_MODE_0 */ | 139 | /* signaling is SPI_MODE_0 */ |
141 | if (spi->mode & (SPI_CPOL | SPI_CPHA)) | 140 | if (spi->mode & (SPI_CPOL | SPI_CPHA)) |
@@ -149,46 +148,14 @@ static int lm70_probe(struct spi_device *spi) | |||
149 | 148 | ||
150 | mutex_init(&p_lm70->lock); | 149 | mutex_init(&p_lm70->lock); |
151 | p_lm70->chip = chip; | 150 | p_lm70->chip = chip; |
151 | p_lm70->spi = spi; | ||
152 | 152 | ||
153 | spi_set_drvdata(spi, p_lm70); | 153 | hwmon_dev = devm_hwmon_device_register_with_groups(&spi->dev, |
154 | 154 | spi->modalias, | |
155 | status = device_create_file(&spi->dev, &dev_attr_temp1_input); | 155 | p_lm70, lm70_groups); |
156 | if (status) | 156 | return PTR_ERR_OR_ZERO(hwmon_dev); |
157 | goto out_dev_create_temp_file_failed; | ||
158 | status = device_create_file(&spi->dev, &dev_attr_name); | ||
159 | if (status) | ||
160 | goto out_dev_create_file_failed; | ||
161 | |||
162 | /* sysfs hook */ | ||
163 | p_lm70->hwmon_dev = hwmon_device_register(&spi->dev); | ||
164 | if (IS_ERR(p_lm70->hwmon_dev)) { | ||
165 | dev_dbg(&spi->dev, "hwmon_device_register failed.\n"); | ||
166 | status = PTR_ERR(p_lm70->hwmon_dev); | ||
167 | goto out_dev_reg_failed; | ||
168 | } | ||
169 | |||
170 | return 0; | ||
171 | |||
172 | out_dev_reg_failed: | ||
173 | device_remove_file(&spi->dev, &dev_attr_name); | ||
174 | out_dev_create_file_failed: | ||
175 | device_remove_file(&spi->dev, &dev_attr_temp1_input); | ||
176 | out_dev_create_temp_file_failed: | ||
177 | return status; | ||
178 | } | 157 | } |
179 | 158 | ||
180 | static int lm70_remove(struct spi_device *spi) | ||
181 | { | ||
182 | struct lm70 *p_lm70 = spi_get_drvdata(spi); | ||
183 | |||
184 | hwmon_device_unregister(p_lm70->hwmon_dev); | ||
185 | device_remove_file(&spi->dev, &dev_attr_temp1_input); | ||
186 | device_remove_file(&spi->dev, &dev_attr_name); | ||
187 | |||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | |||
192 | static const struct spi_device_id lm70_ids[] = { | 159 | static const struct spi_device_id lm70_ids[] = { |
193 | { "lm70", LM70_CHIP_LM70 }, | 160 | { "lm70", LM70_CHIP_LM70 }, |
194 | { "tmp121", LM70_CHIP_TMP121 }, | 161 | { "tmp121", LM70_CHIP_TMP121 }, |
@@ -205,7 +172,6 @@ static struct spi_driver lm70_driver = { | |||
205 | }, | 172 | }, |
206 | .id_table = lm70_ids, | 173 | .id_table = lm70_ids, |
207 | .probe = lm70_probe, | 174 | .probe = lm70_probe, |
208 | .remove = lm70_remove, | ||
209 | }; | 175 | }; |
210 | 176 | ||
211 | module_spi_driver(lm70_driver); | 177 | module_spi_driver(lm70_driver); |