Commit 8cec03ee authored by Anton Vorontsov's avatar Anton Vorontsov Committed by Linus Torvalds

hwmon: lm70: convert to device table matching

Make the code a little bit nicer, and shorter.
Signed-off-by: default avatarAnton 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d2a5c10f
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/mod_devicetable.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
...@@ -130,11 +131,20 @@ static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL); ...@@ -130,11 +131,20 @@ static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL);
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
static int __devinit common_probe(struct spi_device *spi, int chip) static int __devinit lm70_probe(struct spi_device *spi)
{ {
int chip = spi_get_device_id(spi)->driver_data;
struct lm70 *p_lm70; struct lm70 *p_lm70;
int status; int status;
/* signaling is SPI_MODE_0 for both LM70 and TMP121 */
if (spi->mode & (SPI_CPOL | SPI_CPHA))
return -EINVAL;
/* 3-wire link (shared SI/SO) for LM70 */
if (chip == LM70_CHIP_LM70 && !(spi->mode & SPI_3WIRE))
return -EINVAL;
/* NOTE: we assume 8-bit words, and convert to 16 bits manually */ /* NOTE: we assume 8-bit words, and convert to 16 bits manually */
p_lm70 = kzalloc(sizeof *p_lm70, GFP_KERNEL); p_lm70 = kzalloc(sizeof *p_lm70, GFP_KERNEL);
...@@ -170,24 +180,6 @@ static int __devinit common_probe(struct spi_device *spi, int chip) ...@@ -170,24 +180,6 @@ static int __devinit common_probe(struct spi_device *spi, int chip)
return status; return status;
} }
static int __devinit lm70_probe(struct spi_device *spi)
{
/* signaling is SPI_MODE_0 on a 3-wire link (shared SI/SO) */
if ((spi->mode & (SPI_CPOL | SPI_CPHA)) || !(spi->mode & SPI_3WIRE))
return -EINVAL;
return common_probe(spi, LM70_CHIP_LM70);
}
static int __devinit tmp121_probe(struct spi_device *spi)
{
/* signaling is SPI_MODE_0 with only MISO connected */
if (spi->mode & (SPI_CPOL | SPI_CPHA))
return -EINVAL;
return common_probe(spi, LM70_CHIP_TMP121);
}
static int __devexit lm70_remove(struct spi_device *spi) static int __devexit lm70_remove(struct spi_device *spi)
{ {
struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev); struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev);
...@@ -201,41 +193,32 @@ static int __devexit lm70_remove(struct spi_device *spi) ...@@ -201,41 +193,32 @@ static int __devexit lm70_remove(struct spi_device *spi)
return 0; return 0;
} }
static struct spi_driver tmp121_driver = {
.driver = { static const struct spi_device_id lm70_ids[] = {
.name = "tmp121", { "lm70", LM70_CHIP_LM70 },
.owner = THIS_MODULE, { "tmp121", LM70_CHIP_TMP121 },
}, { },
.probe = tmp121_probe,
.remove = __devexit_p(lm70_remove),
}; };
MODULE_DEVICE_TABLE(spi, lm70_ids);
static struct spi_driver lm70_driver = { static struct spi_driver lm70_driver = {
.driver = { .driver = {
.name = "lm70", .name = "lm70",
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
.id_table = lm70_ids,
.probe = lm70_probe, .probe = lm70_probe,
.remove = __devexit_p(lm70_remove), .remove = __devexit_p(lm70_remove),
}; };
static int __init init_lm70(void) static int __init init_lm70(void)
{ {
int ret = spi_register_driver(&lm70_driver); return spi_register_driver(&lm70_driver);
if (ret)
return ret;
ret = spi_register_driver(&tmp121_driver);
if (ret)
spi_unregister_driver(&lm70_driver);
return ret;
} }
static void __exit cleanup_lm70(void) static void __exit cleanup_lm70(void)
{ {
spi_unregister_driver(&lm70_driver); spi_unregister_driver(&lm70_driver);
spi_unregister_driver(&tmp121_driver);
} }
module_init(init_lm70); module_init(init_lm70);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment