ec/it*: Merge all identical ITE EC files

Most of the code is the same between IT8587E and IT5570E.

Identical files were detected with:

    diff -rs src/ec/it8587e/ src/ec/it5570e/ | egrep '^Files .+ and .+ are identical$'

Then manually moved from one variant and deleted from the other.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2021-06-10 12:12:16 -06:00
committed by Jeremy Soller
parent c7fafe0103
commit 851221da61
33 changed files with 16 additions and 475 deletions

View File

@@ -1,11 +1,8 @@
# SPDX-License-Identifier: GPL-3.0-only
ARCH=8051
# 64 KB is the max without banking
CODE_SIZE=65536
# SRAM is 6144 bytes, only 4096 bytes are mapped at address 0. Region at
# 0x0E00-0x1000 is used for AP communication. So this is brought down to 2048,
# which matches it8587e limits
SRAM_SIZE=2048
include src/ec/ite/ec.mk

View File

@@ -1,9 +1,6 @@
# SPDX-License-Identifier: GPL-3.0-only
ARCH=8051
# 64 KB is the max without banking
CODE_SIZE=65536
# SRAM is 4096 bytes, but SRAM at address 2048 is used for scratch ROM
SRAM_SIZE=2048
include src/ec/ite/ec.mk

View File

@@ -1,19 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <ec/gpio.h>
bool gpio_get(struct Gpio * gpio) {
if (*(gpio->data) & gpio->value) {
return true;
} else {
return false;
}
}
void gpio_set(struct Gpio * gpio, bool value) {
if (value) {
*(gpio->data) |= gpio->value;
} else {
*(gpio->data) &= ~(gpio->value);
}
}

View File

@@ -1,10 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _EC_BRAM_H
#define _EC_BRAM_H
#include <stdint.h>
volatile uint8_t __xdata __at(0x2200) BRAM[192];
#endif // _EC_BRAM_H

View File

@@ -1,14 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _EC_DAC_H
#define _EC_DAC_H
#include <stdint.h>
volatile uint8_t __xdata __at(0x1A01) DACPDREG;
volatile uint8_t __xdata __at(0x1A04) DACDAT2;
volatile uint8_t __xdata __at(0x1A05) DACDAT3;
volatile uint8_t __xdata __at(0x1A06) DACDAT4;
volatile uint8_t __xdata __at(0x1A07) DACDAT5;
#endif // _EC_DAC_H

View File

@@ -1,8 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _EC_EC_H
#define _EC_EC_H
void ec_init(void);
#endif // _EC_EC_H

View File

@@ -1,17 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _EC_ECPM_H
#define _EC_ECPM_H
#include <stdint.h>
volatile uint8_t __xdata __at(0x1E01) CGCTRL1;
volatile uint8_t __xdata __at(0x1E02) CGCTRL2;
volatile uint8_t __xdata __at(0x1E03) PLLCTRL;
volatile uint8_t __xdata __at(0x1E04) AUTOCG;
volatile uint8_t __xdata __at(0x1E05) CGCTRL3;
volatile uint8_t __xdata __at(0x1E06) PLLFREQ;
volatile uint8_t __xdata __at(0x1E08) PLLCSS;
volatile uint8_t __xdata __at(0x1E09) CGCTRL4;
#endif // _EC_ECPM_H

View File

@@ -1,15 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _EC_ECWD_H
#define _EC_ECWD_H
#include <stdint.h>
volatile uint8_t __xdata __at(0x1F01) ETWCFG;
volatile uint8_t __xdata __at(0x1F02) ET1PSR;
volatile uint8_t __xdata __at(0x1F04) ET1CNTLLR;
volatile uint8_t __xdata __at(0x1F06) EWDCNTLLR;
volatile uint8_t __xdata __at(0x1F07) EWDKEYR;
volatile uint8_t __xdata __at(0x1F09) EWDCNTLHR;
#endif // _EC_ECWD_H

View File

