Sylwester Nawrocki | 1d45ac4 | 2011-03-10 21:53:40 +0900 | [diff] [blame] | 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 | |
Sylwester Nawrocki | 69a3d4f | 2012-09-17 06:02:48 -0300 | [diff] [blame] | 17 | static int __s5p_mipi_phy_control(int id, bool on, u32 reset) |
Sylwester Nawrocki | 1d45ac4 | 2011-03-10 21:53:40 +0900 | [diff] [blame] | 18 | { |
| 19 | static DEFINE_SPINLOCK(lock); |
| 20 | void __iomem *addr; |
| 21 | unsigned long flags; |
Sylwester Nawrocki | 1d45ac4 | 2011-03-10 21:53:40 +0900 | [diff] [blame] | 22 | u32 cfg; |
| 23 | |
Sylwester Nawrocki | 69a3d4f | 2012-09-17 06:02:48 -0300 | [diff] [blame] | 24 | id = max(0, id); |
| 25 | if (id > 1) |
Sylwester Nawrocki | 1d45ac4 | 2011-03-10 21:53:40 +0900 | [diff] [blame] | 26 | return -EINVAL; |
| 27 | |
Sylwester Nawrocki | 69a3d4f | 2012-09-17 06:02:48 -0300 | [diff] [blame] | 28 | addr = S5P_MIPI_DPHY_CONTROL(id); |
Sylwester Nawrocki | 1d45ac4 | 2011-03-10 21:53:40 +0900 | [diff] [blame] | 29 | |
| 30 | spin_lock_irqsave(&lock, flags); |
| 31 | |
| 32 | cfg = __raw_readl(addr); |
| 33 | cfg = on ? (cfg | reset) : (cfg & ~reset); |
| 34 | __raw_writel(cfg, addr); |
| 35 | |
| 36 | if (on) { |
| 37 | cfg |= S5P_MIPI_DPHY_ENABLE; |
| 38 | } else if (!(cfg & (S5P_MIPI_DPHY_SRESETN | |
| 39 | S5P_MIPI_DPHY_MRESETN) & ~reset)) { |
| 40 | cfg &= ~S5P_MIPI_DPHY_ENABLE; |
| 41 | } |
| 42 | |
| 43 | __raw_writel(cfg, addr); |
| 44 | spin_unlock_irqrestore(&lock, flags); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
Sylwester Nawrocki | 69a3d4f | 2012-09-17 06:02:48 -0300 | [diff] [blame] | 49 | int s5p_csis_phy_enable(int id, bool on) |
Sylwester Nawrocki | 1d45ac4 | 2011-03-10 21:53:40 +0900 | [diff] [blame] | 50 | { |
Sylwester Nawrocki | 69a3d4f | 2012-09-17 06:02:48 -0300 | [diff] [blame] | 51 | return __s5p_mipi_phy_control(id, on, S5P_MIPI_DPHY_SRESETN); |
Sylwester Nawrocki | 1d45ac4 | 2011-03-10 21:53:40 +0900 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | int s5p_dsim_phy_enable(struct platform_device *pdev, bool on) |
| 55 | { |
Sylwester Nawrocki | 69a3d4f | 2012-09-17 06:02:48 -0300 | [diff] [blame] | 56 | return __s5p_mipi_phy_control(pdev->id, on, S5P_MIPI_DPHY_MRESETN); |
Sylwester Nawrocki | 1d45ac4 | 2011-03-10 21:53:40 +0900 | [diff] [blame] | 57 | } |