dbdma.c 32 KB

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