2011-02-14 10:17:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) ST-Ericsson SA 2010
|
|
|
|
* Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com> for ST Ericsson.
|
|
|
|
* License terms: GNU General Public License (GPL) version 2
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/err.h>
|
2011-07-03 19:13:27 +00:00
|
|
|
#include <linux/module.h>
|
2011-02-14 10:17:12 +00:00
|
|
|
#include <linux/platform_device.h>
|
2013-01-14 13:26:15 +00:00
|
|
|
#include <linux/pm.h>
|
2011-08-17 11:20:21 +00:00
|
|
|
#include <linux/reboot.h>
|
2013-01-14 13:26:15 +00:00
|
|
|
#include <linux/signal.h>
|
2011-08-17 11:20:21 +00:00
|
|
|
#include <linux/power_supply.h>
|
2011-02-14 10:17:12 +00:00
|
|
|
#include <linux/mfd/abx500.h>
|
2011-12-02 13:16:33 +00:00
|
|
|
#include <linux/mfd/abx500/ab8500.h>
|
|
|
|
#include <linux/mfd/abx500/ab8500-sysctrl.h>
|
2011-02-14 10:17:12 +00:00
|
|
|
|
|
|
|
static struct device *sysctrl_dev;
|
|
|
|
|
2013-01-14 13:26:15 +00:00
|
|
|
void ab8500_power_off(void)
|
|
|
|
{
|
|
|
|
sigset_t old;
|
|
|
|
sigset_t all;
|
2011-08-17 11:20:21 +00:00
|
|
|
static char *pss[] = {"ab8500_ac", "ab8500_usb"};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have a charger connected and we're powering off,
|
|
|
|
* reboot into charge-only mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(pss); i++) {
|
|
|
|
union power_supply_propval val;
|
|
|
|
struct power_supply *psy;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
psy = power_supply_get_by_name(pss[i]);
|
|
|
|
if (!psy)
|
|
|
|
continue;
|
|
|
|
ret = psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &val);
|
|
|
|
|
|
|
|
if (!ret && val.intval) {
|
|
|
|
printk(KERN_INFO
|
|
|
|
"Charger \"%s\" is connected. Rebooting.\n",
|
|
|
|
pss[i]);
|
|
|
|
machine_restart(NULL);
|
|
|
|
}
|
|
|
|
}
|
2013-01-14 13:26:15 +00:00
|
|
|
|
|
|
|
sigfillset(&all);
|
|
|
|
|
|
|
|
if (!sigprocmask(SIG_BLOCK, &all, &old)) {
|
|
|
|
(void)ab8500_sysctrl_set(AB8500_STW4500CTRL1,
|
|
|
|
AB8500_STW4500CTRL1_SWOFF |
|
|
|
|
AB8500_STW4500CTRL1_SWRESET4500N);
|
|
|
|
(void)sigprocmask(SIG_SETMASK, &old, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-14 10:17:12 +00:00
|
|
|
static inline bool valid_bank(u8 bank)
|
|
|
|
{
|
|
|
|
return ((bank == AB8500_SYS_CTRL1_BLOCK) ||
|
|
|
|
(bank == AB8500_SYS_CTRL2_BLOCK));
|
|
|
|
}
|
|
|
|
|
|
|
|
int ab8500_sysctrl_read(u16 reg, u8 *value)
|
|
|
|
{
|
|
|
|
u8 bank;
|
|
|
|
|
|
|
|
if (sysctrl_dev == NULL)
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
bank = (reg >> 8);
|
|
|
|
if (!valid_bank(bank))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return abx500_get_register_interruptible(sysctrl_dev, bank,
|
|
|
|
(u8)(reg & 0xFF), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value)
|
|
|
|
{
|
|
|
|
u8 bank;
|
|
|
|
|
|
|
|
if (sysctrl_dev == NULL)
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
bank = (reg >> 8);
|
|
|
|
if (!valid_bank(bank))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return abx500_mask_and_set_register_interruptible(sysctrl_dev, bank,
|
|
|
|
(u8)(reg & 0xFF), mask, value);
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:23:04 +00:00
|
|
|
static int ab8500_sysctrl_probe(struct platform_device *pdev)
|
2011-02-14 10:17:12 +00:00
|
|
|
{
|
2013-01-14 13:26:15 +00:00
|
|
|
struct ab8500_platform_data *plat;
|
|
|
|
|
2011-02-14 10:17:12 +00:00
|
|
|
sysctrl_dev = &pdev->dev;
|
2013-01-14 13:26:15 +00:00
|
|
|
plat = dev_get_platdata(pdev->dev.parent);
|
|
|
|
if (plat->pm_power_off)
|
|
|
|
pm_power_off = ab8500_power_off;
|
2011-02-14 10:17:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:01 +00:00
|
|
|
static int ab8500_sysctrl_remove(struct platform_device *pdev)
|
2011-02-14 10:17:12 +00:00
|
|
|
{
|
|
|
|
sysctrl_dev = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver ab8500_sysctrl_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ab8500-sysctrl",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = ab8500_sysctrl_probe,
|
2012-11-19 18:20:24 +00:00
|
|
|
.remove = ab8500_sysctrl_remove,
|
2011-02-14 10:17:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ab8500_sysctrl_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&ab8500_sysctrl_driver);
|
|
|
|
}
|
|
|
|
subsys_initcall(ab8500_sysctrl_init);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com");
|
|
|
|
MODULE_DESCRIPTION("AB8500 system control driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|