diff options
author | David Brownell <david-b@pacbell.net> | 2008-04-21 15:10:53 -0400 |
---|---|---|
committer | Mark M. Hoffman <mhoffman@lightlink.com> | 2008-07-31 23:44:02 -0400 |
commit | 01a52397e95a8532c59506691759dba9262d6be7 (patch) | |
tree | 8429252add519af666178398de7cdfaef500402f | |
parent | 321c4138573da888ca30a387e9973f690c217e9e (diff) |
hwmon: (lm75) cleanup/reorg
Minor cleanup and reorg of the lm75 code.
- Kconfig provides a larger list of lm75-compatible chips
- A top comment now says what the driver does (!) ... as in, just
what sort of sensor is this??
- Section comments now delineate the various sections of the driver:
hwmon attributes, driver binding, register access, module glue.
One driver binding function moved out of the attribute section,
as did the driver struct itself.
- Minor tweaks to legacy probe logic: correct a comment, and
remove a pointless variable.
- Whitespace, linelength, and comment fixes.
This patch should include no functional changes. It's preparation
for adding new-style (driver model) I2C driver binding.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Acked-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Laurent Pinchart <laurentp@cse-semaphore.com>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
-rw-r--r-- | drivers/hwmon/Kconfig | 20 | ||||
-rw-r--r-- | drivers/hwmon/lm75.c | 90 |
2 files changed, 64 insertions, 46 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 00ff53348491..86289c283dc8 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -394,13 +394,19 @@ config SENSORS_LM75 | |||
394 | tristate "National Semiconductor LM75 and compatibles" | 394 | tristate "National Semiconductor LM75 and compatibles" |
395 | depends on I2C | 395 | depends on I2C |
396 | help | 396 | help |
397 | If you say yes here you get support for National Semiconductor LM75 | 397 | If you say yes here you get support for one common type of |
398 | sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in | 398 | temperature sensor chip, with models including: |
399 | 9-bit precision mode), and TelCom (now Microchip) TCN75. | 399 | |
400 | 400 | - Dallas Semiconductor DS75 and DS1775 | |
401 | The DS75 and DS1775 in 10- to 12-bit precision modes will require | 401 | - Maxim MAX6625 and MAX6626 |
402 | a force module parameter. The driver will not handle the extra | 402 | - Microchip MCP980x |
403 | precision anyhow. | 403 | - National Semiconductor LM75 |
404 | - NXP's LM75A | ||
405 | - ST Microelectronics STDS75 | ||
406 | - TelCom (now Microchip) TCN75 | ||
407 | - Texas Instruments TMP100, TMP101, TMP75, TMP175, TMP275 | ||
408 | |||
409 | Most of these chips will require a "force" module parameter. | ||
404 | 410 | ||
405 | This driver can also be built as a module. If so, the module | 411 | This driver can also be built as a module. If so, the module |
406 | will be called lm75. | 412 | will be called lm75. |
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index de698dc73020..25ed26584100 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c | |||
@@ -30,14 +30,19 @@ | |||
30 | #include "lm75.h" | 30 | #include "lm75.h" |
31 | 31 | ||
32 | 32 | ||
33 | /* Addresses to scan */ | 33 | /* |
34 | * This driver handles the LM75 and compatible digital temperature sensors. | ||
35 | * Compatibles include at least the DS75, DS1775, MCP980x, STDS75, TCN75, | ||
36 | * TMP100, TMP101, TMP75, TMP175, and TMP275. | ||
37 | */ | ||
38 | |||
39 | /* Addresses scanned by legacy style driver binding */ | ||
34 | static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, | 40 | static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, |
35 | 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; | 41 | 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; |
36 | 42 | ||
37 | /* Insmod parameters */ | 43 | /* Insmod parameters (only for legacy style driver binding) */ |
38 | I2C_CLIENT_INSMOD_1(lm75); | 44 | I2C_CLIENT_INSMOD_1(lm75); |
39 | 45 | ||
40 | /* Many LM75 constants specified below */ | ||
41 | 46 | ||
42 | /* The LM75 registers */ | 47 | /* The LM75 registers */ |
43 | #define LM75_REG_CONF 0x01 | 48 | #define LM75_REG_CONF 0x01 |
@@ -50,9 +55,9 @@ static const u8 LM75_REG_TEMP[3] = { | |||
50 | /* Each client has this additional data */ | 55 | /* Each client has this additional data */ |
51 | struct lm75_data { | 56 | struct lm75_data { |
52 | struct i2c_client client; | 57 | struct i2c_client client; |
53 | struct device *hwmon_dev; | 58 | struct device *hwmon_dev; |
54 | struct mutex update_lock; | 59 | struct mutex update_lock; |
55 | char valid; /* !=0 if following fields are valid */ | 60 | char valid; /* !=0 if registers are valid */ |
56 | unsigned long last_updated; /* In jiffies */ | 61 | unsigned long last_updated; /* In jiffies */ |
57 | u16 temp[3]; /* Register values, | 62 | u16 temp[3]; /* Register values, |
58 | 0 = input | 63 | 0 = input |
@@ -60,23 +65,15 @@ struct lm75_data { | |||
60 | 2 = hyst */ | 65 | 2 = hyst */ |
61 | }; | 66 | }; |
62 | 67 | ||
63 | static int lm75_attach_adapter(struct i2c_adapter *adapter); | ||
64 | static int lm75_detect(struct i2c_adapter *adapter, int address, int kind); | ||
65 | static void lm75_init_client(struct i2c_client *client); | 68 | static void lm75_init_client(struct i2c_client *client); |
66 | static int lm75_detach_client(struct i2c_client *client); | ||
67 | static int lm75_read_value(struct i2c_client *client, u8 reg); | 69 | static int lm75_read_value(struct i2c_client *client, u8 reg); |
68 | static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value); | 70 | static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value); |
69 | static struct lm75_data *lm75_update_device(struct device *dev); | 71 | static struct lm75_data *lm75_update_device(struct device *dev); |
70 | 72 | ||
71 | 73 | ||
72 | /* This is the driver that will be inserted */ | 74 | /*-----------------------------------------------------------------------*/ |
73 | static struct i2c_driver lm75_driver = { | 75 | |
74 | .driver = { | 76 | /* sysfs attributes for hwmon */ |
75 | .name = "lm75", | ||
76 | }, | ||
77 | .attach_adapter = lm75_attach_adapter, | ||
78 | .detach_client = lm75_detach_client, | ||
79 | }; | ||
80 | 77 | ||
81 | static ssize_t show_temp(struct device *dev, struct device_attribute *da, | 78 | static ssize_t show_temp(struct device *dev, struct device_attribute *da, |
82 | char *buf) | 79 | char *buf) |
@@ -109,13 +106,6 @@ static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, | |||
109 | show_temp, set_temp, 2); | 106 | show_temp, set_temp, 2); |
110 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); | 107 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); |
111 | 108 | ||
112 | static int lm75_attach_adapter(struct i2c_adapter *adapter) | ||
113 | { | ||
114 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
115 | return 0; | ||
116 | return i2c_probe(adapter, &addr_data, lm75_detect); | ||
117 | } | ||
118 | |||
119 | static struct attribute *lm75_attributes[] = { | 109 | static struct attribute *lm75_attributes[] = { |
120 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 110 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
121 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 111 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
@@ -128,6 +118,12 @@ static const struct attribute_group lm75_group = { | |||
128 | .attrs = lm75_attributes, | 118 | .attrs = lm75_attributes, |
129 | }; | 119 | }; |
130 | 120 | ||
121 | /*-----------------------------------------------------------------------*/ | ||
122 | |||
123 | /* "Legacy" I2C driver binding */ | ||
124 | |||
125 | static struct i2c_driver lm75_driver; | ||
126 | |||
131 | /* This function is called by i2c_probe */ | 127 | /* This function is called by i2c_probe */ |
132 | static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) | 128 | static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) |
133 | { | 129 | { |
@@ -135,15 +131,14 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) | |||
135 | struct i2c_client *new_client; | 131 | struct i2c_client *new_client; |
136 | struct lm75_data *data; | 132 | struct lm75_data *data; |
137 | int err = 0; | 133 | int err = 0; |
138 | const char *name = ""; | ||
139 | 134 | ||
140 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 135 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
141 | I2C_FUNC_SMBUS_WORD_DATA)) | 136 | I2C_FUNC_SMBUS_WORD_DATA)) |
142 | goto exit; | 137 | goto exit; |
143 | 138 | ||
144 | /* OK. For now, we presume we have a valid client. We now create the | 139 | /* OK. For now, we presume we have a valid address. We create the |
145 | client structure, even though we cannot fill it completely yet. | 140 | client structure, even though there may be no sensor present. |
146 | But it allows us to access lm75_{read,write}_value. */ | 141 | But it allows us to use i2c_smbus_read_*_data() calls. */ |
147 | if (!(data = kzalloc(sizeof(struct lm75_data), GFP_KERNEL))) { | 142 | if (!(data = kzalloc(sizeof(struct lm75_data), GFP_KERNEL))) { |
148 | err = -ENOMEM; | 143 | err = -ENOMEM; |
149 | goto exit; | 144 | goto exit; |
@@ -174,17 +169,17 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) | |||
174 | || i2c_smbus_read_word_data(new_client, 5) != hyst | 169 | || i2c_smbus_read_word_data(new_client, 5) != hyst |
175 | || i2c_smbus_read_word_data(new_client, 6) != hyst | 170 | || i2c_smbus_read_word_data(new_client, 6) != hyst |
176 | || i2c_smbus_read_word_data(new_client, 7) != hyst) | 171 | || i2c_smbus_read_word_data(new_client, 7) != hyst) |
177 | goto exit_free; | 172 | goto exit_free; |
178 | os = i2c_smbus_read_word_data(new_client, 3); | 173 | os = i2c_smbus_read_word_data(new_client, 3); |
179 | if (i2c_smbus_read_word_data(new_client, 4) != os | 174 | if (i2c_smbus_read_word_data(new_client, 4) != os |
180 | || i2c_smbus_read_word_data(new_client, 5) != os | 175 | || i2c_smbus_read_word_data(new_client, 5) != os |
181 | || i2c_smbus_read_word_data(new_client, 6) != os | 176 | || i2c_smbus_read_word_data(new_client, 6) != os |
182 | || i2c_smbus_read_word_data(new_client, 7) != os) | 177 | || i2c_smbus_read_word_data(new_client, 7) != os) |
183 | goto exit_free; | 178 | goto exit_free; |
184 | 179 | ||
185 | /* Unused bits */ | 180 | /* Unused bits */ |
186 | if (conf & 0xe0) | 181 | if (conf & 0xe0) |
187 | goto exit_free; | 182 | goto exit_free; |
188 | 183 | ||
189 | /* Addresses cycling */ | 184 | /* Addresses cycling */ |
190 | for (i = 8; i < 0xff; i += 8) | 185 | for (i = 8; i < 0xff; i += 8) |
@@ -194,16 +189,10 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) | |||
194 | goto exit_free; | 189 | goto exit_free; |
195 | } | 190 | } |
196 | 191 | ||
197 | /* Determine the chip type - only one kind supported! */ | 192 | /* NOTE: we treat "force=..." and "force_lm75=..." the same. */ |
198 | if (kind <= 0) | 193 | strlcpy(new_client->name, "lm75", I2C_NAME_SIZE); |
199 | kind = lm75; | ||
200 | |||
201 | if (kind == lm75) { | ||
202 | name = "lm75"; | ||
203 | } | ||
204 | 194 | ||
205 | /* Fill in the remaining client fields and put it into the global list */ | 195 | /* Fill in the remaining client fields and put it into the global list */ |
206 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | ||
207 | data->valid = 0; | 196 | data->valid = 0; |
208 | mutex_init(&data->update_lock); | 197 | mutex_init(&data->update_lock); |
209 | 198 | ||
@@ -213,7 +202,7 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) | |||
213 | 202 | ||
214 | /* Initialize the LM75 chip */ | 203 | /* Initialize the LM75 chip */ |
215 | lm75_init_client(new_client); | 204 | lm75_init_client(new_client); |
216 | 205 | ||
217 | /* Register sysfs hooks */ | 206 | /* Register sysfs hooks */ |
218 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm75_group))) | 207 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm75_group))) |
219 | goto exit_detach; | 208 | goto exit_detach; |
@@ -236,6 +225,13 @@ exit: | |||
236 | return err; | 225 | return err; |
237 | } | 226 | } |
238 | 227 | ||
228 | static int lm75_attach_adapter(struct i2c_adapter *adapter) | ||
229 | { | ||
230 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
231 | return 0; | ||
232 | return i2c_probe(adapter, &addr_data, lm75_detect); | ||
233 | } | ||
234 | |||
239 | static int lm75_detach_client(struct i2c_client *client) | 235 | static int lm75_detach_client(struct i2c_client *client) |
240 | { | 236 | { |
241 | struct lm75_data *data = i2c_get_clientdata(client); | 237 | struct lm75_data *data = i2c_get_clientdata(client); |
@@ -246,6 +242,18 @@ static int lm75_detach_client(struct i2c_client *client) | |||
246 | return 0; | 242 | return 0; |
247 | } | 243 | } |
248 | 244 | ||
245 | static struct i2c_driver lm75_driver = { | ||
246 | .driver = { | ||
247 | .name = "lm75", | ||
248 | }, | ||
249 | .attach_adapter = lm75_attach_adapter, | ||
250 | .detach_client = lm75_detach_client, | ||
251 | }; | ||
252 | |||
253 | /*-----------------------------------------------------------------------*/ | ||
254 | |||
255 | /* register access */ | ||
256 | |||
249 | /* All registers are word-sized, except for the configuration register. | 257 | /* All registers are word-sized, except for the configuration register. |
250 | LM75 uses a high-byte first convention, which is exactly opposite to | 258 | LM75 uses a high-byte first convention, which is exactly opposite to |
251 | the SMBus standard. */ | 259 | the SMBus standard. */ |
@@ -309,6 +317,10 @@ static struct lm75_data *lm75_update_device(struct device *dev) | |||
309 | return data; | 317 | return data; |
310 | } | 318 | } |
311 | 319 | ||
320 | /*-----------------------------------------------------------------------*/ | ||
321 | |||
322 | /* module glue */ | ||
323 | |||
312 | static int __init sensors_lm75_init(void) | 324 | static int __init sensors_lm75_init(void) |
313 | { | 325 | { |
314 | return i2c_add_driver(&lm75_driver); | 326 | return i2c_add_driver(&lm75_driver); |