Apollo Lake SoC GPIO Driver

Hello,

I'm trying to control some LEDs in my PCB board which uses an Apollo Lake SoC, and is running FreeBSD 12.3 Release. So far the FreeBSD is running fine, and I'm happy with it. My next step is to manage or control some LEDs on the board where I have their address (Export Value) or GPIO Pin. As a first instinct I tried to use gpioctl from FreeBSD, but I get a message "gpio_open: No such file or directory". Has any one of you tried to use gpioctl or had any experiences with LEDs in FreeBSD?

PS: I tried Linux first and was able to control the LEDs quite easy using /sys/class/gpio gpiochip434
Linux is supporting the Apollo Lake SoC GPIO driver. I'm wondering if there is something I can work with in FreeBSD?

Thank you in advance for any suggestions, or feedbacks.

Kind regards!
 
I'm wondering if there is something I can work with in FreeBSD?
Not for ApolloLake.

All arm boards support GPIO.
Here are the amd64 platforms and module name.

bytgpio for Baytrail.
nctgpio for APU1/2/3/4
chvgpio for Cherrytrail
rccgpio for Netgate boards
 
adnanml I haven't checked... there might be a driver for GPIO in Intel chipsets / SoCs.
E.g., there is amdgpio for AMD counterparts (but no manual page for it).
Having GPIO control is useful on some laptops, so someone might have already written a driver.
 
Thank you for the feedbacks. I will look into it.

I also found that OpenBSD has an aplgpio driver which is written based on bytgpio. But aplgpio does not provide direct device driver entry points, but makes its functions available to acpi.
 
Some update!

So practically there is no driver available for Apollo Lake SoC GPIO in FreeBSD. It's a pity because I only needed to control 5-6 LEDs on my single-board pc with Apollo Lake SoC in it.
However reading through aplgpio in OpenBSD, and seeing how bytgpio and chvgpio is implemented in FreeBSD, I was able to write a driver for aplgpio in FreeBSD. I also had to look into Linux implementation (https://elixir.bootlin.com/linux/latest/source/drivers/pinctrl/intel/pinctrl-broxton.c) to understand pin numbering and banks (North, N-West, West, S-West) used in Apollo Lake SoC. But I'm glad that now it works, and when aplgpio.ko is loaded, I can see the pins and control them.

So thanks for the earlier information guys. 👍
 
If your are willing to share your work I will do the paperwork to see if we can't get it included in FreeBSD.

Can you can share what board or box you used for testing?

I am willing to donate some cash to your favorite cause or to you..
My goal is to foster any additional GPIO drivers for FreeBSD.
 
Sorry to bum rush you like that. I got excited. New GPIO driver.

I wanna try E3940 SuperMicro 3.5" SBC. It would use the Apollo Lake GPIO driver.
It costs similar to Up2 Pro but I have an affinity with SM going back 27 years.
Never tried their embedded boards yet.
There are eight GPIO's on it too so it would be a good test of the driver.
~200$-250$ is tough on my pocket right now..
 
Last edited:
I don't have any update. I offered to do the phab for it. We did briefly chat.
It's not my code so I don't want to push too hard.
I only have one E3920 and its a Sophos firewall. Not sure if it even has gpio pins for testing.

Github repository would be ideal. Followed by phab and review. Heck I would be happy to see a port.

Should any GPIO drivers be in base?
That is a philosophical question above my paygrade.
Smaller base is preferable to me. No reason you can't have hardware drivers from ports. Many exist.
 
We are now talking about a third Intel GPIO driver in base.
Maybe they should be refactored due to similarity into base Intel SOC GPIO driver. Similar to AMD GPIO driver.

That or put them out to the ports tree...

iic is used in touchpads and tablet input and might be required for installation of FreeBSD.
 
Hello.
Here you may find the aplgpio.ko for FreeBSD 13.1 - just kldload the .ko file.
Please test it and let me know if it works for you. I was using an Intel Celeron CPU N3350 (former Apollo Lake). I trying to include the driver in FreeBSD, just as bytgpio and chvgpio.
For me it works. I have some LEDs connected to pins and I can control them now via gpioctl -f /dev/gpioc0 PIN 0 or 1
 

Attachments

  • aplgpio.zip
    6.3 KB · Views: 118
Thank You So Much.
I will test tonight on my Sophos.
See if anything shows up.


We are now talking about a third Intel GPIO driver in base.
Maybe they should be refactored due to similarity into base Intel SOC GPIO driver. Similar to AMD GPIO driver.
I was talking about stuff I should not have. I am not a programmer.
When I investigated Linux they have this for Intel GPIO:
 
adnanml

I ended up getting the two Advantech OEM Boxes.
These only have 8 pins of GPIO.
I will give you one for testing GPIO once I get them.



I didn't check my Sophos yet.
I am pretty confident no GPIO pins. Heck it is missing mini-pcie socket as it was not a wireless model.
 
OK I got my Apollo Lake platforms.
Advantech makes some quality gear.
64GB eMMC too. Newer M.2 Atheros radio that is not supported.

Here is where I just fall in love. In the BIOS are settings for Digital Input Output.
You can set each pin INPUT, OUTPUT LOW, OUTPUT HIGH.
These settings are sticky.
So no u-boot saveenv and cross your fingers.
Man I appreciate a good old school BIOS.
Minnowboard and UpBoard1 both use that Intel Tiano EDK2 UEFI crapola.
UEFI shell to update firmware. Blah.

I worship my Award BIOS now.
TUI bios interfaces have worked forever.

I will check out this GPIO driver right after I get this rig setup.

I have found this in pciconf which brings me great hopes:
Code:
none4@pci0:0:26:0:    class=0x0c8000 rev=0x0b hdr=0x00 vendor=0x8086 device=0x5ac8 subvendor=0x8086 subdevice=0x7270
    vendor     = 'Intel Corporation'
    device     = 'Celeron N3350/Pentium N4200/Atom E3900 Series PWM Pin Controller'
    class      = serial bus

So only 7 people downloaded the device driver? Nobody exploded yet?
Feedbacks????
 
I downloaded aplgpio.ko and loaded it into FreeBSD 13.1 on a E3940 SMARC module and note the following:

I get for entries in the /dev directory: gpioc0, gpioc1, gpioc2 and gpioc3.

On my module, I have access to four pins on gpioc0 (pins 1, 2, 5 and 6 - unfortunately, all outputs).

I try command gpioctl -f /dev/gpioc0 -c 6 OUT PP and I get an error: gpio_pin_set_flags: Invalid argument. It does not like 'PP' as a flag of the -c option. It also does not like the flag 'OD'. If I just use the command gpioctl -f /dev/gpioc0 -c 6 OUT, it appears to work. The pin is low.

I then try command gpioctl -f /dev/gpioc0 6 1 and the pin goes high - SUCCESS!!!

I might be able to get access to other gpios (there are 12 exposed on the SMARC connector), but they are not brought out on the carrier board I am currently using. If I can do that, I will try an input.
 
Thanks for the feedback. I have been busy and just saw this.
I will look onto PP and OD and see why it is complaining.
 
I am sorry I have not gotten to test this driver yet.
I got the Advantech boxes but my DIO Pin header has very small connector. 2X5 pins with 1.27mm pitch.

So I had to buy some cables and breakout board. Not sure I can solder something that fine.
 
I tried to change a pin from output to input but it is stuck as an output as it is still being driven. I used the command: gpioctl -f /dev/gpioc0 -c 6 IN. I verified that in the BIOS, GPIO lock is disabled. The BIOS does not allow me to alter the initialization state of the GPIOs.
 
Back
Top