An Overview of Generic Power Domains (genpd) on Linux

The saying goes that most programming problems can be solved with another layer of abstraction. Generic Power domains (genpd) are a (relatively) new Linux kernel power management abstraction that model the way power is controlled for components on SoCs. In other words, genpd describes the relationship between devices and power controllers. Generic power domains allow these relationships to be declared outside of device drivers, which means these device groups can be updated at runtime.

Static versus Dynamic power management

Linux supports two types of idle power management: static and dynamic. Static power management is the term for suspend and resume operations; it controls system-wide power. This is the traditional way to suspend a system and comes from the original support for laptop PCs where the whole system would be suspended at once. A good example of this is closing the laptop lid.

Dynamic power management, on the other hand, controls power to individual devices, allowing flexible power management based on activity in different parts of the SoC/platform.

Dynamic power management for device drivers is implemented inside of the kernel with the runtime PM framework (dynamic power management for CPUs is handled differently, via the CPUfreq and CPUidle subsystems). Device drivers use the struct dev_pm_ops data object to hook up their callbacks:

These callbacks allow devices to be powered up or down, or enter a low-power idle state when they go idle, such as when a transaction is finished. Each individual driver decides when the device is idle.

Device drivers can inform the PM core when devices are going idle. Idleness is controlled using the pm_runtime_get() and pm_runtime_put() functions. This API maintains a reference counter for each device to track whether the device is in-use at any time. pm_runtime_get() blocks the device from entering a low-power mode until the last pm_runtime_put().

But controlling power on a per-device level, while better than system-wide, isn’t the most efficient way to save power. Instead, hardware vendors have long provided a way to control power to groups of devices through power islands, or power domains.

 

What are power domains?

Devices and SoCs have separate power rails with devices connected to them. Power domains are a hardware concept for managing devices sharing power rails. Their power voltages are correlated. While the hardware power islands have existed for many years, the kernel has only recently added support for them.

Linux power domain drivers sit above devices in the PM hierarchy, at the same level as bus_type.

Power management core hierarchy diagram

These relationships need to be modeled inside of the kernel because the same IP blocks and chip families might have different groups depending on the hardware. For example, the same ARM IP can be used in different SoC vendor products and they might group things differently. So you need a way to describe this fixed relationship. Some examples are whether all CPUs/clusters share a power rail or have independent rails, or whether video-centric IP shares a power rail with the display IP.

A solution is needed that abstracts this so that the driver doesn’t need to care. And these power domain relationships need to be described in a way that does not require updating drivers for every new platform and configuration.

Crucially, we don’t want a driver to care whether it’s running on an AmLogic or Qualcomm chip — it should work on both, independent of how the power rails are configured on those platforms.

 

Generic Power Domains (genpd)

Generic power domains are an abstraction on top of Linux kernel power domains. They provide a number of benefits over regular power domains because they support:

  • Domain hierarchies
  • Adding and removing devices from domains at runtime
  • Power governors
  • Device Tree support

Generic power domain drivers control the entire domain’s power when an entire group of devices goes idle. A typical action is sending a command to a microcontroller or writing to a register to disable a voltage rail. The genpd framework takes care of running the callbacks for every genpd driver in a hierarchy, a feature that makes it possible to control the nested power domains available on some SoCs.

genpd drivers can be both IRQ-safe and always-on. The former (enabled with the GENPD_FLAG_IRQ_SAFE) is useful for domains that can be powered on/off in atomic context. This feature is particularly useful for devices that have low suspend and resume latency, and can be powered on or off quickly.

Always-on genpd drivers make sense if you have devices that must not be powered off. For example, CPUs that are behind a power microcontroller. Whether or not genpd drivers set the GENPD_FLAG_ALWAYS_ON flag can be platform-dependent.

In addition, there are optional driver callbacks that can be used if drivers want to know when new devices are attached or detached from a generic power domain. These callbacks are used to execute power domain-specific actions.

Generic power domains are described in the device tree, so the configuration can be described on a per-platform basis. Storing the configuration data inside device tree also makes it easy to update since the genpd driver requires no changes when new SoCs are released; a single driver can support all platform configurations.

Here’s a simple genpd example:

Here’s how it would be used by a device:

genpd also provides governors which add another level of control in between the PM core and the device drivers. Every generic power domain can have its own governor. Governors decide whether power should be gated to a generic power domain, and their decisions are based on simple heuristics. There are two available in the kernel: the simple QoS governor and the always-on governor.

