Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/arch/8051/include/arch/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
#ifndef _ARCH_TIME_H
#define _ARCH_TIME_H

#include <stdbool.h>
#include <stdint.h>

void time_init(void);
uint32_t time_get(void);

// Set every 50 ms by timer_0; cleared by the main-loop periodic handler
extern volatile bool timer_50ms_pending;

#endif // _ARCH_TIME_H
13 changes: 13 additions & 0 deletions src/arch/8051/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@

static volatile uint32_t time_overflows = 0;

// Set every 50 ms by timer_0; cleared by main loop periodic handler.
// 50 ms is the base for all periodic intervals:
// 2 ticks = 100 ms (power/usbpd poll)
// 5 ticks = 250 ms (smooth fan)
// 20 ticks = 1000 ms (fan normal + battery)
volatile bool timer_50ms_pending = false;

void timer_0(void) __interrupt(1) {
// Stop timer
TR0 = 0;

time_overflows++;

static uint8_t ticks = 0;
if (++ticks >= 50) {
ticks = 0;
timer_50ms_pending = true;
}

// Start timer
TH0 = 0xFD;
TL0 = 0x01;
Expand Down
4 changes: 4 additions & 0 deletions src/board/novacustom/v540tnx/include/board/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern struct Gpio __code EC_EN;
extern struct Gpio __code EC_RSMRST_N;
extern struct Gpio __code GC6_FB_EN;
extern struct Gpio __code H_PROCHOT_EC;
#define HAVE_JACK_IN_N 1
extern struct Gpio __code JACK_IN_N;
extern struct Gpio __code LAN_WAKEUP_N;
extern struct Gpio __code LED_ACIN;
Expand All @@ -40,6 +41,9 @@ extern struct Gpio __code PD_IRQ;
extern struct Gpio __code PWR_BTN_N;
extern struct Gpio __code PWR_SW_N;
extern struct Gpio __code RGBKB_DET_N;
// SINK_CTRL is on GPH7 (same as v560tnx): WU127, Group 13 bit 7, INT148
#define HAVE_SINK_CTRL 1
#define SINK_CTRL_IRQ _GPIO_WUC_IRQ_H7 // 148 (IER18[4])
extern struct Gpio __code SINK_CTRL;
#define HAVE_SLP_SUS_N 0
#define HAVE_SUS_PWR_ACK 0
Expand Down
1 change: 1 addition & 0 deletions src/board/novacustom/v540tu/include/board/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern struct Gpio __code DD_ON;
extern struct Gpio __code EC_EN;
extern struct Gpio __code EC_RSMRST_N;
extern struct Gpio __code H_PROCHOT_EC;
#define HAVE_JACK_IN_N 1
extern struct Gpio __code JACK_IN_N;
extern struct Gpio __code LAN_WAKEUP_N;
extern struct Gpio __code LED_ACIN;
Expand Down
4 changes: 4 additions & 0 deletions src/board/novacustom/v560tnx/include/board/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern struct Gpio __code EC_EN;
extern struct Gpio __code EC_RSMRST_N;
extern struct Gpio __code GC6_FB_EN;
extern struct Gpio __code H_PROCHOT_EC;
#define HAVE_JACK_IN_N 1
extern struct Gpio __code JACK_IN_N;
extern struct Gpio __code LAN_WAKEUP_N;
extern struct Gpio __code LED_ACIN;
Expand All @@ -40,6 +41,9 @@ extern struct Gpio __code PD_IRQ;
extern struct Gpio __code PWR_BTN_N;
extern struct Gpio __code PWR_SW_N;
extern struct Gpio __code RGBKB_DET_N;
// SINK_CTRL is on GPH7 (not GPC3 like nv40mz): WU127, Group 13 bit 7, INT148
#define HAVE_SINK_CTRL 1
#define SINK_CTRL_IRQ _GPIO_WUC_IRQ_H7 // 148 (IER18[4])
extern struct Gpio __code SINK_CTRL;
#define HAVE_SLP_SUS_N 0
#define HAVE_SUS_PWR_ACK 0
Expand Down
1 change: 1 addition & 0 deletions src/board/novacustom/v560tu/include/board/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern struct Gpio __code DD_ON;
extern struct Gpio __code EC_EN;
extern struct Gpio __code EC_RSMRST_N;
extern struct Gpio __code H_PROCHOT_EC;
#define HAVE_JACK_IN_N 1
extern struct Gpio __code JACK_IN_N;
extern struct Gpio __code LAN_WAKEUP_N;
extern struct Gpio __code LED_ACIN;
Expand Down
1 change: 1 addition & 0 deletions src/board/system76/common/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ void battery_event(void) {

TRACE("BAT %d mV %d mA\n", battery_info.voltage, battery_info.current);

battery_charger_configure();
battery_charger_event();
}
2 changes: 2 additions & 0 deletions src/board/system76/common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

board-common-y += acpi.c
board-common-y += battery.c
board-common-y += debug_mailbox.c
board-common-y += config.c
board-common-y += dgpu.c
board-common-y += ecpm.c
Expand Down Expand Up @@ -51,6 +52,7 @@ endif
# Set external programmer
PROGRAMMER=$(wildcard /dev/ttyACM* /dev/ttyUSB*)


ifeq ($(CONFIG_BUS_ESPI),y)
CFLAGS += -DCONFIG_BUS_ESPI=1

Expand Down
52 changes: 52 additions & 0 deletions src/board/system76/common/debug_mailbox.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: GPL-3.0-only

// Debug command mailbox at fixed XDATA address 0x0DF0.
//
// The DBGR/SMB hardware slave allows an external host to write to any EC
// XDATA address via the battery SMBus pins. Write a non-zero command byte
// to trigger execution; firmware clears it on completion.
//
// Host protocol:
// 1. Write command byte to 0x0DF0 via DBGR/SMB memory write
// 2. Poll 0x0DF0 until it reads 0x00 (command complete)
// 3. Read status from 0x0DF1: 0=idle, 1=busy, 2=done

#include <stdint.h>

#include <board/debug_mailbox.h>
#include <board/power.h>
#include <common/debug.h>

#define DBG_CMD_POWER_OFF 0x01
#define DBG_CMD_POWER_ON 0x02

#define MAILBOX_STATUS_IDLE 0x00
#define MAILBOX_STATUS_BUSY 0x01
#define MAILBOX_STATUS_DONE 0x02

static volatile uint8_t __xdata __at(0x0DF0) mailbox_cmd;
static volatile uint8_t __xdata __at(0x0DF1) mailbox_status;

void mailbox_event(void) {
uint8_t cmd = mailbox_cmd;
if (!cmd)
return;

DEBUG("mailbox: cmd=0x%02X\n", cmd);
mailbox_status = MAILBOX_STATUS_BUSY;

switch (cmd) {
case DBG_CMD_POWER_OFF:
power_off();
break;
case DBG_CMD_POWER_ON:
power_on();
break;
default:
DEBUG("mailbox: unknown cmd 0x%02X\n", cmd);
break;
}

mailbox_status = MAILBOX_STATUS_DONE;
mailbox_cmd = 0;
}
10 changes: 8 additions & 2 deletions src/board/system76/common/dgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <board/dgpu.h>
#include <board/fan.h>
#include <board/irq.h>

#if HAVE_DGPU

Expand Down Expand Up @@ -94,13 +95,14 @@ uint8_t dgpu_get_d_notify_level(bool ac) {
return 0;
}

int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points) {
int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points) __reentrant {
int i;
if (count != FAN.points_size) {
TRACE("DGPU: Incorrect number of fan points: %d, expected %d\n", count, FAN.points_size);
return -1;
}

for (int i = 0; i < count; ++i) {
for (i = 0; i < count; ++i) {
TRACE("DGPU: fan curve t%d: %d, d%d: %d\n", i, points[i].temp, i, points[i].duty);
FAN.points[i].temp = points[i].temp;
FAN.points[i].duty = points[i].duty;
Expand Down Expand Up @@ -164,3 +166,7 @@ uint8_t dgpu_get_fan_duty(void) {
}

#endif // HAVE_DGPU

// Defined outside #if HAVE_DGPU so irq.h consumers can always reference it.
// When HAVE_DGPU=0, main.c's #if HAVE_DGPU guard prevents the ISR case from firing.
volatile bool dgpu_irq_pending = false;
5 changes: 3 additions & 2 deletions src/board/system76/common/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ uint8_t fan_smooth(uint8_t last_duty, uint8_t duty) __reentrant {
return next_duty;
}

uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points) {
uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points) __reentrant {
int i;
/*
* Fan curve speeds have to be non-decreasing.
* Fan curve temperatures have to be increasing.
*/
for (int i = 1; i < count; i++) {
for (i = 1; i < count; i++) {
if (points[i].temp <= points[i - 1].temp || points[i].duty < points[i - 1].duty)
return false;
}
Expand Down
20 changes: 10 additions & 10 deletions src/board/system76/common/flash/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ uint8_t __code __at(FLASH_OFFSET) flash_rom[] = {
#include <flash.h>
};

static void flash_api(uint32_t addr, uint8_t *data, uint32_t length, uint8_t command) {
static void flash_api(uint32_t addr, uint8_t *data, uint32_t length, uint8_t command) __reentrant {
// Use DMA mapping to copy flash ROM to scratch ROM
SCARH = 0x80;
SCARL = (uint8_t)(FLASH_OFFSET);
Expand All @@ -29,50 +29,50 @@ static void flash_api(uint32_t addr, uint8_t *data, uint32_t length, uint8_t com
SCARH = 0x07;
}

void flash_read(uint32_t addr, __xdata uint8_t *data, uint32_t length) {
void flash_read(uint32_t addr, __xdata uint8_t *data, uint32_t length) __reentrant {
flash_api(addr, data, length, FLASH_COMMAND_READ);
}

uint32_t flash_read_u32(uint32_t addr) {
uint32_t flash_read_u32(uint32_t addr) __reentrant {
uint32_t data;

flash_api(addr, (uint8_t *)&data, sizeof(data), FLASH_COMMAND_READ);

return data;
}

uint16_t flash_read_u16(uint32_t addr) {
uint16_t flash_read_u16(uint32_t addr) __reentrant {
uint16_t data;

flash_api(addr, (uint8_t *)&data, sizeof(data), FLASH_COMMAND_READ);

return data;
}

uint8_t flash_read_u8(uint32_t addr) {
uint8_t flash_read_u8(uint32_t addr) __reentrant {
uint8_t data;

flash_api(addr, &data, sizeof(data), FLASH_COMMAND_READ);

return data;
}

void flash_write(uint32_t addr, __xdata uint8_t *data, uint32_t length) {
void flash_write(uint32_t addr, __xdata uint8_t *data, uint32_t length) __reentrant {
flash_api(addr, data, length, FLASH_COMMAND_WRITE);
}

void flash_write_u32(uint32_t addr, uint32_t data) {
void flash_write_u32(uint32_t addr, uint32_t data) __reentrant {
flash_api(addr, (uint8_t *)&data, sizeof(data), FLASH_COMMAND_WRITE);
}

void flash_write_u16(uint32_t addr, uint16_t data) {
void flash_write_u16(uint32_t addr, uint16_t data) __reentrant {
flash_api(addr, (uint8_t *)&data, sizeof(data), FLASH_COMMAND_WRITE);
}

void flash_write_u8(uint32_t addr, uint8_t data) {
void flash_write_u8(uint32_t addr, uint8_t data) __reentrant {
flash_api(addr, &data, sizeof(data), FLASH_COMMAND_WRITE);
}

void flash_erase(uint32_t addr) {
void flash_erase(uint32_t addr) __reentrant {
flash_api(addr, NULL, 0, FLASH_COMMAND_ERASE_1K);
}
10 changes: 10 additions & 0 deletions src/board/system76/common/include/board/debug_mailbox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-only

#ifndef _BOARD_DEBUG_MAILBOX_H
#define _BOARD_DEBUG_MAILBOX_H

// Poll the debug command mailbox at 0x0DF0 and execute any pending command.
// Called from the main loop each iteration.
void mailbox_event(void);

#endif // _BOARD_DEBUG_MAILBOX_H
2 changes: 1 addition & 1 deletion src/board/system76/common/include/board/dgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern int16_t dgpu_temp;
#endif // HAVE_DGPU

void dgpu_init(void);
int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points);
int16_t dgpu_set_fan_curve(uint8_t count, struct FanPoint *points) __reentrant;
uint8_t dgpu_get_fan_duty(void);
uint8_t dgpu_get_d_notify_level(bool ac);
void set_mux_ctrl(void);
Expand Down
2 changes: 1 addition & 1 deletion src/board/system76/common/include/board/fan.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant;
uint8_t fan_heatup(const struct Fan *fan, uint8_t duty) __reentrant;
uint8_t fan_cooldown(const struct Fan *fan, uint8_t duty) __reentrant;
uint8_t fan_smooth(uint8_t last_duty, uint8_t duty) __reentrant;
uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points);
uint8_t fan_points_are_valid(uint8_t count, struct FanPoint *points) __reentrant;

#endif // _BOARD_FAN_H
18 changes: 9 additions & 9 deletions src/board/system76/common/include/board/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* \param[out] data The memory area to copy to.
* \param[in] length The number of bytes to copy.
*/
void flash_read(uint32_t addr, __xdata uint8_t *data, uint32_t length);
void flash_read(uint32_t addr, __xdata uint8_t *data, uint32_t length) __reentrant;

/**
* Read a single byte from flash.
Expand All @@ -35,7 +35,7 @@ void flash_read(uint32_t addr, __xdata uint8_t *data, uint32_t length);
*
* \return The value read from flash.
*/
uint8_t flash_read_u8(uint32_t addr);
uint8_t flash_read_u8(uint32_t addr) __reentrant;

/**
* Read two bytes from flash.
Expand All @@ -44,7 +44,7 @@ uint8_t flash_read_u8(uint32_t addr);
*
* \return The value read from flash.
*/
uint16_t flash_read_u16(uint32_t addr);
uint16_t flash_read_u16(uint32_t addr) __reentrant;

/**
* Read four bytes from flash.
Expand All @@ -53,7 +53,7 @@ uint16_t flash_read_u16(uint32_t addr);
*
* \return The value read from flash.
*/
uint32_t flash_read_u32(uint32_t addr);
uint32_t flash_read_u32(uint32_t addr) __reentrant;

/**
* Write data to flash from the specified buffer.
Expand All @@ -62,37 +62,37 @@ uint32_t flash_read_u32(uint32_t addr);
* \param[in] data The memory area to copy from.
* \param[in] length The number of bytes to copy.
*/
void flash_write(uint32_t addr, __xdata uint8_t *data, uint32_t length);
void flash_write(uint32_t addr, __xdata uint8_t *data, uint32_t length) __reentrant;

/**
* Write a single byte to flash.
*
* \param[in] addr The flash address to read.
* \param[in] data The value to write to flash.
*/
void flash_write_u8(uint32_t addr, uint8_t data);
void flash_write_u8(uint32_t addr, uint8_t data) __reentrant;

/**
* Write two bytes to flash.
*
* \param[in] addr The flash address to read.
* \param[in] data The value to write to flash.
*/
void flash_write_u16(uint32_t addr, uint16_t data);
void flash_write_u16(uint32_t addr, uint16_t data) __reentrant;

/**
* Write two bytes to flash.
*
* \param[in] addr The flash address to read.
* \param[in] data The value to write to flash.
*/
void flash_write_u32(uint32_t addr, uint32_t data);
void flash_write_u32(uint32_t addr, uint32_t data) __reentrant;

/**
* Erase a 1K block of flash.
*
* \param[in] addr The flash address contained in the 1K block.
*/
void flash_erase(uint32_t addr);
void flash_erase(uint32_t addr) __reentrant;

#endif // _BOARD_FLASH_H
Loading