- Added iPaq h3xxx battery driver - Added Broadcom STB reset driver - DT support for rx51-battery - misc. fixes -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABCgAGBQJT4WyFAAoJENju1/PIO/qaYvwP/0EcchAHFS6mCyYAs8/h9JPC HMwlGh899FlFtu1Ggr5VIZnWKOdKKmOTcg0HFS63KjFGglyCzrRysXU2oa62LMla d6n7sGzlFFC+OE5neBFs44ieg5iFcff++Vw2Xij804SZDNMTaMzpNASh4jmjmxD3 DHxVLYLQd1Xx30kB/KyXhi+UIMvZDKF2F06CmViNg8eQiq59FTsjYeIJAxFJrfyN C95a3BEnzDuK8w9ylj0pN25bWpScI7B+AaC/bFz9qBRDqeKTQkj1D0t6ZLr7pJnN a2lf+w3px6RBaK+O2fez9z8Drpi35BuaJ4x4f0ieWvlONanvRc6kyLwzggs40X2U BQbgSj88Chk3S6rfdGDYxw8qxcgtrkG1jeazsusdQxRik1vLnjWIw26yYB2Qs5mg zz38h21Ur3l72GTUuTYU+gvX7fHZe81asZaQvb9j/SgYu5NSX2xrVmwYB4z6V0Uj SK5Chp45X7xonRQO9jqnFIN2ADF49cOjPflBHBr7bU4lMFciG2DEN10W9YeVMLDG iYvjNWaztzuxIVEXIwiVAJluVp/379TLZ47/dmdMt4zUBqccAFn0ZiyZFScOku2F gxHzQhFPZueOfo3Mv65SP8RXEVn4ZaLAK+vk/u//orXHf5KGmNf8hLg+40aZT/bw FL2MkAtOgwKtuz70ddya =6Y4V -----END PGP SIGNATURE----- Merge tag 'for-v3.17' of git://git.infradead.org/battery-2.6 Pull power supply changes from Sebastian Reichel: - Added iPaq h3xxx battery driver - Added Broadcom STB reset driver - DT support for rx51-battery - misc. fixes * tag 'for-v3.17' of git://git.infradead.org/battery-2.6: ipaq_micro_battery: fix sparse non static symbol warning power: add driver for battery reading on iPaq h3xxx power: twl4030_charger: detect battery presence prior to enabling charger power: reset: Add reboot driver for brcmstb power_supply: Fix sparse non static symbol warning power_supply: Add inlmt,iterm, min/max temp props charger: tps65090: Allow charger module to be used when no irq power/reset: Fix GPL v2 license string typo power: poweroff: gpio: convert to use descriptors bq27000: report missing device better. bq27x00_battery: Introduce the use of the managed version of kzalloc Documentation: DT: Document rx51-battery binding rx51_battery: convert to iio consumer bq2415x_charger: Fix Atomic Sleep Bugtirimbino
commit
0498cf8429
@ -0,0 +1,25 @@ |
||||
Binding for Nokia N900 battery |
||||
|
||||
The Nokia N900 battery status can be read via the TWL4030's A/D converter. |
||||
|
||||
Required properties: |
||||
- compatible: Should contain one of the following: |
||||
* "nokia,n900-battery" |
||||
- io-channels: Should contain IIO channel specifiers |
||||
for each element in io-channel-names. |
||||
- io-channel-names: Should contain the following values: |
||||
* "temp" - The ADC channel for temperature reading |
||||
* "bsi" - The ADC channel for battery size identification |
||||
* "vbat" - The ADC channel to measure the battery voltage |
||||
|
||||
Example from Nokia N900: |
||||
|
||||
battery: n900-battery { |
||||
compatible = "nokia,n900-battery"; |
||||
io-channels = <&twl4030_madc 0>, |
||||
<&twl4030_madc 4>, |
||||
<&twl4030_madc 12>; |
||||
io-channel-names = "temp", |
||||
"bsi", |
||||
"vbat"; |
||||
}; |
@ -0,0 +1,290 @@ |
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License version 2 as |
||||
* published by the Free Software Foundation. |
||||
* |
||||
* h3xxx atmel micro companion support, battery subdevice |
||||
* based on previous kernel 2.4 version |
||||
* Author : Alessandro Gardich <gremlin@gremlin.it> |
||||
* Author : Linus Walleij <linus.walleij@linaro.org> |
||||
* |
||||
*/ |
||||
|
||||
#include <linux/module.h> |
||||
#include <linux/init.h> |
||||
#include <linux/platform_device.h> |
||||
#include <linux/mfd/ipaq-micro.h> |
||||
#include <linux/power_supply.h> |
||||
#include <linux/workqueue.h> |
||||
|
||||
#define BATT_PERIOD 100000 /* 100 seconds in milliseconds */ |
||||
|
||||
#define MICRO_BATT_CHEM_ALKALINE 0x01 |
||||
#define MICRO_BATT_CHEM_NICD 0x02 |
||||
#define MICRO_BATT_CHEM_NIMH 0x03 |
||||
#define MICRO_BATT_CHEM_LION 0x04 |
||||
#define MICRO_BATT_CHEM_LIPOLY 0x05 |
||||
#define MICRO_BATT_CHEM_NOT_INSTALLED 0x06 |
||||
#define MICRO_BATT_CHEM_UNKNOWN 0xff |
||||
|
||||
#define MICRO_BATT_STATUS_HIGH 0x01 |
||||
#define MICRO_BATT_STATUS_LOW 0x02 |
||||
#define MICRO_BATT_STATUS_CRITICAL 0x04 |
||||
#define MICRO_BATT_STATUS_CHARGING 0x08 |
||||
#define MICRO_BATT_STATUS_CHARGEMAIN 0x10 |
||||
#define MICRO_BATT_STATUS_DEAD 0x20 /* Battery will not charge */ |
||||
#define MICRO_BATT_STATUS_NOTINSTALLED 0x20 /* For expansion pack batteries */ |
||||
#define MICRO_BATT_STATUS_FULL 0x40 /* Battery fully charged */ |
||||
#define MICRO_BATT_STATUS_NOBATTERY 0x80 |
||||
#define MICRO_BATT_STATUS_UNKNOWN 0xff |
||||
|
||||
struct micro_battery { |
||||
struct ipaq_micro *micro; |
||||
struct workqueue_struct *wq; |
||||
struct delayed_work update; |
||||
u8 ac; |
||||
u8 chemistry; |
||||
unsigned int voltage; |
||||
u16 temperature; |
||||
u8 flag; |
||||
}; |
||||
|
||||
static void micro_battery_work(struct work_struct *work) |
||||
{ |
||||
struct micro_battery *mb = container_of(work, |
||||
struct micro_battery, update.work); |
||||
struct ipaq_micro_msg msg_battery = { |
||||
.id = MSG_BATTERY, |
||||
}; |
||||
struct ipaq_micro_msg msg_sensor = { |
||||
.id = MSG_THERMAL_SENSOR, |
||||
}; |
||||
|
||||
/* First send battery message */ |
||||
ipaq_micro_tx_msg_sync(mb->micro, &msg_battery); |
||||
if (msg_battery.rx_len < 4) |
||||
pr_info("ERROR"); |
||||
|
||||
/*
|
||||
* Returned message format: |
||||
* byte 0: 0x00 = Not plugged in |
||||
* 0x01 = AC adapter plugged in |
||||
* byte 1: chemistry |
||||
* byte 2: voltage LSB |
||||
* byte 3: voltage MSB |
||||
* byte 4: flags |
||||
* byte 5-9: same for battery 2 |
||||
*/ |
||||
mb->ac = msg_battery.rx_data[0]; |
||||
mb->chemistry = msg_battery.rx_data[1]; |
||||
mb->voltage = ((((unsigned short)msg_battery.rx_data[3] << 8) + |
||||
msg_battery.rx_data[2]) * 5000L) * 1000 / 1024; |
||||
mb->flag = msg_battery.rx_data[4]; |
||||
|
||||
if (msg_battery.rx_len == 9) |
||||
pr_debug("second battery ignored\n"); |
||||
|
||||
/* Then read the sensor */ |
||||
ipaq_micro_tx_msg_sync(mb->micro, &msg_sensor); |
||||
mb->temperature = msg_sensor.rx_data[1] << 8 | msg_sensor.rx_data[0]; |
||||
|
||||
queue_delayed_work(mb->wq, &mb->update, msecs_to_jiffies(BATT_PERIOD)); |
||||
} |
||||
|
||||
static int get_capacity(struct power_supply *b) |
||||
{ |
||||
struct micro_battery *mb = dev_get_drvdata(b->dev->parent); |
||||
|
||||
switch (mb->flag & 0x07) { |
||||
case MICRO_BATT_STATUS_HIGH: |
||||
return 100; |
||||
break; |
||||
case MICRO_BATT_STATUS_LOW: |
||||
return 50; |
||||
break; |
||||
case MICRO_BATT_STATUS_CRITICAL: |
||||
return 5; |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
static int get_status(struct power_supply *b) |
||||
{ |
||||
struct micro_battery *mb = dev_get_drvdata(b->dev->parent); |
||||
|
||||
if (mb->flag == MICRO_BATT_STATUS_UNKNOWN) |
||||
return POWER_SUPPLY_STATUS_UNKNOWN; |
||||
|
||||
if (mb->flag & MICRO_BATT_STATUS_FULL) |
||||
return POWER_SUPPLY_STATUS_FULL; |
||||
|
||||
if ((mb->flag & MICRO_BATT_STATUS_CHARGING) || |
||||
(mb->flag & MICRO_BATT_STATUS_CHARGEMAIN)) |
||||
return POWER_SUPPLY_STATUS_CHARGING; |
||||
|
||||
return POWER_SUPPLY_STATUS_DISCHARGING; |
||||
} |
||||
|
||||
static int micro_batt_get_property(struct power_supply *b, |
||||
enum power_supply_property psp, |
||||
union power_supply_propval *val) |
||||
{ |
||||
struct micro_battery *mb = dev_get_drvdata(b->dev->parent); |
||||
|
||||
switch (psp) { |
||||
case POWER_SUPPLY_PROP_TECHNOLOGY: |
||||
switch (mb->chemistry) { |
||||
case MICRO_BATT_CHEM_NICD: |
||||
val->intval = POWER_SUPPLY_TECHNOLOGY_NiCd; |
||||
break; |
||||
case MICRO_BATT_CHEM_NIMH: |
||||
val->intval = POWER_SUPPLY_TECHNOLOGY_NiMH; |
||||
break; |
||||
case MICRO_BATT_CHEM_LION: |
||||
val->intval = POWER_SUPPLY_TECHNOLOGY_LION; |
||||
break; |
||||
case MICRO_BATT_CHEM_LIPOLY: |
||||
val->intval = POWER_SUPPLY_TECHNOLOGY_LIPO; |
||||
break; |
||||
default: |
||||
val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; |
||||
break; |
||||
}; |
||||
break; |
||||
case POWER_SUPPLY_PROP_STATUS: |
||||
val->intval = get_status(b); |
||||
break; |
||||
case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: |
||||
val->intval = 4700000; |
||||
break; |
||||
case POWER_SUPPLY_PROP_CAPACITY: |
||||
val->intval = get_capacity(b); |
||||
break; |
||||
case POWER_SUPPLY_PROP_TEMP: |
||||
val->intval = mb->temperature; |
||||
break; |
||||
case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
||||
val->intval = mb->voltage; |
||||
break; |
||||
default: |
||||
return -EINVAL; |
||||
}; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int micro_ac_get_property(struct power_supply *b, |
||||
enum power_supply_property psp, |
||||
union power_supply_propval *val) |
||||
{ |
||||
struct micro_battery *mb = dev_get_drvdata(b->dev->parent); |
||||
|
||||
switch (psp) { |
||||
case POWER_SUPPLY_PROP_ONLINE: |
||||
val->intval = mb->ac; |
||||
break; |
||||
default: |
||||
return -EINVAL; |
||||
}; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static enum power_supply_property micro_batt_power_props[] = { |
||||
POWER_SUPPLY_PROP_TECHNOLOGY, |
||||
POWER_SUPPLY_PROP_STATUS, |
||||
POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, |
||||
POWER_SUPPLY_PROP_CAPACITY, |
||||
POWER_SUPPLY_PROP_TEMP, |
||||
POWER_SUPPLY_PROP_VOLTAGE_NOW, |
||||
}; |
||||
|
||||
static struct power_supply micro_batt_power = { |
||||
.name = "main-battery", |
||||
.type = POWER_SUPPLY_TYPE_BATTERY, |
||||
.properties = micro_batt_power_props, |
||||
.num_properties = ARRAY_SIZE(micro_batt_power_props), |
||||
.get_property = micro_batt_get_property, |
||||
.use_for_apm = 1, |
||||
}; |
||||
|
||||
static enum power_supply_property micro_ac_power_props[] = { |
||||
POWER_SUPPLY_PROP_ONLINE, |
||||
}; |
||||
|
||||
static struct power_supply micro_ac_power = { |
||||
.name = "ac", |
||||
.type = POWER_SUPPLY_TYPE_MAINS, |
||||
.properties = micro_ac_power_props, |
||||
.num_properties = ARRAY_SIZE(micro_ac_power_props), |
||||
.get_property = micro_ac_get_property, |
||||
}; |
||||
|
||||
static int micro_batt_probe(struct platform_device *pdev) |
||||
{ |
||||
struct micro_battery *mb; |
||||
|
||||
mb = devm_kzalloc(&pdev->dev, sizeof(*mb), GFP_KERNEL); |
||||
if (!mb) |
||||
return -ENOMEM; |
||||
|
||||
mb->micro = dev_get_drvdata(pdev->dev.parent); |
||||
mb->wq = create_singlethread_workqueue("ipaq-battery-wq"); |
||||
INIT_DELAYED_WORK(&mb->update, micro_battery_work); |
||||
platform_set_drvdata(pdev, mb); |
||||
queue_delayed_work(mb->wq, &mb->update, 1); |
||||
power_supply_register(&pdev->dev, µ_batt_power); |
||||
power_supply_register(&pdev->dev, µ_ac_power); |
||||
|
||||
dev_info(&pdev->dev, "iPAQ micro battery driver\n"); |
||||
return 0; |
||||
} |
||||
|
||||
static int micro_batt_remove(struct platform_device *pdev) |
||||
|
||||
{ |
||||
struct micro_battery *mb = platform_get_drvdata(pdev); |
||||
|
||||
power_supply_unregister(µ_ac_power); |
||||
power_supply_unregister(µ_batt_power); |
||||
cancel_delayed_work_sync(&mb->update); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int micro_batt_suspend(struct device *dev) |
||||
{ |
||||
struct micro_battery *mb = dev_get_drvdata(dev); |
||||
|
||||
cancel_delayed_work_sync(&mb->update); |
||||
return 0; |
||||
} |
||||
|
||||
static int micro_batt_resume(struct device *dev) |
||||
{ |
||||
struct micro_battery *mb = dev_get_drvdata(dev); |
||||
|
||||
queue_delayed_work(mb->wq, &mb->update, msecs_to_jiffies(BATT_PERIOD)); |
||||
return 0; |
||||
} |
||||
|
||||
static const struct dev_pm_ops micro_batt_dev_pm_ops = { |
||||
SET_SYSTEM_SLEEP_PM_OPS(micro_batt_suspend, micro_batt_resume) |
||||
}; |
||||
|
||||
static struct platform_driver micro_batt_device_driver = { |
||||
.driver = { |
||||
.name = "ipaq-micro-battery", |
||||
.pm = µ_batt_dev_pm_ops, |
||||
}, |
||||
.probe = micro_batt_probe, |
||||
.remove = micro_batt_remove, |
||||
}; |
||||
module_platform_driver(micro_batt_device_driver); |
||||
|
||||
MODULE_LICENSE("GPL"); |
||||
MODULE_DESCRIPTION("driver for iPAQ Atmel micro battery"); |
||||
MODULE_ALIAS("platform:battery-ipaq-micro"); |
@ -0,0 +1,120 @@ |
||||
/*
|
||||
* Copyright (C) 2013 Broadcom Corporation |
||||
* |
||||
* This program is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU General Public License as |
||||
* published by the Free Software Foundation version 2. |
||||
* |
||||
* This program is distributed "as is" WITHOUT ANY WARRANTY of any |
||||
* kind, whether express or implied; without even the implied warranty |
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
*/ |
||||
|
||||
#include <linux/device.h> |
||||
#include <linux/errno.h> |
||||
#include <linux/init.h> |
||||
#include <linux/io.h> |
||||
#include <linux/jiffies.h> |
||||
#include <linux/of_address.h> |
||||
#include <linux/of_irq.h> |
||||
#include <linux/of_platform.h> |
||||
#include <linux/platform_device.h> |
||||
#include <linux/printk.h> |
||||
#include <linux/reboot.h> |
||||
#include <linux/regmap.h> |
||||
#include <linux/smp.h> |
||||
#include <linux/mfd/syscon.h> |
||||
|
||||
#include <asm/system_misc.h> |
||||
|
||||
#define RESET_SOURCE_ENABLE_REG 1 |
||||
#define SW_MASTER_RESET_REG 2 |
||||
|
||||
static struct regmap *regmap; |
||||
static u32 rst_src_en; |
||||
static u32 sw_mstr_rst; |
||||
|
||||
static void brcmstb_reboot(enum reboot_mode mode, const char *cmd) |
||||
{ |
||||
int rc; |
||||
u32 tmp; |
||||
|
||||
rc = regmap_write(regmap, rst_src_en, 1); |
||||
if (rc) { |
||||
pr_err("failed to write rst_src_en (%d)\n", rc); |
||||
return; |
||||
} |
||||
|
||||
rc = regmap_read(regmap, rst_src_en, &tmp); |
||||
if (rc) { |
||||
pr_err("failed to read rst_src_en (%d)\n", rc); |
||||
return; |
||||
} |
||||
|
||||
rc = regmap_write(regmap, sw_mstr_rst, 1); |
||||
if (rc) { |
||||
pr_err("failed to write sw_mstr_rst (%d)\n", rc); |
||||
return; |
||||
} |
||||
|
||||
rc = regmap_read(regmap, sw_mstr_rst, &tmp); |
||||
if (rc) { |
||||
pr_err("failed to read sw_mstr_rst (%d)\n", rc); |
||||
return; |
||||
} |
||||
|
||||
while (1) |
||||
; |
||||
} |
||||
|
||||
static int brcmstb_reboot_probe(struct platform_device *pdev) |
||||
{ |
||||
int rc; |
||||
struct device_node *np = pdev->dev.of_node; |
||||
|
||||
regmap = syscon_regmap_lookup_by_phandle(np, "syscon"); |
||||
if (IS_ERR(regmap)) { |
||||
pr_err("failed to get syscon phandle\n"); |
||||
return -EINVAL; |
||||
} |
||||
|
||||
rc = of_property_read_u32_index(np, "syscon", RESET_SOURCE_ENABLE_REG, |
||||
&rst_src_en); |
||||
if (rc) { |
||||
pr_err("can't get rst_src_en offset (%d)\n", rc); |
||||
return -EINVAL; |
||||
} |
||||
|
||||
rc = of_property_read_u32_index(np, "syscon", SW_MASTER_RESET_REG, |
||||
&sw_mstr_rst); |
||||
if (rc) { |
||||
pr_err("can't get sw_mstr_rst offset (%d)\n", rc); |
||||
return -EINVAL; |
||||
} |
||||
|
||||
arm_pm_restart = brcmstb_reboot; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static const struct of_device_id of_match[] = { |
||||
{ .compatible = "brcm,brcmstb-reboot", }, |
||||
{}, |
||||
}; |
||||
|
||||
static struct platform_driver brcmstb_reboot_driver = { |
||||
.probe = brcmstb_reboot_probe, |
||||
.driver = { |
||||
.name = "brcmstb-reboot", |
||||
.owner = THIS_MODULE, |
||||
.of_match_table = of_match, |
||||
}, |
||||
}; |
||||
|
||||
static int __init brcmstb_reboot_init(void) |
||||
{ |
||||
return platform_driver_probe(&brcmstb_reboot_driver, |
||||
brcmstb_reboot_probe); |
||||
} |
||||
subsys_initcall(brcmstb_reboot_init); |
Loading…
Reference in new issue