xref: /linux/drivers/mfd/stm32-timers.c (revision 06d07429858317ded2db7986113a9e0129cd599b)
1fa93f5b7SBenjamin Gaignard // SPDX-License-Identifier: GPL-2.0
2d0f949e2SBenjamin Gaignard /*
3d0f949e2SBenjamin Gaignard  * Copyright (C) STMicroelectronics 2016
4d0f949e2SBenjamin Gaignard  * Author: Benjamin Gaignard <benjamin.gaignard@st.com>
5d0f949e2SBenjamin Gaignard  */
6d0f949e2SBenjamin Gaignard 
70c660980SFabrice Gasnier #include <linux/bitfield.h>
8d0f949e2SBenjamin Gaignard #include <linux/mfd/stm32-timers.h>
9d0f949e2SBenjamin Gaignard #include <linux/module.h>
10d0f949e2SBenjamin Gaignard #include <linux/of_platform.h>
11dc0c386eSRob Herring #include <linux/platform_device.h>
12d0f949e2SBenjamin Gaignard #include <linux/reset.h>
13d0f949e2SBenjamin Gaignard 
140c660980SFabrice Gasnier #define STM32_TIMERS_MAX_REGISTERS	0x3fc
150c660980SFabrice Gasnier 
160c660980SFabrice Gasnier /* DIER register DMA enable bits */
170c660980SFabrice Gasnier static const u32 stm32_timers_dier_dmaen[STM32_TIMERS_MAX_DMAS] = {
180c660980SFabrice Gasnier 	TIM_DIER_CC1DE,
190c660980SFabrice Gasnier 	TIM_DIER_CC2DE,
200c660980SFabrice Gasnier 	TIM_DIER_CC3DE,
210c660980SFabrice Gasnier 	TIM_DIER_CC4DE,
220c660980SFabrice Gasnier 	TIM_DIER_UIE,
230c660980SFabrice Gasnier 	TIM_DIER_TDE,
240c660980SFabrice Gasnier 	TIM_DIER_COMDE
250c660980SFabrice Gasnier };
260c660980SFabrice Gasnier 
stm32_timers_dma_done(void * p)270c660980SFabrice Gasnier static void stm32_timers_dma_done(void *p)
280c660980SFabrice Gasnier {
290c660980SFabrice Gasnier 	struct stm32_timers_dma *dma = p;
300c660980SFabrice Gasnier 	struct dma_tx_state state;
310c660980SFabrice Gasnier 	enum dma_status status;
320c660980SFabrice Gasnier 
330c660980SFabrice Gasnier 	status = dmaengine_tx_status(dma->chan, dma->chan->cookie, &state);
340c660980SFabrice Gasnier 	if (status == DMA_COMPLETE)
350c660980SFabrice Gasnier 		complete(&dma->completion);
360c660980SFabrice Gasnier }
370c660980SFabrice Gasnier 
380c660980SFabrice Gasnier /**
390c660980SFabrice Gasnier  * stm32_timers_dma_burst_read - Read from timers registers using DMA.
400c660980SFabrice Gasnier  *
410c660980SFabrice Gasnier  * Read from STM32 timers registers using DMA on a single event.
420c660980SFabrice Gasnier  * @dev: reference to stm32_timers MFD device
430c660980SFabrice Gasnier  * @buf: DMA'able destination buffer
440c660980SFabrice Gasnier  * @id: stm32_timers_dmas event identifier (ch[1..4], up, trig or com)
450c660980SFabrice Gasnier  * @reg: registers start offset for DMA to read from (like CCRx for capture)
460c660980SFabrice Gasnier  * @num_reg: number of registers to read upon each DMA request, starting @reg.
470c660980SFabrice Gasnier  * @bursts: number of bursts to read (e.g. like two for pwm period capture)
480c660980SFabrice Gasnier  * @tmo_ms: timeout (milliseconds)
490c660980SFabrice Gasnier  */
stm32_timers_dma_burst_read(struct device * dev,u32 * buf,enum stm32_timers_dmas id,u32 reg,unsigned int num_reg,unsigned int bursts,unsigned long tmo_ms)500c660980SFabrice Gasnier int stm32_timers_dma_burst_read(struct device *dev, u32 *buf,
510c660980SFabrice Gasnier 				enum stm32_timers_dmas id, u32 reg,
520c660980SFabrice Gasnier 				unsigned int num_reg, unsigned int bursts,
530c660980SFabrice Gasnier 				unsigned long tmo_ms)
540c660980SFabrice Gasnier {
550c660980SFabrice Gasnier 	struct stm32_timers *ddata = dev_get_drvdata(dev);
560c660980SFabrice Gasnier 	unsigned long timeout = msecs_to_jiffies(tmo_ms);
570c660980SFabrice Gasnier 	struct regmap *regmap = ddata->regmap;
580c660980SFabrice Gasnier 	struct stm32_timers_dma *dma = &ddata->dma;
590c660980SFabrice Gasnier 	size_t len = num_reg * bursts * sizeof(u32);
600c660980SFabrice Gasnier 	struct dma_async_tx_descriptor *desc;
610c660980SFabrice Gasnier 	struct dma_slave_config config;
620c660980SFabrice Gasnier 	dma_cookie_t cookie;
630c660980SFabrice Gasnier 	dma_addr_t dma_buf;
640c660980SFabrice Gasnier 	u32 dbl, dba;
650c660980SFabrice Gasnier 	long err;
660c660980SFabrice Gasnier 	int ret;
670c660980SFabrice Gasnier 
680c660980SFabrice Gasnier 	/* Sanity check */
690c660980SFabrice Gasnier 	if (id < STM32_TIMERS_DMA_CH1 || id >= STM32_TIMERS_MAX_DMAS)
700c660980SFabrice Gasnier 		return -EINVAL;
710c660980SFabrice Gasnier 
720c660980SFabrice Gasnier 	if (!num_reg || !bursts || reg > STM32_TIMERS_MAX_REGISTERS ||
730c660980SFabrice Gasnier 	    (reg + num_reg * sizeof(u32)) > STM32_TIMERS_MAX_REGISTERS)
740c660980SFabrice Gasnier 		return -EINVAL;
750c660980SFabrice Gasnier 
760c660980SFabrice Gasnier 	if (!dma->chans[id])
770c660980SFabrice Gasnier 		return -ENODEV;
780c660980SFabrice Gasnier 	mutex_lock(&dma->lock);
790c660980SFabrice Gasnier 
800c660980SFabrice Gasnier 	/* Select DMA channel in use */
810c660980SFabrice Gasnier 	dma->chan = dma->chans[id];
820c660980SFabrice Gasnier 	dma_buf = dma_map_single(dev, buf, len, DMA_FROM_DEVICE);
830c660980SFabrice Gasnier 	if (dma_mapping_error(dev, dma_buf)) {
840c660980SFabrice Gasnier 		ret = -ENOMEM;
850c660980SFabrice Gasnier 		goto unlock;
860c660980SFabrice Gasnier 	}
870c660980SFabrice Gasnier 
880c660980SFabrice Gasnier 	/* Prepare DMA read from timer registers, using DMA burst mode */
890c660980SFabrice Gasnier 	memset(&config, 0, sizeof(config));
900c660980SFabrice Gasnier 	config.src_addr = (dma_addr_t)dma->phys_base + TIM_DMAR;
910c660980SFabrice Gasnier 	config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
920c660980SFabrice Gasnier 	ret = dmaengine_slave_config(dma->chan, &config);
930c660980SFabrice Gasnier 	if (ret)
940c660980SFabrice Gasnier 		goto unmap;
950c660980SFabrice Gasnier 
960c660980SFabrice Gasnier 	desc = dmaengine_prep_slave_single(dma->chan, dma_buf, len,
970c660980SFabrice Gasnier 					   DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
980c660980SFabrice Gasnier 	if (!desc) {
990c660980SFabrice Gasnier 		ret = -EBUSY;
1000c660980SFabrice Gasnier 		goto unmap;
1010c660980SFabrice Gasnier 	}
1020c660980SFabrice Gasnier 
1030c660980SFabrice Gasnier 	desc->callback = stm32_timers_dma_done;
1040c660980SFabrice Gasnier 	desc->callback_param = dma;
1050c660980SFabrice Gasnier 	cookie = dmaengine_submit(desc);
1060c660980SFabrice Gasnier 	ret = dma_submit_error(cookie);
1070c660980SFabrice Gasnier 	if (ret)
1080c660980SFabrice Gasnier 		goto dma_term;
1090c660980SFabrice Gasnier 
1100c660980SFabrice Gasnier 	reinit_completion(&dma->completion);
1110c660980SFabrice Gasnier 	dma_async_issue_pending(dma->chan);
1120c660980SFabrice Gasnier 
1130c660980SFabrice Gasnier 	/* Setup and enable timer DMA burst mode */
1140c660980SFabrice Gasnier 	dbl = FIELD_PREP(TIM_DCR_DBL, bursts - 1);
1150c660980SFabrice Gasnier 	dba = FIELD_PREP(TIM_DCR_DBA, reg >> 2);
1160c660980SFabrice Gasnier 	ret = regmap_write(regmap, TIM_DCR, dbl | dba);
1170c660980SFabrice Gasnier 	if (ret)
1180c660980SFabrice Gasnier 		goto dma_term;
1190c660980SFabrice Gasnier 
1200c660980SFabrice Gasnier 	/* Clear pending flags before enabling DMA request */
1210c660980SFabrice Gasnier 	ret = regmap_write(regmap, TIM_SR, 0);
1220c660980SFabrice Gasnier 	if (ret)
1230c660980SFabrice Gasnier 		goto dcr_clr;
1240c660980SFabrice Gasnier 
1250c660980SFabrice Gasnier 	ret = regmap_update_bits(regmap, TIM_DIER, stm32_timers_dier_dmaen[id],
1260c660980SFabrice Gasnier 				 stm32_timers_dier_dmaen[id]);
1270c660980SFabrice Gasnier 	if (ret)
1280c660980SFabrice Gasnier 		goto dcr_clr;
1290c660980SFabrice Gasnier 
1300c660980SFabrice Gasnier 	err = wait_for_completion_interruptible_timeout(&dma->completion,
1310c660980SFabrice Gasnier 							timeout);
1320c660980SFabrice Gasnier 	if (err == 0)
1330c660980SFabrice Gasnier 		ret = -ETIMEDOUT;
1340c660980SFabrice Gasnier 	else if (err < 0)
1350c660980SFabrice Gasnier 		ret = err;
1360c660980SFabrice Gasnier 
1370c660980SFabrice Gasnier 	regmap_update_bits(regmap, TIM_DIER, stm32_timers_dier_dmaen[id], 0);
1380c660980SFabrice Gasnier 	regmap_write(regmap, TIM_SR, 0);
1390c660980SFabrice Gasnier dcr_clr:
1400c660980SFabrice Gasnier 	regmap_write(regmap, TIM_DCR, 0);
1410c660980SFabrice Gasnier dma_term:
1420c660980SFabrice Gasnier 	dmaengine_terminate_all(dma->chan);
1430c660980SFabrice Gasnier unmap:
1440c660980SFabrice Gasnier 	dma_unmap_single(dev, dma_buf, len, DMA_FROM_DEVICE);
1450c660980SFabrice Gasnier unlock:
1460c660980SFabrice Gasnier 	dma->chan = NULL;
1470c660980SFabrice Gasnier 	mutex_unlock(&dma->lock);
1480c660980SFabrice Gasnier 
1490c660980SFabrice Gasnier 	return ret;
1500c660980SFabrice Gasnier }
1510c660980SFabrice Gasnier EXPORT_SYMBOL_GPL(stm32_timers_dma_burst_read);
1520c660980SFabrice Gasnier 
153d0f949e2SBenjamin Gaignard static const struct regmap_config stm32_timers_regmap_cfg = {
154d0f949e2SBenjamin Gaignard 	.reg_bits = 32,
155d0f949e2SBenjamin Gaignard 	.val_bits = 32,
156d0f949e2SBenjamin Gaignard 	.reg_stride = sizeof(u32),
1570c660980SFabrice Gasnier 	.max_register = STM32_TIMERS_MAX_REGISTERS,
158d0f949e2SBenjamin Gaignard };
159d0f949e2SBenjamin Gaignard 
stm32_timers_get_arr_size(struct stm32_timers * ddata)160d0f949e2SBenjamin Gaignard static void stm32_timers_get_arr_size(struct stm32_timers *ddata)
161d0f949e2SBenjamin Gaignard {
1624917e498SFabrice Gasnier 	u32 arr;
1634917e498SFabrice Gasnier 
1644917e498SFabrice Gasnier 	/* Backup ARR to restore it after getting the maximum value */
1654917e498SFabrice Gasnier 	regmap_read(ddata->regmap, TIM_ARR, &arr);
1664917e498SFabrice Gasnier 
167d0f949e2SBenjamin Gaignard 	/*
168d0f949e2SBenjamin Gaignard 	 * Only the available bits will be written so when readback
169d0f949e2SBenjamin Gaignard 	 * we get the maximum value of auto reload register
170d0f949e2SBenjamin Gaignard 	 */
171d0f949e2SBenjamin Gaignard 	regmap_write(ddata->regmap, TIM_ARR, ~0L);
172d0f949e2SBenjamin Gaignard 	regmap_read(ddata->regmap, TIM_ARR, &ddata->max_arr);
1734917e498SFabrice Gasnier 	regmap_write(ddata->regmap, TIM_ARR, arr);
174d0f949e2SBenjamin Gaignard }
175d0f949e2SBenjamin Gaignard 
stm32_timers_dma_probe(struct device * dev,struct stm32_timers * ddata)1768d7de077SPeter Ujfalusi static int stm32_timers_dma_probe(struct device *dev,
1770c660980SFabrice Gasnier 				   struct stm32_timers *ddata)
1780c660980SFabrice Gasnier {
1790c660980SFabrice Gasnier 	int i;
1808d7de077SPeter Ujfalusi 	int ret = 0;
1810c660980SFabrice Gasnier 	char name[4];
1820c660980SFabrice Gasnier 
1830c660980SFabrice Gasnier 	init_completion(&ddata->dma.completion);
1840c660980SFabrice Gasnier 	mutex_init(&ddata->dma.lock);
1850c660980SFabrice Gasnier 
1860c660980SFabrice Gasnier 	/* Optional DMA support: get valid DMA channel(s) or NULL */
1870c660980SFabrice Gasnier 	for (i = STM32_TIMERS_DMA_CH1; i <= STM32_TIMERS_DMA_CH4; i++) {
1880c660980SFabrice Gasnier 		snprintf(name, ARRAY_SIZE(name), "ch%1d", i + 1);
1898d7de077SPeter Ujfalusi 		ddata->dma.chans[i] = dma_request_chan(dev, name);
1900c660980SFabrice Gasnier 	}
1918d7de077SPeter Ujfalusi 	ddata->dma.chans[STM32_TIMERS_DMA_UP] = dma_request_chan(dev, "up");
1928d7de077SPeter Ujfalusi 	ddata->dma.chans[STM32_TIMERS_DMA_TRIG] = dma_request_chan(dev, "trig");
1938d7de077SPeter Ujfalusi 	ddata->dma.chans[STM32_TIMERS_DMA_COM] = dma_request_chan(dev, "com");
1948d7de077SPeter Ujfalusi 
1958d7de077SPeter Ujfalusi 	for (i = STM32_TIMERS_DMA_CH1; i < STM32_TIMERS_MAX_DMAS; i++) {
1968d7de077SPeter Ujfalusi 		if (IS_ERR(ddata->dma.chans[i])) {
1978d7de077SPeter Ujfalusi 			/* Save the first error code to return */
1988d7de077SPeter Ujfalusi 			if (PTR_ERR(ddata->dma.chans[i]) != -ENODEV && !ret)
1998d7de077SPeter Ujfalusi 				ret = PTR_ERR(ddata->dma.chans[i]);
2008d7de077SPeter Ujfalusi 
2018d7de077SPeter Ujfalusi 			ddata->dma.chans[i] = NULL;
2028d7de077SPeter Ujfalusi 		}
2038d7de077SPeter Ujfalusi 	}
2048d7de077SPeter Ujfalusi 
2058d7de077SPeter Ujfalusi 	return ret;
2060c660980SFabrice Gasnier }
2070c660980SFabrice Gasnier 
stm32_timers_dma_remove(struct device * dev,struct stm32_timers * ddata)2080c660980SFabrice Gasnier static void stm32_timers_dma_remove(struct device *dev,
2090c660980SFabrice Gasnier 				    struct stm32_timers *ddata)
2100c660980SFabrice Gasnier {
2110c660980SFabrice Gasnier 	int i;
2120c660980SFabrice Gasnier 
2130c660980SFabrice Gasnier 	for (i = STM32_TIMERS_DMA_CH1; i < STM32_TIMERS_MAX_DMAS; i++)
2140c660980SFabrice Gasnier 		if (ddata->dma.chans[i])
2150c660980SFabrice Gasnier 			dma_release_channel(ddata->dma.chans[i]);
2160c660980SFabrice Gasnier }
2170c660980SFabrice Gasnier 
2181c7ea43fSFabrice Gasnier static const char * const stm32_timers_irq_name[STM32_TIMERS_MAX_IRQS] = {
2191c7ea43fSFabrice Gasnier 	"brk", "up", "trg-com", "cc"
2201c7ea43fSFabrice Gasnier };
2211c7ea43fSFabrice Gasnier 
stm32_timers_irq_probe(struct platform_device * pdev,struct stm32_timers * ddata)2221c7ea43fSFabrice Gasnier static int stm32_timers_irq_probe(struct platform_device *pdev,
2231c7ea43fSFabrice Gasnier 				  struct stm32_timers *ddata)
2241c7ea43fSFabrice Gasnier {
2251c7ea43fSFabrice Gasnier 	int i, ret;
2261c7ea43fSFabrice Gasnier 
2271c7ea43fSFabrice Gasnier 	/*
2281c7ea43fSFabrice Gasnier 	 * STM32 Timer may have either:
2291c7ea43fSFabrice Gasnier 	 * - a unique global interrupt line
2301c7ea43fSFabrice Gasnier 	 * - four dedicated interrupt lines that may be handled separately.
2311c7ea43fSFabrice Gasnier 	 * Optionally get them here, to be used by child devices.
2321c7ea43fSFabrice Gasnier 	 */
2331c7ea43fSFabrice Gasnier 	ret = platform_get_irq_byname_optional(pdev, "global");
2341c7ea43fSFabrice Gasnier 	if (ret < 0 && ret != -ENXIO) {
2351c7ea43fSFabrice Gasnier 		return ret;
2361c7ea43fSFabrice Gasnier 	} else if (ret != -ENXIO) {
2371c7ea43fSFabrice Gasnier 		ddata->irq[STM32_TIMERS_IRQ_GLOBAL_BRK] = ret;
2381c7ea43fSFabrice Gasnier 		ddata->nr_irqs = 1;
2391c7ea43fSFabrice Gasnier 		return 0;
2401c7ea43fSFabrice Gasnier 	}
2411c7ea43fSFabrice Gasnier 
2421c7ea43fSFabrice Gasnier 	for (i = 0; i < STM32_TIMERS_MAX_IRQS; i++) {
2431c7ea43fSFabrice Gasnier 		ret = platform_get_irq_byname_optional(pdev, stm32_timers_irq_name[i]);
2441c7ea43fSFabrice Gasnier 		if (ret < 0 && ret != -ENXIO) {
2451c7ea43fSFabrice Gasnier 			return ret;
2461c7ea43fSFabrice Gasnier 		} else if (ret != -ENXIO) {
2471c7ea43fSFabrice Gasnier 			ddata->irq[i] = ret;
2481c7ea43fSFabrice Gasnier 			ddata->nr_irqs++;
2491c7ea43fSFabrice Gasnier 		}
2501c7ea43fSFabrice Gasnier 	}
2511c7ea43fSFabrice Gasnier 
2521c7ea43fSFabrice Gasnier 	if (ddata->nr_irqs && ddata->nr_irqs != STM32_TIMERS_MAX_IRQS) {
2531c7ea43fSFabrice Gasnier 		dev_err(&pdev->dev, "Invalid number of IRQs %d\n", ddata->nr_irqs);
2541c7ea43fSFabrice Gasnier 		return -EINVAL;
2551c7ea43fSFabrice Gasnier 	}
2561c7ea43fSFabrice Gasnier 
2571c7ea43fSFabrice Gasnier 	return 0;
2581c7ea43fSFabrice Gasnier }
2591c7ea43fSFabrice Gasnier 
stm32_timers_probe(struct platform_device * pdev)260d0f949e2SBenjamin Gaignard static int stm32_timers_probe(struct platform_device *pdev)
261d0f949e2SBenjamin Gaignard {
262d0f949e2SBenjamin Gaignard 	struct device *dev = &pdev->dev;
263d0f949e2SBenjamin Gaignard 	struct stm32_timers *ddata;
264d0f949e2SBenjamin Gaignard 	struct resource *res;
265d0f949e2SBenjamin Gaignard 	void __iomem *mmio;
2660c660980SFabrice Gasnier 	int ret;
267d0f949e2SBenjamin Gaignard 
268d0f949e2SBenjamin Gaignard 	ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
269d0f949e2SBenjamin Gaignard 	if (!ddata)
270d0f949e2SBenjamin Gaignard 		return -ENOMEM;
271d0f949e2SBenjamin Gaignard 
2724c0104bfSYangtao Li 	mmio = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
273d0f949e2SBenjamin Gaignard 	if (IS_ERR(mmio))
274d0f949e2SBenjamin Gaignard 		return PTR_ERR(mmio);
275d0f949e2SBenjamin Gaignard 
2760c660980SFabrice Gasnier 	/* Timer physical addr for DMA */
2770c660980SFabrice Gasnier 	ddata->dma.phys_base = res->start;
2780c660980SFabrice Gasnier 
279d0f949e2SBenjamin Gaignard 	ddata->regmap = devm_regmap_init_mmio_clk(dev, "int", mmio,
280d0f949e2SBenjamin Gaignard 						  &stm32_timers_regmap_cfg);
281d0f949e2SBenjamin Gaignard 	if (IS_ERR(ddata->regmap))
282d0f949e2SBenjamin Gaignard 		return PTR_ERR(ddata->regmap);
283d0f949e2SBenjamin Gaignard 
284d0f949e2SBenjamin Gaignard 	ddata->clk = devm_clk_get(dev, NULL);
285d0f949e2SBenjamin Gaignard 	if (IS_ERR(ddata->clk))
286d0f949e2SBenjamin Gaignard 		return PTR_ERR(ddata->clk);
287d0f949e2SBenjamin Gaignard 
288d0f949e2SBenjamin Gaignard 	stm32_timers_get_arr_size(ddata);
289d0f949e2SBenjamin Gaignard 
2901c7ea43fSFabrice Gasnier 	ret = stm32_timers_irq_probe(pdev, ddata);
2911c7ea43fSFabrice Gasnier 	if (ret)
2921c7ea43fSFabrice Gasnier 		return ret;
2931c7ea43fSFabrice Gasnier 
2948d7de077SPeter Ujfalusi 	ret = stm32_timers_dma_probe(dev, ddata);
2958d7de077SPeter Ujfalusi 	if (ret) {
2968d7de077SPeter Ujfalusi 		stm32_timers_dma_remove(dev, ddata);
2978d7de077SPeter Ujfalusi 		return ret;
2988d7de077SPeter Ujfalusi 	}
2990c660980SFabrice Gasnier 
300d0f949e2SBenjamin Gaignard 	platform_set_drvdata(pdev, ddata);
301d0f949e2SBenjamin Gaignard 
3020c660980SFabrice Gasnier 	ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
3030c660980SFabrice Gasnier 	if (ret)
3040c660980SFabrice Gasnier 		stm32_timers_dma_remove(dev, ddata);
3050c660980SFabrice Gasnier 
3060c660980SFabrice Gasnier 	return ret;
3070c660980SFabrice Gasnier }
3080c660980SFabrice Gasnier 
stm32_timers_remove(struct platform_device * pdev)309*eea669cbSUwe Kleine-König static void stm32_timers_remove(struct platform_device *pdev)
3100c660980SFabrice Gasnier {
3110c660980SFabrice Gasnier 	struct stm32_timers *ddata = platform_get_drvdata(pdev);
3120c660980SFabrice Gasnier 
3130c660980SFabrice Gasnier 	/*
3140c660980SFabrice Gasnier 	 * Don't use devm_ here: enfore of_platform_depopulate() happens before
3150c660980SFabrice Gasnier 	 * DMA are released, to avoid race on DMA.
3160c660980SFabrice Gasnier 	 */
3170c660980SFabrice Gasnier 	of_platform_depopulate(&pdev->dev);
3180c660980SFabrice Gasnier 	stm32_timers_dma_remove(&pdev->dev, ddata);
319f8b7ce67SFabrice Gasnier }
320f8b7ce67SFabrice Gasnier 
321d0f949e2SBenjamin Gaignard static const struct of_device_id stm32_timers_of_match[] = {
322d0f949e2SBenjamin Gaignard 	{ .compatible = "st,stm32-timers", },
323d0f949e2SBenjamin Gaignard 	{ /* end node */ },
324d0f949e2SBenjamin Gaignard };
325d0f949e2SBenjamin Gaignard MODULE_DEVICE_TABLE(of, stm32_timers_of_match);
326d0f949e2SBenjamin Gaignard 
327d0f949e2SBenjamin Gaignard static struct platform_driver stm32_timers_driver = {
328d0f949e2SBenjamin Gaignard 	.probe = stm32_timers_probe,
329*eea669cbSUwe Kleine-König 	.remove_new = stm32_timers_remove,
330d0f949e2SBenjamin Gaignard 	.driver	= {
331d0f949e2SBenjamin Gaignard 		.name = "stm32-timers",
332d0f949e2SBenjamin Gaignard 		.of_match_table = stm32_timers_of_match,
333d0f949e2SBenjamin Gaignard 	},
334d0f949e2SBenjamin Gaignard };
335d0f949e2SBenjamin Gaignard module_platform_driver(stm32_timers_driver);
336d0f949e2SBenjamin Gaignard 
337d0f949e2SBenjamin Gaignard MODULE_DESCRIPTION("STMicroelectronics STM32 Timers");
338d0f949e2SBenjamin Gaignard MODULE_LICENSE("GPL v2");
339