Skip to content

Commit

Permalink
wip: efi stub
Browse files Browse the repository at this point in the history
Make tegra UART, Device detection framework accesible for all devices
  • Loading branch information
jonasschwoebel committed Nov 4, 2022
1 parent 78f0fdc commit 1d480b5
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
109 changes: 109 additions & 0 deletions drivers/firmware/efi/libstub/efi-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
enum winrt_device_names winrt_device = unknown_device;
int i;

u8 buf_recv[4];
u8 buf_send = 0;
u32 size = 1;
u8 address = 0x48;
u8 tmp;

efi_system_table = sys_table_arg;

/* Check if we were booted by the EFI firmware */
Expand All @@ -152,6 +158,26 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
if (status != EFI_SUCCESS)
goto fail;

/*
for (i = 0; i < 256; i++) {
if (i % 16 == 0) {
efi_printk("\n");
efi_printk("%02x: ", i);
}
i2c_recv_buf_small(buf_recv, size, 0, address, i);
efi_printk("%02x ", buf_recv[0]);
}
while(true) {
i2c_recv_buf_small(buf_recv, size, 0, address, buf_send);
if (tmp != buf_recv[0]) {
tmp = buf_recv[0];
efi_info("first byte: %04x\n", tmp);
}
}
*/

/*
* Figure out on which Windows RT device is booted.
*/
Expand Down Expand Up @@ -423,3 +449,86 @@ void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
++*count;
}
}

////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// I2C ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

#define vu32 volatile u32

static void _i2c_wait(vu32 *base)
{
u32 i;
base[0x23] = 0x25;
for (i = 0; i < 20; i++)
{
if (!(base[0x23] & 1))
break;
}
}

/**
* @brief i2c send package
* Sends a package to the I2C Bus
* @param idx i2c controller
* @param x slave address
* @param buf data to be transmitted
* @param size data size
* @return int error code
*/
static int _i2c_send_pkt(u32 idx, u32 x, u8 *buf, u32 size)
{
vu32 *base = (vu32 *) 0x7000d000; //i2c_addrs[idx];
u32 tmp = 0;
if (size > 4)
return 0;

memcpy(&tmp, buf, size);

base[1] = x << 1; //Set x (send mode). x = address + 0=write
base[3] = tmp; //Set value. data register
base[0] = (2 * size - 2) | 0x2800; //Set size and send mode.
_i2c_wait(base); //Kick transaction.

base[0] = (base[0] & 0xFFFFFDFF) | 0x200;
while (base[7] & 0x100)
;

if (base[7] << 28)
return 0;

return 1;
}

static int _i2c_recv_pkt(u32 idx, u8 *buf, u32 size, u32 x)
{
vu32 *base = (vu32 *) 0x7000d000; //i2c_addrs[idx];
u32 tmp;

if (size > 4)
return 0;

base[1] = (x << 1) | 1; //Set x (recv mode).
base[0] = (2 * size - 2) | 0x2840; //Set size and recv mode.
_i2c_wait(base); //Kick transaction.

base[0] = (base[0] & 0xFFFFFDFF) | 0x200;
while (base[7] & 0x100)
;

if (base[7] << 28)
return 0;

tmp = base[3]; //Get value.
memcpy(buf, &tmp, size);

return 1;
}

int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y)
{
int res = _i2c_send_pkt(idx, x, (u8 *)&y, 1);
if (res)
res = _i2c_recv_pkt(idx, buf, size, x);
return res;
}
5 changes: 5 additions & 0 deletions drivers/firmware/efi/libstub/efistub.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,3 +910,8 @@ enum winrt_device_names winrt_setup(void);
void tegra_uart_print(const char *string);
void tegra_uart_init(void);

/**
* I2C Stuff
*/
int i2c_recv_buf_small(u8 *buf, u32 size, u32 idx, u32 x, u32 y);

1 change: 0 additions & 1 deletion drivers/firmware/efi/libstub/tegra_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,3 @@ void tegra_uart_print(const char *string)
++string;
}
}

0 comments on commit 1d480b5

Please sign in to comment.