aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dma/sh/rcar-dmac.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/dma/sh/rcar-dmac.c')
-rw-r--r--drivers/dma/sh/rcar-dmac.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c
index 9c41a4e42575..1072c450c37a 100644
--- a/drivers/dma/sh/rcar-dmac.c
+++ b/drivers/dma/sh/rcar-dmac.c
@@ -192,6 +192,7 @@ struct rcar_dmac_chan {
192 * @iomem: remapped I/O memory base 192 * @iomem: remapped I/O memory base
193 * @n_channels: number of available channels 193 * @n_channels: number of available channels
194 * @channels: array of DMAC channels 194 * @channels: array of DMAC channels
195 * @channels_mask: bitfield of which DMA channels are managed by this driver
195 * @modules: bitmask of client modules in use 196 * @modules: bitmask of client modules in use
196 */ 197 */
197struct rcar_dmac { 198struct rcar_dmac {
@@ -202,6 +203,7 @@ struct rcar_dmac {
202 203
203 unsigned int n_channels; 204 unsigned int n_channels;
204 struct rcar_dmac_chan *channels; 205 struct rcar_dmac_chan *channels;
206 unsigned int channels_mask;
205 207
206 DECLARE_BITMAP(modules, 256); 208 DECLARE_BITMAP(modules, 256);
207}; 209};
@@ -438,7 +440,7 @@ static int rcar_dmac_init(struct rcar_dmac *dmac)
438 u16 dmaor; 440 u16 dmaor;
439 441
440 /* Clear all channels and enable the DMAC globally. */ 442 /* Clear all channels and enable the DMAC globally. */
441 rcar_dmac_write(dmac, RCAR_DMACHCLR, GENMASK(dmac->n_channels - 1, 0)); 443 rcar_dmac_write(dmac, RCAR_DMACHCLR, dmac->channels_mask);
442 rcar_dmac_write(dmac, RCAR_DMAOR, 444 rcar_dmac_write(dmac, RCAR_DMAOR,
443 RCAR_DMAOR_PRI_FIXED | RCAR_DMAOR_DME); 445 RCAR_DMAOR_PRI_FIXED | RCAR_DMAOR_DME);
444 446
@@ -814,6 +816,9 @@ static void rcar_dmac_stop_all_chan(struct rcar_dmac *dmac)
814 for (i = 0; i < dmac->n_channels; ++i) { 816 for (i = 0; i < dmac->n_channels; ++i) {
815 struct rcar_dmac_chan *chan = &dmac->channels[i]; 817 struct rcar_dmac_chan *chan = &dmac->channels[i];
816 818
819 if (!(dmac->channels_mask & BIT(i)))
820 continue;
821
817 /* Stop and reinitialize the channel. */ 822 /* Stop and reinitialize the channel. */
818 spin_lock_irq(&chan->lock); 823 spin_lock_irq(&chan->lock);
819 rcar_dmac_chan_halt(chan); 824 rcar_dmac_chan_halt(chan);
@@ -1776,6 +1781,8 @@ static int rcar_dmac_chan_probe(struct rcar_dmac *dmac,
1776 return 0; 1781 return 0;
1777} 1782}
1778 1783
1784#define RCAR_DMAC_MAX_CHANNELS 32
1785
1779static int rcar_dmac_parse_of(struct device *dev, struct rcar_dmac *dmac) 1786static int rcar_dmac_parse_of(struct device *dev, struct rcar_dmac *dmac)
1780{ 1787{
1781 struct device_node *np = dev->of_node; 1788 struct device_node *np = dev->of_node;
@@ -1787,12 +1794,16 @@ static int rcar_dmac_parse_of(struct device *dev, struct rcar_dmac *dmac)
1787 return ret; 1794 return ret;
1788 } 1795 }
1789 1796
1790 if (dmac->n_channels <= 0 || dmac->n_channels >= 100) { 1797 /* The hardware and driver don't support more than 32 bits in CHCLR */
1798 if (dmac->n_channels <= 0 ||
1799 dmac->n_channels >= RCAR_DMAC_MAX_CHANNELS) {
1791 dev_err(dev, "invalid number of channels %u\n", 1800 dev_err(dev, "invalid number of channels %u\n",
1792 dmac->n_channels); 1801 dmac->n_channels);
1793 return -EINVAL; 1802 return -EINVAL;
1794 } 1803 }
1795 1804
1805 dmac->channels_mask = GENMASK(dmac->n_channels - 1, 0);
1806
1796 return 0; 1807 return 0;
1797} 1808}
1798 1809
@@ -1802,7 +1813,6 @@ static int rcar_dmac_probe(struct platform_device *pdev)
1802 DMA_SLAVE_BUSWIDTH_2_BYTES | DMA_SLAVE_BUSWIDTH_4_BYTES | 1813 DMA_SLAVE_BUSWIDTH_2_BYTES | DMA_SLAVE_BUSWIDTH_4_BYTES |
1803 DMA_SLAVE_BUSWIDTH_8_BYTES | DMA_SLAVE_BUSWIDTH_16_BYTES | 1814 DMA_SLAVE_BUSWIDTH_8_BYTES | DMA_SLAVE_BUSWIDTH_16_BYTES |
1804 DMA_SLAVE_BUSWIDTH_32_BYTES | DMA_SLAVE_BUSWIDTH_64_BYTES; 1815 DMA_SLAVE_BUSWIDTH_32_BYTES | DMA_SLAVE_BUSWIDTH_64_BYTES;
1805 unsigned int channels_offset = 0;
1806 struct dma_device *engine; 1816 struct dma_device *engine;
1807 struct rcar_dmac *dmac; 1817 struct rcar_dmac *dmac;
1808 struct resource *mem; 1818 struct resource *mem;
@@ -1831,10 +1841,8 @@ static int rcar_dmac_probe(struct platform_device *pdev)
1831 * level we can't disable it selectively, so ignore channel 0 for now if 1841 * level we can't disable it selectively, so ignore channel 0 for now if
1832 * the device is part of an IOMMU group. 1842 * the device is part of an IOMMU group.
1833 */ 1843 */
1834 if (device_iommu_mapped(&pdev->dev)) { 1844 if (device_iommu_mapped(&pdev->dev))
1835 dmac->n_channels--; 1845 dmac->channels_mask &= ~BIT(0);
1836 channels_offset = 1;
1837 }
1838 1846
1839 dmac->channels = devm_kcalloc(&pdev->dev, dmac->n_channels, 1847 dmac->channels = devm_kcalloc(&pdev->dev, dmac->n_channels,
1840 sizeof(*dmac->channels), GFP_KERNEL); 1848 sizeof(*dmac->channels), GFP_KERNEL);
@@ -1892,8 +1900,10 @@ static int rcar_dmac_probe(struct platform_device *pdev)
1892 INIT_LIST_HEAD(&engine->channels); 1900 INIT_LIST_HEAD(&engine->channels);
1893 1901
1894 for (i = 0; i < dmac->n_channels; ++i) { 1902 for (i = 0; i < dmac->n_channels; ++i) {
1895 ret = rcar_dmac_chan_probe(dmac, &dmac->channels[i], 1903 if (!(dmac->channels_mask & BIT(i)))
1896 i + channels_offset); 1904 continue;
1905
1906 ret = rcar_dmac_chan_probe(dmac, &dmac->channels[i], i);
1897 if (ret < 0) 1907 if (ret < 0)
1898 goto error; 1908 goto error;
1899 } 1909 }