cs5535.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * AMD CS5535/CS5536 definitions
  3. * Copyright (C) 2006 Advanced Micro Devices, Inc.
  4. * Copyright (C) 2009 Andres Salomon <dilinger@collabora.co.uk>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of version 2 of the GNU General Public License
  8. * as published by the Free Software Foundation.
  9. */
  10. #ifndef _CS5535_H
  11. #define _CS5535_H
  12. #include <asm/msr.h>
  13. /* MSRs */
  14. #define MSR_GLIU_P2D_RO0 0x10000029
  15. #define MSR_LX_GLD_MSR_CONFIG 0x48002001
  16. #define MSR_LX_MSR_PADSEL 0x48002011 /* NOT 0x48000011; the data
  17. * sheet has the wrong value */
  18. #define MSR_GLCP_SYS_RSTPLL 0x4C000014
  19. #define MSR_GLCP_DOTPLL 0x4C000015
  20. #define MSR_LBAR_SMB 0x5140000B
  21. #define MSR_LBAR_GPIO 0x5140000C
  22. #define MSR_LBAR_MFGPT 0x5140000D
  23. #define MSR_LBAR_ACPI 0x5140000E
  24. #define MSR_LBAR_PMS 0x5140000F
  25. #define MSR_DIVIL_SOFT_RESET 0x51400017
  26. #define MSR_PIC_YSEL_LOW 0x51400020
  27. #define MSR_PIC_YSEL_HIGH 0x51400021
  28. #define MSR_PIC_ZSEL_LOW 0x51400022
  29. #define MSR_PIC_ZSEL_HIGH 0x51400023
  30. #define MSR_PIC_IRQM_LPC 0x51400025
  31. #define MSR_MFGPT_IRQ 0x51400028
  32. #define MSR_MFGPT_NR 0x51400029
  33. #define MSR_MFGPT_SETUP 0x5140002B
  34. #define MSR_RTC_DOMA_OFFSET 0x51400055
  35. #define MSR_RTC_MONA_OFFSET 0x51400056
  36. #define MSR_RTC_CEN_OFFSET 0x51400057
  37. #define MSR_LX_SPARE_MSR 0x80000011 /* DC-specific */
  38. #define MSR_GX_GLD_MSR_CONFIG 0xC0002001
  39. #define MSR_GX_MSR_PADSEL 0xC0002011
  40. static inline int cs5535_pic_unreqz_select_high(unsigned int group,
  41. unsigned int irq)
  42. {
  43. uint32_t lo, hi;
  44. rdmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
  45. lo &= ~(0xF << (group * 4));
  46. lo |= (irq & 0xF) << (group * 4);
  47. wrmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
  48. return 0;
  49. }
  50. /* PIC registers */
  51. #define CS5536_PIC_INT_SEL1 0x4d0
  52. #define CS5536_PIC_INT_SEL2 0x4d1
  53. /* resource sizes */
  54. #define LBAR_GPIO_SIZE 0xFF
  55. #define LBAR_MFGPT_SIZE 0x40
  56. #define LBAR_ACPI_SIZE 0x40
  57. #define LBAR_PMS_SIZE 0x80
  58. /*
  59. * PMC registers (PMS block)
  60. * It is only safe to access these registers as dword accesses.
  61. * See CS5536 Specification Update erratas 17 & 18
  62. */
  63. #define CS5536_PM_SCLK 0x10
  64. #define CS5536_PM_IN_SLPCTL 0x20
  65. #define CS5536_PM_WKXD 0x34
  66. #define CS5536_PM_WKD 0x30
  67. #define CS5536_PM_SSC 0x54
  68. /*
  69. * PM registers (ACPI block)
  70. * It is only safe to access these registers as dword accesses.
  71. * See CS5536 Specification Update erratas 17 & 18
  72. */
  73. #define CS5536_PM1_STS 0x00
  74. #define CS5536_PM1_EN 0x02
  75. #define CS5536_PM1_CNT 0x08
  76. #define CS5536_PM_GPE0_STS 0x18
  77. #define CS5536_PM_GPE0_EN 0x1c
  78. /* CS5536_PM1_STS bits */
  79. #define CS5536_WAK_FLAG (1 << 15)
  80. #define CS5536_PWRBTN_FLAG (1 << 8)
  81. /* CS5536_PM1_EN bits */
  82. #define CS5536_PM_PWRBTN (1 << 8)
  83. #define CS5536_PM_RTC (1 << 10)
  84. /* CS5536_PM_GPE0_STS bits */
  85. #define CS5536_GPIOM7_PME_FLAG (1 << 31)
  86. #define CS5536_GPIOM6_PME_FLAG (1 << 30)
  87. /* CS5536_PM_GPE0_EN bits */
  88. #define CS5536_GPIOM7_PME_EN (1 << 31)
  89. #define CS5536_GPIOM6_PME_EN (1 << 30)
  90. /* VSA2 magic values */
  91. #define VSA_VRC_INDEX 0xAC1C
  92. #define VSA_VRC_DATA 0xAC1E
  93. #define VSA_VR_UNLOCK 0xFC53 /* unlock virtual register */
  94. #define VSA_VR_SIGNATURE 0x0003
  95. #define VSA_VR_MEM_SIZE 0x0200
  96. #define AMD_VSA_SIG 0x4132 /* signature is ascii 'VSA2' */
  97. #define GSW_VSA_SIG 0x534d /* General Software signature */
  98. #include <linux/io.h>
  99. static inline int cs5535_has_vsa2(void)
  100. {
  101. static int has_vsa2 = -1;
  102. if (has_vsa2 == -1) {
  103. uint16_t val;
  104. /*
  105. * The VSA has virtual registers that we can query for a
  106. * signature.
  107. */
  108. outw(VSA_VR_UNLOCK, VSA_VRC_INDEX);
  109. outw(VSA_VR_SIGNATURE, VSA_VRC_INDEX);
  110. val = inw(VSA_VRC_DATA);
  111. has_vsa2 = (val == AMD_VSA_SIG || val == GSW_VSA_SIG);
  112. }
  113. return has_vsa2;
  114. }
  115. /* GPIOs */
  116. #define GPIO_OUTPUT_VAL 0x00
  117. #define GPIO_OUTPUT_ENABLE 0x04
  118. #define GPIO_OUTPUT_OPEN_DRAIN 0x08
  119. #define GPIO_OUTPUT_INVERT 0x0C
  120. #define GPIO_OUTPUT_AUX1 0x10
  121. #define GPIO_OUTPUT_AUX2 0x14
  122. #define GPIO_PULL_UP 0x18
  123. #define GPIO_PULL_DOWN 0x1C
  124. #define GPIO_INPUT_ENABLE 0x20
  125. #define GPIO_INPUT_INVERT 0x24
  126. #define GPIO_INPUT_FILTER 0x28
  127. #define GPIO_INPUT_EVENT_COUNT 0x2C
  128. #define GPIO_READ_BACK 0x30
  129. #define GPIO_INPUT_AUX1 0x34
  130. #define GPIO_EVENTS_ENABLE 0x38
  131. #define GPIO_LOCK_ENABLE 0x3C
  132. #define GPIO_POSITIVE_EDGE_EN 0x40
  133. #define GPIO_NEGATIVE_EDGE_EN 0x44
  134. #define GPIO_POSITIVE_EDGE_STS 0x48
  135. #define GPIO_NEGATIVE_EDGE_STS 0x4C
  136. #define GPIO_FLTR7_AMOUNT 0xD8
  137. #define GPIO_MAP_X 0xE0
  138. #define GPIO_MAP_Y 0xE4
  139. #define GPIO_MAP_Z 0xE8
  140. #define GPIO_MAP_W 0xEC
  141. #define GPIO_FE7_SEL 0xF7
  142. void cs5535_gpio_set(unsigned offset, unsigned int reg);
  143. void cs5535_gpio_clear(unsigned offset, unsigned int reg);
  144. int cs5535_gpio_isset(unsigned offset, unsigned int reg);
  145. int cs5535_gpio_set_irq(unsigned group, unsigned irq);
  146. void cs5535_gpio_setup_event(unsigned offset, int pair, int pme);
  147. /* MFGPTs */
  148. #define MFGPT_MAX_TIMERS 8
  149. #define MFGPT_TIMER_ANY (-1)
  150. #define MFGPT_DOMAIN_WORKING 1
  151. #define MFGPT_DOMAIN_STANDBY 2
  152. #define MFGPT_DOMAIN_ANY (MFGPT_DOMAIN_WORKING | MFGPT_DOMAIN_STANDBY)
  153. #define MFGPT_CMP1 0
  154. #define MFGPT_CMP2 1
  155. #define MFGPT_EVENT_IRQ 0
  156. #define MFGPT_EVENT_NMI 1
  157. #define MFGPT_EVENT_RESET 3
  158. #define MFGPT_REG_CMP1 0
  159. #define MFGPT_REG_CMP2 2
  160. #define MFGPT_REG_COUNTER 4
  161. #define MFGPT_REG_SETUP 6
  162. #define MFGPT_SETUP_CNTEN (1 << 15)
  163. #define MFGPT_SETUP_CMP2 (1 << 14)
  164. #define MFGPT_SETUP_CMP1 (1 << 13)
  165. #define MFGPT_SETUP_SETUP (1 << 12)
  166. #define MFGPT_SETUP_STOPEN (1 << 11)
  167. #define MFGPT_SETUP_EXTEN (1 << 10)
  168. #define MFGPT_SETUP_REVEN (1 << 5)
  169. #define MFGPT_SETUP_CLKSEL (1 << 4)
  170. struct cs5535_mfgpt_timer;
  171. extern uint16_t cs5535_mfgpt_read(struct cs5535_mfgpt_timer *timer,
  172. uint16_t reg);
  173. extern void cs5535_mfgpt_write(struct cs5535_mfgpt_timer *timer, uint16_t reg,
  174. uint16_t value);
  175. extern int cs5535_mfgpt_toggle_event(struct cs5535_mfgpt_timer *timer, int cmp,
  176. int event, int enable);
  177. extern int cs5535_mfgpt_set_irq(struct cs5535_mfgpt_timer *timer, int cmp,
  178. int *irq, int enable);
  179. extern struct cs5535_mfgpt_timer *cs5535_mfgpt_alloc_timer(int timer,
  180. int domain);
  181. extern void cs5535_mfgpt_free_timer(struct cs5535_mfgpt_timer *timer);
  182. static inline int cs5535_mfgpt_setup_irq(struct cs5535_mfgpt_timer *timer,
  183. int cmp, int *irq)
  184. {
  185. return cs5535_mfgpt_set_irq(timer, cmp, irq, 1);
  186. }
  187. static inline int cs5535_mfgpt_release_irq(struct cs5535_mfgpt_timer *timer,
  188. int cmp, int *irq)
  189. {
  190. return cs5535_mfgpt_set_irq(timer, cmp, irq, 0);
  191. }
  192. #endif