mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 20:51:44 +00:00
8c1f3b2e24
SIMPLE_DEV_PM_OPS() is deprecated as it requires explicit protection against unused function warnings. The new combination of pm_sleep_ptr() and DEFINE_SIMPLE_DEV_PM_OPS() allows the compiler to see the functions, thus suppressing the warning, but still allowing the unused code to be removed. Thus also drop the __maybe_unused markings. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20221204180841.2211588-8-jic23@kernel.org Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
166 lines
3.9 KiB
C
166 lines
3.9 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
*
|
|
* h3600 atmel micro companion support, key subdevice
|
|
* based on previous kernel 2.4 version
|
|
* Author : Alessandro Gardich <gremlin@gremlin.it>
|
|
* Author : Linus Walleij <linus.walleij@linaro.org>
|
|
*/
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/pm.h>
|
|
#include <linux/sysctl.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/device.h>
|
|
#include <linux/input.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/mfd/ipaq-micro.h>
|
|
|
|
struct ipaq_micro_keys {
|
|
struct ipaq_micro *micro;
|
|
struct input_dev *input;
|
|
u16 *codes;
|
|
};
|
|
|
|
static const u16 micro_keycodes[] = {
|
|
KEY_RECORD, /* 1: Record button */
|
|
KEY_CALENDAR, /* 2: Calendar */
|
|
KEY_ADDRESSBOOK, /* 3: Contacts (looks like Outlook) */
|
|
KEY_MAIL, /* 4: Envelope (Q on older iPAQs) */
|
|
KEY_HOMEPAGE, /* 5: Start (looks like swoopy arrow) */
|
|
KEY_UP, /* 6: Up */
|
|
KEY_RIGHT, /* 7: Right */
|
|
KEY_LEFT, /* 8: Left */
|
|
KEY_DOWN, /* 9: Down */
|
|
};
|
|
|
|
static void micro_key_receive(void *data, int len, unsigned char *msg)
|
|
{
|
|
struct ipaq_micro_keys *keys = data;
|
|
int key, down;
|
|
|
|
down = 0x80 & msg[0];
|
|
key = 0x7f & msg[0];
|
|
|
|
if (key < ARRAY_SIZE(micro_keycodes)) {
|
|
input_report_key(keys->input, keys->codes[key], down);
|
|
input_sync(keys->input);
|
|
}
|
|
}
|
|
|
|
static void micro_key_start(struct ipaq_micro_keys *keys)
|
|
{
|
|
spin_lock(&keys->micro->lock);
|
|
keys->micro->key = micro_key_receive;
|
|
keys->micro->key_data = keys;
|
|
spin_unlock(&keys->micro->lock);
|
|
}
|
|
|
|
static void micro_key_stop(struct ipaq_micro_keys *keys)
|
|
{
|
|
spin_lock(&keys->micro->lock);
|
|
keys->micro->key = NULL;
|
|
keys->micro->key_data = NULL;
|
|
spin_unlock(&keys->micro->lock);
|
|
}
|
|
|
|
static int micro_key_open(struct input_dev *input)
|
|
{
|
|
struct ipaq_micro_keys *keys = input_get_drvdata(input);
|
|
|
|
micro_key_start(keys);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void micro_key_close(struct input_dev *input)
|
|
{
|
|
struct ipaq_micro_keys *keys = input_get_drvdata(input);
|
|
|
|
micro_key_stop(keys);
|
|
}
|
|
|
|
static int micro_key_probe(struct platform_device *pdev)
|
|
{
|
|
struct ipaq_micro_keys *keys;
|
|
int error;
|
|
int i;
|
|
|
|
keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL);
|
|
if (!keys)
|
|
return -ENOMEM;
|
|
|
|
keys->micro = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
keys->input = devm_input_allocate_device(&pdev->dev);
|
|
if (!keys->input)
|
|
return -ENOMEM;
|
|
|
|
keys->input->keycodesize = sizeof(micro_keycodes[0]);
|
|
keys->input->keycodemax = ARRAY_SIZE(micro_keycodes);
|
|
keys->codes = devm_kmemdup(&pdev->dev, micro_keycodes,
|
|
keys->input->keycodesize * keys->input->keycodemax,
|
|
GFP_KERNEL);
|
|
keys->input->keycode = keys->codes;
|
|
|
|
__set_bit(EV_KEY, keys->input->evbit);
|
|
for (i = 0; i < ARRAY_SIZE(micro_keycodes); i++)
|
|
__set_bit(micro_keycodes[i], keys->input->keybit);
|
|
|
|
keys->input->name = "h3600 micro keys";
|
|
keys->input->open = micro_key_open;
|
|
keys->input->close = micro_key_close;
|
|
input_set_drvdata(keys->input, keys);
|
|
|
|
error = input_register_device(keys->input);
|
|
if (error)
|
|
return error;
|
|
|
|
platform_set_drvdata(pdev, keys);
|
|
return 0;
|
|
}
|
|
|
|
static int micro_key_suspend(struct device *dev)
|
|
{
|
|
struct ipaq_micro_keys *keys = dev_get_drvdata(dev);
|
|
|
|
micro_key_stop(keys);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int micro_key_resume(struct device *dev)
|
|
{
|
|
struct ipaq_micro_keys *keys = dev_get_drvdata(dev);
|
|
struct input_dev *input = keys->input;
|
|
|
|
mutex_lock(&input->mutex);
|
|
|
|
if (input_device_enabled(input))
|
|
micro_key_start(keys);
|
|
|
|
mutex_unlock(&input->mutex);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static DEFINE_SIMPLE_DEV_PM_OPS(micro_key_dev_pm_ops,
|
|
micro_key_suspend, micro_key_resume);
|
|
|
|
static struct platform_driver micro_key_device_driver = {
|
|
.driver = {
|
|
.name = "ipaq-micro-keys",
|
|
.pm = pm_sleep_ptr(µ_key_dev_pm_ops),
|
|
},
|
|
.probe = micro_key_probe,
|
|
};
|
|
module_platform_driver(micro_key_device_driver);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("driver for iPAQ Atmel micro keys");
|
|
MODULE_ALIAS("platform:ipaq-micro-keys");
|