dma-jz4780.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Ingenic JZ4780 DMA controller
  4. *
  5. * Copyright (c) 2015 Imagination Technologies
  6. * Author: Alex Smith <[email protected]>
  7. */
  8. #include <linux/clk.h>
  9. #include <linux/dmapool.h>
  10. #include <linux/dma-mapping.h>
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/module.h>
  14. #include <linux/of.h>
  15. #include <linux/of_device.h>
  16. #include <linux/of_dma.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/slab.h>
  19. #include "dmaengine.h"
  20. #include "virt-dma.h"
  21. /* Global registers. */
  22. #define JZ_DMA_REG_DMAC 0x00
  23. #define JZ_DMA_REG_DIRQP 0x04
  24. #define JZ_DMA_REG_DDR 0x08
  25. #define JZ_DMA_REG_DDRS 0x0c
  26. #define JZ_DMA_REG_DCKE 0x10
  27. #define JZ_DMA_REG_DCKES 0x14
  28. #define JZ_DMA_REG_DCKEC 0x18
  29. #define JZ_DMA_REG_DMACP 0x1c
  30. #define JZ_DMA_REG_DSIRQP 0x20
  31. #define JZ_DMA_REG_DSIRQM 0x24
  32. #define JZ_DMA_REG_DCIRQP 0x28
  33. #define JZ_DMA_REG_DCIRQM 0x2c
  34. /* Per-channel registers. */
  35. #define JZ_DMA_REG_CHAN(n) (n * 0x20)
  36. #define JZ_DMA_REG_DSA 0x00
  37. #define JZ_DMA_REG_DTA 0x04
  38. #define JZ_DMA_REG_DTC 0x08
  39. #define JZ_DMA_REG_DRT 0x0c
  40. #define JZ_DMA_REG_DCS 0x10
  41. #define JZ_DMA_REG_DCM 0x14
  42. #define JZ_DMA_REG_DDA 0x18
  43. #define JZ_DMA_REG_DSD 0x1c
  44. #define JZ_DMA_DMAC_DMAE BIT(0)
  45. #define JZ_DMA_DMAC_AR BIT(2)
  46. #define JZ_DMA_DMAC_HLT BIT(3)
  47. #define JZ_DMA_DMAC_FAIC BIT(27)
  48. #define JZ_DMA_DMAC_FMSC BIT(31)
  49. #define JZ_DMA_DRT_AUTO 0x8
  50. #define JZ_DMA_DCS_CTE BIT(0)
  51. #define JZ_DMA_DCS_HLT BIT(2)
  52. #define JZ_DMA_DCS_TT BIT(3)
  53. #define JZ_DMA_DCS_AR BIT(4)
  54. #define JZ_DMA_DCS_DES8 BIT(30)
  55. #define JZ_DMA_DCM_LINK BIT(0)
  56. #define JZ_DMA_DCM_TIE BIT(1)
  57. #define JZ_DMA_DCM_STDE BIT(2)
  58. #define JZ_DMA_DCM_TSZ_SHIFT 8
  59. #define JZ_DMA_DCM_TSZ_MASK (0x7 << JZ_DMA_DCM_TSZ_SHIFT)
  60. #define JZ_DMA_DCM_DP_SHIFT 12
  61. #define JZ_DMA_DCM_SP_SHIFT 14
  62. #define JZ_DMA_DCM_DAI BIT(22)
  63. #define JZ_DMA_DCM_SAI BIT(23)
  64. #define JZ_DMA_SIZE_4_BYTE 0x0
  65. #define JZ_DMA_SIZE_1_BYTE 0x1
  66. #define JZ_DMA_SIZE_2_BYTE 0x2
  67. #define JZ_DMA_SIZE_16_BYTE 0x3
  68. #define JZ_DMA_SIZE_32_BYTE 0x4
  69. #define JZ_DMA_SIZE_64_BYTE 0x5
  70. #define JZ_DMA_SIZE_128_BYTE 0x6
  71. #define JZ_DMA_WIDTH_32_BIT 0x0
  72. #define JZ_DMA_WIDTH_8_BIT 0x1
  73. #define JZ_DMA_WIDTH_16_BIT 0x2
  74. #define JZ_DMA_BUSWIDTHS (BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \
  75. BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \
  76. BIT(DMA_SLAVE_BUSWIDTH_4_BYTES))
  77. #define JZ4780_DMA_CTRL_OFFSET 0x1000
  78. /* macros for use with jz4780_dma_soc_data.flags */
  79. #define JZ_SOC_DATA_ALLOW_LEGACY_DT BIT(0)
  80. #define JZ_SOC_DATA_PROGRAMMABLE_DMA BIT(1)
  81. #define JZ_SOC_DATA_PER_CHAN_PM BIT(2)
  82. #define JZ_SOC_DATA_NO_DCKES_DCKEC BIT(3)
  83. #define JZ_SOC_DATA_BREAK_LINKS BIT(4)
  84. /**
  85. * struct jz4780_dma_hwdesc - descriptor structure read by the DMA controller.
  86. * @dcm: value for the DCM (channel command) register
  87. * @dsa: source address
  88. * @dta: target address
  89. * @dtc: transfer count (number of blocks of the transfer size specified in DCM
  90. * to transfer) in the low 24 bits, offset of the next descriptor from the
  91. * descriptor base address in the upper 8 bits.
  92. */
  93. struct jz4780_dma_hwdesc {
  94. u32 dcm;
  95. u32 dsa;
  96. u32 dta;
  97. u32 dtc;
  98. };
  99. /* Size of allocations for hardware descriptor blocks. */
  100. #define JZ_DMA_DESC_BLOCK_SIZE PAGE_SIZE
  101. #define JZ_DMA_MAX_DESC \
  102. (JZ_DMA_DESC_BLOCK_SIZE / sizeof(struct jz4780_dma_hwdesc))
  103. struct jz4780_dma_desc {
  104. struct virt_dma_desc vdesc;
  105. struct jz4780_dma_hwdesc *desc;
  106. dma_addr_t desc_phys;
  107. unsigned int count;
  108. enum dma_transaction_type type;
  109. u32 transfer_type;
  110. u32 status;
  111. };
  112. struct jz4780_dma_chan {
  113. struct virt_dma_chan vchan;
  114. unsigned int id;
  115. struct dma_pool *desc_pool;
  116. u32 transfer_type_tx, transfer_type_rx;
  117. u32 transfer_shift;
  118. struct dma_slave_config config;
  119. struct jz4780_dma_desc *desc;
  120. unsigned int curr_hwdesc;
  121. };
  122. struct jz4780_dma_soc_data {
  123. unsigned int nb_channels;
  124. unsigned int transfer_ord_max;
  125. unsigned long flags;
  126. };
  127. struct jz4780_dma_dev {
  128. struct dma_device dma_device;
  129. void __iomem *chn_base;
  130. void __iomem *ctrl_base;
  131. struct clk *clk;
  132. unsigned int irq;
  133. const struct jz4780_dma_soc_data *soc_data;
  134. u32 chan_reserved;
  135. struct jz4780_dma_chan chan[];
  136. };
  137. struct jz4780_dma_filter_data {
  138. u32 transfer_type_tx, transfer_type_rx;
  139. int channel;
  140. };
  141. static inline struct jz4780_dma_chan *to_jz4780_dma_chan(struct dma_chan *chan)
  142. {
  143. return container_of(chan, struct jz4780_dma_chan, vchan.chan);
  144. }
  145. static inline struct jz4780_dma_desc *to_jz4780_dma_desc(
  146. struct virt_dma_desc *vdesc)
  147. {
  148. return container_of(vdesc, struct jz4780_dma_desc, vdesc);
  149. }
  150. static inline struct jz4780_dma_dev *jz4780_dma_chan_parent(
  151. struct jz4780_dma_chan *jzchan)
  152. {
  153. return container_of(jzchan->vchan.chan.device, struct jz4780_dma_dev,
  154. dma_device);
  155. }
  156. static inline u32 jz4780_dma_chn_readl(struct jz4780_dma_dev *jzdma,
  157. unsigned int chn, unsigned int reg)
  158. {
  159. return readl(jzdma->chn_base + reg + JZ_DMA_REG_CHAN(chn));
  160. }
  161. static inline void jz4780_dma_chn_writel(struct jz4780_dma_dev *jzdma,
  162. unsigned int chn, unsigned int reg, u32 val)
  163. {
  164. writel(val, jzdma->chn_base + reg + JZ_DMA_REG_CHAN(chn));
  165. }
  166. static inline u32 jz4780_dma_ctrl_readl(struct jz4780_dma_dev *jzdma,
  167. unsigned int reg)
  168. {
  169. return readl(jzdma->ctrl_base + reg);
  170. }
  171. static inline void jz4780_dma_ctrl_writel(struct jz4780_dma_dev *jzdma,
  172. unsigned int reg, u32 val)
  173. {
  174. writel(val, jzdma->ctrl_base + reg);
  175. }
  176. static inline void jz4780_dma_chan_enable(struct jz4780_dma_dev *jzdma,
  177. unsigned int chn)
  178. {
  179. if (jzdma->soc_data->flags & JZ_SOC_DATA_PER_CHAN_PM) {
  180. unsigned int reg;
  181. if (jzdma->soc_data->flags & JZ_SOC_DATA_NO_DCKES_DCKEC)
  182. reg = JZ_DMA_REG_DCKE;
  183. else
  184. reg = JZ_DMA_REG_DCKES;
  185. jz4780_dma_ctrl_writel(jzdma, reg, BIT(chn));
  186. }
  187. }
  188. static inline void jz4780_dma_chan_disable(struct jz4780_dma_dev *jzdma,
  189. unsigned int chn)
  190. {
  191. if ((jzdma->soc_data->flags & JZ_SOC_DATA_PER_CHAN_PM) &&
  192. !(jzdma->soc_data->flags & JZ_SOC_DATA_NO_DCKES_DCKEC))
  193. jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DCKEC, BIT(chn));
  194. }
  195. static struct jz4780_dma_desc *
  196. jz4780_dma_desc_alloc(struct jz4780_dma_chan *jzchan, unsigned int count,
  197. enum dma_transaction_type type,
  198. enum dma_transfer_direction direction)
  199. {
  200. struct jz4780_dma_desc *desc;
  201. if (count > JZ_DMA_MAX_DESC)
  202. return NULL;
  203. desc = kzalloc(sizeof(*desc), GFP_NOWAIT);
  204. if (!desc)
  205. return NULL;
  206. desc->desc = dma_pool_alloc(jzchan->desc_pool, GFP_NOWAIT,
  207. &desc->desc_phys);
  208. if (!desc->desc) {
  209. kfree(desc);
  210. return NULL;
  211. }
  212. desc->count = count;
  213. desc->type = type;
  214. if (direction == DMA_DEV_TO_MEM)
  215. desc->transfer_type = jzchan->transfer_type_rx;
  216. else
  217. desc->transfer_type = jzchan->transfer_type_tx;
  218. return desc;
  219. }
  220. static void jz4780_dma_desc_free(struct virt_dma_desc *vdesc)
  221. {
  222. struct jz4780_dma_desc *desc = to_jz4780_dma_desc(vdesc);
  223. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(vdesc->tx.chan);
  224. dma_pool_free(jzchan->desc_pool, desc->desc, desc->desc_phys);
  225. kfree(desc);
  226. }
  227. static u32 jz4780_dma_transfer_size(struct jz4780_dma_chan *jzchan,
  228. unsigned long val, u32 *shift)
  229. {
  230. struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan);
  231. int ord = ffs(val) - 1;
  232. /*
  233. * 8 byte transfer sizes unsupported so fall back on 4. If it's larger
  234. * than the maximum, just limit it. It is perfectly safe to fall back
  235. * in this way since we won't exceed the maximum burst size supported
  236. * by the device, the only effect is reduced efficiency. This is better
  237. * than refusing to perform the request at all.
  238. */
  239. if (ord == 3)
  240. ord = 2;
  241. else if (ord > jzdma->soc_data->transfer_ord_max)
  242. ord = jzdma->soc_data->transfer_ord_max;
  243. *shift = ord;
  244. switch (ord) {
  245. case 0:
  246. return JZ_DMA_SIZE_1_BYTE;
  247. case 1:
  248. return JZ_DMA_SIZE_2_BYTE;
  249. case 2:
  250. return JZ_DMA_SIZE_4_BYTE;
  251. case 4:
  252. return JZ_DMA_SIZE_16_BYTE;
  253. case 5:
  254. return JZ_DMA_SIZE_32_BYTE;
  255. case 6:
  256. return JZ_DMA_SIZE_64_BYTE;
  257. default:
  258. return JZ_DMA_SIZE_128_BYTE;
  259. }
  260. }
  261. static int jz4780_dma_setup_hwdesc(struct jz4780_dma_chan *jzchan,
  262. struct jz4780_dma_hwdesc *desc, dma_addr_t addr, size_t len,
  263. enum dma_transfer_direction direction)
  264. {
  265. struct dma_slave_config *config = &jzchan->config;
  266. u32 width, maxburst, tsz;
  267. if (direction == DMA_MEM_TO_DEV) {
  268. desc->dcm = JZ_DMA_DCM_SAI;
  269. desc->dsa = addr;
  270. desc->dta = config->dst_addr;
  271. width = config->dst_addr_width;
  272. maxburst = config->dst_maxburst;
  273. } else {
  274. desc->dcm = JZ_DMA_DCM_DAI;
  275. desc->dsa = config->src_addr;
  276. desc->dta = addr;
  277. width = config->src_addr_width;
  278. maxburst = config->src_maxburst;
  279. }
  280. /*
  281. * This calculates the maximum transfer size that can be used with the
  282. * given address, length, width and maximum burst size. The address
  283. * must be aligned to the transfer size, the total length must be
  284. * divisible by the transfer size, and we must not use more than the
  285. * maximum burst specified by the user.
  286. */
  287. tsz = jz4780_dma_transfer_size(jzchan, addr | len | (width * maxburst),
  288. &jzchan->transfer_shift);
  289. switch (width) {
  290. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  291. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  292. break;
  293. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  294. width = JZ_DMA_WIDTH_32_BIT;
  295. break;
  296. default:
  297. return -EINVAL;
  298. }
  299. desc->dcm |= tsz << JZ_DMA_DCM_TSZ_SHIFT;
  300. desc->dcm |= width << JZ_DMA_DCM_SP_SHIFT;
  301. desc->dcm |= width << JZ_DMA_DCM_DP_SHIFT;
  302. desc->dtc = len >> jzchan->transfer_shift;
  303. return 0;
  304. }
  305. static struct dma_async_tx_descriptor *jz4780_dma_prep_slave_sg(
  306. struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len,
  307. enum dma_transfer_direction direction, unsigned long flags,
  308. void *context)
  309. {
  310. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan);
  311. struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan);
  312. struct jz4780_dma_desc *desc;
  313. unsigned int i;
  314. int err;
  315. desc = jz4780_dma_desc_alloc(jzchan, sg_len, DMA_SLAVE, direction);
  316. if (!desc)
  317. return NULL;
  318. for (i = 0; i < sg_len; i++) {
  319. err = jz4780_dma_setup_hwdesc(jzchan, &desc->desc[i],
  320. sg_dma_address(&sgl[i]),
  321. sg_dma_len(&sgl[i]),
  322. direction);
  323. if (err < 0) {
  324. jz4780_dma_desc_free(&jzchan->desc->vdesc);
  325. return NULL;
  326. }
  327. desc->desc[i].dcm |= JZ_DMA_DCM_TIE;
  328. if (i != (sg_len - 1) &&
  329. !(jzdma->soc_data->flags & JZ_SOC_DATA_BREAK_LINKS)) {
  330. /* Automatically proceed to the next descriptor. */
  331. desc->desc[i].dcm |= JZ_DMA_DCM_LINK;
  332. /*
  333. * The upper 8 bits of the DTC field in the descriptor
  334. * must be set to (offset from descriptor base of next
  335. * descriptor >> 4).
  336. */
  337. desc->desc[i].dtc |=
  338. (((i + 1) * sizeof(*desc->desc)) >> 4) << 24;
  339. }
  340. }
  341. return vchan_tx_prep(&jzchan->vchan, &desc->vdesc, flags);
  342. }
  343. static struct dma_async_tx_descriptor *jz4780_dma_prep_dma_cyclic(
  344. struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  345. size_t period_len, enum dma_transfer_direction direction,
  346. unsigned long flags)
  347. {
  348. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan);
  349. struct jz4780_dma_desc *desc;
  350. unsigned int periods, i;
  351. int err;
  352. if (buf_len % period_len)
  353. return NULL;
  354. periods = buf_len / period_len;
  355. desc = jz4780_dma_desc_alloc(jzchan, periods, DMA_CYCLIC, direction);
  356. if (!desc)
  357. return NULL;
  358. for (i = 0; i < periods; i++) {
  359. err = jz4780_dma_setup_hwdesc(jzchan, &desc->desc[i], buf_addr,
  360. period_len, direction);
  361. if (err < 0) {
  362. jz4780_dma_desc_free(&jzchan->desc->vdesc);
  363. return NULL;
  364. }
  365. buf_addr += period_len;
  366. /*
  367. * Set the link bit to indicate that the controller should
  368. * automatically proceed to the next descriptor. In
  369. * jz4780_dma_begin(), this will be cleared if we need to issue
  370. * an interrupt after each period.
  371. */
  372. desc->desc[i].dcm |= JZ_DMA_DCM_TIE | JZ_DMA_DCM_LINK;
  373. /*
  374. * The upper 8 bits of the DTC field in the descriptor must be
  375. * set to (offset from descriptor base of next descriptor >> 4).
  376. * If this is the last descriptor, link it back to the first,
  377. * i.e. leave offset set to 0, otherwise point to the next one.
  378. */
  379. if (i != (periods - 1)) {
  380. desc->desc[i].dtc |=
  381. (((i + 1) * sizeof(*desc->desc)) >> 4) << 24;
  382. }
  383. }
  384. return vchan_tx_prep(&jzchan->vchan, &desc->vdesc, flags);
  385. }
  386. static struct dma_async_tx_descriptor *jz4780_dma_prep_dma_memcpy(
  387. struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
  388. size_t len, unsigned long flags)
  389. {
  390. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan);
  391. struct jz4780_dma_desc *desc;
  392. u32 tsz;
  393. desc = jz4780_dma_desc_alloc(jzchan, 1, DMA_MEMCPY, 0);
  394. if (!desc)
  395. return NULL;
  396. tsz = jz4780_dma_transfer_size(jzchan, dest | src | len,
  397. &jzchan->transfer_shift);
  398. desc->transfer_type = JZ_DMA_DRT_AUTO;
  399. desc->desc[0].dsa = src;
  400. desc->desc[0].dta = dest;
  401. desc->desc[0].dcm = JZ_DMA_DCM_TIE | JZ_DMA_DCM_SAI | JZ_DMA_DCM_DAI |
  402. tsz << JZ_DMA_DCM_TSZ_SHIFT |
  403. JZ_DMA_WIDTH_32_BIT << JZ_DMA_DCM_SP_SHIFT |
  404. JZ_DMA_WIDTH_32_BIT << JZ_DMA_DCM_DP_SHIFT;
  405. desc->desc[0].dtc = len >> jzchan->transfer_shift;
  406. return vchan_tx_prep(&jzchan->vchan, &desc->vdesc, flags);
  407. }
  408. static void jz4780_dma_begin(struct jz4780_dma_chan *jzchan)
  409. {
  410. struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan);
  411. struct virt_dma_desc *vdesc;
  412. unsigned int i;
  413. dma_addr_t desc_phys;
  414. if (!jzchan->desc) {
  415. vdesc = vchan_next_desc(&jzchan->vchan);
  416. if (!vdesc)
  417. return;
  418. list_del(&vdesc->node);
  419. jzchan->desc = to_jz4780_dma_desc(vdesc);
  420. jzchan->curr_hwdesc = 0;
  421. if (jzchan->desc->type == DMA_CYCLIC && vdesc->tx.callback) {
  422. /*
  423. * The DMA controller doesn't support triggering an
  424. * interrupt after processing each descriptor, only
  425. * after processing an entire terminated list of
  426. * descriptors. For a cyclic DMA setup the list of
  427. * descriptors is not terminated so we can never get an
  428. * interrupt.
  429. *
  430. * If the user requested a callback for a cyclic DMA
  431. * setup then we workaround this hardware limitation
  432. * here by degrading to a set of unlinked descriptors
  433. * which we will submit in sequence in response to the
  434. * completion of processing the previous descriptor.
  435. */
  436. for (i = 0; i < jzchan->desc->count; i++)
  437. jzchan->desc->desc[i].dcm &= ~JZ_DMA_DCM_LINK;
  438. }
  439. } else {
  440. /*
  441. * There is an existing transfer, therefore this must be one
  442. * for which we unlinked the descriptors above. Advance to the
  443. * next one in the list.
  444. */
  445. jzchan->curr_hwdesc =
  446. (jzchan->curr_hwdesc + 1) % jzchan->desc->count;
  447. }
  448. /* Enable the channel's clock. */
  449. jz4780_dma_chan_enable(jzdma, jzchan->id);
  450. /* Use 4-word descriptors. */
  451. jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DCS, 0);
  452. /* Set transfer type. */
  453. jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DRT,
  454. jzchan->desc->transfer_type);
  455. /*
  456. * Set the transfer count. This is redundant for a descriptor-driven
  457. * transfer. However, there can be a delay between the transfer start
  458. * time and when DTCn reg contains the new transfer count. Setting
  459. * it explicitly ensures residue is computed correctly at all times.
  460. */
  461. jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DTC,
  462. jzchan->desc->desc[jzchan->curr_hwdesc].dtc);
  463. /* Write descriptor address and initiate descriptor fetch. */
  464. desc_phys = jzchan->desc->desc_phys +
  465. (jzchan->curr_hwdesc * sizeof(*jzchan->desc->desc));
  466. jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DDA, desc_phys);
  467. jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DDRS, BIT(jzchan->id));
  468. /* Enable the channel. */
  469. jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DCS,
  470. JZ_DMA_DCS_CTE);
  471. }
  472. static void jz4780_dma_issue_pending(struct dma_chan *chan)
  473. {
  474. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan);
  475. unsigned long flags;
  476. spin_lock_irqsave(&jzchan->vchan.lock, flags);
  477. if (vchan_issue_pending(&jzchan->vchan) && !jzchan->desc)
  478. jz4780_dma_begin(jzchan);
  479. spin_unlock_irqrestore(&jzchan->vchan.lock, flags);
  480. }
  481. static int jz4780_dma_terminate_all(struct dma_chan *chan)
  482. {
  483. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan);
  484. struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan);
  485. unsigned long flags;
  486. LIST_HEAD(head);
  487. spin_lock_irqsave(&jzchan->vchan.lock, flags);
  488. /* Clear the DMA status and stop the transfer. */
  489. jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DCS, 0);
  490. if (jzchan->desc) {
  491. vchan_terminate_vdesc(&jzchan->desc->vdesc);
  492. jzchan->desc = NULL;
  493. }
  494. jz4780_dma_chan_disable(jzdma, jzchan->id);
  495. vchan_get_all_descriptors(&jzchan->vchan, &head);
  496. spin_unlock_irqrestore(&jzchan->vchan.lock, flags);
  497. vchan_dma_desc_free_list(&jzchan->vchan, &head);
  498. return 0;
  499. }
  500. static void jz4780_dma_synchronize(struct dma_chan *chan)
  501. {
  502. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan);
  503. struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan);
  504. vchan_synchronize(&jzchan->vchan);
  505. jz4780_dma_chan_disable(jzdma, jzchan->id);
  506. }
  507. static int jz4780_dma_config(struct dma_chan *chan,
  508. struct dma_slave_config *config)
  509. {
  510. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan);
  511. if ((config->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES)
  512. || (config->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES))
  513. return -EINVAL;
  514. /* Copy the reset of the slave configuration, it is used later. */
  515. memcpy(&jzchan->config, config, sizeof(jzchan->config));
  516. return 0;
  517. }
  518. static size_t jz4780_dma_desc_residue(struct jz4780_dma_chan *jzchan,
  519. struct jz4780_dma_desc *desc, unsigned int next_sg)
  520. {
  521. struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan);
  522. unsigned int count = 0;
  523. unsigned int i;
  524. for (i = next_sg; i < desc->count; i++)
  525. count += desc->desc[i].dtc & GENMASK(23, 0);
  526. if (next_sg != 0)
  527. count += jz4780_dma_chn_readl(jzdma, jzchan->id,
  528. JZ_DMA_REG_DTC);
  529. return count << jzchan->transfer_shift;
  530. }
  531. static enum dma_status jz4780_dma_tx_status(struct dma_chan *chan,
  532. dma_cookie_t cookie, struct dma_tx_state *txstate)
  533. {
  534. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan);
  535. struct virt_dma_desc *vdesc;
  536. enum dma_status status;
  537. unsigned long flags;
  538. unsigned long residue = 0;
  539. spin_lock_irqsave(&jzchan->vchan.lock, flags);
  540. status = dma_cookie_status(chan, cookie, txstate);
  541. if ((status == DMA_COMPLETE) || (txstate == NULL))
  542. goto out_unlock_irqrestore;
  543. vdesc = vchan_find_desc(&jzchan->vchan, cookie);
  544. if (vdesc) {
  545. /* On the issued list, so hasn't been processed yet */
  546. residue = jz4780_dma_desc_residue(jzchan,
  547. to_jz4780_dma_desc(vdesc), 0);
  548. } else if (cookie == jzchan->desc->vdesc.tx.cookie) {
  549. residue = jz4780_dma_desc_residue(jzchan, jzchan->desc,
  550. jzchan->curr_hwdesc + 1);
  551. }
  552. dma_set_residue(txstate, residue);
  553. if (vdesc && jzchan->desc && vdesc == &jzchan->desc->vdesc
  554. && jzchan->desc->status & (JZ_DMA_DCS_AR | JZ_DMA_DCS_HLT))
  555. status = DMA_ERROR;
  556. out_unlock_irqrestore:
  557. spin_unlock_irqrestore(&jzchan->vchan.lock, flags);
  558. return status;
  559. }
  560. static bool jz4780_dma_chan_irq(struct jz4780_dma_dev *jzdma,
  561. struct jz4780_dma_chan *jzchan)
  562. {
  563. const unsigned int soc_flags = jzdma->soc_data->flags;
  564. struct jz4780_dma_desc *desc = jzchan->desc;
  565. u32 dcs;
  566. bool ack = true;
  567. spin_lock(&jzchan->vchan.lock);
  568. dcs = jz4780_dma_chn_readl(jzdma, jzchan->id, JZ_DMA_REG_DCS);
  569. jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DCS, 0);
  570. if (dcs & JZ_DMA_DCS_AR) {
  571. dev_warn(&jzchan->vchan.chan.dev->device,
  572. "address error (DCS=0x%x)\n", dcs);
  573. }
  574. if (dcs & JZ_DMA_DCS_HLT) {
  575. dev_warn(&jzchan->vchan.chan.dev->device,
  576. "channel halt (DCS=0x%x)\n", dcs);
  577. }
  578. if (jzchan->desc) {
  579. jzchan->desc->status = dcs;
  580. if ((dcs & (JZ_DMA_DCS_AR | JZ_DMA_DCS_HLT)) == 0) {
  581. if (jzchan->desc->type == DMA_CYCLIC) {
  582. vchan_cyclic_callback(&jzchan->desc->vdesc);
  583. jz4780_dma_begin(jzchan);
  584. } else if (dcs & JZ_DMA_DCS_TT) {
  585. if (!(soc_flags & JZ_SOC_DATA_BREAK_LINKS) ||
  586. (jzchan->curr_hwdesc + 1 == desc->count)) {
  587. vchan_cookie_complete(&desc->vdesc);
  588. jzchan->desc = NULL;
  589. }
  590. jz4780_dma_begin(jzchan);
  591. } else {
  592. /* False positive - continue the transfer */
  593. ack = false;
  594. jz4780_dma_chn_writel(jzdma, jzchan->id,
  595. JZ_DMA_REG_DCS,
  596. JZ_DMA_DCS_CTE);
  597. }
  598. }
  599. } else {
  600. dev_err(&jzchan->vchan.chan.dev->device,
  601. "channel IRQ with no active transfer\n");
  602. }
  603. spin_unlock(&jzchan->vchan.lock);
  604. return ack;
  605. }
  606. static irqreturn_t jz4780_dma_irq_handler(int irq, void *data)
  607. {
  608. struct jz4780_dma_dev *jzdma = data;
  609. unsigned int nb_channels = jzdma->soc_data->nb_channels;
  610. unsigned long pending;
  611. u32 dmac;
  612. int i;
  613. pending = jz4780_dma_ctrl_readl(jzdma, JZ_DMA_REG_DIRQP);
  614. for_each_set_bit(i, &pending, nb_channels) {
  615. if (jz4780_dma_chan_irq(jzdma, &jzdma->chan[i]))
  616. pending &= ~BIT(i);
  617. }
  618. /* Clear halt and address error status of all channels. */
  619. dmac = jz4780_dma_ctrl_readl(jzdma, JZ_DMA_REG_DMAC);
  620. dmac &= ~(JZ_DMA_DMAC_HLT | JZ_DMA_DMAC_AR);
  621. jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DMAC, dmac);
  622. /* Clear interrupt pending status. */
  623. jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DIRQP, pending);
  624. return IRQ_HANDLED;
  625. }
  626. static int jz4780_dma_alloc_chan_resources(struct dma_chan *chan)
  627. {
  628. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan);
  629. jzchan->desc_pool = dma_pool_create(dev_name(&chan->dev->device),
  630. chan->device->dev,
  631. JZ_DMA_DESC_BLOCK_SIZE,
  632. PAGE_SIZE, 0);
  633. if (!jzchan->desc_pool) {
  634. dev_err(&chan->dev->device,
  635. "failed to allocate descriptor pool\n");
  636. return -ENOMEM;
  637. }
  638. return 0;
  639. }
  640. static void jz4780_dma_free_chan_resources(struct dma_chan *chan)
  641. {
  642. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan);
  643. vchan_free_chan_resources(&jzchan->vchan);
  644. dma_pool_destroy(jzchan->desc_pool);
  645. jzchan->desc_pool = NULL;
  646. }
  647. static bool jz4780_dma_filter_fn(struct dma_chan *chan, void *param)
  648. {
  649. struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan);
  650. struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan);
  651. struct jz4780_dma_filter_data *data = param;
  652. if (data->channel > -1) {
  653. if (data->channel != jzchan->id)
  654. return false;
  655. } else if (jzdma->chan_reserved & BIT(jzchan->id)) {
  656. return false;
  657. }
  658. jzchan->transfer_type_tx = data->transfer_type_tx;
  659. jzchan->transfer_type_rx = data->transfer_type_rx;
  660. return true;
  661. }
  662. static struct dma_chan *jz4780_of_dma_xlate(struct of_phandle_args *dma_spec,
  663. struct of_dma *ofdma)
  664. {
  665. struct jz4780_dma_dev *jzdma = ofdma->of_dma_data;
  666. dma_cap_mask_t mask = jzdma->dma_device.cap_mask;
  667. struct jz4780_dma_filter_data data;
  668. if (dma_spec->args_count == 2) {
  669. data.transfer_type_tx = dma_spec->args[0];
  670. data.transfer_type_rx = dma_spec->args[0];
  671. data.channel = dma_spec->args[1];
  672. } else if (dma_spec->args_count == 3) {
  673. data.transfer_type_tx = dma_spec->args[0];
  674. data.transfer_type_rx = dma_spec->args[1];
  675. data.channel = dma_spec->args[2];
  676. } else {
  677. return NULL;
  678. }
  679. if (data.channel > -1) {
  680. if (data.channel >= jzdma->soc_data->nb_channels) {
  681. dev_err(jzdma->dma_device.dev,
  682. "device requested non-existent channel %u\n",
  683. data.channel);
  684. return NULL;
  685. }
  686. /* Can only select a channel marked as reserved. */
  687. if (!(jzdma->chan_reserved & BIT(data.channel))) {
  688. dev_err(jzdma->dma_device.dev,
  689. "device requested unreserved channel %u\n",
  690. data.channel);
  691. return NULL;
  692. }
  693. jzdma->chan[data.channel].transfer_type_tx = data.transfer_type_tx;
  694. jzdma->chan[data.channel].transfer_type_rx = data.transfer_type_rx;
  695. return dma_get_slave_channel(
  696. &jzdma->chan[data.channel].vchan.chan);
  697. } else {
  698. return __dma_request_channel(&mask, jz4780_dma_filter_fn, &data,
  699. ofdma->of_node);
  700. }
  701. }
  702. static int jz4780_dma_probe(struct platform_device *pdev)
  703. {
  704. struct device *dev = &pdev->dev;
  705. const struct jz4780_dma_soc_data *soc_data;
  706. struct jz4780_dma_dev *jzdma;
  707. struct jz4780_dma_chan *jzchan;
  708. struct dma_device *dd;
  709. struct resource *res;
  710. int i, ret;
  711. if (!dev->of_node) {
  712. dev_err(dev, "This driver must be probed from devicetree\n");
  713. return -EINVAL;
  714. }
  715. soc_data = device_get_match_data(dev);
  716. if (!soc_data)
  717. return -EINVAL;
  718. jzdma = devm_kzalloc(dev, struct_size(jzdma, chan,
  719. soc_data->nb_channels), GFP_KERNEL);
  720. if (!jzdma)
  721. return -ENOMEM;
  722. jzdma->soc_data = soc_data;
  723. platform_set_drvdata(pdev, jzdma);
  724. jzdma->chn_base = devm_platform_ioremap_resource(pdev, 0);
  725. if (IS_ERR(jzdma->chn_base))
  726. return PTR_ERR(jzdma->chn_base);
  727. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  728. if (res) {
  729. jzdma->ctrl_base = devm_ioremap_resource(dev, res);
  730. if (IS_ERR(jzdma->ctrl_base))
  731. return PTR_ERR(jzdma->ctrl_base);
  732. } else if (soc_data->flags & JZ_SOC_DATA_ALLOW_LEGACY_DT) {
  733. /*
  734. * On JZ4780, if the second memory resource was not supplied,
  735. * assume we're using an old devicetree, and calculate the
  736. * offset to the control registers.
  737. */
  738. jzdma->ctrl_base = jzdma->chn_base + JZ4780_DMA_CTRL_OFFSET;
  739. } else {
  740. dev_err(dev, "failed to get I/O memory\n");
  741. return -EINVAL;
  742. }
  743. jzdma->clk = devm_clk_get(dev, NULL);
  744. if (IS_ERR(jzdma->clk)) {
  745. dev_err(dev, "failed to get clock\n");
  746. ret = PTR_ERR(jzdma->clk);
  747. return ret;
  748. }
  749. clk_prepare_enable(jzdma->clk);
  750. /* Property is optional, if it doesn't exist the value will remain 0. */
  751. of_property_read_u32_index(dev->of_node, "ingenic,reserved-channels",
  752. 0, &jzdma->chan_reserved);
  753. dd = &jzdma->dma_device;
  754. /*
  755. * The real segment size limit is dependent on the size unit selected
  756. * for the transfer. Because the size unit is selected automatically
  757. * and may be as small as 1 byte, use a safe limit of 2^24-1 bytes to
  758. * ensure the 24-bit transfer count in the descriptor cannot overflow.
  759. */
  760. dma_set_max_seg_size(dev, 0xffffff);
  761. dma_cap_set(DMA_MEMCPY, dd->cap_mask);
  762. dma_cap_set(DMA_SLAVE, dd->cap_mask);
  763. dma_cap_set(DMA_CYCLIC, dd->cap_mask);
  764. dd->dev = dev;
  765. dd->copy_align = DMAENGINE_ALIGN_4_BYTES;
  766. dd->device_alloc_chan_resources = jz4780_dma_alloc_chan_resources;
  767. dd->device_free_chan_resources = jz4780_dma_free_chan_resources;
  768. dd->device_prep_slave_sg = jz4780_dma_prep_slave_sg;
  769. dd->device_prep_dma_cyclic = jz4780_dma_prep_dma_cyclic;
  770. dd->device_prep_dma_memcpy = jz4780_dma_prep_dma_memcpy;
  771. dd->device_config = jz4780_dma_config;
  772. dd->device_terminate_all = jz4780_dma_terminate_all;
  773. dd->device_synchronize = jz4780_dma_synchronize;
  774. dd->device_tx_status = jz4780_dma_tx_status;
  775. dd->device_issue_pending = jz4780_dma_issue_pending;
  776. dd->src_addr_widths = JZ_DMA_BUSWIDTHS;
  777. dd->dst_addr_widths = JZ_DMA_BUSWIDTHS;
  778. dd->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
  779. dd->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
  780. dd->max_sg_burst = JZ_DMA_MAX_DESC;
  781. /*
  782. * Enable DMA controller, mark all channels as not programmable.
  783. * Also set the FMSC bit - it increases MSC performance, so it makes
  784. * little sense not to enable it.
  785. */
  786. jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DMAC, JZ_DMA_DMAC_DMAE |
  787. JZ_DMA_DMAC_FAIC | JZ_DMA_DMAC_FMSC);
  788. if (soc_data->flags & JZ_SOC_DATA_PROGRAMMABLE_DMA)
  789. jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DMACP, 0);
  790. INIT_LIST_HEAD(&dd->channels);
  791. for (i = 0; i < soc_data->nb_channels; i++) {
  792. jzchan = &jzdma->chan[i];
  793. jzchan->id = i;
  794. vchan_init(&jzchan->vchan, dd);
  795. jzchan->vchan.desc_free = jz4780_dma_desc_free;
  796. }
  797. /*
  798. * On JZ4760, chan0 won't enable properly the first time.
  799. * Enabling then disabling chan1 will magically make chan0 work
  800. * correctly.
  801. */
  802. jz4780_dma_chan_enable(jzdma, 1);
  803. jz4780_dma_chan_disable(jzdma, 1);
  804. ret = platform_get_irq(pdev, 0);
  805. if (ret < 0)
  806. goto err_disable_clk;
  807. jzdma->irq = ret;
  808. ret = request_irq(jzdma->irq, jz4780_dma_irq_handler, 0, dev_name(dev),
  809. jzdma);
  810. if (ret) {
  811. dev_err(dev, "failed to request IRQ %u!\n", jzdma->irq);
  812. goto err_disable_clk;
  813. }
  814. ret = dmaenginem_async_device_register(dd);
  815. if (ret) {
  816. dev_err(dev, "failed to register device\n");
  817. goto err_free_irq;
  818. }
  819. /* Register with OF DMA helpers. */
  820. ret = of_dma_controller_register(dev->of_node, jz4780_of_dma_xlate,
  821. jzdma);
  822. if (ret) {
  823. dev_err(dev, "failed to register OF DMA controller\n");
  824. goto err_free_irq;
  825. }
  826. dev_info(dev, "JZ4780 DMA controller initialised\n");
  827. return 0;
  828. err_free_irq:
  829. free_irq(jzdma->irq, jzdma);
  830. err_disable_clk:
  831. clk_disable_unprepare(jzdma->clk);
  832. return ret;
  833. }
  834. static int jz4780_dma_remove(struct platform_device *pdev)
  835. {
  836. struct jz4780_dma_dev *jzdma = platform_get_drvdata(pdev);
  837. int i;
  838. of_dma_controller_free(pdev->dev.of_node);
  839. clk_disable_unprepare(jzdma->clk);
  840. free_irq(jzdma->irq, jzdma);
  841. for (i = 0; i < jzdma->soc_data->nb_channels; i++)
  842. tasklet_kill(&jzdma->chan[i].vchan.task);
  843. return 0;
  844. }
  845. static const struct jz4780_dma_soc_data jz4740_dma_soc_data = {
  846. .nb_channels = 6,
  847. .transfer_ord_max = 5,
  848. .flags = JZ_SOC_DATA_BREAK_LINKS,
  849. };
  850. static const struct jz4780_dma_soc_data jz4725b_dma_soc_data = {
  851. .nb_channels = 6,
  852. .transfer_ord_max = 5,
  853. .flags = JZ_SOC_DATA_PER_CHAN_PM | JZ_SOC_DATA_NO_DCKES_DCKEC |
  854. JZ_SOC_DATA_BREAK_LINKS,
  855. };
  856. static const struct jz4780_dma_soc_data jz4760_dma_soc_data = {
  857. .nb_channels = 5,
  858. .transfer_ord_max = 6,
  859. .flags = JZ_SOC_DATA_PER_CHAN_PM | JZ_SOC_DATA_NO_DCKES_DCKEC,
  860. };
  861. static const struct jz4780_dma_soc_data jz4760_mdma_soc_data = {
  862. .nb_channels = 2,
  863. .transfer_ord_max = 6,
  864. .flags = JZ_SOC_DATA_PER_CHAN_PM | JZ_SOC_DATA_NO_DCKES_DCKEC,
  865. };
  866. static const struct jz4780_dma_soc_data jz4760_bdma_soc_data = {
  867. .nb_channels = 3,
  868. .transfer_ord_max = 6,
  869. .flags = JZ_SOC_DATA_PER_CHAN_PM | JZ_SOC_DATA_NO_DCKES_DCKEC,
  870. };
  871. static const struct jz4780_dma_soc_data jz4760b_dma_soc_data = {
  872. .nb_channels = 5,
  873. .transfer_ord_max = 6,
  874. .flags = JZ_SOC_DATA_PER_CHAN_PM,
  875. };
  876. static const struct jz4780_dma_soc_data jz4760b_mdma_soc_data = {
  877. .nb_channels = 2,
  878. .transfer_ord_max = 6,
  879. .flags = JZ_SOC_DATA_PER_CHAN_PM,
  880. };
  881. static const struct jz4780_dma_soc_data jz4760b_bdma_soc_data = {
  882. .nb_channels = 3,
  883. .transfer_ord_max = 6,
  884. .flags = JZ_SOC_DATA_PER_CHAN_PM,
  885. };
  886. static const struct jz4780_dma_soc_data jz4770_dma_soc_data = {
  887. .nb_channels = 6,
  888. .transfer_ord_max = 6,
  889. .flags = JZ_SOC_DATA_PER_CHAN_PM,
  890. };
  891. static const struct jz4780_dma_soc_data jz4780_dma_soc_data = {
  892. .nb_channels = 32,
  893. .transfer_ord_max = 7,
  894. .flags = JZ_SOC_DATA_ALLOW_LEGACY_DT | JZ_SOC_DATA_PROGRAMMABLE_DMA,
  895. };
  896. static const struct jz4780_dma_soc_data x1000_dma_soc_data = {
  897. .nb_channels = 8,
  898. .transfer_ord_max = 7,
  899. .flags = JZ_SOC_DATA_PROGRAMMABLE_DMA,
  900. };
  901. static const struct jz4780_dma_soc_data x1830_dma_soc_data = {
  902. .nb_channels = 32,
  903. .transfer_ord_max = 7,
  904. .flags = JZ_SOC_DATA_PROGRAMMABLE_DMA,
  905. };
  906. static const struct of_device_id jz4780_dma_dt_match[] = {
  907. { .compatible = "ingenic,jz4740-dma", .data = &jz4740_dma_soc_data },
  908. { .compatible = "ingenic,jz4725b-dma", .data = &jz4725b_dma_soc_data },
  909. { .compatible = "ingenic,jz4760-dma", .data = &jz4760_dma_soc_data },
  910. { .compatible = "ingenic,jz4760-mdma", .data = &jz4760_mdma_soc_data },
  911. { .compatible = "ingenic,jz4760-bdma", .data = &jz4760_bdma_soc_data },
  912. { .compatible = "ingenic,jz4760b-dma", .data = &jz4760b_dma_soc_data },
  913. { .compatible = "ingenic,jz4760b-mdma", .data = &jz4760b_mdma_soc_data },
  914. { .compatible = "ingenic,jz4760b-bdma", .data = &jz4760b_bdma_soc_data },
  915. { .compatible = "ingenic,jz4770-dma", .data = &jz4770_dma_soc_data },
  916. { .compatible = "ingenic,jz4780-dma", .data = &jz4780_dma_soc_data },
  917. { .compatible = "ingenic,x1000-dma", .data = &x1000_dma_soc_data },
  918. { .compatible = "ingenic,x1830-dma", .data = &x1830_dma_soc_data },
  919. {},
  920. };
  921. MODULE_DEVICE_TABLE(of, jz4780_dma_dt_match);
  922. static struct platform_driver jz4780_dma_driver = {
  923. .probe = jz4780_dma_probe,
  924. .remove = jz4780_dma_remove,
  925. .driver = {
  926. .name = "jz4780-dma",
  927. .of_match_table = jz4780_dma_dt_match,
  928. },
  929. };
  930. static int __init jz4780_dma_init(void)
  931. {
  932. return platform_driver_register(&jz4780_dma_driver);
  933. }
  934. subsys_initcall(jz4780_dma_init);
  935. static void __exit jz4780_dma_exit(void)
  936. {
  937. platform_driver_unregister(&jz4780_dma_driver);
  938. }
  939. module_exit(jz4780_dma_exit);
  940. MODULE_AUTHOR("Alex Smith <[email protected]>");
  941. MODULE_DESCRIPTION("Ingenic JZ4780 DMA controller driver");
  942. MODULE_LICENSE("GPL");