aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm70.c
diff options
context:
space:
mode:
authorAnton Vorontsov <avorontsov@ru.mvista.com>2009-09-22 19:46:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-09-23 10:39:43 -0400
commit8cec03eee4a771f949c70cff07775c9bb21d4642 (patch)
tree663493a95ca5cea6a3a4ca3a016ba02f00f42046 /drivers/hwmon/lm70.c
parentd2a5c10f806b089a6e6f10deefd01dc4ce67940d (diff)
hwmon: lm70: convert to device table matching
Make the code a little bit nicer, and shorter. Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com> Cc: Kaiwan N Billimoria <kaiwan@designergraphix.com> Cc: David Brownell <dbrownell@users.sourceforge.net> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Grant Likely <grant.likely@secretlab.ca> Cc: Jean Delvare <khali@linux-fr.org> Cc: Ben Dooks <ben-linux@fluff.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/hwmon/lm70.c')
-rw-r--r--drivers/hwmon/lm70.c55
1 files changed, 19 insertions, 36 deletions
diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c
index ae6204f33214..ab8a5d3c7690 100644
--- a/drivers/hwmon/lm70.c
+++ b/drivers/hwmon/lm70.c
@@ -32,6 +32,7 @@
32#include <linux/sysfs.h> 32#include <linux/sysfs.h>
33#include <linux/hwmon.h> 33#include <linux/hwmon.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/mod_devicetable.h>
35#include <linux/spi/spi.h> 36#include <linux/spi/spi.h>
36 37
37 38
@@ -130,11 +131,20 @@ static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL);
130 131
131/*----------------------------------------------------------------------*/ 132/*----------------------------------------------------------------------*/
132 133
133static int __devinit common_probe(struct spi_device *spi, int chip) 134static int __devinit lm70_probe(struct spi_device *spi)
134{ 135{
136 int chip = spi_get_device_id(spi)->driver_data;
135 struct lm70 *p_lm70; 137 struct lm70 *p_lm70;
136 int status; 138 int status;
137 139
140 /* signaling is SPI_MODE_0 for both LM70 and TMP121 */
141 if (spi->mode & (SPI_CPOL | SPI_CPHA))
142 return -EINVAL;
143
144 /* 3-wire link (shared SI/SO) for LM70 */
145 if (chip == LM70_CHIP_LM70 && !(spi->mode & SPI_3WIRE))
146 return -EINVAL;
147
138 /* NOTE: we assume 8-bit words, and convert to 16 bits manually */ 148 /* NOTE: we assume 8-bit words, and convert to 16 bits manually */
139 149
140 p_lm70 = kzalloc(sizeof *p_lm70, GFP_KERNEL); 150 p_lm70 = kzalloc(sizeof *p_lm70, GFP_KERNEL);
@@ -170,24 +180,6 @@ out_dev_reg_failed:
170 return status; 180 return status;
171} 181}
172 182
173static int __devinit lm70_probe(struct spi_device *spi)
174{
175 /* signaling is SPI_MODE_0 on a 3-wire link (shared SI/SO) */
176 if ((spi->mode & (SPI_CPOL | SPI_CPHA)) || !(spi->mode & SPI_3WIRE))
177 return -EINVAL;
178
179 return common_probe(spi, LM70_CHIP_LM70);
180}
181
182static int __devinit tmp121_probe(struct spi_device *spi)
183{
184 /* signaling is SPI_MODE_0 with only MISO connected */
185 if (spi->mode & (SPI_CPOL | SPI_CPHA))
186 return -EINVAL;
187
188 return common_probe(spi, LM70_CHIP_TMP121);
189}
190
191static int __devexit lm70_remove(struct spi_device *spi) 183static int __devexit lm70_remove(struct spi_device *spi)
192{ 184{
193 struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev); 185 struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev);
@@ -201,41 +193,32 @@ static int __devexit lm70_remove(struct spi_device *spi)
201 return 0; 193 return 0;
202} 194}
203 195
204static struct spi_driver tmp121_driver = { 196
205 .driver = { 197static const struct spi_device_id lm70_ids[] = {
206 .name = "tmp121", 198 { "lm70", LM70_CHIP_LM70 },
207 .owner = THIS_MODULE, 199 { "tmp121", LM70_CHIP_TMP121 },
208 }, 200 { },
209 .probe = tmp121_probe,
210 .remove = __devexit_p(lm70_remove),
211}; 201};
202MODULE_DEVICE_TABLE(spi, lm70_ids);
212 203
213static struct spi_driver lm70_driver = { 204static struct spi_driver lm70_driver = {
214 .driver = { 205 .driver = {
215 .name = "lm70", 206 .name = "lm70",
216 .owner = THIS_MODULE, 207 .owner = THIS_MODULE,
217 }, 208 },
209 .id_table = lm70_ids,
218 .probe = lm70_probe, 210 .probe = lm70_probe,
219 .remove = __devexit_p(lm70_remove), 211 .remove = __devexit_p(lm70_remove),
220}; 212};
221 213
222static int __init init_lm70(void) 214static int __init init_lm70(void)
223{ 215{
224 int ret = spi_register_driver(&lm70_driver); 216 return spi_register_driver(&lm70_driver);
225 if (ret)
226 return ret;
227
228 ret = spi_register_driver(&tmp121_driver);
229 if (ret)
230 spi_unregister_driver(&lm70_driver);
231
232 return ret;
233} 217}
234 218
235static void __exit cleanup_lm70(void) 219static void __exit cleanup_lm70(void)
236{ 220{
237 spi_unregister_driver(&lm70_driver); 221 spi_unregister_driver(&lm70_driver);
238 spi_unregister_driver(&tmp121_driver);
239} 222}
240 223
241module_init(init_lm70); 224module_init(init_lm70);