diff options
Diffstat (limited to 'drivers/hwmon/it87.c')
-rw-r--r-- | drivers/hwmon/it87.c | 202 |
1 files changed, 51 insertions, 151 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index 323ef06719c1..1ed8b7e2c35d 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -3,7 +3,7 @@ | |||
3 | monitoring. | 3 | monitoring. |
4 | 4 | ||
5 | Supports: IT8705F Super I/O chip w/LPC interface | 5 | Supports: IT8705F Super I/O chip w/LPC interface |
6 | IT8712F Super I/O chip w/LPC interface & SMBus | 6 | IT8712F Super I/O chip w/LPC interface |
7 | IT8716F Super I/O chip w/LPC interface | 7 | IT8716F Super I/O chip w/LPC interface |
8 | IT8718F Super I/O chip w/LPC interface | 8 | IT8718F Super I/O chip w/LPC interface |
9 | Sis950 A clone of the IT8705F | 9 | Sis950 A clone of the IT8705F |
@@ -41,12 +41,8 @@ | |||
41 | #include <asm/io.h> | 41 | #include <asm/io.h> |
42 | 42 | ||
43 | 43 | ||
44 | /* Addresses to scan */ | ||
45 | static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END }; | ||
46 | static unsigned short isa_address; | 44 | static unsigned short isa_address; |
47 | 45 | enum chips { it87, it8712, it8716, it8718 }; | |
48 | /* Insmod parameters */ | ||
49 | I2C_CLIENT_INSMOD_4(it87, it8712, it8716, it8718); | ||
50 | 46 | ||
51 | #define REG 0x2e /* The register to read/write */ | 47 | #define REG 0x2e /* The register to read/write */ |
52 | #define DEV 0x07 /* Register: Logical device select */ | 48 | #define DEV 0x07 /* Register: Logical device select */ |
@@ -162,8 +158,6 @@ static u8 vid_value; | |||
162 | #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2) | 158 | #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2) |
163 | #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2) | 159 | #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2) |
164 | 160 | ||
165 | #define IT87_REG_I2C_ADDR 0x48 | ||
166 | |||
167 | #define IT87_REG_VIN_ENABLE 0x50 | 161 | #define IT87_REG_VIN_ENABLE 0x50 |
168 | #define IT87_REG_TEMP_ENABLE 0x51 | 162 | #define IT87_REG_TEMP_ENABLE 0x51 |
169 | 163 | ||
@@ -242,33 +236,22 @@ struct it87_data { | |||
242 | }; | 236 | }; |
243 | 237 | ||
244 | 238 | ||
245 | static int it87_attach_adapter(struct i2c_adapter *adapter); | 239 | static int it87_detect(struct i2c_adapter *adapter); |
246 | static int it87_isa_attach_adapter(struct i2c_adapter *adapter); | ||
247 | static int it87_detect(struct i2c_adapter *adapter, int address, int kind); | ||
248 | static int it87_detach_client(struct i2c_client *client); | 240 | static int it87_detach_client(struct i2c_client *client); |
249 | 241 | ||
250 | static int it87_read_value(struct i2c_client *client, u8 reg); | 242 | static int it87_read_value(struct i2c_client *client, u8 reg); |
251 | static int it87_write_value(struct i2c_client *client, u8 reg, u8 value); | 243 | static void it87_write_value(struct i2c_client *client, u8 reg, u8 value); |
252 | static struct it87_data *it87_update_device(struct device *dev); | 244 | static struct it87_data *it87_update_device(struct device *dev); |
253 | static int it87_check_pwm(struct i2c_client *client); | 245 | static int it87_check_pwm(struct i2c_client *client); |
254 | static void it87_init_client(struct i2c_client *client, struct it87_data *data); | 246 | static void it87_init_client(struct i2c_client *client, struct it87_data *data); |
255 | 247 | ||
256 | 248 | ||
257 | static struct i2c_driver it87_driver = { | ||
258 | .driver = { | ||
259 | .name = "it87", | ||
260 | }, | ||
261 | .id = I2C_DRIVERID_IT87, | ||
262 | .attach_adapter = it87_attach_adapter, | ||
263 | .detach_client = it87_detach_client, | ||
264 | }; | ||
265 | |||
266 | static struct i2c_driver it87_isa_driver = { | 249 | static struct i2c_driver it87_isa_driver = { |
267 | .driver = { | 250 | .driver = { |
268 | .owner = THIS_MODULE, | 251 | .owner = THIS_MODULE, |
269 | .name = "it87-isa", | 252 | .name = "it87-isa", |
270 | }, | 253 | }, |
271 | .attach_adapter = it87_isa_attach_adapter, | 254 | .attach_adapter = it87_detect, |
272 | .detach_client = it87_detach_client, | 255 | .detach_client = it87_detach_client, |
273 | }; | 256 | }; |
274 | 257 | ||
@@ -850,22 +833,6 @@ static const struct attribute_group it87_group_opt = { | |||
850 | .attrs = it87_attributes_opt, | 833 | .attrs = it87_attributes_opt, |
851 | }; | 834 | }; |
852 | 835 | ||
853 | /* This function is called when: | ||
854 | * it87_driver is inserted (when this module is loaded), for each | ||
855 | available adapter | ||
856 | * when a new adapter is inserted (and it87_driver is still present) */ | ||
857 | static int it87_attach_adapter(struct i2c_adapter *adapter) | ||
858 | { | ||
859 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
860 | return 0; | ||
861 | return i2c_probe(adapter, &addr_data, it87_detect); | ||
862 | } | ||
863 | |||
864 | static int it87_isa_attach_adapter(struct i2c_adapter *adapter) | ||
865 | { | ||
866 | return it87_detect(adapter, isa_address, -1); | ||
867 | } | ||
868 | |||
869 | /* SuperIO detection - will change isa_address if a chip is found */ | 836 | /* SuperIO detection - will change isa_address if a chip is found */ |
870 | static int __init it87_find(unsigned short *address) | 837 | static int __init it87_find(unsigned short *address) |
871 | { | 838 | { |
@@ -916,29 +883,20 @@ exit: | |||
916 | } | 883 | } |
917 | 884 | ||
918 | /* This function is called by i2c_probe */ | 885 | /* This function is called by i2c_probe */ |
919 | static int it87_detect(struct i2c_adapter *adapter, int address, int kind) | 886 | static int it87_detect(struct i2c_adapter *adapter) |
920 | { | 887 | { |
921 | int i; | ||
922 | struct i2c_client *new_client; | 888 | struct i2c_client *new_client; |
923 | struct it87_data *data; | 889 | struct it87_data *data; |
924 | int err = 0; | 890 | int err = 0; |
925 | const char *name = ""; | 891 | const char *name; |
926 | int is_isa = i2c_is_isa_adapter(adapter); | ||
927 | int enable_pwm_interface; | 892 | int enable_pwm_interface; |
928 | 893 | ||
929 | if (!is_isa && | ||
930 | !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
931 | goto ERROR0; | ||
932 | |||
933 | /* Reserve the ISA region */ | 894 | /* Reserve the ISA region */ |
934 | if (is_isa) | 895 | if (!request_region(isa_address, IT87_EXTENT, |
935 | if (!request_region(address, IT87_EXTENT, | 896 | it87_isa_driver.driver.name)){ |
936 | it87_isa_driver.driver.name)) | 897 | err = -EBUSY; |
937 | goto ERROR0; | 898 | goto ERROR0; |
938 | 899 | } | |
939 | /* For now, we presume we have a valid client. We create the | ||
940 | client structure, even though we cannot fill it completely yet. | ||
941 | But it allows us to access it87_{read,write}_value. */ | ||
942 | 900 | ||
943 | if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) { | 901 | if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) { |
944 | err = -ENOMEM; | 902 | err = -ENOMEM; |
@@ -946,80 +904,46 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
946 | } | 904 | } |
947 | 905 | ||
948 | new_client = &data->client; | 906 | new_client = &data->client; |
949 | if (is_isa) | 907 | mutex_init(&data->lock); |
950 | mutex_init(&data->lock); | ||
951 | i2c_set_clientdata(new_client, data); | 908 | i2c_set_clientdata(new_client, data); |
952 | new_client->addr = address; | 909 | new_client->addr = isa_address; |
953 | new_client->adapter = adapter; | 910 | new_client->adapter = adapter; |
954 | new_client->driver = is_isa ? &it87_isa_driver : &it87_driver; | 911 | new_client->driver = &it87_isa_driver; |
955 | new_client->flags = 0; | ||
956 | 912 | ||
957 | /* Now, we do the remaining detection. */ | 913 | /* Now, we do the remaining detection. */ |
958 | 914 | if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80) | |
959 | if (kind < 0) { | 915 | || it87_read_value(new_client, IT87_REG_CHIPID) != 0x90) { |
960 | if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80) | 916 | err = -ENODEV; |
961 | || (!is_isa | 917 | goto ERROR2; |
962 | && it87_read_value(new_client, IT87_REG_I2C_ADDR) != address)) { | ||
963 | err = -ENODEV; | ||
964 | goto ERROR2; | ||
965 | } | ||
966 | } | 918 | } |
967 | 919 | ||
968 | /* Determine the chip type. */ | 920 | /* Determine the chip type. */ |
969 | if (kind <= 0) { | 921 | switch (chip_type) { |
970 | i = it87_read_value(new_client, IT87_REG_CHIPID); | 922 | case IT8712F_DEVID: |
971 | if (i == 0x90) { | 923 | data->type = it8712; |
972 | kind = it87; | ||
973 | if (is_isa) { | ||
974 | switch (chip_type) { | ||
975 | case IT8712F_DEVID: | ||
976 | kind = it8712; | ||
977 | break; | ||
978 | case IT8716F_DEVID: | ||
979 | kind = it8716; | ||
980 | break; | ||
981 | case IT8718F_DEVID: | ||
982 | kind = it8718; | ||
983 | break; | ||
984 | } | ||
985 | } | ||
986 | } | ||
987 | else { | ||
988 | if (kind == 0) | ||
989 | dev_info(&adapter->dev, | ||
990 | "Ignoring 'force' parameter for unknown chip at " | ||
991 | "adapter %d, address 0x%02x\n", | ||
992 | i2c_adapter_id(adapter), address); | ||
993 | err = -ENODEV; | ||
994 | goto ERROR2; | ||
995 | } | ||
996 | } | ||
997 | |||
998 | if (kind == it87) { | ||
999 | name = "it87"; | ||
1000 | } else if (kind == it8712) { | ||
1001 | name = "it8712"; | 924 | name = "it8712"; |
1002 | } else if (kind == it8716) { | 925 | break; |
926 | case IT8716F_DEVID: | ||
927 | data->type = it8716; | ||
1003 | name = "it8716"; | 928 | name = "it8716"; |
1004 | } else if (kind == it8718) { | 929 | break; |
930 | case IT8718F_DEVID: | ||
931 | data->type = it8718; | ||
1005 | name = "it8718"; | 932 | name = "it8718"; |
933 | break; | ||
934 | default: | ||
935 | data->type = it87; | ||
936 | name = "it87"; | ||
1006 | } | 937 | } |
1007 | 938 | ||
1008 | /* Fill in the remaining client fields and put it into the global list */ | 939 | /* Fill in the remaining client fields and put it into the global list */ |
1009 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 940 | strlcpy(new_client->name, name, I2C_NAME_SIZE); |
1010 | data->type = kind; | ||
1011 | data->valid = 0; | ||
1012 | mutex_init(&data->update_lock); | 941 | mutex_init(&data->update_lock); |
1013 | 942 | ||
1014 | /* Tell the I2C layer a new client has arrived */ | 943 | /* Tell the I2C layer a new client has arrived */ |
1015 | if ((err = i2c_attach_client(new_client))) | 944 | if ((err = i2c_attach_client(new_client))) |
1016 | goto ERROR2; | 945 | goto ERROR2; |
1017 | 946 | ||
1018 | if (!is_isa) | ||
1019 | dev_info(&new_client->dev, "The I2C interface to IT87xxF " | ||
1020 | "hardware monitoring chips is deprecated. Please " | ||
1021 | "report if you still rely on it.\n"); | ||
1022 | |||
1023 | /* Check PWM configuration */ | 947 | /* Check PWM configuration */ |
1024 | enable_pwm_interface = it87_check_pwm(new_client); | 948 | enable_pwm_interface = it87_check_pwm(new_client); |
1025 | 949 | ||
@@ -1129,8 +1053,7 @@ ERROR3: | |||
1129 | ERROR2: | 1053 | ERROR2: |
1130 | kfree(data); | 1054 | kfree(data); |
1131 | ERROR1: | 1055 | ERROR1: |
1132 | if (is_isa) | 1056 | release_region(isa_address, IT87_EXTENT); |
1133 | release_region(address, IT87_EXTENT); | ||
1134 | ERROR0: | 1057 | ERROR0: |
1135 | return err; | 1058 | return err; |
1136 | } | 1059 | } |
@@ -1147,50 +1070,39 @@ static int it87_detach_client(struct i2c_client *client) | |||
1147 | if ((err = i2c_detach_client(client))) | 1070 | if ((err = i2c_detach_client(client))) |
1148 | return err; | 1071 | return err; |
1149 | 1072 | ||
1150 | if(i2c_is_isa_client(client)) | 1073 | release_region(client->addr, IT87_EXTENT); |
1151 | release_region(client->addr, IT87_EXTENT); | ||
1152 | kfree(data); | 1074 | kfree(data); |
1153 | 1075 | ||
1154 | return 0; | 1076 | return 0; |
1155 | } | 1077 | } |
1156 | 1078 | ||
1157 | /* The SMBus locks itself, but ISA access must be locked explicitly! | 1079 | /* ISA access must be locked explicitly! |
1158 | We don't want to lock the whole ISA bus, so we lock each client | ||
1159 | separately. | ||
1160 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, | 1080 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
1161 | would slow down the IT87 access and should not be necessary. */ | 1081 | would slow down the IT87 access and should not be necessary. */ |
1162 | static int it87_read_value(struct i2c_client *client, u8 reg) | 1082 | static int it87_read_value(struct i2c_client *client, u8 reg) |
1163 | { | 1083 | { |
1164 | struct it87_data *data = i2c_get_clientdata(client); | 1084 | struct it87_data *data = i2c_get_clientdata(client); |
1165 | |||
1166 | int res; | 1085 | int res; |
1167 | if (i2c_is_isa_client(client)) { | 1086 | |
1168 | mutex_lock(&data->lock); | 1087 | mutex_lock(&data->lock); |
1169 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); | 1088 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); |
1170 | res = inb_p(client->addr + IT87_DATA_REG_OFFSET); | 1089 | res = inb_p(client->addr + IT87_DATA_REG_OFFSET); |
1171 | mutex_unlock(&data->lock); | 1090 | mutex_unlock(&data->lock); |
1172 | return res; | 1091 | |
1173 | } else | 1092 | return res; |
1174 | return i2c_smbus_read_byte_data(client, reg); | ||
1175 | } | 1093 | } |
1176 | 1094 | ||
1177 | /* The SMBus locks itself, but ISA access muse be locked explicitly! | 1095 | /* ISA access must be locked explicitly! |
1178 | We don't want to lock the whole ISA bus, so we lock each client | ||
1179 | separately. | ||
1180 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, | 1096 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
1181 | would slow down the IT87 access and should not be necessary. */ | 1097 | would slow down the IT87 access and should not be necessary. */ |
1182 | static int it87_write_value(struct i2c_client *client, u8 reg, u8 value) | 1098 | static void it87_write_value(struct i2c_client *client, u8 reg, u8 value) |
1183 | { | 1099 | { |
1184 | struct it87_data *data = i2c_get_clientdata(client); | 1100 | struct it87_data *data = i2c_get_clientdata(client); |
1185 | 1101 | ||
1186 | if (i2c_is_isa_client(client)) { | 1102 | mutex_lock(&data->lock); |
1187 | mutex_lock(&data->lock); | 1103 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); |
1188 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); | 1104 | outb_p(value, client->addr + IT87_DATA_REG_OFFSET); |
1189 | outb_p(value, client->addr + IT87_DATA_REG_OFFSET); | 1105 | mutex_unlock(&data->lock); |
1190 | mutex_unlock(&data->lock); | ||
1191 | return 0; | ||
1192 | } else | ||
1193 | return i2c_smbus_write_byte_data(client, reg, value); | ||
1194 | } | 1106 | } |
1195 | 1107 | ||
1196 | /* Return 1 if and only if the PWM interface is safe to use */ | 1108 | /* Return 1 if and only if the PWM interface is safe to use */ |
@@ -1426,26 +1338,14 @@ static int __init sm_it87_init(void) | |||
1426 | { | 1338 | { |
1427 | int res; | 1339 | int res; |
1428 | 1340 | ||
1429 | res = i2c_add_driver(&it87_driver); | 1341 | if ((res = it87_find(&isa_address))) |
1430 | if (res) | ||
1431 | return res; | 1342 | return res; |
1432 | 1343 | return i2c_isa_add_driver(&it87_isa_driver); | |
1433 | if (!it87_find(&isa_address)) { | ||
1434 | res = i2c_isa_add_driver(&it87_isa_driver); | ||
1435 | if (res) { | ||
1436 | i2c_del_driver(&it87_driver); | ||
1437 | return res; | ||
1438 | } | ||
1439 | } | ||
1440 | |||
1441 | return 0; | ||
1442 | } | 1344 | } |
1443 | 1345 | ||
1444 | static void __exit sm_it87_exit(void) | 1346 | static void __exit sm_it87_exit(void) |
1445 | { | 1347 | { |
1446 | if (isa_address) | 1348 | i2c_isa_del_driver(&it87_isa_driver); |
1447 | i2c_isa_del_driver(&it87_isa_driver); | ||
1448 | i2c_del_driver(&it87_driver); | ||
1449 | } | 1349 | } |
1450 | 1350 | ||
1451 | 1351 | ||