Documentation/driver-api/gpio/legacy-boards.rst

Source file repositories/reference/linux-study-clean/Documentation/driver-api/gpio/legacy-boards.rst

File Facts

System
Linux kernel
Corpus path
Documentation/driver-api/gpio/legacy-boards.rst
Extension
.rst
Size
9982 bytes
Lines
317
Domain
Support Tooling And Documentation
Bucket
Documentation
Inferred role
Support Tooling And Documentation: documentation
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (error) {
  		pr_err("Failed to register software nodes: %d\n", error);
  		return error;
  	}

  	// ... platform device registration follows
  }

.. note::
  When splitting registration of nodes by devices that they represent, it is
  essential that the software node representing the GPIO controller itself
  is registered first, before any of the nodes that reference it.

Step 4: Register Platform Devices with Software Nodes
*****************************************************

Finally, register the platform devices and associate them with their respective
software nodes using the ``fwnode`` field in struct platform_device_info.

.. code-block:: c

  static struct platform_device *leds_pdev;
  static struct platform_device *keys_pdev;

  static int __init myboard_init(void)
  {
  	struct platform_device_info pdev_info;
  	int error;

  	error = software_node_register_node_group(myboard_swnodes);
  	if (error)
  		return error;

  	memset(&pdev_info, 0, sizeof(pdev_info));
  	pdev_info.name = MYBOARD_GPIO_CONTROLLER;
  	pdev_info.id = PLATFORM_DEVID_NONE;
  	pdev_info.swnode = &myboard_gpio_controller_node;
  	gpio_pdev = platform_device_register_full(&pdev_info);
  	if (IS_ERR(gpio_pdev)) {
  		error = PTR_ERR(gpio_pdev);
  		goto err_unregister_nodes;
  	}

  	memset(&pdev_info, 0, sizeof(pdev_info));
  	pdev_info.name = "leds-gpio";
  	pdev_info.id = PLATFORM_DEVID_NONE;
  	pdev_info.fwnode = software_node_fwnode(&myboard_leds_node);
  	leds_pdev = platform_device_register_full(&pdev_info);
  	if (IS_ERR(leds_pdev)) {
  		error = PTR_ERR(leds_pdev);
  		platform_device_unregister(gpio_pdev);
  		goto err_unregister_nodes;
  	}

  	memset(&pdev_info, 0, sizeof(pdev_info));
  	pdev_info.name = "gpio-keys";
  	pdev_info.id = PLATFORM_DEVID_NONE;
  	pdev_info.fwnode = software_node_fwnode(&myboard_keys_node);
  	keys_pdev = platform_device_register_full(&pdev_info);
  	if (IS_ERR(keys_pdev)) {
  		error = PTR_ERR(keys_pdev);
  		platform_device_unregister(gpio_pdev);
  		platform_device_unregister(leds_pdev);
  		goto err_unregister_nodes;
  	}

  	return 0;

  err_unregister_nodes:
  	software_node_unregister_node_group(myboard_swnodes);

Annotation

Implementation Notes