03-09-2020, 03:35 PM
(This post was last modified: 03-09-2020, 04:26 PM by Der Geist der Maschine.
Edit Reason: overview
)
(03-09-2020, 03:10 PM)Foxchild Wrote: So, I would like to use the pinephone to learn more about device driver kernel modules in linux and device nodes. My main goal would be to write a kernel module that I can load, to control an LED in user space but I know, that's a long way to go. As you can see, there's going to be some very naive things I'm going to say, so please bear with me... I'd really like to know how this works!
I am fairly new to the subject and by now I was only developing firmware for STM32 devices and some software backend things, but no embedded linux at all. On a microcontroller I would look up on which GPIO pin the LED is connected, then search the programming manual for the registers that configure and controle the pin and write to those register addresses.
Still, I think I know at least SOME things about how the linux kernel works. Correct me if I'm wrong, but I suppose there is a kernel module which is basically executable machine code and does the "writing-to-register-addresses"-part? This module can be "loaded" in order to control a peripheral. The module then uses files (or nodes) to offer some sort of interface to applications in user space, in order to easily control the peripheral. These files are located either in /sys or /dev (I guess?). Is that kind of true so far? I already saw the files that can be used to turn an LED on or off in /sys/platform/leds/leds/.
If the above isn't too far off, I have many follow-up questions, but one after the other.
It would be really kind if someone would like to take time and provide some inside knowledge and just help me find my way here!
You want to reimplement leds-gpio?
https://www.kernel.org/doc/Documentation...s-gpio.txt
https://elixir.bootlin.com/linux/v5.5.8/...eds-gpio.c
Your overall understanding is correct. the sysfs api lets userspace pass parameters into your kernel driver. There you can then manipulate registers. Register sets of functional blocks on the soc, such as a gpio controller, are typically memory mapped by the soc (memory controller?).