18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * cec - HDMI Consumer Electronics Control support header 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _MEDIA_CEC_H 98c2ecf20Sopenharmony_ci#define _MEDIA_CEC_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/poll.h> 128c2ecf20Sopenharmony_ci#include <linux/fs.h> 138c2ecf20Sopenharmony_ci#include <linux/debugfs.h> 148c2ecf20Sopenharmony_ci#include <linux/device.h> 158c2ecf20Sopenharmony_ci#include <linux/cdev.h> 168c2ecf20Sopenharmony_ci#include <linux/kthread.h> 178c2ecf20Sopenharmony_ci#include <linux/timer.h> 188c2ecf20Sopenharmony_ci#include <linux/cec-funcs.h> 198c2ecf20Sopenharmony_ci#include <media/rc-core.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define CEC_CAP_DEFAULTS (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | \ 228c2ecf20Sopenharmony_ci CEC_CAP_PASSTHROUGH | CEC_CAP_RC) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/** 258c2ecf20Sopenharmony_ci * struct cec_devnode - cec device node 268c2ecf20Sopenharmony_ci * @dev: cec device 278c2ecf20Sopenharmony_ci * @cdev: cec character device 288c2ecf20Sopenharmony_ci * @minor: device node minor number 298c2ecf20Sopenharmony_ci * @registered: the device was correctly registered 308c2ecf20Sopenharmony_ci * @unregistered: the device was unregistered 318c2ecf20Sopenharmony_ci * @fhs_lock: lock to control access to the filehandle list 328c2ecf20Sopenharmony_ci * @fhs: the list of open filehandles (cec_fh) 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * This structure represents a cec-related device node. 358c2ecf20Sopenharmony_ci * 368c2ecf20Sopenharmony_ci * The @parent is a physical device. It must be set by core or device drivers 378c2ecf20Sopenharmony_ci * before registering the node. 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_cistruct cec_devnode { 408c2ecf20Sopenharmony_ci /* sysfs */ 418c2ecf20Sopenharmony_ci struct device dev; 428c2ecf20Sopenharmony_ci struct cdev cdev; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci /* device info */ 458c2ecf20Sopenharmony_ci int minor; 468c2ecf20Sopenharmony_ci bool registered; 478c2ecf20Sopenharmony_ci bool unregistered; 488c2ecf20Sopenharmony_ci struct list_head fhs; 498c2ecf20Sopenharmony_ci struct mutex lock; 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistruct cec_adapter; 538c2ecf20Sopenharmony_cistruct cec_data; 548c2ecf20Sopenharmony_cistruct cec_pin; 558c2ecf20Sopenharmony_cistruct cec_notifier; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistruct cec_data { 588c2ecf20Sopenharmony_ci struct list_head list; 598c2ecf20Sopenharmony_ci struct list_head xfer_list; 608c2ecf20Sopenharmony_ci struct cec_adapter *adap; 618c2ecf20Sopenharmony_ci struct cec_msg msg; 628c2ecf20Sopenharmony_ci struct cec_fh *fh; 638c2ecf20Sopenharmony_ci struct delayed_work work; 648c2ecf20Sopenharmony_ci struct completion c; 658c2ecf20Sopenharmony_ci u8 attempts; 668c2ecf20Sopenharmony_ci bool blocking; 678c2ecf20Sopenharmony_ci bool completed; 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistruct cec_msg_entry { 718c2ecf20Sopenharmony_ci struct list_head list; 728c2ecf20Sopenharmony_ci struct cec_msg msg; 738c2ecf20Sopenharmony_ci}; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistruct cec_event_entry { 768c2ecf20Sopenharmony_ci struct list_head list; 778c2ecf20Sopenharmony_ci struct cec_event ev; 788c2ecf20Sopenharmony_ci}; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define CEC_NUM_CORE_EVENTS 2 818c2ecf20Sopenharmony_ci#define CEC_NUM_EVENTS CEC_EVENT_PIN_5V_HIGH 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistruct cec_fh { 848c2ecf20Sopenharmony_ci struct list_head list; 858c2ecf20Sopenharmony_ci struct list_head xfer_list; 868c2ecf20Sopenharmony_ci struct cec_adapter *adap; 878c2ecf20Sopenharmony_ci u8 mode_initiator; 888c2ecf20Sopenharmony_ci u8 mode_follower; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci /* Events */ 918c2ecf20Sopenharmony_ci wait_queue_head_t wait; 928c2ecf20Sopenharmony_ci struct mutex lock; 938c2ecf20Sopenharmony_ci struct list_head events[CEC_NUM_EVENTS]; /* queued events */ 948c2ecf20Sopenharmony_ci u16 queued_events[CEC_NUM_EVENTS]; 958c2ecf20Sopenharmony_ci unsigned int total_queued_events; 968c2ecf20Sopenharmony_ci struct cec_event_entry core_events[CEC_NUM_CORE_EVENTS]; 978c2ecf20Sopenharmony_ci struct list_head msgs; /* queued messages */ 988c2ecf20Sopenharmony_ci unsigned int queued_msgs; 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci#define CEC_SIGNAL_FREE_TIME_RETRY 3 1028c2ecf20Sopenharmony_ci#define CEC_SIGNAL_FREE_TIME_NEW_INITIATOR 5 1038c2ecf20Sopenharmony_ci#define CEC_SIGNAL_FREE_TIME_NEXT_XFER 7 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/* The nominal data bit period is 2.4 ms */ 1068c2ecf20Sopenharmony_ci#define CEC_FREE_TIME_TO_USEC(ft) ((ft) * 2400) 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistruct cec_adap_ops { 1098c2ecf20Sopenharmony_ci /* Low-level callbacks */ 1108c2ecf20Sopenharmony_ci int (*adap_enable)(struct cec_adapter *adap, bool enable); 1118c2ecf20Sopenharmony_ci int (*adap_monitor_all_enable)(struct cec_adapter *adap, bool enable); 1128c2ecf20Sopenharmony_ci int (*adap_monitor_pin_enable)(struct cec_adapter *adap, bool enable); 1138c2ecf20Sopenharmony_ci int (*adap_log_addr)(struct cec_adapter *adap, u8 logical_addr); 1148c2ecf20Sopenharmony_ci int (*adap_transmit)(struct cec_adapter *adap, u8 attempts, 1158c2ecf20Sopenharmony_ci u32 signal_free_time, struct cec_msg *msg); 1168c2ecf20Sopenharmony_ci void (*adap_status)(struct cec_adapter *adap, struct seq_file *file); 1178c2ecf20Sopenharmony_ci void (*adap_free)(struct cec_adapter *adap); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci /* Error injection callbacks */ 1208c2ecf20Sopenharmony_ci int (*error_inj_show)(struct cec_adapter *adap, struct seq_file *sf); 1218c2ecf20Sopenharmony_ci bool (*error_inj_parse_line)(struct cec_adapter *adap, char *line); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci /* High-level CEC message callback */ 1248c2ecf20Sopenharmony_ci int (*received)(struct cec_adapter *adap, struct cec_msg *msg); 1258c2ecf20Sopenharmony_ci}; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci/* 1288c2ecf20Sopenharmony_ci * The minimum message length you can receive (excepting poll messages) is 2. 1298c2ecf20Sopenharmony_ci * With a transfer rate of at most 36 bytes per second this makes 18 messages 1308c2ecf20Sopenharmony_ci * per second worst case. 1318c2ecf20Sopenharmony_ci * 1328c2ecf20Sopenharmony_ci * We queue at most 3 seconds worth of received messages. The CEC specification 1338c2ecf20Sopenharmony_ci * requires that messages are replied to within a second, so 3 seconds should 1348c2ecf20Sopenharmony_ci * give more than enough margin. Since most messages are actually more than 2 1358c2ecf20Sopenharmony_ci * bytes, this is in practice a lot more than 3 seconds. 1368c2ecf20Sopenharmony_ci */ 1378c2ecf20Sopenharmony_ci#define CEC_MAX_MSG_RX_QUEUE_SZ (18 * 3) 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci/* 1408c2ecf20Sopenharmony_ci * The transmit queue is limited to 1 second worth of messages (worst case). 1418c2ecf20Sopenharmony_ci * Messages can be transmitted by userspace and kernel space. But for both it 1428c2ecf20Sopenharmony_ci * makes no sense to have a lot of messages queued up. One second seems 1438c2ecf20Sopenharmony_ci * reasonable. 1448c2ecf20Sopenharmony_ci */ 1458c2ecf20Sopenharmony_ci#define CEC_MAX_MSG_TX_QUEUE_SZ (18 * 1) 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci/** 1488c2ecf20Sopenharmony_ci * struct cec_adapter - cec adapter structure 1498c2ecf20Sopenharmony_ci * @owner: module owner 1508c2ecf20Sopenharmony_ci * @name: name of the CEC adapter 1518c2ecf20Sopenharmony_ci * @devnode: device node for the /dev/cecX device 1528c2ecf20Sopenharmony_ci * @lock: mutex controlling access to this structure 1538c2ecf20Sopenharmony_ci * @rc: remote control device 1548c2ecf20Sopenharmony_ci * @transmit_queue: queue of pending transmits 1558c2ecf20Sopenharmony_ci * @transmit_queue_sz: number of pending transmits 1568c2ecf20Sopenharmony_ci * @wait_queue: queue of transmits waiting for a reply 1578c2ecf20Sopenharmony_ci * @transmitting: CEC messages currently being transmitted 1588c2ecf20Sopenharmony_ci * @transmit_in_progress: true if a transmit is in progress 1598c2ecf20Sopenharmony_ci * @kthread_config: kthread used to configure a CEC adapter 1608c2ecf20Sopenharmony_ci * @config_completion: used to signal completion of the config kthread 1618c2ecf20Sopenharmony_ci * @kthread: main CEC processing thread 1628c2ecf20Sopenharmony_ci * @kthread_waitq: main CEC processing wait_queue 1638c2ecf20Sopenharmony_ci * @ops: cec adapter ops 1648c2ecf20Sopenharmony_ci * @priv: cec driver's private data 1658c2ecf20Sopenharmony_ci * @capabilities: cec adapter capabilities 1668c2ecf20Sopenharmony_ci * @available_log_addrs: maximum number of available logical addresses 1678c2ecf20Sopenharmony_ci * @phys_addr: the current physical address 1688c2ecf20Sopenharmony_ci * @needs_hpd: if true, then the HDMI HotPlug Detect pin must be high 1698c2ecf20Sopenharmony_ci * in order to transmit or receive CEC messages. This is usually a HW 1708c2ecf20Sopenharmony_ci * limitation. 1718c2ecf20Sopenharmony_ci * @is_configuring: the CEC adapter is configuring (i.e. claiming LAs) 1728c2ecf20Sopenharmony_ci * @is_configured: the CEC adapter is configured (i.e. has claimed LAs) 1738c2ecf20Sopenharmony_ci * @cec_pin_is_high: if true then the CEC pin is high. Only used with the 1748c2ecf20Sopenharmony_ci * CEC pin framework. 1758c2ecf20Sopenharmony_ci * @adap_controls_phys_addr: if true, then the CEC adapter controls the 1768c2ecf20Sopenharmony_ci * physical address, i.e. the CEC hardware can detect HPD changes and 1778c2ecf20Sopenharmony_ci * read the EDID and is not dependent on an external HDMI driver. 1788c2ecf20Sopenharmony_ci * Drivers that need this can set this field to true after the 1798c2ecf20Sopenharmony_ci * cec_allocate_adapter() call. 1808c2ecf20Sopenharmony_ci * @last_initiator: the initiator of the last transmitted message. 1818c2ecf20Sopenharmony_ci * @monitor_all_cnt: number of filehandles monitoring all msgs 1828c2ecf20Sopenharmony_ci * @monitor_pin_cnt: number of filehandles monitoring pin changes 1838c2ecf20Sopenharmony_ci * @follower_cnt: number of filehandles in follower mode 1848c2ecf20Sopenharmony_ci * @cec_follower: filehandle of the exclusive follower 1858c2ecf20Sopenharmony_ci * @cec_initiator: filehandle of the exclusive initiator 1868c2ecf20Sopenharmony_ci * @passthrough: if true, then the exclusive follower is in 1878c2ecf20Sopenharmony_ci * passthrough mode. 1888c2ecf20Sopenharmony_ci * @log_addrs: current logical addresses 1898c2ecf20Sopenharmony_ci * @conn_info: current connector info 1908c2ecf20Sopenharmony_ci * @tx_timeouts: number of transmit timeouts 1918c2ecf20Sopenharmony_ci * @notifier: CEC notifier 1928c2ecf20Sopenharmony_ci * @pin: CEC pin status struct 1938c2ecf20Sopenharmony_ci * @cec_dir: debugfs cec directory 1948c2ecf20Sopenharmony_ci * @status_file: debugfs cec status file 1958c2ecf20Sopenharmony_ci * @error_inj_file: debugfs cec error injection file 1968c2ecf20Sopenharmony_ci * @sequence: transmit sequence counter 1978c2ecf20Sopenharmony_ci * @input_phys: remote control input_phys name 1988c2ecf20Sopenharmony_ci * 1998c2ecf20Sopenharmony_ci * This structure represents a cec adapter. 2008c2ecf20Sopenharmony_ci */ 2018c2ecf20Sopenharmony_cistruct cec_adapter { 2028c2ecf20Sopenharmony_ci struct module *owner; 2038c2ecf20Sopenharmony_ci char name[32]; 2048c2ecf20Sopenharmony_ci struct cec_devnode devnode; 2058c2ecf20Sopenharmony_ci struct mutex lock; 2068c2ecf20Sopenharmony_ci struct rc_dev *rc; 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci struct list_head transmit_queue; 2098c2ecf20Sopenharmony_ci unsigned int transmit_queue_sz; 2108c2ecf20Sopenharmony_ci struct list_head wait_queue; 2118c2ecf20Sopenharmony_ci struct cec_data *transmitting; 2128c2ecf20Sopenharmony_ci bool transmit_in_progress; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci struct task_struct *kthread_config; 2158c2ecf20Sopenharmony_ci struct completion config_completion; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci struct task_struct *kthread; 2188c2ecf20Sopenharmony_ci wait_queue_head_t kthread_waitq; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci const struct cec_adap_ops *ops; 2218c2ecf20Sopenharmony_ci void *priv; 2228c2ecf20Sopenharmony_ci u32 capabilities; 2238c2ecf20Sopenharmony_ci u8 available_log_addrs; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci u16 phys_addr; 2268c2ecf20Sopenharmony_ci bool needs_hpd; 2278c2ecf20Sopenharmony_ci bool is_configuring; 2288c2ecf20Sopenharmony_ci bool is_configured; 2298c2ecf20Sopenharmony_ci bool cec_pin_is_high; 2308c2ecf20Sopenharmony_ci bool adap_controls_phys_addr; 2318c2ecf20Sopenharmony_ci u8 last_initiator; 2328c2ecf20Sopenharmony_ci u32 monitor_all_cnt; 2338c2ecf20Sopenharmony_ci u32 monitor_pin_cnt; 2348c2ecf20Sopenharmony_ci u32 follower_cnt; 2358c2ecf20Sopenharmony_ci struct cec_fh *cec_follower; 2368c2ecf20Sopenharmony_ci struct cec_fh *cec_initiator; 2378c2ecf20Sopenharmony_ci bool passthrough; 2388c2ecf20Sopenharmony_ci struct cec_log_addrs log_addrs; 2398c2ecf20Sopenharmony_ci struct cec_connector_info conn_info; 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci u32 tx_timeouts; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci#ifdef CONFIG_CEC_NOTIFIER 2448c2ecf20Sopenharmony_ci struct cec_notifier *notifier; 2458c2ecf20Sopenharmony_ci#endif 2468c2ecf20Sopenharmony_ci#ifdef CONFIG_CEC_PIN 2478c2ecf20Sopenharmony_ci struct cec_pin *pin; 2488c2ecf20Sopenharmony_ci#endif 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci struct dentry *cec_dir; 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci u32 sequence; 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci char input_phys[32]; 2558c2ecf20Sopenharmony_ci}; 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_cistatic inline void *cec_get_drvdata(const struct cec_adapter *adap) 2588c2ecf20Sopenharmony_ci{ 2598c2ecf20Sopenharmony_ci return adap->priv; 2608c2ecf20Sopenharmony_ci} 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_cistatic inline bool cec_has_log_addr(const struct cec_adapter *adap, u8 log_addr) 2638c2ecf20Sopenharmony_ci{ 2648c2ecf20Sopenharmony_ci return adap->log_addrs.log_addr_mask & (1 << log_addr); 2658c2ecf20Sopenharmony_ci} 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_cistatic inline bool cec_is_sink(const struct cec_adapter *adap) 2688c2ecf20Sopenharmony_ci{ 2698c2ecf20Sopenharmony_ci return adap->phys_addr == 0; 2708c2ecf20Sopenharmony_ci} 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci/** 2738c2ecf20Sopenharmony_ci * cec_is_registered() - is the CEC adapter registered? 2748c2ecf20Sopenharmony_ci * 2758c2ecf20Sopenharmony_ci * @adap: the CEC adapter, may be NULL. 2768c2ecf20Sopenharmony_ci * 2778c2ecf20Sopenharmony_ci * Return: true if the adapter is registered, false otherwise. 2788c2ecf20Sopenharmony_ci */ 2798c2ecf20Sopenharmony_cistatic inline bool cec_is_registered(const struct cec_adapter *adap) 2808c2ecf20Sopenharmony_ci{ 2818c2ecf20Sopenharmony_ci return adap && adap->devnode.registered; 2828c2ecf20Sopenharmony_ci} 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci#define cec_phys_addr_exp(pa) \ 2858c2ecf20Sopenharmony_ci ((pa) >> 12), ((pa) >> 8) & 0xf, ((pa) >> 4) & 0xf, (pa) & 0xf 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_cistruct edid; 2888c2ecf20Sopenharmony_cistruct drm_connector; 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci#if IS_REACHABLE(CONFIG_CEC_CORE) 2918c2ecf20Sopenharmony_cistruct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, 2928c2ecf20Sopenharmony_ci void *priv, const char *name, u32 caps, u8 available_las); 2938c2ecf20Sopenharmony_ciint cec_register_adapter(struct cec_adapter *adap, struct device *parent); 2948c2ecf20Sopenharmony_civoid cec_unregister_adapter(struct cec_adapter *adap); 2958c2ecf20Sopenharmony_civoid cec_delete_adapter(struct cec_adapter *adap); 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ciint cec_s_log_addrs(struct cec_adapter *adap, struct cec_log_addrs *log_addrs, 2988c2ecf20Sopenharmony_ci bool block); 2998c2ecf20Sopenharmony_civoid cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, 3008c2ecf20Sopenharmony_ci bool block); 3018c2ecf20Sopenharmony_civoid cec_s_phys_addr_from_edid(struct cec_adapter *adap, 3028c2ecf20Sopenharmony_ci const struct edid *edid); 3038c2ecf20Sopenharmony_civoid cec_s_conn_info(struct cec_adapter *adap, 3048c2ecf20Sopenharmony_ci const struct cec_connector_info *conn_info); 3058c2ecf20Sopenharmony_ciint cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg, 3068c2ecf20Sopenharmony_ci bool block); 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci/* Called by the adapter */ 3098c2ecf20Sopenharmony_civoid cec_transmit_done_ts(struct cec_adapter *adap, u8 status, 3108c2ecf20Sopenharmony_ci u8 arb_lost_cnt, u8 nack_cnt, u8 low_drive_cnt, 3118c2ecf20Sopenharmony_ci u8 error_cnt, ktime_t ts); 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_cistatic inline void cec_transmit_done(struct cec_adapter *adap, u8 status, 3148c2ecf20Sopenharmony_ci u8 arb_lost_cnt, u8 nack_cnt, 3158c2ecf20Sopenharmony_ci u8 low_drive_cnt, u8 error_cnt) 3168c2ecf20Sopenharmony_ci{ 3178c2ecf20Sopenharmony_ci cec_transmit_done_ts(adap, status, arb_lost_cnt, nack_cnt, 3188c2ecf20Sopenharmony_ci low_drive_cnt, error_cnt, ktime_get()); 3198c2ecf20Sopenharmony_ci} 3208c2ecf20Sopenharmony_ci/* 3218c2ecf20Sopenharmony_ci * Simplified version of cec_transmit_done for hardware that doesn't retry 3228c2ecf20Sopenharmony_ci * failed transmits. So this is always just one attempt in which case 3238c2ecf20Sopenharmony_ci * the status is sufficient. 3248c2ecf20Sopenharmony_ci */ 3258c2ecf20Sopenharmony_civoid cec_transmit_attempt_done_ts(struct cec_adapter *adap, 3268c2ecf20Sopenharmony_ci u8 status, ktime_t ts); 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_cistatic inline void cec_transmit_attempt_done(struct cec_adapter *adap, 3298c2ecf20Sopenharmony_ci u8 status) 3308c2ecf20Sopenharmony_ci{ 3318c2ecf20Sopenharmony_ci cec_transmit_attempt_done_ts(adap, status, ktime_get()); 3328c2ecf20Sopenharmony_ci} 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_civoid cec_received_msg_ts(struct cec_adapter *adap, 3358c2ecf20Sopenharmony_ci struct cec_msg *msg, ktime_t ts); 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_cistatic inline void cec_received_msg(struct cec_adapter *adap, 3388c2ecf20Sopenharmony_ci struct cec_msg *msg) 3398c2ecf20Sopenharmony_ci{ 3408c2ecf20Sopenharmony_ci cec_received_msg_ts(adap, msg, ktime_get()); 3418c2ecf20Sopenharmony_ci} 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci/** 3448c2ecf20Sopenharmony_ci * cec_queue_pin_cec_event() - queue a CEC pin event with a given timestamp. 3458c2ecf20Sopenharmony_ci * 3468c2ecf20Sopenharmony_ci * @adap: pointer to the cec adapter 3478c2ecf20Sopenharmony_ci * @is_high: when true the CEC pin is high, otherwise it is low 3488c2ecf20Sopenharmony_ci * @dropped_events: when true some events were dropped 3498c2ecf20Sopenharmony_ci * @ts: the timestamp for this event 3508c2ecf20Sopenharmony_ci * 3518c2ecf20Sopenharmony_ci */ 3528c2ecf20Sopenharmony_civoid cec_queue_pin_cec_event(struct cec_adapter *adap, bool is_high, 3538c2ecf20Sopenharmony_ci bool dropped_events, ktime_t ts); 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci/** 3568c2ecf20Sopenharmony_ci * cec_queue_pin_hpd_event() - queue a pin event with a given timestamp. 3578c2ecf20Sopenharmony_ci * 3588c2ecf20Sopenharmony_ci * @adap: pointer to the cec adapter 3598c2ecf20Sopenharmony_ci * @is_high: when true the HPD pin is high, otherwise it is low 3608c2ecf20Sopenharmony_ci * @ts: the timestamp for this event 3618c2ecf20Sopenharmony_ci * 3628c2ecf20Sopenharmony_ci */ 3638c2ecf20Sopenharmony_civoid cec_queue_pin_hpd_event(struct cec_adapter *adap, bool is_high, ktime_t ts); 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci/** 3668c2ecf20Sopenharmony_ci * cec_queue_pin_5v_event() - queue a pin event with a given timestamp. 3678c2ecf20Sopenharmony_ci * 3688c2ecf20Sopenharmony_ci * @adap: pointer to the cec adapter 3698c2ecf20Sopenharmony_ci * @is_high: when true the 5V pin is high, otherwise it is low 3708c2ecf20Sopenharmony_ci * @ts: the timestamp for this event 3718c2ecf20Sopenharmony_ci * 3728c2ecf20Sopenharmony_ci */ 3738c2ecf20Sopenharmony_civoid cec_queue_pin_5v_event(struct cec_adapter *adap, bool is_high, ktime_t ts); 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci/** 3768c2ecf20Sopenharmony_ci * cec_get_edid_phys_addr() - find and return the physical address 3778c2ecf20Sopenharmony_ci * 3788c2ecf20Sopenharmony_ci * @edid: pointer to the EDID data 3798c2ecf20Sopenharmony_ci * @size: size in bytes of the EDID data 3808c2ecf20Sopenharmony_ci * @offset: If not %NULL then the location of the physical address 3818c2ecf20Sopenharmony_ci * bytes in the EDID will be returned here. This is set to 0 3828c2ecf20Sopenharmony_ci * if there is no physical address found. 3838c2ecf20Sopenharmony_ci * 3848c2ecf20Sopenharmony_ci * Return: the physical address or CEC_PHYS_ADDR_INVALID if there is none. 3858c2ecf20Sopenharmony_ci */ 3868c2ecf20Sopenharmony_ciu16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size, 3878c2ecf20Sopenharmony_ci unsigned int *offset); 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_civoid cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info, 3908c2ecf20Sopenharmony_ci const struct drm_connector *connector); 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci#else 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_cistatic inline int cec_register_adapter(struct cec_adapter *adap, 3958c2ecf20Sopenharmony_ci struct device *parent) 3968c2ecf20Sopenharmony_ci{ 3978c2ecf20Sopenharmony_ci return 0; 3988c2ecf20Sopenharmony_ci} 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_cistatic inline void cec_unregister_adapter(struct cec_adapter *adap) 4018c2ecf20Sopenharmony_ci{ 4028c2ecf20Sopenharmony_ci} 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_cistatic inline void cec_delete_adapter(struct cec_adapter *adap) 4058c2ecf20Sopenharmony_ci{ 4068c2ecf20Sopenharmony_ci} 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_cistatic inline void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, 4098c2ecf20Sopenharmony_ci bool block) 4108c2ecf20Sopenharmony_ci{ 4118c2ecf20Sopenharmony_ci} 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_cistatic inline void cec_s_phys_addr_from_edid(struct cec_adapter *adap, 4148c2ecf20Sopenharmony_ci const struct edid *edid) 4158c2ecf20Sopenharmony_ci{ 4168c2ecf20Sopenharmony_ci} 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_cistatic inline u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size, 4198c2ecf20Sopenharmony_ci unsigned int *offset) 4208c2ecf20Sopenharmony_ci{ 4218c2ecf20Sopenharmony_ci if (offset) 4228c2ecf20Sopenharmony_ci *offset = 0; 4238c2ecf20Sopenharmony_ci return CEC_PHYS_ADDR_INVALID; 4248c2ecf20Sopenharmony_ci} 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_cistatic inline void cec_s_conn_info(struct cec_adapter *adap, 4278c2ecf20Sopenharmony_ci const struct cec_connector_info *conn_info) 4288c2ecf20Sopenharmony_ci{ 4298c2ecf20Sopenharmony_ci} 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_cistatic inline void 4328c2ecf20Sopenharmony_cicec_fill_conn_info_from_drm(struct cec_connector_info *conn_info, 4338c2ecf20Sopenharmony_ci const struct drm_connector *connector) 4348c2ecf20Sopenharmony_ci{ 4358c2ecf20Sopenharmony_ci memset(conn_info, 0, sizeof(*conn_info)); 4368c2ecf20Sopenharmony_ci} 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci#endif 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci/** 4418c2ecf20Sopenharmony_ci * cec_phys_addr_invalidate() - set the physical address to INVALID 4428c2ecf20Sopenharmony_ci * 4438c2ecf20Sopenharmony_ci * @adap: the CEC adapter 4448c2ecf20Sopenharmony_ci * 4458c2ecf20Sopenharmony_ci * This is a simple helper function to invalidate the physical 4468c2ecf20Sopenharmony_ci * address. 4478c2ecf20Sopenharmony_ci */ 4488c2ecf20Sopenharmony_cistatic inline void cec_phys_addr_invalidate(struct cec_adapter *adap) 4498c2ecf20Sopenharmony_ci{ 4508c2ecf20Sopenharmony_ci cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false); 4518c2ecf20Sopenharmony_ci} 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci/** 4548c2ecf20Sopenharmony_ci * cec_get_edid_spa_location() - find location of the Source Physical Address 4558c2ecf20Sopenharmony_ci * 4568c2ecf20Sopenharmony_ci * @edid: the EDID 4578c2ecf20Sopenharmony_ci * @size: the size of the EDID 4588c2ecf20Sopenharmony_ci * 4598c2ecf20Sopenharmony_ci * This EDID is expected to be a CEA-861 compliant, which means that there are 4608c2ecf20Sopenharmony_ci * at least two blocks and one or more of the extensions blocks are CEA-861 4618c2ecf20Sopenharmony_ci * blocks. 4628c2ecf20Sopenharmony_ci * 4638c2ecf20Sopenharmony_ci * The returned location is guaranteed to be <= size-2. 4648c2ecf20Sopenharmony_ci * 4658c2ecf20Sopenharmony_ci * This is an inline function since it is used by both CEC and V4L2. 4668c2ecf20Sopenharmony_ci * Ideally this would go in a module shared by both, but it is overkill to do 4678c2ecf20Sopenharmony_ci * that for just a single function. 4688c2ecf20Sopenharmony_ci */ 4698c2ecf20Sopenharmony_cistatic inline unsigned int cec_get_edid_spa_location(const u8 *edid, 4708c2ecf20Sopenharmony_ci unsigned int size) 4718c2ecf20Sopenharmony_ci{ 4728c2ecf20Sopenharmony_ci unsigned int blocks = size / 128; 4738c2ecf20Sopenharmony_ci unsigned int block; 4748c2ecf20Sopenharmony_ci u8 d; 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci /* Sanity check: at least 2 blocks and a multiple of the block size */ 4778c2ecf20Sopenharmony_ci if (blocks < 2 || size % 128) 4788c2ecf20Sopenharmony_ci return 0; 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci /* 4818c2ecf20Sopenharmony_ci * If there are fewer extension blocks than the size, then update 4828c2ecf20Sopenharmony_ci * 'blocks'. It is allowed to have more extension blocks than the size, 4838c2ecf20Sopenharmony_ci * since some hardware can only read e.g. 256 bytes of the EDID, even 4848c2ecf20Sopenharmony_ci * though more blocks are present. The first CEA-861 extension block 4858c2ecf20Sopenharmony_ci * should normally be in block 1 anyway. 4868c2ecf20Sopenharmony_ci */ 4878c2ecf20Sopenharmony_ci if (edid[0x7e] + 1 < blocks) 4888c2ecf20Sopenharmony_ci blocks = edid[0x7e] + 1; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci for (block = 1; block < blocks; block++) { 4918c2ecf20Sopenharmony_ci unsigned int offset = block * 128; 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci /* Skip any non-CEA-861 extension blocks */ 4948c2ecf20Sopenharmony_ci if (edid[offset] != 0x02 || edid[offset + 1] != 0x03) 4958c2ecf20Sopenharmony_ci continue; 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci /* search Vendor Specific Data Block (tag 3) */ 4988c2ecf20Sopenharmony_ci d = edid[offset + 2] & 0x7f; 4998c2ecf20Sopenharmony_ci /* Check if there are Data Blocks */ 5008c2ecf20Sopenharmony_ci if (d <= 4) 5018c2ecf20Sopenharmony_ci continue; 5028c2ecf20Sopenharmony_ci if (d > 4) { 5038c2ecf20Sopenharmony_ci unsigned int i = offset + 4; 5048c2ecf20Sopenharmony_ci unsigned int end = offset + d; 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci /* Note: 'end' is always < 'size' */ 5078c2ecf20Sopenharmony_ci do { 5088c2ecf20Sopenharmony_ci u8 tag = edid[i] >> 5; 5098c2ecf20Sopenharmony_ci u8 len = edid[i] & 0x1f; 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci if (tag == 3 && len >= 5 && i + len <= end && 5128c2ecf20Sopenharmony_ci edid[i + 1] == 0x03 && 5138c2ecf20Sopenharmony_ci edid[i + 2] == 0x0c && 5148c2ecf20Sopenharmony_ci edid[i + 3] == 0x00) 5158c2ecf20Sopenharmony_ci return i + 4; 5168c2ecf20Sopenharmony_ci i += len + 1; 5178c2ecf20Sopenharmony_ci } while (i < end); 5188c2ecf20Sopenharmony_ci } 5198c2ecf20Sopenharmony_ci } 5208c2ecf20Sopenharmony_ci return 0; 5218c2ecf20Sopenharmony_ci} 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci#endif /* _MEDIA_CEC_H */ 524