blob: 8884455963de63109cc08acee3a217f50b0d2c86 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07002/*
Yogesh Gaur1a0c4ae2018-05-09 10:52:17 +05303 * Copyright 2013-2016 Freescale Semiconductor, Inc.
Yogesh Gaur318c32f2017-11-15 11:59:31 +05304 * Copyright 2017 NXP
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07005 */
6
7#include <fsl-mc/fsl_mc_sys.h>
8#include <fsl-mc/fsl_mc_cmd.h>
9#include <fsl-mc/fsl_dpio.h>
10
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053011int dpio_open(struct fsl_mc_io *mc_io,
12 uint32_t cmd_flags,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053013 uint32_t dpio_id,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053014 uint16_t *token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070015{
16 struct mc_command cmd = { 0 };
17 int err;
18
19 /* prepare command */
20 cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053021 cmd_flags,
22 0);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070023 DPIO_CMD_OPEN(cmd, dpio_id);
24
25 /* send command to mc*/
26 err = mc_send_command(mc_io, &cmd);
27 if (err)
28 return err;
29
30 /* retrieve response parameters */
31 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
32
33 return 0;
34}
35
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053036int dpio_close(struct fsl_mc_io *mc_io,
37 uint32_t cmd_flags,
38 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070039{
40 struct mc_command cmd = { 0 };
41
42 /* prepare command */
43 cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053044 cmd_flags,
45 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070046
47 /* send command to mc*/
48 return mc_send_command(mc_io, &cmd);
49}
50
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053051int dpio_create(struct fsl_mc_io *mc_io,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053052 uint16_t dprc_token,
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053053 uint32_t cmd_flags,
54 const struct dpio_cfg *cfg,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053055 uint32_t *obj_id)
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053056{
57 struct mc_command cmd = { 0 };
58 int err;
59
60 /* prepare command */
61 cmd.header = mc_encode_cmd_header(DPIO_CMDID_CREATE,
62 cmd_flags,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053063 dprc_token);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053064 DPIO_CMD_CREATE(cmd, cfg);
65
66 /* send command to mc*/
67 err = mc_send_command(mc_io, &cmd);
68 if (err)
69 return err;
70
71 /* retrieve response parameters */
Yogesh Gaur318c32f2017-11-15 11:59:31 +053072 MC_CMD_READ_OBJ_ID(cmd, *obj_id);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053073
74 return 0;
75}
76
77int dpio_destroy(struct fsl_mc_io *mc_io,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053078 uint16_t dprc_token,
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053079 uint32_t cmd_flags,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053080 uint32_t obj_id)
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053081{
82 struct mc_command cmd = { 0 };
83
84 /* prepare command */
85 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DESTROY,
86 cmd_flags,
Yogesh Gaur318c32f2017-11-15 11:59:31 +053087 dprc_token);
88
89 /* set object id to destroy */
90 CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053091
92 /* send command to mc*/
93 return mc_send_command(mc_io, &cmd);
94}
95
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053096int dpio_enable(struct fsl_mc_io *mc_io,
97 uint32_t cmd_flags,
98 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070099{
100 struct mc_command cmd = { 0 };
101
102 /* prepare command */
103 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530104 cmd_flags,
105 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700106
107 /* send command to mc*/
108 return mc_send_command(mc_io, &cmd);
109}
110
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530111int dpio_disable(struct fsl_mc_io *mc_io,
112 uint32_t cmd_flags,
113 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700114{
115 struct mc_command cmd = { 0 };
116
117 /* prepare command */
118 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530119 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700120 token);
121
122 /* send command to mc*/
123 return mc_send_command(mc_io, &cmd);
124}
125
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530126int dpio_reset(struct fsl_mc_io *mc_io,
127 uint32_t cmd_flags,
128 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700129{
130 struct mc_command cmd = { 0 };
131
132 /* prepare command */
133 cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530134 cmd_flags,
135 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700136
137 /* send command to mc*/
138 return mc_send_command(mc_io, &cmd);
139}
140
141int dpio_get_attributes(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530142 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700143 uint16_t token,
144 struct dpio_attr *attr)
145{
146 struct mc_command cmd = { 0 };
147 int err;
148
149 /* prepare command */
150 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530151 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700152 token);
153
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 DPIO_RSP_GET_ATTR(cmd, attr);
161
162 return 0;
163}
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530164
165int dpio_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(DPIO_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}