Skip to content

Commit 333ef6b

Browse files
Hans Verkuilmchehab
authored andcommitted
media: cec: add CEC_EVENT_PIN_HPD_LOW/HIGH events
Add support for two new low-level events: PIN_HPD_LOW and PIN_HPD_HIGH. This is specifically meant for use with the upcoming cec-gpio driver and makes it possible to trace when the HPD pin changes. Some HDMI sinks do strange things with the HPD and this makes it easy to debug this. Note that this also moves the initialization of a devnode mutex and list to the allocate_adapter function: if the HPD is high, then as soon as the HPD interrupt is created an interrupt occurs and cec_queue_pin_hpd_event() is called which requires that the devnode mutex and list are initialized. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
1 parent da634f6 commit 333ef6b

6 files changed

Lines changed: 52 additions & 10 deletions

File tree

‎drivers/media/cec/cec-adap.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void cec_queue_event_fh(struct cec_fh *fh,
8686
const struct cec_event *new_ev, u64 ts)
8787
{
8888
static const u8 max_events[CEC_NUM_EVENTS] = {
89-
1, 1, 64, 64,
89+
1, 1, 64, 64, 8, 8,
9090
};
9191
struct cec_event_entry *entry;
9292
unsigned int ev_idx = new_ev->event - 1;
@@ -170,6 +170,22 @@ void cec_queue_pin_cec_event(struct cec_adapter *adap, bool is_high, ktime_t ts)
170170
}
171171
EXPORT_SYMBOL_GPL(cec_queue_pin_cec_event);
172172

