61 lines
1.1 KiB
C
61 lines
1.1 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;
|
|
}
|
|
|
|
static struct spi_driver CHIP_driver = {
|
|
.driver = {
|
|
.name = "CHIP",
|
|
.owner = THIS_MODULE,
|
|
},
|
|
|
|
.probe = CHIP_probe,
|
|
.remove = CHIP_remove,
|
|
};
|
|
|
|
module_spi_driver(CHIP_driver);
|