Posted on March 2024 by Felipe Aníbal
Last updated on June 26, 2024
With the proper environment set up, me and Otávio Silva were ready for our first contribution to the Linux Kernel. Professor Paulo Meirelles gathered with Marcelo Schmitt (former IME student that now works with IIO drivers at Analog) and made a list of suggestions of drivers that we could contribute to and of possible improvements to the code. The suggestions involved choosing a driver and applying a correction (or improvement) that was already applied elsewhere. Marcelo ranked the suggestions in order of difficulty. We studied them all, and decided to give it a try at the hardest one. (As you will see in a moment, maybe we were overly confident).
The correction we set out to do involved changing the output of the driver LTC2309, a 12-bit ADC (analog to digital converter). This device converts an analog input into a digital signal. The output is in the form of a 12-bit binary number. Marcelo identified that in some similar devices the output of negative numbers was not always properly represented in 2’s complement form. That means that the negative numbers were not properly displayed to the user. To fix that, some patches to other drivers used the function sign_extend32() to correct the position of the sign-bit. Our idea was to implement a similar change but on the driver we were working on.
We studied the drivers that implement that change and realized that most of then apply the sign-extension inside the read_raw function - where information is read from the device. We found a very similar structure on the LTC2309 driver and, after reading the device documentation to better understand how it worked, we applied a similar fix.
The maintainers were very quick to respond to our patch! But the response was not exactly what we expected: our first patch was rejected! The maintainers made some important questions that lead us to further study the driver. It turns out that the LTC2309 ADC has to modes of operation: single-ended mode and differential mode. However, the unipolar mode does not use negative numbers, and what we discovered is that the bipolar mode (the one that uses negative numbers) was not implemented in the driver! In order for our patch to be accepted, we would have to implement the bipolar mode from scratch. That was no trivial task! Since this was our first time contributing to the kernel and we had other projects to work on for the rest of the discipline, we reported our discoveries but decided not to continue.
Unfortunately our contribution was not accepted, but we learned a lot with the process! We learned how to set up the environment for the Kernel, we gained a in depth understanding of drivers and modules, and we learned how to send a patch to the Kernel. We also learned hands-on how the kernel is implemented. I hope that in the future we can look at the Kernel again and make another contribution!