mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-12 19:04:59 +00:00
battery: Move presence checks out of common
Undo some of CL:1072637 so that battery_is_present() and battery_hw_present() move back to baseboard. battery_fuel_gauge.c now only includes code which is directly involved with the fuel gauge. BUG=b:109894491,b:80299100 BRANCH=none TEST=make -j buildall Change-Id: I8fc5be3856564601019d94514dcfc8ffb3071c2e Signed-off-by: Edward Hill <ecgh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1097954 Commit-Ready: Devin Lu <Devin.Lu@quantatw.com> Reviewed-by: Jett Rink <jettrink@chromium.org>
This commit is contained in:
69
baseboard/grunt/battery.c
Normal file
69
baseboard/grunt/battery.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Copyright 2018 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.
|
||||
*
|
||||
* Battery pack vendor provided charging profile
|
||||
*/
|
||||
|
||||
#include "battery.h"
|
||||
#include "battery_smart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
static enum battery_present batt_pres_prev = BP_NOT_SURE;
|
||||
|
||||
enum battery_present battery_hw_present(void)
|
||||
{
|
||||
/* The GPIO is low when the battery is physically present */
|
||||
return gpio_get_level(GPIO_EC_BATT_PRES_L) ? BP_NO : BP_YES;
|
||||
}
|
||||
|
||||
static int battery_init(void)
|
||||
{
|
||||
int batt_status;
|
||||
|
||||
return battery_status(&batt_status) ? 0 :
|
||||
!!(batt_status & STATUS_INITIALIZED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Physical detection of battery.
|
||||
*/
|
||||
static enum battery_present battery_check_present_status(void)
|
||||
{
|
||||
enum battery_present batt_pres;
|
||||
|
||||
/* Get the physical hardware status */
|
||||
batt_pres = battery_hw_present();
|
||||
|
||||
/*
|
||||
* If the battery is not physically connected, then no need to perform
|
||||
* any more checks.
|
||||
*/
|
||||
if (batt_pres != BP_YES)
|
||||
return batt_pres;
|
||||
|
||||
/*
|
||||
* If the battery is present now and was present last time we checked,
|
||||
* return early.
|
||||
*/
|
||||
if (batt_pres == batt_pres_prev)
|
||||
return batt_pres;
|
||||
|
||||
/*
|
||||
* Ensure that battery is:
|
||||
* 1. Not in cutoff
|
||||
* 2. Initialized
|
||||
*/
|
||||
if (battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL ||
|
||||
battery_init() == 0) {
|
||||
batt_pres = BP_NO;
|
||||
}
|
||||
|
||||
return batt_pres;
|
||||
}
|
||||
|
||||
enum battery_present battery_is_present(void)
|
||||
{
|
||||
batt_pres_prev = battery_check_present_status();
|
||||
return batt_pres_prev;
|
||||
}
|
||||
@@ -7,4 +7,5 @@
|
||||
#
|
||||
|
||||
baseboard-y=baseboard.o
|
||||
baseboard-$(CONFIG_BATTERY_SMART)+=battery.o
|
||||
baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
|
||||
|
||||
69
baseboard/octopus/battery.c
Normal file
69
baseboard/octopus/battery.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Copyright 2018 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.
|
||||
*
|
||||
* Battery pack vendor provided charging profile
|
||||
*/
|
||||
|
||||
#include "battery.h"
|
||||
#include "battery_smart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
static enum battery_present batt_pres_prev = BP_NOT_SURE;
|
||||
|
||||
enum battery_present battery_hw_present(void)
|
||||
{
|
||||
/* The GPIO is low when the battery is physically present */
|
||||
return gpio_get_level(GPIO_EC_BATT_PRES_L) ? BP_NO : BP_YES;
|
||||
}
|
||||
|
||||
static int battery_init(void)
|
||||
{
|
||||
int batt_status;
|
||||
|
||||
return battery_status(&batt_status) ? 0 :
|
||||
!!(batt_status & STATUS_INITIALIZED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Physical detection of battery.
|
||||
*/
|
||||
static enum battery_present battery_check_present_status(void)
|
||||
{
|
||||
enum battery_present batt_pres;
|
||||
|
||||
/* Get the physical hardware status */
|
||||
batt_pres = battery_hw_present();
|
||||
|
||||
/*
|
||||
* If the battery is not physically connected, then no need to perform
|
||||
* any more checks.
|
||||
*/
|
||||
if (batt_pres != BP_YES)
|
||||
return batt_pres;
|
||||
|
||||
/*
|
||||
* If the battery is present now and was present last time we checked,
|
||||
* return early.
|
||||
*/
|
||||
if (batt_pres == batt_pres_prev)
|
||||
return batt_pres;
|
||||
|
||||
/*
|
||||
* Ensure that battery is:
|
||||
* 1. Not in cutoff
|
||||
* 2. Initialized
|
||||
*/
|
||||
if (battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL ||
|
||||
battery_init() == 0) {
|
||||
batt_pres = BP_NO;
|
||||
}
|
||||
|
||||
return batt_pres;
|
||||
}
|
||||
|
||||
enum battery_present battery_is_present(void)
|
||||
{
|
||||
batt_pres_prev = battery_check_present_status();
|
||||
return batt_pres_prev;
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#
|
||||
|
||||
baseboard-y=baseboard.o
|
||||
baseboard-$(CONFIG_BATTERY_SMART)+=battery.o
|
||||
baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
|
||||
baseboard-$(VARIANT_OCTOPUS_EC_NPCX796FB)+=variant_ec_npcx796fb.o
|
||||
baseboard-$(VARIANT_OCTOPUS_EC_ITE8320)+=variant_ec_ite8320.o
|
||||
|
||||
@@ -7,18 +7,13 @@
|
||||
|
||||
#include "battery_fuel_gauge.h"
|
||||
#include "battery_smart.h"
|
||||
#include "charge_state.h"
|
||||
#include "common.h"
|
||||
#include "console.h"
|
||||
#include "gpio.h"
|
||||
#include "hooks.h"
|
||||
#include "util.h"
|
||||
|
||||
#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
|
||||
|
||||
|
||||
static enum battery_present batt_pres_prev = BP_NOT_SURE;
|
||||
|
||||
/* Get type of the battery connected on the board */
|
||||
static int get_battery_type(void)
|
||||
{
|
||||
@@ -118,20 +113,6 @@ int board_cut_off_battery(void)
|
||||
return rv ? EC_RES_ERROR : EC_RES_SUCCESS;
|
||||
}
|
||||
|
||||
enum battery_present battery_hw_present(void)
|
||||
{
|
||||
/* The GPIO is low when the battery is physically present */
|
||||
return gpio_get_level(GPIO_EC_BATT_PRES_L) ? BP_NO : BP_YES;
|
||||
}
|
||||
|
||||
static int battery_init(void)
|
||||
{
|
||||
int batt_status;
|
||||
|
||||
return battery_status(&batt_status) ? 0 :
|
||||
!!(batt_status & STATUS_INITIALIZED);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function checks the charge/discharge FET status bits. Each battery type
|
||||
* supported provides the register address, mask, and disconnect value for these
|
||||
@@ -181,46 +162,3 @@ enum battery_disconnect_state battery_get_disconnect_state(void)
|
||||
|
||||
return BATTERY_NOT_DISCONNECTED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Physical detection of battery.
|
||||
*/
|
||||
static enum battery_present battery_check_present_status(void)
|
||||
{
|
||||
enum battery_present batt_pres;
|
||||
|
||||
/* Get the physical hardware status */
|
||||
batt_pres = battery_hw_present();
|
||||
|
||||
/*
|
||||
* If the battery is not physically connected, then no need to perform
|
||||
* any more checks.
|
||||
*/
|
||||
if (batt_pres != BP_YES)
|
||||
return batt_pres;
|
||||
|
||||
/*
|
||||
* If the battery is present now and was present last time we checked,
|
||||
* return early.
|
||||
*/
|
||||
if (batt_pres == batt_pres_prev)
|
||||
return batt_pres;
|
||||
|
||||
/*
|
||||
* Ensure that battery is:
|
||||
* 1. Not in cutoff
|
||||
* 2. Initialized
|
||||
*/
|
||||
if (battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL ||
|
||||
battery_init() == 0) {
|
||||
batt_pres = BP_NO;
|
||||
}
|
||||
|
||||
return batt_pres;
|
||||
}
|
||||
|
||||
enum battery_present battery_is_present(void)
|
||||
{
|
||||
batt_pres_prev = battery_check_present_status();
|
||||
return batt_pres_prev;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user