Skip to contentSkip to conversation

udev rule for custom driver

DISCUSSION Justin Clacherty 3 participants 5 messages Dec 19, 2006

lore
Share & tools
lore
#0 lore raw

Hi,

I've been trying to get a udev rule to automatically create the /dev entries for the custom spi driver I've written for my board but am having no luck. I've created the file /etc/udev/rules.d/10-spi.rules which contains the following line:

SUBSYSTEM="spi", SYSFS{modalias}="nexus_spi", NAME="nspi%n"

If I run udevmonitor and do a udev trigger I see the following line in the output:

UEVENT[1166449657.257561] add@/devices/platform/pxa2xx-spi.1/spi1.0

Running udevinfo on /devices/platform/pxa2xx-spi.1/spi1.0 gives:

looking at device '/devices/platform/pxa2xx-spi.1/spi1.0':

    KERNEL="spi1.0"
    SUBSYSTEM="spi"
    SYSFS{modalias}="nexus_spi"

looking at parent device '/devices/platform/pxa2xx-spi.1':

    ID="pxa2xx-spi.1"
    BUS="platform"
    DRIVER="pxa2xx-spi"
    SYSFS{modalias}="pxa2xx-spi"

looking at parent device '/devices/platform':

    ID="platform"
    BUS=""
    DRIVER=""

Running udevtest on the sysfs tree gives the following output:

main: looking at device '/devices/platform/pxa2xx-spi.1/spi1.0' from subsystem 'spi'
main: run: 'socket:/org/kernel/udev/monitor'

Obviously I've missed something here, can anyone point to the problem? Do I need to add something to my driver for this to work or is my udev setup at fault?

Regards,
Justin.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CIDÞVDEV
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw
Quoted 8 lines · Justin Clacherty

Hi,

I've been trying to get a udev rule to automatically create the /dev entries for the custom spi driver I've written for my board but am having no luck. I've created the file /etc/udev/rules.d/10-spi.rules which contains the following line:

SUBSYSTEM=="spi", SYSFS{modalias}=="nexus_spi", NAME="nspi%n"

[snip]

Quoted 6 lines

Running udevinfo on /devices/platform/pxa2xx-spi.1/spi1.0 gives:

looking at device '/devices/platform/pxa2xx-spi.1/spi1.0':

    KERNEL=="spi1.0"
    SUBSYSTEM=="spi"
    SYSFS{modalias}=="nexus_spi"

The original kernel name is spi1.0. Do you get /dev/spi1.0 created already (ie: even without the rule)? If not, I don't think your rule will help at all - udev doesn't think there's device to create, so simply renaming it to nspi won't do anything. In the absence of a matching rule, udev will still create the device, but with the default name and some default permissions.

I don't know much about registering devices in the kernel, but there's some doc in the kernel, and no doubt Kay or Greg will be able to give your more helpful advice if this is the problem. One other thing to check, though, is whether /sys/devices/platform/pxa2xx-spi.1/spi1.0/dev exists (it should have a major:minor pair to tell udev how to create the device).

Alex :-)

Signature · 4 lines
Pippin
Computer Monkey to the Pelican
www.oxrev.org.uk, www.corpusjcr.org, www.rev.org.uk
0870 120 0870, ext 26669

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Justin Clacherty

Thanks Alex.

Quoted 1 line · Alex Merry

The original kernel name is spi1.0. Do you get /dev/spi1.0 created already (ie: even without the rule)?

I thought it should automagically create /dev/spi1.0 but it doesn't.

Quoted 2 lines

One other thing to check, though, is whether /sys/devices/platform/pxa2xx-spi.1/spi1.0/dev exists (it should have a major:minor pair to tell udev how to create the device).

No, this doesn't exist, I guess that's the problem. I can manually create the node and it works fine but if the major number changes (it's dynamic) then I'll have some problems - thus udev. Looks like it's time to find out how to create the dev entry in /sys. If anyone can help by pointing me to appropriate documents or code that'd be great.

Justin.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CIDÞVDEV
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Justin Clacherty
Quoted 8 lines · Justin Clacherty

No, this doesn't exist, I guess that's the problem. I can manually create the node and it works fine but if the major number changes (it's dynamic) then I'll have some problems - thus udev. Looks like it's time to find out how to create the dev entry in /sys. If anyone can help by pointing me to appropriate documents or code that'd be great.

It looks like all you need to do is create a new class in the module initialisation, then create new device classes for each device that is probed. Once that is done the sys entries are created and udev is happy.

Justin.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CIDÞVDEV
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#4 lore raw
In reply to Justin Clacherty
Quoted 5 lines · Justin Clacherty
Quoted 1 line · Alex Merry

The original kernel name is spi1.0. Do you get /dev/spi1.0 created already (ie: even without the rule)?

I thought it should automagically create /dev/spi1.0 but it doesn't.

Quoted 8 lines
Quoted 2 lines

One other thing to check, though, is whether /sys/devices/platform/pxa2xx-spi.1/spi1.0/dev exists (it should have a major:minor pair to tell udev how to create the device).

No, this doesn't exist, I guess that's the problem. I can manually create the node and it works fine but if the major number changes (it's dynamic) then I'll have some problems - thus udev. Looks like it's time to find out how to create the dev entry in /sys. If anyone can help by pointing me to appropriate documents or code that'd be great.

Set the dev_t value in "struct device" in your driver's devices, otherwise udev doesn't know the major/minor and can't create any device file. Doing this will automatically add the needed MAJOR=/MINOR= to the event-environment and create the "dev" file in sysfs.

Kay

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CIDÞVDEV
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel