setup-mipiphy.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include <linux/export.h>
  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. static int __s5p_mipi_phy_control(int id, bool on, u32 reset)
  17. {
  18. static DEFINE_SPINLOCK(lock);
  19. void __iomem *addr;
  20. unsigned long flags;
  21. u32 cfg;
  22. id = max(0, id);
  23. if (id > 1)
  24. return -EINVAL;
  25. addr = S5P_MIPI_DPHY_CONTROL(id);
  26. spin_lock_irqsave(&lock, flags);
  27. cfg = __raw_readl(addr);
  28. cfg = on ? (cfg | reset) : (cfg & ~reset);
  29. __raw_writel(cfg, addr);
  30. if (on) {
  31. cfg |= S5P_MIPI_DPHY_ENABLE;
  32. } else if (!(cfg & (S5P_MIPI_DPHY_SRESETN |
  33. S5P_MIPI_DPHY_MRESETN) & ~reset)) {
  34. cfg &= ~S5P_MIPI_DPHY_ENABLE;
  35. }
  36. __raw_writel(cfg, addr);
  37. spin_unlock_irqrestore(&lock, flags);
  38. return 0;
  39. }
  40. int s5p_csis_phy_enable(int id, bool on)
  41. {
  42. return __s5p_mipi_phy_control(id, on, S5P_MIPI_DPHY_SRESETN);
  43. }
  44. EXPORT_SYMBOL(s5p_csis_phy_enable);
  45. int s5p_dsim_phy_enable(struct platform_device *pdev, bool on)
  46. {
  47. return __s5p_mipi_phy_control(pdev->id, on, S5P_MIPI_DPHY_MRESETN);
  48. }
  49. EXPORT_SYMBOL(s5p_dsim_phy_enable);