]>
Commit | Line | Data |
---|---|---|
61b0cfe9 L |
1 | /* |
2 | * Copyright (C) 2009 Sergey Kubushyn <ksi@koi8.net> | |
3 | * Copyright (C) 2009 - 2013 Heiko Schocher <hs@denx.de> | |
4 | * Changes for multibus/multiadapter I2C support. | |
5 | * | |
6 | * (C) Copyright 2001 | |
7 | * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com. | |
8 | * | |
9 | * SPDX-License-Identifier: GPL-2.0+ | |
10 | * | |
11 | * The original I2C interface was | |
12 | * (C) 2000 by Paolo Scaffardi (arsenio@tin.it) | |
13 | * AIRVENT SAM s.p.a - RIMINI(ITALY) | |
14 | * but has been changed substantially. | |
15 | */ | |
16 | ||
17 | #ifndef _I2C_H_ | |
18 | #define _I2C_H_ | |
19 | ||
20 | /* | |
21 | * Configuration items. | |
22 | */ | |
23 | /* TODO: config.h? */ | |
24 | #define I2C_RXTX_LEN 128 /* maximum tx/rx buffer length */ | |
25 | ||
26 | ||
27 | /* | |
28 | * Initialization, must be called once on start up, may be called | |
29 | * repeatedly to change the speed. | |
30 | */ | |
31 | void i2c_init(uint32_t speed); | |
32 | ||
33 | /* | |
34 | * Probe the given I2C chip address. Returns 0 if a chip responded, | |
35 | * not 0 on failure. | |
36 | */ | |
37 | int i2c_probe(uint8_t chip); | |
38 | ||
39 | /* | |
40 | * Read/Write interface: | |
41 | * chip: I2C chip address, range 0..127 | |
42 | * addr: Memory (register) address within the chip | |
43 | * alen: Number of bytes to use for addr (typically 1, 2 for larger | |
44 | * memories, 0 for register type devices with only one | |
45 | * register) | |
46 | * buffer: Where to read/write the data | |
47 | * len: How many bytes to read/write | |
48 | * | |
49 | * Returns: 0 on success, not 0 on failure | |
50 | */ | |
51 | int i2c_read(uint8_t chip, unsigned int addr, uint_fast8_t alen, | |
52 | uint8_t *buffer, uint_fast8_t len); | |
53 | int i2c_write(uint8_t chip, unsigned int addr, uint_fast8_t alen, | |
54 | uint8_t *buffer, uint_fast8_t len); | |
55 | ||
56 | /* | |
57 | * Utility routines to read/write registers. | |
58 | */ | |
59 | uint8_t i2c_reg_read(uint8_t addr, uint8_t reg); | |
60 | ||
61 | void i2c_reg_write(uint8_t addr, uint8_t reg, uint8_t val); | |
62 | ||
63 | #endif /* _I2C_H_*/ |