162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * cec-pin.h - low-level CEC pin control
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef LINUX_CEC_PIN_H
962306a36Sopenharmony_ci#define LINUX_CEC_PIN_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <linux/types.h>
1262306a36Sopenharmony_ci#include <media/cec.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/**
1562306a36Sopenharmony_ci * struct cec_pin_ops - low-level CEC pin operations
1662306a36Sopenharmony_ci * @read:	read the CEC pin. Returns > 0 if high, 0 if low, or an error
1762306a36Sopenharmony_ci *		if negative.
1862306a36Sopenharmony_ci * @low:	drive the CEC pin low.
1962306a36Sopenharmony_ci * @high:	stop driving the CEC pin. The pull-up will drive the pin
2062306a36Sopenharmony_ci *		high, unless someone else is driving the pin low.
2162306a36Sopenharmony_ci * @enable_irq:	optional, enable the interrupt to detect pin voltage changes.
2262306a36Sopenharmony_ci * @disable_irq: optional, disable the interrupt.
2362306a36Sopenharmony_ci * @free:	optional. Free any allocated resources. Called when the
2462306a36Sopenharmony_ci *		adapter is deleted.
2562306a36Sopenharmony_ci * @status:	optional, log status information.
2662306a36Sopenharmony_ci * @read_hpd:	optional. Read the HPD pin. Returns > 0 if high, 0 if low or
2762306a36Sopenharmony_ci *		an error if negative.
2862306a36Sopenharmony_ci * @read_5v:	optional. Read the 5V pin. Returns > 0 if high, 0 if low or
2962306a36Sopenharmony_ci *		an error if negative.
3062306a36Sopenharmony_ci * @received:	optional. High-level CEC message callback. Allows the driver
3162306a36Sopenharmony_ci *		to process CEC messages.
3262306a36Sopenharmony_ci *
3362306a36Sopenharmony_ci * These operations (except for the @received op) are used by the
3462306a36Sopenharmony_ci * cec pin framework to manipulate the CEC pin.
3562306a36Sopenharmony_ci */
3662306a36Sopenharmony_cistruct cec_pin_ops {
3762306a36Sopenharmony_ci	int  (*read)(struct cec_adapter *adap);
3862306a36Sopenharmony_ci	void (*low)(struct cec_adapter *adap);
3962306a36Sopenharmony_ci	void (*high)(struct cec_adapter *adap);
4062306a36Sopenharmony_ci	bool (*enable_irq)(struct cec_adapter *adap);
4162306a36Sopenharmony_ci	void (*disable_irq)(struct cec_adapter *adap);
4262306a36Sopenharmony_ci	void (*free)(struct cec_adapter *adap);
4362306a36Sopenharmony_ci	void (*status)(struct cec_adapter *adap, struct seq_file *file);
4462306a36Sopenharmony_ci	int  (*read_hpd)(struct cec_adapter *adap);
4562306a36Sopenharmony_ci	int  (*read_5v)(struct cec_adapter *adap);
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci	/* High-level CEC message callback */
4862306a36Sopenharmony_ci	int (*received)(struct cec_adapter *adap, struct cec_msg *msg);
4962306a36Sopenharmony_ci};
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci/**
5262306a36Sopenharmony_ci * cec_pin_changed() - update pin state from interrupt
5362306a36Sopenharmony_ci *
5462306a36Sopenharmony_ci * @adap:	pointer to the cec adapter
5562306a36Sopenharmony_ci * @value:	when true the pin is high, otherwise it is low
5662306a36Sopenharmony_ci *
5762306a36Sopenharmony_ci * If changes of the CEC voltage are detected via an interrupt, then
5862306a36Sopenharmony_ci * cec_pin_changed is called from the interrupt with the new value.
5962306a36Sopenharmony_ci */
6062306a36Sopenharmony_civoid cec_pin_changed(struct cec_adapter *adap, bool value);
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/**
6362306a36Sopenharmony_ci * cec_pin_allocate_adapter() - allocate a pin-based cec adapter
6462306a36Sopenharmony_ci *
6562306a36Sopenharmony_ci * @pin_ops:	low-level pin operations
6662306a36Sopenharmony_ci * @priv:	will be stored in adap->priv and can be used by the adapter ops.
6762306a36Sopenharmony_ci *		Use cec_get_drvdata(adap) to get the priv pointer.
6862306a36Sopenharmony_ci * @name:	the name of the CEC adapter. Note: this name will be copied.
6962306a36Sopenharmony_ci * @caps:	capabilities of the CEC adapter. This will be ORed with
7062306a36Sopenharmony_ci *		CEC_CAP_MONITOR_ALL and CEC_CAP_MONITOR_PIN.
7162306a36Sopenharmony_ci *
7262306a36Sopenharmony_ci * Allocate a cec adapter using the cec pin framework.
7362306a36Sopenharmony_ci *
7462306a36Sopenharmony_ci * Return: a pointer to the cec adapter or an error pointer
7562306a36Sopenharmony_ci */
7662306a36Sopenharmony_cistruct cec_adapter *cec_pin_allocate_adapter(const struct cec_pin_ops *pin_ops,
7762306a36Sopenharmony_ci					void *priv, const char *name, u32 caps);
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci#endif
80