img-ir.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * ImgTec IR Decoder found in PowerDown Controller.
  3. *
  4. * Copyright 2010-2014 Imagination Technologies Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #ifndef _IMG_IR_H_
  12. #define _IMG_IR_H_
  13. #include <linux/io.h>
  14. #include <linux/spinlock.h>
  15. #include "img-ir-raw.h"
  16. #include "img-ir-hw.h"
  17. /* registers */
  18. /* relative to the start of the IR block of registers */
  19. #define IMG_IR_CONTROL 0x00
  20. #define IMG_IR_STATUS 0x04
  21. #define IMG_IR_DATA_LW 0x08
  22. #define IMG_IR_DATA_UP 0x0c
  23. #define IMG_IR_LEAD_SYMB_TIMING 0x10
  24. #define IMG_IR_S00_SYMB_TIMING 0x14
  25. #define IMG_IR_S01_SYMB_TIMING 0x18
  26. #define IMG_IR_S10_SYMB_TIMING 0x1c
  27. #define IMG_IR_S11_SYMB_TIMING 0x20
  28. #define IMG_IR_FREE_SYMB_TIMING 0x24
  29. #define IMG_IR_POW_MOD_PARAMS 0x28
  30. #define IMG_IR_POW_MOD_ENABLE 0x2c
  31. #define IMG_IR_IRQ_MSG_DATA_LW 0x30
  32. #define IMG_IR_IRQ_MSG_DATA_UP 0x34
  33. #define IMG_IR_IRQ_MSG_MASK_LW 0x38
  34. #define IMG_IR_IRQ_MSG_MASK_UP 0x3c
  35. #define IMG_IR_IRQ_ENABLE 0x40
  36. #define IMG_IR_IRQ_STATUS 0x44
  37. #define IMG_IR_IRQ_CLEAR 0x48
  38. #define IMG_IR_IRCORE_ID 0xf0
  39. #define IMG_IR_CORE_REV 0xf4
  40. #define IMG_IR_CORE_DES1 0xf8
  41. #define IMG_IR_CORE_DES2 0xfc
  42. /* field masks */
  43. /* IMG_IR_CONTROL */
  44. #define IMG_IR_DECODEN 0x40000000
  45. #define IMG_IR_CODETYPE 0x30000000
  46. #define IMG_IR_CODETYPE_SHIFT 28
  47. #define IMG_IR_HDRTOG 0x08000000
  48. #define IMG_IR_LDRDEC 0x04000000
  49. #define IMG_IR_DECODINPOL 0x02000000 /* active high */
  50. #define IMG_IR_BITORIEN 0x01000000 /* MSB first */
  51. #define IMG_IR_D1VALIDSEL 0x00008000
  52. #define IMG_IR_BITINV 0x00000040 /* don't invert */
  53. #define IMG_IR_DECODEND2 0x00000010
  54. #define IMG_IR_BITORIEND2 0x00000002 /* MSB first */
  55. #define IMG_IR_BITINVD2 0x00000001 /* don't invert */
  56. /* IMG_IR_STATUS */
  57. #define IMG_IR_RXDVALD2 0x00001000
  58. #define IMG_IR_IRRXD 0x00000400
  59. #define IMG_IR_TOGSTATE 0x00000200
  60. #define IMG_IR_RXDVAL 0x00000040
  61. #define IMG_IR_RXDLEN 0x0000003f
  62. #define IMG_IR_RXDLEN_SHIFT 0
  63. /* IMG_IR_LEAD_SYMB_TIMING, IMG_IR_Sxx_SYMB_TIMING */
  64. #define IMG_IR_PD_MAX 0xff000000
  65. #define IMG_IR_PD_MAX_SHIFT 24
  66. #define IMG_IR_PD_MIN 0x00ff0000
  67. #define IMG_IR_PD_MIN_SHIFT 16
  68. #define IMG_IR_W_MAX 0x0000ff00
  69. #define IMG_IR_W_MAX_SHIFT 8
  70. #define IMG_IR_W_MIN 0x000000ff
  71. #define IMG_IR_W_MIN_SHIFT 0
  72. /* IMG_IR_FREE_SYMB_TIMING */
  73. #define IMG_IR_MAXLEN 0x0007e000
  74. #define IMG_IR_MAXLEN_SHIFT 13
  75. #define IMG_IR_MINLEN 0x00001f00
  76. #define IMG_IR_MINLEN_SHIFT 8
  77. #define IMG_IR_FT_MIN 0x000000ff
  78. #define IMG_IR_FT_MIN_SHIFT 0
  79. /* IMG_IR_POW_MOD_PARAMS */
  80. #define IMG_IR_PERIOD_LEN 0x3f000000
  81. #define IMG_IR_PERIOD_LEN_SHIFT 24
  82. #define IMG_IR_PERIOD_DUTY 0x003f0000
  83. #define IMG_IR_PERIOD_DUTY_SHIFT 16
  84. #define IMG_IR_STABLE_STOP 0x00003f00
  85. #define IMG_IR_STABLE_STOP_SHIFT 8
  86. #define IMG_IR_STABLE_START 0x0000003f
  87. #define IMG_IR_STABLE_START_SHIFT 0
  88. /* IMG_IR_POW_MOD_ENABLE */
  89. #define IMG_IR_POWER_OUT_EN 0x00000002
  90. #define IMG_IR_POWER_MOD_EN 0x00000001
  91. /* IMG_IR_IRQ_ENABLE, IMG_IR_IRQ_STATUS, IMG_IR_IRQ_CLEAR */
  92. #define IMG_IR_IRQ_DEC2_ERR 0x00000080
  93. #define IMG_IR_IRQ_DEC_ERR 0x00000040
  94. #define IMG_IR_IRQ_ACT_LEVEL 0x00000020
  95. #define IMG_IR_IRQ_FALL_EDGE 0x00000010
  96. #define IMG_IR_IRQ_RISE_EDGE 0x00000008
  97. #define IMG_IR_IRQ_DATA_MATCH 0x00000004
  98. #define IMG_IR_IRQ_DATA2_VALID 0x00000002
  99. #define IMG_IR_IRQ_DATA_VALID 0x00000001
  100. #define IMG_IR_IRQ_ALL 0x000000ff
  101. #define IMG_IR_IRQ_EDGE (IMG_IR_IRQ_FALL_EDGE | IMG_IR_IRQ_RISE_EDGE)
  102. /* IMG_IR_CORE_ID */
  103. #define IMG_IR_CORE_ID 0x00ff0000
  104. #define IMG_IR_CORE_ID_SHIFT 16
  105. #define IMG_IR_CORE_CONFIG 0x0000ffff
  106. #define IMG_IR_CORE_CONFIG_SHIFT 0
  107. /* IMG_IR_CORE_REV */
  108. #define IMG_IR_DESIGNER 0xff000000
  109. #define IMG_IR_DESIGNER_SHIFT 24
  110. #define IMG_IR_MAJOR_REV 0x00ff0000
  111. #define IMG_IR_MAJOR_REV_SHIFT 16
  112. #define IMG_IR_MINOR_REV 0x0000ff00
  113. #define IMG_IR_MINOR_REV_SHIFT 8
  114. #define IMG_IR_MAINT_REV 0x000000ff
  115. #define IMG_IR_MAINT_REV_SHIFT 0
  116. struct device;
  117. struct clk;
  118. /**
  119. * struct img_ir_priv - Private driver data.
  120. * @dev: Platform device.
  121. * @irq: IRQ number.
  122. * @clk: Input clock.
  123. * @sys_clk: System clock.
  124. * @reg_base: Iomem base address of IR register block.
  125. * @lock: Protects IR registers and variables in this struct.
  126. * @raw: Driver data for raw decoder.
  127. * @hw: Driver data for hardware decoder.
  128. */
  129. struct img_ir_priv {
  130. struct device *dev;
  131. int irq;
  132. struct clk *clk;
  133. struct clk *sys_clk;
  134. void __iomem *reg_base;
  135. spinlock_t lock;
  136. struct img_ir_priv_raw raw;
  137. struct img_ir_priv_hw hw;
  138. };
  139. /* Hardware access */
  140. static inline void img_ir_write(struct img_ir_priv *priv,
  141. unsigned int reg_offs, unsigned int data)
  142. {
  143. iowrite32(data, priv->reg_base + reg_offs);
  144. }
  145. static inline unsigned int img_ir_read(struct img_ir_priv *priv,
  146. unsigned int reg_offs)
  147. {
  148. return ioread32(priv->reg_base + reg_offs);
  149. }
  150. #endif /* _IMG_IR_H_ */