ns87308.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * (C) Copyright 2000
  3. * Rob Taylor, Flying Pig Systems. robt@flyingpig.com.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #ifndef _NS87308_H_
  8. #define _NS87308_H_
  9. #include <asm/pci_io.h>
  10. /* Note: I couldn't find a full data sheet for the ns87308, but the ns87307 seems to be pretty
  11. functionally- (and pin-) equivalent to the 87308, but the 308 has better ir support. */
  12. void initialise_ns87308(void);
  13. /*
  14. * The following struct represents the GPIO registers on the NS87308/NS97307
  15. */
  16. struct GPIO
  17. {
  18. unsigned char dta1; /* 0 data port 1 */
  19. unsigned char dir1; /* 1 direction port 1 */
  20. unsigned char out1; /* 2 output type port 1 */
  21. unsigned char puc1; /* 3 pull-up control port 1 */
  22. unsigned char dta2; /* 4 data port 2 */
  23. unsigned char dir2; /* 5 direction port 2 */
  24. unsigned char out2; /* 6 output type port 2 */
  25. unsigned char puc2; /* 7 pull-up control port 2 */
  26. };
  27. /*
  28. * The following represents the power management registers on the NS87308/NS97307
  29. */
  30. #define PWM_FER1 0 /* 0 function enable reg. 1 */
  31. #define PWM_FER2 1 /* 1 function enable reg. 2 */
  32. #define PWM_PMC1 2 /* 2 power mgmt. control 1 */
  33. #define PWM_PMC2 3 /* 3 power mgmt. control 2 */
  34. #define PWM_PMC3 4 /* 4 power mgmt. control 3 */
  35. #define PWM_WDTO 5 /* 5 watchdog time-out */
  36. #define PWM_WDCF 6 /* 6 watchdog config. */
  37. #define PWM_WDST 7 /* 7 watchdog status */
  38. /*PNP config registers:
  39. * these depend on the stated of BADDR1 and BADDR0 on startup
  40. * so there's three versions here with the last two digits indicating
  41. * for which configuration their valid
  42. * the 1st of the two digits indicates the state of BADDR1
  43. * the 2st of the two digits indicates the state of BADDR0
  44. */
  45. #define IO_INDEX_OFFSET_0x 0x0279 /* full PnP isa Mode */
  46. #define IO_INDEX_OFFSET_10 0x015C /* PnP motherboard mode */
  47. #define IO_INDEX_OFFSET_11 0x002E /* PnP motherboard mode */
  48. #define IO_DATA_OFFSET_0x 0x0A79 /* full PnP isa Mode */
  49. #define IO_DATA_OFFSET_10 0x015D /* PnP motherboard mode */
  50. #define IO_DATA_OFFSET_11 0x002F /* PnP motherboard mode */
  51. #if defined(CONFIG_SYS_NS87308_BADDR_0x)
  52. #define IO_INDEX (CONFIG_SYS_ISA_IO + IO_INDEX_OFFSET_0x)
  53. #define IO_DATA (CONFIG_SYS_ISA_IO + IO_DATA_OFFSET_0x)
  54. #elif defined(CONFIG_SYS_NS87308_BADDR_10)
  55. #define IO_INDEX (CONFIG_SYS_ISA_IO + IO_INDEX_OFFSET_10)
  56. #define IO_DATA (CONFIG_SYS_ISA_IO + IO_DATA_OFFSET_10)
  57. #elif defined(CONFIG_SYS_NS87308_BADDR_11)
  58. #define IO_INDEX (CONFIG_SYS_ISA_IO + IO_INDEX_OFFSET_11)
  59. #define IO_DATA (CONFIG_SYS_ISA_IO + IO_DATA_OFFSET_11)
  60. #endif
  61. /* PnP register definitions */
  62. #define SET_RD_DATA_PORT 0x00
  63. #define SERIAL_ISOLATION 0x01
  64. #define CONFIG_CONTROL 0x02
  65. #define WAKE_CSN 0x03
  66. #define RES_DATA 0x04
  67. #define STATUS 0x05
  68. #define SET_CSN 0x06
  69. #define LOGICAL_DEVICE 0x07
  70. /*vendor defined values */
  71. #define SID_REG 0x20
  72. #define SUPOERIO_CONF1 0x21
  73. #define SUPOERIO_CONF2 0x22
  74. #define PGCS_INDEX 0x23
  75. #define PGCS_DATA 0x24
  76. /* values above 30 are different for each logical device
  77. but I can't be arsed to enter them all. the ones here
  78. are pretty consistent between all logical devices
  79. feel free to correct the situation if you want.. ;)
  80. */
  81. #define ACTIVATE 0x30
  82. #define ACTIVATE_OFF 0x00
  83. #define ACTIVATE_ON 0x01
  84. #define BASE_ADDR_HIGH 0x60
  85. #define BASE_ADDR_LOW 0x61
  86. #define LUN_CONFIG_REG 0xF0
  87. #define DBASE_HIGH 0x60 /* SIO KBC data base address, 15:8 */
  88. #define DBASE_LOW 0x61 /* SIO KBC data base address, 7:0 */
  89. #define CBASE_HIGH 0x62 /* SIO KBC command base addr, 15:8 */
  90. #define CBASE_LOW 0x63 /* SIO KBC command base addr, 7:0 */
  91. /* the logical devices*/
  92. #define LDEV_KBC1 0x00 /* 2 devices for keyboard and mouse controller*/
  93. #define LDEV_KBC2 0x01
  94. #define LDEV_MOUSE 0x01
  95. #define LDEV_RTC_APC 0x02 /*Real Time Clock and Advanced Power Control*/
  96. #define LDEV_FDC 0x03 /*floppy disk controller*/
  97. #define LDEV_PARP 0x04 /*Parallel port*/
  98. #define LDEV_UART2 0x05
  99. #define LDEV_UART1 0x06
  100. #define LDEV_GPIO 0x07 /*General Purpose IO and chip select output signals*/
  101. #define LDEV_POWRMAN 0x08 /*Power Managment*/
  102. #define CONFIG_SYS_NS87308_KBC1 (1 << LDEV_KBC1)
  103. #define CONFIG_SYS_NS87308_KBC2 (1 << LDEV_KBC2)
  104. #define CONFIG_SYS_NS87308_MOUSE (1 << LDEV_MOUSE)
  105. #define CONFIG_SYS_NS87308_RTC_APC (1 << LDEV_RTC_APC)
  106. #define CONFIG_SYS_NS87308_FDC (1 << LDEV_FDC)
  107. #define CONFIG_SYS_NS87308_PARP (1 << LDEV_PARP)
  108. #define CONFIG_SYS_NS87308_UART2 (1 << LDEV_UART2)
  109. #define CONFIG_SYS_NS87308_UART1 (1 << LDEV_UART1)
  110. #define CONFIG_SYS_NS87308_GPIO (1 << LDEV_GPIO)
  111. #define CONFIG_SYS_NS87308_POWRMAN (1 << LDEV_POWRMAN)
  112. /*some functions and macro's for doing configuration */
  113. static inline void read_pnp_config(unsigned char index, unsigned char *data)
  114. {
  115. pci_writeb(index,IO_INDEX);
  116. pci_readb(IO_DATA, *data);
  117. }
  118. static inline void write_pnp_config(unsigned char index, unsigned char data)
  119. {
  120. pci_writeb(index,IO_INDEX);
  121. pci_writeb(data, IO_DATA);
  122. }
  123. static inline void pnp_set_device(unsigned char dev)
  124. {
  125. write_pnp_config(LOGICAL_DEVICE, dev);
  126. }
  127. static inline void write_pm_reg(unsigned short base, unsigned char index, unsigned char data)
  128. {
  129. pci_writeb(index, CONFIG_SYS_ISA_IO + base);
  130. eieio();
  131. pci_writeb(data, CONFIG_SYS_ISA_IO + base + 1);
  132. }
  133. /*void write_pnp_config(unsigned char index, unsigned char data);
  134. void pnp_set_device(unsigned char dev);
  135. */
  136. #define PNP_SET_DEVICE_BASE(dev,base) \
  137. pnp_set_device(dev); \
  138. write_pnp_config(ACTIVATE, ACTIVATE_OFF); \
  139. write_pnp_config(BASE_ADDR_HIGH, ((base) >> 8) & 0xff ); \
  140. write_pnp_config(BASE_ADDR_LOW, (base) &0xff); \
  141. write_pnp_config(ACTIVATE, ACTIVATE_ON);
  142. #define PNP_ACTIVATE_DEVICE(dev) \
  143. pnp_set_device(dev); \
  144. write_pnp_config(ACTIVATE, ACTIVATE_ON);
  145. #define PNP_DEACTIVATE_DEVICE(dev) \
  146. pnp_set_device(dev); \
  147. write_pnp_config(ACTIVATE, ACTIVATE_OFF);
  148. static inline void write_pgcs_config(unsigned char index, unsigned char data)
  149. {
  150. write_pnp_config(PGCS_INDEX, index);
  151. write_pnp_config(PGCS_DATA, data);
  152. }
  153. /* these macrose configure the 3 CS lines
  154. on the sandpoint board these controll NVRAM
  155. CS0 is connected to NVRAMCS
  156. CS1 is connected to NVRAMAS0
  157. CS2 is connected to NVRAMAS1
  158. */
  159. #define PGCS_CS_ASSERT_ON_WRITE 0x10
  160. #define PGCS_CS_ASSERT_ON_READ 0x20
  161. #define PNP_PGCS_CSLINE_BASE(cs, base) \
  162. write_pgcs_config((cs) << 2, ((base) >> 8) & 0xff ); \
  163. write_pgcs_config(((cs) << 2) + 1, (base) & 0xff );
  164. #define PNP_PGCS_CSLINE_CONF(cs, conf) \
  165. write_pgcs_config(((cs) << 2) + 2, (conf) );
  166. /* The following sections are for 87308 extensions to the standard compoents it emulates */
  167. /* extensions to 16550*/
  168. #define MCR_MDSL_MSK 0xe0 /*mode select mask*/
  169. #define MCR_MDSL_UART 0x00 /*uart, default*/
  170. #define MCR_MDSL_SHRPIR 0x02 /*Sharp IR*/
  171. #define MCR_MDSL_SIR 0x03 /*SIR*/
  172. #define MCR_MDSL_CIR 0x06 /*Consumer IR*/
  173. #define FCR_TXFTH0 0x10 /* these bits control threshod of data level in fifo */
  174. #define FCR_TXFTH1 0x20 /* for interrupt trigger */
  175. /*
  176. * Default NS87308 configuration
  177. */
  178. #ifndef CONFIG_SYS_NS87308_KBC1_BASE
  179. #define CONFIG_SYS_NS87308_KBC1_BASE 0x0060
  180. #endif
  181. #ifndef CONFIG_SYS_NS87308_RTC_BASE
  182. #define CONFIG_SYS_NS87308_RTC_BASE 0x0070
  183. #endif
  184. #ifndef CONFIG_SYS_NS87308_FDC_BASE
  185. #define CONFIG_SYS_NS87308_FDC_BASE 0x03F0
  186. #endif
  187. #ifndef CONFIG_SYS_NS87308_LPT_BASE
  188. #define CONFIG_SYS_NS87308_LPT_BASE 0x0278
  189. #endif
  190. #ifndef CONFIG_SYS_NS87308_UART1_BASE
  191. #define CONFIG_SYS_NS87308_UART1_BASE 0x03F8
  192. #endif
  193. #ifndef CONFIG_SYS_NS87308_UART2_BASE
  194. #define CONFIG_SYS_NS87308_UART2_BASE 0x02F8
  195. #endif
  196. #endif /*_NS87308_H_*/