Skip to contentSkip to conversation

riscv: Add FPIOA and GPIO support for Kendryte K210

PATCH Superseded Sean Anderson 4 participants 29 messages Aug 15, 2020 – Sep 5, 2020 1 message not in the archive

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover riscv: Add FPIOA and GPIO support for Kendryte K210

This patch series adds support for pinmuxing, gpios, and leds on the Kendyte K210.

This patch series was previously part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576

This patch series depends on
https://patchwork.ozlabs.org/project/uboot/list/?series=178480

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.
- Rebase onto u-boot/master

Changes in v4:
- Add sandbox dt-binding headers to MAINTAINERS
- Add test for led behavior
- Add test/dm/pinmux.c to patch
- Move sandbox_* variables into a priv structure. This resets them to the default state every time we re-probe.
- Reformat documentation in dm/pinctrl.h

Changes in v3:
- Add dt-bindings/pinctrl/sandbox-pinmux.h to patch

Changes in v2:
- Add test for pinmuxing
- Don't clear existing pinctrl settings on probe
- Re-order GPIOs to match the defaults more closely
- Rebase onto v13 of "riscv: Add Sipeed Maix support"
- Rewrite FPIOA driver to use pinmux property
- Support muxing the output enable signal for each function in the FPIOA
- Support output and input inversion in the pinmux driver
- Support pinmux property in pinctrl-generic

Sean Anderson (11):
pinctrl: Add pinmux property support to pinctrl-generic
pinctrl: Reformat documentation in dm/pinctrl.h
test: pinmux: Add test for pin muxing
pinctrl: Add support for Kendryte K210 FPIOA
gpio: dw: Fix warnings about casting int to pointer
gpio: dw: Add a trailing underscore to generated name
gpio: dw: Return output value when direction is out
led: gpio: Default to using node name if label is absent
test: dm: Test for default led naming
riscv: Add pinmux and gpio bindings for Kendryte K210
riscv: Add FPIOA and GPIO support for Kendryte K210

 MAINTAINERS                                   |   3 +
 arch/riscv/dts/k210-maix-bit.dts              | 104 +++
 arch/riscv/dts/k210.dtsi                      |  12 +
 arch/sandbox/dts/test.dts                     |  47 +-
 board/sipeed/maix/Kconfig                     |   9 +
 configs/sipeed_maix_bitm_defconfig            |   2 +
 doc/board/sipeed/maix.rst                     |  64 +-
 .../pinctrl/kendryte,k210-fpioa.txt           | 102 +++
 .../pinctrl/pinctrl-bindings.txt              |  65 +-
 drivers/gpio/dwapb_gpio.c                     |  33 +-
 drivers/led/led_gpio.c                        |   7 +-
 drivers/pinctrl/Kconfig                       |   1 +
 drivers/pinctrl/Makefile                      |   1 +
 drivers/pinctrl/kendryte/Kconfig              |   7 +
 drivers/pinctrl/kendryte/Makefile             |   1 +
 drivers/pinctrl/kendryte/pinctrl.c            | 678 ++++++++++++++++++
 drivers/pinctrl/kendryte/pinctrl.h            |  70 ++
 drivers/pinctrl/pinctrl-generic.c             | 125 +++-
 drivers/pinctrl/pinctrl-sandbox.c             | 186 +++--
 include/dm/pinctrl.h                          | 360 +++++++---
 include/dt-bindings/pinctrl/k210-pinctrl.h    | 277 +++++++
 include/dt-bindings/pinctrl/sandbox-pinmux.h  |  19 +
 test/dm/Makefile                              |   3 +
 test/dm/led.c                                 |   3 +-
 test/dm/pinmux.c                              |  57 ++
 test/py/tests/test_pinmux.py                  |  36 +-
 26 files changed, 2028 insertions(+), 244 deletions(-)
 create mode 100644 doc/device-tree-bindings/pinctrl/kendryte,k210-fpioa.txt
 create mode 100644 drivers/pinctrl/kendryte/Kconfig
 create mode 100644 drivers/pinctrl/kendryte/Makefile
 create mode 100644 drivers/pinctrl/kendryte/pinctrl.c
 create mode 100644 drivers/pinctrl/kendryte/pinctrl.h
 create mode 100644 include/dt-bindings/pinctrl/k210-pinctrl.h
 create mode 100644 include/dt-bindings/pinctrl/sandbox-pinmux.h
 create mode 100644 test/dm/pinmux.c
Signature · 1 line
2.28.0
#1 lore raw

PATCH v5 1/11 pinctrl: Add pinmux property support to pinctrl-generic

The pinmux property allows for smaller and more compact device trees, especially when there are many pins which need to be assigned individually. Instead of specifying an array of strings to be parsed as pins and a function property, the pinmux property contains an array of integers representing pinmux groups. A pinmux group consists of the pin identifier and mux settings represented as a single integer or an array of integers. Each individual pin controller driver specifies the exact format of a pinmux group. As specified in the Linux documentation, a pinmux group may be multiple integers long. However, no existing drivers use multi-integer pinmux groups, so I have chosen to omit this feature. This makes the implementation easier, since there is no need to allocate a buffer to do endian conversions.

Support for the pinmux property is done differently than in Linux. As far as I can tell, inversion of control is used when implementing support for the pins and groups properties to avoid allocating. This results in some duplication of effort; every property in a config node is parsed once for each pin in that node. This is not such an overhead with pins and groups properties, since having multiple pins in one config node does not occur especially often. However, the semantics of the pinmux property make such a configuration much more appealing. A future patch could parse all config properties at once and store them in an array. This would make it easier to create drivers which do not function solely as callbacks from pinctrl-generic.

This commit increases the size of the sandbox build by approximately 48 bytes. However, it also decreases the size of the K210 device tree by 2 KiB from the previous version of this series.

The documentation has been updated from the last Linux commit before it was split off into yaml files.

---

(no changes since v2)

Changes in v2:
- New

 .../pinctrl/pinctrl-bindings.txt              |  65 ++++++++-
 drivers/pinctrl/pinctrl-generic.c             | 125 ++++++++++++++----
 include/dm/pinctrl.h                          |  21 +--
 3 files changed, 168 insertions(+), 43 deletions(-)
doc/device-tree-bindings/pinctrl/pinctrl-bindings.txt +59 -6
index b73c96d24f..603796f169 100644
@@ -119,7 +119,8 @@ For example:
 
 The contents of each of those pin configuration child nodes is defined
 entirely by the binding for the individual pin controller device. There
-exists no common standard for this content.
+exists no common standard for this content. The pinctrl framework only
+provides generic helper bindings that the pin controller driver can use.
 
 The pin configuration nodes need not be direct children of the pin controller
 device; they may be grandchildren, for example. Whether this is legal, and
@@ -156,6 +157,29 @@ state_2_node_a {
 	pins = "mfio29", "mfio30";
 };
 
+For hardware where pin multiplexing configurations have to be specified for
+each single pin the number of required sub-nodes containing "pin" and
+"function" properties can quickly escalate and become hard to write and
+maintain.
+
+For cases like this, the pin controller driver may use the pinmux helper
+property, where the pin identifier is provided with mux configuration settings
+in a pinmux group. A pinmux group consists of the pin identifier and mux
+settings represented as a single integer or an array of integers.
+
+The pinmux property accepts an array of pinmux groups, each of them describing
+a single pin multiplexing configuration.
+
+pincontroller {
+	state_0_node_a {
+		pinmux = <PINMUX_GROUP>, <PINMUX_GROUP>, ...;
+	};
+};
+
+Each individual pin controller driver bindings documentation shall specify
+how pin IDs and pin multiplexing configuration are defined and assembled
+together in a pinmux group.
+
 == Generic pin configuration node content ==
 
 Many data items that are represented in a pin configuration node are common
@@ -168,12 +192,15 @@ structure of the DT nodes that contain these properties.
 Supported generic properties are:
 
 pins			- the list of pins that properties in the node
-			  apply to (either this or "group" has to be
+			  apply to (either this, "group" or "pinmux" has to be
 			  specified)
 group			- the group to apply the properties to, if the driver
 			  supports configuration of whole groups rather than
-			  individual pins (either this or "pins" has to be
-			  specified)
+			  individual pins (either this, "pins" or "pinmux" has
+			  to be specified)
+pinmux			- the list of numeric pin ids and their mux settings
+			  that properties in the node apply to (either this,
+			  "pins" or "groups" have to be specified)
 bias-disable		- disable any pin bias
 bias-high-impedance	- high impedance mode ("third-state", "floating")
 bias-bus-hold		- latch weakly
@@ -184,17 +211,30 @@ drive-push-pull		- drive actively high and low
 drive-open-drain	- drive with open drain
 drive-open-source	- drive with open source
 drive-strength		- sink or source at most X mA
-input-enable		- enable input on pin (no effect on output)
-input-disable		- disable input on pin (no effect on output)
+drive-strength-microamp	- sink or source at most X uA
+input-enable		- enable input on pin (no effect on output, such as
+			  enabling an input buffer)
+input-disable		- disable input on pin (no effect on output, such as
+			  disabling an input buffer)
 input-schmitt-enable	- enable schmitt-trigger mode
 input-schmitt-disable	- disable schmitt-trigger mode
 input-debounce		- debounce mode with debound time X
 power-source		- select between different power supplies
 low-power-enable	- enable low power mode
 low-power-disable	- disable low power mode
+output-disable		- disable output on a pin (such as disable an output
+			  buffer)
+output-enable		- enable output on a pin without actively driving it
+			  (such as enabling an output buffer)
 output-low		- set the pin to output mode with low level
 output-high		- set the pin to output mode with high level
+sleep-hardware-state	- indicate this is sleep related state which will be programmed
+			  into the registers for the sleep state.
 slew-rate		- set the slew rate
+skew-delay		- this affects the expected clock skew on input pins
+			  and the delay before latching a value to an output
+			  pin. Typically indicates how many double-inverters are
+			  used to delay the signal.
 
 For example:
 
@@ -216,6 +256,12 @@ state_2_node_a {
 		bias-pull-up;
 	};
 };
+state_3_node_a {
+	mux {
+		pinmux = <GPIOx_PINm_MUXn>, <GPIOx_PINj_MUXk)>;
+		input-enable;
+	};
+};
 
 Some of the generic properties take arguments. For those that do, the
 arguments are described below.
@@ -224,11 +270,18 @@ arguments are described below.
   binding for the hardware defines:
   - Whether the entries are integers or strings, and their meaning.
 
+- pinmux takes a list of pin IDs and mux settings as required argument. The
+  specific bindings for the hardware defines:
+  - How pin IDs and mux settings are defined and assembled together in a single
+    integer or an array of integers.
+
 - bias-pull-up, -down and -pin-default take as optional argument on hardware
   supporting it the pull strength in Ohm. bias-disable will disable the pull.
 
 - drive-strength takes as argument the target strength in mA.
 
+- drive-strength-microamp takes as argument the target strength in uA.
+
 - input-debounce takes the debounce time in usec as argument
   or 0 to disable debouncing
 
drivers/pinctrl/pinctrl-generic.c +96 -29

183 lines not on this page · raw message

include/dm/pinctrl.h +13 -8
index 692e5fc8cb..d50af1ce38 100644
@@ -34,29 +34,33 @@ struct pinconf_param {
  * depending on your necessity.
  *
  * @get_pins_count: return number of selectable named pins available
- *	in this driver.  (necessary to parse "pins" property in DTS)
+ *	in this driver. (necessary to parse "pins" property in DTS)
  * @get_pin_name: return the pin name of the pin selector,
  *	called by the core to figure out which pin it shall do
- *	operations to.  (necessary to parse "pins" property in DTS)
+ *	operations to. (necessary to parse "pins" property in DTS)
  * @get_groups_count: return number of selectable named groups available
- *	in this driver.  (necessary to parse "groups" property in DTS)
+ *	in this driver. (necessary to parse "groups" property in DTS)
  * @get_group_name: return the group name of the group selector,
  *	called by the core to figure out which pin group it shall do
- *	operations to.  (necessary to parse "groups" property in DTS)
+ *	operations to. (necessary to parse "groups" property in DTS)
  * @get_functions_count: return number of selectable named functions available
- *	in this driver.  (necessary for pin-muxing)
+ *	in this driver. (necessary for pin-muxing)
  * @get_function_name: return the function name of the muxing selector,
  *	called by the core to figure out which mux setting it shall map a
- *	certain device to.  (necessary for pin-muxing)
+ *	certain device to. (necessary for pin-muxing)
  * @pinmux_set: enable a certain muxing function with a certain pin.
  *	The @func_selector selects a certain function whereas @pin_selector
  *	selects a certain pin to be used. On simple controllers one of them
- *	may be ignored.  (necessary for pin-muxing against a single pin)
+ *	may be ignored. (necessary for pin-muxing against a single pin)
  * @pinmux_group_set: enable a certain muxing function with a certain pin
- *	group.  The @func_selector selects a certain function whereas
+ *	group. The @func_selector selects a certain function whereas
  *	@group_selector selects a certain set of pins to be used. On simple
  *	controllers one of them may be ignored.
  *	(necessary for pin-muxing against a pin group)
+ * @pinmux_property_set: enable a pinmux group. @pinmux_group should specify the
+ *      pin identifier and mux settings. The exact format of a pinmux group is
+ *      left up to the driver. The pin selector for the mux-ed pin should be
+ *      returned on success. (necessary to parse the "pinmux" property in DTS)
  * @pinconf_num_params: number of driver-specific parameters to be parsed
  *	from device trees  (necessary for pin-configuration)
  * @pinconf_params: list of driver_specific parameters to be parsed from
@@ -90,6 +94,7 @@ struct pinctrl_ops {
 			  unsigned func_selector);
 	int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
 				unsigned func_selector);
+	int (*pinmux_property_set)(struct udevice *dev, u32 pinmux_group);
 	unsigned int pinconf_num_params;
 	const struct pinconf_param *pinconf_params;
 	int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
Signature · 1 line
2.28.0
#2 lore raw

PATCH v5 2/11 pinctrl: Reformat documentation in dm/pinctrl.h

In reply to Sean Anderson

This normalizes the documentatation to conform to kernel-doc style [1]. It also moves the documentation for pinctrl_ops inline, and adds argument and return-value documentation. I have kept the usual function style for these comments. I could not find any existing examples of function documentation inside structs.

[1] https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html

---

(no changes since v4)

Changes in v4:
- New

 include/dm/pinctrl.h | 363 ++++++++++++++++++++++++++++---------------
 1 file changed, 242 insertions(+), 121 deletions(-)
