diff options
author | Daniel Mack <daniel@caiaq.de> | 2009-12-14 21:00:17 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-15 11:53:25 -0500 |
commit | 4d00928c1f02defc81afcc5cc6198581c4bd03e8 (patch) | |
tree | 79d86f033dec3a2c5c9cfb5a9856eb9735ca92d7 | |
parent | c0f68c2fab4898bcc4671a8fb941f428856b4ad5 (diff) |
drivers/misc: add driver for Texas Instruments DAC7512
Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: "H Hartley Sweeten" <hartleys@visionengravers.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/misc/Kconfig | 10 | ||||
-rw-r--r-- | drivers/misc/Makefile | 1 | ||||
-rw-r--r-- | drivers/misc/ti_dac7512.c | 101 |
3 files changed, 112 insertions, 0 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 0c7f4c5dd07f..724d1188a322 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig | |||
@@ -270,6 +270,16 @@ config DS1682 | |||
270 | This driver can also be built as a module. If so, the module | 270 | This driver can also be built as a module. If so, the module |
271 | will be called ds1682. | 271 | will be called ds1682. |
272 | 272 | ||
273 | config TI_DAC7512 | ||
274 | tristate "Texas Instruments DAC7512" | ||
275 | depends on SPI && SYSFS | ||
276 | help | ||
277 | If you say yes here you get support for the Texas Instruments | ||
278 | DAC7512 16-bit digital-to-analog converter. | ||
279 | |||
280 | This driver can also be built as a module. If so, the module | ||
281 | will be calles ti_dac7512. | ||
282 | |||
273 | source "drivers/misc/c2port/Kconfig" | 283 | source "drivers/misc/c2port/Kconfig" |
274 | source "drivers/misc/eeprom/Kconfig" | 284 | source "drivers/misc/eeprom/Kconfig" |
275 | source "drivers/misc/cb710/Kconfig" | 285 | source "drivers/misc/cb710/Kconfig" |
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 18c8418a5132..e76b77977442 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile | |||
@@ -22,6 +22,7 @@ obj-$(CONFIG_HP_ILO) += hpilo.o | |||
22 | obj-$(CONFIG_ISL29003) += isl29003.o | 22 | obj-$(CONFIG_ISL29003) += isl29003.o |
23 | obj-$(CONFIG_EP93XX_PWM) += ep93xx_pwm.o | 23 | obj-$(CONFIG_EP93XX_PWM) += ep93xx_pwm.o |
24 | obj-$(CONFIG_DS1682) += ds1682.o | 24 | obj-$(CONFIG_DS1682) += ds1682.o |
25 | obj-$(CONFIG_TI_DAC7512) += ti_dac7512.o | ||
25 | obj-$(CONFIG_C2PORT) += c2port/ | 26 | obj-$(CONFIG_C2PORT) += c2port/ |
26 | obj-$(CONFIG_IWMC3200TOP) += iwmc3200top/ | 27 | obj-$(CONFIG_IWMC3200TOP) += iwmc3200top/ |
27 | obj-y += eeprom/ | 28 | obj-y += eeprom/ |
diff --git a/drivers/misc/ti_dac7512.c b/drivers/misc/ti_dac7512.c new file mode 100644 index 000000000000..d3f229a3a77e --- /dev/null +++ b/drivers/misc/ti_dac7512.c | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | * dac7512.c - Linux kernel module for | ||
3 | * Texas Instruments DAC7512 | ||
4 | * | ||
5 | * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de> | ||
6 | * | ||
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 | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/spi/spi.h> | ||
25 | |||
26 | #define DAC7512_DRV_NAME "dac7512" | ||
27 | #define DRIVER_VERSION "1.0" | ||
28 | |||
29 | static ssize_t dac7512_store_val(struct device *dev, | ||
30 | struct device_attribute *attr, | ||
31 | const char *buf, size_t count) | ||
32 | { | ||
33 | struct spi_device *spi = to_spi_device(dev); | ||
34 | unsigned char tmp[2]; | ||
35 | unsigned long val; | ||
36 | |||
37 | if (strict_strtoul(buf, 10, &val) < 0) | ||
38 | return -EINVAL; | ||
39 | |||
40 | tmp[0] = val >> 8; | ||
41 | tmp[1] = val & 0xff; | ||
42 | spi_write(spi, tmp, sizeof(tmp)); | ||
43 | return count; | ||
44 | } | ||
45 | |||
46 | static DEVICE_ATTR(value, S_IWUSR, NULL, dac7512_store_val); | ||
47 | |||
48 | static struct attribute *dac7512_attributes[] = { | ||
49 | &dev_attr_value.attr, | ||
50 | NULL | ||
51 | }; | ||
52 | |||
53 | static const struct attribute_group dac7512_attr_group = { | ||
54 | .attrs = dac7512_attributes, | ||
55 | }; | ||
56 | |||
57 | static int __devinit dac7512_probe(struct spi_device *spi) | ||
58 | { | ||
59 | int ret; | ||
60 | |||
61 | spi->bits_per_word = 8; | ||
62 | spi->mode = SPI_MODE_0; | ||
63 | ret = spi_setup(spi); | ||
64 | if (ret < 0) | ||
65 | return ret; | ||
66 | |||
67 | return sysfs_create_group(&spi->dev.kobj, &dac7512_attr_group); | ||
68 | } | ||
69 | |||
70 | static int __devexit dac7512_remove(struct spi_device *spi) | ||
71 | { | ||
72 | sysfs_remove_group(&spi->dev.kobj, &dac7512_attr_group); | ||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | static struct spi_driver dac7512_driver = { | ||
77 | .driver = { | ||
78 | .name = DAC7512_DRV_NAME, | ||
79 | .owner = THIS_MODULE, | ||
80 | }, | ||
81 | .probe = dac7512_probe, | ||
82 | .remove = __devexit_p(dac7512_remove), | ||
83 | }; | ||
84 | |||
85 | static int __init dac7512_init(void) | ||
86 | { | ||
87 | return spi_register_driver(&dac7512_driver); | ||
88 | } | ||
89 | |||
90 | static void __exit dac7512_exit(void) | ||
91 | { | ||
92 | spi_unregister_driver(&dac7512_driver); | ||
93 | } | ||
94 | |||
95 | MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); | ||
96 | MODULE_DESCRIPTION("DAC7512 16-bit DAC"); | ||
97 | MODULE_LICENSE("GPL v2"); | ||
98 | MODULE_VERSION(DRIVER_VERSION); | ||
99 | |||
100 | module_init(dac7512_init); | ||
101 | module_exit(dac7512_exit); | ||