drv_dc.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. void rt_hw_dc_register(struct phytium_dc_bus *dc_control_bus, const char *name, rt_uint32_t flag, void *data);
  32. static rt_err_t dc_config(struct phytium_dc_bus *dc_control_bus)
  33. {
  34. RT_ASSERT(dc_control_bus);
  35. rt_uint32_t chan = dc_control_bus->fdc_id;
  36. FDcDp *instance_p = &dc_control_bus->dc_handle;
  37. return RT_EOK;
  38. }
  39. static rt_err_t rt_dc_init(struct phytium_dc_bus *device)
  40. {
  41. RT_ASSERT(device != RT_NULL);
  42. rt_err_t ret;
  43. FDcDp *instance_p = &device->dc_handle;
  44. FDcDpCfgInitialize(instance_p);
  45. rt_uint32_t chan = device->fdc_id;
  46. instance_p->user_config[chan].color_depth = DISPLAY_COLOR_DEPTH;
  47. instance_p->user_config[chan].width = FB_XSIZE;
  48. instance_p->user_config[chan].height = FB_YSIZE;
  49. instance_p->user_config[chan].refresh_rate = DISPLAY_REFRESH_RATE_60;
  50. instance_p->user_config[chan].multi_mode = 0;
  51. instance_p->user_config[chan].fb_phy = _rt_framebuffer;
  52. instance_p->user_config[chan].fb_virtual = _rt_framebuffer;
  53. instance_p->dc_instance_p[chan].config = *FDcLookupConfig(chan);
  54. instance_p->dp_instance_p[chan].config = *FDpLookupConfig(chan);
  55. #ifdef RT_USING_SMART
  56. 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 */
  57. 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*/
  58. 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*/
  59. 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*/
  60. 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*/
  61. #endif
  62. _dc_info.bits_per_pixel = DISPLAY_COLOR_DEPTH;
  63. _dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
  64. _dc_info.framebuffer = (rt_uint8_t *)instance_p->user_config[chan].fb_virtual;
  65. _dc_info.width = FB_XSIZE;
  66. _dc_info.height = FB_YSIZE;
  67. rt_hw_dc_register(device, device->name, RT_DEVICE_FLAG_RDWR, NULL);
  68. dc_config(device);
  69. ret = FDcDpInitialize(instance_p, device->fdc_id);
  70. if (ret != RT_EOK)
  71. {
  72. LOG_E("Init dc failed, ret: 0x%x", ret);
  73. return -RT_ERROR;;
  74. }
  75. return RT_EOK;
  76. }
  77. static rt_err_t rt_dc_control(rt_device_t dev, int cmd, void *args)
  78. {
  79. RT_ASSERT(dev);
  80. struct phytium_dc_bus *dc_bus;
  81. dc_bus = (struct phytium_dc_bus *)(dev);
  82. switch (cmd)
  83. {
  84. case RTGRAPHIC_CTRL_RECT_UPDATE:
  85. break;
  86. case RTGRAPHIC_CTRL_POWERON:
  87. break;
  88. case RTGRAPHIC_CTRL_POWEROFF:
  89. break;
  90. case RTGRAPHIC_CTRL_GET_INFO:
  91. rt_memcpy(args, &_dc_info, sizeof(_dc_info));
  92. break;
  93. case RTGRAPHIC_CTRL_SET_MODE:
  94. break;
  95. }
  96. return RT_EOK;
  97. }
  98. #ifdef RT_USING_DEVICE_OPS
  99. const static struct rt_device_ops dc_ops =
  100. {
  101. rt_dc_init,
  102. RT_NULL,
  103. RT_NULL,
  104. RT_NULL,
  105. RT_NULL,
  106. rt_dc_control
  107. };
  108. #endif
  109. void rt_hw_dc_register(struct phytium_dc_bus *dc_control_bus, const char *name, rt_uint32_t flag, void *data)
  110. {
  111. RT_ASSERT(dc_control_bus != RT_NULL);
  112. struct rt_device *dc;
  113. dc = &(dc_control_bus->parent);
  114. dc->type = RT_Device_Class_Graphic;
  115. #ifdef RT_USING_DEVICE_OPS
  116. dc->ops = &dc_ops;
  117. #else
  118. dc->init = rt_dc_init;
  119. dc->control = rt_dc_control;
  120. #endif
  121. dc->user_data = data;
  122. /* register Display Controller device to RT-Thread */
  123. rt_device_register(dc, name, RT_DEVICE_FLAG_RDWR);
  124. }
  125. #if defined(RT_USING_DC_CHANNEL0)
  126. static struct phytium_dc_bus dev_dc0;
  127. #endif
  128. #if defined(RT_USING_DC_CHANNEL1)
  129. static struct phytium_dc_bus dev_dc1;
  130. #endif
  131. int rt_hw_dc_init(void)
  132. {
  133. #if defined(RT_USING_DC_CHANNEL0)
  134. dev_dc0.name = "DC0";
  135. dev_dc0.fdc_id = FDCDP_ID0;
  136. rt_dc_init(&dev_dc0);
  137. #endif
  138. #if defined(RT_USING_DC_CHANNEL1)
  139. dev_dc1.name = "DC1";
  140. dev_dc1.fdc_id = FDCDP_ID1;
  141. rt_dc_init(&dev_dc1);
  142. #endif
  143. return RT_EOK;
  144. }
  145. INIT_DEVICE_EXPORT(rt_hw_dc_init);