blob: c609efb9abcc3ade14d4d74d602b034771ae43bc [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07002/*
3 * Freescale Layerscape MC I/O wrapper
4 *
Yogesh Gaura6f2a6e2018-05-09 10:52:17 +05305 * Copyright 2013-2016 Freescale Semiconductor, Inc.
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05306 * Copyright 2017 NXP
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07007 */
8#include <fsl-mc/fsl_mc_sys.h>
9#include <fsl-mc/fsl_mc_cmd.h>
10#include <fsl-mc/fsl_dpbp.h>
11
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053012int dpbp_open(struct fsl_mc_io *mc_io,
13 uint32_t cmd_flags,
14 int dpbp_id,
15 uint16_t *token)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070016{
17 struct mc_command cmd = { 0 };
18 int err;
19
20 /* prepare command */
21 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053022 cmd_flags,
23 0);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070024 DPBP_CMD_OPEN(cmd, dpbp_id);
25
26 /* send command to mc*/
27 err = mc_send_command(mc_io, &cmd);
28 if (err)
29 return err;
30
31 /* retrieve response parameters */
32 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
33
34 return err;
35}
36
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053037int dpbp_close(struct fsl_mc_io *mc_io,
38 uint32_t cmd_flags,
39 uint16_t token)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070040{
41 struct mc_command cmd = { 0 };
42
43 /* prepare command */
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053044 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070045 token);
46
47 /* send command to mc*/
48 return mc_send_command(mc_io, &cmd);
49}
50
Prabhakar Kushwaha1ebbe4f2015-11-04 12:25:53 +053051int dpbp_create(struct fsl_mc_io *mc_io,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053052 uint16_t dprc_token,
Prabhakar Kushwaha1ebbe4f2015-11-04 12:25:53 +053053 uint32_t cmd_flags,
54 const struct dpbp_cfg *cfg,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053055 uint32_t *obj_id)
Prabhakar Kushwaha1ebbe4f2015-11-04 12:25:53 +053056{
57 struct mc_command cmd = { 0 };
58 int err;
59
60 (void)(cfg); /* unused */
61
62 /* prepare command */
63 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
64 cmd_flags,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053065 dprc_token);
Prabhakar Kushwaha1ebbe4f2015-11-04 12:25:53 +053066
67 /* send command to mc*/
68 err = mc_send_command(mc_io, &cmd);
69 if (err)
70 return err;
71
72 /* retrieve response parameters */
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053073 MC_CMD_READ_OBJ_ID(cmd, *obj_id);
Prabhakar Kushwaha1ebbe4f2015-11-04 12:25:53 +053074
75 return 0;
76}
77
78int dpbp_destroy(struct fsl_mc_io *mc_io,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053079 uint16_t dprc_token,
Prabhakar Kushwaha1ebbe4f2015-11-04 12:25:53 +053080 uint32_t cmd_flags,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053081 uint32_t obj_id)
Prabhakar Kushwaha1ebbe4f2015-11-04 12:25:53 +053082{
83 struct mc_command cmd = { 0 };
84
85 /* prepare command */
86 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
87 cmd_flags,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053088 dprc_token);
89
90 /* set object id to destroy */
91 CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id);
Prabhakar Kushwaha1ebbe4f2015-11-04 12:25:53 +053092
93 /* send command to mc*/
94 return mc_send_command(mc_io, &cmd);
95}
96
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +053097int dpbp_enable(struct fsl_mc_io *mc_io,
98 uint32_t cmd_flags,
99 uint16_t token)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700100{
101 struct mc_command cmd = { 0 };
102
103 /* prepare command */
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530104 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700105 token);
106
107 /* send command to mc*/
108 return mc_send_command(mc_io, &cmd);
109}
110
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530111int dpbp_disable(struct fsl_mc_io *mc_io,
112 uint32_t cmd_flags,
113 uint16_t token)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700114{
115 struct mc_command cmd = { 0 };
116
117 /* prepare command */
118 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530119 cmd_flags,
120 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700121
122 /* send command to mc*/
123 return mc_send_command(mc_io, &cmd);
124}
125
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530126int dpbp_reset(struct fsl_mc_io *mc_io,
127 uint32_t cmd_flags,
128 uint16_t token)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700129{
130 struct mc_command cmd = { 0 };
131
132 /* prepare command */
133 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530134 cmd_flags,
135 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700136
137 /* send command to mc*/
138 return mc_send_command(mc_io, &cmd);
139}
140
141int dpbp_get_attributes(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530142 uint32_t cmd_flags,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700143 uint16_t token,
144 struct dpbp_attr *attr)
145{
146 struct mc_command cmd = { 0 };
147 int err;
148
149 /* prepare command */
150 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +0530151 cmd_flags,
152 token);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700153
154 /* send command to mc*/
155 err = mc_send_command(mc_io, &cmd);
156 if (err)
157 return err;
158
159 /* retrieve response parameters */
160 DPBP_RSP_GET_ATTRIBUTES(cmd, attr);
161
162 return 0;
163}
Yogesh Gaur2557c5a2017-11-15 11:59:31 +0530164
165int dpbp_get_api_version(struct fsl_mc_io *mc_io,
166 u32 cmd_flags,
167 u16 *major_ver,
168 u16 *minor_ver)
169{
170 struct mc_command cmd = { 0 };
171 int err;
172
173 /* prepare command */
174 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
175 cmd_flags, 0);
176
177 /* send command to mc */
178 err = mc_send_command(mc_io, &cmd);
179 if (err)
180 return err;
181
182 /* retrieve response parameters */
183 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
184
185 return 0;
186}