blob: b61df52860e50351d47478275e01b9e1e75f3cb7 [file] [log] [blame]
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001/*
2 * Copyright (C) 2013-2015 Freescale Semiconductor
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
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,
13 int dpio_id,
14 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,
52 uint32_t cmd_flags,
53 const struct dpio_cfg *cfg,
54 uint16_t *token)
55{
56 struct mc_command cmd = { 0 };
57 int err;
58
59 /* prepare command */
60 cmd.header = mc_encode_cmd_header(DPIO_CMDID_CREATE,
61 cmd_flags,
62 0);
63 DPIO_CMD_CREATE(cmd, cfg);
64
65 /* send command to mc*/
66 err = mc_send_command(mc_io, &cmd);
67 if (err)
68 return err;
69
70 /* retrieve response parameters */
71 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
72
73 return 0;
74}
75
76int dpio_destroy(struct fsl_mc_io *mc_io,
77 uint32_t cmd_flags,
78 uint16_t token)
79{
80 struct mc_command cmd = { 0 };
81
82 /* prepare command */
83 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DESTROY,
84 cmd_flags,
85 token);
86
87 /* send command to mc*/
88 return mc_send_command(mc_io, &cmd);
89}
90
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053091int dpio_enable(struct fsl_mc_io *mc_io,
92 uint32_t cmd_flags,
93 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070094{
95 struct mc_command cmd = { 0 };
96
97 /* prepare command */
98 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053099 cmd_flags,
100 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700101
102 /* send command to mc*/
103 return mc_send_command(mc_io, &cmd);
104}
105
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530106int dpio_disable(struct fsl_mc_io *mc_io,
107 uint32_t cmd_flags,
108 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700109{
110 struct mc_command cmd = { 0 };
111
112 /* prepare command */
113 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530114 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700115 token);
116
117 /* send command to mc*/
118 return mc_send_command(mc_io, &cmd);
119}
120
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530121int dpio_reset(struct fsl_mc_io *mc_io,
122 uint32_t cmd_flags,
123 uint16_t token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700124{
125 struct mc_command cmd = { 0 };
126
127 /* prepare command */
128 cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530129 cmd_flags,
130 token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700131
132 /* send command to mc*/
133 return mc_send_command(mc_io, &cmd);
134}
135
136int dpio_get_attributes(struct fsl_mc_io *mc_io,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530137 uint32_t cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700138 uint16_t token,
139 struct dpio_attr *attr)
140{
141 struct mc_command cmd = { 0 };
142 int err;
143
144 /* prepare command */
145 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530146 cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700147 token);
148
149 /* send command to mc*/
150 err = mc_send_command(mc_io, &cmd);
151 if (err)
152 return err;
153
154 /* retrieve response parameters */
155 DPIO_RSP_GET_ATTR(cmd, attr);
156
157 return 0;
158}