Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Freescale Layerscape MC I/O wrapper |
| 4 | * |
Yogesh Gaur | a6f2a6e | 2018-05-09 10:52:17 +0530 | [diff] [blame] | 5 | * Copyright 2013-2016 Freescale Semiconductor, Inc. |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 6 | * Copyright 2017 NXP |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 7 | */ |
| 8 | #include <fsl-mc/fsl_mc_sys.h> |
| 9 | #include <fsl-mc/fsl_mc_cmd.h> |
| 10 | #include <fsl-mc/fsl_dpbp.h> |
| 11 | |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 12 | int dpbp_open(struct fsl_mc_io *mc_io, |
| 13 | uint32_t cmd_flags, |
| 14 | int dpbp_id, |
| 15 | uint16_t *token) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 16 | { |
| 17 | struct mc_command cmd = { 0 }; |
| 18 | int err; |
| 19 | |
| 20 | /* prepare command */ |
| 21 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 22 | cmd_flags, |
| 23 | 0); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 24 | DPBP_CMD_OPEN(cmd, dpbp_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 err; |
| 35 | } |
| 36 | |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 37 | int dpbp_close(struct fsl_mc_io *mc_io, |
| 38 | uint32_t cmd_flags, |
| 39 | uint16_t token) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 40 | { |
| 41 | struct mc_command cmd = { 0 }; |
| 42 | |
| 43 | /* prepare command */ |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 44 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 45 | token); |
| 46 | |
| 47 | /* send command to mc*/ |
| 48 | return mc_send_command(mc_io, &cmd); |
| 49 | } |
| 50 | |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 51 | int dpbp_create(struct fsl_mc_io *mc_io, |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 52 | uint16_t dprc_token, |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 53 | uint32_t cmd_flags, |
| 54 | const struct dpbp_cfg *cfg, |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 55 | uint32_t *obj_id) |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 56 | { |
| 57 | struct mc_command cmd = { 0 }; |
| 58 | int err; |
| 59 | |
| 60 | (void)(cfg); /* unused */ |
| 61 | |
| 62 | /* prepare command */ |
| 63 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE, |
| 64 | cmd_flags, |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 65 | dprc_token); |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 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 */ |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 73 | MC_CMD_READ_OBJ_ID(cmd, *obj_id); |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | int dpbp_destroy(struct fsl_mc_io *mc_io, |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 79 | uint16_t dprc_token, |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 80 | uint32_t cmd_flags, |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 81 | uint32_t obj_id) |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 82 | { |
| 83 | struct mc_command cmd = { 0 }; |
| 84 | |
| 85 | /* prepare command */ |
| 86 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY, |
| 87 | cmd_flags, |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 88 | dprc_token); |
| 89 | |
| 90 | /* set object id to destroy */ |
| 91 | CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id); |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 92 | |
| 93 | /* send command to mc*/ |
| 94 | return mc_send_command(mc_io, &cmd); |
| 95 | } |
| 96 | |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 97 | int dpbp_enable(struct fsl_mc_io *mc_io, |
| 98 | uint32_t cmd_flags, |
| 99 | uint16_t token) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 100 | { |
| 101 | struct mc_command cmd = { 0 }; |
| 102 | |
| 103 | /* prepare command */ |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 104 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 105 | token); |
| 106 | |
| 107 | /* send command to mc*/ |
| 108 | return mc_send_command(mc_io, &cmd); |
| 109 | } |
| 110 | |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 111 | int dpbp_disable(struct fsl_mc_io *mc_io, |
| 112 | uint32_t cmd_flags, |
| 113 | uint16_t token) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 114 | { |
| 115 | struct mc_command cmd = { 0 }; |
| 116 | |
| 117 | /* prepare command */ |
| 118 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 119 | cmd_flags, |
| 120 | token); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 121 | |
| 122 | /* send command to mc*/ |
| 123 | return mc_send_command(mc_io, &cmd); |
| 124 | } |
| 125 | |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 126 | int dpbp_reset(struct fsl_mc_io *mc_io, |
| 127 | uint32_t cmd_flags, |
| 128 | uint16_t token) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 129 | { |
| 130 | struct mc_command cmd = { 0 }; |
| 131 | |
| 132 | /* prepare command */ |
| 133 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 134 | cmd_flags, |
| 135 | token); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 136 | |
| 137 | /* send command to mc*/ |
| 138 | return mc_send_command(mc_io, &cmd); |
| 139 | } |
| 140 | |
| 141 | int dpbp_get_attributes(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 142 | uint32_t cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 143 | uint16_t token, |
| 144 | struct dpbp_attr *attr) |
| 145 | { |
| 146 | struct mc_command cmd = { 0 }; |
| 147 | int err; |
| 148 | |
| 149 | /* prepare command */ |
| 150 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 151 | cmd_flags, |
| 152 | token); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 153 | |
| 154 | /* send command to mc*/ |
| 155 | err = mc_send_command(mc_io, &cmd); |
| 156 | if (err) |
| 157 | return err; |
| 158 | |
| 159 | /* retrieve response parameters */ |
| 160 | DPBP_RSP_GET_ATTRIBUTES(cmd, attr); |
| 161 | |
| 162 | return 0; |
| 163 | } |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 164 | |
| 165 | int dpbp_get_api_version(struct fsl_mc_io *mc_io, |
| 166 | u32 cmd_flags, |
| 167 | u16 *major_ver, |
| 168 | u16 *minor_ver) |
| 169 | { |
| 170 | struct mc_command cmd = { 0 }; |
| 171 | int err; |
| 172 | |
| 173 | /* prepare command */ |
| 174 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION, |
| 175 | cmd_flags, 0); |
| 176 | |
| 177 | /* send command to mc */ |
| 178 | err = mc_send_command(mc_io, &cmd); |
| 179 | if (err) |
| 180 | return err; |
| 181 | |
| 182 | /* retrieve response parameters */ |
| 183 | mc_cmd_read_api_version(&cmd, major_ver, minor_ver); |
| 184 | |
| 185 | return 0; |
| 186 | } |