mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-09 17:11:42 +00:00
Big: Correct the charger IC driver
Add bq24735 driver and move to here for further developing BRANCH=big BUG=None TEST=test basic charing/discharging function Change-Id: I66c22a29cf94383cec86c5cf53db82494504fa77 Reviewed-on: https://chromium-review.googlesource.com/196541 Reviewed-by: Yung-chieh Lo <yjlou@chromium.org> Tested-by: Lin Cloud <cloud_lin@compal.com> Commit-Queue: Lin Cloud <cloud_lin@compal.com>
This commit is contained in:
committed by
chrome-internal-fetch
parent
2e7ea4efdb
commit
295e409ea9
@@ -14,7 +14,7 @@
|
||||
#define CONFIG_BATTERY_CUT_OFF
|
||||
#define CONFIG_CHARGER
|
||||
#define CONFIG_CHARGER_V2
|
||||
#define CONFIG_CHARGER_BQ24725
|
||||
#define CONFIG_CHARGER_BQ24735
|
||||
#define CONFIG_CHIPSET_TEGRA
|
||||
#define CONFIG_POWER_COMMON
|
||||
#define CONFIG_EXTPOWER_GPIO
|
||||
|
||||
@@ -24,6 +24,7 @@ driver-$(CONFIG_CHARGER_BQ24192)+=charger/bq24192.o
|
||||
driver-$(CONFIG_CHARGER_BQ24707A)+=charger/bq24707a.o
|
||||
driver-$(CONFIG_CHARGER_BQ24715)+=charger/bq24715.o
|
||||
driver-$(CONFIG_CHARGER_BQ24725)+=charger/bq24725.o
|
||||
driver-$(CONFIG_CHARGER_BQ24735)+=charger/bq24735.o
|
||||
driver-$(CONFIG_CHARGER_BQ24738)+=charger/bq24738.o
|
||||
driver-$(CONFIG_CHARGER_BQ24773)+=charger/bq24773.o
|
||||
|
||||
|
||||
183
driver/charger/bq24735.c
Normal file
183
driver/charger/bq24735.c
Normal file
@@ -0,0 +1,183 @@
|
||||
/* Copyright (c) 2014 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.
|
||||
*
|
||||
* TI bq24735 battery charger driver.
|
||||
*/
|
||||
|
||||
#include "battery_smart.h"
|
||||
#include "bq24735.h"
|
||||
#include "charger.h"
|
||||
#include "console.h"
|
||||
#include "common.h"
|
||||
#include "util.h"
|
||||
|
||||
/* Sense resistor configurations and macros */
|
||||
#define DEFAULT_SENSE_RESISTOR 10
|
||||
#define R_SNS CONFIG_CHARGER_SENSE_RESISTOR
|
||||
#define R_AC CONFIG_CHARGER_SENSE_RESISTOR_AC
|
||||
#define REG_TO_CURRENT(REG, RS) ((REG) * DEFAULT_SENSE_RESISTOR / (RS))
|
||||
#define CURRENT_TO_REG(CUR, RS) ((CUR) * (RS) / DEFAULT_SENSE_RESISTOR)
|
||||
|
||||
/* Charger infomation
|
||||
* charge voltage bitmask: 0111 1111 1111 0000
|
||||
* charge current bitmask: 0001 1111 1000 0000
|
||||
* input current bitmask : 0000 0000 1000 0000
|
||||
*/
|
||||
static const struct charger_info bq24735_charger_info = {
|
||||
.name = "bq24735",
|
||||
.voltage_max = 19200,
|
||||
.voltage_min = 1024,
|
||||
.voltage_step = 16,
|
||||
.current_max = REG_TO_CURRENT(8128, R_SNS),
|
||||
.current_min = REG_TO_CURRENT(128, R_SNS),
|
||||
.current_step = REG_TO_CURRENT(128, R_SNS),
|
||||
.input_current_max = REG_TO_CURRENT(8064, R_AC),
|
||||
.input_current_min = REG_TO_CURRENT(128, R_AC),
|
||||
.input_current_step = REG_TO_CURRENT(128, R_AC),
|
||||
};
|
||||
|
||||
/* bq24735 specific interfaces */
|
||||
|
||||
int charger_set_input_current(int input_current)
|
||||
{
|
||||
return sbc_write(BQ24735_INPUT_CURRENT,
|
||||
CURRENT_TO_REG(input_current, R_AC));
|
||||
}
|
||||
|
||||
int charger_get_input_current(int *input_current)
|
||||
{
|
||||
int rv;
|
||||
int reg;
|
||||
|
||||
rv = sbc_read(BQ24735_INPUT_CURRENT, ®);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
*input_current = REG_TO_CURRENT(reg, R_AC);
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int charger_manufacturer_id(int *id)
|
||||
{
|
||||
return sbc_read(BQ24735_MANUFACTURE_ID, id);
|
||||
}
|
||||
|
||||
int charger_device_id(int *id)
|
||||
{
|
||||
return sbc_read(BQ24735_DEVICE_ID, id);
|
||||
}
|
||||
|
||||
int charger_get_option(int *option)
|
||||
{
|
||||
return sbc_read(BQ24735_CHARGE_OPTION, option);
|
||||
}
|
||||
|
||||
int charger_set_option(int option)
|
||||
{
|
||||
return sbc_write(BQ24735_CHARGE_OPTION, option);
|
||||
}
|
||||
|
||||
/* Charger interfaces */
|
||||
|
||||
const struct charger_info *charger_get_info(void)
|
||||
{
|
||||
return &bq24735_charger_info;
|
||||
}
|
||||
|
||||
int charger_get_status(int *status)
|
||||
{
|
||||
int rv;
|
||||
int option;
|
||||
|
||||
rv = charger_get_option(&option);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
/* Default status */
|
||||
*status = CHARGER_LEVEL_2;
|
||||
|
||||
if (option & OPTION_CHARGE_INHIBIT)
|
||||
*status |= CHARGER_CHARGE_INHIBITED;
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int charger_set_mode(int mode)
|
||||
{
|
||||
int rv;
|
||||
int option;
|
||||
|
||||
rv = charger_get_option(&option);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
if (mode & CHARGE_FLAG_INHIBIT_CHARGE)
|
||||
option |= OPTION_CHARGE_INHIBIT;
|
||||
else
|
||||
option &= ~OPTION_CHARGE_INHIBIT;
|
||||
return charger_set_option(option);
|
||||
}
|
||||
|
||||
int charger_get_current(int *current)
|
||||
{
|
||||
int rv;
|
||||
int reg;
|
||||
|
||||
rv = sbc_read(SB_CHARGING_CURRENT, ®);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
*current = REG_TO_CURRENT(reg, R_SNS);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int charger_set_current(int current)
|
||||
{
|
||||
current = charger_closest_current(current);
|
||||
|
||||
return sbc_write(SB_CHARGING_CURRENT, CURRENT_TO_REG(current, R_SNS));
|
||||
}
|
||||
|
||||
int charger_get_voltage(int *voltage)
|
||||
{
|
||||
return sbc_read(SB_CHARGING_VOLTAGE, voltage);
|
||||
}
|
||||
|
||||
int charger_set_voltage(int voltage)
|
||||
{
|
||||
return sbc_write(SB_CHARGING_VOLTAGE, voltage);
|
||||
}
|
||||
|
||||
/* Charging power state initialization */
|
||||
int charger_post_init(void)
|
||||
{
|
||||
/*
|
||||
* Note: bq24735 power on reset state is:
|
||||
* watch dog timer = 175 sec
|
||||
* input current limit = ~1/2 maximum setting
|
||||
* charging voltage = 0 mV
|
||||
* charging current = 0 mA
|
||||
*/
|
||||
|
||||
/* Set charger input current limit */
|
||||
return charger_set_input_current(CONFIG_CHARGER_INPUT_CURRENT);
|
||||
}
|
||||
|
||||
int charger_discharge_on_ac(int enable)
|
||||
{
|
||||
int rv;
|
||||
int option;
|
||||
|
||||
rv = charger_get_option(&option);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
if (enable)
|
||||
rv = charger_set_option(option | OPTION_LEARN_ENABLE);
|
||||
else
|
||||
rv = charger_set_option(option & ~OPTION_LEARN_ENABLE);
|
||||
|
||||
return rv;
|
||||
}
|
||||
57
driver/charger/bq24735.h
Normal file
57
driver/charger/bq24735.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* Copyright (c) 2014 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.
|
||||
*
|
||||
* TI bq24735 battery charger driver.
|
||||
*/
|
||||
|
||||
#ifndef __CROS_EC_CHARGER_BQ24735_H
|
||||
#define __CROS_EC_CHARGER_BQ24735_H
|
||||
|
||||
/* Chip specific commands */
|
||||
#define BQ24735_CHARGE_OPTION 0x12
|
||||
#define BQ24735_INPUT_CURRENT 0x3f
|
||||
#define BQ24735_MANUFACTURE_ID 0xfe
|
||||
#define BQ24735_DEVICE_ID 0xff
|
||||
|
||||
/* ChargeOption 0x12 */
|
||||
#define OPTION_CHARGE_INHIBIT (1 << 0)
|
||||
#define OPTION_ACOC_THRESHOLD (1 << 1)
|
||||
#define OPTION_BOOST_MODE_STATE (1 << 2)
|
||||
#define OPTION_BOOST_MODE_ENABLE (1 << 3)
|
||||
#define OPTION_ACDET_STATE (1 << 4)
|
||||
#define OPTION_IOUT_SELECTION (1 << 5)
|
||||
#define OPTION_LEARN_ENABLE (1 << 6)
|
||||
#define OPTION_IFAULT_LOW_THRESHOLD (1 << 7)
|
||||
#define OPTION_IFAULT_HI_ENABLE (1 << 8)
|
||||
#define OPTION_EMI_FREQ_ENABLE (1 << 9)
|
||||
#define OPTION_EMI_FREQ_ADJ (1 << 10)
|
||||
#define OPTION_BAT_DEPLETION_THRESHOLD (3 << 11)
|
||||
#define OPTION_WATCHDOG_TIMER (3 << 13)
|
||||
#define OPTION_ACPRES_DEGLITCH_TIME (1 << 15)
|
||||
|
||||
/* OPTION_ACOC_THRESHOLD */
|
||||
#define ACOC_THRESHOLD_DISABLE (0 << 1)
|
||||
#define ACOC_THRESHOLD_133X (1 << 1)
|
||||
|
||||
/* OPTION_IFAULT_LOW_THRESHOLD */
|
||||
#define IFAULT_LOW_135MV_DEFAULT (0 << 7)
|
||||
#define IFAULT_LOW_230MV (1 << 7)
|
||||
|
||||
/* OPTION_BAT_DEPLETION_THRESHOLD */
|
||||
#define FALLING_THRESHOLD_5919 (0 << 11)
|
||||
#define FALLING_THRESHOLD_6265 (1 << 11)
|
||||
#define FALLING_THRESHOLD_6655 (2 << 11)
|
||||
#define FALLING_THRESHOLD_7097_DEFAULT (3 << 11)
|
||||
|
||||
/* OPTION_WATCHDOG_TIMER */
|
||||
#define CHARGE_WATCHDOG_DISABLE (0 << 13)
|
||||
#define CHARGE_WATCHDOG_44SEC (1 << 13)
|
||||
#define CHARGE_WATCHDOG_88SEC (2 << 13)
|
||||
#define CHARGE_WATCHDOG_175SEC_DEFAULT (3 << 13)
|
||||
|
||||
/* OPTION_ACPRES_DEGLITCH_TIME */
|
||||
#define ACPRES_DEGLITCH_150MS (0 << 15)
|
||||
#define ACPRES_DEGLITCH_1300MS_DEFAULT (1 << 15)
|
||||
|
||||
#endif /* __CROS_EC_CHARGER_BQ24735_H */
|
||||
Reference in New Issue
Block a user