drivers/adc: Switch ti_adc108s102 driver to new SPI API
Replacing legacy API calls by news ones. Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
2f7e6b6d42
commit
d620c16a0d
4 changed files with 31 additions and 71 deletions
|
@ -19,33 +19,12 @@ config PWM
|
|||
config SPI
|
||||
def_bool y
|
||||
|
||||
config ADC
|
||||
def_bool y
|
||||
|
||||
config SHARED_IRQ
|
||||
def_bool y
|
||||
|
||||
config PCI_ENUMERATION
|
||||
def_bool y
|
||||
|
||||
if ADC
|
||||
|
||||
config ADC_TI_ADC108S102
|
||||
def_bool y
|
||||
|
||||
if ADC_TI_ADC108S102
|
||||
|
||||
config ADC_TI_ADC108S102_SPI_PORT_NAME
|
||||
default "SPI_0"
|
||||
config ADC_TI_ADC108S102_SPI_CONFIGURATION
|
||||
default 0x81
|
||||
config ADC_TI_ADC108S102_SPI_MAX_FREQ
|
||||
default 0x20000000
|
||||
|
||||
endif # ADC_TI_AC108S102
|
||||
|
||||
endif # ADC
|
||||
|
||||
if GPIO && I2C
|
||||
|
||||
config GPIO_PCAL9535A
|
||||
|
@ -131,7 +110,4 @@ config SPI_INIT_PRIORITY
|
|||
config PINMUX_INIT_PRIORITY
|
||||
default 80 if PINMUX
|
||||
|
||||
config ADC_INIT_PRIORITY
|
||||
default 95
|
||||
|
||||
endif # BOARD_GALILEO
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
menuconfig ADC_TI_ADC108S102
|
||||
bool "TI adc108s102 chip driver"
|
||||
select SPI
|
||||
select SPI_LEGACY_API
|
||||
select ADC_0
|
||||
default n
|
||||
help
|
||||
|
@ -23,17 +22,11 @@ config ADC_TI_ADC108S102_SPI_PORT_NAME
|
|||
help
|
||||
Master SPI port name through which adc108s102 chip is accessed.
|
||||
|
||||
config ADC_TI_ADC108S102_SPI_CONFIGURATION
|
||||
hex "Master SPI port configuration"
|
||||
default 0x0
|
||||
config ADC_TI_ADC108S102_SPI_FREQ
|
||||
int "Master SPI port max frequency"
|
||||
default 0
|
||||
help
|
||||
Master SPI port configuration flags used to access adc108s102 chip.
|
||||
|
||||
config ADC_TI_ADC108S102_SPI_MAX_FREQ
|
||||
hex "Master SPI port max frequency"
|
||||
default 0x0
|
||||
help
|
||||
Master SPI port maximum frequency used to access adc108s102 chip.
|
||||
Master SPI port frequency used to access adc108s102 chip.
|
||||
|
||||
config ADC_TI_ADC108S102_SPI_SLAVE
|
||||
int "SPI slave slot"
|
||||
|
|
|
@ -20,14 +20,26 @@
|
|||
static inline int _ti_adc108s102_sampling(struct device *dev)
|
||||
{
|
||||
struct ti_adc108s102_data *adc = dev->driver_data;
|
||||
const struct spi_buf tx_buf = {
|
||||
.buf = adc->cmd_buffer,
|
||||
.len = ADC108S102_CMD_BUFFER_SIZE
|
||||
};
|
||||
const struct spi_buf_set tx = {
|
||||
.buffers = &tx_buf,
|
||||
.count = 1
|
||||
};
|
||||
const struct spi_buf rx_buf = {
|
||||
.buf = adc->sampling_buffer,
|
||||
.len = ADC108S102_SAMPLING_BUFFER_SIZE
|
||||
};
|
||||
const struct spi_buf_set rx = {
|
||||
.buffers = &rx_buf,
|
||||
.count = 1
|
||||
};
|
||||
|
||||
SYS_LOG_DBG("Sampling!");
|
||||
|
||||
/* SPI deals with u8_t buffers so multiplying by 2 the length */
|
||||
return spi_transceive(adc->spi, adc->cmd_buffer,
|
||||
adc->cmd_buf_len * 2,
|
||||
adc->sampling_buffer,
|
||||
adc->sampling_buf_len * 2);
|
||||
return spi_transceive(adc->spi, &adc->spi_cfg, &tx, &rx);
|
||||
}
|
||||
|
||||
static inline void _ti_adc108s102_handle_result(struct device *dev)
|
||||
|
@ -143,23 +155,10 @@ static inline int _verify_entries(struct adc_seq_table *seq_table)
|
|||
static int ti_adc108s102_read(struct device *dev,
|
||||
struct adc_seq_table *seq_table)
|
||||
{
|
||||
const struct ti_adc108s102_config *config = dev->config->config_info;
|
||||
struct ti_adc108s102_data *adc = dev->driver_data;
|
||||
struct spi_config spi_conf;
|
||||
int ret = 0;
|
||||
s32_t delay;
|
||||
|
||||
spi_conf.config = config->spi_config_flags;
|
||||
spi_conf.max_sys_freq = config->spi_freq;
|
||||
|
||||
if (spi_configure(adc->spi, &spi_conf)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (spi_slave_select(adc->spi, config->spi_slave)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* Resetting all internal channel data */
|
||||
memset(adc->chans, 0, ADC108S102_CHANNELS_SIZE);
|
||||
|
||||
|
@ -201,14 +200,19 @@ static const struct adc_driver_api ti_adc108s102_api = {
|
|||
|
||||
static int ti_adc108s102_init(struct device *dev)
|
||||
{
|
||||
const struct ti_adc108s102_config *config = dev->config->config_info;
|
||||
struct ti_adc108s102_data *adc = dev->driver_data;
|
||||
|
||||
adc->spi = device_get_binding((char *)config->spi_port);
|
||||
adc->spi = device_get_binding(
|
||||
CONFIG_ADC_TI_ADC108S102_SPI_PORT_NAME);
|
||||
if (!adc->spi) {
|
||||
return -EPERM;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
adc->spi_cfg.operation = SPI_WORD_SET(16);
|
||||
adc->spi_cfg.frequency = CONFIG_ADC_TI_ADC108S102_SPI_FREQ;
|
||||
adc->spi_cfg.slave = CONFIG_ADC_TI_ADC108S102_SPI_SLAVE;
|
||||
|
||||
|
||||
SYS_LOG_DBG("ADC108s102 initialized");
|
||||
|
||||
dev->driver_api = &ti_adc108s102_api;
|
||||
|
@ -220,16 +224,9 @@ static int ti_adc108s102_init(struct device *dev)
|
|||
|
||||
static struct ti_adc108s102_data adc108s102_data;
|
||||
|
||||
static const struct ti_adc108s102_config adc108s102_config = {
|
||||
.spi_port = CONFIG_ADC_TI_ADC108S102_SPI_PORT_NAME,
|
||||
.spi_config_flags = CONFIG_ADC_TI_ADC108S102_SPI_CONFIGURATION,
|
||||
.spi_freq = CONFIG_ADC_TI_ADC108S102_SPI_MAX_FREQ,
|
||||
.spi_slave = CONFIG_ADC_TI_ADC108S102_SPI_SLAVE,
|
||||
};
|
||||
|
||||
DEVICE_INIT(adc108s102, CONFIG_ADC_0_NAME,
|
||||
ti_adc108s102_init,
|
||||
&adc108s102_data, &adc108s102_config,
|
||||
&adc108s102_data, NULL,
|
||||
POST_KERNEL, CONFIG_ADC_INIT_PRIORITY);
|
||||
|
||||
#endif /* CONFIG_ADC_TI_ADC108S102 */
|
||||
|
|
|
@ -32,13 +32,6 @@ extern "C" {
|
|||
#define ADC108S102_RESULT(_res_) \
|
||||
(sys_be16_to_cpu(_res_) & ADC108S102_RESULT_MASK)
|
||||
|
||||
struct ti_adc108s102_config {
|
||||
const char *spi_port;
|
||||
u32_t spi_config_flags;
|
||||
u32_t spi_freq;
|
||||
u32_t spi_slave;
|
||||
};
|
||||
|
||||
struct ti_adc108s102_chan {
|
||||
u32_t buf_idx;
|
||||
};
|
||||
|
@ -47,6 +40,7 @@ struct ti_adc108s102_data {
|
|||
u16_t cmd_buffer[ADC108S102_CMD_BUFFER_SIZE];
|
||||
u16_t sampling_buffer[ADC108S102_SAMPLING_BUFFER_SIZE];
|
||||
struct device *spi;
|
||||
struct spi_config spi_cfg;
|
||||
struct ti_adc108s102_chan chans[ADC108S102_CHANNELS];
|
||||
struct adc_seq_table *seq_table;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue