Changes in 4.9.174 ALSA: line6: use dynamic buffers ipv4: ip_do_fragment: Preserve skb_iif during fragmentation ipv6/flowlabel: wait rcu grace period before put_pid() ipv6: invert flowlabel sharing check in process and user mode packet: validate msg_namelen in send directly bnxt_en: Improve multicast address setup logic. net: phy: marvell: Fix buffer overrun with stats counters x86/suspend: fix false positive KASAN warning on suspend/resume mm/kasan: Switch to using __pa_symbol and lm_alias x86/unwind: Disable KASAN checks for non-current tasks arm64: kasan: avoid bad virt_to_pfn() kasan: add a prototype of task_struct to avoid warning kasan: avoid -Wmaybe-uninitialized warning kasan: remove redundant initialization of variable 'real_size' arm64: proc: Set PTE_NG for table entries to avoid traversing them twice kasan: prevent compiler from optimizing away memset in tests arm64: mm: print out correct page table entries arm64: mm: don't print out page table entries on EL0 faults caif: reduce stack size with KASAN USB: yurex: Fix protection fault after device removal USB: w1 ds2490: Fix bug caused by improper use of altsetting array usb: usbip: fix isoc packet num validation in get_pipe USB: core: Fix unterminated string returned by usb_string() USB: core: Fix bug caused by duplicate interface PM usage counter nvme-loop: init nvmet_ctrl fatal_err_work when allocate HID: logitech: check the return value of create_singlethread_workqueue HID: debug: fix race condition with between rdesc_show() and device removal rtc: sh: Fix invalid alarm warning for non-enabled alarm batman-adv: Reduce claim hash refcnt only for removed entry batman-adv: Reduce tt_local hash refcnt only for removed entry batman-adv: Reduce tt_global hash refcnt only for removed entry igb: Fix WARN_ONCE on runtime suspend net/mlx5: E-Switch, Fix esw manager vport indication for more vport commands bonding: show full hw address in sysfs for slave entries net: stmmac: don't overwrite discard_frame status net: stmmac: fix dropping of multi-descriptor RX frames net: stmmac: don't log oversized frames jffs2: fix use-after-free on symlink traversal debugfs: fix use-after-free on symlink traversal rtc: da9063: set uie_unsupported when relevant vfio/pci: use correct format characters scsi: core: add new RDAC LENOVO/DE_Series device scsi: storvsc: Fix calculation of sub-channel count net: hns: fix KASAN: use-after-free in hns_nic_net_xmit_hw() net: hns: Use NAPI_POLL_WEIGHT for hns driver net: hns: Fix WARNING when remove HNS driver with SMMU enabled hugetlbfs: fix memory leak for resv_map sh: fix multiple function definition build errors xsysace: Fix error handling in ace_setup ARM: orion: don't use using 64-bit DMA masks ARM: iop: don't use using 64-bit DMA masks perf/x86/amd: Update generic hardware cache events for Family 17h staging: iio: adt7316: allow adt751x to use internal vref for all dacs staging: iio: adt7316: fix the dac read calculation staging: iio: adt7316: fix the dac write calculation scsi: RDMA/srpt: Fix a credit leak for aborted commands Input: snvs_pwrkey - initialize necessary driver data before enabling IRQ selinux: never allow relabeling on context mounts x86/mce: Improve error message when kernel cannot recover, p2 media: v4l2: i2c: ov7670: Fix PLL bypass register values Linux 4.9.174 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
226 lines
5.7 KiB
C
226 lines
5.7 KiB
C
/*
|
|
* Driver for the IMX SNVS ON/OFF Power Key
|
|
* Copyright (C) 2015 Freescale Semiconductor, Inc. All Rights Reserved.
|
|
*
|
|
* The code contained herein is licensed under the GNU General Public
|
|
* License. You may obtain a copy of the GNU General Public License
|
|
* Version 2 or later at the following locations:
|
|
*
|
|
* http://www.opensource.org/licenses/gpl-license.html
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*/
|
|
|
|
#include <linux/device.h>
|
|
#include <linux/err.h>
|
|
#include <linux/init.h>
|
|
#include <linux/input.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/io.h>
|
|
#include <linux/jiffies.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_address.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/mfd/syscon.h>
|
|
#include <linux/regmap.h>
|
|
|
|
#define SNVS_LPSR_REG 0x4C /* LP Status Register */
|
|
#define SNVS_LPCR_REG 0x38 /* LP Control Register */
|
|
#define SNVS_HPSR_REG 0x14
|
|
#define SNVS_HPSR_BTN BIT(6)
|
|
#define SNVS_LPSR_SPO BIT(18)
|
|
#define SNVS_LPCR_DEP_EN BIT(5)
|
|
|
|
#define DEBOUNCE_TIME 30
|
|
#define REPEAT_INTERVAL 60
|
|
|
|
struct pwrkey_drv_data {
|
|
struct regmap *snvs;
|
|
int irq;
|
|
int keycode;
|
|
int keystate; /* 1:pressed */
|
|
int wakeup;
|
|
struct timer_list check_timer;
|
|
struct input_dev *input;
|
|
};
|
|
|
|
static void imx_imx_snvs_check_for_events(unsigned long data)
|
|
{
|
|
struct pwrkey_drv_data *pdata = (struct pwrkey_drv_data *) data;
|
|
struct input_dev *input = pdata->input;
|
|
u32 state;
|
|
|
|
regmap_read(pdata->snvs, SNVS_HPSR_REG, &state);
|
|
state = state & SNVS_HPSR_BTN ? 1 : 0;
|
|
|
|
/* only report new event if status changed */
|
|
if (state ^ pdata->keystate) {
|
|
pdata->keystate = state;
|
|
input_event(input, EV_KEY, pdata->keycode, state);
|
|
input_sync(input);
|
|
pm_relax(pdata->input->dev.parent);
|
|
}
|
|
|
|
/* repeat check if pressed long */
|
|
if (state) {
|
|
mod_timer(&pdata->check_timer,
|
|
jiffies + msecs_to_jiffies(REPEAT_INTERVAL));
|
|
}
|
|
}
|
|
|
|
static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)
|
|
{
|
|
struct platform_device *pdev = dev_id;
|
|
struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev);
|
|
u32 lp_status;
|
|
|
|
pm_wakeup_event(pdata->input->dev.parent, 0);
|
|
|
|
regmap_read(pdata->snvs, SNVS_LPSR_REG, &lp_status);
|
|
if (lp_status & SNVS_LPSR_SPO)
|
|
mod_timer(&pdata->check_timer, jiffies + msecs_to_jiffies(DEBOUNCE_TIME));
|
|
|
|
/* clear SPO status */
|
|
regmap_write(pdata->snvs, SNVS_LPSR_REG, SNVS_LPSR_SPO);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static void imx_snvs_pwrkey_act(void *pdata)
|
|
{
|
|
struct pwrkey_drv_data *pd = pdata;
|
|
|
|
del_timer_sync(&pd->check_timer);
|
|
}
|
|
|
|
static int imx_snvs_pwrkey_probe(struct platform_device *pdev)
|
|
{
|
|
struct pwrkey_drv_data *pdata = NULL;
|
|
struct input_dev *input = NULL;
|
|
struct device_node *np;
|
|
int error;
|
|
|
|
/* Get SNVS register Page */
|
|
np = pdev->dev.of_node;
|
|
if (!np)
|
|
return -ENODEV;
|
|
|
|
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
|
|
if (!pdata)
|
|
return -ENOMEM;
|
|
|
|
pdata->snvs = syscon_regmap_lookup_by_phandle(np, "regmap");
|
|
if (IS_ERR(pdata->snvs)) {
|
|
dev_err(&pdev->dev, "Can't get snvs syscon\n");
|
|
return PTR_ERR(pdata->snvs);
|
|
}
|
|
|
|
if (of_property_read_u32(np, "linux,keycode", &pdata->keycode)) {
|
|
pdata->keycode = KEY_POWER;
|
|
dev_warn(&pdev->dev, "KEY_POWER without setting in dts\n");
|
|
}
|
|
|
|
pdata->wakeup = of_property_read_bool(np, "wakeup-source");
|
|
|
|
pdata->irq = platform_get_irq(pdev, 0);
|
|
if (pdata->irq < 0) {
|
|
dev_err(&pdev->dev, "no irq defined in platform data\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
regmap_update_bits(pdata->snvs, SNVS_LPCR_REG, SNVS_LPCR_DEP_EN, SNVS_LPCR_DEP_EN);
|
|
|
|
/* clear the unexpected interrupt before driver ready */
|
|
regmap_write(pdata->snvs, SNVS_LPSR_REG, SNVS_LPSR_SPO);
|
|
|
|
setup_timer(&pdata->check_timer,
|
|
imx_imx_snvs_check_for_events, (unsigned long) pdata);
|
|
|
|
input = devm_input_allocate_device(&pdev->dev);
|
|
if (!input) {
|
|
dev_err(&pdev->dev, "failed to allocate the input device\n");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
input->name = pdev->name;
|
|
input->phys = "snvs-pwrkey/input0";
|
|
input->id.bustype = BUS_HOST;
|
|
|
|
input_set_capability(input, EV_KEY, pdata->keycode);
|
|
|
|
/* input customer action to cancel release timer */
|
|
error = devm_add_action(&pdev->dev, imx_snvs_pwrkey_act, pdata);
|
|
if (error) {
|
|
dev_err(&pdev->dev, "failed to register remove action\n");
|
|
return error;
|
|
}
|
|
|
|
pdata->input = input;
|
|
platform_set_drvdata(pdev, pdata);
|
|
|
|
error = devm_request_irq(&pdev->dev, pdata->irq,
|
|
imx_snvs_pwrkey_interrupt,
|
|
0, pdev->name, pdev);
|
|
|
|
if (error) {
|
|
dev_err(&pdev->dev, "interrupt not available.\n");
|
|
return error;
|
|
}
|
|
|
|
error = input_register_device(input);
|
|
if (error < 0) {
|
|
dev_err(&pdev->dev, "failed to register input device\n");
|
|
return error;
|
|
}
|
|
|
|
device_init_wakeup(&pdev->dev, pdata->wakeup);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int __maybe_unused imx_snvs_pwrkey_suspend(struct device *dev)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
if (device_may_wakeup(&pdev->dev))
|
|
enable_irq_wake(pdata->irq);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int __maybe_unused imx_snvs_pwrkey_resume(struct device *dev)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
if (device_may_wakeup(&pdev->dev))
|
|
disable_irq_wake(pdata->irq);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id imx_snvs_pwrkey_ids[] = {
|
|
{ .compatible = "fsl,sec-v4.0-pwrkey" },
|
|
{ /* sentinel */ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, imx_snvs_pwrkey_ids);
|
|
|
|
static SIMPLE_DEV_PM_OPS(imx_snvs_pwrkey_pm_ops, imx_snvs_pwrkey_suspend,
|
|
imx_snvs_pwrkey_resume);
|
|
|
|
static struct platform_driver imx_snvs_pwrkey_driver = {
|
|
.driver = {
|
|
.name = "snvs_pwrkey",
|
|
.pm = &imx_snvs_pwrkey_pm_ops,
|
|
.of_match_table = imx_snvs_pwrkey_ids,
|
|
},
|
|
.probe = imx_snvs_pwrkey_probe,
|
|
};
|
|
module_platform_driver(imx_snvs_pwrkey_driver);
|
|
|
|
MODULE_AUTHOR("Freescale Semiconductor");
|
|
MODULE_DESCRIPTION("i.MX snvs power key Driver");
|
|
MODULE_LICENSE("GPL");
|