summaryrefstree
path: root/kernel/drivers/misc/mipi-lli/exynos543x-mipi-lli.c
blob: cf4de640e725d2bc720a9804372d6bd4a67466b0 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
 * Exynos MIPI-LLI driver
 *
 * Copyright (C) 2013 Samsung Electronics Co.Ltd
 * Author: Byeongjo Park <bjo.park@samsung.com>
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#include <linux/clk.h>
#include <linux/clk-private.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/mipi-lli.h>
#ifdef CONFIG_SOC_EXYNOS5430
#include <mach/regs-clock-exynos5430.h>
#else
#include <mach/regs-clock-exynos5433.h>
#endif

#include "exynos-mipi-lli.h"
#include "exynos-mipi-lli-mphy.h"

static const void __iomem *lli_debug_clk_info[] = {
	EXYNOS5430_DIV_MIF3,
	EXYNOS5430_DIV_STAT_MIF3,
	EXYNOS5430_ENABLE_ACLK_MIF3,
	EXYNOS5430_ENABLE_IP_CPIF0,
	EXYNOS5430_ENABLE_IP_CPIF1,
	EXYNOS5430_ENABLE_IP_MIF3,
	EXYNOS5430_SRC_SEL_CPIF0,
	EXYNOS5430_SRC_STAT_CPIF1,
};

static int exynos_lli_get_clk_info(struct mipi_lli *lli)
{
	struct mipi_lli_clks *clks = &lli->clks;

	clks->aclk_cpif_200 = devm_clk_get(lli->dev, "aclk_cpif_200");
	/* To gate/ungate clocks */
	clks->gate_cpifnm_200 = devm_clk_get(lli->dev, "gate_cpifnm_200");
	clks->gate_lli_svc_loc = devm_clk_get(lli->dev, "gate_lli_svc_loc");
	clks->gate_lli_svc_rem = devm_clk_get(lli->dev, "gate_lli_svc_rem");
	clks->gate_lli_ll_init = devm_clk_get(lli->dev, "gate_lli_ll_init");
	clks->gate_lli_be_init = devm_clk_get(lli->dev, "gate_lli_be_init");
	clks->gate_lli_cmn_cfg = devm_clk_get(lli->dev, "gate_lli_cmn_cfg");
	clks->gate_lli_tx0_cfg = devm_clk_get(lli->dev, "gate_lli_tx0_cfg");
	clks->gate_lli_rx0_cfg = devm_clk_get(lli->dev, "gate_lli_rx0_cfg");
	clks->gate_lli_tx0_symbol = devm_clk_get(lli->dev, "gate_lli_tx0_symbol");
	clks->gate_lli_rx0_symbol = devm_clk_get(lli->dev, "gate_lli_rx0_symbol");

	/* For mux selection of clocks */
	clks->mout_phyclk_lli_tx0_symbol_user = devm_clk_get(lli->dev,
			"mout_phyclk_lli_tx0_symbol_user");
	clks->phyclk_lli_tx0_symbol = devm_clk_get(lli->dev,
			"phyclk_lli_tx0_symbol");
	clks->mout_phyclk_lli_rx0_symbol_user = devm_clk_get(lli->dev,
			"mout_phyclk_lli_rx0_symbol_user");
	clks->phyclk_lli_rx0_symbol = devm_clk_get(lli->dev,
			"phyclk_lli_rx0_symbol");

	if (IS_ERR(clks->aclk_cpif_200) ||
		IS_ERR(clks->gate_cpifnm_200) ||
		IS_ERR(clks->gate_lli_svc_loc) ||
		IS_ERR(clks->gate_lli_svc_rem) ||
		IS_ERR(clks->gate_lli_ll_init) ||
		IS_ERR(clks->gate_lli_be_init) ||
		IS_ERR(clks->gate_lli_cmn_cfg) ||
		IS_ERR(clks->gate_lli_tx0_cfg) ||
		IS_ERR(clks->gate_lli_rx0_cfg) ||
		IS_ERR(clks->gate_lli_tx0_symbol) ||
		IS_ERR(clks->gate_lli_rx0_symbol) ||
		IS_ERR(clks->mout_phyclk_lli_tx0_symbol_user) ||
		IS_ERR(clks->phyclk_lli_tx0_symbol) ||
		IS_ERR(clks->mout_phyclk_lli_rx0_symbol_user) ||
		IS_ERR(clks->phyclk_lli_rx0_symbol)
	) {
		dev_err(lli->dev, "exynos_lli_get_clks - failed\n");
		return -ENODEV;
	}

	return 0;
}

