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