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 | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 126 | int dpio_get_attributes(struct fsl_mc_io *mc_io, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 127 | uint32_t cmd_flags, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 128 | uint16_t token, |
| 129 | struct dpio_attr *attr) |
| 130 | { |
| 131 | struct mc_command cmd = { 0 }; |
| 132 | int err; |
| 133 | |
| 134 | /* prepare command */ |
| 135 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 136 | cmd_flags, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 137 | token); |
| 138 | |
| 139 | /* send command to mc*/ |
| 140 | err = mc_send_command(mc_io, &cmd); |
| 141 | if (err) |
| 142 | return err; |
| 143 | |
| 144 | /* retrieve response parameters */ |
| 145 | DPIO_RSP_GET_ATTR(cmd, attr); |
| 146 | |
| 147 | return 0; |
| 148 | } |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 149 | |
| 150 | int dpio_get_api_version(struct fsl_mc_io *mc_io, |
| 151 | u32 cmd_flags, |
| 152 | u16 *major_ver, |
| 153 | u16 *minor_ver) |
| 154 | { |
| 155 | struct mc_command cmd = { 0 }; |
| 156 | int err; |
| 157 | |
| 158 | /* prepare command */ |
| 159 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION, |
| 160 | cmd_flags, 0); |
| 161 | |
| 162 | /* send command to mc */ |
| 163 | err = mc_send_command(mc_io, &cmd); |
| 164 | if (err) |
| 165 | return err; |
| 166 | |
| 167 | /* retrieve response parameters */ |
| 168 | mc_cmd_read_api_version(&cmd, major_ver, minor_ver); |
| 169 | |
| 170 | return 0; |
| 171 | } |