1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2012 Stephen Warren
9 #include <asm/arch/mbox.h>
11 struct msg_set_power_state {
12 struct bcm2835_mbox_hdr hdr;
13 struct bcm2835_mbox_tag_set_power_state set_power_state;
17 struct msg_get_clock_rate {
18 struct bcm2835_mbox_hdr hdr;
19 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
24 struct bcm2835_mbox_hdr hdr;
25 struct bcm2835_mbox_tag_physical_w_h physical_w_h;
30 struct bcm2835_mbox_hdr hdr;
31 struct bcm2835_mbox_tag_physical_w_h physical_w_h;
32 struct bcm2835_mbox_tag_virtual_w_h virtual_w_h;
33 struct bcm2835_mbox_tag_depth depth;
34 struct bcm2835_mbox_tag_pixel_order pixel_order;
35 struct bcm2835_mbox_tag_alpha_mode alpha_mode;
36 struct bcm2835_mbox_tag_virtual_offset virtual_offset;
37 struct bcm2835_mbox_tag_overscan overscan;
38 struct bcm2835_mbox_tag_allocate_buffer allocate_buffer;
39 struct bcm2835_mbox_tag_pitch pitch;
43 int bcm2835_power_on_module(u32 module)
45 ALLOC_CACHE_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1);
48 BCM2835_MBOX_INIT_HDR(msg_pwr);
49 BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
51 msg_pwr->set_power_state.body.req.device_id = module;
52 msg_pwr->set_power_state.body.req.state =
53 BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
54 BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
56 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
59 printf("bcm2835: Could not set module %u power state\n",
67 int bcm2835_get_mmc_clock(u32 clock_id)
69 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1);
72 ret = bcm2835_power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
76 BCM2835_MBOX_INIT_HDR(msg_clk);
77 BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
78 msg_clk->get_clock_rate.body.req.clock_id = clock_id;
80 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
82 printf("bcm2835: Could not query eMMC clock rate\n");
86 return msg_clk->get_clock_rate.body.resp.rate_hz;
89 int bcm2835_get_video_size(int *widthp, int *heightp)
91 ALLOC_CACHE_ALIGN_BUFFER(struct msg_query, msg_query, 1);
94 BCM2835_MBOX_INIT_HDR(msg_query);
95 BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_query->physical_w_h,
97 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_query->hdr);
99 printf("bcm2835: Could not query display resolution\n");
102 *widthp = msg_query->physical_w_h.body.resp.width;
103 *heightp = msg_query->physical_w_h.body.resp.height;
108 int bcm2835_set_video_params(int *widthp, int *heightp, int depth_bpp,
109 int pixel_order, int alpha_mode, ulong *fb_basep,
110 ulong *fb_sizep, int *pitchp)
112 ALLOC_CACHE_ALIGN_BUFFER(struct msg_setup, msg_setup, 1);
115 BCM2835_MBOX_INIT_HDR(msg_setup);
116 BCM2835_MBOX_INIT_TAG(&msg_setup->physical_w_h, SET_PHYSICAL_W_H);
117 msg_setup->physical_w_h.body.req.width = *widthp;
118 msg_setup->physical_w_h.body.req.height = *heightp;
119 BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_w_h, SET_VIRTUAL_W_H);
120 msg_setup->virtual_w_h.body.req.width = *widthp;
121 msg_setup->virtual_w_h.body.req.height = *heightp;
122 BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH);
123 msg_setup->depth.body.req.bpp = 32;
124 BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER);
125 msg_setup->pixel_order.body.req.order = pixel_order;
126 BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE);
127 msg_setup->alpha_mode.body.req.alpha = alpha_mode;
128 BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET);
129 msg_setup->virtual_offset.body.req.x = 0;
130 msg_setup->virtual_offset.body.req.y = 0;
131 BCM2835_MBOX_INIT_TAG(&msg_setup->overscan, SET_OVERSCAN);
132 msg_setup->overscan.body.req.top = 0;
133 msg_setup->overscan.body.req.bottom = 0;
134 msg_setup->overscan.body.req.left = 0;
135 msg_setup->overscan.body.req.right = 0;
136 BCM2835_MBOX_INIT_TAG(&msg_setup->allocate_buffer, ALLOCATE_BUFFER);
137 msg_setup->allocate_buffer.body.req.alignment = 0x100;
138 BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_setup->pitch, GET_PITCH);
140 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr);
142 printf("bcm2835: Could not configure display\n");
145 *widthp = msg_setup->physical_w_h.body.resp.width;
146 *heightp = msg_setup->physical_w_h.body.resp.height;
147 *pitchp = msg_setup->pitch.body.resp.pitch;
148 *fb_basep = bus_to_phys(
149 msg_setup->allocate_buffer.body.resp.fb_address);
150 *fb_sizep = msg_setup->allocate_buffer.body.resp.fb_size;