shdma-base.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Dmaengine driver base library for DMA controllers, found on SH-based SoCs
  3. *
  4. * extracted from shdma.c and headers
  5. *
  6. * Copyright (C) 2011-2012 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
  7. * Copyright (C) 2009 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>
  8. * Copyright (C) 2009 Renesas Solutions, Inc. All rights reserved.
  9. * Copyright (C) 2007 Freescale Semiconductor, Inc. All rights reserved.
  10. *
  11. * This is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. */
  15. #ifndef SHDMA_BASE_H
  16. #define SHDMA_BASE_H
  17. #include <linux/dmaengine.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/list.h>
  20. #include <linux/types.h>
  21. /**
  22. * shdma_pm_state - DMA channel PM state
  23. * SHDMA_PM_ESTABLISHED: either idle or during data transfer
  24. * SHDMA_PM_BUSY: during the transfer preparation, when we have to
  25. * drop the lock temporarily
  26. * SHDMA_PM_PENDING: transfers pending
  27. */
  28. enum shdma_pm_state {
  29. SHDMA_PM_ESTABLISHED,
  30. SHDMA_PM_BUSY,
  31. SHDMA_PM_PENDING,
  32. };
  33. struct device;
  34. /*
  35. * Drivers, using this library are expected to embed struct shdma_dev,
  36. * struct shdma_chan, struct shdma_desc, and struct shdma_slave
  37. * in their respective device, channel, descriptor and slave objects.
  38. */
  39. struct shdma_slave {
  40. unsigned int slave_id;
  41. };
  42. struct shdma_desc {
  43. struct list_head node;
  44. struct dma_async_tx_descriptor async_tx;
  45. enum dma_transfer_direction direction;
  46. dma_cookie_t cookie;
  47. int chunks;
  48. int mark;
  49. };
  50. struct shdma_chan {
  51. spinlock_t chan_lock; /* Channel operation lock */
  52. struct list_head ld_queue; /* Link descriptors queue */
  53. struct list_head ld_free; /* Free link descriptors */
  54. struct dma_chan dma_chan; /* DMA channel */
  55. struct device *dev; /* Channel device */
  56. void *desc; /* buffer for descriptor array */
  57. int desc_num; /* desc count */
  58. size_t max_xfer_len; /* max transfer length */
  59. int id; /* Raw id of this channel */
  60. int irq; /* Channel IRQ */
  61. struct shdma_slave *slave; /* Client data for slave DMA */
  62. enum shdma_pm_state pm_state;
  63. };
  64. /**
  65. * struct shdma_ops - simple DMA driver operations
  66. * desc_completed: return true, if this is the descriptor, that just has
  67. * completed (atomic)
  68. * halt_channel: stop DMA channel operation (atomic)
  69. * channel_busy: return true, if the channel is busy (atomic)
  70. * slave_addr: return slave DMA address
  71. * desc_setup: set up the hardware specific descriptor portion (atomic)
  72. * set_slave: bind channel to a slave
  73. * setup_xfer: configure channel hardware for operation (atomic)
  74. * start_xfer: start the DMA transfer (atomic)
  75. * embedded_desc: return Nth struct shdma_desc pointer from the
  76. * descriptor array
  77. * chan_irq: process channel IRQ, return true if a transfer has
  78. * completed (atomic)
  79. */
  80. struct shdma_ops {
  81. bool (*desc_completed)(struct shdma_chan *, struct shdma_desc *);
  82. void (*halt_channel)(struct shdma_chan *);
  83. bool (*channel_busy)(struct shdma_chan *);
  84. dma_addr_t (*slave_addr)(struct shdma_chan *);
  85. int (*desc_setup)(struct shdma_chan *, struct shdma_desc *,
  86. dma_addr_t, dma_addr_t, size_t *);
  87. int (*set_slave)(struct shdma_chan *, struct shdma_slave *);
  88. void (*setup_xfer)(struct shdma_chan *, struct shdma_slave *);
  89. void (*start_xfer)(struct shdma_chan *, struct shdma_desc *);
  90. struct shdma_desc *(*embedded_desc)(void *, int);
  91. bool (*chan_irq)(struct shdma_chan *, int);
  92. };
  93. struct shdma_dev {
  94. struct dma_device dma_dev;
  95. struct shdma_chan **schan;
  96. const struct shdma_ops *ops;
  97. size_t desc_size;
  98. };
  99. #define shdma_for_each_chan(c, d, i) for (i = 0, c = (d)->schan[0]; \
  100. i < (d)->dma_dev.chancnt; c = (d)->schan[++i])
  101. int shdma_request_irq(struct shdma_chan *, int,
  102. unsigned long, const char *);
  103. void shdma_free_irq(struct shdma_chan *);
  104. bool shdma_reset(struct shdma_dev *sdev);
  105. void shdma_chan_probe(struct shdma_dev *sdev,
  106. struct shdma_chan *schan, int id);
  107. void shdma_chan_remove(struct shdma_chan *schan);
  108. int shdma_init(struct device *dev, struct shdma_dev *sdev,
  109. int chan_num);
  110. void shdma_cleanup(struct shdma_dev *sdev);
  111. #endif