Merge tag 'lsk-v3.10-android-15.02'
[firefly-linux-kernel-4.4.55.git] / drivers / video / rockchip / hdmi / rockchip-hdmi-cec.h
1 #ifndef __ROCKCHIP_HDMI_CEC_H__
2 #define __ROCKCHIP_HDMI_CEC_H__
3 #include "rockchip-hdmi.h"
4
5 #include <linux/input.h>
6
7 enum {
8         CEC_LOGADDR_TV          = 0x00,
9         CEC_LOGADDR_RECDEV1     = 0x01,
10         CEC_LOGADDR_RECDEV2     = 0x02,
11         CEC_LOGADDR_TUNER1      = 0x03,     /* STB1 in Spev v1.3 */
12         CEC_LOGADDR_PLAYBACK1   = 0x04,     /* DVD1 in Spev v1.3 */
13         CEC_LOGADDR_AUDSYS      = 0x05,
14         CEC_LOGADDR_TUNER2      = 0x06,     /* STB2 in Spec v1.3 */
15         CEC_LOGADDR_TUNER3      = 0x07,     /* STB3 in Spec v1.3 */
16         CEC_LOGADDR_PLAYBACK2   = 0x08,     /* DVD2 in Spec v1.3 */
17         CEC_LOGADDR_RECDEV3     = 0x09,
18         CEC_LOGADDR_TUNER4      = 0x0A,     /* RES1 in Spec v1.3 */
19         CEC_LOGADDR_PLAYBACK3   = 0x0B,     /* RES2 in Spec v1.3 */
20         CEC_LOGADDR_RES3        = 0x0C,
21         CEC_LOGADDR_RES4        = 0x0D,
22         CEC_LOGADDR_FREEUSE     = 0x0E,
23         CEC_LOGADDR_UNREGORBC   = 0x0F
24
25 };
26
27 enum {                   /* CEC Messages */
28         CECOP_FEATURE_ABORT                     = 0x00,
29         CECOP_IMAGE_VIEW_ON                     = 0x04,
30         CECOP_TUNER_STEP_INCREMENT              = 0x05,
31         CECOP_TUNER_STEP_DECREMENT              = 0x06,
32         CECOP_TUNER_DEVICE_STATUS               = 0x07,
33         CECOP_GIVE_TUNER_DEVICE_STATUS          = 0x08,
34         CECOP_RECORD_ON                         = 0x09,
35         CECOP_RECORD_STATUS                     = 0x0A,
36         CECOP_RECORD_OFF                        = 0x0B,
37         CECOP_TEXT_VIEW_ON                      = 0x0D,
38         CECOP_RECORD_TV_SCREEN                  = 0x0F,
39         CECOP_GIVE_DECK_STATUS                  = 0x1A,
40         CECOP_DECK_STATUS                       = 0x1B,
41         CECOP_SET_MENU_LANGUAGE                 = 0x32,
42         CECOP_CLEAR_ANALOGUE_TIMER              = 0x33,     /* Spec 1.3A */
43         CECOP_SET_ANALOGUE_TIMER                = 0x34,     /* Spec 1.3A */
44         CECOP_TIMER_STATUS                      = 0x35,     /* Spec 1.3A */
45         CECOP_STANDBY                           = 0x36,
46         CECOP_PLAY                              = 0x41,
47         CECOP_DECK_CONTROL                      = 0x42,
48         CECOP_TIMER_CLEARED_STATUS              = 0x43,     /* Spec 1.3A */
49         CECOP_USER_CONTROL_PRESSED              = 0x44,
50         CECOP_USER_CONTROL_RELEASED             = 0x45,
51         CECOP_GIVE_OSD_NAME                     = 0x46,
52         CECOP_SET_OSD_NAME                      = 0x47,
53         CECOP_SET_OSD_STRING                    = 0x64,
54         CECOP_SET_TIMER_PROGRAM_TITLE           = 0x67, /* Spec 1.3A */
55         CECOP_SYSTEM_AUDIO_MODE_REQUEST         = 0x70, /* Spec 1.3A */
56         CECOP_GIVE_AUDIO_STATUS                 = 0x71, /* Spec 1.3A */
57         CECOP_SET_SYSTEM_AUDIO_MODE             = 0x72, /* Spec 1.3A */
58         CECOP_REPORT_AUDIO_STATUS               = 0x7A, /* Spec 1.3A */
59         CECOP_GIVE_SYSTEM_AUDIO_MODE_STATUS     = 0x7D, /* Spec 1.3A */
60         CECOP_SYSTEM_AUDIO_MODE_STATUS          = 0x7E, /* Spec 1.3A */
61         CECOP_ROUTING_CHANGE                    = 0x80,
62         CECOP_ROUTING_INFORMATION               = 0x81,
63         CECOP_ACTIVE_SOURCE                     = 0x82,
64         CECOP_GIVE_PHYSICAL_ADDRESS             = 0x83,
65         CECOP_REPORT_PHYSICAL_ADDRESS           = 0x84,
66         CECOP_REQUEST_ACTIVE_SOURCE             = 0x85,
67         CECOP_SET_STREAM_PATH                   = 0x86,
68         CECOP_DEVICE_VENDOR_ID                  = 0x87,
69         CECOP_VENDOR_COMMAND                    = 0x89,
70         CECOP_VENDOR_REMOTE_BUTTON_DOWN         = 0x8A,
71         CECOP_VENDOR_REMOTE_BUTTON_UP           = 0x8B,
72         CECOP_GIVE_DEVICE_VENDOR_ID             = 0x8C,
73         CECOP_MENU_REQUEST                      = 0x8D,
74         CECOP_MENU_STATUS                       = 0x8E,
75         CECOP_GIVE_DEVICE_POWER_STATUS          = 0x8F,
76         CECOP_REPORT_POWER_STATUS               = 0x90,
77         CECOP_GET_MENU_LANGUAGE                 = 0x91,
78         CECOP_SELECT_ANALOGUE_SERVICE           = 0x92,     /* Spec 1.3A */
79         CECOP_SELECT_DIGITAL_SERVICE            = 0x93,
80         CECOP_SET_DIGITAL_TIMER                 = 0x97,     /* Spec 1.3A */
81         CECOP_CLEAR_DIGITAL_TIMER               = 0x99,     /* Spec 1.3A */
82         CECOP_SET_AUDIO_RATE                    = 0x9A,     /* Spec 1.3A */
83         CECOP_INACTIVE_SOURCE                   = 0x9D,     /* Spec 1.3A */
84         CECOP_CEC_VERSION                       = 0x9E,     /* Spec 1.3A */
85         CECOP_GET_CEC_VERSION                   = 0x9F,     /* Spec 1.3A */
86         CECOP_VENDOR_COMMAND_WITH_ID            = 0xA0,     /* Spec 1.3A */
87         CECOP_CLEAR_EXTERNAL_TIMER              = 0xA1,     /* Spec 1.3A */
88         CECOP_SET_EXTERNAL_TIMER                = 0xA2,     /* Spec 1.3A */
89         CDCOP_HEADER                            = 0xF8,
90         CECOP_ABORT                             = 0xFF,
91
92         CECOP_REPORT_SHORT_AUDIO                = 0xA3,     /* Spec 1.4 */
93         CECOP_REQUEST_SHORT_AUDIO               = 0xA4,     /* Spec 1.4 */
94
95         CECOP_ARC_INITIATE                      = 0xC0,
96         CECOP_ARC_REPORT_INITIATED              = 0xC1,
97         CECOP_ARC_REPORT_TERMINATED             = 0xC2,
98
99         CECOP_ARC_REQUEST_INITIATION            = 0xC3,
100         CECOP_ARC_REQUEST_TERMINATION           = 0xC4,
101         CECOP_ARC_TERMINATE                     = 0xC5,
102
103 };
104
105 /* Operands for <Feature Abort> Opcode */
106 enum {
107         CECAR_UNRECOG_OPCODE            = 0x00,
108         CECAR_NOT_CORRECT_MODE,
109         CECAR_CANT_PROVIDE_SOURCE,
110         CECAR_INVALID_OPERAND,
111         CECAR_REFUSED
112 };
113
114 /* Operands for <Power Status> Opcode */
115 enum {
116         CEC_POWERSTATUS_ON              = 0x00,
117         CEC_POWERSTATUS_STANDBY         = 0x01,
118         CEC_POWERSTATUS_STANDBY_TO_ON   = 0x02,
119         CEC_POWERSTATUS_ON_TO_STANDBY   = 0x03,
120 };
121
122 enum {
123         EVENT_RX_FRAME,
124         EVENT_ENUMERATE,
125 };
126
127 #define MAKE_SRCDEST(src, dest)    ((src << 4) | dest)
128
129 #define MAX_CMD_SIZE 16
130
131 struct cec_framedata {
132         char srcdestaddr; /* Source in upper nybble, dest in lower nybble */
133         char opcode;
134         char args[MAX_CMD_SIZE];
135         char argcount;
136         char nextframeargcount;
137 };
138
139 struct cec_delayed_work {
140         struct delayed_work work;
141         int event;
142         void *data;
143 };
144
145 struct cec_device {
146         struct workqueue_struct *workqueue;
147         struct hdmi *hdmi;
148         int address_phy;
149         int address_logic;
150         int powerstatus;
151         char cecval[32];
152
153         int (*sendframe)(struct hdmi *, struct cec_framedata *);
154         int (*readframe)(struct hdmi *, struct cec_framedata *);
155         void (*setceclogicaddr)(struct hdmi *, int);
156 };
157
158 #ifdef DEBUG
159 #define CECDBG(format, ...) \
160                 pr_info(format, ## __VA_ARGS__)
161 #else
162 #define CECDBG(format, ...)
163 #endif
164
165 /*====================================
166 //used for cec key control direction  OK and back
167 ====================================*/
168 enum  {
169         S_CEC_MAKESURE   = 0x0,
170         S_CEC_UP         = 0x1,
171         S_CEC_DOWN       = 0x2,
172         S_CEC_LEFT       = 0x3,
173         S_CEC_RIGHT      = 0x4,
174         S_CEC_BACK       = 0x0d,
175         S_CEC_VENDORBACK = 0x91,
176 };
177
178 int rockchip_hdmi_cec_init(struct hdmi *hdmi,
179                            int (*sendframe)(struct hdmi *,
180                                             struct cec_framedata *),
181                            int (*readframe)(struct hdmi *,
182                                             struct cec_framedata *),
183                            void (*setceclogicaddr)(struct hdmi *, int));
184 void rockchip_hdmi_cec_set_pa(int devpa);
185 void rockchip_hdmi_cec_submit_work(int event, int delay, void *data);
186 #endif /* __HDMI_CEC_H__ */