@@ -1,46 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _EC_KBC_H
#define _EC_KBC_H
#include <common/macro.h>
#include <stdbool.h>
#include <stdint.h>
void kbc_init(void);
struct Kbc {
// Control register
volatile uint8_t * control;
// Interrupt control register
volatile uint8_t * irq;
// Status register
volatile uint8_t * status;
// Keyboard out register
volatile uint8_t * keyboard_out;
// Mouse out register
volatile uint8_t * mouse_out;
// Data in register
volatile uint8_t * data_in;
};
extern struct Kbc __code KBC;
#define KBC_STS_OBF BIT(0)
#define KBC_STS_IBF BIT(1)
#define KBC_STS_CMD BIT(3)
uint8_t kbc_status(struct Kbc * kbc);
uint8_t kbc_read(struct Kbc * kbc);
bool kbc_keyboard(struct Kbc * kbc, uint8_t data, int timeout);
bool kbc_mouse(struct Kbc * kbc, uint8_t data, int timeout);
volatile uint8_t __xdata __at(0x1300) KBHICR;
volatile uint8_t __xdata __at(0x1302) KBIRQR;
volatile uint8_t __xdata __at(0x1304) KBHISR;
volatile uint8_t __xdata __at(0x1306) KBHIKDOR;
volatile uint8_t __xdata __at(0x1308) KBHIMDOR;
volatile uint8_t __xdata __at(0x130A) KBHIDIR;
#endif // _EC_KBC_H

View File

@@ -1,49 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _EC_KBSCAN_H
#define _EC_KBSCAN_H
#include <stdint.h>
volatile uint8_t __xdata __at(0x1D00) KSOL;
volatile uint8_t __xdata __at(0x1D01) KSOH1;
volatile uint8_t __xdata __at(0x1D02) KSOCTRL;
volatile uint8_t __xdata __at(0x1D03) KSOH2;
volatile uint8_t __xdata __at(0x1D04) KSI;
volatile uint8_t __xdata __at(0x1D05) KSICTRLR;
volatile uint8_t __xdata __at(0x1D06) KSIGCTRL;
volatile uint8_t __xdata __at(0x1D07) KSIGOEN;
volatile uint8_t __xdata __at(0x1D08) KSIGDAT;
volatile uint8_t __xdata __at(0x1D09) KSIGDMRR;
volatile uint8_t __xdata __at(0x1D0A) KSOHGCTRL;
volatile uint8_t __xdata __at(0x1D0B) KSOHGOEN;
volatile uint8_t __xdata __at(0x1D0C) KSOHGDMRR;
volatile uint8_t __xdata __at(0x1D0D) KSOLGCTRL;
volatile uint8_t __xdata __at(0x1D0E) KSOLGOEN;
volatile uint8_t __xdata __at(0x1D0F) KSOLGDMRR;
volatile uint8_t __xdata __at(0x1D10) KSO0LSDR;
volatile uint8_t __xdata __at(0x1D11) KSO1LSDR;
volatile uint8_t __xdata __at(0x1D12) KSO2LSDR;
volatile uint8_t __xdata __at(0x1D13) KSO3LSDR;
volatile uint8_t __xdata __at(0x1D14) KSO4LSDR;
volatile uint8_t __xdata __at(0x1D15) KSO5LSDR;
volatile uint8_t __xdata __at(0x1D16) KSO6LSDR;
volatile uint8_t __xdata __at(0x1D17) KSO7LSDR;
volatile uint8_t __xdata __at(0x1D18) KSO8LSDR;
volatile uint8_t __xdata __at(0x1D19) KSO9LSDR;
volatile uint8_t __xdata __at(0x1D1A) KSO10LSDR;
volatile uint8_t __xdata __at(0x1D1B) KSO11LSDR;
volatile uint8_t __xdata __at(0x1D1C) KSO12LSDR;
volatile uint8_t __xdata __at(0x1D1D) KSO13LSDR;
volatile uint8_t __xdata __at(0x1D1E) KSO14LSDR;
volatile uint8_t __xdata __at(0x1D1F) KSO15LSDR;
volatile uint8_t __xdata __at(0x1D20) KSO16LSDR;
volatile uint8_t __xdata __at(0x1D21) KSO17LSDR;
volatile uint8_t __xdata __at(0x1D22) SDC1R;
volatile uint8_t __xdata __at(0x1D23) SDC2R;
volatile uint8_t __xdata __at(0x1D24) SDC3R;
volatile uint8_t __xdata __at(0x1D25) SDSR;
#endif // _EC_KBSCAN_H

