How to bind my driver?

I’m trying to bind the device driver made myself.

My Device Tree is follows:

spi@7000d400 { /* it alias to ‘spi0’ */
status = “okay”;
reg = <0x0>;
nvidia,rx-clk-tap-delay = <7>;
/ {
eeprom-manager {
bus@0 {
status = “okay”;
spi_bus = <&spi0>;
compatible = “microchip,93LC56B”;
reg = <0>;
spi-max-frequency = <1000000>;
size = <256>;

and my driver is follows:

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/sched.h>
#include <linux/platform_device.h>
#include <linux/printk.h>

#include <linux/spi/spi.h>
#include <linux/spi/eeprom.h>
#include <linux/of.h>


  • NOTE: this is an EEPROM driver. The vagaries of product naming
  • mean that some 93L products are EEPROMs.

#define DRIVER_NAME “M93LC56B”

struct m93l_data {
struct spi_device * spi;
struct memory_accessor mem;
struct mutex lock;
struct spi_eeprom chip;
struct bin_attribute bin;
unsigned addrlen;

#define M93L_ERASE (3)
#define M93L_ERAL (0)
#define M93L_EWDS (0)
#define M93L_READ (2)
#define M93L_WRITE (1)
#define M93L_WRAL (0)

/* ------------------ for DTB ---------------------------------------- */
static const struct of_device_id m93l_of_match_table = {
.compatible = “microchip,93LC56B”,
} ;

MODULE_DEVICE_TABLE(of, m93l_of_match_table);

static struct platform_device_id m93l_spi_idtable = {
{“M93LC56B”,0 },
} ;

MODULE_DEVICE_TABLE(spi, m93l_spi_idtable) ;

/* ------------------------------------------------------------------- */

static struct platform_device *spi_dev = NULL ;

static int m93l_spi_probe( struct platform_device *dev )
spi_dev = dev ;

static int m93l_spi_remove( struct platform_device *dev )
spi_dev = NULL;
return 0;

/* ------- define driver function table ------------------------------- */
static struct platform_driver m93l_driver = {
.id_table = m93l_spi_idtable,
.probe = m93l_spi_probe,
.remove = m93l_spi_remove,
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
.pm = NULL,
.of_match_table = of_match_ptr( m93l_of_match_table ),
} ;

MODULE_DESCRIPTION(“Microchip EEPROM via API driver.”);

I think that the kernel searches my driver from Device Tree by ‘compatible’ palameter.
And It shows folder ‘/dev/’.

But now, It seems my driver is not found and loaded.

Please tell me some advices.

Thank you.

hello t.hirose,

it’s compatible property for device identifier;
the Linux kernel uses this keyword to bind the device driver to a specific device.
you may have the compatible member of the of_device_id structure, which must match what is specified in sensor’s device tree node.
please also check developer guide, Setting Up the V4L2 Subdevice and Camera Common for reference,

Hello, JerryChang.
Thank you for your advice.

But I could not understand well.
I wonder why my device not show in ‘/dev/’ folder.
I think the mechanism of driver binding like follows:
kernel scan the Device Tree
-> binding drivers from compatible palameter

If the kernel found the driver matching ‘compatible’, then the driver’s device appear in ‘/dev’ folder.

Is my Interpretation wrong ?
Are there the other method the driver bindings ?

I’m confusing…

hello t.hirose,

assume you would like to add your own driver to the linux kernel, you may also review Kconfig for adding the configuration.
please also make sure you’d specify the driver configure into Makefile for building kernel images.

Hello JerryChang.
I already got .o file and .ko file.
I wonder why the kernel don’t call my driver’s ‘probe’ function.
SPI is not ‘plug and play’ device. In this case, Don’t the kernel use ‘probe’ function?

How to bind the kernel and select the driver from the information in Device Tree?

Thank you.

hello t.hirose,

please confirm you’d update kernel image correctly,

for example,
there’re two ways to update kernel image,

  1. you might also refer to Flashing a Specific Partition to have partition update by enable the flash script.
    i.e. $ sudo ./ -r -k DTB jetson-nano-emmc mmcblk0p1
  2. there’s also cboot to choose kernel image by checking LINUX entry in the /boot/extlinux/extlinux.conf

in other words, you should look into /boot/extlinux/extlinux.conf; it still loads the kernel image via LINUX entry instead the kernel you’d update to the kernel partition.

Hello JerryChang.
I will try it, thank you.

But my DTB settings are reflected the folder ‘/proc/’, and my modules .ko .o files are loaded correctly.
If my driver probed, it will show ‘m93l_spi_probe’ by ‘printk’.

Please tell me the confirmation method that my driver is probed.

Thank you.


My driver appears in folder ‘/sys/bus/spi/drivers/’.
But It has not loaded by udev yet.

I would like to use Jetson Nano for embedded environment, so the driver must be loaded automatically.

The driver is developped on Host Computer used VMWare.
Kernel, Device tree and my driver compiles same environment, and flash to target board.

In this case, please tell me correct method to write device tree, or any other things.

hello t.hirose,

you may also refer to Topic 83215 for SPI devices driver implementations.

Hello, JerryChang. Thank you for your advice.
But I have not resolved the probrem.
My driver is in ‘/sys/bus/spi/drivers/’, and the driver’s description is in ‘/proc/device-tree/eeprom-manager/bus@0/’.
The ‘lsmod’ command was not list my driver.

So I think my driver has not binded and not recognized by kernel.

In this case, my driver can be used from user program?
( using ‘open’ functhion and so on.)

hello t.hirose,

are you compile your SPI driver as kernel module or built-in driver?

Hello JerryChang.

I compiled my driver for kernel module. (.ko file)

hello t.hirose,

you may execute below command manually to load the new module,
for example, sudo insmod <path_to_sensor_drive_file>

Hello JerryChang.
Thank you, It succeeded.

But I would like to bind my driver automatically.
Can do It?

To bind automatically, there are any terms in kernel probing ?

hello t.hirose,

you may recompile your kernel image to configure your SPI as built-in kernel driver.

How to confirm the driver binded in kernel?

hello t.hirose,

please refer to my previous comments in post #5.
if you have correct configuration, your SPI driver would be probed during kernel initialization stage.

I’m sorry for my understanding is not well.
I have tried it. But my driver was not installed.

My most question is my post

The EEPROM has implemented on out board, and the Device Tree, my driver describe same ‘compatible’ parameter. So when my EEPROM( via SPI ) driver is probed, the driver should bind by the kernel.
I think as above. What’s wrong thing, I can’t understand.

Thank you.

hello t.hirose,

please add some kernel prints to check whether you’d update kernel image correctly.
please also look into /boot/extlinux/extlinux.conf ; it’ll load the kernel image via LINUX entry, or it’ll load the kernel image from the partition.