blob: 17266c01a69b7b9fc7c25fa35d9bbfbd7239f7a2 [file] [log] [blame]
Simon Glass70997d82017-04-05 16:23:36 -06001/*
2 * (C) Copyright 2012 Stephen Warren
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <memalign.h>
Simon Glass2e4170b2017-04-05 16:23:40 -06009#include <phys2bus.h>
Simon Glass70997d82017-04-05 16:23:36 -060010#include <asm/arch/mbox.h>
11
12struct msg_set_power_state {
13 struct bcm2835_mbox_hdr hdr;
14 struct bcm2835_mbox_tag_set_power_state set_power_state;
15 u32 end_tag;
16};
17
Simon Glassc6606512017-04-05 16:23:37 -060018struct msg_get_clock_rate {
19 struct bcm2835_mbox_hdr hdr;
20 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
21 u32 end_tag;
22};
23
Simon Glass2e4170b2017-04-05 16:23:40 -060024struct msg_query {
25 struct bcm2835_mbox_hdr hdr;
26 struct bcm2835_mbox_tag_physical_w_h physical_w_h;
27 u32 end_tag;
28};
29
Simon Glass70997d82017-04-05 16:23:36 -060030int bcm2835_power_on_module(u32 module)
31{
32 ALLOC_CACHE_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1);
33 int ret;
34
35 BCM2835_MBOX_INIT_HDR(msg_pwr);
36 BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
37 SET_POWER_STATE);
38 msg_pwr->set_power_state.body.req.device_id = module;
39 msg_pwr->set_power_state.body.req.state =
40 BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
41 BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
42
43 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
44 &msg_pwr->hdr);
45 if (ret) {
46 printf("bcm2835: Could not set module %u power state\n",
47 module);
48 return -EIO;
49 }
50
51 return 0;
52}
Simon Glassc6606512017-04-05 16:23:37 -060053
54int bcm2835_get_mmc_clock(void)
55{
56 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1);
57 int ret;
58
59 ret = bcm2835_power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
60 if (ret)
61 return ret;
62
63 BCM2835_MBOX_INIT_HDR(msg_clk);
64 BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
65 msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
66
67 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
68 if (ret) {
69 printf("bcm2835: Could not query eMMC clock rate\n");
70 return -EIO;
71 }
72
73 return msg_clk->get_clock_rate.body.resp.rate_hz;
74}
Simon Glass2e4170b2017-04-05 16:23:40 -060075
76int bcm2835_get_video_size(int *widthp, int *heightp)
77{
78 ALLOC_CACHE_ALIGN_BUFFER(struct msg_query, msg_query, 1);
79 int ret;
80
81 BCM2835_MBOX_INIT_HDR(msg_query);
82 BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_query->physical_w_h,
83 GET_PHYSICAL_W_H);
84 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_query->hdr);
85 if (ret) {
86 printf("bcm2835: Could not query display resolution\n");
87 return ret;
88 }
89 *widthp = msg_query->physical_w_h.body.resp.width;
90 *heightp = msg_query->physical_w_h.body.resp.height;
91
92 return 0;
93}