Blame view

drivers/misc/ti_dac7512.c 2.5 KB
4d00928c1   Daniel Mack   drivers/misc: add...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  /*
   *  dac7512.c - Linux kernel module for
   * 	Texas Instruments DAC7512
   *
   *  Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2 of the License, or
   *  (at your option) any later version.
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, write to the Free Software
   *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   */
  
  #include <linux/module.h>
4d00928c1   Daniel Mack   drivers/misc: add...
23
  #include <linux/spi/spi.h>
f91f9258f   Daniel Mack   drivers: misc: ti...
24
  #include <linux/of.h>
4d00928c1   Daniel Mack   drivers/misc: add...
25

4d00928c1   Daniel Mack   drivers/misc: add...
26
27
28
29
30
31
32
  static ssize_t dac7512_store_val(struct device *dev,
  				 struct device_attribute *attr,
  				 const char *buf, size_t count)
  {
  	struct spi_device *spi = to_spi_device(dev);
  	unsigned char tmp[2];
  	unsigned long val;
f7b41276b   Jingoo Han   misc: replace str...
33
  	int ret;
4d00928c1   Daniel Mack   drivers/misc: add...
34

f7b41276b   Jingoo Han   misc: replace str...
35
36
37
  	ret = kstrtoul(buf, 10, &val);
  	if (ret)
  		return ret;
4d00928c1   Daniel Mack   drivers/misc: add...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  
  	tmp[0] = val >> 8;
  	tmp[1] = val & 0xff;
  	spi_write(spi, tmp, sizeof(tmp));
  	return count;
  }
  
  static DEVICE_ATTR(value, S_IWUSR, NULL, dac7512_store_val);
  
  static struct attribute *dac7512_attributes[] = {
  	&dev_attr_value.attr,
  	NULL
  };
  
  static const struct attribute_group dac7512_attr_group = {
  	.attrs = dac7512_attributes,
  };
80c8ae289   Bill Pemberton   misc: remove use ...
55
  static int dac7512_probe(struct spi_device *spi)
4d00928c1   Daniel Mack   drivers/misc: add...
56
57
58
59
60
61
62
63
64
65
66
  {
  	int ret;
  
  	spi->bits_per_word = 8;
  	spi->mode = SPI_MODE_0;
  	ret = spi_setup(spi);
  	if (ret < 0)
  		return ret;
  
  	return sysfs_create_group(&spi->dev.kobj, &dac7512_attr_group);
  }
486a5c28c   Bill Pemberton   misc: remove use ...
67
  static int dac7512_remove(struct spi_device *spi)
4d00928c1   Daniel Mack   drivers/misc: add...
68
69
70
71
  {
  	sysfs_remove_group(&spi->dev.kobj, &dac7512_attr_group);
  	return 0;
  }
beb900fc2   Daniel Mack   drivers: misc: ti...
72
73
74
75
76
  static const struct spi_device_id dac7512_id_table[] = {
  	{ "dac7512", 0 },
  	{ }
  };
  MODULE_DEVICE_TABLE(spi, dac7512_id_table);
f91f9258f   Daniel Mack   drivers: misc: ti...
77
78
79
80
81
82
83
  #ifdef CONFIG_OF
  static const struct of_device_id dac7512_of_match[] = {
  	{ .compatible = "ti,dac7512", },
  	{ }
  };
  MODULE_DEVICE_TABLE(of, dac7512_of_match);
  #endif
4d00928c1   Daniel Mack   drivers/misc: add...
84
85
  static struct spi_driver dac7512_driver = {
  	.driver = {
e06465050   Daniel Mack   drivers: misc: ti...
86
  		.name	= "dac7512",
f91f9258f   Daniel Mack   drivers: misc: ti...
87
  		.of_match_table = of_match_ptr(dac7512_of_match),
4d00928c1   Daniel Mack   drivers/misc: add...
88
89
  	},
  	.probe	= dac7512_probe,
2d6bed9ca   Bill Pemberton   drivers/misc: rem...
90
  	.remove	= dac7512_remove,
beb900fc2   Daniel Mack   drivers: misc: ti...
91
  	.id_table = dac7512_id_table,
4d00928c1   Daniel Mack   drivers/misc: add...
92
  };
a3dc3c9eb   Axel Lin   MISC: convert dri...
93
  module_spi_driver(dac7512_driver);
4d00928c1   Daniel Mack   drivers/misc: add...
94
95
96
97
  
  MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
  MODULE_DESCRIPTION("DAC7512 16-bit DAC");
  MODULE_LICENSE("GPL v2");