As the name implies, the always-on governor prevents devices from being powered off. The simple QoS governor is more interesting — it considers the time it takes to power devices on and off, known as suspend and resume latency. If a power domain is predicted to be resumed before power can be turned off to all devices, the simple QoS governor will prevent the power domain from suspending.

Governors have a standard plugin-architecture, so you can write custom versions for specific platforms as well.

 

Performance states

A recent addition to the kernel, in v4.15, is support for power domain performance states. This new feature makes it possible to finely tune the power consumption of devices by varying the voltage to power rails. genpd drivers implement this with the (*set_performance_state) callback. Sadly, there are no upstream users of this API yet, but one is currently being reviewed on the kernel mailing lists.

 

Resources

The genpd framework provides an extremely flexible API for finely controlling power domains. If you want to learn more, here is a list of resources:

And here’s the video of Kevin’s talk on generic power domains at Kernel Recipes 2017.

Linux Kernel 4.17 released, our contributions

BayLibre has continued our contribution to the Linux community as seen with this new version of Linux Kernel 4.17, released on June, 3rd 2018.  An excellent summary of this release can be found at KernelNewbies.

We’re happy to report BayLibre is once again featured in the LWN stats for this release. Corentin Labbe from our team is a Top 10 developer and BayLibre is a Top 20 employer, both by Lines Changed.

Here is a summary of our contributions, organized by SoC family and a summary graph of contributions by developer.

Amlogic SoC family:

  • clocks: major rework to switch to regmap; misc. cleanups
  • improve DT support for WeTek hub and play2
  • MMC: reduce max speed for Odroid-C2 boards after multiple problems reported
  • AXG family: enable hardware RNG
  • HDMI: Add support for DMT modes

Misc:

  • Lots of cleanup and dead code removal (see Lines removed by Corentin)

 

 

Linux Kernel 4.16 released, our contributions

Linux Kernel 4.16 released

BayLibre has continued our contribution to the Linux community as seen with this new version of Linux Kernel 4.16, released on April, 1st 2018.  An excellent summary of this release can be found at KernelNewbies.

Here is a summary of our contributions, organized by SoC family and a summary graph of contributions by developer.

Amlogic SoC family:

This release is important since it’s the first Linux release that can boot an Amlogic SoC with graphics with u-boot mainline, both unchanged !

  • Finally enable the Video Processing Unit power domain and all the missing bit :
    • drm/meson: Add missing VPU init
    • drm/meson: dw_hdmi: Add support for an optional external 5V regulator
    • ARM64: dts: odroid-c2: Add HDMI and CEC Nodes
    • ARM64: dts: meson-gx: grow reset controller memory zone
    • ARM64: dts: meson-gx: Add HDMI_5V regulator on selected boards
    • ARM64: dts: meson-gx: add VPU power domain
    • dt-bindings: display: amlogic, meson-dw-hdmi: Add optional HDMI 5V regulator
    • dt-bindings: display: amlogic, meson-vpu: Add optional power domain property
    • This means you can download Linux v4.16 and U-Boot v2018.01, build them, flash them and you will be able to boot to graphics with HDMI on most Amlogic S905, S905X and S912 supported boards !
  • drm/meson: fix vsync buffer update : fix a long-time issue causing glitches when rendering directly using GBM
  • Jerome improved the Meson S905X/S905D/S912 internal ethernet PHY support by :
    • net: phy: meson-gxl: add interrupt support
    • net: phy: meson-gxl: use genphy_config_init
    • net: phy: meson-gxl: add read and write helpers for banked registers
    • net: phy: meson-gxl: define control registers
    • net: phy: meson-gxl: check phy_write return value
    • ARM64: dts: meson-gxl: add internal ethernet PHY irq
  • Jerome added the “clock protection” feature to the clock framework

Misc:

  • Add support for the the Variscite DART-MX6 SoM and Carrier board with LVDS display
  • media: uvcvideo: Add a quirk for Generalplus Technology Inc. 808 Camera
  • ARM: davinci: fix the GPIO lookup for omapl138-hawk
  • i2c: davinci: fix the cpufreq transition
  • Corentin did some cleanup in the crypto directory and some overall remove of unused code/documentation

 

 

Linux Kernel 4.15 released, our contributions

Linux Kernel 4.15 released

BayLibre has continued our contribution to the Linux community as seen with this new version of Linux Kernel 4.15, released on January, 28th 2018.  An excellent summary of this release can be found at KernelNewbies.

Here is a summary of our contributions, organized by SoC family and a summary graph of contributions by developer.

