Add TCPM I2C bus and initialize it

This commit is contained in:
Jeremy Soller
2020-02-13 10:34:28 -07:00
parent fc7fa1f11c
commit 17cce5687f
9 changed files with 93 additions and 2 deletions

View File

@@ -19,6 +19,9 @@ CFLAGS+=-DI2C_DEBUGGER=0x76
# Set battery I2C bus
CFLAGS+=-DI2C_SMBUS=I2C_4
# Set type-c port manager I2C bus
CFLAGS+=-DI2C_TCPM=I2C_1
# Set scratch ROM parameters
SCRATCH_OFFSET=1024
SCRATCH_SIZE=1024

View File

@@ -11,6 +11,7 @@ struct Gpio __code CCD_EN = GPIO(D, 1);
struct Gpio __code DD_ON = GPIO(E, 4);
struct Gpio __code EC_EN = GPIO(J, 6);
struct Gpio __code EC_RSMRST_N = GPIO(E, 5);
struct Gpio __code EC_SMD_EN_N = GPIO(I, 6);
struct Gpio __code LED_ACIN = GPIO(C, 7);
struct Gpio __code LED_PWR = GPIO(D, 0);
struct Gpio __code LID_SW_N = GPIO(B, 1);
@@ -91,9 +92,9 @@ void gpio_init() {
// ALL_SYS_PWRGD
GPCRC0 = GPIO_IN;
// SMB_CLK_EC
GPCRC1 = GPIO_OUT;
GPCRC1 = GPIO_ALT;
// SMB_DATA_EC
GPCRC2 = GPIO_OUT;
GPCRC2 = GPIO_ALT;
// PCIE_WAKE#
GPCRC3 = GPIO_IN;
// CNVI_DET#

View File

@@ -22,6 +22,7 @@ extern struct Gpio __code CCD_EN;
extern struct Gpio __code DD_ON;
extern struct Gpio __code EC_EN;
extern struct Gpio __code EC_RSMRST_N;
extern struct Gpio __code EC_SMD_EN_N;
extern struct Gpio __code LED_ACIN;
extern struct Gpio __code LED_PWR;
extern struct Gpio __code LID_SW_N;

View File

@@ -0,0 +1,11 @@
#ifndef _BOARD_TCPM_H
#define _BOARD_TCPM_H
#include <ec/smbus.h>
void tcpm_init(void);
int tcpm_read(uint8_t address, uint8_t command, uint16_t * data);
int tcpm_write(uint8_t address, uint8_t command, uint16_t data);
void tcpm_event(void);
#endif // _BOARD_TCPM_H

View File

@@ -18,6 +18,7 @@
#include <board/ps2.h>
#include <board/pwm.h>
#include <board/smbus.h>
#include <board/tcpm.h>
#include <common/debug.h>
#include <common/macro.h>
@@ -47,6 +48,7 @@ void init(void) {
pmc_init();
pwm_init();
smbus_init();
tcpm_init();
//TODO: INTC
}
@@ -112,6 +114,8 @@ void main(void) {
peci_event();
// Updates battery status
battery_event();
// Updates type-c port
tcpm_event();
}
// Handles ACPI communication
pmc_event(&PMC_1);

View File

@@ -0,0 +1,23 @@
#include <board/gpio.h>
#include <board/tcpm.h>
#include <ec/i2c.h>
void tcpm_init(void) {
// Set up for i2c usage
i2c_reset(&I2C_TCPM, true);
// Enable connection to TCPC
*(EC_SMD_EN_N.control) = GPIO_OUT;
}
int tcpm_read(uint8_t address, uint8_t command, uint16_t * data) {
return i2c_get(&I2C_TCPM, address, command, (uint8_t *)data, 2);
}
int tcpm_write(uint8_t address, uint8_t command, uint16_t data) {
return i2c_set(&I2C_TCPM, address, command, (uint8_t *)&data, 2);
}
void tcpm_event(void) {
//TODO
}