Jinsuk Kim | 62195dc | 2014-02-19 10:21:35 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_INCLUDE_HARDWARE_HDMI_CEC_H |
| 18 | #define ANDROID_INCLUDE_HARDWARE_HDMI_CEC_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/cdefs.h> |
| 22 | |
| 23 | #include <hardware/hardware.h> |
| 24 | |
| 25 | __BEGIN_DECLS |
| 26 | |
| 27 | #define HDMI_CEC_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0) |
| 28 | #define HDMI_CEC_MODULE_API_VERSION_CURRENT HDMI_MODULE_API_VERSION_1_0 |
| 29 | |
| 30 | #define HDMI_CEC_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0) |
| 31 | #define HDMI_CEC_DEVICE_API_VERSION_CURRENT HDMI_DEVICE_API_VERSION_1_0 |
| 32 | |
| 33 | #define HDMI_CEC_HARDWARE_MODULE_ID "hdmi_cec" |
| 34 | #define HDMI_CEC_HARDWARE_INTERFACE "hdmi_cec_hw_if" |
| 35 | |
| 36 | typedef enum cec_device_type { |
| 37 | CEC_DEVICE_TV = 0, |
| 38 | CEC_DEVICE_RECORDER = 1, |
| 39 | CEC_DEVICE_RESERVED = 2, |
| 40 | CEC_DEVICE_TUNER = 3, |
| 41 | CEC_DEVICE_PLAYBACK = 4, |
| 42 | CEC_DEVICE_AUDIO_SYSTEM = 5, |
| 43 | CEC_DEVICE_MAX = CEC_DEVICE_AUDIO_SYSTEM |
| 44 | } cec_device_type_t; |
| 45 | |
| 46 | typedef enum cec_logical_address { |
| 47 | CEC_ADDR_TV = 0, |
| 48 | CEC_ADDR_RECORDER_1 = 1, |
| 49 | CEC_ADDR_RECORDER_2 = 2, |
| 50 | CEC_ADDR_TUNER_1 = 3, |
| 51 | CEC_ADDR_PLAYBACK_1 = 4, |
| 52 | CEC_ADDR_AUDIO_SYSTEM = 5, |
| 53 | CEC_ADDR_TUNER_2 = 6, |
| 54 | CEC_ADDR_TUNER_3 = 7, |
| 55 | CEC_ADDR_PLAYBACK_2 = 8, |
| 56 | CEC_ADDR_RECORDER_3 = 9, |
| 57 | CEC_ADDR_TUNER_4 = 10, |
| 58 | CEC_ADDR_PLAYBACK_3 = 11, |
| 59 | CEC_ADDR_RESERVED_1 = 12, |
| 60 | CEC_ADDR_RESERVED_2 = 13, |
| 61 | CEC_ADDR_FREE_USE = 14, |
| 62 | CEC_ADDR_UNREGISTERED = 15, |
| 63 | CEC_ADDR_BROADCAST = 15 |
| 64 | } cec_logical_address_t; |
| 65 | |
| 66 | /* |
| 67 | * HDMI CEC messages |
| 68 | */ |
| 69 | enum cec_message_type { |
| 70 | CEC_MESSAGE_FEATURE_ABORT = 0x00, |
| 71 | CEC_MESSAGE_IMAGE_VIEW_ON = 0x04, |
| 72 | CEC_MESSAGE_TUNER_STEP_INCREMENT = 0x05, |
| 73 | CEC_MESSAGE_TUNER_STEP_DECREMENT = 0x06, |
| 74 | CEC_MESSAGE_TUNER_DEVICE_STATUS = 0x07, |
| 75 | CEC_MESSAGE_GIVE_TUNER_DEVICE_STATUS = 0x08, |
| 76 | CEC_MESSAGE_RECORD_ON = 0x09, |
| 77 | CEC_MESSAGE_RECORD_STATUS = 0x0A, |
| 78 | CEC_MESSAGE_RECORD_OFF = 0x0B, |
| 79 | CEC_MESSAGE_TEXT_VIEW_ON = 0x0D, |
| 80 | CEC_MESSAGE_RECORD_TV_SCREEN = 0x0F, |
| 81 | CEC_MESSAGE_GIVE_DECK_STATUS = 0x1A, |
| 82 | CEC_MESSAGE_DECK_STATUS = 0x1B, |
| 83 | CEC_MESSAGE_SET_MENU_LANGUAGE = 0x32, |
| 84 | CEC_MESSAGE_CLEAR_ANALOG_TIMER = 0x33, |
| 85 | CEC_MESSAGE_SET_ANALOG_TIMER = 0x34, |
| 86 | CEC_MESSAGE_TIMER_STATUS = 0x35, |
| 87 | CEC_MESSAGE_STANDBY = 0x36, |
| 88 | CEC_MESSAGE_PLAY = 0x41, |
| 89 | CEC_MESSAGE_DECK_CONTROL = 0x42, |
| 90 | CEC_MESSAGE_TIMER_CLEARED_STATUS = 0x043, |
| 91 | CEC_MESSAGE_USER_CONTROL_PRESSED = 0x44, |
| 92 | CEC_MESSAGE_USER_CONTROL_RELEASED = 0x45, |
| 93 | CEC_MESSAGE_GET_OSD_NAME = 0x46, |
| 94 | CEC_MESSAGE_SET_OSD_NAME = 0x47, |
| 95 | CEC_MESSAGE_SET_OSD_STRING = 0x64, |
| 96 | CEC_MESSAGE_SET_TIMER_PROGRAM_TITLE = 0x67, |
| 97 | CEC_MESSAGE_SYSTEM_AUDIO_MODE_REQUEST = 0x70, |
| 98 | CEC_MESSAGE_GIVE_AUDIO_STATUS = 0x71, |
| 99 | CEC_MESSAGE_SET_SYSTEM_AUDIO_MODE = 0x72, |
| 100 | CEC_MESSAGE_REPORT_AUDIO_STATUS = 0x7A, |
| 101 | CEC_MESSAGE_GIVE_SYSTEM_AUDIO_MODE_STATUS = 0x7D, |
| 102 | CEC_MESSAGE_SYSTEM_AUDIO_MODE_STATUS = 0x7E, |
| 103 | CEC_MESSAGE_ROUTING_CHANGE = 0x80, |
| 104 | CEC_MESSAGE_ROUTING_INFORMATION = 0x81, |
| 105 | CEC_MESSAGE_ACTIVE_SOURCE = 0x82, |
| 106 | CEC_MESSAGE_GIVE_PHYSICAL_ADDRESS = 0x83, |
| 107 | CEC_MESSAGE_REPORT_PHYSICAL_ADDRESS = 0x84, |
| 108 | CEC_MESSAGE_REQUEST_ACTIVE_SOURCE = 0x85, |
| 109 | CEC_MESSAGE_SET_STREAM_PATH = 0x86, |
| 110 | CEC_MESSAGE_DEVICE_VENDOR_ID = 0x87, |
| 111 | CEC_MESSAGE_VENDOR_COMMAND = 0x89, |
| 112 | CEC_MESSAGE_VENDOR_REMOTE_BUTTON_DOWN = 0x8A, |
| 113 | CEC_MESSAGE_VENDOR_REMOTE_BUTTON_UP = 0x8B, |
| 114 | CEC_MESSAGE_GIVE_DEVICE_VENDOR_ID = 0x8C, |
| 115 | CEC_MESSAGE_MENU_REQUEST = 0x8D, |
| 116 | CEC_MESSAGE_MENU_STATUS = 0x8E, |
| 117 | CEC_MESSAGE_GIVE_DEVICE_POWER_STATUS = 0x8F, |
| 118 | CEC_MESSAGE_REPORT_POWER_STATUS = 0x90, |
| 119 | CEC_MESSAGE_GET_MENU_LANGUAGE = 0x91, |
| 120 | CEC_MESSAGE_SELECT_ANALOG_SERVICE = 0x92, |
| 121 | CEC_MESSAGE_SELECT_DIGITAL_SERVICE = 0x93, |
| 122 | CEC_MESSAGE_SET_DIGITAL_TIMER = 0x97, |
| 123 | CEC_MESSAGE_CLEAR_DIGITAL_TIMER = 0x99, |
| 124 | CEC_MESSAGE_SET_AUDIO_RATE = 0x9A, |
| 125 | CEC_MESSAGE_INACTIVE_SOURCE = 0x9D, |
| 126 | CEC_MESSAGE_CEC_VERSION = 0x9E, |
| 127 | CEC_MESSAGE_GET_CEC_VERSION = 0x9F, |
| 128 | CEC_MESSAGE_VENDOR_COMMAND_WITH_ID = 0xA0, |
| 129 | CEC_MESSAGE_CLEAR_EXTERNAL_TIMER = 0xA1, |
| 130 | CEC_MESSAGE_SET_EXTERNAL_TIMER = 0xA2 |
| 131 | }; |
| 132 | |
| 133 | /* |
| 134 | * HDMI event type. used for hdmi_event_t. |
| 135 | */ |
| 136 | enum { |
| 137 | HDMI_EVENT_CEC_MESSAGE = 1, |
| 138 | HDMI_EVENT_HOT_PLUG = 2 |
| 139 | }; |
| 140 | |
| 141 | /* |
| 142 | * HDMI hotplug event type. Used when the event |
| 143 | * type is HDMI_EVENT_HOT_PLUG. |
| 144 | */ |
| 145 | enum { |
| 146 | HDMI_NOT_CONNECTED = 0, |
| 147 | HDMI_CONNECTED = 1 |
| 148 | }; |
| 149 | |
| 150 | /* |
| 151 | * Maximum length in bytes of cec message body (exclude header block), |
| 152 | * should not exceed 16 (spec CEC 6 Frame Description) |
| 153 | */ |
| 154 | #define CEC_MESSAGE_BODY_MAX_LENGTH 16 |
| 155 | |
| 156 | typedef struct cec_message { |
| 157 | /* |
| 158 | * logical address of sender |
| 159 | */ |
| 160 | cec_logical_address_t initiator; |
| 161 | |
| 162 | /* |
| 163 | * logical address of receiver |
| 164 | */ |
| 165 | cec_logical_address_t destination; |
| 166 | |
| 167 | /* |
| 168 | * length in bytes of body, range [0, CEC_MESSAGE_BODY_MAX_LENGTH] |
| 169 | */ |
| 170 | size_t length; |
| 171 | unsigned char body[CEC_MESSAGE_BODY_MAX_LENGTH]; |
| 172 | } cec_message_t; |
| 173 | |
| 174 | typedef struct hotplug_event { |
| 175 | /* |
| 176 | * true if the cable is connected; otherwise false. |
| 177 | */ |
| 178 | int connected; |
| 179 | } hotplug_event_t; |
| 180 | |
| 181 | /* |
| 182 | * HDMI event generated from HAL. |
| 183 | */ |
| 184 | typedef struct hdmi_event { |
| 185 | int type; |
| 186 | struct hdmi_cec_device* dev; |
| 187 | union { |
| 188 | cec_message_t cec; |
| 189 | hotplug_event_t hotplug; |
| 190 | }; |
| 191 | } hdmi_event_t; |
| 192 | |
| 193 | /* |
| 194 | * Callback function type that will be called by HAL implementation. |
| 195 | * Services can not close/open the device in the callback. |
| 196 | */ |
Jinsuk Kim | 70ae777 | 2014-03-06 19:25:19 +0900 | [diff] [blame^] | 197 | typedef void (*event_callback_t)(const hdmi_event_t* event, void* arg); |
Jinsuk Kim | 62195dc | 2014-02-19 10:21:35 +0900 | [diff] [blame] | 198 | |
| 199 | typedef struct hdmi_cec_module { |
| 200 | struct hw_module_t common; |
| 201 | } hdmi_module_t; |
| 202 | |
| 203 | /* |
| 204 | * HDMI-CEC HAL interface definition. |
| 205 | */ |
| 206 | typedef struct hdmi_cec_device { |
| 207 | struct hw_device_t common; |
| 208 | |
| 209 | /* |
| 210 | * (*allocate_logical_address)() allocates a new logical address |
| 211 | * for a given device type. The address is written to addr. The HAL |
| 212 | * implementation is also expected to configure itself to start receiving |
| 213 | * the messages addressed to the allocated one. If allocation |
| 214 | * is not successful the addr will be set to CEC_ADDR_UNREGISTERED. |
| 215 | * |
| 216 | * Returns 0 on success or -errno on error. |
Jinsuk Kim | 62195dc | 2014-02-19 10:21:35 +0900 | [diff] [blame] | 217 | */ |
| 218 | int (*allocate_logical_address)(const struct hdmi_cec_device* dev, |
| 219 | int device_type, cec_logical_address_t* addr); |
| 220 | |
| 221 | /* |
| 222 | * (*get_physical_address)() returns the CEC physical address. The |
| 223 | * address is written to addr. |
| 224 | * |
| 225 | * The physical address depends on the topology of the network formed |
| 226 | * by connected HDMI devices. It is therefore likely to change if the cable |
| 227 | * is plugged off and on again. It is advised to call get_physical_address |
| 228 | * to get the updated address when hot plug event takes place. |
| 229 | * |
| 230 | * Returns 0 on success or -errno on error. |
| 231 | */ |
| 232 | int (*get_physical_address)(const struct hdmi_cec_device* dev, uint16_t* addr); |
| 233 | |
| 234 | /* |
| 235 | * (*send_message)() transmits HDMI-CEC message to other HDMI device. |
| 236 | * |
| 237 | * Returns 0 on success or -errno on error. |
| 238 | */ |
| 239 | int (*send_message)(const struct hdmi_cec_device* dev, |
Jinsuk Kim | 70ae777 | 2014-03-06 19:25:19 +0900 | [diff] [blame^] | 240 | const cec_message_t*); |
Jinsuk Kim | 62195dc | 2014-02-19 10:21:35 +0900 | [diff] [blame] | 241 | |
| 242 | /* |
| 243 | * (*register_event_callback)() registers a callback that HDMI-CEC HAL |
| 244 | * can later use for incoming CEC messages or internal HDMI events. |
Jinsuk Kim | 70ae777 | 2014-03-06 19:25:19 +0900 | [diff] [blame^] | 245 | * When calling from C++, use the argument arg to pass the calling object. |
| 246 | * It will be passed back when the callback is invoked so that the context |
| 247 | * can be retrieved. |
Jinsuk Kim | 62195dc | 2014-02-19 10:21:35 +0900 | [diff] [blame] | 248 | */ |
| 249 | void (*register_event_callback)(const struct hdmi_cec_device* dev, |
Jinsuk Kim | 70ae777 | 2014-03-06 19:25:19 +0900 | [diff] [blame^] | 250 | event_callback_t callback, void* arg); |
Jinsuk Kim | 62195dc | 2014-02-19 10:21:35 +0900 | [diff] [blame] | 251 | |
| 252 | /* |
| 253 | * (*get_version)() returns the CEC version supported by underlying |
| 254 | * hardware. The version this HAL interface is based on is 0x04, |
| 255 | * which corresponds to 1.3a. |
| 256 | */ |
| 257 | void (*get_version)(const struct hdmi_cec_device* dev, int* version); |
| 258 | |
| 259 | /* |
| 260 | * (*get_vendor_id)() returns the identifier of the vendor. It is |
| 261 | * the 24-bit unique company ID obtained from the IEEE Registration |
| 262 | * Authority Committee (RAC). |
| 263 | */ |
| 264 | void (*get_vendor_id)(const struct hdmi_cec_device* dev, uint32_t* vendor_id); |
| 265 | |
| 266 | /* Reserved for future use to maximum 16 functions. Must be NULL. */ |
| 267 | void* reserved[16 - 6]; |
| 268 | } hdmi_cec_device_t; |
| 269 | |
| 270 | /** convenience API for opening and closing a device */ |
| 271 | |
| 272 | static inline int hdmi_cec_open(const struct hw_module_t* module, |
| 273 | struct hdmi_cec_device** device) { |
| 274 | return module->methods->open(module, |
| 275 | HDMI_CEC_HARDWARE_INTERFACE, (struct hw_device_t**)device); |
| 276 | } |
| 277 | |
| 278 | static inline int hdmi_cec_close(struct hdmi_cec_device* device) { |
| 279 | return device->common.close(&device->common); |
| 280 | } |
| 281 | |
| 282 | __END_DECLS |
| 283 | |
| 284 | #endif /* ANDROID_INCLUDE_HARDWARE_HDMI_CEC_H */ |