Amlogic SoC family:

  • Finally GPIO IRQ Support for Amlogic SoCs
  • Pinctrl cleanup for AXG future support
  • Meson GXL/GXM Internal PHY fixup for reliability
  • Support for new boards :
    • Vega S96
    • Khadas VIM2
  • Driver support for the Video Processing Unit Power Domain for mainline U-Boot support
  • Level Reset support for GX Family

Misc:

  • Support for the Winbond w25q16dw present on the Khadas VIM2
  • usb: musb: da8xx: Remove duplicated defines

 

 

How We Improved AmLogic Support in Mainline Linux

It was a match made in heaven: two years ago AmLogic and BayLibre joined forces to bring top-notch support for AmLogic SoCs into the mainline Linux kernel.

Since that time AmLogic has continued to become one of the most relevant and widely used silicon vendors in the world. Similarly, BayLibre has expanded the variety of SoCs, drivers and frameworks supported upstream all while supporting a growing number of OEMs basing their products off of recent kernel releases.

Along the way Baylibre has collaborated with a great community of product makers, kernel hackers and hobbyists to improve the AmLogic Meson SoC support in mainline Linux. We’ve added support for 64-bit SoCs, new drivers, and we’ve become maintainers for the AmLogic platform in Linux.

Our goal is straightforward: AmLogic system-on-chip processors should be so well-supported in the mainline Linux kernel that OEMs will go to market using the latest stable kernel release.

Last year at Embedded Linux Conference 2017 and this year at Linux Conf Australia, Neil Armstrong gave a well-received talk on our work. This post expands on Neil’s presentation and provides an update on some of the changes we’ve been involved with recently.

The Linux Meson project

The Linux Meson project is an effort to get support for the ARM-based SoCs produced by AmLogic into the upstream Linux kernel and GNU/Linux distributions. AmLogic chips are found in many Android-based multimedia devices such as set-top boxes, smart TVs, projectors, and tablets but are also starting to appear in products in the smart speaker market. Popular consumer products and community boards using the AmLogic Meson SoC include:

  • Amazon Fire TV (gen3)
  • Wetek Play/Hub
  • Nexbox A1/A95
  • Hardkernel ODROID-C2
  • Tronsmart Vega S96
  • R-Box Pro
  • HwaCom AmazeTV
  • Libre Tech CC (a.k.a “Le Potato”)
  • Khadas VIM and VIM2
  • NanoPi K2

AmLogic provides a kernel release and SDK that supports their hardware but it’s a heavily-modified 3.10-based or 3.14-based kernel for Android. Thankfully, most of the changes are confined to the `drivers/amlogic` directory and it has been possible to use them as a starting point to write the upstream support.

Carlo Caione added the initial support for the 32-bit Meson6 SoC in Linux 3.18, with Beniamino Galvani adding support for Ethernet and Andreas Färber contributing code for the GXBB platform. Since then, support has been added for Meson8, Meson8b, and the 64-bit ARM Meson GXBB, Meson GXL and GXM SoCs and a whole host of hardware. Codenames for the 64-bit SoCs are used in the kernel source and the following table shows how they map to their respective product names:

 

Codename Product name
GXBB S905
GXL S905X, S905D
GXM S912
AXG A111, A112, A113

 

Here’s How We Helped

Our efforts have mainly been focused on adding support for the 64-bit Meson SoCs. Kevin Hilman generalized the boot and serial console code for the 64-bit AmLogic family of SoCs so that more boards could be supported, starting with the Hardkernel ODROID-C2).

Michael Turquette reworked the Meson SoC clock driver to move to the `platform_driver` API and replaced the dynamic configuration code with statically initialized data. That was in preparation for adding clock driver support for the S905 SoC. We’ve also added S905 AO (Always-On) clock and reset controller drivers and support for PWM, RNG, Watchdog, IR, I2C, SPIFC devices.

Because some of AmLogic SoCs use a legacy version of the System Control and Power Interface (SCPI) protocol (pre-v1.0), we pushed changes to the upstream SCPI driver to support it. The SCPI driver is used for Dynamic Voltage and Frequency Scaling (DVFS) with the CPUFreq subsystem to dynamically alter the processor’s speed.

We’ve added a driver for the AmLogic SPI Communication Controller (SPICC) that’s capable of full-duplex transfers up to 30MHz. And in v4.10 Kevin added a brand new SD/eMMC driver that supports the host controller found on the AmLogic S905/GX* family of SoCs.

Neil wrote the AmLogic Meson DRM driver and has added HDMI support since his last update during his talk at Embedded Linux Conference 2017.

