dbdma.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. /*
  2. *
  3. * BRIEF MODULE DESCRIPTION
  4. * The Descriptor Based DMA channel manager that first appeared
  5. * on the Au1550. I started with dma.c, but I think all that is
  6. * left is this initial comment :-)
  7. *
  8. * Copyright 2004 Embedded Edge, LLC
  9. * dan@embeddededge.com
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. *
  16. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  19. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  22. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  23. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. * You should have received a copy of the GNU General Public License along
  28. * with this program; if not, write to the Free Software Foundation, Inc.,
  29. * 675 Mass Ave, Cambridge, MA 02139, USA.
  30. *
  31. */
  32. #include <linux/kernel.h>
  33. #include <linux/slab.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/module.h>
  37. #include <asm/mach-au1x00/au1000.h>
  38. #include <asm/mach-au1x00/au1xxx_dbdma.h>
  39. #if defined(CONFIG_SOC_AU1550) || defined(CONFIG_SOC_AU1200)
  40. /*
  41. * The Descriptor Based DMA supports up to 16 channels.
  42. *
  43. * There are 32 devices defined. We keep an internal structure
  44. * of devices using these channels, along with additional
  45. * information.
  46. *
  47. * We allocate the descriptors and allow access to them through various
  48. * functions. The drivers allocate the data buffers and assign them
  49. * to the descriptors.
  50. */
  51. static DEFINE_SPINLOCK(au1xxx_dbdma_spin_lock);
  52. /* I couldn't find a macro that did this... */
  53. #define ALIGN_ADDR(x, a) ((((u32)(x)) + (a-1)) & ~(a-1))
  54. static dbdma_global_t *dbdma_gptr = (dbdma_global_t *)DDMA_GLOBAL_BASE;
  55. static int dbdma_initialized;
  56. static void au1xxx_dbdma_init(void);
  57. static dbdev_tab_t dbdev_tab[] = {
  58. #ifdef CONFIG_SOC_AU1550
  59. /* UARTS */
  60. { DSCR_CMD0_UART0_TX, DEV_FLAGS_OUT, 0, 8, 0x11100004, 0, 0 },
  61. { DSCR_CMD0_UART0_RX, DEV_FLAGS_IN, 0, 8, 0x11100000, 0, 0 },
  62. { DSCR_CMD0_UART3_TX, DEV_FLAGS_OUT, 0, 8, 0x11400004, 0, 0 },
  63. { DSCR_CMD0_UART3_RX, DEV_FLAGS_IN, 0, 8, 0x11400000, 0, 0 },
  64. /* EXT DMA */
  65. { DSCR_CMD0_DMA_REQ0, 0, 0, 0, 0x00000000, 0, 0 },
  66. { DSCR_CMD0_DMA_REQ1, 0, 0, 0, 0x00000000, 0, 0 },
  67. { DSCR_CMD0_DMA_REQ2, 0, 0, 0, 0x00000000, 0, 0 },
  68. { DSCR_CMD0_DMA_REQ3, 0, 0, 0, 0x00000000, 0, 0 },
  69. /* USB DEV */
  70. { DSCR_CMD0_USBDEV_RX0, DEV_FLAGS_IN, 4, 8, 0x10200000, 0, 0 },
  71. { DSCR_CMD0_USBDEV_TX0, DEV_FLAGS_OUT, 4, 8, 0x10200004, 0, 0 },
  72. { DSCR_CMD0_USBDEV_TX1, DEV_FLAGS_OUT, 4, 8, 0x10200008, 0, 0 },
  73. { DSCR_CMD0_USBDEV_TX2, DEV_FLAGS_OUT, 4, 8, 0x1020000c, 0, 0 },
  74. { DSCR_CMD0_USBDEV_RX3, DEV_FLAGS_IN, 4, 8, 0x10200010, 0, 0 },
  75. { DSCR_CMD0_USBDEV_RX4, DEV_FLAGS_IN, 4, 8, 0x10200014, 0, 0 },
  76. /* PSC 0 */
  77. { DSCR_CMD0_PSC0_TX, DEV_FLAGS_OUT, 0, 0, 0x11a0001c, 0, 0 },
  78. { DSCR_CMD0_PSC0_RX, DEV_FLAGS_IN, 0, 0, 0x11a0001c, 0, 0 },
  79. /* PSC 1 */
  80. { DSCR_CMD0_PSC1_TX, DEV_FLAGS_OUT, 0, 0, 0x11b0001c, 0, 0 },
  81. { DSCR_CMD0_PSC1_RX, DEV_FLAGS_IN, 0, 0, 0x11b0001c, 0, 0 },
  82. /* PSC 2 */
  83. { DSCR_CMD0_PSC2_TX, DEV_FLAGS_OUT, 0, 0, 0x10a0001c, 0, 0 },
  84. { DSCR_CMD0_PSC2_RX, DEV_FLAGS_IN, 0, 0, 0x10a0001c, 0, 0 },
  85. /* PSC 3 */
  86. { DSCR_CMD0_PSC3_TX, DEV_FLAGS_OUT, 0, 0, 0x10b0001c, 0, 0 },
  87. { DSCR_CMD0_PSC3_RX, DEV_FLAGS_IN, 0, 0, 0x10b0001c, 0, 0 },
  88. { DSCR_CMD0_PCI_WRITE, 0, 0, 0, 0x00000000, 0, 0 }, /* PCI */
  89. { DSCR_CMD0_NAND_FLASH, 0, 0, 0, 0x00000000, 0, 0 }, /* NAND */
  90. /* MAC 0 */
  91. { DSCR_CMD0_MAC0_RX, DEV_FLAGS_IN, 0, 0, 0x00000000, 0, 0 },
  92. { DSCR_CMD0_MAC0_TX, DEV_FLAGS_OUT, 0, 0, 0x00000000, 0, 0 },
  93. /* MAC 1 */
  94. { DSCR_CMD0_MAC1_RX, DEV_FLAGS_IN, 0, 0, 0x00000000, 0, 0 },
  95. { DSCR_CMD0_MAC1_TX, DEV_FLAGS_OUT, 0, 0, 0x00000000, 0, 0 },
  96. #endif /* CONFIG_SOC_AU1550 */
  97. #ifdef CONFIG_SOC_AU1200
  98. { DSCR_CMD0_UART0_TX, DEV_FLAGS_OUT, 0, 8, 0x11100004, 0, 0 },
  99. { DSCR_CMD0_UART0_RX, DEV_FLAGS_IN, 0, 8, 0x11100000, 0, 0 },
  100. { DSCR_CMD0_UART1_TX, DEV_FLAGS_OUT, 0, 8, 0x11200004, 0, 0 },
  101. { DSCR_CMD0_UART1_RX, DEV_FLAGS_IN, 0, 8, 0x11200000, 0, 0 },
  102. { DSCR_CMD0_DMA_REQ0, 0, 0, 0, 0x00000000, 0, 0 },
  103. { DSCR_CMD0_DMA_REQ1, 0, 0, 0, 0x00000000, 0, 0 },
  104. { DSCR_CMD0_MAE_BE, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
  105. { DSCR_CMD0_MAE_FE, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
  106. { DSCR_CMD0_MAE_BOTH, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
  107. { DSCR_CMD0_LCD, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
  108. { DSCR_CMD0_SDMS_TX0, DEV_FLAGS_OUT, 4, 8, 0x10600000, 0, 0 },
  109. { DSCR_CMD0_SDMS_RX0, DEV_FLAGS_IN, 4, 8, 0x10600004, 0, 0 },
  110. { DSCR_CMD0_SDMS_TX1, DEV_FLAGS_OUT, 4, 8, 0x10680000, 0, 0 },
  111. { DSCR_CMD0_SDMS_RX1, DEV_FLAGS_IN, 4, 8, 0x10680004, 0, 0 },
  112. { DSCR_CMD0_AES_RX, DEV_FLAGS_IN , 4, 32, 0x10300008, 0, 0 },
  113. { DSCR_CMD0_AES_TX, DEV_FLAGS_OUT, 4, 32, 0x10300004, 0, 0 },
  114. { DSCR_CMD0_PSC0_TX, DEV_FLAGS_OUT, 0, 16, 0x11a0001c, 0, 0 },
  115. { DSCR_CMD0_PSC0_RX, DEV_FLAGS_IN, 0, 16, 0x11a0001c, 0, 0 },
  116. { DSCR_CMD0_PSC0_SYNC, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
  117. { DSCR_CMD0_PSC1_TX, DEV_FLAGS_OUT, 0, 16, 0x11b0001c, 0, 0 },
  118. { DSCR_CMD0_PSC1_RX, DEV_FLAGS_IN, 0, 16, 0x11b0001c, 0, 0 },
  119. { DSCR_CMD0_PSC1_SYNC, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
  120. { DSCR_CMD0_CIM_RXA, DEV_FLAGS_IN, 0, 32, 0x14004020, 0, 0 },
  121. { DSCR_CMD0_CIM_RXB, DEV_FLAGS_IN, 0, 32, 0x14004040, 0, 0 },
  122. { DSCR_CMD0_CIM_RXC, DEV_FLAGS_IN, 0, 32, 0x14004060, 0, 0 },
  123. { DSCR_CMD0_CIM_SYNC, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
  124. { DSCR_CMD0_NAND_FLASH, DEV_FLAGS_IN, 0, 0, 0x00000000, 0, 0 },
  125. #endif /* CONFIG_SOC_AU1200 */
  126. { DSCR_CMD0_THROTTLE, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
  127. { DSCR_CMD0_ALWAYS, DEV_FLAGS_ANYUSE, 0, 0, 0x00000000, 0, 0 },
  128. /* Provide 16 user definable device types */
  129. { ~0, 0, 0, 0, 0, 0, 0 },
  130. { ~0, 0, 0, 0, 0, 0, 0 },
  131. { ~0, 0, 0, 0, 0, 0, 0 },
  132. { ~0, 0, 0, 0, 0, 0, 0 },
  133. { ~0, 0, 0, 0, 0, 0, 0 },
  134. { ~0, 0, 0, 0, 0, 0, 0 },
  135. { ~0, 0, 0, 0, 0, 0, 0 },
  136. { ~0, 0, 0, 0, 0, 0, 0 },
  137. { ~0, 0, 0, 0, 0, 0, 0 },
  138. { ~0, 0, 0, 0, 0, 0, 0 },
  139. { ~0, 0, 0, 0, 0, 0, 0 },
  140. { ~0, 0, 0, 0, 0, 0, 0 },
  141. { ~0, 0, 0, 0, 0, 0, 0 },
  142. { ~0, 0, 0, 0, 0, 0, 0 },
  143. { ~0, 0, 0, 0, 0, 0, 0 },
  144. { ~0, 0, 0, 0, 0, 0, 0 },
  145. };
  146. #define DBDEV_TAB_SIZE ARRAY_SIZE(dbdev_tab)
  147. #ifdef CONFIG_PM
  148. static u32 au1xxx_dbdma_pm_regs[NUM_DBDMA_CHANS + 1][8];
  149. #endif
  150. static chan_tab_t *chan_tab_ptr[NUM_DBDMA_CHANS];
  151. static dbdev_tab_t *find_dbdev_id(u32 id)
  152. {
  153. int i;
  154. dbdev_tab_t *p;
  155. for (i = 0; i < DBDEV_TAB_SIZE; ++i) {
  156. p = &dbdev_tab[i];
  157. if (p->dev_id == id)
  158. return p;
  159. }
  160. return NULL;
  161. }
  162. void *au1xxx_ddma_get_nextptr_virt(au1x_ddma_desc_t *dp)
  163. {
  164. return phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  165. }
  166. EXPORT_SYMBOL(au1xxx_ddma_get_nextptr_virt);
  167. u32 au1xxx_ddma_add_device(dbdev_tab_t *dev)
  168. {
  169. u32 ret = 0;
  170. dbdev_tab_t *p;
  171. static u16 new_id = 0x1000;
  172. p = find_dbdev_id(~0);
  173. if (NULL != p) {
  174. memcpy(p, dev, sizeof(dbdev_tab_t));
  175. p->dev_id = DSCR_DEV2CUSTOM_ID(new_id, dev->dev_id);
  176. ret = p->dev_id;
  177. new_id++;
  178. #if 0
  179. printk(KERN_DEBUG "add_device: id:%x flags:%x padd:%x\n",
  180. p->dev_id, p->dev_flags, p->dev_physaddr);
  181. #endif
  182. }
  183. return ret;
  184. }
  185. EXPORT_SYMBOL(au1xxx_ddma_add_device);
  186. void au1xxx_ddma_del_device(u32 devid)
  187. {
  188. dbdev_tab_t *p = find_dbdev_id(devid);
  189. if (p != NULL) {
  190. memset(p, 0, sizeof(dbdev_tab_t));
  191. p->dev_id = ~0;
  192. }
  193. }
  194. EXPORT_SYMBOL(au1xxx_ddma_del_device);
  195. /* Allocate a channel and return a non-zero descriptor if successful. */
  196. u32 au1xxx_dbdma_chan_alloc(u32 srcid, u32 destid,
  197. void (*callback)(int, void *), void *callparam)
  198. {
  199. unsigned long flags;
  200. u32 used, chan, rv;
  201. u32 dcp;
  202. int i;
  203. dbdev_tab_t *stp, *dtp;
  204. chan_tab_t *ctp;
  205. au1x_dma_chan_t *cp;
  206. /*
  207. * We do the intialization on the first channel allocation.
  208. * We have to wait because of the interrupt handler initialization
  209. * which can't be done successfully during board set up.
  210. */
  211. if (!dbdma_initialized)
  212. au1xxx_dbdma_init();
  213. dbdma_initialized = 1;
  214. stp = find_dbdev_id(srcid);
  215. if (stp == NULL)
  216. return 0;
  217. dtp = find_dbdev_id(destid);
  218. if (dtp == NULL)
  219. return 0;
  220. used = 0;
  221. rv = 0;
  222. /* Check to see if we can get both channels. */
  223. spin_lock_irqsave(&au1xxx_dbdma_spin_lock, flags);
  224. if (!(stp->dev_flags & DEV_FLAGS_INUSE) ||
  225. (stp->dev_flags & DEV_FLAGS_ANYUSE)) {
  226. /* Got source */
  227. stp->dev_flags |= DEV_FLAGS_INUSE;
  228. if (!(dtp->dev_flags & DEV_FLAGS_INUSE) ||
  229. (dtp->dev_flags & DEV_FLAGS_ANYUSE)) {
  230. /* Got destination */
  231. dtp->dev_flags |= DEV_FLAGS_INUSE;
  232. } else {
  233. /* Can't get dest. Release src. */
  234. stp->dev_flags &= ~DEV_FLAGS_INUSE;
  235. used++;
  236. }
  237. } else
  238. used++;
  239. spin_unlock_irqrestore(&au1xxx_dbdma_spin_lock, flags);
  240. if (!used) {
  241. /* Let's see if we can allocate a channel for it. */
  242. ctp = NULL;
  243. chan = 0;
  244. spin_lock_irqsave(&au1xxx_dbdma_spin_lock, flags);
  245. for (i = 0; i < NUM_DBDMA_CHANS; i++)
  246. if (chan_tab_ptr[i] == NULL) {
  247. /*
  248. * If kmalloc fails, it is caught below same
  249. * as a channel not available.
  250. */
  251. ctp = kmalloc(sizeof(chan_tab_t), GFP_ATOMIC);
  252. chan_tab_ptr[i] = ctp;
  253. break;
  254. }
  255. spin_unlock_irqrestore(&au1xxx_dbdma_spin_lock, flags);
  256. if (ctp != NULL) {
  257. memset(ctp, 0, sizeof(chan_tab_t));
  258. ctp->chan_index = chan = i;
  259. dcp = DDMA_CHANNEL_BASE;
  260. dcp += (0x0100 * chan);
  261. ctp->chan_ptr = (au1x_dma_chan_t *)dcp;
  262. cp = (au1x_dma_chan_t *)dcp;
  263. ctp->chan_src = stp;
  264. ctp->chan_dest = dtp;
  265. ctp->chan_callback = callback;
  266. ctp->chan_callparam = callparam;
  267. /* Initialize channel configuration. */
  268. i = 0;
  269. if (stp->dev_intlevel)
  270. i |= DDMA_CFG_SED;
  271. if (stp->dev_intpolarity)
  272. i |= DDMA_CFG_SP;
  273. if (dtp->dev_intlevel)
  274. i |= DDMA_CFG_DED;
  275. if (dtp->dev_intpolarity)
  276. i |= DDMA_CFG_DP;
  277. if ((stp->dev_flags & DEV_FLAGS_SYNC) ||
  278. (dtp->dev_flags & DEV_FLAGS_SYNC))
  279. i |= DDMA_CFG_SYNC;
  280. cp->ddma_cfg = i;
  281. au_sync();
  282. /* Return a non-zero value that can be used to
  283. * find the channel information in subsequent
  284. * operations.
  285. */
  286. rv = (u32)(&chan_tab_ptr[chan]);
  287. } else {
  288. /* Release devices */
  289. stp->dev_flags &= ~DEV_FLAGS_INUSE;
  290. dtp->dev_flags &= ~DEV_FLAGS_INUSE;
  291. }
  292. }
  293. return rv;
  294. }
  295. EXPORT_SYMBOL(au1xxx_dbdma_chan_alloc);
  296. /*
  297. * Set the device width if source or destination is a FIFO.
  298. * Should be 8, 16, or 32 bits.
  299. */
  300. u32 au1xxx_dbdma_set_devwidth(u32 chanid, int bits)
  301. {
  302. u32 rv;
  303. chan_tab_t *ctp;
  304. dbdev_tab_t *stp, *dtp;
  305. ctp = *((chan_tab_t **)chanid);
  306. stp = ctp->chan_src;
  307. dtp = ctp->chan_dest;
  308. rv = 0;
  309. if (stp->dev_flags & DEV_FLAGS_IN) { /* Source in fifo */
  310. rv = stp->dev_devwidth;
  311. stp->dev_devwidth = bits;
  312. }
  313. if (dtp->dev_flags & DEV_FLAGS_OUT) { /* Destination out fifo */
  314. rv = dtp->dev_devwidth;
  315. dtp->dev_devwidth = bits;
  316. }
  317. return rv;
  318. }
  319. EXPORT_SYMBOL(au1xxx_dbdma_set_devwidth);
  320. /* Allocate a descriptor ring, initializing as much as possible. */
  321. u32 au1xxx_dbdma_ring_alloc(u32 chanid, int entries)
  322. {
  323. int i;
  324. u32 desc_base, srcid, destid;
  325. u32 cmd0, cmd1, src1, dest1;
  326. u32 src0, dest0;
  327. chan_tab_t *ctp;
  328. dbdev_tab_t *stp, *dtp;
  329. au1x_ddma_desc_t *dp;
  330. /*
  331. * I guess we could check this to be within the
  332. * range of the table......
  333. */
  334. ctp = *((chan_tab_t **)chanid);
  335. stp = ctp->chan_src;
  336. dtp = ctp->chan_dest;
  337. /*
  338. * The descriptors must be 32-byte aligned. There is a
  339. * possibility the allocation will give us such an address,
  340. * and if we try that first we are likely to not waste larger
  341. * slabs of memory.
  342. */
  343. desc_base = (u32)kmalloc(entries * sizeof(au1x_ddma_desc_t),
  344. GFP_KERNEL|GFP_DMA);
  345. if (desc_base == 0)
  346. return 0;
  347. if (desc_base & 0x1f) {
  348. /*
  349. * Lost....do it again, allocate extra, and round
  350. * the address base.
  351. */
  352. kfree((const void *)desc_base);
  353. i = entries * sizeof(au1x_ddma_desc_t);
  354. i += (sizeof(au1x_ddma_desc_t) - 1);
  355. desc_base = (u32)kmalloc(i, GFP_KERNEL|GFP_DMA);
  356. if (desc_base == 0)
  357. return 0;
  358. desc_base = ALIGN_ADDR(desc_base, sizeof(au1x_ddma_desc_t));
  359. }
  360. dp = (au1x_ddma_desc_t *)desc_base;
  361. /* Keep track of the base descriptor. */
  362. ctp->chan_desc_base = dp;
  363. /* Initialize the rings with as much information as we know. */
  364. srcid = stp->dev_id;
  365. destid = dtp->dev_id;
  366. cmd0 = cmd1 = src1 = dest1 = 0;
  367. src0 = dest0 = 0;
  368. cmd0 |= DSCR_CMD0_SID(srcid);
  369. cmd0 |= DSCR_CMD0_DID(destid);
  370. cmd0 |= DSCR_CMD0_IE | DSCR_CMD0_CV;
  371. cmd0 |= DSCR_CMD0_ST(DSCR_CMD0_ST_NOCHANGE);
  372. /* Is it mem to mem transfer? */
  373. if (((DSCR_CUSTOM2DEV_ID(srcid) == DSCR_CMD0_THROTTLE) ||
  374. (DSCR_CUSTOM2DEV_ID(srcid) == DSCR_CMD0_ALWAYS)) &&
  375. ((DSCR_CUSTOM2DEV_ID(destid) == DSCR_CMD0_THROTTLE) ||
  376. (DSCR_CUSTOM2DEV_ID(destid) == DSCR_CMD0_ALWAYS)))
  377. cmd0 |= DSCR_CMD0_MEM;
  378. switch (stp->dev_devwidth) {
  379. case 8:
  380. cmd0 |= DSCR_CMD0_SW(DSCR_CMD0_BYTE);
  381. break;
  382. case 16:
  383. cmd0 |= DSCR_CMD0_SW(DSCR_CMD0_HALFWORD);
  384. break;
  385. case 32:
  386. default:
  387. cmd0 |= DSCR_CMD0_SW(DSCR_CMD0_WORD);
  388. break;
  389. }
  390. switch (dtp->dev_devwidth) {
  391. case 8:
  392. cmd0 |= DSCR_CMD0_DW(DSCR_CMD0_BYTE);
  393. break;
  394. case 16:
  395. cmd0 |= DSCR_CMD0_DW(DSCR_CMD0_HALFWORD);
  396. break;
  397. case 32:
  398. default:
  399. cmd0 |= DSCR_CMD0_DW(DSCR_CMD0_WORD);
  400. break;
  401. }
  402. /*
  403. * If the device is marked as an in/out FIFO, ensure it is
  404. * set non-coherent.
  405. */
  406. if (stp->dev_flags & DEV_FLAGS_IN)
  407. cmd0 |= DSCR_CMD0_SN; /* Source in FIFO */
  408. if (dtp->dev_flags & DEV_FLAGS_OUT)
  409. cmd0 |= DSCR_CMD0_DN; /* Destination out FIFO */
  410. /*
  411. * Set up source1. For now, assume no stride and increment.
  412. * A channel attribute update can change this later.
  413. */
  414. switch (stp->dev_tsize) {
  415. case 1:
  416. src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE1);
  417. break;
  418. case 2:
  419. src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE2);
  420. break;
  421. case 4:
  422. src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE4);
  423. break;
  424. case 8:
  425. default:
  426. src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE8);
  427. break;
  428. }
  429. /* If source input is FIFO, set static address. */
  430. if (stp->dev_flags & DEV_FLAGS_IN) {
  431. if (stp->dev_flags & DEV_FLAGS_BURSTABLE)
  432. src1 |= DSCR_SRC1_SAM(DSCR_xAM_BURST);
  433. else
  434. src1 |= DSCR_SRC1_SAM(DSCR_xAM_STATIC);
  435. }
  436. if (stp->dev_physaddr)
  437. src0 = stp->dev_physaddr;
  438. /*
  439. * Set up dest1. For now, assume no stride and increment.
  440. * A channel attribute update can change this later.
  441. */
  442. switch (dtp->dev_tsize) {
  443. case 1:
  444. dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE1);
  445. break;
  446. case 2:
  447. dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE2);
  448. break;
  449. case 4:
  450. dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE4);
  451. break;
  452. case 8:
  453. default:
  454. dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE8);
  455. break;
  456. }
  457. /* If destination output is FIFO, set static address. */
  458. if (dtp->dev_flags & DEV_FLAGS_OUT) {
  459. if (dtp->dev_flags & DEV_FLAGS_BURSTABLE)
  460. dest1 |= DSCR_DEST1_DAM(DSCR_xAM_BURST);
  461. else
  462. dest1 |= DSCR_DEST1_DAM(DSCR_xAM_STATIC);
  463. }
  464. if (dtp->dev_physaddr)
  465. dest0 = dtp->dev_physaddr;
  466. #if 0
  467. printk(KERN_DEBUG "did:%x sid:%x cmd0:%x cmd1:%x source0:%x "
  468. "source1:%x dest0:%x dest1:%x\n",
  469. dtp->dev_id, stp->dev_id, cmd0, cmd1, src0,
  470. src1, dest0, dest1);
  471. #endif
  472. for (i = 0; i < entries; i++) {
  473. dp->dscr_cmd0 = cmd0;
  474. dp->dscr_cmd1 = cmd1;
  475. dp->dscr_source0 = src0;
  476. dp->dscr_source1 = src1;
  477. dp->dscr_dest0 = dest0;
  478. dp->dscr_dest1 = dest1;
  479. dp->dscr_stat = 0;
  480. dp->sw_context = 0;
  481. dp->sw_status = 0;
  482. dp->dscr_nxtptr = DSCR_NXTPTR(virt_to_phys(dp + 1));
  483. dp++;
  484. }
  485. /* Make last descrptor point to the first. */
  486. dp--;
  487. dp->dscr_nxtptr = DSCR_NXTPTR(virt_to_phys(ctp->chan_desc_base));
  488. ctp->get_ptr = ctp->put_ptr = ctp->cur_ptr = ctp->chan_desc_base;
  489. return (u32)ctp->chan_desc_base;
  490. }
  491. EXPORT_SYMBOL(au1xxx_dbdma_ring_alloc);
  492. /*
  493. * Put a source buffer into the DMA ring.
  494. * This updates the source pointer and byte count. Normally used
  495. * for memory to fifo transfers.
  496. */
  497. u32 _au1xxx_dbdma_put_source(u32 chanid, void *buf, int nbytes, u32 flags)
  498. {
  499. chan_tab_t *ctp;
  500. au1x_ddma_desc_t *dp;
  501. /*
  502. * I guess we could check this to be within the
  503. * range of the table......
  504. */
  505. ctp = *(chan_tab_t **)chanid;
  506. /*
  507. * We should have multiple callers for a particular channel,
  508. * an interrupt doesn't affect this pointer nor the descriptor,
  509. * so no locking should be needed.
  510. */
  511. dp = ctp->put_ptr;
  512. /*
  513. * If the descriptor is valid, we are way ahead of the DMA
  514. * engine, so just return an error condition.
  515. */
  516. if (dp->dscr_cmd0 & DSCR_CMD0_V)
  517. return 0;
  518. /* Load up buffer address and byte count. */
  519. dp->dscr_source0 = virt_to_phys(buf);
  520. dp->dscr_cmd1 = nbytes;
  521. /* Check flags */
  522. if (flags & DDMA_FLAGS_IE)
  523. dp->dscr_cmd0 |= DSCR_CMD0_IE;
  524. if (flags & DDMA_FLAGS_NOIE)
  525. dp->dscr_cmd0 &= ~DSCR_CMD0_IE;
  526. /*
  527. * There is an errata on the Au1200/Au1550 parts that could result
  528. * in "stale" data being DMA'ed. It has to do with the snoop logic on
  529. * the cache eviction buffer. DMA_NONCOHERENT is on by default for
  530. * these parts. If it is fixed in the future, these dma_cache_inv will
  531. * just be nothing more than empty macros. See io.h.
  532. */
  533. dma_cache_wback_inv((unsigned long)buf, nbytes);
  534. dp->dscr_cmd0 |= DSCR_CMD0_V; /* Let it rip */
  535. au_sync();
  536. dma_cache_wback_inv((unsigned long)dp, sizeof(dp));
  537. ctp->chan_ptr->ddma_dbell = 0;
  538. /* Get next descriptor pointer. */
  539. ctp->put_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  540. /* Return something non-zero. */
  541. return nbytes;
  542. }
  543. EXPORT_SYMBOL(_au1xxx_dbdma_put_source);
  544. /* Put a destination buffer into the DMA ring.
  545. * This updates the destination pointer and byte count. Normally used
  546. * to place an empty buffer into the ring for fifo to memory transfers.
  547. */
  548. u32
  549. _au1xxx_dbdma_put_dest(u32 chanid, void *buf, int nbytes, u32 flags)
  550. {
  551. chan_tab_t *ctp;
  552. au1x_ddma_desc_t *dp;
  553. /* I guess we could check this to be within the
  554. * range of the table......
  555. */
  556. ctp = *((chan_tab_t **)chanid);
  557. /* We should have multiple callers for a particular channel,
  558. * an interrupt doesn't affect this pointer nor the descriptor,
  559. * so no locking should be needed.
  560. */
  561. dp = ctp->put_ptr;
  562. /* If the descriptor is valid, we are way ahead of the DMA
  563. * engine, so just return an error condition.
  564. */
  565. if (dp->dscr_cmd0 & DSCR_CMD0_V)
  566. return 0;
  567. /* Load up buffer address and byte count */
  568. /* Check flags */
  569. if (flags & DDMA_FLAGS_IE)
  570. dp->dscr_cmd0 |= DSCR_CMD0_IE;
  571. if (flags & DDMA_FLAGS_NOIE)
  572. dp->dscr_cmd0 &= ~DSCR_CMD0_IE;
  573. dp->dscr_dest0 = virt_to_phys(buf);
  574. dp->dscr_cmd1 = nbytes;
  575. #if 0
  576. printk(KERN_DEBUG "cmd0:%x cmd1:%x source0:%x source1:%x dest0:%x dest1:%x\n",
  577. dp->dscr_cmd0, dp->dscr_cmd1, dp->dscr_source0,
  578. dp->dscr_source1, dp->dscr_dest0, dp->dscr_dest1);
  579. #endif
  580. /*
  581. * There is an errata on the Au1200/Au1550 parts that could result in
  582. * "stale" data being DMA'ed. It has to do with the snoop logic on the
  583. * cache eviction buffer. DMA_NONCOHERENT is on by default for these
  584. * parts. If it is fixed in the future, these dma_cache_inv will just
  585. * be nothing more than empty macros. See io.h.
  586. */
  587. dma_cache_inv((unsigned long)buf, nbytes);
  588. dp->dscr_cmd0 |= DSCR_CMD0_V; /* Let it rip */
  589. au_sync();
  590. dma_cache_wback_inv((unsigned long)dp, sizeof(dp));
  591. ctp->chan_ptr->ddma_dbell = 0;
  592. /* Get next descriptor pointer. */
  593. ctp->put_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  594. /* Return something non-zero. */
  595. return nbytes;
  596. }
  597. EXPORT_SYMBOL(_au1xxx_dbdma_put_dest);
  598. /*
  599. * Get a destination buffer into the DMA ring.
  600. * Normally used to get a full buffer from the ring during fifo
  601. * to memory transfers. This does not set the valid bit, you will
  602. * have to put another destination buffer to keep the DMA going.
  603. */
  604. u32 au1xxx_dbdma_get_dest(u32 chanid, void **buf, int *nbytes)
  605. {
  606. chan_tab_t *ctp;
  607. au1x_ddma_desc_t *dp;
  608. u32 rv;
  609. /*
  610. * I guess we could check this to be within the
  611. * range of the table......
  612. */
  613. ctp = *((chan_tab_t **)chanid);
  614. /*
  615. * We should have multiple callers for a particular channel,
  616. * an interrupt doesn't affect this pointer nor the descriptor,
  617. * so no locking should be needed.
  618. */
  619. dp = ctp->get_ptr;
  620. /*
  621. * If the descriptor is valid, we are way ahead of the DMA
  622. * engine, so just return an error condition.
  623. */
  624. if (dp->dscr_cmd0 & DSCR_CMD0_V)
  625. return 0;
  626. /* Return buffer address and byte count. */
  627. *buf = (void *)(phys_to_virt(dp->dscr_dest0));
  628. *nbytes = dp->dscr_cmd1;
  629. rv = dp->dscr_stat;
  630. /* Get next descriptor pointer. */
  631. ctp->get_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  632. /* Return something non-zero. */
  633. return rv;
  634. }
  635. EXPORT_SYMBOL_GPL(au1xxx_dbdma_get_dest);
  636. void au1xxx_dbdma_stop(u32 chanid)
  637. {
  638. chan_tab_t *ctp;
  639. au1x_dma_chan_t *cp;
  640. int halt_timeout = 0;
  641. ctp = *((chan_tab_t **)chanid);
  642. cp = ctp->chan_ptr;
  643. cp->ddma_cfg &= ~DDMA_CFG_EN; /* Disable channel */
  644. au_sync();
  645. while (!(cp->ddma_stat & DDMA_STAT_H)) {
  646. udelay(1);
  647. halt_timeout++;
  648. if (halt_timeout > 100) {
  649. printk(KERN_WARNING "warning: DMA channel won't halt\n");
  650. break;
  651. }
  652. }
  653. /* clear current desc valid and doorbell */
  654. cp->ddma_stat |= (DDMA_STAT_DB | DDMA_STAT_V);
  655. au_sync();
  656. }
  657. EXPORT_SYMBOL(au1xxx_dbdma_stop);
  658. /*
  659. * Start using the current descriptor pointer. If the DBDMA encounters
  660. * a non-valid descriptor, it will stop. In this case, we can just
  661. * continue by adding a buffer to the list and starting again.
  662. */
  663. void au1xxx_dbdma_start(u32 chanid)
  664. {
  665. chan_tab_t *ctp;
  666. au1x_dma_chan_t *cp;
  667. ctp = *((chan_tab_t **)chanid);
  668. cp = ctp->chan_ptr;
  669. cp->ddma_desptr = virt_to_phys(ctp->cur_ptr);
  670. cp->ddma_cfg |= DDMA_CFG_EN; /* Enable channel */
  671. au_sync();
  672. cp->ddma_dbell = 0;
  673. au_sync();
  674. }
  675. EXPORT_SYMBOL(au1xxx_dbdma_start);
  676. void au1xxx_dbdma_reset(u32 chanid)
  677. {
  678. chan_tab_t *ctp;
  679. au1x_ddma_desc_t *dp;
  680. au1xxx_dbdma_stop(chanid);
  681. ctp = *((chan_tab_t **)chanid);
  682. ctp->get_ptr = ctp->put_ptr = ctp->cur_ptr = ctp->chan_desc_base;
  683. /* Run through the descriptors and reset the valid indicator. */
  684. dp = ctp->chan_desc_base;
  685. do {
  686. dp->dscr_cmd0 &= ~DSCR_CMD0_V;
  687. /*
  688. * Reset our software status -- this is used to determine
  689. * if a descriptor is in use by upper level software. Since
  690. * posting can reset 'V' bit.
  691. */
  692. dp->sw_status = 0;
  693. dp = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  694. } while (dp != ctp->chan_desc_base);
  695. }
  696. EXPORT_SYMBOL(au1xxx_dbdma_reset);
  697. u32 au1xxx_get_dma_residue(u32 chanid)
  698. {
  699. chan_tab_t *ctp;
  700. au1x_dma_chan_t *cp;
  701. u32 rv;
  702. ctp = *((chan_tab_t **)chanid);
  703. cp = ctp->chan_ptr;
  704. /* This is only valid if the channel is stopped. */
  705. rv = cp->ddma_bytecnt;
  706. au_sync();
  707. return rv;
  708. }
  709. EXPORT_SYMBOL_GPL(au1xxx_get_dma_residue);
  710. void au1xxx_dbdma_chan_free(u32 chanid)
  711. {
  712. chan_tab_t *ctp;
  713. dbdev_tab_t *stp, *dtp;
  714. ctp = *((chan_tab_t **)chanid);
  715. stp = ctp->chan_src;
  716. dtp = ctp->chan_dest;
  717. au1xxx_dbdma_stop(chanid);
  718. kfree((void *)ctp->chan_desc_base);
  719. stp->dev_flags &= ~DEV_FLAGS_INUSE;
  720. dtp->dev_flags &= ~DEV_FLAGS_INUSE;
  721. chan_tab_ptr[ctp->chan_index] = NULL;
  722. kfree(ctp);
  723. }
  724. EXPORT_SYMBOL(au1xxx_dbdma_chan_free);
  725. static irqreturn_t dbdma_interrupt(int irq, void *dev_id)
  726. {
  727. u32 intstat;
  728. u32 chan_index;
  729. chan_tab_t *ctp;
  730. au1x_ddma_desc_t *dp;
  731. au1x_dma_chan_t *cp;
  732. intstat = dbdma_gptr->ddma_intstat;
  733. au_sync();
  734. chan_index = __ffs(intstat);
  735. ctp = chan_tab_ptr[chan_index];
  736. cp = ctp->chan_ptr;
  737. dp = ctp->cur_ptr;
  738. /* Reset interrupt. */
  739. cp->ddma_irq = 0;
  740. au_sync();
  741. if (ctp->chan_callback)
  742. ctp->chan_callback(irq, ctp->chan_callparam);
  743. ctp->cur_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  744. return IRQ_RETVAL(1);
  745. }
  746. static void au1xxx_dbdma_init(void)
  747. {
  748. int irq_nr;
  749. dbdma_gptr->ddma_config = 0;
  750. dbdma_gptr->ddma_throttle = 0;
  751. dbdma_gptr->ddma_inten = 0xffff;
  752. au_sync();
  753. #if defined(CONFIG_SOC_AU1550)
  754. irq_nr = AU1550_DDMA_INT;
  755. #elif defined(CONFIG_SOC_AU1200)
  756. irq_nr = AU1200_DDMA_INT;
  757. #else
  758. #error Unknown Au1x00 SOC
  759. #endif
  760. if (request_irq(irq_nr, dbdma_interrupt, IRQF_DISABLED,
  761. "Au1xxx dbdma", (void *)dbdma_gptr))
  762. printk(KERN_ERR "Can't get 1550 dbdma irq");
  763. }
  764. void au1xxx_dbdma_dump(u32 chanid)
  765. {
  766. chan_tab_t *ctp;
  767. au1x_ddma_desc_t *dp;
  768. dbdev_tab_t *stp, *dtp;
  769. au1x_dma_chan_t *cp;
  770. u32 i = 0;
  771. ctp = *((chan_tab_t **)chanid);
  772. stp = ctp->chan_src;
  773. dtp = ctp->chan_dest;
  774. cp = ctp->chan_ptr;
  775. printk(KERN_DEBUG "Chan %x, stp %x (dev %d) dtp %x (dev %d) \n",
  776. (u32)ctp, (u32)stp, stp - dbdev_tab, (u32)dtp,
  777. dtp - dbdev_tab);
  778. printk(KERN_DEBUG "desc base %x, get %x, put %x, cur %x\n",
  779. (u32)(ctp->chan_desc_base), (u32)(ctp->get_ptr),
  780. (u32)(ctp->put_ptr), (u32)(ctp->cur_ptr));
  781. printk(KERN_DEBUG "dbdma chan %x\n", (u32)cp);
  782. printk(KERN_DEBUG "cfg %08x, desptr %08x, statptr %08x\n",
  783. cp->ddma_cfg, cp->ddma_desptr, cp->ddma_statptr);
  784. printk(KERN_DEBUG "dbell %08x, irq %08x, stat %08x, bytecnt %08x\n",
  785. cp->ddma_dbell, cp->ddma_irq, cp->ddma_stat,
  786. cp->ddma_bytecnt);
  787. /* Run through the descriptors */
  788. dp = ctp->chan_desc_base;
  789. do {
  790. printk(KERN_DEBUG "Dp[%d]= %08x, cmd0 %08x, cmd1 %08x\n",
  791. i++, (u32)dp, dp->dscr_cmd0, dp->dscr_cmd1);
  792. printk(KERN_DEBUG "src0 %08x, src1 %08x, dest0 %08x, dest1 %08x\n",
  793. dp->dscr_source0, dp->dscr_source1,
  794. dp->dscr_dest0, dp->dscr_dest1);
  795. printk(KERN_DEBUG "stat %08x, nxtptr %08x\n",
  796. dp->dscr_stat, dp->dscr_nxtptr);
  797. dp = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  798. } while (dp != ctp->chan_desc_base);
  799. }
  800. /* Put a descriptor into the DMA ring.
  801. * This updates the source/destination pointers and byte count.
  802. */
  803. u32 au1xxx_dbdma_put_dscr(u32 chanid, au1x_ddma_desc_t *dscr)
  804. {
  805. chan_tab_t *ctp;
  806. au1x_ddma_desc_t *dp;
  807. u32 nbytes = 0;
  808. /*
  809. * I guess we could check this to be within the
  810. * range of the table......
  811. */
  812. ctp = *((chan_tab_t **)chanid);
  813. /*
  814. * We should have multiple callers for a particular channel,
  815. * an interrupt doesn't affect this pointer nor the descriptor,
  816. * so no locking should be needed.
  817. */
  818. dp = ctp->put_ptr;
  819. /*
  820. * If the descriptor is valid, we are way ahead of the DMA
  821. * engine, so just return an error condition.
  822. */
  823. if (dp->dscr_cmd0 & DSCR_CMD0_V)
  824. return 0;
  825. /* Load up buffer addresses and byte count. */
  826. dp->dscr_dest0 = dscr->dscr_dest0;
  827. dp->dscr_source0 = dscr->dscr_source0;
  828. dp->dscr_dest1 = dscr->dscr_dest1;
  829. dp->dscr_source1 = dscr->dscr_source1;
  830. dp->dscr_cmd1 = dscr->dscr_cmd1;
  831. nbytes = dscr->dscr_cmd1;
  832. /* Allow the caller to specifiy if an interrupt is generated */
  833. dp->dscr_cmd0 &= ~DSCR_CMD0_IE;
  834. dp->dscr_cmd0 |= dscr->dscr_cmd0 | DSCR_CMD0_V;
  835. ctp->chan_ptr->ddma_dbell = 0;
  836. /* Get next descriptor pointer. */
  837. ctp->put_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  838. /* Return something non-zero. */
  839. return nbytes;
  840. }
  841. #ifdef CONFIG_PM
  842. void au1xxx_dbdma_suspend(void)
  843. {
  844. int i;
  845. u32 addr;
  846. addr = DDMA_GLOBAL_BASE;
  847. au1xxx_dbdma_pm_regs[0][0] = au_readl(addr + 0x00);
  848. au1xxx_dbdma_pm_regs[0][1] = au_readl(addr + 0x04);
  849. au1xxx_dbdma_pm_regs[0][2] = au_readl(addr + 0x08);
  850. au1xxx_dbdma_pm_regs[0][3] = au_readl(addr + 0x0c);
  851. /* save channel configurations */
  852. for (i = 1, addr = DDMA_CHANNEL_BASE; i < NUM_DBDMA_CHANS; i++) {
  853. au1xxx_dbdma_pm_regs[i][0] = au_readl(addr + 0x00);
  854. au1xxx_dbdma_pm_regs[i][1] = au_readl(addr + 0x04);
  855. au1xxx_dbdma_pm_regs[i][2] = au_readl(addr + 0x08);
  856. au1xxx_dbdma_pm_regs[i][3] = au_readl(addr + 0x0c);
  857. au1xxx_dbdma_pm_regs[i][4] = au_readl(addr + 0x10);
  858. au1xxx_dbdma_pm_regs[i][5] = au_readl(addr + 0x14);
  859. au1xxx_dbdma_pm_regs[i][6] = au_readl(addr + 0x18);
  860. /* halt channel */
  861. au_writel(au1xxx_dbdma_pm_regs[i][0] & ~1, addr + 0x00);
  862. au_sync();
  863. while (!(au_readl(addr + 0x14) & 1))
  864. au_sync();
  865. addr += 0x100; /* next channel base */
  866. }
  867. /* disable channel interrupts */
  868. au_writel(0, DDMA_GLOBAL_BASE + 0x0c);
  869. au_sync();
  870. }
  871. void au1xxx_dbdma_resume(void)
  872. {
  873. int i;
  874. u32 addr;
  875. addr = DDMA_GLOBAL_BASE;
  876. au_writel(au1xxx_dbdma_pm_regs[0][0], addr + 0x00);
  877. au_writel(au1xxx_dbdma_pm_regs[0][1], addr + 0x04);
  878. au_writel(au1xxx_dbdma_pm_regs[0][2], addr + 0x08);
  879. au_writel(au1xxx_dbdma_pm_regs[0][3], addr + 0x0c);
  880. /* restore channel configurations */
  881. for (i = 1, addr = DDMA_CHANNEL_BASE; i < NUM_DBDMA_CHANS; i++) {
  882. au_writel(au1xxx_dbdma_pm_regs[i][0], addr + 0x00);
  883. au_writel(au1xxx_dbdma_pm_regs[i][1], addr + 0x04);
  884. au_writel(au1xxx_dbdma_pm_regs[i][2], addr + 0x08);
  885. au_writel(au1xxx_dbdma_pm_regs[i][3], addr + 0x0c);
  886. au_writel(au1xxx_dbdma_pm_regs[i][4], addr + 0x10);
  887. au_writel(au1xxx_dbdma_pm_regs[i][5], addr + 0x14);
  888. au_writel(au1xxx_dbdma_pm_regs[i][6], addr + 0x18);
  889. au_sync();
  890. addr += 0x100; /* next channel base */
  891. }
  892. }
  893. #endif /* CONFIG_PM */
  894. #endif /* defined(CONFIG_SOC_AU1550) || defined(CONFIG_SOC_AU1200) */