upload tizen1.0 source
[kernel/linux-2.6.36.git] / arch / arm / mach-s5pv310 / setup-mipi.c
1 /* linux/arch/arm/mach-s5pv310/setup-mipi.c
2  *
3  * Copyright (c) 2010 Samsung Electronics Co., Ltd
4  *
5  * S5PV310 - Helper functions for MIPI CSIS/DSIM PHY control
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/platform_device.h>
14 #include <linux/io.h>
15 #include <linux/spinlock.h>
16 #include <mach/regs-pmu.h>
17
18 /* Global MIPI CSIS or DSIM PHY enable and reset control. */
19 static int s5p_mipi_phy_control(struct platform_device *pdev, bool on, u32 rst)
20 {
21         static DEFINE_SPINLOCK(lock);
22         void __iomem *addr;
23         unsigned long flags;
24         int pid;
25         u32 cfg;
26
27         if (pdev == NULL)
28                 return -EINVAL;
29
30         pid = pdev->id;
31         if (pid != 0 && pid != 1)
32                 return -EINVAL;
33
34         addr = pid ? S5P_MIPI_PHY1_CONTROL : S5P_MIPI_PHY0_CONTROL;
35
36         spin_lock_irqsave(&lock, flags);
37
38         cfg = __raw_readl(addr) & ~rst;
39         if (on)
40                 cfg |= rst;
41         __raw_writel(cfg, addr);
42
43         if (on)
44                 cfg |= S5P_MIPI_PHY_ENABLE;
45         else if (!(cfg & (S5P_MIPI_PHY_SRESETN | S5P_MIPI_PHY_MRESETN) & ~rst))
46                 cfg &= ~S5P_MIPI_PHY_ENABLE;
47
48         __raw_writel(cfg, addr);
49
50         spin_unlock_irqrestore(&lock, flags);
51         return 0;
52 }
53
54 int s5p_csis_phy_enable(struct platform_device *pdev, bool on)
55 {
56         return s5p_mipi_phy_control(pdev, on, S5P_MIPI_PHY_SRESETN);
57 }
58
59 int s5p_dsim_phy_enable(struct platform_device *pdev, bool on)
60 {
61         return s5p_mipi_phy_control(pdev, on, S5P_MIPI_PHY_MRESETN);
62 }