drivers: tlv320dac: use reset GPIO from DTS

Driver update to use GPIO driver for the reset control signal.
Driver update to use definitions from DTS including I2C address.

Signed-off-by: Sathish Kuttan <sathish.k.kuttan@intel.com>
This commit is contained in:
Sathish Kuttan 2019-01-07 09:15:08 -08:00 committed by Kumar Gala
commit b3bb689cab
2 changed files with 35 additions and 9 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 Intel Corporation
* Copyright (c) 2019 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -10,6 +10,7 @@
#include <device.h>
#include <i2c.h>
#include <gpio.h>
#include <audio/codec.h>
#include "tlv320dac310x.h"
@ -21,10 +22,17 @@ LOG_MODULE_REGISTER(tlv320dac310x);
#define CODEC_OUTPUT_VOLUME_MAX 0
#define CODEC_OUTPUT_VOLUME_MIN (-78 * 2)
#define CODEC_RESET_PIN_ASSERT 0
#define CODEC_RESET_PIN_DEASSERT 1
struct codec_driver_config {
struct device *i2c_device;
const char *i2c_dev_name;
u8_t i2c_address;
struct device *gpio_device;
const char *gpio_dev_name;
u32_t gpio_pin;
int gpio_flags;
};
struct codec_driver_data {
@ -35,6 +43,10 @@ static struct codec_driver_config codec_device_config = {
.i2c_device = NULL,
.i2c_dev_name = DT_CODEC_I2C_BUS_NAME,
.i2c_address = DT_CODEC_I2C_BUS_ADDR,
.gpio_device = NULL,
.gpio_dev_name = DT_CODEC_RESET_GPIO_NAME,
.gpio_pin = DT_CODEC_RESET_GPIO_PIN,
.gpio_flags = DT_CODEC_RESET_GPIO_FLAGS,
};
static struct codec_driver_data codec_device_data;
@ -73,12 +85,22 @@ static int codec_initialize(struct device *dev)
LOG_ERR("I2C device binding error");
return -ENXIO;
}
/* bind GPIO */
dev_cfg->gpio_device = device_get_binding(dev_cfg->gpio_dev_name);
if (dev_cfg->gpio_device == NULL) {
LOG_ERR("GPIO device binding error");
return -ENXIO;
}
return 0;
}
static int codec_configure(struct device *dev,
struct audio_codec_cfg *cfg)
{
struct codec_driver_config *const dev_cfg = DEV_CFG(dev);
int ret;
if (cfg->dai_type != AUDIO_DAI_TYPE_I2S) {
@ -86,6 +108,13 @@ static int codec_configure(struct device *dev,
return -EINVAL;
}
/* configure reset GPIO */
gpio_pin_configure(dev_cfg->gpio_device, dev_cfg->gpio_pin,
dev_cfg->gpio_flags);
/* de-assert reset */
gpio_pin_write(dev_cfg->gpio_device, dev_cfg->gpio_pin,
CODEC_RESET_PIN_DEASSERT);
codec_soft_reset(dev);
ret = codec_configure_clocks(dev, cfg);
@ -176,12 +205,12 @@ static void codec_write_reg(struct device *dev, struct reg_addr reg, u8_t val)
/* set page if different */
if (dev_data->reg_addr_cache.page != reg.page) {
i2c_reg_write_byte(dev_cfg->i2c_device,
DAC_I2C_DEV_ADDR, 0, reg.page);
dev_cfg->i2c_address, 0, reg.page);
dev_data->reg_addr_cache.page = reg.page;
}
i2c_reg_write_byte(dev_cfg->i2c_device,
DAC_I2C_DEV_ADDR, reg.reg_addr, val);
dev_cfg->i2c_address, reg.reg_addr, val);
LOG_DBG("WR PG:%u REG:%02u VAL:0x%02x",
reg.page, reg.reg_addr, val);
}
@ -194,12 +223,12 @@ static void codec_read_reg(struct device *dev, struct reg_addr reg, u8_t *val)
/* set page if different */
if (dev_data->reg_addr_cache.page != reg.page) {
i2c_reg_write_byte(dev_cfg->i2c_device,
DAC_I2C_DEV_ADDR, 0, reg.page);
dev_cfg->i2c_address, 0, reg.page);
dev_data->reg_addr_cache.page = reg.page;
}
i2c_reg_read_byte(dev_cfg->i2c_device,
DAC_I2C_DEV_ADDR, reg.reg_addr, val);
dev_cfg->i2c_address, reg.reg_addr, val);
LOG_DBG("RD PG:%u REG:%02u VAL:0x%02x",
reg.page, reg.reg_addr, *val);
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 Intel Corporation.
* Copyright (c) 2019 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -11,9 +11,6 @@
extern "C" {
#endif
/* I2C device address of TLV320DAC3101 */
#define DAC_I2C_DEV_ADDR (0x30 >> 1)
/* Register addresses */
#define PAGE_CONTROL_ADDR 0