# Apollo Lake SoC GPIO Driver



## adnanml (Aug 19, 2022)

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!


----------



## Phishfry (Aug 22, 2022)

adnanml said:


> 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


----------



## Andriy (Aug 22, 2022)

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.


----------



## adnanml (Aug 23, 2022)

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.


----------



## adnanml (Aug 30, 2022)

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.


----------



## Phishfry (Aug 30, 2022)

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.


----------



## adnanml (Aug 30, 2022)

Yes, that would be Ok with me.
I tested it with an UP2 board.


----------



## Phishfry (Aug 30, 2022)

OK I will get an UP2 Board for testing. I will contact you via a 'conversation' here and we can get this rolling.


----------



## Phishfry (Sep 6, 2022)

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.


			A2SAP-H | Motherboards | Products | Supermicro
		

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..


----------



## taman (Sep 16, 2022)

Any updates on this driver?
If not, can you share the source for aplgpio.ko


----------



## Phishfry (Sep 16, 2022)

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.


----------



## Alain De Vos (Sep 16, 2022)

iic is in base ...


----------



## Phishfry (Sep 16, 2022)

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.


----------



## taman (Sep 16, 2022)

I have an E3940 and E3950 that need GPIO support. I would prefer not to do the driver if someone else has one.


----------



## Phishfry (Sep 17, 2022)

I found a cheap Apollo Lake board.








						New DFI AL553-EN-E3950: R.A w/2x2 right angle, Wide temp F/G RoHS MOTHER BOARD    | eBay
					

1 AL553 board. CE, FCC Class B, RoHS. 1 Heat sink for N series CPU (Height: 25mm) A71-008119-000G/ for E series CPU 0 to 60℃ (Height: 35mm) A71-010038-010G. 1 x RS-232/422/485 (2.0mm pitch). 2 x USB 2.0 (2.0mm pitch).



					www.ebay.com
				



10 GPIO pins. 8 GPIO Pins and power/ground

Also Advantech E3930 2@$250

Not in my budget this week.


----------



## adnanml (Sep 21, 2022)

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


----------



## Phishfry (Sep 21, 2022)

Thank You So Much.
I will test tonight on my Sophos.
See if anything shows up.




Phishfry said:


> 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:








						linux/Kconfig at master · torvalds/linux
					

Linux kernel source tree. Contribute to torvalds/linux development by creating an account on GitHub.




					github.com


----------



## Phishfry (Sep 22, 2022)

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.









						(2) Now Micro EPC-U2117T IOT Core media players    | eBay
					

Windows 10 IoT Core. 2 x WiFi Jacks. 1 x HDMI 1.4 1 x DP 1.2. 4 x USB 3.0 2 x LAN (RJ45) 1 x Audio jack 1 x Serial (RS-232 DB9).



					www.ebay.com
				









						AIMB-U117
					

Intel® Atom™ E3950/E3930 DC 1.6/1.3 GHz UTX Industrial Motherboard with HDMI/eDP (LVDS)/DP  , 2 COMs and Dual LAN




					www.advantech.com
				




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.


----------



## Phishfry (Sep 28, 2022)

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:

```
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????


----------



## adnanml (Oct 21, 2022)

Hello guys,

Did anyone give it a try? Any feedbacks?


----------



## taman (Nov 14, 2022)

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.


----------



## adnanml (Nov 15, 2022)

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.


----------



## Phishfry (Nov 15, 2022)

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.


----------



## taman (Nov 19, 2022)

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.


----------



## taman (Dec 6, 2022)

adnanml , would it be possible for me to get the source so I can get the driver working for my configuration?


----------



## Phishfry (Dec 31, 2022)

OK thanks so now I have an UP2 Board and the driver is working.
Can you give me insight what pin is where on 40 pin header?

gpioc0=north bank
gpioc1=nortwest bank
gpioc2=west bank
gpioc3=southwest bank


----------



## Phishfry (Dec 31, 2022)

I do notice that the caps<> field is empty for all gpiobus pins on UP2 and aplgpio.ko
I have seen boards with some empty caps but I assume they were system level peripherals like eMMC and display.


```
# gpioctl -lv -f /dev/gpioc3
pin 00:    0    southwestbank0<IN>, caps:<>
pin 01:    0    southwestbank1<IN>, caps:<>
pin 02:    0    southwestbank2<IN>, caps:<>
pin 03:    0    southwestbank3<IN>, caps:<>
pin 04:    0    southwestbank4<IN>, caps:<>
pin 05:    0    southwestbank5<IN>, caps:<>
pin 06:    0    southwestbank6<IN>, caps:<>
pin 07:    0    southwestbank7<IN>, caps:<>
```

This doesn't help me here.








						Pinout_UP2 · up-board/up-community Wiki
					

Contribute to up-board/up-community development by creating an account on GitHub.




					github.com


----------



## Phishfry (Dec 31, 2022)

I have noticed that on Linux you have the four GPIO buses I quoted above.
But the they also have a fifth bus gpio4 which seems to be user pins: (See Comments)





						How to get GPIO running using the new UP Squared Pro?
					

Hello, I followed the instructions from here but without any success to get the GPIO running with mraa under Ubuntu 18.04.5 (server) including the upboard-extras.



					forum.up-community.org
				



The number of GPIO lines I get for aplgpio.ko is exactly the same as above post on Linux.
gpioc0=78 pins/lines
gpioc1=77
gpioc2=47
gpioc3=43
But no gpioc4 with aplgpio.ko ???


> gpiochip4 [Raspberry Pi compatible UP GPIO] (28 lines)


Is it possible the missing pins are not being properly exposed?
It seems really strange that all pins on gpio0,1,2,3 have empty caps.
I suspect they are hiding on the missing gpiochip4 bus. 28 Lines sounds right for the 40 pin GPIO header.


----------



## Phishfry (Jan 3, 2023)

adnanml said:


> I have some LEDs connected to pins and I can control them now via gpioctl -f /dev/gpioc0 PIN 0 or 1


Please share what header pin on UpSquared board is gpio0 pin 0. I need a reference point.


----------



## Phishfry (Jan 3, 2023)

taman said:


> _*adnanml*_ , would it be possible for me to get the source so I can get the driver working for my configuration?


I really think a github repo is best to get this ball rolling.


----------

