summaryrefslogtreecommitdiff
path: root/drivers/video/imx/hdp_load.c
blob: 42c2ef05cf9542e97c2f66cf643441a2a8c3111f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * Copyright 2017-2018 NXP
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <command.h>

#include "API_General.h"
#include "scfw_utils.h"

DECLARE_GLOBAL_DATA_PTR;

#define ON  1
#define OFF 0

static void display_set_power(int onoff)
{
	sc_ipc_t ipch = gd->arch.ipc_channel_handle;

	SC_PM_SET_RESOURCE_POWER_MODE(ipch, SC_R_DC_0, onoff);
	SC_PM_SET_RESOURCE_POWER_MODE(ipch, SC_R_HDMI, onoff);
}

static void display_set_clocks(void)
{
	sc_ipc_t ipch = gd->arch.ipc_channel_handle;
	const sc_pm_clock_rate_t pll = 657000000;
	const sc_pm_clock_rate_t hdmi_core_clock = pll / 5; /* 135.000 Mhz */
	const sc_pm_clock_rate_t hdmi_bus_clock = pll / 8;  /*  83.375 Mhz */

	SC_PM_SET_RESOURCE_POWER_MODE(ipch,
				      SC_R_HDMI_PLL_0, SC_PM_PW_MODE_OFF);
	SC_PM_SET_CLOCK_RATE(ipch,
			     SC_R_HDMI_PLL_0, SC_PM_CLK_PLL, pll);
	SC_PM_SET_RESOURCE_POWER_MODE(ipch,
				      SC_R_HDMI_PLL_0, SC_PM_PW_MODE_ON);

	/* HDMI DI Bus Clock  */
	SC_PM_SET_CLOCK_RATE(ipch,
			     SC_R_HDMI, SC_PM_CLK_MISC4, hdmi_bus_clock);
	/* HDMI DI Core Clock  */
	SC_PM_SET_CLOCK_RATE(ipch,
			     SC_R_HDMI, SC_PM_CLK_MISC2, hdmi_core_clock);
}

static void display_enable_clocks(int enable)
{
	sc_ipc_t ipch = gd->arch.ipc_channel_handle;

	SC_PM_CLOCK_ENABLE(ipch, SC_R_HDMI_PLL_0, SC_PM_CLK_PLL, enable);
	SC_PM_CLOCK_ENABLE(ipch, SC_R_HDMI, SC_PM_CLK_MISC2, enable);
	SC_PM_CLOCK_ENABLE(ipch, SC_R_HDMI, SC_PM_CLK_MISC4, enable);
	if (enable == OFF)
		SC_PM_SET_RESOURCE_POWER_MODE(ipch, SC_R_HDMI_PLL_0,
					      SC_PM_PW_MODE_OFF);
}

int do_hdp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
	if (argc < 2)
		return 0;

	if (strncmp(argv[1], "tracescfw", 9) == 0) {
		g_debug_scfw = 1;
		printf("Enabled SCFW API tracing\n");
	} else if (strncmp(argv[1], "load", 4) == 0) {
		unsigned long address = 0;
		unsigned long offset  = 0x2000;
		const int iram_size   = 0x10000;
		const int dram_size   = 0x8000;
		const char *s;
		sc_ipc_t ipch = gd->arch.ipc_channel_handle;

		if (argc > 2) {
			address = simple_strtoul(argv[2], NULL, 0);
			if (argc > 3)
				offset = simple_strtoul(argv[3], NULL, 0);
		} else {
			printf("Missing address\n");
		}

		printf("Loading hdp firmware from 0x%016lx offset 0x%016lx\n",
		       address, offset);
		display_set_power(SC_PM_PW_MODE_ON);
		display_set_clocks();
		display_enable_clocks(ON);
		cdn_api_loadfirmware((unsigned char *)(address + offset),
				     iram_size,
				     (unsigned char *)(address + offset +
						       iram_size),
				     dram_size);

		s = env_get("hdp_authenticate_fw");
		if (s && !strcmp(s, "yes"))
			SC_MISC_AUTH(ipch, SC_MISC_SECO_AUTH_HDMI_TX_FW, 0);

		display_enable_clocks(OFF);
		printf("Loading hdp firmware Complete\n");

		/* do not turn off hdmi power or firmware load will be lost */
	} else {
		printf("test error argc %d\n", argc);
	}

	return 0;
}

/***************************************************/
U_BOOT_CMD(
	hdp,  CONFIG_SYS_MAXARGS, 1, do_hdp,
	"load hdmi firmware ",
	"[<command>] ...\n"
	"hdpload [address] [<offset>]\n"
	"        address - address where the binary image starts\n"
	"        <offset> - IRAM offset in the binary image (8192 default)\n"
	"\n"
	"        if \"hdp_authenticate_fw\" is set to \"yes\", the seco\n"
	"        will authenticate the firmware and load HDCP keys.\n"
	"\n"
	"tracescfw - Trace SCFW API calls for video commands\n"
	);