setup-mipiphy.c 1.4 KB

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