-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Analog AD5592 MFD driver #64592
Add Analog AD5592 MFD driver #64592
Conversation
5a6884e
to
d29fc79
Compare
6dd963e
to
74f4b83
Compare
@gmarull @aasinclair gentle ping ;) |
drivers/mfd/mfd_ad5592.c
Outdated
.bus = SPI_DT_SPEC_INST_GET(inst, (SPI_WORD_SET(8) | SPI_TRANSFER_MSB | \ | ||
SPI_OP_MODE_MASTER | \ | ||
SPI_MODE_CPOL), 0), \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about using an external define for the spi flags? would clean up the indentation here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
drivers/gpio/Kconfig.ad5592
Outdated
help | ||
Enable the AD5592 GPIO driver. | ||
|
||
config GPIO_AD5592_INIT_PRIORITY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey how about using CONFIG_MFD_INIT_PRIORITY
for the subdevices as well? Then the sublevel will ensure that the parent is initialized first automatically. We haven't done that for other MFD devices, but I'm thinking we should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not totally convinced about this (yet) to be honest but worth having a thought about, breakages would certainly be caught by the build time validation, question is whether you'd have the flexibility of fixing them if it happens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's find out ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabiobaltieri it seems you were right. I'm gonna remove the extra *_INIT_PRIORITY
options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guess an more conservative alternative could have been to default them to MFD_INIT_PRIORITY
but if we can just get rid of them it's even better, maybe we can drop other MFD child symbols too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
drivers/mfd/Kconfig.ad5592
Outdated
bool "Analog AD5592 SPI configurable ADC/DAC/GPIO chip" | ||
default y | ||
depends on DT_HAS_ADI_AD5592_ENABLED | ||
depends on MFD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
default y | ||
depends on DT_HAS_ADI_AD5592_ENABLED | ||
depends on MFD | ||
depends on SPI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
select SPI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can not because of dependency loop. Please see:
..snipp... Dependency loop =============== SPI (defined at boards/shields/x_nucleo_idb05a1/Kconfig.defconfig:8, soc/arm/nxp_kinetis/k6x/Kconfig.defconfig.mk64f12:18, soc/arm/nxp_kinetis/kwx/Kconfig.defconfig.mkw2xd512:19, drivers/spi/Kconfig:9), with definition... config SPI bool default y depends on BT && SHIELD_X_NUCLEO_IDB05A1 config SPI bool default n depends on SOC_MK64F12 && SOC_SERIES_KINETIS_K6X config SPI bool default y depends on (SOC_MKW22D5 || SOC_MKW24D5) && SOC_SERIES_KINETIS_KWX menuconfig SPI bool "Serial Peripheral Interface (SPI) bus drivers" help Enable support for the SPI hardware bus. (select-related dependencies: (AD5592_MFD && DT_HAS_ADI_AD5592_ENABLED && MFD) || (ADC_LMP90XXX && (DT_HAS_TI_LMP90077_ENABLED || DT_HAS_TI_LMP90078_ENABLED || DT_HAS_TI_LMP90079_ENABLED || DT_HAS_TI_LMP90080_ENABLED || DT_HAS_TI_LMP90097_ENABLED || DT_HAS_TI_LMP90098_ENABLED || DT_HAS_TI_LMP90099_ENABLED || DT_HAS_TI_LMP90100_ENABLED) && ADC) || (ADC_MCP320X && (DT_HAS_MICROCHIP_MCP3204_ENABLED || DT_HAS_MICROCHIP_MCP3208_ENABLED) && ADC) || (ADC_ADS7052 && DT_HAS_TI_ADS7052_ENABLED && ADC) || (ADC_ADS114S0X && DT_HAS_TI_ADS114S08_ENABLED && ADC) || (CAN_MCP2515 && DT_HAS_MICROCHIP_MCP2515_ENABLED && CAN) || (DAC_DACX0508 && (DT_HAS_TI_DAC60508_ENABLED || DT_HAS_TI_DAC70508_ENABLED || DT_HAS_TI_DAC80508_ENABLED) && DAC) || (DAC_LTC166X && (DT_HAS_LLTC_LTC1660_ENABLED || DT_HAS_LLTC_LTC1665_ENABLED) && DAC) || (ILI9340 && DT_HAS_ILITEK_ILI9340_ENABLED && DISPLAY) || (ILI9341 && DT_HAS_ILITEK_ILI9341_ENABLED && DISPLAY) || (ILI9342C && DT_HAS_ILITEK_ILI9342C_ENABLED && DISPLAY) || (ILI9488 && DT_HAS_ILITEK_ILI9488_ENABLED && DISPLAY) || (SSD16XX && (DT_HAS_SOLOMON_SSD1608_ENABLED || DT_HAS_SOLOMON_SSD1673_ENABLED || DT_HAS_SOLOMON_SSD1675A_ENABLED || DT_HAS_SOLOMON_SSD1680_ENABLED || DT_HAS_SOLOMON_SSD1681_ENABLED) && DISPLAY) || (ST7735R && DT_HAS_SITRONIX_ST7735R_ENABLED && DISPLAY) || (ST7789V && DT_HAS_SITRONIX_ST7789V_ENABLED && DISPLAY) || (UC81XX && (DT_HAS_ULTRACHIP_UC8176_ENABLED || DT_HAS_ULTRACHIP_UC8179_ENABLED) && DISPLAY) || (LS0XX && DT_HAS_SHARP_LS0XX_ENABLED && DISPLAY) || (MAX7219 && DT_HAS_MAXIM_MAX7219_ENABLED && DISPLAY) || (EEPROM_AT25 && DT_HAS_ATMEL_AT25_ENABLED && EEPROM) || (ETH_ENC28J60 && DT_HAS_MICROCHIP_ENC28J60_ENABLED && ETH_DRIVER) || (ETH_ENC424J600 && DT_HAS_MICROCHIP_ENC424J600_ENABLED && ETH_DRIVER) || (ETH_W5500 && DT_HAS_WIZNET_W5500_ENABLED && ETH_DRIVER) || (ETH_ADIN2111 && DT_HAS_ADI_ADIN2111_ENABLED && ETH_DRIVER) || (SPI_FLASH_AT45 && DT_HAS_ATMEL_AT45_ENABLED && FLASH) || (SPI_NOR && DT_HAS_JEDEC_SPI_NOR_ENABLED && FLASH) || (IEEE802154_MCR20A && DT_HAS_NXP_MCR20A_ENABLED && IEEE802154) || (IEEE802154_RF2XX && DT_HAS_ATMEL_RF2XX_ENABLED && IEEE802154) || (IEEE802154_DW1000 && DT_HAS_DECAWAVE_DW1000_ENABLED && IEEE802154) || (KSCAN_XPT2046 && DT_HAS_XPTEK_XPT2046_ENABLED && KSCAN) || (FT800 && DT_HAS_FTDI_FT800_ENABLED) || (SPI_SDHC && DT_HAS_ZEPHYR_SDHC_SPI_SLOT_ENABLED && SDHC) || (ADT7310 && DT_HAS_ADI_ADT7310_ENABLED && SENSOR) || (ADXL362 && DT_HAS_ADI_ADXL362_ENABLED && SENSOR) || (I3G4250D && DT_HAS_ST_I3G4250D_ENABLED && SENSOR) || (ICM42605 && DT_HAS_INVENSENSE_ICM42605_ENABLED && SENSOR) || (ICM42670 && DT_HAS_INVENSENSE_ICM42670_ENABLED && SENSOR) || (ICM42688 && DT_HAS_INVENSENSE_ICM42688_ENABLED && SENSOR) || (IIS3DHHC && DT_HAS_ST_IIS3DHHC_ENABLED && SENSOR) || (MAX31855 && DT_HAS_MAXIM_MAX31855_ENABLED && SENSOR) || (MAX31865 && DT_HAS_MAXIM_MAX31865_ENABLED && SENSOR) || (MAX6675 && DT_HAS_MAXIM_MAX6675_ENABLED && SENSOR) || (UHC_MAX3421E && DT_HAS_MAXIM_MAX3421E_SPI_ENABLED && UHC_DRIVER) || (WIFI_WINC1500 && DT_HAS_ATMEL_WINC1500_ENABLED && WIFI) || (WIFI_ESWIFI_BUS_SPI && )) ...depends on MFD (defined at drivers/mfd/Kconfig:4), with definition... menuconfig MFD bool "Multi-function device (MFD) drivers" help Include drivers for multi-function devices (select-related dependencies: (GPIO_NPM6001 && DT_HAS_NORDIC_NPM6001_GPIO_ENABLED && GPIO) || (REGULATOR_NPM6001 && DT_HAS_NORDIC_NPM6001_REGULATOR_ENABLED && REGULATOR) || (WDT_NPM6001 && DT_HAS_NORDIC_NPM6001_WDT_ENABLED && WATCHDOG)) ...depends on GPIO_NPM6001 (defined at drivers/gpio/Kconfig.npm6001:4), with definition... config GPIO_NPM6001 bool "nPM6001 GPIO driver" default y select I2C select MFD depends on DT_HAS_NORDIC_NPM6001_GPIO_ENABLED && GPIO help Enable the nPM6001 GPIO driver. ...depends on GPIO (defined at soc/arm/microchip_mec/mec1501/Kconfig.defconfig.mec1501hsz:11, soc/arm/microchip_mec/mec172x/Kconfig.defconfig.mec172xnlj:11, soc/arm/microchip_mec/mec172x/Kconfig.defconfig.mec172xnsz:11, soc/arm/nordic_nrf/Kconfig.defconfig:42, soc/arm/nxp_imx/mcimx7_m4/Kconfig.defconfig.mcimx7_m4:14, soc/arm/nxp_imx/mimx8ml8_m7/Kconfig.defconfig.mimx8ml8_m7:16, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1010:18, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1015:17, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1021:17, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1024:17, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1042:12, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1052:14, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1062:14, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1064:14, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1166_cm4:14, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1166_cm7:14, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1176_cm4:14, soc/arm/nxp_imx/rt/Kconfig.defconfig.mimxrt1176_cm7:14, soc/arm/nxp_kinetis/k2x/Kconfig.defconfig.mk22f12:11, soc/arm/nxp_kinetis/k6x/Kconfig.defconfig.mk64f12:15, soc/arm/nxp_kinetis/k6x/Kconfig.defconfig.mk66f18:15, soc/arm/nxp_kinetis/k8x/Kconfig.defconfig.series:22, soc/arm/nxp_kinetis/ke1xf/Kconfig.defconfig.series:36, soc/arm/nxp_kinetis/kv5x/Kconfig.defconfig.series:15, soc/arm/nxp_lpc/lpc54xxx/Kconfig.defconfig.lpc54114_m0:11, soc/arm/nxp_lpc/lpc55xxx/Kconfig.defconfig.lpc55S69_cpu1:11, drivers/gpio/Kconfig:6), with definition... config GPIO bool default y depends on SOC_MEC1501_HSZ && SOC_SERIES_MEC1501X config GPIO bool default y depends on SOC_MEC172X_NLJ && SOC_SERIES_MEC172X config GPIO bool default y depends on SOC_MEC172X_NSZ && SOC_SERIES_MEC172X config GPIO bool default y depends on SPI && SOC_FAMILY_NRF config GPIO bool default y depends on SOC_MCIMX7_M4 && SOC_SERIES_IMX7_M4 config GPIO bool default y depends on SOC_MIMX8ML8 && SOC_SERIES_IMX8ML_M7 config GPIO bool default y depends on SOC_MIMXRT1011 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MIMXRT1015 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MIMXRT1021 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MIMXRT1024 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MIMXRT1042 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MIMXRT1052 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MIMXRT1062 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MIMXRT1064 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MIMXRT1166_CM4 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MIMXRT1166_CM7 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MIMXRT1176_CM4 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MIMXRT1176_CM7 && SOC_SERIES_IMX_RT config GPIO bool default y depends on SOC_MK22F51212 && SOC_SERIES_KINETIS_K2X config GPIO bool default y depends on SOC_MK64F12 && SOC_SERIES_KINETIS_K6X config GPIO bool default y depends on SOC_MK66F18 && SOC_SERIES_KINETIS_K6X config GPIO bool default y depends on SOC_SERIES_KINETIS_K8X config GPIO bool default y depends on SOC_SERIES_KINETIS_KE1XF config GPIO bool default y depends on SOC_SERIES_KINETIS_KV5X config GPIO bool default n depends on SOC_LPC54114_M0 && SOC_SERIES_LPC54XXX config GPIO bool default y depends on SOC_LPC55S69_CPU1 && SOC_SERIES_LPC55XXX menuconfig GPIO bool "General-Purpose Input/Output (GPIO) drivers" help Include GPIO drivers in system config (select-related dependencies: (MAX32664 && DT_HAS_ADI_MAX32664_ENABLED) || (AUXDISPLAY_ITRON && DT_HAS_NORITAKE_ITRON_ENABLED && AUXDISPLAY) || (IEEE802154_RF2XX && DT_HAS_ATMEL_RF2XX_ENABLED && IEEE802154) || (SPI_SAM && DT_HAS_ATMEL_SAM_SPI_ENABLED && SPI) || (SPI_XMC4XXX && DT_HAS_INFINEON_XMC4XXX_SPI_ENABLED && SPI) || (WIFI_ESWIFI && (DT_HAS_INVENTEK_ESWIFI_ENABLED || DT_HAS_INVENTEK_ESWIFI_UART_ENABLED) && WIFI)) (imply-related dependencies: (MAX32664 && DT_HAS_ADI_MAX32664_ENABLED) || (AUXDISPLAY_ITRON && DT_HAS_NORITAKE_ITRON_ENABLED && AUXDISPLAY) || (IEEE802154_RF2XX && DT_HAS_ATMEL_RF2XX_ENABLED && IEEE802154) || (SPI_SAM && DT_HAS_ATMEL_SAM_SPI_ENABLED && SPI) || (SPI_XMC4XXX && DT_HAS_INFINEON_XMC4XXX_SPI_ENABLED && SPI) || (WIFI_ESWIFI && (DT_HAS_INVENTEK_ESWIFI_ENABLED || DT_HAS_INVENTEK_ESWIFI_UART_ENABLED) && WIFI)) ...depends on SPI_XMC4XXX (defined at drivers/spi/Kconfig.xmc4xxx:4), with definition... menuconfig SPI_XMC4XXX bool "XMC4XX SPI driver" default y select GPIO depends on DT_HAS_INFINEON_XMC4XXX_SPI_ENABLED && SPI help Enable XMC4XXX SPI driver. ...depends again on SPI (defined at boards/shields/x_nucleo_idb05a1/Kconfig.defconfig:8, soc/arm/nxp_kinetis/k6x/Kconfig.defconfig.mk64f12:18, soc/arm/nxp_kinetis/kwx/Kconfig.defconfig.mkw2xd512:19, drivers/spi/Kconfig:9) ...snip...
include/zephyr/drivers/mfd/ad5592.h
Outdated
/** | ||
* @brief AD5592 MFD driver APIs | ||
* @defgroup mfd_ad5592_apis ad5592 | ||
* @{ | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks like a top-level group, you should add it to mfd (or create it if not present, see doc/_doxygen/groups.dox)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean something like that?
/** * @defgroup mdf_interface_ad5592 MFD AD5592 interface * @ingroup mfd_interfaces * @{ */
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
drivers/gpio/gpio_ad5592.c
Outdated
ret = mfd_ad5592_write_reg(config->mfd_dev, | ||
AD5592_REG_GPIO_OUTPUT_EN, data->gpio_out); | ||
if (ret < 0) { | ||
return ret; | ||
} | ||
|
||
ret = mfd_ad5592_write_reg(config->mfd_dev, | ||
AD5592_REG_GPIO_INPUT_EN, data->gpio_in); | ||
if (ret < 0) { | ||
return ret; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is repeated in the else, please move it outside the if/else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
d09aae8
to
6049357
Compare
This commit introduces a driver for Analog AD5592 8-channel, configurable ADC/DAC/GPIO chip. Signed-off-by: Bartosz Bilas <[email protected]>
33a4e8d
to
e6ce260
Compare
drivers/adc/adc_ad5592.c
Outdated
const struct adc_ad5592_config *config = dev->config; | ||
struct adc_ad5592_data *data = dev->data; | ||
|
||
if (k_is_in_isr()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmarull I guess this all needs to be removed from the drivers, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this all depends on the driver class, for example, for some GPIO ops this is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okey, removed from ADC and DAC only.
Add MFD subdriver for the built-in ADC controller in AD5592 chip. Signed-off-by: Bartosz Bilas <[email protected]>
Add MFD subdriver for the built-in GPIO controller in AD5592 chip. Signed-off-by: Bartosz Bilas <[email protected]>
Add MFD subdriver for the built-in DAC controller in AD5592 chip. Signed-off-by: Bartosz Bilas <[email protected]>
e6ce260
to
7f5fe62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DAC looks good.
if (channel >= 1) { | ||
val -= channel * AD5592_ADC_MAX_VAL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: If this is masking out the ADC channel information from the result field, it might be clearer to just select the lower 12 bits here.
e.g:
if (channel >= 1) { | |
val -= channel * AD5592_ADC_MAX_VAL; | |
} | |
val &= BITMASK(AD5592_ADC_RESOLUTION); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've followed the same way that has been done for GPIO/DAC and to be honest, I didn't check the native_posix.overlay
file. I'm gonna fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinjaeger #64975 please take a look.
Those commits introduce separate drivers for Analog AD5592 8-channel, configurable ADC/DAC/GPIO chip.
Depends on #64673 and #64672.