1#ifndef __LINUX_CLASS_DUAL_ROLE_H__ 2#define __LINUX_CLASS_DUAL_ROLE_H__ 3 4#include <linux/workqueue.h> 5#include <linux/errno.h> 6#include <linux/types.h> 7 8struct device; 9 10enum dual_role_supported_modes { 11 DUAL_ROLE_SUPPORTED_MODES_DFP_AND_UFP = 0, 12 DUAL_ROLE_SUPPORTED_MODES_DFP, 13 DUAL_ROLE_SUPPORTED_MODES_UFP, 14/*The following should be the last element*/ 15 DUAL_ROLE_PROP_SUPPORTED_MODES_TOTAL, 16}; 17 18enum { 19 DUAL_ROLE_PROP_MODE_UFP = 0, 20 DUAL_ROLE_PROP_MODE_DFP, 21 DUAL_ROLE_PROP_MODE_NONE, 22/*The following should be the last element*/ 23 DUAL_ROLE_PROP_MODE_TOTAL, 24}; 25 26enum { 27 DUAL_ROLE_PROP_PR_SRC = 0, 28 DUAL_ROLE_PROP_PR_SNK, 29 DUAL_ROLE_PROP_PR_NONE, 30/*The following should be the last element*/ 31 DUAL_ROLE_PROP_PR_TOTAL, 32 33}; 34 35enum { 36 DUAL_ROLE_PROP_DR_HOST = 0, 37 DUAL_ROLE_PROP_DR_DEVICE, 38 DUAL_ROLE_PROP_DR_NONE, 39/*The following should be the last element*/ 40 DUAL_ROLE_PROP_DR_TOTAL, 41}; 42 43enum { 44 DUAL_ROLE_PROP_VCONN_SUPPLY_NO = 0, 45 DUAL_ROLE_PROP_VCONN_SUPPLY_YES, 46/*The following should be the last element*/ 47 DUAL_ROLE_PROP_VCONN_SUPPLY_TOTAL, 48}; 49 50enum dual_role_property { 51 DUAL_ROLE_PROP_SUPPORTED_MODES = 0, 52 DUAL_ROLE_PROP_MODE, 53 DUAL_ROLE_PROP_PR, 54 DUAL_ROLE_PROP_DR, 55 DUAL_ROLE_PROP_VCONN_SUPPLY, 56}; 57 58struct dual_role_phy_instance; 59 60/* Description of typec port */ 61struct dual_role_phy_desc { 62 /* /sys/class/dual_role_usb/<name>/ */ 63 const char *name; 64 enum dual_role_supported_modes supported_modes; 65 enum dual_role_property *properties; 66 size_t num_properties; 67 68 /* Callback for "cat /sys/class/dual_role_usb/<name>/<property>" */ 69 int (*get_property)(struct dual_role_phy_instance *dual_role, 70 enum dual_role_property prop, 71 unsigned int *val); 72 /* Callback for "echo <value> > 73 * /sys/class/dual_role_usb/<name>/<property>" */ 74 int (*set_property)(struct dual_role_phy_instance *dual_role, 75 enum dual_role_property prop, 76 const unsigned int *val); 77 /* Decides whether userspace can change a specific property */ 78 int (*property_is_writeable)(struct dual_role_phy_instance *dual_role, 79 enum dual_role_property prop); 80}; 81 82struct dual_role_phy_instance { 83 const struct dual_role_phy_desc *desc; 84 85 /* Driver private data */ 86 void *drv_data; 87 88 struct device dev; 89 struct work_struct changed_work; 90}; 91 92#if IS_ENABLED(CONFIG_DUAL_ROLE_USB_INTF) 93extern void dual_role_instance_changed(struct dual_role_phy_instance 94 *dual_role); 95extern struct dual_role_phy_instance *__must_check 96devm_dual_role_instance_register(struct device *parent, 97 const struct dual_role_phy_desc *desc); 98extern void devm_dual_role_instance_unregister(struct device *dev, 99 struct dual_role_phy_instance 100 *dual_role); 101extern int dual_role_get_property(struct dual_role_phy_instance *dual_role, 102 enum dual_role_property prop, 103 unsigned int *val); 104extern int dual_role_set_property(struct dual_role_phy_instance *dual_role, 105 enum dual_role_property prop, 106 const unsigned int *val); 107extern int dual_role_property_is_writeable(struct dual_role_phy_instance 108 *dual_role, 109 enum dual_role_property prop); 110extern void *dual_role_get_drvdata(struct dual_role_phy_instance *dual_role); 111#else /* CONFIG_DUAL_ROLE_USB_INTF */ 112static void dual_role_instance_changed(struct dual_role_phy_instance 113 *dual_role){} 114static struct dual_role_phy_instance *__must_check 115devm_dual_role_instance_register(struct device *parent, 116 const struct dual_role_phy_desc *desc) 117{ 118 return ERR_PTR(-ENOSYS); 119} 120static void devm_dual_role_instance_unregister(struct device *dev, 121 struct dual_role_phy_instance 122 *dual_role){} 123static void *dual_role_get_drvdata(struct dual_role_phy_instance *dual_role) 124{ 125 return ERR_PTR(-ENOSYS); 126} 127#endif /* CONFIG_DUAL_ROLE_USB_INTF */ 128#endif /* __LINUX_CLASS_DUAL_ROLE_H__ */ 129