@@ -137,7 +137,6 @@ enum uhc_dwc2_ctrl_stage {
137137struct uhc_dwc2_chan {
138138 /* XFER queuing related */
139139 sys_dlist_t xfer_pending_list ;
140- /* TODO: Lists of pending and done? */
141140 int num_xfer_pending ;
142141 int num_xfer_done ;
143142 /* Pointer to the transfer associated with the buffer */
@@ -189,12 +188,12 @@ struct uhc_dwc2_chan {
189188 uint8_t active : 1 ;
190189 /* Halt has been requested */
191190 uint8_t halt_requested : 1 ;
191+ /* TODO: Lists of pending and done? */
192192 /* TODO: Add channel error? */
193193};
194194
195195struct uhc_dwc2_data {
196196 struct k_sem irq_sem ;
197- /* TODO: spinlock? */
198197 struct k_thread thread_data ;
199198 /* Mutex for port access */
200199 struct k_mutex mutex ;
@@ -227,6 +226,7 @@ struct uhc_dwc2_data {
227226 /* TODO: Dynamic chan allocation on enqueue? */
228227 /* TODO: FRAME LIST? */
229228 /* TODO: Pipes/channels LIST? */
229+ /* TODO: spinlock? */
230230};
231231
232232/* Host channel registers address */
@@ -262,18 +262,18 @@ struct uhc_dwc2_data {
262262 */
263263
264264/* Programming Guide 2.1.2 FIFO RAM allocation
265- * RX
265+ *
266+ * RX:
266267 * - Largest-EPsize/4 + 2 (status info). recommended x2 if high bandwidth or multiple ISO are used.
267268 * - 2 for transfer complete and channel halted status
268269 * - 1 for each Control/Bulk out endpoint to Handle NAK/NYET (i.e max is number of host channel)
269270 *
270- * TX non-periodic (NPTX)
271+ * TX non-periodic (NPTX):
271272 * - At least largest-EPsize/4, recommended x2
272273 *
273- *
274- config-> * TX periodic (PTX)
275- * - At least largest-EPsize*MulCount/4 (MulCount up to 3 for high-bandwidth ISO/interrupt)
276- */
274+ * TX periodic (PTX):
275+ * - At least largest-EPsize*MulCount/4 (MulCount up to 3 for high-bandwidth ISO/interrupt)
276+ */
277277
278278enum {
279279 EPSIZE_BULK_FS = 64 ,
@@ -543,22 +543,20 @@ static inline void dwc2_port_enable(const struct device *dev)
543543 hcfg &= ~USB_DWC2_HCFG_PERSCHEDENA ;
544544
545545 if (UHC_DWC2_HSPHYTYPE (config ) == 0 ) {
546- /*
547- Indicate to the OTG core what speed the PHY clock is at
548- Note: FSLS PHY has an implicit 8 divider applied when in LS mode,
549- so the values of FSLSPclkSel and FrInt have to be adjusted accordingly.
550- */
546+ /* Indicate to the OTG core what speed the PHY clock is at
547+ * Note: FSLS PHY has an implicit 8 divider applied when in LS mode,
548+ * so the values of FSLSPclkSel and FrInt have to be adjusted accordingly.
549+ */
551550 uint8_t fslspclksel = (speed == UHC_DWC2_SPEED_FULL ) ? 1 : 2 ;
552551 hcfg &= ~USB_DWC2_HCFG_FSLSPCLKSEL_MASK ;
553552 hcfg |= (fslspclksel << USB_DWC2_HCFG_FSLSPCLKSEL_POS );
554553
555554 /* Disable dynamic loading */
556555 hfir &= ~USB_DWC2_HFIR_HFIRRLDCTRL ;
557- /*
558- Set frame interval to be equal to 1ms
559- Note: FSLS PHY has an implicit 8 divider applied when in LS mode,
560- so the values of FSLSPclkSel and FrInt have to be adjusted accordingly.
561- */
556+ /* Set frame interval to be equal to 1ms
557+ * Note: FSLS PHY has an implicit 8 divider applied when in LS mode,
558+ * so the values of FSLSPclkSel and FrInt have to be adjusted accordingly.
559+ */
562560 uint16_t frint = (speed == UHC_DWC2_SPEED_FULL ) ? 48000 : 6000 ;
563561 hfir &= ~USB_DWC2_HFIR_FRINT_MASK ;
564562 hfir |= (frint << USB_DWC2_HFIR_FRINT_POS );
@@ -702,7 +700,8 @@ static enum uhc_port_event uhc_dwc2_decode_hprt(const struct device *dev,
702700 if (priv -> port_state != UHC_PORT_STATE_RESETTING ) {
703701 if (priv -> waiting_disable ) {
704702 /* Disabled by request (i.e. by port command). Generate an internal
705- * event */
703+ * event
704+ */
706705 priv -> port_state = UHC_PORT_STATE_DISABLED ;
707706 priv -> waiting_disable = 0 ;
708707 /* TODO: Notify the port event from ISR */
@@ -721,8 +720,7 @@ static enum uhc_port_event uhc_dwc2_decode_hprt(const struct device *dev,
721720 case UHC_DWC2_CORE_EVENT_OVRCUR_CLR : {
722721 /* TODO: Handle overcurrent event */
723722
724- /*
725- * If port state powered, we need to power it off to protect it
723+ /* If port state powered, we need to power it off to protect it
726724 * change port state to recovery
727725 * generate port event UHC_PORT_EVENT_OVERCURRENT
728726 * disable the flag conn_dev_ena
@@ -1005,8 +1003,8 @@ static void IRAM_ATTR _buffer_exec_proceed(const struct device *dev, struct uhc_
10051003 /* TODO: Check if the buffer is large enough for the next transfer? */
10061004
10071005 /* TODO: Check that the buffer is DMA and CACHE aligned and compatible with
1008- * the DMA */
1009- /* (better to do this on enqueue) */
1006+ * the DMA (better to do this on enqueue)
1007+ */
10101008
10111009 if (xfer -> buf != NULL ) {
10121010 /* Get the tail of the buffer to append data */
@@ -1015,8 +1013,10 @@ static void IRAM_ATTR _buffer_exec_proceed(const struct device *dev, struct uhc_
10151013 net_buf_add (xfer -> buf , size );
10161014 }
10171015 }
1018- } else { /* cur_stg == 1. Just finished data stage. Go to status stage */
1019- /* Status stage is always the opposite direction of data stage */
1016+ } else {
1017+ /* cur_stg == 1. Just finished data stage. Go to status stage
1018+ * Status stage is always the opposite direction of data stage
1019+ */
10201020 next_dir_is_in = !chan -> data_stg_in ;
10211021 next_pid = CTRL_STAGE_DATA1 ; /* Status stage always has a PID of DATA1 */
10221022 chan -> cur_stg = 2 ;
@@ -1070,7 +1070,7 @@ static inline bool _buffer_can_exec(struct uhc_dwc2_chan *chan)
10701070}
10711071
10721072/*
1073- * Decode a channel interrupt and take appropriate action
1073+ * Decode a channel interrupt and take appropriate action.
10741074 * Interrupt context.
10751075 */
10761076static enum uhc_dwc2_chan_event uhc_dwc2_decode_chan (const struct device * dev ,
@@ -1191,7 +1191,8 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
11911191 k_event_post (& priv -> drv_evt , BIT (UHC_DWC2_EVENT_CHAN ));
11921192 }
11931193 /* Check for more channels with pending interrupts. Returns NULL if there
1194- * are no more */
1194+ * are no more
1195+ */
11951196 chan = uhc_dwc2_get_chan_pending_intr (dev );
11961197 }
11971198 } else {
@@ -1274,10 +1275,12 @@ static inline enum uhc_port_event uhc_dwc2_get_port_event(const struct device *d
12741275 return ret ;
12751276}
12761277
1278+ /*
1279+ * Flush the channel EP characteristic
1280+ */
12771281static inline void uhc_dwc2_flush_chans (const struct device * dev )
12781282{
12791283 /* TODO: For each chan, reinitialize the channel with EP characteristics */
1280- /* Flush the channel EP characteristics */
12811284 /* TODO: Sync CACHE */
12821285}
12831286
@@ -1323,26 +1326,23 @@ static inline int uhc_dwc2_port_reset(const struct device *dev)
13231326
13241327 int ret ;
13251328
1326- /* Enter critical section */
13271329 unsigned int key = irq_lock ();
13281330
13291331 /* TODO: implement port checks */
13301332
1331- /*
1332- * Hint:
1333+ /* Hint:
13331334 * Port can only a reset when it is in the enabled or disabled (in the case of a new
13341335 * connection) states. priv->port_state == UHC_PORT_STATE_ENABLED;
13351336 * priv->port_state == UHC_PORT_STATE_DISABLED;
13361337 * priv->num_channels_chans_queued == 0
13371338 */
13381339
1339- /*
1340- Proceed to resetting the bus:
1341- - Update the port's state variable
1342- - Hold the bus in the reset state for RESET_HOLD_MS.
1343- - Return the bus to the idle state for RESET_RECOVERY_MS
1344- During this reset the port state should be set to RESETTING and do not change.
1345- */
1340+ /* Proceed to resetting the bus:
1341+ * - Update the port's state variable
1342+ * - Hold the bus in the reset state for RESET_HOLD_MS.
1343+ * - Return the bus to the idle state for RESET_RECOVERY_MS
1344+ * During this reset the port state should be set to RESETTING and do not change.
1345+ */
13461346 priv -> port_state = UHC_PORT_STATE_RESETTING ;
13471347 dwc2_hal_toggle_reset (dwc2 , true);
13481348
@@ -1398,8 +1398,10 @@ static inline int uhc_dwc2_port_recovery(const struct device *dev)
13981398 int ret ;
13991399
14001400 /* TODO: Implement port checks */
1401- /* Port should be in recovery state and no ongoing transfers */
1402- /* Port flags should be 0 */
1401+
1402+ /* Port should be in recovery state and no ongoing transfers
1403+ * Port flags should be 0
1404+ */
14031405
14041406 /* TODO: enter critical section */
14051407 ret = uhc_dwc2_quirk_irq_disable_func (dev );
@@ -1528,6 +1530,7 @@ static inline int uhc_dwc2_chan_config(const struct device *dev, uint8_t chan_id
15281530 /* TODO: sync CACHE */
15291531
15301532 /* TODO: Add the chan to the list of idle chans in the port object */
1533+
15311534 sys_dlist_init (& chan -> xfer_pending_list );
15321535 priv -> num_chans_idle ++ ;
15331536
@@ -1791,7 +1794,9 @@ static int uhc_dwc2_bus_reset(const struct device *dev)
17911794{
17921795 /* TODO: move the reset logic here */
17931796
1794- /* Hint: First reset is done by the uhc dwc2 driver, so we don't need to do anything here */
1797+ /* Hint:
1798+ * First reset is done by the uhc dwc2 driver, so we don't need to do anything here.
1799+ */
17951800 uhc_submit_event (dev , UHC_EVT_RESETED , 0 );
17961801 return 0 ;
17971802}
0 commit comments