dbdma.c 29 KB

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