From 1b99ed4133a6ee618345353fe08a695a8806b382 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 22 Mar 2021 09:56:42 +1300 Subject: Create a public header for isl923x Add a separate public header for this chip so we can include it from Zephyr. Update the charger file to use that header, so it builds on Zephyr. BUG=b:183296099 BRANCH=none TEST=make BOARD=lazor -j4 Signed-off-by: Simon Glass Change-Id: I54506ef17ecda2683f1c1a933f1978df458e08ea Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2774916 Reviewed-by: Jack Rosenthal Reviewed-by: Keith Short --- driver/charger/isl923x.c | 3 +- driver/charger/isl923x.h | 43 ++------------------------- include/driver/charger/isl923x_public.h | 51 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 41 deletions(-) create mode 100644 include/driver/charger/isl923x_public.h diff --git a/driver/charger/isl923x.c b/driver/charger/isl923x.c index 7d2b894f96..2f822d64e1 100644 --- a/driver/charger/isl923x.c +++ b/driver/charger/isl923x.c @@ -95,7 +95,7 @@ enum isl923x_mon_dir { MON_CHARGE = 0, MON_DISCHARGE = 1 }; static int learn_mode; /* Mutex for CONTROL1 register, that can be updated from multiple tasks. */ -static struct mutex control1_mutex; +static mutex_t control1_mutex; static enum ec_error_list isl923x_discharge_on_ac(int chgnum, int enable); @@ -559,6 +559,7 @@ static void isl923x_init(int chgnum) int precharge_voltage = bi->precharge_voltage ? bi->precharge_voltage : bi->voltage_min; + (void)k_mutex_init(&control1_mutex); if (IS_ENABLED(CONFIG_CHARGER_RAA489000)) { if (CONFIG_CHARGER_SENSE_RESISTOR == CONFIG_CHARGER_SENSE_RESISTOR_AC) { diff --git a/driver/charger/isl923x.h b/driver/charger/isl923x.h index 5da8649c38..69bc82389c 100644 --- a/driver/charger/isl923x.h +++ b/driver/charger/isl923x.h @@ -9,8 +9,7 @@ #ifndef __CROS_EC_ISL923X_H #define __CROS_EC_ISL923X_H -#include "stdbool.h" -#define ISL923X_ADDR_FLAGS (0x09) +#include "driver/charger/isl923x_public.h" /* Registers */ #define ISL923X_REG_CHG_CURRENT 0x14 @@ -345,43 +344,7 @@ enum isl9237_fsm_state { #define I2C_ADDR_CHARGER_FLAGS ISL923X_ADDR_FLAGS -extern const struct charger_drv isl923x_drv; - -#endif /* __CROS_EC_ISL923X_H */ - -/** - * Initialize AC & DC prochot threshold - * - * @param chgnum: Index into charger chips - * @param AC Prochot threshold current in mA: - * multiple of 128 up to 6400 mA - * DC Prochot threshold current in mA: - * multiple of 128 up to 12800 mA - * Bits below 128mA are truncated (ignored). - * @return enum ec_error_list - */ -int isl923x_set_ac_prochot(int chgnum, uint16_t ma); -int isl923x_set_dc_prochot(int chgnum, uint16_t ma); - -/** - * Set the general comparator output polarity when asserted. - * - * @param chgnum: Index into charger chips - * @param invert: Non-zero to invert polarity, zero to non-invert. - * @return EC_SUCCESS, error otherwise. - */ -int isl923x_set_comparator_inversion(int chgnum, int invert); - -/** - * Prepare the charger IC for battery ship mode. Battery ship mode sets the - * lowest power state for the IC. Battery ship mode can only be entered from - * battery only mode. - * - * @param chgnum index into chg_chips table. - */ -void raa489000_hibernate(int chgnum, bool disable_adc); -enum ec_error_list isl9238c_hibernate(int chgnum); -enum ec_error_list isl9238c_resume(int chgnum); - #define ISL923X_AC_PROCHOT_CURRENT_MAX 6400 /* mA */ #define ISL923X_DC_PROCHOT_CURRENT_MAX 12800 /* mA */ + +#endif /* __CROS_EC_ISL923X_H */ diff --git a/include/driver/charger/isl923x_public.h b/include/driver/charger/isl923x_public.h new file mode 100644 index 0000000000..df3b0ce057 --- /dev/null +++ b/include/driver/charger/isl923x_public.h @@ -0,0 +1,51 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Renesas (Intersil) ISL-9237/38 battery charger public header + */ + +#ifndef __CROS_EC_DRIVER_CHARGER_ISL923X_PUBLIC_H +#define __CROS_EC_DRIVER_CHARGER_ISL923X_PUBLIC_H + +#include "stdbool.h" + +#define ISL923X_ADDR_FLAGS (0x09) + +extern const struct charger_drv isl923x_drv; + +/** + * Initialize AC & DC prochot threshold + * + * @param chgnum: Index into charger chips + * @param AC Prochot threshold current in mA: + * multiple of 128 up to 6400 mA + * DC Prochot threshold current in mA: + * multiple of 128 up to 12800 mA + * Bits below 128mA are truncated (ignored). + * @return enum ec_error_list + */ +int isl923x_set_ac_prochot(int chgnum, uint16_t ma); +int isl923x_set_dc_prochot(int chgnum, uint16_t ma); + +/** + * Set the general comparator output polarity when asserted. + * + * @param chgnum: Index into charger chips + * @param invert: Non-zero to invert polarity, zero to non-invert. + * @return EC_SUCCESS, error otherwise. + */ +int isl923x_set_comparator_inversion(int chgnum, int invert); + +/** + * Prepare the charger IC for battery ship mode. Battery ship mode sets the + * lowest power state for the IC. Battery ship mode can only be entered from + * battery only mode. + * + * @param chgnum index into chg_chips table. + */ +void raa489000_hibernate(int chgnum, bool disable_adc); +enum ec_error_list isl9238c_hibernate(int chgnum); +enum ec_error_list isl9238c_resume(int chgnum); + +#endif /* __CROS_EC_DRIVER_CHARGER_ISL923X_PUBLIC_H */ -- cgit v1.2.1