1 // SPDX-License-Identifier: GPL-2.0
3 * This file is part of STM32 ADC driver
5 * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
6 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>.
8 * Inspired from: fsl-imx25-tsadc
12 #include <linux/clk.h>
13 #include <linux/interrupt.h>
14 #include <linux/irqchip/chained_irq.h>
15 #include <linux/irqdesc.h>
16 #include <linux/irqdomain.h>
17 #include <linux/mfd/syscon.h>
18 #include <linux/module.h>
19 #include <linux/of_device.h>
20 #include <linux/pm_runtime.h>
21 #include <linux/regmap.h>
22 #include <linux/regulator/consumer.h>
23 #include <linux/slab.h>
25 #include "stm32-adc-core.h"
27 #define STM32_ADC_CORE_SLEEP_DELAY_MS 2000
29 /* SYSCFG registers */
30 #define STM32MP1_SYSCFG_PMCSETR 0x04
31 #define STM32MP1_SYSCFG_PMCCLRR 0x44
33 /* SYSCFG bit fields */
34 #define STM32MP1_SYSCFG_ANASWVDD_MASK BIT(9)
36 /* SYSCFG capability flags */
37 #define HAS_VBOOSTER BIT(0)
38 #define HAS_ANASWVDD BIT(1)
41 * struct stm32_adc_common_regs - stm32 common registers
42 * @csr: common status register offset
43 * @ccr: common control register offset
44 * @eoc_msk: array of eoc (end of conversion flag) masks in csr for adc1..n
45 * @ovr_msk: array of ovr (overrun flag) masks in csr for adc1..n
46 * @ier: interrupt enable register offset for each adc
47 * @eocie_msk: end of conversion interrupt enable mask in @ier
49 struct stm32_adc_common_regs {
52 u32 eoc_msk[STM32_ADC_MAX_ADCS];
53 u32 ovr_msk[STM32_ADC_MAX_ADCS];
58 struct stm32_adc_priv;
61 * struct stm32_adc_priv_cfg - stm32 core compatible configuration data
62 * @regs: common registers for all instances
63 * @clk_sel: clock selection routine
64 * @max_clk_rate_hz: maximum analog clock rate (Hz, from datasheet)
65 * @has_syscfg: SYSCFG capability flags
66 * @num_irqs: number of interrupt lines
67 * @num_adcs: maximum number of ADC instances in the common registers
69 struct stm32_adc_priv_cfg {
70 const struct stm32_adc_common_regs *regs;
71 int (*clk_sel)(struct platform_device *, struct stm32_adc_priv *);
73 unsigned int has_syscfg;
74 unsigned int num_irqs;
75 unsigned int num_adcs;
79 * struct stm32_adc_priv - stm32 ADC core private data
80 * @irq: irq(s) for ADC block
81 * @domain: irq domain reference
82 * @aclk: clock reference for the analog circuitry
83 * @bclk: bus clock common for all ADCs, depends on part used
84 * @max_clk_rate: desired maximum clock rate
85 * @booster: booster supply reference
86 * @vdd: vdd supply reference
87 * @vdda: vdda analog supply reference
88 * @vref: regulator reference
89 * @vdd_uv: vdd supply voltage (microvolts)
90 * @vdda_uv: vdda supply voltage (microvolts)
91 * @cfg: compatible configuration data
92 * @common: common data for all ADC instances
93 * @ccr_bak: backup CCR in low power mode
94 * @syscfg: reference to syscon, system control registers
96 struct stm32_adc_priv {
97 int irq[STM32_ADC_MAX_ADCS];
98 struct irq_domain *domain;
102 struct regulator *booster;
103 struct regulator *vdd;
104 struct regulator *vdda;
105 struct regulator *vref;
108 const struct stm32_adc_priv_cfg *cfg;
109 struct stm32_adc_common common;
111 struct regmap *syscfg;
114 static struct stm32_adc_priv *to_stm32_adc_priv(struct stm32_adc_common *com)
116 return container_of(com, struct stm32_adc_priv, common);
119 /* STM32F4 ADC internal common clock prescaler division ratios */
120 static int stm32f4_pclk_div[] = {2, 4, 6, 8};
123 * stm32f4_adc_clk_sel() - Select stm32f4 ADC common clock prescaler
124 * @pdev: platform device
125 * @priv: stm32 ADC core private data
126 * Select clock prescaler used for analog conversions, before using ADC.
128 static int stm32f4_adc_clk_sel(struct platform_device *pdev,
129 struct stm32_adc_priv *priv)
135 /* stm32f4 has one clk input for analog (mandatory), enforce it here */
137 dev_err(&pdev->dev, "No 'adc' clock found\n");
141 rate = clk_get_rate(priv->aclk);
143 dev_err(&pdev->dev, "Invalid clock rate: 0\n");
147 for (i = 0; i < ARRAY_SIZE(stm32f4_pclk_div); i++) {
148 if ((rate / stm32f4_pclk_div[i]) <= priv->max_clk_rate)
151 if (i >= ARRAY_SIZE(stm32f4_pclk_div)) {
152 dev_err(&pdev->dev, "adc clk selection failed\n");
156 priv->common.rate = rate / stm32f4_pclk_div[i];
157 val = readl_relaxed(priv->common.base + STM32F4_ADC_CCR);
158 val &= ~STM32F4_ADC_ADCPRE_MASK;
159 val |= i << STM32F4_ADC_ADCPRE_SHIFT;
160 writel_relaxed(val, priv->common.base + STM32F4_ADC_CCR);
162 dev_dbg(&pdev->dev, "Using analog clock source at %ld kHz\n",
163 priv->common.rate / 1000);
169 * struct stm32h7_adc_ck_spec - specification for stm32h7 adc clock
170 * @ckmode: ADC clock mode, Async or sync with prescaler.
171 * @presc: prescaler bitfield for async clock mode
172 * @div: prescaler division ratio
174 struct stm32h7_adc_ck_spec {
180 static const struct stm32h7_adc_ck_spec stm32h7_adc_ckmodes_spec[] = {
181 /* 00: CK_ADC[1..3]: Asynchronous clock modes */
194 /* HCLK used: Synchronous clock modes (1, 2 or 4 prescaler) */
200 static int stm32h7_adc_clk_sel(struct platform_device *pdev,
201 struct stm32_adc_priv *priv)
203 u32 ckmode, presc, val;
207 /* stm32h7 bus clock is common for all ADC instances (mandatory) */
209 dev_err(&pdev->dev, "No 'bus' clock found\n");
214 * stm32h7 can use either 'bus' or 'adc' clock for analog circuitry.
215 * So, choice is to have bus clock mandatory and adc clock optional.
216 * If optional 'adc' clock has been found, then try to use it first.
220 * Asynchronous clock modes (e.g. ckmode == 0)
221 * From spec: PLL output musn't exceed max rate
223 rate = clk_get_rate(priv->aclk);
225 dev_err(&pdev->dev, "Invalid adc clock rate: 0\n");
229 /* If duty is an error, kindly use at least /2 divider */
230 duty = clk_get_scaled_duty_cycle(priv->aclk, 100);
232 dev_warn(&pdev->dev, "adc clock duty: %d\n", duty);
234 for (i = 0; i < ARRAY_SIZE(stm32h7_adc_ckmodes_spec); i++) {
235 ckmode = stm32h7_adc_ckmodes_spec[i].ckmode;
236 presc = stm32h7_adc_ckmodes_spec[i].presc;
237 div = stm32h7_adc_ckmodes_spec[i].div;
243 * For proper operation, clock duty cycle range is 49%
244 * to 51%. Apply at least /2 prescaler otherwise.
246 if (div == 1 && (duty < 49 || duty > 51))
249 if ((rate / div) <= priv->max_clk_rate)
254 /* Synchronous clock modes (e.g. ckmode is 1, 2 or 3) */
255 rate = clk_get_rate(priv->bclk);
257 dev_err(&pdev->dev, "Invalid bus clock rate: 0\n");
261 duty = clk_get_scaled_duty_cycle(priv->bclk, 100);
263 dev_warn(&pdev->dev, "bus clock duty: %d\n", duty);
265 for (i = 0; i < ARRAY_SIZE(stm32h7_adc_ckmodes_spec); i++) {
266 ckmode = stm32h7_adc_ckmodes_spec[i].ckmode;
267 presc = stm32h7_adc_ckmodes_spec[i].presc;
268 div = stm32h7_adc_ckmodes_spec[i].div;
273 if (div == 1 && (duty < 49 || duty > 51))
276 if ((rate / div) <= priv->max_clk_rate)
280 dev_err(&pdev->dev, "adc clk selection failed\n");
284 /* rate used later by each ADC instance to control BOOST mode */
285 priv->common.rate = rate / div;
287 /* Set common clock mode and prescaler */
288 val = readl_relaxed(priv->common.base + STM32H7_ADC_CCR);
289 val &= ~(STM32H7_CKMODE_MASK | STM32H7_PRESC_MASK);
290 val |= ckmode << STM32H7_CKMODE_SHIFT;
291 val |= presc << STM32H7_PRESC_SHIFT;
292 writel_relaxed(val, priv->common.base + STM32H7_ADC_CCR);
294 dev_dbg(&pdev->dev, "Using %s clock/%d source at %ld kHz\n",
295 ckmode ? "bus" : "adc", div, priv->common.rate / 1000);
300 /* STM32F4 common registers definitions */
301 static const struct stm32_adc_common_regs stm32f4_adc_common_regs = {
302 .csr = STM32F4_ADC_CSR,
303 .ccr = STM32F4_ADC_CCR,
304 .eoc_msk = { STM32F4_EOC1, STM32F4_EOC2, STM32F4_EOC3},
305 .ovr_msk = { STM32F4_OVR1, STM32F4_OVR2, STM32F4_OVR3},
306 .ier = STM32F4_ADC_CR1,
307 .eocie_msk = STM32F4_EOCIE,
310 /* STM32H7 common registers definitions */
311 static const struct stm32_adc_common_regs stm32h7_adc_common_regs = {
312 .csr = STM32H7_ADC_CSR,
313 .ccr = STM32H7_ADC_CCR,
314 .eoc_msk = { STM32H7_EOC_MST, STM32H7_EOC_SLV},
315 .ovr_msk = { STM32H7_OVR_MST, STM32H7_OVR_SLV},
316 .ier = STM32H7_ADC_IER,
317 .eocie_msk = STM32H7_EOCIE,
320 static const unsigned int stm32_adc_offset[STM32_ADC_MAX_ADCS] = {
321 0, STM32_ADC_OFFSET, STM32_ADC_OFFSET * 2,
324 static unsigned int stm32_adc_eoc_enabled(struct stm32_adc_priv *priv,
327 u32 ier, offset = stm32_adc_offset[adc];
329 ier = readl_relaxed(priv->common.base + offset + priv->cfg->regs->ier);
331 return ier & priv->cfg->regs->eocie_msk;
334 /* ADC common interrupt for all instances */
335 static void stm32_adc_irq_handler(struct irq_desc *desc)
337 struct stm32_adc_priv *priv = irq_desc_get_handler_data(desc);
338 struct irq_chip *chip = irq_desc_get_chip(desc);
342 chained_irq_enter(chip, desc);
343 status = readl_relaxed(priv->common.base + priv->cfg->regs->csr);
346 * End of conversion may be handled by using IRQ or DMA. There may be a
347 * race here when two conversions complete at the same time on several
348 * ADCs. EOC may be read 'set' for several ADCs, with:
349 * - an ADC configured to use DMA (EOC triggers the DMA request, and
350 * is then automatically cleared by DR read in hardware)
351 * - an ADC configured to use IRQs (EOCIE bit is set. The handler must
352 * be called in this case)
353 * So both EOC status bit in CSR and EOCIE control bit must be checked
354 * before invoking the interrupt handler (e.g. call ISR only for
357 for (i = 0; i < priv->cfg->num_adcs; i++) {
358 if ((status & priv->cfg->regs->eoc_msk[i] &&
359 stm32_adc_eoc_enabled(priv, i)) ||
360 (status & priv->cfg->regs->ovr_msk[i]))
361 generic_handle_domain_irq(priv->domain, i);
364 chained_irq_exit(chip, desc);
367 static int stm32_adc_domain_map(struct irq_domain *d, unsigned int irq,
368 irq_hw_number_t hwirq)
370 irq_set_chip_data(irq, d->host_data);
371 irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_level_irq);
376 static void stm32_adc_domain_unmap(struct irq_domain *d, unsigned int irq)
378 irq_set_chip_and_handler(irq, NULL, NULL);
379 irq_set_chip_data(irq, NULL);
382 static const struct irq_domain_ops stm32_adc_domain_ops = {
383 .map = stm32_adc_domain_map,
384 .unmap = stm32_adc_domain_unmap,
385 .xlate = irq_domain_xlate_onecell,
388 static int stm32_adc_irq_probe(struct platform_device *pdev,
389 struct stm32_adc_priv *priv)
391 struct device_node *np = pdev->dev.of_node;
395 * Interrupt(s) must be provided, depending on the compatible:
396 * - stm32f4/h7 shares a common interrupt line.
397 * - stm32mp1, has one line per ADC
399 for (i = 0; i < priv->cfg->num_irqs; i++) {
400 priv->irq[i] = platform_get_irq(pdev, i);
401 if (priv->irq[i] < 0)
405 priv->domain = irq_domain_add_simple(np, STM32_ADC_MAX_ADCS, 0,
406 &stm32_adc_domain_ops,
409 dev_err(&pdev->dev, "Failed to add irq domain\n");
413 for (i = 0; i < priv->cfg->num_irqs; i++) {
414 irq_set_chained_handler(priv->irq[i], stm32_adc_irq_handler);
415 irq_set_handler_data(priv->irq[i], priv);
421 static void stm32_adc_irq_remove(struct platform_device *pdev,
422 struct stm32_adc_priv *priv)
427 for (hwirq = 0; hwirq < STM32_ADC_MAX_ADCS; hwirq++)
428 irq_dispose_mapping(irq_find_mapping(priv->domain, hwirq));
429 irq_domain_remove(priv->domain);
431 for (i = 0; i < priv->cfg->num_irqs; i++)
432 irq_set_chained_handler(priv->irq[i], NULL);
435 static int stm32_adc_core_switches_supply_en(struct stm32_adc_priv *priv,
441 * On STM32H7 and STM32MP1, the ADC inputs are multiplexed with analog
442 * switches (via PCSEL) which have reduced performances when their
443 * supply is below 2.7V (vdda by default):
444 * - Voltage booster can be used, to get full ADC performances
445 * (increases power consumption).
446 * - Vdd can be used to supply them, if above 2.7V (STM32MP1 only).
448 * Recommended settings for ANASWVDD and EN_BOOSTER:
449 * - vdda < 2.7V but vdd > 2.7V: ANASWVDD = 1, EN_BOOSTER = 0 (stm32mp1)
450 * - vdda < 2.7V and vdd < 2.7V: ANASWVDD = 0, EN_BOOSTER = 1
451 * - vdda >= 2.7V: ANASWVDD = 0, EN_BOOSTER = 0 (default)
453 if (priv->vdda_uv < 2700000) {
454 if (priv->syscfg && priv->vdd_uv > 2700000) {
455 ret = regulator_enable(priv->vdd);
457 dev_err(dev, "vdd enable failed %d\n", ret);
461 ret = regmap_write(priv->syscfg,
462 STM32MP1_SYSCFG_PMCSETR,
463 STM32MP1_SYSCFG_ANASWVDD_MASK);
465 regulator_disable(priv->vdd);
466 dev_err(dev, "vdd select failed, %d\n", ret);
469 dev_dbg(dev, "analog switches supplied by vdd\n");
476 * This is optional, as this is a trade-off between
477 * analog performance and power consumption.
479 ret = regulator_enable(priv->booster);
481 dev_err(dev, "booster enable failed %d\n", ret);
484 dev_dbg(dev, "analog switches supplied by booster\n");
490 /* Fallback using vdda (default), nothing to do */
491 dev_dbg(dev, "analog switches supplied by vdda (%d uV)\n",
497 static void stm32_adc_core_switches_supply_dis(struct stm32_adc_priv *priv)
499 if (priv->vdda_uv < 2700000) {
500 if (priv->syscfg && priv->vdd_uv > 2700000) {
501 regmap_write(priv->syscfg, STM32MP1_SYSCFG_PMCCLRR,
502 STM32MP1_SYSCFG_ANASWVDD_MASK);
503 regulator_disable(priv->vdd);
507 regulator_disable(priv->booster);
511 static int stm32_adc_core_hw_start(struct device *dev)
513 struct stm32_adc_common *common = dev_get_drvdata(dev);
514 struct stm32_adc_priv *priv = to_stm32_adc_priv(common);
517 ret = regulator_enable(priv->vdda);
519 dev_err(dev, "vdda enable failed %d\n", ret);
523 ret = regulator_get_voltage(priv->vdda);
525 dev_err(dev, "vdda get voltage failed, %d\n", ret);
526 goto err_vdda_disable;
530 ret = stm32_adc_core_switches_supply_en(priv, dev);
532 goto err_vdda_disable;
534 ret = regulator_enable(priv->vref);
536 dev_err(dev, "vref enable failed\n");
537 goto err_switches_dis;
540 ret = clk_prepare_enable(priv->bclk);
542 dev_err(dev, "bus clk enable failed\n");
543 goto err_regulator_disable;
546 ret = clk_prepare_enable(priv->aclk);
548 dev_err(dev, "adc clk enable failed\n");
549 goto err_bclk_disable;
552 writel_relaxed(priv->ccr_bak, priv->common.base + priv->cfg->regs->ccr);
557 clk_disable_unprepare(priv->bclk);
558 err_regulator_disable:
559 regulator_disable(priv->vref);
561 stm32_adc_core_switches_supply_dis(priv);
563 regulator_disable(priv->vdda);
568 static void stm32_adc_core_hw_stop(struct device *dev)
570 struct stm32_adc_common *common = dev_get_drvdata(dev);
571 struct stm32_adc_priv *priv = to_stm32_adc_priv(common);
573 /* Backup CCR that may be lost (depends on power state to achieve) */
574 priv->ccr_bak = readl_relaxed(priv->common.base + priv->cfg->regs->ccr);
575 clk_disable_unprepare(priv->aclk);
576 clk_disable_unprepare(priv->bclk);
577 regulator_disable(priv->vref);
578 stm32_adc_core_switches_supply_dis(priv);
579 regulator_disable(priv->vdda);
582 static int stm32_adc_core_switches_probe(struct device *dev,
583 struct stm32_adc_priv *priv)
585 struct device_node *np = dev->of_node;
588 /* Analog switches supply can be controlled by syscfg (optional) */
589 priv->syscfg = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
590 if (IS_ERR(priv->syscfg)) {
591 ret = PTR_ERR(priv->syscfg);
593 return dev_err_probe(dev, ret, "Can't probe syscfg\n");
598 /* Booster can be used to supply analog switches (optional) */
599 if (priv->cfg->has_syscfg & HAS_VBOOSTER &&
600 of_property_read_bool(np, "booster-supply")) {
601 priv->booster = devm_regulator_get_optional(dev, "booster");
602 if (IS_ERR(priv->booster)) {
603 ret = PTR_ERR(priv->booster);
605 return dev_err_probe(dev, ret, "can't get booster\n");
607 priv->booster = NULL;
611 /* Vdd can be used to supply analog switches (optional) */
612 if (priv->cfg->has_syscfg & HAS_ANASWVDD &&
613 of_property_read_bool(np, "vdd-supply")) {
614 priv->vdd = devm_regulator_get_optional(dev, "vdd");
615 if (IS_ERR(priv->vdd)) {
616 ret = PTR_ERR(priv->vdd);
618 return dev_err_probe(dev, ret, "can't get vdd\n");
625 ret = regulator_enable(priv->vdd);
627 dev_err(dev, "vdd enable failed %d\n", ret);
631 ret = regulator_get_voltage(priv->vdd);
633 dev_err(dev, "vdd get voltage failed %d\n", ret);
634 regulator_disable(priv->vdd);
639 regulator_disable(priv->vdd);
645 static int stm32_adc_probe(struct platform_device *pdev)
647 struct stm32_adc_priv *priv;
648 struct device *dev = &pdev->dev;
649 struct device_node *np = pdev->dev.of_node;
650 struct resource *res;
654 if (!pdev->dev.of_node)
657 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
660 platform_set_drvdata(pdev, &priv->common);
662 priv->cfg = (const struct stm32_adc_priv_cfg *)
663 of_match_device(dev->driver->of_match_table, dev)->data;
664 spin_lock_init(&priv->common.lock);
666 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
667 priv->common.base = devm_ioremap_resource(&pdev->dev, res);
668 if (IS_ERR(priv->common.base))
669 return PTR_ERR(priv->common.base);
670 priv->common.phys_base = res->start;
672 priv->vdda = devm_regulator_get(&pdev->dev, "vdda");
673 if (IS_ERR(priv->vdda))
674 return dev_err_probe(&pdev->dev, PTR_ERR(priv->vdda),
675 "vdda get failed\n");
677 priv->vref = devm_regulator_get(&pdev->dev, "vref");
678 if (IS_ERR(priv->vref))
679 return dev_err_probe(&pdev->dev, PTR_ERR(priv->vref),
680 "vref get failed\n");
682 priv->aclk = devm_clk_get_optional(&pdev->dev, "adc");
683 if (IS_ERR(priv->aclk))
684 return dev_err_probe(&pdev->dev, PTR_ERR(priv->aclk),
685 "Can't get 'adc' clock\n");
687 priv->bclk = devm_clk_get_optional(&pdev->dev, "bus");
688 if (IS_ERR(priv->bclk))
689 return dev_err_probe(&pdev->dev, PTR_ERR(priv->bclk),
690 "Can't get 'bus' clock\n");
692 ret = stm32_adc_core_switches_probe(dev, priv);
696 pm_runtime_get_noresume(dev);
697 pm_runtime_set_active(dev);
698 pm_runtime_set_autosuspend_delay(dev, STM32_ADC_CORE_SLEEP_DELAY_MS);
699 pm_runtime_use_autosuspend(dev);
700 pm_runtime_enable(dev);
702 ret = stm32_adc_core_hw_start(dev);
706 ret = regulator_get_voltage(priv->vref);
708 dev_err(&pdev->dev, "vref get voltage failed, %d\n", ret);
711 priv->common.vref_mv = ret / 1000;
712 dev_dbg(&pdev->dev, "vref+=%dmV\n", priv->common.vref_mv);
714 ret = of_property_read_u32(pdev->dev.of_node, "st,max-clk-rate-hz",
717 priv->max_clk_rate = min(max_rate, priv->cfg->max_clk_rate_hz);
719 priv->max_clk_rate = priv->cfg->max_clk_rate_hz;
721 ret = priv->cfg->clk_sel(pdev, priv);
725 ret = stm32_adc_irq_probe(pdev, priv);
729 ret = of_platform_populate(np, NULL, NULL, &pdev->dev);
731 dev_err(&pdev->dev, "failed to populate DT children\n");
735 pm_runtime_mark_last_busy(dev);
736 pm_runtime_put_autosuspend(dev);
741 stm32_adc_irq_remove(pdev, priv);
743 stm32_adc_core_hw_stop(dev);
745 pm_runtime_disable(dev);
746 pm_runtime_set_suspended(dev);
747 pm_runtime_put_noidle(dev);
752 static int stm32_adc_remove(struct platform_device *pdev)
754 struct stm32_adc_common *common = platform_get_drvdata(pdev);
755 struct stm32_adc_priv *priv = to_stm32_adc_priv(common);
757 pm_runtime_get_sync(&pdev->dev);
758 of_platform_depopulate(&pdev->dev);
759 stm32_adc_irq_remove(pdev, priv);
760 stm32_adc_core_hw_stop(&pdev->dev);
761 pm_runtime_disable(&pdev->dev);
762 pm_runtime_set_suspended(&pdev->dev);
763 pm_runtime_put_noidle(&pdev->dev);
768 static int stm32_adc_core_runtime_suspend(struct device *dev)
770 stm32_adc_core_hw_stop(dev);
775 static int stm32_adc_core_runtime_resume(struct device *dev)
777 return stm32_adc_core_hw_start(dev);
780 static int stm32_adc_core_runtime_idle(struct device *dev)
782 pm_runtime_mark_last_busy(dev);
787 static DEFINE_RUNTIME_DEV_PM_OPS(stm32_adc_core_pm_ops,
788 stm32_adc_core_runtime_suspend,
789 stm32_adc_core_runtime_resume,
790 stm32_adc_core_runtime_idle);
792 static const struct stm32_adc_priv_cfg stm32f4_adc_priv_cfg = {
793 .regs = &stm32f4_adc_common_regs,
794 .clk_sel = stm32f4_adc_clk_sel,
795 .max_clk_rate_hz = 36000000,
800 static const struct stm32_adc_priv_cfg stm32h7_adc_priv_cfg = {
801 .regs = &stm32h7_adc_common_regs,
802 .clk_sel = stm32h7_adc_clk_sel,
803 .max_clk_rate_hz = 36000000,
804 .has_syscfg = HAS_VBOOSTER,
809 static const struct stm32_adc_priv_cfg stm32mp1_adc_priv_cfg = {
810 .regs = &stm32h7_adc_common_regs,
811 .clk_sel = stm32h7_adc_clk_sel,
812 .max_clk_rate_hz = 36000000,
813 .has_syscfg = HAS_VBOOSTER | HAS_ANASWVDD,
818 static const struct of_device_id stm32_adc_of_match[] = {
820 .compatible = "st,stm32f4-adc-core",
821 .data = (void *)&stm32f4_adc_priv_cfg
823 .compatible = "st,stm32h7-adc-core",
824 .data = (void *)&stm32h7_adc_priv_cfg
826 .compatible = "st,stm32mp1-adc-core",
827 .data = (void *)&stm32mp1_adc_priv_cfg
831 MODULE_DEVICE_TABLE(of, stm32_adc_of_match);
833 static struct platform_driver stm32_adc_driver = {
834 .probe = stm32_adc_probe,
835 .remove = stm32_adc_remove,
837 .name = "stm32-adc-core",
838 .of_match_table = stm32_adc_of_match,
839 .pm = pm_ptr(&stm32_adc_core_pm_ops),
842 module_platform_driver(stm32_adc_driver);
844 MODULE_AUTHOR("Fabrice Gasnier <fabrice.gasnier@st.com>");
845 MODULE_DESCRIPTION("STMicroelectronics STM32 ADC core driver");
846 MODULE_LICENSE("GPL v2");
847 MODULE_ALIAS("platform:stm32-adc-core");