memoryOperation.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * GPIO Abstraction Layer
  3. *
  4. * Copyright 2006-2010 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/module.h>
  10. #include <linux/err.h>
  11. #include <linux/proc_fs.h>
  12. #include <linux/seq_file.h>
  13. #include <asm/blackfin.h>
  14. #include <asm/gpio.h>
  15. #include <asm/portmux.h>
  16. #include <linux/irq.h>
  17. #include <asm/irq_handler.h>
  18. #if ANOMALY_05000311 || ANOMALY_05000323
  19. enum {
  20. AWA_data = SYSCR,
  21. AWA_data_clear = SYSCR,
  22. AWA_data_set = SYSCR,
  23. AWA_toggle = SYSCR,
  24. AWA_maska = BFIN_UART_SCR,
  25. AWA_maska_clear = BFIN_UART_SCR,
  26. AWA_maska_set = BFIN_UART_SCR,
  27. AWA_maska_toggle = BFIN_UART_SCR,
  28. AWA_maskb = BFIN_UART_GCTL,
  29. AWA_maskb_clear = BFIN_UART_GCTL,
  30. AWA_maskb_set = BFIN_UART_GCTL,
  31. AWA_maskb_toggle = BFIN_UART_GCTL,
  32. AWA_dir = SPORT1_STAT,
  33. AWA_polar = SPORT1_STAT,
  34. AWA_edge = SPORT1_STAT,
  35. AWA_both = SPORT1_STAT,
  36. #if ANOMALY_05000311
  37. AWA_inen = TIMER_ENABLE,
  38. #elif ANOMALY_05000323
  39. AWA_inen = DMA1_1_CONFIG,
  40. #endif
  41. };
  42. /* Anomaly Workaround */
  43. #define AWA_DUMMY_READ(name) bfin_read16(AWA_ ## name)
  44. #else
  45. #define AWA_DUMMY_READ(...) do { } while (0)
  46. #endif
  47. static struct gpio_port_t * const gpio_array[] = {
  48. #if defined(BF533_FAMILY) || defined(BF538_FAMILY)
  49. (struct gpio_port_t *) FIO_FLAG_D,
  50. #elif defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
  51. (struct gpio_port_t *) PORTFIO,
  52. (struct gpio_port_t *) PORTGIO,
  53. (struct gpio_port_t *) PORTHIO,
  54. #elif defined(BF561_FAMILY)
  55. (struct gpio_port_t *) FIO0_FLAG_D,
  56. (struct gpio_port_t *) FIO1_FLAG_D,
  57. (struct gpio_port_t *) FIO2_FLAG_D,
  58. #elif defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
  59. (struct gpio_port_t *)PORTA_FER,
  60. (struct gpio_port_t *)PORTB_FER,
  61. (struct gpio_port_t *)PORTC_FER,
  62. (struct gpio_port_t *)PORTD_FER,
  63. (struct gpio_port_t *)PORTE_FER,
  64. (struct gpio_port_t *)PORTF_FER,
  65. (struct gpio_port_t *)PORTG_FER,
  66. # if defined(CONFIG_BF54x)
  67. (struct gpio_port_t *)PORTH_FER,
  68. (struct gpio_port_t *)PORTI_FER,
  69. (struct gpio_port_t *)PORTJ_FER,
  70. # endif
  71. #else
  72. # error no gpio arrays defined
  73. #endif
  74. };
  75. #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
  76. static unsigned short * const port_fer[] = {
  77. (unsigned short *) PORTF_FER,
  78. (unsigned short *) PORTG_FER,
  79. (unsigned short *) PORTH_FER,
  80. };
  81. # if !defined(BF537_FAMILY)
  82. static unsigned short * const port_mux[] = {
  83. (unsigned short *) PORTF_MUX,
  84. (unsigned short *) PORTG_MUX,
  85. (unsigned short *) PORTH_MUX,
  86. };
  87. static const
  88. u8 pmux_offset[][16] = {
  89. # if defined(CONFIG_BF52x)
  90. { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 4, 6, 8, 8, 10, 10 }, /* PORTF */
  91. { 0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 8, 10, 10, 10, 12, 12 }, /* PORTG */
  92. { 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4 }, /* PORTH */
  93. # elif defined(CONFIG_BF51x)
  94. { 0, 2, 2, 2, 2, 2, 2, 4, 6, 6, 6, 8, 8, 8, 8, 10 }, /* PORTF */
  95. { 0, 0, 0, 2, 4, 6, 6, 6, 8, 10, 10, 12, 14, 14, 14, 14 }, /* PORTG */
  96. { 0, 0, 0, 0, 2, 2, 4, 6, 10, 10, 10, 10, 10, 10, 10, 10 }, /* PORTH */
  97. # endif
  98. };
  99. # endif
  100. #elif defined(BF538_FAMILY)
  101. static unsigned short * const port_fer[] = {
  102. (unsigned short *) PORTCIO_FER,
  103. (unsigned short *) PORTDIO_FER,
  104. (unsigned short *) PORTEIO_FER,
  105. };
  106. #endif
  107. #define RESOURCE_LABEL_SIZE 16
  108. static struct str_ident {
  109. char name[RESOURCE_LABEL_SIZE];
  110. } str_ident[MAX_RESOURCES];
  111. #if defined(CONFIG_PM)
  112. static struct gpio_port_s gpio_bank_saved[GPIO_BANK_NUM];
  113. # ifdef BF538_FAMILY
  114. static unsigned short port_fer_saved[3];
  115. # endif
  116. #endif
  117. static void gpio_error(unsigned gpio)
  118. {
  119. printk(KERN_ERR "bfin-gpio: GPIO %d wasn't requested!\n", gpio);
  120. }
  121. static void set_label(unsigned short ident, const char *label)
  122. {
  123. if (label) {
  124. strncpy(str_ident[ident].name, label,
  125. RESOURCE_LABEL_SIZE);
  126. str_ident[ident].name[RESOURCE_LABEL_SIZE - 1] = 0;
  127. }
  128. }
  129. static char *get_label(unsigned short ident)
  130. {
  131. return (*str_ident[ident].name ? str_ident[ident].name : "UNKNOWN");
  132. }
  133. static int cmp_label(unsigned short ident, const char *label)
  134. {
  135. if (label == NULL) {
  136. dump_stack();
  137. printk(KERN_ERR "Please provide none-null label\n");
  138. }
  139. if (label)
  140. return strcmp(str_ident[ident].name, label);
  141. else
  142. return -EINVAL;
  143. }
  144. #define map_entry(m, i) reserved_##m##_map[gpio_bank(i)]
  145. #define is_reserved(m, i, e) (map_entry(m, i) & gpio_bit(i))
  146. #define reserve(m, i) (map_entry(m, i) |= gpio_bit(i))
  147. #define unreserve(m, i) (map_entry(m, i) &= ~gpio_bit(i))
  148. #define DECLARE_RESERVED_MAP(m, c) static unsigned short reserved_##m##_map[c]
  149. DECLARE_RESERVED_MAP(gpio, GPIO_BANK_NUM);
  150. DECLARE_RESERVED_MAP(peri, DIV_ROUND_UP(MAX_RESOURCES, GPIO_BANKSIZE));
  151. DECLARE_RESERVED_MAP(gpio_irq, GPIO_BANK_NUM);
  152. inline int check_gpio(unsigned gpio)
  153. {
  154. #if defined(CONFIG_BF54x)
  155. if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15
  156. || gpio == GPIO_PH14 || gpio == GPIO_PH15
  157. || gpio == GPIO_PJ14 || gpio == GPIO_PJ15)
  158. return -EINVAL;
  159. #endif
  160. if (gpio >= MAX_BLACKFIN_GPIOS)
  161. return -EINVAL;
  162. return 0;
  163. }
  164. static void port_setup(unsigned gpio, unsigned short usage)
  165. {
  166. #if defined(BF538_FAMILY)
  167. /*
  168. * BF538/9 Port C,D and E are special.
  169. * Inverted PORT_FER polarity on CDE and no PORF_FER on F
  170. * Regular PORT F GPIOs are handled here, CDE are exclusively
  171. * managed by GPIOLIB
  172. */
  173. if (gpio < MAX_BLACKFIN_GPIOS || gpio >= MAX_RESOURCES)
  174. return;
  175. gpio -= MAX_BLACKFIN_GPIOS;
  176. if (usage == GPIO_USAGE)
  177. *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
  178. else
  179. *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio);
  180. SSYNC();
  181. return;
  182. #endif
  183. if (check_gpio(gpio))
  184. return;
  185. #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
  186. if (usage == GPIO_USAGE)
  187. *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio);
  188. else
  189. *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
  190. SSYNC();
  191. #elif defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
  192. if (usage == GPIO_USAGE)
  193. gpio_array[gpio_bank(gpio)]->port_fer &= ~gpio_bit(gpio);
  194. else
  195. gpio_array[gpio_bank(gpio)]->port_fer |= gpio_bit(gpio);
  196. SSYNC();
  197. #endif
  198. }
  199. #ifdef BF537_FAMILY
  200. static const s8 port_mux[] = {
  201. [GPIO_PF0] = 3,
  202. [GPIO_PF1] = 3,
  203. [GPIO_PF2] = 4,
  204. [GPIO_PF3] = 4,
  205. [GPIO_PF4] = 5,
  206. [GPIO_PF5] = 6,
  207. [GPIO_PF6] = 7,
  208. [GPIO_PF7] = 8,
  209. [GPIO_PF8 ... GPIO_PF15] = -1,
  210. [GPIO_PG0 ... GPIO_PG7] = -1,