mirror of
https://github.com/torvalds/linux.git
synced 2026-05-29 17:43:52 +02:00
Input: twl4030 - add TWL603x power button
Like the TWL4030, these PMICs also have a power button feature, so extend the TWL4030 power button driver. As the irqchip of the TWL6030 mfd driver does not provide mask, unmask finctions, do it manually. Signed-off-by: Andreas Kemnade <andreas@kemnade.info> Link: https://patch.msgid.link/20251106-twl6030-button-v4-2-fdf1aa6e1e9a@kernel.org Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
b72fbdc080
commit
ec8fce2a57
|
|
@ -20,6 +20,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <linux/bits.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
|
|
@ -30,17 +31,31 @@
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/mfd/twl.h>
|
#include <linux/mfd/twl.h>
|
||||||
|
|
||||||
#define PWR_PWRON_IRQ (1 << 0)
|
#define PWR_PWRON_IRQ BIT(0)
|
||||||
|
|
||||||
#define STS_HW_CONDITIONS 0xf
|
struct twl_pwrbutton_chipdata {
|
||||||
|
u8 status_reg;
|
||||||
|
bool need_manual_irq;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct twl_pwrbutton_chipdata twl4030_chipdata = {
|
||||||
|
.status_reg = 0xf,
|
||||||
|
.need_manual_irq = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct twl_pwrbutton_chipdata twl6030_chipdata = {
|
||||||
|
.status_reg = 0x2,
|
||||||
|
.need_manual_irq = true,
|
||||||
|
};
|
||||||
|
|
||||||
static irqreturn_t powerbutton_irq(int irq, void *_pwr)
|
static irqreturn_t powerbutton_irq(int irq, void *_pwr)
|
||||||
{
|
{
|
||||||
struct input_dev *pwr = _pwr;
|
struct input_dev *pwr = _pwr;
|
||||||
|
const struct twl_pwrbutton_chipdata *pdata = dev_get_drvdata(pwr->dev.parent);
|
||||||
int err;
|
int err;
|
||||||
u8 value;
|
u8 value;
|
||||||
|
|
||||||
err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &value, STS_HW_CONDITIONS);
|
err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &value, pdata->status_reg);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
pm_wakeup_event(pwr->dev.parent, 0);
|
pm_wakeup_event(pwr->dev.parent, 0);
|
||||||
input_report_key(pwr, KEY_POWER, value & PWR_PWRON_IRQ);
|
input_report_key(pwr, KEY_POWER, value & PWR_PWRON_IRQ);
|
||||||
|
|
@ -55,10 +70,17 @@ static irqreturn_t powerbutton_irq(int irq, void *_pwr)
|
||||||
|
|
||||||
static int twl4030_pwrbutton_probe(struct platform_device *pdev)
|
static int twl4030_pwrbutton_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
|
const struct twl_pwrbutton_chipdata *pdata;
|
||||||
struct input_dev *pwr;
|
struct input_dev *pwr;
|
||||||
int irq = platform_get_irq(pdev, 0);
|
int irq = platform_get_irq(pdev, 0);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
pdata = device_get_match_data(&pdev->dev);
|
||||||
|
if (!pdata)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
platform_set_drvdata(pdev, (void *)pdata);
|
||||||
|
|
||||||
pwr = devm_input_allocate_device(&pdev->dev);
|
pwr = devm_input_allocate_device(&pdev->dev);
|
||||||
if (!pwr) {
|
if (!pwr) {
|
||||||
dev_err(&pdev->dev, "Can't allocate power button\n");
|
dev_err(&pdev->dev, "Can't allocate power button\n");
|
||||||
|
|
@ -85,21 +107,49 @@ static int twl4030_pwrbutton_probe(struct platform_device *pdev)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pdata->need_manual_irq) {
|
||||||
|
err = twl6030_interrupt_unmask(0x01, REG_INT_MSK_LINE_A);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
err = twl6030_interrupt_unmask(0x01, REG_INT_MSK_STS_A);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
device_init_wakeup(&pdev->dev, true);
|
device_init_wakeup(&pdev->dev, true);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void twl4030_pwrbutton_remove(struct platform_device *pdev)
|
||||||
|
{
|
||||||
|
const struct twl_pwrbutton_chipdata *pdata = platform_get_drvdata(pdev);
|
||||||
|
|
||||||
|
if (pdata->need_manual_irq) {
|
||||||
|
twl6030_interrupt_mask(0x01, REG_INT_MSK_LINE_A);
|
||||||
|
twl6030_interrupt_mask(0x01, REG_INT_MSK_STS_A);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_OF
|
#ifdef CONFIG_OF
|
||||||
static const struct of_device_id twl4030_pwrbutton_dt_match_table[] = {
|
static const struct of_device_id twl4030_pwrbutton_dt_match_table[] = {
|
||||||
{ .compatible = "ti,twl4030-pwrbutton" },
|
{
|
||||||
{},
|
.compatible = "ti,twl4030-pwrbutton",
|
||||||
|
.data = &twl4030_chipdata,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.compatible = "ti,twl6030-pwrbutton",
|
||||||
|
.data = &twl6030_chipdata,
|
||||||
|
},
|
||||||
|
{ }
|
||||||
};
|
};
|
||||||
MODULE_DEVICE_TABLE(of, twl4030_pwrbutton_dt_match_table);
|
MODULE_DEVICE_TABLE(of, twl4030_pwrbutton_dt_match_table);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct platform_driver twl4030_pwrbutton_driver = {
|
static struct platform_driver twl4030_pwrbutton_driver = {
|
||||||
.probe = twl4030_pwrbutton_probe,
|
.probe = twl4030_pwrbutton_probe,
|
||||||
|
.remove = twl4030_pwrbutton_remove,
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "twl4030_pwrbutton",
|
.name = "twl4030_pwrbutton",
|
||||||
.of_match_table = of_match_ptr(twl4030_pwrbutton_dt_match_table),
|
.of_match_table = of_match_ptr(twl4030_pwrbutton_dt_match_table),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user