dbdma.c 29 KB

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