33// USB-PD driver for TPS65987 and the mostly compatible TPS65993 and TPS65994.
44// I2C register reference: https://www.ti.com/lit/ug/slvubh2b/slvubh2b.pdf
55
6+ #include "usbpd.h"
67#include <board/battery.h>
78#include <board/gpio.h>
89#include <board/power.h>
9- #include <board/usbpd.h>
1010#include <common/debug.h>
1111#include <ec/i2c.h>
1212
1515#define REG_ACTIVE_CONTRACT_PDO 0x34
1616
1717void usbpd_init (void ) {
18- i2c_reset (& I2C_USBPD , true);
18+ i2c_reset (& USBPD_I2C , true);
1919}
2020
2121static int16_t usbpd_current_limit (void ) {
2222 uint8_t value [7 ] = { 0 };
23- int16_t res = i2c_get (& I2C_USBPD , USBPD_ADDRESS , REG_ACTIVE_CONTRACT_PDO , value , sizeof (value ));
23+ int16_t res = i2c_get (& USBPD_I2C , USBPD_ADDRESS , REG_ACTIVE_CONTRACT_PDO , value , sizeof (value ));
2424 if (res == 7 ) {
2525 if (value [0 ] == 6 ) {
2626 uint32_t pdo = ((uint32_t )value [1 ]) | (((uint32_t )value [2 ]) << 8 ) |
@@ -72,7 +72,7 @@ static void usbpd_dump(void) {
7272 // Dump all registers for debugging
7373 for (uint8_t reg = 0x00 ; reg < 0x40 ; reg += 1 ) {
7474 uint8_t value [65 ] = { 0 };
75- int16_t res = i2c_get (& I2C_USBPD , USBPD_ADDRESS , reg , value , sizeof (value ));
75+ int16_t res = i2c_get (& USBPD_I2C , USBPD_ADDRESS , reg , value , sizeof (value ));
7676 if (res < 0 ) {
7777 DEBUG ("USBPD %02X ERROR %04X\n" , reg , res );
7878 } else {
@@ -168,7 +168,7 @@ static int16_t usbpd_aneg(void) {
168168 int16_t res ;
169169
170170 uint8_t cmd [5 ] = { 4 , 'A' , 'N' , 'e' , 'g' };
171- res = i2c_set (& I2C_USBPD , USBPD_ADDRESS , 0x08 , cmd , sizeof (cmd ));
171+ res = i2c_set (& USBPD_I2C , USBPD_ADDRESS , 0x08 , cmd , sizeof (cmd ));
172172 if (res < 0 ) {
173173 return res ;
174174 }
@@ -185,7 +185,7 @@ void usbpd_disable_charging(void) {
185185
186186 // Read current value
187187 uint8_t value [2 ] = { 0 };
188- res = i2c_get (& I2C_USBPD , USBPD_ADDRESS , 0x33 , value , sizeof (value ));
188+ res = i2c_get (& USBPD_I2C , USBPD_ADDRESS , 0x33 , value , sizeof (value ));
189189 if (res < 0 ) {
190190 DEBUG ("ERR %04X\n" , - res );
191191 return ;
@@ -200,7 +200,7 @@ void usbpd_disable_charging(void) {
200200 // Enable only the first TX sink PDO (5V)
201201 value [0 ] = 1 ;
202202 value [1 ] = 1 ;
203- res = i2c_set (& I2C_USBPD , USBPD_ADDRESS , 0x33 , value , sizeof (value ));
203+ res = i2c_set (& USBPD_I2C , USBPD_ADDRESS , 0x33 , value , sizeof (value ));
204204 if (res < 0 ) {
205205 DEBUG ("ERR %04X\n" , - res );
206206 return ;
@@ -223,7 +223,7 @@ void usbpd_enable_charging(void) {
223223
224224 // Read current value
225225 uint8_t value [2 ] = { 0 };
226- res = i2c_get (& I2C_USBPD , USBPD_ADDRESS , 0x33 , value , sizeof (value ));
226+ res = i2c_get (& USBPD_I2C , USBPD_ADDRESS , 0x33 , value , sizeof (value ));
227227 if (res < 0 ) {
228228 DEBUG ("ERR %04X\n" , - res );
229229 return ;
@@ -238,7 +238,7 @@ void usbpd_enable_charging(void) {
238238 // Enable the first two TX sink PDO (5V and 20V)
239239 value [0 ] = 1 ;
240240 value [1 ] = 2 ;
241- res = i2c_set (& I2C_USBPD , USBPD_ADDRESS , 0x33 , value , sizeof (value ));
241+ res = i2c_set (& USBPD_I2C , USBPD_ADDRESS , 0x33 , value , sizeof (value ));
242242 if (res < 0 ) {
243243 DEBUG ("ERR %04X\n" , - res );
244244 return ;
0 commit comments