summaryrefslogtreecommitdiff
path: root/board/servo_v4p1/tca6416a.h
blob: 5255059d993bf0702860688d03481c9b56b95159 (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
/* 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_TCA6416A_H
#define __CROS_EC_IOEXPANDER_TCA6416A_H

#include <stdint.h>

#define TCA6416A_ADDR_FLAGS 0x21

enum tca6416a_bank {
	TCA6416A_IN_PORT_0  = 0x0,
	TCA6416A_IN_PORT_1  = 0x1,
	TCA6416A_OUT_PORT_0 = 0x2,
	TCA6416A_OUT_PORT_1 = 0x3,
	TCA6416A_DIR_PORT_0 = 0x6,
	TCA6416A_DIR_PORT_1 = 0x7,
};

/*
 * Set a bit in the supplied bank
 *
 * @param port  The I2C port of TCA6416A.
 * @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 tca6416a_write_bit(int port,
			enum tca6416a_bank bank, uint8_t bit, int val);

/*
 * Get a bit in the supplied bank
 *
 * @param port  The I2C port of TCA6416A.
 * @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 tca6416a_read_bit(int port, enum tca6416a_bank bank, uint8_t bit);

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

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

#endif /* __CROS_EC_IOEXPANDER_TCA6416A_H */