#define BUS_PP_PRECHG_CURRENT_MASK 0x0E
#define BUS_POWER_PATH_PRECHG_ENA 0x01
-/**
- * struct ab8500_res_to_temp - defines one point in a temp to res curve. To
- * be used in battery packs that combines the identification resistor with a
- * NTC resistor.
- * @temp: battery pack temperature in Celsius
- * @resist: NTC resistor net total resistance
- */
-struct ab8500_res_to_temp {
- int temp;
- int resist;
-};
-
/* Forward declaration */
struct ab8500_fg;
* @maint_b_chg_timer_h: charge time in maintenance B state
* @low_high_cur_lvl: charger current in temp low/high state in mA
* @low_high_vol_lvl: charger voltage in temp low/high state in mV'
- * @n_r_t_tbl_elements: number of elements in r_to_t_tbl
- * @r_to_t_tbl: table containing resistance to temp points
*/
struct ab8500_battery_type {
int resis_high;
int maint_b_chg_timer_h;
int low_high_cur_lvl;
int low_high_vol_lvl;
- int n_temp_tbl_elements;
- const struct ab8500_res_to_temp *r_to_t_tbl;
};
/**
const struct ab8500_fg_parameters *fg_params;
};
-enum {
- NTC_EXTERNAL = 0,
- NTC_INTERNAL,
-};
-
-/**
- * struct res_to_temp - defines one point in a temp to res curve. To
- * be used in battery packs that combines the identification resistor with a
- * NTC resistor.
- * @temp: battery pack temperature in Celsius
- * @resist: NTC resistor net total resistance
- */
-struct res_to_temp {
- int temp;
- int resist;
-};
-
/* Forward declaration */
struct ab8500_fg;
#include <linux/mfd/core.h>
#include <linux/mfd/abx500.h>
#include <linux/mfd/abx500/ab8500.h>
+#include <linux/thermal.h>
#include <linux/iio/consumer.h>
#include <linux/fixp-arith.h>
#include "ab8500-bm.h"
-#define VTVOUT_V 1800
-
#define BTEMP_THERMAL_LOW_LIMIT -10
#define BTEMP_THERMAL_MED_LIMIT 0
#define BTEMP_THERMAL_HIGH_LIMIT_52 52
* @bat_temp: Dispatched battery temperature in degree Celsius
* @prev_bat_temp Last measured battery temperature in degree Celsius
* @parent: Pointer to the struct ab8500
- * @adc_btemp_ball: ADC channel for the battery ball temperature
+ * @tz: Thermal zone for the battery
* @adc_bat_ctrl: ADC channel for the battery control
* @fg: Pointer to the struct fg
* @bm: Platform specific battery management information
int bat_temp;
int prev_bat_temp;
struct ab8500 *parent;
- struct iio_channel *btemp_ball;
+ struct thermal_zone_device *tz;
struct iio_channel *bat_ctrl;
struct ab8500_fg *fg;
struct ab8500_bm_data *bm;
return res;
}
-/**
- * ab8500_btemp_res_to_temp() - resistance to temperature
- * @di: pointer to the ab8500_btemp structure
- * @tbl: pointer to the resiatance to temperature table
- * @tbl_size: size of the resistance to temperature table
- * @res: resistance to calculate the temperature from
- *
- * This function returns the battery temperature in degrees Celsius
- * based on the NTC resistance.
- */
-static int ab8500_btemp_res_to_temp(struct ab8500_btemp *di,
- const struct ab8500_res_to_temp *tbl, int tbl_size, int res)
-{
- int i;
- /*
- * Calculate the formula for the straight line
- * Simple interpolation if we are within
- * the resistance table limits, extrapolate
- * if resistance is outside the limits.
- */
- if (res > tbl[0].resist)
- i = 0;
- else if (res <= tbl[tbl_size - 1].resist)
- i = tbl_size - 2;
- else {
- i = 0;
- while (!(res <= tbl[i].resist &&
- res > tbl[i + 1].resist))
- i++;
- }
-
- return fixp_linear_interpolate(tbl[i].resist, tbl[i].temp,
- tbl[i + 1].resist, tbl[i + 1].temp,
- res);
-}
-
-/**
- * ab8500_btemp_measure_temp() - measure battery temperature
- * @di: pointer to the ab8500_btemp structure
- *
- * Returns battery temperature (on success) else the previous temperature
- */
-static int ab8500_btemp_measure_temp(struct ab8500_btemp *di)
-{
- int temp, ret;
- static int prev;
- int rntc, vntc;
-
- ret = iio_read_channel_processed(di->btemp_ball, &vntc);
- if (ret < 0) {
- dev_err(di->dev,
- "%s ADC conversion failed,"
- " using previous value\n", __func__);
- return prev;
- }
- /*
- * The PCB NTC is sourced from VTVOUT via a 230kOhm
- * resistor.
- */
- rntc = 230000 * vntc / (VTVOUT_V - vntc);
-
- temp = ab8500_btemp_res_to_temp(di,
- di->bm->bat_type->r_to_t_tbl,
- di->bm->bat_type->n_temp_tbl_elements, rntc);
- prev = temp;
-
- dev_dbg(di->dev, "Battery temperature is %d\n", temp);
- return temp;
-}
-
/**
* ab8500_btemp_id() - Identify the connected battery
* @di: pointer to the ab8500_btemp structure
int bat_temp;
struct ab8500_btemp *di = container_of(work,
struct ab8500_btemp, btemp_periodic_work.work);
+ /* Assume 25 degrees celsius as start temperature */
+ static int prev = 25;
+ int ret;
if (!di->initialized) {
/* Identify the battery */
dev_warn(di->dev, "failed to identify the battery\n");
}
- bat_temp = ab8500_btemp_measure_temp(di);
+ /* Failover if a reading is erroneous, use last meausurement */
+ ret = thermal_zone_get_temp(di->tz, &bat_temp);
+ if (ret) {
+ dev_err(di->dev, "error reading temperature\n");
+ bat_temp = prev;
+ } else {
+ /* Convert from millicentigrades to centigrades */
+ bat_temp /= 1000;
+ prev = bat_temp;
+ }
+
/*
* Filter battery temperature.
* Allow direct updates on temperature only if two samples result in
di->dev = dev;
di->parent = dev_get_drvdata(pdev->dev.parent);
- /* Get ADC channels */
- di->btemp_ball = devm_iio_channel_get(dev, "btemp_ball");
- if (IS_ERR(di->btemp_ball)) {
- ret = dev_err_probe(dev, PTR_ERR(di->btemp_ball),
- "failed to get BTEMP BALL ADC channel\n");
- return ret;
+ /* Get thermal zone and ADC */
+ di->tz = thermal_zone_get_zone_by_name("battery-thermal");
+ if (IS_ERR(di->tz)) {
+ return dev_err_probe(dev, PTR_ERR(di->tz),
+ "failed to get battery thermal zone\n");
}
di->bat_ctrl = devm_iio_channel_get(dev, "bat_ctrl");
if (IS_ERR(di->bat_ctrl)) {