summaryrefslogtreecommitdiffstats
path: root/drivers/video/tegra/dc/clock.c
blob: e2ea72f85d3ac0287be91bd7b53f189f51733115 (plain) (blame)
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
/*
 * clock.c: Functions required for internal dc clock utility.
 *
 * Copyright (C) 2010 Google, Inc.
 *
 * Copyright (c) 2010-2017, NVIDIA CORPORATION, All rights reserved.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/err.h>
#include <linux/types.h>
#include <linux/clk.h>
#include <linux/clk/tegra.h>

#include "dc.h"
#include "dc_reg.h"
#include "dc_priv.h"

unsigned long tegra_dc_pclk_round_rate(struct tegra_dc *dc, int pclk)
{
	unsigned long rate;
	unsigned long div;

	rate = tegra_dc_clk_get_rate(dc);

	if (TEGRA_DC_OUT_DSI == dc->out->type ||
		TEGRA_DC_OUT_FAKE_DSIA == dc->out->type ||
		TEGRA_DC_OUT_FAKE_DSIB == dc->out->type ||
		TEGRA_DC_OUT_FAKE_DSI_GANGED == dc->out->type) {
		div = DIV_ROUND_CLOSEST(rate * 2, pclk);
		if (tegra_dc_is_nvdisplay())
			return rate;	/*shift_clk_div is not available*/
	} else { /* round-up for divider for other display types */
		div = DIV_ROUND_UP(rate * 2, pclk);
	}

	if (tegra_dc_is_t21x()) {
		if (dc->out->type == TEGRA_DC_OUT_HDMI)
			return rate;
	}

	if (div < 2)
		return 0;

	return rate * 2 / div;
}

void tegra_dc_setup_clk(struct tegra_dc *dc, struct clk *clk)
{
	int pclk;

	if (dc->out_ops->setup_clk)
		pclk = dc->out_ops->setup_clk(dc, clk);
	else
		pclk = 0;
	if (tegra_dc_is_nvdisplay())
		tegra_nvdisp_set_compclk(dc);

	WARN_ONCE(!pclk, "pclk is 0\n");
#ifdef CONFIG_TEGRA_CORE_DVFS
	tegra_dvfs_set_rate(clk, pclk);
#endif
}