blob: 30ecc9124b2787edd31a36158ed541790a6ca1b3 [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 Kushwahacfd9fbf2015-03-19 09:20:45 -0700126int dpio_get_attributes(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530127 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700128 uint16_t token,
129 struct dpio_attr *attr)
130{
131 struct mc_command cmd = { 0 };
132 int err;
133
134 /* prepare command */
135 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530136 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700137 token);
138
139 /* send command to mc*/
140 err = mc_send_command(mc_io, &cmd);
141 if (err)
142 return err;
143
144 /* retrieve response parameters */
145 DPIO_RSP_GET_ATTR(cmd, attr);
146
147 return 0;
148}
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530149
150int dpio_get_api_version(struct fsl_mc_io *mc_io,
151 u32 cmd_flags,
152 u16 *major_ver,
153 u16 *minor_ver)
154{
155 struct mc_command cmd = { 0 };
156 int err;
157
158 /* prepare command */
159 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
160 cmd_flags, 0);
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 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
169
170 return 0;
171}