etraxgpio.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * The following devices are accessible using this driver using
  3. * GPIO_MAJOR (120) and a couple of minor numbers.
  4. *
  5. * For ETRAX 100LX (CONFIG_ETRAX_ARCH_V10):
  6. * /dev/gpioa minor 0, 8 bit GPIO, each bit can change direction
  7. * /dev/gpiob minor 1, 8 bit GPIO, each bit can change direction
  8. * /dev/leds minor 2, Access to leds depending on kernelconfig
  9. * /dev/gpiog minor 3
  10. * g0dir, g8_15dir, g16_23dir, g24 dir configurable in R_GEN_CONFIG
  11. * g1-g7 and g25-g31 is both input and outputs but on different pins
  12. * Also note that some bits change pins depending on what interfaces
  13. * are enabled.
  14. *
  15. * For ETRAX FS (CONFIG_ETRAXFS):
  16. * /dev/gpioa minor 0, 8 bit GPIO, each bit can change direction
  17. * /dev/gpiob minor 1, 18 bit GPIO, each bit can change direction
  18. * /dev/gpioc minor 3, 18 bit GPIO, each bit can change direction
  19. * /dev/gpiod minor 4, 18 bit GPIO, each bit can change direction
  20. * /dev/gpioe minor 5, 18 bit GPIO, each bit can change direction
  21. * /dev/leds minor 2, Access to leds depending on kernelconfig
  22. *
  23. * For ARTPEC-3 (CONFIG_CRIS_MACH_ARTPEC3):
  24. * /dev/gpioa minor 0, 32 bit GPIO, each bit can change direction
  25. * /dev/gpiob minor 1, 32 bit GPIO, each bit can change direction
  26. * /dev/gpioc minor 3, 16 bit GPIO, each bit can change direction
  27. * /dev/gpiod minor 4, 32 bit GPIO, input only
  28. * /dev/leds minor 2, Access to leds depending on kernelconfig
  29. * /dev/pwm0 minor 16, PWM channel 0 on PA30
  30. * /dev/pwm1 minor 17, PWM channel 1 on PA31
  31. * /dev/pwm2 minor 18, PWM channel 2 on PB26
  32. * /dev/ppwm minor 19, PPWM channel
  33. *
  34. */
  35. #ifndef _ASM_ETRAXGPIO_H
  36. #define _ASM_ETRAXGPIO_H
  37. #define GPIO_MINOR_FIRST 0
  38. #define ETRAXGPIO_IOCTYPE 43
  39. /* etraxgpio _IOC_TYPE, bits 8 to 15 in ioctl cmd */
  40. #ifdef CONFIG_ETRAX_ARCH_V10
  41. #define GPIO_MINOR_A 0
  42. #define GPIO_MINOR_B 1
  43. #define GPIO_MINOR_LEDS 2
  44. #define GPIO_MINOR_G 3
  45. #define GPIO_MINOR_LAST 3
  46. #define GPIO_MINOR_LAST_REAL GPIO_MINOR_LAST
  47. #endif
  48. #ifdef CONFIG_ETRAXFS
  49. #define GPIO_MINOR_A 0
  50. #define GPIO_MINOR_B 1
  51. #define GPIO_MINOR_LEDS 2
  52. #define GPIO_MINOR_C 3
  53. #define GPIO_MINOR_D 4
  54. #define GPIO_MINOR_E 5
  55. #ifdef CONFIG_ETRAX_VIRTUAL_GPIO
  56. #define GPIO_MINOR_V 6
  57. #define GPIO_MINOR_LAST 6
  58. #else
  59. #define GPIO_MINOR_LAST 5
  60. #endif
  61. #define GPIO_MINOR_LAST_REAL GPIO_MINOR_LAST
  62. #endif
  63. #ifdef CONFIG_CRIS_MACH_ARTPEC3
  64. #define GPIO_MINOR_A 0
  65. #define GPIO_MINOR_B 1
  66. #define GPIO_MINOR_LEDS 2
  67. #define GPIO_MINOR_C 3
  68. #define GPIO_MINOR_D 4
  69. #ifdef CONFIG_ETRAX_VIRTUAL_GPIO
  70. #define GPIO_MINOR_V 6
  71. #define GPIO_MINOR_LAST 6
  72. #else
  73. #define GPIO_MINOR_LAST 4
  74. #endif
  75. #define GPIO_MINOR_FIRST_PWM 16
  76. #define GPIO_MINOR_PWM0 (GPIO_MINOR_FIRST_PWM+0)
  77. #define GPIO_MINOR_PWM1 (GPIO_MINOR_FIRST_PWM+1)
  78. #define GPIO_MINOR_PWM2 (GPIO_MINOR_FIRST_PWM+2)
  79. #define GPIO_MINOR_PPWM (GPIO_MINOR_FIRST_PWM+3)
  80. #define GPIO_MINOR_LAST_PWM GPIO_MINOR_PPWM
  81. #define GPIO_MINOR_LAST_REAL GPIO_MINOR_LAST_PWM
  82. #endif
  83. /* supported ioctl _IOC_NR's */
  84. #define IO_READBITS 0x1 /* read and return current port bits (obsolete) */
  85. #define IO_SETBITS 0x2 /* set the bits marked by 1 in the argument */
  86. #define IO_CLRBITS 0x3 /* clear the bits marked by 1 in the argument */
  87. /* the alarm is waited for by select() */
  88. #define IO_HIGHALARM 0x4 /* set alarm on high for bits marked by 1 */
  89. #define IO_LOWALARM 0x5 /* set alarm on low for bits marked by 1 */
  90. #define IO_CLRALARM 0x6 /* clear alarm for bits marked by 1 */
  91. /* LED ioctl */
  92. #define IO_LEDACTIVE_SET 0x7 /* set active led
  93. * 0=off, 1=green, 2=red, 3=yellow */
  94. /* GPIO direction ioctl's */
  95. #define IO_READDIR 0x8 /* Read direction 0=input 1=output (obsolete) */
  96. #define IO_SETINPUT 0x9 /* Set direction for bits set, 0=unchanged 1=input,
  97. returns mask with current inputs (obsolete) */
  98. #define IO_SETOUTPUT 0xA /* Set direction for bits set, 0=unchanged 1=output,
  99. returns mask with current outputs (obsolete)*/
  100. /* LED ioctl extended */
  101. #define IO_LED_SETBIT 0xB
  102. #define IO_LED_CLRBIT 0xC
  103. /* SHUTDOWN ioctl */
  104. #define IO_SHUTDOWN 0xD
  105. #define IO_GET_PWR_BT 0xE
  106. /* Bit toggling in driver settings */
  107. /* bit set in low byte0 is CLK mask (0x00FF),
  108. bit set in byte1 is DATA mask (0xFF00)
  109. msb, data_mask[7:0] , clk_mask[7:0]
  110. */
  111. #define IO_CFG_WRITE_MODE 0xF
  112. #define IO_CFG_WRITE_MODE_VALUE(msb, data_mask, clk_mask) \
  113. ( (((msb)&1) << 16) | (((data_mask) &0xFF) << 8) | ((clk_mask) & 0xFF) )
  114. /* The following 4 ioctl's take a pointer as argument and handles
  115. * 32 bit ports (port G) properly.
  116. * These replaces IO_READBITS,IO_SETINPUT AND IO_SETOUTPUT
  117. */
  118. #define IO_READ_INBITS 0x10 /* *arg is result of reading the input pins */
  119. #define IO_READ_OUTBITS 0x11 /* *arg is result of reading the output shadow */
  120. #define IO_SETGET_INPUT 0x12 /* bits set in *arg is set to input, */
  121. /* *arg updated with current input pins. */
  122. #define IO_SETGET_OUTPUT 0x13 /* bits set in *arg is set to output, */
  123. /* *arg updated with current output pins. */
  124. /* The following ioctl's are applicable to the PWM channels only */
  125. #define IO_PWM_SET_MODE 0x20
  126. enum io_pwm_mode {
  127. PWM_OFF = 0, /* disabled, deallocated */
  128. PWM_STANDARD = 1, /* 390 kHz, duty cycle 0..255/256 */
  129. PWM_FAST = 2, /* variable freq, w/ 10ns active pulse len */
  130. PWM_VARFREQ = 3, /* individually configurable high/low periods */
  131. PWM_SOFT = 4 /* software generated */
  132. };
  133. struct io_pwm_set_mode {
  134. enum io_pwm_mode mode;
  135. };
  136. /* Only for mode PWM_VARFREQ. Period lo/high set in increments of 10ns
  137. * from 10ns (value = 0) to 81920ns (value = 8191)
  138. * (Resulting frequencies range from 50 MHz (10ns + 10ns) down to
  139. * 6.1 kHz (81920ns + 81920ns) at 50% duty cycle, to 12.2 kHz at min/max duty
  140. * cycle (81920 + 10ns or 10ns + 81920ns, respectively).)
  141. */
  142. #define IO_PWM_SET_PERIOD 0x21
  143. struct io_pwm_set_period {
  144. unsigned int lo; /* 0..8191 */
  145. unsigned int hi; /* 0..8191 */
  146. };
  147. /* Only for modes PWM_STANDARD and PWM_FAST.
  148. * For PWM_STANDARD, set duty cycle of 390 kHz PWM output signal, from
  149. * 0 (value = 0) to 255/256 (value = 255).
  150. * For PWM_FAST, set duty cycle of PWM output signal from
  151. * 0% (value = 0) to 100% (value = 255). Output signal in this mode
  152. * is a 10ns pulse surrounded by a high or low level depending on duty
  153. * cycle (except for 0% and 100% which result in a constant output).
  154. * Resulting output frequency varies from 50 MHz at 50% duty cycle,
  155. * down to 390 kHz at min/max duty cycle.
  156. */
  157. #define IO_PWM_SET_DUTY 0x22
  158. struct io_pwm_set_duty {
  159. int duty; /* 0..255 */
  160. };
  161. /* Returns information about the latest PWM pulse.
  162. * lo: Length of the latest low period, in units of 10ns.
  163. * hi: Length of the latest high period, in units of 10ns.
  164. * cnt: Time since last detected edge, in units of 10ns.
  165. *
  166. * The input source to PWM is decied by IO_PWM_SET_INPUT_SRC.
  167. *
  168. * NOTE: All PWM devices is connected to the same input source.
  169. */
  170. #define IO_PWM_GET_PERIOD 0x23
  171. struct io_pwm_get_period {
  172. unsigned int lo;
  173. unsigned int hi;
  174. unsigned int cnt;
  175. };
  176. /* Sets the input source for the PWM input. For the src value see the
  177. * register description for gio:rw_pwm_in_cfg.
  178. *
  179. * NOTE: All PWM devices is connected to the same input source.
  180. */
  181. #define IO_PWM_SET_INPUT_SRC 0x24
  182. struct io_pwm_set_input_src {
  183. unsigned int src; /* 0..7 */
  184. };
  185. /* Sets the duty cycles in steps of 1/256, 0 = 0%, 255 = 100% duty cycle */
  186. #define IO_PPWM_SET_DUTY 0x25
  187. struct io_ppwm_set_duty {
  188. int duty; /* 0..255 */
  189. };
  190. /* Configuraton struct for the IO_PWMCLK_SET_CONFIG ioctl to configure
  191. * PWM capable gpio pins:
  192. */
  193. #define IO_PWMCLK_SETGET_CONFIG 0x26
  194. struct gpio_pwmclk_conf {
  195. unsigned int gpiopin; /* The pin number based on the opened device */
  196. unsigned int baseclk; /* The base clock to use, or sw will select one close*/
  197. unsigned int low; /* The number of low periods of the baseclk */
  198. unsigned int high; /* The number of high periods of the baseclk */
  199. };
  200. /* Examples:
  201. * To get a symmetric 12 MHz clock without knowing anything about the hardware:
  202. * baseclk = 12000000, low = 0, high = 0
  203. * To just get info of current setting:
  204. * baseclk = 0, low = 0, high = 0, the values will be updated by driver.
  205. */
  206. #endif