dbdma.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  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/init.h>
  33. #include <linux/kernel.h>
  34. #include <linux/slab.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/module.h>
  38. #include <asm/mach-au1x00/au1000.h>
  39. #include <asm/mach-au1x00/au1xxx_dbdma.h>
  40. #if defined(CONFIG_SOC_AU1550) || defined(CONFIG_SOC_AU1200)
  41. /*
  42. * The Descriptor Based DMA supports up to 16 channels.
  43. *
  44. * There are 32 devices defined. We keep an internal structure
  45. * of devices using these channels, along with additional
  46. * information.
  47. *
  48. * We allocate the descriptors and allow access to them through various
  49. * functions. The drivers allocate the data buffers and assign them
  50. * to the descriptors.
  51. */
  52. static DEFINE_SPINLOCK(au1xxx_dbdma_spin_lock);
  53. /* I couldn't find a macro that did this... */
  54. #define ALIGN_ADDR(x, a) ((((u32)(x)) + (a-1)) & ~(a-1))
  55. static dbdma_global_t *dbdma_gptr = (dbdma_global_t *)DDMA_GLOBAL_BASE;
  56. static int dbdma_initialized;
  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][6];
  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;
  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. return 0;
  213. stp = find_dbdev_id(srcid);
  214. if (stp == NULL)
  215. return 0;
  216. dtp = find_dbdev_id(destid);
  217. if (dtp == NULL)
  218. return 0;
  219. used = 0;
  220. /* Check to see if we can get both channels. */
  221. spin_lock_irqsave(&au1xxx_dbdma_spin_lock, flags);
  222. if (!(stp->dev_flags & DEV_FLAGS_INUSE) ||
  223. (stp->dev_flags & DEV_FLAGS_ANYUSE)) {
  224. /* Got source */
  225. stp->dev_flags |= DEV_FLAGS_INUSE;
  226. if (!(dtp->dev_flags & DEV_FLAGS_INUSE) ||
  227. (dtp->dev_flags & DEV_FLAGS_ANYUSE)) {
  228. /* Got destination */
  229. dtp->dev_flags |= DEV_FLAGS_INUSE;
  230. } else {
  231. /* Can't get dest. Release src. */
  232. stp->dev_flags &= ~DEV_FLAGS_INUSE;
  233. used++;
  234. }
  235. } else
  236. used++;
  237. spin_unlock_irqrestore(&au1xxx_dbdma_spin_lock, flags);
  238. if (used)
  239. return 0;
  240. /* Let's see if we can allocate a channel for it. */
  241. ctp = NULL;
  242. chan = 0;
  243. spin_lock_irqsave(&au1xxx_dbdma_spin_lock, flags);
  244. for (i = 0; i < NUM_DBDMA_CHANS; i++)
  245. if (chan_tab_ptr[i] == NULL) {
  246. /*
  247. * If kmalloc fails, it is caught below same
  248. * as a channel not available.
  249. */
  250. ctp = kmalloc(sizeof(chan_tab_t), GFP_ATOMIC);
  251. chan_tab_ptr[i] = ctp;
  252. break;
  253. }
  254. spin_unlock_irqrestore(&au1xxx_dbdma_spin_lock, flags);
  255. if (ctp != NULL) {
  256. memset(ctp, 0, sizeof(chan_tab_t));
  257. ctp->chan_index = chan = i;
  258. dcp = DDMA_CHANNEL_BASE;
  259. dcp += (0x0100 * chan);
  260. ctp->chan_ptr = (au1x_dma_chan_t *)dcp;
  261. cp = (au1x_dma_chan_t *)dcp;
  262. ctp->chan_src = stp;
  263. ctp->chan_dest = dtp;
  264. ctp->chan_callback = callback;
  265. ctp->chan_callparam = callparam;
  266. /* Initialize channel configuration. */
  267. i = 0;
  268. if (stp->dev_intlevel)
  269. i |= DDMA_CFG_SED;
  270. if (stp->dev_intpolarity)
  271. i |= DDMA_CFG_SP;
  272. if (dtp->dev_intlevel)
  273. i |= DDMA_CFG_DED;
  274. if (dtp->dev_intpolarity)
  275. i |= DDMA_CFG_DP;
  276. if ((stp->dev_flags & DEV_FLAGS_SYNC) ||
  277. (dtp->dev_flags & DEV_FLAGS_SYNC))
  278. i |= DDMA_CFG_SYNC;
  279. cp->ddma_cfg = i;
  280. au_sync();
  281. /*
  282. * Return a non-zero value that can be used to find the channel
  283. * information in subsequent operations.
  284. */
  285. return (u32)(&chan_tab_ptr[chan]);
  286. }
  287. /* Release devices */
  288. stp->dev_flags &= ~DEV_FLAGS_INUSE;
  289. dtp->dev_flags &= ~DEV_FLAGS_INUSE;
  290. return 0;
  291. }
  292. EXPORT_SYMBOL(au1xxx_dbdma_chan_alloc);
  293. /*
  294. * Set the device width if source or destination is a FIFO.
  295. * Should be 8, 16, or 32 bits.
  296. */
  297. u32 au1xxx_dbdma_set_devwidth(u32 chanid, int bits)
  298. {
  299. u32 rv;
  300. chan_tab_t *ctp;
  301. dbdev_tab_t *stp, *dtp;
  302. ctp = *((chan_tab_t **)chanid);
  303. stp = ctp->chan_src;
  304. dtp = ctp->chan_dest;
  305. rv = 0;
  306. if (stp->dev_flags & DEV_FLAGS_IN) { /* Source in fifo */
  307. rv = stp->dev_devwidth;
  308. stp->dev_devwidth = bits;
  309. }
  310. if (dtp->dev_flags & DEV_FLAGS_OUT) { /* Destination out fifo */
  311. rv = dtp->dev_devwidth;
  312. dtp->dev_devwidth = bits;
  313. }
  314. return rv;
  315. }
  316. EXPORT_SYMBOL(au1xxx_dbdma_set_devwidth);
  317. /* Allocate a descriptor ring, initializing as much as possible. */
  318. u32 au1xxx_dbdma_ring_alloc(u32 chanid, int entries)
  319. {
  320. int i;
  321. u32 desc_base, srcid, destid;
  322. u32 cmd0, cmd1, src1, dest1;
  323. u32 src0, dest0;
  324. chan_tab_t *ctp;
  325. dbdev_tab_t *stp, *dtp;
  326. au1x_ddma_desc_t *dp;
  327. /*
  328. * I guess we could check this to be within the
  329. * range of the table......
  330. */
  331. ctp = *((chan_tab_t **)chanid);
  332. stp = ctp->chan_src;
  333. dtp = ctp->chan_dest;
  334. /*
  335. * The descriptors must be 32-byte aligned. There is a
  336. * possibility the allocation will give us such an address,
  337. * and if we try that first we are likely to not waste larger
  338. * slabs of memory.
  339. */
  340. desc_base = (u32)kmalloc(entries * sizeof(au1x_ddma_desc_t),
  341. GFP_KERNEL|GFP_DMA);
  342. if (desc_base == 0)
  343. return 0;
  344. if (desc_base & 0x1f) {
  345. /*
  346. * Lost....do it again, allocate extra, and round
  347. * the address base.
  348. */
  349. kfree((const void *)desc_base);
  350. i = entries * sizeof(au1x_ddma_desc_t);
  351. i += (sizeof(au1x_ddma_desc_t) - 1);
  352. desc_base = (u32)kmalloc(i, GFP_KERNEL|GFP_DMA);
  353. if (desc_base == 0)
  354. return 0;
  355. ctp->cdb_membase = desc_base;
  356. desc_base = ALIGN_ADDR(desc_base, sizeof(au1x_ddma_desc_t));
  357. } else
  358. ctp->cdb_membase = desc_base;
  359. dp = (au1x_ddma_desc_t *)desc_base;
  360. /* Keep track of the base descriptor. */
  361. ctp->chan_desc_base = dp;
  362. /* Initialize the rings with as much information as we know. */
  363. srcid = stp->dev_id;
  364. destid = dtp->dev_id;
  365. cmd0 = cmd1 = src1 = dest1 = 0;
  366. src0 = dest0 = 0;
  367. cmd0 |= DSCR_CMD0_SID(srcid);
  368. cmd0 |= DSCR_CMD0_DID(destid);
  369. cmd0 |= DSCR_CMD0_IE | DSCR_CMD0_CV;
  370. cmd0 |= DSCR_CMD0_ST(DSCR_CMD0_ST_NOCHANGE);
  371. /* Is it mem to mem transfer? */
  372. if (((DSCR_CUSTOM2DEV_ID(srcid) == DSCR_CMD0_THROTTLE) ||
  373. (DSCR_CUSTOM2DEV_ID(srcid) == DSCR_CMD0_ALWAYS)) &&
  374. ((DSCR_CUSTOM2DEV_ID(destid) == DSCR_CMD0_THROTTLE) ||
  375. (DSCR_CUSTOM2DEV_ID(destid) == DSCR_CMD0_ALWAYS)))
  376. cmd0 |= DSCR_CMD0_MEM;
  377. switch (stp->dev_devwidth) {
  378. case 8:
  379. cmd0 |= DSCR_CMD0_SW(DSCR_CMD0_BYTE);
  380. break;
  381. case 16:
  382. cmd0 |= DSCR_CMD0_SW(DSCR_CMD0_HALFWORD);
  383. break;
  384. case 32:
  385. default:
  386. cmd0 |= DSCR_CMD0_SW(DSCR_CMD0_WORD);
  387. break;
  388. }
  389. switch (dtp->dev_devwidth) {
  390. case 8:
  391. cmd0 |= DSCR_CMD0_DW(DSCR_CMD0_BYTE);
  392. break;
  393. case 16:
  394. cmd0 |= DSCR_CMD0_DW(DSCR_CMD0_HALFWORD);
  395. break;
  396. case 32:
  397. default:
  398. cmd0 |= DSCR_CMD0_DW(DSCR_CMD0_WORD);
  399. break;
  400. }
  401. /*
  402. * If the device is marked as an in/out FIFO, ensure it is
  403. * set non-coherent.
  404. */
  405. if (stp->dev_flags & DEV_FLAGS_IN)
  406. cmd0 |= DSCR_CMD0_SN; /* Source in FIFO */
  407. if (dtp->dev_flags & DEV_FLAGS_OUT)
  408. cmd0 |= DSCR_CMD0_DN; /* Destination out FIFO */
  409. /*
  410. * Set up source1. For now, assume no stride and increment.
  411. * A channel attribute update can change this later.
  412. */
  413. switch (stp->dev_tsize) {
  414. case 1:
  415. src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE1);
  416. break;
  417. case 2:
  418. src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE2);
  419. break;
  420. case 4:
  421. src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE4);
  422. break;
  423. case 8:
  424. default:
  425. src1 |= DSCR_SRC1_STS(DSCR_xTS_SIZE8);
  426. break;
  427. }
  428. /* If source input is FIFO, set static address. */
  429. if (stp->dev_flags & DEV_FLAGS_IN) {
  430. if (stp->dev_flags & DEV_FLAGS_BURSTABLE)
  431. src1 |= DSCR_SRC1_SAM(DSCR_xAM_BURST);
  432. else
  433. src1 |= DSCR_SRC1_SAM(DSCR_xAM_STATIC);
  434. }
  435. if (stp->dev_physaddr)
  436. src0 = stp->dev_physaddr;
  437. /*
  438. * Set up dest1. For now, assume no stride and increment.
  439. * A channel attribute update can change this later.
  440. */
  441. switch (dtp->dev_tsize) {
  442. case 1:
  443. dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE1);
  444. break;
  445. case 2:
  446. dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE2);
  447. break;
  448. case 4:
  449. dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE4);
  450. break;
  451. case 8:
  452. default:
  453. dest1 |= DSCR_DEST1_DTS(DSCR_xTS_SIZE8);
  454. break;
  455. }
  456. /* If destination output is FIFO, set static address. */
  457. if (dtp->dev_flags & DEV_FLAGS_OUT) {
  458. if (dtp->dev_flags & DEV_FLAGS_BURSTABLE)
  459. dest1 |= DSCR_DEST1_DAM(DSCR_xAM_BURST);
  460. else
  461. dest1 |= DSCR_DEST1_DAM(DSCR_xAM_STATIC);
  462. }
  463. if (dtp->dev_physaddr)
  464. dest0 = dtp->dev_physaddr;
  465. #if 0
  466. printk(KERN_DEBUG "did:%x sid:%x cmd0:%x cmd1:%x source0:%x "
  467. "source1:%x dest0:%x dest1:%x\n",
  468. dtp->dev_id, stp->dev_id, cmd0, cmd1, src0,
  469. src1, dest0, dest1);
  470. #endif
  471. for (i = 0; i < entries; i++) {
  472. dp->dscr_cmd0 = cmd0;
  473. dp->dscr_cmd1 = cmd1;
  474. dp->dscr_source0 = src0;
  475. dp->dscr_source1 = src1;
  476. dp->dscr_dest0 = dest0;
  477. dp->dscr_dest1 = dest1;
  478. dp->dscr_stat = 0;
  479. dp->sw_context = 0;
  480. dp->sw_status = 0;
  481. dp->dscr_nxtptr = DSCR_NXTPTR(virt_to_phys(dp + 1));
  482. dp++;
  483. }
  484. /* Make last descrptor point to the first. */
  485. dp--;
  486. dp->dscr_nxtptr = DSCR_NXTPTR(virt_to_phys(ctp->chan_desc_base));
  487. ctp->get_ptr = ctp->put_ptr = ctp->cur_ptr = ctp->chan_desc_base;
  488. return (u32)ctp->chan_desc_base;
  489. }
  490. EXPORT_SYMBOL(au1xxx_dbdma_ring_alloc);
  491. /*
  492. * Put a source buffer into the DMA ring.
  493. * This updates the source pointer and byte count. Normally used
  494. * for memory to fifo transfers.
  495. */
  496. u32 au1xxx_dbdma_put_source(u32 chanid, dma_addr_t buf, int nbytes, u32 flags)
  497. {
  498. chan_tab_t *ctp;
  499. au1x_ddma_desc_t *dp;
  500. /*
  501. * I guess we could check this to be within the
  502. * range of the table......
  503. */
  504. ctp = *(chan_tab_t **)chanid;
  505. /*
  506. * We should have multiple callers for a particular channel,
  507. * an interrupt doesn't affect this pointer nor the descriptor,
  508. * so no locking should be needed.
  509. */
  510. dp = ctp->put_ptr;
  511. /*
  512. * If the descriptor is valid, we are way ahead of the DMA
  513. * engine, so just return an error condition.
  514. */
  515. if (dp->dscr_cmd0 & DSCR_CMD0_V)
  516. return 0;
  517. /* Load up buffer address and byte count. */
  518. dp->dscr_source0 = buf & ~0UL;
  519. dp->dscr_cmd1 = nbytes;
  520. /* Check flags */
  521. if (flags & DDMA_FLAGS_IE)
  522. dp->dscr_cmd0 |= DSCR_CMD0_IE;
  523. if (flags & DDMA_FLAGS_NOIE)
  524. dp->dscr_cmd0 &= ~DSCR_CMD0_IE;
  525. /*
  526. * There is an errata on the Au1200/Au1550 parts that could result
  527. * in "stale" data being DMA'ed. It has to do with the snoop logic on
  528. * the cache eviction buffer. DMA_NONCOHERENT is on by default for
  529. * these parts. If it is fixed in the future, these dma_cache_inv will
  530. * just be nothing more than empty macros. See io.h.
  531. */
  532. dma_cache_wback_inv((unsigned long)buf, nbytes);
  533. dp->dscr_cmd0 |= DSCR_CMD0_V; /* Let it rip */
  534. au_sync();
  535. dma_cache_wback_inv((unsigned long)dp, sizeof(*dp));
  536. ctp->chan_ptr->ddma_dbell = 0;
  537. /* Get next descriptor pointer. */
  538. ctp->put_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  539. /* Return something non-zero. */
  540. return nbytes;
  541. }
  542. EXPORT_SYMBOL(au1xxx_dbdma_put_source);
  543. /* Put a destination buffer into the DMA ring.
  544. * This updates the destination pointer and byte count. Normally used
  545. * to place an empty buffer into the ring for fifo to memory transfers.
  546. */
  547. u32 au1xxx_dbdma_put_dest(u32 chanid, dma_addr_t buf, int nbytes, u32 flags)
  548. {
  549. chan_tab_t *ctp;
  550. au1x_ddma_desc_t *dp;
  551. /* I guess we could check this to be within the
  552. * range of the table......
  553. */
  554. ctp = *((chan_tab_t **)chanid);
  555. /* We should have multiple callers for a particular channel,
  556. * an interrupt doesn't affect this pointer nor the descriptor,
  557. * so no locking should be needed.
  558. */
  559. dp = ctp->put_ptr;
  560. /* If the descriptor is valid, we are way ahead of the DMA
  561. * engine, so just return an error condition.
  562. */
  563. if (dp->dscr_cmd0 & DSCR_CMD0_V)
  564. return 0;
  565. /* Load up buffer address and byte count */
  566. /* Check flags */
  567. if (flags & DDMA_FLAGS_IE)
  568. dp->dscr_cmd0 |= DSCR_CMD0_IE;
  569. if (flags & DDMA_FLAGS_NOIE)
  570. dp->dscr_cmd0 &= ~DSCR_CMD0_IE;
  571. dp->dscr_dest0 = buf & ~0UL;
  572. dp->dscr_cmd1 = nbytes;
  573. #if 0
  574. printk(KERN_DEBUG "cmd0:%x cmd1:%x source0:%x source1:%x dest0:%x dest1:%x\n",
  575. dp->dscr_cmd0, dp->dscr_cmd1, dp->dscr_source0,
  576. dp->dscr_source1, dp->dscr_dest0, dp->dscr_dest1);
  577. #endif
  578. /*
  579. * There is an errata on the Au1200/Au1550 parts that could result in
  580. * "stale" data being DMA'ed. It has to do with the snoop logic on the
  581. * cache eviction buffer. DMA_NONCOHERENT is on by default for these
  582. * parts. If it is fixed in the future, these dma_cache_inv will just
  583. * be nothing more than empty macros. See io.h.
  584. */
  585. dma_cache_inv((unsigned long)buf, nbytes);
  586. dp->dscr_cmd0 |= DSCR_CMD0_V; /* Let it rip */
  587. au_sync();
  588. dma_cache_wback_inv((unsigned long)dp, sizeof(*dp));
  589. ctp->chan_ptr->ddma_dbell = 0;
  590. /* Get next descriptor pointer. */
  591. ctp->put_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  592. /* Return something non-zero. */
  593. return nbytes;
  594. }
  595. EXPORT_SYMBOL(au1xxx_dbdma_put_dest);
  596. /*
  597. * Get a destination buffer into the DMA ring.
  598. * Normally used to get a full buffer from the ring during fifo
  599. * to memory transfers. This does not set the valid bit, you will
  600. * have to put another destination buffer to keep the DMA going.
  601. */
  602. u32 au1xxx_dbdma_get_dest(u32 chanid, void **buf, int *nbytes)
  603. {
  604. chan_tab_t *ctp;
  605. au1x_ddma_desc_t *dp;
  606. u32 rv;
  607. /*
  608. * I guess we could check this to be within the
  609. * range of the table......
  610. */
  611. ctp = *((chan_tab_t **)chanid);
  612. /*
  613. * We should have multiple callers for a particular channel,
  614. * an interrupt doesn't affect this pointer nor the descriptor,
  615. * so no locking should be needed.
  616. */
  617. dp = ctp->get_ptr;
  618. /*
  619. * If the descriptor is valid, we are way ahead of the DMA
  620. * engine, so just return an error condition.
  621. */
  622. if (dp->dscr_cmd0 & DSCR_CMD0_V)
  623. return 0;
  624. /* Return buffer address and byte count. */
  625. *buf = (void *)(phys_to_virt(dp->dscr_dest0));
  626. *nbytes = dp->dscr_cmd1;
  627. rv = dp->dscr_stat;
  628. /* Get next descriptor pointer. */
  629. ctp->get_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  630. /* Return something non-zero. */
  631. return rv;
  632. }
  633. EXPORT_SYMBOL_GPL(au1xxx_dbdma_get_dest);
  634. void au1xxx_dbdma_stop(u32 chanid)
  635. {
  636. chan_tab_t *ctp;
  637. au1x_dma_chan_t *cp;
  638. int halt_timeout = 0;
  639. ctp = *((chan_tab_t **)chanid);
  640. cp = ctp->chan_ptr;
  641. cp->ddma_cfg &= ~DDMA_CFG_EN; /* Disable channel */
  642. au_sync();
  643. while (!(cp->ddma_stat & DDMA_STAT_H)) {
  644. udelay(1);
  645. halt_timeout++;
  646. if (halt_timeout > 100) {
  647. printk(KERN_WARNING "warning: DMA channel won't halt\n");
  648. break;
  649. }
  650. }
  651. /* clear current desc valid and doorbell */
  652. cp->ddma_stat |= (DDMA_STAT_DB | DDMA_STAT_V);
  653. au_sync();
  654. }
  655. EXPORT_SYMBOL(au1xxx_dbdma_stop);
  656. /*
  657. * Start using the current descriptor pointer. If the DBDMA encounters
  658. * a non-valid descriptor, it will stop. In this case, we can just
  659. * continue by adding a buffer to the list and starting again.
  660. */
  661. void au1xxx_dbdma_start(u32 chanid)
  662. {
  663. chan_tab_t *ctp;
  664. au1x_dma_chan_t *cp;
  665. ctp = *((chan_tab_t **)chanid);
  666. cp = ctp->chan_ptr;
  667. cp->ddma_desptr = virt_to_phys(ctp->cur_ptr);
  668. cp->ddma_cfg |= DDMA_CFG_EN; /* Enable channel */
  669. au_sync();
  670. cp->ddma_dbell = 0;
  671. au_sync();
  672. }
  673. EXPORT_SYMBOL(au1xxx_dbdma_start);
  674. void au1xxx_dbdma_reset(u32 chanid)
  675. {
  676. chan_tab_t *ctp;
  677. au1x_ddma_desc_t *dp;
  678. au1xxx_dbdma_stop(chanid);
  679. ctp = *((chan_tab_t **)chanid);
  680. ctp->get_ptr = ctp->put_ptr = ctp->cur_ptr = ctp->chan_desc_base;
  681. /* Run through the descriptors and reset the valid indicator. */
  682. dp = ctp->chan_desc_base;
  683. do {
  684. dp->dscr_cmd0 &= ~DSCR_CMD0_V;
  685. /*
  686. * Reset our software status -- this is used to determine
  687. * if a descriptor is in use by upper level software. Since
  688. * posting can reset 'V' bit.
  689. */
  690. dp->sw_status = 0;
  691. dp = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  692. } while (dp != ctp->chan_desc_base);
  693. }
  694. EXPORT_SYMBOL(au1xxx_dbdma_reset);
  695. u32 au1xxx_get_dma_residue(u32 chanid)
  696. {
  697. chan_tab_t *ctp;
  698. au1x_dma_chan_t *cp;
  699. u32 rv;
  700. ctp = *((chan_tab_t **)chanid);
  701. cp = ctp->chan_ptr;
  702. /* This is only valid if the channel is stopped. */
  703. rv = cp->ddma_bytecnt;
  704. au_sync();
  705. return rv;
  706. }
  707. EXPORT_SYMBOL_GPL(au1xxx_get_dma_residue);
  708. void au1xxx_dbdma_chan_free(u32 chanid)
  709. {
  710. chan_tab_t *ctp;
  711. dbdev_tab_t *stp, *dtp;
  712. ctp = *((chan_tab_t **)chanid);
  713. stp = ctp->chan_src;
  714. dtp = ctp->chan_dest;
  715. au1xxx_dbdma_stop(chanid);
  716. kfree((void *)ctp->cdb_membase);
  717. stp->dev_flags &= ~DEV_FLAGS_INUSE;
  718. dtp->dev_flags &= ~DEV_FLAGS_INUSE;
  719. chan_tab_ptr[ctp->chan_index] = NULL;
  720. kfree(ctp);
  721. }
  722. EXPORT_SYMBOL(au1xxx_dbdma_chan_free);
  723. static irqreturn_t dbdma_interrupt(int irq, void *dev_id)
  724. {
  725. u32 intstat;
  726. u32 chan_index;
  727. chan_tab_t *ctp;
  728. au1x_ddma_desc_t *dp;
  729. au1x_dma_chan_t *cp;
  730. intstat = dbdma_gptr->ddma_intstat;
  731. au_sync();
  732. chan_index = __ffs(intstat);
  733. ctp = chan_tab_ptr[chan_index];
  734. cp = ctp->chan_ptr;
  735. dp = ctp->cur_ptr;
  736. /* Reset interrupt. */
  737. cp->ddma_irq = 0;
  738. au_sync();
  739. if (ctp->chan_callback)
  740. ctp->chan_callback(irq, ctp->chan_callparam);
  741. ctp->cur_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  742. return IRQ_RETVAL(1);
  743. }
  744. void au1xxx_dbdma_dump(u32 chanid)
  745. {
  746. chan_tab_t *ctp;
  747. au1x_ddma_desc_t *dp;
  748. dbdev_tab_t *stp, *dtp;
  749. au1x_dma_chan_t *cp;
  750. u32 i = 0;
  751. ctp = *((chan_tab_t **)chanid);
  752. stp = ctp->chan_src;
  753. dtp = ctp->chan_dest;
  754. cp = ctp->chan_ptr;
  755. printk(KERN_DEBUG "Chan %x, stp %x (dev %d) dtp %x (dev %d)\n",
  756. (u32)ctp, (u32)stp, stp - dbdev_tab, (u32)dtp,
  757. dtp - dbdev_tab);
  758. printk(KERN_DEBUG "desc base %x, get %x, put %x, cur %x\n",
  759. (u32)(ctp->chan_desc_base), (u32)(ctp->get_ptr),
  760. (u32)(ctp->put_ptr), (u32)(ctp->cur_ptr));
  761. printk(KERN_DEBUG "dbdma chan %x\n", (u32)cp);
  762. printk(KERN_DEBUG "cfg %08x, desptr %08x, statptr %08x\n",
  763. cp->ddma_cfg, cp->ddma_desptr, cp->ddma_statptr);
  764. printk(KERN_DEBUG "dbell %08x, irq %08x, stat %08x, bytecnt %08x\n",
  765. cp->ddma_dbell, cp->ddma_irq, cp->ddma_stat,
  766. cp->ddma_bytecnt);
  767. /* Run through the descriptors */
  768. dp = ctp->chan_desc_base;
  769. do {
  770. printk(KERN_DEBUG "Dp[%d]= %08x, cmd0 %08x, cmd1 %08x\n",
  771. i++, (u32)dp, dp->dscr_cmd0, dp->dscr_cmd1);
  772. printk(KERN_DEBUG "src0 %08x, src1 %08x, dest0 %08x, dest1 %08x\n",
  773. dp->dscr_source0, dp->dscr_source1,
  774. dp->dscr_dest0, dp->dscr_dest1);
  775. printk(KERN_DEBUG "stat %08x, nxtptr %08x\n",
  776. dp->dscr_stat, dp->dscr_nxtptr);
  777. dp = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  778. } while (dp != ctp->chan_desc_base);
  779. }
  780. /* Put a descriptor into the DMA ring.
  781. * This updates the source/destination pointers and byte count.
  782. */
  783. u32 au1xxx_dbdma_put_dscr(u32 chanid, au1x_ddma_desc_t *dscr)
  784. {
  785. chan_tab_t *ctp;
  786. au1x_ddma_desc_t *dp;
  787. u32 nbytes = 0;
  788. /*
  789. * I guess we could check this to be within the
  790. * range of the table......
  791. */
  792. ctp = *((chan_tab_t **)chanid);
  793. /*
  794. * We should have multiple callers for a particular channel,
  795. * an interrupt doesn't affect this pointer nor the descriptor,
  796. * so no locking should be needed.
  797. */
  798. dp = ctp->put_ptr;
  799. /*
  800. * If the descriptor is valid, we are way ahead of the DMA
  801. * engine, so just return an error condition.
  802. */
  803. if (dp->dscr_cmd0 & DSCR_CMD0_V)
  804. return 0;
  805. /* Load up buffer addresses and byte count. */
  806. dp->dscr_dest0 = dscr->dscr_dest0;
  807. dp->dscr_source0 = dscr->dscr_source0;
  808. dp->dscr_dest1 = dscr->dscr_dest1;
  809. dp->dscr_source1 = dscr->dscr_source1;
  810. dp->dscr_cmd1 = dscr->dscr_cmd1;
  811. nbytes = dscr->dscr_cmd1;
  812. /* Allow the caller to specifiy if an interrupt is generated */
  813. dp->dscr_cmd0 &= ~DSCR_CMD0_IE;
  814. dp->dscr_cmd0 |= dscr->dscr_cmd0 | DSCR_CMD0_V;
  815. ctp->chan_ptr->ddma_dbell = 0;
  816. /* Get next descriptor pointer. */
  817. ctp->put_ptr = phys_to_virt(DSCR_GET_NXTPTR(dp->dscr_nxtptr));
  818. /* Return something non-zero. */
  819. return nbytes;
  820. }
  821. #ifdef CONFIG_PM
  822. void au1xxx_dbdma_suspend(void)
  823. {
  824. int i;
  825. u32 addr;
  826. addr = DDMA_GLOBAL_BASE;
  827. au1xxx_dbdma_pm_regs[0][0] = au_readl(addr + 0x00);
  828. au1xxx_dbdma_pm_regs[0][1] = au_readl(addr + 0x04);
  829. au1xxx_dbdma_pm_regs[0][2] = au_readl(addr + 0x08);
  830. au1xxx_dbdma_pm_regs[0][3] = au_readl(addr + 0x0c);
  831. /* save channel configurations */
  832. for (i = 1, addr = DDMA_CHANNEL_BASE; i <= NUM_DBDMA_CHANS; i++) {
  833. au1xxx_dbdma_pm_regs[i][0] = au_readl(addr + 0x00);
  834. au1xxx_dbdma_pm_regs[i][1] = au_readl(addr + 0x04);
  835. au1xxx_dbdma_pm_regs[i][2] = au_readl(addr + 0x08);
  836. au1xxx_dbdma_pm_regs[i][3] = au_readl(addr + 0x0c);
  837. au1xxx_dbdma_pm_regs[i][4] = au_readl(addr + 0x10);
  838. au1xxx_dbdma_pm_regs[i][5] = au_readl(addr + 0x14);
  839. /* halt channel */
  840. au_writel(au1xxx_dbdma_pm_regs[i][0] & ~1, addr + 0x00);
  841. au_sync();
  842. while (!(au_readl(addr + 0x14) & 1))
  843. au_sync();
  844. addr += 0x100; /* next channel base */
  845. }
  846. /* disable channel interrupts */
  847. au_writel(0, DDMA_GLOBAL_BASE + 0x0c);
  848. au_sync();
  849. }
  850. void au1xxx_dbdma_resume(void)
  851. {
  852. int i;
  853. u32 addr;
  854. addr = DDMA_GLOBAL_BASE;
  855. au_writel(au1xxx_dbdma_pm_regs[0][0], addr + 0x00);
  856. au_writel(au1xxx_dbdma_pm_regs[0][1], addr + 0x04);
  857. au_writel(au1xxx_dbdma_pm_regs[0][2], addr + 0x08);
  858. au_writel(au1xxx_dbdma_pm_regs[0][3], addr + 0x0c);
  859. /* restore channel configurations */
  860. for (i = 1, addr = DDMA_CHANNEL_BASE; i <= NUM_DBDMA_CHANS; i++) {
  861. au_writel(au1xxx_dbdma_pm_regs[i][0], addr + 0x00);
  862. au_writel(au1xxx_dbdma_pm_regs[i][1], addr + 0x04);
  863. au_writel(au1xxx_dbdma_pm_regs[i][2], addr + 0x08);
  864. au_writel(au1xxx_dbdma_pm_regs[i][3], addr + 0x0c);
  865. au_writel(au1xxx_dbdma_pm_regs[i][4], addr + 0x10);
  866. au_writel(au1xxx_dbdma_pm_regs[i][5], addr + 0x14);
  867. au_sync();
  868. addr += 0x100; /* next channel base */
  869. }
  870. }
  871. #endif /* CONFIG_PM */
  872. static int __init au1xxx_dbdma_init(void)
  873. {
  874. int irq_nr, ret;
  875. dbdma_gptr->ddma_config = 0;
  876. dbdma_gptr->ddma_throttle = 0;
  877. dbdma_gptr->ddma_inten = 0xffff;
  878. au_sync();
  879. switch (alchemy_get_cputype()) {
  880. case ALCHEMY_CPU_AU1550:
  881. irq_nr = AU1550_DDMA_INT;
  882. break;
  883. case ALCHEMY_CPU_AU1200:
  884. irq_nr = AU1200_DDMA_INT;
  885. break;
  886. default:
  887. return -ENODEV;
  888. }
  889. ret = request_irq(irq_nr, dbdma_interrupt, IRQF_DISABLED,
  890. "Au1xxx dbdma", (void *)dbdma_gptr);
  891. if (ret)
  892. printk(KERN_ERR "Cannot grab DBDMA interrupt!\n");
  893. else {
  894. dbdma_initialized = 1;
  895. printk(KERN_INFO "Alchemy DBDMA initialized\n");
  896. }
  897. return ret;
  898. }
  899. subsys_initcall(au1xxx_dbdma_init);
  900. #endif /* defined(CONFIG_SOC_AU1550) || defined(CONFIG_SOC_AU1200) */