1 /*******************************************************************************
2  * Copyright 2019-2020 Microchip FPGA Embedded Systems Solutions.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * PolarFire SoC MSS USB Driver Stack
7  *      USB Core Interface Layer (USB-CIFL)
8  *          USBD-CIF
9  *
10  *  This file provides interfaces to perform register and register bit level
11  *  read / write operations in USB Device mode.
12  *
13  */
14 
15 #ifndef __MSS_USB_DEVICE_REG_IO_H_
16 #define __MSS_USB_DEVICE_REG_IO_H_
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include "mss_usb_core_regs.h"
23 
24 
25 /*******************************************************************************
26 * Device mode functions
27 */
28 
29 /*******************************************************************************
30  * POWER register related APIs
31  */
32 /*lint -e20 -e522 -e10 -e40 -e63 -e35 -e26 -e78*/
33 static __INLINE uint8_t
MSS_USBD_CIF_is_suspend_mode(void)34 MSS_USBD_CIF_is_suspend_mode
35 (
36     void
37 )
38 {
39     return(((USB->POWER & POWER_REG_SUSPEND_MODE_MASK) ?
40             MSS_USB_BOOLEAN_TRUE : MSS_USB_BOOLEAN_FALSE));
41 }
42 
43 /*To force out of the Suspend while in Device mode.*/
44 static __INLINE void
MSS_USBD_CIF_resume_gen(void)45 MSS_USBD_CIF_resume_gen
46 (
47     void
48 )
49 {
50     USB->POWER |= POWER_REG_RESUME_SIGNAL_MASK;
51     /*clear after 10ms*/
52 }
53 
54 /*******************************************************************************
55  * DEVCTL register related APIs
56  */
57 static __INLINE uint8_t
MSS_USB_OTG_is_session_on(void)58 MSS_USB_OTG_is_session_on
59 (
60     void
61 )
62 {
63     return (((USB->DEV_CTRL & DEV_CTRL_SESSION_MASK) ?
64             MSS_USB_BOOLEAN_TRUE : MSS_USB_BOOLEAN_FALSE));
65 }
66 
67 static __INLINE void
MSS_USB_OTG_initiate_srp(void)68 MSS_USB_OTG_initiate_srp
69 (
70     void
71 )
72 {
73     /*
74     TODO:make sure that the device is suspended and is a B-device when this
75     function is called
76     */
77     USB->DEV_CTRL |= DEV_CTRL_SESSION_MASK;
78 }
79 
80 static __INLINE void
MSS_USB_OTG_initiate_hnp(void)81 MSS_USB_OTG_initiate_hnp
82 (
83     void
84 )
85 {
86     /*TODO:make sure that the device is B-device when this function is called*/
87     USB->DEV_CTRL |= DEV_CTRL_HOST_REQ_MASK;
88 }
89 
90 /*lint -restore */
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 #endif  /* __MSS_USB_DEVICE_REG_IO_H_ */
96