xref: /rk3399_ARM-atf/include/drivers/brcm/i2c/i2c.h (revision 4bd8c929b4bc6e1731c2892b38d4a8c43e8e89dc)
148c6a6b6SBharat Gooty /*
248c6a6b6SBharat Gooty  * Copyright (c) 2016 - 2021, Broadcom
348c6a6b6SBharat Gooty  *
448c6a6b6SBharat Gooty  * SPDX-License-Identifier: BSD-3-Clause
548c6a6b6SBharat Gooty  */
648c6a6b6SBharat Gooty 
748c6a6b6SBharat Gooty #ifndef I2C_H
848c6a6b6SBharat Gooty #define I2C_H
948c6a6b6SBharat Gooty 
1048c6a6b6SBharat Gooty #include <stdint.h>
1148c6a6b6SBharat Gooty 
1248c6a6b6SBharat Gooty #define I2C_SPEED_100KHz	100000
1348c6a6b6SBharat Gooty #define I2C_SPEED_400KHz	400000
1448c6a6b6SBharat Gooty #define I2C_SPEED_DEFAULT	I2C_SPEED_100KHz
1548c6a6b6SBharat Gooty 
1648c6a6b6SBharat Gooty /*
1748c6a6b6SBharat Gooty  * Function Name:    i2c_probe
1848c6a6b6SBharat Gooty  *
1948c6a6b6SBharat Gooty  * Description:
2048c6a6b6SBharat Gooty  *	This function probes the I2C bus for the existence of the specified
2148c6a6b6SBharat Gooty  *	device.
2248c6a6b6SBharat Gooty  *
2348c6a6b6SBharat Gooty  * Parameters:
2448c6a6b6SBharat Gooty  *	bus_id  - I2C bus ID
2548c6a6b6SBharat Gooty  *	devaddr - Device Address
2648c6a6b6SBharat Gooty  *
2748c6a6b6SBharat Gooty  * Return:
2848c6a6b6SBharat Gooty  *	0 on success, or -1 on failure.
2948c6a6b6SBharat Gooty  */
3048c6a6b6SBharat Gooty int i2c_probe(uint32_t bus_id, uint8_t devaddr);
3148c6a6b6SBharat Gooty 
3248c6a6b6SBharat Gooty /*
3348c6a6b6SBharat Gooty  * Function Name:    i2c_init
3448c6a6b6SBharat Gooty  *
3548c6a6b6SBharat Gooty  * Description:
3648c6a6b6SBharat Gooty  *	This function initializes the SMBUS.
3748c6a6b6SBharat Gooty  *
3848c6a6b6SBharat Gooty  * Parameters:
3948c6a6b6SBharat Gooty  *	bus_id - I2C bus ID
4048c6a6b6SBharat Gooty  *	speed  - I2C bus speed in Hz
4148c6a6b6SBharat Gooty  *
4248c6a6b6SBharat Gooty  * Return:
4348c6a6b6SBharat Gooty  *	0 on success, or -1 on failure.
4448c6a6b6SBharat Gooty  */
4548c6a6b6SBharat Gooty int i2c_init(uint32_t bus_id, int speed);
4648c6a6b6SBharat Gooty 
4748c6a6b6SBharat Gooty /*
4848c6a6b6SBharat Gooty  * Function Name:    i2c_set_bus_speed
4948c6a6b6SBharat Gooty  *
5048c6a6b6SBharat Gooty  * Description:
5148c6a6b6SBharat Gooty  *	This function configures the SMBUS speed
5248c6a6b6SBharat Gooty  *
5348c6a6b6SBharat Gooty  * Parameters:
5448c6a6b6SBharat Gooty  *	bus_id - I2C bus ID
5548c6a6b6SBharat Gooty  *	speed  - I2C bus speed in Hz
5648c6a6b6SBharat Gooty  *
5748c6a6b6SBharat Gooty  * Return:
5848c6a6b6SBharat Gooty  *	0 on success, or -1 on failure.
5948c6a6b6SBharat Gooty  */
6048c6a6b6SBharat Gooty int i2c_set_bus_speed(uint32_t bus_id, uint32_t speed);
6148c6a6b6SBharat Gooty 
6248c6a6b6SBharat Gooty /*
6348c6a6b6SBharat Gooty  * Function Name:    i2c_get_bus_speed
6448c6a6b6SBharat Gooty  *
6548c6a6b6SBharat Gooty  * Description:
6648c6a6b6SBharat Gooty  *	This function returns the SMBUS speed.
6748c6a6b6SBharat Gooty  *
6848c6a6b6SBharat Gooty  * Parameters:
6948c6a6b6SBharat Gooty  *	bus_id - I2C bus ID
7048c6a6b6SBharat Gooty  *
7148c6a6b6SBharat Gooty  * Return:
7248c6a6b6SBharat Gooty  *	Bus speed in Hz, 0 on failure
7348c6a6b6SBharat Gooty  */
7448c6a6b6SBharat Gooty uint32_t i2c_get_bus_speed(uint32_t bus_id);
7548c6a6b6SBharat Gooty 
7648c6a6b6SBharat Gooty /*
7748c6a6b6SBharat Gooty  * Function Name:    i2c_recv_byte
7848c6a6b6SBharat Gooty  *
7948c6a6b6SBharat Gooty  * Description:
8048c6a6b6SBharat Gooty  *	This function reads I2C data from a device without specifying
81*1b491eeaSElyes Haouas  *	a command register.
8248c6a6b6SBharat Gooty  *
8348c6a6b6SBharat Gooty  * Parameters:
8448c6a6b6SBharat Gooty  *	bus_id  - I2C bus ID
8548c6a6b6SBharat Gooty  *	devaddr - Device Address
8648c6a6b6SBharat Gooty  *	value   - Data Read
8748c6a6b6SBharat Gooty  *
8848c6a6b6SBharat Gooty  * Return:
8948c6a6b6SBharat Gooty  *	0 on success, or -1 on failure.
9048c6a6b6SBharat Gooty  */
9148c6a6b6SBharat Gooty int i2c_recv_byte(uint32_t bus_id, uint8_t devaddr, uint8_t *value);
9248c6a6b6SBharat Gooty 
9348c6a6b6SBharat Gooty /*
9448c6a6b6SBharat Gooty  * Function Name:    i2c_send_byte
9548c6a6b6SBharat Gooty  *
9648c6a6b6SBharat Gooty  * Description:
9748c6a6b6SBharat Gooty  *	This function send I2C data to a device without specifying
98*1b491eeaSElyes Haouas  *	a command register.
9948c6a6b6SBharat Gooty  *
10048c6a6b6SBharat Gooty  * Parameters:
10148c6a6b6SBharat Gooty  *	bus_id  - I2C bus ID
10248c6a6b6SBharat Gooty  *	devaddr - Device Address
10348c6a6b6SBharat Gooty  *	value   - Data Send
10448c6a6b6SBharat Gooty  *
10548c6a6b6SBharat Gooty  * Return:
10648c6a6b6SBharat Gooty  *	0 on success, or -1 on failure.
10748c6a6b6SBharat Gooty  */
10848c6a6b6SBharat Gooty int i2c_send_byte(uint32_t bus_id, uint8_t devaddr, uint8_t value);
10948c6a6b6SBharat Gooty 
11048c6a6b6SBharat Gooty /*
11148c6a6b6SBharat Gooty  * Function Name:    i2c_read
11248c6a6b6SBharat Gooty  *
11348c6a6b6SBharat Gooty  * Description:
11448c6a6b6SBharat Gooty  *	This function reads I2C data from a device with a designated
11548c6a6b6SBharat Gooty  *	command register
11648c6a6b6SBharat Gooty  *
11748c6a6b6SBharat Gooty  * Parameters:
11848c6a6b6SBharat Gooty  *	bus_id  - I2C bus ID
11948c6a6b6SBharat Gooty  *	devaddr - Device Address
12048c6a6b6SBharat Gooty  *	addr    - Register Offset
12148c6a6b6SBharat Gooty  *	alen    - Address Length, 1 for byte, 2 for word (not supported)
12248c6a6b6SBharat Gooty  *	buffer  - Data Buffer
12348c6a6b6SBharat Gooty  *	len     - Data Length in bytes
12448c6a6b6SBharat Gooty  *
12548c6a6b6SBharat Gooty  * Return:
12648c6a6b6SBharat Gooty  *	0 on success, or -1 on failure.
12748c6a6b6SBharat Gooty  */
12848c6a6b6SBharat Gooty int i2c_read(uint32_t bus_id,
12948c6a6b6SBharat Gooty 	     uint8_t devaddr,
13048c6a6b6SBharat Gooty 	     uint32_t addr,
13148c6a6b6SBharat Gooty 	     int alen,
13248c6a6b6SBharat Gooty 	     uint8_t *buffer,
13348c6a6b6SBharat Gooty 	     int len);
13448c6a6b6SBharat Gooty 
13548c6a6b6SBharat Gooty /*
13648c6a6b6SBharat Gooty  * Function Name:    i2c_write
13748c6a6b6SBharat Gooty  *
13848c6a6b6SBharat Gooty  * Description:
13948c6a6b6SBharat Gooty  *	This function write I2C data to a device with a designated
14048c6a6b6SBharat Gooty  *	command register
14148c6a6b6SBharat Gooty  *
14248c6a6b6SBharat Gooty  * Parameters:
14348c6a6b6SBharat Gooty  *	bus_id  - I2C bus ID
14448c6a6b6SBharat Gooty  *	devaddr - Device Address
14548c6a6b6SBharat Gooty  *	addr    - Register Offset
14648c6a6b6SBharat Gooty  *	alen    - Address Length, 1 for byte, 2 for word (not supported)
14748c6a6b6SBharat Gooty  *	buffer  - Data Buffer
14848c6a6b6SBharat Gooty  *	len     - Data Length in bytes
14948c6a6b6SBharat Gooty  *
15048c6a6b6SBharat Gooty  * Return:
15148c6a6b6SBharat Gooty  *	0 on success, or -1 on failure.
15248c6a6b6SBharat Gooty  */
15348c6a6b6SBharat Gooty int i2c_write(uint32_t bus_id,
15448c6a6b6SBharat Gooty 	      uint8_t devaddr,
15548c6a6b6SBharat Gooty 	      uint32_t addr,
15648c6a6b6SBharat Gooty 	      int alen,
15748c6a6b6SBharat Gooty 	      uint8_t *buffer,
15848c6a6b6SBharat Gooty 	      int len);
15948c6a6b6SBharat Gooty 
16048c6a6b6SBharat Gooty 
16148c6a6b6SBharat Gooty #endif /* I2C_H */
162