@@ -222,6 +222,32 @@ static int jesd204_fsm_propagate_cb_outputs(struct jesd204_dev *jdev,
222222 return ret ;
223223}
224224
225+ static int jesd204_fsm_propagate_cb_top_level (struct jesd204_dev * jdev ,
226+ struct jesd204_fsm_data * fsm_data )
227+ {
228+ unsigned int i ;
229+ int ret ;
230+
231+ if (fsm_data -> link_idx != JESD204_LINKS_ALL )
232+ return jesd204_fsm_handle_con_cb (jdev , NULL ,
233+ fsm_data -> link_idx ,
234+ fsm_data );
235+
236+ /*
237+ * FIXME: think of a better way to iterate the top-level device callback here.
238+ * for now this works; and is slightly cleaner than before
239+ */
240+ jdev = & fsm_data -> jdev_top -> jdev ;
241+ for (i = 0 ; i < fsm_data -> jdev_top -> num_links ; i ++ ) {
242+ ret = jesd204_fsm_handle_con_cb (jdev , NULL , i , fsm_data );
243+ if (ret )
244+ break ;
245+ }
246+ /* FIXME: error message here? */
247+
248+ return ret ;
249+ }
250+
225251static int jesd204_fsm_propagate_cb (struct jesd204_dev * jdev ,
226252 struct jesd204_fsm_data * data )
227253{
@@ -237,8 +263,7 @@ static int jesd204_fsm_propagate_cb(struct jesd204_dev *jdev,
237263 if (ret )
238264 goto out ;
239265
240- ret = jesd204_fsm_handle_con_cb (jdev , NULL , JESD204_LINKS_ALL , data );
241- /* FIXME: error message here? */
266+ ret = jesd204_fsm_propagate_cb_top_level (jdev , data );
242267out :
243268 return ret ;
244269}
@@ -375,10 +400,10 @@ static int jesd204_con_validate_cur_state(struct jesd204_dev *jdev,
375400 if (fsm_data -> cur_state == JESD204_STATE_DONT_CARE )
376401 return 0 ;
377402
378- if (c && c -> state == fsm_data -> nxt_state )
403+ if (c -> state == fsm_data -> nxt_state )
379404 return 0 ;
380405
381- if (c && fsm_data -> cur_state != c -> state ) {
406+ if (fsm_data -> cur_state != c -> state ) {
382407 ol = & fsm_data -> jdev_top -> active_links [c -> link_idx ];
383408 dev_warn (& jdev -> dev ,
384409 "JESD204 link[%d] invalid connection state: %s, exp: %s, nxt: %s\n" ,
@@ -425,15 +450,14 @@ static int jesd204_fsm_handle_con(struct jesd204_dev *jdev,
425450 struct jesd204_fsm_data * fsm_data )
426451{
427452 struct jesd204_dev_top * jdev_top ;
428- struct jesd204_link_opaque * ol ;
429453 unsigned int link_idx ;
430454 int ret ;
431455
432456 if (!fsm_data -> fsm_change_cb )
433457 return 0 ;
434458
435459 /* if this transitioned already, we're done */
436- if (con && con -> state == fsm_data -> nxt_state )
460+ if (con -> state == fsm_data -> nxt_state )
437461 return 0 ;
438462
439463 ret = jesd204_con_validate_cur_state (jdev , con , fsm_data );
@@ -442,7 +466,7 @@ static int jesd204_fsm_handle_con(struct jesd204_dev *jdev,
442466
443467 jdev_top = fsm_data -> jdev_top ;
444468
445- if (con && jdev_top -> initialized && con -> link_idx == JESD204_LINKS_ALL ) {
469+ if (jdev_top -> initialized && con -> link_idx == JESD204_LINKS_ALL ) {
446470 dev_err (& jdev -> dev , "Uninitialized connection in topology\n" );
447471 return - EINVAL ;
448472 }
@@ -451,21 +475,20 @@ static int jesd204_fsm_handle_con(struct jesd204_dev *jdev,
451475 fsm_data -> link_idx != con -> link_idx )
452476 return 0 ;
453477
454- if (con && con -> link_idx != JESD204_LINKS_ALL )
478+ if (con -> link_idx != JESD204_LINKS_ALL )
455479 return jesd204_fsm_handle_con_cb (jdev , con , con -> link_idx ,
456480 fsm_data );
457481
458- /* FIXME: this implies top-level device ; see about making this better logic; same as Point1 */
459- if (!con ) {
460- return jesd204_fsm_handle_con_cb (jdev , NULL , con -> link_idx , fsm_data );
461- }
462-
463482 if (jdev_top -> initialized )
464483 return 0 ;
465484
466- /* FIXME: make this better; same as Point1 */
485+ /**
486+ * At this point, the connections don't have initialized link indexes
487+ * so they don't know to which JESD204 link they belong to.
488+ * So, we initialize then here; this is a special case,
489+ * we are running jesd204_dev_initialize_cb()
490+ */
467491 for (link_idx = 0 ; link_idx < jdev_top -> num_links ; link_idx ++ ) {
468- ol = & jdev_top -> active_links [link_idx ];
469492 ret = jesd204_fsm_handle_con_cb (jdev , con , link_idx , fsm_data );
470493 if (ret < 0 )
471494 return ret ;
@@ -825,50 +848,38 @@ int jesd204_fsm_start(struct jesd204_dev *jdev, unsigned int link_idx)
825848}
826849EXPORT_SYMBOL_GPL (jesd204_fsm_start );
827850
828- static int jesd204_fsm_table_entry_cb (struct jesd204_dev * jdev ,
829- struct jesd204_dev_con_out * con ,
830- unsigned int link_idx ,
831- struct jesd204_fsm_data * fsm_data )
851+ static int jesd204_fsm_table_link_op_cb (struct jesd204_dev * jdev ,
852+ const struct jesd204_state_ops * state_op ,
853+ unsigned int link_idx ,
854+ struct jesd204_fsm_data * fsm_data )
832855{
833- struct jesd204_fsm_table_entry_iter * it = fsm_data -> cb_data ;
834- struct jesd204_dev_top * jdev_top ;
835856 struct jesd204_link_opaque * ol ;
836857 jesd204_link_cb link_op ;
837- int ret , ret1 ;
838-
839- if (!jdev -> state_ops )
840- return JESD204_STATE_CHANGE_DONE ;
841858
842- link_op = jdev -> state_ops [ it -> table [ 0 ]. op ]. per_link ;
859+ link_op = state_op -> per_link ;
843860 if (!link_op )
844861 return JESD204_STATE_CHANGE_DONE ;
845862
846863 ol = & fsm_data -> jdev_top -> active_links [link_idx ];
847864
848- if (con )
849- return link_op (jdev , con -> link_idx , & ol -> link );
850-
851- /* From here-on it's assumed that this is called for the top-level device */
865+ return link_op (jdev , link_idx , & ol -> link );
866+ }
852867
853- jdev_top = fsm_data -> jdev_top ;
854- link_idx = fsm_data -> link_idx ;
868+ static int jesd204_fsm_table_entry_cb (struct jesd204_dev * jdev ,
869+ struct jesd204_dev_con_out * con ,
870+ unsigned int link_idx ,
871+ struct jesd204_fsm_data * fsm_data )
872+ {
873+ struct jesd204_fsm_table_entry_iter * it = fsm_data -> cb_data ;
874+ const struct jesd204_state_ops * state_op ;
855875
856- if (link_idx != JESD204_LINKS_ALL ) {
857- ol = & jdev_top -> active_links [link_idx ];
858- return link_op (jdev , link_idx , & ol -> link );
859- }
876+ if (!jdev -> state_ops )
877+ return JESD204_STATE_CHANGE_DONE ;
860878
861- ret1 = JESD204_STATE_CHANGE_DONE ;
862- for (link_idx = 0 ; link_idx < jdev_top -> num_links ; link_idx ++ ) {
863- ol = & jdev_top -> active_links [link_idx ];
864- ret = link_op (jdev , link_idx , & ol -> link );
865- if (ret < 0 )
866- return ret ;
867- if (ret == JESD204_STATE_CHANGE_DEFER )
868- ret1 = JESD204_STATE_CHANGE_DEFER ;
869- }
879+ state_op = & jdev -> state_ops [it -> table [0 ].op ];
870880
871- return ret1 ;
881+ return jesd204_fsm_table_link_op_cb (jdev , state_op , link_idx ,
882+ fsm_data );
872883}
873884
874885static int jesd204_fsm_table_entry_done (struct jesd204_dev * jdev ,
0 commit comments