As the following graph shows, the number of Meson patches merged into the kernel has risen steadily over the last few kernel releases, and Baylibre is responsible for hundreds of them.

AmLogic kernel commits and BayLibre contributions
And because of our knowledge of the Meson code, we’ve had the honour of becoming (co-)maintainers for the majority of it.

  • Meson SoC code (Kevin Hilman)
  • DRM display driver (Neil Armstrong)
  • AO-CEC driver (Neil Armstrong)
  • Meson SoC clock framework (Neil Armstrong and Jerome Brunet)

As the number of supported boards has grown, it’s become increasingly important to maintain quality across all devices. For that, we’ve leaned heavily on kernelci.org. Baylibre is a founding member of kCI and you can expect more details in an upcoming blog post.

kernelci.org has been extremely useful for our AmLogic work. Part of our lab is made up of 8 AmLogic Meson boards which we use to check for regressions across 6 kernel trees. The kernelci.org infrastructure recently caught a kernel regression in the SCPI code which resulted in CPUFreq failures on boot. Thanks to kernelci.org and our collection of Meson boards, we were able to get the offending patch reverted before the final v4.15 release.

 

Links to Community Resources

AmLogic Meson support has come a long way in the last two years. That progress has been possible thanks to the supportive Linux Meson community and the kernel hackers (shout out to Martin Blumenstringl for his contributions as well as Carlo Caione and Andreas Färber for their early work and ongoing reviews) helping to improve the upstream AmLogic code. There’s lots more to come and we are currently working on support for the new AXG SoC (including audio) which is targeted at the smart speaker market.

If you want to know more about Linux Meson development you can subscribe to the linux-amlogic mailing list or join the #linux-amlogic IRC channel on irc.freenode.net. Also, the Linux Meson wiki is updated as support for new devices and SoCs lands in mainline Linux.

 

Post header image by Hardkernel – http://odroid.com/dokuwiki/doku.php?id=en:odroid-c2, CC BY-SA 3.0, Link

U-Boot v2018.01 released, our contributions

BayLibre has continued contribution to the open-source community as seen with this new version of U-Boot v2018.01, released on 9 Jan 2018.

Here is a summary of our contributions:

Amlogic SoC family:

Add support for the Meson GXL Family by :

  • Adding pinctrl support, based on excellent work of Beniamino Galvani
  • Adding Internal PHY Support + fixups for reliability
  • Add support for dynamic reserved memory
  • Adding support for S905X Based boards :
    • P212 reference board
    • Khadas VIM
    • LibreTech-CC
  • Neil Armstrong becomes maintainer of these freshly added boards

This version of U-Boot for Amlogic GXL SoCs will need to wait for Linux 4.16 to be released, or is compatible with the LibreTech-cc 4.14 stable linux tree for the LibreTech-CC board.

Khadas has released an image with this version of U-Boot and Linux Mainline for the Khadas VIM board here.

Misc :

  • fat: Use cache aligned buffers for fat_opendir

Linux Kernel v4.14 released, our contributions

Linux Kernel v4.14 released

BayLibre has continued our contribution to the Linux community as seen with this new version of Linux Kernel v4.14, released on Nov 12 2017.  An excellent summary of this release can be found at KernelNewbies.

Here is a summary of our contributions, organized by SoC family and a summary graph of contributions by developer.

Amlogic SoC family:

  • Add support for eMMC HS200 and SD SRD104 modes to GX MMC Controller
  • Fix GX MMC Controller clocking scheme
  • Add GPIO Lines names to the following Single Board Computers :
    • LibreTech-CC
    • Nanopi K2
    • Khadas VIM
  • Add support for the HDMI CEC Controller on Meson GX SoCs

TI DaVinci SoC family:

  • musb: musb_cppi41: Configure the number of channels for DA8xx

 

 

Kernel Recipes: Mainline Linux on AML-S905X-CC: Le Potato

At Kernel Recipes this year, BayLibre was proud to partner with the Libre Computer Project to give away around 30 “Le Potato” boards to attendees.  Kernel Recipes is already known for its throw microphone, but this year each speaker threw a “Le Potato” board at the audience.

For those who received the board, pre-built images (to be written to a microSD card, at least 4Gb) are available here :

