pl080.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * arch/arm/plat-spear/pl080.c
  3. *
  4. * DMAC pl080 definitions for SPEAr platform
  5. *
  6. * Copyright (C) 2012 ST Microelectronics
  7. * Viresh Kumar <vireshk@kernel.org>
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #include <linux/amba/pl08x.h>
  14. #include <linux/amba/bus.h>
  15. #include <linux/bug.h>
  16. #include <linux/err.h>
  17. #include <linux/io.h>
  18. #include <linux/spinlock_types.h>
  19. #include <mach/spear.h>
  20. #include <mach/misc_regs.h>
  21. static spinlock_t lock = __SPIN_LOCK_UNLOCKED(x);
  22. struct {
  23. unsigned char busy;
  24. unsigned char val;
  25. } signals[16] = {{0, 0}, };
  26. int pl080_get_signal(const struct pl08x_channel_data *cd)
  27. {
  28. unsigned int signal = cd->min_signal, val;
  29. unsigned long flags;
  30. spin_lock_irqsave(&lock, flags);
  31. /* Return if signal is already acquired by somebody else */
  32. if (signals[signal].busy &&
  33. (signals[signal].val != cd->muxval)) {
  34. spin_unlock_irqrestore(&lock, flags);
  35. return -EBUSY;
  36. }
  37. /* If acquiring for the first time, configure it */
  38. if (!signals[signal].busy) {
  39. val = readl(DMA_CHN_CFG);
  40. /*
  41. * Each request line has two bits in DMA_CHN_CFG register. To
  42. * goto the bits of current request line, do left shift of
  43. * value by 2 * signal number.
  44. */
  45. val &= ~(0x3 << (signal * 2));
  46. val |= cd->muxval << (signal * 2);
  47. writel(val, DMA_CHN_CFG);
  48. }
  49. signals[signal].busy++;
  50. signals[signal].val = cd->muxval;
  51. spin_unlock_irqrestore(&lock, flags);
  52. return signal;
  53. }
  54. void pl080_put_signal(const struct pl08x_channel_data *cd, int signal)
  55. {
  56. unsigned long flags;
  57. spin_lock_irqsave(&lock, flags);
  58. /* if signal is not used */
  59. if (!signals[signal].busy)
  60. BUG();
  61. signals[signal].busy--;
  62. spin_unlock_irqrestore(&lock, flags);
  63. }