dc-tc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2024 NXP
  4. */
  5. #include <linux/component.h>
  6. #include <linux/mod_devicetable.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/regmap.h>
  10. #include "dc-drv.h"
  11. #include "dc-de.h"
  12. #define TCON_CTRL 0x410
  13. #define CTRL_RST_VAL 0x01401408
  14. /* red: MAPBIT 29-20, green: MAPBIT 19-10, blue: MAPBIT 9-0 */
  15. #define MAPBIT3_0 0x418
  16. #define MAPBIT7_4 0x41c
  17. #define MAPBIT11_8 0x420
  18. #define MAPBIT15_12 0x424
  19. #define MAPBIT19_16 0x428
  20. #define MAPBIT23_20 0x42c
  21. #define MAPBIT27_24 0x430
  22. #define MAPBIT31_28 0x434
  23. static const struct dc_subdev_info dc_tc_info[] = {
  24. { .reg_start = 0x5618c800, .id = 0, },
  25. { .reg_start = 0x5618e400, .id = 1, },
  26. };
  27. static const struct regmap_range dc_tc_regmap_ranges[] = {
  28. regmap_reg_range(TCON_CTRL, TCON_CTRL),
  29. regmap_reg_range(MAPBIT3_0, MAPBIT31_28),
  30. };
  31. static const struct regmap_access_table dc_tc_regmap_access_table = {
  32. .yes_ranges = dc_tc_regmap_ranges,
  33. .n_yes_ranges = ARRAY_SIZE(dc_tc_regmap_ranges),
  34. };
  35. static const struct regmap_config dc_tc_regmap_config = {
  36. .reg_bits = 32,
  37. .reg_stride = 4,
  38. .val_bits = 32,
  39. .fast_io = true,
  40. .wr_table = &dc_tc_regmap_access_table,
  41. .rd_table = &dc_tc_regmap_access_table,
  42. .max_register = MAPBIT31_28,
  43. };
  44. /*
  45. * The pixels reach TCON are always in 30-bit BGR format.
  46. * The first bridge always receives pixels in 30-bit RGB format.
  47. * So, map the format to MEDIA_BUS_FMT_RGB101010_1X30.
  48. */
  49. static const u32 dc_tc_mapbit[] = {
  50. 0x17161514, 0x1b1a1918, 0x0b0a1d1c, 0x0f0e0d0c,
  51. 0x13121110, 0x03020100, 0x07060504, 0x00000908,
  52. };
  53. void dc_tc_init(struct dc_tc *tc)
  54. {
  55. /* reset TCON_CTRL to POR default so that TCON works in bypass mode */
  56. regmap_write(tc->reg, TCON_CTRL, CTRL_RST_VAL);
  57. /* set format */
  58. regmap_bulk_write(tc->reg, MAPBIT3_0, dc_tc_mapbit,
  59. ARRAY_SIZE(dc_tc_mapbit));
  60. }
  61. static int dc_tc_bind(struct device *dev, struct device *master, void *data)
  62. {
  63. struct platform_device *pdev = to_platform_device(dev);
  64. struct dc_drm_device *dc_drm = data;
  65. struct resource *res;
  66. void __iomem *base;
  67. struct dc_tc *tc;
  68. int id;
  69. tc = devm_kzalloc(dev, sizeof(*tc), GFP_KERNEL);
  70. if (!tc)
  71. return -ENOMEM;
  72. base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
  73. if (IS_ERR(base))
  74. return PTR_ERR(base);
  75. tc->reg = devm_regmap_init_mmio(dev, base, &dc_tc_regmap_config);
  76. if (IS_ERR(tc->reg))
  77. return PTR_ERR(tc->reg);
  78. id = dc_subdev_get_id(dc_tc_info, ARRAY_SIZE(dc_tc_info), res);
  79. if (id < 0) {
  80. dev_err(dev, "failed to get instance number: %d\n", id);
  81. return id;
  82. }
  83. tc->dev = dev;
  84. dc_drm->tc[id] = tc;
  85. return 0;
  86. }
  87. static const struct component_ops dc_tc_ops = {
  88. .bind = dc_tc_bind,
  89. };
  90. static int dc_tc_probe(struct platform_device *pdev)
  91. {
  92. int ret;
  93. ret = component_add(&pdev->dev, &dc_tc_ops);
  94. if (ret)
  95. return dev_err_probe(&pdev->dev, ret,
  96. "failed to add component\n");
  97. return 0;
  98. }
  99. static void dc_tc_remove(struct platform_device *pdev)
  100. {
  101. component_del(&pdev->dev, &dc_tc_ops);
  102. }
  103. static const struct of_device_id dc_tc_dt_ids[] = {
  104. { .compatible = "fsl,imx8qxp-dc-tcon" },
  105. { /* sentinel */ }
  106. };
  107. MODULE_DEVICE_TABLE(of, dc_tc_dt_ids);
  108. struct platform_driver dc_tc_driver = {
  109. .probe = dc_tc_probe,
  110. .remove = dc_tc_remove,
  111. .driver = {
  112. .name = "imx8-dc-tcon",
  113. .suppress_bind_attrs = true,
  114. .of_match_table = dc_tc_dt_ids,
  115. },
  116. };