![Linus Torvalds](/assets/img/avatar_default.png)
* update power/reset drivers to use kernel restart handler * add power off driver for i.mx6 * add DT support for gpio-charger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABCgAGBQJUjv52AAoJENju1/PIO/qaESIP/3rRE/Gw1fmfX+F1wN+jXQao WXw2JW/IUQG0TQlpTnEqPQQu+H48dX58MbpNVSLy2O7Z4XiMRDG2HkEduyJYGm+P 37pfgiTH9Vj7MJ0EnNK3lLrQmF1l+yNHIjZUGLPEjbKmXSzJYPHwNhtC5U9/QooY igRwKC51bBw6of6pPaIYP6nxQeaNVgI3MaOnJ1+glLc0uQuy5mc4gODL6yCEkvuR WCsyJi226m/dBD+ZgejSet7kJS3JG4dR0GuqZkJ22DS5wKbwKrgXfOiVl+xrgCwR FqbvnZbscr+jt/xFJsAT5zqtvHNgxx37XVwkV3nHsKX8UugYg3rCB5T/mlgNj+m/ Cg5BePP84O1NMJHYXSj7Wo6BYYoFJO8ucT0uIKpcci3UyvtqWcMXzptNjkAtylw1 P+0EtP7HL4jBLJ5Snd0Je47w2mztmaJmqCc9LU8odznlFbaJ25X3chf3zqAoKdpY Lqe1XWxi5HtLNmuX/NsNhw0tdxuSiH5e2r7yM5Bwtm4uh4Yx9Ab9TEtloF3u+en5 ALR88cryxbP0zu0K/HFUeoM3v7mqH3x29NqAsSpY1D6p87308FUa1rkvYMlHwcFD Y2W2iZhmxnE5Bi9OTpfDgGQYNEUiELWmMDi3S3aSwb0QM9UWsi043LGMQfpG5QCn +xKTKJDNJsHAX5jYDuDY =v7l/ -----END PGP SIGNATURE----- Merge tag 'for-v3.19' of git://git.infradead.org/battery-2.6 Pull power supply updates from Sebastian Reichel:: "Power supply and reset changes for the v3.19 series - update power/reset drivers to use kernel restart handler - add power off driver for i.mx6 - add DT support for gpio-charger" * tag 'for-v3.19' of git://git.infradead.org/battery-2.6: power: reset: adjust priority of simple syscon reboot driver power: ds2782_battery: Simplify the PM hooks power/reset: brcmstb: Register with kernel restart handler power/reset: hisi: Register with kernel restart handler power/reset: keystone: Register with kernel restart handler power/reset: axxia: Register with kernel restart handler power/reset: xgene: Register with kernel restart handler power/reset: xgene: Use mdelay instead of jiffies based timeout power/reset: xgene: Use local variable dev instead of pdev->dev power/reset: xgene: Drop devm_kfree power/reset: xgene: Return -ENOMEM if out of memory power/reset: vexpress: Register with kernel restart handler power: reset: imx-snvs-poweroff: add power off driver for i.mx6 power: gpio-charger: add device tree support dt-bindings: document gpio-charger bindings
176 lines
4.2 KiB
C
176 lines
4.2 KiB
C
/*
|
|
* TI keystone reboot driver
|
|
*
|
|
* Copyright (C) 2014 Texas Instruments Incorporated. http://www.ti.com/
|
|
*
|
|
* Author: Ivan Khoronzhuk <ivan.khoronzhuk@ti.com>
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include <linux/io.h>
|
|
#include <linux/module.h>
|
|
#include <linux/notifier.h>
|
|
#include <linux/reboot.h>
|
|
#include <linux/regmap.h>
|
|
#include <linux/mfd/syscon.h>
|
|
#include <linux/of_platform.h>
|
|
|
|
#define RSTYPE_RG 0x0
|
|
#define RSCTRL_RG 0x4
|
|
#define RSCFG_RG 0x8
|
|
#define RSISO_RG 0xc
|
|
|
|
#define RSCTRL_KEY_MASK 0x0000ffff
|
|
#define RSCTRL_RESET_MASK BIT(16)
|
|
#define RSCTRL_KEY 0x5a69
|
|
|
|
#define RSMUX_OMODE_MASK 0xe
|
|
#define RSMUX_OMODE_RESET_ON 0xa
|
|
#define RSMUX_OMODE_RESET_OFF 0x0
|
|
#define RSMUX_LOCK_MASK 0x1
|
|
#define RSMUX_LOCK_SET 0x1
|
|
|
|
#define RSCFG_RSTYPE_SOFT 0x300f
|
|
#define RSCFG_RSTYPE_HARD 0x0
|
|
|
|
#define WDT_MUX_NUMBER 0x4
|
|
|
|
static int rspll_offset;
|
|
static struct regmap *pllctrl_regs;
|
|
|
|
/**
|
|
* rsctrl_enable_rspll_write - enable access to RSCTRL, RSCFG
|
|
* To be able to access to RSCTRL, RSCFG registers
|
|
* we have to write a key before
|
|
*/
|
|
static inline int rsctrl_enable_rspll_write(void)
|
|
{
|
|
return regmap_update_bits(pllctrl_regs, rspll_offset + RSCTRL_RG,
|
|
RSCTRL_KEY_MASK, RSCTRL_KEY);
|
|
}
|
|
|
|
static int rsctrl_restart_handler(struct notifier_block *this,
|
|
unsigned long mode, void *cmd)
|
|
{
|
|
/* enable write access to RSTCTRL */
|
|
rsctrl_enable_rspll_write();
|
|
|
|
/* reset the SOC */
|
|
regmap_update_bits(pllctrl_regs, rspll_offset + RSCTRL_RG,
|
|
RSCTRL_RESET_MASK, 0);
|
|
|
|
return NOTIFY_DONE;
|
|
}
|
|
|
|
static struct notifier_block rsctrl_restart_nb = {
|
|
.notifier_call = rsctrl_restart_handler,
|
|
.priority = 128,
|
|
};
|
|
|
|
static struct of_device_id rsctrl_of_match[] = {
|
|
{.compatible = "ti,keystone-reset", },
|
|
{},
|
|
};
|
|
|
|
static int rsctrl_probe(struct platform_device *pdev)
|
|
{
|
|
int i;
|
|
int ret;
|
|
u32 val;
|
|
unsigned int rg;
|
|
u32 rsmux_offset;
|
|
struct regmap *devctrl_regs;
|
|
struct device *dev = &pdev->dev;
|
|
struct device_node *np = dev->of_node;
|
|
|
|
if (!np)
|
|
return -ENODEV;
|
|
|
|
/* get regmaps */
|
|
pllctrl_regs = syscon_regmap_lookup_by_phandle(np, "ti,syscon-pll");
|
|
if (IS_ERR(pllctrl_regs))
|
|
return PTR_ERR(pllctrl_regs);
|
|
|
|
devctrl_regs = syscon_regmap_lookup_by_phandle(np, "ti,syscon-dev");
|
|
if (IS_ERR(devctrl_regs))
|
|
return PTR_ERR(devctrl_regs);
|
|
|
|
ret = of_property_read_u32_index(np, "ti,syscon-pll", 1, &rspll_offset);
|
|
if (ret) {
|
|
dev_err(dev, "couldn't read the reset pll offset!\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
ret = of_property_read_u32_index(np, "ti,syscon-dev", 1, &rsmux_offset);
|
|
if (ret) {
|
|
dev_err(dev, "couldn't read the rsmux offset!\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* set soft/hard reset */
|
|
val = of_property_read_bool(np, "ti,soft-reset");
|
|
val = val ? RSCFG_RSTYPE_SOFT : RSCFG_RSTYPE_HARD;
|
|
|
|
ret = rsctrl_enable_rspll_write();
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = regmap_write(pllctrl_regs, rspll_offset + RSCFG_RG, val);
|
|
if (ret)
|
|
return ret;
|
|
|
|
/* disable a reset isolation for all module clocks */
|
|
ret = regmap_write(pllctrl_regs, rspll_offset + RSISO_RG, 0);
|
|
if (ret)
|
|
return ret;
|
|
|
|
/* enable a reset for watchdogs from wdt-list */
|
|
for (i = 0; i < WDT_MUX_NUMBER; i++) {
|
|
ret = of_property_read_u32_index(np, "ti,wdt-list", i, &val);
|
|
if (ret == -EOVERFLOW && !i) {
|
|
dev_err(dev, "ti,wdt-list property has to contain at"
|
|
"least one entry\n");
|
|
return -EINVAL;
|
|
} else if (ret) {
|
|
break;
|
|
}
|
|
|
|
if (val >= WDT_MUX_NUMBER) {
|
|
dev_err(dev, "ti,wdt-list property can contain"
|
|
"only numbers < 4\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
rg = rsmux_offset + val * 4;
|
|
|
|
ret = regmap_update_bits(devctrl_regs, rg, RSMUX_OMODE_MASK,
|
|
RSMUX_OMODE_RESET_ON |
|
|
RSMUX_LOCK_SET);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
|
|
ret = register_restart_handler(&rsctrl_restart_nb);
|
|
if (ret)
|
|
dev_err(dev, "cannot register restart handler (err=%d)\n", ret);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static struct platform_driver rsctrl_driver = {
|
|
.probe = rsctrl_probe,
|
|
.driver = {
|
|
.name = KBUILD_MODNAME,
|
|
.of_match_table = rsctrl_of_match,
|
|
},
|
|
};
|
|
module_platform_driver(rsctrl_driver);
|
|
|
|
MODULE_AUTHOR("Ivan Khoronzhuk <ivan.khoronzhuk@ti.com>");
|
|
MODULE_DESCRIPTION("Texas Instruments keystone reset driver");
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_ALIAS("platform:" KBUILD_MODNAME);
|