ccac506e9957ed2694d2b78ab78bb7f94fdd3bb3
[platform/kernel/u-boot.git] / drivers / net / fsl-mc / dpio / dpio.c
1 /*
2  * Copyright (C) 2013-2016 Freescale Semiconductor
3  * Copyright 2017 NXP
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <fsl-mc/fsl_mc_sys.h>
9 #include <fsl-mc/fsl_mc_cmd.h>
10 #include <fsl-mc/fsl_dpio.h>
11
12 int dpio_open(struct fsl_mc_io *mc_io,
13               uint32_t cmd_flags,
14               uint32_t dpio_id,
15               uint16_t *token)
16 {
17         struct mc_command cmd = { 0 };
18         int err;
19
20         /* prepare command */
21         cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
22                                           cmd_flags,
23                                           0);
24         DPIO_CMD_OPEN(cmd, dpio_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 0;
35 }
36
37 int dpio_close(struct fsl_mc_io *mc_io,
38                uint32_t cmd_flags,
39                uint16_t token)
40 {
41         struct mc_command cmd = { 0 };
42
43         /* prepare command */
44         cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
45                                           cmd_flags,
46                                           token);
47
48         /* send command to mc*/
49         return mc_send_command(mc_io, &cmd);
50 }
51
52 int dpio_create(struct fsl_mc_io *mc_io,
53                 uint16_t dprc_token,
54                 uint32_t cmd_flags,
55                 const struct dpio_cfg *cfg,
56                 uint32_t *obj_id)
57 {
58         struct mc_command cmd = { 0 };
59         int err;
60
61         /* prepare command */
62         cmd.header = mc_encode_cmd_header(DPIO_CMDID_CREATE,
63                                           cmd_flags,
64                                           dprc_token);
65         DPIO_CMD_CREATE(cmd, cfg);
66
67         /* send command to mc*/
68         err = mc_send_command(mc_io, &cmd);
69         if (err)
70                 return err;
71
72         /* retrieve response parameters */
73         MC_CMD_READ_OBJ_ID(cmd, *obj_id);
74
75         return 0;
76 }
77
78 int dpio_destroy(struct fsl_mc_io *mc_io,
79                  uint16_t dprc_token,
80                  uint32_t cmd_flags,
81                  uint32_t obj_id)
82 {
83         struct mc_command cmd = { 0 };
84
85         /* prepare command */
86         cmd.header = mc_encode_cmd_header(DPIO_CMDID_DESTROY,
87                                           cmd_flags,
88                                           dprc_token);
89
90         /* set object id to destroy */
91         CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id);
92
93         /* send command to mc*/
94         return mc_send_command(mc_io, &cmd);
95 }
96
97 int dpio_enable(struct fsl_mc_io *mc_io,
98                 uint32_t cmd_flags,
99                 uint16_t token)
100 {
101         struct mc_command cmd = { 0 };
102
103         /* prepare command */
104         cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
105                                           cmd_flags,
106                                           token);
107
108         /* send command to mc*/
109         return mc_send_command(mc_io, &cmd);
110 }
111
112 int dpio_disable(struct fsl_mc_io *mc_io,
113                  uint32_t cmd_flags,
114                  uint16_t token)
115 {
116         struct mc_command cmd = { 0 };
117
118         /* prepare command */
119         cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
120                                           cmd_flags,
121                                           token);
122
123         /* send command to mc*/
124         return mc_send_command(mc_io, &cmd);
125 }
126
127 int dpio_reset(struct fsl_mc_io *mc_io,
128                uint32_t cmd_flags,
129                uint16_t token)
130 {
131         struct mc_command cmd = { 0 };
132
133         /* prepare command */
134         cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET,
135                                           cmd_flags,
136                                           token);
137
138         /* send command to mc*/
139         return mc_send_command(mc_io, &cmd);
140 }
141
142 int dpio_get_attributes(struct fsl_mc_io *mc_io,
143                         uint32_t cmd_flags,
144                         uint16_t token,
145                         struct dpio_attr *attr)
146 {
147         struct mc_command cmd = { 0 };
148         int err;
149
150         /* prepare command */
151         cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
152                                           cmd_flags,
153                                           token);
154
155         /* send command to mc*/
156         err = mc_send_command(mc_io, &cmd);
157         if (err)
158                 return err;
159
160         /* retrieve response parameters */
161         DPIO_RSP_GET_ATTR(cmd, attr);
162
163         return 0;
164 }
165
166 int dpio_get_api_version(struct fsl_mc_io *mc_io,
167                          u32 cmd_flags,
168                          u16 *major_ver,
169                          u16 *minor_ver)
170 {
171         struct mc_command cmd = { 0 };
172         int err;
173
174         /* prepare command */
175         cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
176                                           cmd_flags, 0);
177
178         /* send command to mc */
179         err = mc_send_command(mc_io, &cmd);
180         if (err)
181                 return err;
182
183         /* retrieve response parameters */
184         mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
185
186         return 0;
187 }