950-0110-dmaengine-Add-support-for-BCM2708.patch 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. From 52f0d07b546d1fd84aace07d69f8cf751ce8a3ab Mon Sep 17 00:00:00 2001
  2. From: Florian Meier <[email protected]>
  3. Date: Fri, 22 Nov 2013 14:22:53 +0100
  4. Subject: [PATCH] dmaengine: Add support for BCM2708
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Add support for DMA controller of BCM2708 as used in the Raspberry Pi.
  9. Currently it only supports cyclic DMA.
  10. Signed-off-by: Florian Meier <[email protected]>
  11. dmaengine: expand functionality by supporting scatter/gather transfers sdhci-bcm2708 and dma.c: fix for LITE channels
  12. DMA: fix cyclic LITE length overflow bug
  13. dmaengine: bcm2708: Remove chancnt affectations
  14. Mirror bcm2835-dma.c commit 9eba5536a7434c69d8c185d4bd1c70734d92287d:
  15. chancnt is already filled by dma_async_device_register, which uses the channel
  16. list to know how much channels there is.
  17. Since it's already filled, we can safely remove it from the drivers' probe
  18. function.
  19. Signed-off-by: Noralf Trønnes <[email protected]>
  20. dmaengine: bcm2708: overwrite dreq only if it is not set
  21. dreq is set when the DMA channel is fetched from Device Tree.
  22. slave_id is set using dmaengine_slave_config().
  23. Only overwrite dreq with slave_id if it is not set.
  24. dreq/slave_id in the cyclic DMA case is not touched, because I don't
  25. have hardware to test with.
  26. Signed-off-by: Noralf Trønnes <[email protected]>
  27. dmaengine: bcm2708: do device registration in the board file
  28. Don't register the device in the driver. Do it in the board file.
  29. Signed-off-by: Noralf Trønnes <[email protected]>
  30. dmaengine: bcm2708: don't restrict DT support to ARCH_BCM2835
  31. Both ARCH_BCM2835 and ARCH_BCM270x are built with OF now.
  32. Add Device Tree support to the non ARCH_BCM2835 case.
  33. Use the same driver name regardless of architecture.
  34. Signed-off-by: Noralf Trønnes <[email protected]>
  35. BCM270x_DT: add bcm2835-dma entry
  36. Add Device Tree entry for bcm2835-dma.
  37. The entry doesn't contain any resources since they are handled
  38. by the arch/arm/mach-bcm270x/dma.c driver.
  39. In non-DT mode, don't add the device in the board file.
  40. Signed-off-by: Noralf Trønnes <[email protected]>
  41. bcm2708-dmaengine: Add debug options
  42. BCM270x: Add memory and irq resources to dmaengine device and DT
  43. Prepare for merging of the legacy DMA API arch driver dma.c
  44. with bcm2708-dmaengine by adding memory and irq resources both
  45. to platform file device and Device Tree node.
  46. Don't use BCM_DMAMAN_DRIVER_NAME so we don't have to include mach/dma.h
  47. Signed-off-by: Noralf Trønnes <[email protected]>
  48. dmaengine: bcm2708: Merge with arch dma.c driver and disable dma.c
  49. Merge the legacy DMA API driver with bcm2708-dmaengine.
  50. This is done so we can use bcm2708_fb on ARCH_BCM2835 (mailbox
  51. driver is also needed).
  52. Changes to the dma.c code:
  53. - Use BIT() macro.
  54. - Cutdown some comments to one line.
  55. - Add mutex to vc_dmaman and use this, since the dev lock is locked
  56. during probing of the engine part.
  57. - Add global g_dmaman variable since drvdata is used by the engine part.
  58. - Restructure for readability:
  59. vc_dmaman_chan_alloc()
  60. vc_dmaman_chan_free()
  61. bcm_dma_chan_free()
  62. - Restructure bcm_dma_chan_alloc() to simplify error handling.
  63. - Use device irq resources instead of hardcoded bcm_dma_irqs table.
  64. - Remove dev_dmaman_register() and code it directly.
  65. - Remove dev_dmaman_deregister() and code it directly.
  66. - Simplify bcm_dmaman_probe() using devm_* functions.
  67. - Get dmachans from DT if available.
  68. - Keep 'dma.dmachans' module argument name for backwards compatibility.
  69. Make it available on ARCH_BCM2835 as well.
  70. Signed-off-by: Noralf Trønnes <[email protected]>
  71. dmaengine: bcm2708: set residue_granularity field
  72. bcm2708-dmaengine supports residue reporting at burst level
  73. but didn't report this via the residue_granularity field.
  74. Without this field set properly we get playback issues with I2S cards.
  75. dmaengine: bcm2708-dmaengine: Fix memory leak when stopping a running transfer
  76. bcm2708-dmaengine: Use more DMA channels (but not 12)
  77. 1) Only the bcm2708_fb drivers uses the legacy DMA API, and
  78. it requires a BULK-capable channel, so all other types
  79. (FAST, NORMAL and LITE) can be made available to the regular
  80. DMA API.
  81. 2) DMA channels 11-14 share an interrupt. The driver can't
  82. handle this, so don't use channels 12-14 (12 was used, probably
  83. because it appears to have an interrupt, but in reality that
  84. interrupt is for activity on ANY channel). This may explain
  85. a lockup encountered when running out of DMA channels.
  86. The combined effect of this patch is to leave 7 DMA channels
  87. available + channel 0 for bcm2708_fb via the legacy API.
  88. See: https://github.com/raspberrypi/linux/issues/1110
  89. https://github.com/raspberrypi/linux/issues/1108
  90. dmaengine: bcm2708: Make legacy API available for bcm2835-dma
  91. bcm2708_fb uses the legacy DMA API, so in order to start using
  92. bcm2835-dma, bcm2835-dma has to support the legacy API. Make this
  93. possible by exporting bcm_dmaman_probe() and bcm_dmaman_remove().
  94. Signed-off-by: Noralf Trønnes <[email protected]>
  95. dmaengine: bcm2708: Change DT compatible string
  96. Both bcm2835-dma and bcm2708-dmaengine have the same compatible string.
  97. So change compatible to "brcm,bcm2708-dma".
  98. Signed-off-by: Noralf Trønnes <[email protected]>
  99. dmaengine: bcm2708: Remove driver but keep legacy API
  100. Dropping non-DT support means we don't need this driver,
  101. but we still need the legacy DMA API.
  102. Signed-off-by: Noralf Trønnes <[email protected]>
  103. bcm2708-dmaengine - Fix arm64 portability/build issues
  104. dma-bcm2708: Fix module compilation of CONFIG_DMA_BCM2708
  105. bcm2708-dmaengine.c defines functions like bcm_dma_start which are
  106. defined as well in dma-bcm2708.h as inline versions when
  107. CONFIG_DMA_BCM2708 is not defined. This works fine when
  108. CONFIG_DMA_BCM2708 is built in, but when it is selected as module build
  109. fails with redefinition errors because in the build system when
  110. CONFIG_DMA_BCM2708 is selected as module, the macro becomes
  111. CONFIG_DMA_BCM2708_MODULE.
  112. This patch makes the header use CONFIG_DMA_BCM2708_MODULE too when
  113. available.
  114. Fixes https://github.com/raspberrypi/linux/issues/2056
  115. Signed-off-by: Andrei Gherzan <[email protected]>
  116. bcm2708-dmaengine: Use platform_get_irq
  117. The platform driver framework no longer creates IRQ resources for
  118. platform devices because they are expected to use platform_get_irq.
  119. This causes the bcm2808_fb acceleration to fail.
  120. Fix the problem by calling platform_get_irq as intended.
  121. See: https://github.com/raspberrypi/linux/issues/5131
  122. Signed-off-by: Phil Elwell <[email protected]>
  123. ---
  124. drivers/dma/Kconfig | 6 +-
  125. drivers/dma/Makefile | 1 +
  126. drivers/dma/bcm2708-dmaengine.c | 281 ++++++++++++++++++++++
  127. include/linux/platform_data/dma-bcm2708.h | 143 +++++++++++
  128. 4 files changed, 430 insertions(+), 1 deletion(-)
  129. create mode 100644 drivers/dma/bcm2708-dmaengine.c
  130. create mode 100644 include/linux/platform_data/dma-bcm2708.h
  131. --- a/drivers/dma/Kconfig
  132. +++ b/drivers/dma/Kconfig
  133. @@ -135,7 +135,7 @@ config BCM_SBA_RAID
  134. config DMA_BCM2835
  135. tristate "BCM2835 DMA engine support"
  136. - depends on ARCH_BCM2835 || ARCH_BCM2708 || ARCH_BCM2709
  137. + depends on ARCH_BCM2835
  138. select DMA_ENGINE
  139. select DMA_VIRTUAL_CHANNELS
  140. @@ -705,6 +705,10 @@ config UNIPHIER_XDMAC
  141. UniPhier platform. This DMA controller can transfer data from
  142. memory to memory, memory to peripheral and peripheral to memory.
  143. +config DMA_BCM2708
  144. + tristate "BCM2708 DMA legacy API support"
  145. + depends on DMA_BCM2835
  146. +
  147. config XGENE_DMA
  148. tristate "APM X-Gene DMA support"
  149. depends on ARCH_XGENE || COMPILE_TEST
  150. --- a/drivers/dma/Makefile
  151. +++ b/drivers/dma/Makefile
  152. @@ -22,6 +22,7 @@ obj-$(CONFIG_AT_HDMAC) += at_hdmac.o
  153. obj-$(CONFIG_AT_XDMAC) += at_xdmac.o
  154. obj-$(CONFIG_AXI_DMAC) += dma-axi-dmac.o
  155. obj-$(CONFIG_BCM_SBA_RAID) += bcm-sba-raid.o
  156. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  157. obj-$(CONFIG_DMA_BCM2835) += bcm2835-dma.o
  158. obj-$(CONFIG_DMA_JZ4780) += dma-jz4780.o
  159. obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o
  160. --- /dev/null
  161. +++ b/drivers/dma/bcm2708-dmaengine.c
  162. @@ -0,0 +1,281 @@
  163. +/*
  164. + * BCM2708 legacy DMA API
  165. + *
  166. + * This program is free software; you can redistribute it and/or modify
  167. + * it under the terms of the GNU General Public License as published by
  168. + * the Free Software Foundation; either version 2 of the License, or
  169. + * (at your option) any later version.
  170. + *
  171. + * This program is distributed in the hope that it will be useful,
  172. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  173. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  174. + * GNU General Public License for more details.
  175. + */
  176. +
  177. +#include <linux/init.h>
  178. +#include <linux/interrupt.h>
  179. +#include <linux/list.h>
  180. +#include <linux/module.h>
  181. +#include <linux/platform_data/dma-bcm2708.h>
  182. +#include <linux/platform_device.h>
  183. +#include <linux/slab.h>
  184. +#include <linux/io.h>
  185. +#include <linux/spinlock.h>
  186. +
  187. +#include "virt-dma.h"
  188. +
  189. +#define CACHE_LINE_MASK 31
  190. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  191. +
  192. +/* valid only for channels 0 - 14, 15 has its own base address */
  193. +#define BCM2708_DMA_CHAN(n) ((n) << 8) /* base address */
  194. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  195. + ((void __iomem *)((char *)(dma_base) + BCM2708_DMA_CHAN(n)))
  196. +
  197. +struct vc_dmaman {
  198. + void __iomem *dma_base;
  199. + u32 chan_available; /* bitmap of available channels */
  200. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  201. + struct mutex lock;
  202. +};
  203. +
  204. +static struct device *dmaman_dev; /* we assume there's only one! */
  205. +static struct vc_dmaman *g_dmaman; /* DMA manager */
  206. +
  207. +/* DMA Auxiliary Functions */
  208. +
  209. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  210. + section inside the DMA buffer and another section outside it.
  211. + Even if we flush DMA buffers from the cache there is always the chance that
  212. + during a DMA someone will access the part of a cache line that is outside
  213. + the DMA buffer - which will then bring in unwelcome data.
  214. + Without being able to dictate our own buffer pools we must insist that
  215. + DMA buffers consist of a whole number of cache lines.
  216. +*/
  217. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  218. +{
  219. + int i;
  220. +
  221. + for (i = 0; i < sg_len; i++) {
  222. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  223. + sg_ptr[i].length & CACHE_LINE_MASK)
  224. + return 0;
  225. + }
  226. +
  227. + return 1;
  228. +}
  229. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  230. +
  231. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  232. + dma_addr_t control_block)
  233. +{
  234. + dsb(sy); /* ARM data synchronization (push) operation */
  235. +
  236. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  237. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  238. +}
  239. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  240. +
  241. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  242. +{
  243. + dsb(sy);
  244. +
  245. + /* ugly busy wait only option for now */
  246. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  247. + cpu_relax();
  248. +}
  249. +EXPORT_SYMBOL_GPL(bcm_dma_wait_idle);
  250. +
  251. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  252. +{
  253. + dsb(sy);
  254. +
  255. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  256. +}
  257. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  258. +
  259. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  260. + Does nothing if there is no DMA in progress.
  261. + This routine waits for the current AXI transfer to complete before
  262. + terminating the current DMA. If the current transfer is hung on a DREQ used
  263. + by an uncooperative peripheral the AXI transfer may never complete. In this
  264. + case the routine times out and return a non-zero error code.
  265. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  266. + does not produce an interrupt.
  267. +*/
  268. +extern int bcm_dma_abort(void __iomem *dma_chan_base)
  269. +{
  270. + unsigned long int cs;
  271. + int rc = 0;
  272. +
  273. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  274. +
  275. + if (BCM2708_DMA_ACTIVE & cs) {
  276. + long int timeout = 10000;
  277. +
  278. + /* write 0 to the active bit - pause the DMA */
  279. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  280. +
  281. + /* wait for any current AXI transfer to complete */
  282. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  283. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  284. +
  285. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  286. + /* we'll un-pause when we set of our next DMA */
  287. + rc = -ETIMEDOUT;
  288. +
  289. + } else if (BCM2708_DMA_ACTIVE & cs) {
  290. + /* terminate the control block chain */
  291. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  292. +
  293. + /* abort the whole DMA */
  294. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  295. + dma_chan_base + BCM2708_DMA_CS);
  296. + }
  297. + }
  298. +
  299. + return rc;
  300. +}
  301. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  302. +
  303. + /* DMA Manager Device Methods */
  304. +
  305. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  306. + u32 chans_available)
  307. +{
  308. + dmaman->dma_base = dma_base;
  309. + dmaman->chan_available = chans_available;
  310. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* 2 & 3 */
  311. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* 0 */
  312. + dmaman->has_feature[BCM_DMA_FEATURE_NORMAL_ORD] = 0xfe; /* 1 to 7 */
  313. + dmaman->has_feature[BCM_DMA_FEATURE_LITE_ORD] = 0x7f00; /* 8 to 14 */
  314. +}
  315. +
  316. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  317. + unsigned required_feature_set)
  318. +{
  319. + u32 chans;
  320. + int chan = 0;
  321. + int feature;
  322. +
  323. + chans = dmaman->chan_available;
  324. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  325. + /* select the subset of available channels with the desired
  326. + features */
  327. + if (required_feature_set & (1 << feature))
  328. + chans &= dmaman->has_feature[feature];
  329. +
  330. + if (!chans)
  331. + return -ENOENT;
  332. +
  333. + /* return the ordinal of the first channel in the bitmap */
  334. + while (chans != 0 && (chans & 1) == 0) {
  335. + chans >>= 1;
  336. + chan++;
  337. + }
  338. + /* claim the channel */
  339. + dmaman->chan_available &= ~(1 << chan);
  340. +
  341. + return chan;
  342. +}
  343. +
  344. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  345. +{
  346. + if (chan < 0)
  347. + return -EINVAL;
  348. +
  349. + if ((1 << chan) & dmaman->chan_available)
  350. + return -EIDRM;
  351. +
  352. + dmaman->chan_available |= (1 << chan);
  353. +
  354. + return 0;
  355. +}
  356. +
  357. +/* DMA Manager Monitor */
  358. +
  359. +extern int bcm_dma_chan_alloc(unsigned required_feature_set,
  360. + void __iomem **out_dma_base, int *out_dma_irq)
  361. +{
  362. + struct vc_dmaman *dmaman = g_dmaman;
  363. + struct platform_device *pdev = to_platform_device(dmaman_dev);
  364. + int chan;
  365. + int irq;
  366. +
  367. + if (!dmaman_dev)
  368. + return -ENODEV;
  369. +
  370. + mutex_lock(&dmaman->lock);
  371. + chan = vc_dmaman_chan_alloc(dmaman, required_feature_set);
  372. + if (chan < 0)
  373. + goto out;
  374. +
  375. + irq = platform_get_irq(pdev, (unsigned int)chan);
  376. + if (irq < 0) {
  377. + dev_err(dmaman_dev, "failed to get irq for DMA channel %d\n",
  378. + chan);
  379. + vc_dmaman_chan_free(dmaman, chan);
  380. + chan = -ENOENT;
  381. + goto out;
  382. + }
  383. +
  384. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base, chan);
  385. + *out_dma_irq = irq;
  386. + dev_dbg(dmaman_dev,
  387. + "Legacy API allocated channel=%d, base=%p, irq=%i\n",
  388. + chan, *out_dma_base, *out_dma_irq);
  389. +
  390. +out:
  391. + mutex_unlock(&dmaman->lock);
  392. +
  393. + return chan;
  394. +}
  395. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  396. +
  397. +extern int bcm_dma_chan_free(int channel)
  398. +{
  399. + struct vc_dmaman *dmaman = g_dmaman;
  400. + int rc;
  401. +
  402. + if (!dmaman_dev)
  403. + return -ENODEV;
  404. +
  405. + mutex_lock(&dmaman->lock);
  406. + rc = vc_dmaman_chan_free(dmaman, channel);
  407. + mutex_unlock(&dmaman->lock);
  408. +
  409. + return rc;
  410. +}
  411. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  412. +
  413. +int bcm_dmaman_probe(struct platform_device *pdev, void __iomem *base,
  414. + u32 chans_available)
  415. +{
  416. + struct device *dev = &pdev->dev;
  417. + struct vc_dmaman *dmaman;
  418. +
  419. + dmaman = devm_kzalloc(dev, sizeof(*dmaman), GFP_KERNEL);
  420. + if (!dmaman)
  421. + return -ENOMEM;
  422. +
  423. + mutex_init(&dmaman->lock);
  424. + vc_dmaman_init(dmaman, base, chans_available);
  425. + g_dmaman = dmaman;
  426. + dmaman_dev = dev;
  427. +
  428. + dev_info(dev, "DMA legacy API manager, dmachans=0x%x\n",
  429. + chans_available);
  430. +
  431. + return 0;
  432. +}
  433. +EXPORT_SYMBOL(bcm_dmaman_probe);
  434. +
  435. +int bcm_dmaman_remove(struct platform_device *pdev)
  436. +{
  437. + dmaman_dev = NULL;
  438. +
  439. + return 0;
  440. +}
  441. +EXPORT_SYMBOL(bcm_dmaman_remove);
  442. +
  443. +MODULE_LICENSE("GPL");
  444. --- /dev/null
  445. +++ b/include/linux/platform_data/dma-bcm2708.h
  446. @@ -0,0 +1,143 @@
  447. +/*
  448. + * Copyright (C) 2010 Broadcom
  449. + *
  450. + * This program is free software; you can redistribute it and/or modify
  451. + * it under the terms of the GNU General Public License version 2 as
  452. + * published by the Free Software Foundation.
  453. + */
  454. +
  455. +#ifndef _PLAT_BCM2708_DMA_H
  456. +#define _PLAT_BCM2708_DMA_H
  457. +
  458. +/* DMA CS Control and Status bits */
  459. +#define BCM2708_DMA_ACTIVE BIT(0)
  460. +#define BCM2708_DMA_INT BIT(2)
  461. +#define BCM2708_DMA_ISPAUSED BIT(4) /* Pause requested or not active */
  462. +#define BCM2708_DMA_ISHELD BIT(5) /* Is held by DREQ flow control */
  463. +#define BCM2708_DMA_ERR BIT(8)
  464. +#define BCM2708_DMA_ABORT BIT(30) /* stop current CB, go to next, WO */
  465. +#define BCM2708_DMA_RESET BIT(31) /* WO, self clearing */
  466. +
  467. +/* DMA control block "info" field bits */
  468. +#define BCM2708_DMA_INT_EN BIT(0)
  469. +#define BCM2708_DMA_TDMODE BIT(1)
  470. +#define BCM2708_DMA_WAIT_RESP BIT(3)
  471. +#define BCM2708_DMA_D_INC BIT(4)
  472. +#define BCM2708_DMA_D_WIDTH BIT(5)
  473. +#define BCM2708_DMA_D_DREQ BIT(6)
  474. +#define BCM2708_DMA_S_INC BIT(8)
  475. +#define BCM2708_DMA_S_WIDTH BIT(9)
  476. +#define BCM2708_DMA_S_DREQ BIT(10)
  477. +
  478. +#define BCM2708_DMA_BURST(x) (((x) & 0xf) << 12)
  479. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  480. +#define BCM2708_DMA_WAITS(x) (((x) & 0x1f) << 21)
  481. +
  482. +#define BCM2708_DMA_DREQ_EMMC 11
  483. +#define BCM2708_DMA_DREQ_SDHOST 13
  484. +
  485. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  486. +#define BCM2708_DMA_ADDR 0x04
  487. +/* the current control block appears in the following registers - read only */
  488. +#define BCM2708_DMA_INFO 0x08
  489. +#define BCM2708_DMA_SOURCE_AD 0x0c
  490. +#define BCM2708_DMA_DEST_AD 0x10
  491. +#define BCM2708_DMA_NEXTCB 0x1C
  492. +#define BCM2708_DMA_DEBUG 0x20
  493. +
  494. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4) + BCM2708_DMA_CS)
  495. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4) + BCM2708_DMA_ADDR)
  496. +
  497. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  498. +
  499. +/* When listing features we can ask for when allocating DMA channels give
  500. + those with higher priority smaller ordinal numbers */
  501. +#define BCM_DMA_FEATURE_FAST_ORD 0
  502. +#define BCM_DMA_FEATURE_BULK_ORD 1
  503. +#define BCM_DMA_FEATURE_NORMAL_ORD 2
  504. +#define BCM_DMA_FEATURE_LITE_ORD 3
  505. +#define BCM_DMA_FEATURE_FAST BIT(BCM_DMA_FEATURE_FAST_ORD)
  506. +#define BCM_DMA_FEATURE_BULK BIT(BCM_DMA_FEATURE_BULK_ORD)
  507. +#define BCM_DMA_FEATURE_NORMAL BIT(BCM_DMA_FEATURE_NORMAL_ORD)
  508. +#define BCM_DMA_FEATURE_LITE BIT(BCM_DMA_FEATURE_LITE_ORD)
  509. +#define BCM_DMA_FEATURE_COUNT 4
  510. +
  511. +struct bcm2708_dma_cb {
  512. + u32 info;
  513. + u32 src;
  514. + u32 dst;
  515. + u32 length;
  516. + u32 stride;
  517. + u32 next;
  518. + u32 pad[2];
  519. +};
  520. +
  521. +struct scatterlist;
  522. +struct platform_device;
  523. +
  524. +#if defined(CONFIG_DMA_BCM2708) || defined(CONFIG_DMA_BCM2708_MODULE)
  525. +
  526. +int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  527. +void bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block);
  528. +void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  529. +bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  530. +int bcm_dma_abort(void __iomem *dma_chan_base);
  531. +
  532. +/* return channel no or -ve error */
  533. +int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  534. + void __iomem **out_dma_base, int *out_dma_irq);
  535. +int bcm_dma_chan_free(int channel);
  536. +
  537. +int bcm_dmaman_probe(struct platform_device *pdev, void __iomem *base,
  538. + u32 chans_available);
  539. +int bcm_dmaman_remove(struct platform_device *pdev);
  540. +
  541. +#else /* CONFIG_DMA_BCM2708 */
  542. +
  543. +static inline int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr,
  544. + int sg_len)
  545. +{
  546. + return 0;
  547. +}
  548. +
  549. +static inline void bcm_dma_start(void __iomem *dma_chan_base,
  550. + dma_addr_t control_block) { }
  551. +
  552. +static inline void bcm_dma_wait_idle(void __iomem *dma_chan_base) { }
  553. +
  554. +static inline bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  555. +{
  556. + return false;
  557. +}
  558. +
  559. +static inline int bcm_dma_abort(void __iomem *dma_chan_base)
  560. +{
  561. + return -EINVAL;
  562. +}
  563. +
  564. +static inline int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  565. + void __iomem **out_dma_base,
  566. + int *out_dma_irq)
  567. +{
  568. + return -EINVAL;
  569. +}
  570. +
  571. +static inline int bcm_dma_chan_free(int channel)
  572. +{
  573. + return -EINVAL;
  574. +}
  575. +
  576. +static inline int bcm_dmaman_probe(struct platform_device *pdev,
  577. + void __iomem *base, u32 chans_available)
  578. +{
  579. + return 0;
  580. +}
  581. +
  582. +static inline int bcm_dmaman_remove(struct platform_device *pdev)
  583. +{
  584. + return 0;
  585. +}
  586. +
  587. +#endif /* CONFIG_DMA_BCM2708 || CONFIG_DMA_BCM2708_MODULE */
  588. +
  589. +#endif /* _PLAT_BCM2708_DMA_H */