hsu.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Driver for the High Speed UART DMA
  3. *
  4. * Copyright (C) 2015 Intel Corporation
  5. *
  6. * Partially based on the bits found in drivers/tty/serial/mfd.c.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef __DMA_HSU_H__
  13. #define __DMA_HSU_H__
  14. #include <linux/spinlock.h>
  15. #include <linux/dma/hsu.h>
  16. #include "../virt-dma.h"
  17. #define HSU_CH_SR 0x00 /* channel status */
  18. #define HSU_CH_CR 0x04 /* channel control */
  19. #define HSU_CH_DCR 0x08 /* descriptor control */
  20. #define HSU_CH_BSR 0x10 /* FIFO buffer size */
  21. #define HSU_CH_MTSR 0x14 /* minimum transfer size */
  22. #define HSU_CH_DxSAR(x) (0x20 + 8 * (x)) /* desc start addr */
  23. #define HSU_CH_DxTSR(x) (0x24 + 8 * (x)) /* desc transfer size */
  24. #define HSU_CH_D0SAR 0x20 /* desc 0 start addr */
  25. #define HSU_CH_D0TSR 0x24 /* desc 0 transfer size */
  26. #define HSU_CH_D1SAR 0x28
  27. #define HSU_CH_D1TSR 0x2c
  28. #define HSU_CH_D2SAR 0x30
  29. #define HSU_CH_D2TSR 0x34
  30. #define HSU_CH_D3SAR 0x38
  31. #define HSU_CH_D3TSR 0x3c
  32. #define HSU_DMA_CHAN_NR_DESC 4
  33. #define HSU_DMA_CHAN_LENGTH 0x40
  34. /* Bits in HSU_CH_SR */
  35. #define HSU_CH_SR_DESCTO(x) BIT(8 + (x))
  36. #define HSU_CH_SR_DESCTO_ANY (BIT(11) | BIT(10) | BIT(9) | BIT(8))
  37. #define HSU_CH_SR_CHE BIT(15)
  38. /* Bits in HSU_CH_CR */
  39. #define HSU_CH_CR_CHA BIT(0)
  40. #define HSU_CH_CR_CHD BIT(1)
  41. /* Bits in HSU_CH_DCR */
  42. #define HSU_CH_DCR_DESCA(x) BIT(0 + (x))
  43. #define HSU_CH_DCR_CHSOD(x) BIT(8 + (x))
  44. #define HSU_CH_DCR_CHSOTO BIT(14)
  45. #define HSU_CH_DCR_CHSOE BIT(15)
  46. #define HSU_CH_DCR_CHDI(x) BIT(16 + (x))
  47. #define HSU_CH_DCR_CHEI BIT(23)
  48. #define HSU_CH_DCR_CHTOI(x) BIT(24 + (x))
  49. struct hsu_dma_sg {
  50. dma_addr_t addr;
  51. unsigned int len;
  52. };
  53. struct hsu_dma_desc {
  54. struct virt_dma_desc vdesc;
  55. enum dma_transfer_direction direction;
  56. struct hsu_dma_sg *sg;
  57. unsigned int nents;
  58. unsigned int active;
  59. enum dma_status status;
  60. };
  61. static inline struct hsu_dma_desc *to_hsu_dma_desc(struct virt_dma_desc *vdesc)
  62. {
  63. return container_of(vdesc, struct hsu_dma_desc, vdesc);
  64. }
  65. struct hsu_dma_chan {
  66. struct virt_dma_chan vchan;
  67. void __iomem *reg;
  68. spinlock_t lock;
  69. /* hardware configuration */
  70. enum dma_transfer_direction direction;
  71. struct dma_slave_config config;
  72. struct hsu_dma_desc *desc;
  73. };
  74. static inline struct hsu_dma_chan *to_hsu_dma_chan(struct dma_chan *chan)
  75. {
  76. return container_of(chan, struct hsu_dma_chan, vchan.chan);
  77. }
  78. static inline u32 hsu_chan_readl(struct hsu_dma_chan *hsuc, int offset)
  79. {
  80. return readl(hsuc->reg + offset);
  81. }
  82. static inline void hsu_chan_writel(struct hsu_dma_chan *hsuc, int offset,
  83. u32 value)
  84. {
  85. writel(value, hsuc->reg + offset);
  86. }
  87. struct hsu_dma {
  88. struct dma_device dma;
  89. /* channels */
  90. struct hsu_dma_chan *chan;
  91. };
  92. static inline struct hsu_dma *to_hsu_dma(struct dma_device *ddev)
  93. {
  94. return container_of(ddev, struct hsu_dma, dma);
  95. }
  96. #endif /* __DMA_HSU_H__ */