0031-dmaengine-Add-support-for-BCM2708.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. From 2ea9159435f6fdc6190126e7c413cb8c37259036 Mon Sep 17 00:00:00 2001
  2. From: Florian Meier <florian.meier@koalo.de>
  3. Date: Fri, 22 Nov 2013 14:22:53 +0100
  4. Subject: [PATCH 031/381] 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 <florian.meier@koalo.de>
  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 <noralf@tronnes.org>
  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 <noralf@tronnes.org>
  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 <noralf@tronnes.org>
  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 <noralf@tronnes.org>
  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 <noralf@tronnes.org>
  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 <noralf@tronnes.org>
  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 <noralf@tronnes.org>
  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 <noralf@tronnes.org>
  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 <noralf@tronnes.org>
  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 <noralf@tronnes.org>
  103. ---
  104. drivers/dma/Kconfig | 4 +
  105. drivers/dma/Makefile | 1 +
  106. drivers/dma/bcm2708-dmaengine.c | 281 ++++++++++++++++++++++++++++++
  107. include/linux/platform_data/dma-bcm2708.h | 143 +++++++++++++++
  108. 4 files changed, 429 insertions(+)
  109. create mode 100644 drivers/dma/bcm2708-dmaengine.c
  110. create mode 100644 include/linux/platform_data/dma-bcm2708.h
  111. --- a/drivers/dma/Kconfig
  112. +++ b/drivers/dma/Kconfig
  113. @@ -470,6 +470,10 @@ config TIMB_DMA
  114. help
  115. Enable support for the Timberdale FPGA DMA engine.
  116. +config DMA_BCM2708
  117. + tristate "BCM2708 DMA legacy API support"
  118. + depends on DMA_BCM2835
  119. +
  120. config TI_CPPI41
  121. tristate "AM33xx CPPI41 DMA support"
  122. depends on ARCH_OMAP
  123. --- a/drivers/dma/Makefile
  124. +++ b/drivers/dma/Makefile
  125. @@ -18,6 +18,7 @@ obj-$(CONFIG_AT_HDMAC) += at_hdmac.o
  126. obj-$(CONFIG_AT_XDMAC) += at_xdmac.o
  127. obj-$(CONFIG_AXI_DMAC) += dma-axi-dmac.o
  128. obj-$(CONFIG_COH901318) += coh901318.o coh901318_lli.o
  129. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  130. obj-$(CONFIG_DMA_BCM2835) += bcm2835-dma.o
  131. obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
  132. obj-$(CONFIG_DMA_JZ4780) += dma-jz4780.o
  133. --- /dev/null
  134. +++ b/drivers/dma/bcm2708-dmaengine.c
  135. @@ -0,0 +1,281 @@
  136. +/*
  137. + * BCM2708 legacy DMA API
  138. + *
  139. + * This program is free software; you can redistribute it and/or modify
  140. + * it under the terms of the GNU General Public License as published by
  141. + * the Free Software Foundation; either version 2 of the License, or
  142. + * (at your option) any later version.
  143. + *
  144. + * This program is distributed in the hope that it will be useful,
  145. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  146. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  147. + * GNU General Public License for more details.
  148. + */
  149. +
  150. +#include <linux/init.h>
  151. +#include <linux/interrupt.h>
  152. +#include <linux/list.h>
  153. +#include <linux/module.h>
  154. +#include <linux/platform_data/dma-bcm2708.h>
  155. +#include <linux/platform_device.h>
  156. +#include <linux/slab.h>
  157. +#include <linux/io.h>
  158. +#include <linux/spinlock.h>
  159. +
  160. +#include "virt-dma.h"
  161. +
  162. +#define CACHE_LINE_MASK 31
  163. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  164. +
  165. +/* valid only for channels 0 - 14, 15 has its own base address */
  166. +#define BCM2708_DMA_CHAN(n) ((n) << 8) /* base address */
  167. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  168. + ((void __iomem *)((char *)(dma_base) + BCM2708_DMA_CHAN(n)))
  169. +
  170. +struct vc_dmaman {
  171. + void __iomem *dma_base;
  172. + u32 chan_available; /* bitmap of available channels */
  173. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  174. + struct mutex lock;
  175. +};
  176. +
  177. +static struct device *dmaman_dev; /* we assume there's only one! */
  178. +static struct vc_dmaman *g_dmaman; /* DMA manager */
  179. +
  180. +/* DMA Auxiliary Functions */
  181. +
  182. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  183. + section inside the DMA buffer and another section outside it.
  184. + Even if we flush DMA buffers from the cache there is always the chance that
  185. + during a DMA someone will access the part of a cache line that is outside
  186. + the DMA buffer - which will then bring in unwelcome data.
  187. + Without being able to dictate our own buffer pools we must insist that
  188. + DMA buffers consist of a whole number of cache lines.
  189. +*/
  190. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  191. +{
  192. + int i;
  193. +
  194. + for (i = 0; i < sg_len; i++) {
  195. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  196. + sg_ptr[i].length & CACHE_LINE_MASK)
  197. + return 0;
  198. + }
  199. +
  200. + return 1;
  201. +}
  202. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  203. +
  204. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  205. + dma_addr_t control_block)
  206. +{
  207. + dsb(); /* ARM data synchronization (push) operation */
  208. +
  209. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  210. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  211. +}
  212. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  213. +
  214. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  215. +{
  216. + dsb();
  217. +
  218. + /* ugly busy wait only option for now */
  219. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  220. + cpu_relax();
  221. +}
  222. +EXPORT_SYMBOL_GPL(bcm_dma_wait_idle);
  223. +
  224. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  225. +{
  226. + dsb();
  227. +
  228. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  229. +}
  230. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  231. +
  232. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  233. + Does nothing if there is no DMA in progress.
  234. + This routine waits for the current AXI transfer to complete before
  235. + terminating the current DMA. If the current transfer is hung on a DREQ used
  236. + by an uncooperative peripheral the AXI transfer may never complete. In this
  237. + case the routine times out and return a non-zero error code.
  238. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  239. + does not produce an interrupt.
  240. +*/
  241. +extern int bcm_dma_abort(void __iomem *dma_chan_base)
  242. +{
  243. + unsigned long int cs;
  244. + int rc = 0;
  245. +
  246. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  247. +
  248. + if (BCM2708_DMA_ACTIVE & cs) {
  249. + long int timeout = 10000;
  250. +
  251. + /* write 0 to the active bit - pause the DMA */
  252. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  253. +
  254. + /* wait for any current AXI transfer to complete */
  255. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  256. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  257. +
  258. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  259. + /* we'll un-pause when we set of our next DMA */
  260. + rc = -ETIMEDOUT;
  261. +
  262. + } else if (BCM2708_DMA_ACTIVE & cs) {
  263. + /* terminate the control block chain */
  264. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  265. +
  266. + /* abort the whole DMA */
  267. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  268. + dma_chan_base + BCM2708_DMA_CS);
  269. + }
  270. + }
  271. +
  272. + return rc;
  273. +}
  274. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  275. +
  276. + /* DMA Manager Device Methods */
  277. +
  278. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  279. + u32 chans_available)
  280. +{
  281. + dmaman->dma_base = dma_base;
  282. + dmaman->chan_available = chans_available;
  283. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* 2 & 3 */
  284. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* 0 */
  285. + dmaman->has_feature[BCM_DMA_FEATURE_NORMAL_ORD] = 0xfe; /* 1 to 7 */
  286. + dmaman->has_feature[BCM_DMA_FEATURE_LITE_ORD] = 0x7f00; /* 8 to 14 */
  287. +}
  288. +
  289. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  290. + unsigned required_feature_set)
  291. +{
  292. + u32 chans;
  293. + int chan = 0;
  294. + int feature;
  295. +
  296. + chans = dmaman->chan_available;
  297. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  298. + /* select the subset of available channels with the desired
  299. + features */
  300. + if (required_feature_set & (1 << feature))
  301. + chans &= dmaman->has_feature[feature];
  302. +
  303. + if (!chans)
  304. + return -ENOENT;
  305. +
  306. + /* return the ordinal of the first channel in the bitmap */
  307. + while (chans != 0 && (chans & 1) == 0) {
  308. + chans >>= 1;
  309. + chan++;
  310. + }
  311. + /* claim the channel */
  312. + dmaman->chan_available &= ~(1 << chan);
  313. +
  314. + return chan;
  315. +}
  316. +
  317. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  318. +{
  319. + if (chan < 0)
  320. + return -EINVAL;
  321. +
  322. + if ((1 << chan) & dmaman->chan_available)
  323. + return -EIDRM;
  324. +
  325. + dmaman->chan_available |= (1 << chan);
  326. +
  327. + return 0;
  328. +}
  329. +
  330. +/* DMA Manager Monitor */
  331. +
  332. +extern int bcm_dma_chan_alloc(unsigned required_feature_set,
  333. + void __iomem **out_dma_base, int *out_dma_irq)
  334. +{
  335. + struct vc_dmaman *dmaman = g_dmaman;
  336. + struct platform_device *pdev = to_platform_device(dmaman_dev);
  337. + struct resource *r;
  338. + int chan;
  339. +
  340. + if (!dmaman_dev)
  341. + return -ENODEV;
  342. +
  343. + mutex_lock(&dmaman->lock);
  344. + chan = vc_dmaman_chan_alloc(dmaman, required_feature_set);
  345. + if (chan < 0)
  346. + goto out;
  347. +
  348. + r = platform_get_resource(pdev, IORESOURCE_IRQ, (unsigned int)chan);
  349. + if (!r) {
  350. + dev_err(dmaman_dev, "failed to get irq for DMA channel %d\n",
  351. + chan);
  352. + vc_dmaman_chan_free(dmaman, chan);
  353. + chan = -ENOENT;
  354. + goto out;
  355. + }
  356. +
  357. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base, chan);
  358. + *out_dma_irq = r->start;
  359. + dev_dbg(dmaman_dev,
  360. + "Legacy API allocated channel=%d, base=%p, irq=%i\n",
  361. + chan, *out_dma_base, *out_dma_irq);
  362. +
  363. +out:
  364. + mutex_unlock(&dmaman->lock);
  365. +
  366. + return chan;
  367. +}
  368. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  369. +
  370. +extern int bcm_dma_chan_free(int channel)
  371. +{
  372. + struct vc_dmaman *dmaman = g_dmaman;
  373. + int rc;
  374. +
  375. + if (!dmaman_dev)
  376. + return -ENODEV;
  377. +
  378. + mutex_lock(&dmaman->lock);
  379. + rc = vc_dmaman_chan_free(dmaman, channel);
  380. + mutex_unlock(&dmaman->lock);
  381. +
  382. + return rc;
  383. +}
  384. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  385. +
  386. +int bcm_dmaman_probe(struct platform_device *pdev, void __iomem *base,
  387. + u32 chans_available)
  388. +{
  389. + struct device *dev = &pdev->dev;
  390. + struct vc_dmaman *dmaman;
  391. +
  392. + dmaman = devm_kzalloc(dev, sizeof(*dmaman), GFP_KERNEL);
  393. + if (!dmaman)
  394. + return -ENOMEM;
  395. +
  396. + mutex_init(&dmaman->lock);
  397. + vc_dmaman_init(dmaman, base, chans_available);
  398. + g_dmaman = dmaman;
  399. + dmaman_dev = dev;
  400. +
  401. + dev_info(dev, "DMA legacy API manager at %p, dmachans=0x%x\n",
  402. + base, chans_available);
  403. +
  404. + return 0;
  405. +}
  406. +EXPORT_SYMBOL(bcm_dmaman_probe);
  407. +
  408. +int bcm_dmaman_remove(struct platform_device *pdev)
  409. +{
  410. + dmaman_dev = NULL;
  411. +
  412. + return 0;
  413. +}
  414. +EXPORT_SYMBOL(bcm_dmaman_remove);
  415. +
  416. +MODULE_LICENSE("GPL");
  417. --- /dev/null
  418. +++ b/include/linux/platform_data/dma-bcm2708.h
  419. @@ -0,0 +1,143 @@
  420. +/*
  421. + * Copyright (C) 2010 Broadcom
  422. + *
  423. + * This program is free software; you can redistribute it and/or modify
  424. + * it under the terms of the GNU General Public License version 2 as
  425. + * published by the Free Software Foundation.
  426. + */
  427. +
  428. +#ifndef _PLAT_BCM2708_DMA_H
  429. +#define _PLAT_BCM2708_DMA_H
  430. +
  431. +/* DMA CS Control and Status bits */
  432. +#define BCM2708_DMA_ACTIVE BIT(0)
  433. +#define BCM2708_DMA_INT BIT(2)
  434. +#define BCM2708_DMA_ISPAUSED BIT(4) /* Pause requested or not active */
  435. +#define BCM2708_DMA_ISHELD BIT(5) /* Is held by DREQ flow control */
  436. +#define BCM2708_DMA_ERR BIT(8)
  437. +#define BCM2708_DMA_ABORT BIT(30) /* stop current CB, go to next, WO */
  438. +#define BCM2708_DMA_RESET BIT(31) /* WO, self clearing */
  439. +
  440. +/* DMA control block "info" field bits */
  441. +#define BCM2708_DMA_INT_EN BIT(0)
  442. +#define BCM2708_DMA_TDMODE BIT(1)
  443. +#define BCM2708_DMA_WAIT_RESP BIT(3)
  444. +#define BCM2708_DMA_D_INC BIT(4)
  445. +#define BCM2708_DMA_D_WIDTH BIT(5)
  446. +#define BCM2708_DMA_D_DREQ BIT(6)
  447. +#define BCM2708_DMA_S_INC BIT(8)
  448. +#define BCM2708_DMA_S_WIDTH BIT(9)
  449. +#define BCM2708_DMA_S_DREQ BIT(10)
  450. +
  451. +#define BCM2708_DMA_BURST(x) (((x) & 0xf) << 12)
  452. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  453. +#define BCM2708_DMA_WAITS(x) (((x) & 0x1f) << 21)
  454. +
  455. +#define BCM2708_DMA_DREQ_EMMC 11
  456. +#define BCM2708_DMA_DREQ_SDHOST 13
  457. +
  458. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  459. +#define BCM2708_DMA_ADDR 0x04
  460. +/* the current control block appears in the following registers - read only */
  461. +#define BCM2708_DMA_INFO 0x08
  462. +#define BCM2708_DMA_SOURCE_AD 0x0c
  463. +#define BCM2708_DMA_DEST_AD 0x10
  464. +#define BCM2708_DMA_NEXTCB 0x1C
  465. +#define BCM2708_DMA_DEBUG 0x20
  466. +
  467. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4) + BCM2708_DMA_CS)
  468. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4) + BCM2708_DMA_ADDR)
  469. +
  470. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  471. +
  472. +/* When listing features we can ask for when allocating DMA channels give
  473. + those with higher priority smaller ordinal numbers */
  474. +#define BCM_DMA_FEATURE_FAST_ORD 0
  475. +#define BCM_DMA_FEATURE_BULK_ORD 1
  476. +#define BCM_DMA_FEATURE_NORMAL_ORD 2
  477. +#define BCM_DMA_FEATURE_LITE_ORD 3
  478. +#define BCM_DMA_FEATURE_FAST BIT(BCM_DMA_FEATURE_FAST_ORD)
  479. +#define BCM_DMA_FEATURE_BULK BIT(BCM_DMA_FEATURE_BULK_ORD)
  480. +#define BCM_DMA_FEATURE_NORMAL BIT(BCM_DMA_FEATURE_NORMAL_ORD)
  481. +#define BCM_DMA_FEATURE_LITE BIT(BCM_DMA_FEATURE_LITE_ORD)
  482. +#define BCM_DMA_FEATURE_COUNT 4
  483. +
  484. +struct bcm2708_dma_cb {
  485. + unsigned long info;
  486. + unsigned long src;
  487. + unsigned long dst;
  488. + unsigned long length;
  489. + unsigned long stride;
  490. + unsigned long next;
  491. + unsigned long pad[2];
  492. +};
  493. +
  494. +struct scatterlist;
  495. +struct platform_device;
  496. +
  497. +#ifdef CONFIG_DMA_BCM2708
  498. +
  499. +int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  500. +void bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block);
  501. +void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  502. +bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  503. +int bcm_dma_abort(void __iomem *dma_chan_base);
  504. +
  505. +/* return channel no or -ve error */
  506. +int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  507. + void __iomem **out_dma_base, int *out_dma_irq);
  508. +int bcm_dma_chan_free(int channel);
  509. +
  510. +int bcm_dmaman_probe(struct platform_device *pdev, void __iomem *base,
  511. + u32 chans_available);
  512. +int bcm_dmaman_remove(struct platform_device *pdev);
  513. +
  514. +#else /* CONFIG_DMA_BCM2708 */
  515. +
  516. +static inline int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr,
  517. + int sg_len)
  518. +{
  519. + return 0;
  520. +}
  521. +
  522. +static inline void bcm_dma_start(void __iomem *dma_chan_base,
  523. + dma_addr_t control_block) { }
  524. +
  525. +static inline void bcm_dma_wait_idle(void __iomem *dma_chan_base) { }
  526. +
  527. +static inline bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  528. +{
  529. + return false;
  530. +}
  531. +
  532. +static inline int bcm_dma_abort(void __iomem *dma_chan_base)
  533. +{
  534. + return -EINVAL;
  535. +}
  536. +
  537. +static inline int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  538. + void __iomem **out_dma_base,
  539. + int *out_dma_irq)
  540. +{
  541. + return -EINVAL;
  542. +}
  543. +
  544. +static inline int bcm_dma_chan_free(int channel)
  545. +{
  546. + return -EINVAL;
  547. +}
  548. +
  549. +static inline int bcm_dmaman_probe(struct platform_device *pdev,
  550. + void __iomem *base, u32 chans_available)
  551. +{
  552. + return 0;
  553. +}
  554. +
  555. +static inline int bcm_dmaman_remove(struct platform_device *pdev)
  556. +{
  557. + return 0;
  558. +}
  559. +
  560. +#endif /* CONFIG_DMA_BCM2708 */
  561. +
  562. +#endif /* _PLAT_BCM2708_DMA_H */