Commit | Line | Data |
---|---|---|
1d45ac49 SN |
1 | /* |
2 | * Copyright (C) 2011 Samsung Electronics Co., Ltd. | |
3 | * | |
4 | * S5P - Helper functions for MIPI-CSIS and MIPI-DSIM D-PHY control | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | */ | |
10 | ||
11 | #include <linux/kernel.h> | |
12 | #include <linux/platform_device.h> | |
13 | #include <linux/io.h> | |
14 | #include <linux/spinlock.h> | |
15 | #include <mach/regs-clock.h> | |
16 | ||
17 | static int __s5p_mipi_phy_control(struct platform_device *pdev, | |
18 | bool on, u32 reset) | |
19 | { | |
20 | static DEFINE_SPINLOCK(lock); | |
21 | void __iomem *addr; | |
22 | unsigned long flags; | |
23 | int pid; | |
24 | u32 cfg; | |
25 | ||
26 | if (!pdev) | |
27 | return -EINVAL; | |
28 | ||
29 | pid = (pdev->id == -1) ? 0 : pdev->id; | |
30 | ||
31 | if (pid != 0 && pid != 1) | |
32 | return -EINVAL; | |
33 | ||
34 | addr = S5P_MIPI_DPHY_CONTROL(pid); | |
35 | ||
36 | spin_lock_irqsave(&lock, flags); | |
37 | ||
38 | cfg = __raw_readl(addr); | |
39 | cfg = on ? (cfg | reset) : (cfg & ~reset); | |
40 | __raw_writel(cfg, addr); | |
41 | ||
42 | if (on) { | |
43 | cfg |= S5P_MIPI_DPHY_ENABLE; | |
44 | } else if (!(cfg & (S5P_MIPI_DPHY_SRESETN | | |
45 | S5P_MIPI_DPHY_MRESETN) & ~reset)) { | |
46 | cfg &= ~S5P_MIPI_DPHY_ENABLE; | |
47 | } | |
48 | ||
49 | __raw_writel(cfg, addr); | |
50 | spin_unlock_irqrestore(&lock, flags); | |
51 | ||
52 | return 0; | |
53 | } | |
54 | ||
55 | int s5p_csis_phy_enable(struct platform_device *pdev, bool on) | |
56 | { | |
57 | return __s5p_mipi_phy_control(pdev, on, S5P_MIPI_DPHY_SRESETN); | |
58 | } | |
59 | ||
60 | int s5p_dsim_phy_enable(struct platform_device *pdev, bool on) | |
61 | { | |
62 | return __s5p_mipi_phy_control(pdev, on, S5P_MIPI_DPHY_MRESETN); | |
63 | } |