Source
x
static ssize_t voltage_show(struct device *dev, struct device_attribute *da,
/*
* ads7871 - driver for TI ADS7871 A/D converter
*
* Copyright (c) 2010 Paul Thomas <pthomas8589@gmail.com>
*
* 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.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 or
* later as publishhed by the Free Software Foundation.
*
* You need to have something like this in struct spi_board_info
* {
* .modalias = "ads7871",
* .max_speed_hz = 2*1000*1000,
* .chip_select = 0,
* .bus_num = 1,
* },
*/
/*From figure 18 in the datasheet*/
/*Register addresses*/
/*A/D Output Data, LS Byte*/
/*A/D Output Data, MS Byte*/
/*PGA Valid Register*/
/*A/D Control Register*/
/*Gain/Mux Register*/
/*Digital I/O State Register*/
/*Digital I/O Control Register*/
/*Rev/Oscillator Control Register*/
/*Serial Interface Control Register*/
/*ID Register*/
/*
* From figure 17 in the datasheet
* These bits get ORed with the address to form
* the instruction byte
*/
/*Instruction Bit masks*/
/*From figure 18 in the datasheet*/
/*bit masks for Rev/Oscillator Control Register*/
/*M3 selects single ended*/
/*allows for reg = (gain << MUX_G_BV) | ...*/
/*From figure 18 in the datasheet*/
/*bit masks for Rev/Oscillator Control Register*/
struct ads7871_data {
struct spi_device *spi;
};
static int ads7871_read_reg8(struct spi_device *spi, int reg)
{
int ret;
reg = reg | INST_READ_BM;
ret = spi_w8r8(spi, reg);
return ret;
}
static int ads7871_read_reg16(struct spi_device *spi, int reg)
{
int ret;
reg = reg | INST_READ_BM | INST_16BIT_BM;
ret = spi_w8r16(spi, reg);
return ret;
}