xref: /linux/drivers/dma/dw/platform.c (revision f8d9ddbc28518a0f7d39d2ce51f778759b49f73e)
1b466a37fSAndy Shevchenko // SPDX-License-Identifier: GPL-2.0
29cade1a4SAndy Shevchenko /*
39cade1a4SAndy Shevchenko  * Platform driver for the Synopsys DesignWare DMA Controller
49cade1a4SAndy Shevchenko  *
59cade1a4SAndy Shevchenko  * Copyright (C) 2007-2008 Atmel Corporation
69cade1a4SAndy Shevchenko  * Copyright (C) 2010-2011 ST Microelectronics
79cade1a4SAndy Shevchenko  * Copyright (C) 2013 Intel Corporation
89cade1a4SAndy Shevchenko  *
99cade1a4SAndy Shevchenko  * Some parts of this driver are derived from the original dw_dmac.
109cade1a4SAndy Shevchenko  */
119cade1a4SAndy Shevchenko 
129cade1a4SAndy Shevchenko #include <linux/module.h>
139cade1a4SAndy Shevchenko #include <linux/device.h>
149cade1a4SAndy Shevchenko #include <linux/clk.h>
156acf3998SAndy Shevchenko #include <linux/pm_runtime.h>
169cade1a4SAndy Shevchenko #include <linux/platform_device.h>
179cade1a4SAndy Shevchenko #include <linux/dmaengine.h>
189cade1a4SAndy Shevchenko #include <linux/dma-mapping.h>
199cade1a4SAndy Shevchenko #include <linux/of.h>
209cade1a4SAndy Shevchenko #include <linux/of_dma.h>
219cade1a4SAndy Shevchenko #include <linux/acpi.h>
229cade1a4SAndy Shevchenko #include <linux/acpi_dma.h>
239cade1a4SAndy Shevchenko 
249cade1a4SAndy Shevchenko #include "internal.h"
259cade1a4SAndy Shevchenko 
26a104a45bSAndy Shevchenko #define DRV_NAME	"dw_dmac"
27a104a45bSAndy Shevchenko 
289cade1a4SAndy Shevchenko static struct dma_chan *dw_dma_of_xlate(struct of_phandle_args *dma_spec,
299cade1a4SAndy Shevchenko 					struct of_dma *ofdma)
309cade1a4SAndy Shevchenko {
319cade1a4SAndy Shevchenko 	struct dw_dma *dw = ofdma->of_dma_data;
324d130de2SAndy Shevchenko 	struct dw_dma_slave slave = {
334d130de2SAndy Shevchenko 		.dma_dev = dw->dma.dev,
349cade1a4SAndy Shevchenko 	};
359cade1a4SAndy Shevchenko 	dma_cap_mask_t cap;
369cade1a4SAndy Shevchenko 
379cade1a4SAndy Shevchenko 	if (dma_spec->args_count != 3)
389cade1a4SAndy Shevchenko 		return NULL;
399cade1a4SAndy Shevchenko 
404d130de2SAndy Shevchenko 	slave.src_id = dma_spec->args[0];
414d130de2SAndy Shevchenko 	slave.dst_id = dma_spec->args[0];
42c422025cSAndy Shevchenko 	slave.m_master = dma_spec->args[1];
43c422025cSAndy Shevchenko 	slave.p_master = dma_spec->args[2];
449cade1a4SAndy Shevchenko 
454d130de2SAndy Shevchenko 	if (WARN_ON(slave.src_id >= DW_DMA_MAX_NR_REQUESTS ||
464d130de2SAndy Shevchenko 		    slave.dst_id >= DW_DMA_MAX_NR_REQUESTS ||
47161c3d04SAndy Shevchenko 		    slave.m_master >= dw->pdata->nr_masters ||
48161c3d04SAndy Shevchenko 		    slave.p_master >= dw->pdata->nr_masters))
499cade1a4SAndy Shevchenko 		return NULL;
509cade1a4SAndy Shevchenko 
519cade1a4SAndy Shevchenko 	dma_cap_zero(cap);
529cade1a4SAndy Shevchenko 	dma_cap_set(DMA_SLAVE, cap);
539cade1a4SAndy Shevchenko 
549cade1a4SAndy Shevchenko 	/* TODO: there should be a simpler way to do this */
554d130de2SAndy Shevchenko 	return dma_request_channel(cap, dw_dma_filter, &slave);
569cade1a4SAndy Shevchenko }
579cade1a4SAndy Shevchenko 
589cade1a4SAndy Shevchenko #ifdef CONFIG_ACPI
599cade1a4SAndy Shevchenko static bool dw_dma_acpi_filter(struct dma_chan *chan, void *param)
609cade1a4SAndy Shevchenko {
619cade1a4SAndy Shevchenko 	struct acpi_dma_spec *dma_spec = param;
624d130de2SAndy Shevchenko 	struct dw_dma_slave slave = {
634d130de2SAndy Shevchenko 		.dma_dev = dma_spec->dev,
644d130de2SAndy Shevchenko 		.src_id = dma_spec->slave_id,
654d130de2SAndy Shevchenko 		.dst_id = dma_spec->slave_id,
66c422025cSAndy Shevchenko 		.m_master = 0,
67c422025cSAndy Shevchenko 		.p_master = 1,
684d130de2SAndy Shevchenko 	};
699cade1a4SAndy Shevchenko 
704d130de2SAndy Shevchenko 	return dw_dma_filter(chan, &slave);
719cade1a4SAndy Shevchenko }
729cade1a4SAndy Shevchenko 
739cade1a4SAndy Shevchenko static void dw_dma_acpi_controller_register(struct dw_dma *dw)
749cade1a4SAndy Shevchenko {
759cade1a4SAndy Shevchenko 	struct device *dev = dw->dma.dev;
769cade1a4SAndy Shevchenko 	struct acpi_dma_filter_info *info;
779cade1a4SAndy Shevchenko 	int ret;
789cade1a4SAndy Shevchenko 
799cade1a4SAndy Shevchenko 	info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
809cade1a4SAndy Shevchenko 	if (!info)
819cade1a4SAndy Shevchenko 		return;
829cade1a4SAndy Shevchenko 
839cade1a4SAndy Shevchenko 	dma_cap_zero(info->dma_cap);
849cade1a4SAndy Shevchenko 	dma_cap_set(DMA_SLAVE, info->dma_cap);
859cade1a4SAndy Shevchenko 	info->filter_fn = dw_dma_acpi_filter;
869cade1a4SAndy Shevchenko 
879cade1a4SAndy Shevchenko 	ret = devm_acpi_dma_controller_register(dev, acpi_dma_simple_xlate,
889cade1a4SAndy Shevchenko 						info);
899cade1a4SAndy Shevchenko 	if (ret)
909cade1a4SAndy Shevchenko 		dev_err(dev, "could not register acpi_dma_controller\n");
919cade1a4SAndy Shevchenko }
929cade1a4SAndy Shevchenko #else /* !CONFIG_ACPI */
939cade1a4SAndy Shevchenko static inline void dw_dma_acpi_controller_register(struct dw_dma *dw) {}
949cade1a4SAndy Shevchenko #endif /* !CONFIG_ACPI */
959cade1a4SAndy Shevchenko 
969cade1a4SAndy Shevchenko #ifdef CONFIG_OF
979cade1a4SAndy Shevchenko static struct dw_dma_platform_data *
989cade1a4SAndy Shevchenko dw_dma_parse_dt(struct platform_device *pdev)
999cade1a4SAndy Shevchenko {
1009cade1a4SAndy Shevchenko 	struct device_node *np = pdev->dev.of_node;
1019cade1a4SAndy Shevchenko 	struct dw_dma_platform_data *pdata;
102bd2c6636SEugeniy Paltsev 	u32 tmp, arr[DW_DMA_MAX_NR_MASTERS], mb[DW_DMA_MAX_NR_CHANNELS];
103969f750fSAndy Shevchenko 	u32 nr_masters;
1042b574ba9SMans Rullgard 	u32 nr_channels;
1059cade1a4SAndy Shevchenko 
1069cade1a4SAndy Shevchenko 	if (!np) {
1079cade1a4SAndy Shevchenko 		dev_err(&pdev->dev, "Missing DT data\n");
1089cade1a4SAndy Shevchenko 		return NULL;
1099cade1a4SAndy Shevchenko 	}
1109cade1a4SAndy Shevchenko 
111969f750fSAndy Shevchenko 	if (of_property_read_u32(np, "dma-masters", &nr_masters))
112969f750fSAndy Shevchenko 		return NULL;
113969f750fSAndy Shevchenko 	if (nr_masters < 1 || nr_masters > DW_DMA_MAX_NR_MASTERS)
114969f750fSAndy Shevchenko 		return NULL;
115969f750fSAndy Shevchenko 
1162b574ba9SMans Rullgard 	if (of_property_read_u32(np, "dma-channels", &nr_channels))
1172b574ba9SMans Rullgard 		return NULL;
118bd2c6636SEugeniy Paltsev 	if (nr_channels > DW_DMA_MAX_NR_CHANNELS)
119bd2c6636SEugeniy Paltsev 		return NULL;
1202b574ba9SMans Rullgard 
1219cade1a4SAndy Shevchenko 	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
1229cade1a4SAndy Shevchenko 	if (!pdata)
1239cade1a4SAndy Shevchenko 		return NULL;
1249cade1a4SAndy Shevchenko 
125969f750fSAndy Shevchenko 	pdata->nr_masters = nr_masters;
1262b574ba9SMans Rullgard 	pdata->nr_channels = nr_channels;
1279cade1a4SAndy Shevchenko 
1289cade1a4SAndy Shevchenko 	if (!of_property_read_u32(np, "chan_allocation_order", &tmp))
1299cade1a4SAndy Shevchenko 		pdata->chan_allocation_order = (unsigned char)tmp;
1309cade1a4SAndy Shevchenko 
1319cade1a4SAndy Shevchenko 	if (!of_property_read_u32(np, "chan_priority", &tmp))
1329cade1a4SAndy Shevchenko 		pdata->chan_priority = tmp;
1339cade1a4SAndy Shevchenko 
1349cade1a4SAndy Shevchenko 	if (!of_property_read_u32(np, "block_size", &tmp))
1359cade1a4SAndy Shevchenko 		pdata->block_size = tmp;
1369cade1a4SAndy Shevchenko 
1372e65060eSAndy Shevchenko 	if (!of_property_read_u32_array(np, "data-width", arr, nr_masters)) {
138969f750fSAndy Shevchenko 		for (tmp = 0; tmp < nr_masters; tmp++)
1399cade1a4SAndy Shevchenko 			pdata->data_width[tmp] = arr[tmp];
1402e65060eSAndy Shevchenko 	} else if (!of_property_read_u32_array(np, "data_width", arr, nr_masters)) {
1412e65060eSAndy Shevchenko 		for (tmp = 0; tmp < nr_masters; tmp++)
1422e65060eSAndy Shevchenko 			pdata->data_width[tmp] = BIT(arr[tmp] & 0x07);
143969f750fSAndy Shevchenko 	}
1449cade1a4SAndy Shevchenko 
145bd2c6636SEugeniy Paltsev 	if (!of_property_read_u32_array(np, "multi-block", mb, nr_channels)) {
146bd2c6636SEugeniy Paltsev 		for (tmp = 0; tmp < nr_channels; tmp++)
147bd2c6636SEugeniy Paltsev 			pdata->multi_block[tmp] = mb[tmp];
148bd2c6636SEugeniy Paltsev 	} else {
149bd2c6636SEugeniy Paltsev 		for (tmp = 0; tmp < nr_channels; tmp++)
150bd2c6636SEugeniy Paltsev 			pdata->multi_block[tmp] = 1;
151bd2c6636SEugeniy Paltsev 	}
152bd2c6636SEugeniy Paltsev 
1537b0c03ecSChristian Lamparter 	if (!of_property_read_u32(np, "snps,dma-protection-control", &tmp)) {
1547b0c03ecSChristian Lamparter 		if (tmp > CHAN_PROTCTL_MASK)
1557b0c03ecSChristian Lamparter 			return NULL;
1567b0c03ecSChristian Lamparter 		pdata->protctl = tmp;
1577b0c03ecSChristian Lamparter 	}
1587b0c03ecSChristian Lamparter 
1599cade1a4SAndy Shevchenko 	return pdata;
1609cade1a4SAndy Shevchenko }
1619cade1a4SAndy Shevchenko #else
1629cade1a4SAndy Shevchenko static inline struct dw_dma_platform_data *
1639cade1a4SAndy Shevchenko dw_dma_parse_dt(struct platform_device *pdev)
1649cade1a4SAndy Shevchenko {
1659cade1a4SAndy Shevchenko 	return NULL;
1669cade1a4SAndy Shevchenko }
1679cade1a4SAndy Shevchenko #endif
1689cade1a4SAndy Shevchenko 
1699cade1a4SAndy Shevchenko static int dw_probe(struct platform_device *pdev)
1709cade1a4SAndy Shevchenko {
171b3757413SAndy Shevchenko 	const struct dw_dma_chip_pdata *match;
172b3757413SAndy Shevchenko 	struct dw_dma_chip_pdata *data;
1739cade1a4SAndy Shevchenko 	struct dw_dma_chip *chip;
1749cade1a4SAndy Shevchenko 	struct device *dev = &pdev->dev;
1759cade1a4SAndy Shevchenko 	struct resource *mem;
1769cade1a4SAndy Shevchenko 	int err;
1779cade1a4SAndy Shevchenko 
178b3757413SAndy Shevchenko 	match = device_get_match_data(dev);
179b3757413SAndy Shevchenko 	if (!match)
180b3757413SAndy Shevchenko 		return -ENODEV;
181b3757413SAndy Shevchenko 
182b3757413SAndy Shevchenko 	data = devm_kmemdup(&pdev->dev, match, sizeof(*match), GFP_KERNEL);
183b3757413SAndy Shevchenko 	if (!data)
184b3757413SAndy Shevchenko 		return -ENOMEM;
185b3757413SAndy Shevchenko 
1869cade1a4SAndy Shevchenko 	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
1879cade1a4SAndy Shevchenko 	if (!chip)
1889cade1a4SAndy Shevchenko 		return -ENOMEM;
1899cade1a4SAndy Shevchenko 
1909cade1a4SAndy Shevchenko 	chip->irq = platform_get_irq(pdev, 0);
1919cade1a4SAndy Shevchenko 	if (chip->irq < 0)
1929cade1a4SAndy Shevchenko 		return chip->irq;
1939cade1a4SAndy Shevchenko 
1949cade1a4SAndy Shevchenko 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1959cade1a4SAndy Shevchenko 	chip->regs = devm_ioremap_resource(dev, mem);
1969cade1a4SAndy Shevchenko 	if (IS_ERR(chip->regs))
1979cade1a4SAndy Shevchenko 		return PTR_ERR(chip->regs);
1989cade1a4SAndy Shevchenko 
19924353b8bSRussell King 	err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
20024353b8bSRussell King 	if (err)
20124353b8bSRussell King 		return err;
2029cade1a4SAndy Shevchenko 
203*f8d9ddbcSAndy Shevchenko 	if (!data->pdata)
204*f8d9ddbcSAndy Shevchenko 		data->pdata = dev_get_platdata(dev);
205*f8d9ddbcSAndy Shevchenko 	if (!data->pdata)
206*f8d9ddbcSAndy Shevchenko 		data->pdata = dw_dma_parse_dt(pdev);
2079cade1a4SAndy Shevchenko 
2089cade1a4SAndy Shevchenko 	chip->dev = dev;
20908d62f58SAndy Shevchenko 	chip->id = pdev->id;
210*f8d9ddbcSAndy Shevchenko 	chip->pdata = data->pdata;
2119cade1a4SAndy Shevchenko 
212b3757413SAndy Shevchenko 	data->chip = chip;
213b3757413SAndy Shevchenko 
214a15636e8SAndy Shevchenko 	chip->clk = devm_clk_get(chip->dev, "hclk");
215a15636e8SAndy Shevchenko 	if (IS_ERR(chip->clk))
216a15636e8SAndy Shevchenko 		return PTR_ERR(chip->clk);
217a15636e8SAndy Shevchenko 	err = clk_prepare_enable(chip->clk);
2189cade1a4SAndy Shevchenko 	if (err)
2199cade1a4SAndy Shevchenko 		return err;
2209cade1a4SAndy Shevchenko 
2216acf3998SAndy Shevchenko 	pm_runtime_enable(&pdev->dev);
2226acf3998SAndy Shevchenko 
223b3757413SAndy Shevchenko 	err = data->probe(chip);
224a15636e8SAndy Shevchenko 	if (err)
225a15636e8SAndy Shevchenko 		goto err_dw_dma_probe;
226a15636e8SAndy Shevchenko 
227b3757413SAndy Shevchenko 	platform_set_drvdata(pdev, data);
2289cade1a4SAndy Shevchenko 
2299cade1a4SAndy Shevchenko 	if (pdev->dev.of_node) {
2309cade1a4SAndy Shevchenko 		err = of_dma_controller_register(pdev->dev.of_node,
2319cade1a4SAndy Shevchenko 						 dw_dma_of_xlate, chip->dw);
2329cade1a4SAndy Shevchenko 		if (err)
2339cade1a4SAndy Shevchenko 			dev_err(&pdev->dev,
2349cade1a4SAndy Shevchenko 				"could not register of_dma_controller\n");
2359cade1a4SAndy Shevchenko 	}
2369cade1a4SAndy Shevchenko 
2379cade1a4SAndy Shevchenko 	if (ACPI_HANDLE(&pdev->dev))
2389cade1a4SAndy Shevchenko 		dw_dma_acpi_controller_register(chip->dw);
2399cade1a4SAndy Shevchenko 
2409cade1a4SAndy Shevchenko 	return 0;
241a15636e8SAndy Shevchenko 
242a15636e8SAndy Shevchenko err_dw_dma_probe:
2436acf3998SAndy Shevchenko 	pm_runtime_disable(&pdev->dev);
244a15636e8SAndy Shevchenko 	clk_disable_unprepare(chip->clk);
245a15636e8SAndy Shevchenko 	return err;
2469cade1a4SAndy Shevchenko }
2479cade1a4SAndy Shevchenko 
2489cade1a4SAndy Shevchenko static int dw_remove(struct platform_device *pdev)
2499cade1a4SAndy Shevchenko {
250b3757413SAndy Shevchenko 	struct dw_dma_chip_pdata *data = platform_get_drvdata(pdev);
251b3757413SAndy Shevchenko 	struct dw_dma_chip *chip = data->chip;
252b3757413SAndy Shevchenko 	int ret;
2539cade1a4SAndy Shevchenko 
2549cade1a4SAndy Shevchenko 	if (pdev->dev.of_node)
2559cade1a4SAndy Shevchenko 		of_dma_controller_free(pdev->dev.of_node);
2569cade1a4SAndy Shevchenko 
257b3757413SAndy Shevchenko 	ret = data->remove(chip);
258b3757413SAndy Shevchenko 	if (ret)
259b3757413SAndy Shevchenko 		dev_warn(chip->dev, "can't remove device properly: %d\n", ret);
260b3757413SAndy Shevchenko 
2616acf3998SAndy Shevchenko 	pm_runtime_disable(&pdev->dev);
262a15636e8SAndy Shevchenko 	clk_disable_unprepare(chip->clk);
263a15636e8SAndy Shevchenko 
264a15636e8SAndy Shevchenko 	return 0;
2659cade1a4SAndy Shevchenko }
2669cade1a4SAndy Shevchenko 
2679cade1a4SAndy Shevchenko static void dw_shutdown(struct platform_device *pdev)
2689cade1a4SAndy Shevchenko {
269b3757413SAndy Shevchenko 	struct dw_dma_chip_pdata *data = platform_get_drvdata(pdev);
270b3757413SAndy Shevchenko 	struct dw_dma_chip *chip = data->chip;
2719cade1a4SAndy Shevchenko 
27232146588SAndy Shevchenko 	/*
27369da8be9SAndy Shevchenko 	 * We have to call do_dw_dma_disable() to stop any ongoing transfer. On
27432146588SAndy Shevchenko 	 * some platforms we can't do that since DMA device is powered off.
27532146588SAndy Shevchenko 	 * Moreover we have no possibility to check if the platform is affected
27632146588SAndy Shevchenko 	 * or not. That's why we call pm_runtime_get_sync() / pm_runtime_put()
27732146588SAndy Shevchenko 	 * unconditionally. On the other hand we can't use
27832146588SAndy Shevchenko 	 * pm_runtime_suspended() because runtime PM framework is not fully
27932146588SAndy Shevchenko 	 * used by the driver.
28032146588SAndy Shevchenko 	 */
28132146588SAndy Shevchenko 	pm_runtime_get_sync(chip->dev);
28269da8be9SAndy Shevchenko 	do_dw_dma_disable(chip);
28332146588SAndy Shevchenko 	pm_runtime_put_sync_suspend(chip->dev);
28432146588SAndy Shevchenko 
285a15636e8SAndy Shevchenko 	clk_disable_unprepare(chip->clk);
2869cade1a4SAndy Shevchenko }
2879cade1a4SAndy Shevchenko 
2889cade1a4SAndy Shevchenko #ifdef CONFIG_OF
2899cade1a4SAndy Shevchenko static const struct of_device_id dw_dma_of_id_table[] = {
290b3757413SAndy Shevchenko 	{ .compatible = "snps,dma-spear1340", .data = &dw_dma_chip_pdata },
2919cade1a4SAndy Shevchenko 	{}
2929cade1a4SAndy Shevchenko };
2939cade1a4SAndy Shevchenko MODULE_DEVICE_TABLE(of, dw_dma_of_id_table);
2949cade1a4SAndy Shevchenko #endif
2959cade1a4SAndy Shevchenko 
2969cade1a4SAndy Shevchenko #ifdef CONFIG_ACPI
2979cade1a4SAndy Shevchenko static const struct acpi_device_id dw_dma_acpi_id_table[] = {
298b3757413SAndy Shevchenko 	{ "INTL9C60", (kernel_ulong_t)&dw_dma_chip_pdata },
299b3757413SAndy Shevchenko 	{ "80862286", (kernel_ulong_t)&dw_dma_chip_pdata },
300b3757413SAndy Shevchenko 	{ "808622C0", (kernel_ulong_t)&dw_dma_chip_pdata },
301*f8d9ddbcSAndy Shevchenko 
302*f8d9ddbcSAndy Shevchenko 	/* Elkhart Lake iDMA 32-bit (PSE DMA) */
303*f8d9ddbcSAndy Shevchenko 	{ "80864BB4", (kernel_ulong_t)&idma32_chip_pdata },
304*f8d9ddbcSAndy Shevchenko 	{ "80864BB5", (kernel_ulong_t)&idma32_chip_pdata },
305*f8d9ddbcSAndy Shevchenko 	{ "80864BB6", (kernel_ulong_t)&idma32_chip_pdata },
306*f8d9ddbcSAndy Shevchenko 
3079cade1a4SAndy Shevchenko 	{ }
3089cade1a4SAndy Shevchenko };
309be480dcbSAndy Shevchenko MODULE_DEVICE_TABLE(acpi, dw_dma_acpi_id_table);
3109cade1a4SAndy Shevchenko #endif
3119cade1a4SAndy Shevchenko 
3129cade1a4SAndy Shevchenko #ifdef CONFIG_PM_SLEEP
3139cade1a4SAndy Shevchenko 
314067bd4fdSAndy Shevchenko static int dw_suspend_late(struct device *dev)
3159cade1a4SAndy Shevchenko {
316b3757413SAndy Shevchenko 	struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
317b3757413SAndy Shevchenko 	struct dw_dma_chip *chip = data->chip;
3189cade1a4SAndy Shevchenko 
31969da8be9SAndy Shevchenko 	do_dw_dma_disable(chip);
320a15636e8SAndy Shevchenko 	clk_disable_unprepare(chip->clk);
321a15636e8SAndy Shevchenko 
322a15636e8SAndy Shevchenko 	return 0;
3239cade1a4SAndy Shevchenko }
3249cade1a4SAndy Shevchenko 
325067bd4fdSAndy Shevchenko static int dw_resume_early(struct device *dev)
3269cade1a4SAndy Shevchenko {
327b3757413SAndy Shevchenko 	struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
328b3757413SAndy Shevchenko 	struct dw_dma_chip *chip = data->chip;
329702fce05SArvind Yadav 	int ret;
3309cade1a4SAndy Shevchenko 
331702fce05SArvind Yadav 	ret = clk_prepare_enable(chip->clk);
332702fce05SArvind Yadav 	if (ret)
333702fce05SArvind Yadav 		return ret;
334702fce05SArvind Yadav 
33569da8be9SAndy Shevchenko 	return do_dw_dma_enable(chip);
3369cade1a4SAndy Shevchenko }
3379cade1a4SAndy Shevchenko 
338067bd4fdSAndy Shevchenko #endif /* CONFIG_PM_SLEEP */
3399cade1a4SAndy Shevchenko 
3409cade1a4SAndy Shevchenko static const struct dev_pm_ops dw_dev_pm_ops = {
341067bd4fdSAndy Shevchenko 	SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_suspend_late, dw_resume_early)
3429cade1a4SAndy Shevchenko };
3439cade1a4SAndy Shevchenko 
3449cade1a4SAndy Shevchenko static struct platform_driver dw_driver = {
3459cade1a4SAndy Shevchenko 	.probe		= dw_probe,
3469cade1a4SAndy Shevchenko 	.remove		= dw_remove,
3479cade1a4SAndy Shevchenko 	.shutdown       = dw_shutdown,
3489cade1a4SAndy Shevchenko 	.driver = {
349a104a45bSAndy Shevchenko 		.name	= DRV_NAME,
3509cade1a4SAndy Shevchenko 		.pm	= &dw_dev_pm_ops,
3519cade1a4SAndy Shevchenko 		.of_match_table = of_match_ptr(dw_dma_of_id_table),
3529cade1a4SAndy Shevchenko 		.acpi_match_table = ACPI_PTR(dw_dma_acpi_id_table),
3539cade1a4SAndy Shevchenko 	},
3549cade1a4SAndy Shevchenko };
3559cade1a4SAndy Shevchenko 
3569cade1a4SAndy Shevchenko static int __init dw_init(void)
3579cade1a4SAndy Shevchenko {
3589cade1a4SAndy Shevchenko 	return platform_driver_register(&dw_driver);
3599cade1a4SAndy Shevchenko }
3609cade1a4SAndy Shevchenko subsys_initcall(dw_init);
3619cade1a4SAndy Shevchenko 
3629cade1a4SAndy Shevchenko static void __exit dw_exit(void)
3639cade1a4SAndy Shevchenko {
3649cade1a4SAndy Shevchenko 	platform_driver_unregister(&dw_driver);
3659cade1a4SAndy Shevchenko }
3669cade1a4SAndy Shevchenko module_exit(dw_exit);
3679cade1a4SAndy Shevchenko 
3689cade1a4SAndy Shevchenko MODULE_LICENSE("GPL v2");
3699cade1a4SAndy Shevchenko MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller platform driver");
370a104a45bSAndy Shevchenko MODULE_ALIAS("platform:" DRV_NAME);
371