BigW Consortium Gitlab

Commit fd386000 by David Frey

backport features required for bq27xxx

The bq27xxx module now compiles for both 9x15 and 9x07 based targets. The module has not been tested yet.
parent ee8e9a36
......@@ -56,7 +56,7 @@
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/power/bq27xxx_battery.h>
#include "bq27xxx_battery.h"
#define BQ27XXX_MANUFACTURER "Texas Instruments"
......
sources:
{
bq27xxx_battery.c
power_supply_backport.c
}
\ No newline at end of file
......@@ -19,7 +19,7 @@
#include <linux/module.h>
#include <asm/unaligned.h>
#include <linux/power/bq27xxx_battery.h>
#include "bq27xxx_battery.h"
static DEFINE_IDR(battery_id);
static DEFINE_MUTEX(battery_mutex);
......
sources:
{
bq27xxx_battery_i2c.c
devres_backport.c
}
requires:
......
#ifndef DEVICE_BACKPORT_H
#define DEVICE_BACKPORT_H
#include <linux/compiler.h>
#include <linux/gfp.h>
/* Pulled from linux/compiler-gcc.h */
#define __malloc __attribute__((__malloc__))
extern __printf(3, 0)
char *devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, va_list ap) __malloc;
extern __printf(3, 4)
char *devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...) __malloc;
#endif /* DEVICE_BACKPORT_H */
#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
#include <linux/slab.h>
#include <linux/device.h>
#include "device_backport.h"
/**
* devm_kvasprintf - Allocate resource managed space and format a string
* into that.
* @dev: Device to allocate memory for
* @gfp: the GFP mask used in the devm_kmalloc() call when
* allocating memory
* @fmt: The printf()-style format string
* @ap: Arguments for the format string
* RETURNS:
* Pointer to allocated string on success, NULL on failure.
*/
char *devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt,
va_list ap)
{
unsigned int len;
char *p;
va_list aq;
va_copy(aq, ap);
len = vsnprintf(NULL, 0, fmt, aq);
va_end(aq);
p = devm_kmalloc(dev, len+1, gfp);
if (!p)
return NULL;
vsnprintf(p, len+1, fmt, ap);
return p;
}
EXPORT_SYMBOL(devm_kvasprintf);
/**
* devm_kasprintf - Allocate resource managed space and format a string
* into that.
* @dev: Device to allocate memory for
* @gfp: the GFP mask used in the devm_kmalloc() call when
* allocating memory
* @fmt: The printf()-style format string
* @...: Arguments for the format string
* RETURNS:
* Pointer to allocated string on success, NULL on failure.
*/
char *devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...)
{
va_list ap;
char *p;
va_start(ap, fmt);
p = devm_kvasprintf(dev, gfp, fmt, ap);
va_end(ap);
return p;
}
EXPORT_SYMBOL_GPL(devm_kasprintf);
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) */
/*
* This file contains backported features of the power supply subsystem from 4.18-rc8
*/
#include <linux/device.h>
#include <linux/of.h>
#include <linux/power_supply.h>
#include "power_supply_backport.h"
int power_supply_get_battery_info(struct power_supply *psy,
struct power_supply_battery_info *info)
{
struct device_node *battery_np;
const char *value;
int err;
info->energy_full_design_uwh = -EINVAL;
info->charge_full_design_uah = -EINVAL;
info->voltage_min_design_uv = -EINVAL;
info->precharge_current_ua = -EINVAL;
info->charge_term_current_ua = -EINVAL;
info->constant_charge_current_max_ua = -EINVAL;
info->constant_charge_voltage_max_uv = -EINVAL;
if (!psy->of_node) {
dev_warn(psy->dev, "%s currently only supports devicetree\n",
__func__);
return -ENXIO;
}
battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
if (!battery_np)
return -ENODEV;
err = of_property_read_string(battery_np, "compatible", &value);
if (err)
return err;
if (strcmp("simple-battery", value))
return -ENODEV;
/* The property and field names below must correspond to elements
* in enum power_supply_property. For reasoning, see
* Documentation/power/power_supply_class.txt.
*/
of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
&info->energy_full_design_uwh);
of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
&info->charge_full_design_uah);
of_property_read_u32(battery_np, "voltage-min-design-microvolt",
&info->voltage_min_design_uv);
of_property_read_u32(battery_np, "precharge-current-microamp",
&info->precharge_current_ua);
of_property_read_u32(battery_np, "charge-term-current-microamp",
&info->charge_term_current_ua);
of_property_read_u32(battery_np, "constant_charge_current_max_microamp",
&info->constant_charge_current_max_ua);
of_property_read_u32(battery_np, "constant_charge_voltage_max_microvolt",
&info->constant_charge_voltage_max_uv);
return 0;
}
EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
#ifndef POWER_SUPPLY_BACKPORT_H
#define POWER_SUPPLY_BACKPORT_H
/*
* This is the recommended struct to manage static battery parameters,
* populated by power_supply_get_battery_info(). Most platform drivers should
* use these for consistency.
* Its field names must correspond to elements in enum power_supply_property.
* The default field value is -EINVAL.
* Power supply class itself doesn't use this.
*/
struct power_supply_battery_info {
int energy_full_design_uwh; /* microWatt-hours */
int charge_full_design_uah; /* microAmp-hours */
int voltage_min_design_uv; /* microVolts */
int precharge_current_ua; /* microAmps */
int charge_term_current_ua; /* microAmps */
int constant_charge_current_max_ua; /* microAmps */
int constant_charge_voltage_max_uv; /* microVolts */
};
extern int power_supply_get_battery_info(struct power_supply *psy,
struct power_supply_battery_info *info);
#endif /* POWER_SUPPLY_BACKPORT_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment