xref: /openbmc/u-boot/drivers/net/fsl-mc/dpio/dpio.c (revision 038be18f)
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_enable(struct fsl_mc_io *mc_io,
52 		uint32_t cmd_flags,
53 		uint16_t token)
54 {
55 	struct mc_command cmd = { 0 };
56 
57 	/* prepare command */
58 	cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
59 					  cmd_flags,
60 					  token);
61 
62 	/* send command to mc*/
63 	return mc_send_command(mc_io, &cmd);
64 }
65 
66 int dpio_disable(struct fsl_mc_io *mc_io,
67 		 uint32_t cmd_flags,
68 		 uint16_t token)
69 {
70 	struct mc_command cmd = { 0 };
71 
72 	/* prepare command */
73 	cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
74 					  cmd_flags,
75 					  token);
76 
77 	/* send command to mc*/
78 	return mc_send_command(mc_io, &cmd);
79 }
80 
81 int dpio_reset(struct fsl_mc_io *mc_io,
82 	       uint32_t cmd_flags,
83 	       uint16_t token)
84 {
85 	struct mc_command cmd = { 0 };
86 
87 	/* prepare command */
88 	cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET,
89 					  cmd_flags,
90 					  token);
91 
92 	/* send command to mc*/
93 	return mc_send_command(mc_io, &cmd);
94 }
95 
96 int dpio_get_attributes(struct fsl_mc_io *mc_io,
97 			uint32_t cmd_flags,
98 			uint16_t token,
99 			struct dpio_attr *attr)
100 {
101 	struct mc_command cmd = { 0 };
102 	int err;
103 
104 	/* prepare command */
105 	cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
106 					  cmd_flags,
107 					  token);
108 
109 	/* send command to mc*/
110 	err = mc_send_command(mc_io, &cmd);
111 	if (err)
112 		return err;
113 
114 	/* retrieve response parameters */
115 	DPIO_RSP_GET_ATTR(cmd, attr);
116 
117 	return 0;
118 }
119