0391-Revert-dmaengine-bcm2835-Add-slave-dma-support.patch 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. From 31f3ee328b2a471999acca527e3a83d6af3c75d9 Mon Sep 17 00:00:00 2001
  2. From: Martin Sperl <kernel@martin.sperl.org>
  3. Date: Fri, 22 Apr 2016 17:17:37 +0000
  4. Subject: [PATCH] Revert "dmaengine: bcm2835: Add slave dma support"
  5. This reverts commit 8a349301238aabb40c9da5ca8c8492b6b8d146f6.
  6. ---
  7. drivers/dma/bcm2835-dma.c | 206 ++++------------------------------------------
  8. 1 file changed, 14 insertions(+), 192 deletions(-)
  9. --- a/drivers/dma/bcm2835-dma.c
  10. +++ b/drivers/dma/bcm2835-dma.c
  11. @@ -1,10 +1,11 @@
  12. /*
  13. * BCM2835 DMA engine support
  14. *
  15. + * This driver only supports cyclic DMA transfers
  16. + * as needed for the I2S module.
  17. + *
  18. * Author: Florian Meier <florian.meier@koalo.de>
  19. * Copyright 2013
  20. - * Gellert Weisz <gellert@raspberrypi.org>
  21. - * Copyright 2013-2014
  22. *
  23. * Based on
  24. * OMAP DMAengine support by Russell King
  25. @@ -94,8 +95,6 @@ struct bcm2835_desc {
  26. size_t size;
  27. };
  28. -#define BCM2835_DMA_WAIT_CYCLES 0 /* Slow down DMA transfers: 0-31 */
  29. -
  30. #define BCM2835_DMA_CS 0x00
  31. #define BCM2835_DMA_ADDR 0x04
  32. #define BCM2835_DMA_SOURCE_AD 0x0c
  33. @@ -112,16 +111,12 @@ struct bcm2835_desc {
  34. #define BCM2835_DMA_RESET BIT(31) /* WO, self clearing */
  35. #define BCM2835_DMA_INT_EN BIT(0)
  36. -#define BCM2835_DMA_WAIT_RESP BIT(3)
  37. #define BCM2835_DMA_D_INC BIT(4)
  38. -#define BCM2835_DMA_D_WIDTH BIT(5)
  39. #define BCM2835_DMA_D_DREQ BIT(6)
  40. #define BCM2835_DMA_S_INC BIT(8)
  41. -#define BCM2835_DMA_S_WIDTH BIT(9)
  42. #define BCM2835_DMA_S_DREQ BIT(10)
  43. #define BCM2835_DMA_PER_MAP(x) ((x) << 16)
  44. -#define BCM2835_DMA_WAITS(x) (((x) & 0x1f) << 21)
  45. #define BCM2835_DMA_DATA_TYPE_S8 1
  46. #define BCM2835_DMA_DATA_TYPE_S16 2
  47. @@ -135,14 +130,6 @@ struct bcm2835_desc {
  48. #define BCM2835_DMA_CHAN(n) ((n) << 8) /* Base address */
  49. #define BCM2835_DMA_CHANIO(base, n) ((base) + BCM2835_DMA_CHAN(n))
  50. -#define MAX_NORMAL_TRANSFER SZ_1G
  51. -/*
  52. - * Max length on a Lite channel is 65535 bytes.
  53. - * DMA handles byte-enables on SDRAM reads and writes even on 128-bit accesses,
  54. - * but byte-enables don't exist on peripheral addresses, so align to 32-bit.
  55. - */
  56. -#define MAX_LITE_TRANSFER (SZ_64K - 4)
  57. -
  58. static inline struct bcm2835_dmadev *to_bcm2835_dma_dev(struct dma_device *d)
  59. {
  60. return container_of(d, struct bcm2835_dmadev, ddev);
  61. @@ -239,19 +226,13 @@ static irqreturn_t bcm2835_dma_callback(
  62. d = c->desc;
  63. if (d) {
  64. - if (c->cyclic) {
  65. - vchan_cyclic_callback(&d->vd);
  66. -
  67. - /* Keep the DMA engine running */
  68. - writel(BCM2835_DMA_ACTIVE,
  69. - c->chan_base + BCM2835_DMA_CS);
  70. -
  71. - } else {
  72. - vchan_cookie_complete(&c->desc->vd);
  73. - bcm2835_dma_start_desc(c);
  74. - }
  75. + /* TODO Only works for cyclic DMA */
  76. + vchan_cyclic_callback(&d->vd);
  77. }
  78. + /* Keep the DMA engine running */
  79. + writel(BCM2835_DMA_ACTIVE, c->chan_base + BCM2835_DMA_CS);
  80. +
  81. spin_unlock_irqrestore(&c->vc.lock, flags);
  82. return IRQ_HANDLED;
  83. @@ -358,6 +339,8 @@ static void bcm2835_dma_issue_pending(st
  84. struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  85. unsigned long flags;
  86. + c->cyclic = true; /* Nothing else is implemented */
  87. +
  88. spin_lock_irqsave(&c->vc.lock, flags);
  89. if (vchan_issue_pending(&c->vc) && !c->desc)
  90. bcm2835_dma_start_desc(c);
  91. @@ -375,7 +358,7 @@ static struct dma_async_tx_descriptor *b
  92. struct bcm2835_desc *d;
  93. dma_addr_t dev_addr;
  94. unsigned int es, sync_type;
  95. - unsigned int frame, max_size;
  96. + unsigned int frame;
  97. int i;
  98. /* Grab configuration */
  99. @@ -410,12 +393,7 @@ static struct dma_async_tx_descriptor *b
  100. d->c = c;
  101. d->dir = direction;
  102. - if (c->ch >= 8) /* LITE channel */
  103. - max_size = MAX_LITE_TRANSFER;
  104. - else
  105. - max_size = MAX_NORMAL_TRANSFER;
  106. - period_len = min(period_len, max_size);
  107. - d->frames = (buf_len - 1) / (period_len + 1);
  108. + d->frames = buf_len / period_len;
  109. d->cb_list = kcalloc(d->frames, sizeof(*d->cb_list), GFP_KERNEL);
  110. if (!d->cb_list) {
  111. @@ -463,171 +441,17 @@ static struct dma_async_tx_descriptor *b
  112. BCM2835_DMA_PER_MAP(c->dreq);
  113. /* Length of a frame */
  114. - if (frame != d->frames - 1)
  115. - control_block->length = period_len;
  116. - else
  117. - control_block->length = buf_len - (d->frames - 1) *
  118. - period_len;
  119. + control_block->length = period_len;
  120. d->size += control_block->length;
  121. /*
  122. * Next block is the next frame.
  123. - * This function is called on cyclic DMA transfers.
  124. + * This DMA engine driver currently only supports cyclic DMA.
  125. * Therefore, wrap around at number of frames.
  126. */
  127. control_block->next = d->cb_list[((frame + 1) % d->frames)].paddr;
  128. }
  129. - c->cyclic = true;
  130. -
  131. - return vchan_tx_prep(&c->vc, &d->vd, flags);
  132. -}
  133. -
  134. -static struct dma_async_tx_descriptor *
  135. -bcm2835_dma_prep_slave_sg(struct dma_chan *chan,
  136. - struct scatterlist *sgl,
  137. - unsigned int sg_len,
  138. - enum dma_transfer_direction direction,
  139. - unsigned long flags, void *context)
  140. -{
  141. - struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  142. - enum dma_slave_buswidth dev_width;
  143. - struct bcm2835_desc *d;
  144. - dma_addr_t dev_addr;
  145. - struct scatterlist *sgent;
  146. - unsigned int i, sync_type, split_cnt, max_size;
  147. -
  148. - if (!is_slave_direction(direction)) {
  149. - dev_err(chan->device->dev, "direction not supported\n");
  150. - return NULL;
  151. - }
  152. -
  153. - if (direction == DMA_DEV_TO_MEM) {
  154. - dev_addr = c->cfg.src_addr;
  155. - dev_width = c->cfg.src_addr_width;
  156. - sync_type = BCM2835_DMA_S_DREQ;
  157. - } else {
  158. - dev_addr = c->cfg.dst_addr;
  159. - dev_width = c->cfg.dst_addr_width;
  160. - sync_type = BCM2835_DMA_D_DREQ;
  161. - }
  162. -
  163. - /* Bus width translates to the element size (ES) */
  164. - switch (dev_width) {
  165. - case DMA_SLAVE_BUSWIDTH_4_BYTES:
  166. - break;
  167. - default:
  168. - dev_err(chan->device->dev, "buswidth not supported: %i\n",
  169. - dev_width);
  170. - return NULL;
  171. - }
  172. -
  173. - /* Allocate and setup the descriptor. */
  174. - d = kzalloc(sizeof(*d), GFP_NOWAIT);
  175. - if (!d)
  176. - return NULL;
  177. -
  178. - d->dir = direction;
  179. -
  180. - if (c->ch >= 8) /* LITE channel */
  181. - max_size = MAX_LITE_TRANSFER;
  182. - else
  183. - max_size = MAX_NORMAL_TRANSFER;
  184. -
  185. - /*
  186. - * Store the length of the SG list in d->frames
  187. - * taking care to account for splitting up transfers
  188. - * too large for a LITE channel
  189. - */
  190. - d->frames = 0;
  191. - for_each_sg(sgl, sgent, sg_len, i) {
  192. - unsigned int len = sg_dma_len(sgent);
  193. -
  194. - d->frames += len / max_size + 1;
  195. - }
  196. -
  197. - /* Allocate memory for control blocks */
  198. - d->control_block_size = d->frames * sizeof(struct bcm2835_dma_cb);
  199. - d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  200. - d->control_block_size, &d->control_block_base_phys,
  201. - GFP_NOWAIT);
  202. - if (!d->control_block_base) {
  203. - kfree(d);
  204. - return NULL;
  205. - }
  206. -
  207. - /*
  208. - * Iterate over all SG entries, create a control block
  209. - * for each frame and link them together.
  210. - * Count the number of times an SG entry had to be split
  211. - * as a result of using a LITE channel
  212. - */
  213. - split_cnt = 0;
  214. -
  215. - for_each_sg(sgl, sgent, sg_len, i) {
  216. - unsigned int j;
  217. - dma_addr_t addr = sg_dma_address(sgent);
  218. - unsigned int len = sg_dma_len(sgent);
  219. -
  220. - for (j = 0; j < len; j += max_size) {
  221. - struct bcm2835_dma_cb *control_block =
  222. - &d->control_block_base[i + split_cnt];
  223. -
  224. - /* Setup addresses */
  225. - if (d->dir == DMA_DEV_TO_MEM) {
  226. - control_block->info = BCM2835_DMA_D_INC |
  227. - BCM2835_DMA_D_WIDTH |
  228. - BCM2835_DMA_S_DREQ;
  229. - control_block->src = dev_addr;
  230. - control_block->dst = addr + (dma_addr_t)j;
  231. - } else {
  232. - control_block->info = BCM2835_DMA_S_INC |
  233. - BCM2835_DMA_S_WIDTH |
  234. - BCM2835_DMA_D_DREQ;
  235. - control_block->src = addr + (dma_addr_t)j;
  236. - control_block->dst = dev_addr;
  237. - }
  238. -
  239. - /* Common part */
  240. - control_block->info |=
  241. - BCM2835_DMA_WAITS(BCM2835_DMA_WAIT_CYCLES);
  242. - control_block->info |= BCM2835_DMA_WAIT_RESP;
  243. -
  244. - /* Enable */
  245. - if (i == sg_len - 1 && len - j <= max_size)
  246. - control_block->info |= BCM2835_DMA_INT_EN;
  247. -
  248. - /* Setup synchronization */
  249. - if (sync_type)
  250. - control_block->info |= sync_type;
  251. -
  252. - /* Setup DREQ channel */
  253. - if (c->dreq)
  254. - control_block->info |=
  255. - BCM2835_DMA_PER_MAP(c->dreq);
  256. -
  257. - /* Length of a frame */
  258. - control_block->length = min(len - j, max_size);
  259. - d->size += control_block->length;
  260. -
  261. - if (i < sg_len - 1 || len - j > max_size) {
  262. - /* Next block is the next frame. */
  263. - control_block->next =
  264. - d->control_block_base_phys +
  265. - sizeof(struct bcm2835_dma_cb) *
  266. - (i + split_cnt + 1);
  267. - } else {
  268. - /* Next block is empty. */
  269. - control_block->next = 0;
  270. - }
  271. -
  272. - if (len - j > max_size)
  273. - split_cnt++;
  274. - }
  275. - }
  276. -
  277. - c->cyclic = false;
  278. -
  279. return vchan_tx_prep(&c->vc, &d->vd, flags);
  280. error_cb:
  281. i--;
  282. @@ -796,7 +620,6 @@ static int bcm2835_dma_probe(struct plat
  283. od->ddev.device_tx_status = bcm2835_dma_tx_status;
  284. od->ddev.device_issue_pending = bcm2835_dma_issue_pending;
  285. od->ddev.device_prep_dma_cyclic = bcm2835_dma_prep_dma_cyclic;
  286. - od->ddev.device_prep_slave_sg = bcm2835_dma_prep_slave_sg;
  287. od->ddev.device_config = bcm2835_dma_slave_config;
  288. od->ddev.device_terminate_all = bcm2835_dma_terminate_all;
  289. od->ddev.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
  290. @@ -886,5 +709,4 @@ module_platform_driver(bcm2835_dma_drive
  291. MODULE_ALIAS("platform:bcm2835-dma");
  292. MODULE_DESCRIPTION("BCM2835 DMA engine driver");
  293. MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  294. -MODULE_AUTHOR("Gellert Weisz <gellert@raspberrypi.org>");
  295. MODULE_LICENSE("GPL v2");