Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1 | /* |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 2 | * Copyright (C) 2013-2016 Freescale Semiconductor |
| 3 | * Copyright 2017 NXP |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <fsl-mc/fsl_mc_sys.h> |
| 9 | #include <fsl-mc/fsl_mc_cmd.h> |
| 10 | #include <fsl-mc/fsl_dpio.h> |
| 11 | |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 12 | int dpio_open(struct fsl_mc_io *mc_io, |
| 13 | uint32_t cmd_flags, |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 14 | uint32_t dpio_id, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 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(DPIO_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 | DPIO_CMD_OPEN(cmd, dpio_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 0; |
| 35 | } |
| 36 | |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 37 | int dpio_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 */ |
| 44 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 45 | cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 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 | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 52 | int dpio_create(struct fsl_mc_io *mc_io, |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 53 | uint16_t dprc_token, |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 54 | uint32_t cmd_flags, |
| 55 | const struct dpio_cfg *cfg, |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 56 | uint32_t *obj_id) |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 57 | { |
| 58 | struct mc_command cmd = { 0 }; |
| 59 | int err; |
| 60 | |
| 61 | /* prepare command */ |
| 62 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_CREATE, |
| 63 | cmd_flags, |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 64 | dprc_token); |
Prabhakar Kushwaha | 1ebbe4f | 2015-11-04 12:25:53 +0530 | [diff] [blame] | 65 | DPIO_CMD_CREATE(cmd, cfg); |
| 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 dpio_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(DPIO_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 dpio_enable(struct fsl_mc_io *mc_io, |
| 98 | uint32_t cmd_flags, |
| 99 | uint16_t token) |
| 100 | { |
| 101 | struct mc_command cmd = { 0 }; |
| 102 | |
| 103 | /* prepare command */ |
| 104 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE, |
| 105 | cmd_flags, |
| 106 | token); |
| 107 | |
| 108 | /* send command to mc*/ |
| 109 | return mc_send_command(mc_io, &cmd); |
| 110 | } |
| 111 | |
| 112 | int dpio_disable(struct fsl_mc_io *mc_io, |
| 113 | uint32_t cmd_flags, |
| 114 | uint16_t token) |
| 115 | { |
| 116 | struct mc_command cmd = { 0 }; |
| 117 | |
| 118 | /* prepare command */ |
| 119 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE, |
| 120 | cmd_flags, |
| 121 | token); |
| 122 | |
| 123 | /* send command to mc*/ |
| 124 | return mc_send_command(mc_io, &cmd); |
| 125 | } |
| 126 | |
| 127 | int dpio_reset(struct fsl_mc_io *mc_io, |
| 128 | uint32_t cmd_flags, |
| 129 | uint16_t token) |
Prabhakar Kushwaha | a2a55e5 | 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(DPIO_CMDID_RESET, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 135 | cmd_flags, |
| 136 | token); |
Prabhakar Kushwaha | a2a55e5 | 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 dpio_get_attributes(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 143 | uint32_t cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 144 | uint16_t token, |
| 145 | struct dpio_attr *attr) |
| 146 | { |
| 147 | struct mc_command cmd = { 0 }; |
| 148 | int err; |
| 149 | |
| 150 | /* prepare command */ |
| 151 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR, |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 152 | cmd_flags, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 153 | token); |
| 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 | DPIO_RSP_GET_ATTR(cmd, attr); |
| 162 | |
| 163 | return 0; |
| 164 | } |
Yogesh Gaur | 2557c5a | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 165 | |
| 166 | int dpio_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(DPIO_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 | } |