[Mod] SPI驱动模板
This commit is contained in:
60
spi/pn5180.c
Normal file
60
spi/pn5180.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct spi_driver CHIP_driver = {
|
||||||
|
.driver = {
|
||||||
|
.name = "CHIP",
|
||||||
|
.owner = THIS_MODULE,
|
||||||
|
},
|
||||||
|
|
||||||
|
.probe = CHIP_probe,
|
||||||
|
.remove = CHIP_remove,
|
||||||
|
};
|
||||||
|
|
||||||
|
module_spi_driver(CHIP_driver);
|
||||||
Reference in New Issue
Block a user