Skip to content

Commit

Permalink
iio: adc: stm32-adc: add stm32mp13 support
Browse files Browse the repository at this point in the history
Add STM32 ADC support for STM32MP13x SOCs family.

On STM32MP13x, each ADC peripheral has a single ADC block.
These ADC peripherals, ADC1 and ADC2, are fully independent.
This introduces changes in common registers handling.

Some features such as boost mode, channel preselection and
linear calibration are not supported by the STM32MP13x ADC.
Add diversity management for these features.

The STM32MP13x ADC introduces registers and bitfield variants
on existing features such as calibration factors and internal
channels. Add register diversity management.

Add also support for new internal channels VDDCPU and VDDQ_DDR.

Signed-off-by: Olivier Moysan <[email protected]>
Reviewed-by: Fabrice Gasnier <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
Olivier Moysan authored and jic23 committed Nov 23, 2022
1 parent 6cafcdb commit cf0fb80
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 31 deletions.
30 changes: 26 additions & 4 deletions drivers/iio/adc/stm32-adc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/units.h>

#include "stm32-adc-core.h"

Expand Down Expand Up @@ -306,8 +307,8 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev,
static const struct stm32_adc_common_regs stm32f4_adc_common_regs = {
.csr = STM32F4_ADC_CSR,
.ccr = STM32F4_ADC_CCR,
.eoc_msk = { STM32F4_EOC1, STM32F4_EOC2, STM32F4_EOC3},
.ovr_msk = { STM32F4_OVR1, STM32F4_OVR2, STM32F4_OVR3},
.eoc_msk = { STM32F4_EOC1, STM32F4_EOC2, STM32F4_EOC3 },
.ovr_msk = { STM32F4_OVR1, STM32F4_OVR2, STM32F4_OVR3 },
.ier = STM32F4_ADC_CR1,
.eocie_msk = STM32F4_EOCIE,
};
Expand All @@ -316,8 +317,18 @@ static const struct stm32_adc_common_regs stm32f4_adc_common_regs = {
static const struct stm32_adc_common_regs stm32h7_adc_common_regs = {
.csr = STM32H7_ADC_CSR,
.ccr = STM32H7_ADC_CCR,
.eoc_msk = { STM32H7_EOC_MST, STM32H7_EOC_SLV},
.ovr_msk = { STM32H7_OVR_MST, STM32H7_OVR_SLV},
.eoc_msk = { STM32H7_EOC_MST, STM32H7_EOC_SLV },
.ovr_msk = { STM32H7_OVR_MST, STM32H7_OVR_SLV },
.ier = STM32H7_ADC_IER,
.eocie_msk = STM32H7_EOCIE,
};

/* STM32MP13 common registers definitions */
static const struct stm32_adc_common_regs stm32mp13_adc_common_regs = {
.csr = STM32H7_ADC_CSR,
.ccr = STM32H7_ADC_CCR,
.eoc_msk = { STM32H7_EOC_MST },
.ovr_msk = { STM32H7_OVR_MST },
.ier = STM32H7_ADC_IER,
.eocie_msk = STM32H7_EOCIE,
};
Expand Down Expand Up @@ -868,6 +879,14 @@ static const struct stm32_adc_priv_cfg stm32mp1_adc_priv_cfg = {
.num_irqs = 2,
};

static const struct stm32_adc_priv_cfg stm32mp13_adc_priv_cfg = {
.regs = &stm32mp13_adc_common_regs,
.clk_sel = stm32h7_adc_clk_sel,
.max_clk_rate_hz = 75 * HZ_PER_MHZ,
.ipid = STM32MP13_IPIDR_NUMBER,
.num_irqs = 1,
};

static const struct of_device_id stm32_adc_of_match[] = {
{
.compatible = "st,stm32f4-adc-core",
Expand All @@ -878,6 +897,9 @@ static const struct of_device_id stm32_adc_of_match[] = {
}, {
.compatible = "st,stm32mp1-adc-core",
.data = (void *)&stm32mp1_adc_priv_cfg
}, {
.compatible = "st,stm32mp13-adc-core",
.data = (void *)&stm32mp13_adc_priv_cfg
}, {
},
};
Expand Down
30 changes: 30 additions & 0 deletions drivers/iio/adc/stm32-adc-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@
#define STM32MP1_ADC_IPDR 0x3F8
#define STM32MP1_ADC_SIDR 0x3FC

/* STM32MP13 - Registers for each ADC instance */
#define STM32MP13_ADC_DIFSEL 0xB0
#define STM32MP13_ADC_CALFACT 0xB4
#define STM32MP13_ADC2_OR 0xC8

/* STM32H7 - common registers for all ADC instances */
#define STM32H7_ADC_CSR (STM32_ADCX_COMN_OFFSET + 0x00)
#define STM32H7_ADC_CCR (STM32_ADCX_COMN_OFFSET + 0x08)
Expand Down Expand Up @@ -161,6 +166,9 @@ enum stm32h7_adc_dmngt {
STM32H7_DMNGT_DMA_CIRC, /* DMA circular mode */
};

/* STM32H7_ADC_DIFSEL - bit fields */
#define STM32H7_DIFSEL_MASK GENMASK(19, 0)

/* STM32H7_ADC_CALFACT - bit fields */
#define STM32H7_CALFACT_D_SHIFT 16
#define STM32H7_CALFACT_D_MASK GENMASK(26, 16)
Expand Down Expand Up @@ -210,7 +218,29 @@ enum stm32h7_adc_dmngt {
/* STM32MP1_ADC_SIDR - bit fields */
#define STM32MP1_SIDR_MASK GENMASK(31, 0)

/* STM32MP13_ADC_CFGR specific bit fields */
#define STM32MP13_DMAEN BIT(0)
#define STM32MP13_DMACFG BIT(1)
#define STM32MP13_DFSDMCFG BIT(2)
#define STM32MP13_RES_SHIFT 3
#define STM32MP13_RES_MASK GENMASK(4, 3)

/* STM32MP13_ADC_DIFSEL - bit fields */
#define STM32MP13_DIFSEL_MASK GENMASK(18, 0)

/* STM32MP13_ADC_CALFACT - bit fields */
#define STM32MP13_CALFACT_D_SHIFT 16
#define STM32MP13_CALFACT_D_MASK GENMASK(22, 16)
#define STM32MP13_CALFACT_S_SHIFT 0
#define STM32MP13_CALFACT_S_MASK GENMASK(6, 0)

/* STM32MP13_ADC2_OR - bit fields */
#define STM32MP13_OP2 BIT(2)
#define STM32MP13_OP1 BIT(1)
#define STM32MP13_OP0 BIT(0)

#define STM32MP15_IPIDR_NUMBER 0x00110005
#define STM32MP13_IPIDR_NUMBER 0x00110006

/**
* struct stm32_adc_common - stm32 ADC driver common data (for all instances)
Expand Down
Loading

0 comments on commit cf0fb80

Please sign in to comment.