pl111_vexpress.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Versatile Express PL111 handling
  4. * Copyright (C) 2018 Linus Walleij
  5. *
  6. * This module binds to the "arm,vexpress-muxfpga" device on the
  7. * Versatile Express configuration bus and sets up which CLCD instance
  8. * gets muxed out on the DVI bridge.
  9. */
  10. #include <linux/device.h>
  11. #include <linux/module.h>
  12. #include <linux/regmap.h>
  13. #include <linux/vexpress.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_platform.h>
  18. #include "pl111_drm.h"
  19. #include "pl111_vexpress.h"
  20. #define VEXPRESS_FPGAMUX_MOTHERBOARD 0x00
  21. #define VEXPRESS_FPGAMUX_DAUGHTERBOARD_1 0x01
  22. #define VEXPRESS_FPGAMUX_DAUGHTERBOARD_2 0x02
  23. int pl111_vexpress_clcd_init(struct device *dev,
  24. struct pl111_drm_dev_private *priv,
  25. struct regmap *map)
  26. {
  27. struct device_node *root;
  28. struct device_node *child;
  29. struct device_node *ct_clcd = NULL;
  30. bool has_coretile_clcd = false;
  31. bool has_coretile_hdlcd = false;
  32. bool mux_motherboard = true;
  33. u32 val;
  34. int ret;
  35. /*
  36. * Check if we have a CLCD or HDLCD on the core tile by checking if a
  37. * CLCD or HDLCD is available in the root of the device tree.
  38. */
  39. root = of_find_node_by_path("/");
  40. if (!root)
  41. return -EINVAL;
  42. for_each_available_child_of_node(root, child) {
  43. if (of_device_is_compatible(child, "arm,pl111")) {
  44. has_coretile_clcd = true;
  45. ct_clcd = child;
  46. break;
  47. }
  48. if (of_device_is_compatible(child, "arm,hdlcd")) {
  49. has_coretile_hdlcd = true;
  50. break;
  51. }
  52. }
  53. /*
  54. * If there is a coretile HDLCD and it has a driver,
  55. * do not mux the CLCD on the motherboard to the DVI.
  56. */
  57. if (has_coretile_hdlcd && IS_ENABLED(CONFIG_DRM_HDLCD))
  58. mux_motherboard = false;
  59. /*
  60. * On the Vexpress CA9 we let the CLCD on the coretile
  61. * take precedence, so also in this case do not mux the
  62. * motherboard to the DVI.
  63. */
  64. if (has_coretile_clcd)
  65. mux_motherboard = false;
  66. if (mux_motherboard) {
  67. dev_info(dev, "DVI muxed to motherboard CLCD\n");
  68. val = VEXPRESS_FPGAMUX_MOTHERBOARD;
  69. } else if (ct_clcd == dev->of_node) {
  70. dev_info(dev,
  71. "DVI muxed to daughterboard 1 (core tile) CLCD\n");
  72. val = VEXPRESS_FPGAMUX_DAUGHTERBOARD_1;
  73. } else {
  74. dev_info(dev, "core tile graphics present\n");
  75. dev_info(dev, "this device will be deactivated\n");
  76. return -ENODEV;
  77. }
  78. ret = regmap_write(map, 0, val);
  79. if (ret) {
  80. dev_err(dev, "error setting DVI muxmode\n");
  81. return -ENODEV;
  82. }
  83. return 0;
  84. }
  85. /*
  86. * This sets up the regmap pointer that will then be retrieved by
  87. * the detection code in pl111_versatile.c and passed in to the
  88. * pl111_vexpress_clcd_init() function above.
  89. */
  90. static int vexpress_muxfpga_probe(struct platform_device *pdev)
  91. {
  92. struct device *dev = &pdev->dev;
  93. struct regmap *map;
  94. map = devm_regmap_init_vexpress_config(&pdev->dev);
  95. if (IS_ERR(map))
  96. return PTR_ERR(map);
  97. dev_set_drvdata(dev, map);
  98. return 0;
  99. }
  100. static const struct of_device_id vexpress_muxfpga_match[] = {
  101. { .compatible = "arm,vexpress-muxfpga", }
  102. };
  103. static struct platform_driver vexpress_muxfpga_driver = {
  104. .driver = {
  105. .name = "vexpress-muxfpga",
  106. .of_match_table = of_match_ptr(vexpress_muxfpga_match),
  107. },
  108. .probe = vexpress_muxfpga_probe,
  109. };
  110. int vexpress_muxfpga_init(void)
  111. {
  112. int ret;
  113. ret = platform_driver_register(&vexpress_muxfpga_driver);
  114. /* -EBUSY just means this driver is already registered */
  115. if (ret == -EBUSY)
  116. ret = 0;
  117. return ret;
  118. }