b078dff88382963201e303229b78fa5cba2561c9
[deb_dpdk.git] / drivers / bus / fslmc / mc / dpcon.c
1 /* Copyright 2013-2016 Freescale Semiconductor Inc.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are met:
5  * * Redistributions of source code must retain the above copyright
6  * notice, this list of conditions and the following disclaimer.
7  * * Redistributions in binary form must reproduce the above copyright
8  * notice, this list of conditions and the following disclaimer in the
9  * documentation and/or other materials provided with the distribution.
10  * * Neither the name of the above-listed copyright holders nor the
11  * names of any contributors may be used to endorse or promote products
12  * derived from this software without specific prior written permission.
13  *
14  *
15  * ALTERNATIVELY, this software may be distributed under the terms of the
16  * GNU General Public License ("GPL") as published by the Free Software
17  * Foundation, either version 2 of that License or (at your option) any
18  * later version.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 #include <fsl_mc_sys.h>
33 #include <fsl_mc_cmd.h>
34 #include <fsl_dpcon.h>
35 #include <fsl_dpcon_cmd.h>
36
37 int dpcon_open(struct fsl_mc_io *mc_io,
38                uint32_t cmd_flags,
39                int dpcon_id,
40                uint16_t *token)
41 {
42         struct mc_command cmd = { 0 };
43         int err;
44
45         /* prepare command */
46         cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
47                                           cmd_flags,
48                                           0);
49         DPCON_CMD_OPEN(cmd, dpcon_id);
50
51         /* send command to mc*/
52         err = mc_send_command(mc_io, &cmd);
53         if (err)
54                 return err;
55
56         /* retrieve response parameters */
57         *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
58
59         return 0;
60 }
61
62 int dpcon_close(struct fsl_mc_io *mc_io,
63                 uint32_t cmd_flags,
64                 uint16_t token)
65 {
66         struct mc_command cmd = { 0 };
67
68         /* prepare command */
69         cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
70                                           cmd_flags,
71                                           token);
72
73         /* send command to mc*/
74         return mc_send_command(mc_io, &cmd);
75 }
76
77 int dpcon_create(struct fsl_mc_io *mc_io,
78                  uint16_t dprc_token,
79                 uint32_t cmd_flags,
80                 const struct dpcon_cfg *cfg,
81                 uint32_t *obj_id)
82 {
83         struct mc_command cmd = { 0 };
84         int err;
85
86         /* prepare command */
87         cmd.header = mc_encode_cmd_header(DPCON_CMDID_CREATE,
88                                           cmd_flags,
89                                           dprc_token);
90         DPCON_CMD_CREATE(cmd, cfg);
91
92         /* send command to mc*/
93         err = mc_send_command(mc_io, &cmd);
94         if (err)
95                 return err;
96
97         /* retrieve response parameters */
98         CMD_CREATE_RSP_GET_OBJ_ID_PARAM0(cmd, *obj_id);
99
100         return 0;
101 }
102
103 int dpcon_destroy(struct fsl_mc_io *mc_io,
104                   uint16_t dprc_token,
105                 uint32_t cmd_flags,
106                 uint32_t object_id)
107 {
108         struct mc_command cmd = { 0 };
109
110         /* prepare command */
111         cmd.header = mc_encode_cmd_header(DPCON_CMDID_DESTROY,
112                                           cmd_flags,
113                                           dprc_token);
114         /* set object id to destroy */
115         CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, object_id);
116         /* send command to mc*/
117         return mc_send_command(mc_io, &cmd);
118 }
119
120 int dpcon_enable(struct fsl_mc_io *mc_io,
121                  uint32_t cmd_flags,
122                  uint16_t token)
123 {
124         struct mc_command cmd = { 0 };
125
126         /* prepare command */
127         cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
128                                           cmd_flags,
129                                           token);
130
131         /* send command to mc*/
132         return mc_send_command(mc_io, &cmd);
133 }
134
135 int dpcon_disable(struct fsl_mc_io *mc_io,
136                   uint32_t cmd_flags,
137                   uint16_t token)
138 {
139         struct mc_command cmd = { 0 };
140
141         /* prepare command */
142         cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
143                                           cmd_flags,
144                                           token);
145
146         /* send command to mc*/
147         return mc_send_command(mc_io, &cmd);
148 }
149
150 int dpcon_is_enabled(struct fsl_mc_io *mc_io,
151                      uint32_t cmd_flags,
152                      uint16_t token,
153                      int *en)
154 {
155         struct mc_command cmd = { 0 };
156         int err;
157         /* prepare command */
158         cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
159                                           cmd_flags,
160                                           token);
161
162         /* send command to mc*/
163         err = mc_send_command(mc_io, &cmd);
164         if (err)
165                 return err;
166
167         /* retrieve response parameters */
168         DPCON_RSP_IS_ENABLED(cmd, *en);
169
170         return 0;
171 }
172
173 int dpcon_reset(struct fsl_mc_io *mc_io,
174                 uint32_t cmd_flags,
175                 uint16_t token)
176 {
177         struct mc_command cmd = { 0 };
178
179         /* prepare command */
180         cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
181                                           cmd_flags, token);
182
183         /* send command to mc*/
184         return mc_send_command(mc_io, &cmd);
185 }
186
187 int dpcon_get_attributes(struct fsl_mc_io *mc_io,
188                          uint32_t cmd_flags,
189                          uint16_t token,
190                          struct dpcon_attr *attr)
191 {
192         struct mc_command cmd = { 0 };
193         int err;
194
195         /* prepare command */
196         cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
197                                           cmd_flags,
198                                           token);
199
200         /* send command to mc*/
201         err = mc_send_command(mc_io, &cmd);
202         if (err)
203                 return err;
204
205         /* retrieve response parameters */
206         DPCON_RSP_GET_ATTR(cmd, attr);
207
208         return 0;
209 }
210
211 int dpcon_get_api_version(struct fsl_mc_io *mc_io,
212                           uint32_t cmd_flags,
213                            uint16_t *major_ver,
214                            uint16_t *minor_ver)
215 {
216         struct mc_command cmd = { 0 };
217         int err;
218
219         cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
220                                         cmd_flags,
221                                         0);
222
223         err = mc_send_command(mc_io, &cmd);
224         if (err)
225                 return err;
226
227         DPCON_RSP_GET_API_VERSION(cmd, *major_ver, *minor_ver);
228
229         return 0;
230 }