Status of sunxi gpio in the mainline kernel

312 views
Skip to first unread message

bruce bushby

unread,
Dec 5, 2014, 5:54:32 AM12/5/14
to linux...@googlegroups.com
Hi

I've been using the Olimex A20-SOM and having a lot of success using the mainline kernel....so far everything just works so a big thank you to all the contributors!! 

One area I'm struggling with is "gpio" I see there are various patches about:

and some discussions which reference sun4i-gpio:


I'm currently using 3.18.0-rc3
[root@A20-SOM ppp]# uname -a
Linux A20-SOM 3.18.0-rc3 #1 SMP Tue Dec 2 10:37:44 GMT 2014 armv7l GNU/Linux
[root@A20-SOM ppp]# 


However I can't find any reference to these in the mainline kernel:
[bruce@home linux-ac4a319cf0be6edd02092d0f220247c9e202a165]$ find . -name "*gpio*" | grep -i sun
./Documentation/devicetree/bindings/gpio/gpio-samsung.txt
./drivers/gpio/gpio-samsung.c
./arch/arm/plat-samsung/pm-gpio.c
./arch/arm/plat-samsung/include/plat/gpio-core.h
./arch/arm/plat-samsung/include/plat/gpio-cfg-helpers.h
./arch/arm/plat-samsung/include/plat/gpio-cfg.h
./arch/arm/mach-s3c24xx/include/mach/gpio-samsung.h
./arch/arm/mach-s3c64xx/include/mach/gpio-samsung.h
[bruce@home linux-ac4a319cf0be6edd02092d0f220247c9e202a165]$


What is the correct kernel config to enable gpio.h for sunxi?


Thanks
Bruce



Iain Paton

unread,
Dec 5, 2014, 9:44:08 AM12/5/14
to linux...@googlegroups.com, bruce bushby
On 05/12/14 10:54, bruce bushby wrote:
> Hi
>
> I've been using the Olimex A20-SOM and having a lot of success using the
> mainline kernel....so far everything just works so a big thank you to all
> the contributors!!
>
> One area I'm struggling with is "gpio" I see there are various patches
> about:

mainline != 3.4.x don't confuse them

for mainline see:

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/pinctrl/sunxi/pinctrl-sunxi.c

and for how to use them from userspace

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/gpio/sysfs.txt

try something like

root@lime2-2:~# cat /sys/class/gpio/gpiochip0/ngpio
288

if that works and gives you a number, then gpios are working fine and you
can use them.

since pinctrl and the gpio susbystem are used for lots of purposes by many
different parts of the kernel and drivers, I think it's unlikely your kernel
would boot without it being functional

bruce bushby

unread,
Dec 5, 2014, 10:10:23 AM12/5/14
to Iain Paton, linux...@googlegroups.com

Many thanks Iain!!  At least the number matches up :)


[root@A20-SOM gpiochip0]# pwd
/sys/class/gpio/gpiochip0
[root@A20-SOM gpiochip0]# cat ngpio 
288
[root@A20-SOM gpiochip0]# 


I'm attempting to add this kernel module:

But I don't know what gpio.h I can use....any ideas? 


Is the "pinctrl-sunxi" module used to setup/configure pins? .... or are their functions first defined in the DTS and then "enabled" via the "pinctrl-sunxi" module?

This describes calculating the pin number:


Excuse all the questions but I'm struggling to understand how or what gpio.h I would use to implement the servodrive module.

Thanks
Bruce




sels...@gmail.com

unread,
Dec 5, 2014, 11:05:31 AM12/5/14
to linux...@googlegroups.com, bruce bushby, Iain Paton
On 05/12/14 15:10, bruce bushby wrote:

> I'm attempting to add this kernel module:
> https://github.com/tallakt/servodrive/blob/master/files/servodrive.c
>
> But I don't know what gpio.h I can use....any ideas?

looks like it uses include/linux/gpio.h from within the kernel source tree,
however, I think for this module you want to have a look at
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/gpio/gpio-legacy.txt

> Is the "pinctrl-sunxi" module used to setup/configure pins? .... or are
> their functions first defined in the DTS and then "enabled" via the
> "pinctrl-sunxi" module?

err.. yes to both :)

from the POV of a driver wanting to access some gpios perhaps you need to
have a look at
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/gpio/consumer.txt

the devicetree part only comes into play for drivers that understand how
to look up their resources in DT. This makes the difference that you don't
have to hard-code the pins you want to use in the driver source code.
The driver can just lookup it's compatible string in DT and use that to
bind to the specific resources defined in the DT.
Yes, however that documents how to access them from userspace via /sys, your
driver is a kernel module so it needs to use the proper internal kernel
interface

> Excuse all the questions but I'm struggling to understand how or what
> gpio.h I would use to implement the servodrive module.

This one I expect:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/gpio.h

To build your driver you need to do something like

make -C <path_to_kernel_src> M=$PWD

where you replace <path_to_kernel_src> with the directory you built your
kernel in. It's possible this can be /lib/modules/`uname -r`/build
if the kernel you want the module built for is the currently running
kernel, but this gets somewhat complex if you're cross compiling for
Arm on an x86 PC.
https://www.kernel.org/doc/Documentation/kbuild/modules.txt gives some
hints on how to go about building external modules like your servodrive.

note that the servodrive module seems to date from 2010, it's quite possible
you'll have some work to do to make it compile and work with the 3.18-rc3
you're running. Out-of-tree drivers like this can bit-rot quite quickly.

good luck!

Reply all
Reply to author
Forward
0 new messages