Thanks guys, I think I'm making some progress now.....if only I had more time :)
I found this little guy: https://github.com/torvalds/linux/blob/master/drivers/hwmon/lm70.c Only 181 lines so not too complicated, will have a go at adapting it to read the device id from my breakout board. Also need to pop over to Emilio's repo as he was working on releasing dma enabled spi for sunxi. On Sun, Aug 3, 2014 at 2:23 PM, Maxime Ripard < [email protected]> wrote: > On Sat, Aug 02, 2014 at 11:45:22PM -0700, bruce bushby wrote: > > Hi > > > > I've been wanting to write an SPI skeleton driver to learn the basics. > I'm > > hoping a driver guru could offer some guidance. > > > > The idea is to write a skeleton driver that simply prints the chip id > > > > Kernel: stock standard mainline 3.16.0-rc7 kernel on Olimex A20-SOM (EVK) > > Device: MPU9250 Break out board > > > > My thinking so far: > > > > 1. DTS > > Add an SPI slave device to my DTS file. > > > > I will connect the Break out board to the second SPI bus .... so need to > > add the slave device to SPI1 > > > > Existing SPI1 device (from dts file) > > > > spi1: spi@01c06000 { > > pinctrl-names = "default"; > > pinctrl-0 = <&spi1_pins_a>; > > status = "okay"; > > }; > > > > > > Adding SPI1 slave device: > > > > spi1: spi@01c06000 { > > pinctrl-names = "default"; > > pinctrl-0 = <&spi1_pins_a>; > > status = "okay"; > > > > mpu9250@0 { > > compatible = "mpu9250"; > > reg = <0>; > > spi-max-frequency = <1000000>; > > ???? interrupt pin .... gpio ??????? > > }; > > > > }; > > This one is okay. > > > 2. The driver will create an entry in "sysfs" and a "corresponding" entry > > in /dev. Catting the device " /dev/mpu9250 " will return the device id. > > > > Then the driver will be a standard Linux kernel module with support for > SPI > > .... > > #include <linux/module.h> > > #include <linux/spi/spi.h> > > .... > > > > struct spi_driver > > spi_register_driver (struct device dev; dictates the name of the > device) > > spi_alloc_device > > spi_add_device > > Not quite. > > You should declare a struct spi_driver, register it using > spi_register_module, and in that structure, put the compatibles you > support. You'll also have to implement the probe and remove functions, > give in that spi_driver structure pointers to these functions, and > Linux will call probe whenever a device shows up, and call remove > whenever that device disappears. > > Note that all this is covered in LDD3 and > http://free-electrons.com/doc/training/linux-kernel/slides.pdf, so I'd > suggest you go read these two, like I suggested you already (or should > have) > > As for how to find simple SPI drivers, I don't really have an example > in mind, but you can search for spi_register_module, you should have a > huge number of hits. > > Maxime > > -- > Maxime Ripard, Free Electrons > Embedded Linux, Kernel and Android engineering > http://free-electrons.com > -- You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