static int exynos_lli_clock_init(struct mipi_lli *lli)
{
	struct mipi_lli_clks *clks = &lli->clks;

	if(!clks)
		return -EINVAL;

	clk_set_parent(clks->mout_phyclk_lli_tx0_symbol_user,
			clks->phyclk_lli_tx0_symbol);
	clk_set_parent(clks->mout_phyclk_lli_rx0_symbol_user,
			clks->phyclk_lli_rx0_symbol);

	return 0;
}

static int exynos_lli_clock_div(struct mipi_lli *lli)
{
	struct clk *dout_aclk_cpif_200 = clk_get(lli->dev, "dout_aclk_cpif_200");
	struct clk *dout_mif_pre = clk_get(lli->dev, "dout_mif_pre");

	int ret = clk_set_rate(dout_aclk_cpif_200, 100000000);

	dev_err(lli->dev, "dout_aclk_cpif_200 = %ld\n", dout_aclk_cpif_200->rate);
	dev_err(lli->dev, "dout_mif_pre= %ld\n", dout_mif_pre->rate);

	return ret;
}

static int exynos_lli_clock_gating(struct mipi_lli *lli, int is_gating)
{
	struct mipi_lli_clks *clks = &lli->clks;

	if (!clks)
		return -EINVAL;

	if (is_gating) {
		clk_disable_unprepare(clks->gate_lli_rx0_symbol);
		clk_disable_unprepare(clks->gate_lli_tx0_symbol);
		clk_disable_unprepare(clks->gate_lli_rx0_cfg);
		clk_disable_unprepare(clks->gate_lli_tx0_cfg);
		clk_disable_unprepare(clks->gate_lli_cmn_cfg);
		clk_disable_unprepare(clks->gate_lli_be_init);
		clk_disable_unprepare(clks->gate_lli_ll_init);
		clk_disable_unprepare(clks->gate_lli_svc_rem);
		clk_disable_unprepare(clks->gate_lli_svc_loc);
		clk_disable_unprepare(clks->gate_cpifnm_200);
		/* it doesn't gate/ungate aclk_cpif_200
		   clk_disable_unprepare(clks->aclk_cpif_200);
		 */
	} else {
		/* it doesn't gate/ungate aclk_cpif_200
		   clk_prepare_enable(clks->aclk_cpif_200);
		 */
		if (clks->gate_cpifnm_200->enable_count < 1)
			clk_prepare_enable(clks->gate_cpifnm_200);
		if (clks->gate_lli_svc_loc->enable_count < 1)
			clk_prepare_enable(clks->gate_lli_svc_loc);
		if (clks->gate_lli_svc_rem->enable_count < 1)
			clk_prepare_enable(clks->gate_lli_svc_rem);
		if (clks->gate_lli_ll_init->enable_count < 1)
			clk_prepare_enable(clks->gate_lli_ll_init);
		if (clks->gate_lli_be_init->enable_count < 1)
			clk_prepare_enable(clks->gate_lli_be_init);
		if (clks->gate_lli_cmn_cfg->enable_count < 1)
			clk_prepare_enable(clks->gate_lli_cmn_cfg);
		if (clks->gate_lli_tx0_cfg->enable_count < 1)
			clk_prepare_enable(clks->gate_lli_tx0_cfg);
		if (clks->gate_lli_rx0_cfg->enable_count < 1)
			clk_prepare_enable(clks->gate_lli_rx0_cfg);
		if (clks->gate_lli_tx0_symbol->enable_count < 1)
			clk_prepare_enable(clks->gate_lli_tx0_symbol);
		if (clks->gate_lli_rx0_symbol->enable_count < 1)
			clk_prepare_enable(clks->gate_lli_rx0_symbol);
	}

	return 0;
}

