2
* AD7606 SPI ADC driver
4
* Copyright 2011 Analog Devices Inc.
6
* Licensed under the GPL-2.
9
#include <linux/module.h>
10
#include <linux/spi/spi.h>
11
#include <linux/types.h>
12
#include <linux/err.h>
15
#define MAX_SPI_FREQ_HZ 23500000 /* VDRIVE above 4.75 V */
17
static int ad7606_spi_read_block(struct device *dev,
20
struct spi_device *spi = to_spi_device(dev);
22
unsigned short *data = buf;
24
ret = spi_read(spi, (u8 *)buf, count * 2);
26
dev_err(&spi->dev, "SPI read error\n");
30
for (i = 0; i < count; i++)
31
data[i] = be16_to_cpu(data[i]);
36
static const struct ad7606_bus_ops ad7606_spi_bops = {
37
.read_block = ad7606_spi_read_block,
40
static int __devinit ad7606_spi_probe(struct spi_device *spi)
42
struct ad7606_state *st;
44
st = ad7606_probe(&spi->dev, spi->irq, NULL,
45
spi_get_device_id(spi)->driver_data,
51
spi_set_drvdata(spi, st);
56
static int __devexit ad7606_spi_remove(struct spi_device *spi)
58
struct ad7606_state *st = dev_get_drvdata(&spi->dev);
60
return ad7606_remove(st);
64
static int ad7606_spi_suspend(struct device *dev)
66
struct ad7606_state *st = dev_get_drvdata(dev);
73
static int ad7606_spi_resume(struct device *dev)
75
struct ad7606_state *st = dev_get_drvdata(dev);
82
static const struct dev_pm_ops ad7606_pm_ops = {
83
.suspend = ad7606_spi_suspend,
84
.resume = ad7606_spi_resume,
86
#define AD7606_SPI_PM_OPS (&ad7606_pm_ops)
89
#define AD7606_SPI_PM_OPS NULL
92
static const struct spi_device_id ad7606_id[] = {
93
{"ad7606-8", ID_AD7606_8},
94
{"ad7606-6", ID_AD7606_6},
95
{"ad7606-4", ID_AD7606_4},
99
static struct spi_driver ad7606_driver = {
102
.bus = &spi_bus_type,
103
.owner = THIS_MODULE,
104
.pm = AD7606_SPI_PM_OPS,
106
.probe = ad7606_spi_probe,
107
.remove = __devexit_p(ad7606_spi_remove),
108
.id_table = ad7606_id,
111
static int __init ad7606_spi_init(void)
113
return spi_register_driver(&ad7606_driver);
115
module_init(ad7606_spi_init);
117
static void __exit ad7606_spi_exit(void)
119
spi_unregister_driver(&ad7606_driver);
121
module_exit(ad7606_spi_exit);
123
MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
124
MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
125
MODULE_LICENSE("GPL v2");
126
MODULE_ALIAS("spi:ad7606_spi");