hmatrix.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * High-Speed Bus Matrix helper functions
  3. *
  4. * Copyright (C) 2008 Atmel Corporation
  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/clk.h>
  11. #include <linux/io.h>
  12. #include <mach/chip.h>
  13. #include <mach/hmatrix.h>
  14. static inline void __hmatrix_write_reg(unsigned long offset, u32 value)
  15. {
  16. __raw_writel(value, (void __iomem __force *)(HMATRIX_BASE + offset));
  17. }
  18. static inline u32 __hmatrix_read_reg(unsigned long offset)
  19. {
  20. return __raw_readl((void __iomem __force *)(HMATRIX_BASE + offset));
  21. }
  22. /**
  23. * hmatrix_write_reg - write HMATRIX configuration register
  24. * @offset: register offset
  25. * @value: value to be written to the register at @offset
  26. */
  27. void hmatrix_write_reg(unsigned long offset, u32 value)
  28. {
  29. clk_enable(&at32_hmatrix_clk);
  30. __hmatrix_write_reg(offset, value);
  31. __hmatrix_read_reg(offset);
  32. clk_disable(&at32_hmatrix_clk);
  33. }
  34. /**
  35. * hmatrix_read_reg - read HMATRIX configuration register
  36. * @offset: register offset
  37. *
  38. * Returns the value of the register at @offset.
  39. */
  40. u32 hmatrix_read_reg(unsigned long offset)
  41. {
  42. u32 value;
  43. clk_enable(&at32_hmatrix_clk);
  44. value = __hmatrix_read_reg(offset);
  45. clk_disable(&at32_hmatrix_clk);
  46. return value;
  47. }
  48. /**
  49. * hmatrix_sfr_set_bits - set bits in a slave's Special Function Register
  50. * @slave_id: operate on the SFR belonging to this slave
  51. * @mask: mask of bits to be set in the SFR
  52. */
  53. void hmatrix_sfr_set_bits(unsigned int slave_id, u32 mask)
  54. {
  55. u32 value;
  56. clk_enable(&at32_hmatrix_clk);
  57. value = __hmatrix_read_reg(HMATRIX_SFR(slave_id));
  58. value |= mask;
  59. __hmatrix_write_reg(HMATRIX_SFR(slave_id), value);
  60. __hmatrix_read_reg(HMATRIX_SFR(slave_id));
  61. clk_disable(&at32_hmatrix_clk);
  62. }
  63. /**
  64. * hmatrix_sfr_set_bits - clear bits in a slave's Special Function Register
  65. * @slave_id: operate on the SFR belonging to this slave
  66. * @mask: mask of bits to be cleared in the SFR
  67. */
  68. void hmatrix_sfr_clear_bits(unsigned int slave_id, u32 mask)
  69. {
  70. u32 value;
  71. clk_enable(&at32_hmatrix_clk);
  72. value = __hmatrix_read_reg(HMATRIX_SFR(slave_id));
  73. value &= ~mask;
  74. __hmatrix_write_reg(HMATRIX_SFR(slave_id), value);
  75. __hmatrix_read_reg(HMATRIX_SFR(slave_id));
  76. clk_disable(&at32_hmatrix_clk);
  77. }