dbdma.c 29 KB

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