coh901318.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  1. /*
  2. * driver/dma/coh901318.c
  3. *
  4. * Copyright (C) 2007-2009 ST-Ericsson
  5. * License terms: GNU General Public License (GPL) version 2
  6. * DMA driver for COH 901 318
  7. * Author: Per Friden <per.friden@stericsson.com>
  8. */
  9. #include <linux/init.h>
  10. #include <linux/module.h>
  11. #include <linux/kernel.h> /* printk() */
  12. #include <linux/fs.h> /* everything... */
  13. #include <linux/slab.h> /* kmalloc() */
  14. #include <linux/dmaengine.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/device.h>
  17. #include <linux/irqreturn.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/io.h>
  20. #include <linux/uaccess.h>
  21. #include <linux/debugfs.h>
  22. #include <mach/coh901318.h>
  23. #include "coh901318_lli.h"
  24. #define COHC_2_DEV(cohc) (&cohc->chan.dev->device)
  25. #ifdef VERBOSE_DEBUG
  26. #define COH_DBG(x) ({ if (1) x; 0; })
  27. #else
  28. #define COH_DBG(x) ({ if (0) x; 0; })
  29. #endif
  30. struct coh901318_desc {
  31. struct dma_async_tx_descriptor desc;
  32. struct list_head node;
  33. struct scatterlist *sg;
  34. unsigned int sg_len;
  35. struct coh901318_lli *lli;
  36. enum dma_data_direction dir;
  37. unsigned long flags;
  38. };
  39. struct coh901318_base {
  40. struct device *dev;
  41. void __iomem *virtbase;
  42. struct coh901318_pool pool;
  43. struct powersave pm;
  44. struct dma_device dma_slave;
  45. struct dma_device dma_memcpy;
  46. struct coh901318_chan *chans;
  47. struct coh901318_platform *platform;
  48. };
  49. struct coh901318_chan {
  50. spinlock_t lock;
  51. int allocated;
  52. int completed;
  53. int id;
  54. int stopped;
  55. struct work_struct free_work;
  56. struct dma_chan chan;
  57. struct tasklet_struct tasklet;
  58. struct list_head active;
  59. struct list_head queue;
  60. struct list_head free;
  61. unsigned long nbr_active_done;
  62. unsigned long busy;
  63. struct coh901318_base *base;
  64. };
  65. static void coh901318_list_print(struct coh901318_chan *cohc,
  66. struct coh901318_lli *lli)
  67. {
  68. struct coh901318_lli *l = lli;
  69. int i = 0;
  70. while (l) {
  71. dev_vdbg(COHC_2_DEV(cohc), "i %d, lli %p, ctrl 0x%x, src 0x%x"
  72. ", dst 0x%x, link 0x%x virt_link_addr 0x%p\n",
  73. i, l, l->control, l->src_addr, l->dst_addr,
  74. l->link_addr, l->virt_link_addr);
  75. i++;
  76. l = l->virt_link_addr;
  77. }
  78. }
  79. #ifdef CONFIG_DEBUG_FS
  80. #define COH901318_DEBUGFS_ASSIGN(x, y) (x = y)
  81. static struct coh901318_base *debugfs_dma_base;
  82. static struct dentry *dma_dentry;
  83. static int coh901318_debugfs_open(struct inode *inode, struct file *file)
  84. {
  85. file->private_data = inode->i_private;
  86. return 0;
  87. }
  88. static int coh901318_debugfs_read(struct file *file, char __user *buf,
  89. size_t count, loff_t *f_pos)
  90. {
  91. u64 started_channels = debugfs_dma_base->pm.started_channels;
  92. int pool_count = debugfs_dma_base->pool.debugfs_pool_counter;
  93. int i;
  94. int ret = 0;
  95. char *dev_buf;
  96. char *tmp;
  97. int dev_size;
  98. dev_buf = kmalloc(4*1024, GFP_KERNEL);
  99. if (dev_buf == NULL)
  100. goto err_kmalloc;
  101. tmp = dev_buf;
  102. tmp += sprintf(tmp, "DMA -- enabled dma channels\n");
  103. for (i = 0; i < debugfs_dma_base->platform->max_channels; i++)
  104. if (started_channels & (1 << i))
  105. tmp += sprintf(tmp, "channel %d\n", i);
  106. tmp += sprintf(tmp, "Pool alloc nbr %d\n", pool_count);
  107. dev_size = tmp - dev_buf;
  108. /* No more to read if offset != 0 */
  109. if (*f_pos > dev_size)
  110. goto out;
  111. if (count > dev_size - *f_pos)
  112. count = dev_size - *f_pos;
  113. if (copy_to_user(buf, dev_buf + *f_pos, count))
  114. ret = -EINVAL;
  115. ret = count;
  116. *f_pos += count;
  117. out:
  118. kfree(dev_buf);
  119. return ret;
  120. err_kmalloc:
  121. return 0;
  122. }
  123. static const struct file_operations coh901318_debugfs_status_operations = {
  124. .owner = THIS_MODULE,
  125. .open = coh901318_debugfs_open,
  126. .read = coh901318_debugfs_read,
  127. };
  128. static int __init init_coh901318_debugfs(void)
  129. {
  130. dma_dentry = debugfs_create_dir("dma", NULL);
  131. (void) debugfs_create_file("status",
  132. S_IFREG | S_IRUGO,
  133. dma_dentry, NULL,
  134. &coh901318_debugfs_status_operations);
  135. return 0;
  136. }
  137. static void __exit exit_coh901318_debugfs(void)
  138. {
  139. debugfs_remove_recursive(dma_dentry);
  140. }
  141. module_init(init_coh901318_debugfs);
  142. module_exit(exit_coh901318_debugfs);
  143. #else
  144. #define COH901318_DEBUGFS_ASSIGN(x, y)
  145. #endif /* CONFIG_DEBUG_FS */
  146. static inline struct coh901318_chan *to_coh901318_chan(struct dma_chan *chan)
  147. {
  148. return container_of(chan, struct coh901318_chan, chan);
  149. }
  150. static inline dma_addr_t
  151. cohc_dev_addr(struct coh901318_chan *cohc)
  152. {
  153. return cohc->base->platform->chan_conf[cohc->id].dev_addr;
  154. }
  155. static inline const struct coh901318_params *
  156. cohc_chan_param(struct coh901318_chan *cohc)
  157. {
  158. return &cohc->base->platform->chan_conf[cohc->id].param;
  159. }
  160. static inline const struct coh_dma_channel *
  161. cohc_chan_conf(struct coh901318_chan *cohc)
  162. {
  163. return &cohc->base->platform->chan_conf[cohc->id];
  164. }
  165. static void enable_powersave(struct coh901318_chan *cohc)
  166. {
  167. unsigned long flags;
  168. struct powersave *pm = &cohc->base->pm;
  169. spin_lock_irqsave(&pm->lock, flags);
  170. pm->started_channels &= ~(1ULL << cohc->id);
  171. if (!pm->started_channels) {
  172. /* DMA no longer intends to access memory */
  173. cohc->base->platform->access_memory_state(cohc->base->dev,
  174. false);
  175. }
  176. spin_unlock_irqrestore(&pm->lock, flags);
  177. }
  178. static void disable_powersave(struct coh901318_chan *cohc)
  179. {
  180. unsigned long flags;
  181. struct powersave *pm = &cohc->base->pm;
  182. spin_lock_irqsave(&pm->lock, flags);
  183. if (!pm->started_channels) {
  184. /* DMA intends to access memory */
  185. cohc->base->platform->access_memory_state(cohc->base->dev,
  186. true);
  187. }
  188. pm->started_channels |= (1ULL << cohc->id);
  189. spin_unlock_irqrestore(&pm->lock, flags);
  190. }
  191. static inline int coh901318_set_ctrl(struct coh901318_chan *cohc, u32 control)
  192. {
  193. int channel = cohc->id;
  194. void __iomem *virtbase = cohc->base->virtbase;
  195. writel(control,
  196. virtbase + COH901318_CX_CTRL +
  197. COH901318_CX_CTRL_SPACING * channel);
  198. return 0;
  199. }
  200. static inline int coh901318_set_conf(struct coh901318_chan *cohc, u32 conf)
  201. {
  202. int channel = cohc->id;
  203. void __iomem *virtbase = cohc->base->virtbase;
  204. writel(conf,
  205. virtbase + COH901318_CX_CFG +
  206. COH901318_CX_CFG_SPACING*channel);
  207. return 0;
  208. }
  209. static int coh901318_start(struct coh901318_chan *cohc)
  210. {
  211. u32 val;
  212. int channel = cohc->id;
  213. void __iomem *virtbase = cohc->base->virtbase;
  214. disable_powersave(cohc);
  215. val = readl(virtbase + COH901318_CX_CFG +
  216. COH901318_CX_CFG_SPACING * channel);
  217. /* Enable channel */
  218. val |= COH901318_CX_CFG_CH_ENABLE;
  219. writel(val, virtbase + COH901318_CX_CFG +
  220. COH901318_CX_CFG_SPACING * channel);
  221. return 0;
  222. }
  223. static int coh901318_prep_linked_list(struct coh901318_chan *cohc,
  224. struct coh901318_lli *lli)
  225. {
  226. int channel = cohc->id;
  227. void __iomem *virtbase = cohc->base->virtbase;
  228. BUG_ON(readl(virtbase + COH901318_CX_STAT +
  229. COH901318_CX_STAT_SPACING*channel) &
  230. COH901318_CX_STAT_ACTIVE);
  231. writel(lli->src_addr,
  232. virtbase + COH901318_CX_SRC_ADDR +
  233. COH901318_CX_SRC_ADDR_SPACING * channel);
  234. writel(lli->dst_addr, virtbase +
  235. COH901318_CX_DST_ADDR +
  236. COH901318_CX_DST_ADDR_SPACING * channel);
  237. writel(lli->link_addr, virtbase + COH901318_CX_LNK_ADDR +
  238. COH901318_CX_LNK_ADDR_SPACING * channel);
  239. writel(lli->control, virtbase + COH901318_CX_CTRL +
  240. COH901318_CX_CTRL_SPACING * channel);
  241. return 0;
  242. }
  243. static dma_cookie_t
  244. coh901318_assign_cookie(struct coh901318_chan *cohc,
  245. struct coh901318_desc *cohd)
  246. {
  247. dma_cookie_t cookie = cohc->chan.cookie;
  248. if (++cookie < 0)
  249. cookie = 1;
  250. cohc->chan.cookie = cookie;
  251. cohd->desc.cookie = cookie;
  252. return cookie;
  253. }
  254. static struct coh901318_desc *
  255. coh901318_desc_get(struct coh901318_chan *cohc)
  256. {
  257. struct coh901318_desc *desc;
  258. if (list_empty(&cohc->free)) {
  259. /* alloc new desc because we're out of used ones
  260. * TODO: alloc a pile of descs instead of just one,
  261. * avoid many small allocations.
  262. */
  263. desc = kzalloc(sizeof(struct coh901318_desc), GFP_NOWAIT);
  264. if (desc == NULL)
  265. goto out;
  266. INIT_LIST_HEAD(&desc->node);
  267. dma_async_tx_descriptor_init(&desc->desc, &cohc->chan);
  268. } else {
  269. /* Reuse an old desc. */
  270. desc = list_first_entry(&cohc->free,
  271. struct coh901318_desc,
  272. node);
  273. list_del(&desc->node);
  274. /* Initialize it a bit so it's not insane */
  275. desc->sg = NULL;
  276. desc->sg_len = 0;
  277. desc->desc.callback = NULL;
  278. desc->desc.callback_param = NULL;
  279. }
  280. out:
  281. return desc;
  282. }
  283. static void
  284. coh901318_desc_free(struct coh901318_chan *cohc, struct coh901318_desc *cohd)
  285. {
  286. list_add_tail(&cohd->node, &cohc->free);
  287. }
  288. /* call with irq lock held */
  289. static void
  290. coh901318_desc_submit(struct coh901318_chan *cohc, struct coh901318_desc *desc)
  291. {
  292. list_add_tail(&desc->node, &cohc->active);
  293. }
  294. static struct coh901318_desc *
  295. coh901318_first_active_get(struct coh901318_chan *cohc)
  296. {
  297. struct coh901318_desc *d;
  298. if (list_empty(&cohc->active))
  299. return NULL;
  300. d = list_first_entry(&cohc->active,
  301. struct coh901318_desc,
  302. node);
  303. return d;
  304. }
  305. static void
  306. coh901318_desc_remove(struct coh901318_desc *cohd)
  307. {
  308. list_del(&cohd->node);
  309. }
  310. static void
  311. coh901318_desc_queue(struct coh901318_chan *cohc, struct coh901318_desc *desc)
  312. {
  313. list_add_tail(&desc->node, &cohc->queue);
  314. }
  315. static struct coh901318_desc *
  316. coh901318_first_queued(struct coh901318_chan *cohc)
  317. {
  318. struct coh901318_desc *d;
  319. if (list_empty(&cohc->queue))
  320. return NULL;
  321. d = list_first_entry(&cohc->queue,
  322. struct coh901318_desc,
  323. node);
  324. return d;
  325. }
  326. static inline u32 coh901318_get_bytes_in_lli(struct coh901318_lli *in_lli)
  327. {
  328. struct coh901318_lli *lli = in_lli;
  329. u32 bytes = 0;
  330. while (lli) {
  331. bytes += lli->control & COH901318_CX_CTRL_TC_VALUE_MASK;
  332. lli = lli->virt_link_addr;
  333. }
  334. return bytes;
  335. }
  336. /*
  337. * Get the number of bytes left to transfer on this channel,
  338. * it is unwise to call this before stopping the channel for
  339. * absolute measures, but for a rough guess you can still call
  340. * it.
  341. */
  342. static u32 coh901318_get_bytes_left(struct dma_chan *chan)
  343. {
  344. struct coh901318_chan *cohc = to_coh901318_chan(chan);
  345. struct coh901318_desc *cohd;
  346. struct list_head *pos;
  347. unsigned long flags;
  348. u32 left = 0;
  349. int i = 0;
  350. spin_lock_irqsave(&cohc->lock, flags);
  351. /*
  352. * If there are many queued jobs, we iterate and add the
  353. * size of them all. We take a special look on the first
  354. * job though, since it is probably active.
  355. */
  356. list_for_each(pos, &cohc->active) {
  357. /*
  358. * The first job in the list will be working on the
  359. * hardware. The job can be stopped but still active,
  360. * so that the transfer counter is somewhere inside
  361. * the buffer.
  362. */
  363. cohd = list_entry(pos, struct coh901318_desc, node);
  364. if (i == 0) {
  365. struct coh901318_lli *lli;
  366. dma_addr_t ladd;
  367. /* Read current transfer count value */
  368. left = readl(cohc->base->virtbase +
  369. COH901318_CX_CTRL +
  370. COH901318_CX_CTRL_SPACING * cohc->id) &
  371. COH901318_CX_CTRL_TC_VALUE_MASK;
  372. /* See if the transfer is linked... */
  373. ladd = readl(cohc->base->virtbase +
  374. COH901318_CX_LNK_ADDR +
  375. COH901318_CX_LNK_ADDR_SPACING *
  376. cohc->id) &
  377. ~COH901318_CX_LNK_LINK_IMMEDIATE;
  378. /* Single transaction */
  379. if (!ladd)
  380. continue;
  381. /*
  382. * Linked transaction, follow the lli, find the
  383. * currently processing lli, and proceed to the next
  384. */
  385. lli = cohd->lli;
  386. while (lli && lli->link_addr != ladd)
  387. lli = lli->virt_link_addr;
  388. if (lli)
  389. lli = lli->virt_link_addr;
  390. /*
  391. * Follow remaining lli links around to count the total
  392. * number of bytes left
  393. */
  394. left += coh901318_get_bytes_in_lli(lli);
  395. } else {
  396. left += coh901318_get_bytes_in_lli(cohd->lli);
  397. }
  398. i++;
  399. }
  400. /* Also count bytes in the queued jobs */
  401. list_for_each(pos, &cohc->queue) {
  402. cohd = list_entry(pos, struct coh901318_desc, node);
  403. left += coh901318_get_bytes_in_lli(cohd->lli);
  404. }
  405. spin_unlock_irqrestore(&cohc->lock, flags);
  406. return left;
  407. }
  408. /*
  409. * Pauses a transfer without losing data. Enables power save.
  410. * Use this function in conjunction with coh901318_resume.
  411. */
  412. static void coh901318_pause(struct dma_chan *chan)
  413. {
  414. u32 val;
  415. unsigned long flags;
  416. struct coh901318_chan *cohc = to_coh901318_chan(chan);
  417. int channel = cohc->id;
  418. void __iomem *virtbase = cohc->base->virtbase;
  419. spin_lock_irqsave(&cohc->lock, flags);
  420. /* Disable channel in HW */
  421. val = readl(virtbase + COH901318_CX_CFG +
  422. COH901318_CX_CFG_SPACING * channel);
  423. /* Stopping infinit transfer */
  424. if ((val & COH901318_CX_CTRL_TC_ENABLE) == 0 &&
  425. (val & COH901318_CX_CFG_CH_ENABLE))
  426. cohc->stopped = 1;
  427. val &= ~COH901318_CX_CFG_CH_ENABLE;
  428. /* Enable twice, HW bug work around */
  429. writel(val, virtbase + COH901318_CX_CFG +
  430. COH901318_CX_CFG_SPACING * channel);
  431. writel(val, virtbase + COH901318_CX_CFG +
  432. COH901318_CX_CFG_SPACING * channel);
  433. /* Spin-wait for it to actually go inactive */
  434. while (readl(virtbase + COH901318_CX_STAT+COH901318_CX_STAT_SPACING *
  435. channel) & COH901318_CX_STAT_ACTIVE)
  436. cpu_relax();
  437. /* Check if we stopped an active job */
  438. if ((readl(virtbase + COH901318_CX_CTRL+COH901318_CX_CTRL_SPACING *
  439. channel) & COH901318_CX_CTRL_TC_VALUE_MASK) > 0)
  440. cohc->stopped = 1;
  441. enable_powersave(cohc);
  442. spin_unlock_irqrestore(&cohc->lock, flags);
  443. }
  444. /* Resumes a transfer that has been stopped via 300_dma_stop(..).
  445. Power save is handled.
  446. */
  447. static void coh901318_resume(struct dma_chan *chan)
  448. {
  449. u32 val;
  450. unsigned long flags;
  451. struct coh901318_chan *cohc = to_coh901318_chan(chan);
  452. int channel = cohc->id;
  453. spin_lock_irqsave(&cohc->lock, flags);
  454. disable_powersave(cohc);
  455. if (cohc->stopped) {
  456. /* Enable channel in HW */
  457. val = readl(cohc->base->virtbase + COH901318_CX_CFG +
  458. COH901318_CX_CFG_SPACING * channel);
  459. val |= COH901318_CX_CFG_CH_ENABLE;
  460. writel(val, cohc->base->virtbase + COH901318_CX_CFG +
  461. COH901318_CX_CFG_SPACING*channel);
  462. cohc->stopped = 0;
  463. }
  464. spin_unlock_irqrestore(&cohc->lock, flags);
  465. }
  466. bool coh901318_filter_id(struct dma_chan *chan, void *chan_id)
  467. {
  468. unsigned int ch_nr = (unsigned int) chan_id;
  469. if (ch_nr == to_coh901318_chan(chan)->id)
  470. return true;
  471. return false;
  472. }
  473. EXPORT_SYMBOL(coh901318_filter_id);
  474. /*
  475. * DMA channel allocation
  476. */
  477. static int coh901318_config(struct coh901318_chan *cohc,
  478. struct coh901318_params *param)
  479. {
  480. unsigned long flags;
  481. const struct coh901318_params *p;
  482. int channel = cohc->id;
  483. void __iomem *virtbase = cohc->base->virtbase;
  484. spin_lock_irqsave(&cohc->lock, flags);
  485. if (param)
  486. p = param;
  487. else
  488. p = &cohc->base->platform->chan_conf[channel].param;
  489. /* Clear any pending BE or TC interrupt */
  490. if (channel < 32) {
  491. writel(1 << channel, virtbase + COH901318_BE_INT_CLEAR1);
  492. writel(1 << channel, virtbase + COH901318_TC_INT_CLEAR1);
  493. } else {
  494. writel(1 << (channel - 32), virtbase +
  495. COH901318_BE_INT_CLEAR2);
  496. writel(1 << (channel - 32), virtbase +
  497. COH901318_TC_INT_CLEAR2);
  498. }
  499. coh901318_set_conf(cohc, p->config);
  500. coh901318_set_ctrl(cohc, p->ctrl_lli_last);
  501. spin_unlock_irqrestore(&cohc->lock, flags);
  502. return 0;
  503. }
  504. /* must lock when calling this function
  505. * start queued jobs, if any
  506. * TODO: start all queued jobs in one go
  507. *
  508. * Returns descriptor if queued job is started otherwise NULL.
  509. * If the queue is empty NULL is returned.
  510. */
  511. static struct coh901318_desc *coh901318_queue_start(struct coh901318_chan *cohc)
  512. {
  513. struct coh901318_desc *cohd;
  514. /*
  515. * start queued jobs, if any
  516. * TODO: transmit all queued jobs in one go
  517. */
  518. cohd = coh901318_first_queued(cohc);
  519. if (cohd != NULL) {
  520. /* Remove from queue */
  521. coh901318_desc_remove(cohd);
  522. /* initiate DMA job */
  523. cohc->busy = 1;
  524. coh901318_desc_submit(cohc, cohd);
  525. coh901318_prep_linked_list(cohc, cohd->lli);
  526. /* start dma job on this channel */
  527. coh901318_start(cohc);
  528. }
  529. return cohd;
  530. }
  531. /*
  532. * This tasklet is called from the interrupt handler to
  533. * handle each descriptor (DMA job) that is sent to a channel.
  534. */
  535. static void dma_tasklet(unsigned long data)
  536. {
  537. struct coh901318_chan *cohc = (struct coh901318_chan *) data;
  538. struct coh901318_desc *cohd_fin;
  539. unsigned long flags;
  540. dma_async_tx_callback callback;
  541. void *callback_param;
  542. dev_vdbg(COHC_2_DEV(cohc), "[%s] chan_id %d"
  543. " nbr_active_done %ld\n", __func__,
  544. cohc->id, cohc->nbr_active_done);
  545. spin_lock_irqsave(&cohc->lock, flags);
  546. /* get first active descriptor entry from list */
  547. cohd_fin = coh901318_first_active_get(cohc);
  548. if (cohd_fin == NULL)
  549. goto err;
  550. /* locate callback to client */
  551. callback = cohd_fin->desc.callback;
  552. callback_param = cohd_fin->desc.callback_param;
  553. /* sign this job as completed on the channel */
  554. cohc->completed = cohd_fin->desc.cookie;
  555. /* release the lli allocation and remove the descriptor */
  556. coh901318_lli_free(&cohc->base->pool, &cohd_fin->lli);
  557. /* return desc to free-list */
  558. coh901318_desc_remove(cohd_fin);
  559. coh901318_desc_free(cohc, cohd_fin);
  560. spin_unlock_irqrestore(&cohc->lock, flags);
  561. /* Call the callback when we're done */
  562. if (callback)
  563. callback(callback_param);
  564. spin_lock_irqsave(&cohc->lock, flags);
  565. /*
  566. * If another interrupt fired while the tasklet was scheduling,
  567. * we don't get called twice, so we have this number of active
  568. * counter that keep track of the number of IRQs expected to
  569. * be handled for this channel. If there happen to be more than
  570. * one IRQ to be ack:ed, we simply schedule this tasklet again.
  571. */
  572. cohc->nbr_active_done--;
  573. if (cohc->nbr_active_done) {
  574. dev_dbg(COHC_2_DEV(cohc), "scheduling tasklet again, new IRQs "
  575. "came in while we were scheduling this tasklet\n");
  576. if (cohc_chan_conf(cohc)->priority_high)
  577. tasklet_hi_schedule(&cohc->tasklet);
  578. else
  579. tasklet_schedule(&cohc->tasklet);
  580. }
  581. spin_unlock_irqrestore(&cohc->lock, flags);
  582. return;
  583. err:
  584. spin_unlock_irqrestore(&cohc->lock, flags);
  585. dev_err(COHC_2_DEV(cohc), "[%s] No active dma desc\n", __func__);
  586. }
  587. /* called from interrupt context */
  588. static void dma_tc_handle(struct coh901318_chan *cohc)
  589. {
  590. /*
  591. * If the channel is not allocated, then we shouldn't have
  592. * any TC interrupts on it.
  593. */
  594. if (!cohc->allocated) {
  595. dev_err(COHC_2_DEV(cohc), "spurious interrupt from "
  596. "unallocated channel\n");
  597. return;
  598. }
  599. spin_lock(&cohc->lock);
  600. /*
  601. * When we reach this point, at least one queue item
  602. * should have been moved over from cohc->queue to
  603. * cohc->active and run to completion, that is why we're
  604. * getting a terminal count interrupt is it not?
  605. * If you get this BUG() the most probable cause is that
  606. * the individual nodes in the lli chain have IRQ enabled,
  607. * so check your platform config for lli chain ctrl.
  608. */
  609. BUG_ON(list_empty(&cohc->active));
  610. cohc->nbr_active_done++;
  611. /*
  612. * This attempt to take a job from cohc->queue, put it
  613. * into cohc->active and start it.
  614. */
  615. if (coh901318_queue_start(cohc) == NULL)
  616. cohc->busy = 0;
  617. spin_unlock(&cohc->lock);
  618. /*
  619. * This tasklet will remove items from cohc->active
  620. * and thus terminates them.
  621. */
  622. if (cohc_chan_conf(cohc)->priority_high)
  623. tasklet_hi_schedule(&cohc->tasklet);
  624. else
  625. tasklet_schedule(&cohc->tasklet);
  626. }
  627. static irqreturn_t dma_irq_handler(int irq, void *dev_id)
  628. {
  629. u32 status1;
  630. u32 status2;
  631. int i;
  632. int ch;
  633. struct coh901318_base *base = dev_id;
  634. struct coh901318_chan *cohc;
  635. void __iomem *virtbase = base->virtbase;
  636. status1 = readl(virtbase + COH901318_INT_STATUS1);
  637. status2 = readl(virtbase + COH901318_INT_STATUS2);
  638. if (unlikely(status1 == 0 && status2 == 0)) {
  639. dev_warn(base->dev, "spurious DMA IRQ from no channel!\n");
  640. return IRQ_HANDLED;
  641. }
  642. /* TODO: consider handle IRQ in tasklet here to
  643. * minimize interrupt latency */
  644. /* Check the first 32 DMA channels for IRQ */
  645. while (status1) {
  646. /* Find first bit set, return as a number. */
  647. i = ffs(status1) - 1;
  648. ch = i;
  649. cohc = &base->chans[ch];
  650. spin_lock(&cohc->lock);
  651. /* Mask off this bit */
  652. status1 &= ~(1 << i);
  653. /* Check the individual channel bits */
  654. if (test_bit(i, virtbase + COH901318_BE_INT_STATUS1)) {
  655. dev_crit(COHC_2_DEV(cohc),
  656. "DMA bus error on channel %d!\n", ch);
  657. BUG_ON(1);
  658. /* Clear BE interrupt */
  659. __set_bit(i, virtbase + COH901318_BE_INT_CLEAR1);
  660. } else {
  661. /* Caused by TC, really? */
  662. if (unlikely(!test_bit(i, virtbase +
  663. COH901318_TC_INT_STATUS1))) {
  664. dev_warn(COHC_2_DEV(cohc),
  665. "ignoring interrupt not caused by terminal count on channel %d\n", ch);
  666. /* Clear TC interrupt */
  667. BUG_ON(1);
  668. __set_bit(i, virtbase + COH901318_TC_INT_CLEAR1);
  669. } else {
  670. /* Enable powersave if transfer has finished */
  671. if (!(readl(virtbase + COH901318_CX_STAT +
  672. COH901318_CX_STAT_SPACING*ch) &
  673. COH901318_CX_STAT_ENABLED)) {
  674. enable_powersave(cohc);
  675. }
  676. /* Must clear TC interrupt before calling
  677. * dma_tc_handle
  678. * in case tc_handle initate a new dma job
  679. */
  680. __set_bit(i, virtbase + COH901318_TC_INT_CLEAR1);
  681. dma_tc_handle(cohc);
  682. }
  683. }
  684. spin_unlock(&cohc->lock);
  685. }
  686. /* Check the remaining 32 DMA channels for IRQ */
  687. while (status2) {
  688. /* Find first bit set, return as a number. */
  689. i = ffs(status2) - 1;
  690. ch = i + 32;
  691. cohc = &base->chans[ch];
  692. spin_lock(&cohc->lock);
  693. /* Mask off this bit */
  694. status2 &= ~(1 << i);
  695. /* Check the individual channel bits */
  696. if (test_bit(i, virtbase + COH901318_BE_INT_STATUS2)) {
  697. dev_crit(COHC_2_DEV(cohc),
  698. "DMA bus error on channel %d!\n", ch);
  699. /* Clear BE interrupt */
  700. BUG_ON(1);
  701. __set_bit(i, virtbase + COH901318_BE_INT_CLEAR2);
  702. } else {
  703. /* Caused by TC, really? */
  704. if (unlikely(!test_bit(i, virtbase +
  705. COH901318_TC_INT_STATUS2))) {
  706. dev_warn(COHC_2_DEV(cohc),
  707. "ignoring interrupt not caused by terminal count on channel %d\n", ch);
  708. /* Clear TC interrupt */
  709. __set_bit(i, virtbase + COH901318_TC_INT_CLEAR2);
  710. BUG_ON(1);
  711. } else {
  712. /* Enable powersave if transfer has finished */
  713. if (!(readl(virtbase + COH901318_CX_STAT +
  714. COH901318_CX_STAT_SPACING*ch) &
  715. COH901318_CX_STAT_ENABLED)) {
  716. enable_powersave(cohc);
  717. }
  718. /* Must clear TC interrupt before calling
  719. * dma_tc_handle
  720. * in case tc_handle initate a new dma job
  721. */
  722. __set_bit(i, virtbase + COH901318_TC_INT_CLEAR2);
  723. dma_tc_handle(cohc);
  724. }
  725. }
  726. spin_unlock(&cohc->lock);
  727. }
  728. return IRQ_HANDLED;
  729. }
  730. static int coh901318_alloc_chan_resources(struct dma_chan *chan)
  731. {
  732. struct coh901318_chan *cohc = to_coh901318_chan(chan);
  733. unsigned long flags;
  734. dev_vdbg(COHC_2_DEV(cohc), "[%s] DMA channel %d\n",
  735. __func__, cohc->id);
  736. if (chan->client_count > 1)
  737. return -EBUSY;
  738. spin_lock_irqsave(&cohc->lock, flags);
  739. coh901318_config(cohc, NULL);
  740. cohc->allocated = 1;
  741. cohc->completed = chan->cookie = 1;
  742. spin_unlock_irqrestore(&cohc->lock, flags);
  743. return 1;
  744. }
  745. static void
  746. coh901318_free_chan_resources(struct dma_chan *chan)
  747. {
  748. struct coh901318_chan *cohc = to_coh901318_chan(chan);
  749. int channel = cohc->id;
  750. unsigned long flags;
  751. spin_lock_irqsave(&cohc->lock, flags);
  752. /* Disable HW */
  753. writel(0x00000000U, cohc->base->virtbase + COH901318_CX_CFG +
  754. COH901318_CX_CFG_SPACING*channel);
  755. writel(0x00000000U, cohc->base->virtbase + COH901318_CX_CTRL +
  756. COH901318_CX_CTRL_SPACING*channel);
  757. cohc->allocated = 0;
  758. spin_unlock_irqrestore(&cohc->lock, flags);
  759. chan->device->device_control(chan, DMA_TERMINATE_ALL, 0);
  760. }
  761. static dma_cookie_t
  762. coh901318_tx_submit(struct dma_async_tx_descriptor *tx)
  763. {
  764. struct coh901318_desc *cohd = container_of(tx, struct coh901318_desc,
  765. desc);
  766. struct coh901318_chan *cohc = to_coh901318_chan(tx->chan);
  767. unsigned long flags;
  768. spin_lock_irqsave(&cohc->lock, flags);
  769. tx->cookie = coh901318_assign_cookie(cohc, cohd);
  770. coh901318_desc_queue(cohc, cohd);
  771. spin_unlock_irqrestore(&cohc->lock, flags);
  772. return tx->cookie;
  773. }
  774. static struct dma_async_tx_descriptor *
  775. coh901318_prep_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
  776. size_t size, unsigned long flags)
  777. {
  778. struct coh901318_lli *lli;
  779. struct coh901318_desc *cohd;
  780. unsigned long flg;
  781. struct coh901318_chan *cohc = to_coh901318_chan(chan);
  782. int lli_len;
  783. u32 ctrl_last = cohc_chan_param(cohc)->ctrl_lli_last;
  784. int ret;
  785. spin_lock_irqsave(&cohc->lock, flg);
  786. dev_vdbg(COHC_2_DEV(cohc),
  787. "[%s] channel %d src 0x%x dest 0x%x size %d\n",
  788. __func__, cohc->id, src, dest, size);
  789. if (flags & DMA_PREP_INTERRUPT)
  790. /* Trigger interrupt after last lli */
  791. ctrl_last |= COH901318_CX_CTRL_TC_IRQ_ENABLE;
  792. lli_len = size >> MAX_DMA_PACKET_SIZE_SHIFT;
  793. if ((lli_len << MAX_DMA_PACKET_SIZE_SHIFT) < size)
  794. lli_len++;
  795. lli = coh901318_lli_alloc(&cohc->base->pool, lli_len);
  796. if (lli == NULL)
  797. goto err;
  798. ret = coh901318_lli_fill_memcpy(
  799. &cohc->base->pool, lli, src, size, dest,
  800. cohc_chan_param(cohc)->ctrl_lli_chained,
  801. ctrl_last);
  802. if (ret)
  803. goto err;
  804. COH_DBG(coh901318_list_print(cohc, lli));
  805. /* Pick a descriptor to handle this transfer */
  806. cohd = coh901318_desc_get(cohc);
  807. cohd->lli = lli;
  808. cohd->flags = flags;
  809. cohd->desc.tx_submit = coh901318_tx_submit;
  810. spin_unlock_irqrestore(&cohc->lock, flg);
  811. return &cohd->desc;
  812. err:
  813. spin_unlock_irqrestore(&cohc->lock, flg);
  814. return NULL;
  815. }
  816. static struct dma_async_tx_descriptor *
  817. coh901318_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
  818. unsigned int sg_len, enum dma_data_direction direction,
  819. unsigned long flags)
  820. {
  821. struct coh901318_chan *cohc = to_coh901318_chan(chan);
  822. struct coh901318_lli *lli;
  823. struct coh901318_desc *cohd;
  824. const struct coh901318_params *params;
  825. struct scatterlist *sg;
  826. int len = 0;
  827. int size;
  828. int i;
  829. u32 ctrl_chained = cohc_chan_param(cohc)->ctrl_lli_chained;
  830. u32 ctrl = cohc_chan_param(cohc)->ctrl_lli;
  831. u32 ctrl_last = cohc_chan_param(cohc)->ctrl_lli_last;
  832. u32 config;
  833. unsigned long flg;
  834. int ret;
  835. if (!sgl)
  836. goto out;
  837. if (sgl->length == 0)
  838. goto out;
  839. spin_lock_irqsave(&cohc->lock, flg);
  840. dev_vdbg(COHC_2_DEV(cohc), "[%s] sg_len %d dir %d\n",
  841. __func__, sg_len, direction);
  842. if (flags & DMA_PREP_INTERRUPT)
  843. /* Trigger interrupt after last lli */
  844. ctrl_last |= COH901318_CX_CTRL_TC_IRQ_ENABLE;
  845. params = cohc_chan_param(cohc);
  846. config = params->config;
  847. if (direction == DMA_TO_DEVICE) {
  848. u32 tx_flags = COH901318_CX_CTRL_PRDD_SOURCE |
  849. COH901318_CX_CTRL_SRC_ADDR_INC_ENABLE;
  850. config |= COH901318_CX_CFG_RM_MEMORY_TO_PRIMARY;
  851. ctrl_chained |= tx_flags;
  852. ctrl_last |= tx_flags;
  853. ctrl |= tx_flags;
  854. } else if (direction == DMA_FROM_DEVICE) {
  855. u32 rx_flags = COH901318_CX_CTRL_PRDD_DEST |
  856. COH901318_CX_CTRL_DST_ADDR_INC_ENABLE;
  857. config |= COH901318_CX_CFG_RM_PRIMARY_TO_MEMORY;
  858. ctrl_chained |= rx_flags;
  859. ctrl_last |= rx_flags;
  860. ctrl |= rx_flags;
  861. } else
  862. goto err_direction;
  863. coh901318_set_conf(cohc, config);
  864. /* The dma only supports transmitting packages up to
  865. * MAX_DMA_PACKET_SIZE. Calculate to total number of
  866. * dma elemts required to send the entire sg list
  867. */
  868. for_each_sg(sgl, sg, sg_len, i) {
  869. unsigned int factor;
  870. size = sg_dma_len(sg);
  871. if (size <= MAX_DMA_PACKET_SIZE) {
  872. len++;
  873. continue;
  874. }
  875. factor = size >> MAX_DMA_PACKET_SIZE_SHIFT;
  876. if ((factor << MAX_DMA_PACKET_SIZE_SHIFT) < size)
  877. factor++;
  878. len += factor;
  879. }
  880. pr_debug("Allocate %d lli:s for this transfer\n", len);
  881. lli = coh901318_lli_alloc(&cohc->base->pool, len);
  882. if (lli == NULL)
  883. goto err_dma_alloc;
  884. /* initiate allocated lli list */
  885. ret = coh901318_lli_fill_sg(&cohc->base->pool, lli, sgl, sg_len,
  886. cohc_dev_addr(cohc),
  887. ctrl_chained,
  888. ctrl,
  889. ctrl_last,
  890. direction, COH901318_CX_CTRL_TC_IRQ_ENABLE);
  891. if (ret)
  892. goto err_lli_fill;
  893. COH_DBG(coh901318_list_print(cohc, lli));
  894. /* Pick a descriptor to handle this transfer */
  895. cohd = coh901318_desc_get(cohc);
  896. cohd->dir = direction;
  897. cohd->flags = flags;
  898. cohd->desc.tx_submit = coh901318_tx_submit;
  899. cohd->lli = lli;
  900. spin_unlock_irqrestore(&cohc->lock, flg);
  901. return &cohd->desc;
  902. err_lli_fill:
  903. err_dma_alloc:
  904. err_direction:
  905. spin_unlock_irqrestore(&cohc->lock, flg);
  906. out:
  907. return NULL;
  908. }
  909. static enum dma_status
  910. coh901318_tx_status(struct dma_chan *chan, dma_cookie_t cookie,
  911. struct dma_tx_state *txstate)
  912. {
  913. struct coh901318_chan *cohc = to_coh901318_chan(chan);
  914. dma_cookie_t last_used;
  915. dma_cookie_t last_complete;
  916. int ret;
  917. last_complete = cohc->completed;
  918. last_used = chan->cookie;
  919. ret = dma_async_is_complete(cookie, last_complete, last_used);
  920. dma_set_tx_state(txstate, last_complete, last_used,
  921. coh901318_get_bytes_left(chan));
  922. if (ret == DMA_IN_PROGRESS && cohc->stopped)
  923. ret = DMA_PAUSED;
  924. return ret;
  925. }
  926. static void
  927. coh901318_issue_pending(struct dma_chan *chan)
  928. {
  929. struct coh901318_chan *cohc = to_coh901318_chan(chan);
  930. unsigned long flags;
  931. spin_lock_irqsave(&cohc->lock, flags);
  932. /*
  933. * Busy means that pending jobs are already being processed,
  934. * and then there is no point in starting the queue: the
  935. * terminal count interrupt on the channel will take the next
  936. * job on the queue and execute it anyway.
  937. */
  938. if (!cohc->busy)
  939. coh901318_queue_start(cohc);
  940. spin_unlock_irqrestore(&cohc->lock, flags);
  941. }
  942. static int
  943. coh901318_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  944. unsigned long arg)
  945. {
  946. unsigned long flags;
  947. struct coh901318_chan *cohc = to_coh901318_chan(chan);
  948. struct coh901318_desc *cohd;
  949. void __iomem *virtbase = cohc->base->virtbase;
  950. if (cmd == DMA_PAUSE) {
  951. coh901318_pause(chan);
  952. return 0;
  953. }
  954. if (cmd == DMA_RESUME) {
  955. coh901318_resume(chan);
  956. return 0;
  957. }
  958. if (cmd != DMA_TERMINATE_ALL)
  959. return -ENXIO;
  960. /* The remainder of this function terminates the transfer */
  961. coh901318_pause(chan);
  962. spin_lock_irqsave(&cohc->lock, flags);
  963. /* Clear any pending BE or TC interrupt */
  964. if (cohc->id < 32) {
  965. writel(1 << cohc->id, virtbase + COH901318_BE_INT_CLEAR1);
  966. writel(1 << cohc->id, virtbase + COH901318_TC_INT_CLEAR1);
  967. } else {
  968. writel(1 << (cohc->id - 32), virtbase +
  969. COH901318_BE_INT_CLEAR2);
  970. writel(1 << (cohc->id - 32), virtbase +
  971. COH901318_TC_INT_CLEAR2);
  972. }
  973. enable_powersave(cohc);
  974. while ((cohd = coh901318_first_active_get(cohc))) {
  975. /* release the lli allocation*/
  976. coh901318_lli_free(&cohc->base->pool, &cohd->lli);
  977. /* return desc to free-list */
  978. coh901318_desc_remove(cohd);
  979. coh901318_desc_free(cohc, cohd);
  980. }
  981. while ((cohd = coh901318_first_queued(cohc))) {
  982. /* release the lli allocation*/
  983. coh901318_lli_free(&cohc->base->pool, &cohd->lli);
  984. /* return desc to free-list */
  985. coh901318_desc_remove(cohd);
  986. coh901318_desc_free(cohc, cohd);
  987. }
  988. cohc->nbr_active_done = 0;
  989. cohc->busy = 0;
  990. spin_unlock_irqrestore(&cohc->lock, flags);
  991. return 0;
  992. }
  993. void coh901318_base_init(struct dma_device *dma, const int *pick_chans,
  994. struct coh901318_base *base)
  995. {
  996. int chans_i;
  997. int i = 0;
  998. struct coh901318_chan *cohc;
  999. INIT_LIST_HEAD(&dma->channels);
  1000. for (chans_i = 0; pick_chans[chans_i] != -1; chans_i += 2) {
  1001. for (i = pick_chans[chans_i]; i <= pick_chans[chans_i+1]; i++) {
  1002. cohc = &base->chans[i];
  1003. cohc->base = base;
  1004. cohc->chan.device = dma;
  1005. cohc->id = i;
  1006. /* TODO: do we really need this lock if only one
  1007. * client is connected to each channel?
  1008. */
  1009. spin_lock_init(&cohc->lock);
  1010. cohc->nbr_active_done = 0;
  1011. cohc->busy = 0;
  1012. INIT_LIST_HEAD(&cohc->free);
  1013. INIT_LIST_HEAD(&cohc->active);
  1014. INIT_LIST_HEAD(&cohc->queue);
  1015. tasklet_init(&cohc->tasklet, dma_tasklet,
  1016. (unsigned long) cohc);
  1017. list_add_tail(&cohc->chan.device_node,
  1018. &dma->channels);
  1019. }
  1020. }
  1021. }
  1022. static int __init coh901318_probe(struct platform_device *pdev)
  1023. {
  1024. int err = 0;
  1025. struct coh901318_platform *pdata;
  1026. struct coh901318_base *base;
  1027. int irq;
  1028. struct resource *io;
  1029. io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1030. if (!io)
  1031. goto err_get_resource;
  1032. /* Map DMA controller registers to virtual memory */
  1033. if (request_mem_region(io->start,
  1034. resource_size(io),
  1035. pdev->dev.driver->name) == NULL) {
  1036. err = -EBUSY;
  1037. goto err_request_mem;
  1038. }
  1039. pdata = pdev->dev.platform_data;
  1040. if (!pdata)
  1041. goto err_no_platformdata;
  1042. base = kmalloc(ALIGN(sizeof(struct coh901318_base), 4) +
  1043. pdata->max_channels *
  1044. sizeof(struct coh901318_chan),
  1045. GFP_KERNEL);
  1046. if (!base)
  1047. goto err_alloc_coh_dma_channels;
  1048. base->chans = ((void *)base) + ALIGN(sizeof(struct coh901318_base), 4);
  1049. base->virtbase = ioremap(io->start, resource_size(io));
  1050. if (!base->virtbase) {
  1051. err = -ENOMEM;
  1052. goto err_no_ioremap;
  1053. }
  1054. base->dev = &pdev->dev;
  1055. base->platform = pdata;
  1056. spin_lock_init(&base->pm.lock);
  1057. base->pm.started_channels = 0;
  1058. COH901318_DEBUGFS_ASSIGN(debugfs_dma_base, base);
  1059. platform_set_drvdata(pdev, base);
  1060. irq = platform_get_irq(pdev, 0);
  1061. if (irq < 0)
  1062. goto err_no_irq;
  1063. err = request_irq(irq, dma_irq_handler, IRQF_DISABLED,
  1064. "coh901318", base);
  1065. if (err) {
  1066. dev_crit(&pdev->dev,
  1067. "Cannot allocate IRQ for DMA controller!\n");
  1068. goto err_request_irq;
  1069. }
  1070. err = coh901318_pool_create(&base->pool, &pdev->dev,
  1071. sizeof(struct coh901318_lli),
  1072. 32);
  1073. if (err)
  1074. goto err_pool_create;
  1075. /* init channels for device transfers */
  1076. coh901318_base_init(&base->dma_slave, base->platform->chans_slave,
  1077. base);
  1078. dma_cap_zero(base->dma_slave.cap_mask);
  1079. dma_cap_set(DMA_SLAVE, base->dma_slave.cap_mask);
  1080. base->dma_slave.device_alloc_chan_resources = coh901318_alloc_chan_resources;
  1081. base->dma_slave.device_free_chan_resources = coh901318_free_chan_resources;
  1082. base->dma_slave.device_prep_slave_sg = coh901318_prep_slave_sg;
  1083. base->dma_slave.device_tx_status = coh901318_tx_status;
  1084. base->dma_slave.device_issue_pending = coh901318_issue_pending;
  1085. base->dma_slave.device_control = coh901318_control;
  1086. base->dma_slave.dev = &pdev->dev;
  1087. err = dma_async_device_register(&base->dma_slave);
  1088. if (err)
  1089. goto err_register_slave;
  1090. /* init channels for memcpy */
  1091. coh901318_base_init(&base->dma_memcpy, base->platform->chans_memcpy,
  1092. base);
  1093. dma_cap_zero(base->dma_memcpy.cap_mask);
  1094. dma_cap_set(DMA_MEMCPY, base->dma_memcpy.cap_mask);
  1095. base->dma_memcpy.device_alloc_chan_resources = coh901318_alloc_chan_resources;
  1096. base->dma_memcpy.device_free_chan_resources = coh901318_free_chan_resources;
  1097. base->dma_memcpy.device_prep_dma_memcpy = coh901318_prep_memcpy;
  1098. base->dma_memcpy.device_tx_status = coh901318_tx_status;
  1099. base->dma_memcpy.device_issue_pending = coh901318_issue_pending;
  1100. base->dma_memcpy.device_control = coh901318_control;
  1101. base->dma_memcpy.dev = &pdev->dev;
  1102. /*
  1103. * This controller can only access address at even 32bit boundaries,
  1104. * i.e. 2^2
  1105. */
  1106. base->dma_memcpy.copy_align = 2;
  1107. err = dma_async_device_register(&base->dma_memcpy);
  1108. if (err)
  1109. goto err_register_memcpy;
  1110. dev_info(&pdev->dev, "Initialized COH901318 DMA on virtual base 0x%08x\n",
  1111. (u32) base->virtbase);
  1112. return err;
  1113. err_register_memcpy:
  1114. dma_async_device_unregister(&base->dma_slave);
  1115. err_register_slave:
  1116. coh901318_pool_destroy(&base->pool);
  1117. err_pool_create:
  1118. free_irq(platform_get_irq(pdev, 0), base);
  1119. err_request_irq:
  1120. err_no_irq:
  1121. iounmap(base->virtbase);
  1122. err_no_ioremap:
  1123. kfree(base);
  1124. err_alloc_coh_dma_channels:
  1125. err_no_platformdata:
  1126. release_mem_region(pdev->resource->start,
  1127. resource_size(pdev->resource));
  1128. err_request_mem:
  1129. err_get_resource:
  1130. return err;
  1131. }
  1132. static int __exit coh901318_remove(struct platform_device *pdev)
  1133. {
  1134. struct coh901318_base *base = platform_get_drvdata(pdev);
  1135. dma_async_device_unregister(&base->dma_memcpy);
  1136. dma_async_device_unregister(&base->dma_slave);
  1137. coh901318_pool_destroy(&base->pool);
  1138. free_irq(platform_get_irq(pdev, 0), base);
  1139. iounmap(base->virtbase);
  1140. kfree(base);
  1141. release_mem_region(pdev->resource->start,
  1142. resource_size(pdev->resource));
  1143. return 0;
  1144. }
  1145. static struct platform_driver coh901318_driver = {
  1146. .remove = __exit_p(coh901318_remove),
  1147. .driver = {
  1148. .name = "coh901318",
  1149. },
  1150. };
  1151. int __init coh901318_init(void)
  1152. {
  1153. return platform_driver_probe(&coh901318_driver, coh901318_probe);
  1154. }
  1155. subsys_initcall(coh901318_init);
  1156. void __exit coh901318_exit(void)
  1157. {
  1158. platform_driver_unregister(&coh901318_driver);
  1159. }
  1160. module_exit(coh901318_exit);
  1161. MODULE_LICENSE("GPL");
  1162. MODULE_AUTHOR("Per Friden");