^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* NXP PCF50633 Input Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * (C) 2006-2008 by Openmoko, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author: Balaji Rao <balajirrao@openmoko.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Broken down from monstrous PCF50633 driver mainly by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Harald Welte, Andy Green and Werner Almesberger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mfd/pcf50633/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define PCF50633_OOCSTAT_ONKEY 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define PCF50633_REG_OOCSTAT 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define PCF50633_REG_OOCMODE 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct pcf50633_input {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct pcf50633 *pcf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) pcf50633_input_irq(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct pcf50633_input *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int onkey_released;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) input = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* We report only one event depending on the key press status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) onkey_released = pcf50633_reg_read(input->pcf, PCF50633_REG_OOCSTAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) & PCF50633_OOCSTAT_ONKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if (irq == PCF50633_IRQ_ONKEYF && !onkey_released)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) input_report_key(input->input_dev, KEY_POWER, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) else if (irq == PCF50633_IRQ_ONKEYR && onkey_released)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) input_report_key(input->input_dev, KEY_POWER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) input_sync(input->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int pcf50633_input_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct pcf50633_input *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) input = kzalloc(sizeof(*input), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (!input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) kfree(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) platform_set_drvdata(pdev, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) input->pcf = dev_to_pcf50633(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) input->input_dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) input_dev->name = "PCF50633 PMU events";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) input_dev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_PWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) set_bit(KEY_POWER, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ret = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) kfree(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) pcf50633_register_irq(input->pcf, PCF50633_IRQ_ONKEYR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) pcf50633_input_irq, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) pcf50633_register_irq(input->pcf, PCF50633_IRQ_ONKEYF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) pcf50633_input_irq, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int pcf50633_input_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct pcf50633_input *input = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) input_unregister_device(input->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) kfree(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static struct platform_driver pcf50633_input_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .name = "pcf50633-input",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .probe = pcf50633_input_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .remove = pcf50633_input_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) module_platform_driver(pcf50633_input_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) MODULE_DESCRIPTION("PCF50633 input driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) MODULE_ALIAS("platform:pcf50633-input");