ec_kb3310b.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * KB3310B Embedded Controller
  4. *
  5. * Copyright (C) 2008 Lemote Inc.
  6. * Author: liujl <[email protected]>, 2008-03-14
  7. */
  8. #ifndef _EC_KB3310B_H
  9. #define _EC_KB3310B_H
  10. extern unsigned char ec_read(unsigned short addr);
  11. extern void ec_write(unsigned short addr, unsigned char val);
  12. extern int ec_query_seq(unsigned char cmd);
  13. extern int ec_query_event_num(void);
  14. extern int ec_get_event_num(void);
  15. typedef int (*sci_handler) (int status);
  16. extern sci_handler yeeloong_report_lid_status;
  17. #define SCI_IRQ_NUM 0x0A
  18. /*
  19. * The following registers are determined by the EC index configuration.
  20. * 1, fill the PORT_HIGH as EC register high part.
  21. * 2, fill the PORT_LOW as EC register low part.
  22. * 3, fill the PORT_DATA as EC register write data or get the data from it.
  23. */
  24. #define EC_IO_PORT_HIGH 0x0381
  25. #define EC_IO_PORT_LOW 0x0382
  26. #define EC_IO_PORT_DATA 0x0383
  27. /*
  28. * EC delay time is 500us for register and status access
  29. */
  30. #define EC_REG_DELAY 500 /* unit : us */
  31. #define EC_CMD_TIMEOUT 0x1000
  32. /*
  33. * EC access port for SCI communication
  34. */
  35. #define EC_CMD_PORT 0x66
  36. #define EC_STS_PORT 0x66
  37. #define EC_DAT_PORT 0x62
  38. #define CMD_INIT_IDLE_MODE 0xdd
  39. #define CMD_EXIT_IDLE_MODE 0xdf
  40. #define CMD_INIT_RESET_MODE 0xd8
  41. #define CMD_REBOOT_SYSTEM 0x8c
  42. #define CMD_GET_EVENT_NUM 0x84
  43. #define CMD_PROGRAM_PIECE 0xda
  44. /* temperature & fan registers */
  45. #define REG_TEMPERATURE_VALUE 0xF458
  46. #define REG_FAN_AUTO_MAN_SWITCH 0xF459
  47. #define BIT_FAN_AUTO 0
  48. #define BIT_FAN_MANUAL 1
  49. #define REG_FAN_CONTROL 0xF4D2
  50. #define BIT_FAN_CONTROL_ON (1 << 0)
  51. #define BIT_FAN_CONTROL_OFF (0 << 0)
  52. #define REG_FAN_STATUS 0xF4DA
  53. #define BIT_FAN_STATUS_ON (1 << 0)
  54. #define BIT_FAN_STATUS_OFF (0 << 0)
  55. #define REG_FAN_SPEED_HIGH 0xFE22
  56. #define REG_FAN_SPEED_LOW 0xFE23
  57. #define REG_FAN_SPEED_LEVEL 0xF4CC
  58. /* fan speed divider */
  59. #define FAN_SPEED_DIVIDER 480000 /* (60*1000*1000/62.5/2)*/
  60. /* battery registers */
  61. #define REG_BAT_DESIGN_CAP_HIGH 0xF77D
  62. #define REG_BAT_DESIGN_CAP_LOW 0xF77E
  63. #define REG_BAT_FULLCHG_CAP_HIGH 0xF780
  64. #define REG_BAT_FULLCHG_CAP_LOW 0xF781
  65. #define REG_BAT_DESIGN_VOL_HIGH 0xF782
  66. #define REG_BAT_DESIGN_VOL_LOW 0xF783
  67. #define REG_BAT_CURRENT_HIGH 0xF784
  68. #define REG_BAT_CURRENT_LOW 0xF785
  69. #define REG_BAT_VOLTAGE_HIGH 0xF786
  70. #define REG_BAT_VOLTAGE_LOW 0xF787
  71. #define REG_BAT_TEMPERATURE_HIGH 0xF788
  72. #define REG_BAT_TEMPERATURE_LOW 0xF789
  73. #define REG_BAT_RELATIVE_CAP_HIGH 0xF492
  74. #define REG_BAT_RELATIVE_CAP_LOW 0xF493
  75. #define REG_BAT_VENDOR 0xF4C4
  76. #define FLAG_BAT_VENDOR_SANYO 0x01
  77. #define FLAG_BAT_VENDOR_SIMPLO 0x02
  78. #define REG_BAT_CELL_COUNT 0xF4C6
  79. #define FLAG_BAT_CELL_3S1P 0x03
  80. #define FLAG_BAT_CELL_3S2P 0x06
  81. #define REG_BAT_CHARGE 0xF4A2
  82. #define FLAG_BAT_CHARGE_DISCHARGE 0x01
  83. #define FLAG_BAT_CHARGE_CHARGE 0x02
  84. #define FLAG_BAT_CHARGE_ACPOWER 0x00
  85. #define REG_BAT_STATUS 0xF4B0
  86. #define BIT_BAT_STATUS_LOW (1 << 5)
  87. #define BIT_BAT_STATUS_DESTROY (1 << 2)
  88. #define BIT_BAT_STATUS_FULL (1 << 1)
  89. #define BIT_BAT_STATUS_IN (1 << 0)
  90. #define REG_BAT_CHARGE_STATUS 0xF4B1
  91. #define BIT_BAT_CHARGE_STATUS_OVERTEMP (1 << 2)
  92. #define BIT_BAT_CHARGE_STATUS_PRECHG (1 << 1)
  93. #define REG_BAT_STATE 0xF482
  94. #define BIT_BAT_STATE_CHARGING (1 << 1)
  95. #define BIT_BAT_STATE_DISCHARGING (1 << 0)
  96. #define REG_BAT_POWER 0xF440
  97. #define BIT_BAT_POWER_S3 (1 << 2)
  98. #define BIT_BAT_POWER_ON (1 << 1)
  99. #define BIT_BAT_POWER_ACIN (1 << 0)
  100. /* other registers */
  101. /* Audio: rd/wr */
  102. #define REG_AUDIO_VOLUME 0xF46C
  103. #define REG_AUDIO_MUTE 0xF4E7
  104. #define REG_AUDIO_BEEP 0xF4D0
  105. /* USB port power or not: rd/wr */
  106. #define REG_USB0_FLAG 0xF461
  107. #define REG_USB1_FLAG 0xF462
  108. #define REG_USB2_FLAG 0xF463
  109. #define BIT_USB_FLAG_ON 1
  110. #define BIT_USB_FLAG_OFF 0
  111. /* LID */
  112. #define REG_LID_DETECT 0xF4BD
  113. #define BIT_LID_DETECT_ON 1
  114. #define BIT_LID_DETECT_OFF 0
  115. /* CRT */
  116. #define REG_CRT_DETECT 0xF4AD
  117. #define BIT_CRT_DETECT_PLUG 1
  118. #define BIT_CRT_DETECT_UNPLUG 0
  119. /* LCD backlight brightness adjust: 9 levels */
  120. #define REG_DISPLAY_BRIGHTNESS 0xF4F5
  121. /* Black screen Status */
  122. #define BIT_DISPLAY_LCD_ON 1
  123. #define BIT_DISPLAY_LCD_OFF 0
  124. /* LCD backlight control: off/restore */
  125. #define REG_BACKLIGHT_CTRL 0xF7BD
  126. #define BIT_BACKLIGHT_ON 1
  127. #define BIT_BACKLIGHT_OFF 0
  128. /* Reset the machine auto-clear: rd/wr */
  129. #define REG_RESET 0xF4EC
  130. #define BIT_RESET_ON 1
  131. /* Light the led: rd/wr */
  132. #define REG_LED 0xF4C8
  133. #define BIT_LED_RED_POWER (1 << 0)
  134. #define BIT_LED_ORANGE_POWER (1 << 1)
  135. #define BIT_LED_GREEN_CHARGE (1 << 2)
  136. #define BIT_LED_RED_CHARGE (1 << 3)
  137. #define BIT_LED_NUMLOCK (1 << 4)
  138. /* Test led mode, all led on/off */
  139. #define REG_LED_TEST 0xF4C2
  140. #define BIT_LED_TEST_IN 1
  141. #define BIT_LED_TEST_OUT 0
  142. /* Camera on/off */
  143. #define REG_CAMERA_STATUS 0xF46A
  144. #define BIT_CAMERA_STATUS_ON 1
  145. #define BIT_CAMERA_STATUS_OFF 0
  146. #define REG_CAMERA_CONTROL 0xF7B7
  147. #define BIT_CAMERA_CONTROL_OFF 0
  148. #define BIT_CAMERA_CONTROL_ON 1
  149. /* Wlan Status */
  150. #define REG_WLAN 0xF4FA
  151. #define BIT_WLAN_ON 1
  152. #define BIT_WLAN_OFF 0
  153. #define REG_DISPLAY_LCD 0xF79F
  154. /* SCI Event Number from EC */
  155. enum {
  156. EVENT_LID = 0x23, /* LID open/close */
  157. EVENT_DISPLAY_TOGGLE, /* Fn+F3 for display switch */
  158. EVENT_SLEEP, /* Fn+F1 for entering sleep mode */
  159. EVENT_OVERTEMP, /* Over-temperature happened */
  160. EVENT_CRT_DETECT, /* CRT is connected */
  161. EVENT_CAMERA, /* Camera on/off */
  162. EVENT_USB_OC2, /* USB2 Over Current occurred */
  163. EVENT_USB_OC0, /* USB0 Over Current occurred */
  164. EVENT_BLACK_SCREEN, /* Turn on/off backlight */
  165. EVENT_AUDIO_MUTE, /* Mute on/off */
  166. EVENT_DISPLAY_BRIGHTNESS,/* LCD backlight brightness adjust */
  167. EVENT_AC_BAT, /* AC & Battery relative issue */
  168. EVENT_AUDIO_VOLUME, /* Volume adjust */
  169. EVENT_WLAN, /* Wlan on/off */
  170. EVENT_END
  171. };
  172. #endif /* !_EC_KB3310B_H */