drv_dc.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Email: opensource_embedded@phytium.com.cn
  7. *
  8. * Change Logs:
  9. * Date Author Notes
  10. * 2023-11-07 wangzongqiang first version
  11. *
  12. */
  13. #include <string.h>
  14. #include "rtconfig.h"
  15. #include <rtthread.h>
  16. #include <rtdevice.h>
  17. #define LOG_TAG "dc_drv"
  18. #include "mm_aspace.h"
  19. #include "drv_log.h"
  20. #include "drv_dc.h"
  21. #include "fparameters.h"
  22. #include "fdcdp.h"
  23. #include "fdc.h"
  24. #include "fdp_hw.h"
  25. #include "fdc_common_hw.h"
  26. #ifdef RT_USING_SMART
  27. #include "ioremap.h"
  28. #endif
  29. static rt_uint16_t _rt_framebuffer[1024 * 768 * 4] __aligned(128);
  30. static struct rt_device_graphic_info _dc_info;
  31. static rt_err_t dc_config(struct phytium_dc_bus *dc_control_bus)
  32. {
  33. RT_ASSERT(dc_control_bus);
  34. rt_uint32_t chan = dc_control_bus->fdc_id;
  35. FDcDp *instance_p = &dc_control_bus->dc_handle;
  36. return RT_EOK;
  37. }
  38. static rt_err_t rt_dc_init(struct phytium_dc_bus *device)
  39. {
  40. RT_ASSERT(device != RT_NULL);
  41. rt_err_t ret;
  42. FDcDp *instance_p = &device->dc_handle;
  43. FDcDpCfgInitialize(instance_p);
  44. rt_uint32_t chan = device->fdc_id;
  45. instance_p->user_config[chan].color_depth = DISPLAY_COLOR_DEPTH;
  46. instance_p->user_config[chan].width = FB_XSIZE;
  47. instance_p->user_config[chan].height = FB_YSIZE;
  48. instance_p->user_config[chan].refresh_rate = DISPLAY_REFRESH_RATE_60;
  49. instance_p->user_config[chan].multi_mode = 0;
  50. instance_p->user_config[chan].fb_phy = _rt_framebuffer;
  51. instance_p->user_config[chan].fb_virtual = _rt_framebuffer;
  52. instance_p->dc_instance_p[chan].config = *FDcLookupConfig(chan);
  53. instance_p->dp_instance_p[chan].config = *FDpLookupConfig(chan);
  54. #ifdef RT_USING_SMART
  55. instance_p->user_config[chan].fb_phy = instance_p->user_config[chan].fb_phy + PV_OFFSET;/*the FB addr iomap length is x_size * y_size * 4 */
  56. instance_p->dc_instance_p[chan].config.dcch_baseaddr = (uintptr)rt_ioremap((void *)instance_p->dc_instance_p[chan].config.dcch_baseaddr, 0x1000);/*the dc channel addr iomap length is 0x1000*/
  57. instance_p->dc_instance_p[chan].config.dcctrl_baseaddr = (uintptr)rt_ioremap((void *)instance_p->dc_instance_p[chan].config.dcctrl_baseaddr, 0x4000);/*the dc control addr iomap length is 0x4000*/
  58. instance_p->dp_instance_p[chan].config.dp_channe_base_addr = (uintptr)rt_ioremap((void *)instance_p->dp_instance_p[chan].config.dp_channe_base_addr, 0x4000); /*the dc control addr iomap length is 0x4000*/
  59. instance_p->dp_instance_p[chan].config.dp_phy_base_addr = (size_t)rt_ioremap((void *) instance_p->dp_instance_p[chan].config.dp_phy_base_addr, 0x100000);/*the dc control addr iomap length is 0x100000*/
  60. #endif
  61. _dc_info.bits_per_pixel = DISPLAY_COLOR_DEPTH;
  62. _dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
  63. _dc_info.framebuffer = (rt_uint8_t *)instance_p->user_config[chan].fb_virtual;
  64. _dc_info.width = FB_XSIZE;
  65. _dc_info.height = FB_YSIZE;
  66. rt_hw_dc_register(device, device->name, RT_DEVICE_FLAG_RDWR, NULL);
  67. dc_config(device);
  68. ret = FDcDpInitialize(instance_p, device->fdc_id);
  69. if (ret != RT_EOK)
  70. {
  71. LOG_E("Init dc failed, ret: 0x%x", ret);
  72. return -RT_ERROR;;
  73. }
  74. return RT_EOK;
  75. }
  76. static rt_err_t rt_dc_control(rt_device_t dev, int cmd, void *args)
  77. {
  78. RT_ASSERT(dev);
  79. struct phytium_dc_bus *dc_bus;
  80. dc_bus = (struct phytium_dc_bus *)(dev);
  81. switch (cmd)
  82. {
  83. case RTGRAPHIC_CTRL_RECT_UPDATE:
  84. break;
  85. case RTGRAPHIC_CTRL_POWERON:
  86. break;
  87. case RTGRAPHIC_CTRL_POWEROFF:
  88. break;
  89. case RTGRAPHIC_CTRL_GET_INFO:
  90. rt_memcpy(args, &_dc_info, sizeof(_dc_info));
  91. break;
  92. case RTGRAPHIC_CTRL_SET_MODE:
  93. break;
  94. }
  95. return RT_EOK;
  96. }
  97. #ifdef RT_USING_DEVICE_OPS
  98. const static struct rt_device_ops dc_ops =
  99. {
  100. rt_dc_init,
  101. RT_NULL,
  102. RT_NULL,
  103. RT_NULL,
  104. RT_NULL,
  105. rt_dc_control
  106. };
  107. #endif
  108. void rt_hw_dc_register(struct phytium_dc_bus *dc_control_bus, const char *name, rt_uint32_t flag, void *data)
  109. {
  110. RT_ASSERT(dc_control_bus != RT_NULL);
  111. struct rt_device *dc;
  112. dc = &(dc_control_bus->parent);
  113. dc->type = RT_Device_Class_Graphic;
  114. #ifdef RT_USING_DEVICE_OPS
  115. dc->ops = &dc_ops;
  116. #else
  117. dc->init = rt_dc_init;
  118. dc->control = rt_dc_control;
  119. #endif
  120. dc->user_data = data;
  121. /* register Display Controller device to RT-Thread */
  122. rt_device_register(dc, name, RT_DEVICE_FLAG_RDWR);
  123. }
  124. #if defined(RT_USING_DC_CHANNEL0)
  125. static struct phytium_dc_bus dev_dc0;
  126. #endif
  127. #if defined(RT_USING_DC_CHANNEL1)
  128. static struct phytium_dc_bus dev_dc1;
  129. #endif
  130. int rt_hw_dc_init(void)
  131. {
  132. #if defined(RT_USING_DC_CHANNEL0)
  133. dev_dc0.name = "DC0";
  134. dev_dc0.fdc_id = FDCDP_ID0;
  135. rt_dc_init(&dev_dc0);
  136. #endif
  137. #if defined(RT_USING_DC_CHANNEL1)
  138. dev_dc1.name = "DC1";
  139. dev_dc1.fdc_id = FDCDP_ID1;
  140. rt_dc_init(&dev_dc1);
  141. #endif
  142. return RT_EOK;
  143. }
  144. INIT_DEVICE_EXPORT(rt_hw_dc_init);