tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Kernel doesn't call spi driver's _match() and _attach()



I followed NetBSD bus space tutorial
(https://wiki.netbsd.org/tutorials/bus_space_tutorial/), but used spi(4)
bus instead of pci(4).

I am using evbarm port for RPI 1 (earmv6hf) and it's kernel config
sys/arch/evbarm/conf/RPI.

What I have at the moment:
* driver source at sys/dev/spi/mydev.c

* entry in sys/dev/spi/files.spi:
	device mydev
	attach mydev at spi
	file   dev/spi/mydev.c		mydev

* entry in sys/dev/DEVNAMES:
	mydev	MI

* entry in sys/arch/evbarm/conf/RPI:
	mydev0 at spi0 slave 0
	device-major mydev char 666 mydev

So, when I compile RPI kernel with build.sh:
	$ ./build.sh ... -m evbarm -a earmv6hf -N1 kernel=RPI 2> /dev/null

I can see how my driver gets successfully compiled and it's object file
gets placed into obj/ directory.

Once installed successfully built kernel, in mknod(8)'s list of drivers I
can see my driver is actually in there:
	$ mknod -l | grep mydev
	mydev character major 666

According to spi(4):
> Note that when referencing SPI devices in a config(1) file, the `slave'
> must be provided, as SPI lacks any way to automatically probe devices.
there is no probing available, so I created my device node manually:
	# mknod /dev/mydev0 c mydev 0
	# ls -l /dev/mydev0
	crw-r--r--  1 root  wheel  666, 0 Sep 16 17:19 /dev/mydev0

During open("/dev/mydev0", O_RDONLY) call no errors occured.  But when I
tried to perform one of ioctls from userland, I got invalid memory
access error in the very beginning of mydev_ioctl().

int
mydev_ioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *lwp)
{
	struct mydev_softc *sc;
	sc = device_lookup_private(&mydev_cd, minor(dev)); /* BANG! */
	...

After some time, I noticed that neither mydev_match(), nor mydev_attach()
gets called.  I suppose this was the root cause of problem, desribed above. 
Even though I provided necessary autoconfig interface via
CFATTACH_DECL_NEW(), it didn't work.

I have no idea why doesn't kernel call these two, or at least
mydev_match(), which in my case simply always returns 1.

Furthermore, it seems that kernel doesn't know anything about spi bus...
From spi(4):
> FILES
> /dev/spiu  SPI device unit u file.
I expected to see at least a bunch of /dev/spi* entries, but there is no
single one there (except something called spiflash):
	# ls /dev/spi*
	/dev/spiflash0

dmesg(8) also doesn't mention anything related to spi, but has, e.g. to i2c:
	# dmesg | grep spi
	# dmesg | grep iic
	[     1.000000] bsciic0 at simplebus1: Broadcom Serial Controller
	[     1.000000] bsciic0: interrupting on icu irq 53
	[     1.000000] iic0 at bsciic0: I2C bus
	[     1.000000] bsciic1 at simplebus1: Broadcom Serial Controller
	[     1.000000] bsciic1: interrupting on icu irq 53
	[     1.000000] iic1 at bsciic1: I2C bus
	[     1.000000] bsciic2 at simplebus1: Broadcom Serial Controller
	[     1.000000] bsciic2: interrupting on icu irq 53
	[     1.000000] iic2 at bsciic2: I2C bus

Spi is configured by default in sys/arch/evbarm/conf/RPI config file nearly
the same way, as i2c:
	# Broadcom Serial Control (I2C)
	bsciic* at fdt?
	iic* at i2cbus?
	...

	# SPI controller
	bcmspi* at fdt?
	spi* at spibus?

What I've tried to do is creating /dev/spiu device node manually:
	# cd /dev
	# sh MAKEDEV spi0
	# ls -l spi0
	crw-------  1 root  wheel  347, 0 Sep 16 22:08 spi0

`mknod -l` shows that kernel in fact has spi driver and spi device major
number is supposed to be 347.

So, why doesn't kernel know anything about spi bus even though it has spi
driver and autoconf can associate appropriate driver with spi device?  And,
after all, why doesn't kernel call mydev_match() and mydev_attach()
functions of my spi driver?

I'll be really grateful for any kind of information/help/resources you
provide
- Nikita


Home | Main Index | Thread Index | Old Index