Use SMBus for console output

This commit is contained in:
Jeremy Soller 2019-10-01 12:00:33 -06:00
parent 281ffd6d05
commit a4c4c34ff9
No known key found for this signature in database
GPG Key ID: E988B49EE78A7FB1
2 changed files with 81 additions and 25 deletions

View File

@ -1,38 +1,48 @@
#include <stdio.h>
#include <arch/timer.h>
#include <board/kbscan.h>
#include <ec/smbus.h>
// Wait 25 us
// 65536 - (25 / 1.304) = 65517
void parallel_delay(void) {
timer_mode_1(65517);
timer_wait();
timer_stop();
}
void i2c_write(unsigned char value) {
for (;;) {
// Wait for last command
while (HOSTAA & 1) {}
// This takes a time of 25 us * 3 = 75 us
// That produces a frequency of 13.333 KHz
// Which produces a bitrate of 106.667 KHz
void parallel_write(unsigned char value) {
// Make sure clock is high
KSOH1 = 0xFF;
parallel_delay();
// Clear result
HOSTAA = HOSTAA;
// Set value
KSOL = value;
parallel_delay();
// Clock down to 50 KHz
SCLKTSA = 1;
// Set clock low
KSOH1 = 0;
parallel_delay();
// Enable host interface with i2c compatibility
HOCTL2A = (1 << 1) | (1 << 0);
// Set clock high again
KSOH1 = 0xFF;
// Write value to 0x76
TRASLAA = (0x76 << 1) | (0 << 1);
HOCMDA = value;
// Start command
HOCTLA = (1 << 6) | (0b001 << 2);
// Wait for command to start
while (!(HOSTAA & 1)) {}
// Wait for command to finish
while (HOSTAA & 1) {}
// Read and clear status
uint8_t status = HOSTAA;
HOSTAA = status;
// If there were no errors, return
uint8_t error = (1 << 6) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
if (!(status & error)) {
break;
}
}
}
int putchar(int c) {
unsigned char byte = (unsigned char)c;
parallel_write(byte);
i2c_write(byte);
return (int)byte;
}

View File

@ -0,0 +1,46 @@
#ifndef _EC_SMBUS_H
#define _EC_SMBUS_H
#include <stdint.h>
// Host status for channel A
volatile uint8_t __xdata __at(0x1C00) HOSTAA;
// Host control for channel A
volatile uint8_t __xdata __at(0x1C01) HOCTLA;
// Host command for channel A
volatile uint8_t __xdata __at(0x1C02) HOCMDA;
// Transmit slave address for channel A
volatile uint8_t __xdata __at(0x1C03) TRASLAA;
// Host data 0 for channel A
volatile uint8_t __xdata __at(0x1C04) D0REGA;
// Host data 1 for channel A
volatile uint8_t __xdata __at(0x1C05) D1REGA;
// Host block data byte for channel A
volatile uint8_t __xdata __at(0x1C06) HOBDBA;
// Packet error check for channel A
volatile uint8_t __xdata __at(0x1C07) PECERCA;
// Receive slave address for channel A
volatile uint8_t __xdata __at(0x1C08) RESLADRA;
// Receive slave address 2 for channel A
volatile uint8_t __xdata __at(0x1C3F) RESLADR2A;
// Slave data for channel A
volatile uint8_t __xdata __at(0x1C09) SLDAA;
// SMBus pin control for channel A
volatile uint8_t __xdata __at(0x1C0A) SMBPCTLA;
// Slave status for channel A
volatile uint8_t __xdata __at(0x1C0B) SLSTAA;
// Slave interrupt control for channel A
volatile uint8_t __xdata __at(0x1C0C) SICRA;
// Notify device address for channel A
volatile uint8_t __xdata __at(0x1C0D) NDADRA;
// Notify data low byte for channel A
volatile uint8_t __xdata __at(0x1C0E) NDLBA;
// Notify data high byte for channel A
volatile uint8_t __xdata __at(0x1C0F) NDHBA;
// Host control 2 for channel A
volatile uint8_t __xdata __at(0x1C10) HOCTL2A;
// SMCLK timing setting for channel A
volatile uint8_t __xdata __at(0x1C10) SCLKTSA;
#endif // _EC_SMBUS_H