2 * dac7512.c - Linux kernel module for
3 * Texas Instruments DAC7512
5 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
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.
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.
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.
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/spi/spi.h>
27 static ssize_t
dac7512_store_val(struct device
*dev
,
28 struct device_attribute
*attr
,
29 const char *buf
, size_t count
)
31 struct spi_device
*spi
= to_spi_device(dev
);
36 ret
= kstrtoul(buf
, 10, &val
);
42 spi_write(spi
, tmp
, sizeof(tmp
));
46 static DEVICE_ATTR(value
, S_IWUSR
, NULL
, dac7512_store_val
);
48 static struct attribute
*dac7512_attributes
[] = {
53 static const struct attribute_group dac7512_attr_group
= {
54 .attrs
= dac7512_attributes
,
57 static int dac7512_probe(struct spi_device
*spi
)
61 spi
->bits_per_word
= 8;
62 spi
->mode
= SPI_MODE_0
;
67 return sysfs_create_group(&spi
->dev
.kobj
, &dac7512_attr_group
);
70 static int dac7512_remove(struct spi_device
*spi
)
72 sysfs_remove_group(&spi
->dev
.kobj
, &dac7512_attr_group
);
76 static const struct spi_device_id dac7512_id_table
[] = {
80 MODULE_DEVICE_TABLE(spi
, dac7512_id_table
);
83 static const struct of_device_id dac7512_of_match
[] = {
84 { .compatible
= "ti,dac7512", },
87 MODULE_DEVICE_TABLE(of
, dac7512_of_match
);
90 static struct spi_driver dac7512_driver
= {
94 .of_match_table
= of_match_ptr(dac7512_of_match
),
96 .probe
= dac7512_probe
,
97 .remove
= dac7512_remove
,
98 .id_table
= dac7512_id_table
,
101 module_spi_driver(dac7512_driver
);
103 MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
104 MODULE_DESCRIPTION("DAC7512 16-bit DAC");
105 MODULE_LICENSE("GPL v2");