VAR-SOM-MX8 WakeableGPIO

From Variscite Wiki
VAR-SOM-MX8 Wakeable GPIO

1 Introduction: the GPIO driver code

In the device tree, the standard wakeup-source property has no effect for VAR-SOM-MX8.

Inspecting the code in the kernel driver

 drivers/gpio/gpio-mxc.c

you can find something like

 1#ifdef CONFIG_GPIO_MXC_PAD_WAKEUP
 2	/*
 3	 * parse pad wakeup info from dtb, each pad has to provide
 4	 * <pin_id, type, line>, these info should be put in each
 5	 * gpio node and with a "pad-wakeup-num" to indicate the
 6	 * total lines are with pad wakeup enabled.
 7	 */
 8	if (!of_property_read_u32(np, "pad-wakeup-num", &port->pad_wakeup_num)) {
 9		if (port->pad_wakeup_num != 0) {
10			if (!gpio_ipc_handle) {
11				err = imx_scu_get_handle(&gpio_ipc_handle);
12				if (err)
13					return err;
14			}
15			for (i = 0; i < port->pad_wakeup_num; i++) {
16				of_property_read_u32_index(np, "pad-wakeup",
17					i * 3 + 0, &port->pad_wakeup[i].pin_id);
18				of_property_read_u32_index(np, "pad-wakeup",
19					i * 3 + 1, &port->pad_wakeup[i].type);
20				of_property_read_u32_index(np, "pad-wakeup",
21					i * 3 + 2, &port->pad_wakeup[i].line);
22			}
23			err = imx_scu_irq_group_enable(IMX_SC_IRQ_GROUP_WAKE, IMX_SC_IRQ_PAD, true);
24			if (err)
25				dev_warn(&pdev->dev, "Enable irq failed, GPIO pad wakeup NOT supported\n");
26		}
27	}
28#endif

This means that 2 properties, pad-wakeup-num and pad-wakeup, are expected.

2 The device tree binding

The property pad-wakeup-num must provide the total number of pads belonging to the specific GPIO bank that will be declared as wakeup sources.

The property pad-wakeup must provide a list of pad-wakeup-num triplets. Each triplet will provide:

  • the pad identifier from kernel file include/dt-bindings/pinctrl/pads-imx8qm.h
  • the trigger type from kernel file include/dt-bindings/pinctrl/pads-imx8qm.h
  • the wakeup line the GPIO line in the 32bit GPIO group

Also these properties must me located within the specific gpio bank node associated to the pin you want to use as wakeup source.

2.1 A reference example

Let's summarize in a reference example

&lsio_gpio1 {
	/* Enable wakeup-source from Capacitive touch */

	pad-wakeup-num = <1>;	/* Total number of wakeup pads in gpio1 bank */

	/*
	 IMX8QM_LVDS0_GPIO01:   Touch IRQ pin id
	 SC_PAD_WAKEUP_LOW_LVL: trigger type
	 5:                     Touch IRQ gpio pin
	*/
	pad-wakeup = <IMX8QM_LVDS0_GPIO01 SC_PAD_WAKEUP_LOW_LVL 5>;
};