VAR-SOM-MX8 WakeableGPIO

From Variscite Wiki
Revision as of 23:59, 13 June 2021 by Pierluigi (talk | contribs) (Created page with "<!-- Set release according to "release" parameter in URL and use RELEASE_DUNFELL_V1.1_VAR-SOM-MX8 as default --> {{#vardefine:RELEASE_PARAM|{{#urlget:release|RELEASE_DUNFELL_V...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
VAR-SOM-MX8 Wakeable GPIO

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

#ifdef CONFIG_GPIO_MXC_PAD_WAKEUP
	/*
	 * parse pad wakeup info from dtb, each pad has to provide
	 * <pin_id, type, line>, these info should be put in each
	 * gpio node and with a "pad-wakeup-num" to indicate the
	 * total lines are with pad wakeup enabled.
	 */
	if (!of_property_read_u32(np, "pad-wakeup-num", &port->pad_wakeup_num)) {
		if (port->pad_wakeup_num != 0) {
			if (!gpio_ipc_handle) {
				err = imx_scu_get_handle(&gpio_ipc_handle);
				if (err)
					return err;
			}
			for (i = 0; i < port->pad_wakeup_num; i++) {
				of_property_read_u32_index(np, "pad-wakeup",
					i * 3 + 0, &port->pad_wakeup[i].pin_id);
				of_property_read_u32_index(np, "pad-wakeup",
					i * 3 + 1, &port->pad_wakeup[i].type);
				of_property_read_u32_index(np, "pad-wakeup",
					i * 3 + 2, &port->pad_wakeup[i].line);
			}
			err = imx_scu_irq_group_enable(IMX_SC_IRQ_GROUP_WAKE, IMX_SC_IRQ_PAD, true);
			if (err)
				dev_warn(&pdev->dev, "Enable irq failed, GPIO pad wakeup NOT supported\n");
		}
	}
#endif

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

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.

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>;
};