xref: /openbmc/u-boot/drivers/net/fsl-mc/dpbp.c (revision 2a0b7dc3)
1 /*
2  * Freescale Layerscape MC I/O wrapper
3  *
4  * Copyright (C) 2013-2015 Freescale Semiconductor, Inc.
5  * Author: German Rivera <German.Rivera@freescale.com>
6  *
7  * SPDX-License-Identifier:	GPL-2.0+
8  */
9 #include <fsl-mc/fsl_mc_sys.h>
10 #include <fsl-mc/fsl_mc_cmd.h>
11 #include <fsl-mc/fsl_dpbp.h>
12 
13 int dpbp_open(struct fsl_mc_io *mc_io,
14 	      uint32_t cmd_flags,
15 	      int dpbp_id,
16 	      uint16_t *token)
17 {
18 	struct mc_command cmd = { 0 };
19 	int err;
20 
21 	/* prepare command */
22 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
23 					  cmd_flags,
24 					  0);
25 	DPBP_CMD_OPEN(cmd, dpbp_id);
26 
27 	/* send command to mc*/
28 	err = mc_send_command(mc_io, &cmd);
29 	if (err)
30 		return err;
31 
32 	/* retrieve response parameters */
33 	*token = MC_CMD_HDR_READ_TOKEN(cmd.header);
34 
35 	return err;
36 }
37 
38 int dpbp_close(struct fsl_mc_io *mc_io,
39 	       uint32_t cmd_flags,
40 	       uint16_t token)
41 {
42 	struct mc_command cmd = { 0 };
43 
44 	/* prepare command */
45 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
46 					  token);
47 
48 	/* send command to mc*/
49 	return mc_send_command(mc_io, &cmd);
50 }
51 
52 int dpbp_enable(struct fsl_mc_io *mc_io,
53 		uint32_t cmd_flags,
54 		uint16_t token)
55 {
56 	struct mc_command cmd = { 0 };
57 
58 	/* prepare command */
59 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
60 					  token);
61 
62 	/* send command to mc*/
63 	return mc_send_command(mc_io, &cmd);
64 }
65 
66 int dpbp_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(DPBP_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 dpbp_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(DPBP_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 dpbp_get_attributes(struct fsl_mc_io *mc_io,
97 			uint32_t cmd_flags,
98 			uint16_t token,
99 			struct dpbp_attr *attr)
100 {
101 	struct mc_command cmd = { 0 };
102 	int err;
103 
104 	/* prepare command */
105 	cmd.header = mc_encode_cmd_header(DPBP_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 	DPBP_RSP_GET_ATTRIBUTES(cmd, attr);
116 
117 	return 0;
118 }
119