0

Having trouble binding a SPI driver on the BeagleBone Black. The driver in question, ltc2947-spi, is in the linux mainline, but not in the beaglebone kernel tree. When I get this working, I'll submit a PR to add it.

I compiled the ltc2947 drivers as an out-of-tree module using this repo (also on github).

 % sudo apt-get install linux-headers-$(uname -r)
 % find /lib/modules/$(uname -r) -iname "*ltc29*"
 % make

The module compiles fine, and modinfo produces the expected output:

 % sudo modinfo ltc2947-spi.ko                                  
filename:       /home/lily/kmod-ltc2947/ltc2947-spi.ko
license:        GPL
description:    LTC2947 SPI power and energy monitor driver
author:         Nuno Sa <nuno.sa@analog.com>
alias:          spi:ltc2947
depends:        ltc2947-core
name:           ltc2947_spi
vermagic:       5.4.70-ti-r19 SMP preempt mod_unload modversions ARMv7 p2v8 

And insmod appears to insert the module correctly (note there are two modules, since the SPI and I2C drivers for this chip share a common core):

 % sudo insmod ./ltc2947-core.ko && sudo insmod ./ltc2947-spi.ko
 % grep ltc2947 /proc/modules
ltc2947_spi 16384 0 - Live 0x00000000 (O)
ltc2947_core 24576 1 ltc2947_spi, Live 0x00000000 (O)
 % tree /sys/bus/spi/drivers/ltc2947 
/sys/bus/spi/drivers/ltc2947
├── bind
├── module -> ../../../../module/ltc2947_spi
├── uevent
└── unbind

1 directory, 3 files

From here, I need to bind the driver to a device on the SPI bus. I'm using the Mikroe VCP Monitor 3 Click connected to SPI via the mikroBus Cape. The board is in slot 1 right now, so the pin connections are:

  • P9_28: CS
  • P9_29: MISO
  • P9_30: MOSI
  • P9_31: SCK

It is not yet clear to me where I specify the chip select pin, or how to determine the string to echo to /sys/bus/usb/drivers/ltc2947/bind.

The pins from the cape correspond to spi1, according to this diagram: beaglebone black SPI pinout and I noticed spi1 was already bound to spidev, so I unbind it:

 % echo "spi1.0" | sudo tee -a /sys/bus/spi/drivers/spidev/unbind
spi1.0
 % echo "spi1.1" | sudo tee -a /sys/bus/spi/drivers/spidev/unbind
spi1.1
 % tree /sys/bus/spi/drivers/spidev                              
/sys/bus/spi/drivers/spidev
├── bind
├── module -> ../../../../module/spidev
├── spi0.0 -> ../../../../devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48030000.target-module/48030000.spi/spi_master/spi0/spi0.0
├── spi0.1 -> ../../../../devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48030000.target-module/48030000.spi/spi_master/spi0/spi0.1
├── uevent
└── unbind

3 directories, 3 files

But then when I try to bind it to the ltc2947 driver, it gives the error "/sys/bus/spi/drivers/ltc2947/bind: No such device":

 % echo "spi1" | sudo tee -a /sys/bus/spi/drivers/ltc2947/bind 
spi1
tee: /sys/bus/spi/drivers/ltc2947/bind: No such device
 % echo "spi1.0" | sudo tee -a /sys/bus/spi/drivers/ltc2947/bind
spi1.0
tee: /sys/bus/spi/drivers/ltc2947/bind: No such device
 % echo "spi1.1" | sudo tee -a /sys/bus/spi/drivers/ltc2947/bind
spi1.1
tee: /sys/bus/spi/drivers/ltc2947/bind: No such device

Echoing to the bind under /sys/module produces the same result:

 % echo "spi1" | sudo tee -a /sys/module/ltc2947_spi/drivers/spi:ltc2947/bind  
spi1
tee: '/sys/module/ltc2947_spi/drivers/spi:ltc2947/bind': No such device
0

Found a page on the Analog Devices Wiki that pointed me in the right direction.

Currently, the devices can only be instantiated via device tree.

So for the Beaglebone Black, I drafted a device tree overlay and sent a pull request to bb.org-overlays.

I've tested this with a LED + resistor as the load on the VCP Monitor 3 click, and can successfully read voltage, current, power, and energy from files under /sys/class/hwmon/hwmon0, e.g.:

lily@beaglebone /sys/class/hwmon/hwmon0
% cat name                 
ltc2947
lily@beaglebone /sys/class/hwmon/hwmon0
% echo 1 > in0_reset_history 
lily@beaglebone /sys/class/hwmon/hwmon0
% cat in0_label            
VP-VM
lily@beaglebone /sys/class/hwmon/hwmon0
% cat in0_input
0

# Here I turned on 5V @ 12 mA to light an LED

lily@beaglebone /sys/class/hwmon/hwmon0
% cat in0_input  
5054

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.