ccu_mmc_timing.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2017 Chen-Yu Tsai. All rights reserved.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/clk-provider.h>
  14. #include <linux/clk/sunxi-ng.h>
  15. #include "ccu_common.h"
  16. /**
  17. * sunxi_ccu_set_mmc_timing_mode: Configure the MMC clock timing mode
  18. * @clk: clock to be configured
  19. * @new_mode: true for new timing mode introduced in A83T and later
  20. *
  21. * Returns 0 on success, -ENOTSUPP if the clock does not support
  22. * switching modes.
  23. */
  24. int sunxi_ccu_set_mmc_timing_mode(struct clk *clk, bool new_mode)
  25. {
  26. struct clk_hw *hw = __clk_get_hw(clk);
  27. struct ccu_common *cm = hw_to_ccu_common(hw);
  28. unsigned long flags;
  29. u32 val;
  30. if (!(cm->features & CCU_FEATURE_MMC_TIMING_SWITCH))
  31. return -ENOTSUPP;
  32. spin_lock_irqsave(cm->lock, flags);
  33. val = readl(cm->base + cm->reg);
  34. if (new_mode)
  35. val |= CCU_MMC_NEW_TIMING_MODE;
  36. else
  37. val &= ~CCU_MMC_NEW_TIMING_MODE;
  38. writel(val, cm->base + cm->reg);
  39. spin_unlock_irqrestore(cm->lock, flags);
  40. return 0;
  41. }
  42. EXPORT_SYMBOL_GPL(sunxi_ccu_set_mmc_timing_mode);
  43. /**
  44. * sunxi_ccu_set_mmc_timing_mode: Get the current MMC clock timing mode
  45. * @clk: clock to query
  46. *
  47. * Returns 0 if the clock is in old timing mode, > 0 if it is in
  48. * new timing mode, and -ENOTSUPP if the clock does not support
  49. * this function.
  50. */
  51. int sunxi_ccu_get_mmc_timing_mode(struct clk *clk)
  52. {
  53. struct clk_hw *hw = __clk_get_hw(clk);
  54. struct ccu_common *cm = hw_to_ccu_common(hw);
  55. if (!(cm->features & CCU_FEATURE_MMC_TIMING_SWITCH))
  56. return -ENOTSUPP;
  57. return !!(readl(cm->base + cm->reg) & CCU_MMC_NEW_TIMING_MODE);
  58. }
  59. EXPORT_SYMBOL_GPL(sunxi_ccu_get_mmc_timing_mode);