2
0

820-libata-Assign-OF-node-to-the-SCSI-device.patch 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From 43a93893eb33e996836b99fb3e1f7300c0132a51 Mon Sep 17 00:00:00 2001
  2. From: Linus Walleij <[email protected]>
  3. Date: Tue, 31 Dec 2019 18:15:33 +0100
  4. Subject: [PATCH 5/7] libata: Assign OF node to the SCSI device
  5. When we spawn a SCSI device from an ATA device in libata-scsi
  6. the SCSI device had no relation to the device tree.
  7. The DT binding allows us to define port nodes under a
  8. PATA (IDE) or SATA host controller, so we can have proper device
  9. nodes for these devices.
  10. If OF is enabled, walk the children of the host controller node
  11. to see if there is a valid device tree node to assign. The reg
  12. is used to match to ID 0 for the master device and ID 1 for the
  13. slave device.
  14. The corresponding device tree bindings have been accepted by
  15. the device tree maintainers.
  16. Cc: Chris Healy <[email protected]>
  17. Cc: Martin K. Petersen <[email protected]>
  18. Cc: Bart Van Assche <[email protected]>
  19. Cc: Guenter Roeck <[email protected]>
  20. Signed-off-by: Linus Walleij <[email protected]>
  21. ---
  22. ChangeLog v1->v2:
  23. - Use dev_dbg() for the debug print
  24. - return immediately after finding a matching OF node
  25. ---
  26. drivers/ata/libata-scsi.c | 30 ++++++++++++++++++++++++++++++
  27. 1 file changed, 30 insertions(+)
  28. --- a/drivers/ata/libata-scsi.c
  29. +++ b/drivers/ata/libata-scsi.c
  30. @@ -35,6 +35,7 @@
  31. #include <linux/suspend.h>
  32. #include <asm/unaligned.h>
  33. #include <linux/ioprio.h>
  34. +#include <linux/of.h>
  35. #include "libata.h"
  36. #include "libata-transport.h"
  37. @@ -4579,6 +4580,34 @@ int ata_scsi_add_hosts(struct ata_host *
  38. return rc;
  39. }
  40. +#ifdef CONFIG_OF
  41. +static void ata_scsi_assign_ofnode(struct ata_device *dev, struct ata_port *ap)
  42. +{
  43. + struct scsi_device *sdev = dev->sdev;
  44. + struct device *d = ap->host->dev;
  45. + struct device_node *np = d->of_node;
  46. + struct device_node *child;
  47. +
  48. + for_each_available_child_of_node(np, child) {
  49. + int ret;
  50. + u32 val;
  51. +
  52. + ret = of_property_read_u32(child, "reg", &val);
  53. + if (ret)
  54. + continue;
  55. + if (val == dev->devno) {
  56. + dev_dbg(d, "found matching device node\n");
  57. + sdev->sdev_gendev.of_node = child;
  58. + return;
  59. + }
  60. + }
  61. +}
  62. +#else
  63. +static void ata_scsi_assign_ofnode(struct ata_device *dev, struct ata_port *ap)
  64. +{
  65. +}
  66. +#endif
  67. +
  68. void ata_scsi_scan_host(struct ata_port *ap, int sync)
  69. {
  70. int tries = 5;
  71. @@ -4604,6 +4633,7 @@ void ata_scsi_scan_host(struct ata_port
  72. NULL);
  73. if (!IS_ERR(sdev)) {
  74. dev->sdev = sdev;
  75. + ata_scsi_assign_ofnode(dev, ap);
  76. scsi_device_put(sdev);
  77. } else {
  78. dev->sdev = NULL;