Move most code in system76 boards into system76/common
This commit is contained in:
committed by
Jeremy Soller
parent
185459b031
commit
42e88d03b3
@@ -1,145 +0,0 @@
|
||||
#include <board/acpi.h>
|
||||
#include <board/battery.h>
|
||||
#include <board/gpio.h>
|
||||
#include <board/kbled.h>
|
||||
#include <board/lid.h>
|
||||
#include <board/peci.h>
|
||||
#include <common/debug.h>
|
||||
|
||||
extern uint8_t sci_extra;
|
||||
|
||||
uint8_t ecos = 0;
|
||||
|
||||
static uint8_t fcmd = 0;
|
||||
static uint8_t fdat = 0;
|
||||
static uint8_t fbuf[4] = { 0, 0, 0, 0 };
|
||||
|
||||
void fcommand(void) {
|
||||
switch (fcmd) {
|
||||
// Keyboard backlight
|
||||
case 0xCA:
|
||||
switch (fdat) {
|
||||
// Set white LED brightness
|
||||
case 0x00:
|
||||
kbled_set(fbuf[0]);
|
||||
break;
|
||||
// Get white LED brightness
|
||||
case 0x01:
|
||||
fbuf[0] = kbled_get();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t acpi_read(uint8_t addr) {
|
||||
uint8_t data = 0;
|
||||
|
||||
#define ACPI_8(K, V) \
|
||||
case (K): \
|
||||
data = (uint8_t)(V); \
|
||||
break
|
||||
|
||||
#define ACPI_16(K, V) \
|
||||
ACPI_8(K, V); \
|
||||
ACPI_8((K) + 1, (V) >> 8)
|
||||
|
||||
#define ACPI_32(K, V) \
|
||||
ACPI_16(K, V); \
|
||||
ACPI_16((K) + 2, (V) >> 16)
|
||||
|
||||
switch (addr) {
|
||||
// Lid state and other flags
|
||||
case 0x03:
|
||||
if (gpio_get(&LID_SW_N)) {
|
||||
// Lid is open
|
||||
data |= 1 << 0;
|
||||
}
|
||||
if (lid_wake) {
|
||||
data |= 1 << 2;
|
||||
}
|
||||
break;
|
||||
|
||||
// Handle AC adapter and battery present
|
||||
case 0x10:
|
||||
if (!gpio_get(&ACIN_N)) {
|
||||
// AC adapter connected
|
||||
data |= 1 << 0;
|
||||
}
|
||||
// BAT0 always connected - TODO
|
||||
data |= 1 << 2;
|
||||
break;
|
||||
|
||||
ACPI_16(0x16, battery_design_capacity);
|
||||
ACPI_16(0x1A, battery_full_capacity);
|
||||
ACPI_16(0x22, battery_design_voltage);
|
||||
|
||||
case 0x26:
|
||||
// If AC adapter connected
|
||||
if (!gpio_get(&ACIN_N)) {
|
||||
// And battery is not fully charged
|
||||
if (!(battery_status & 0x0020)) {
|
||||
// Battery is charging
|
||||
data |= 1 << 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
ACPI_16(0x2A, battery_current);
|
||||
ACPI_16(0x2E, battery_remaining_capacity);
|
||||
ACPI_16(0x32, battery_voltage);
|
||||
|
||||
ACPI_8(0x68, ecos);
|
||||
|
||||
ACPI_8(0xCC, sci_extra);
|
||||
|
||||
// Set size of flash (from old firmware)
|
||||
ACPI_8 (0xE5, 0x80);
|
||||
|
||||
ACPI_8 (0xF8, fcmd);
|
||||
ACPI_8 (0xF9, fdat);
|
||||
ACPI_8 (0xFA, fbuf[0]);
|
||||
ACPI_8 (0xFB, fbuf[1]);
|
||||
ACPI_8 (0xFC, fbuf[2]);
|
||||
ACPI_8 (0xFD, fbuf[3]);
|
||||
}
|
||||
|
||||
DEBUG("acpi_read %02X = %02X\n", addr, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
void acpi_write(uint8_t addr, uint8_t data) {
|
||||
DEBUG("acpi_write %02X = %02X\n", addr, data);
|
||||
|
||||
switch (addr) {
|
||||
// Lid state and other flags
|
||||
case 0x03:
|
||||
lid_wake = (bool)(data & (1 << 2));
|
||||
break;
|
||||
|
||||
case 0x68:
|
||||
ecos = data;
|
||||
break;
|
||||
|
||||
case 0xF8:
|
||||
fcmd = data;
|
||||
fcommand();
|
||||
break;
|
||||
case 0xF9:
|
||||
fdat = data;
|
||||
break;
|
||||
case 0xFA:
|
||||
fbuf[0] = data;
|
||||
break;
|
||||
case 0xFB:
|
||||
fbuf[1] = data;
|
||||
break;
|
||||
case 0xFC:
|
||||
fbuf[2] = data;
|
||||
break;
|
||||
case 0xFD:
|
||||
fbuf[3] = data;
|
||||
break;
|
||||
}
|
||||
}
|
@@ -23,6 +23,8 @@ void board_init(void) {
|
||||
gpio_set(&SWI_N, true);
|
||||
}
|
||||
|
||||
void board_on_ac(bool ac) { /* Fix unused variable */ ac = ac; }
|
||||
|
||||
void board_event(void) {
|
||||
if (main_cycle == 0) {
|
||||
if (power_state == POWER_STATE_S0 || power_state == POWER_STATE_S3 || power_state == POWER_STATE_DS3) {
|
||||
|
@@ -24,6 +24,9 @@ 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;
|
||||
#define HAVE_LED_AIRPLANE_N 0
|
||||
#define HAVE_LED_BAT_CHG 0
|
||||
#define HAVE_LED_BAT_FULL 0
|
||||
extern struct Gpio __code LED_PWR;
|
||||
extern struct Gpio __code LID_SW_N;
|
||||
extern struct Gpio __code PCH_DPWROK_EC;
|
||||
|
@@ -1,11 +0,0 @@
|
||||
#ifndef _BOARD_KBLED_H
|
||||
#define _BOARD_KBLED_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void kbled_init(void);
|
||||
void kbled_reset(void);
|
||||
uint8_t kbled_get(void);
|
||||
void kbled_set(uint8_t level);
|
||||
|
||||
#endif // _BOARD_KBLED_H
|
@@ -42,3 +42,5 @@ void kbled_set(uint8_t level) {
|
||||
}
|
||||
KBLED_DACDAT = raw;
|
||||
}
|
||||
|
||||
void kbled_set_color(uint32_t color) { /*Fix unused variable*/ color = color; }
|
||||
|
@@ -1,39 +0,0 @@
|
||||
#include <8051.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <board/smfi.h>
|
||||
#include <common/macro.h>
|
||||
#include <ec/pwm.h>
|
||||
|
||||
// Include scratch ROM
|
||||
uint8_t __code __at(SCRATCH_OFFSET) scratch_rom[] = {
|
||||
#include <scratch.h>
|
||||
};
|
||||
|
||||
// SCAR0 is stored in processor cache, not in xram
|
||||
volatile uint8_t __xdata __at(0x1040) SCAR0L;
|
||||
volatile uint8_t __xdata __at(0x1041) SCAR0M;
|
||||
volatile uint8_t __xdata __at(0x1042) SCAR0H;
|
||||
|
||||
// Enter or exit scratch ROM
|
||||
void scratch_trampoline(void) {
|
||||
// Set fans to 100%
|
||||
DCR2 = 0xFF;
|
||||
|
||||
//TODO: Clear keyboard presses
|
||||
|
||||
// Start watchdog timer
|
||||
smfi_watchdog();
|
||||
|
||||
// Disable interrupts
|
||||
EA = 0;
|
||||
|
||||
// Use DMA mapping to copy flash data
|
||||
SCAR0H = 0x80;
|
||||
SCAR0L = (uint8_t)(SCRATCH_OFFSET);
|
||||
SCAR0M = (uint8_t)(SCRATCH_OFFSET >> 8);
|
||||
SCAR0H = 0;
|
||||
|
||||
// Jump to scratch reset function
|
||||
__asm__("ljmp " xstr(SCRATCH_OFFSET));
|
||||
}
|
Reference in New Issue
Block a user