aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/max1111.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-08-20 21:52:36 -0400
committerGuenter Roeck <linux@roeck-us.net>2012-09-24 00:08:34 -0400
commit9224c38a312a339f1c9c2115a1f379c9f8f1731e (patch)
tree05c6319616e9ab13c63314b992f7687918780a9e /drivers/hwmon/max1111.c
parenta86e94dc946d58fb5abb8e250a99720c9bdf8c2d (diff)
hwmon: (max1111) Add support for MAX1110, MAX1112, and MAX1113
MAX1110 is similar to MAX1111, with 8 instead of 4 channels. MAX1112 and MAX1113 are similar to MAX1110 and MAX1111, with 4.096V reference voltage instead of 2.048V. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/max1111.c')
-rw-r--r--drivers/hwmon/max1111.c74
1 files changed, 67 insertions, 7 deletions
diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c
index f3978a46e844..b4eb0889c465 100644
--- a/drivers/hwmon/max1111.c
+++ b/drivers/hwmon/max1111.c
@@ -22,6 +22,8 @@
22#include <linux/spi/spi.h> 22#include <linux/spi/spi.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24 24
25enum chips { max1110, max1111, max1112, max1113 };
26
25#define MAX1111_TX_BUF_SIZE 1 27#define MAX1111_TX_BUF_SIZE 1
26#define MAX1111_RX_BUF_SIZE 2 28#define MAX1111_RX_BUF_SIZE 2
27 29
@@ -30,6 +32,7 @@
30#define MAX1111_CTRL_PD1 (1u << 1) 32#define MAX1111_CTRL_PD1 (1u << 1)
31#define MAX1111_CTRL_SGL (1u << 2) 33#define MAX1111_CTRL_SGL (1u << 2)
32#define MAX1111_CTRL_UNI (1u << 3) 34#define MAX1111_CTRL_UNI (1u << 3)
35#define MAX1110_CTRL_SEL_SH (4)
33#define MAX1111_CTRL_SEL_SH (5) /* NOTE: bit 4 is ignored */ 36#define MAX1111_CTRL_SEL_SH (5) /* NOTE: bit 4 is ignored */
34#define MAX1111_CTRL_STR (1u << 7) 37#define MAX1111_CTRL_STR (1u << 7)
35 38
@@ -42,6 +45,8 @@ struct max1111_data {
42 uint8_t rx_buf[MAX1111_RX_BUF_SIZE]; 45 uint8_t rx_buf[MAX1111_RX_BUF_SIZE];
43 struct mutex drvdata_lock; 46 struct mutex drvdata_lock;
44 /* protect msg, xfer and buffers from multiple access */ 47 /* protect msg, xfer and buffers from multiple access */
48 int sel_sh;
49 int lsb;
45}; 50};
46 51
47static int max1111_read(struct device *dev, int channel) 52static int max1111_read(struct device *dev, int channel)
@@ -53,7 +58,7 @@ static int max1111_read(struct device *dev, int channel)
53 /* writing to drvdata struct is not thread safe, wait on mutex */ 58 /* writing to drvdata struct is not thread safe, wait on mutex */
54 mutex_lock(&data->drvdata_lock); 59 mutex_lock(&data->drvdata_lock);
55 60
56 data->tx_buf[0] = (channel << MAX1111_CTRL_SEL_SH) | 61 data->tx_buf[0] = (channel << data->sel_sh) |
57 MAX1111_CTRL_PD0 | MAX1111_CTRL_PD1 | 62 MAX1111_CTRL_PD0 | MAX1111_CTRL_PD1 |
58 MAX1111_CTRL_SGL | MAX1111_CTRL_UNI | MAX1111_CTRL_STR; 63 MAX1111_CTRL_SGL | MAX1111_CTRL_UNI | MAX1111_CTRL_STR;
59 64
@@ -93,12 +98,13 @@ EXPORT_SYMBOL(max1111_read_channel);
93static ssize_t show_name(struct device *dev, 98static ssize_t show_name(struct device *dev,
94 struct device_attribute *attr, char *buf) 99 struct device_attribute *attr, char *buf)
95{ 100{
96 return sprintf(buf, "max1111\n"); 101 return sprintf(buf, "%s\n", to_spi_device(dev)->modalias);
97} 102}
98 103
99static ssize_t show_adc(struct device *dev, 104static ssize_t show_adc(struct device *dev,
100 struct device_attribute *attr, char *buf) 105 struct device_attribute *attr, char *buf)
101{ 106{
107 struct max1111_data *data = dev_get_drvdata(dev);
102 int channel = to_sensor_dev_attr(attr)->index; 108 int channel = to_sensor_dev_attr(attr)->index;
103 int ret; 109 int ret;
104 110
@@ -107,10 +113,10 @@ static ssize_t show_adc(struct device *dev,
107 return ret; 113 return ret;
108 114
109 /* 115 /*
110 * assume the reference voltage to be 2.048V, with an 8-bit sample, 116 * Assume the reference voltage to be 2.048V or 4.096V, with an 8-bit
111 * the LSB weight is 8mV 117 * sample. The LSB weight is 8mV or 16mV depending on the chip type.
112 */ 118 */
113 return sprintf(buf, "%d\n", ret * 8); 119 return sprintf(buf, "%d\n", ret * data->lsb);
114} 120}
115 121
116#define MAX1111_ADC_ATTR(_id) \ 122#define MAX1111_ADC_ATTR(_id) \
@@ -121,6 +127,10 @@ static MAX1111_ADC_ATTR(0);
121static MAX1111_ADC_ATTR(1); 127static MAX1111_ADC_ATTR(1);
122static MAX1111_ADC_ATTR(2); 128static MAX1111_ADC_ATTR(2);
123static MAX1111_ADC_ATTR(3); 129static MAX1111_ADC_ATTR(3);
130static MAX1111_ADC_ATTR(4);
131static MAX1111_ADC_ATTR(5);
132static MAX1111_ADC_ATTR(6);
133static MAX1111_ADC_ATTR(7);
124 134
125static struct attribute *max1111_attributes[] = { 135static struct attribute *max1111_attributes[] = {
126 &dev_attr_name.attr, 136 &dev_attr_name.attr,
@@ -135,6 +145,18 @@ static const struct attribute_group max1111_attr_group = {
135 .attrs = max1111_attributes, 145 .attrs = max1111_attributes,
136}; 146};
137 147
148static struct attribute *max1110_attributes[] = {
149 &sensor_dev_attr_in4_input.dev_attr.attr,
150 &sensor_dev_attr_in5_input.dev_attr.attr,
151 &sensor_dev_attr_in6_input.dev_attr.attr,
152 &sensor_dev_attr_in7_input.dev_attr.attr,
153 NULL,
154};
155
156static const struct attribute_group max1110_attr_group = {
157 .attrs = max1110_attributes,
158};
159
138static int __devinit setup_transfer(struct max1111_data *data) 160static int __devinit setup_transfer(struct max1111_data *data)
139{ 161{
140 struct spi_message *m; 162 struct spi_message *m;
@@ -159,6 +181,7 @@ static int __devinit setup_transfer(struct max1111_data *data)
159 181
160static int __devinit max1111_probe(struct spi_device *spi) 182static int __devinit max1111_probe(struct spi_device *spi)
161{ 183{
184 enum chips chip = spi_get_device_id(spi)->driver_data;
162 struct max1111_data *data; 185 struct max1111_data *data;
163 int err; 186 int err;
164 187
@@ -174,6 +197,24 @@ static int __devinit max1111_probe(struct spi_device *spi)
174 return -ENOMEM; 197 return -ENOMEM;
175 } 198 }
176 199
200 switch (chip) {
201 case max1110:
202 data->lsb = 8;
203 data->sel_sh = MAX1110_CTRL_SEL_SH;
204 break;
205 case max1111:
206 data->lsb = 8;
207 data->sel_sh = MAX1111_CTRL_SEL_SH;
208 break;
209 case max1112:
210 data->lsb = 16;
211 data->sel_sh = MAX1110_CTRL_SEL_SH;
212 break;
213 case max1113:
214 data->lsb = 16;
215 data->sel_sh = MAX1111_CTRL_SEL_SH;
216 break;
217 }
177 err = setup_transfer(data); 218 err = setup_transfer(data);
178 if (err) 219 if (err)
179 return err; 220 return err;
@@ -188,6 +229,14 @@ static int __devinit max1111_probe(struct spi_device *spi)
188 dev_err(&spi->dev, "failed to create attribute group\n"); 229 dev_err(&spi->dev, "failed to create attribute group\n");
189 return err; 230 return err;
190 } 231 }
232 if (chip == max1110 || chip == max1112) {
233 err = sysfs_create_group(&spi->dev.kobj, &max1110_attr_group);
234 if (err) {
235 dev_err(&spi->dev,
236 "failed to create extended attribute group\n");
237 goto err_remove;
238 }
239 }
191 240
192 data->hwmon_dev = hwmon_device_register(&spi->dev); 241 data->hwmon_dev = hwmon_device_register(&spi->dev);
193 if (IS_ERR(data->hwmon_dev)) { 242 if (IS_ERR(data->hwmon_dev)) {
@@ -202,6 +251,7 @@ static int __devinit max1111_probe(struct spi_device *spi)
202 return 0; 251 return 0;
203 252
204err_remove: 253err_remove:
254 sysfs_remove_group(&spi->dev.kobj, &max1110_attr_group);
205 sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group); 255 sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
206 return err; 256 return err;
207} 257}
@@ -211,16 +261,27 @@ static int __devexit max1111_remove(struct spi_device *spi)
211 struct max1111_data *data = spi_get_drvdata(spi); 261 struct max1111_data *data = spi_get_drvdata(spi);
212 262
213 hwmon_device_unregister(data->hwmon_dev); 263 hwmon_device_unregister(data->hwmon_dev);
264 sysfs_remove_group(&spi->dev.kobj, &max1110_attr_group);
214 sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group); 265 sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
215 mutex_destroy(&data->drvdata_lock); 266 mutex_destroy(&data->drvdata_lock);
216 return 0; 267 return 0;
217} 268}
218 269
270static const struct spi_device_id max1111_ids[] = {
271 { "max1110", max1110 },
272 { "max1111", max1111 },
273 { "max1112", max1112 },
274 { "max1113", max1113 },
275 { },
276};
277MODULE_DEVICE_TABLE(spi, max1111_ids);
278
219static struct spi_driver max1111_driver = { 279static struct spi_driver max1111_driver = {
220 .driver = { 280 .driver = {
221 .name = "max1111", 281 .name = "max1111",
222 .owner = THIS_MODULE, 282 .owner = THIS_MODULE,
223 }, 283 },
284 .id_table = max1111_ids,
224 .probe = max1111_probe, 285 .probe = max1111_probe,
225 .remove = __devexit_p(max1111_remove), 286 .remove = __devexit_p(max1111_remove),
226}; 287};
@@ -228,6 +289,5 @@ static struct spi_driver max1111_driver = {
228module_spi_driver(max1111_driver); 289module_spi_driver(max1111_driver);
229 290
230MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"); 291MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>");
231MODULE_DESCRIPTION("MAX1111 ADC Driver"); 292MODULE_DESCRIPTION("MAX1110/MAX1111/MAX1112/MAX1113 ADC Driver");
232MODULE_LICENSE("GPL"); 293MODULE_LICENSE("GPL");
233MODULE_ALIAS("spi:max1111");