Mikrobus

mikroBUS is a standard specification by MikroElektronika that can be freely used by anyone following the guidelines. It includes SPI, I2C, UART, PWM, ADC, reset, interrupt, and power (3.3V and 5V) connections to common embedded peripherals.

This page is meant to foster discussion within the embedded Linux community on usage of mikroBUS compatible add-on boards, adding mikroBUS sockets to embedded Linux systems, and ways to improve both Linux support for mikroBUS and the mikroBUS standard.

Device tree overlays loaded at boot time
Today, there is no mainline solution for enabling mikroBUS add-on boards at run-time, so they must all be configured at boot-time with device trees.

Instructions for PocketBeagle: https://github.com/beagleboard/pocketbeagle/wiki/Click-boards%E2%84%A2

Example overlay: https://github.com/beagleboard/bb.org-overlays/blob/master/src/arm/PB-I2C2-MPU-9DOF-CLICK.dts

This is the primary mechanism for enumerating device drivers for mikroBUS add-on boards today. It suffers from the need to maintain a large out-of-tree database for which you'd need an overlay for every mikroBUS add-on board for every Linux system for every mikroBUS socket on that system. Multiplying 1,000 Click boards by the number of BeagleBoard.org boards by the number of sockets supported on each of those boards ends up being a LOT of device tree overlay fragments.

Further, the application of those fragments is rather error-prone and can even result in preventing a system from booting.

Run-time device tree overlays
There are some out-of-tree mechanisms for loading device-tree overlay fragments via ConfigFS.

This patch doesn't apply after 4.14 and is not likely to be accepted in mainline. Mainline doesn't want arbitrary device-tree fragments, but there is a chance that this could be considered a "development-only" patch if this is rebased. The solution would allow run-time loading, but would not be automatic and requires authoring of overlay fragments specific to every add-on board, every Linux platform and every mikroBUS socket.

Using Greybus simulator to enable software hotplug support
It is possible to enumerate some device drivers for mikroBUS add-on boards by running the Greybus simulator, gbsim. Instructions for setting up gbsim and more information can be found in a wiki write-up on a GSoC project. This method uses Greybus simulator to load a manifest blob to the kernel greybus driver where the virtual interfaces(SPI/I2C/other) are created.

gbsim manages the transfers between the physical bus/gpio/interrupt and the virtual Greybus interface. Having a userspace application, gbsim, in the middle of the transactions has a performance and security impact.

This approach requires additional platform data for instantiating device drivers for mikroBUS add-on boards with platform data requirements like reset, interrupt-gpio, and other named-gpio, thus the approach needs more refinements to tackle the issues of instantiating devices with additional platform data requirements. A few approaches to solve this problem are discussed here.

Using Greybus to enumerate drivers for mikroBUS add-on boards has an added advantage of using different transports which makes it ideal for IoT applications. A transport could be a wired or wireless network, in addition to more flexible embedded busses like Unipro.

Creation of a mikroBUS bus driver in the Linux kernel
This approach does not involve the use of greybus directly but uses the greybus manifests for providing the platform data, it is actually a combination of the Greybus manifest parsing logic combined with the working of Bone Cape Manager used in the previous BB kernels, the Cape Manager used to load the data for a cape from the Device Tree whereas this bus driver takes the data from the manifest blob passed via the SysFS interface.The Mikrobus port information for the device is parsed from the Device Tree(this information only account for the port information and does not have any click specific information).

Identifier
Adding an identifier would provide a way to load the device drivers for a mikroBUS add-on board without the need for manual configuration. By fetching the identifier in the mikroBUS bus driver probe function, would enable that function to call the probe function in the various device drivers.

Proposal #1: Use Greybus Manifest binaries

 * Module vendor specified separately from driver usage
 * Possibility of using existing driver names for invocation

Proposal #2: Use simple string identifiers

 * Requires table to be kept in kernel
 * Fix-ups would be very direct and not "fix-ups" at all, since no driver specific information would be encoded

Specifics on power function
The direction and accommodations related to the power pins aren't as specific in the mikroBus standard as with Feather.

Usage of improved mikroBUS support in Linux and mikroBUS standard
Assuming all of the suggestions above are implemented, what would the resulting usage be?

Adding a mikroBUS socket to your Linux system
Once the mikroBUS driver is implemented, the device tree fragment for a particular mikroBUS socket will have a basic structure like this:

mikrobus@f00 { #address-cells = <1>; #size-cells   = <0>; compatible    = "mikroe,mikrobus"; pinctrl-0     = <&mikrobus0_pins>; /*contains the pin information of the SPI/I2C/UART ports, for pinmux configuration*/ i2c-port      = <&i2cN>; spi-port      = <&spiN>; uart-port     = <&uartN>; int-gpio      = <&gpioN M 0>; pwm-gpio      = <&gpioN M 0>; rst-gpio      = <&gpioN M 0>; status        = "okay"; };

Greybus Manifest
The Greybus manifest format for a MPU9DOF Click will have a structure like this:

[manifest-header] version-major = 0 version-minor = 1 [interface-descriptor] vendor-string-id = 1 driver-string-id = 2 ; Interface vendor string (id can't be 0) [string-descriptor 1] string = invensense ; Interface driver string (id can't be 0) [string-descriptor 2] string = mpu9150 [platform-descriptor 1] type = string value = mpu9150,int-gpio [platform-descriptor 2] type = u8 value = 23 ;Control protocol on CPort 0 [cport-descriptor 0] bundle = 0 protocol = 0x00 ;Control protocol Bundle 0 [bundle-descriptor 0] class = 0 ; I2C protocol on CPort 1 [cport-descriptor 1] bundle = 1 protocol = 0x03 platform-descriptor = mpu9150,interrupt-source, 1 ; Bundle 1 [bundle-descriptor 1] class = 0x0a ; GPIO protocol on CPort 2 [cport-descriptor 2] bundle = 1 protocol = 0x02 platform-descriptor = mpu9150,interrupt-gpio, 2 ; Bundle 2 [bundle-descriptor 2] class = 0x0a

Comparisons to other popular embedded add-on form-factors
The purpose of this page is to advance the development of mikroBUS support in Linux. Some distractions may be introduced to either illustrate the effort cannot be sufficiently limited in scope to tackle or that focus should be elsewhere. I'm not assuming these would be introduced with any ill-will, they are just natural concerns that need to be addressed up-front.

Why should mikroBUS be a bus in the kernel even if these other interfaces aren't?

 * mikroBUS is simple, not requiring the need to overlay arbitrary device trees like Capes or other excessively flexible interfaces defined arbitrary collections of microcontroller pins.
 * mikroBUS a free standard and not an ad-hoc one.
 * Over 750+ Click add-on boards ranging from wireless connectivity clicks to Human Machine Interface clicks, of which more than 100+ clicks already have support in the Linux kernel.
 * Over 140+ Development boards supported.

Definitions
