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