static int exynos_lli_loopback_test(struct mipi_lli *lli)
{
	int uval = 0;
	struct exynos_mphy *phy = dev_get_drvdata(lli->mphy);

	/* enable LLI_PHY_CONTROL */
	writel(1, lli->pmu_regs);

	/* software reset */
	writel(1, lli->regs + EXYNOS_DME_LLI_RESET);

	/* to set TxH8 as H8_EXIT : 0x2b -> 0 */
	writel(0x0, phy->loc_regs + PHY_TX_HIBERN8_CONTROL(0));
	/* to set RxH8 as H8_EXIT : 0xa7 -> 0 */
	writel(0x0, phy->loc_regs + PHY_RX_ENTER_HIBERN8(0));

	writel(0x1, phy->loc_regs + PHY_TX_MODE(0));
	writel(0x1, phy->loc_regs + PHY_RX_MODE(0));

	writel(0x0, phy->loc_regs + PHY_TX_LCC_ENABLE(0));
	/* 0x10F24128 sets 0xFFFFFFFF to
	   LLI_Set_Config_update_All(LLI_SVC_BASE_LOCAL); */
	writel(0xFFFFFFFF, lli->regs + EXYNOS_PA_CONFIG_UPDATE);

	writel(0x1, lli->regs + EXYNOS_PA_MPHY_OV_TM_ENABLE);
	/* RX setting */
	writel(0x75, phy->loc_regs + (0x0a*4)); /* Internal Serial loopback */
	writel(0x01, phy->loc_regs + (0x16*4)); /* Align Enable */

	writel(0x01, phy->loc_regs + (0x0b*4)); /* user pattern ALL 0 */
	writel(0x0F, phy->loc_regs + (0x0C*4));
	writel(0xFF, phy->loc_regs + (0x0D*4));
	writel(0xFF, phy->loc_regs + (0x0E*4));

	writel(0x2b, phy->loc_regs + (0x2f*4));
	writel(0x60, phy->loc_regs + (0x1a*4));
	writel(0x14, phy->loc_regs + (0x29*4)); /* failed LB test on ATE */
	writel(0xC0, phy->loc_regs + (0x2E*4));

	/* TX setting */
	writel(0x03, phy->loc_regs + (0x32*4));
	writel(0x25, phy->loc_regs + (0x78*4)); /* Internal serial loopback */
	writel(0x01, phy->loc_regs + (0x79*4)); /* user ALL 0 */

	writel(0x0F, phy->loc_regs + (0x7A*4));
	writel(0xFF, phy->loc_regs + (0x7B*4));
	writel(0xFF, phy->loc_regs + (0x7C*4));

	writel(0x0, lli->regs + EXYNOS_PA_MPHY_OV_TM_ENABLE);

	mdelay(100);
	/* LLI_Set_RxBYpass as BY_PASS_ENTER */
	writel(0x1, phy->loc_regs + (0x2e*4));
	writel(0xFFFFFFFF, lli->regs + EXYNOS_PA_CONFIG_UPDATE);
	/* LLI_Set_TxBYpass as BY_PASS_ENTER */
	writel(0x1, phy->loc_regs + (0xa8*4));
	writel(0xFFFFFFFF, lli->regs + EXYNOS_PA_CONFIG_UPDATE);

	mdelay(200);

	writel(0x1, lli->regs + EXYNOS_PA_MPHY_OV_TM_ENABLE);
	uval = readl(phy->loc_regs + (0x23*4));
	dev_err(lli->dev, "LB error : 0x%x\n", uval);
	if (uval == 0x24)
		dev_err(lli->dev, "PWM loopbacktest is Passed!!");
	else
		dev_err(lli->dev, "PWM loopbacktest is Failed!!");

	writel(0x0, lli->regs + EXYNOS_PA_MPHY_OV_TM_ENABLE);

	writel(0x1, lli->regs + EXYNOS_PA_MPHY_CMN_ENABLE);
	uval = readl(phy->loc_regs + (0x26*4)); /* o_pll_lock[7] */
	writel(0x0, lli->regs + EXYNOS_PA_MPHY_CMN_ENABLE);

	dev_err(lli->dev, "uval : %d\n", uval);

	return 0;
}

static void exynos_lli_system_config(struct mipi_lli *lli)
{
	if (lli->sys_regs) {
		writel(SIG_INT_MASK0, lli->sys_regs + CPIF_LLI_SIG_INT_MASK0);
		writel(SIG_INT_MASK1, lli->sys_regs + CPIF_LLI_SIG_INT_MASK1);
	}
}