From 0a3f68b4fbf48db339a1ad7e2f643b3a9642cee1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 9 Aug 2017 17:29:52 +0100 Subject: [PATCH] spi example --- 4.9.11/examples/Makefile | 1 + 4.9.11/examples/example_spi.c | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 4.9.11/examples/example_spi.c diff --git a/4.9.11/examples/Makefile b/4.9.11/examples/Makefile index cdeca07..1be0b31 100644 --- a/4.9.11/examples/Makefile +++ b/4.9.11/examples/Makefile @@ -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 diff --git a/4.9.11/examples/example_spi.c b/4.9.11/examples/example_spi.c new file mode 100644 index 0000000..3bfa65c --- /dev/null +++ b/4.9.11/examples/example_spi.c @@ -0,0 +1,47 @@ +#include +#include +#include + +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");