blob: 9b6053e940e90d1d99d2d08595810fed08e9a43f [file] [log] [blame]
Jack Phamf4baeb12017-02-03 19:01:48 -08001/* Copyright (c) 2016-2017, Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _USBPD_H
14#define _USBPD_H
15
16#include <linux/device.h>
17
18struct usbpd;
19
20#if IS_ENABLED(CONFIG_USB_PD_POLICY)
21struct usbpd *usbpd_create(struct device *parent);
22void usbpd_destroy(struct usbpd *pd);
23#else
24static inline struct usbpd *usbpd_create(struct device *parent)
25{
26 return ERR_PTR(-ENODEV);
27}
28static inline void usbpd_destroy(struct usbpd *pd) { }
29#endif
30
31enum data_role {
32 DR_NONE = -1,
33 DR_UFP = 0,
34 DR_DFP = 1,
35};
36
37enum power_role {
38 PR_NONE = -1,
39 PR_SINK = 0,
40 PR_SRC = 1,
41};
42
43enum pd_sig_type {
44 HARD_RESET_SIG = 0,
45 CABLE_RESET_SIG,
46};
47
Jack Phame95cfc72017-08-01 17:36:50 -070048enum pd_sop_type {
Jack Phamf4baeb12017-02-03 19:01:48 -080049 SOP_MSG = 0,
50 SOPI_MSG,
51 SOPII_MSG,
52};
53
54enum pd_spec_rev {
55 USBPD_REV_20 = 1,
56 USBPD_REV_30 = 2,
57};
58
59/* enable msg and signal to be received by phy */
60#define FRAME_FILTER_EN_SOP BIT(0)
61#define FRAME_FILTER_EN_HARD_RESET BIT(5)
62
63struct pd_phy_params {
Jack Phame95cfc72017-08-01 17:36:50 -070064 void (*signal_cb)(struct usbpd *pd, enum pd_sig_type sig);
65 void (*msg_rx_cb)(struct usbpd *pd, enum pd_sop_type sop,
Jack Phamf4baeb12017-02-03 19:01:48 -080066 u8 *buf, size_t len);
67 void (*shutdown_cb)(struct usbpd *pd);
68 enum data_role data_role;
69 enum power_role power_role;
70 u8 frame_filter_val;
Jack Phamf4baeb12017-02-03 19:01:48 -080071};
72
73#if IS_ENABLED(CONFIG_QPNP_USB_PDPHY)
74int pd_phy_open(struct pd_phy_params *params);
Jack Pham7dfd7612017-08-01 18:04:13 -070075int pd_phy_signal(enum pd_sig_type sig);
Jack Phamf4baeb12017-02-03 19:01:48 -080076int pd_phy_write(u16 hdr, const u8 *data, size_t data_len,
Jack Pham7dfd7612017-08-01 18:04:13 -070077 enum pd_sop_type sop);
Jack Phamf4baeb12017-02-03 19:01:48 -080078int pd_phy_update_roles(enum data_role dr, enum power_role pr);
Jack Phamf4baeb12017-02-03 19:01:48 -080079void pd_phy_close(void);
80#else
81static inline int pd_phy_open(struct pd_phy_params *params)
82{
83 return -ENODEV;
84}
85
Jack Pham7dfd7612017-08-01 18:04:13 -070086static inline int pd_phy_signal(enum pd_sig_type type)
Jack Phamf4baeb12017-02-03 19:01:48 -080087{
88 return -ENODEV;
89}
90
91static inline int pd_phy_write(u16 hdr, const u8 *data, size_t data_len,
Jack Pham7dfd7612017-08-01 18:04:13 -070092 enum pd_sop_type sop)
Jack Phamf4baeb12017-02-03 19:01:48 -080093{
94 return -ENODEV;
95}
96
97static inline int pd_phy_update_roles(enum data_role dr, enum power_role pr)
98{
99 return -ENODEV;
100}
101
Jack Phamf4baeb12017-02-03 19:01:48 -0800102static inline void pd_phy_close(void)
103{
104}
105#endif
106#endif /* _USBPD_H */