phy-mtk-io.h 897 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2021 MediaTek Inc.
  4. *
  5. * Author: Chunfeng Yun <[email protected]>
  6. */
  7. #ifndef __PHY_MTK_H__
  8. #define __PHY_MTK_H__
  9. #include <linux/bitfield.h>
  10. #include <linux/io.h>
  11. static inline void mtk_phy_clear_bits(void __iomem *reg, u32 bits)
  12. {
  13. u32 tmp = readl(reg);
  14. tmp &= ~bits;
  15. writel(tmp, reg);
  16. }
  17. static inline void mtk_phy_set_bits(void __iomem *reg, u32 bits)
  18. {
  19. u32 tmp = readl(reg);
  20. tmp |= bits;
  21. writel(tmp, reg);
  22. }
  23. static inline void mtk_phy_update_bits(void __iomem *reg, u32 mask, u32 val)
  24. {
  25. u32 tmp = readl(reg);
  26. tmp &= ~mask;
  27. tmp |= val & mask;
  28. writel(tmp, reg);
  29. }
  30. /* field @mask shall be constant and continuous */
  31. #define mtk_phy_update_field(reg, mask, val) \
  32. ({ \
  33. BUILD_BUG_ON_MSG(!__builtin_constant_p(mask), "mask is not constant"); \
  34. mtk_phy_update_bits(reg, mask, FIELD_PREP(mask, val)); \
  35. })
  36. #endif