@@ -77,7 +77,7 @@ static const struct software_node max17047_node = {
7777 * software node.
7878 */
7979static struct software_node_ref_args fusb302_mux_refs [] = {
80- { . node = NULL } ,
80+ SOFTWARE_NODE_REFERENCE ( NULL ) ,
8181};
8282
8383static const struct property_entry fusb302_properties [] = {
@@ -190,19 +190,22 @@ static void cht_int33fe_remove_nodes(struct cht_int33fe_data *data)
190190{
191191 software_node_unregister_node_group (node_group );
192192
193- if (fusb302_mux_refs [0 ].node ) {
194- fwnode_handle_put (software_node_fwnode (fusb302_mux_refs [0 ].node ));
195- fusb302_mux_refs [0 ].node = NULL ;
196- }
197-
198193 if (data -> dp ) {
199194 data -> dp -> secondary = NULL ;
200195 fwnode_handle_put (data -> dp );
201196 data -> dp = NULL ;
202197 }
203198}
204199
205- static int cht_int33fe_add_nodes (struct cht_int33fe_data * data )
200+ static void cht_int33fe_put_swnode (void * data )
201+ {
202+ struct fwnode_handle * fwnode = data ;
203+
204+ fwnode_handle_put (fwnode );
205+ fusb302_mux_refs [0 ] = SOFTWARE_NODE_REFERENCE (NULL );
206+ }
207+
208+ static int cht_int33fe_add_nodes (struct device * dev , struct cht_int33fe_data * data )
206209{
207210 const struct software_node * mux_ref_node ;
208211 int ret ;
@@ -212,17 +215,25 @@ static int cht_int33fe_add_nodes(struct cht_int33fe_data *data)
212215 * until the mux driver has created software node for the mux device.
213216 * It means we depend on the mux driver. This function will return
214217 * -EPROBE_DEFER until the mux device is registered.
218+ *
219+ * FIXME: the relevant software node exists in intel-xhci-usb-role-switch
220+ * and - if exported - could be used to set up a static reference.
215221 */
216222 mux_ref_node = software_node_find_by_name (NULL , "intel-xhci-usb-sw" );
217223 if (!mux_ref_node )
218224 return - EPROBE_DEFER ;
219225
226+ ret = devm_add_action_or_reset (dev , cht_int33fe_put_swnode ,
227+ software_node_fwnode (mux_ref_node ));
228+ if (ret )
229+ return ret ;
230+
220231 /*
221232 * Update node used in "usb-role-switch" property. Note that we
222233 * rely on software_node_register_node_group() to use the original
223234 * instance of properties instead of copying them.
224235 */
225- fusb302_mux_refs [0 ]. node = mux_ref_node ;
236+ fusb302_mux_refs [0 ] = SOFTWARE_NODE_REFERENCE ( mux_ref_node ) ;
226237
227238 ret = software_node_register_node_group (node_group );
228239 if (ret )
@@ -345,7 +356,7 @@ static int cht_int33fe_typec_probe(struct platform_device *pdev)
345356 return fusb302_irq ;
346357 }
347358
348- ret = cht_int33fe_add_nodes (data );
359+ ret = cht_int33fe_add_nodes (dev , data );
349360 if (ret )
350361 return ret ;
351362
0 commit comments