# Cubox-i4 Pro: Disable USB port power

**URL:** <https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612>\
**Category:** I.MX6\
**Created:** [March 29, 2023, 6:02pm UTC](https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612 "2023-03-29T18:02:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![GAZ082](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/gaz082/32/183_2.png) [@GAZ082](https://community.solid-run.com/u/GAZ082)\
**Post date:** [March 29, 2023, 6:02pm UTC](https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612/1 "2023-03-29T18:02:32Z")

</div>

Hi. Im using ArchlinuxArm, is there a way to disable the power of one of the USB ports? I think this needs something on the hardware side to take out the 5v.

Thanks!

---

<div class="post-metadata">

**Author:** ![jnettlet](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/jnettlet/32/62_2.png) [@jnettlet](https://community.solid-run.com/u/jnettlet)\
**Post date:** [March 30, 2023, 4:30am UTC](https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612/2 "2023-03-30T04:30:02Z")

</div>

The USB port regulators are controlled by gpio’s and in the mainline kernel are defined as.

```auto
        v_usb2: regulator-v-usb2 {
                compatible = "regulator-fixed";
                enable-active-high;
                gpio = <&gpio1 0 GPIO_ACTIVE_HIGH>;
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_cubox_i_usbh1_vbus>;
                regulator-max-microvolt = <5000000>;
                regulator-min-microvolt = <5000000>;
                regulator-name = "v_usb2";
                vin-supply = <&v_5v0>;
        };

        v_usb1: regulator-v-usb1 {
                compatible = "regulator-fixed";
                enable-active-high;
                gpio = <&gpio3 22 GPIO_ACTIVE_HIGH>;
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_cubox_i_usbotg_vbus>;
                regulator-max-microvolt = <5000000>;
                regulator-min-microvolt = <5000000>;
                regulator-name = "v_usb1";
                vin-supply = <&v_5v0>;
        };

```

There is no existing kernel mechanism to control these regulators from userspace. In our BSP builds we use a patch to the userspace consumer regulator platform driver to make it device-tree enabled. [meta-solidrun-arm-imx8/0006-regulator-userspace-consumer-add-DT-support.patch at kirkstone-imx8m · SolidRun/meta-solidrun-arm-imx8 · GitHub](https://github.com/SolidRun/meta-solidrun-arm-imx8/blob/kirkstone-imx8m/recipes-kernel/linux/linux-imx/0006-regulator-userspace-consumer-add-DT-support.patch)

Then you need to patch the device-tree to add a node to expose the control. This is the patch we use for our iMX8MP platforms, but it could easily be adapted to the iMX6 Cubox-i device-tree

```auto
+	power-usb-port1 {
+ compatible = "reg-userspace-consumer";
+ regulator-name = "usb-port1-pwr-consumer";
+ regulator-boot-on;
+ regulator-supplies = "vcc";
+ vcc-supply = <&reg_usb1_host_vbus>;
+ comment = "USB Port1 vbus power switch";
+ };

```

---

<div class="post-metadata">

**Author:** ![GAZ082](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/gaz082/32/183_2.png) [@GAZ082](https://community.solid-run.com/u/GAZ082)\
**Post date:** [March 30, 2023, 1:16pm UTC](https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612/3 "2023-03-30T13:16:46Z")

</div>

Thanks @jnettlet !

This is all new to me. Let me put what you just wrote into simple actionable steps so I can tackle one by one.  
In order:

1. Patch the Kernel with the code you linked (as is, no modifications?)
2. Patch the device tree.

You mentioned should be trivial to adapt the device tree patch to IMX6, but I do not know where to look at to adapt it (unless the patch you gave me was already fitted for IMX6).

Thanks!

---

<div class="post-metadata">

**Author:** ![jnettlet](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/jnettlet/32/62_2.png) [@jnettlet](https://community.solid-run.com/u/jnettlet)\
**Post date:** [March 30, 2023, 1:59pm UTC](https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612/4 "2023-03-30T13:59:47Z")

</div>

Which kernel version are you using? I can probably write you a patch series to incorporate this pretty quickly. That is unless you want to give it a try.

The device-tree file would be, arch/arm/boot/dts/imx6qdl-cubox-i.dtsi

---

<div class="post-metadata">

**Author:** ![GAZ082](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/gaz082/32/183_2.png) [@GAZ082](https://community.solid-run.com/u/GAZ082)\
**Post date:** [March 30, 2023, 3:06pm UTC](https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612/5 "2023-03-30T15:06:53Z")

</div>

That would be awesome. Im not really interested in Kernel development, just want to be able to completely shut down my 3D printer connected to the Cubox without having to turn the box off 🙂

My uname -a output is:  
`Linux alarm 6.2.8-1-ARCH #1 SMP PREEMPT Wed Mar 22 21:10:24 MDT 2023 armv7l GNU/Linux`

Im using ArchlinuxArm.

Dont know if the patch you make is possible to merge upstream, would be a nice addition to Arch.

Thanks!

---

<div class="post-metadata">

**Author:** ![jnettlet](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/jnettlet/32/62_2.png) [@jnettlet](https://community.solid-run.com/u/jnettlet)\
**Post date:** [March 30, 2023, 3:44pm UTC](https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612/6 "2023-03-30T15:44:55Z")

</div>

Does your 3d printer power itself off if the USB-port is not powered? Or do you just mean the controller for your 3d printer?

This patch won’t be mainlined, it was already attempted years ago and the mainline stance is that userspace should not be handling regulators. It is annoying but that is the status of things.

---

<div class="post-metadata">

**Author:** ![GAZ082](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/gaz082/32/183_2.png) [@GAZ082](https://community.solid-run.com/u/GAZ082)\
**Post date:** [March 30, 2023, 4:38pm UTC](https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612/7 "2023-03-30T16:38:19Z")

</div>

Yeah, the controller stays powered. And also in the same 5v rail has a fan that just keeps spinning.

My work around was to also shut the cubox, but having to unplug-plug to start is annoying.

---

<div class="post-metadata">

**Author:** ![jnettlet](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/jnettlet/32/62_2.png) [@jnettlet](https://community.solid-run.com/u/jnettlet)\
**Post date:** [March 31, 2023, 6:59am UTC](https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612/8 "2023-03-31T06:59:36Z")

</div>

Hmmm…so 6.2 has added this commit.

```auto
commit 5c51d4afcf3fd36159713556402e16cfab794ae9
Author: Zev Weiss <zev@bewilderbeest.net>
Date: Mon Oct 31 16:37:04 2022 -0700

    regulator: userspace-consumer: Handle regulator-output DT nodes

```

I will need to see if we can leverage this to maybe mainline patches. Otherwise the patch I am using will need to be adapted to work with this new code. This may make things easier or more difficult, I will need to do some testing first.

---

<div class="post-metadata">

**Author:** ![GAZ082](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/gaz082/32/183_2.png) [@GAZ082](https://community.solid-run.com/u/GAZ082)\
**Post date:** [March 31, 2023, 12:25pm UTC](https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612/9 "2023-03-31T12:25:36Z")

</div>

Looks like you are having fun!

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![GAZ082](https://dub1.discourse-cdn.com/flex005/user_avatar/community.solid-run.com/gaz082/32/183_2.png) [@GAZ082](https://community.solid-run.com/u/GAZ082)\
**Post date:** [April 4, 2023, 10:30pm UTC](https://community.solid-run.com/t/cubox-i4-pro-disable-usb-port-power/612/10 "2023-04-04T22:30:23Z")

</div>

Hi @jnettlet , any news?

Thanks!
