ite: drivers/adc: create pinmux phandle to the ADC driver node
Create the pinmux phandle to the ADC driver node in the devicetree. When the pinmux_pin_set function in adc_it8xxx2_channel_setup can refer to the setting of this phandle. It is more flexible to use. Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
This commit is contained in:
parent
65f798a00a
commit
8ea58d4389
11 changed files with 131 additions and 13 deletions
|
@ -15,12 +15,22 @@ LOG_MODULE_REGISTER(adc_ite_it8xxx2);
|
|||
#include <soc.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <dt-bindings/pinctrl/it8xxx2-pinctrl.h>
|
||||
|
||||
#define ADC_CONTEXT_USES_KERNEL_TIMER
|
||||
#include "adc_context.h"
|
||||
|
||||
#define DEV_DATA(dev) ((struct adc_it8xxx2_data * const)(dev)->data)
|
||||
|
||||
#define DEV_CFG(dev) ((struct adc_it8xxx2_cfg * const)(dev)->config)
|
||||
|
||||
#define DEV_PIN(adc_ch) DT_PHA(DT_PHANDLE_BY_IDX(DT_DRV_INST(0), \
|
||||
pinctrl_0, adc_ch), pinctrls, pin)
|
||||
#define DEV_ALT_FUNC(adc_ch) DT_PHA(DT_PHANDLE_BY_IDX(DT_DRV_INST(0), \
|
||||
pinctrl_0, adc_ch), pinctrls, alt_func)
|
||||
#define DEV_PINMUX(adc_ch) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_NODELABEL \
|
||||
(pinctrl_adc##adc_ch), pinctrls, 0))
|
||||
|
||||
/* ADC internal reference voltage (Unit:mV) */
|
||||
#define IT8XXX2_ADC_VREF_VOL 3000
|
||||
/* ADC channels disabled */
|
||||
|
@ -52,14 +62,26 @@ struct adc_it8xxx2_data {
|
|||
uint16_t *repeat_buffer;
|
||||
};
|
||||
|
||||
/*
|
||||
* Strcture adc_it8xxx2_cfg is about the setting of adc
|
||||
* this config will be used at initial time
|
||||
*/
|
||||
struct adc_it8xxx2_cfg {
|
||||
/* Pinmux control group */
|
||||
const struct device *pinctrls;
|
||||
/* GPIO pin */
|
||||
uint8_t pin;
|
||||
/* Alternate function */
|
||||
uint8_t alt_fun;
|
||||
};
|
||||
|
||||
#define ADC_IT8XXX2_REG_BASE \
|
||||
((struct adc_it8xxx2_regs *)(DT_INST_REG_ADDR(0)))
|
||||
|
||||
static int adc_it8xxx2_channel_setup(const struct device *dev,
|
||||
const struct adc_channel_cfg *channel_cfg)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
const struct device *porti = DEVICE_DT_GET(DT_NODELABEL(pinmuxi));
|
||||
struct adc_it8xxx2_cfg *config = DEV_CFG(dev);
|
||||
|
||||
if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) {
|
||||
LOG_ERR("Selected ADC acquisition time is not valid");
|
||||
|
@ -82,7 +104,9 @@ static int adc_it8xxx2_channel_setup(const struct device *dev,
|
|||
}
|
||||
|
||||
/* The channel is set to ADC alternate function */
|
||||
pinmux_pin_set(porti, channel_cfg->channel_id, IT8XXX2_PINMUX_FUNC_1);
|
||||
pinmux_pin_set(config[channel_cfg->channel_id].pinctrls,
|
||||
config[channel_cfg->channel_id].pin,
|
||||
config[channel_cfg->channel_id].alt_fun);
|
||||
LOG_DBG("Channel setup succeeded!");
|
||||
return 0;
|
||||
}
|
||||
|
@ -310,9 +334,19 @@ static struct adc_it8xxx2_data adc_it8xxx2_data_0 = {
|
|||
ADC_CONTEXT_INIT_LOCK(adc_it8xxx2_data_0, ctx),
|
||||
ADC_CONTEXT_INIT_SYNC(adc_it8xxx2_data_0, ctx),
|
||||
};
|
||||
#define ITE_DT_ITEMS_BY_CH(adc_ch, _) \
|
||||
{ \
|
||||
.pin = DEV_PIN(adc_ch), \
|
||||
.alt_fun = DEV_ALT_FUNC(adc_ch), \
|
||||
.pinctrls = DEV_PINMUX(adc_ch), \
|
||||
},
|
||||
|
||||
static const struct adc_it8xxx2_cfg adc_it8xxx2_cfg_0[CHIP_ADC_COUNT] = {
|
||||
UTIL_LISTIFY(DT_INST_PROP_LEN(0, pinctrl_0), ITE_DT_ITEMS_BY_CH, _)
|
||||
};
|
||||
DEVICE_DT_INST_DEFINE(0, adc_it8xxx2_init,
|
||||
NULL,
|
||||
&adc_it8xxx2_data_0,
|
||||
NULL, PRE_KERNEL_1,
|
||||
&adc_it8xxx2_cfg_0, PRE_KERNEL_1,
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
||||
&api_it8xxx2_driver_api);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue