dbdma.c 32 KB

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