Hans Verkuil | ab15d24 | 2018-02-07 09:05:46 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 2 | /* |
| 3 | * cec - HDMI Consumer Electronics Control support header |
| 4 | * |
| 5 | * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _MEDIA_CEC_H |
| 9 | #define _MEDIA_CEC_H |
| 10 | |
| 11 | #include <linux/poll.h> |
| 12 | #include <linux/fs.h> |
| 13 | #include <linux/debugfs.h> |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/cdev.h> |
| 16 | #include <linux/kthread.h> |
| 17 | #include <linux/timer.h> |
| 18 | #include <linux/cec-funcs.h> |
| 19 | #include <media/rc-core.h> |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 20 | |
Hans Verkuil | ee0c503 | 2017-08-04 06:41:51 -0400 | [diff] [blame] | 21 | #define CEC_CAP_DEFAULTS (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | \ |
| 22 | CEC_CAP_PASSTHROUGH | CEC_CAP_RC) |
| 23 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 24 | /** |
| 25 | * struct cec_devnode - cec device node |
| 26 | * @dev: cec device |
| 27 | * @cdev: cec character device |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 28 | * @minor: device node minor number |
| 29 | * @registered: the device was correctly registered |
| 30 | * @unregistered: the device was unregistered |
| 31 | * @fhs_lock: lock to control access to the filehandle list |
| 32 | * @fhs: the list of open filehandles (cec_fh) |
| 33 | * |
| 34 | * This structure represents a cec-related device node. |
| 35 | * |
| 36 | * The @parent is a physical device. It must be set by core or device drivers |
| 37 | * before registering the node. |
| 38 | */ |
| 39 | struct cec_devnode { |
| 40 | /* sysfs */ |
| 41 | struct device dev; |
| 42 | struct cdev cdev; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 43 | |
| 44 | /* device info */ |
| 45 | int minor; |
| 46 | bool registered; |
| 47 | bool unregistered; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 48 | struct list_head fhs; |
Hans Verkuil | 62148f0 | 2016-08-02 08:11:00 -0300 | [diff] [blame] | 49 | struct mutex lock; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct cec_adapter; |
| 53 | struct cec_data; |
Hans Verkuil | ea5c8ef | 2017-07-11 03:30:42 -0300 | [diff] [blame] | 54 | struct cec_pin; |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 55 | struct cec_notifier; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 56 | |
| 57 | struct cec_data { |
| 58 | struct list_head list; |
| 59 | struct list_head xfer_list; |
| 60 | struct cec_adapter *adap; |
| 61 | struct cec_msg msg; |
| 62 | struct cec_fh *fh; |
| 63 | struct delayed_work work; |
| 64 | struct completion c; |
| 65 | u8 attempts; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 66 | bool blocking; |
| 67 | bool completed; |
| 68 | }; |
| 69 | |
| 70 | struct cec_msg_entry { |
| 71 | struct list_head list; |
| 72 | struct cec_msg msg; |
| 73 | }; |
| 74 | |
Hans Verkuil | 6b2bbb0 | 2017-07-11 03:30:39 -0300 | [diff] [blame] | 75 | struct cec_event_entry { |
| 76 | struct list_head list; |
| 77 | struct cec_event ev; |
| 78 | }; |
| 79 | |
| 80 | #define CEC_NUM_CORE_EVENTS 2 |
Hans Verkuil | 4786b0d | 2018-06-28 07:43:46 -0400 | [diff] [blame] | 81 | #define CEC_NUM_EVENTS CEC_EVENT_PIN_5V_HIGH |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 82 | |
| 83 | struct cec_fh { |
| 84 | struct list_head list; |
| 85 | struct list_head xfer_list; |
| 86 | struct cec_adapter *adap; |
| 87 | u8 mode_initiator; |
| 88 | u8 mode_follower; |
| 89 | |
| 90 | /* Events */ |
| 91 | wait_queue_head_t wait; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 92 | struct mutex lock; |
Hans Verkuil | 6b2bbb0 | 2017-07-11 03:30:39 -0300 | [diff] [blame] | 93 | struct list_head events[CEC_NUM_EVENTS]; /* queued events */ |
Hans Verkuil | 6ec1cbf | 2018-03-06 16:20:00 -0500 | [diff] [blame] | 94 | u16 queued_events[CEC_NUM_EVENTS]; |
Hans Verkuil | 6b2bbb0 | 2017-07-11 03:30:39 -0300 | [diff] [blame] | 95 | unsigned int total_queued_events; |
| 96 | struct cec_event_entry core_events[CEC_NUM_CORE_EVENTS]; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 97 | struct list_head msgs; /* queued messages */ |
| 98 | unsigned int queued_msgs; |
| 99 | }; |
| 100 | |
| 101 | #define CEC_SIGNAL_FREE_TIME_RETRY 3 |
| 102 | #define CEC_SIGNAL_FREE_TIME_NEW_INITIATOR 5 |
| 103 | #define CEC_SIGNAL_FREE_TIME_NEXT_XFER 7 |
| 104 | |
| 105 | /* The nominal data bit period is 2.4 ms */ |
| 106 | #define CEC_FREE_TIME_TO_USEC(ft) ((ft) * 2400) |
| 107 | |
| 108 | struct cec_adap_ops { |
| 109 | /* Low-level callbacks */ |
| 110 | int (*adap_enable)(struct cec_adapter *adap, bool enable); |
| 111 | int (*adap_monitor_all_enable)(struct cec_adapter *adap, bool enable); |
Hans Verkuil | 48ea2e9 | 2017-11-05 07:36:36 -0500 | [diff] [blame] | 112 | int (*adap_monitor_pin_enable)(struct cec_adapter *adap, bool enable); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 113 | int (*adap_log_addr)(struct cec_adapter *adap, u8 logical_addr); |
| 114 | int (*adap_transmit)(struct cec_adapter *adap, u8 attempts, |
| 115 | u32 signal_free_time, struct cec_msg *msg); |
| 116 | void (*adap_status)(struct cec_adapter *adap, struct seq_file *file); |
Hans Verkuil | e6259b5 | 2017-07-11 03:30:36 -0300 | [diff] [blame] | 117 | void (*adap_free)(struct cec_adapter *adap); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 118 | |
Hans Verkuil | 9ca400c | 2017-10-31 09:55:09 -0400 | [diff] [blame] | 119 | /* Error injection callbacks */ |
| 120 | int (*error_inj_show)(struct cec_adapter *adap, struct seq_file *sf); |
| 121 | bool (*error_inj_parse_line)(struct cec_adapter *adap, char *line); |
| 122 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 123 | /* High-level CEC message callback */ |
| 124 | int (*received)(struct cec_adapter *adap, struct cec_msg *msg); |
| 125 | }; |
| 126 | |
| 127 | /* |
| 128 | * The minimum message length you can receive (excepting poll messages) is 2. |
| 129 | * With a transfer rate of at most 36 bytes per second this makes 18 messages |
| 130 | * per second worst case. |
| 131 | * |
Hans Verkuil | 11065f8 | 2016-07-17 11:40:05 -0300 | [diff] [blame] | 132 | * We queue at most 3 seconds worth of received messages. The CEC specification |
| 133 | * requires that messages are replied to within a second, so 3 seconds should |
| 134 | * give more than enough margin. Since most messages are actually more than 2 |
| 135 | * bytes, this is in practice a lot more than 3 seconds. |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 136 | */ |
Hans Verkuil | 11065f8 | 2016-07-17 11:40:05 -0300 | [diff] [blame] | 137 | #define CEC_MAX_MSG_RX_QUEUE_SZ (18 * 3) |
| 138 | |
| 139 | /* |
| 140 | * The transmit queue is limited to 1 second worth of messages (worst case). |
| 141 | * Messages can be transmitted by userspace and kernel space. But for both it |
| 142 | * makes no sense to have a lot of messages queued up. One second seems |
| 143 | * reasonable. |
| 144 | */ |
| 145 | #define CEC_MAX_MSG_TX_QUEUE_SZ (18 * 1) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 146 | |
Hans Verkuil | e233f81 | 2020-06-20 12:16:41 +0200 | [diff] [blame] | 147 | /** |
| 148 | * struct cec_adapter - cec adapter structure |
| 149 | * @owner: module owner |
| 150 | * @name: name of the CEC adapter |
| 151 | * @devnode: device node for the /dev/cecX device |
| 152 | * @lock: mutex controlling access to this structure |
| 153 | * @rc: remote control device |
| 154 | * @transmit_queue: queue of pending transmits |
| 155 | * @transmit_queue_sz: number of pending transmits |
| 156 | * @wait_queue: queue of transmits waiting for a reply |
| 157 | * @transmitting: CEC messages currently being transmitted |
| 158 | * @transmit_in_progress: true if a transmit is in progress |
| 159 | * @kthread_config: kthread used to configure a CEC adapter |
| 160 | * @config_completion: used to signal completion of the config kthread |
| 161 | * @kthread: main CEC processing thread |
| 162 | * @kthread_waitq: main CEC processing wait_queue |
| 163 | * @ops: cec adapter ops |
| 164 | * @priv: cec driver's private data |
| 165 | * @capabilities: cec adapter capabilities |
| 166 | * @available_log_addrs: maximum number of available logical addresses |
| 167 | * @phys_addr: the current physical address |
| 168 | * @needs_hpd: if true, then the HDMI HotPlug Detect pin must be high |
| 169 | * in order to transmit or receive CEC messages. This is usually a HW |
| 170 | * limitation. |
| 171 | * @is_configuring: the CEC adapter is configuring (i.e. claiming LAs) |
| 172 | * @is_configured: the CEC adapter is configured (i.e. has claimed LAs) |
| 173 | * @cec_pin_is_high: if true then the CEC pin is high. Only used with the |
| 174 | * CEC pin framework. |
Jeff Chase | 98f803c | 2020-06-23 01:59:49 +0200 | [diff] [blame] | 175 | * @adap_controls_phys_addr: if true, then the CEC adapter controls the |
| 176 | * physical address, i.e. the CEC hardware can detect HPD changes and |
| 177 | * read the EDID and is not dependent on an external HDMI driver. |
| 178 | * Drivers that need this can set this field to true after the |
| 179 | * cec_allocate_adapter() call. |
Hans Verkuil | e233f81 | 2020-06-20 12:16:41 +0200 | [diff] [blame] | 180 | * @last_initiator: the initiator of the last transmitted message. |
| 181 | * @monitor_all_cnt: number of filehandles monitoring all msgs |
| 182 | * @monitor_pin_cnt: number of filehandles monitoring pin changes |
| 183 | * @follower_cnt: number of filehandles in follower mode |
| 184 | * @cec_follower: filehandle of the exclusive follower |
| 185 | * @cec_initiator: filehandle of the exclusive initiator |
| 186 | * @passthrough: if true, then the exclusive follower is in |
| 187 | * passthrough mode. |
| 188 | * @log_addrs: current logical addresses |
| 189 | * @conn_info: current connector info |
| 190 | * @tx_timeouts: number of transmit timeouts |
| 191 | * @notifier: CEC notifier |
| 192 | * @pin: CEC pin status struct |
| 193 | * @cec_dir: debugfs cec directory |
| 194 | * @status_file: debugfs cec status file |
| 195 | * @error_inj_file: debugfs cec error injection file |
| 196 | * @sequence: transmit sequence counter |
| 197 | * @input_phys: remote control input_phys name |
| 198 | * |
| 199 | * This structure represents a cec adapter. |
| 200 | */ |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 201 | struct cec_adapter { |
| 202 | struct module *owner; |
| 203 | char name[32]; |
| 204 | struct cec_devnode devnode; |
| 205 | struct mutex lock; |
| 206 | struct rc_dev *rc; |
| 207 | |
| 208 | struct list_head transmit_queue; |
Hans Verkuil | 11065f8 | 2016-07-17 11:40:05 -0300 | [diff] [blame] | 209 | unsigned int transmit_queue_sz; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 210 | struct list_head wait_queue; |
| 211 | struct cec_data *transmitting; |
Hans Verkuil | 32804fc | 2018-10-19 03:55:34 -0400 | [diff] [blame] | 212 | bool transmit_in_progress; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 213 | |
| 214 | struct task_struct *kthread_config; |
| 215 | struct completion config_completion; |
| 216 | |
| 217 | struct task_struct *kthread; |
| 218 | wait_queue_head_t kthread_waitq; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 219 | |
| 220 | const struct cec_adap_ops *ops; |
| 221 | void *priv; |
| 222 | u32 capabilities; |
| 223 | u8 available_log_addrs; |
| 224 | |
| 225 | u16 phys_addr; |
Hans Verkuil | f902c1e | 2017-06-07 11:46:12 -0300 | [diff] [blame] | 226 | bool needs_hpd; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 227 | bool is_configuring; |
| 228 | bool is_configured; |
Hans Verkuil | 28e11b1 | 2017-08-20 06:53:10 -0400 | [diff] [blame] | 229 | bool cec_pin_is_high; |
Jeff Chase | 98f803c | 2020-06-23 01:59:49 +0200 | [diff] [blame] | 230 | bool adap_controls_phys_addr; |
Hans Verkuil | 7d867a1 | 2018-10-05 08:00:21 -0400 | [diff] [blame] | 231 | u8 last_initiator; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 232 | u32 monitor_all_cnt; |
Hans Verkuil | b8d62f5 | 2017-07-11 03:30:41 -0300 | [diff] [blame] | 233 | u32 monitor_pin_cnt; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 234 | u32 follower_cnt; |
| 235 | struct cec_fh *cec_follower; |
| 236 | struct cec_fh *cec_initiator; |
| 237 | bool passthrough; |
| 238 | struct cec_log_addrs log_addrs; |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 239 | struct cec_connector_info conn_info; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 240 | |
Hans Verkuil | bb789e0 | 2017-07-11 03:30:34 -0300 | [diff] [blame] | 241 | u32 tx_timeouts; |
| 242 | |
Hans Verkuil | e94c328 | 2017-05-28 05:58:04 -0300 | [diff] [blame] | 243 | #ifdef CONFIG_CEC_NOTIFIER |
Hans Verkuil | e3a93ad | 2016-12-13 12:15:57 -0200 | [diff] [blame] | 244 | struct cec_notifier *notifier; |
| 245 | #endif |
Hans Verkuil | ea5c8ef | 2017-07-11 03:30:42 -0300 | [diff] [blame] | 246 | #ifdef CONFIG_CEC_PIN |
| 247 | struct cec_pin *pin; |
| 248 | #endif |
Hans Verkuil | e3a93ad | 2016-12-13 12:15:57 -0200 | [diff] [blame] | 249 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 250 | struct dentry *cec_dir; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 251 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 252 | u32 sequence; |
| 253 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 254 | char input_phys[32]; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 255 | }; |
| 256 | |
Jose Abreu | 0b0b97d | 2017-03-24 13:47:52 -0300 | [diff] [blame] | 257 | static inline void *cec_get_drvdata(const struct cec_adapter *adap) |
| 258 | { |
| 259 | return adap->priv; |
| 260 | } |
| 261 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 262 | static inline bool cec_has_log_addr(const struct cec_adapter *adap, u8 log_addr) |
| 263 | { |
| 264 | return adap->log_addrs.log_addr_mask & (1 << log_addr); |
| 265 | } |
| 266 | |
| 267 | static inline bool cec_is_sink(const struct cec_adapter *adap) |
| 268 | { |
| 269 | return adap->phys_addr == 0; |
| 270 | } |
| 271 | |
Hans Verkuil | c8959a3 | 2017-11-22 04:12:39 -0500 | [diff] [blame] | 272 | /** |
| 273 | * cec_is_registered() - is the CEC adapter registered? |
| 274 | * |
| 275 | * @adap: the CEC adapter, may be NULL. |
| 276 | * |
| 277 | * Return: true if the adapter is registered, false otherwise. |
| 278 | */ |
| 279 | static inline bool cec_is_registered(const struct cec_adapter *adap) |
| 280 | { |
| 281 | return adap && adap->devnode.registered; |
| 282 | } |
| 283 | |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 284 | #define cec_phys_addr_exp(pa) \ |
| 285 | ((pa) >> 12), ((pa) >> 8) & 0xf, ((pa) >> 4) & 0xf, (pa) & 0xf |
| 286 | |
Hans Verkuil | 23111ec | 2017-06-07 11:46:08 -0300 | [diff] [blame] | 287 | struct edid; |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 288 | struct drm_connector; |
Hans Verkuil | 23111ec | 2017-06-07 11:46:08 -0300 | [diff] [blame] | 289 | |
Hans Verkuil | f9f314f | 2017-06-08 15:37:44 -0300 | [diff] [blame] | 290 | #if IS_REACHABLE(CONFIG_CEC_CORE) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 291 | struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, |
Hans Verkuil | f51e808 | 2016-11-25 06:23:34 -0200 | [diff] [blame] | 292 | void *priv, const char *name, u32 caps, u8 available_las); |
| 293 | int cec_register_adapter(struct cec_adapter *adap, struct device *parent); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 294 | void cec_unregister_adapter(struct cec_adapter *adap); |
| 295 | void cec_delete_adapter(struct cec_adapter *adap); |
| 296 | |
| 297 | int cec_s_log_addrs(struct cec_adapter *adap, struct cec_log_addrs *log_addrs, |
| 298 | bool block); |
| 299 | void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, |
| 300 | bool block); |
Hans Verkuil | 23111ec | 2017-06-07 11:46:08 -0300 | [diff] [blame] | 301 | void cec_s_phys_addr_from_edid(struct cec_adapter *adap, |
| 302 | const struct edid *edid); |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 303 | void cec_s_conn_info(struct cec_adapter *adap, |
| 304 | const struct cec_connector_info *conn_info); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 305 | int cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg, |
| 306 | bool block); |
| 307 | |
| 308 | /* Called by the adapter */ |
Hans Verkuil | 0861ad1 | 2017-07-11 03:30:35 -0300 | [diff] [blame] | 309 | void cec_transmit_done_ts(struct cec_adapter *adap, u8 status, |
| 310 | u8 arb_lost_cnt, u8 nack_cnt, u8 low_drive_cnt, |
| 311 | u8 error_cnt, ktime_t ts); |
| 312 | |
| 313 | static inline void cec_transmit_done(struct cec_adapter *adap, u8 status, |
| 314 | u8 arb_lost_cnt, u8 nack_cnt, |
| 315 | u8 low_drive_cnt, u8 error_cnt) |
| 316 | { |
| 317 | cec_transmit_done_ts(adap, status, arb_lost_cnt, nack_cnt, |
| 318 | low_drive_cnt, error_cnt, ktime_get()); |
| 319 | } |
Hans Verkuil | c94cdc1 | 2017-06-07 11:46:10 -0300 | [diff] [blame] | 320 | /* |
| 321 | * Simplified version of cec_transmit_done for hardware that doesn't retry |
| 322 | * failed transmits. So this is always just one attempt in which case |
| 323 | * the status is sufficient. |
| 324 | */ |
Hans Verkuil | 0861ad1 | 2017-07-11 03:30:35 -0300 | [diff] [blame] | 325 | void cec_transmit_attempt_done_ts(struct cec_adapter *adap, |
| 326 | u8 status, ktime_t ts); |
| 327 | |
| 328 | static inline void cec_transmit_attempt_done(struct cec_adapter *adap, |
| 329 | u8 status) |
| 330 | { |
| 331 | cec_transmit_attempt_done_ts(adap, status, ktime_get()); |
| 332 | } |
| 333 | |
| 334 | void cec_received_msg_ts(struct cec_adapter *adap, |
| 335 | struct cec_msg *msg, ktime_t ts); |
| 336 | |
| 337 | static inline void cec_received_msg(struct cec_adapter *adap, |
| 338 | struct cec_msg *msg) |
| 339 | { |
| 340 | cec_received_msg_ts(adap, msg, ktime_get()); |
| 341 | } |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 342 | |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 343 | /** |
Hans Verkuil | 9a6b2a8 | 2017-08-15 15:26:25 -0400 | [diff] [blame] | 344 | * cec_queue_pin_cec_event() - queue a CEC pin event with a given timestamp. |
Hans Verkuil | b8d62f5 | 2017-07-11 03:30:41 -0300 | [diff] [blame] | 345 | * |
| 346 | * @adap: pointer to the cec adapter |
Hans Verkuil | 9a6b2a8 | 2017-08-15 15:26:25 -0400 | [diff] [blame] | 347 | * @is_high: when true the CEC pin is high, otherwise it is low |
Hans Verkuil | 6ec1cbf | 2018-03-06 16:20:00 -0500 | [diff] [blame] | 348 | * @dropped_events: when true some events were dropped |
Hans Verkuil | b8d62f5 | 2017-07-11 03:30:41 -0300 | [diff] [blame] | 349 | * @ts: the timestamp for this event |
| 350 | * |
| 351 | */ |
Hans Verkuil | 6ec1cbf | 2018-03-06 16:20:00 -0500 | [diff] [blame] | 352 | void cec_queue_pin_cec_event(struct cec_adapter *adap, bool is_high, |
| 353 | bool dropped_events, ktime_t ts); |
Hans Verkuil | b8d62f5 | 2017-07-11 03:30:41 -0300 | [diff] [blame] | 354 | |
| 355 | /** |
Hans Verkuil | 333ef6b | 2017-08-15 10:07:25 -0400 | [diff] [blame] | 356 | * cec_queue_pin_hpd_event() - queue a pin event with a given timestamp. |
| 357 | * |
| 358 | * @adap: pointer to the cec adapter |
| 359 | * @is_high: when true the HPD pin is high, otherwise it is low |
| 360 | * @ts: the timestamp for this event |
| 361 | * |
| 362 | */ |
| 363 | void cec_queue_pin_hpd_event(struct cec_adapter *adap, bool is_high, ktime_t ts); |
| 364 | |
| 365 | /** |
Hans Verkuil | 4786b0d | 2018-06-28 07:43:46 -0400 | [diff] [blame] | 366 | * cec_queue_pin_5v_event() - queue a pin event with a given timestamp. |
| 367 | * |
| 368 | * @adap: pointer to the cec adapter |
| 369 | * @is_high: when true the 5V pin is high, otherwise it is low |
| 370 | * @ts: the timestamp for this event |
| 371 | * |
| 372 | */ |
| 373 | void cec_queue_pin_5v_event(struct cec_adapter *adap, bool is_high, ktime_t ts); |
| 374 | |
| 375 | /** |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 376 | * cec_get_edid_phys_addr() - find and return the physical address |
| 377 | * |
| 378 | * @edid: pointer to the EDID data |
| 379 | * @size: size in bytes of the EDID data |
| 380 | * @offset: If not %NULL then the location of the physical address |
| 381 | * bytes in the EDID will be returned here. This is set to 0 |
| 382 | * if there is no physical address found. |
| 383 | * |
| 384 | * Return: the physical address or CEC_PHYS_ADDR_INVALID if there is none. |
| 385 | */ |
| 386 | u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size, |
| 387 | unsigned int *offset); |
| 388 | |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 389 | void cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info, |
| 390 | const struct drm_connector *connector); |
| 391 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 392 | #else |
| 393 | |
Hans Verkuil | f51e808 | 2016-11-25 06:23:34 -0200 | [diff] [blame] | 394 | static inline int cec_register_adapter(struct cec_adapter *adap, |
| 395 | struct device *parent) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 396 | { |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | static inline void cec_unregister_adapter(struct cec_adapter *adap) |
| 401 | { |
| 402 | } |
| 403 | |
| 404 | static inline void cec_delete_adapter(struct cec_adapter *adap) |
| 405 | { |
| 406 | } |
| 407 | |
| 408 | static inline void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, |
| 409 | bool block) |
| 410 | { |
| 411 | } |
| 412 | |
Hans Verkuil | 23111ec | 2017-06-07 11:46:08 -0300 | [diff] [blame] | 413 | static inline void cec_s_phys_addr_from_edid(struct cec_adapter *adap, |
| 414 | const struct edid *edid) |
| 415 | { |
| 416 | } |
| 417 | |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 418 | static inline u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size, |
| 419 | unsigned int *offset) |
| 420 | { |
| 421 | if (offset) |
| 422 | *offset = 0; |
| 423 | return CEC_PHYS_ADDR_INVALID; |
| 424 | } |
| 425 | |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 426 | static inline void cec_s_conn_info(struct cec_adapter *adap, |
| 427 | const struct cec_connector_info *conn_info) |
| 428 | { |
| 429 | } |
| 430 | |
| 431 | static inline void |
| 432 | cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info, |
| 433 | const struct drm_connector *connector) |
| 434 | { |
| 435 | memset(conn_info, 0, sizeof(*conn_info)); |
| 436 | } |
| 437 | |
| 438 | #endif |
| 439 | |
Hans Verkuil | 1353278 | 2017-06-07 11:46:09 -0300 | [diff] [blame] | 440 | /** |
| 441 | * cec_phys_addr_invalidate() - set the physical address to INVALID |
| 442 | * |
| 443 | * @adap: the CEC adapter |
| 444 | * |
| 445 | * This is a simple helper function to invalidate the physical |
| 446 | * address. |
| 447 | */ |
| 448 | static inline void cec_phys_addr_invalidate(struct cec_adapter *adap) |
| 449 | { |
| 450 | cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false); |
| 451 | } |
| 452 | |
Hans Verkuil | b915bf57 | 2018-09-13 03:25:59 -0400 | [diff] [blame] | 453 | /** |
| 454 | * cec_get_edid_spa_location() - find location of the Source Physical Address |
| 455 | * |
| 456 | * @edid: the EDID |
| 457 | * @size: the size of the EDID |
| 458 | * |
| 459 | * This EDID is expected to be a CEA-861 compliant, which means that there are |
| 460 | * at least two blocks and one or more of the extensions blocks are CEA-861 |
| 461 | * blocks. |
| 462 | * |
| 463 | * The returned location is guaranteed to be <= size-2. |
| 464 | * |
| 465 | * This is an inline function since it is used by both CEC and V4L2. |
| 466 | * Ideally this would go in a module shared by both, but it is overkill to do |
| 467 | * that for just a single function. |
| 468 | */ |
| 469 | static inline unsigned int cec_get_edid_spa_location(const u8 *edid, |
| 470 | unsigned int size) |
| 471 | { |
| 472 | unsigned int blocks = size / 128; |
| 473 | unsigned int block; |
| 474 | u8 d; |
| 475 | |
| 476 | /* Sanity check: at least 2 blocks and a multiple of the block size */ |
| 477 | if (blocks < 2 || size % 128) |
| 478 | return 0; |
| 479 | |
| 480 | /* |
| 481 | * If there are fewer extension blocks than the size, then update |
| 482 | * 'blocks'. It is allowed to have more extension blocks than the size, |
| 483 | * since some hardware can only read e.g. 256 bytes of the EDID, even |
| 484 | * though more blocks are present. The first CEA-861 extension block |
| 485 | * should normally be in block 1 anyway. |
| 486 | */ |
| 487 | if (edid[0x7e] + 1 < blocks) |
| 488 | blocks = edid[0x7e] + 1; |
| 489 | |
| 490 | for (block = 1; block < blocks; block++) { |
| 491 | unsigned int offset = block * 128; |
| 492 | |
| 493 | /* Skip any non-CEA-861 extension blocks */ |
| 494 | if (edid[offset] != 0x02 || edid[offset + 1] != 0x03) |
| 495 | continue; |
| 496 | |
| 497 | /* search Vendor Specific Data Block (tag 3) */ |
| 498 | d = edid[offset + 2] & 0x7f; |
| 499 | /* Check if there are Data Blocks */ |
| 500 | if (d <= 4) |
| 501 | continue; |
| 502 | if (d > 4) { |
| 503 | unsigned int i = offset + 4; |
| 504 | unsigned int end = offset + d; |
| 505 | |
| 506 | /* Note: 'end' is always < 'size' */ |
| 507 | do { |
| 508 | u8 tag = edid[i] >> 5; |
| 509 | u8 len = edid[i] & 0x1f; |
| 510 | |
| 511 | if (tag == 3 && len >= 5 && i + len <= end && |
| 512 | edid[i + 1] == 0x03 && |
| 513 | edid[i + 2] == 0x0c && |
| 514 | edid[i + 3] == 0x00) |
| 515 | return i + 4; |
| 516 | i += len + 1; |
| 517 | } while (i < end); |
| 518 | } |
| 519 | } |
| 520 | return 0; |
| 521 | } |
| 522 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 523 | #endif /* _MEDIA_CEC_H */ |