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