Difference between revisions of "OTG device tree configuration"

[quality revision] [quality revision]
m (DT configuration (board level))
 
m
Template:ArticleMainWriter Template:ReviewersList Template:ArticleApprovedVersion

1 Article purpose[edit]

This article explains how to configure the OTG internal peripheral when it is assigned to the Linux® OS. In that case, it is controlled by the USB framework.

The configuration is performed using the device tree mechanism.

It is used by OTG Linux driver[1] which registers the relevant information in the USB framework.

2 DT bindings documentation[edit]

The Platform DesignWare HS OTG USB 2.0 controller device tree bindings[2] document represents the OTG (DRD) controller.

The Generic USB device tree bindings[3] document represents generic USB properties, proposed by USB framework such as maximum speed, dr_mode...

3 DT configuration[edit]

This hardware description is a combination of the STM32 microprocessor device tree files (.dtsi extension) and board device tree files (.dts extension). See the Device tree for an explanation of the device tree file split.

STM32CubeMX can be used to generate the board device tree. Refer to How to configure the DT using STM32CubeMX for more details.

3.1 DT configuration (STM32 level)[edit]

The usbotg_hs DT node is declared in stm32mp157c.dtsi[4].

It is composed of a set of properties, used to describe the OTG controller: registers address, clocks, resets, interrupts...

usbotg_hs: usb-otg@49000000 {
	compatible = "snps,dwc2";
	reg = <0x49000000 0x10000>;
	clocks = <&rcc USBO_K>;
	clock-names = "otg";
	resets = <&rcc USBO_R>;
	reset-names = "dwc2";
	interrupts = <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>;
	dr_mode = "otg"; 	 	 	 	/* dr_mode[3] can be overwritten at board level to set a particular mode */
	status = "disabled";
};
Warning white.png Warning
This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user.


3.2 DT configuration (board level)[edit]

Follow the sequences described in the below chapters to configure and enable the OTG on your board.

OTG supports two PHY interfaces that can be statically selected via DT:

  • full-speed PHY, embedded with the OTG controller
  • high-speed USBPHYC HS PHY that can be assigned to either the USBH or the OTG controller.

When operating in "otg" or "host" mode, an external charge pump, e.g. 5V regulator must be specified.

Info white.png Information
Please refer to Regulator overview for additional information on regulators configuration.

3.2.1 DT configuration using full-speed USB PHY[edit]

  • Enable the OTG by setting status = "okay".
  • Use embedded full-speed PHY by setting compatible = "st,stm32mp1-fsotg", "snps,dwc2"
  • Configure full-speed PHY pins (OTG ID, DM, DP) as analog via pinctrl, through pinctrl-0 and pinctrl-names.
  • Optionally set dual-role mode through dr_mode = "peripheral", "host" or "otg" (default to "otg" in case it is not set)
  • Optionally set vbus voltage regulator for otg and host modes, through vbus-supply = <&your_regulator>

3.2.2 DT configuration using high-speed USB PHY[edit]

  • Enable the OTG by setting status = "okay".
  • Select USBPHYC port#2 by setting phys = <&usbphyc_port1 0>; and phy-names = "usb2-phy";
  • Optionally configure OTG ID pin as analog via pinctrl, through pinctrl-0 and pinctrl-names.
  • Optionally set dual-role mode through dr_mode = "peripheral", "host" or "otg" (default to "otg" in case it is not set)
  • Optionally set vbus voltage regulator for otg and host modes, through vbus-supply = <&your_regulator>
Info white.png Information
Please refer to USBPHYC device tree configuration for additional information on USBPHYC port#2 configuration

3.3 DT configuration examples[edit]

3.3.1 DT configuration example as full-speed OTG[edit]

The example below shows how to configure full-speed OTG, with the ID pin to detect role (peripheral, host):

  • OTG ID and data (DM, DP) pins: use Pinctrl device tree configuration to configure PA10, PA11 and PA12 as analog input.
  • Use integrated full-speed USB PHY by setting compatible
  • Dual-role (dr_mode) is "otg" (e.g. the default as unspecified)
  • Use vbus voltage regulator
# part of pin-controller dt node
Template:Highlight2:usbotg_hs_pins_a: usbotg_hs-0 {
	pins {
		pinmux = <STM32_PINMUX('A', 10, ANALOG)>; /* OTG_ID */            /* configure 'PA10' as ANALOG */

	};
};

