162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * KB3310B Embedded Controller
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci *  Copyright (C) 2008 Lemote Inc.
662306a36Sopenharmony_ci *  Author: liujl <liujl@lemote.com>, 2008-03-14
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef _EC_KB3310B_H
1062306a36Sopenharmony_ci#define _EC_KB3310B_H
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciextern unsigned char ec_read(unsigned short addr);
1362306a36Sopenharmony_ciextern void ec_write(unsigned short addr, unsigned char val);
1462306a36Sopenharmony_ciextern int ec_query_seq(unsigned char cmd);
1562306a36Sopenharmony_ciextern int ec_query_event_num(void);
1662306a36Sopenharmony_ciextern int ec_get_event_num(void);
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_citypedef int (*sci_handler) (int status);
1962306a36Sopenharmony_ciextern sci_handler yeeloong_report_lid_status;
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#define SCI_IRQ_NUM 0x0A
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/*
2462306a36Sopenharmony_ci * The following registers are determined by the EC index configuration.
2562306a36Sopenharmony_ci * 1, fill the PORT_HIGH as EC register high part.
2662306a36Sopenharmony_ci * 2, fill the PORT_LOW as EC register low part.
2762306a36Sopenharmony_ci * 3, fill the PORT_DATA as EC register write data or get the data from it.
2862306a36Sopenharmony_ci */
2962306a36Sopenharmony_ci#define EC_IO_PORT_HIGH 0x0381
3062306a36Sopenharmony_ci#define EC_IO_PORT_LOW	0x0382
3162306a36Sopenharmony_ci#define EC_IO_PORT_DATA 0x0383
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci/*
3462306a36Sopenharmony_ci * EC delay time is 500us for register and status access
3562306a36Sopenharmony_ci */
3662306a36Sopenharmony_ci#define EC_REG_DELAY	500	/* unit : us */
3762306a36Sopenharmony_ci#define EC_CMD_TIMEOUT	0x1000
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/*
4062306a36Sopenharmony_ci * EC access port for SCI communication
4162306a36Sopenharmony_ci */
4262306a36Sopenharmony_ci#define EC_CMD_PORT		0x66
4362306a36Sopenharmony_ci#define EC_STS_PORT		0x66
4462306a36Sopenharmony_ci#define EC_DAT_PORT		0x62
4562306a36Sopenharmony_ci#define CMD_INIT_IDLE_MODE	0xdd
4662306a36Sopenharmony_ci#define CMD_EXIT_IDLE_MODE	0xdf
4762306a36Sopenharmony_ci#define CMD_INIT_RESET_MODE	0xd8
4862306a36Sopenharmony_ci#define CMD_REBOOT_SYSTEM	0x8c
4962306a36Sopenharmony_ci#define CMD_GET_EVENT_NUM	0x84
5062306a36Sopenharmony_ci#define CMD_PROGRAM_PIECE	0xda
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/* temperature & fan registers */
5362306a36Sopenharmony_ci#define REG_TEMPERATURE_VALUE	0xF458
5462306a36Sopenharmony_ci#define REG_FAN_AUTO_MAN_SWITCH 0xF459
5562306a36Sopenharmony_ci#define BIT_FAN_AUTO		0
5662306a36Sopenharmony_ci#define BIT_FAN_MANUAL		1
5762306a36Sopenharmony_ci#define REG_FAN_CONTROL		0xF4D2
5862306a36Sopenharmony_ci#define BIT_FAN_CONTROL_ON	(1 << 0)
5962306a36Sopenharmony_ci#define BIT_FAN_CONTROL_OFF	(0 << 0)
6062306a36Sopenharmony_ci#define REG_FAN_STATUS		0xF4DA
6162306a36Sopenharmony_ci#define BIT_FAN_STATUS_ON	(1 << 0)
6262306a36Sopenharmony_ci#define BIT_FAN_STATUS_OFF	(0 << 0)
6362306a36Sopenharmony_ci#define REG_FAN_SPEED_HIGH	0xFE22
6462306a36Sopenharmony_ci#define REG_FAN_SPEED_LOW	0xFE23
6562306a36Sopenharmony_ci#define REG_FAN_SPEED_LEVEL	0xF4CC
6662306a36Sopenharmony_ci/* fan speed divider */
6762306a36Sopenharmony_ci#define FAN_SPEED_DIVIDER	480000	/* (60*1000*1000/62.5/2)*/
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci/* battery registers */
7062306a36Sopenharmony_ci#define REG_BAT_DESIGN_CAP_HIGH		0xF77D
7162306a36Sopenharmony_ci#define REG_BAT_DESIGN_CAP_LOW		0xF77E
7262306a36Sopenharmony_ci#define REG_BAT_FULLCHG_CAP_HIGH	0xF780
7362306a36Sopenharmony_ci#define REG_BAT_FULLCHG_CAP_LOW		0xF781
7462306a36Sopenharmony_ci#define REG_BAT_DESIGN_VOL_HIGH		0xF782
7562306a36Sopenharmony_ci#define REG_BAT_DESIGN_VOL_LOW		0xF783
7662306a36Sopenharmony_ci#define REG_BAT_CURRENT_HIGH		0xF784
7762306a36Sopenharmony_ci#define REG_BAT_CURRENT_LOW		0xF785
7862306a36Sopenharmony_ci#define REG_BAT_VOLTAGE_HIGH		0xF786
7962306a36Sopenharmony_ci#define REG_BAT_VOLTAGE_LOW		0xF787
8062306a36Sopenharmony_ci#define REG_BAT_TEMPERATURE_HIGH	0xF788
8162306a36Sopenharmony_ci#define REG_BAT_TEMPERATURE_LOW		0xF789
8262306a36Sopenharmony_ci#define REG_BAT_RELATIVE_CAP_HIGH	0xF492
8362306a36Sopenharmony_ci#define REG_BAT_RELATIVE_CAP_LOW	0xF493
8462306a36Sopenharmony_ci#define REG_BAT_VENDOR			0xF4C4
8562306a36Sopenharmony_ci#define FLAG_BAT_VENDOR_SANYO		0x01
8662306a36Sopenharmony_ci#define FLAG_BAT_VENDOR_SIMPLO		0x02
8762306a36Sopenharmony_ci#define REG_BAT_CELL_COUNT		0xF4C6
8862306a36Sopenharmony_ci#define FLAG_BAT_CELL_3S1P		0x03
8962306a36Sopenharmony_ci#define FLAG_BAT_CELL_3S2P		0x06
9062306a36Sopenharmony_ci#define REG_BAT_CHARGE			0xF4A2
9162306a36Sopenharmony_ci#define FLAG_BAT_CHARGE_DISCHARGE	0x01
9262306a36Sopenharmony_ci#define FLAG_BAT_CHARGE_CHARGE		0x02
9362306a36Sopenharmony_ci#define FLAG_BAT_CHARGE_ACPOWER		0x00
9462306a36Sopenharmony_ci#define REG_BAT_STATUS			0xF4B0
9562306a36Sopenharmony_ci#define BIT_BAT_STATUS_LOW		(1 << 5)
9662306a36Sopenharmony_ci#define BIT_BAT_STATUS_DESTROY		(1 << 2)
9762306a36Sopenharmony_ci#define BIT_BAT_STATUS_FULL		(1 << 1)
9862306a36Sopenharmony_ci#define BIT_BAT_STATUS_IN		(1 << 0)
9962306a36Sopenharmony_ci#define REG_BAT_CHARGE_STATUS		0xF4B1
10062306a36Sopenharmony_ci#define BIT_BAT_CHARGE_STATUS_OVERTEMP	(1 << 2)
10162306a36Sopenharmony_ci#define BIT_BAT_CHARGE_STATUS_PRECHG	(1 << 1)
10262306a36Sopenharmony_ci#define REG_BAT_STATE			0xF482
10362306a36Sopenharmony_ci#define BIT_BAT_STATE_CHARGING		(1 << 1)
10462306a36Sopenharmony_ci#define BIT_BAT_STATE_DISCHARGING	(1 << 0)
10562306a36Sopenharmony_ci#define REG_BAT_POWER			0xF440
10662306a36Sopenharmony_ci#define BIT_BAT_POWER_S3		(1 << 2)
10762306a36Sopenharmony_ci#define BIT_BAT_POWER_ON		(1 << 1)
10862306a36Sopenharmony_ci#define BIT_BAT_POWER_ACIN		(1 << 0)
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci/* other registers */
11162306a36Sopenharmony_ci/* Audio: rd/wr */
11262306a36Sopenharmony_ci#define REG_AUDIO_VOLUME	0xF46C
11362306a36Sopenharmony_ci#define REG_AUDIO_MUTE		0xF4E7
11462306a36Sopenharmony_ci#define REG_AUDIO_BEEP		0xF4D0
11562306a36Sopenharmony_ci/* USB port power or not: rd/wr */
11662306a36Sopenharmony_ci#define REG_USB0_FLAG		0xF461
11762306a36Sopenharmony_ci#define REG_USB1_FLAG		0xF462
11862306a36Sopenharmony_ci#define REG_USB2_FLAG		0xF463
11962306a36Sopenharmony_ci#define BIT_USB_FLAG_ON		1
12062306a36Sopenharmony_ci#define BIT_USB_FLAG_OFF	0
12162306a36Sopenharmony_ci/* LID */
12262306a36Sopenharmony_ci#define REG_LID_DETECT		0xF4BD
12362306a36Sopenharmony_ci#define BIT_LID_DETECT_ON	1
12462306a36Sopenharmony_ci#define BIT_LID_DETECT_OFF	0
12562306a36Sopenharmony_ci/* CRT */
12662306a36Sopenharmony_ci#define REG_CRT_DETECT		0xF4AD
12762306a36Sopenharmony_ci#define BIT_CRT_DETECT_PLUG	1
12862306a36Sopenharmony_ci#define BIT_CRT_DETECT_UNPLUG	0
12962306a36Sopenharmony_ci/* LCD backlight brightness adjust: 9 levels */
13062306a36Sopenharmony_ci#define REG_DISPLAY_BRIGHTNESS	0xF4F5
13162306a36Sopenharmony_ci/* Black screen Status */
13262306a36Sopenharmony_ci#define BIT_DISPLAY_LCD_ON	1
13362306a36Sopenharmony_ci#define BIT_DISPLAY_LCD_OFF	0
13462306a36Sopenharmony_ci/* LCD backlight control: off/restore */
13562306a36Sopenharmony_ci#define REG_BACKLIGHT_CTRL	0xF7BD
13662306a36Sopenharmony_ci#define BIT_BACKLIGHT_ON	1
13762306a36Sopenharmony_ci#define BIT_BACKLIGHT_OFF	0
13862306a36Sopenharmony_ci/* Reset the machine auto-clear: rd/wr */
13962306a36Sopenharmony_ci#define REG_RESET		0xF4EC
14062306a36Sopenharmony_ci#define BIT_RESET_ON		1
14162306a36Sopenharmony_ci/* Light the led: rd/wr */
14262306a36Sopenharmony_ci#define REG_LED			0xF4C8
14362306a36Sopenharmony_ci#define BIT_LED_RED_POWER	(1 << 0)
14462306a36Sopenharmony_ci#define BIT_LED_ORANGE_POWER	(1 << 1)
14562306a36Sopenharmony_ci#define BIT_LED_GREEN_CHARGE	(1 << 2)
14662306a36Sopenharmony_ci#define BIT_LED_RED_CHARGE	(1 << 3)
14762306a36Sopenharmony_ci#define BIT_LED_NUMLOCK		(1 << 4)
14862306a36Sopenharmony_ci/* Test led mode, all led on/off */
14962306a36Sopenharmony_ci#define REG_LED_TEST		0xF4C2
15062306a36Sopenharmony_ci#define BIT_LED_TEST_IN		1
15162306a36Sopenharmony_ci#define BIT_LED_TEST_OUT	0
15262306a36Sopenharmony_ci/* Camera on/off */
15362306a36Sopenharmony_ci#define REG_CAMERA_STATUS	0xF46A
15462306a36Sopenharmony_ci#define BIT_CAMERA_STATUS_ON	1
15562306a36Sopenharmony_ci#define BIT_CAMERA_STATUS_OFF	0
15662306a36Sopenharmony_ci#define REG_CAMERA_CONTROL	0xF7B7
15762306a36Sopenharmony_ci#define BIT_CAMERA_CONTROL_OFF	0
15862306a36Sopenharmony_ci#define BIT_CAMERA_CONTROL_ON	1
15962306a36Sopenharmony_ci/* Wlan Status */
16062306a36Sopenharmony_ci#define REG_WLAN		0xF4FA
16162306a36Sopenharmony_ci#define BIT_WLAN_ON		1
16262306a36Sopenharmony_ci#define BIT_WLAN_OFF		0
16362306a36Sopenharmony_ci#define REG_DISPLAY_LCD		0xF79F
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci/* SCI Event Number from EC */
16662306a36Sopenharmony_cienum {
16762306a36Sopenharmony_ci	EVENT_LID = 0x23,	/*  LID open/close */
16862306a36Sopenharmony_ci	EVENT_DISPLAY_TOGGLE,	/*  Fn+F3 for display switch */
16962306a36Sopenharmony_ci	EVENT_SLEEP,		/*  Fn+F1 for entering sleep mode */
17062306a36Sopenharmony_ci	EVENT_OVERTEMP,		/*  Over-temperature happened */
17162306a36Sopenharmony_ci	EVENT_CRT_DETECT,	/*  CRT is connected */
17262306a36Sopenharmony_ci	EVENT_CAMERA,		/*  Camera on/off */
17362306a36Sopenharmony_ci	EVENT_USB_OC2,		/*  USB2 Over Current occurred */
17462306a36Sopenharmony_ci	EVENT_USB_OC0,		/*  USB0 Over Current occurred */
17562306a36Sopenharmony_ci	EVENT_BLACK_SCREEN,	/*  Turn on/off backlight */
17662306a36Sopenharmony_ci	EVENT_AUDIO_MUTE,	/*  Mute on/off */
17762306a36Sopenharmony_ci	EVENT_DISPLAY_BRIGHTNESS,/* LCD backlight brightness adjust */
17862306a36Sopenharmony_ci	EVENT_AC_BAT,		/*  AC & Battery relative issue */
17962306a36Sopenharmony_ci	EVENT_AUDIO_VOLUME,	/*  Volume adjust */
18062306a36Sopenharmony_ci	EVENT_WLAN,		/*  Wlan on/off */
18162306a36Sopenharmony_ci	EVENT_END
18262306a36Sopenharmony_ci};
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci#endif /* !_EC_KB3310B_H */
185