linuxfilesystemsdriversysfs

Where in the Linux file system should I put my board voltage monitor driver?


My knowledge level

Hi I'm new to Linux and have been doing my best to read up on Linux Device Model and file systems. Sorry if I don't have the vocabulary to ask/google what I'm looking for (I come from a PCB designer background). I'm feeling a bit over my head here.

some docs I've read:

The question

I'm looking to implement a driver for my various PCB rail voltage monitors. ADC values will be read by an MCU that will communicate to my main processor over SPI. This MCU also does GPIO control for which I've already written a working /sys/class/GPIO driver for but that to be honest I don't fully understand.

So I'm thinking for the ADC side I should also be somewhere under /sys but I'm not sure where. /devices? /class?

My understanding is that I could but shouldn't be building in /dev or /proc because these are more for things like drives and the CPU.

One option I'm looking at is making a custom class. Maybe /sys/class/boardvoltage? But I figure this must be a common driver board developers make and there's already a class with the proper attributes for it.

Bonus questions

More broadly, how is a driver developer supposed to know what each of the classes are for? How does one learn the various way of accessing each type of class? For example, GPIOs get 'cat'ed or 'echo'ed while /dev drivers get read and write. How would I learn how to run something like /sys/class/leds?


Solution

  • Very old thread but hit on it doing some google search and there is no answer yet.

    For a device driver to monitor the board's rail voltages, the best subsystem to use would be hwmon.

    The voltages can then be found under one of the /sys/class/hwmon/ folders.

    Hwmon is made to monitor the hardware's voltage, current, temperature and even humidity. Relevant doc is found under https://docs.kernel.org/hwmon/hwmon-kernel-api.html