xref: /openbmc/u-boot/drivers/net/fsl-mc/dpio/dpio.c (revision 7c4213f6)
1 /*
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 
11 int dpio_open(struct fsl_mc_io *mc_io,
12 	      uint32_t cmd_flags,
13 	      int dpio_id,
14 	      uint16_t *token)
15 {
16 	struct mc_command cmd = { 0 };
17 	int err;
18 
19 	/* prepare command */
20 	cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
21 					  cmd_flags,
22 					  0);
23 	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 
36 int dpio_close(struct fsl_mc_io *mc_io,
37 	       uint32_t cmd_flags,
38 	       uint16_t token)
39 {
40 	struct mc_command cmd = { 0 };
41 
42 	/* prepare command */
43 	cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
44 					  cmd_flags,
45 					  token);
46 
47 	/* send command to mc*/
48 	return mc_send_command(mc_io, &cmd);
49 }
50 
51 int 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 
76 int 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 
91 int dpio_enable(struct fsl_mc_io *mc_io,
92 		uint32_t cmd_flags,
93 		uint16_t token)
94 {
95 	struct mc_command cmd = { 0 };
96 
97 	/* prepare command */
98 	cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
99 					  cmd_flags,
100 					  token);
101 
102 	/* send command to mc*/
103 	return mc_send_command(mc_io, &cmd);
104 }
105 
106 int dpio_disable(struct fsl_mc_io *mc_io,
107 		 uint32_t cmd_flags,
108 		 uint16_t token)
109 {
110 	struct mc_command cmd = { 0 };
111 
112 	/* prepare command */
113 	cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
114 					  cmd_flags,
115 					  token);
116 
117 	/* send command to mc*/
118 	return mc_send_command(mc_io, &cmd);
119 }
120 
121 int dpio_reset(struct fsl_mc_io *mc_io,
122 	       uint32_t cmd_flags,
123 	       uint16_t token)
124 {
125 	struct mc_command cmd = { 0 };
126 
127 	/* prepare command */
128 	cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET,
129 					  cmd_flags,
130 					  token);
131 
132 	/* send command to mc*/
133 	return mc_send_command(mc_io, &cmd);
134 }
135 
136 int dpio_get_attributes(struct fsl_mc_io *mc_io,
137 			uint32_t cmd_flags,
138 			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,
146 					  cmd_flags,
147 					  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 }
159