summaryrefslogtreecommitdiff
path: root/board/servo_v4p1/tca6424a.h
blob: 80db7ebdba3e2fb8ba687b296ec0465b0fc9e0cc (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Copyright 2020 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef __CROS_EC_IOEXPANDER_TCA6424A_H
#define __CROS_EC_IOEXPANDER_TCA6424A_H

#include <stdint.h>

#define TCA6424A_ADDR_FLAGS 0x23

enum tca6424a_bank {
	TCA6424A_IN_PORT_0  = 0x0,
	TCA6424A_IN_PORT_1  = 0x1,
	TCA6424A_IN_PORT_2  = 0x2,
	TCA6424A_OUT_PORT_0 = 0x4,
	TCA6424A_OUT_PORT_1 = 0x5,
	TCA6424A_OUT_PORT_2 = 0x6,
	TCA6424A_DIR_PORT_0 = 0xc,
	TCA6424A_DIR_PORT_1 = 0xd,
	TCA6424A_DIR_PORT_2 = 0xe,
};

/*
 * Set a bit in the supplied bank
 *
 * @param port  The I2C port of TCA6424A.
 * @param bank  The bank the bit belongs to.
 * @param bit   The index of the bit to set.
 * @param val   The value to set.
 *
 * @return EC_SUCCESS, or EC_ERROR_* on error.
 */
int tca6424a_write_bit(int port,
			enum tca6424a_bank bank, uint8_t bit, int val);

/*
 * Get a bit in the supplied bank
 *
 * @param port  The I2C port of TCA6424A.
 * @param bank  The bank the bit belongs to.
 * @param bit   The index of the bit to get.
 *
 * @return bit value, or -1 on error.
 */
int tca6424a_read_bit(int port, enum tca6424a_bank bank, uint8_t bit);

/*
 * Write a byt to the supplied bank
 *
 * @param port The I2C port of TCA6424A.
 * @param bank  The bank to write the byte to.
 *
 * @return EC_SUCCESS, or EC_ERROR_* on error.
 */
int tca6424a_write_byte(int port, enum tca6424a_bank bank, uint8_t val);

/*
 * Read a byte in the supplied bank
 *
 * @param port  The I2C port of TCA6424A.
 * @param bank  The bank to read byte from.
 *
 * @return byte value, or -1 on error.
 */
int tca6424a_read_byte(int port, enum tca6424a_bank bank);

#endif /* __CROS_EC_IOEXPANDER_TCA6424A_H */