bcm2835.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * (C) Copyright 2012 Stephen Warren
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <lcd.h>
  8. #include <memalign.h>
  9. #include <phys2bus.h>
  10. #include <asm/arch/mbox.h>
  11. #include <asm/global_data.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. /* Global variables that lcd.c expects to exist */
  14. vidinfo_t panel_info;
  15. static u32 bcm2835_pitch;
  16. struct msg_query {
  17. struct bcm2835_mbox_hdr hdr;
  18. struct bcm2835_mbox_tag_physical_w_h physical_w_h;
  19. u32 end_tag;
  20. };
  21. struct msg_setup {
  22. struct bcm2835_mbox_hdr hdr;
  23. struct bcm2835_mbox_tag_physical_w_h physical_w_h;
  24. struct bcm2835_mbox_tag_virtual_w_h virtual_w_h;
  25. struct bcm2835_mbox_tag_depth depth;
  26. struct bcm2835_mbox_tag_pixel_order pixel_order;
  27. struct bcm2835_mbox_tag_alpha_mode alpha_mode;
  28. struct bcm2835_mbox_tag_virtual_offset virtual_offset;
  29. struct bcm2835_mbox_tag_overscan overscan;
  30. struct bcm2835_mbox_tag_allocate_buffer allocate_buffer;
  31. struct bcm2835_mbox_tag_pitch pitch;
  32. u32 end_tag;
  33. };
  34. void lcd_ctrl_init(void *lcdbase)
  35. {
  36. ALLOC_CACHE_ALIGN_BUFFER(struct msg_query, msg_query, 1);
  37. ALLOC_CACHE_ALIGN_BUFFER(struct msg_setup, msg_setup, 1);
  38. int ret;
  39. u32 w, h;
  40. u32 fb_start, fb_end;
  41. debug("bcm2835: Query resolution...\n");
  42. BCM2835_MBOX_INIT_HDR(msg_query);
  43. BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_query->physical_w_h,
  44. GET_PHYSICAL_W_H);
  45. ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_query->hdr);
  46. if (ret) {
  47. printf("bcm2835: Could not query display resolution\n");
  48. /* FIXME: How to disable the LCD to prevent errors? hang()? */
  49. return;
  50. }
  51. w = msg_query->physical_w_h.body.resp.width;
  52. h = msg_query->physical_w_h.body.resp.height;
  53. debug("bcm2835: Setting up display for %d x %d\n", w, h);
  54. BCM2835_MBOX_INIT_HDR(msg_setup);
  55. BCM2835_MBOX_INIT_TAG(&msg_setup->physical_w_h, SET_PHYSICAL_W_H);
  56. msg_setup->physical_w_h.body.req.width = w;
  57. msg_setup->physical_w_h.body.req.height = h;
  58. BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_w_h, SET_VIRTUAL_W_H);
  59. msg_setup->virtual_w_h.body.req.width = w;
  60. msg_setup->virtual_w_h.body.req.height = h;
  61. BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH);
  62. msg_setup->depth.body.req.bpp = 32;
  63. BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER);
  64. msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_RGB;
  65. BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE);
  66. msg_setup->alpha_mode.body.req.alpha = BCM2835_MBOX_ALPHA_MODE_IGNORED;
  67. BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET);
  68. msg_setup->virtual_offset.body.req.x = 0;
  69. msg_setup->virtual_offset.body.req.y = 0;
  70. BCM2835_MBOX_INIT_TAG(&msg_setup->overscan, SET_OVERSCAN);
  71. msg_setup->overscan.body.req.top = 0;
  72. msg_setup->overscan.body.req.bottom = 0;
  73. msg_setup->overscan.body.req.left = 0;
  74. msg_setup->overscan.body.req.right = 0;
  75. BCM2835_MBOX_INIT_TAG(&msg_setup->allocate_buffer, ALLOCATE_BUFFER);
  76. msg_setup->allocate_buffer.body.req.alignment = 0x100;
  77. BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_setup->pitch, GET_PITCH);
  78. ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr);
  79. if (ret) {
  80. printf("bcm2835: Could not configure display\n");
  81. /* FIXME: How to disable the LCD to prevent errors? hang()? */
  82. return;
  83. }
  84. w = msg_setup->physical_w_h.body.resp.width;
  85. h = msg_setup->physical_w_h.body.resp.height;
  86. bcm2835_pitch = msg_setup->pitch.body.resp.pitch;
  87. debug("bcm2835: Final resolution is %d x %d\n", w, h);
  88. panel_info.vl_col = w;
  89. panel_info.vl_row = h;
  90. panel_info.vl_bpix = LCD_COLOR32;
  91. gd->fb_base = bus_to_phys(
  92. msg_setup->allocate_buffer.body.resp.fb_address);
  93. /* Enable dcache for the frame buffer */
  94. fb_start = gd->fb_base & ~(MMU_SECTION_SIZE - 1);
  95. fb_end = gd->fb_base + msg_setup->allocate_buffer.body.resp.fb_size;
  96. fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
  97. mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
  98. DCACHE_WRITEBACK);
  99. lcd_set_flush_dcache(1);
  100. }
  101. void lcd_enable(void)
  102. {
  103. }
  104. int lcd_get_size(int *line_length)
  105. {
  106. *line_length = bcm2835_pitch;
  107. return *line_length * panel_info.vl_row;
  108. }