bcm2835.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 <asm/arch/mbox.h>
  9. #include <asm/global_data.h>
  10. DECLARE_GLOBAL_DATA_PTR;
  11. /* Global variables that lcd.c expects to exist */
  12. vidinfo_t panel_info;
  13. static u32 bcm2835_pitch;
  14. struct msg_query {
  15. struct bcm2835_mbox_hdr hdr;
  16. struct bcm2835_mbox_tag_physical_w_h physical_w_h;
  17. u32 end_tag;
  18. };
  19. struct msg_setup {
  20. struct bcm2835_mbox_hdr hdr;
  21. struct bcm2835_mbox_tag_physical_w_h physical_w_h;
  22. struct bcm2835_mbox_tag_virtual_w_h virtual_w_h;
  23. struct bcm2835_mbox_tag_depth depth;
  24. struct bcm2835_mbox_tag_pixel_order pixel_order;
  25. struct bcm2835_mbox_tag_alpha_mode alpha_mode;
  26. struct bcm2835_mbox_tag_virtual_offset virtual_offset;
  27. struct bcm2835_mbox_tag_overscan overscan;
  28. struct bcm2835_mbox_tag_allocate_buffer allocate_buffer;
  29. struct bcm2835_mbox_tag_pitch pitch;
  30. u32 end_tag;
  31. };
  32. void lcd_ctrl_init(void *lcdbase)
  33. {
  34. ALLOC_ALIGN_BUFFER(struct msg_query, msg_query, 1, 16);
  35. ALLOC_ALIGN_BUFFER(struct msg_setup, msg_setup, 1, 16);
  36. int ret;
  37. u32 w, h;
  38. debug("bcm2835: Query resolution...\n");
  39. BCM2835_MBOX_INIT_HDR(msg_query);
  40. BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_query->physical_w_h,
  41. GET_PHYSICAL_W_H);
  42. ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_query->hdr);
  43. if (ret) {
  44. printf("bcm2835: Could not query display resolution\n");
  45. /* FIXME: How to disable the LCD to prevent errors? hang()? */
  46. return;
  47. }
  48. w = msg_query->physical_w_h.body.resp.width;
  49. h = msg_query->physical_w_h.body.resp.height;
  50. debug("bcm2835: Setting up display for %d x %d\n", w, h);
  51. BCM2835_MBOX_INIT_HDR(msg_setup);
  52. BCM2835_MBOX_INIT_TAG(&msg_setup->physical_w_h, SET_PHYSICAL_W_H);
  53. msg_setup->physical_w_h.body.req.width = w;
  54. msg_setup->physical_w_h.body.req.height = h;
  55. BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_w_h, SET_VIRTUAL_W_H);
  56. msg_setup->virtual_w_h.body.req.width = w;
  57. msg_setup->virtual_w_h.body.req.height = h;
  58. BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH);
  59. msg_setup->depth.body.req.bpp = 16;
  60. BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER);
  61. msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_BGR;
  62. BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE);
  63. msg_setup->alpha_mode.body.req.alpha = BCM2835_MBOX_ALPHA_MODE_IGNORED;
  64. BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET);
  65. msg_setup->virtual_offset.body.req.x = 0;
  66. msg_setup->virtual_offset.body.req.y = 0;
  67. BCM2835_MBOX_INIT_TAG(&msg_setup->overscan, SET_OVERSCAN);
  68. msg_setup->overscan.body.req.top = 0;
  69. msg_setup->overscan.body.req.bottom = 0;
  70. msg_setup->overscan.body.req.left = 0;
  71. msg_setup->overscan.body.req.right = 0;
  72. BCM2835_MBOX_INIT_TAG(&msg_setup->allocate_buffer, ALLOCATE_BUFFER);
  73. msg_setup->allocate_buffer.body.req.alignment = 0x100;
  74. BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_setup->pitch, GET_PITCH);
  75. ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr);
  76. if (ret) {
  77. printf("bcm2835: Could not configure display\n");
  78. /* FIXME: How to disable the LCD to prevent errors? hang()? */
  79. return;
  80. }
  81. w = msg_setup->physical_w_h.body.resp.width;
  82. h = msg_setup->physical_w_h.body.resp.height;
  83. bcm2835_pitch = msg_setup->pitch.body.resp.pitch;
  84. debug("bcm2835: Final resolution is %d x %d\n", w, h);
  85. panel_info.vl_col = w;
  86. panel_info.vl_row = h;
  87. panel_info.vl_bpix = LCD_COLOR16;
  88. gd->fb_base = msg_setup->allocate_buffer.body.resp.fb_address;
  89. }
  90. void lcd_enable(void)
  91. {
  92. }
  93. int lcd_get_size(int *line_length)
  94. {
  95. *line_length = bcm2835_pitch;
  96. return *line_length * panel_info.vl_row;
  97. }