1
0
mirror of https://github.com/bashrc/LKMPG.git synced 2018-06-11 03:06:54 +02:00

spi example

This commit is contained in:
Bob Mottram
2017-08-09 17:29:52 +01:00
parent c1461bf703
commit 0a3f68b4fb
2 changed files with 48 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ obj-m += example_rwlock.o
obj-m += example_atomic.o obj-m += example_atomic.o
obj-m += example_mutex.o obj-m += example_mutex.o
obj-m += bottomhalf.o obj-m += bottomhalf.o
obj-m += example_spi.o
all: all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

View 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");