sandbox_dsi_host.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
  2. /*
  3. * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
  4. */
  5. #include <common.h>
  6. #include <display.h>
  7. #include <dm.h>
  8. #include <dsi_host.h>
  9. /**
  10. * struct sandbox_dsi_host_priv - private data for driver
  11. * @device: DSI peripheral device
  12. * @timing: Display timings
  13. * @max_data_lanes: maximum number of data lines
  14. * @phy_ops: set of function pointers for performing physical operations
  15. */
  16. struct sandbox_dsi_host_priv {
  17. struct mipi_dsi_device *device;
  18. struct display_timing *timings;
  19. unsigned int max_data_lanes;
  20. const struct mipi_dsi_phy_ops *phy_ops;
  21. };
  22. static int sandbox_dsi_host_init(struct udevice *dev,
  23. struct mipi_dsi_device *device,
  24. struct display_timing *timings,
  25. unsigned int max_data_lanes,
  26. const struct mipi_dsi_phy_ops *phy_ops)
  27. {
  28. struct sandbox_dsi_host_priv *priv = dev_get_priv(dev);
  29. if (!device)
  30. return -1;
  31. if (!timings)
  32. return -2;
  33. if (max_data_lanes == 0)
  34. return -3;
  35. if (!phy_ops)
  36. return -4;
  37. if (!phy_ops->init || !phy_ops->get_lane_mbps ||
  38. !phy_ops->post_set_mode)
  39. return -5;
  40. priv->max_data_lanes = max_data_lanes;
  41. priv->phy_ops = phy_ops;
  42. priv->timings = timings;
  43. priv->device = device;
  44. return 0;
  45. }
  46. static int sandbox_dsi_host_enable(struct udevice *dev)
  47. {
  48. struct sandbox_dsi_host_priv *priv = dev_get_priv(dev);
  49. unsigned int lane_mbps;
  50. int ret;
  51. priv->phy_ops->init(priv->device);
  52. ret = priv->phy_ops->get_lane_mbps(priv->device, priv->timings, 2,
  53. MIPI_DSI_FMT_RGB888, &lane_mbps);
  54. if (ret)
  55. return -1;
  56. priv->phy_ops->post_set_mode(priv->device, MIPI_DSI_MODE_VIDEO);
  57. return 0;
  58. }
  59. struct dsi_host_ops sandbox_dsi_host_ops = {
  60. .init = sandbox_dsi_host_init,
  61. .enable = sandbox_dsi_host_enable,
  62. };
  63. static const struct udevice_id sandbox_dsi_host_ids[] = {
  64. { .compatible = "sandbox,dsi-host"},
  65. { }
  66. };
  67. U_BOOT_DRIVER(sandbox_dsi_host) = {
  68. .name = "sandbox-dsi-host",
  69. .id = UCLASS_DSI_HOST,
  70. .of_match = sandbox_dsi_host_ids,
  71. .ops = &sandbox_dsi_host_ops,
  72. .priv_auto = sizeof(struct sandbox_dsi_host_priv),
  73. };