2012-07-20

learning learning and GPIOs...

Partytime!

I kept extra long weekend holiday, wow! Reason for that was Ilosaarirock festival I attended with friends. Heh, we were there from Friday to Sunday night and back to home late Monday... not surprise I was a little bit tired. There was very good reason to party as my Google Summer of Code project (that Kernel Media project for Linux Foundation) Midterm Evaluations successfully were passed!

GPIOs

GPIO, shorthand for General Purpose Input/Output

implement functionality of LNA API call in real life

I was forced to find out "proper" solution to control LNA (inside Kernel driver) after I added DVB API support for it. Very often those LNAs are controlled by GPIO line or two. Almost every chip has few GPIOs, for DVB -device this means there could be GPIOs on USB/PCI-bridge, demodulator and tuner. LNA commonly is very simple to control, ON or OFF, which means there is no own driver for LNA chip. Controlling this kind of general device specific properties belongs to the bridge driver.

LNA control path

I should write short article about anatomy of DVB-device but as there is no such article yet, lets explains some wiring as background. I used PCTV nanoStick T2 290e during development, but for most others it is just similar. That device LNA is controlled by demodulator GPIO. Here is the control path, from computer to LNA:

PC|bus=USB|chip=bridge|bus=I2C|chip=demodulator|bus=GPIO|chip=LNA

LNA controlling problem

The problem. Bridge wants to set LNA, but LNA is controlled by the demodulator. How to deliver that request to the demodulator driver? Simplest solution is to export function from demodulator driver to perform request. Function like set_lna() or set_gpio() and call that from the bridge driver. Yes, works, used widely, easy to implement, but so home-brew.

Kernel gpiolib framework

After digging Kernel code and documentation I found there is existing GPIO support. I decided to  try that. At the first glance it looked like only for the motherboard GPIO handling and my need is inside device driver. Looking code more I found it was extended to handle GPIO expanders using gpiolib.  This kind of DVB -device could be seen actually as a USB-I2C-GPIO-expander. For the bonus point we get userspace sysfs interface for free! It is very nice to have as it provides easy access for GPIOs during development.

gpiolib sysfs example

For example this is how I can enable (echo 0) and disable (echo 1) LNA in question:
echo 253 > /sys/class/gpio/export
echo 0 > /sys/class/gpio/gpio253/value
echo 1 > /sys/class/gpio/gpio253/value
echo 253 > /sys/class/gpio/unexport


Final notes

I encourage all the other DVB driver developers use same solution for demodulator and tuner GPIOs. It is now learned and found to working at least some level. Implementation seems to be quite simple and interface is standard provided by Kernel gpiolib framework. Look example from the cxd2820r demodulator driver.

No comments:

Post a Comment