dma.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /* linux/arch/arm/plat-s3c64xx/dma.c
  2. *
  3. * Copyright 2009 Openmoko, Inc.
  4. * Copyright 2009 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * S3C64XX DMA core
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/dmapool.h>
  18. #include <linux/sysdev.h>
  19. #include <linux/errno.h>
  20. #include <linux/delay.h>
  21. #include <linux/clk.h>
  22. #include <linux/err.h>
  23. #include <linux/io.h>
  24. #include <mach/dma.h>
  25. #include <mach/map.h>
  26. #include <mach/irqs.h>
  27. #include <mach/regs-sys.h>
  28. #include <asm/hardware/pl080.h>
  29. /* dma channel state information */
  30. struct s3c64xx_dmac {
  31. struct sys_device sysdev;
  32. struct clk *clk;
  33. void __iomem *regs;
  34. struct s3c2410_dma_chan *channels;
  35. enum dma_ch chanbase;
  36. };
  37. /* pool to provide LLI buffers */
  38. static struct dma_pool *dma_pool;
  39. /* Debug configuration and code */
  40. static unsigned char debug_show_buffs = 0;
  41. static void dbg_showchan(struct s3c2410_dma_chan *chan)
  42. {
  43. pr_debug("DMA%d: %08x->%08x L %08x C %08x,%08x S %08x\n",
  44. chan->number,
  45. readl(chan->regs + PL080_CH_SRC_ADDR),
  46. readl(chan->regs + PL080_CH_DST_ADDR),
  47. readl(chan->regs + PL080_CH_LLI),
  48. readl(chan->regs + PL080_CH_CONTROL),
  49. readl(chan->regs + PL080S_CH_CONTROL2),
  50. readl(chan->regs + PL080S_CH_CONFIG));
  51. }
  52. static void show_lli(struct pl080s_lli *lli)
  53. {
  54. pr_debug("LLI[%p] %08x->%08x, NL %08x C %08x,%08x\n",
  55. lli, lli->src_addr, lli->dst_addr, lli->next_lli,
  56. lli->control0, lli->control1);
  57. }
  58. static void dbg_showbuffs(struct s3c2410_dma_chan *chan)
  59. {
  60. struct s3c64xx_dma_buff *ptr;
  61. struct s3c64xx_dma_buff *end;
  62. pr_debug("DMA%d: buffs next %p, curr %p, end %p\n",
  63. chan->number, chan->next, chan->curr, chan->end);
  64. ptr = chan->next;
  65. end = chan->end;
  66. if (debug_show_buffs) {
  67. for (; ptr != NULL; ptr = ptr->next) {
  68. pr_debug("DMA%d: %08x ",
  69. chan->number, ptr->lli_dma);
  70. show_lli(ptr->lli);
  71. }
  72. }
  73. }
  74. /* End of Debug */
  75. static struct s3c2410_dma_chan *s3c64xx_dma_map_channel(unsigned int channel)
  76. {
  77. struct s3c2410_dma_chan *chan;
  78. unsigned int start, offs;
  79. start = 0;
  80. if (channel >= DMACH_PCM1_TX)
  81. start = 8;
  82. for (offs = 0; offs < 8; offs++) {
  83. chan = &s3c2410_chans[start + offs];
  84. if (!chan->in_use)
  85. goto found;
  86. }
  87. return NULL;
  88. found:
  89. s3c_dma_chan_map[channel] = chan;
  90. return chan;
  91. }
  92. int s3c2410_dma_config(unsigned int channel, int xferunit)
  93. {
  94. struct s3c2410_dma_chan *chan = s3c_dma_lookup_channel(channel);
  95. if (chan == NULL)
  96. return -EINVAL;
  97. switch (xferunit) {
  98. case 1:
  99. chan->hw_width = 0;
  100. break;
  101. case 2:
  102. chan->hw_width = 1;
  103. break;
  104. case 4:
  105. chan->hw_width = 2;
  106. break;
  107. default:
  108. printk(KERN_ERR "%s: illegal width %d\n", __func__, xferunit);
  109. return -EINVAL;
  110. }
  111. return 0;
  112. }
  113. EXPORT_SYMBOL(s3c2410_dma_config);
  114. static void s3c64xx_dma_fill_lli(struct s3c2410_dma_chan *chan,
  115. struct pl080s_lli *lli,
  116. dma_addr_t data, int size)
  117. {
  118. dma_addr_t src, dst;
  119. u32 control0, control1;
  120. switch (chan->source) {
  121. case S3C2410_DMASRC_HW:
  122. src = chan->dev_addr;
  123. dst = data;
  124. control0 = PL080_CONTROL_SRC_AHB2;
  125. control0 |= PL080_CONTROL_DST_INCR;
  126. break;
  127. case S3C2410_DMASRC_MEM:
  128. src = data;
  129. dst = chan->dev_addr;
  130. control0 = PL080_CONTROL_DST_AHB2;
  131. control0 |= PL080_CONTROL_SRC_INCR;
  132. break;
  133. default:
  134. BUG();
  135. }
  136. /* note, we do not currently setup any of the burst controls */
  137. control1 = size >> chan->hw_width; /* size in no of xfers */
  138. control0 |= PL080_CONTROL_PROT_SYS; /* always in priv. mode */
  139. control0 |= PL080_CONTROL_TC_IRQ_EN; /* always fire IRQ */
  140. control0 |= (u32)chan->hw_width << PL080_CONTROL_DWIDTH_SHIFT;
  141. control0 |= (u32)chan->hw_width << PL080_CONTROL_SWIDTH_SHIFT;
  142. lli->src_addr = src;
  143. lli->dst_addr = dst;
  144. lli->next_lli = 0;
  145. lli->control0 = control0;
  146. lli->control1 = control1;
  147. }
  148. static void s3c64xx_lli_to_regs(struct s3c2410_dma_chan *chan,
  149. struct pl080s_lli *lli)
  150. {
  151. void __iomem *regs = chan->regs;
  152. pr_debug("%s: LLI %p => regs\n", __func__, lli);
  153. show_lli(lli);
  154. writel(lli->src_addr, regs + PL080_CH_SRC_ADDR);
  155. writel(lli->dst_addr, regs + PL080_CH_DST_ADDR);
  156. writel(lli->next_lli, regs + PL080_CH_LLI);
  157. writel(lli->control0, regs + PL080_CH_CONTROL);
  158. writel(lli->control1, regs + PL080S_CH_CONTROL2);
  159. }
  160. static int s3c64xx_dma_start(struct s3c2410_dma_chan *chan)
  161. {
  162. struct s3c64xx_dmac *dmac = chan->dmac;
  163. u32 config;
  164. u32 bit = chan->bit;
  165. dbg_showchan(chan);
  166. pr_debug("%s: clearing interrupts\n", __func__);
  167. /* clear interrupts */
  168. writel(bit, dmac->regs + PL080_TC_CLEAR);
  169. writel(bit, dmac->regs + PL080_ERR_CLEAR);
  170. pr_debug("%s: starting channel\n", __func__);
  171. config = readl(chan->regs + PL080S_CH_CONFIG);
  172. config |= PL080_CONFIG_ENABLE;
  173. pr_debug("%s: writing config %08x\n", __func__, config);
  174. writel(config, chan->regs + PL080S_CH_CONFIG);
  175. return 0;
  176. }
  177. static int s3c64xx_dma_stop(struct s3c2410_dma_chan *chan)
  178. {
  179. u32 config;
  180. int timeout;
  181. pr_debug("%s: stopping channel\n", __func__);
  182. dbg_showchan(chan);
  183. config = readl(chan->regs + PL080S_CH_CONFIG);
  184. config |= PL080_CONFIG_HALT;
  185. writel(config, chan->regs + PL080S_CH_CONFIG);
  186. timeout = 1000;
  187. do {
  188. config = readl(chan->regs + PL080S_CH_CONFIG);
  189. pr_debug("%s: %d - config %08x\n", __func__, timeout, config);
  190. if (config & PL080_CONFIG_ACTIVE)
  191. udelay(10);
  192. else
  193. break;
  194. } while (--timeout > 0);
  195. if (config & PL080_CONFIG_ACTIVE) {
  196. printk(KERN_ERR "%s: channel still active\n", __func__);
  197. return -EFAULT;
  198. }
  199. config = readl(chan->regs + PL080S_CH_CONFIG);
  200. config &= ~PL080_CONFIG_ENABLE;
  201. writel(config, chan->regs + PL080S_CH_CONFIG);
  202. return 0;
  203. }
  204. static inline void s3c64xx_dma_bufffdone(struct s3c2410_dma_chan *chan,
  205. struct s3c64xx_dma_buff *buf,
  206. enum s3c2410_dma_buffresult result)
  207. {
  208. if (chan->callback_fn != NULL)
  209. (chan->callback_fn)(chan, buf->pw, 0, result);
  210. }
  211. static void s3c64xx_dma_freebuff(struct s3c64xx_dma_buff *buff)
  212. {
  213. dma_pool_free(dma_pool, buff->lli, buff->lli_dma);
  214. kfree(buff);
  215. }
  216. static int s3c64xx_dma_flush(struct s3c2410_dma_chan *chan)
  217. {
  218. struct s3c64xx_dma_buff *buff, *next;
  219. u32 config;
  220. dbg_showchan(chan);
  221. pr_debug("%s: flushing channel\n", __func__);
  222. config = readl(chan->regs + PL080S_CH_CONFIG);
  223. config &= ~PL080_CONFIG_ENABLE;
  224. writel(config, chan->regs + PL080S_CH_CONFIG);
  225. /* dump all the buffers associated with this channel */
  226. for (buff = chan->curr; buff != NULL; buff = next) {
  227. next = buff->next;
  228. pr_debug("%s: buff %p (next %p)\n", __func__, buff, buff->next);
  229. s3c64xx_dma_bufffdone(chan, buff, S3C2410_RES_ABORT);
  230. s3c64xx_dma_freebuff(buff);
  231. }
  232. chan->curr = chan->next = chan->end = NULL;
  233. return 0;
  234. }
  235. int s3c2410_dma_ctrl(unsigned int channel, enum s3c2410_chan_op op)
  236. {
  237. struct s3c2410_dma_chan *chan = s3c_dma_lookup_channel(channel);
  238. WARN_ON(!chan);
  239. if (!chan)
  240. return -EINVAL;
  241. switch (op) {
  242. case S3C2410_DMAOP_START:
  243. return s3c64xx_dma_start(chan);
  244. case S3C2410_DMAOP_STOP:
  245. return s3c64xx_dma_stop(chan);
  246. case S3C2410_DMAOP_FLUSH:
  247. return s3c64xx_dma_flush(chan);
  248. /* belive PAUSE/RESUME are no-ops */
  249. case S3C2410_DMAOP_PAUSE:
  250. case S3C2410_DMAOP_RESUME:
  251. case S3C2410_DMAOP_STARTED:
  252. case S3C2410_DMAOP_TIMEOUT:
  253. return 0;
  254. }
  255. return -ENOENT;
  256. }
  257. EXPORT_SYMBOL(s3c2410_dma_ctrl);
  258. /* s3c2410_dma_enque
  259. *
  260. */
  261. int s3c2410_dma_enqueue(unsigned int channel, void *id,
  262. dma_addr_t data, int size)
  263. {
  264. struct s3c2410_dma_chan *chan = s3c_dma_lookup_channel(channel);
  265. struct s3c64xx_dma_buff *next;
  266. struct s3c64xx_dma_buff *buff;
  267. struct pl080s_lli *lli;
  268. unsigned long flags;
  269. int ret;
  270. WARN_ON(!chan);
  271. if (!chan)
  272. return -EINVAL;
  273. buff = kzalloc(sizeof(struct s3c64xx_dma_buff), GFP_ATOMIC);
  274. if (!buff) {
  275. printk(KERN_ERR "%s: no memory for buffer\n", __func__);
  276. return -ENOMEM;
  277. }
  278. lli = dma_pool_alloc(dma_pool, GFP_ATOMIC, &buff->lli_dma);
  279. if (!lli) {
  280. printk(KERN_ERR "%s: no memory for lli\n", __func__);
  281. ret = -ENOMEM;
  282. goto err_buff;
  283. }
  284. pr_debug("%s: buff %p, dp %08x lli (%p, %08x) %d\n",
  285. __func__, buff, data, lli, (u32)buff->lli_dma, size);
  286. buff->lli = lli;
  287. buff->pw = id;
  288. s3c64xx_dma_fill_lli(chan, lli, data, size);
  289. local_irq_save(flags);
  290. if ((next = chan->next) != NULL) {
  291. struct s3c64xx_dma_buff *end = chan->end;
  292. struct pl080s_lli *endlli = end->lli;
  293. pr_debug("enquing onto channel\n");
  294. end->next = buff;
  295. endlli->next_lli = buff->lli_dma;
  296. if (chan->flags & S3C2410_DMAF_CIRCULAR) {
  297. struct s3c64xx_dma_buff *curr = chan->curr;
  298. lli->next_lli = curr->lli_dma;
  299. }
  300. if (next == chan->curr) {
  301. writel(buff->lli_dma, chan->regs + PL080_CH_LLI);
  302. chan->next = buff;
  303. }
  304. show_lli(endlli);
  305. chan->end = buff;
  306. } else {
  307. pr_debug("enquing onto empty channel\n");
  308. chan->curr = buff;
  309. chan->next = buff;
  310. chan->end = buff;
  311. s3c64xx_lli_to_regs(chan, lli);
  312. }
  313. local_irq_restore(flags);
  314. show_lli(lli);
  315. dbg_showchan(chan);
  316. dbg_showbuffs(chan);
  317. return 0;
  318. err_buff:
  319. kfree(buff);
  320. return ret;
  321. }
  322. EXPORT_SYMBOL(s3c2410_dma_enqueue);
  323. int s3c2410_dma_devconfig(int channel,
  324. enum s3c2410_dmasrc source,
  325. unsigned long devaddr)
  326. {
  327. struct s3c2410_dma_chan *chan = s3c_dma_lookup_channel(channel);
  328. u32 peripheral;
  329. u32 config = 0;
  330. pr_debug("%s: channel %d, source %d, dev %08lx, chan %p\n",
  331. __func__, channel, source, devaddr, chan);
  332. WARN_ON(!chan);
  333. if (!chan)
  334. return -EINVAL;
  335. peripheral = (chan->peripheral & 0xf);
  336. chan->source = source;
  337. chan->dev_addr = devaddr;
  338. pr_debug("%s: peripheral %d\n", __func__, peripheral);
  339. switch (source) {
  340. case S3C2410_DMASRC_HW:
  341. config = 2 << PL080_CONFIG_FLOW_CONTROL_SHIFT;
  342. config |= peripheral << PL080_CONFIG_SRC_SEL_SHIFT;
  343. break;
  344. case S3C2410_DMASRC_MEM:
  345. config = 1 << PL080_CONFIG_FLOW_CONTROL_SHIFT;
  346. config |= peripheral << PL080_CONFIG_DST_SEL_SHIFT;
  347. break;
  348. default:
  349. printk(KERN_ERR "%s: bad source\n", __func__);
  350. return -EINVAL;
  351. }
  352. /* allow TC and ERR interrupts */
  353. config |= PL080_CONFIG_TC_IRQ_MASK;
  354. config |= PL080_CONFIG_ERR_IRQ_MASK;
  355. pr_debug("%s: config %08x\n", __func__, config);
  356. writel(config, chan->regs + PL080S_CH_CONFIG);
  357. return 0;
  358. }
  359. EXPORT_SYMBOL(s3c2410_dma_devconfig);
  360. int s3c2410_dma_getposition(unsigned int channel,
  361. dma_addr_t *src, dma_addr_t *dst)
  362. {
  363. struct s3c2410_dma_chan *chan = s3c_dma_lookup_channel(channel);
  364. WARN_ON(!chan);
  365. if (!chan)
  366. return -EINVAL;
  367. if (src != NULL)
  368. *src = readl(chan->regs + PL080_CH_SRC_ADDR);
  369. if (dst != NULL)
  370. *dst = readl(chan->regs + PL080_CH_DST_ADDR);
  371. return 0;
  372. }
  373. EXPORT_SYMBOL(s3c2410_dma_getposition);
  374. /* s3c2410_request_dma
  375. *
  376. * get control of an dma channel
  377. */
  378. int s3c2410_dma_request(unsigned int channel,
  379. struct s3c2410_dma_client *client,
  380. void *dev)
  381. {
  382. struct s3c2410_dma_chan *chan;
  383. unsigned long flags;
  384. pr_debug("dma%d: s3c2410_request_dma: client=%s, dev=%p\n",
  385. channel, client->name, dev);
  386. local_irq_save(flags);
  387. chan = s3c64xx_dma_map_channel(channel);
  388. if (chan == NULL) {
  389. local_irq_restore(flags);
  390. return -EBUSY;
  391. }
  392. dbg_showchan(chan);
  393. chan->client = client;
  394. chan->in_use = 1;
  395. chan->peripheral = channel;
  396. local_irq_restore(flags);
  397. /* need to setup */
  398. pr_debug("%s: channel initialised, %p\n", __func__, chan);
  399. return chan->number | DMACH_LOW_LEVEL;
  400. }
  401. EXPORT_SYMBOL(s3c2410_dma_request);
  402. /* s3c2410_dma_free
  403. *
  404. * release the given channel back to the system, will stop and flush
  405. * any outstanding transfers, and ensure the channel is ready for the
  406. * next claimant.
  407. *
  408. * Note, although a warning is currently printed if the freeing client
  409. * info is not the same as the registrant's client info, the free is still
  410. * allowed to go through.
  411. */
  412. int s3c2410_dma_free(unsigned int channel, struct s3c2410_dma_client *client)
  413. {
  414. struct s3c2410_dma_chan *chan = s3c_dma_lookup_channel(channel);
  415. unsigned long flags;
  416. if (chan == NULL)
  417. return -EINVAL;
  418. local_irq_save(flags);
  419. if (chan->client != client) {
  420. printk(KERN_WARNING "dma%d: possible free from different client (channel %p, passed %p)\n",
  421. channel, chan->client, client);
  422. }
  423. /* sort out stopping and freeing the channel */
  424. chan->client = NULL;
  425. chan->in_use = 0;
  426. if (!(channel & DMACH_LOW_LEVEL))
  427. s3c_dma_chan_map[channel] = NULL;
  428. local_irq_restore(flags);
  429. return 0;
  430. }
  431. EXPORT_SYMBOL(s3c2410_dma_free);
  432. static irqreturn_t s3c64xx_dma_irq(int irq, void *pw)
  433. {
  434. struct s3c64xx_dmac *dmac = pw;
  435. struct s3c2410_dma_chan *chan;
  436. enum s3c2410_dma_buffresult res;
  437. u32 tcstat, errstat;
  438. u32 bit;
  439. int offs;
  440. tcstat = readl(dmac->regs + PL080_TC_STATUS);
  441. errstat = readl(dmac->regs + PL080_ERR_STATUS);
  442. for (offs = 0, bit = 1; offs < 8; offs++, bit <<= 1) {
  443. struct s3c64xx_dma_buff *buff;
  444. if (!(errstat & bit) && !(tcstat & bit))
  445. continue;
  446. chan = dmac->channels + offs;
  447. res = S3C2410_RES_ERR;
  448. if (tcstat & bit) {
  449. writel(bit, dmac->regs + PL080_TC_CLEAR);
  450. res = S3C2410_RES_OK;
  451. }
  452. if (errstat & bit)
  453. writel(bit, dmac->regs + PL080_ERR_CLEAR);
  454. /* 'next' points to the buffer that is next to the
  455. * currently active buffer.
  456. * For CIRCULAR queues, 'next' will be same as 'curr'
  457. * when 'end' is the active buffer.
  458. */
  459. buff = chan->curr;
  460. while (buff && buff != chan->next
  461. && buff->next != chan->next)
  462. buff = buff->next;
  463. if (!buff)
  464. BUG();
  465. if (buff == chan->next)
  466. buff = chan->end;
  467. s3c64xx_dma_bufffdone(chan, buff, res);
  468. /* Free the node and update curr, if non-circular queue */
  469. if (!(chan->flags & S3C2410_DMAF_CIRCULAR)) {
  470. chan->curr = buff->next;
  471. s3c64xx_dma_freebuff(buff);
  472. }
  473. /* Update 'next' */
  474. buff = chan->next;
  475. if (chan->next == chan->end) {
  476. chan->next = chan->curr;
  477. if (!(chan->flags & S3C2410_DMAF_CIRCULAR))
  478. chan->end = NULL;
  479. } else {
  480. chan->next = buff->next;
  481. }
  482. }
  483. return IRQ_HANDLED;
  484. }
  485. static struct sysdev_class dma_sysclass = {
  486. .name = "s3c64xx-dma",
  487. };
  488. static int s3c64xx_dma_init1(int chno, enum dma_ch chbase,
  489. int irq, unsigned int base)
  490. {
  491. struct s3c2410_dma_chan *chptr = &s3c2410_chans[chno];
  492. struct s3c64xx_dmac *dmac;
  493. char clkname[16];
  494. void __iomem *regs;
  495. void __iomem *regptr;
  496. int err, ch;
  497. dmac = kzalloc(sizeof(struct s3c64xx_dmac), GFP_KERNEL);
  498. if (!dmac) {
  499. printk(KERN_ERR "%s: failed to alloc mem\n", __func__);
  500. return -ENOMEM;
  501. }
  502. dmac->sysdev.id = chno / 8;
  503. dmac->sysdev.cls = &dma_sysclass;
  504. err = sysdev_register(&dmac->sysdev);
  505. if (err) {
  506. printk(KERN_ERR "%s: failed to register sysdevice\n", __func__);
  507. goto err_alloc;
  508. }
  509. regs = ioremap(base, 0x200);
  510. if (!regs) {
  511. printk(KERN_ERR "%s: failed to ioremap()\n", __func__);
  512. err = -ENXIO;
  513. goto err_dev;
  514. }
  515. snprintf(clkname, sizeof(clkname), "dma%d", dmac->sysdev.id);
  516. dmac->clk = clk_get(NULL, clkname);
  517. if (IS_ERR(dmac->clk)) {
  518. printk(KERN_ERR "%s: failed to get clock %s\n", __func__, clkname);
  519. err = PTR_ERR(dmac->clk);
  520. goto err_map;
  521. }
  522. clk_enable(dmac->clk);
  523. dmac->regs = regs;
  524. dmac->chanbase = chbase;
  525. dmac->channels = chptr;
  526. err = request_irq(irq, s3c64xx_dma_irq, 0, "DMA", dmac);
  527. if (err < 0) {
  528. printk(KERN_ERR "%s: failed to get irq\n", __func__);
  529. goto err_clk;
  530. }
  531. regptr = regs + PL080_Cx_BASE(0);
  532. for (ch = 0; ch < 8; ch++, chno++, chptr++) {
  533. printk(KERN_INFO "%s: registering DMA %d (%p)\n",
  534. __func__, chno, regptr);
  535. chptr->bit = 1 << ch;
  536. chptr->number = chno;
  537. chptr->dmac = dmac;
  538. chptr->regs = regptr;
  539. regptr += PL008_Cx_STRIDE;
  540. }
  541. /* for the moment, permanently enable the controller */
  542. writel(PL080_CONFIG_ENABLE, regs + PL080_CONFIG);
  543. printk(KERN_INFO "PL080: IRQ %d, at %p\n", irq, regs);
  544. return 0;
  545. err_clk:
  546. clk_disable(dmac->clk);
  547. clk_put(dmac->clk);
  548. err_map:
  549. iounmap(regs);
  550. err_dev:
  551. sysdev_unregister(&dmac->sysdev);
  552. err_alloc:
  553. kfree(dmac);
  554. return err;
  555. }
  556. static int __init s3c64xx_dma_init(void)
  557. {
  558. int ret;
  559. printk(KERN_INFO "%s: Registering DMA channels\n", __func__);
  560. dma_pool = dma_pool_create("DMA-LLI", NULL, sizeof(struct pl080s_lli), 16, 0);
  561. if (!dma_pool) {
  562. printk(KERN_ERR "%s: failed to create pool\n", __func__);
  563. return -ENOMEM;
  564. }
  565. ret = sysdev_class_register(&dma_sysclass);
  566. if (ret) {
  567. printk(KERN_ERR "%s: failed to create sysclass\n", __func__);
  568. return -ENOMEM;
  569. }
  570. /* Set all DMA configuration to be DMA, not SDMA */
  571. writel(0xffffff, S3C_SYSREG(0x110));
  572. /* Register standard DMA controlers */
  573. s3c64xx_dma_init1(0, DMACH_UART0, IRQ_DMA0, 0x75000000);
  574. s3c64xx_dma_init1(8, DMACH_PCM1_TX, IRQ_DMA1, 0x75100000);
  575. return 0;
  576. }
  577. arch_initcall(s3c64xx_dma_init);