summaryrefslogtreecommitdiff
path: root/sys/src/cmd/reform
diff options
context:
space:
mode:
authorSigrid Solveig Haflínudóttir <sigrid@ftrv.se>2022-09-08 19:44:12 +0000
committerSigrid Solveig Haflínudóttir <sigrid@ftrv.se>2022-09-08 19:44:12 +0000
commita1a4ae4a53640eea33c76b41ecbbd7a091e019f8 (patch)
tree9323489d502c4b09a7ba51863453d5ec568c0a99 /sys/src/cmd/reform
parent247d5183c731685906fced14e6a945c78bae1e57 (diff)
reform/pm: lpccall: read as much as possible after the command; clean up
Diffstat (limited to 'sys/src/cmd/reform')
-rw-r--r--sys/src/cmd/reform/pm.c39
1 files changed, 7 insertions, 32 deletions
diff --git a/sys/src/cmd/reform/pm.c b/sys/src/cmd/reform/pm.c
index 6000336c6..d1f84c6d3 100644
--- a/sys/src/cmd/reform/pm.c
+++ b/sys/src/cmd/reform/pm.c
@@ -62,11 +62,7 @@ enum
CON_XCH = 1<<2,
CON_EN = 1<<0,
SPIx_CONFIGREG = 0x0c/4,
- CONFIG_SCLK_CTL_LOW = 0<<20,
- CONFIG_DATA_CTL_HIGH = 0<<16,
- CONFIG_SS_POL_LOW = 0<<12,
CONFIG_SS_CTL_NCSS = 1<<8,
- CONFIG_SCLK_POL_HIGH = 0<<4,
CONFIG_SCLK_PHA_1 = 1<<0,
SPIx_STATREG = 0x18/4,
STAT_RR = 1<<3,
@@ -183,12 +179,7 @@ static void
lpccall(char cmd, u8int arg, void *ret)
{
u32int con;
- int i, try;
-
- /* in case someone messed up and ran pm more than once */
- try = 0;
- while((rd(spi2, SPIx_CONREG) & CON_EN) != 0 && try++ < 50)
- sleep(10);
+ int i;
con =
/* 8 bits burst */
@@ -202,12 +193,7 @@ lpccall(char cmd, u8int arg, void *ret)
wr(spi2, SPIx_CONREG, con);
wr(spi2, SPIx_CONFIGREG,
- /* defaults */
- CONFIG_SCLK_CTL_LOW |
- CONFIG_DATA_CTL_HIGH |
- CONFIG_SS_POL_LOW |
- CONFIG_SCLK_POL_HIGH |
- /* tx shift - rising edge SCLK; tx latch - falling edge */
+ /* tx shift - rising edge; rx latch - falling edge */
CONFIG_SCLK_PHA_1 |
CONFIG_SS_CTL_NCSS);
@@ -215,14 +201,10 @@ lpccall(char cmd, u8int arg, void *ret)
wr(spi2, SPIx_TXDATA, cmd);
wr(spi2, SPIx_TXDATA, arg);
wr(spi2, SPIx_CONREG, con | CON_XCH);
+ sleep(60);
- /*
- * give enough time to send and for LPC to process
- * 50ms seems safe but add more just in case
- */
- sleep(75);
- /* LPC buffers 3 bytes without responding, ignore */
- for(i = 0; i < 3; i++)
+ /* LPC buffers 3 bytes without responding, ignore (including garbage) */
+ while(rd(spi2, SPIx_STATREG) & STAT_RR)
rd(spi2, SPIx_RXDATA);
/*
@@ -234,16 +216,10 @@ lpccall(char cmd, u8int arg, void *ret)
for(i = 0; i < 8; i++)
wr(spi2, SPIx_TXDATA, 0);
wr(spi2, SPIx_CONREG, con | CON_XCH);
+ sleep(60);
- for(i = 0; i < 8; i++){
- try = 0;
- do{
- sleep(10);
- }while((rd(spi2, SPIx_STATREG) & STAT_RR) == 0 && try++ < 50);
- if(try >= 50) /* give up */
- break;
+ for(i = 0; i < 8; i++)
((u8int*)ret)[i] = rd(spi2, SPIx_RXDATA);
- }
wr(spi2, SPIx_CONREG, con & ~CON_EN);
}
@@ -253,7 +229,6 @@ lpcinit(void)
{
char s[3][8];
- lpccall(0, 0, s[0]); /* a dummy one to make sure there is no garbage */
lpccall('f', 0, s[0]);
lpccall('f', 1, s[1]);
lpccall('f', 2, s[2]);