-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mostly a copy from it8587e with updated signature string. - Add I2C channels C and D - Add definitions for open drain output control and LED0/1 dimming control - Add ADC register definitions, implementation Signed-off-by: Matt DeVillier <matt.devillier@puri.sm>
- Loading branch information
Showing
27 changed files
with
1,198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
#include <stdbool.h> | ||
#include <arch/delay.h> | ||
#include <ec/adc.h> | ||
|
||
void adc_enable(bool enable) { | ||
if (enable) | ||
ADCCFG |= (1 << 0); // ADCEN | ||
else | ||
ADCCFG &= ~(1 << 0); | ||
} | ||
|
||
void adc_init(void) { | ||
// adc_enable(true); | ||
ADCSTS |= (1 << 2); | ||
delay_us(1300); | ||
ADCSTS &= ~(1 << 2); | ||
|
||
ADCSTS |= (1 << 3); // AINITB, only run once after power up | ||
delay_us(100); | ||
ADCSTS &= ~(1 << 3); | ||
|
||
ADCSTS |= (1 << 2); | ||
delay_us(1300); | ||
ADCSTS &= ~(1 << 2); | ||
|
||
ADCGCR |= (1L << 7); // keep buffer enable ADCDBKEN | ||
KDCTL = 0x80; // enable auto hardware calibration AHCE | ||
// adc_enable(false); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
#include <ec/ec.h> | ||
#include <ec/gctrl.h> | ||
|
||
void ec_init(void) { | ||
RSTS = 0x84; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
#include <stdbool.h> | ||
|
||
#include <common/i2c.h> | ||
#include <ec/smbus.h> | ||
|
||
//TODO: find best value | ||
#define I2C_TIMEOUT 10000 | ||
|
||
struct I2C { | ||
volatile uint8_t * hosta; | ||
volatile uint8_t * hoctl; | ||
volatile uint8_t * hoctl2; | ||
volatile uint8_t * hobdb; | ||
volatile uint8_t * trasla; | ||
}; | ||
|
||
struct I2C __code I2C_0 = { | ||
.hosta = HOSTAA, | ||
.hoctl = HOCTLA, | ||
.hoctl2 = HOCTL2A, | ||
.hobdb = HOBDBA, | ||
.trasla = TRASLAA, | ||
}; | ||
|
||
struct I2C __code I2C_1 = { | ||
.hosta = HOSTAB, | ||
.hoctl = HOCTLB, | ||
.hoctl2 = HOCTL2B, | ||
.hobdb = HOBDBB, | ||
.trasla = TRASLAB, | ||
}; | ||
|
||
struct I2C __code I2C_2 = { | ||
.hosta = HOSTAC, | ||
.hoctl = HOCTLC, | ||
.hoctl2 = HOCTL2C, | ||
.hobdb = HOBDBC, | ||
.trasla = TRASLAC, | ||
}; | ||
|
||
struct I2C __code I2C_3 = { | ||
.hosta = HOSTAD, | ||
.hoctl = HOCTLD, | ||
.hoctl2 = HOCTL2D, | ||
.hobdb = HOBDBD, | ||
.trasla = TRASLAD, | ||
}; | ||
|
||
void i2c_reset(struct I2C * i2c, bool kill) { | ||
if (*(i2c->hosta) & HOSTA_BUSY) { | ||
// Set kill bit | ||
if (kill) *(i2c->hoctl) |= (1 << 1); | ||
// Wait for host to finish | ||
while (*(i2c->hosta) & HOSTA_BUSY) {} | ||
} | ||
// Clear status register | ||
*(i2c->hosta) = *(i2c->hosta); | ||
// Clear current command | ||
*(i2c->hoctl) = 0; | ||
// Disable host interface | ||
*(i2c->hoctl2) = 0; | ||
} | ||
|
||
int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant { | ||
// If we are already in a transaction | ||
if (*(i2c->hosta) & HOSTA_BYTE_DONE) { | ||
// If we are switching direction | ||
if ((*(i2c->trasla) & 1) != read) { | ||
// If we are switching to read mode | ||
if (read) { | ||
// Enable direction switch | ||
*(i2c->hoctl2) |= (1 << 3) | (1 << 2); | ||
} else { | ||
// Unsupported! | ||
i2c_reset(i2c, true); | ||
return -1; | ||
} | ||
} | ||
} else { | ||
i2c_reset(i2c, true); | ||
|
||
// Enable host controller with i2c compatibility | ||
*(i2c->hoctl2) = (1 << 1) | 1; | ||
|
||
// Set address | ||
*(i2c->trasla) = (addr << 1) | read; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
void i2c_stop(struct I2C * i2c) { | ||
// Disable i2c compatibility | ||
*(i2c->hoctl2) &= ~(1 << 1); | ||
// Clear status | ||
*(i2c->hosta) = *(i2c->hosta); | ||
|
||
i2c_reset(i2c, false); | ||
} | ||
|
||
static int i2c_transaction(struct I2C * i2c, uint8_t * data, int length, bool read) { | ||
int i; | ||
for (i = 0; i < length; i++) { | ||
if (read) { | ||
// If last byte | ||
if ((i + 1) == length) { | ||
// Set last byte bit | ||
*(i2c->hoctl) |= (1 << 5); | ||
} | ||
} else { | ||
// Write byte | ||
*(i2c->hobdb) = data[i]; | ||
} | ||
|
||
// If we are already in a transaction | ||
if (*(i2c->hosta) & HOSTA_BYTE_DONE) { | ||
// Clear status to process next byte | ||
*(i2c->hosta) = *(i2c->hosta); | ||
} else { | ||
// Start new transaction | ||
*(i2c->hoctl) = (1 << 6) | (0b111 << 2); | ||
} | ||
|
||
// If we are waiting on direction switch | ||
if (*(i2c->hoctl2) & (1 << 2)) { | ||
// Complete direction switch | ||
*(i2c->hoctl2) &= ~(1 << 2); | ||
} | ||
|
||
// Wait for byte done, timeout, or error | ||
uint8_t status; | ||
uint32_t timeout = I2C_TIMEOUT; | ||
for(timeout = I2C_TIMEOUT; timeout > 0; timeout--) { | ||
status = *(i2c->hosta); | ||
// If error occured, kill transaction and return error | ||
if (status & HOSTA_ERR) { | ||
i2c_reset(i2c, true); | ||
return -(int)(status); | ||
} else | ||
// If byte done, break | ||
if (status & HOSTA_BYTE_DONE) { | ||
break; | ||
} | ||
} | ||
// If timeout occured, kill transaction and return error | ||
if (timeout == 0) { | ||
i2c_reset(i2c, true); | ||
return -(0x1000 | (int)status); | ||
} | ||
|
||
if (read) { | ||
// Read byte | ||
data[i] = *(i2c->hobdb); | ||
} | ||
} | ||
|
||
return i; | ||
} | ||
|
||
int i2c_read(struct I2C * i2c, uint8_t * data, int length) __reentrant { | ||
return i2c_transaction(i2c, data, length, true); | ||
} | ||
|
||
int i2c_write(struct I2C * i2c, uint8_t * data, int length) __reentrant { | ||
return i2c_transaction(i2c, data, length, false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
#ifndef _EC_ADC_H | ||
#define _EC_ADC_H | ||
|
||
#include <stdint.h> | ||
|
||
volatile uint8_t __xdata __at(0x1900) ADCSTS; | ||
volatile uint8_t __xdata __at(0x1901) ADCCFG; | ||
volatile uint8_t __xdata __at(0x1902) ADCCTL; | ||
volatile uint8_t __xdata __at(0x1903) ADCGCR; | ||
volatile uint8_t __xdata __at(0x1904) VCH0CTL; | ||
volatile uint8_t __xdata __at(0x1905) KDCTL; | ||
volatile uint8_t __xdata __at(0x1906) VCH1CTL; | ||
volatile uint8_t __xdata __at(0x1907) VCH1DATL; | ||
volatile uint8_t __xdata __at(0x1908) VCH1DATM; | ||
volatile uint8_t __xdata __at(0x1909) VCH2CTL; | ||
volatile uint8_t __xdata __at(0x190A) VCH2DATL; | ||
volatile uint8_t __xdata __at(0x190B) VCH2DATM; | ||
volatile uint8_t __xdata __at(0x190C) VCH3CTL; | ||
volatile uint8_t __xdata __at(0x190D) VCH3DATL; | ||
volatile uint8_t __xdata __at(0x190E) VCH3DATM; | ||
volatile uint8_t __xdata __at(0x1918) VCH0DATL; | ||
volatile uint8_t __xdata __at(0x1919) VCH0DATM; | ||
volatile uint8_t __xdata __at(0x1937) VCMPSCP; | ||
volatile uint8_t __xdata __at(0x1938) VCH4CTL; | ||
volatile uint8_t __xdata __at(0x1939) VCH4DATM; | ||
volatile uint8_t __xdata __at(0x193A) VCH4DATL; | ||
volatile uint8_t __xdata __at(0x193B) VCH5CTL; | ||
volatile uint8_t __xdata __at(0x193C) VCH5DATM; | ||
volatile uint8_t __xdata __at(0x193D) VCH5DATL; | ||
volatile uint8_t __xdata __at(0x193E) VC6CTL; | ||
volatile uint8_t __xdata __at(0x193F) VCH6DATM; | ||
volatile uint8_t __xdata __at(0x1940) VCH6DATL; | ||
volatile uint8_t __xdata __at(0x1941) VCH7CTL; | ||
volatile uint8_t __xdata __at(0x1942) VCH7DATM; | ||
volatile uint8_t __xdata __at(0x1943) VCH7DATL; | ||
volatile uint8_t __xdata __at(0x1944) ADCDVSTS; | ||
volatile uint8_t __xdata __at(0x1945) VCMPSTS; | ||
volatile uint8_t __xdata __at(0x1946) VCMP0CTL; | ||
volatile uint8_t __xdata __at(0x1947) VCMP0DATM; | ||
volatile uint8_t __xdata __at(0x1948) VCMP0DATL; | ||
volatile uint8_t __xdata __at(0x1949) VCMP1CTL; | ||
volatile uint8_t __xdata __at(0x194A) VCMP1DATM; | ||
volatile uint8_t __xdata __at(0x194B) VCMP1DATL; | ||
volatile uint8_t __xdata __at(0x194C) VCMP2CTL; | ||
volatile uint8_t __xdata __at(0x194D) VCMP2DATM; | ||
volatile uint8_t __xdata __at(0x194E) VCMP2DATL; | ||
volatile uint8_t __xdata __at(0x194F) VCMPOTR; | ||
volatile uint8_t __xdata __at(0x1952) VCMPLR; | ||
|
||
void adc_enable(bool enable); | ||
void adc_init(void); | ||
|
||
#endif // _EC_ADC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
#ifndef _EC_EC_H | ||
#define _EC_EC_H | ||
|
||
void ec_init(void); | ||
|
||
#endif // _EC_EC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
#ifndef _EC_ESPI_H | ||
#define _EC_ESPI_H | ||
|
||
// eSPI not supported on IT8587E | ||
#define EC_ESPI 0 | ||
|
||
#endif // _EC_ESPI_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
#ifndef _EC_GCTRL_H | ||
#define _EC_GCTRL_H | ||
|
||
#include <stdint.h> | ||
|
||
volatile uint8_t __xdata __at(0x2006) RSTS; | ||
volatile uint8_t __xdata __at(0x200A) BADRSEL; | ||
volatile uint8_t __xdata __at(0x200D) SPCTRL1; | ||
|
||
#endif // _EC_GCTRL_H |
Oops, something went wrong.