aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2011-07-25 15:46:11 -0400
committerJean Delvare <khali@endymion.delvare>2011-07-25 15:46:11 -0400
commit90534c5c5e535d7bf78a4efdbd0999e04b57d6e3 (patch)
tree755a31606e47c783662f9b1c27423caf764695cc /drivers/hwmon
parented4cebdf9cfbf5f97f388ae7f2ac2b24fc362a39 (diff)
hwmon: (lm78) Make ISA interface depend on CONFIG_ISA
We should only include support for the ISA interface of the LM78/LM79 if CONFIG_ISA is set. Not only this makes the driver somewhat smaller on most architectures, but this also avoids poking at random I/O ports on these architectures. This is very similiar to what was done for the w83781d driver in October 2008. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Dean Nelson <dnelson@redhat.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lm78.c98
1 files changed, 79 insertions, 19 deletions
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 5b7c69570619..05290e34a1be 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -2,7 +2,7 @@
2 lm78.c - Part of lm_sensors, Linux kernel modules for hardware 2 lm78.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5 Copyright (c) 2007 Jean Delvare <khali@linux-fr.org> 5 Copyright (c) 2007, 2011 Jean Delvare <khali@linux-fr.org>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
@@ -26,23 +26,21 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/platform_device.h>
30#include <linux/ioport.h>
31#include <linux/hwmon.h> 29#include <linux/hwmon.h>
32#include <linux/hwmon-vid.h> 30#include <linux/hwmon-vid.h>
33#include <linux/hwmon-sysfs.h> 31#include <linux/hwmon-sysfs.h>
34#include <linux/err.h> 32#include <linux/err.h>
35#include <linux/mutex.h> 33#include <linux/mutex.h>
36#include <linux/io.h>
37 34
38/* ISA device, if found */ 35#ifdef CONFIG_ISA
39static struct platform_device *pdev; 36#include <linux/platform_device.h>
37#include <linux/ioport.h>
38#include <linux/io.h>
39#endif
40 40
41/* Addresses to scan */ 41/* Addresses to scan */
42static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 42static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
43 0x2e, 0x2f, I2C_CLIENT_END }; 43 0x2e, 0x2f, I2C_CLIENT_END };
44static unsigned short isa_address = 0x290;
45
46enum chips { lm78, lm79 }; 44enum chips { lm78, lm79 };
47 45
48/* Many LM78 constants specified below */ 46/* Many LM78 constants specified below */
@@ -476,6 +474,16 @@ static const struct attribute_group lm78_group = {
476 .attrs = lm78_attributes, 474 .attrs = lm78_attributes,
477}; 475};
478 476
477/*
478 * ISA related code
479 */
480#ifdef CONFIG_ISA
481
482/* ISA device, if found */
483static struct platform_device *pdev;
484
485static unsigned short isa_address = 0x290;
486
479/* I2C devices get this name attribute automatically, but for ISA devices 487/* I2C devices get this name attribute automatically, but for ISA devices
480 we must create it by ourselves. */ 488 we must create it by ourselves. */
481static ssize_t show_name(struct device *dev, struct device_attribute 489static ssize_t show_name(struct device *dev, struct device_attribute
@@ -487,6 +495,11 @@ static ssize_t show_name(struct device *dev, struct device_attribute
487} 495}
488static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 496static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
489 497
498static struct lm78_data *lm78_data_if_isa(void)
499{
500 return pdev ? platform_get_drvdata(pdev) : NULL;
501}
502
490/* Returns 1 if the I2C chip appears to be an alias of the ISA chip */ 503/* Returns 1 if the I2C chip appears to be an alias of the ISA chip */
491static int lm78_alias_detect(struct i2c_client *client, u8 chipid) 504static int lm78_alias_detect(struct i2c_client *client, u8 chipid)
492{ 505{
@@ -520,12 +533,24 @@ static int lm78_alias_detect(struct i2c_client *client, u8 chipid)
520 533
521 return 1; 534 return 1;
522} 535}
536#else /* !CONFIG_ISA */
537
538static int lm78_alias_detect(struct i2c_client *client, u8 chipid)
539{
540 return 0;
541}
542
543static struct lm78_data *lm78_data_if_isa(void)
544{
545 return NULL;
546}
547#endif /* CONFIG_ISA */
523 548
524static int lm78_i2c_detect(struct i2c_client *client, 549static int lm78_i2c_detect(struct i2c_client *client,
525 struct i2c_board_info *info) 550 struct i2c_board_info *info)
526{ 551{
527 int i; 552 int i;
528 struct lm78_data *isa = pdev ? platform_get_drvdata(pdev) : NULL; 553 struct lm78_data *isa = lm78_data_if_isa();
529 const char *client_name; 554 const char *client_name;
530 struct i2c_adapter *adapter = client->adapter; 555 struct i2c_adapter *adapter = client->adapter;
531 int address = client->addr; 556 int address = client->addr;
@@ -653,6 +678,7 @@ static int lm78_read_value(struct lm78_data *data, u8 reg)
653{ 678{
654 struct i2c_client *client = data->client; 679 struct i2c_client *client = data->client;
655 680
681#ifdef CONFIG_ISA
656 if (!client) { /* ISA device */ 682 if (!client) { /* ISA device */
657 int res; 683 int res;
658 mutex_lock(&data->lock); 684 mutex_lock(&data->lock);
@@ -661,6 +687,7 @@ static int lm78_read_value(struct lm78_data *data, u8 reg)
661 mutex_unlock(&data->lock); 687 mutex_unlock(&data->lock);
662 return res; 688 return res;
663 } else 689 } else
690#endif
664 return i2c_smbus_read_byte_data(client, reg); 691 return i2c_smbus_read_byte_data(client, reg);
665} 692}
666 693
@@ -675,6 +702,7 @@ static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value)
675{ 702{
676 struct i2c_client *client = data->client; 703 struct i2c_client *client = data->client;
677 704
705#ifdef CONFIG_ISA
678 if (!client) { /* ISA device */ 706 if (!client) { /* ISA device */
679 mutex_lock(&data->lock); 707 mutex_lock(&data->lock);
680 outb_p(reg, data->isa_addr + LM78_ADDR_REG_OFFSET); 708 outb_p(reg, data->isa_addr + LM78_ADDR_REG_OFFSET);
@@ -682,6 +710,7 @@ static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value)
682 mutex_unlock(&data->lock); 710 mutex_unlock(&data->lock);
683 return 0; 711 return 0;
684 } else 712 } else
713#endif
685 return i2c_smbus_write_byte_data(client, reg, value); 714 return i2c_smbus_write_byte_data(client, reg, value);
686} 715}
687 716
@@ -759,6 +788,7 @@ static struct lm78_data *lm78_update_device(struct device *dev)
759 return data; 788 return data;
760} 789}
761 790
791#ifdef CONFIG_ISA
762static int __devinit lm78_isa_probe(struct platform_device *pdev) 792static int __devinit lm78_isa_probe(struct platform_device *pdev)
763{ 793{
764 int err; 794 int err;
@@ -960,12 +990,10 @@ static int __init lm78_isa_device_add(unsigned short address)
960 return err; 990 return err;
961} 991}
962 992
963static int __init sm_lm78_init(void) 993static int __init lm78_isa_register(void)
964{ 994{
965 int res; 995 int res;
966 996
967 /* We register the ISA device first, so that we can skip the
968 * registration of an I2C interface to the same device. */
969 if (lm78_isa_found(isa_address)) { 997 if (lm78_isa_found(isa_address)) {
970 res = platform_driver_register(&lm78_isa_driver); 998 res = platform_driver_register(&lm78_isa_driver);
971 if (res) 999 if (res)
@@ -977,26 +1005,58 @@ static int __init sm_lm78_init(void)
977 goto exit_unreg_isa_driver; 1005 goto exit_unreg_isa_driver;
978 } 1006 }
979 1007
980 res = i2c_add_driver(&lm78_driver);
981 if (res)
982 goto exit_unreg_isa_device;
983
984 return 0; 1008 return 0;
985 1009
986 exit_unreg_isa_device:
987 platform_device_unregister(pdev);
988 exit_unreg_isa_driver: 1010 exit_unreg_isa_driver:
989 platform_driver_unregister(&lm78_isa_driver); 1011 platform_driver_unregister(&lm78_isa_driver);
990 exit: 1012 exit:
991 return res; 1013 return res;
992} 1014}
993 1015
994static void __exit sm_lm78_exit(void) 1016static void lm78_isa_unregister(void)
995{ 1017{
996 if (pdev) { 1018 if (pdev) {
997 platform_device_unregister(pdev); 1019 platform_device_unregister(pdev);
998 platform_driver_unregister(&lm78_isa_driver); 1020 platform_driver_unregister(&lm78_isa_driver);
999 } 1021 }
1022}
1023#else /* !CONFIG_ISA */
1024
1025static int __init lm78_isa_register(void)
1026{
1027 return 0;
1028}
1029
1030static void lm78_isa_unregister(void)
1031{
1032}
1033#endif /* CONFIG_ISA */
1034
1035static int __init sm_lm78_init(void)
1036{
1037 int res;
1038
1039 /* We register the ISA device first, so that we can skip the
1040 * registration of an I2C interface to the same device. */
1041 res = lm78_isa_register();
1042 if (res)
1043 goto exit;
1044
1045 res = i2c_add_driver(&lm78_driver);
1046 if (res)
1047 goto exit_unreg_isa_device;
1048
1049 return 0;
1050
1051 exit_unreg_isa_device:
1052 lm78_isa_unregister();
1053 exit:
1054 return res;
1055}
1056
1057static void __exit sm_lm78_exit(void)
1058{
1059 lm78_isa_unregister();
1000 i2c_del_driver(&lm78_driver); 1060 i2c_del_driver(&lm78_driver);
1001} 1061}
1002 1062