Files
Linux_Drivers/spi/02-Sub1G_CMT2301/cmt2301.c
2024-07-19 15:22:44 +08:00

76 lines
1.5 KiB
C

#include <linux/module.h>
#include <linux/slab.h>
#include <linux/spi/spi.h>
#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;
}
#ifdef CONFIG_OF
static const struct of_device_id CHIP_of_match[] = {
{ .compatible = "nxp,pn5180", },
{ }
};
MODULE_DEVICE_TABLE(of, CHIP_of_match); // Used by file2alias, which indicated what devices are support with this drive.
#endif // CONFIG_OF
static struct spi_driver CHIP_driver = {
.driver = {
.name = "CHIP",
.owner = THIS_MODULE,
#ifdef CONFIG_OF
.of_match_table = CHIP_of_match,
#endif // CONFIG_OF
},
.probe = CHIP_probe,
.remove = CHIP_remove,
};
module_spi_driver(CHIP_driver);
MODULE_AUTHOR("Gao yang <gaoyang3513@163.com>");
MODULE_DESCRIPTION("NXP PN5180 NFC driver");
MODULE_LICENSE("GPL");