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