1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/* Copyright 2019 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* PS8818 retimer.
*/
#include "chipset.h"
#include "common.h"
#include "console.h"
#include "gpio.h"
#include "i2c.h"
#include "ioexpander.h"
#include "ps8818.h"
#include "usb_mux.h"
static int ps8818_i2c_read(int port, int page, int offset, int *data)
{
return i2c_read8(usb_retimers[port].i2c_port,
usb_retimers[port].i2c_addr_flags + page,
offset, data);
}
static int ps8818_i2c_write(int port, int page, int offset, int data)
{
return i2c_write8(usb_retimers[port].i2c_port,
usb_retimers[port].i2c_addr_flags + page,
offset, data);
}
int ps8818_detect(int port)
{
int rv = EC_ERROR_NOT_POWERED;
int val;
/* Detected if we are powered and can read the device */
if (!chipset_in_state(CHIPSET_STATE_HARD_OFF))
rv = ps8818_i2c_read(port,
PS8818_REG_PAGE0,
PS8818_REG0_FLIP,
&val);
return rv;
}
static int ps8818_set_mux(int port, mux_state_t mux_state)
{
int rv;
int val = 0;
if (chipset_in_state(CHIPSET_STATE_HARD_OFF))
return (mux_state == USB_PD_MUX_NONE) ? EC_SUCCESS
: EC_ERROR_NOT_POWERED;
if (mux_state & USB_PD_MUX_USB_ENABLED)
val |= PS8818_MODE_USB_ENABLE;
if (mux_state & USB_PD_MUX_DP_ENABLED)
val |= PS8818_MODE_DP_ENABLE;
rv = ps8818_i2c_write(port,
PS8818_REG_PAGE0,
PS8818_REG0_MODE,
val);
if (rv)
return rv;
val = 0;
if (mux_state & USB_PD_MUX_POLARITY_INVERTED)
val |= PS8818_FLIP_CONFIG;
return ps8818_i2c_write(port,
PS8818_REG_PAGE0,
PS8818_REG0_FLIP,
val);
}
const struct usb_retimer_driver ps8818_usb_retimer = {
.set = ps8818_set_mux,
};
|