@@ -228,6 +228,61 @@ static const struct regmap_config sm5502_muic_regmap_config = {
228228 .max_register = SM5502_REG_END ,
229229};
230230
231+ /* Change DM_CON/DP_CON/VBUSIN switch according to cable type */
232+ static int sm5502_muic_set_path (struct sm5502_muic_info * info ,
233+ unsigned int con_sw , unsigned int vbus_sw ,
234+ bool attached )
235+ {
236+ int ret ;
237+
238+ if (!attached ) {
239+ con_sw = DM_DP_SWITCH_OPEN ;
240+ vbus_sw = VBUSIN_SWITCH_OPEN ;
241+ }
242+
243+ switch (con_sw ) {
244+ case DM_DP_SWITCH_OPEN :
245+ case DM_DP_SWITCH_USB :
246+ case DM_DP_SWITCH_AUDIO :
247+ case DM_DP_SWITCH_UART :
248+ ret = regmap_update_bits (info -> regmap , SM5502_REG_MANUAL_SW1 ,
249+ SM5502_REG_MANUAL_SW1_DP_MASK |
250+ SM5502_REG_MANUAL_SW1_DM_MASK ,
251+ con_sw );
252+ if (ret < 0 ) {
253+ dev_err (info -> dev ,
254+ "cannot update DM_CON/DP_CON switch\n" );
255+ return ret ;
256+ }
257+ break ;
258+ default :
259+ dev_err (info -> dev , "Unknown DM_CON/DP_CON switch type (%d)\n" ,
260+ con_sw );
261+ return - EINVAL ;
262+ };
263+
264+ switch (vbus_sw ) {
265+ case VBUSIN_SWITCH_OPEN :
266+ case VBUSIN_SWITCH_VBUSOUT :
267+ case VBUSIN_SWITCH_MIC :
268+ case VBUSIN_SWITCH_VBUSOUT_WITH_USB :
269+ ret = regmap_update_bits (info -> regmap , SM5502_REG_MANUAL_SW1 ,
270+ SM5502_REG_MANUAL_SW1_VBUSIN_MASK ,
271+ vbus_sw );
272+ if (ret < 0 ) {
273+ dev_err (info -> dev ,
274+ "cannot update VBUSIN switch\n" );
275+ return ret ;
276+ }
277+ break ;
278+ default :
279+ dev_err (info -> dev , "Unknown VBUS switch type (%d)\n" , vbus_sw );
280+ return - EINVAL ;
281+ };
282+
283+ return 0 ;
284+ }
285+
231286/* Return cable type of attached or detached accessories */
232287static unsigned int sm5502_muic_get_cable_type (struct sm5502_muic_info * info )
233288{
@@ -329,7 +384,10 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
329384 static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND ;
330385 const char * * cable_names = info -> edev -> supported_cable ;
331386 unsigned int cable_type = SM5502_MUIC_ADC_GROUND ;
387+ unsigned int con_sw = DM_DP_SWITCH_OPEN ;
388+ unsigned int vbus_sw = VBUSIN_SWITCH_OPEN ;
332389 unsigned int idx = 0 ;
390+ int ret ;
333391
334392 if (!cable_names )
335393 return 0 ;
@@ -343,22 +401,32 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
343401
344402 switch (cable_type ) {
345403 case SM5502_MUIC_ADC_OPEN_USB :
346- idx = EXTCON_CABLE_USB ;
404+ idx = EXTCON_CABLE_USB ;
405+ con_sw = DM_DP_SWITCH_USB ;
406+ vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB ;
347407 break ;
348408 case SM5502_MUIC_ADC_OPEN_TA :
349- idx = EXTCON_CABLE_TA ;
409+ idx = EXTCON_CABLE_TA ;
410+ con_sw = DM_DP_SWITCH_OPEN ;
411+ vbus_sw = VBUSIN_SWITCH_VBUSOUT ;
350412 break ;
351413 case SM5502_MUIC_ADC_OPEN_USB_OTG :
352- idx = EXTCON_CABLE_USB_HOST ;
353- break ;
354- case SM5502_MUIC_ADC_GROUND :
414+ idx = EXTCON_CABLE_USB_HOST ;
415+ con_sw = DM_DP_SWITCH_USB ;
416+ vbus_sw = VBUSIN_SWITCH_OPEN ;
355417 break ;
356418 default :
357419 dev_dbg (info -> dev ,
358420 "cannot handle this cable_type (0x%x)\n" , cable_type );
359421 return 0 ;
360422 };
361423
424+ /* Change internal hardware path(DM_CON/DP_CON, VBUSIN) */
425+ ret = sm5502_muic_set_path (info , con_sw , vbus_sw , attached );
426+ if (ret < 0 )
427+ return ret ;
428+
429+ /* Change the state of external accessory */
362430 extcon_set_cable_state (info -> edev , cable_names [idx ], attached );
363431
364432 return 0 ;
0 commit comments