Template:Highlight2:usbotg_fs_dp_dm_pins_a: usbotg-fs-dp-dm-0 {
	pins {
		pinmux = <STM32_PINMUX('A', 11, ANALOG)>, /* OTG_FS_DM */
			 <STM32_PINMUX('A', 12, ANALOG)>; /* OTG_FS_DP */
	};
};
&usbotg_hs {
	compatible = "st,stm32mp1-fsotg", "snps,dwc2";                            /* Use full-speed integrated PHY */
	pinctrl-names = "default";
	pinctrl-0 = <Template:Highlight2&usbotg_hs_pins_a &usbotg_fs_dp_dm_pins_a>;                  /* configure OTG ID and full-speed data pins */
	vbus-supply = <&vbus_otg>;                                                /* voltage regulator to supply Vbus */
	status = "okay";
};

3.3.2 DT configuration example as high speed OTG[edit]

The example below shows how to configure high-speed OTG, with the ID pin to detect role (peripheral, host):

  • OTG ID pin: use Pinctrl device tree configuration to configure PA10 as analog input.
  • Use USB HS PHY port#2, with the UTMI switch that selects the OTG controller
  • Dual-role mode (dr_mode) is "otg" (e.g. the default as unspecified)
  • Use vbus voltage regulator
# part of pin-controller dt node
Template:Highlight2:usbotg_hs_pins_a: usbotg_hs-0 {
	pins {
		pinmux = <STM32_PINMUX('A', 10, ANALOG)>; /* OTG_ID */            /* configure 'PA10' as ANALOG */

	};
};
&usbotg_hs {
	compatible = "st,stm32mp1-hsotg", "snps,dwc2";
	pinctrl-names = "default";
	pinctrl-0 = <Template:Highlight2&usbotg_hs_pins_a>;                                          /* configure OTG_ID pin */
	phys = <&usbphyc_port1 0>;                                                /* 0: UTMI switch selects the OTG controller */
	phy-names = "usb2-phy";
	vbus-supply = <&vbus_otg>;                                                /* voltage regulator to supply Vbus */
	status = "okay";                                                          /* enable OTG */
};

4 How to configure the DT using STM32CubeMX[edit]

The STM32CubeMX tool can be used to configure the STM32MPU device and get the corresponding platform configuration device tree files.
The STM32CubeMX may not support all the properties described in the above DT bindings documentation paragraph. If so, the tool inserts user sections in the generated device tree. These sections can then be edited to add some properties and they are preserved from one generation to another. Refer to STM32CubeMX user manual for further information.

5 References[edit]

Please refer to the following links for additional information:

  1. drivers/usb/dwc2/ , DesignWare HS OTG Controller driver
  2. Documentation/devicetree/bindings/usb/dwc2.txt , Platform DesignWare HS OTG USB 2.0 controller device tree bindings
  3. 3.03.1 Documentation/devicetree/bindings/usb/generic.txt , Generic USB device tree bindings
  4. arch/arm/boot/dts/stm32mp157c.dtsi , STM32MP157C device tree file



<noinclude>

{{ArticleBasedOnModel | [[Peripheral or framework device tree configuration model]]}}
{{ArticleMainWriter | AmelieD}}
{{ReviewersList | AmelieD, FabriceG}}
{{ArticleApprovedVersion | FabriceG | AmelieD | No previous approved version | AlainF - 16Jan'19 - 10336 | 16Jan'19}}
[[Category:Device tree configuration]]
[[Category:USB|0]]</noinclude>

== Article purpose ==
This article explains how to configure the [[OTG internal peripheral|'''OTG''' internal peripheral]] when it is assigned to the Linux<sup>&reg;</sup> OS. In that case, it is controlled by the [[USB overview|USB framework]].

The configuration is performed using the [[Device tree|device tree]] mechanism.

It is used by ''OTG Linux driver''<ref>{{CodeSource | Linux kernel | drivers/usb/dwc2/}}, DesignWare HS OTG Controller driver</ref> which registers the relevant information in the [[USB overview|USB framework]].

== DT bindings documentation ==
The ''Platform DesignWare HS OTG USB 2.0 controller device tree bindings''<ref name="dwc2_bindings>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/usb/dwc2.txt}}, Platform DesignWare HS OTG USB 2.0 controller device tree bindings</ref> document represents the [[OTG internal peripheral|OTG]] (DRD) controller.

The ''Generic USB device tree bindings''<ref name="generic_bindings">{{CodeSource | Linux kernel | Documentation/devicetree/bindings/usb/generic.txt}}, Generic USB device tree bindings</ref> document represents generic USB properties, proposed by [[USB overview|USB framework]] such as maximum speed, dr_mode...

== DT configuration ==
This hardware description is a combination of the '''STM32 microprocessor''' device tree files (''.dtsi'' extension) and '''board''' device tree files (''.dts'' extension). See the [[Device tree]] for an explanation of the device tree file split.

