Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 1 | /* 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 | |
| 18 | struct usbpd; |
| 19 | |
| 20 | #if IS_ENABLED(CONFIG_USB_PD_POLICY) |
| 21 | struct usbpd *usbpd_create(struct device *parent); |
| 22 | void usbpd_destroy(struct usbpd *pd); |
| 23 | #else |
| 24 | static inline struct usbpd *usbpd_create(struct device *parent) |
| 25 | { |
| 26 | return ERR_PTR(-ENODEV); |
| 27 | } |
| 28 | static inline void usbpd_destroy(struct usbpd *pd) { } |
| 29 | #endif |
| 30 | |
| 31 | enum data_role { |
| 32 | DR_NONE = -1, |
| 33 | DR_UFP = 0, |
| 34 | DR_DFP = 1, |
| 35 | }; |
| 36 | |
| 37 | enum power_role { |
| 38 | PR_NONE = -1, |
| 39 | PR_SINK = 0, |
| 40 | PR_SRC = 1, |
| 41 | }; |
| 42 | |
| 43 | enum pd_sig_type { |
| 44 | HARD_RESET_SIG = 0, |
| 45 | CABLE_RESET_SIG, |
| 46 | }; |
| 47 | |
Jack Pham | e95cfc7 | 2017-08-01 17:36:50 -0700 | [diff] [blame] | 48 | enum pd_sop_type { |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 49 | SOP_MSG = 0, |
| 50 | SOPI_MSG, |
| 51 | SOPII_MSG, |
| 52 | }; |
| 53 | |
| 54 | enum 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 | |
| 63 | struct pd_phy_params { |
Jack Pham | e95cfc7 | 2017-08-01 17:36:50 -0700 | [diff] [blame] | 64 | 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 Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 66 | 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 Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | #if IS_ENABLED(CONFIG_QPNP_USB_PDPHY) |
| 74 | int pd_phy_open(struct pd_phy_params *params); |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 75 | int pd_phy_signal(enum pd_sig_type sig); |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 76 | int pd_phy_write(u16 hdr, const u8 *data, size_t data_len, |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 77 | enum pd_sop_type sop); |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 78 | int pd_phy_update_roles(enum data_role dr, enum power_role pr); |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 79 | void pd_phy_close(void); |
| 80 | #else |
| 81 | static inline int pd_phy_open(struct pd_phy_params *params) |
| 82 | { |
| 83 | return -ENODEV; |
| 84 | } |
| 85 | |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 86 | static inline int pd_phy_signal(enum pd_sig_type type) |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 87 | { |
| 88 | return -ENODEV; |
| 89 | } |
| 90 | |
| 91 | static inline int pd_phy_write(u16 hdr, const u8 *data, size_t data_len, |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 92 | enum pd_sop_type sop) |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 93 | { |
| 94 | return -ENODEV; |
| 95 | } |
| 96 | |
| 97 | static inline int pd_phy_update_roles(enum data_role dr, enum power_role pr) |
| 98 | { |
| 99 | return -ENODEV; |
| 100 | } |
| 101 | |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 102 | static inline void pd_phy_close(void) |
| 103 | { |
| 104 | } |
| 105 | #endif |
| 106 | #endif /* _USBPD_H */ |