Detect button press at u-boot

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Detect button press at u-boot

299 Views
Dhvani
Contributor I

Hi there,
I am using custom i.MX8MM board. I have some issue regarding u-boot button press detection.
I have custom functionality that, I have 4 button (as gpio), when We press 4 buttons together, I want to jump to fastboot mode. I have found gpio library in uboot and tried to detect one gpio and reading its state, but I am unable to read gpio state it always gives me 0. Here is my basuc code which I tried,

ret = gpio_to_device(46, &desc);
if (ret)
{
printf("error in gpio_to_device\n");
return ret;
}
else
{
printf("\nsuccess gpio_to_device\n");
}

ret = dm_gpio_request(&desc, "MINUS");
if(ret)
{
printf("error in dm_gpio_request\n");
}
else
{
printf("success in dm_gpio_request ret=%d\n", ret);
}

value = dm_gpio_get_value(&desc);
if(ret)
{
printf("error in gpio_get_value ***** value=%d\n", value);
}
else
{
printf("success in gpio_get_value ***** value=%d\n", value);
}

Then I also tried with 
ret = gpio_direction_input(46);
if (ret)
{
printf("error in gpio_direction_input\n");
}
else
{
printf("\nsuccess gpio_direction_input ret=%d\n", ret);
}
But adding above function gives me error like,
"gpio not reserved"

Can anyone help me, How can I detect button press at u-boot?

Thank you

0 Kudos
1 Reply

267 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Please refer gpio operation in setup_typec

 

static int setup_typec(void)
{
	int ret;
	struct gpio_desc per_12v_desc;

	debug("tcpc_init port 2\n");
	ret = tcpc_init(&port2, port2_config, NULL);
	if (ret) {
		printf("%s: tcpc port2 init failed, err=%d\n",
		       __func__, ret);
	} else if (tcpc_pd_sink_check_charging(&port2)) {
		printf("Power supply on USB2\n");

		/* Enable PER 12V, any check before it? */
		ret = dm_gpio_lookup_name("gpio@20_1", &per_12v_desc);
		if (ret) {
			printf("%s lookup gpio@20_1 failed ret = %d\n", __func__, ret);
			return -ENODEV;
		}

		ret = dm_gpio_request(&per_12v_desc, "per_12v_en");
		if (ret) {
			printf("%s request per_12v failed ret = %d\n", __func__, ret);
			return -EIO;
		}

		/* Enable PER 12V regulator */
		dm_gpio_set_dir_flags(&per_12v_desc, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
	}

	debug("tcpc_init port 1\n");
	imx_iomux_v3_setup_multiple_pads(ss_mux_gpio, ARRAY_SIZE(ss_mux_gpio));
	gpio_request(USB_TYPEC_SEL, "typec_sel");
	gpio_request(USB_TYPEC_EN, "typec_en");
	gpio_direction_output(USB_TYPEC_EN, 0);

	ret = tcpc_init(&port1, port1_config, &ss_mux_select);
	if (ret) {
		printf("%s: tcpc port1 init failed, err=%d\n",
		       __func__, ret);
	} else {
		return ret;
	}

	return ret;
}
0 Kudos