xref: /openbmc/linux/include/media/cec-pin.h (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1ab15d248SHans Verkuil /* SPDX-License-Identifier: GPL-2.0-only */
2ea5c8ef2SHans Verkuil /*
3ea5c8ef2SHans Verkuil  * cec-pin.h - low-level CEC pin control
4ea5c8ef2SHans Verkuil  *
5ea5c8ef2SHans Verkuil  * Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6ea5c8ef2SHans Verkuil  */
7ea5c8ef2SHans Verkuil 
8ea5c8ef2SHans Verkuil #ifndef LINUX_CEC_PIN_H
9ea5c8ef2SHans Verkuil #define LINUX_CEC_PIN_H
10ea5c8ef2SHans Verkuil 
11ea5c8ef2SHans Verkuil #include <linux/types.h>
12ea5c8ef2SHans Verkuil #include <media/cec.h>
13ea5c8ef2SHans Verkuil 
14ea5c8ef2SHans Verkuil /**
15ea5c8ef2SHans Verkuil  * struct cec_pin_ops - low-level CEC pin operations
16*e5ad7db4SHans Verkuil  * @read:	read the CEC pin. Returns > 0 if high, 0 if low, or an error
17*e5ad7db4SHans Verkuil  *		if negative.
18ea5c8ef2SHans Verkuil  * @low:	drive the CEC pin low.
19ea5c8ef2SHans Verkuil  * @high:	stop driving the CEC pin. The pull-up will drive the pin
20ea5c8ef2SHans Verkuil  *		high, unless someone else is driving the pin low.
21ea5c8ef2SHans Verkuil  * @enable_irq:	optional, enable the interrupt to detect pin voltage changes.
22ea5c8ef2SHans Verkuil  * @disable_irq: optional, disable the interrupt.
23ea5c8ef2SHans Verkuil  * @free:	optional. Free any allocated resources. Called when the
24ea5c8ef2SHans Verkuil  *		adapter is deleted.
25ea5c8ef2SHans Verkuil  * @status:	optional, log status information.
26*e5ad7db4SHans Verkuil  * @read_hpd:	optional. Read the HPD pin. Returns > 0 if high, 0 if low or
27*e5ad7db4SHans Verkuil  *		an error if negative.
28*e5ad7db4SHans Verkuil  * @read_5v:	optional. Read the 5V pin. Returns > 0 if high, 0 if low or
29*e5ad7db4SHans Verkuil  *		an error if negative.
3069e3235dSHans Verkuil  * @received:	optional. High-level CEC message callback. Allows the driver
3169e3235dSHans Verkuil  *		to process CEC messages.
3269e3235dSHans Verkuil  *
3369e3235dSHans Verkuil  * These operations (except for the @received op) are used by the
3469e3235dSHans Verkuil  * cec pin framework to manipulate the CEC pin.
35ea5c8ef2SHans Verkuil  */
36ea5c8ef2SHans Verkuil struct cec_pin_ops {
37*e5ad7db4SHans Verkuil 	int  (*read)(struct cec_adapter *adap);
38ea5c8ef2SHans Verkuil 	void (*low)(struct cec_adapter *adap);
39ea5c8ef2SHans Verkuil 	void (*high)(struct cec_adapter *adap);
40ea5c8ef2SHans Verkuil 	bool (*enable_irq)(struct cec_adapter *adap);
41ea5c8ef2SHans Verkuil 	void (*disable_irq)(struct cec_adapter *adap);
42ea5c8ef2SHans Verkuil 	void (*free)(struct cec_adapter *adap);
43ea5c8ef2SHans Verkuil 	void (*status)(struct cec_adapter *adap, struct seq_file *file);
44333ef6bdSHans Verkuil 	int  (*read_hpd)(struct cec_adapter *adap);
454786b0d6SHans Verkuil 	int  (*read_5v)(struct cec_adapter *adap);
4669e3235dSHans Verkuil 
4769e3235dSHans Verkuil 	/* High-level CEC message callback */
4869e3235dSHans Verkuil 	int (*received)(struct cec_adapter *adap, struct cec_msg *msg);
49ea5c8ef2SHans Verkuil };
50ea5c8ef2SHans Verkuil 
51ea5c8ef2SHans Verkuil /**
52ea5c8ef2SHans Verkuil  * cec_pin_changed() - update pin state from interrupt
53ea5c8ef2SHans Verkuil  *
54ea5c8ef2SHans Verkuil  * @adap:	pointer to the cec adapter
55ea5c8ef2SHans Verkuil  * @value:	when true the pin is high, otherwise it is low
56ea5c8ef2SHans Verkuil  *
57ea5c8ef2SHans Verkuil  * If changes of the CEC voltage are detected via an interrupt, then
58ea5c8ef2SHans Verkuil  * cec_pin_changed is called from the interrupt with the new value.
59ea5c8ef2SHans Verkuil  */
60ea5c8ef2SHans Verkuil void cec_pin_changed(struct cec_adapter *adap, bool value);
61ea5c8ef2SHans Verkuil 
62ea5c8ef2SHans Verkuil /**
63ea5c8ef2SHans Verkuil  * cec_pin_allocate_adapter() - allocate a pin-based cec adapter
64ea5c8ef2SHans Verkuil  *
65ea5c8ef2SHans Verkuil  * @pin_ops:	low-level pin operations
66ea5c8ef2SHans Verkuil  * @priv:	will be stored in adap->priv and can be used by the adapter ops.
67ea5c8ef2SHans Verkuil  *		Use cec_get_drvdata(adap) to get the priv pointer.
68ea5c8ef2SHans Verkuil  * @name:	the name of the CEC adapter. Note: this name will be copied.
69ea5c8ef2SHans Verkuil  * @caps:	capabilities of the CEC adapter. This will be ORed with
70ea5c8ef2SHans Verkuil  *		CEC_CAP_MONITOR_ALL and CEC_CAP_MONITOR_PIN.
71ea5c8ef2SHans Verkuil  *
72ea5c8ef2SHans Verkuil  * Allocate a cec adapter using the cec pin framework.
73ea5c8ef2SHans Verkuil  *
74ea5c8ef2SHans Verkuil  * Return: a pointer to the cec adapter or an error pointer
75ea5c8ef2SHans Verkuil  */
76ea5c8ef2SHans Verkuil struct cec_adapter *cec_pin_allocate_adapter(const struct cec_pin_ops *pin_ops,
77ea5c8ef2SHans Verkuil 					void *priv, const char *name, u32 caps);
78ea5c8ef2SHans Verkuil 
79ea5c8ef2SHans Verkuil #endif
80