summaryrefslogtreecommitdiff
path: root/driver/ina3221.h
blob: 5d642bba3b8da988427b3169f55653b964eeaa0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Copyright 2019 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 * TI INA3221 Current/Power monitor driver.
 */

#ifndef __CROS_EC_INA3221_H
#define __CROS_EC_INA3221_H

#define INA3221_REG_CONFIG 0x00
#define INA3221_REG_MASK 0x0F

/*
 * Common bits are:
 * Reset
 * average = 1
 * conversion time = 1.1 ms
 * mode = shunt and bus, continuous.
 */
#define INA3221_CONFIG_BASE 0x8127

/* Bus voltage: lower 3 bits clear, LSB = 8 mV */
#define INA3221_BUS_MV(reg) (reg)
/* Shunt voltage: lower 3 bits clear, LSB = 40 uV */
#define INA3221_SHUNT_UV(reg) ((reg) * (40 / 8))

enum ina3221_channel {
	INA3221_CHAN_1 = 0,
	INA3221_CHAN_2 = 1,
	INA3221_CHAN_3 = 2,
	INA3221_CHAN_COUNT = 3
};

/* Registers for each channel */
enum ina3221_register {
	INA3221_SHUNT_VOLT = 0,
	INA3221_BUS_VOLT = 1,
	INA3221_CRITICAL = 2,
	INA3221_WARNING = 3,
	INA3221_MAX_REG = 4
};

/* Configuration table - defined in board file. */
struct ina3221_t {
	int port; /* I2C port index */
	uint8_t address; /* I2C address */
	const char *name[INA3221_CHAN_COUNT]; /* Channel names */
};

/* External config in board file */
extern const struct ina3221_t ina3221[];
extern const unsigned int ina3221_count;

#endif /* __CROS_EC_INA3221_H */