1010#include <drivers/i2c.h>
1111#include <drivers/gpio.h>
1212#include <sys/byteorder.h>
13- #include "tmo_batt_charger.h"
13+ #include "tmo_bq24250.h"
14+
15+ #if DT_NODE_HAS_STATUS (DT_NODELABEL (bq24250 ), okay )
1416
1517#define BQ_GPIO_F_NAME "GPIO_F"
1618#define BQ_CHARGE_INT 12 /* PF12 - configured here */
@@ -46,9 +48,9 @@ static const struct device *i2c1_dev = DEVICE_DT_GET(DT_NODELABEL(i2c1));
4648static struct gpio_callback gpio_batt_chrg_cb ;
4749int bq_battery_charge_int_isr_count = 0 ;
4850bool bq_battery_charge_int_state_change = false;
49-
5051uint8_t i2c_read_data [20 ];
51- static int i2c_read_to_buffer ( uint8_t dev_addr , int reg_addr , uint8_t * buf , uint8_t buf_length )
52+
53+ static int i2c_read_to_buffer (uint8_t dev_addr , int reg_addr , uint8_t * buf , uint8_t buf_length )
5254{
5355 const struct device * dev ;
5456 uint8_t reg_addr_buf [MAX_BYTES_FOR_REGISTER_INDEX ];
@@ -72,11 +74,10 @@ static int i2c_read_to_buffer( uint8_t dev_addr, int reg_addr, uint8_t *buf, uin
7274 printf ("Failed to read from device: 0x%x" , dev_addr );
7375 return - EIO ;
7476 }
75-
7677 return 0 ;
7778}
7879
79- int get_bq24250_charger_vbus_status (uint8_t * charging , uint8_t * vbus , uint8_t * attached , uint8_t * fault )
80+ int get_bq24250_status (uint8_t * charging , uint8_t * vbus , uint8_t * attached , uint8_t * fault )
8081{
8182 int ret = 0 ;
8283 uint8_t bq_addr = 0x6a ;
@@ -93,40 +94,38 @@ int get_bq24250_charger_vbus_status (uint8_t * charging, uint8_t * vbus, uint8_t
9394 uint8_t charger_status = ((bq_reg_0x00_data & 0x30 ) >> 4 );
9495 uint8_t charge_fault_status = (bq_reg_0x00_data & 0x0F );
9596
97+ * vbus = 0 ;
98+ * charging = 0 ;
99+ * attached = 0 ;
100+ * fault = 0 ;
96101
97- * vbus = 0 ;
98- * charging = 0 ;
99- * attached = 0 ;
100- * fault = 0 ;
101-
102- if ((charger_status == 3 ) && (charge_fault_status > 0 )) {
103- * vbus = 0 ;
104- * charging = 0 ;
105- if (charge_fault_status == 8 ) {
106- * attached = 0 ;
107- }
108- else {
109- * attached = 1 ;
110- * fault = 1 ;
111- }
112- }
113- else {
114- if ((charger_status == 1 ) && (charge_fault_status == 0 )) {
115- * vbus = 1 ;
116- * charging = 1 ;
117- * attached = 1 ;
118- }
119- else {
120- * vbus = 1 ;
121- * charging = 0 ;
122- * attached = 1 ;
123- }
124- }
125-
126- return ret ;
102+ if ((charger_status == 3 ) && (charge_fault_status > 0 )) {
103+ * vbus = 0 ;
104+ * charging = 0 ;
105+ if (charge_fault_status == 8 ) {
106+ * attached = 0 ;
107+ }
108+ else {
109+ * attached = 1 ;
110+ * fault = 1 ;
111+ }
112+ }
113+ else {
114+ if ((charger_status == 1 ) && (charge_fault_status == 0 )) {
115+ * vbus = 1 ;
116+ * charging = 1 ;
117+ * attached = 1 ;
118+ }
119+ else {
120+ * vbus = 1 ;
121+ * charging = 0 ;
122+ * attached = 1 ;
123+ }
124+ }
125+ return ret ;
127126}
128127
129- static int check_battery_charger_regs (void )
128+ static int check_battery_charger_regs (void )
130129{
131130 int ret = 0 ;
132131
@@ -240,18 +239,17 @@ static int check_battery_charger_regs (void)
240239 break ;
241240 }
242241 }
243-
244242 return ret ;
245243}
246244
247- void bq_intr_callback (const struct device * port ,
245+ static void bq_intr_callback (const struct device * port ,
248246 struct gpio_callback * cb , uint32_t pins )
249247{
250248 bq_battery_charge_int_isr_count ++ ;
251249 bq_battery_charge_int_state_change = true;
252250}
253251
254- void bq_thread (void * a , void * b , void * c )
252+ static void bq_thread (void * a , void * b , void * c )
255253{
256254 ARG_UNUSED (a );
257255 ARG_UNUSED (b );
@@ -330,7 +328,6 @@ void bq_thread(void *a, void *b, void *c)
330328#define BQ_NOTIF_THREAD_STACK_SIZE 2048
331329#define BQ_NOTIF_THREAD_PRIORITY CONFIG_MAIN_THREAD_PRIORITY
332330
333- #if DT_NODE_HAS_STATUS (DT_NODELABEL (bq24250 ), okay )
334331K_THREAD_DEFINE (bq_tid , BQ_NOTIF_THREAD_STACK_SIZE ,
335332 bq_thread , NULL , NULL , NULL ,
336333 BQ_NOTIF_THREAD_PRIORITY , 0 , 0 );
0 commit comments