aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-10-11 13:09:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-11 13:09:45 -0400
commit7cc4e87f912bbefa440a51856b8d076e5d1f554a (patch)
tree1b8df8683f3de37d2e8211ffa8d151f60d59af62 /drivers/hwmon
parent5ba2f67afb02c5302b2898949ed6fc3b3d37dcf1 (diff)
parent69fc7eed5f56bce15b239e5110de2575a6970df4 (diff)
Merge branch 'for-linus' of master.kernel.org:/home/rmk/linux-2.6-arm
* 'for-linus' of master.kernel.org:/home/rmk/linux-2.6-arm: (236 commits) [ARM] 5300/1: fixup spitz reset during boot [ARM] 5295/1: make ZONE_DMA optional [ARM] 5239/1: Palm Zire 72 power management support [ARM] 5298/1: Drop desc_handle_irq() [ARM] 5297/1: [KS8695] Fix two compile-time warnings [ARM] 5296/1: [KS8695] Replace macro's with trailing underscores. [ARM] pxa: allow multi-machine PCMCIA builds [ARM] pxa: add preliminary CPUFREQ support for PXA3xx [ARM] pxa: add missing ACCR bit definitions to pxa3xx-regs.h [ARM] pxa: rename cpu-pxa.c to cpufreq-pxa2xx.c [ARM] pxa/zylonite: add support for USB OHCI [ARM] ohci-pxa27x: use ioremap() and offset for register access [ARM] ohci-pxa27x: introduce pxa27x_clear_otgph() [ARM] ohci-pxa27x: use platform_get_{irq,resource} for the resource [ARM] ohci-pxa27x: move OHCI controller specific registers into the driver [ARM] ohci-pxa27x: introduce flags to avoid direct access to OHCI registers [ARM] pxa: move I2S register and bit definitions into pxa2xx-i2s.c [ARM] pxa: simplify DMA register definitions [ARM] pxa: make additional DCSR bits valid for PXA3xx [ARM] pxa: move i2c register and bit definitions into i2c-pxa.c ... Fixed up conflicts in arch/arm/mach-versatile/core.c sound/soc/pxa/pxa2xx-ac97.c sound/soc/pxa/pxa2xx-i2s.c manually.
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/Kconfig9
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/max1111.c244
3 files changed, 254 insertions, 0 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index d402e8d813ce..3309e862f317 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -540,6 +540,15 @@ config SENSORS_LM93
540 This driver can also be built as a module. If so, the module 540 This driver can also be built as a module. If so, the module
541 will be called lm93. 541 will be called lm93.
542 542
543config SENSORS_MAX1111
544 tristate "Maxim MAX1111 Multichannel, Serial 8-bit ADC chip"
545 depends on SPI_MASTER
546 help
547 Say y here to support Maxim's MAX1111 ADC chips.
548
549 This driver can also be built as a module. If so, the module
550 will be called max1111.
551
543config SENSORS_MAX1619 552config SENSORS_MAX1619
544 tristate "Maxim MAX1619 sensor chip" 553 tristate "Maxim MAX1619 sensor chip"
545 depends on I2C 554 depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 950134ab8426..6babc801b348 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -59,6 +59,7 @@ obj-$(CONFIG_SENSORS_LM87) += lm87.o
59obj-$(CONFIG_SENSORS_LM90) += lm90.o 59obj-$(CONFIG_SENSORS_LM90) += lm90.o
60obj-$(CONFIG_SENSORS_LM92) += lm92.o 60obj-$(CONFIG_SENSORS_LM92) += lm92.o
61obj-$(CONFIG_SENSORS_LM93) += lm93.o 61obj-$(CONFIG_SENSORS_LM93) += lm93.o
62obj-$(CONFIG_SENSORS_MAX1111) += max1111.o
62obj-$(CONFIG_SENSORS_MAX1619) += max1619.o 63obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
63obj-$(CONFIG_SENSORS_MAX6650) += max6650.o 64obj-$(CONFIG_SENSORS_MAX6650) += max6650.o
64obj-$(CONFIG_SENSORS_PC87360) += pc87360.o 65obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c
new file mode 100644
index 000000000000..bfaa665ccf32
--- /dev/null
+++ b/drivers/hwmon/max1111.c
@@ -0,0 +1,244 @@
1/*
2 * max1111.c - +2.7V, Low-Power, Multichannel, Serial 8-bit ADCs
3 *
4 * Based on arch/arm/mach-pxa/corgi_ssp.c
5 *
6 * Copyright (C) 2004-2005 Richard Purdie
7 *
8 * Copyright (C) 2008 Marvell International Ltd.
9 * Eric Miao <eric.miao@marvell.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * publishhed by the Free Software Foundation.
14 */
15
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/err.h>
20#include <linux/hwmon.h>
21#include <linux/hwmon-sysfs.h>
22#include <linux/spi/spi.h>
23
24#define MAX1111_TX_BUF_SIZE 1
25#define MAX1111_RX_BUF_SIZE 2
26
27/* MAX1111 Commands */
28#define MAX1111_CTRL_PD0 (1u << 0)
29#define MAX1111_CTRL_PD1 (1u << 1)
30#define MAX1111_CTRL_SGL (1u << 2)
31#define MAX1111_CTRL_UNI (1u << 3)
32#define MAX1111_CTRL_SEL_SH (5) /* NOTE: bit 4 is ignored */
33#define MAX1111_CTRL_STR (1u << 7)
34
35struct max1111_data {
36 struct spi_device *spi;
37 struct device *hwmon_dev;
38 struct spi_message msg;
39 struct spi_transfer xfer[2];
40 uint8_t *tx_buf;
41 uint8_t *rx_buf;
42};
43
44static int max1111_read(struct device *dev, int channel)
45{
46 struct max1111_data *data = dev_get_drvdata(dev);
47 uint8_t v1, v2;
48 int err;
49
50 data->tx_buf[0] = (channel << MAX1111_CTRL_SEL_SH) |
51 MAX1111_CTRL_PD0 | MAX1111_CTRL_PD1 |
52 MAX1111_CTRL_SGL | MAX1111_CTRL_UNI | MAX1111_CTRL_STR;
53
54 err = spi_sync(data->spi, &data->msg);
55 if (err < 0) {
56 dev_err(dev, "spi_sync failed with %d\n", err);
57 return err;
58 }
59
60 v1 = data->rx_buf[0];
61 v2 = data->rx_buf[1];
62
63 if ((v1 & 0xc0) || (v2 & 0x3f))
64 return -EINVAL;
65
66 return (v1 << 2) | (v2 >> 6);
67}
68
69#ifdef CONFIG_SHARPSL_PM
70static struct max1111_data *the_max1111;
71
72int max1111_read_channel(int channel)
73{
74 return max1111_read(&the_max1111->spi->dev, channel);
75}
76EXPORT_SYMBOL(max1111_read_channel);
77#endif
78
79/*
80 * NOTE: SPI devices do not have a default 'name' attribute, which is
81 * likely to be used by hwmon applications to distinguish between
82 * different devices, explicitly add a name attribute here.
83 */
84static ssize_t show_name(struct device *dev,
85 struct device_attribute *attr, char *buf)
86{
87 return sprintf(buf, "max1111\n");
88}
89
90static ssize_t show_adc(struct device *dev,
91 struct device_attribute *attr, char *buf)
92{
93 int channel = to_sensor_dev_attr(attr)->index;
94 int ret;
95
96 ret = max1111_read(dev, channel);
97 if (ret < 0)
98 return ret;
99
100 return sprintf(buf, "%d\n", ret);
101}
102
103#define MAX1111_ADC_ATTR(_id) \
104 SENSOR_DEVICE_ATTR(adc##_id##_in, S_IRUGO, show_adc, NULL, _id)
105
106static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
107static MAX1111_ADC_ATTR(0);
108static MAX1111_ADC_ATTR(1);
109static MAX1111_ADC_ATTR(2);
110static MAX1111_ADC_ATTR(3);
111
112static struct attribute *max1111_attributes[] = {
113 &dev_attr_name.attr,
114 &sensor_dev_attr_adc0_in.dev_attr.attr,
115 &sensor_dev_attr_adc1_in.dev_attr.attr,
116 &sensor_dev_attr_adc2_in.dev_attr.attr,
117 &sensor_dev_attr_adc3_in.dev_attr.attr,
118 NULL,
119};
120
121static const struct attribute_group max1111_attr_group = {
122 .attrs = max1111_attributes,
123};
124
125static int setup_transfer(struct max1111_data *data)
126{
127 struct spi_message *m;
128 struct spi_transfer *x;
129
130 data->tx_buf = kmalloc(MAX1111_TX_BUF_SIZE, GFP_KERNEL);
131 if (!data->tx_buf)
132 return -ENOMEM;
133
134 data->rx_buf = kmalloc(MAX1111_RX_BUF_SIZE, GFP_KERNEL);
135 if (!data->rx_buf) {
136 kfree(data->tx_buf);
137 return -ENOMEM;
138 }
139
140 m = &data->msg;
141 x = &data->xfer[0];
142
143 spi_message_init(m);
144
145 x->tx_buf = &data->tx_buf[0];
146 x->len = 1;
147 spi_message_add_tail(x, m);
148
149 x++;
150 x->rx_buf = &data->rx_buf[0];
151 x->len = 2;
152 spi_message_add_tail(x, m);
153
154 return 0;
155}
156
157static int __devinit max1111_probe(struct spi_device *spi)
158{
159 struct max1111_data *data;
160 int err;
161
162 spi->bits_per_word = 8;
163 spi->mode = SPI_MODE_0;
164 err = spi_setup(spi);
165 if (err < 0)
166 return err;
167
168 data = kzalloc(sizeof(struct max1111_data), GFP_KERNEL);
169 if (data == NULL) {
170 dev_err(&spi->dev, "failed to allocate memory\n");
171 return -ENOMEM;
172 }
173
174 err = setup_transfer(data);
175 if (err)
176 goto err_free_data;
177
178 data->spi = spi;
179 spi_set_drvdata(spi, data);
180
181 err = sysfs_create_group(&spi->dev.kobj, &max1111_attr_group);
182 if (err) {
183 dev_err(&spi->dev, "failed to create attribute group\n");
184 goto err_free_all;
185 }
186
187 data->hwmon_dev = hwmon_device_register(&spi->dev);
188 if (IS_ERR(data->hwmon_dev)) {
189 dev_err(&spi->dev, "failed to create hwmon device\n");
190 err = PTR_ERR(data->hwmon_dev);
191 goto err_remove;
192 }
193
194#ifdef CONFIG_SHARPSL_PM
195 the_max1111 = data;
196#endif
197 return 0;
198
199err_remove:
200 sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
201err_free_all:
202 kfree(data->rx_buf);
203 kfree(data->tx_buf);
204err_free_data:
205 kfree(data);
206 return err;
207}
208
209static int __devexit max1111_remove(struct spi_device *spi)
210{
211 struct max1111_data *data = spi_get_drvdata(spi);
212
213 hwmon_device_unregister(data->hwmon_dev);
214 sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
215 kfree(data->rx_buf);
216 kfree(data->tx_buf);
217 kfree(data);
218 return 0;
219}
220
221static struct spi_driver max1111_driver = {
222 .driver = {
223 .name = "max1111",
224 .owner = THIS_MODULE,
225 },
226 .probe = max1111_probe,
227 .remove = __devexit_p(max1111_remove),
228};
229
230static int __init max1111_init(void)
231{
232 return spi_register_driver(&max1111_driver);
233}
234module_init(max1111_init);
235
236static void __exit max1111_exit(void)
237{
238 spi_unregister_driver(&max1111_driver);
239}
240module_exit(max1111_exit);
241
242MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>");
243MODULE_DESCRIPTION("MAX1111 ADC Driver");
244MODULE_LICENSE("GPL");