linux-loongson/include/linux/spi/offload/provider.h
David Lechner d7231be4b4
spi: offload: add support for hardware triggers
Extend SPI offloading to support hardware triggers.

This allows an arbitrary hardware trigger to be used to start a SPI
transfer that was previously set up with spi_optimize_message().

A new struct spi_offload_trigger is introduced that can be used to
configure any type of trigger. It has a type discriminator and a union
to allow it to be extended in the future. Two trigger types are defined
to start with. One is a trigger that indicates that the SPI peripheral
is ready to read or write data. The other is a periodic trigger to
repeat a SPI message at a fixed rate.

There is also a spi_offload_hw_trigger_validate() function that works
similar to clk_round_rate(). It basically asks the question of if we
enabled the hardware trigger what would the actual parameters be. This
can be used to test if the requested trigger type is actually supported
by the hardware and for periodic triggers, it can be used to find the
actual rate that the hardware is capable of.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250207-dlech-mainline-spi-engine-offload-2-v8-2-e48a489be48c@baylibre.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2025-02-07 20:17:08 +00:00

48 lines
1.5 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2024 Analog Devices Inc.
* Copyright (C) 2024 BayLibre, SAS
*/
#ifndef __LINUX_SPI_OFFLOAD_PROVIDER_H
#define __LINUX_SPI_OFFLOAD_PROVIDER_H
#include <linux/module.h>
#include <linux/spi/offload/types.h>
#include <linux/types.h>
MODULE_IMPORT_NS("SPI_OFFLOAD");
struct device;
struct spi_offload_trigger;
struct spi_offload *devm_spi_offload_alloc(struct device *dev, size_t priv_size);
struct spi_offload_trigger_ops {
bool (*match)(struct spi_offload_trigger *trigger,
enum spi_offload_trigger_type type, u64 *args, u32 nargs);
int (*request)(struct spi_offload_trigger *trigger,
enum spi_offload_trigger_type type, u64 *args, u32 nargs);
void (*release)(struct spi_offload_trigger *trigger);
int (*validate)(struct spi_offload_trigger *trigger,
struct spi_offload_trigger_config *config);
int (*enable)(struct spi_offload_trigger *trigger,
struct spi_offload_trigger_config *config);
void (*disable)(struct spi_offload_trigger *trigger);
};
struct spi_offload_trigger_info {
/** @fwnode: Provider fwnode, used to match to consumer. */
struct fwnode_handle *fwnode;
/** @ops: Provider-specific callbacks. */
const struct spi_offload_trigger_ops *ops;
/** Provider-specific state to be used in callbacks. */
void *priv;
};
int devm_spi_offload_trigger_register(struct device *dev,
struct spi_offload_trigger_info *info);
void *spi_offload_trigger_get_priv(struct spi_offload_trigger *trigger);
#endif /* __LINUX_SPI_OFFLOAD_PROVIDER_H */