I am writing a Linux device driver to be used with some custom hardware on an embedded platform. I'm planning on implementing attributes with sysfs to communicate with user-space applications on this platform, but I find the descriptions and examples in the reference materials that I have to be a bit unclear on how I should proceed.

My device is on a PCI bus. The single PCI target provides four distinct external physical interfaces, each with their own semantics. Applications will use normal file stream semantics (open(), write(), read(), poll(), ioctl(), close()) on the device nodes in /dev. The state of the subsystem will be queried and controlled through sysfs by an application that should never have to open any of the specific device nodes in /dev.

I have the traditional interface stuff working pretty well. My current code misuses procfs for some of what I want to do with sysfs. What I would like to do is get my sysfs stuff to conform to current Linux conventions, but I can find no examples of how to do what I want to do other than creating a new "bus". I don't want to do this.

I've read chapter 14 of "Linux Device Drivers, 3rd Edition" by Corbet, Rubini & Kroah-Hartman several times and I've looked through lots of code, but have found no driver (though I'm pretty sure one exists, I just haven't found it) that both handles multiple device interfaces and uses sysfs. I understand the kobject stuff. I don't understand how I'm supposed to use it in my situation.

For the sake of discussion, I will outline the device I'm working with. It is a single PCI device that provides the following distinct interfaces with the listed specific attributes:
  • Single bit output (64 lines)
    • enable (r/w)
    • state (r/w)
    • time since last change (r, binary)
    • number of state changes since enabled (r, binary)
  • Single bit input lines (64 lines)
    • enable (r/w)
    • state (r)
    • time since last change (r, binary)
    • interval between last change and the one previous to that (r, binary)
    • number of state changes since enabled (r, binary)
  • 32-bit serial out (16 lines)
    • enable (r/w)
    • last error (r)
    • parity generation enable (r/w)
    • data rate (r/w)
    • line statistics (r, binary)
  • 32-bit serial in (32 lines)
    • enable (r/w)
    • last error (r)
    • parity detect enable (r/w)
    • data rate (r/w)
    • line statistics (r, binary)
  • Binary stream input (2 lines)
    • enable (r/w)
    • mode (r/w)
    • sync patterns (r/w, binary)
    • last error (r)
    • data rate (r/w)
    • line statistics (r, binary)
  • Subsystem status and diagnostic information
    • Memory status (r)
    • Reset (w)
    • Ready (r)
    • Part number, revision, serial (r)


Here's my actual question: Do I define a device class for all of this and a device kobject (device_crate_file) for each of the 179 individual interfaces? Do I define several classes? Do I define any classes? I'm not asking for anyone to write code for me, just give me some guidance, and possibly a pointer to the source for another multifunction PCI device that uses sysfs to use as an example.

Thanks for wading through all of this...