Add mask enable and alert register reading for INA231.
The INA231 ADC has two additional registers compared to the INA219.
This CL exposes those registers via controls:
<railname>_msken_reg &
<railname>_alrt_reg
BUG=none
TEST=manual
sudo servod -b samus -c samus.xml
dut-control pp5000_msken_reg
pp5000_msken_reg:0x8
- Conversion ready bit asserted
dut-control pp5000_alrt_reg
pp5000_alrt_reg:0x0
Change-Id: Ic4b0b8d94c2c61a8ee59f35cc2605598fa0c42cc
Reviewed-on: https://chromium-review.googlesource.com/211205
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
diff --git a/servo/data/generate_ina_controls.py b/servo/data/generate_ina_controls.py
index 060dda3..3f0a4e5 100644
--- a/servo/data/generate_ina_controls.py
+++ b/servo/data/generate_ina_controls.py
@@ -26,6 +26,9 @@
parsed by servod daemon ( servo/system_config.py )
"""
regs = ['cfg', 'shv', 'busv', 'pwr', 'cur', 'cal']
+ if drvname == 'ina231':
+ regs.extend(['msken', 'alrt'])
+
rsp = ""
for (slv, name, nom, sense, mux, is_calib) in adcs:
rsp += (
diff --git a/servo/drv/ina231.py b/servo/drv/ina231.py
index 3d18671..f31cccd 100644
--- a/servo/drv/ina231.py
+++ b/servo/drv/ina231.py
@@ -19,9 +19,6 @@
Beyond that the coefficients for calculating current & power LSBs are slightly
different.
"""
- REG_MSKEN = 6
- REG_ALRT = 7
-
MAX_CALIB = 0xffff
MSKEN_CNVR = 0x8
diff --git a/servo/drv/ina2xx.py b/servo/drv/ina2xx.py
index 36f7104..77bd5a4 100644
--- a/servo/drv/ina2xx.py
+++ b/servo/drv/ina2xx.py
@@ -41,6 +41,9 @@
REG_PWR = 3
REG_CUR = 4
REG_CALIB = 5
+ # Additional registers of INA231
+ REG_MSKEN = 6
+ REG_ALRT = 7
# maximum number of re-reads of bus voltage to do before raising
# exception for failing to see a data conversion. Note the CNVR bit
@@ -133,6 +136,21 @@
self._calib_reg = None
self._reg_cache = None
+ def _check_reg_index(self, reg):
+ """Validate register index is valid.
+
+ Args:
+ reg: integer of register index to check.
+
+ Raises: Ina2xxError if index out of range.
+ """
+ max_reg = self.REG_CALIB
+ if self._params['drv'] == 'ina231':
+ max_reg = self.REG_ALRT
+
+ if reg > max_reg or reg < self.REG_CFG:
+ raise Ina2xxError("register index %d, out of range" % reg)
+
def _read_reg(self, reg):
"""Read architected register and return value."""
return self._i2c_obj._read_reg(reg)
@@ -283,8 +301,7 @@
if 'reg' not in self._params:
raise Ina2xxError("no register defined in paramters")
reg = int(self._params['reg'])
- if reg > self.REG_CALIB or reg < self.REG_CFG:
- raise Ina2xxError("register index %d, out of range" % reg)
+ self._check_reg_index(reg)
return self._read_reg(reg)
def _Set_writereg(self, value):
@@ -303,8 +320,7 @@
reg = int(self._params['reg'])
except ValueError, e:
raise Ina2xxError(e)
- if reg > self.REG_CALIB or reg < self.REG_CFG:
- raise Ina2xxError("register index %d, out of range" % reg)
+ self._check_reg_index(reg)
self._i2c_obj._write_reg(reg, value)
def _wake(self):