173+
/* Notify userspace that the HPD pin changed state at the given time. */
174+
void cec_queue_pin_hpd_event(struct cec_adapter *adap, bool is_high, ktime_t ts)
175+
{
176+
struct cec_event ev = {
177+
.event = is_high ? CEC_EVENT_PIN_HPD_HIGH :
178+
CEC_EVENT_PIN_HPD_LOW,
179+
};
180+
struct cec_fh *fh;
181+
182+
mutex_lock(&adap->devnode.lock);
183+
list_for_each_entry(fh, &adap->devnode.fhs, list)
184+
cec_queue_event_fh(fh, &ev, ktime_to_ns(ts));
185+
mutex_unlock(&adap->devnode.lock);
186+
}
187+
EXPORT_SYMBOL_GPL(cec_queue_pin_hpd_event);
188+
173189
/*
174190
* Queue a new message for this filehandle.
175191
*

‎drivers/media/cec/cec-api.c‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ static int cec_open(struct inode *inode, struct file *filp)
529529
* Initial events that are automatically sent when the cec device is
530530
* opened.
531531
*/
532-
struct cec_event ev_state = {
532+
struct cec_event ev = {
533533
.event = CEC_EVENT_STATE_CHANGE,
534534
.flags = CEC_EVENT_FL_INITIAL_STATE,
535535
};
@@ -569,9 +569,19 @@ static int cec_open(struct inode *inode, struct file *filp)
569569
filp->private_data = fh;
570570

571571
/* Queue up initial state events */
572-
ev_state.state_change.phys_addr = adap->phys_addr;
573-
ev_state.state_change.log_addr_mask = adap->log_addrs.log_addr_mask;
574-
cec_queue_event_fh(fh, &ev_state, 0);
572+
ev.state_change.phys_addr = adap->phys_addr;
573+
ev.state_change.log_addr_mask = adap->log_addrs.log_addr_mask;
574+
cec_queue_event_fh(fh, &ev, 0);
575+
#ifdef CONFIG_CEC_PIN
576+
if (adap->pin && adap->pin->ops->read_hpd) {
577+
err = adap->pin->ops->read_hpd(adap);
578+
if (err >= 0) {
579+
ev.event = err ? CEC_EVENT_PIN_HPD_HIGH :
580+
CEC_EVENT_PIN_HPD_LOW;
581+
cec_queue_event_fh(fh, &ev, 0);
582+
}
583+
}
584+
#endif
575585

576586
list_add(&fh->list, &devnode->fhs);
577587
mutex_unlock(&devnode->lock);

‎drivers/media/cec/cec-core.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ static int __must_check cec_devnode_register(struct cec_devnode *devnode,
112112
int minor;
113113
int ret;
114114

115-
/* Initialization */
116-
INIT_LIST_HEAD(&devnode->fhs);
117-
mutex_init(&devnode->lock);
118-
119115
/* Part 1: Find a free minor number */
120116
mutex_lock(&cec_devnode_lock);
121117
minor = find_next_zero_bit(cec_devnode_nums, CEC_NUM_DEVICES, 0);
@@ -242,6 +238,10 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
242238
INIT_LIST_HEAD(&adap->wait_queue);
243239
init_waitqueue_head(&adap->kthread_waitq);
244240

241+
/* adap->devnode initialization */
242+
INIT_LIST_HEAD(&adap->devnode.fhs);
243+
mutex_init(&adap->devnode.lock);
244+
245245
adap->kthread = kthread_run(cec_thread_func, adap, "cec-%s", name);
246246
if (IS_ERR(adap->kthread)) {
247247
pr_err("cec-%s: kernel_thread() failed\n", name);

‎include/media/cec-pin.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ enum cec_pin_state {
9797
* @free: optional. Free any allocated resources. Called when the
9898
* adapter is deleted.
9999
* @status: optional, log status information.
100+
* @read_hpd: read the HPD pin. Return true if high, false if low or
101+
* an error if negative. If NULL or -ENOTTY is returned,
102+
* then this is not supported.
100103
*
101104
* These operations are used by the cec pin framework to manipulate
102105
* the CEC pin.
@@ -109,6 +112,7 @@ struct cec_pin_ops {
109112
void (*disable_irq)(struct cec_adapter *adap);
110113
void (*free)(struct cec_adapter *adap);
111114
void (*status)(struct cec_adapter *adap, struct seq_file *file);
115+
int (*read_hpd)(struct cec_adapter *adap);
112116
};
113117

114118
#define CEC_NUM_PIN_EVENTS 128

‎include/media/cec.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct cec_event_entry {
9191
};
9292

9393
#define CEC_NUM_CORE_EVENTS 2
94-
#define CEC_NUM_EVENTS CEC_EVENT_PIN_CEC_HIGH
94+
#define CEC_NUM_EVENTS CEC_EVENT_PIN_HPD_HIGH
9595

9696
struct cec_fh {
9797
struct list_head list;
@@ -296,6 +296,16 @@ static inline void cec_received_msg(struct cec_adapter *adap,
296296
void cec_queue_pin_cec_event(struct cec_adapter *adap,
297297
bool is_high, ktime_t ts);
298298

299+
/**
300+
* cec_queue_pin_hpd_event() - queue a pin event with a given timestamp.
301+
*
302+
* @adap: pointer to the cec adapter
303+
* @is_high: when true the HPD pin is high, otherwise it is low
304+
* @ts: the timestamp for this event
305+
*
306+
*/
307+
void cec_queue_pin_hpd_event(struct cec_adapter *adap, bool is_high, ktime_t ts);
308+
299309
/**
300310
* cec_get_edid_phys_addr() - find and return the physical address
301311
*

‎include/uapi/linux/cec.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ struct cec_log_addrs {
410410
#define CEC_EVENT_LOST_MSGS 2
411411
#define CEC_EVENT_PIN_CEC_LOW 3
412412
#define CEC_EVENT_PIN_CEC_HIGH 4
413+
#define CEC_EVENT_PIN_HPD_LOW 5
414+
#define CEC_EVENT_PIN_HPD_HIGH 6
413415

414416
#define CEC_EVENT_FL_INITIAL_STATE (1 << 0)
415417
#define CEC_EVENT_FL_DROPPED_EVENTS (1 << 1)

0 commit comments

Comments
 (0)