SPI: chipselect 0 already in use

so, my idea is the as follows:

static int __init ModuleInit(void) 
/*1. allocate char device region
2. create class
3. create device
4. init device file 
5. register device into kernel
6. register spi driver 
7 . then i need to add board info, tried func spi_register_board_info() but it fails */
NOTE: there is no spidev under /dev directory.

Initially, there was spidev0.0 under /dev, when i use spi_busnum_to_mater() it was successful, but there was another issue, the kernel says: that CS pin is already in use.

you had spidev overlay/driver loaded, it took control of the spi node and spi pins configured inside the overlay.

Then you tried to load your driver on top, and tried to directly use that CS pin, well it was owned by spidev driver which was already loaded…

I’m not sure why you are wanting to write a adxl345 driver, is this a university exercise?

As for a “NON” DT driver, there already exists one in kernel tree: adxl34x.c « misc « input « drivers - kernel/git/torvalds/linux.git - Linux kernel source tree (spi bits: adxl34x-spi.c « misc « input « drivers - kernel/git/torvalds/linux.git - Linux kernel source tree )

along with a DT version under iio: adxl345_core.c « accel « iio « drivers - kernel/git/torvalds/linux.git - Linux kernel source tree

Along with a dozen ‘spidev’ versions running thru python…

The adxl345 is one of those devices that has had many different drivers written for it over the years…


how to make sure that overlay/driver loaded?

this is not a university exercise, i’m trying to understand Linux driver on my own, create char device driver under /dev and getting access from user space with a help of read and write.

easy way, plug in a usb-serial adapter into j1, u-boot will report if it loaded the overlay…


BBB-output.txt (3.9 KB)
not 100% sure, looks like all overlays disabled:

From that output, you are booting your BBB, with a disabled ADC, eMMC and HDMI…


I modified file BB-SPIDEV0-00A0.dts from source in the following way:
comment out the line, which I suppose control CS pin:
AM33XX_PADCONF(AM335X_PIN_SPI0_CS0, PIN_INPUT, MUX_MODE0) /* P9_17 (A16) spi0_cs0.spi0_cs0 */
But I don’t know how to compile this specific file.
My idea is to disable CS pin from SPIDEV and let my interface driver controls it.

From the base directory of the git project hosting that file…



My steps:

  1. under directory arch/arm/boot/dts/overlays copied file BB-SPIDEV0-00A0.dts into BB-SPIDEV0-CUSTOM-00A0.dts.
  2. being under aforementioned dir, run the command:
    dtc -@ -I dts -O dtb -o BB-SPIDEV0-CUSTOM-00A0.dtbo BB-SPIDEV0-CUSTOM-00A0.dts
    The output:
Error: BB-SPIDEV0-CUSTOM-00A0.dts:10.1-9 syntax error
FATAL ERROR: Unable to parse input tree

I assume this is b/c some other files are included and dtc can’t resolve these dependencies.

Next steps:

  1. under dir /linux run command:
    sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs
    The output:
  DTC     arch/arm/boot/dts/am335x-boneblack.dtb                                                                                                                                        
  DTC     arch/arm/boot/dts/am335x-boneblack-pruswuart.dtb                                                                                                                              
  DTC     arch/arm/boot/dts/am335x-bonegreen.dtb                                                                                                                                        
  DTC     arch/arm/boot/dts/am335x-bonegreen-wireless.dtb                                                                                                                               
  DTC     arch/arm/boot/dts/am335x-boneblack-pps.dtb                                                                                                                                    
  DTC     arch/arm/boot/dts/am335x-sancloud-bbe.dtb

The point is that after this there is no file BB-SPIDEV0-CUSTOM-00A0.dtbo as I expected.
The goal is to compile file BB-SPIDEV0-CUSTOM-00A0.dts info BB-SPIDEV0-CUSTOM-00A0.dtbo, then transfer it to BBB and enable it in uEnv.txt
Could you please help me how to compile .dts into .dtbo?

For the kernel build scripts, you need to add it to the makefile…


I hope that I am reading your post correctly, if not my apologies in advance.

1.Clone the tree on your host, not the target.

$git clone https://openbeagle.org/beagleboard/BeagleBoard-DeviceTrees.git

2.On your ubuntu / Debian host

$sudo apt install device-tree-compiler

Step into top of the tree then create and checkout your own branch

$git checkout -B my-bbb

This lets you work in your own tree and main tree is original. Modify the dts file and save it then run make and it will only generate a .dtbo for the file you modified (this is after the second launch of make, first time it will generate all the .dtbo files).

Now you have a .dtbo, it is portable, no need for cross-compile. Just move it to your target from the host and edit your uEnv.txt if needed to reflect that absolute file path. Typically place it with all the others under overlays.

What i did:

  1. cloned device tree (https://openbeagle.org/beagleboard/BeagleBoard-DeviceTrees);
  2. create a separate branch (based on v5.10.x-ti-unified);
  3. under /src/arm/overlay copy BB-SPIDEV0-00A0.dts into BB-SPIDEV0-CUSTOM-00A0.dts (no modification inside);
  4. run make;
  5. transfer BB-SPIDEV0-00A0.dtbo to BBB;
  6. copy BB-SPIDEV0-00A0.dtbo into /lib/firmware;
  7. enable it in /boot/uEnv.txt (uboot_overlay_addr6=/lib/firmware/BB-SPIDEV0-CUSTOM-00A0.dtbo);
  8. reboot BBB;
  9. after reboot there is no spidev0.0 or spidev0.1 under /dev.
    NOTE: after enabling in /boot/uEnv.txt
    spidev0.0 and spidev0.1 are in /dev directory.
    What i missed?

I don’t have a bbb in front of me at the moment, however if I recall properly it was in /boot/dtbs/5.xxxxx/overlays.

Something like that, your image might be different than what I am using.

I moved BB-SPIDEV0-CUSTOM-00A0.dtbo file into /boot/dtbs/5.10.168-ti-r72/overlays
Edited /boot/uEnv.txt file:
boot output looks:

Anyway, there is no spidev0.x in the system.

is the spidev kernel module loaded?


based on lsmod output spidev is not loaded.
I expected, after enabling BB-SPIDEV0-CUSTOM-00A0.dtbo in /boot/uEnv.txt the kernel parsed it and loaded corresponding module.

Doesn’t always happen… Just modprobe spidev…

it works, thanks.