xref: /linux/drivers/spi/spi-offload-trigger-adi-util-sigma-delta.c (revision 0262163136de813894cb172aa8ccf762b92e5fd7)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2025 Analog Devices Inc.
4  * Copyright (C) 2025 BayLibre, SAS
5  */
6 
7 #include <linux/clk.h>
8 #include <linux/device.h>
9 #include <linux/mod_devicetable.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/property.h>
13 #include <linux/spi/offload/provider.h>
14 
adi_util_sigma_delta_match(struct spi_offload_trigger * trigger,enum spi_offload_trigger_type type,u64 * args,u32 nargs)15 static bool adi_util_sigma_delta_match(struct spi_offload_trigger *trigger,
16 				       enum spi_offload_trigger_type type,
17 				       u64 *args, u32 nargs)
18 {
19 	return type == SPI_OFFLOAD_TRIGGER_DATA_READY && nargs == 0;
20 }
21 
22 static const struct spi_offload_trigger_ops adi_util_sigma_delta_ops = {
23 	.match = adi_util_sigma_delta_match,
24 };
25 
adi_util_sigma_delta_probe(struct platform_device * pdev)26 static int adi_util_sigma_delta_probe(struct platform_device *pdev)
27 {
28 	struct device *dev = &pdev->dev;
29 	struct spi_offload_trigger_info info = {
30 		.fwnode = dev_fwnode(dev),
31 		.ops = &adi_util_sigma_delta_ops,
32 	};
33 	struct clk *clk;
34 
35 	clk = devm_clk_get_enabled(dev, NULL);
36 	if (IS_ERR(clk))
37 		return dev_err_probe(dev, PTR_ERR(clk), "Failed to get clock\n");
38 
39 	return devm_spi_offload_trigger_register(dev, &info);
40 }
41 
42 static const struct of_device_id adi_util_sigma_delta_of_match_table[] = {
43 	{ .compatible = "adi,util-sigma-delta-spi", },
44 	{ }
45 };
46 MODULE_DEVICE_TABLE(of, adi_util_sigma_delta_of_match_table);
47 
48 static struct platform_driver adi_util_sigma_delta_driver = {
49 	.probe  = adi_util_sigma_delta_probe,
50 	.driver = {
51 		.name = "adi-util-sigma-delta-spi",
52 		.of_match_table = adi_util_sigma_delta_of_match_table,
53 	},
54 };
55 module_platform_driver(adi_util_sigma_delta_driver);
56 
57 MODULE_AUTHOR("David Lechner <dlechner@baylibre.com>");
58 MODULE_DESCRIPTION("ADI Sigma-Delta SPI offload trigger utility driver");
59 MODULE_LICENSE("GPL");
60