View File

@@ -1,20 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _EC_PECI_H
#define _EC_PECI_H
#include <stdint.h>
static volatile uint8_t __xdata __at(0x3000) HOSTAR;
static volatile uint8_t __xdata __at(0x3001) HOCTLR;
static volatile uint8_t __xdata __at(0x3002) HOCMDR;
static volatile uint8_t __xdata __at(0x3003) HOTRADDR;
static volatile uint8_t __xdata __at(0x3004) HOWRLR;
static volatile uint8_t __xdata __at(0x3005) HORDLR;
static volatile uint8_t __xdata __at(0x3006) HOWRDR;
static volatile uint8_t __xdata __at(0x3007) HORDDR;
static volatile uint8_t __xdata __at(0x3008) HOCTL2R;
static volatile uint8_t __xdata __at(0x3009) RWFCSV;
static volatile uint8_t __xdata __at(0x300E) PADCTLR;
#endif // _EC_PECI_H

View File

@@ -1,62 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _EC_PMC_H
#define _EC_PMC_H
#include <common/macro.h>
#include <stdbool.h>
#include <stdint.h>
struct Pmc {
// Status register
volatile uint8_t * status;
// Data out register
volatile uint8_t * data_out;
// Data in register
volatile uint8_t * data_in;
// Control register
volatile uint8_t * control;
};
extern struct Pmc __code PMC_1;
extern struct Pmc __code PMC_2;
extern struct Pmc __code PMC_3;
extern struct Pmc __code PMC_4;
extern struct Pmc __code PMC_5;
#define PMC_STS_OBF BIT(0)
#define PMC_STS_IBF BIT(1)
#define PMC_STS_CMD BIT(3)
uint8_t pmc_status(struct Pmc * pmc);
void pmc_set_status(struct Pmc * pmc, uint8_t status);
uint8_t pmc_read(struct Pmc * pmc);
void pmc_write(struct Pmc * pmc, uint8_t data);
volatile uint8_t __xdata __at(0x1500) PM1STS;
volatile uint8_t __xdata __at(0x1501) PM1DO;
volatile uint8_t __xdata __at(0x1504) PM1DI;
volatile uint8_t __xdata __at(0x1506) PM1CTL;
volatile uint8_t __xdata __at(0x1510) PM2STS;
volatile uint8_t __xdata __at(0x1511) PM2DO;
volatile uint8_t __xdata __at(0x1514) PM2DI;
volatile uint8_t __xdata __at(0x1516) PM2CTL;
volatile uint8_t __xdata __at(0x1520) PM3STS;
volatile uint8_t __xdata __at(0x1521) PM3DO;
volatile uint8_t __xdata __at(0x1522) PM3DI;
volatile uint8_t __xdata __at(0x1523) PM3CTL;
volatile uint8_t __xdata __at(0x1530) PM4STS;
volatile uint8_t __xdata __at(0x1531) PM4DO;
volatile uint8_t __xdata __at(0x1532) PM4DI;
volatile uint8_t __xdata __at(0x1533) PM4CTL;
volatile uint8_t __xdata __at(0x1540) PM5STS;
volatile uint8_t __xdata __at(0x1541) PM5DO;
volatile uint8_t __xdata __at(0x1542) PM5DI;
volatile uint8_t __xdata __at(0x1543) PM5CTL;
#endif // _EC_PMC_H

View File

