Skip to content

Commit 432748c

Browse files
committed
[WIP] ec/system76/ec: Implement usbc_get_ops
Change-Id: Icee0661ec0d0c949b73503e639dd8a461c05235a Signed-off-by: Tim Crawford <[email protected]>
1 parent 69daa35 commit 432748c

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

src/ec/system76/ec/Makefile.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ all-y += system76_ec.c
55

66
ramstage-y += smbios.c
77
ramstage-$(CONFIG_EC_SYSTEM76_EC_LOCKDOWN) += lockdown.c
8+
ramstage-y += usbc_mux.c
89

910
smm-$(CONFIG_DEBUG_SMI) += system76_ec.c
1011

src/ec/system76/ec/usbc_mux.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
3+
#include "system76_ec.h"
4+
#include <console/console.h>
5+
#include <delay.h>
6+
#include <device/usbc_mux.h>
7+
#include <types.h>
8+
9+
#define CMD_USBC_MUX_INFO 23
10+
11+
enum usbc_mux_flags {
12+
USBC_MUX_DP = BIT(0),
13+
USBC_MUX_USB = BIT(1),
14+
USBC_MUX_CABLE = BIT(2),
15+
USBC_MUX_POLARITY = BIT(3),
16+
USBC_MUX_HPD_LVL = BIT(4),
17+
USBC_MUX_HPD_IRQ = BIT(5),
18+
USBC_MUX_UFP = BIT(6),
19+
USBC_MUX_DBG_ACC = BIT(7),
20+
};
21+
22+
static int system76_ec_get_mux_info(int port, struct usbc_mux_info *info)
23+
{
24+
uint8_t request[1] = { port };
25+
uint8_t reply[3] = { 0 };
26+
uint8_t flags;
27+
uint8_t pin_mode;
28+
bool res;
29+
30+
if (!info)
31+
return -1;
32+
33+
res = system76_ec_cmd(CMD_USBC_MUX_INFO, request, ARRAY_SIZE(request),
34+
reply, ARRAY_SIZE(reply));
35+
if (!res)
36+
return -1;
37+
38+
flags = reply[1];
39+
pin_mode = reply[2];
40+
41+
info->dp = !!(flags & USBC_MUX_DP);
42+
info->usb = !!(flags & USBC_MUX_USB);
43+
info->cable = !!(flags & USBC_MUX_CABLE);
44+
info->polarity = !!(flags & USBC_MUX_POLARITY);
45+
info->hpd_lvl = !!(flags & USBC_MUX_HPD_LVL);
46+
info->hpd_irq = !!(flags & USBC_MUX_HPD_IRQ);
47+
info->ufp = !!(flags & USBC_MUX_UFP);
48+
info->dbg_acc = !!(flags & USBC_MUX_DBG_ACC);
49+
info->dp_pin_mode = pin_mode;
50+
51+
printk(BIOS_SPEW, "%s: dp=%u, usb=%u\n", __func__, info->dp, info->usb);
52+
printk(BIOS_SPEW, "%s: cable=%u, polarity=%u\n", __func__, info->cable, info->polarity);
53+
printk(BIOS_SPEW, "%s: hpd_lvl=%u, hpd_irq=%u\n", __func__, info->hpd_lvl, info->hpd_irq);
54+
printk(BIOS_SPEW, "%s: ufp=%u, dbg_acc=%u\n", __func__, info->ufp, info->dbg_acc);
55+
printk(BIOS_SPEW, "%s: pin_mode=0x%x\n", __func__, info->dp_pin_mode);
56+
57+
return 0;
58+
}
59+
60+
static int system76_ec_wait_for_connection(long timeout_ms)
61+
{
62+
// TODO
63+
return 0;
64+
}
65+
66+
static int system76_ec_enter_dp_mode(int port)
67+
{
68+
// TODO
69+
return -1;
70+
}
71+
72+
static int system76_ec_wait_for_dp_mode_entry(int port, long timeout_ms)
73+
{
74+
// TODO
75+
return -1;
76+
}
77+
78+
static int system76_ec_wait_for_hpd(int port, long timeout_ms)
79+
{
80+
// TODO
81+
return -1;
82+
}
83+
84+
static const struct usbc_ops system76_ec_usbc_ops = {
85+
.mux_ops = {
86+
.get_mux_info = system76_ec_get_mux_info,
87+
},
88+
.dp_ops = {
89+
.wait_for_connection = system76_ec_wait_for_connection,
90+
.enter_dp_mode = system76_ec_enter_dp_mode,
91+
.wait_for_dp_mode_entry = system76_ec_wait_for_dp_mode_entry,
92+
.wait_for_hpd = system76_ec_wait_for_hpd,
93+
},
94+
};
95+
96+
const struct usbc_ops *usbc_get_ops(void)
97+
{
98+
return &system76_ec_usbc_ops;
99+
}

0 commit comments

Comments
 (0)