'''STM32CubeMX''' can be used to generate the board device tree. Refer to [[#How_to_configure_the_DT_using_STM32CubeMX|How to configure the DT using STM32CubeMX]] for more details.
=== DT configuration (STM32 level) ===
The '''usbotg_hs''' DT node is declared in stm32mp157c.dtsi<ref name="stm32mp157c_dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157c.dtsi}}, STM32MP157C device tree file</ref>.

It is composed of a set of properties, used to describe the [[OTG_internal_peripheral#Features|OTG controller]]: registers address, clocks, resets, interrupts...

 '''usbotg_hs''': usb-otg@49000000 {
 	compatible = "snps,dwc2";
 	reg = <0x49000000 0x10000>;
 	clocks = <&rcc USBO_K>;
 	clock-names = "otg";
 	resets = <&rcc USBO_R>;
 	reset-names = "dwc2";
 	interrupts = <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>;
 	'''dr_mode = "otg";''' 	 	 	 	{{Highlight|/* '''dr_mode'''<ref name="generic_bindings"/> can be overwritten at board level to set a particular mode */}}
 	status = "disabled";
 };
{{Warning|This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user.}}
{{ReviewsComments|FGA W902: Later add some examples to fine tune various fifo size (g-rx-fifo-size, g-np-tx-fifo-size, g-tx-fifo-size) depending on the use case: host, gadget eth, gadget mass storage... Maybe part of a dedicated article}}

=== DT configuration (board level) ===
Follow the sequences described in the below chapters to configure and enable the OTG on your board.

OTG supports two PHY interfaces that can be statically selected via DT:
* full-speed PHY, embedded with the [[OTG_internal_peripheral|OTG]] controller
* high-speed [[USBPHYC_internal_peripheral|USBPHYC]] HS PHY that can be assigned to either the [[USBH_internal_peripheral|USBH]] or the [[OTG_internal_peripheral|OTG]] controller.
When operating in "otg" or "host" mode, an external charge pump, e.g. 5V regulator must be specified.
{{Info|Please refer to  [[Regulator overview]] for additional information on regulators configuration.}}

==== DT configuration using full-speed USB PHY ====
* Enable the OTG by setting '''status = "okay".'''
* Use embedded full-speed PHY by setting '''compatible = "st,stm32mp1-fsotg", "snps,dwc2"'''
* Configure full-speed PHY pins (OTG ID, DM, DP) as analog via [[Pinctrl overview|pinctrl]], through '''pinctrl-0''' and '''pinctrl-names'''.
* Optionally set dual-role mode through '''dr_mode = "peripheral"''', '''"host"''' or '''"otg"''' (default to "otg" in case it is not set)
* Optionally set vbus voltage [[Regulator overview|regulator]] for otg and host modes, through '''vbus-supply = <&your_regulator>'''

==== DT configuration using high-speed USB PHY ====
* Enable the OTG by setting '''status = "okay".'''
* Select USBPHYC port#2 by setting '''phys = <&usbphyc_port1 {{highlight|0}}>;''' and '''phy-names = "usb2-phy";'''
* Optionally configure OTG ID pin as analog via [[Pinctrl overview|pinctrl]], through '''pinctrl-0''' and '''pinctrl-names'''.
* Optionally set dual-role mode through '''dr_mode = "peripheral"''', '''"host"''' or '''"otg"''' (default to "otg" in case it is not set)
* Optionally set vbus voltage [[Regulator overview|regulator]] for otg and host modes, through '''vbus-supply = <&your_regulator>'''
{{Info|Please refer to [[USBPHYC device tree configuration]] for additional information on USBPHYC port#2 configuration}}

=== DT configuration examples ===
==== DT configuration example as full-speed OTG ====
The example below shows how to configure full-speed OTG, with the ID pin to detect role (peripheral, host):
* OTG ID and data (DM, DP) pins: use [[Pinctrl device tree configuration]] to configure PA10, PA11 and PA12 as analog input.
* Use integrated ''full-speed USB PHY'' by setting '''compatible'''
* Dual-role (dr_mode) is "otg" (e.g. the default as unspecified)
* Use vbus voltage regulator
 # part of pin-controller dt node
 {{highlight2HighlightParam|usbotg_hs_pins_a}}: usbotg_hs-0 {
 	pins {
 		pinmux = <STM32_PINMUX('A', 10, ANALOG)>; /* OTG_ID */            {{highlight|/* configure 'PA10' as ANALOG */}}

 	};
 };

 {{highlight2HighlightParam|usbotg_fs_dp_dm_pins_a}}: usbotg-fs-dp-dm-0 {
 	pins {
 		pinmux = <STM32_PINMUX('A', 11, ANALOG)>, /* OTG_FS_DM */<STM32_PINMUX('A', 12, ANALOG)>; /* OTG_FS_DP */
 	};
 };

 &usbotg_hs {
 	compatible = "{{highlight|st,stm32mp1-'''fsotg'''}}", "snps,dwc2";                            {{highlight|/* Use full-speed integrated PHY */}}
 	pinctrl-names = "default";
 	pinctrl-0 = <{{highlight2|&usbotg_hs_pins_a &usbotg_fs_dp_dm_pins_a}}><{{HighlightParam|&usbotg_hs_pins_a &usbotg_fs_dp_dm_pins_a}}>;                  {{highlight|/* configure OTG ID and full-speed data pins */}}
 	vbus-supply = <{{highlight|&vbus_otg}}>;                                                {{highlight|/* voltage regulator to supply Vbus */}}
 	status = "okay";
 };

==== DT configuration example as high speed OTG ====
The example below shows how to configure high-speed OTG, with the ID pin to detect role (peripheral, host):
* OTG ID pin: use [[Pinctrl device tree configuration]] to configure PA10 as analog input.
* Use ''USB HS PHY port#2'', with the UTMI switch that selects the OTG controller
* Dual-role mode (dr_mode) is "otg" (e.g. the default as unspecified)
* Use vbus voltage regulator
 # part of pin-controller dt node
 {{highlight2HighlightParam|usbotg_hs_pins_a}}: usbotg_hs-0 {
 	pins {
 		pinmux = <STM32_PINMUX('A', 10, ANALOG)>; /* OTG_ID */            {{highlight|/* configure 'PA10' as ANALOG */}}

 	};
 };

 &usbotg_hs {
 	compatible = "{{highlight|st,stm32mp1-'''hsotg'''}}", "snps,dwc2";
 	pinctrl-names = "default";
 	pinctrl-0 = <{{highlight2|&usbotg_hs_pins_a}}><{{HighlightParam|&usbotg_hs_pins_a}}>;                                          {{highlight|/* configure OTG_ID pin */}}
 	phys = <&usbphyc_port1 {{highlight|'''0'''}}>;                                                {{highlight|/* '''0''': UTMI switch selects the OTG controller */}}
 	phy-names = "usb2-phy";
 	vbus-supply = <{{highlight|&vbus_otg}}>;                                                {{highlight|/* voltage regulator to supply Vbus */}}
 	status = "{{highlight|okay}}";                                                          {{highlight|/* enable OTG */}}
 };

==How to configure the DT using STM32CubeMX==
The [[STM32CubeMX]] tool can be used to configure the STM32MPU device and get the corresponding [[Device_tree#STM32|platform configuration device tree]] files.<br />

The STM32CubeMX may not support all the properties described in the above [[#DT bindings documentation|DT bindings documentation]] paragraph. If so, the tool inserts '''user sections''' in the generated device tree. These sections can then be edited to add some properties and they are preserved from one generation to another. Refer to [[STM32CubeMX]] user manual for further information.

==References==
Please refer to the following links for additional information:
<references />

<noinclude>

{{ArticleBasedOnModel | Peripheral or framework device tree configuration model}}
{{PublicationRequestId | 10336 | 2019-01-16 | AlainF}}
[[Category:Device tree configuration]]
[[Category:USB|0]]</noinclude>
Line 1: Line 1:
<noinclude>
 
{{ArticleBasedOnModel | [[Peripheral or framework device tree configuration model]]}}
 
{{ArticleMainWriter | AmelieD}}
 
{{ReviewersList | AmelieD, FabriceG}}
 
{{ArticleApprovedVersion | FabriceG | AmelieD | No previous approved version | AlainF - 16Jan'19 - 10336 | 16Jan'19}}
 
[[Category:Device tree configuration]]
 
[[Category:USB|0]]
 
</noinclude>
 
 
 
== Article purpose ==
 
== Article purpose ==
 
This article explains how to configure the [[OTG internal peripheral|'''OTG''' internal peripheral]] when it is assigned to the Linux<sup>&reg;</sup> OS. In that case, it is controlled by the [[USB overview|USB framework]].
 
This article explains how to configure the [[OTG internal peripheral|'''OTG''' internal peripheral]] when it is assigned to the Linux<sup>&reg;</sup> OS. In that case, it is controlled by the [[USB overview|USB framework]].
Line 75: Line 66:
 
* Use vbus voltage regulator
 
* Use vbus voltage regulator
 
  # part of pin-controller dt node
 
  # part of pin-controller dt node
  {{highlight2|usbotg_hs_pins_a}}: usbotg_hs-0 {
+
  {{HighlightParam|usbotg_hs_pins_a}}: usbotg_hs-0 {
 
  pins {
 
  pins {
 
  pinmux = <STM32_PINMUX('A', 10, ANALOG)>; /* OTG_ID */            {{highlight|/* configure 'PA10' as ANALOG */}}
 
  pinmux = <STM32_PINMUX('A', 10, ANALOG)>; /* OTG_ID */            {{highlight|/* configure 'PA10' as ANALOG */}}
Line 82: Line 73:
 
  };
 
  };
 
   
 
   
  {{highlight2|usbotg_fs_dp_dm_pins_a}}: usbotg-fs-dp-dm-0 {
+
  {{HighlightParam|usbotg_fs_dp_dm_pins_a}}: usbotg-fs-dp-dm-0 {
 
  pins {
 
  pins {
 
  pinmux = <STM32_PINMUX('A', 11, ANALOG)>, /* OTG_FS_DM */
 
  pinmux = <STM32_PINMUX('A', 11, ANALOG)>, /* OTG_FS_DM */
Line 92: Line 83:
 
  compatible = "{{highlight|st,stm32mp1-'''fsotg'''}}", "snps,dwc2";                            {{highlight|/* Use full-speed integrated PHY */}}
 
  compatible = "{{highlight|st,stm32mp1-'''fsotg'''}}", "snps,dwc2";                            {{highlight|/* Use full-speed integrated PHY */}}
 
  pinctrl-names = "default";
 
  pinctrl-names = "default";
  pinctrl-0 = <{{highlight2|&usbotg_hs_pins_a &usbotg_fs_dp_dm_pins_a}}>;                  {{highlight|/* configure OTG ID and full-speed data pins */}}
+
  pinctrl-0 = <{{HighlightParam|&usbotg_hs_pins_a &usbotg_fs_dp_dm_pins_a}}>;                  {{highlight|/* configure OTG ID and full-speed data pins */}}
 
  vbus-supply = <{{highlight|&vbus_otg}}>;                                                {{highlight|/* voltage regulator to supply Vbus */}}
 
  vbus-supply = <{{highlight|&vbus_otg}}>;                                                {{highlight|/* voltage regulator to supply Vbus */}}
 
  status = "okay";
 
  status = "okay";
Line 104: Line 95:
 
* Use vbus voltage regulator
 
* Use vbus voltage regulator
 
  # part of pin-controller dt node
 
  # part of pin-controller dt node
  {{highlight2|usbotg_hs_pins_a}}: usbotg_hs-0 {
+
  {{HighlightParam|usbotg_hs_pins_a}}: usbotg_hs-0 {
 
  pins {
 
  pins {
 
  pinmux = <STM32_PINMUX('A', 10, ANALOG)>; /* OTG_ID */            {{highlight|/* configure 'PA10' as ANALOG */}}
 
  pinmux = <STM32_PINMUX('A', 10, ANALOG)>; /* OTG_ID */            {{highlight|/* configure 'PA10' as ANALOG */}}
Line 114: Line 105:
 
  compatible = "{{highlight|st,stm32mp1-'''hsotg'''}}", "snps,dwc2";
 
  compatible = "{{highlight|st,stm32mp1-'''hsotg'''}}", "snps,dwc2";
 
  pinctrl-names = "default";
 
  pinctrl-names = "default";
  pinctrl-0 = <{{highlight2|&usbotg_hs_pins_a}}>;                                          {{highlight|/* configure OTG_ID pin */}}
+
  pinctrl-0 = <{{HighlightParam|&usbotg_hs_pins_a}}>;                                          {{highlight|/* configure OTG_ID pin */}}
 
  phys = <&usbphyc_port1 {{highlight|'''0'''}}>;                                                {{highlight|/* '''0''': UTMI switch selects the OTG controller */}}
 
  phys = <&usbphyc_port1 {{highlight|'''0'''}}>;                                                {{highlight|/* '''0''': UTMI switch selects the OTG controller */}}
 
  phy-names = "usb2-phy";
 
  phy-names = "usb2-phy";
Line 129: Line 120:
   
 
<references />
 
<references />
  +
  +
<noinclude>
  +
{{ArticleBasedOnModel | Peripheral or framework device tree configuration model}}
  +
{{PublicationRequestId | 10336 | 2019-01-16 | AlainF}}
  +
[[Category:Device tree configuration]]
  +
[[Category:USB|0]]
  +
</noinclude>