2021-01-15 09:06:37 -08:00
|
|
|
/*
|
|
|
|
* HID over I2C Open Firmware Subclass
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com>
|
|
|
|
* Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
|
|
|
|
* Copyright (c) 2012 Red Hat, Inc
|
|
|
|
*
|
|
|
|
* This code was forked out of the core code, which was partly based on
|
|
|
|
* "USB HID support for Linux":
|
|
|
|
*
|
|
|
|
* Copyright (c) 1999 Andreas Gal
|
|
|
|
* Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
|
|
|
|
* Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
|
|
|
|
* Copyright (c) 2007-2008 Oliver Neukum
|
|
|
|
* Copyright (c) 2006-2010 Jiri Kosina
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file COPYING in the main directory of this archive for
|
|
|
|
* more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/device.h>
|
2023-04-13 11:36:25 +02:00
|
|
|
#include <linux/gpio/consumer.h>
|
2021-12-08 22:40:44 +10:00
|
|
|
#include <linux/hid.h>
|
2021-01-15 09:06:37 -08:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/regulator/consumer.h>
|
|
|
|
|
|
|
|
#include "i2c-hid.h"
|
|
|
|
|
|
|
|
struct i2c_hid_of {
|
|
|
|
struct i2chid_ops ops;
|
|
|
|
|
|
|
|
struct i2c_client *client;
|
2023-04-13 11:36:25 +02:00
|
|
|
struct gpio_desc *reset_gpio;
|
2021-01-15 09:06:37 -08:00
|
|
|
struct regulator_bulk_data supplies[2];
|
|
|
|
int post_power_delay_ms;
|
2023-04-13 11:36:25 +02:00
|
|
|
int post_reset_delay_ms;
|
2021-01-15 09:06:37 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int i2c_hid_of_power_up(struct i2chid_ops *ops)
|
|
|
|
{
|
|
|
|
struct i2c_hid_of *ihid_of = container_of(ops, struct i2c_hid_of, ops);
|
|
|
|
struct device *dev = &ihid_of->client->dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = regulator_bulk_enable(ARRAY_SIZE(ihid_of->supplies),
|
|
|
|
ihid_of->supplies);
|
|
|
|
if (ret) {
|
|
|
|
dev_warn(dev, "Failed to enable supplies: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ihid_of->post_power_delay_ms)
|
|
|
|
msleep(ihid_of->post_power_delay_ms);
|
|
|
|
|
2023-04-13 11:36:25 +02:00
|
|
|
gpiod_set_value_cansleep(ihid_of->reset_gpio, 0);
|
|
|
|
if (ihid_of->post_reset_delay_ms)
|
|
|
|
msleep(ihid_of->post_reset_delay_ms);
|
|
|
|
|
2021-01-15 09:06:37 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_hid_of_power_down(struct i2chid_ops *ops)
|
|
|
|
{
|
|
|
|
struct i2c_hid_of *ihid_of = container_of(ops, struct i2c_hid_of, ops);
|
|
|
|
|
2023-04-13 11:36:25 +02:00
|
|
|
gpiod_set_value_cansleep(ihid_of->reset_gpio, 1);
|
2021-01-15 09:06:37 -08:00
|
|
|
regulator_bulk_disable(ARRAY_SIZE(ihid_of->supplies),
|
|
|
|
ihid_of->supplies);
|
|
|
|
}
|
|
|
|
|
HID: i2c: use simple i2c probe
All these drivers have an i2c probe function which doesn't use the
"struct i2c_device_id *id" parameter, so they can trivially be
converted to the "probe_new" style of probe with a single argument.
This is part of an ongoing transition to single-argument i2c probe
functions. Old-style probe functions involve a call to i2c_match_id:
in drivers/i2c/i2c-core-base.c,
/*
* When there are no more users of probe(),
* rename probe_new to probe.
*/
if (driver->probe_new)
status = driver->probe_new(client);
else if (driver->probe)
status = driver->probe(client,
i2c_match_id(driver->id_table, client));
else
status = -EINVAL;
Drivers which don't need the second parameter can be declared using
probe_new instead, avoiding the call to i2c_match_id. Drivers which do
can still be converted to probe_new-style, calling i2c_match_id
themselves (as is done currently for of_match_id).
This change was done using the following Coccinelle script, and fixed
up for whitespace changes:
@ rule1 @
identifier fn;
identifier client, id;
@@
- static int fn(struct i2c_client *client, const struct i2c_device_id *id)
+ static int fn(struct i2c_client *client)
{
...when != id
}
@ rule2 depends on rule1 @
identifier rule1.fn;
identifier driver;
@@
struct i2c_driver driver = {
- .probe
+ .probe_new
=
(
fn
|
- &fn
+ fn
)
,
};
Signed-off-by: Stephen Kitt <steve@sk2.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2022-10-12 18:33:00 +02:00
|
|
|
static int i2c_hid_of_probe(struct i2c_client *client)
|
2021-01-15 09:06:37 -08:00
|
|
|
{
|
|
|
|
struct device *dev = &client->dev;
|
|
|
|
struct i2c_hid_of *ihid_of;
|
|
|
|
u16 hid_descriptor_address;
|
2021-12-08 22:40:44 +10:00
|
|
|
u32 quirks = 0;
|
2021-01-15 09:06:37 -08:00
|
|
|
int ret;
|
|
|
|
u32 val;
|
|
|
|
|
2023-04-13 11:36:23 +02:00
|
|
|
ihid_of = devm_kzalloc(dev, sizeof(*ihid_of), GFP_KERNEL);
|
2021-01-15 09:06:37 -08:00
|
|
|
if (!ihid_of)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ihid_of->ops.power_up = i2c_hid_of_power_up;
|
|
|
|
ihid_of->ops.power_down = i2c_hid_of_power_down;
|
|
|
|
|
2023-04-13 11:36:24 +02:00
|
|
|
ret = device_property_read_u32(dev, "hid-descr-addr", &val);
|
2021-01-15 09:06:37 -08:00
|
|
|
if (ret) {
|
2023-04-13 11:36:23 +02:00
|
|
|
dev_err(dev, "HID register address not provided\n");
|
2021-01-15 09:06:37 -08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
if (val >> 16) {
|
2023-04-13 11:36:23 +02:00
|
|
|
dev_err(dev, "Bad HID register address: 0x%08x\n", val);
|
2021-01-15 09:06:37 -08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
hid_descriptor_address = val;
|
|
|
|
|
2023-04-13 11:36:23 +02:00
|
|
|
if (!device_property_read_u32(dev, "post-power-on-delay-ms", &val))
|
2021-01-15 09:06:37 -08:00
|
|
|
ihid_of->post_power_delay_ms = val;
|
|
|
|
|
2023-04-13 11:36:25 +02:00
|
|
|
/*
|
|
|
|
* Note this is a kernel internal device-property set by x86 platform code,
|
|
|
|
* this MUST not be used in devicetree files without first adding it to
|
|
|
|
* the DT bindings.
|
|
|
|
*/
|
|
|
|
if (!device_property_read_u32(dev, "post-reset-deassert-delay-ms", &val))
|
|
|
|
ihid_of->post_reset_delay_ms = val;
|
|
|
|
|
|
|
|
/* Start out with reset asserted */
|
|
|
|
ihid_of->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
|
|
|
|
if (IS_ERR(ihid_of->reset_gpio))
|
|
|
|
return PTR_ERR(ihid_of->reset_gpio);
|
|
|
|
|
2021-01-15 09:06:37 -08:00
|
|
|
ihid_of->supplies[0].supply = "vdd";
|
|
|
|
ihid_of->supplies[1].supply = "vddl";
|
2023-04-13 11:36:23 +02:00
|
|
|
ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ihid_of->supplies),
|
2021-01-15 09:06:37 -08:00
|
|
|
ihid_of->supplies);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2021-12-08 22:40:44 +10:00
|
|
|
if (device_property_read_bool(dev, "touchscreen-inverted-x"))
|
|
|
|
quirks |= HID_QUIRK_X_INVERT;
|
|
|
|
|
|
|
|
if (device_property_read_bool(dev, "touchscreen-inverted-y"))
|
|
|
|
quirks |= HID_QUIRK_Y_INVERT;
|
|
|
|
|
2021-01-15 09:06:37 -08:00
|
|
|
return i2c_hid_core_probe(client, &ihid_of->ops,
|
2021-12-08 22:40:44 +10:00
|
|
|
hid_descriptor_address, quirks);
|
2021-01-15 09:06:37 -08:00
|
|
|
}
|
|
|
|
|
2023-04-13 11:36:24 +02:00
|
|
|
#ifdef CONFIG_OF
|
2021-01-15 09:06:37 -08:00
|
|
|
static const struct of_device_id i2c_hid_of_match[] = {
|
|
|
|
{ .compatible = "hid-over-i2c" },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, i2c_hid_of_match);
|
2023-04-13 11:36:24 +02:00
|
|
|
#endif
|
2021-01-15 09:06:37 -08:00
|
|
|
|
|
|
|
static const struct i2c_device_id i2c_hid_of_id_table[] = {
|
|
|
|
{ "hid", 0 },
|
|
|
|
{ "hid-over-i2c", 0 },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, i2c_hid_of_id_table);
|
|
|
|
|
|
|
|
static struct i2c_driver i2c_hid_of_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "i2c_hid_of",
|
|
|
|
.pm = &i2c_hid_core_pm,
|
|
|
|
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
|
|
|
|
.of_match_table = of_match_ptr(i2c_hid_of_match),
|
|
|
|
},
|
|
|
|
|
HID: i2c: use simple i2c probe
All these drivers have an i2c probe function which doesn't use the
"struct i2c_device_id *id" parameter, so they can trivially be
converted to the "probe_new" style of probe with a single argument.
This is part of an ongoing transition to single-argument i2c probe
functions. Old-style probe functions involve a call to i2c_match_id:
in drivers/i2c/i2c-core-base.c,
/*
* When there are no more users of probe(),
* rename probe_new to probe.
*/
if (driver->probe_new)
status = driver->probe_new(client);
else if (driver->probe)
status = driver->probe(client,
i2c_match_id(driver->id_table, client));
else
status = -EINVAL;
Drivers which don't need the second parameter can be declared using
probe_new instead, avoiding the call to i2c_match_id. Drivers which do
can still be converted to probe_new-style, calling i2c_match_id
themselves (as is done currently for of_match_id).
This change was done using the following Coccinelle script, and fixed
up for whitespace changes:
@ rule1 @
identifier fn;
identifier client, id;
@@
- static int fn(struct i2c_client *client, const struct i2c_device_id *id)
+ static int fn(struct i2c_client *client)
{
...when != id
}
@ rule2 depends on rule1 @
identifier rule1.fn;
identifier driver;
@@
struct i2c_driver driver = {
- .probe
+ .probe_new
=
(
fn
|
- &fn
+ fn
)
,
};
Signed-off-by: Stephen Kitt <steve@sk2.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2022-10-12 18:33:00 +02:00
|
|
|
.probe_new = i2c_hid_of_probe,
|
2021-01-15 09:06:37 -08:00
|
|
|
.remove = i2c_hid_core_remove,
|
|
|
|
.shutdown = i2c_hid_core_shutdown,
|
|
|
|
.id_table = i2c_hid_of_id_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_i2c_driver(i2c_hid_of_driver);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("HID over I2C OF driver");
|
|
|
|
MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|