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