drv_dc.c 5.1 KB

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