@@ -181,8 +181,6 @@ struct wcd939x_priv {
181
181
/* typec handling */
182
182
bool typec_analog_mux ;
183
183
#if IS_ENABLED (CONFIG_TYPEC )
184
- struct typec_mux_dev * typec_mux ;
185
- struct typec_switch_dev * typec_sw ;
186
184
enum typec_orientation typec_orientation ;
187
185
unsigned long typec_mode ;
188
186
struct typec_switch * typec_switch ;
@@ -3519,6 +3517,68 @@ static const struct component_master_ops wcd939x_comp_ops = {
3519
3517
.unbind = wcd939x_unbind ,
3520
3518
};
3521
3519
3520
+ static void __maybe_unused wcd939x_typec_mux_unregister (void * data )
3521
+ {
3522
+ struct typec_mux_dev * typec_mux = data ;
3523
+
3524
+ typec_mux_unregister (typec_mux );
3525
+ }
3526
+
3527
+ static void __maybe_unused wcd939x_typec_switch_unregister (void * data )
3528
+ {
3529
+ struct typec_switch_dev * typec_sw = data ;
3530
+
3531
+ typec_switch_unregister (typec_sw );
3532
+ }
3533
+
3534
+ static int wcd939x_add_typec (struct wcd939x_priv * wcd939x , struct device * dev )
3535
+ {
3536
+ #if IS_ENABLED (CONFIG_TYPEC )
3537
+ int ret ;
3538
+ struct typec_mux_dev * typec_mux ;
3539
+ struct typec_switch_dev * typec_sw ;
3540
+ struct typec_mux_desc mux_desc = {
3541
+ .drvdata = wcd939x ,
3542
+ .fwnode = dev_fwnode (dev ),
3543
+ .set = wcd939x_typec_mux_set ,
3544
+ };
3545
+ struct typec_switch_desc sw_desc = {
3546
+ .drvdata = wcd939x ,
3547
+ .fwnode = dev_fwnode (dev ),
3548
+ .set = wcd939x_typec_switch_set ,
3549
+ };
3550
+
3551
+ /*
3552
+ * Is USBSS is used to mux analog lines,
3553
+ * register a typec mux/switch to get typec events
3554
+ */
3555
+ if (!wcd939x -> typec_analog_mux )
3556
+ return 0 ;
3557
+
3558
+ typec_mux = typec_mux_register (dev , & mux_desc );
3559
+ if (IS_ERR (typec_mux ))
3560
+ return dev_err_probe (dev , PTR_ERR (typec_mux ),
3561
+ "failed to register typec mux\n" );
3562
+
3563
+ ret = devm_add_action_or_reset (dev , wcd939x_typec_mux_unregister ,
3564
+ typec_mux );
3565
+ if (ret )
3566
+ return ret ;
3567
+
3568
+ typec_sw = typec_switch_register (dev , & sw_desc );
3569
+ if (IS_ERR (typec_sw ))
3570
+ return dev_err_probe (dev , PTR_ERR (typec_sw ),
3571
+ "failed to register typec switch\n" );
3572
+
3573
+ ret = devm_add_action_or_reset (dev , wcd939x_typec_switch_unregister ,
3574
+ typec_sw );
3575
+ if (ret )
3576
+ return ret ;
3577
+ #endif
3578
+
3579
+ return 0 ;
3580
+ }
3581
+
3522
3582
static int wcd939x_add_slave_components (struct wcd939x_priv * wcd939x ,
3523
3583
struct device * dev ,
3524
3584
struct component_match * * matchptr )
@@ -3567,42 +3627,13 @@ static int wcd939x_probe(struct platform_device *pdev)
3567
3627
return - EINVAL ;
3568
3628
}
3569
3629
3570
- #if IS_ENABLED (CONFIG_TYPEC )
3571
- /*
3572
- * Is USBSS is used to mux analog lines,
3573
- * register a typec mux/switch to get typec events
3574
- */
3575
- if (wcd939x -> typec_analog_mux ) {
3576
- struct typec_mux_desc mux_desc = {
3577
- .drvdata = wcd939x ,
3578
- .fwnode = dev_fwnode (dev ),
3579
- .set = wcd939x_typec_mux_set ,
3580
- };
3581
- struct typec_switch_desc sw_desc = {
3582
- .drvdata = wcd939x ,
3583
- .fwnode = dev_fwnode (dev ),
3584
- .set = wcd939x_typec_switch_set ,
3585
- };
3586
-
3587
- wcd939x -> typec_mux = typec_mux_register (dev , & mux_desc );
3588
- if (IS_ERR (wcd939x -> typec_mux )) {
3589
- ret = dev_err_probe (dev , PTR_ERR (wcd939x -> typec_mux ),
3590
- "failed to register typec mux\n" );
3591
- goto err_disable_regulators ;
3592
- }
3593
-
3594
- wcd939x -> typec_sw = typec_switch_register (dev , & sw_desc );
3595
- if (IS_ERR (wcd939x -> typec_sw )) {
3596
- ret = dev_err_probe (dev , PTR_ERR (wcd939x -> typec_sw ),
3597
- "failed to register typec switch\n" );
3598
- goto err_unregister_typec_mux ;
3599
- }
3600
- }
3601
- #endif /* CONFIG_TYPEC */
3630
+ ret = wcd939x_add_typec (wcd939x , dev );
3631
+ if (ret )
3632
+ goto err_disable_regulators ;
3602
3633
3603
3634
ret = wcd939x_add_slave_components (wcd939x , dev , & match );
3604
3635
if (ret )
3605
- goto err_unregister_typec_switch ;
3636
+ goto err_disable_regulators ;
3606
3637
3607
3638
wcd939x_reset (wcd939x );
3608
3639
@@ -3619,18 +3650,6 @@ static int wcd939x_probe(struct platform_device *pdev)
3619
3650
3620
3651
return 0 ;
3621
3652
3622
- #if IS_ENABLED (CONFIG_TYPEC )
3623
- err_unregister_typec_mux :
3624
- if (wcd939x -> typec_analog_mux )
3625
- typec_mux_unregister (wcd939x -> typec_mux );
3626
- #endif /* CONFIG_TYPEC */
3627
-
3628
- err_unregister_typec_switch :
3629
- #if IS_ENABLED (CONFIG_TYPEC )
3630
- if (wcd939x -> typec_analog_mux )
3631
- typec_switch_unregister (wcd939x -> typec_sw );
3632
- #endif /* CONFIG_TYPEC */
3633
-
3634
3653
err_disable_regulators :
3635
3654
regulator_bulk_disable (WCD939X_MAX_SUPPLY , wcd939x -> supplies );
3636
3655
regulator_bulk_free (WCD939X_MAX_SUPPLY , wcd939x -> supplies );
0 commit comments