@@ -1,43 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _EC_PS2_H
#define _EC_PS2_H
#include <stdint.h>
#define PSSTS_TIMEOUT_ERR BIT(6)
#define PSSTS_FRAME_ERR BIT(5)
#define PSSTS_PARITY_ERR BIT(4)
#define PSSTS_ALL_ERR (PSSTS_TIMEOUT_ERR | PSSTS_FRAME_ERR | PSSTS_PARITY_ERR)
#define PSSTS_DONE BIT(3)
struct Ps2 {
volatile uint8_t * control;
volatile uint8_t * interrupt;
volatile uint8_t * status;
volatile uint8_t * data;
};
extern struct Ps2 __code PS2_1;
extern struct Ps2 __code PS2_2;
extern struct Ps2 __code PS2_3;
void ps2_reset(struct Ps2 * ps2);
volatile uint8_t __xdata __at(0x1700) PSCTL1;
volatile uint8_t __xdata __at(0x1701) PSCTL2;
volatile uint8_t __xdata __at(0x1702) PSCTL3;
volatile uint8_t __xdata __at(0x1704) PSINT1;
volatile uint8_t __xdata __at(0x1705) PSINT2;
volatile uint8_t __xdata __at(0x1706) PSINT3;
volatile uint8_t __xdata __at(0x1708) PSSTS1;
volatile uint8_t __xdata __at(0x1709) PSSTS2;
volatile uint8_t __xdata __at(0x170A) PSSTS3;
volatile uint8_t __xdata __at(0x170C) PSDAT1;
volatile uint8_t __xdata __at(0x170D) PSDAT2;
volatile uint8_t __xdata __at(0x170E) PSDAT3;
#endif // _EC_PS2_H

View File

@@ -1,65 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef _EC_PWM_H
#define _EC_PWM_H
#include <stdint.h>
// Channel 0 clock prescaler register
volatile uint8_t __xdata __at(0x1800) C0CPRS;
// Channel 6 clock prescaler register (low byte)
volatile uint8_t __xdata __at(0x182B) C6CPRS;
// Channel 6 clock prescaler register (high byte)
volatile uint8_t __xdata __at(0x182C) C6MCPRS;
// Cycle Time 0
volatile uint8_t __xdata __at(0x1801) CTR0;
// Cycle Time 1
volatile uint8_t __xdata __at(0x1841) CTR1;
// Cycle Time 2
volatile uint8_t __xdata __at(0x1842) CTR2;
// Cycle Time 3
volatile uint8_t __xdata __at(0x1843) CTR3;
// Duty cycle register 0
volatile uint8_t __xdata __at(0x1802) DCR0;
// Duty cycle register 1
volatile uint8_t __xdata __at(0x1803) DCR1;
// Duty cycle register 2
volatile uint8_t __xdata __at(0x1804) DCR2;
// Duty cycle register 3
volatile uint8_t __xdata __at(0x1805) DCR3;
// Duty cycle register 4
volatile uint8_t __xdata __at(0x1806) DCR4;
// Duty cycle register 5
volatile uint8_t __xdata __at(0x1807) DCR5;
// Duty cycle register 6
volatile uint8_t __xdata __at(0x1808) DCR6;
// Duty cycle register 7
volatile uint8_t __xdata __at(0x1809) DCR7;
// Fan one tachometer least significant byte reading register
volatile uint8_t __xdata __at(0x181E) F1TLRR;
// Fan one tachometer most significant byte reading register
volatile uint8_t __xdata __at(0x181F) F1TMRR;
// Fan two tachometer least significant byte reading register
volatile uint8_t __xdata __at(0x1820) F2TLRR;
// Fan two tachometer most significant byte reading register
volatile uint8_t __xdata __at(0x1821) F2TMRR;
// PWM polarity register
volatile uint8_t __xdata __at(0x180A) PWMPOL;
// Prescaler clock frequency select register
volatile uint8_t __xdata __at(0x180B) PCFSR;
// Prescaler clock source select group low
volatile uint8_t __xdata __at(0x180C) PCSSGL;
// Prescaler clock source select group high
volatile uint8_t __xdata __at(0x180D) PCSSGH;
// Prescaler clock source gating register
volatile uint8_t __xdata __at(0x180F) PCSGR;
// PWM clock control register with weird name
volatile uint8_t __xdata __at(0x1823) ZTIER;
// Tachometer switch control register
volatile uint8_t __xdata __at(0x1848) TSWCTLR;
#endif // _EC_PWM_H

