From 913b0dfc44cb70d8e9a5af41a9eeca0049e9942c Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 10 Jun 2021 09:04:43 -0600 Subject: [PATCH] Expose pnp_read and pnp_write --- src/board/system76/common/include/board/pnp.h | 4 +++ src/board/system76/common/pnp.c | 29 ++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/board/system76/common/include/board/pnp.h b/src/board/system76/common/include/board/pnp.h index 09cf8bc..a0decf4 100644 --- a/src/board/system76/common/include/board/pnp.h +++ b/src/board/system76/common/include/board/pnp.h @@ -3,6 +3,10 @@ #ifndef _BOARD_PNP_H #define _BOARD_PNP_H +#include + +uint8_t pnp_read(uint8_t reg); +void pnp_write(uint8_t reg, uint8_t data); void pnp_enable(void); #endif // _BOARD_PNP_H diff --git a/src/board/system76/common/pnp.c b/src/board/system76/common/pnp.c index 30c85a0..7dff19a 100644 --- a/src/board/system76/common/pnp.c +++ b/src/board/system76/common/pnp.c @@ -2,6 +2,7 @@ #include +#include #include #include #include @@ -10,20 +11,34 @@ volatile uint8_t __xdata __at(0x1200) IHIOA; volatile uint8_t __xdata __at(0x1201) IHD; volatile uint8_t __xdata __at(0x1204) IBMAE; volatile uint8_t __xdata __at(0x1205) IBCTL; -void e2ci_write(uint8_t port, uint8_t data) { + +uint8_t ec2i_read(uint8_t port) { while (IBCTL & (BIT(2) | BIT(1))) {} + IBCTL = 1; + IBMAE = 1; + IHIOA = port; + IBCTL |= BIT(1); + while (IBCTL & BIT(1)) {} + return IHD; +} + +void ec2i_write(uint8_t port, uint8_t data) { + while (IBCTL & (BIT(2) | BIT(1))) {} + IBCTL = 1; + IBMAE = 1; IHIOA = port; IHD = data; - IBMAE = 1; - IBCTL = 1; while (IBCTL & BIT(2)) {} - IBMAE = 0; - IBCTL = 0; +} + +uint8_t pnp_read(uint8_t reg) { + ec2i_write(0x2E, reg); + return ec2i_read(0x2F); } void pnp_write(uint8_t reg, uint8_t data) { - e2ci_write(0x2E, reg); - e2ci_write(0x2F, data); + ec2i_write(0x2E, reg); + ec2i_write(0x2F, data); } void pnp_enable() {