From 672e90c932ac356bc81bd98f71b9218b20552329 Mon Sep 17 00:00:00 2001 From: gaoyang3513 Date: Tue, 2 Jul 2024 17:15:14 +0800 Subject: [PATCH] =?UTF-8?q?[Mod]=20SPI=E9=A9=B1=E5=8A=A8=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spi/pn5180.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 spi/pn5180.c diff --git a/spi/pn5180.c b/spi/pn5180.c new file mode 100644 index 000000000..17f27ac53 --- /dev/null +++ b/spi/pn5180.c @@ -0,0 +1,60 @@ +#include +#include +#include + +#define IS_USE_STATIC_PLATFORM_DATA 0 + +struct CHIP { + struct spi_device *spi; +}; + +#if IS_USE_STATIC_PLATFORM_DATA +struct CHIP_platform_data { + int spi_ch; +}; +#endif // IS_USE_STATIC_PLATFORM_DATA + +static int CHIP_probe(struct spi_device *spi) +{ + struct CHIP *chip; +#if IS_USE_STATIC_PLATFORM_DATA + struct CHIP_platform_data *pdata; + + /* assuming the driver requires board-specific data: */ + pdata = (struct CHIP_platform_data *)&spi->dev.platform_data; + if (!pdata) + return -ENODEV; +#endif // IS_USE_STATIC_PLATFORM_DATA + + /* get memory for driver's per-chip state */ + chip = kzalloc(sizeof *chip, GFP_KERNEL); + if (!chip) + return -ENOMEM; + + spi_set_drvdata(spi, chip); + + return 0; +} + +int CHIP_remove(struct spi_device *spi) +{ + struct CHIP *chip = NULL; + + chip = (struct CHIP *)spi_get_drvdata(spi); + + kfree(chip); + + return 0; +} + +static struct spi_driver CHIP_driver = { + .driver = { + .name = "CHIP", + .owner = THIS_MODULE, + }, + + .probe = CHIP_probe, + .remove = CHIP_remove, +}; + +module_spi_driver(CHIP_driver);