1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (C) 2013-2016 Freescale Semiconductor 4 * Copyright 2017 NXP 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 uint32_t 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_create(struct fsl_mc_io *mc_io, 52 uint16_t dprc_token, 53 uint32_t cmd_flags, 54 const struct dpio_cfg *cfg, 55 uint32_t *obj_id) 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, 63 dprc_token); 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 */ 72 MC_CMD_READ_OBJ_ID(cmd, *obj_id); 73 74 return 0; 75 } 76 77 int dpio_destroy(struct fsl_mc_io *mc_io, 78 uint16_t dprc_token, 79 uint32_t cmd_flags, 80 uint32_t obj_id) 81 { 82 struct mc_command cmd = { 0 }; 83 84 /* prepare command */ 85 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DESTROY, 86 cmd_flags, 87 dprc_token); 88 89 /* set object id to destroy */ 90 CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id); 91 92 /* send command to mc*/ 93 return mc_send_command(mc_io, &cmd); 94 } 95 96 int dpio_enable(struct fsl_mc_io *mc_io, 97 uint32_t cmd_flags, 98 uint16_t token) 99 { 100 struct mc_command cmd = { 0 }; 101 102 /* prepare command */ 103 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE, 104 cmd_flags, 105 token); 106 107 /* send command to mc*/ 108 return mc_send_command(mc_io, &cmd); 109 } 110 111 int dpio_disable(struct fsl_mc_io *mc_io, 112 uint32_t cmd_flags, 113 uint16_t token) 114 { 115 struct mc_command cmd = { 0 }; 116 117 /* prepare command */ 118 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE, 119 cmd_flags, 120 token); 121 122 /* send command to mc*/ 123 return mc_send_command(mc_io, &cmd); 124 } 125 126 int dpio_reset(struct fsl_mc_io *mc_io, 127 uint32_t cmd_flags, 128 uint16_t token) 129 { 130 struct mc_command cmd = { 0 }; 131 132 /* prepare command */ 133 cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET, 134 cmd_flags, 135 token); 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, 142 uint32_t cmd_flags, 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, 151 cmd_flags, 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 } 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 } 187