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