Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 2 | /* |
Yogesh Gaur | 1a0c4ae | 2018-05-09 10:52:17 +0530 | [diff] [blame] | 3 | * Copyright 2013-2016 Freescale Semiconductor, Inc. |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 4 | * Copyright 2017 NXP |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 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 | |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 11 | int dpio_open(struct fsl_mc_io *mc_io, |
| 12 | uint32_t cmd_flags, |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 13 | uint32_t dpio_id, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 14 | uint16_t *token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 15 | { |
| 16 | struct mc_command cmd = { 0 }; |
| 17 | int err; |
| 18 | |
| 19 | /* prepare command */ |
| 20 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 21 | cmd_flags, |
| 22 | 0); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 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 | |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 36 | int dpio_close(struct fsl_mc_io *mc_io, |
| 37 | uint32_t cmd_flags, |
| 38 | uint16_t token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 39 | { |
| 40 | struct mc_command cmd = { 0 }; |
| 41 | |
| 42 | /* prepare command */ |
| 43 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 44 | cmd_flags, |
| 45 | token); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 46 | |
| 47 | /* send command to mc*/ |
| 48 | return mc_send_command(mc_io, &cmd); |
| 49 | } |
| 50 | |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 51 | int dpio_create(struct fsl_mc_io *mc_io, |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 52 | uint16_t dprc_token, |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 53 | uint32_t cmd_flags, |
| 54 | const struct dpio_cfg *cfg, |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 55 | uint32_t *obj_id) |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 56 | { |
| 57 | struct mc_command cmd = { 0 }; |
| 58 | int err; |
| 59 | |
| 60 | /* prepare command */ |
| 61 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_CREATE, |
| 62 | cmd_flags, |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 63 | dprc_token); |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 64 | DPIO_CMD_CREATE(cmd, cfg); |
| 65 | |
| 66 | /* send command to mc*/ |
| 67 | err = mc_send_command(mc_io, &cmd); |
| 68 | if (err) |
| 69 | return err; |
| 70 | |
| 71 | /* retrieve response parameters */ |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 72 | MC_CMD_READ_OBJ_ID(cmd, *obj_id); |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | int dpio_destroy(struct fsl_mc_io *mc_io, |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 78 | uint16_t dprc_token, |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 79 | uint32_t cmd_flags, |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 80 | uint32_t obj_id) |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 81 | { |
| 82 | struct mc_command cmd = { 0 }; |
| 83 | |
| 84 | /* prepare command */ |
| 85 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_DESTROY, |
| 86 | cmd_flags, |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 87 | dprc_token); |
| 88 | |
| 89 | /* set object id to destroy */ |
| 90 | CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id); |
Prabhakar Kushwaha | cf0c8cf | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 91 | |
| 92 | /* send command to mc*/ |
| 93 | return mc_send_command(mc_io, &cmd); |
| 94 | } |
| 95 | |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 96 | int dpio_enable(struct fsl_mc_io *mc_io, |
| 97 | uint32_t cmd_flags, |
| 98 | uint16_t token) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 99 | { |
| 100 | struct mc_command cmd = { 0 }; |
| 101 | |
| 102 | /* prepare command */ |
| 103 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 104 | cmd_flags, |
| 105 | token); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 106 | |
| 107 | /* send command to mc*/ |
| 108 | return mc_send_command(mc_io, &cmd); |
| 109 | } |
| 110 | |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 111 | int dpio_disable(struct fsl_mc_io *mc_io, |
| 112 | uint32_t cmd_flags, |
| 113 | uint16_t token) |
Prabhakar Kushwaha | cfd9fbf | 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(DPIO_CMDID_DISABLE, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 119 | cmd_flags, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 120 | token); |
| 121 | |
| 122 | /* send command to mc*/ |
| 123 | return mc_send_command(mc_io, &cmd); |
| 124 | } |
| 125 | |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 126 | int dpio_reset(struct fsl_mc_io *mc_io, |
| 127 | uint32_t cmd_flags, |
| 128 | uint16_t token) |
Prabhakar Kushwaha | cfd9fbf | 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(DPIO_CMDID_RESET, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 134 | cmd_flags, |
| 135 | token); |
Prabhakar Kushwaha | cfd9fbf | 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 dpio_get_attributes(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 142 | uint32_t cmd_flags, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 143 | uint16_t token, |
| 144 | struct dpio_attr *attr) |
| 145 | { |
| 146 | struct mc_command cmd = { 0 }; |
| 147 | int err; |
| 148 | |
| 149 | /* prepare command */ |
| 150 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 151 | cmd_flags, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 152 | token); |
| 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 | DPIO_RSP_GET_ATTR(cmd, attr); |
| 161 | |
| 162 | return 0; |
| 163 | } |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 164 | |
| 165 | int dpio_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(DPIO_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 | } |