]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - arch/arm/mach-snapdragon/include/mach/qcom-smd.h
misc: add support for Qualcomm SMD protocol
[karo-tx-uboot.git] / arch / arm / mach-snapdragon / include / mach / qcom-smd.h
1 /*
2  * Copyright (C) 2017, Lothar Waßmann <LW@KARO-electronics.de>
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  *
6  * based on: platform/msm_shared/include/smd.h
7  * from Android Little Kernel: https://github.com/littlekernel/lk
8  *
9  * Copyright (c) 2014, The Linux Foundation. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *     * Redistributions of source code must retain the above copyright
15  *       notice, this list of conditions and the following disclaimer.
16  *     * Redistributions in binary form must reproduce the above
17  *       copyright notice, this list of conditions and the following
18  *       disclaimer in the documentation and/or other materials provided
19  *       with the distribution.
20  *     * Neither the name of The Linux Fundation, Inc. nor the names of its
21  *       contributors may be used to endorse or promote products derived
22  *       from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
25  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37
38 #ifndef __QCOM_SMD_H
39 #define __QCOM_SMD_H
40
41 #define SMD_CHANNEL_ALLOC_MAX 2048
42 #define SMD_CHANNEL_NAME_SIZE_MAX 20
43
44 /* Stream related states */
45 #define SMD_SS_CLOSED           0x0 /* Closed: must be 0 */
46 #define SMD_SS_OPENING          0x1 /* Stream is opening */
47 #define SMD_SS_OPENED           0x2 /* Stream is opened */
48 #define SMD_SS_FLUSHING         0x3 /* Stream is flushing */
49 #define SMD_SS_CLOSING          0x4 /* Stream is closing */
50 #define SMD_SS_RESET            0x5 /* Stream is resetting */
51 #define SMD_SS_RESET_OPENING    0x6 /* Stream reset on local */
52
53 typedef enum {
54         SMD_APPS_RPM = 0x0F,
55 } smd_channel_type;
56
57 typedef struct {
58         uint32_t stream_state;
59         uint32_t DTR_DSR;
60         uint32_t CTS_RTS;
61         uint32_t CD;
62         uint32_t RI;
63         uint32_t data_written;
64         uint32_t data_read;
65         uint32_t state_updated;
66         uint32_t mask_recv_intr;
67         uint32_t read_index;
68         uint32_t write_index;
69 } smd_shared_stream_info_type;
70
71 /* Each port has 2 FIFOs, one per direction */
72 typedef struct {
73         char name[SMD_CHANNEL_NAME_SIZE_MAX];
74         uint32_t cid;
75         uint32_t ctype;
76         uint32_t ref_count;
77 } smd_channel_alloc_entry_t;
78
79 typedef enum {
80         SMD_STREAMING_BUFFER,
81 } smd_protocol_type;
82
83 typedef struct {
84         smd_protocol_type protocol;
85         uint32_t port_id;
86         smd_channel_type ch_type;
87 } smd_port_to_info_type;
88
89 typedef struct {
90         uint32_t pkt_size;
91         uint32_t app_field;
92         uint32_t app_ptr;
93         uint32_t kind;
94         uint32_t priority;
95 } smd_pkt_hdr;
96
97 typedef struct {
98         smd_shared_stream_info_type ch0;
99         smd_shared_stream_info_type ch1;
100 } smd_port_ctrl_info;
101
102 typedef struct {
103         smd_channel_alloc_entry_t alloc_entry;
104         uint8_t *send_buf;
105         uint8_t *recv_buf;
106         uint32_t fifo_size;
107         smd_port_ctrl_info *port_info;
108         uint32_t current_state;
109 } smd_channel_info_t;
110
111 int smd_init(smd_channel_info_t *ch, uint32_t ch_type);
112 void smd_uninit(smd_channel_info_t *ch);
113 int smd_read(smd_channel_info_t *ch, uint32_t *len, int ch_type,
114         uint32_t *response);
115 int smd_write(smd_channel_info_t *ch, const void *data, uint32_t len, int type);
116 void smd_signal_read_complete(smd_channel_info_t *ch, uint32_t len);
117 #endif /* __QCOM_SMD_H */