aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-exynos/setup-csis.c
blob: e342aa8fbe35a1bf0cb20a260ec8dd14ac1ba0e3 (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
/* linux/arch/arm/mach-exynos/setup-csis.c
 *
 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
 *	http://www.samsung.com/
 *
 * EXYNOS4 - Base MIPI-CSI2 gpio configuration
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
*/

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/gpio.h>
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <plat/clock.h>
#include <plat/gpio-cfg.h>
#include <mach/regs-gpio.h>
#include <plat/map-s5p.h>
#include <mach/map.h>
#include <mach/regs-clock.h>
#include <plat/csis.h>

#ifdef DEBUG
#define dbg(fmt, args...) \
	printk(KERN_INFO "%s:%d: " fmt "\n", __func__, __LINE__, ##args)
#else
#define dbg(fmt, args...)
#endif

struct platform_device; /* don't need the contents */

void s3c_csis0_cfg_gpio(void) { }
void s3c_csis1_cfg_gpio(void) { }

void s3c_csis0_cfg_phy_global(int on)
{
	u32 cfg;

	if (on) {
		/* MIPI D-PHY Power Enable */
		cfg = __raw_readl(EXYNOS4_MIPI_CONTROL0);
		cfg |= EXYNOS4_MIPI_DPHY_S_RESETN;
		__raw_writel(cfg, EXYNOS4_MIPI_CONTROL0);

		cfg = __raw_readl(EXYNOS4_MIPI_CONTROL0);
		cfg |= EXYNOS4_MIPI_DPHY_EN;
		__raw_writel(cfg, EXYNOS4_MIPI_CONTROL0);

		dbg(KERN_INFO "csis0 on\n");
	} else {
		/* MIPI Power Disable */
		cfg = __raw_readl(EXYNOS4_MIPI_CONTROL0);
		cfg &= ~EXYNOS4_MIPI_DPHY_S_RESETN;

		if (!(cfg & EXYNOS4_MIPI_DPHY_M_RESETN))
			cfg &= ~EXYNOS4_MIPI_DPHY_EN;

		__raw_writel(cfg, EXYNOS4_MIPI_CONTROL0);

		dbg(KERN_INFO "csis0 off\n");
	}
}
void s3c_csis1_cfg_phy_global(int on)
{
	u32 cfg;

	if (on) {
		/* MIPI D-PHY Power Enable */
		cfg = __raw_readl(EXYNOS4_MIPI_CONTROL1);
		cfg |= EXYNOS4_MIPI_DPHY_S_RESETN;
		__raw_writel(cfg, EXYNOS4_MIPI_CONTROL1);

		cfg = __raw_readl(EXYNOS4_MIPI_CONTROL1);
		cfg |= EXYNOS4_MIPI_DPHY_EN;
		__raw_writel(cfg, EXYNOS4_MIPI_CONTROL1);

		dbg(KERN_INFO "csis1 on\n");
	} else {
		/* MIPI Power Disable */
		cfg = __raw_readl(EXYNOS4_MIPI_CONTROL1);
		cfg &= ~EXYNOS4_MIPI_DPHY_S_RESETN;

		if (!(cfg & EXYNOS4_MIPI_DPHY_M_RESETN))
			cfg &= ~EXYNOS4_MIPI_DPHY_EN;

		__raw_writel(cfg, EXYNOS4_MIPI_CONTROL1);

		dbg(KERN_INFO "csis1 off\n");
	}
}
int s3c_csis_clk_on(struct platform_device *pdev, struct clk **clk)
{
	struct s3c_platform_csis *pdata;
	struct clk *sclk_csis = NULL;
	struct clk *mout_mpll = NULL;

	pdata = to_csis_plat(&pdev->dev);

	/* mout_mpll */
	mout_mpll = clk_get(&pdev->dev, pdata->srclk_name);
	if (IS_ERR(mout_mpll)) {
		dev_err(&pdev->dev, "failed to get mout_mpll\n");
		goto err_clk1;
	}

	/* sclk_csis */
	sclk_csis = clk_get(&pdev->dev, pdata->clk_name);
	if (IS_ERR(sclk_csis)) {
		dev_err(&pdev->dev, "failed to get sclk_csis\n");
		goto err_clk2;
	}

	if (clk_set_parent(sclk_csis, mout_mpll)) {
		dev_err(&pdev->dev, "Unable to set parent %s of clock %s.\n",
				mout_mpll->name, sclk_csis->name);
		goto err_clk3;
	}

	if (clk_set_rate(sclk_csis, pdata->clk_rate)) {
		dev_err(&pdev->dev, "%s rate change failed: %lu\n",
				sclk_csis->name, pdata->clk_rate);
		goto err_clk3;
	}

	/* csis */
	*clk = clk_get(&pdev->dev, "csis");
	if (IS_ERR(*clk)) {
		dev_err(&pdev->dev, "failed to get csis clock\n");
		goto err_clk3;
	}
	/* clock enable for csis */
	clk_enable(*clk);
	clk_enable(sclk_csis);

	return 0;

err_clk3:
	clk_put(sclk_csis);

err_clk2:
	clk_put(mout_mpll);

err_clk1:
	return -EINVAL;
}
int s3c_csis_clk_off(struct platform_device *pdev, struct clk **clk)
{
	clk_disable(*clk);
	clk_put(*clk);

	*clk = NULL;

	return 0;
}