I've got a custom driver, which gets loaded on boot (I compiled a kernel image for it). It uses a number of GPIOs, as defined in the device tree overlay (specifically, the cam gpios of the raspberry, mostly CAM_GPIO aka line 5 of gpiochip1). This shows up if for example I use gpioinfo, and works mostly as expected. So far so good.

Now, for testing I would like to manually set some of thes GPIOs. This does not work, because they're in use. I tried to remove the driver useing modprobe, but this does not work. While the driver is removed, the pins are still blocked.

What is the best way of handling the problem?

Either by removing the driver in such a way that it releases the pins, or by being able to set the value while it's in use. I've looked for similar problems, but couldn't find anything.

The only alternative I see is changing my config.txt for test so the overlay for the driver does not get loaded, and deactivate the camera. However, this would require a restart, which is inconvienint, and I'd also like to understand what is happening here.

1 Answer 1


From the second paragraph of Hello, World (part 1): The Simplest Module:

Kernel modules must have at least two functions: a "start" (initialization) function called init_module() which is called when the module is insmoded into the kernel, and an "end" (cleanup) function called cleanup_module() which is called just before it is rmmoded. Actually, things have changed starting with kernel 2.3.13. You can now use whatever name you like for the start and end functions of a module, and you'll learn how to do this in the Section called Hello World (part 2). In fact, the new method is the preferred method.

That is quite dated although it still holds. The "new method" is documented much more recently here: https://www.embeddedrelated.com/showarticle/1274.php along with the details necessary for registering these functions.

  • How does that apply for a driver written for/in the V4L2 framework, where the start and end methods are not actually situated in the code written by me?
    – BurnNote
    Mar 30, 2022 at 15:00
  • Dunno. I should think it has hooks of some sort or it is a bit daft, but you're better off asking about that on Stack Overflow; there's very little kernel mod programming going on here (I'm just familiar with the basics).
    – goldilocks
    Mar 30, 2022 at 15:13
  • Having completed these tutorials, are we entitled to call ourselves "kernel programmers"?
    – Seamus
    Mar 31, 2022 at 15:07
  • You've have to ask the LKML about that ;) Since most of the kernel can in theory be compiled as loadable modules, including various bits of critical infrastructure like networking and peripheral access, drawing a line between "just a module" and "the kernel proper" seems arbitrary. But you do have to actually write some code and make it work @Seamus -- ever use C? You'll love it. Separates the boys from the men so to speak. Or the children from the adults, to be more inclusive.
    – goldilocks
    Mar 31, 2022 at 15:27
  • Just between us - I do not like C. But like the line in the movie, "I said I didn't have much use for it - I never said I didn't know how to use it" LOL
    – Seamus
    Mar 31, 2022 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.