1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2017-2022, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Description:
8  *     XRP7724 driver (aka Juno PMIC)
9  */
10 
11 #ifndef MOD_JUNO_XRP7724_H
12 #define MOD_JUNO_XRP7724_H
13 
14 #include <fwk_id.h>
15 #include <fwk_module_idx.h>
16 
17 #include <stdint.h>
18 
19 /*!
20  * \ingroup GroupJunoModule
21  *
22  * \defgroup GroupXRP7724 XRP7724 Driver
23  * \{
24  */
25 
26 /*!
27  * \brief Module configuration.
28  */
29 struct mod_juno_xrp7724_config {
30     /*! Target address of the I2C device */
31     unsigned int target_address;
32 
33     /*! Identifier of the I2C HAL */
34     fwk_id_t i2c_hal_id;
35 
36     /*! Identifier of the timer */
37     fwk_id_t timer_hal_id;
38 
39     /*! Identifier of the GPIO for the assert command */
40     fwk_id_t gpio_assert_id;
41 
42     /*! Identifier of the GPIO for the system mode selection */
43     fwk_id_t gpio_mode_id;
44 };
45 
46 /*!
47  * \brief Element type.
48  */
49 enum mod_juno_xrp7724_element_type {
50     MOD_JUNO_XRP7724_ELEMENT_TYPE_GPIO,
51     MOD_JUNO_XRP7724_ELEMENT_TYPE_SENSOR,
52     MOD_JUNO_XRP7724_ELEMENT_TYPE_PSU,
53     MOD_JUNO_XRP7724_ELEMENT_TYPE_COUNT,
54 };
55 
56 /*!
57  * \brief Element configuration
58  */
59 struct mod_juno_xrp7724_dev_config {
60     /*! Identifier of the element for the driver response */
61     fwk_id_t driver_response_id;
62 
63     /*! Identifier of the driver response API */
64     fwk_id_t driver_response_api_id;
65 
66     /*!
67      * \brief Identifier of the ADC sensor associated with the PSU channel.
68      *
69      * \note Only provided for a PSU element
70      */
71     fwk_id_t psu_adc_id;
72 
73     /*!
74      * \brief Index of the bus associated to the PSU.
75      *
76      * \note Only provided for a PSU element
77      */
78     uint8_t psu_bus_idx;
79 
80     /*!
81      * \brief Sensor information
82      *
83      * \note Only provided for a sensor element
84      */
85     struct mod_sensor_info *sensor_info;
86 
87     /*! Element type */
88     enum mod_juno_xrp7724_element_type type;
89 
90     /*!
91      * \brief Identifier of the alarm.
92      *
93      * \note  When setting the voltage, it is necessary to wait for the PSU to
94      * \note  stabilize at the new voltage. We use the Timer HAL to insert a
95      * \note  short delay for this.
96      */
97     fwk_id_t alarm_hal_id;
98 };
99 
100 /*! API for system mode */
101 struct mod_juno_xrp7724_api_system_mode {
102     /*!
103      * \brief Perform a shutdown.
104      *
105      * \details When the function returns the request may not be completed.
106      *      When the operation has successfully finished, no response will be
107      *      returned to caller since the hardware will be entirely turned off.
108      *      The caller may get a response through an event in case the request
109      *      failed.
110      *
111      * \retval ::FWK_PENDING The request was submitted, not yet completed.
112      * \return One of the standard framework error codes.
113      */
114     int (*shutdown)(void);
115 
116     /*!
117      * \brief Perform a cold reset.
118      *
119      * \details When the function returns the request may not be completed.
120      *      When the operation has successfully finished, no response will be
121      *      returned to caller since the hardware will be restarted.
122      *      The caller may get a response through an event in case the request
123      *      failed.
124 
125      * \retval ::FWK_PENDING The request was submitted, not yet completed.
126      * \return One of the standard framework error codes.
127      */
128     int (*reset)(void);
129 };
130 
131 /*! Index of the available APIs */
132 enum mod_juno_xrp7724_api_idx {
133     MOD_JUNO_XRP7724_API_IDX_SENSOR,
134     MOD_JUNO_XRP7724_API_IDX_SYSTEM_MODE,
135     MOD_JUNO_XRP7724_API_IDX_PSU,
136     MOD_JUNO_XRP7724_API_IDX_COUNT,
137 };
138 
139 /*! Identifier of the system mode API */
140 static const fwk_id_t mod_juno_xrp7724_api_id_system_mode = FWK_ID_API_INIT(
141     FWK_MODULE_IDX_JUNO_XRP7724, MOD_JUNO_XRP7724_API_IDX_SYSTEM_MODE);
142 
143 /*! Identifier of the sensor driver API */
144 static const fwk_id_t mod_juno_xrp7724_api_id_sensor = FWK_ID_API_INIT(
145     FWK_MODULE_IDX_JUNO_XRP7724, MOD_JUNO_XRP7724_API_IDX_SENSOR);
146 
147 /*! Identifier of the PSU driver API */
148 static const fwk_id_t mod_juno_xrp7724_api_id_psu = FWK_ID_API_INIT(
149     FWK_MODULE_IDX_JUNO_XRP7724, MOD_JUNO_XRP7724_API_IDX_PSU);
150 
151 /*!
152  * \}
153  */
154 
155 #endif /* MOD_JUNO_XRP7724_H */
156