vcmdswhwregisters.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2014 - 2021 VERISILICON
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. *****************************************************************************
  26. *
  27. * The GPL License (GPL)
  28. *
  29. * Copyright (C) 2014 - 2021 VERISILICON
  30. *
  31. * This program is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU General Public License
  33. * as published by the Free Software Foundation; either version 2
  34. * of the License, or (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License
  42. * along with this program; if not, write to the Free Software Foundation,
  43. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  44. *
  45. *****************************************************************************
  46. *
  47. * Note: This software is released under dual MIT and GPL licenses. A
  48. * recipient may use this file under the terms of either the MIT license or
  49. * GPL License. If you wish to use only one license not the other, you can
  50. * indicate your decision by deleting one of the above license notices in your
  51. * version of this file.
  52. *
  53. *****************************************************************************/
  54. /*------------------------------------------------------------------------------
  55. Table of contents
  56. 1. Include headers
  57. 2. External compiler flags
  58. 3. Module defines
  59. ------------------------------------------------------------------------------*/
  60. /*------------------------------------------------------------------------------
  61. 1. Include headers
  62. ------------------------------------------------------------------------------*/
  63. #include <asm/io.h>
  64. #include "vcmdswhwregisters.h"
  65. /* NOTE: Don't use ',' in descriptions, because it is used as separator in csv
  66. * parsing. */
  67. const regVcmdField_s asicVcmdRegisterDesc[] =
  68. {
  69. #include "vcmdregistertable.h"
  70. };
  71. /*------------------------------------------------------------------------------
  72. 2. External compiler flags
  73. --------------------------------------------------------------------------------
  74. --------------------------------------------------------------------------------
  75. 3. Module defines
  76. ------------------------------------------------------------------------------*/
  77. /* Define this to print debug info for every register write.
  78. #define DEBUG_PRINT_REGS */
  79. /*******************************************************************************
  80. Function name : vcmd_read_reg
  81. Description : Retrive the content of a hadware register
  82. Note: The status register will be read after every MB
  83. so it may be needed to buffer it's content if reading
  84. the HW register is slow.
  85. Return type : u32
  86. Argument : u32 offset
  87. *******************************************************************************/
  88. u32 vcmd_read_reg(const void *hwregs, u32 offset)
  89. {
  90. u32 val;
  91. val =(u32) ioread32((void*)hwregs + offset);
  92. PDEBUG("vcmd_read_reg 0x%02x --> %08x\n", offset, val);
  93. return val;
  94. }
  95. /*******************************************************************************
  96. Function name : vcmd_write_reg
  97. Description : Set the content of a hadware register
  98. Return type : void
  99. Argument : u32 offset
  100. Argument : u32 val
  101. *******************************************************************************/
  102. void vcmd_write_reg(const void *hwregs, u32 offset, u32 val)
  103. {
  104. iowrite32(val,(void*)hwregs + offset);
  105. PDEBUG("vcmd_write_reg 0x%02x with value %08x\n", offset, val);
  106. }
  107. /*------------------------------------------------------------------------------
  108. vcmd_write_register_value
  109. Write a value into a defined register field (write will happens actually).
  110. ------------------------------------------------------------------------------*/
  111. void vcmd_write_register_value(const void *hwregs,u32* reg_mirror,regVcmdName name, u32 value)
  112. {
  113. const regVcmdField_s *field;
  114. u32 regVal;
  115. field = &asicVcmdRegisterDesc[name];
  116. #ifdef DEBUG_PRINT_REGS
  117. PDEBUG("vcmd_write_register_value 0x%2x 0x%08x Value: %10d %s\n",
  118. field->base, field->mask, value, field->description);
  119. #endif
  120. /* Check that value fits in field */
  121. PDEBUG("field->name == name=%d\n",field->name == name);
  122. PDEBUG("((field->mask >> field->lsb) << field->lsb) == field->mask=%d\n",((field->mask >> field->lsb) << field->lsb) == field->mask);
  123. PDEBUG("(field->mask >> field->lsb) >= value=%d\n",(field->mask >> field->lsb) >= value);
  124. PDEBUG("field->base < ASIC_VCMD_SWREG_AMOUNT*4=%d\n",field->base < ASIC_VCMD_SWREG_AMOUNT*4);
  125. /* Clear previous value of field in register */
  126. regVal = reg_mirror[field->base/4] & ~(field->mask);
  127. /* Put new value of field in register */
  128. reg_mirror[field->base/4] = regVal | ((value << field->lsb) & field->mask);
  129. /* write it into HW registers */
  130. vcmd_write_reg(hwregs, field->base,reg_mirror[field->base/4]);
  131. }
  132. /*------------------------------------------------------------------------------
  133. vcmd_get_register_value
  134. Get an unsigned value from the ASIC registers
  135. ------------------------------------------------------------------------------*/
  136. u32 vcmd_get_register_value(const void *hwregs, u32* reg_mirror,regVcmdName name)
  137. {
  138. const regVcmdField_s *field;
  139. u32 value;
  140. field = &asicVcmdRegisterDesc[name];
  141. PDEBUG("field->base < ASIC_VCMD_SWREG_AMOUNT * 4=%d\n",field->base < ASIC_VCMD_SWREG_AMOUNT * 4);
  142. value = reg_mirror[field->base / 4] = vcmd_read_reg(hwregs, field->base);
  143. value = (value & field->mask) >> field->lsb;
  144. return value;
  145. }