include/dm/pinctrl.h +242 -121
index d50af1ce38..5b994f22cc 100644
@@ -11,11 +11,10 @@
 
 /**
  * struct pinconf_param - pin config parameters
- *
- * @property: property name in DT nodes
- * @param: ID for this config parameter
- * @default_value: default value for this config parameter used in case
- *	no value is specified in DT nodes
+ * @property:		Property name in DT nodes
+ * @param:		ID for this config parameter
+ * @default_value:	default value for this config parameter used in case
+ *			no value is specified in DT nodes
  */
 struct pinconf_param {
 	const char * const property;
@@ -27,111 +26,228 @@ struct pinconf_param {
  * struct pinctrl_ops - pin control operations, to be implemented by
  * pin controller drivers.
  *
- * The @set_state is the only mandatory operation.  You can implement your
- * pinctrl driver with its own @set_state.  In this case, the other callbacks
- * are not required.  Otherwise, generic pinctrl framework is also available;
- * use pinctrl_generic_set_state for @set_state, and implement other operations
+ * set_state() is the only mandatory operation. You can implement your pinctrl
+ * driver with its own @set_state. In this case, the other callbacks are not
+ * required. Otherwise, generic pinctrl framework is also available; use
+ * pinctrl_generic_set_state for @set_state, and implement other operations
  * depending on your necessity.
- *
- * @get_pins_count: return number of selectable named pins available
- *	in this driver. (necessary to parse "pins" property in DTS)
- * @get_pin_name: return the pin name of the pin selector,
- *	called by the core to figure out which pin it shall do
- *	operations to. (necessary to parse "pins" property in DTS)
- * @get_groups_count: return number of selectable named groups available
- *	in this driver. (necessary to parse "groups" property in DTS)
- * @get_group_name: return the group name of the group selector,
- *	called by the core to figure out which pin group it shall do
- *	operations to. (necessary to parse "groups" property in DTS)
- * @get_functions_count: return number of selectable named functions available
- *	in this driver. (necessary for pin-muxing)
- * @get_function_name: return the function name of the muxing selector,
- *	called by the core to figure out which mux setting it shall map a
- *	certain device to. (necessary for pin-muxing)
- * @pinmux_set: enable a certain muxing function with a certain pin.
- *	The @func_selector selects a certain function whereas @pin_selector
- *	selects a certain pin to be used. On simple controllers one of them
- *	may be ignored. (necessary for pin-muxing against a single pin)
- * @pinmux_group_set: enable a certain muxing function with a certain pin
- *	group. The @func_selector selects a certain function whereas
- *	@group_selector selects a certain set of pins to be used. On simple
- *	controllers one of them may be ignored.
- *	(necessary for pin-muxing against a pin group)
- * @pinmux_property_set: enable a pinmux group. @pinmux_group should specify the
- *      pin identifier and mux settings. The exact format of a pinmux group is
- *      left up to the driver. The pin selector for the mux-ed pin should be
- *      returned on success. (necessary to parse the "pinmux" property in DTS)
- * @pinconf_num_params: number of driver-specific parameters to be parsed
- *	from device trees  (necessary for pin-configuration)
- * @pinconf_params: list of driver_specific parameters to be parsed from
- *	device trees  (necessary for pin-configuration)
- * @pinconf_set: configure an individual pin with a given parameter.
- *	(necessary for pin-configuration against a single pin)
- * @pinconf_group_set: configure all pins in a group with a given parameter.
- *	(necessary for pin-configuration against a pin group)
- * @set_state: do pinctrl operations specified by @config, a pseudo device
- *	pointing a config node. (necessary for pinctrl_full)
- * @set_state_simple: do needed pinctrl operations for a peripherl @periph.
- *	(necessary for pinctrl_simple)
- * @get_pin_muxing: display the muxing of a given pin.
- * @gpio_request_enable: requests and enables GPIO on a certain pin.
- *	Implement this only if you can mux every pin individually as GPIO. The
- *	affected GPIO range is passed along with an offset(pin number) into that
- *	specific GPIO range - function selectors and pin groups are orthogonal
- *	to this, the core will however make sure the pins do not collide.
- * @gpio_disable_free: free up GPIO muxing on a certain pin, the reverse of
- *	@gpio_request_enable
  */
 struct pinctrl_ops {
+	/**
+	 * get_pins_count() - Get the number of selectable pins
+	 * @dev:	Pinctrl device to use
+	 *
+	 * This function is necessary to parse the "pins" property in DTS.
+	 *
+	 * Return: number of selectable named pins available in this driver
+	 */
 	int (*get_pins_count)(struct udevice *dev);
+
+	/**
+	 * get_pin_name() - Get the name of a pin
+	 * @dev:	Pinctrl device of the pin
+	 * @selector:	The pin selector
+	 *
+	 * This function is called by the core to figure out which pin it shall
+	 * do operations to. This function is necessary to parse the "pins"
+	 * property in DTS.
+	 *
+	 * Return: const pointer to the name of the pin
+	 */
 	const char *(*get_pin_name)(struct udevice *dev, unsigned selector);
+
+	/**
+	 * get_groups_count() - Get the number of selectable groups
+	 * @dev:	Pinctrl device to use
+	 *
+	 * This function is necessary to parse the "groups" property in DTS.
+	 *
+	 * Return: number of selectable named groups available in the driver
+	 */
 	int (*get_groups_count)(struct udevice *dev);
+
+	/**
+	 * get_group_name() - Get the name of a group
+	 * @dev:	Pinctrl device of the group
+	 * @selector:	The group selector
+	 *
+	 * This function is called by the core to figure out which group it
+	 * shall do operations to. This function is necessary to parse the
+	 * "groups" property in DTS.
+	 *
+	 * Return: const pointer to the name of the group
+	 */
 	const char *(*get_group_name)(struct udevice *dev, unsigned selector);
+
+	/**
+	 * get_functions_count() - Get the number of selectable functions
+	 * @dev:	Pinctrl device to use
+	 *
+	 * This function is necessary for pin-muxing.
+	 *
+	 * Return: number of selectable named functions available in this driver
+	 */
 	int (*get_functions_count)(struct udevice *dev);
+
+	/**
+	 * get_function_name() - Get the name of a function
+	 * @dev:	Pinmux device of the function
+	 * @selector:	The function selector
+	 *
+	 * This function is called by the core to figure out which mux setting
+	 * it shall map a certain device to. This function is necessary for
+	 * pin-muxing.
+	 *
+	 * Return: const pointer to the function name of the muxing selector
+	 */
 	const char *(*get_function_name)(struct udevice *dev,
 					 unsigned selector);
+
+	/**
+	 * pinmux_set() - Mux a pin to a function
+	 * @dev:		Pinctrl device to use
+	 * @pin_selector:	The pin selector
+	 * @func_selector:	The func selector
+	 *
+	 * On simple controllers one of @pin_selector or @func_selector may be
+	 * ignored. This function is necessary for pin-muxing against a single
+	 * pin.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*pinmux_set)(struct udevice *dev, unsigned pin_selector,
 			  unsigned func_selector);
+
+	/**
+	 * pinmux_set() - Mux a group of pins to a function
+	 * @dev:		Pinctrl device to use
+	 * @group_selector:	The group selector
+	 * @func_selector:	The func selector
+	 *
+	 * On simple controllers one of @group_selector or @func_selector may be
+	 * ignored. This function is necessary for pin-muxing against a group of
+	 * pins.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
 				unsigned func_selector);
+
+	/**
+	 * pinmux_property_set() - Enable a pinmux group
+	 * @dev:		Pinctrl device to use
+	 * @pinmux_group:	A u32 representing the pin identifier and mux
+	 *			settings. The exact format of a pinmux group is
+	 *			left up to the driver.
+	 *
+	 * Mux a single pin to a single function based on a driver-specific
+	 * pinmux group. This function is necessary for parsing the "pinmux"
+	 * property in DTS, and for pin-muxing against a pinmux group.
+	 *
+	 * Return: pin selector for the muxed pin if OK, or negative error code
+	 * on failure
+	 */
 	int (*pinmux_property_set)(struct udevice *dev, u32 pinmux_group);
+
+	/**
+	 * @pinconf_num_params:	Number of driver-specific parameters to be
+	 *			parsed from device trees. This member is
+	 *			necessary for pin configuration.
+	 */
 	unsigned int pinconf_num_params;
+
+	/**
+	 * @pinconf_params:	List of driver-specific parameters to be parsed
+	 *			from the device tree. This member is necessary
+	 *			for pin configuration.
+	 */
 	const struct pinconf_param *pinconf_params;
+
+	/**
+	 * pinconf_set() - configure an individual pin with a parameter
+	 * @dev:		Pinctrl device to use
+	 * @pin_selector:	The pin selector
+	 * @param:		A &enum pin_config_param from @pinconf_params
+	 * @argument:		The argument to this param from the device tree
+	 *
+	 * This function is necessary for pin configuration against a single
+	 * pin.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
 			   unsigned param, unsigned argument);
+
+	/**
+	 * pinconf_group_set() - configure all pins in a group with a parameter
+	 * @dev:		Pinctrl device to use
+	 * @pin_selector:	The group selector
+	 * @param:		A &enum pin_config_param from @pinconf_params
+	 * @argument:		The argument to this param from the device tree
+	 *
+	 * This function is necessary for pin configuration against a group of
+	 * pins.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
 				 unsigned param, unsigned argument);
+
+	/**
+	 * set_state() - Configure a pinctrl device
+	 * @dev:	Pinctrl device to use
+	 * @config:	Pseudo device pointing a config node
+	 *
+	 * This function is required to be implemented by all pinctrl drivers.
+	 * Drivers may set this member to pinctrl_generic_set_state(), which
+	 * will call other functions in &struct pinctrl_ops to parse @config.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*set_state)(struct udevice *dev, struct udevice *config);
 
-	/* for pinctrl-simple */
+	/**
+	 * set_state_simple() - Configure a pinctrl device
+	 * @dev:	Pinctrl device to use
+	 * @config:	Pseudo-device pointing a config node
+	 *
+	 * This function is usually a simpler version of set_state(). Only the
+	 * first pinctrl device on the system is supported by this function.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
+
 	/**
 	 * request() - Request a particular pinctrl function
+	 * @dev:	Device to adjust (UCLASS_PINCTRL)
+	 * @func:	Function number (driver-specific)
 	 *
 	 * This activates the selected function.
 	 *
-	 * @dev:	Device to adjust (UCLASS_PINCTRL)
-	 * @func:	Function number (driver-specific)
-	 * @return 0 if OK, -ve on error
+	 * Return: 0 if OK, or negative error code on failure
 	 */
 	int (*request)(struct udevice *dev, int func, int flags);
 
 	/**
 	* get_periph_id() - get the peripheral ID for a device
+	* @dev:		Pinctrl device to use for decoding
+	* @periph:	Device to check
 	*
 	* This generally looks at the peripheral's device tree node to work
 	* out the peripheral ID. The return value is normally interpreted as
 	* enum periph_id. so long as this is defined by the platform (which it
 	* should be).
 	*
-	* @dev:		Pinctrl device to use for decoding
-	* @periph:	Device to check
-	* @return peripheral ID of @periph, or -ENOENT on error
+	* Return: peripheral ID of @periph, or -ENOENT on error
 	*/
 	int (*get_periph_id)(struct udevice *dev, struct udevice *periph);
 
 	/**
 	 * get_gpio_mux() - get the mux value for a particular GPIO
+	 * @dev:	Pinctrl device to use
+	 * @banknum:	GPIO bank number
+	 * @index:	GPIO index within the bank
 	 *
 	 * This allows the raw mux value for a GPIO to be obtained. It is
 	 * useful for displaying the function being used by that GPIO, such
@@ -139,46 +255,50 @@ struct pinctrl_ops {
 	 * subsystem and should not be used by generic code. Typically it is
 	 * used by a GPIO driver with knowledge of the SoC pinctrl setup.
 	 *
-	* @dev:		Pinctrl device to use
-	* @banknum:	GPIO bank number
-	* @index:	GPIO index within the bank
-	* @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
+	 * Return: mux value (SoC-specific, e.g. 0 for input, 1 for output)
 	 */
 	int (*get_gpio_mux)(struct udevice *dev, int banknum, int index);
 
 	/**
 	 * get_pin_muxing() - show pin muxing
-	 *
-	 * This allows to display the muxing of a given pin. It's useful for
-	 * debug purpose to know if a pin is configured as GPIO or as an
-	 * alternate function and which one.
-	 * Typically it is used by a PINCTRL driver with knowledge of the SoC
-	 * pinctrl setup.
-	 *
 	 * @dev:	Pinctrl device to use
 	 * @selector:	Pin selector
 	 * @buf		Pin's muxing description
 	 * @size	Pin's muxing description length
-	 * return 0 if OK, -ve on error
+	 *
+	 * This allows to display the muxing of a given pin. It's useful for
+	 * debug purposes to know if a pin is configured as GPIO or as an
+	 * alternate function and which one. Typically it is used by a PINCTRL
+	 * driver with knowledge of the SoC pinctrl setup.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
 	 */
 	 int (*get_pin_muxing)(struct udevice *dev, unsigned int selector,
 			       char *buf, int size);
 
 	/**
-	 * gpio_request_enable: requests and enables GPIO on a certain pin.
-	 *
+	 * gpio_request_enable() - request and enable GPIO on a certain pin.
 	 * @dev:	Pinctrl device to use
 	 * @selector:	Pin selector
-	 * return 0 if OK, -ve on error
+	 *
+	 * Implement this only if you can mux every pin individually as GPIO.
+	 * The affected GPIO range is passed along with an offset(pin number)
+	 * into that specific GPIO range - function selectors and pin groups are
+	 * orthogonal to this, the core will however make sure the pins do not
+	 * collide.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
 	 */
 	int (*gpio_request_enable)(struct udevice *dev, unsigned int selector);
 
 	/**
-	 * gpio_disable_free: free up GPIO muxing on a certain pin.
-	 *
+	 * gpio_disable_free() - free up GPIO muxing on a certain pin.
 	 * @dev:	Pinctrl device to use
 	 * @selector:	Pin selector
-	 * return 0 if OK, -ve on error
+	 *
+	 * This function is the reverse of gpio_request_enable().
+	 *
+	 * Return: 0 if OK, or negative error code on failure
 	 */
 	int (*gpio_disable_free)(struct udevice *dev, unsigned int selector);
 };
@@ -230,8 +350,8 @@ struct pinctrl_ops {
  *	push-pull mode, the argument is ignored.
  * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
  *	passed as argument. The argument is in mA.
- * @PIN_CONFIG_DRIVE_STRENGTH_UA: the pin will sink or source at most the current
- *	passed as argument. The argument is in uA.
+ * @PIN_CONFIG_DRIVE_STRENGTH_UA: the pin will sink or source at most the
+ *	current passed as argument. The argument is in uA.
  * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
  *	which means it will wait for signals to settle when reading inputs. The
  *	argument gives the debounce time in usecs. Setting the
@@ -307,12 +427,13 @@ enum pin_config_param {
 #if CONFIG_IS_ENABLED(PINCTRL_GENERIC)
 /**
  * pinctrl_generic_set_state() - generic set_state operation
+ * @pctldev:	Pinctrl device to use
+ * @config:	Config device (pseudo device), pointing a config node in DTS
+ *
  * Parse the DT node of @config and its children and handle generic properties
  * such as "pins", "groups", "functions", and pin configuration parameters.
  *
- * @pctldev: pinctrl device
- * @config: config device (pseudo device), pointing a config node in DTS
- * @return: 0 on success, or negative error code on failure
+ * Return: 0 on success, or negative error code on failure
  */
 int pinctrl_generic_set_state(struct udevice *pctldev, struct udevice *config);
 #else
@@ -326,10 +447,10 @@ static inline int pinctrl_generic_set_state(struct udevice *pctldev,
 #if CONFIG_IS_ENABLED(PINCTRL)
 /**
  * pinctrl_select_state() - set a device to a given state
+ * @dev:	Peripheral device
+ * @statename:	State name, like "default"
  *
- * @dev: peripheral device
- * @statename: state name, like "default"
- * @return: 0 on success, or negative error code on failure
+ * Return: 0 on success, or negative error code on failure
  */
 int pinctrl_select_state(struct udevice *dev, const char *statename);
 #else
@@ -342,40 +463,43 @@ static inline int pinctrl_select_state(struct udevice *dev,
 
 /**
  * pinctrl_request() - Request a particular pinctrl function
- *
- * @dev:	Device to check (UCLASS_PINCTRL)
+ * @dev:	Pinctrl device to use
  * @func:	Function number (driver-specific)
  * @flags:	Flags (driver-specific)
- * @return 0 if OK, -ve on error
+ *
+ * Return: 0 if OK, or negative error code on failure
  */
 int pinctrl_request(struct udevice *dev, int func, int flags);
 
 /**
  * pinctrl_request_noflags() - Request a particular pinctrl function
+ * @dev:	Pinctrl device to use
+ * @func:	Function number (driver-specific)
  *
  * This is similar to pinctrl_request() but uses 0 for @flags.
  *
- * @dev:	Device to check (UCLASS_PINCTRL)
- * @func:	Function number (driver-specific)
- * @return 0 if OK, -ve on error
+ * Return: 0 if OK, or negative error code on failure
  */
 int pinctrl_request_noflags(struct udevice *dev, int func);
 
 /**
  * pinctrl_get_periph_id() - get the peripheral ID for a device
+ * @dev:	Pinctrl device to use for decoding
+ * @periph:	Device to check
  *
  * This generally looks at the peripheral's device tree node to work out the
  * peripheral ID. The return value is normally interpreted as enum periph_id.
  * so long as this is defined by the platform (which it should be).
  *
- * @dev:	Pinctrl device to use for decoding
- * @periph:	Device to check
- * @return peripheral ID of @periph, or -ENOENT on error
+ * Return: peripheral ID of @periph, or -ENOENT on error
  */
 int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
 
 /**
  * pinctrl_get_gpio_mux() - get the mux value for a particular GPIO
+ * @dev:	Pinctrl device to use
+ * @banknum:	GPIO bank number
+ * @index:	GPIO index within the bank
  *
  * This allows the raw mux value for a GPIO to be obtained. It is
  * useful for displaying the function being used by that GPIO, such
@@ -383,66 +507,63 @@ int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
  * subsystem and should not be used by generic code. Typically it is
  * used by a GPIO driver with knowledge of the SoC pinctrl setup.
  *
- * @dev:	Pinctrl device to use
- * @banknum:	GPIO bank number
- * @index:	GPIO index within the bank
- * @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
+ * Return: mux value (SoC-specific, e.g. 0 for input, 1 for output)
 */
 int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index);
 
 /**
  * pinctrl_get_pin_muxing() - Returns the muxing description
+ * @dev:	Pinctrl device to use
+ * @selector:	Pin index within pin-controller
+ * @buf:	Pin's muxing description
+ * @size:	Pin's muxing description length
  *
  * This allows to display the muxing description of the given pin for
  * debug purpose
  *
- * @dev:	Pinctrl device to use
- * @selector	Pin index within pin-controller
- * @buf		Pin's muxing description
- * @size	Pin's muxing description length
- * @return 0 if OK, -ve on error
+ * Return: 0 if OK, or negative error code on failure
  */
 int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf,
 			   int size);
 
 /**
  * pinctrl_get_pins_count() - display pin-controller pins number
+ * @dev:	Pinctrl device to use
  *
  * This allows to know the number of pins owned by a given pin-controller
  *
- * @dev:	Pinctrl device to use
- * @return pins number if OK, -ve on error
+ * Return: number of pins if OK, or negative error code on failure
  */
 int pinctrl_get_pins_count(struct udevice *dev);
 
 /**
  * pinctrl_get_pin_name() - Returns the pin's name
+ * @dev:	Pinctrl device to use
+ * @selector:	Pin index within pin-controller
+ * @buf:	Pin's name
  *
  * This allows to display the pin's name for debug purpose
  *
- * @dev:	Pinctrl device to use
- * @selector	Pin index within pin-controller
- * @buf		Pin's name
- * @return 0 if OK, -ve on error
+ * Return: 0 if OK, or negative error code on failure
  */
 int pinctrl_get_pin_name(struct udevice *dev, int selector, char *buf,
 			 int size);
 
 /**
  * pinctrl_gpio_request() - request a single pin to be used as GPIO
+ * @dev:	GPIO peripheral device
+ * @offset:	GPIO pin offset from the GPIO controller
  *
- * @dev: GPIO peripheral device
- * @offset: the GPIO pin offset from the GPIO controller
- * @return: 0 on success, or negative error code on failure
+ * Return: 0 on success, or negative error code on failure
  */
 int pinctrl_gpio_request(struct udevice *dev, unsigned offset);
 
 /**
  * pinctrl_gpio_free() - free a single pin used as GPIO
+ * @dev:	GPIO peripheral device
+ * @offset:	GPIO pin offset from the GPIO controller
  *
- * @dev: GPIO peripheral device
- * @offset: the GPIO pin offset from the GPIO controller
- * @return: 0 on success, or negative error code on failure
+ * Return: 0 on success, or negative error code on failure
  */
 int pinctrl_gpio_free(struct udevice *dev, unsigned offset);
 
Signature · 1 line
2.28.0
#3 lore raw

PATCH v5 2/11 pinctrl: Reformat documentation in dm/pinctrl.h

Quoted 1 line · Sean Anderson

This normalizes the documentatation to conform to kernel-doc style [1]. It

Nits:
%s/documentatation/documentation/

Quoted 9 lines

also moves the documentation for pinctrl_ops inline, and adds argument and return-value documentation. I have kept the usual function style for these comments. I could not find any existing examples of function documentation inside structs.

[1] https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html

Before and after this patch the documentation format is incorrect. See output below for the situation after the patch.

Please include include/dm/pinctrl.h into doc/api/index.rst via a new file doc/api/pnctrl.rst.

A documentation style accepted by 'make htmldocs' is:

struct pinctrl_ops {
??? /**
???? * @get_pins_count:?????????? Get the number of selectable pins ???? *
???? * @get_pins_count.dev:?????? Pinctrl device to use ???? *
???? * This function is necessary to parse the "pins" property
* in DTS.
???? *
???? * @get_pins_count.Return:??? number of selectable named pins ???? *??????????????????????????? available in this driver ???? */

    int (*get_pins_count)(struct udevice *dev);

See the nested structures in

https://www.kernel.org/doc/html/v5.7/doc-guide/kernel-doc.html#in-line-member-documentation-comments
and
https://www.kernel.org/doc/html/v5.7/doc-guide/kernel-doc.html#nested-structs-unions

The generated doc looks like this:

Members
get_pins_count
Get the number of selectable pins get_pins_count.dev: Pinctrl device to use
This function is necessary to parse the ?pins? property in DTS. get_pins_count.Return: number of selectable named pins
available in this driver

Best regards

Heinrich

./include/dm/pinctrl.h:38: warning: Incorrect use of kernel-doc format:
* get_pins_count() - Get the number of selectable pins

./include/dm/pinctrl.h:48: warning: Incorrect use of kernel-doc format:
* get_pin_name() - Get the name of a pin
./include/dm/pinctrl.h:61: warning: Incorrect use of kernel-doc format:
* get_groups_count() - Get the number of selectable groups
./include/dm/pinctrl.h:71: warning: Incorrect use of kernel-doc format:
* get_group_name() - Get the name of a group
./include/dm/pinctrl.h:84: warning: Incorrect use of kernel-doc format:
* get_functions_count() - Get the number of selectable functions
./include/dm/pinctrl.h:94: warning: Incorrect use of kernel-doc format:
* get_function_name() - Get the name of a function
./include/dm/pinctrl.h:108: warning: Incorrect use of kernel-doc format:
* pinmux_set() - Mux a pin to a function
./include/dm/pinctrl.h:123: warning: Incorrect use of kernel-doc format:
* pinmux_set() - Mux a group of pins to a function
./include/dm/pinctrl.h:138: warning: Incorrect use of kernel-doc format:
* pinmux_property_set() - Enable a pinmux group
./include/dm/pinctrl.h:168: warning: Incorrect use of kernel-doc format:
* pinconf_set() - configure an individual pin with a parameter
./include/dm/pinctrl.h:183: warning: Incorrect use of kernel-doc format:
* pinconf_group_set() - configure all pins in a group with a
parameter
./include/dm/pinctrl.h:198: warning: Incorrect use of kernel-doc format:
* set_state() - Configure a pinctrl device
./include/dm/pinctrl.h:211: warning: Incorrect use of kernel-doc format:
* set_state_simple() - Configure a pinctrl device
./include/dm/pinctrl.h:223: warning: Incorrect use of kernel-doc format:
* request() - Request a particular pinctrl function
./include/dm/pinctrl.h:234: warning: Incorrect use of kernel-doc format:
* get_periph_id() - get the peripheral ID for a device
./include/dm/pinctrl.h:248: warning: Incorrect use of kernel-doc format:
* get_gpio_mux() - get the mux value for a particular GPIO
./include/dm/pinctrl.h:264: warning: Incorrect use of kernel-doc format:
* get_pin_muxing() - show pin muxing
./include/dm/pinctrl.h:281: warning: Incorrect use of kernel-doc format:
* gpio_request_enable() - request and enable GPIO on a certain pin.
./include/dm/pinctrl.h:296: warning: Incorrect use of kernel-doc format:
* gpio_disable_free() - free up GPIO muxing on a certain pin.
./include/dm/pinctrl.h:305: warning: Function parameter or member 'get_pins_count' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'get_pin_name' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'get_groups_count' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'get_group_name' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'get_functions_count' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'get_function_name' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'pinmux_set' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'pinmux_group_set' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'pinmux_property_set' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'pinconf_set' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'pinconf_group_set' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'set_state' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'set_state_simple' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'request' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'get_periph_id' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'get_gpio_mux' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'get_pin_muxing' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'gpio_request_enable' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:305: warning: Function parameter or member 'gpio_disable_free' not described in 'pinctrl_ops' ./include/dm/pinctrl.h:401: warning: cannot understand function
prototype: 'enum pin_config_param '
./include/dm/pinctrl.h:551: warning: Function parameter or member 'size' not described in 'pinctrl_get_pin_name'

Quoted 569 lines

---

(no changes since v4)

Changes in v4:
- New

 include/dm/pinctrl.h | 363 ++++++++++++++++++++++++++++---------------
 1 file changed, 242 insertions(+), 121 deletions(-)
include/dm/pinctrl.h +242 -121
index d50af1ce38..5b994f22cc 100644
@@ -11,11 +11,10 @@
 
 /**
  * struct pinconf_param - pin config parameters
- *
- * @property: property name in DT nodes
- * @param: ID for this config parameter
- * @default_value: default value for this config parameter used in case
- *	no value is specified in DT nodes
+ * @property:		Property name in DT nodes
+ * @param:		ID for this config parameter
+ * @default_value:	default value for this config parameter used in case
+ *			no value is specified in DT nodes
  */
 struct pinconf_param {
 	const char * const property;
@@ -27,111 +26,228 @@ struct pinconf_param {
  * struct pinctrl_ops - pin control operations, to be implemented by
  * pin controller drivers.
  *
- * The @set_state is the only mandatory operation.  You can implement your
- * pinctrl driver with its own @set_state.  In this case, the other callbacks
- * are not required.  Otherwise, generic pinctrl framework is also available;
- * use pinctrl_generic_set_state for @set_state, and implement other operations
+ * set_state() is the only mandatory operation. You can implement your pinctrl
+ * driver with its own @set_state. In this case, the other callbacks are not
+ * required. Otherwise, generic pinctrl framework is also available; use
+ * pinctrl_generic_set_state for @set_state, and implement other operations
  * depending on your necessity.
- *
- * @get_pins_count: return number of selectable named pins available
- *	in this driver. (necessary to parse "pins" property in DTS)
- * @get_pin_name: return the pin name of the pin selector,
- *	called by the core to figure out which pin it shall do
- *	operations to. (necessary to parse "pins" property in DTS)
- * @get_groups_count: return number of selectable named groups available
- *	in this driver. (necessary to parse "groups" property in DTS)
- * @get_group_name: return the group name of the group selector,
- *	called by the core to figure out which pin group it shall do
- *	operations to. (necessary to parse "groups" property in DTS)
- * @get_functions_count: return number of selectable named functions available
- *	in this driver. (necessary for pin-muxing)
- * @get_function_name: return the function name of the muxing selector,
- *	called by the core to figure out which mux setting it shall map a
- *	certain device to. (necessary for pin-muxing)
- * @pinmux_set: enable a certain muxing function with a certain pin.
- *	The @func_selector selects a certain function whereas @pin_selector
- *	selects a certain pin to be used. On simple controllers one of them
- *	may be ignored. (necessary for pin-muxing against a single pin)
- * @pinmux_group_set: enable a certain muxing function with a certain pin
- *	group. The @func_selector selects a certain function whereas
- *	@group_selector selects a certain set of pins to be used. On simple
- *	controllers one of them may be ignored.
- *	(necessary for pin-muxing against a pin group)
- * @pinmux_property_set: enable a pinmux group. @pinmux_group should specify the
- *      pin identifier and mux settings. The exact format of a pinmux group is
- *      left up to the driver. The pin selector for the mux-ed pin should be
- *      returned on success. (necessary to parse the "pinmux" property in DTS)
- * @pinconf_num_params: number of driver-specific parameters to be parsed
- *	from device trees  (necessary for pin-configuration)
- * @pinconf_params: list of driver_specific parameters to be parsed from
- *	device trees  (necessary for pin-configuration)
- * @pinconf_set: configure an individual pin with a given parameter.
- *	(necessary for pin-configuration against a single pin)
- * @pinconf_group_set: configure all pins in a group with a given parameter.
- *	(necessary for pin-configuration against a pin group)
- * @set_state: do pinctrl operations specified by @config, a pseudo device
- *	pointing a config node. (necessary for pinctrl_full)
- * @set_state_simple: do needed pinctrl operations for a peripherl @periph.
- *	(necessary for pinctrl_simple)
- * @get_pin_muxing: display the muxing of a given pin.
- * @gpio_request_enable: requests and enables GPIO on a certain pin.
- *	Implement this only if you can mux every pin individually as GPIO. The
- *	affected GPIO range is passed along with an offset(pin number) into that
- *	specific GPIO range - function selectors and pin groups are orthogonal
- *	to this, the core will however make sure the pins do not collide.
- * @gpio_disable_free: free up GPIO muxing on a certain pin, the reverse of
- *	@gpio_request_enable
  */
 struct pinctrl_ops {
+	/**
+	 * get_pins_count() - Get the number of selectable pins
+	 * @dev:	Pinctrl device to use
+	 *
+	 * This function is necessary to parse the "pins" property in DTS.
+	 *
+	 * Return: number of selectable named pins available in this driver
+	 */
 	int (*get_pins_count)(struct udevice *dev);
+
+	/**
+	 * get_pin_name() - Get the name of a pin
+	 * @dev:	Pinctrl device of the pin
+	 * @selector:	The pin selector
+	 *
+	 * This function is called by the core to figure out which pin it shall
+	 * do operations to. This function is necessary to parse the "pins"
+	 * property in DTS.
+	 *
+	 * Return: const pointer to the name of the pin
+	 */
 	const char *(*get_pin_name)(struct udevice *dev, unsigned selector);
+
+	/**
+	 * get_groups_count() - Get the number of selectable groups
+	 * @dev:	Pinctrl device to use
+	 *
+	 * This function is necessary to parse the "groups" property in DTS.
+	 *
+	 * Return: number of selectable named groups available in the driver
+	 */
 	int (*get_groups_count)(struct udevice *dev);
+
+	/**
+	 * get_group_name() - Get the name of a group
+	 * @dev:	Pinctrl device of the group
+	 * @selector:	The group selector
+	 *
+	 * This function is called by the core to figure out which group it
+	 * shall do operations to. This function is necessary to parse the
+	 * "groups" property in DTS.
+	 *
+	 * Return: const pointer to the name of the group
+	 */
 	const char *(*get_group_name)(struct udevice *dev, unsigned selector);
+
+	/**
+	 * get_functions_count() - Get the number of selectable functions
+	 * @dev:	Pinctrl device to use
+	 *
+	 * This function is necessary for pin-muxing.
+	 *
+	 * Return: number of selectable named functions available in this driver
+	 */
 	int (*get_functions_count)(struct udevice *dev);
+
+	/**
+	 * get_function_name() - Get the name of a function
+	 * @dev:	Pinmux device of the function
+	 * @selector:	The function selector
+	 *
+	 * This function is called by the core to figure out which mux setting
+	 * it shall map a certain device to. This function is necessary for
+	 * pin-muxing.
+	 *
+	 * Return: const pointer to the function name of the muxing selector
+	 */
 	const char *(*get_function_name)(struct udevice *dev,
 					 unsigned selector);
+
+	/**
+	 * pinmux_set() - Mux a pin to a function
+	 * @dev:		Pinctrl device to use
+	 * @pin_selector:	The pin selector
+	 * @func_selector:	The func selector
+	 *
+	 * On simple controllers one of @pin_selector or @func_selector may be
+	 * ignored. This function is necessary for pin-muxing against a single
+	 * pin.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*pinmux_set)(struct udevice *dev, unsigned pin_selector,
 			  unsigned func_selector);
+
+	/**
+	 * pinmux_set() - Mux a group of pins to a function
+	 * @dev:		Pinctrl device to use
+	 * @group_selector:	The group selector
+	 * @func_selector:	The func selector
+	 *
+	 * On simple controllers one of @group_selector or @func_selector may be
+	 * ignored. This function is necessary for pin-muxing against a group of
+	 * pins.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
 				unsigned func_selector);
+
+	/**
+	 * pinmux_property_set() - Enable a pinmux group
+	 * @dev:		Pinctrl device to use
+	 * @pinmux_group:	A u32 representing the pin identifier and mux
+	 *			settings. The exact format of a pinmux group is
+	 *			left up to the driver.
+	 *
+	 * Mux a single pin to a single function based on a driver-specific
+	 * pinmux group. This function is necessary for parsing the "pinmux"
+	 * property in DTS, and for pin-muxing against a pinmux group.
+	 *
+	 * Return: pin selector for the muxed pin if OK, or negative error code
+	 * on failure
+	 */
 	int (*pinmux_property_set)(struct udevice *dev, u32 pinmux_group);
+
+	/**
+	 * @pinconf_num_params:	Number of driver-specific parameters to be
+	 *			parsed from device trees. This member is
+	 *			necessary for pin configuration.
+	 */
 	unsigned int pinconf_num_params;
+
+	/**
+	 * @pinconf_params:	List of driver-specific parameters to be parsed
+	 *			from the device tree. This member is necessary
+	 *			for pin configuration.
+	 */
 	const struct pinconf_param *pinconf_params;
+
+	/**
+	 * pinconf_set() - configure an individual pin with a parameter
+	 * @dev:		Pinctrl device to use
+	 * @pin_selector:	The pin selector
+	 * @param:		A &enum pin_config_param from @pinconf_params
+	 * @argument:		The argument to this param from the device tree
+	 *
+	 * This function is necessary for pin configuration against a single
+	 * pin.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
 			   unsigned param, unsigned argument);
+
+	/**
+	 * pinconf_group_set() - configure all pins in a group with a parameter
+	 * @dev:		Pinctrl device to use
+	 * @pin_selector:	The group selector
+	 * @param:		A &enum pin_config_param from @pinconf_params
+	 * @argument:		The argument to this param from the device tree
+	 *
+	 * This function is necessary for pin configuration against a group of
+	 * pins.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
 				 unsigned param, unsigned argument);
+
+	/**
+	 * set_state() - Configure a pinctrl device
+	 * @dev:	Pinctrl device to use
+	 * @config:	Pseudo device pointing a config node
+	 *
+	 * This function is required to be implemented by all pinctrl drivers.
+	 * Drivers may set this member to pinctrl_generic_set_state(), which
+	 * will call other functions in &struct pinctrl_ops to parse @config.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*set_state)(struct udevice *dev, struct udevice *config);
 
-	/* for pinctrl-simple */
+	/**
+	 * set_state_simple() - Configure a pinctrl device
+	 * @dev:	Pinctrl device to use
+	 * @config:	Pseudo-device pointing a config node
+	 *
+	 * This function is usually a simpler version of set_state(). Only the
+	 * first pinctrl device on the system is supported by this function.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
+	 */
 	int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
+
 	/**
 	 * request() - Request a particular pinctrl function
+	 * @dev:	Device to adjust (UCLASS_PINCTRL)
+	 * @func:	Function number (driver-specific)
 	 *
 	 * This activates the selected function.
 	 *
-	 * @dev:	Device to adjust (UCLASS_PINCTRL)
-	 * @func:	Function number (driver-specific)
-	 * @return 0 if OK, -ve on error
+	 * Return: 0 if OK, or negative error code on failure
 	 */
 	int (*request)(struct udevice *dev, int func, int flags);
 
 	/**
 	* get_periph_id() - get the peripheral ID for a device
+	* @dev:		Pinctrl device to use for decoding
+	* @periph:	Device to check
 	*
 	* This generally looks at the peripheral's device tree node to work
 	* out the peripheral ID. The return value is normally interpreted as
 	* enum periph_id. so long as this is defined by the platform (which it
 	* should be).
 	*
-	* @dev:		Pinctrl device to use for decoding
-	* @periph:	Device to check
-	* @return peripheral ID of @periph, or -ENOENT on error
+	* Return: peripheral ID of @periph, or -ENOENT on error
 	*/
 	int (*get_periph_id)(struct udevice *dev, struct udevice *periph);
 
 	/**
 	 * get_gpio_mux() - get the mux value for a particular GPIO
+	 * @dev:	Pinctrl device to use
+	 * @banknum:	GPIO bank number
+	 * @index:	GPIO index within the bank
 	 *
 	 * This allows the raw mux value for a GPIO to be obtained. It is
 	 * useful for displaying the function being used by that GPIO, such
@@ -139,46 +255,50 @@ struct pinctrl_ops {
 	 * subsystem and should not be used by generic code. Typically it is
 	 * used by a GPIO driver with knowledge of the SoC pinctrl setup.
 	 *
-	* @dev:		Pinctrl device to use
-	* @banknum:	GPIO bank number
-	* @index:	GPIO index within the bank
-	* @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
+	 * Return: mux value (SoC-specific, e.g. 0 for input, 1 for output)
 	 */
 	int (*get_gpio_mux)(struct udevice *dev, int banknum, int index);
 
 	/**
 	 * get_pin_muxing() - show pin muxing
-	 *
-	 * This allows to display the muxing of a given pin. It's useful for
-	 * debug purpose to know if a pin is configured as GPIO or as an
-	 * alternate function and which one.
-	 * Typically it is used by a PINCTRL driver with knowledge of the SoC
-	 * pinctrl setup.
-	 *
 	 * @dev:	Pinctrl device to use
 	 * @selector:	Pin selector
 	 * @buf		Pin's muxing description
 	 * @size	Pin's muxing description length
-	 * return 0 if OK, -ve on error
+	 *
+	 * This allows to display the muxing of a given pin. It's useful for
+	 * debug purposes to know if a pin is configured as GPIO or as an
+	 * alternate function and which one. Typically it is used by a PINCTRL
+	 * driver with knowledge of the SoC pinctrl setup.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
 	 */
 	 int (*get_pin_muxing)(struct udevice *dev, unsigned int selector,
 			       char *buf, int size);
 
 	/**
-	 * gpio_request_enable: requests and enables GPIO on a certain pin.
-	 *
+	 * gpio_request_enable() - request and enable GPIO on a certain pin.
 	 * @dev:	Pinctrl device to use
 	 * @selector:	Pin selector
-	 * return 0 if OK, -ve on error
+	 *
+	 * Implement this only if you can mux every pin individually as GPIO.
+	 * The affected GPIO range is passed along with an offset(pin number)
+	 * into that specific GPIO range - function selectors and pin groups are
+	 * orthogonal to this, the core will however make sure the pins do not
+	 * collide.
+	 *
+	 * Return: 0 if OK, or negative error code on failure
 	 */
 	int (*gpio_request_enable)(struct udevice *dev, unsigned int selector);
 
 	/**
-	 * gpio_disable_free: free up GPIO muxing on a certain pin.
-	 *
+	 * gpio_disable_free() - free up GPIO muxing on a certain pin.
 	 * @dev:	Pinctrl device to use
 	 * @selector:	Pin selector
-	 * return 0 if OK, -ve on error
+	 *
+	 * This function is the reverse of gpio_request_enable().
+	 *
+	 * Return: 0 if OK, or negative error code on failure
 	 */
 	int (*gpio_disable_free)(struct udevice *dev, unsigned int selector);
 };
@@ -230,8 +350,8 @@ struct pinctrl_ops {
  *	push-pull mode, the argument is ignored.
  * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
  *	passed as argument. The argument is in mA.
- * @PIN_CONFIG_DRIVE_STRENGTH_UA: the pin will sink or source at most the current
- *	passed as argument. The argument is in uA.
+ * @PIN_CONFIG_DRIVE_STRENGTH_UA: the pin will sink or source at most the
+ *	current passed as argument. The argument is in uA.
  * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
  *	which means it will wait for signals to settle when reading inputs. The
  *	argument gives the debounce time in usecs. Setting the
@@ -307,12 +427,13 @@ enum pin_config_param {
 #if CONFIG_IS_ENABLED(PINCTRL_GENERIC)
 /**
  * pinctrl_generic_set_state() - generic set_state operation
+ * @pctldev:	Pinctrl device to use
+ * @config:	Config device (pseudo device), pointing a config node in DTS
+ *
  * Parse the DT node of @config and its children and handle generic properties
  * such as "pins", "groups", "functions", and pin configuration parameters.
  *
- * @pctldev: pinctrl device
- * @config: config device (pseudo device), pointing a config node in DTS
- * @return: 0 on success, or negative error code on failure
+ * Return: 0 on success, or negative error code on failure
  */
 int pinctrl_generic_set_state(struct udevice *pctldev, struct udevice *config);
 #else
@@ -326,10 +447,10 @@ static inline int pinctrl_generic_set_state(struct udevice *pctldev,
 #if CONFIG_IS_ENABLED(PINCTRL)
 /**
  * pinctrl_select_state() - set a device to a given state
+ * @dev:	Peripheral device
+ * @statename:	State name, like "default"
  *
- * @dev: peripheral device
- * @statename: state name, like "default"
- * @return: 0 on success, or negative error code on failure
+ * Return: 0 on success, or negative error code on failure
  */
 int pinctrl_select_state(struct udevice *dev, const char *statename);
 #else
@@ -342,40 +463,43 @@ static inline int pinctrl_select_state(struct udevice *dev,
 
 /**
  * pinctrl_request() - Request a particular pinctrl function
- *
- * @dev:	Device to check (UCLASS_PINCTRL)
+ * @dev:	Pinctrl device to use
  * @func:	Function number (driver-specific)
  * @flags:	Flags (driver-specific)
- * @return 0 if OK, -ve on error
+ *
+ * Return: 0 if OK, or negative error code on failure
  */
 int pinctrl_request(struct udevice *dev, int func, int flags);
 
 /**
  * pinctrl_request_noflags() - Request a particular pinctrl function
+ * @dev:	Pinctrl device to use
+ * @func:	Function number (driver-specific)
  *
  * This is similar to pinctrl_request() but uses 0 for @flags.
  *
- * @dev:	Device to check (UCLASS_PINCTRL)
- * @func:	Function number (driver-specific)
- * @return 0 if OK, -ve on error
+ * Return: 0 if OK, or negative error code on failure
  */
 int pinctrl_request_noflags(struct udevice *dev, int func);
 
 /**
  * pinctrl_get_periph_id() - get the peripheral ID for a device
+ * @dev:	Pinctrl device to use for decoding
+ * @periph:	Device to check
  *
  * This generally looks at the peripheral's device tree node to work out the
  * peripheral ID. The return value is normally interpreted as enum periph_id.
  * so long as this is defined by the platform (which it should be).
  *
- * @dev:	Pinctrl device to use for decoding
- * @periph:	Device to check
- * @return peripheral ID of @periph, or -ENOENT on error
+ * Return: peripheral ID of @periph, or -ENOENT on error
  */
 int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
 
 /**
  * pinctrl_get_gpio_mux() - get the mux value for a particular GPIO
+ * @dev:	Pinctrl device to use
+ * @banknum:	GPIO bank number
+ * @index:	GPIO index within the bank
  *
  * This allows the raw mux value for a GPIO to be obtained. It is
  * useful for displaying the function being used by that GPIO, such
@@ -383,66 +507,63 @@ int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
  * subsystem and should not be used by generic code. Typically it is
  * used by a GPIO driver with knowledge of the SoC pinctrl setup.
  *
- * @dev:	Pinctrl device to use
- * @banknum:	GPIO bank number
- * @index:	GPIO index within the bank
- * @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
+ * Return: mux value (SoC-specific, e.g. 0 for input, 1 for output)
 */
 int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index);
 
 /**
  * pinctrl_get_pin_muxing() - Returns the muxing description
+ * @dev:	Pinctrl device to use
+ * @selector:	Pin index within pin-controller
+ * @buf:	Pin's muxing description
+ * @size:	Pin's muxing description length
  *
  * This allows to display the muxing description of the given pin for
  * debug purpose
  *
- * @dev:	Pinctrl device to use
- * @selector	Pin index within pin-controller
- * @buf		Pin's muxing description
- * @size	Pin's muxing description length
- * @return 0 if OK, -ve on error
+ * Return: 0 if OK, or negative error code on failure
  */
 int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf,
 			   int size);
 
 /**
  * pinctrl_get_pins_count() - display pin-controller pins number
+ * @dev:	Pinctrl device to use
  *
  * This allows to know the number of pins owned by a given pin-controller
  *
- * @dev:	Pinctrl device to use
- * @return pins number if OK, -ve on error
+ * Return: number of pins if OK, or negative error code on failure
  */
 int pinctrl_get_pins_count(struct udevice *dev);
 
 /**
  * pinctrl_get_pin_name() - Returns the pin's name
+ * @dev:	Pinctrl device to use
+ * @selector:	Pin index within pin-controller
+ * @buf:	Pin's name
  *
  * This allows to display the pin's name for debug purpose
  *
- * @dev:	Pinctrl device to use
- * @selector	Pin index within pin-controller
- * @buf		Pin's name
- * @return 0 if OK, -ve on error
+ * Return: 0 if OK, or negative error code on failure
  */
 int pinctrl_get_pin_name(struct udevice *dev, int selector, char *buf,
 			 int size);
 
 /**
  * pinctrl_gpio_request() - request a single pin to be used as GPIO
+ * @dev:	GPIO peripheral device
+ * @offset:	GPIO pin offset from the GPIO controller
  *
- * @dev: GPIO peripheral device
- * @offset: the GPIO pin offset from the GPIO controller
- * @return: 0 on success, or negative error code on failure
+ * Return: 0 on success, or negative error code on failure
  */
 int pinctrl_gpio_request(struct udevice *dev, unsigned offset);
 
 /**
  * pinctrl_gpio_free() - free a single pin used as GPIO
+ * @dev:	GPIO peripheral device
+ * @offset:	GPIO pin offset from the GPIO controller
  *
- * @dev: GPIO peripheral device
- * @offset: the GPIO pin offset from the GPIO controller
- * @return: 0 on success, or negative error code on failure
+ * Return: 0 on success, or negative error code on failure
  */
 int pinctrl_gpio_free(struct udevice *dev, unsigned offset);
 
#4 lore raw

PATCH v5 2/11 pinctrl: Reformat documentation in dm/pinctrl.h

Quoted 39 lines · Heinrich Schuchardt
Quoted 1 line · Sean Anderson

This normalizes the documentatation to conform to kernel-doc style [1]. It

Nits:
%s/documentatation/documentation/

Quoted 9 lines

also moves the documentation for pinctrl_ops inline, and adds argument and return-value documentation. I have kept the usual function style for these comments. I could not find any existing examples of function documentation inside structs.

[1] https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html

Before and after this patch the documentation format is incorrect. See output below for the situation after the patch.

Please include include/dm/pinctrl.h into doc/api/index.rst via a new file doc/api/pnctrl.rst.

A documentation style accepted by 'make htmldocs' is:

struct pinctrl_ops {
/**
* @get_pins_count: Get the number of selectable pins
*
* @get_pins_count.dev: Pinctrl device to use
*
* This function is necessary to parse the "pins" property
* in DTS.
*
* @get_pins_count.Return: number of selectable named pins
* available in this driver
*/
int (*get_pins_count)(struct udevice *dev);

Quoted 5 lines

See the nested structures in

https://www.kernel.org/doc/html/v5.7/doc-guide/kernel-doc.html#in-line-member-documentation-comments
and
https://www.kernel.org/doc/html/v5.7/doc-guide/kernel-doc.html#nested-structs-unions

Thanks for suggesting those changes. This works better. As far as I can tell, fully-qualified members are only necessary when documenting nested structs at the top-level. When using in-line documentation, members are automatically nested. With that in mind, I am using the following format

/**
* @pinmux_property_set: Enable a pinmux group
*
* @dev: Pinctrl device to use
*
* @pinmux_group: A u32 representing the pin identifier and mux
* settings. The exact format of a pinmux group is left
* up to the driver.
*
* Mux a single pin to a single function based on a driver-specific
* pinmux group. This function is necessary for parsing the "pinmux"
* property in DTS, and for pin-muxing against a pinmux group. *
* @Return:
* Pin selector for the muxed pin if OK, or negative error code on
* failure
*/
int (*pinmux_property_set)(struct udevice *dev, u32 pinmux_group);

However, I am having some problems with multi-line descriptions. In the example above, the desciption for @pinmux_group has the first line bolded and the rest of the description is typeset as normal, but is indented. The generated html is

<dl class="docutils">
<dt><strong>pinmux_group</strong>: A u32 representing the pin identifier and mux</dt>
<dd>settings. The exact format of a pinmux group is left up to the driver.</dd>
</dl>

However, it should be something like

<p><strong>pinmux_group</strong>: A u32 representing the pin identifier and mux settings. The exact format of a pinmux group is left up to the driver.</p>

I have also tried an alternate style, as shown for @Return. However, this too generated the wrong html:

<dl class="last docutils"> <dt><strong>Return</strong>:</dt>
<dd>Pin selector for the muxed pin if OK, or negative error code on failure</dd>
</dl>

where it should generate something like

<p class="last"><strong>Return</strong>: Pin selector for the muxed pin if OK, or negative error code on failure</p>

Do you have any suggestions for generating the latter forms? My current work is at [1].

--Sean

[1] https://github.com/Forty-Bot/u-boot/commit/e835cf9552dc96438699806731a208b40daead7b

#5 lore raw

PATCH v5 2/11 pinctrl: Reformat documentation in dm/pinctrl.h

Quoted 71 lines · Sean Anderson
Quoted 39 lines · Heinrich Schuchardt
Quoted 1 line · Sean Anderson

This normalizes the documentatation to conform to kernel-doc style [1]. It

Nits:
%s/documentatation/documentation/

Quoted 9 lines

also moves the documentation for pinctrl_ops inline, and adds argument and return-value documentation. I have kept the usual function style for these comments. I could not find any existing examples of function documentation inside structs.

[1] https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html

Before and after this patch the documentation format is incorrect. See output below for the situation after the patch.

Please include include/dm/pinctrl.h into doc/api/index.rst via a new file doc/api/pnctrl.rst.

A documentation style accepted by 'make htmldocs' is:

struct pinctrl_ops {
/**
* @get_pins_count: Get the number of selectable pins
*
* @get_pins_count.dev: Pinctrl device to use
*
* This function is necessary to parse the "pins" property
* in DTS.
*
* @get_pins_count.Return: number of selectable named pins
* available in this driver
*/
int (*get_pins_count)(struct udevice *dev);

Quoted 5 lines

See the nested structures in

https://www.kernel.org/doc/html/v5.7/doc-guide/kernel-doc.html#in-line-member-documentation-comments
and
https://www.kernel.org/doc/html/v5.7/doc-guide/kernel-doc.html#nested-structs-unions

Thanks for suggesting those changes. This works better. As far as I can tell, fully-qualified members are only necessary when documenting nested structs at the top-level. When using in-line documentation, members are automatically nested. With that in mind, I am using the following format

/**
* @pinmux_property_set: Enable a pinmux group
*
* @dev: Pinctrl device to use
*
* @pinmux_group: A u32 representing the pin identifier and mux
* settings. The exact format of a pinmux group is left
* up to the driver.
*
* Mux a single pin to a single function based on a driver-specific
* pinmux group. This function is necessary for parsing the "pinmux"
* property in DTS, and for pin-muxing against a pinmux group. *
* @Return:
* Pin selector for the muxed pin if OK, or negative error code on
* failure
*/
int (*pinmux_property_set)(struct udevice *dev, u32 pinmux_group);

Quoted 4 lines

However, I am having some problems with multi-line descriptions. In the example above, the desciption for @pinmux_group has the first line bolded and the rest of the description is typeset as normal, but is indented. The generated html is

Use fully qualified names and you are fine.

Best regards

Heinrich

Quoted 35 lines

<dl class="docutils">
<dt><strong>pinmux_group</strong>: A u32 representing the pin identifier and mux</dt>
<dd>settings. The exact format of a pinmux group is left up to the driver.</dd>
</dl>

However, it should be something like

<p><strong>pinmux_group</strong>: A u32 representing the pin identifier and mux settings. The exact format of a pinmux group is left up to the driver.</p>

I have also tried an alternate style, as shown for @Return. However, this too generated the wrong html:

<dl class="last docutils"> <dt><strong>Return</strong>:</dt>
<dd>Pin selector for the muxed pin if OK, or negative error code on failure</dd>
</dl>

where it should generate something like

<p class="last"><strong>Return</strong>: Pin selector for the muxed pin if OK, or negative error code on failure</p>

Do you have any suggestions for generating the latter forms? My current work is at [1].

--Sean

[1] https://github.com/Forty-Bot/u-boot/commit/e835cf9552dc96438699806731a208b40daead7b

#6 lore raw

PATCH v5 2/11 pinctrl: Reformat documentation in dm/pinctrl.h

Quoted 72 lines · Heinrich Schuchardt
Quoted 71 lines · Sean Anderson
Quoted 39 lines · Heinrich Schuchardt
Quoted 1 line · Sean Anderson

This normalizes the documentatation to conform to kernel-doc style [1]. It

Nits:
%s/documentatation/documentation/

Quoted 9 lines

also moves the documentation for pinctrl_ops inline, and adds argument and return-value documentation. I have kept the usual function style for these comments. I could not find any existing examples of function documentation inside structs.

[1] https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html

Before and after this patch the documentation format is incorrect. See output below for the situation after the patch.

Please include include/dm/pinctrl.h into doc/api/index.rst via a new file doc/api/pnctrl.rst.

A documentation style accepted by 'make htmldocs' is:

struct pinctrl_ops {
/**
* @get_pins_count: Get the number of selectable pins
*
* @get_pins_count.dev: Pinctrl device to use
*
* This function is necessary to parse the "pins" property
* in DTS.
*
* @get_pins_count.Return: number of selectable named pins
* available in this driver
*/
int (*get_pins_count)(struct udevice *dev);

Quoted 5 lines

See the nested structures in

https://www.kernel.org/doc/html/v5.7/doc-guide/kernel-doc.html#in-line-member-documentation-comments
and
https://www.kernel.org/doc/html/v5.7/doc-guide/kernel-doc.html#nested-structs-unions

Thanks for suggesting those changes. This works better. As far as I can tell, fully-qualified members are only necessary when documenting nested structs at the top-level. When using in-line documentation, members are automatically nested. With that in mind, I am using the following format

/**
* @pinmux_property_set: Enable a pinmux group
*
* @dev: Pinctrl device to use
*
* @pinmux_group: A u32 representing the pin identifier and mux
* settings. The exact format of a pinmux group is left
* up to the driver.
*
* Mux a single pin to a single function based on a driver-specific
* pinmux group. This function is necessary for parsing the "pinmux"
* property in DTS, and for pin-muxing against a pinmux group. *
* @Return:
* Pin selector for the muxed pin if OK, or negative error code on
* failure
*/
int (*pinmux_property_set)(struct udevice *dev, u32 pinmux_group);

Quoted 6 lines
Quoted 4 lines

However, I am having some problems with multi-line descriptions. In the example above, the desciption for @pinmux_group has the first line bolded and the rest of the description is typeset as normal, but is indented. The generated html is

Use fully qualified names and you are fine.

I also experienced this issue when using fully-qualified names.

Quoted 41 lines

Best regards

Heinrich

Quoted 35 lines

<dl class="docutils">
<dt><strong>pinmux_group</strong>: A u32 representing the pin identifier and mux</dt>
<dd>settings. The exact format of a pinmux group is left up to the driver.</dd>
</dl>

However, it should be something like

<p><strong>pinmux_group</strong>: A u32 representing the pin identifier and mux settings. The exact format of a pinmux group is left up to the driver.</p>

I have also tried an alternate style, as shown for @Return. However, this too generated the wrong html:

<dl class="last docutils"> <dt><strong>Return</strong>:</dt>
<dd>Pin selector for the muxed pin if OK, or negative error code on failure</dd>
</dl>

where it should generate something like

<p class="last"><strong>Return</strong>: Pin selector for the muxed pin if OK, or negative error code on failure</p>

Do you have any suggestions for generating the latter forms? My current work is at [1].

--Sean

[1] https://github.com/Forty-Bot/u-boot/commit/e835cf9552dc96438699806731a208b40daead7b

#7 lore raw

PATCH v5 3/11 test: pinmux: Add test for pin muxing

In reply to Sean Anderson

This extends the pinctrl-sandbox driver to support pin muxing, and adds a test for that behaviour. The test is done in C and not python (like the existing tests for the pinctrl uclass) because it needs to call pinctrl_select_state. Another option could be to add a command that invokes pinctrl_select_state and then test everything in test/py/tests/test_pinmux.py.

The pinctrl-sandbox driver now mimics the way that many pinmux devices work. There are two groups of pins which are muxed together, as well as four pins which are muxed individually. I have tried to test all normal paths. However, very few error cases are explicitly checked for.

---

(no changes since v4)

Changes in v4:
- Add sandbox dt-binding headers to MAINTAINERS
- Add test/dm/pinmux.c to patch
- Move sandbox_* variables into a priv structure. This resets them to the default state every time we re-probe.

Changes in v3:
- Add dt-bindings/pinctrl/sandbox-pinmux.h to patch

Changes in v2:
- New

 MAINTAINERS                                  |   1 +
 arch/sandbox/dts/test.dts                    |  45 ++++-
 drivers/pinctrl/pinctrl-sandbox.c            | 186 ++++++++++++++-----
 include/dt-bindings/pinctrl/sandbox-pinmux.h |  19 ++
 test/dm/Makefile                             |   3 +
 test/dm/pinmux.c                             |  57 ++++++
 test/py/tests/test_pinmux.py                 |  36 ++--
 7 files changed, 274 insertions(+), 73 deletions(-)
 create mode 100644 include/dt-bindings/pinctrl/sandbox-pinmux.h
 create mode 100644 test/dm/pinmux.c
MAINTAINERS +1 -0
index 17ac45587b..24de698433 100644
@@ -953,6 +953,7 @@ SANDBOX
 M:	Simon Glass <[email protected]>
 S:	Maintained
 F:	arch/sandbox/
+F:	include/dt-bindings/*/sandbox*.h
 
 SH
 M:	Marek Vasut <[email protected]>
arch/sandbox/dts/test.dts +38 -7

74 lines not on this page · raw message

drivers/pinctrl/pinctrl-sandbox.c +138 -48

268 lines not on this page · raw message

include/dt-bindings/pinctrl/sandbox-pinmux.h new file +19 -0
new file mode 100644
index 0000000000..891af072e5
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 Sean Anderson <[email protected]>
+ */
+
+#ifndef SANDBOX_PINMUX_H
+#define SANDBOX_PINMUX_H
+
+#define SANDBOX_PINMUX_UART 0
+#define SANDBOX_PINMUX_I2C  1
+#define SANDBOX_PINMUX_SPI  2
+#define SANDBOX_PINMUX_I2S  3
+#define SANDBOX_PINMUX_GPIO 4
+#define SANDBOX_PINMUX_CS   5
+#define SANDBOX_PINMUX_PWM  6
+
+#define SANDBOX_PINMUX(pin, func) ((func) << 16 | (pin))
+
+#endif /* SANDBOX_PINMUX_H */
test/dm/Makefile +3 -0
index 864c8d0b4c..a5b8eac678 100644
@@ -80,4 +80,7 @@ obj-$(CONFIG_DM_RNG) += rng.o
 obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o
 obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o
 obj-$(CONFIG_RESET_SYSCON) += syscon-reset.o
+ifneq ($(CONFIG_PINMUX),)
+obj-$(CONFIG_PINCONF) += pinmux.o
+endif
 endif
test/dm/pinmux.c new file +57 -0

57 lines not on this page · raw message

test/py/tests/test_pinmux.py +18 -18
index 4e6df992a4..0cbbae000c 100644
@@ -28,15 +28,15 @@ def test_pinmux_status_all(u_boot_console):
     assert ('a6        : gpio output .' in output)
 
     assert ('pinctrl:' in output)
-    assert ('SCL       : I2C SCL.' in output)
-    assert ('SDA       : I2C SDA.' in output)
-    assert ('TX        : Uart TX.' in output)
-    assert ('RX        : Uart RX.' in output)
-    assert ('W1        : 1-wire gpio.' in output)
-    assert ('GPIO0     : gpio bias-pull-up input-disable.' in output)
-    assert ('GPIO1     : gpio drive-open-drain.' in output)
-    assert ('GPIO2     : gpio bias-pull-down input-enable.' in output)
-    assert ('GPIO3     : gpio bias-disable.' in output)
+    assert ('P0        : UART TX.' in output)
+    assert ('P1        : UART RX.' in output)
+    assert ('P2        : I2S SCK.' in output)
+    assert ('P3        : I2S SD.' in output)
+    assert ('P4        : I2S WS.' in output)
+    assert ('P5        : GPIO0 bias-pull-up input-disable.' in output)
+    assert ('P6        : GPIO1 drive-open-drain.' in output)
+    assert ('P7        : GPIO2 bias-pull-down input-enable.' in output)
+    assert ('P8        : GPIO3 bias-disable.' in output)
 
 @pytest.mark.buildconfigspec('cmd_pinmux')
 @pytest.mark.boardspec('sandbox')
@@ -73,12 +73,12 @@ def test_pinmux_status(u_boot_console):
     assert (not 'pinctrl-gpio:' in output)
     assert (not 'pinctrl:' in output)
 
-    assert ('SCL       : I2C SCL.' in output)
-    assert ('SDA       : I2C SDA.' in output)
-    assert ('TX        : Uart TX.' in output)
-    assert ('RX        : Uart RX.' in output)
-    assert ('W1        : 1-wire gpio.' in output)
-    assert ('GPIO0     : gpio bias-pull-up input-disable.' in output)
-    assert ('GPIO1     : gpio drive-open-drain.' in output)
-    assert ('GPIO2     : gpio bias-pull-down input-enable.' in output)
-    assert ('GPIO3     : gpio bias-disable.' in output)
+    assert ('P0        : UART TX.' in output)
+    assert ('P1        : UART RX.' in output)
+    assert ('P2        : I2S SCK.' in output)
+    assert ('P3        : I2S SD.' in output)
+    assert ('P4        : I2S WS.' in output)
+    assert ('P5        : GPIO0 bias-pull-up input-disable.' in output)
+    assert ('P6        : GPIO1 drive-open-drain.' in output)
+    assert ('P7        : GPIO2 bias-pull-down input-enable.' in output)
+    assert ('P8        : GPIO3 bias-disable.' in output)
Signature · 1 line
2.28.0
#8 lore raw

PATCH v5 4/11 pinctrl: Add support for Kendryte K210 FPIOA

In reply to Sean Anderson

The Fully-Programmable Input/Output Array (FPIOA) device controls pin multiplexing on the K210. The FPIOA can remap any supported function to any multifunctional IO pin. It can also perform basic GPIO functions, such as reading the current value of a pin. However, GPIO functionality remains largely unimplemented (in favor of the dedicated GPIO peripherals).

---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576

Changes from that version include:
- Reformat to reduce errors from checkpatch

(no changes since v2)

Changes in v2:
- Don't clear existing pinctrl settings on probe
- Rewrite to use pinmux property
- Support muxing the output enable signal for each function
- Support output and input inversion
- Update binding documentation

 MAINTAINERS                                   |   2 +
 .../pinctrl/kendryte,k210-fpioa.txt           | 102 +++
 drivers/pinctrl/Kconfig                       |   1 +
 drivers/pinctrl/Makefile                      |   1 +
 drivers/pinctrl/kendryte/Kconfig              |   7 +
 drivers/pinctrl/kendryte/Makefile             |   1 +
 drivers/pinctrl/kendryte/pinctrl.c            | 678 ++++++++++++++++++
 drivers/pinctrl/kendryte/pinctrl.h            |  70 ++
 include/dt-bindings/pinctrl/k210-pinctrl.h    | 277 +++++++
 9 files changed, 1139 insertions(+)
 create mode 100644 doc/device-tree-bindings/pinctrl/kendryte,k210-fpioa.txt
 create mode 100644 drivers/pinctrl/kendryte/Kconfig
 create mode 100644 drivers/pinctrl/kendryte/Makefile
 create mode 100644 drivers/pinctrl/kendryte/pinctrl.c
 create mode 100644 drivers/pinctrl/kendryte/pinctrl.h
 create mode 100644 include/dt-bindings/pinctrl/k210-pinctrl.h
MAINTAINERS +2 -0
index 24de698433..3abe52570f 100644
@@ -929,7 +929,9 @@ RISC-V KENDRYTE
 M:	Sean Anderson <[email protected]>
 S:	Maintained
 F:	doc/device-tree-bindings/mfd/kendryte,k210-sysctl.txt
+F:	doc/device-tree-bindings/pinctrl/kendryte,k210-fpioa.txt
 F:	drivers/clk/kendryte/
+F:	drivers/pinctrl/kendryte/
 F:	include/kendryte/
 
 RNG
doc/device-tree-bindings/pinctrl/kendryte,k210-fpioa.txt new file +102 -0

102 lines not on this page · raw message

drivers/pinctrl/Kconfig +1 -0
index cdbccfd285..7e208f573b 100644
@@ -289,6 +289,7 @@ endif
 source "drivers/pinctrl/broadcom/Kconfig"
 source "drivers/pinctrl/exynos/Kconfig"
 source "drivers/pinctrl/intel/Kconfig"
+source "drivers/pinctrl/kendryte/Kconfig"
 source "drivers/pinctrl/mediatek/Kconfig"
 source "drivers/pinctrl/meson/Kconfig"
 source "drivers/pinctrl/mscc/Kconfig"
drivers/pinctrl/Makefile +1 -0
index 92cff1b100..4c2b4236d1 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_PINCTRL_SANDBOX)	+= pinctrl-sandbox.o
 obj-$(CONFIG_PINCTRL_UNIPHIER)	+= uniphier/
 obj-$(CONFIG_PINCTRL_PIC32)	+= pinctrl_pic32.o
 obj-$(CONFIG_PINCTRL_EXYNOS)	+= exynos/
+obj-$(CONFIG_PINCTRL_K210)	+= kendryte/
 obj-$(CONFIG_PINCTRL_MESON)	+= meson/
 obj-$(CONFIG_PINCTRL_MTK)	+= mediatek/
 obj-$(CONFIG_PINCTRL_MSCC)	+= mscc/
drivers/pinctrl/kendryte/Kconfig new file +7 -0
new file mode 100644
index 0000000000..6fc10e9516
@@ -0,0 +1,7 @@
+config PINCTRL_K210
+	bool "Kendryte K210 Fully-Programmable Input/Output Array driver"
+	depends on DM && PINCTRL_GENERIC
+	help
+	  Support pin multiplexing on the K210. The "FPIOA" can remap any
+	  supported function to any multifunctional IO pin. It can also perform
+	  basic GPIO functions, such as reading the current value of a pin.
drivers/pinctrl/kendryte/Makefile new file +1 -0
new file mode 100644
index 0000000000..1c10d7a929
@@ -0,0 +1 @@
+obj-y += pinctrl.o
drivers/pinctrl/kendryte/pinctrl.c new file +678 -0

678 lines not on this page · raw message

drivers/pinctrl/kendryte/pinctrl.h new file +70 -0

70 lines not on this page · raw message

include/dt-bindings/pinctrl/k210-pinctrl.h new file +277 -0

277 lines not on this page · raw message

Signature · 1 line
2.28.0
#9 lore raw

PATCH v5 5/11 gpio: dw: Fix warnings about casting int to pointer

In reply to Sean Anderson

Change the type of gpio_dwabp_platdata.base from fdt_addr_t to a void pointer, since we pass it to readl.

---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576

(no changes since v1)

 drivers/gpio/dwapb_gpio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/dwapb_gpio.c +2 -2
index e5e3518194..bf324f5239 100644
@@ -40,7 +40,7 @@ struct gpio_dwapb_platdata {
 	const char	*name;
 	int		bank;
 	int		pins;
-	fdt_addr_t	base;
+	void __iomem	*base;
 };
 
 static int dwapb_gpio_direction_input(struct udevice *dev, unsigned pin)
@@ -176,7 +176,7 @@ static int gpio_dwapb_bind(struct udevice *dev)
 		if (!plat)
 			return -ENOMEM;
 
-		plat->base = base;
+		plat->base = (void *)base;
 		plat->bank = bank;
 		plat->pins = ofnode_read_u32_default(node, "snps,nr-gpios", 0);
 
Signature · 1 line
2.28.0
#10 lore raw

PATCH v5 6/11 gpio: dw: Add a trailing underscore to generated name

In reply to Sean Anderson

Previously, if there was no bank-name property, it was easy to have confusing gpio names like "gpio1 at 08", instead of "gpio1 at 0_8". This patch follows the example of the sifive gpio driver.

---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576

(no changes since v1)

 drivers/gpio/dwapb_gpio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +9 -1
index bf324f5239..a52c9e18e3 100644
@@ -186,7 +186,15 @@ static int gpio_dwapb_bind(struct udevice *dev)
 			 * Fall back to node name. This means accessing pins
 			 * via bank name won't work.
 			 */
-			plat->name = ofnode_get_name(node);
+			char name[32];
+
+			snprintf(name, sizeof(name), "%s_",
+				 ofnode_get_name(node));
+			plat->name = strdup(name);
+			if (!plat->name) {
+				kfree(plat);
+				return -ENOMEM;
+			}
 		}
 
 		ret = device_bind_ofnode(dev, dev->driver, plat->name,
Signature · 1 line
2.28.0
#11 lore raw

PATCH v5 7/11 gpio: dw: Return output value when direction is out

In reply to Sean Anderson

dm_gpio_ops.get_value can be called when the gpio is either input or output. The current dw code always returns the input value, which is invalid if the direction is set to out.

---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576

(no changes since v3)

Changes in v3:
- Undo reorder to prevent use-before-declared error

Changes in v2:
- Reorder changes to minimize diff

 drivers/gpio/dwapb_gpio.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/gpio/dwapb_gpio.c +12 -7
index a52c9e18e3..37916e7771 100644
@@ -66,13 +66,6 @@ static int dwapb_gpio_direction_output(struct udevice *dev, unsigned pin,
 	return 0;
 }
 
-static int dwapb_gpio_get_value(struct udevice *dev, unsigned pin)
-{
-	struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
-	return !!(readl(plat->base + GPIO_EXT_PORT(plat->bank)) & (1 << pin));
-}
-
-
 static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val)
 {
 	struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
@@ -98,6 +91,18 @@ static int dwapb_gpio_get_function(struct udevice *dev, unsigned offset)
 		return GPIOF_INPUT;
 }
 
+static int dwapb_gpio_get_value(struct udevice *dev, unsigned pin)
+{
+	struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
+	u32 value;
+
+	if (dwapb_gpio_get_function(dev, pin) == GPIOF_OUTPUT)
+		value = readl(plat->base + GPIO_SWPORT_DR(plat->bank));
+	else
+		value = readl(plat->base + GPIO_EXT_PORT(plat->bank));
+	return !!(value & BIT(pin));
+}
+
 static const struct dm_gpio_ops gpio_dwapb_ops = {
 	.direction_input	= dwapb_gpio_direction_input,
 	.direction_output	= dwapb_gpio_direction_output,
Signature · 1 line
2.28.0
#12 lore raw

PATCH v5 8/11 led: gpio: Default to using node name if label is absent

In reply to Sean Anderson

This more closely mirrors Linux's behaviour, and will make it easier to transition to using function+color in the future.

---
This patch was previously submitted as part of
https://patchwork.ozlabs.org/project/uboot/list/?series=161576

(no changes since v1)

 drivers/led/led_gpio.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/led/led_gpio.c +2 -5
index ef9b61ee62..2cdb0269f4 100644
@@ -99,11 +99,8 @@ static int led_gpio_bind(struct udevice *parent)
 		const char *label;
 
 		label = ofnode_read_string(node, "label");
-		if (!label) {
-			debug("%s: node %s has no label\n", __func__,
-			      ofnode_get_name(node));
-			return -EINVAL;
-		}
+		if (!label)
+			label = ofnode_get_name(node);
 		ret = device_bind_driver_to_node(parent, "gpio_led",
 						 ofnode_get_name(node),
 						 node, &dev);
Signature · 1 line
2.28.0
#13 lore raw

PATCH v5 9/11 test: dm: Test for default led naming

In reply to Sean Anderson

This modifies the existing led test to check for default led naming as added in the previous patch.

---

(no changes since v4)

Changes in v4:
- New

 arch/sandbox/dts/test.dts | 2 +-
 test/dm/led.c             | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
arch/sandbox/dts/test.dts +1 -1
index 0255c97cf5..a0a57143f0 100644
@@ -503,7 +503,7 @@
 
 		default_off {
 			gpios = <&gpio_a 6 0>;
-			label = "sandbox:default_off";
+			/* label intentionally omitted */
 			default-state = "off";
 		};
 	};
test/dm/led.c +2 -1
index 8b587d0a22..ac6ee36394 100644
@@ -40,7 +40,8 @@ static int dm_test_led_default_state(struct unit_test_state *uts)
 	ut_assertok(led_get_by_label("sandbox:default_on", &dev));
 	ut_asserteq(LEDST_ON, led_get_state(dev));
 
-	ut_assertok(led_get_by_label("sandbox:default_off", &dev));
+	/* Also tests default label behaviour */
+	ut_assertok(led_get_by_label("default_off", &dev));
 	ut_asserteq(LEDST_OFF, led_get_state(dev));
 
 	return 0;
Signature · 1 line
2.28.0
#14 lore raw

PATCH v5 10/11 riscv: Add pinmux and gpio bindings for Kendryte K210

In reply to Sean Anderson

This patch adds the necessary device tree bindings.

---

(no changes since v2)

Changes in v2:
- Convert to use pinmux property
- Don't hog ISP on boot
- Re-order GPIOs to match the defaults more closely

 arch/riscv/dts/k210-maix-bit.dts | 104 +++++++++++++++++++++++++++++++
 arch/riscv/dts/k210.dtsi         |  12 ++++
 2 files changed, 116 insertions(+)
arch/riscv/dts/k210-maix-bit.dts +104 -0
index 5b32c5fd5f..e840e04ada 100644
@@ -17,6 +17,22 @@
 		stdout-path = "serial0:115200";
 	};
 
+	gpio-leds {
+		compatible = "gpio-leds";
+
+		green {
+			gpios = <&gpio1_0 4 GPIO_ACTIVE_LOW>;
+		};
+
+		red {
+			gpios = <&gpio1_0 5 GPIO_ACTIVE_LOW>;
+		};
+
+		blue {
+			gpios = <&gpio1_0 6 GPIO_ACTIVE_LOW>;
+		};
+	};
+
 	sound {
 		compatible = "simple-audio-card";
 		simple-audio-card,format = "i2s";
@@ -39,9 +55,97 @@
 };
 
 &uarths0 {
+	pinctrl-0 = <&fpioa_uarths>;
+	pinctrl-names = "default";
+	status = "okay";
+};
+
+&gpio0 {
+	pinctrl-0 = <&fpioa_gpiohs>;
+	pinctrl-names = "default";
+	status = "okay";
+};
+
+&gpio1 {
+	pinctrl-0 = <&fpioa_gpio>;
+	pinctrl-names = "default";
 	status = "okay";
 };
 
 &i2s0 {
 	#sound-dai-cells = <1>;
+	pinctrl-0 = <&fpioa_i2s0>;
+	pinctrl-names = "default";
+};
+
+&fpioa {
+	status = "okay";
+
+	fpioa_uarths: uarths {
+		pinmux = <K210_FPIOA(4, K210_PCF_UARTHS_RX)>,
+			 <K210_FPIOA(5, K210_PCF_UARTHS_TX)>;
+	};
+
+	fpioa_gpio: gpio {
+		pinmux = <K210_FPIOA(8, K210_PCF_GPIO0)>,
+			 <K210_FPIOA(9, K210_PCF_GPIO1)>,
+			 <K210_FPIOA(10, K210_PCF_GPIO2)>,
+			 <K210_FPIOA(11, K210_PCF_GPIO3)>,
+			 <K210_FPIOA(12, K210_PCF_GPIO4)>,
+			 <K210_FPIOA(13, K210_PCF_GPIO5)>,
+			 <K210_FPIOA(14, K210_PCF_GPIO6)>,
+			 <K210_FPIOA(15, K210_PCF_GPIO7)>;
+	};
+
+	fpioa_gpiohs: gpiohs {
+		pinmux = <K210_FPIOA(16, K210_PCF_GPIOHS0)>,
+			 <K210_FPIOA(17, K210_PCF_GPIOHS1)>,
+			 <K210_FPIOA(21, K210_PCF_GPIOHS5)>,
+			 <K210_FPIOA(22, K210_PCF_GPIOHS6)>,
+			 <K210_FPIOA(23, K210_PCF_GPIOHS7)>,
+			 <K210_FPIOA(24, K210_PCF_GPIOHS8)>,
+			 <K210_FPIOA(25, K210_PCF_GPIOHS9)>,
+			 <K210_FPIOA(30, K210_PCF_GPIOHS14)>,
+			 <K210_FPIOA(31, K210_PCF_GPIOHS15)>,
+			 <K210_FPIOA(32, K210_PCF_GPIOHS16)>,
+			 <K210_FPIOA(33, K210_PCF_GPIOHS17)>,
+			 <K210_FPIOA(34, K210_PCF_GPIOHS18)>,
+			 <K210_FPIOA(35, K210_PCF_GPIOHS19)>;
+	};
+
+	fpioa_i2s0: i2s0 {
+		pinmux = <K210_FPIOA(18, K210_PCF_I2S0_SCLK)>,
+			 <K210_FPIOA(19, K210_PCF_I2S0_WS)>,
+			 <K210_FPIOA(20, K210_PCF_I2S0_IN_D0)>;
+	};
+
+	fpioa_dvp: dvp {
+		pinmux = <K210_FPIOA(40, K210_PCF_SCCB_SDA)>,
+			 <K210_FPIOA(41, K210_PCF_SCCB_SCLK)>,
+			 <K210_FPIOA(42, K210_PCF_DVP_RST)>,
+			 <K210_FPIOA(43, K210_PCF_DVP_VSYNC)>,
+			 <K210_FPIOA(44, K210_PCF_DVP_PWDN)>,
+			 <K210_FPIOA(45, K210_PCF_DVP_HSYNC)>,
+			 <K210_FPIOA(46, K210_PCF_DVP_XCLK)>,
+			 <K210_FPIOA(47, K210_PCF_DVP_PCLK)>;
+	};
+
+	fpioa_spi0: spi0 {
+		pinmux = <K210_FPIOA(36, K210_PCF_GPIOHS20)>,  /* cs */
+			 <K210_FPIOA(37, K210_PCF_GPIOHS21)>,  /* rst */
+			 <K210_FPIOA(38, K210_PCF_GPIOHS22)>,  /* dc */
+			 <K210_FPIOA(39, K210_PCF_SPI0_SCLK)>; /* wr */
+	};
+
+	fpioa_spi1: spi1 {
+		pinmux = <K210_FPIOA(26, K210_PCF_SPI1_D1)>,
+			 <K210_FPIOA(27, K210_PCF_SPI1_SCLK)>,
+			 <K210_FPIOA(28, K210_PCF_SPI1_D0)>,
+			 <K210_FPIOA(29, K210_PCF_GPIOHS13)>;
+	};
+};
+
+&dvp0 {
+	pinctrl-0 = <&fpioa_dvp>;
+	pinctrl-names = "default";
 };
arch/riscv/dts/k210.dtsi +12 -0
index 2546c7d4e0..fc7986b326 100644
@@ -5,6 +5,7 @@
 
 #include <dt-bindings/clock/k210-sysctl.h>
 #include <dt-bindings/mfd/k210-sysctl.h>
+#include <dt-bindings/pinctrl/k210-pinctrl.h>
 #include <dt-bindings/reset/k210-sysctl.h>
 
 / {
@@ -367,7 +368,18 @@
 				reg = <0x502B0000 0x100>;
 				clocks = <&sysclk K210_CLK_FPIOA>;
 				resets = <&sysrst K210_RST_FPIOA>;
+				kendryte,sysctl = <&sysctl>;
+				kendryte,power-offset = <K210_SYSCTL_POWER_SEL>;
+				pinctrl-0 = <&fpioa_jtag>;
+				pinctrl-names = "default";
 				status = "disabled";
+
+				fpioa_jtag: jtag {
+					pinmux = <K210_FPIOA(0, K210_PCF_JTAG_TCLK)>,
+						 <K210_FPIOA(1, K210_PCF_JTAG_TDI)>,
+						 <K210_FPIOA(2, K210_PCF_JTAG_TMS)>,
+						 <K210_FPIOA(3, K210_PCF_JTAG_TDO)>;
+				};
 			};
 
 			sha256: sha256 at 502C0000 {
Signature · 1 line
2.28.0
#15 lore raw

PATCH v5 10/11 riscv: Add pinmux and gpio bindings for Kendryte K210

Quoted 78 lines · Sean Anderson

This patch adds the necessary device tree bindings.

---

(no changes since v2)

Changes in v2:
- Convert to use pinmux property
- Don't hog ISP on boot
- Re-order GPIOs to match the defaults more closely

 arch/riscv/dts/k210-maix-bit.dts | 104 +++++++++++++++++++++++++++++++
 arch/riscv/dts/k210.dtsi         |  12 ++++
 2 files changed, 116 insertions(+)
arch/riscv/dts/k210-maix-bit.dts +41 -0
index 5b32c5fd5f..e840e04ada 100644
@@ -17,6 +17,22 @@
 		stdout-path = "serial0:115200";
 	};
 
+	gpio-leds {
+		compatible = "gpio-leds";
+
+		green {
+			gpios = <&gpio1_0 4 GPIO_ACTIVE_LOW>;
+		};
+
+		red {
+			gpios = <&gpio1_0 5 GPIO_ACTIVE_LOW>;
+		};
+
+		blue {
+			gpios = <&gpio1_0 6 GPIO_ACTIVE_LOW>;
+		};
+	};
+
 	sound {
 		compatible = "simple-audio-card";
 		simple-audio-card,format = "i2s";
@@ -39,9 +55,97 @@
 };
 
 &uarths0 {
+	pinctrl-0 = <&fpioa_uarths>;
+	pinctrl-names = "default";
+	status = "okay";
+};
+
+&gpio0 {
+	pinctrl-0 = <&fpioa_gpiohs>;
+	pinctrl-names = "default";
+	status = "okay";
+};
+
+&gpio1 {
+	pinctrl-0 = <&fpioa_gpio>;
+	pinctrl-names = "default";
 	status = "okay";
 };
 
 &i2s0 {
 	#sound-dai-cells = <1>;
+	pinctrl-0 = <&fpioa_i2s0>;
+	pinctrl-names = "default";
+};
+
+&fpioa {
+	status = "okay";
+
+	fpioa_uarths: uarths {
+		pinmux = <K210_FPIOA(4, K210_PCF_UARTHS_RX)>,
+			 <K210_FPIOA(5, K210_PCF_UARTHS_TX)>;
+	};

arch/riscv/dts/k210-maix-bit.dts line 97

Quoted 10 lines
arch/riscv/dts/k210-maix-bit.dts +10 -0
+
+	fpioa_gpio: gpio {
+		pinmux = <K210_FPIOA(8, K210_PCF_GPIO0)>,
+			 <K210_FPIOA(9, K210_PCF_GPIO1)>,
+			 <K210_FPIOA(10, K210_PCF_GPIO2)>,
+			 <K210_FPIOA(11, K210_PCF_GPIO3)>,
+			 <K210_FPIOA(12, K210_PCF_GPIO4)>,
+			 <K210_FPIOA(13, K210_PCF_GPIO5)>,
+			 <K210_FPIOA(14, K210_PCF_GPIO6)>,
+			 <K210_FPIOA(15, K210_PCF_GPIO7)>;

On the Maixduino the K210 package pins IO_6 - IO_9, IO_25 - IO_29 serve as interface to the ESP32 which is used for WLAN. In the schema for the Maixduino the naming is:

IO_6 - ESP32_TX
IO_7 - ESP32_RX
IO_8 - ESP32_EN
IO_9 - ESP32_READY

IO_6 and IO_7 are not mapped in reset state and in a Python example I found for connecting to a WLAN these lines were not used.

If the usage of IO_8 and IO_9 differs between the Maixduino and the Maix Bit, shouldn't they be mapped in k210-maix-bit.dts instead of k210.dtsi?

According to https://github.com/sipeed/MaixPy/issues/127 one of the SPI interfaces is switched between SD-card and WLAN. The ESP32 connection uses gpiohs while the SD card does not.

arch/riscv/dts/k210-maix-bit.dts line 101

Quoted 4 lines
arch/riscv/dts/k210-maix-bit.dts +4 -0
+	};
+
+	fpioa_gpiohs: gpiohs {
+		pinmux = <K210_FPIOA(16, K210_PCF_GPIOHS0)>,

IO_16 is connected to the boot button on the Maixduino and Maix Fit boards. So I guess we should add an entry compatible = "gpio-keys" for it and add a comment here.

Quoted 12 lines
arch/riscv/dts/k210-maix-bit.dts +12 -0
+			 <K210_FPIOA(17, K210_PCF_GPIOHS1)>,
+			 <K210_FPIOA(21, K210_PCF_GPIOHS5)>,
+			 <K210_FPIOA(22, K210_PCF_GPIOHS6)>,
+			 <K210_FPIOA(23, K210_PCF_GPIOHS7)>,
+			 <K210_FPIOA(24, K210_PCF_GPIOHS8)>,
+			 <K210_FPIOA(25, K210_PCF_GPIOHS9)>,
+			 <K210_FPIOA(30, K210_PCF_GPIOHS14)>,
+			 <K210_FPIOA(31, K210_PCF_GPIOHS15)>,
+			 <K210_FPIOA(32, K210_PCF_GPIOHS16)>,
+			 <K210_FPIOA(33, K210_PCF_GPIOHS17)>,
+			 <K210_FPIOA(34, K210_PCF_GPIOHS18)>,
+			 <K210_FPIOA(35, K210_PCF_GPIOHS19)>;

arch/riscv/dts/k210-maix-bit.dts line 123

Quoted 10 lines
arch/riscv/dts/k210-maix-bit.dts +10 -0
+	};
+
+	fpioa_i2s0: i2s0 {
+		pinmux = <K210_FPIOA(18, K210_PCF_I2S0_SCLK)>,
+			 <K210_FPIOA(19, K210_PCF_I2S0_WS)>,
+			 <K210_FPIOA(20, K210_PCF_I2S0_IN_D0)>;
+	};
+
+	fpioa_dvp: dvp {
+		pinmux = <K210_FPIOA(40, K210_PCF_SCCB_SDA)>,

DVP_SDA in 'Maix-Bit-V2.0(Pin assignment table.xlsx'

arch/riscv/dts/k210-maix-bit.dts line 124

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(41, K210_PCF_SCCB_SCLK)>,

DVP_SCL

arch/riscv/dts/k210-maix-bit.dts line 125

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(42, K210_PCF_DVP_RST)>,

DVP_RST

arch/riscv/dts/k210-maix-bit.dts line 126

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(43, K210_PCF_DVP_VSYNC)>,

DVP_VSYNC

arch/riscv/dts/k210-maix-bit.dts line 127

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(44, K210_PCF_DVP_PWDN)>,

DVP_PWDN

arch/riscv/dts/k210-maix-bit.dts line 128

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(45, K210_PCF_DVP_HSYNC)>,

DVP_HSYNC

arch/riscv/dts/k210-maix-bit.dts line 129

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(46, K210_PCF_DVP_XCLK)>,

DVP_XCLK

arch/riscv/dts/k210-maix-bit.dts line 130

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(47, K210_PCF_DVP_PCLK)>;

DVP_PCLK

arch/riscv/dts/k210-maix-bit.dts line 134

Quoted 4 lines
arch/riscv/dts/k210-maix-bit.dts +4 -0
+	};
+
+	fpioa_spi0: spi0 {
+		pinmux = <K210_FPIOA(36, K210_PCF_GPIOHS20)>,  /* cs */

LCD_CS in 'Maix-Bit-V2.0(Pin assignment table.xlsx'

arch/riscv/dts/k210-maix-bit.dts line 135

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(37, K210_PCF_GPIOHS21)>,  /* rst */

LCD_RST

arch/riscv/dts/k210-maix-bit.dts line 136

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(38, K210_PCF_GPIOHS22)>,  /* dc */

LCD_DC

arch/riscv/dts/k210-maix-bit.dts line 137

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(39, K210_PCF_SPI0_SCLK)>; /* wr */

LCD_WR

Should the comments be updated to reflect the connection to LCD?

arch/riscv/dts/k210-maix-bit.dts line 141

Quoted 4 lines
arch/riscv/dts/k210-maix-bit.dts +4 -0
+	};
+
+	fpioa_spi1: spi1 {
+		pinmux = <K210_FPIOA(26, K210_PCF_SPI1_D1)>,

SPI0 MISO in 'Maix-Bit-V2.0(Pin assignment table.xlsx'

arch/riscv/dts/k210-maix-bit.dts line 142

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(27, K210_PCF_SPI1_SCLK)>,

SPI0 SCLK

arch/riscv/dts/k210-maix-bit.dts line 143

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(28, K210_PCF_SPI1_D0)>,

SPI0 MOSI

arch/riscv/dts/k210-maix-bit.dts line 144

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(29, K210_PCF_GPIOHS13)>;

SPI0_CS0

Should we add comments?

Best regards

Heinrich

Quoted 39 lines
arch/riscv/dts/k210-maix-bit.dts +6 -0
+	};
+};
+
+&dvp0 {
+	pinctrl-0 = <&fpioa_dvp>;
+	pinctrl-names = "default";
 };
arch/riscv/dts/k210.dtsi +12 -0
index 2546c7d4e0..fc7986b326 100644
@@ -5,6 +5,7 @@
 
 #include <dt-bindings/clock/k210-sysctl.h>
 #include <dt-bindings/mfd/k210-sysctl.h>
+#include <dt-bindings/pinctrl/k210-pinctrl.h>
 #include <dt-bindings/reset/k210-sysctl.h>
 
 / {
@@ -367,7 +368,18 @@
 				reg = <0x502B0000 0x100>;
 				clocks = <&sysclk K210_CLK_FPIOA>;
 				resets = <&sysrst K210_RST_FPIOA>;
+				kendryte,sysctl = <&sysctl>;
+				kendryte,power-offset = <K210_SYSCTL_POWER_SEL>;
+				pinctrl-0 = <&fpioa_jtag>;
+				pinctrl-names = "default";
 				status = "disabled";
+
+				fpioa_jtag: jtag {
+					pinmux = <K210_FPIOA(0, K210_PCF_JTAG_TCLK)>,
+						 <K210_FPIOA(1, K210_PCF_JTAG_TDI)>,
+						 <K210_FPIOA(2, K210_PCF_JTAG_TMS)>,
+						 <K210_FPIOA(3, K210_PCF_JTAG_TDO)>;
+				};
 			};
 
 			sha256: sha256 at 502C0000 {
#16 lore raw

PATCH v5 10/11 riscv: Add pinmux and gpio bindings for Kendryte K210

Quoted 99 lines · Heinrich Schuchardt
Quoted 78 lines · Sean Anderson

This patch adds the necessary device tree bindings.

---

(no changes since v2)

Changes in v2:
- Convert to use pinmux property
- Don't hog ISP on boot
- Re-order GPIOs to match the defaults more closely

 arch/riscv/dts/k210-maix-bit.dts | 104 +++++++++++++++++++++++++++++++
 arch/riscv/dts/k210.dtsi         |  12 ++++
 2 files changed, 116 insertions(+)
arch/riscv/dts/k210-maix-bit.dts +41 -0
index 5b32c5fd5f..e840e04ada 100644
@@ -17,6 +17,22 @@
 		stdout-path = "serial0:115200";
 	};
 
+	gpio-leds {
+		compatible = "gpio-leds";
+
+		green {
+			gpios = <&gpio1_0 4 GPIO_ACTIVE_LOW>;
+		};
+
+		red {
+			gpios = <&gpio1_0 5 GPIO_ACTIVE_LOW>;
+		};
+
+		blue {
+			gpios = <&gpio1_0 6 GPIO_ACTIVE_LOW>;
+		};
+	};
+
 	sound {
 		compatible = "simple-audio-card";
 		simple-audio-card,format = "i2s";
@@ -39,9 +55,97 @@
 };
 
 &uarths0 {
+	pinctrl-0 = <&fpioa_uarths>;
+	pinctrl-names = "default";
+	status = "okay";
+};
+
+&gpio0 {
+	pinctrl-0 = <&fpioa_gpiohs>;
+	pinctrl-names = "default";
+	status = "okay";
+};
+
+&gpio1 {
+	pinctrl-0 = <&fpioa_gpio>;
+	pinctrl-names = "default";
 	status = "okay";
 };
 
 &i2s0 {
 	#sound-dai-cells = <1>;
+	pinctrl-0 = <&fpioa_i2s0>;
+	pinctrl-names = "default";
+};
+
+&fpioa {
+	status = "okay";
+
+	fpioa_uarths: uarths {
+		pinmux = <K210_FPIOA(4, K210_PCF_UARTHS_RX)>,
+			 <K210_FPIOA(5, K210_PCF_UARTHS_TX)>;
+	};

arch/riscv/dts/k210-maix-bit.dts line 97

Quoted 10 lines
arch/riscv/dts/k210-maix-bit.dts +10 -0
+
+	fpioa_gpio: gpio {
+		pinmux = <K210_FPIOA(8, K210_PCF_GPIO0)>,
+			 <K210_FPIOA(9, K210_PCF_GPIO1)>,
+			 <K210_FPIOA(10, K210_PCF_GPIO2)>,
+			 <K210_FPIOA(11, K210_PCF_GPIO3)>,
+			 <K210_FPIOA(12, K210_PCF_GPIO4)>,
+			 <K210_FPIOA(13, K210_PCF_GPIO5)>,
+			 <K210_FPIOA(14, K210_PCF_GPIO6)>,
+			 <K210_FPIOA(15, K210_PCF_GPIO7)>;

On the Maixduino the K210 package pins IO_6 - IO_9, IO_25 - IO_29 serve as interface to the ESP32 which is used for WLAN. In the schema for the Maixduino the naming is:

IO_6 - ESP32_TX
IO_7 - ESP32_RX
IO_8 - ESP32_EN
IO_9 - ESP32_READY

Quoted 5 lines

IO_6 and IO_7 are not mapped in reset state and in a Python example I found for connecting to a WLAN these lines were not used.

If the usage of IO_8 and IO_9 differs between the Maixduino and the Maix Bit, shouldn't they be mapped in k210-maix-bit.dts instead of k210.dtsi?

These *are* in k210-maix-bit.dts.

Quoted 5 lines

According to https://github.com/sipeed/MaixPy/issues/127 one of the SPI interfaces is switched between SD-card and WLAN. The ESP32 connection uses gpiohs while the SD card does not.

Quoted 8 lines

arch/riscv/dts/k210-maix-bit.dts line 101

Quoted 4 lines
arch/riscv/dts/k210-maix-bit.dts +4 -0
+	};
+
+	fpioa_gpiohs: gpiohs {
+		pinmux = <K210_FPIOA(16, K210_PCF_GPIOHS0)>,

IO_16 is connected to the boot button on the Maixduino and Maix Fit boards. So I guess we should add an entry compatible = "gpio-keys" for it and add a comment here.

I saw you created a patch for this [1]. Would you like to keep that separate, or should I add it to this series?

[1] https://patchwork.ozlabs.org/project/uboot/patch/20200902201159.98034-1-xypron.glpk at gmx.de/

Quoted 68 lines
Quoted 12 lines
arch/riscv/dts/k210-maix-bit.dts +12 -0
+			 <K210_FPIOA(17, K210_PCF_GPIOHS1)>,
+			 <K210_FPIOA(21, K210_PCF_GPIOHS5)>,
+			 <K210_FPIOA(22, K210_PCF_GPIOHS6)>,
+			 <K210_FPIOA(23, K210_PCF_GPIOHS7)>,
+			 <K210_FPIOA(24, K210_PCF_GPIOHS8)>,
+			 <K210_FPIOA(25, K210_PCF_GPIOHS9)>,
+			 <K210_FPIOA(30, K210_PCF_GPIOHS14)>,
+			 <K210_FPIOA(31, K210_PCF_GPIOHS15)>,
+			 <K210_FPIOA(32, K210_PCF_GPIOHS16)>,
+			 <K210_FPIOA(33, K210_PCF_GPIOHS17)>,
+			 <K210_FPIOA(34, K210_PCF_GPIOHS18)>,
+			 <K210_FPIOA(35, K210_PCF_GPIOHS19)>;

arch/riscv/dts/k210-maix-bit.dts line 123

Quoted 10 lines
arch/riscv/dts/k210-maix-bit.dts +10 -0
+	};
+
+	fpioa_i2s0: i2s0 {
+		pinmux = <K210_FPIOA(18, K210_PCF_I2S0_SCLK)>,
+			 <K210_FPIOA(19, K210_PCF_I2S0_WS)>,
+			 <K210_FPIOA(20, K210_PCF_I2S0_IN_D0)>;
+	};
+
+	fpioa_dvp: dvp {
+		pinmux = <K210_FPIOA(40, K210_PCF_SCCB_SDA)>,

DVP_SDA in 'Maix-Bit-V2.0(Pin assignment table.xlsx'

arch/riscv/dts/k210-maix-bit.dts line 124

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(41, K210_PCF_SCCB_SCLK)>,

DVP_SCL

arch/riscv/dts/k210-maix-bit.dts line 125

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(42, K210_PCF_DVP_RST)>,

DVP_RST

arch/riscv/dts/k210-maix-bit.dts line 126

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(43, K210_PCF_DVP_VSYNC)>,

DVP_VSYNC

arch/riscv/dts/k210-maix-bit.dts line 127

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(44, K210_PCF_DVP_PWDN)>,

DVP_PWDN

arch/riscv/dts/k210-maix-bit.dts line 128

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(45, K210_PCF_DVP_HSYNC)>,

DVP_HSYNC

arch/riscv/dts/k210-maix-bit.dts line 129

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(46, K210_PCF_DVP_XCLK)>,

DVP_XCLK

arch/riscv/dts/k210-maix-bit.dts line 130

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(47, K210_PCF_DVP_PCLK)>;

DVP_PCLK

arch/riscv/dts/k210-maix-bit.dts line 134

Quoted 4 lines
arch/riscv/dts/k210-maix-bit.dts +4 -0
+	};
+
+	fpioa_spi0: spi0 {
+		pinmux = <K210_FPIOA(36, K210_PCF_GPIOHS20)>,  /* cs */

LCD_CS in 'Maix-Bit-V2.0(Pin assignment table.xlsx'

arch/riscv/dts/k210-maix-bit.dts line 135

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(37, K210_PCF_GPIOHS21)>,  /* rst */

LCD_RST

arch/riscv/dts/k210-maix-bit.dts line 136

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(38, K210_PCF_GPIOHS22)>,  /* dc */

LCD_DC

Quoted 5 lines

arch/riscv/dts/k210-maix-bit.dts line 137

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(39, K210_PCF_SPI0_SCLK)>; /* wr */

LCD_WR

Should the comments be updated to reflect the connection to LCD?

Sure.

Quoted 15 lines

arch/riscv/dts/k210-maix-bit.dts line 141

Quoted 4 lines
arch/riscv/dts/k210-maix-bit.dts +4 -0
+	};
+
+	fpioa_spi1: spi1 {
+		pinmux = <K210_FPIOA(26, K210_PCF_SPI1_D1)>,

SPI0 MISO in 'Maix-Bit-V2.0(Pin assignment table.xlsx'

arch/riscv/dts/k210-maix-bit.dts line 142

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(27, K210_PCF_SPI1_SCLK)>,

SPI0 SCLK

arch/riscv/dts/k210-maix-bit.dts line 143

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(28, K210_PCF_SPI1_D0)>,

SPI0 MOSI

Quoted 5 lines

arch/riscv/dts/k210-maix-bit.dts line 144

Quoted 1 line
arch/riscv/dts/k210-maix-bit.dts +1 -0
+			 <K210_FPIOA(29, K210_PCF_GPIOHS13)>;

SPI0_CS0

Should we add comments?

I will add some for this spi in the next revision.

Quoted 45 lines

Best regards

Heinrich

Quoted 39 lines
arch/riscv/dts/k210-maix-bit.dts +6 -0
+	};
+};
+
+&dvp0 {
+	pinctrl-0 = <&fpioa_dvp>;
+	pinctrl-names = "default";
 };
arch/riscv/dts/k210.dtsi +12 -0
index 2546c7d4e0..fc7986b326 100644
@@ -5,6 +5,7 @@
 
 #include <dt-bindings/clock/k210-sysctl.h>
 #include <dt-bindings/mfd/k210-sysctl.h>
+#include <dt-bindings/pinctrl/k210-pinctrl.h>
 #include <dt-bindings/reset/k210-sysctl.h>
 
 / {
@@ -367,7 +368,18 @@
 				reg = <0x502B0000 0x100>;
 				clocks = <&sysclk K210_CLK_FPIOA>;
 				resets = <&sysrst K210_RST_FPIOA>;
+				kendryte,sysctl = <&sysctl>;
+				kendryte,power-offset = <K210_SYSCTL_POWER_SEL>;
+				pinctrl-0 = <&fpioa_jtag>;
+				pinctrl-names = "default";
 				status = "disabled";
+
+				fpioa_jtag: jtag {
+					pinmux = <K210_FPIOA(0, K210_PCF_JTAG_TCLK)>,
+						 <K210_FPIOA(1, K210_PCF_JTAG_TDI)>,
+						 <K210_FPIOA(2, K210_PCF_JTAG_TMS)>,
+						 <K210_FPIOA(3, K210_PCF_JTAG_TDO)>;
+				};
 			};
 
 			sha256: sha256 at 502C0000 {
#17 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

In reply to Sean Anderson

This patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.

The board does not boot unless CONSOLE_LOGLEVEL is set to a non-default value . It also boots when the tree is dirty (and CONSOLE_LOGLEVEL is not changed). It also boots when changes are made to the device tree and then committed. I don't know why this happens. These breakages only occur after bf2fb81ad3.

---

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.

Changes in v3:
- Document pins 6 and 7 as not set

Changes in v2:
- Remove SPI flash related Kconfig settings

 board/sipeed/maix/Kconfig          |  9 +++++
 configs/sipeed_maix_bitm_defconfig |  2 +
 doc/board/sipeed/maix.rst          | 64 +++++++++++++++++++++++++++++-
 3 files changed, 73 insertions(+), 2 deletions(-)
board/sipeed/maix/Kconfig +9 -0
index 0cdcd32adc..4c42dd2087 100644
@@ -44,4 +44,13 @@ config BOARD_SPECIFIC_OPTIONS
 	imply RESET_SYSCON
 	imply SYSRESET
 	imply SYSRESET_SYSCON
+	imply PINCTRL
+	imply PINCONF
+	imply PINCTRL_K210
+	imply DM_GPIO
+	imply DWAPB_GPIO
+	imply SIFIVE_GPIO
+	imply CMD_GPIO
+	imply LED
+	imply LED_GPIO
 endif
configs/sipeed_maix_bitm_defconfig +2 -0
index 459bf0d530..0b038ff0a1 100644
@@ -2,6 +2,8 @@ CONFIG_RISCV=y
 CONFIG_TARGET_SIPEED_MAIX=y
 CONFIG_ARCH_RV64I=y
 CONFIG_STACK_SIZE=0x100000
+# FIXME: Dirty hack to get boot working!
+CONFIG_LOGLEVEL=5
 # CONFIG_NET is not set
 # CONFIG_INPUT is not set
 # CONFIG_DM_ETH is not set
doc/board/sipeed/maix.rst +62 -2

80 lines not on this page · raw message

Signature · 1 line
2.28.0
#18 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

Hi Tom

Quoted 9 lines

This patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.

The board does not boot unless CONSOLE_LOGLEVEL is set to a non-default value . It also boots when the tree is dirty (and CONSOLE_LOGLEVEL is not changed). It also boots when changes are made to the device tree and then committed. I don't know why this happens. These breakages only occur after bf2fb81ad3.

Quoted 7 lines

---

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.

Would you like to pick up this series, [PATCH v5 00/11] riscv: Add FPIOA and GPIO support for Kendryte K210 ?
Or maybe it is better to figure out what is wrong here and find the root cause why it need to Increase CONSOLE_LOGLEVEL to 5 as a hack ?

Thanks,
Rick

Quoted 133 lines

Changes in v3:
- Document pins 6 and 7 as not set

Changes in v2:
- Remove SPI flash related Kconfig settings

 board/sipeed/maix/Kconfig          |  9 +++++
 configs/sipeed_maix_bitm_defconfig |  2 +
 doc/board/sipeed/maix.rst          | 64 +++++++++++++++++++++++++++++-
 3 files changed, 73 insertions(+), 2 deletions(-)
board/sipeed/maix/Kconfig +9 -0
index 0cdcd32adc..4c42dd2087 100644
@@ -44,4 +44,13 @@ config BOARD_SPECIFIC_OPTIONS
        imply RESET_SYSCON
        imply SYSRESET
        imply SYSRESET_SYSCON
+       imply PINCTRL
+       imply PINCONF
+       imply PINCTRL_K210
+       imply DM_GPIO
+       imply DWAPB_GPIO
+       imply SIFIVE_GPIO
+       imply CMD_GPIO
+       imply LED
+       imply LED_GPIO
 endif
configs/sipeed_maix_bitm_defconfig +2 -0
index 459bf0d530..0b038ff0a1 100644
@@ -2,6 +2,8 @@ CONFIG_RISCV=y
 CONFIG_TARGET_SIPEED_MAIX=y
 CONFIG_ARCH_RV64I=y
 CONFIG_STACK_SIZE=0x100000
+# FIXME: Dirty hack to get boot working!
+CONFIG_LOGLEVEL=5
 # CONFIG_NET is not set
 # CONFIG_INPUT is not set
 # CONFIG_DM_ETH is not set
doc/board/sipeed/maix.rst +62 -3
index b1894f3a6f..3811eac61f 100644
@@ -156,7 +156,7 @@ To run legacy images, use the ``bootm`` command:
     Load Address: 80000000
     Entry Point:  80000000
 
-    $ picocom -b 115200 /dev/ttyUSB0i
+    $ picocom -b 115200 /dev/ttyUSB0
     => loady
     ## Ready for binary (ymodem) download to 0x80000000 at 115200 bps...
     C
@@ -187,6 +187,66 @@ To run legacy images, use the ``bootm`` command:
     argv[0] = "<NULL>"
     Hit any key to exit ...
 
+Pin Assignment
+--------------
+
+The K210 contains a Fully Programmable I/O Array (FPIOA), which can remap any of
+its 256 input functions to any any of 48 output pins. The following table has
+the default pin assignments for the BitM.
+
+===== ========== =======
+Pin   Function   Comment
+===== ========== =======
+IO_0  JTAG_TCLK
+IO_1  JTAG_TDI
+IO_2  JTAG_TMS
+IO_3  JTAG_TDO
+IO_4  UARTHS_RX
+IO_5  UARTHS_TX
+IO_6             Not set
+IO_7             Not set
+IO_8  GPIO_0
+IO_9  GPIO_1
+IO_10 GPIO_2
+IO_11 GPIO_3
+IO_12 GPIO_4     Green LED
+IO_13 GPIO_5     Red LED
+IO_14 GPIO_6     Blue LED
+IO_15 GPIO_7
+IO_16 GPIOHS_0   ISP
+IO_17 GPIOHS_1
+IO_18 I2S0_SCLK  MIC CLK
+IO_19 I2S0_WS    MIC WS
+IO_20 I2S0_IN_D0 MIC SD
+IO_21 GPIOHS_5
+IO_22 GPIOHS_6
+IO_23 GPIOHS_7
+IO_24 GPIOHS_8
+IO_25 GPIOHS_9
+IO_26 SPI1_D1    MMC MISO
+IO_27 SPI1_SCLK  MMC CLK
+IO_28 SPI1_D0    MMC MOSI
+IO_29 GPIOHS_13  MMC CS
+IO_30 GPIOHS_14
+IO_31 GPIOHS_15
+IO_32 GPIOHS_16
+IO_33 GPIOHS_17
+IO_34 GPIOHS_18
+IO_35 GPIOHS_19
+IO_36 GPIOHS_20  Panel CS
+IO_37 GPIOHS_21  Panel RST
+IO_38 GPIOHS_22  Panel DC
+IO_39 SPI0_SCK   Panel WR
+IO_40 SCCP_SDA
+IO_41 SCCP_SCLK
+IO_42 DVP_RST
+IO_43 DVP_VSYNC
+IO_44 DVP_PWDN
+IO_45 DVP_HSYNC
+IO_46 DVP_XCLK
+IO_47 DVP_PCLK
+===== ========== =======
+
 Over- and Under-clocking
 ------------------------
 
@@ -361,5 +421,5 @@ Address    Size      Description
 0x8801C000 0x1000    riscv priv spec 1.9 config
 0x8801D000 0x2000    flattened device tree (contains only addresses and
                      interrupts)
-0x8801f000 0x1000    credits
+0x8801F000 0x1000    credits
 ========== ========= ===========
--

2.28.0

#19 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

Quoted 19 lines · Rick Chen

Hi Tom

Quoted 9 lines

This patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.

The board does not boot unless CONSOLE_LOGLEVEL is set to a non-default value . It also boots when the tree is dirty (and CONSOLE_LOGLEVEL is not changed). It also boots when changes are made to the device tree and then committed. I don't know why this happens. These breakages only occur after bf2fb81ad3.

Quoted 7 lines

---

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.

Quoted 4 lines

Would you like to pick up this series, [PATCH v5 00/11] riscv: Add FPIOA and GPIO support for Kendryte K210 ?
Or maybe it is better to figure out what is wrong here and find the root cause why it need to Increase CONSOLE_LOGLEVEL to 5 as a hack ?

As an additional note, *CONFIG_LOGLEVEL (whoops) can also be decreased for the same effect. In addition, there are several other ways I found to "fix" this bug (as noted in the commit message). If you would like to test this out, I have two trees [1, 2] where this series (actually a slightly earlier version of this series) is applied just before and just after bf2fb81ad3. The original patch is located at [3].

--Sean

[1] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_good
[2] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_bad
[3] https://patchwork.ozlabs.org/project/uboot/patch/20200724111225.12513-15-ovidiu.panait at windriver.com/

#20 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

Hi Sean

Quoted 32 lines · Rick Chen
Quoted 19 lines

Hi Tom

Quoted 9 lines

This patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.

The board does not boot unless CONSOLE_LOGLEVEL is set to a non-default value . It also boots when the tree is dirty (and CONSOLE_LOGLEVEL is not changed). It also boots when changes are made to the device tree and then committed. I don't know why this happens. These breakages only occur after bf2fb81ad3.

Quoted 7 lines

---

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.

Quoted 4 lines

Would you like to pick up this series, [PATCH v5 00/11] riscv: Add FPIOA and GPIO support for Kendryte K210 ?
Or maybe it is better to figure out what is wrong here and find the root cause why it need to Increase CONSOLE_LOGLEVEL to 5 as a hack ?

As an additional note, *CONFIG_LOGLEVEL (whoops) can also be decreased for the same effect. In addition, there are several other ways I found to "fix" this bug (as noted in the commit message). If you would like to test this out, I have two trees [1, 2] where this series (actually a slightly earlier version of this series) is applied just before and just after bf2fb81ad3. The original patch is located at [3].

Quoted 5 lines

--Sean

[1] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_good
[2] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_bad
[3] https://patchwork.ozlabs.org/project/uboot/patch/20200724111225.12513-15-ovidiu.panait at windriver.com/

I don't have a K210 board for verification.
But it is OK to run in AE350 board after applying your series.

After check about this commit "common/board_r: Remove initr_serial wrapper", it seem shall not affect anything.
It just change to call serial_initialize directly.
Only I can think about maybe it is a cache problem.
Just like sometime we add a printf, then the problem will be walk around.

Thanks,
Rick

#21 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

Hi Sean

Quoted 40 lines

Hi Sean

Quoted 32 lines · Rick Chen
Quoted 19 lines

Hi Tom

Quoted 9 lines

This patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.

The board does not boot unless CONSOLE_LOGLEVEL is set to a non-default value . It also boots when the tree is dirty (and CONSOLE_LOGLEVEL is not changed). It also boots when changes are made to the device tree and then committed. I don't know why this happens. These breakages only occur after bf2fb81ad3.

Quoted 7 lines

---

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.

Quoted 4 lines

Would you like to pick up this series, [PATCH v5 00/11] riscv: Add FPIOA and GPIO support for Kendryte K210 ?
Or maybe it is better to figure out what is wrong here and find the root cause why it need to Increase CONSOLE_LOGLEVEL to 5 as a hack ?

As an additional note, *CONFIG_LOGLEVEL (whoops) can also be decreased for the same effect. In addition, there are several other ways I found to "fix" this bug (as noted in the commit message). If you would like to test this out, I have two trees [1, 2] where this series (actually a slightly earlier version of this series) is applied just before and just after bf2fb81ad3. The original patch is located at [3].

Quoted 5 lines

--Sean

[1] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_good
[2] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_bad
[3] https://patchwork.ozlabs.org/project/uboot/patch/20200724111225.12513-15-ovidiu.panait at windriver.com/

Quoted 8 lines

I don't have a K210 board for verification.
But it is OK to run in AE350 board after applying your series.

After check about this commit "common/board_r: Remove initr_serial wrapper", it seem shall not affect anything.
It just change to call serial_initialize directly.
Only I can think about maybe it is a cache problem.
Just like sometime we add a printf, then the problem will be walk around.

Can you dig in to find the root cause ?
For code stability, it is better not to have any unknown issue. Yo can dirty hack and work around currently, but it may crash again after several commits.

Thanks,
Rick

Quoted 3 lines

Thanks,
Rick

#22 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

Quoted 51 lines · Rick Chen

Hi Sean

Quoted 40 lines

Hi Sean

Quoted 32 lines · Rick Chen
Quoted 19 lines

Hi Tom

Quoted 9 lines

This patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.

The board does not boot unless CONSOLE_LOGLEVEL is set to a non-default value . It also boots when the tree is dirty (and CONSOLE_LOGLEVEL is not changed). It also boots when changes are made to the device tree and then committed. I don't know why this happens. These breakages only occur after bf2fb81ad3.

Quoted 7 lines

---

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.

Quoted 4 lines

Would you like to pick up this series, [PATCH v5 00/11] riscv: Add FPIOA and GPIO support for Kendryte K210 ?
Or maybe it is better to figure out what is wrong here and find the root cause why it need to Increase CONSOLE_LOGLEVEL to 5 as a hack ?

As an additional note, *CONFIG_LOGLEVEL (whoops) can also be decreased for the same effect. In addition, there are several other ways I found to "fix" this bug (as noted in the commit message). If you would like to test this out, I have two trees [1, 2] where this series (actually a slightly earlier version of this series) is applied just before and just after bf2fb81ad3. The original patch is located at [3].

Quoted 5 lines

--Sean

[1] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_good
[2] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_bad
[3] https://patchwork.ozlabs.org/project/uboot/patch/20200724111225.12513-15-ovidiu.panait at windriver.com/

Quoted 8 lines

I don't have a K210 board for verification.
But it is OK to run in AE350 board after applying your series.

After check about this commit "common/board_r: Remove initr_serial wrapper", it seem shall not affect anything.
It just change to call serial_initialize directly.
Only I can think about maybe it is a cache problem.
Just like sometime we add a printf, then the problem will be walk around.

Quoted 4 lines

Can you dig in to find the root cause ?
For code stability, it is better not to have any unknown issue. Yo can dirty hack and work around currently, but it may crash again after several commits.

Ok, so I did some further digging, but I was unable to pin down the cause of the bug. My efforts to determine a cause have been primarily thwarted because the bug disappears after any change to initialization code. Adding any function to init_sequence_f or init_sequence_r, even a no-op function which just returns 0, causes the board to boot normally. In addition, adding a nop() to any function in those sequences will cause the board to boot normally. The board seems to fail to boot only with a very specific boot sequence and timing.

When the board fails to boot, it hangs in a manner similar to when the airam is accessed: the bus appears to hang. Just as when airam is accessed, a debugger cannot read registers or memory until the cpu is reset. This may be a separate issue which hangs the bus, or it could also be caused by an inadvertent access to airam. The puzzling thing is still the manner of triggering the bug. It's almost as if it was specifically designed to be impossible to debug by disappearing whenever one makes an attempt...

--Sean

#23 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

Hi Sean

Quoted 57 lines · Rick Chen
Quoted 51 lines

Hi Sean

Quoted 40 lines

Hi Sean

Quoted 32 lines · Rick Chen
Quoted 19 lines

Hi Tom

Quoted 9 lines

This patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.

The board does not boot unless CONSOLE_LOGLEVEL is set to a non-default value . It also boots when the tree is dirty (and CONSOLE_LOGLEVEL is not changed). It also boots when changes are made to the device tree and then committed. I don't know why this happens. These breakages only occur after bf2fb81ad3.

Quoted 7 lines

---

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.

Quoted 4 lines

Would you like to pick up this series, [PATCH v5 00/11] riscv: Add FPIOA and GPIO support for Kendryte K210 ?
Or maybe it is better to figure out what is wrong here and find the root cause why it need to Increase CONSOLE_LOGLEVEL to 5 as a hack ?

As an additional note, *CONFIG_LOGLEVEL (whoops) can also be decreased for the same effect. In addition, there are several other ways I found to "fix" this bug (as noted in the commit message). If you would like to test this out, I have two trees [1, 2] where this series (actually a slightly earlier version of this series) is applied just before and just after bf2fb81ad3. The original patch is located at [3].

Quoted 5 lines

--Sean

[1] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_good
[2] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_bad
[3] https://patchwork.ozlabs.org/project/uboot/patch/20200724111225.12513-15-ovidiu.panait at windriver.com/

Quoted 8 lines

I don't have a K210 board for verification.
But it is OK to run in AE350 board after applying your series.

After check about this commit "common/board_r: Remove initr_serial wrapper", it seem shall not affect anything.
It just change to call serial_initialize directly.
Only I can think about maybe it is a cache problem.
Just like sometime we add a printf, then the problem will be walk around.

Quoted 4 lines

Can you dig in to find the root cause ?
For code stability, it is better not to have any unknown issue. Yo can dirty hack and work around currently, but it may crash again after several commits.

Quoted 8 lines

Ok, so I did some further digging, but I was unable to pin down the cause of the bug. My efforts to determine a cause have been primarily thwarted because the bug disappears after any change to initialization code. Adding any function to init_sequence_f or init_sequence_r, even a no-op function which just returns 0, causes the board to boot normally. In addition, adding a nop() to any function in those sequences will cause the board to boot normally. The board seems to fail to boot only with a very specific boot sequence and timing.

If you modify any code and the result will change, then you shall debug it via debugger(GDB) without any code modification.

Quoted 2 lines

When the board fails to boot, it hangs in a manner similar to when the

Maybe you can try to set a break and access the bus, if the bus access fail, then you re-set a break a bit ahead until the bus access NOT fail.
To see if this way can pin down which instruction or the crucial code to cause the bus hang problem. And guess what maybe the root-cause.

If you can find the instruction which may cause the bus hang, you can info all-registers and compare the differences between NG and OK. And guess what maybe the root-cause.

Thanks,
Rick

Quoted 9 lines

airam is accessed: the bus appears to hang. Just as when airam is accessed, a debugger cannot read registers or memory until the cpu is reset. This may be a separate issue which hangs the bus, or it could also be caused by an inadvertent access to airam. The puzzling thing is still the manner of triggering the bug. It's almost as if it was specifically designed to be impossible to debug by disappearing whenever one makes an attempt...

--Sean

#24 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

Quoted 80 lines · Rick Chen

Hi Sean

Quoted 57 lines · Rick Chen
Quoted 51 lines

Hi Sean

Quoted 40 lines

Hi Sean

Quoted 32 lines · Rick Chen
Quoted 19 lines

Hi Tom

Quoted 9 lines

This patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.

The board does not boot unless CONSOLE_LOGLEVEL is set to a non-default value . It also boots when the tree is dirty (and CONSOLE_LOGLEVEL is not changed). It also boots when changes are made to the device tree and then committed. I don't know why this happens. These breakages only occur after bf2fb81ad3.

Quoted 7 lines

---

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.

Quoted 4 lines

Would you like to pick up this series, [PATCH v5 00/11] riscv: Add FPIOA and GPIO support for Kendryte K210 ?
Or maybe it is better to figure out what is wrong here and find the root cause why it need to Increase CONSOLE_LOGLEVEL to 5 as a hack ?

As an additional note, *CONFIG_LOGLEVEL (whoops) can also be decreased for the same effect. In addition, there are several other ways I found to "fix" this bug (as noted in the commit message). If you would like to test this out, I have two trees [1, 2] where this series (actually a slightly earlier version of this series) is applied just before and just after bf2fb81ad3. The original patch is located at [3].

Quoted 5 lines

--Sean

[1] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_good
[2] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_bad
[3] https://patchwork.ozlabs.org/project/uboot/patch/20200724111225.12513-15-ovidiu.panait at windriver.com/

Quoted 8 lines

I don't have a K210 board for verification.
But it is OK to run in AE350 board after applying your series.

After check about this commit "common/board_r: Remove initr_serial wrapper", it seem shall not affect anything.
It just change to call serial_initialize directly.
Only I can think about maybe it is a cache problem.
Just like sometime we add a printf, then the problem will be walk around.

Quoted 4 lines

Can you dig in to find the root cause ?
For code stability, it is better not to have any unknown issue. Yo can dirty hack and work around currently, but it may crash again after several commits.

Quoted 8 lines

Ok, so I did some further digging, but I was unable to pin down the cause of the bug. My efforts to determine a cause have been primarily thwarted because the bug disappears after any change to initialization code. Adding any function to init_sequence_f or init_sequence_r, even a no-op function which just returns 0, causes the board to boot normally. In addition, adding a nop() to any function in those sequences will cause the board to boot normally. The board seems to fail to boot only with a very specific boot sequence and timing.

If you modify any code and the result will change, then you shall debug it via debugger(GDB) without any code modification.

Quoted 2 lines

When the board fails to boot, it hangs in a manner similar to when the

Maybe you can try to set a break and access the bus, if the bus access fail, then you re-set a break a bit ahead until the bus access NOT fail.
To see if this way can pin down which instruction or the crucial code to cause the bus hang problem. And guess what maybe the root-cause.

Quoted 3 lines

If you can find the instruction which may cause the bus hang, you can info all-registers and compare the differences between NG and OK. And guess what maybe the root-cause.

Trying to narrow down on the problem I found the following:

The system hangs before arch_cpu_init_dm() is called.

After adding some debug functions the error appeared and disappeared when changing the code in function panic(). So my guess is that there is some alignment problem in the static data section.

Best regards

Heinrich

Quoted 13 lines

Thanks,
Rick

Quoted 9 lines

airam is accessed: the bus appears to hang. Just as when airam is accessed, a debugger cannot read registers or memory until the cpu is reset. This may be a separate issue which hangs the bus, or it could also be caused by an inadvertent access to airam. The puzzling thing is still the manner of triggering the bug. It's almost as if it was specifically designed to be impossible to debug by disappearing whenever one makes an attempt...

--Sean

#25 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

Quoted 73 lines · Heinrich Schuchardt
Quoted 72 lines · Rick Chen

Hi Sean

Quoted 57 lines · Rick Chen
Quoted 51 lines

Hi Sean

Quoted 40 lines

Hi Sean

Quoted 32 lines · Rick Chen
Quoted 19 lines

Hi Tom

Quoted 9 lines

This patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.

The board does not boot unless CONSOLE_LOGLEVEL is set to a non-default value . It also boots when the tree is dirty (and CONSOLE_LOGLEVEL is not changed). It also boots when changes are made to the device tree and then committed. I don't know why this happens. These breakages only occur after bf2fb81ad3.

Quoted 7 lines

---

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.

Quoted 4 lines

Would you like to pick up this series, [PATCH v5 00/11] riscv: Add FPIOA and GPIO support for Kendryte K210 ?
Or maybe it is better to figure out what is wrong here and find the root cause why it need to Increase CONSOLE_LOGLEVEL to 5 as a hack ?

As an additional note, *CONFIG_LOGLEVEL (whoops) can also be decreased for the same effect. In addition, there are several other ways I found to "fix" this bug (as noted in the commit message). If you would like to test this out, I have two trees [1, 2] where this series (actually a slightly earlier version of this series) is applied just before and just after bf2fb81ad3. The original patch is located at [3].

Quoted 5 lines

--Sean

[1] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_good
[2] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_bad
[3] https://patchwork.ozlabs.org/project/uboot/patch/20200724111225.12513-15-ovidiu.panait at windriver.com/

Quoted 8 lines

I don't have a K210 board for verification.
But it is OK to run in AE350 board after applying your series.

After check about this commit "common/board_r: Remove initr_serial wrapper", it seem shall not affect anything.
It just change to call serial_initialize directly.
Only I can think about maybe it is a cache problem.
Just like sometime we add a printf, then the problem will be walk around.

Quoted 4 lines

Can you dig in to find the root cause ?
For code stability, it is better not to have any unknown issue. Yo can dirty hack and work around currently, but it may crash again after several commits.

Quoted 8 lines

Ok, so I did some further digging, but I was unable to pin down the cause of the bug. My efforts to determine a cause have been primarily thwarted because the bug disappears after any change to initialization code. Adding any function to init_sequence_f or init_sequence_r, even a no-op function which just returns 0, causes the board to boot normally. In addition, adding a nop() to any function in those sequences will cause the board to boot normally. The board seems to fail to boot only with a very specific boot sequence and timing.

If you modify any code and the result will change, then you shall debug it via debugger(GDB) without any code modification.

Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

When the board fails to boot, it hangs in a manner similar to when the

Maybe you can try to set a break and access the bus, if the bus access fail, then you re-set a break a bit ahead until the bus access NOT fail.

Yeah, I was investigating that, however I was unable to get the k210 to break at 0x80000000. I suspect this may be a problem with openocd, as the k210 port is rather buggy (e.g. it can cause address misaligned errors, and sometimes leaves the pc in the debug dection of memory). I *can* get it to break in the otp (0x88000000), so perhaps I just need to identify the address before it jumps to U-Boot.

Quoted 10 lines
Quoted 6 lines

To see if this way can pin down which instruction or the crucial code to cause the bus hang problem. And guess what maybe the root-cause.

If you can find the instruction which may cause the bus hang, you can info all-registers and compare the differences between NG and OK. And guess what maybe the root-cause.

Trying to narrow down on the problem I found the following:

The system hangs before arch_cpu_init_dm() is called.

This is not always the case. On most boots, the following output is present:

U-Boot 2020.10-rc3-00045-g7532b003f0 (Sep 02 2020 - 11:09:16 -0400)

DRAM: 8 MiB

which means at least everything up to dram_init gets called.

Quoted 4 lines

After adding some debug functions the error appeared and disappeared when changing the code in function panic(). So my guess is that there is some alignment problem in the static data section.

I investigated this further using the following script

while true; do

	sed -i 's/nop();$/nop(); nop();/g' board/sipeed/maix/maix.c &&
	git commit --amend --no-edit board/sipeed/maix/maix.c &&
	CROSS_COMPILE=riscv64-linux-gnu- make -j$(nproc) &&
	kflash -tp /dev/ttyUSB0 -B bit_mic -b 1500000 u-boot-dtb.bin"

done

To start this process, create a commit which adds a nop() to board/sipeed/maix/maix.c. On every iteration, this script will amend that commit by adding another nop. I tried up to 65 nops. If the amount of nops is 0, 24, 28, 29, 30, 31, 32, 40, 44, 46, 49, 56, 60, 61, 62, 63, or 64 the board fails to boot. Of these failures, all printed up to "DRAM: ..." except for those with 28, 29, 30, 31, 60, 61, 62, or 64 nops. There is clearly a pattern whith failures occuring at or near (but not always exactly on) multiples of 4, and in the lead-up to multiples of 32.

My next line of investigation will be to determine the size and alignment of the various sections based in the failing configurations. I also plan to try enabling more debug info and see if I can trigger this issue by adding some choice no-ops.

--Sean

#26 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

Quoted 14 lines · Sean Anderson
Quoted 3 lines · Heinrich Schuchardt

After adding some debug functions the error appeared and disappeared when changing the code in function panic(). So my guess is that there is some alignment problem in the static data section.

I investigated this further using the following script

while true; do

	sed -i 's/nop();$/nop(); nop();/g' board/sipeed/maix/maix.c &&
	git commit --amend --no-edit board/sipeed/maix/maix.c &&
	CROSS_COMPILE=riscv64-linux-gnu- make -j$(nproc) &&
	kflash -tp /dev/ttyUSB0 -B bit_mic -b 1500000 u-boot-dtb.bin"

done

Quoted 9 lines

To start this process, create a commit which adds a nop() to board/sipeed/maix/maix.c. On every iteration, this script will amend that commit by adding another nop. I tried up to 65 nops. If the amount of nops is 0, 24, 28, 29, 30, 31, 32, 40, 44, 46, 49, 56, 60, 61, 62, 63, or 64 the board fails to boot. Of these failures, all printed up to "DRAM: ..." except for those with 28, 29, 30, 31, 60, 61, 62, or 64 nops. There is clearly a pattern whith failures occuring at or near (but not always exactly on) multiples of 4, and in the lead-up to multiples of 32.

These patterns cause two different bugs, which I will refer to as the "multiple-of-four" bug and the "periodic-32" bug.

The multiple-of-four bug is fixed by [1]. This bug is not present in u-boot/master atm, but I am not sure why. Perhaps adding more drivers which depend on the device tree triggers the behavior.

Quoted 12 lines
Quoted 11 lines · Rick Chen
Quoted 6 lines

To see if this way can pin down which instruction or the crucial code to cause the bus hang problem. And guess what maybe the root-cause.

If you can find the instruction which may cause the bus hang, you can info all-registers and compare the differences between NG and OK. And guess what maybe the root-cause.

Trying to narrow down on the problem I found the following:

The system hangs before arch_cpu_init_dm() is called.

Quoted 8 lines

This is not always the case. On most boots, the following output is present:

U-Boot 2020.10-rc3-00045-g7532b003f0 (Sep 02 2020 - 11:09:16 -0400)

DRAM: 8 MiB

which means at least everything up to dram_init gets called.

This output is symptomatic of the multiple-of-four bug. After applying [1], either a successful boot should take place, or there should be no output at all (corresponding to the periodic-32 bug).

Quoted 11 lines
Quoted 4 lines
Quoted 4 lines

Maybe you can try to set a break and access the bus, if the bus access fail, then you re-set a break a bit ahead until the bus access NOT fail.

Yeah, I was investigating that, however I was unable to get the k210 to break at 0x80000000. I suspect this may be a problem with openocd, as the k210 port is rather buggy (e.g. it can cause address misaligned errors, and sometimes leaves the pc in the debug dection of memory). I *can* get it to break in the otp (0x88000000), so perhaps I just need to identify the address before it jumps to U-Boot.

When attempting to boot with a U-boot which has the periodic-32 bug, there is no output, even with an early uart and debug logs enabled. I have tried using two versions of openocd to determine the cause. The kendryte openocd [2] supports attaching to either core of the k210, but must be restarted to debug the other core. It also keeps the non-debugged core halted. The riscv openocd [3] only supports debugging core 0. However, it contains numerous bugfixes and improvements which the kendryte openocd does not contain.

When attaching the kendryte openocd, the following output (among other things) is printed:

Core [1] halted at 0x80015590 due to debug interrupt Core [0] halted at 0x88008c00 due to debug interrupt

The core 1's pc is located within _sifive_serial_putc, and this is reflected by the console containing a partially-printed announcement for the first printed initcall. This initcall is initf_bootstage, which is the first initcall after log_init. If openocd is attached to core 1, and it is resumed, then U-Boot boots as normal (in contrast to the behavior exhibited if openocd is not attached).

What is more interesting is the pc of core 0. It is located in the boot rom of the K210. According to [4] (and as verified by myself), this address corresponds with the uarths_getc function. This function is only called by isp_run. This means core 0 is stuck in ISP mode, which is used to flash firmware.

Attaching a debugger clearly affects the boot process of this core, but I am not sure in what manner. I am attempting to modify the riscv openocd to support multiple cores, but it is slow going (there is a lot of undocumented code with side-effects).

--Sean

[1] https://patchwork.ozlabs.org/project/uboot/patch/20200905132211.412711-1-seanga2 at gmail.com/
[2] https://github.com/kendryte/openocd-kendryte
[3] https://github.com/riscv/riscv-openocd
[4] https://github.com/kelas/k210-sdk-stuff/blob/master/rom/k210.rom.h

A message that is not in the archive (sent off-list or not yet received): [email protected]

#28 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

Hi Sean and all,

Sorry for dropping this mail out of the blue.

I'm trying to follow the instrcutions from doc/board/sipeed/maix.rst to build and flash u-boot so as to verify Sean's work on maix_gpio_good tree.

Yet the console has no output.

Furthermore, I found the documentation on Sipeed board to be a little bit confusing. In your first commit of that document, it's stated that "only the Sipeed MAIX BiT V2.0 (bitm) and Sipeed MAIXDUINO are supported."
Yet the later commit (137dc15) added a table which implies that the older version of MAIX BiT is supported. So I'm a bit confused about whether older MAIX BiTs get supported or not ? (I'm testing the builts on the older version.)
Does the replacement of CH34x with CH552 may cause the issue I'm encountering ?

By the way, I was trying to use the pre-built toolchain from kendryte's GitHub [1]. Yet the linker (riscv64-unknown-elf-ld.bfd) complains that -pie is not supported. Hence I switched to the the binutils v2.34 built from upstream and the u-boot could be built without that hiccup.

Could someone tell me which toolchain is recommended for building the u-boot for boards Kendryte K210 ?

[1] https://github.com/kendryte/kendryte-gnu-toolchainhttps://github.com/kendryte/kendryte-gnu-toolchain

Many thanks,
Ruinland

Quoted 46 lines · Rick Jian-Zhi Chen(???)

-----Original Message-----
From: Sean Anderson [mailto:seanga2 at gmail.com]
Sent: Wednesday, August 19, 2020 7:13 PM
To: Rick Chen
Cc: U-Boot Mailing List; Simon Glass; Tom Rini; Bin Meng; Rick Jian-Zhi Chen(???); Alan Quey-Liang Kao(???)
Subject: Re: [PATCH v5 11/11] riscv: Add FPIOA and GPIO support for Kendryte K210

Quoted 19 lines · Rick Chen

Hi Tom

Quoted 9 lines

This patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.

The board does not boot unless CONSOLE_LOGLEVEL is set to a non-default value . It also boots when the tree is dirty (and CONSOLE_LOGLEVEL is not changed). It also boots when changes are made to the device tree and then committed. I don't know why this happens. These breakages only occur after bf2fb81ad3.

Quoted 7 lines

---

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.

Quoted 4 lines

Would you like to pick up this series, [PATCH v5 00/11] riscv: Add FPIOA and GPIO support for Kendryte K210 ?
Or maybe it is better to figure out what is wrong here and find the root cause why it need to Increase CONSOLE_LOGLEVEL to 5 as a hack ?

As an additional note, *CONFIG_LOGLEVEL (whoops) can also be decreased for the same effect. In addition, there are several other ways I found to "fix" this bug (as noted in the commit message). If you would like to test this out, I have two trees [1, 2] where this series (actually a slightly earlier version of this series) is applied just before and just after bf2fb81ad3. The original patch is located at [3].

--Sean

[1] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_good
[2] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_bad
[3] https://patchwork.ozlabs.org/project/uboot/patch/20200724111225.12513-15-ovidiu.panait at windriver.com/

#29 lore raw

PATCH v5 11/11 riscv: Add FPIOA and GPIO support for Kendryte K210

Quoted 4 lines · Ruinland ChuanTzu Tsai

Hi Sean and all,

Sorry for dropping this mail out of the blue.

Quoted 8 lines

I'm trying to follow the instrcutions from doc/board/sipeed/maix.rst to build and flash u-boot so as to verify Sean's work on maix_gpio_good tree.

Yet the console has no output.

Furthermore, I found the documentation on Sipeed board to be a little bit confusing. In your first commit of that document, it's stated that "only the Sipeed MAIX BiT V2.0 (bitm) and Sipeed MAIXDUINO are supported."

Those are the only boards I have, so those are all that I can support.

Quoted 3 lines

Yet the later commit (137dc15) added a table which implies that the older version of MAIX BiT is supported. So I'm a bit confused about whether older MAIX BiTs get supported or not ? (I'm testing the builts on the older version.)

It *should* work, but I haven't tested anything on a bit v1. Have you tried booting with v2020.07? That release should have the bare minimum needed to get things working.

Quoted 1 line

Does the replacement of CH34x with CH552 may cause the issue I'm encountering ?

Probably not.

Quoted 5 lines

By the way, I was trying to use the pre-built toolchain from kendryte's GitHub [1]. Yet the linker (riscv64-unknown-elf-ld.bfd) complains that -pie is not supported. Hence I switched to the the binutils v2.34 built from upstream and the u-boot could be built without that hiccup.

I have been using the toolchain which comes with my distro (riscv64-linux-gnu-* on Arch). I don't know whether that makes much difference, but I have never used Canaan's pre-build toolchain.

--Sean

Quoted 56 lines

Could someone tell me which toolchain is recommended for building the u-boot for boards Kendryte K210 ?

[1] https://github.com/kendryte/kendryte-gnu-toolchainhttps://github.com/kendryte/kendryte-gnu-toolchain

Many thanks,
Ruinland

Quoted 46 lines · Rick Jian-Zhi Chen(???)

-----Original Message-----
From: Sean Anderson [mailto:seanga2 at gmail.com]
Sent: Wednesday, August 19, 2020 7:13 PM
To: Rick Chen
Cc: U-Boot Mailing List; Simon Glass; Tom Rini; Bin Meng; Rick Jian-Zhi Chen(???); Alan Quey-Liang Kao(???)
Subject: Re: [PATCH v5 11/11] riscv: Add FPIOA and GPIO support for Kendryte K210

Quoted 19 lines · Rick Chen

Hi Tom

Quoted 9 lines

This patch adds the necessary configs and docs for FPIOA and GPIO support on the K210.

The board does not boot unless CONSOLE_LOGLEVEL is set to a non-default value . It also boots when the tree is dirty (and CONSOLE_LOGLEVEL is not changed). It also boots when changes are made to the device tree and then committed. I don't know why this happens. These breakages only occur after bf2fb81ad3.

Quoted 7 lines

---

Changes in v5:
- Increase CONSOLE_LOGLEVEL to 5 as a hack to get the board booting again
- Patch 05/12 "gpio: sifive: Use generic reg read function" has been superseded by commit 2548493ab4.

Quoted 4 lines

Would you like to pick up this series, [PATCH v5 00/11] riscv: Add FPIOA and GPIO support for Kendryte K210 ?
Or maybe it is better to figure out what is wrong here and find the root cause why it need to Increase CONSOLE_LOGLEVEL to 5 as a hack ?

As an additional note, *CONFIG_LOGLEVEL (whoops) can also be decreased for the same effect. In addition, there are several other ways I found to "fix" this bug (as noted in the commit message). If you would like to test this out, I have two trees [1, 2] where this series (actually a slightly earlier version of this series) is applied just before and just after bf2fb81ad3. The original patch is located at [3].

--Sean

[1] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_good
[2] https://github.com/Forty-Bot/u-boot/tree/maix_gpio_bad
[3] https://patchwork.ozlabs.org/project/uboot/patch/20200724111225.12513-15-ovidiu.panait at windriver.com/