mirror of
https://github.com/bashrc/LKMPG.git
synced 2018-06-11 03:06:54 +02:00
spi example
This commit is contained in:
@@ -28,6 +28,7 @@ obj-m += example_rwlock.o
|
||||
obj-m += example_atomic.o
|
||||
obj-m += example_mutex.o
|
||||
obj-m += bottomhalf.o
|
||||
obj-m += example_spi.o
|
||||
|
||||
all:
|
||||
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
|
||||
|
||||
47
4.9.11/examples/example_spi.c
Normal file
47
4.9.11/examples/example_spi.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/spi/spi.h>
|
||||
|
||||
static int spi_probe(struct spi_device *spi)
|
||||
{
|
||||
int ret;
|
||||
|
||||
printk("spi example probe\n");
|
||||
|
||||
spi->bits_per_word = 8;
|
||||
spi->mode = SPI_MODE_0;
|
||||
ret = spi_setup(spi);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
printk("spi device name = %s \n", spi->modalias);
|
||||
printk("spi device freq = %d \n", spi->max_speed_hz);
|
||||
printk("spi device's bus_num = %d \n", spi->master->bus_num);
|
||||
printk("spi device cs = %d \n", spi->chip_select);
|
||||
printk("spi device mode = %d \n\n", spi->mode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int spi_remove(struct spi_device *spi)
|
||||
{
|
||||
printk("spi example remove\n");
|
||||
|
||||
/* Your spi remove code */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct spi_driver my_spi_driver = {
|
||||
.driver = {
|
||||
.name = "my_spi",
|
||||
},
|
||||
.probe = spi_probe,
|
||||
.remove = spi_remove,
|
||||
};
|
||||
|
||||
module_spi_driver(my_spi_driver);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Bob Mottram");
|
||||
MODULE_DESCRIPTION("SPI driver module example");
|
||||
Reference in New Issue
Block a user