staging: fsl-mc: up-rev dpbp binary interface to v2.0
[firefly-linux-kernel-4.4.55.git] / drivers / staging / fsl-mc / bus / dpbp.c
1 /* Copyright 2013-2014 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 "../include/mc-sys.h"
33 #include "../include/mc-cmd.h"
34 #include "../include/dpbp.h"
35 #include "../include/dpbp-cmd.h"
36
37 int dpbp_open(struct fsl_mc_io *mc_io,
38               uint32_t cmd_flags,
39               int dpbp_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(DPBP_CMDID_OPEN,
47                                           cmd_flags, 0);
48         cmd.params[0] |= mc_enc(0, 32, dpbp_id);
49
50         /* send command to mc*/
51         err = mc_send_command(mc_io, &cmd);
52         if (err)
53                 return err;
54
55         /* retrieve response parameters */
56         *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
57
58         return err;
59 }
60 EXPORT_SYMBOL(dpbp_open);
61
62 int dpbp_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(DPBP_CMDID_CLOSE, cmd_flags,
70                                           token);
71
72         /* send command to mc*/
73         return mc_send_command(mc_io, &cmd);
74 }
75 EXPORT_SYMBOL(dpbp_close);
76
77 int dpbp_create(struct fsl_mc_io *mc_io,
78                 uint32_t cmd_flags,
79                 const struct dpbp_cfg *cfg,
80                 uint16_t *token)
81 {
82         struct mc_command cmd = { 0 };
83         int err;
84
85         (void)(cfg); /* unused */
86
87         /* prepare command */
88         cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
89                                           cmd_flags, 0);
90
91         /* send command to mc*/
92         err = mc_send_command(mc_io, &cmd);
93         if (err)
94                 return err;
95
96         /* retrieve response parameters */
97         *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
98
99         return 0;
100 }
101
102 int dpbp_destroy(struct fsl_mc_io *mc_io,
103                  uint32_t cmd_flags,
104                  uint16_t token)
105 {
106         struct mc_command cmd = { 0 };
107
108         /* prepare command */
109         cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
110                                           cmd_flags, token);
111
112         /* send command to mc*/
113         return mc_send_command(mc_io, &cmd);
114 }
115
116 int dpbp_enable(struct fsl_mc_io *mc_io,
117                 uint32_t cmd_flags,
118                 uint16_t token)
119 {
120         struct mc_command cmd = { 0 };
121
122         /* prepare command */
123         cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
124                                           token);
125
126         /* send command to mc*/
127         return mc_send_command(mc_io, &cmd);
128 }
129 EXPORT_SYMBOL(dpbp_enable);
130
131 int dpbp_disable(struct fsl_mc_io *mc_io,
132                  uint32_t cmd_flags,
133                  uint16_t token)
134 {
135         struct mc_command cmd = { 0 };
136
137         /* prepare command */
138         cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
139                                           cmd_flags, token);
140
141         /* send command to mc*/
142         return mc_send_command(mc_io, &cmd);
143 }
144 EXPORT_SYMBOL(dpbp_disable);
145
146 int dpbp_is_enabled(struct fsl_mc_io *mc_io,
147                     uint32_t cmd_flags,
148                     uint16_t token,
149                     int *en)
150 {
151         struct mc_command cmd = { 0 };
152         int err;
153         /* prepare command */
154         cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, cmd_flags,
155                                           token);
156
157         /* send command to mc*/
158         err = mc_send_command(mc_io, &cmd);
159         if (err)
160                 return err;
161
162         /* retrieve response parameters */
163         *en = (int)mc_dec(cmd.params[0], 0, 1);
164
165         return 0;
166 }
167
168 int dpbp_reset(struct fsl_mc_io *mc_io,
169                uint32_t cmd_flags,
170                uint16_t token)
171 {
172         struct mc_command cmd = { 0 };
173
174         /* prepare command */
175         cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
176                                           cmd_flags, token);
177
178         /* send command to mc*/
179         return mc_send_command(mc_io, &cmd);
180 }
181
182 int dpbp_set_irq(struct fsl_mc_io *mc_io,
183                  uint32_t cmd_flags,
184                  uint16_t token,
185                  uint8_t irq_index,
186                  struct dpbp_irq_cfg *irq_cfg)
187 {
188         struct mc_command cmd = { 0 };
189
190         /* prepare command */
191         cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ,
192                                           cmd_flags, token);
193         cmd.params[0] |= mc_enc(0, 8, irq_index);
194         cmd.params[0] |= mc_enc(32, 32, irq_cfg->val);
195         cmd.params[1] |= mc_enc(0, 64, irq_cfg->addr);
196         cmd.params[2] |= mc_enc(0, 32, irq_cfg->user_irq_id);
197
198         /* send command to mc*/
199         return mc_send_command(mc_io, &cmd);
200 }
201
202 int dpbp_get_irq(struct fsl_mc_io *mc_io,
203                  uint32_t cmd_flags,
204                  uint16_t token,
205                  uint8_t irq_index,
206                  int *type,
207                  struct dpbp_irq_cfg *irq_cfg)
208 {
209         struct mc_command cmd = { 0 };
210         int err;
211
212         /* prepare command */
213         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ,
214                                           cmd_flags, token);
215         cmd.params[0] |= mc_enc(32, 8, irq_index);
216
217         /* send command to mc*/
218         err = mc_send_command(mc_io, &cmd);
219         if (err)
220                 return err;
221
222         /* retrieve response parameters */
223         irq_cfg->val = (uint32_t)mc_dec(cmd.params[0], 0, 32);
224         irq_cfg->addr = (uint64_t)mc_dec(cmd.params[1], 0, 64);
225         irq_cfg->user_irq_id = (int)mc_dec(cmd.params[2], 0, 32);
226         *type = (int)mc_dec(cmd.params[2], 32, 32);
227         return 0;
228 }
229
230 int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
231                         uint32_t cmd_flags,
232                         uint16_t token,
233                         uint8_t irq_index,
234                         uint8_t en)
235 {
236         struct mc_command cmd = { 0 };
237
238         /* prepare command */
239         cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_ENABLE,
240                                           cmd_flags, token);
241         cmd.params[0] |= mc_enc(0, 8, en);
242         cmd.params[0] |= mc_enc(32, 8, irq_index);
243
244         /* send command to mc*/
245         return mc_send_command(mc_io, &cmd);
246 }
247
248 int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
249                         uint32_t cmd_flags,
250                         uint16_t token,
251                         uint8_t irq_index,
252                         uint8_t *en)
253 {
254         struct mc_command cmd = { 0 };
255         int err;
256
257         /* prepare command */
258         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_ENABLE,
259                                           cmd_flags, token);
260         cmd.params[0] |= mc_enc(32, 8, irq_index);
261
262         /* send command to mc*/
263         err = mc_send_command(mc_io, &cmd);
264         if (err)
265                 return err;
266
267         /* retrieve response parameters */
268         *en = (uint8_t)mc_dec(cmd.params[0], 0, 8);
269         return 0;
270 }
271
272 int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
273                       uint32_t cmd_flags,
274                       uint16_t token,
275                       uint8_t irq_index,
276                       uint32_t mask)
277 {
278         struct mc_command cmd = { 0 };
279
280         /* prepare command */
281         cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_MASK,
282                                           cmd_flags, token);
283         cmd.params[0] |= mc_enc(0, 32, mask);
284         cmd.params[0] |= mc_enc(32, 8, irq_index);
285
286         /* send command to mc*/
287         return mc_send_command(mc_io, &cmd);
288 }
289
290 int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
291                       uint32_t cmd_flags,
292                       uint16_t token,
293                       uint8_t irq_index,
294                       uint32_t *mask)
295 {
296         struct mc_command cmd = { 0 };
297         int err;
298
299         /* prepare command */
300         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_MASK,
301                                           cmd_flags, token);
302         cmd.params[0] |= mc_enc(32, 8, irq_index);
303
304         /* send command to mc*/
305         err = mc_send_command(mc_io, &cmd);
306         if (err)
307                 return err;
308
309         /* retrieve response parameters */
310         *mask = (uint32_t)mc_dec(cmd.params[0], 0, 32);
311         return 0;
312 }
313
314 int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
315                         uint32_t cmd_flags,
316                         uint16_t token,
317                         uint8_t irq_index,
318                         uint32_t *status)
319 {
320         struct mc_command cmd = { 0 };
321         int err;
322
323         /* prepare command */
324         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_STATUS,
325                                           cmd_flags, token);
326         cmd.params[0] |= mc_enc(32, 8, irq_index);
327
328         /* send command to mc*/
329         err = mc_send_command(mc_io, &cmd);
330         if (err)
331                 return err;
332
333         /* retrieve response parameters */
334         *status = (uint32_t)mc_dec(cmd.params[0], 0, 32);
335         return 0;
336 }
337
338 int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
339                           uint32_t cmd_flags,
340                           uint16_t token,
341                           uint8_t irq_index,
342                           uint32_t status)
343 {
344         struct mc_command cmd = { 0 };
345
346         /* prepare command */
347         cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLEAR_IRQ_STATUS,
348                                           cmd_flags, token);
349         cmd.params[0] |= mc_enc(0, 32, status);
350         cmd.params[0] |= mc_enc(32, 8, irq_index);
351
352         /* send command to mc*/
353         return mc_send_command(mc_io, &cmd);
354 }
355
356 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
357                         uint32_t cmd_flags,
358                         uint16_t token,
359                         struct dpbp_attr *attr)
360 {
361         struct mc_command cmd = { 0 };
362         int err;
363
364         /* prepare command */
365         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
366                                           cmd_flags, token);
367
368         /* send command to mc*/
369         err = mc_send_command(mc_io, &cmd);
370         if (err)
371                 return err;
372
373         /* retrieve response parameters */
374         attr->bpid = (uint16_t)mc_dec(cmd.params[0], 16, 16);
375         attr->id = (int)mc_dec(cmd.params[0], 32, 32);
376         attr->version.major = (uint16_t)mc_dec(cmd.params[1], 0, 16);
377         attr->version.minor = (uint16_t)mc_dec(cmd.params[1], 16, 16);
378         return 0;
379 }
380 EXPORT_SYMBOL(dpbp_get_attributes);