ad525x_dpot: add support for SPI parts
Split the bus logic out into separate files so that we can handle I2C and
SPI busses independently. The new SPI bus logic brings in support for a
lot more parts:
AD5160, AD5161, AD5162, AD5165, AD5200, AD5201, AD5203,
AD5204, AD5206, AD5207, AD5231, AD5232, AD5233, AD5235,
AD5260, AD5262, AD5263, AD5290, AD5291, AD5292, AD5293,
AD7376, AD8400, AD8402, AD8403, ADN2850
[randy.dunlap@oracle.com: fix ad525X_dpot build]
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-05-25 05:33:14 +08:00
|
|
|
/*
|
|
|
|
* Driver for the Analog Devices digital potentiometers (SPI bus)
|
|
|
|
*
|
2011-11-18 18:05:11 +08:00
|
|
|
* Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc.
|
ad525x_dpot: add support for SPI parts
Split the bus logic out into separate files so that we can handle I2C and
SPI busses independently. The new SPI bus logic brings in support for a
lot more parts:
AD5160, AD5161, AD5162, AD5165, AD5200, AD5201, AD5203,
AD5204, AD5206, AD5207, AD5231, AD5232, AD5233, AD5235,
AD5260, AD5262, AD5263, AD5290, AD5291, AD5292, AD5293,
AD7376, AD8400, AD8402, AD8403, ADN2850
[randy.dunlap@oracle.com: fix ad525X_dpot build]
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-05-25 05:33:14 +08:00
|
|
|
*
|
|
|
|
* Licensed under the GPL-2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include "ad525x_dpot.h"
|
|
|
|
|
|
|
|
/* SPI bus functions */
|
|
|
|
static int write8(void *client, u8 val)
|
|
|
|
{
|
|
|
|
u8 data = val;
|
|
|
|
return spi_write(client, &data, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int write16(void *client, u8 reg, u8 val)
|
|
|
|
{
|
|
|
|
u8 data[2] = {reg, val};
|
2010-10-27 05:21:16 +08:00
|
|
|
return spi_write(client, data, 2);
|
ad525x_dpot: add support for SPI parts
Split the bus logic out into separate files so that we can handle I2C and
SPI busses independently. The new SPI bus logic brings in support for a
lot more parts:
AD5160, AD5161, AD5162, AD5165, AD5200, AD5201, AD5203,
AD5204, AD5206, AD5207, AD5231, AD5232, AD5233, AD5235,
AD5260, AD5262, AD5263, AD5290, AD5291, AD5292, AD5293,
AD7376, AD8400, AD8402, AD8403, ADN2850
[randy.dunlap@oracle.com: fix ad525X_dpot build]
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-05-25 05:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int write24(void *client, u8 reg, u16 val)
|
|
|
|
{
|
|
|
|
u8 data[3] = {reg, val >> 8, val};
|
2010-10-27 05:21:16 +08:00
|
|
|
return spi_write(client, data, 3);
|
ad525x_dpot: add support for SPI parts
Split the bus logic out into separate files so that we can handle I2C and
SPI busses independently. The new SPI bus logic brings in support for a
lot more parts:
AD5160, AD5161, AD5162, AD5165, AD5200, AD5201, AD5203,
AD5204, AD5206, AD5207, AD5231, AD5232, AD5233, AD5235,
AD5260, AD5262, AD5263, AD5290, AD5291, AD5292, AD5293,
AD7376, AD8400, AD8402, AD8403, ADN2850
[randy.dunlap@oracle.com: fix ad525X_dpot build]
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-05-25 05:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int read8(void *client)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u8 data;
|
|
|
|
ret = spi_read(client, &data, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read16(void *client, u8 reg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u8 buf_rx[2];
|
|
|
|
|
|
|
|
write16(client, reg, 0);
|
|
|
|
ret = spi_read(client, buf_rx, 2);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return (buf_rx[0] << 8) | buf_rx[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read24(void *client, u8 reg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u8 buf_rx[3];
|
|
|
|
|
|
|
|
write24(client, reg, 0);
|
|
|
|
ret = spi_read(client, buf_rx, 3);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return (buf_rx[1] << 8) | buf_rx[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ad_dpot_bus_ops bops = {
|
|
|
|
.read_d8 = read8,
|
|
|
|
.read_r8d8 = read16,
|
|
|
|
.read_r8d16 = read24,
|
|
|
|
.write_d8 = write8,
|
|
|
|
.write_r8d8 = write16,
|
|
|
|
.write_r8d16 = write24,
|
|
|
|
};
|
|
|
|
static int __devinit ad_dpot_spi_probe(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct ad_dpot_bus_data bdata = {
|
|
|
|
.client = spi,
|
|
|
|
.bops = &bops,
|
|
|
|
};
|
|
|
|
|
2011-11-18 18:05:11 +08:00
|
|
|
return ad_dpot_probe(&spi->dev, &bdata,
|
|
|
|
spi_get_device_id(spi)->driver_data,
|
|
|
|
spi_get_device_id(spi)->name);
|
ad525x_dpot: add support for SPI parts
Split the bus logic out into separate files so that we can handle I2C and
SPI busses independently. The new SPI bus logic brings in support for a
lot more parts:
AD5160, AD5161, AD5162, AD5165, AD5200, AD5201, AD5203,
AD5204, AD5206, AD5207, AD5231, AD5232, AD5233, AD5235,
AD5260, AD5262, AD5263, AD5290, AD5291, AD5292, AD5293,
AD7376, AD8400, AD8402, AD8403, ADN2850
[randy.dunlap@oracle.com: fix ad525X_dpot build]
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-05-25 05:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit ad_dpot_spi_remove(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
return ad_dpot_remove(&spi->dev);
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:05:11 +08:00
|
|
|
static const struct spi_device_id ad_dpot_spi_id[] = {
|
|
|
|
{"ad5160", AD5160_ID},
|
|
|
|
{"ad5161", AD5161_ID},
|
|
|
|
{"ad5162", AD5162_ID},
|
|
|
|
{"ad5165", AD5165_ID},
|
|
|
|
{"ad5200", AD5200_ID},
|
|
|
|
{"ad5201", AD5201_ID},
|
|
|
|
{"ad5203", AD5203_ID},
|
|
|
|
{"ad5204", AD5204_ID},
|
|
|
|
{"ad5206", AD5206_ID},
|
|
|
|
{"ad5207", AD5207_ID},
|
|
|
|
{"ad5231", AD5231_ID},
|
|
|
|
{"ad5232", AD5232_ID},
|
|
|
|
{"ad5233", AD5233_ID},
|
|
|
|
{"ad5235", AD5235_ID},
|
|
|
|
{"ad5260", AD5260_ID},
|
|
|
|
{"ad5262", AD5262_ID},
|
|
|
|
{"ad5263", AD5263_ID},
|
|
|
|
{"ad5290", AD5290_ID},
|
|
|
|
{"ad5291", AD5291_ID},
|
|
|
|
{"ad5292", AD5292_ID},
|
|
|
|
{"ad5293", AD5293_ID},
|
|
|
|
{"ad7376", AD7376_ID},
|
|
|
|
{"ad8400", AD8400_ID},
|
|
|
|
{"ad8402", AD8402_ID},
|
|
|
|
{"ad8403", AD8403_ID},
|
|
|
|
{"adn2850", ADN2850_ID},
|
|
|
|
{"ad5270", AD5270_ID},
|
|
|
|
{"ad5271", AD5271_ID},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(spi, ad_dpot_spi_id);
|
|
|
|
|
ad525x_dpot: add support for SPI parts
Split the bus logic out into separate files so that we can handle I2C and
SPI busses independently. The new SPI bus logic brings in support for a
lot more parts:
AD5160, AD5161, AD5162, AD5165, AD5200, AD5201, AD5203,
AD5204, AD5206, AD5207, AD5231, AD5232, AD5233, AD5235,
AD5260, AD5262, AD5263, AD5290, AD5291, AD5292, AD5293,
AD7376, AD8400, AD8402, AD8403, ADN2850
[randy.dunlap@oracle.com: fix ad525X_dpot build]
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-05-25 05:33:14 +08:00
|
|
|
static struct spi_driver ad_dpot_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ad_dpot",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = ad_dpot_spi_probe,
|
|
|
|
.remove = __devexit_p(ad_dpot_spi_remove),
|
2011-11-18 18:05:11 +08:00
|
|
|
.id_table = ad_dpot_spi_id,
|
ad525x_dpot: add support for SPI parts
Split the bus logic out into separate files so that we can handle I2C and
SPI busses independently. The new SPI bus logic brings in support for a
lot more parts:
AD5160, AD5161, AD5162, AD5165, AD5200, AD5201, AD5203,
AD5204, AD5206, AD5207, AD5231, AD5232, AD5233, AD5235,
AD5260, AD5262, AD5263, AD5290, AD5291, AD5292, AD5293,
AD7376, AD8400, AD8402, AD8403, ADN2850
[randy.dunlap@oracle.com: fix ad525X_dpot build]
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-05-25 05:33:14 +08:00
|
|
|
};
|
|
|
|
|
2012-01-22 15:38:22 +08:00
|
|
|
module_spi_driver(ad_dpot_spi_driver);
|
ad525x_dpot: add support for SPI parts
Split the bus logic out into separate files so that we can handle I2C and
SPI busses independently. The new SPI bus logic brings in support for a
lot more parts:
AD5160, AD5161, AD5162, AD5165, AD5200, AD5201, AD5203,
AD5204, AD5206, AD5207, AD5231, AD5232, AD5233, AD5235,
AD5260, AD5262, AD5263, AD5290, AD5291, AD5292, AD5293,
AD7376, AD8400, AD8402, AD8403, ADN2850
[randy.dunlap@oracle.com: fix ad525X_dpot build]
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-05-25 05:33:14 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
|
|
|
|
MODULE_DESCRIPTION("digital potentiometer SPI bus driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("spi:ad_dpot");
|