What works:

  • Quad-Core Cortex-A53 @ 1.5GHz with Dynamic Voltage and Frequency Scaling (DVFS)
  • Penta-Core Mali-450 MP3 GPU limited to X11 (experimental) and Framebuffer acceleration
  • RS-232 TTL serial console on UART header and 40-pin header using DT Overlay
  • microSDCard SD/SDHC/SDXC up to SDR104 (UHS-I) speed
  • Optional eMMC 5.1 up to HS200 speed
  • SDIO up to SDR104 on 40-pin header
  • I2C, SPI, PWM, ADC on 40-pin header
  • Infrared Receiver
  • Hardware Watchdog
  • Up to 100Mb Full Duplex Ethernet
  • 4x USB2.0 Type A ports
  • 480i/576i CVBS Analog Output on AV Jack
  • Up to 1080p60 Full HD Output with CEC and Stereo Digital Audio

What doesn’t work (yet) :

  • 4k2k HDMI 2.0a modes, 7.1 and compressed Digital Audio
  • Mali-450 MP3 GPU Acceleration for Wayland
  • Analog and 7.1 I2S Digital audio output
  • Hardware Accelerated Video decoding/encoding for H.264/H.265/VP9

How to build and boot your own kernel from mainline:

For Overlays support, please follow the steps on https://github.com/libre-computer-project/libretech-overlays/blob/for-4.13.y/README.md

For Questions, please find us on the IRC channel #linux-amlogic (on Freenode) or ask questions on linux-amlogic@lists.infradead.org

Embedded and Kernel Recipes speakers

BayLibre’s team experts talk in the Open source community

It’s the end of holidays and we’re ready to tackle September in fine fettle.
Two major conferences are taking place in the Embedded and Open source community.
BayLibre is sponsors at those events.
We are longing for them for good reasons!

Two Jedi of our team, will demonstrate their power as embedded systems experts.

  • Neil Armstrong (yes the real one !) : Embedded system expert and software engineer, one of the Embedded Recipes speakers
  • Kevin Hilman : Linux Kernel expert, one of the Kernel Recipes speakers

Embedded Recipes

The first edition of the Embedded Recipes conference, #er2017, will take place in Paris, the 26th of September 2017.

Just as it’s big sister, Kernel Recipes, the objective is to bring together a developer community.

That day will be dedicated to Embedded Open Source actors.

Share your experience with us. 

Neil Armstrong : From Embedded Recipe speakers

Software and Linux Embedded System Engineer

9 years of passion for embedded systems, Linux Expert.

Neil was keen on computing at the youngest age. He obtains his degree of engineering in computer science from Polytech Nice-Sophia.

He got into Neotion as a Linux embedded system engineer.

From this experience he has got increasingly interested in the Open source community.

Then, in 2015 he decides, to join the team BayLibre.


Kernel Recipes

We wish a happy 6th edition to Kernel Recipes!

From the 27th to the 29th September 2017 in Paris.

A great, human and professional experience as always.

A unique track of conferences on subjects as varied as:

  • Open source hardware,
  • Core,
  • Security,
  • Experience feedback,
  • Industrialization processes
  • and so many more…

Kevin Hilman: From Kernel recipes speakers

Linux Kernel Consulting and Engineering

20 years of engagement with Embedded Linux. Expert in power management. Upstream maintenance of Kernel subsystems.

Early in computer science, he earns a Master of Science in Electrical Engineering from the University of Seattle.

Then in 2003 he decides to settle down in France and joins Texas Instrument. He works there as a Linux Kernel developer and meet his future collaborators.

Later he returns Seattle and Texas Instrument for a few years. He finally decides to join the team BayLibre.

 

How to Subscribe ?

The subscription is limited so unfortunately there are no more places left.

Think about it next year and be sure to subscribe!

Embedded Recipes

Kernel Recipes

Linux Kernel v4.13 released, our contributions

Linux Kernel v4.13 released

BayLibre has continued our contribution to the Linux community as seen with this new version of Linux Kernel v4.13, released on Sept 3rd.

For this version we supplied:

  • multiple team members
  • many work hours
  • several cups of coffee
  • and a few pastries

An excellent summary of this release can be found at KernelNewbies.

Here is a summary of our contributions, organized by SoC family and a summary graph of contributions by developer.

Amlogic SoC family:

  • Add S905x based libretech-cc “Le Potato” board support (Succesfully backed on kickstarter)
  • Fix PWM for AO Domain
  • Add HDMI Nodes for more boards (p212, p230, Khadas VIM, Wetek Play2)
  • Support for the SPICC controller added
  • And missing GXL pinctrl pins

TI DaVinci SoC family:

  • da850: Enable CPPI 4.1 DMA to USB OTG controller
  • da850: vpif: adaptions for DT support

Various

  • Fix for Mediatek MMC driver