1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. 4 * Copyright (c) 2023, Linaro Ltd. All rights reserved. 5 */ 6 #ifndef __QCOM_PMIC_TYPEC_H__ 7 #define __QCOM_PMIC_TYPEC_H__ 8 9 #include <linux/platform_device.h> 10 #include <linux/usb/tcpm.h> 11 12 #define TYPEC_SNK_STATUS_REG 0x06 13 #define DETECTED_SNK_TYPE_MASK GENMASK(6, 0) 14 #define SNK_DAM_MASK GENMASK(6, 4) 15 #define SNK_DAM_500MA BIT(6) 16 #define SNK_DAM_1500MA BIT(5) 17 #define SNK_DAM_3000MA BIT(4) 18 #define SNK_RP_STD BIT(3) 19 #define SNK_RP_1P5 BIT(2) 20 #define SNK_RP_3P0 BIT(1) 21 #define SNK_RP_SHORT BIT(0) 22 23 #define TYPEC_SRC_STATUS_REG 0x08 24 #define DETECTED_SRC_TYPE_MASK GENMASK(4, 0) 25 #define SRC_HIGH_BATT BIT(5) 26 #define SRC_DEBUG_ACCESS BIT(4) 27 #define SRC_RD_OPEN BIT(3) 28 #define SRC_RD_RA_VCONN BIT(2) 29 #define SRC_RA_OPEN BIT(1) 30 #define AUDIO_ACCESS_RA_RA BIT(0) 31 32 #define TYPEC_STATE_MACHINE_STATUS_REG 0x09 33 #define TYPEC_ATTACH_DETACH_STATE BIT(5) 34 35 #define TYPEC_SM_STATUS_REG 0x0A 36 #define TYPEC_SM_VBUS_VSAFE5V BIT(5) 37 #define TYPEC_SM_VBUS_VSAFE0V BIT(6) 38 #define TYPEC_SM_USBIN_LT_LV BIT(7) 39 40 #define TYPEC_MISC_STATUS_REG 0x0B 41 #define TYPEC_WATER_DETECTION_STATUS BIT(7) 42 #define SNK_SRC_MODE BIT(6) 43 #define TYPEC_VBUS_DETECT BIT(5) 44 #define TYPEC_VBUS_ERROR_STATUS BIT(4) 45 #define TYPEC_DEBOUNCE_DONE BIT(3) 46 #define CC_ORIENTATION BIT(1) 47 #define CC_ATTACHED BIT(0) 48 49 #define LEGACY_CABLE_STATUS_REG 0x0D 50 #define TYPEC_LEGACY_CABLE_STATUS BIT(1) 51 #define TYPEC_NONCOMP_LEGACY_CABLE_STATUS BIT(0) 52 53 #define TYPEC_U_USB_STATUS_REG 0x0F 54 #define U_USB_GROUND_NOVBUS BIT(6) 55 #define U_USB_GROUND BIT(4) 56 #define U_USB_FMB1 BIT(3) 57 #define U_USB_FLOAT1 BIT(2) 58 #define U_USB_FMB2 BIT(1) 59 #define U_USB_FLOAT2 BIT(0) 60 61 #define TYPEC_MODE_CFG_REG 0x44 62 #define TYPEC_TRY_MODE_MASK GENMASK(4, 3) 63 #define EN_TRY_SNK BIT(4) 64 #define EN_TRY_SRC BIT(3) 65 #define TYPEC_POWER_ROLE_CMD_MASK GENMASK(2, 0) 66 #define EN_SRC_ONLY BIT(2) 67 #define EN_SNK_ONLY BIT(1) 68 #define TYPEC_DISABLE_CMD BIT(0) 69 70 #define TYPEC_VCONN_CONTROL_REG 0x46 71 #define VCONN_EN_ORIENTATION BIT(2) 72 #define VCONN_EN_VALUE BIT(1) 73 #define VCONN_EN_SRC BIT(0) 74 75 #define TYPEC_CCOUT_CONTROL_REG 0x48 76 #define TYPEC_CCOUT_BUFFER_EN BIT(2) 77 #define TYPEC_CCOUT_VALUE BIT(1) 78 #define TYPEC_CCOUT_SRC BIT(0) 79 80 #define DEBUG_ACCESS_SRC_CFG_REG 0x4C 81 #define EN_UNORIENTED_DEBUG_ACCESS_SRC BIT(0) 82 83 #define TYPE_C_CRUDE_SENSOR_CFG_REG 0x4e 84 #define EN_SRC_CRUDE_SENSOR BIT(1) 85 #define EN_SNK_CRUDE_SENSOR BIT(0) 86 87 #define TYPEC_EXIT_STATE_CFG_REG 0x50 88 #define BYPASS_VSAFE0V_DURING_ROLE_SWAP BIT(3) 89 #define SEL_SRC_UPPER_REF BIT(2) 90 #define USE_TPD_FOR_EXITING_ATTACHSRC BIT(1) 91 #define EXIT_SNK_BASED_ON_CC BIT(0) 92 93 #define TYPEC_CURRSRC_CFG_REG 0x52 94 #define TYPEC_SRC_RP_SEL_330UA BIT(1) 95 #define TYPEC_SRC_RP_SEL_180UA BIT(0) 96 #define TYPEC_SRC_RP_SEL_80UA 0 97 #define TYPEC_SRC_RP_SEL_MASK GENMASK(1, 0) 98 99 #define TYPEC_INTERRUPT_EN_CFG_1_REG 0x5E 100 #define TYPEC_LEGACY_CABLE_INT_EN BIT(7) 101 #define TYPEC_NONCOMPLIANT_LEGACY_CABLE_INT_EN BIT(6) 102 #define TYPEC_TRYSOURCE_DETECT_INT_EN BIT(5) 103 #define TYPEC_TRYSINK_DETECT_INT_EN BIT(4) 104 #define TYPEC_CCOUT_DETACH_INT_EN BIT(3) 105 #define TYPEC_CCOUT_ATTACH_INT_EN BIT(2) 106 #define TYPEC_VBUS_DEASSERT_INT_EN BIT(1) 107 #define TYPEC_VBUS_ASSERT_INT_EN BIT(0) 108 109 #define TYPEC_INTERRUPT_EN_CFG_2_REG 0x60 110 #define TYPEC_SRC_BATT_HPWR_INT_EN BIT(6) 111 #define MICRO_USB_STATE_CHANGE_INT_EN BIT(5) 112 #define TYPEC_STATE_MACHINE_CHANGE_INT_EN BIT(4) 113 #define TYPEC_DEBUG_ACCESS_DETECT_INT_EN BIT(3) 114 #define TYPEC_WATER_DETECTION_INT_EN BIT(2) 115 #define TYPEC_VBUS_ERROR_INT_EN BIT(1) 116 #define TYPEC_DEBOUNCE_DONE_INT_EN BIT(0) 117 118 #define TYPEC_DEBOUNCE_OPTION_REG 0x62 119 #define REDUCE_TCCDEBOUNCE_TO_2MS BIT(2) 120 121 #define TYPE_C_SBU_CFG_REG 0x6A 122 #define SEL_SBU1_ISRC_VAL 0x04 123 #define SEL_SBU2_ISRC_VAL 0x01 124 125 #define TYPEC_U_USB_CFG_REG 0x70 126 #define EN_MICRO_USB_FACTORY_MODE BIT(1) 127 #define EN_MICRO_USB_MODE BIT(0) 128 129 #define TYPEC_PMI632_U_USB_WATER_PROTECTION_CFG_REG 0x72 130 131 #define TYPEC_U_USB_WATER_PROTECTION_CFG_REG 0x73 132 #define EN_MICRO_USB_WATER_PROTECTION BIT(4) 133 #define MICRO_USB_DETECTION_ON_TIME_CFG_MASK GENMASK(3, 2) 134 #define MICRO_USB_DETECTION_PERIOD_CFG_MASK GENMASK(1, 0) 135 136 #define TYPEC_PMI632_MICRO_USB_MODE_REG 0x73 137 #define MICRO_USB_MODE_ONLY BIT(0) 138 139 /* Interrupt numbers */ 140 #define PMIC_TYPEC_OR_RID_IRQ 0x0 141 #define PMIC_TYPEC_VPD_IRQ 0x1 142 #define PMIC_TYPEC_CC_STATE_IRQ 0x2 143 #define PMIC_TYPEC_VCONN_OC_IRQ 0x3 144 #define PMIC_TYPEC_VBUS_IRQ 0x4 145 #define PMIC_TYPEC_ATTACH_DETACH_IRQ 0x5 146 #define PMIC_TYPEC_LEGACY_CABLE_IRQ 0x6 147 #define PMIC_TYPEC_TRY_SNK_SRC_IRQ 0x7 148 149 /* Resources */ 150 #define PMIC_TYPEC_MAX_IRQS 0x08 151 152 struct pmic_typec_port_irq_params { 153 int virq; 154 char *irq_name; 155 }; 156 157 struct pmic_typec_port_resources { 158 unsigned int nr_irqs; 159 struct pmic_typec_port_irq_params irq_params[PMIC_TYPEC_MAX_IRQS]; 160 }; 161 162 /* API */ 163 struct pmic_typec; 164 165 struct pmic_typec_port *qcom_pmic_typec_port_alloc(struct device *dev); 166 167 int qcom_pmic_typec_port_probe(struct platform_device *pdev, 168 struct pmic_typec_port *pmic_typec_port, 169 struct pmic_typec_port_resources *res, 170 struct regmap *regmap, 171 u32 base); 172 173 int qcom_pmic_typec_port_start(struct pmic_typec_port *pmic_typec_port, 174 struct tcpm_port *tcpm_port); 175 176 void qcom_pmic_typec_port_stop(struct pmic_typec_port *pmic_typec_port); 177 178 int qcom_pmic_typec_port_get_cc(struct pmic_typec_port *pmic_typec_port, 179 enum typec_cc_status *cc1, 180 enum typec_cc_status *cc2); 181 182 int qcom_pmic_typec_port_set_cc(struct pmic_typec_port *pmic_typec_port, 183 enum typec_cc_status cc); 184 185 int qcom_pmic_typec_port_get_vbus(struct pmic_typec_port *pmic_typec_port); 186 187 int qcom_pmic_typec_port_set_vconn(struct pmic_typec_port *pmic_typec_port, bool on); 188 189 int qcom_pmic_typec_port_start_toggling(struct pmic_typec_port *pmic_typec_port, 190 enum typec_port_type port_type, 191 enum typec_cc_status cc); 192 193 int qcom_pmic_typec_port_set_vbus(struct pmic_typec_port *pmic_typec_port, bool on); 194 195 #endif /* __QCOM_PMIC_TYPE_C_PORT_H__ */ 196