]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/staging/fsl-mc/include/mc-cmd.h
iio: imu: inv_mpu6050: test whoami first and against all known values
[mirror_ubuntu-artful-kernel.git] / drivers / staging / fsl-mc / include / mc-cmd.h
CommitLineData
363b0cbf 1/*
6466dac7 2 * Copyright 2013-2016 Freescale Semiconductor Inc.
31c88965
GR
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33#ifndef __FSL_MC_CMD_H
34#define __FSL_MC_CMD_H
35
36#define MC_CMD_NUM_OF_PARAMS 7
37
9989b599
IR
38struct mc_cmd_header {
39 u8 src_id;
40 u8 flags_hw;
41 u8 status;
42 u8 flags_sw;
43 __le16 token;
44 __le16 cmd_id;
45};
31c88965
GR
46
47struct mc_command {
ba72f25b
GR
48 u64 header;
49 u64 params[MC_CMD_NUM_OF_PARAMS];
31c88965
GR
50};
51
decd3d0c
IC
52struct mc_rsp_create {
53 __le32 object_id;
54};
55
56struct mc_rsp_api_ver {
57 __le16 major_ver;
58 __le16 minor_ver;
59};
60
31c88965
GR
61enum mc_cmd_status {
62 MC_CMD_STATUS_OK = 0x0, /* Completed successfully */
63 MC_CMD_STATUS_READY = 0x1, /* Ready to be processed */
64 MC_CMD_STATUS_AUTH_ERR = 0x3, /* Authentication error */
65 MC_CMD_STATUS_NO_PRIVILEGE = 0x4, /* No privilege */
66 MC_CMD_STATUS_DMA_ERR = 0x5, /* DMA or I/O error */
67 MC_CMD_STATUS_CONFIG_ERR = 0x6, /* Configuration error */
68 MC_CMD_STATUS_TIMEOUT = 0x7, /* Operation timed out */
69 MC_CMD_STATUS_NO_RESOURCE = 0x8, /* No resources */
70 MC_CMD_STATUS_NO_MEMORY = 0x9, /* No memory available */
71 MC_CMD_STATUS_BUSY = 0xA, /* Device is busy */
72 MC_CMD_STATUS_UNSUPPORTED_OP = 0xB, /* Unsupported operation */
73 MC_CMD_STATUS_INVALID_STATE = 0xC /* Invalid state */
74};
75
e8604669
GR
76/*
77 * MC command flags
78 */
79
80/* High priority flag */
9989b599 81#define MC_CMD_FLAG_PRI 0x80
e8604669 82/* Command completion flag */
9989b599 83#define MC_CMD_FLAG_INTR_DIS 0x01
31c88965 84
ba72f25b
GR
85static inline u64 mc_encode_cmd_header(u16 cmd_id,
86 u32 cmd_flags,
87 u16 token)
31c88965 88{
9989b599
IR
89 u64 header = 0;
90 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&header;
91
decd3d0c
IC
92 hdr->cmd_id = cpu_to_le16(cmd_id);
93 hdr->token = cpu_to_le16(token);
9989b599
IR
94 hdr->status = MC_CMD_STATUS_READY;
95 if (cmd_flags & MC_CMD_FLAG_PRI)
96 hdr->flags_hw = MC_CMD_FLAG_PRI;
97 if (cmd_flags & MC_CMD_FLAG_INTR_DIS)
98 hdr->flags_sw = MC_CMD_FLAG_INTR_DIS;
99
100 return header;
101}
31c88965 102
9989b599
IR
103static inline u16 mc_cmd_hdr_read_token(struct mc_command *cmd)
104{
105 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
106 u16 token = le16_to_cpu(hdr->token);
31c88965 107
decd3d0c
IC
108 return token;
109}
110
111static inline u32 mc_cmd_read_object_id(struct mc_command *cmd)
112{
113 struct mc_rsp_create *rsp_params;
114
115 rsp_params = (struct mc_rsp_create *)cmd->params;
116 return le32_to_cpu(rsp_params->object_id);
117}
118
119static inline void mc_cmd_read_api_version(struct mc_command *cmd,
120 u16 *major_ver,
121 u16 *minor_ver)
122{
123 struct mc_rsp_api_ver *rsp_params;
124
125 rsp_params = (struct mc_rsp_api_ver *)cmd->params;
126 *major_ver = le16_to_cpu(rsp_params->major_ver);
127 *minor_ver = le16_to_cpu(rsp_params->minor_ver);
31c88965
GR
128}
129
130#endif /* __FSL_MC_CMD_H */