View File

@@ -1,44 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <arch/delay.h>
#include <ec/kbc.h>
struct Kbc __code KBC = {
.control = &KBHICR,
.irq = &KBIRQR,
.status = &KBHISR,
.keyboard_out = &KBHIKDOR,
.mouse_out = &KBHIMDOR,
.data_in = &KBHIDIR,
};
uint8_t kbc_status(struct Kbc * kbc) {
return *(kbc->status);
}
uint8_t kbc_read(struct Kbc * kbc) {
return *(kbc->data_in);
}
static bool kbc_wait(struct Kbc * kbc, int timeout) {
while (*(kbc->status) & KBC_STS_OBF) {
if (timeout == 0) return false;
timeout -= 1;
delay_us(1);
}
return true;
}
bool kbc_keyboard(struct Kbc * kbc, uint8_t data, int timeout) {
if (!kbc_wait(kbc, timeout)) return false;
*(kbc->status) &= ~0x20;
*(kbc->keyboard_out) = data;
return true;
}
bool kbc_mouse(struct Kbc * kbc, uint8_t data, int timeout) {
if (!kbc_wait(kbc, timeout)) return false;
*(kbc->status) |= 0x20;
*(kbc->mouse_out) = data;
return true;
}

View File

@@ -1,32 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <ec/pmc.h>
#define PMC(NUM) { \
.status = &PM ## NUM ## STS, \
.data_out = &PM ## NUM ## DO, \
.data_in = &PM ## NUM ## DI, \
.control = &PM ## NUM ## CTL, \
}
struct Pmc __code PMC_1 = PMC(1);
struct Pmc __code PMC_2 = PMC(2);
struct Pmc __code PMC_3 = PMC(3);
struct Pmc __code PMC_4 = PMC(4);
struct Pmc __code PMC_5 = PMC(5);
uint8_t pmc_status(struct Pmc * pmc) {
return *(pmc->status);
}
void pmc_set_status(struct Pmc * pmc, uint8_t status) {
*(pmc->status) = status;
}
uint8_t pmc_read(struct Pmc * pmc) {
return *(pmc->data_in);
}
void pmc_write(struct Pmc * pmc, uint8_t data) {
*(pmc->data_out) = data;
}

View File

@@ -1,21 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <ec/ps2.h>
#define PS2(NUM) { \
.control = &PSCTL ## NUM, \
.interrupt = &PSINT ## NUM, \
.status = &PSSTS ## NUM, \
.data = &PSDAT ## NUM, \
}
struct Ps2 __code PS2_1 = PS2(1);
struct Ps2 __code PS2_2 = PS2(2);
struct Ps2 __code PS2_3 = PS2(3);
void ps2_reset(struct Ps2 * ps2) {
// Reset interface to defaults
*(ps2->control) = 1;
// Clear status
*(ps2->status) = *(ps2->status);
}

12
src/ec/ite/ec.mk Normal file
View File

@@ -0,0 +1,12 @@
# SPDX-License-Identifier: GPL-3.0-only
ARCH=8051
# 64 KB is the max without banking
CODE_SIZE=65536
# Include ITE common source
EC_ITE_COMMON_DIR=src/ec/ite
SRC+=$(wildcard $(EC_ITE_COMMON_DIR)/*.c)
INCLUDE+=$(wildcard $(EC_ITE_COMMON_DIR)/include/ec/*.h) $(EC_ITE_COMMON_DIR)/ec.mk
CFLAGS+=-I$(EC_ITE_COMMON_DIR)/include