Commit 100e1695 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: libps2 - attach ps2dev instances as serio port's drvdata

In preparation of having unified interrupt handler for PS/2 devices,
instead of attaching instances of psmouse and atkbd structures as serio's
driver data, switch to attaching ps2dev instances.
Reviewed-by: default avatarRaul Rangel <rrangel@chromium.org>
Link: https://lore.kernel.org/r/20230511185252.386941-2-dmitry.torokhov@gmail.comSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent d8bde56d
...@@ -309,12 +309,19 @@ static ssize_t atkbd_show_function_row_physmap(struct atkbd *atkbd, char *buf) ...@@ -309,12 +309,19 @@ static ssize_t atkbd_show_function_row_physmap(struct atkbd *atkbd, char *buf)
return vivaldi_function_row_physmap_show(&atkbd->vdata, buf); return vivaldi_function_row_physmap_show(&atkbd->vdata, buf);
} }
static struct atkbd *atkbd_from_serio(struct serio *serio)
{
struct ps2dev *ps2dev = serio_get_drvdata(serio);
return container_of(ps2dev, struct atkbd, ps2dev);
}
static umode_t atkbd_attr_is_visible(struct kobject *kobj, static umode_t atkbd_attr_is_visible(struct kobject *kobj,
struct attribute *attr, int i) struct attribute *attr, int i)
{ {
struct device *dev = kobj_to_dev(kobj); struct device *dev = kobj_to_dev(kobj);
struct serio *serio = to_serio_port(dev); struct serio *serio = to_serio_port(dev);
struct atkbd *atkbd = serio_get_drvdata(serio); struct atkbd *atkbd = atkbd_from_serio(serio);
if (attr == &atkbd_attr_function_row_physmap.attr && if (attr == &atkbd_attr_function_row_physmap.attr &&
!atkbd->vdata.num_function_row_keys) !atkbd->vdata.num_function_row_keys)
...@@ -399,7 +406,7 @@ static unsigned int atkbd_compat_scancode(struct atkbd *atkbd, unsigned int code ...@@ -399,7 +406,7 @@ static unsigned int atkbd_compat_scancode(struct atkbd *atkbd, unsigned int code
static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data, static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
unsigned int flags) unsigned int flags)
{ {
struct atkbd *atkbd = serio_get_drvdata(serio); struct atkbd *atkbd = atkbd_from_serio(serio);
struct input_dev *dev = atkbd->dev; struct input_dev *dev = atkbd->dev;
unsigned int code = data; unsigned int code = data;
int scroll = 0, hscroll = 0, click = -1; int scroll = 0, hscroll = 0, click = -1;
...@@ -909,7 +916,7 @@ static int atkbd_reset_state(struct atkbd *atkbd) ...@@ -909,7 +916,7 @@ static int atkbd_reset_state(struct atkbd *atkbd)
static void atkbd_cleanup(struct serio *serio) static void atkbd_cleanup(struct serio *serio)
{ {
struct atkbd *atkbd = serio_get_drvdata(serio); struct atkbd *atkbd = atkbd_from_serio(serio);
atkbd_disable(atkbd); atkbd_disable(atkbd);
ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF); ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF);
...@@ -922,7 +929,7 @@ static void atkbd_cleanup(struct serio *serio) ...@@ -922,7 +929,7 @@ static void atkbd_cleanup(struct serio *serio)
static void atkbd_disconnect(struct serio *serio) static void atkbd_disconnect(struct serio *serio)
{ {
struct atkbd *atkbd = serio_get_drvdata(serio); struct atkbd *atkbd = atkbd_from_serio(serio);
atkbd_disable(atkbd); atkbd_disable(atkbd);
...@@ -1188,7 +1195,7 @@ static void atkbd_set_device_attrs(struct atkbd *atkbd) ...@@ -1188,7 +1195,7 @@ static void atkbd_set_device_attrs(struct atkbd *atkbd)
static void atkbd_parse_fwnode_data(struct serio *serio) static void atkbd_parse_fwnode_data(struct serio *serio)
{ {
struct atkbd *atkbd = serio_get_drvdata(serio); struct atkbd *atkbd = atkbd_from_serio(serio);
struct device *dev = &serio->dev; struct device *dev = &serio->dev;
int n; int n;
...@@ -1295,7 +1302,7 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv) ...@@ -1295,7 +1302,7 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
static int atkbd_reconnect(struct serio *serio) static int atkbd_reconnect(struct serio *serio)
{ {
struct atkbd *atkbd = serio_get_drvdata(serio); struct atkbd *atkbd = atkbd_from_serio(serio);
struct serio_driver *drv = serio->drv; struct serio_driver *drv = serio->drv;
int retval = -1; int retval = -1;
...@@ -1389,7 +1396,7 @@ static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf, ...@@ -1389,7 +1396,7 @@ static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf,
ssize_t (*handler)(struct atkbd *, char *)) ssize_t (*handler)(struct atkbd *, char *))
{ {
struct serio *serio = to_serio_port(dev); struct serio *serio = to_serio_port(dev);
struct atkbd *atkbd = serio_get_drvdata(serio); struct atkbd *atkbd = atkbd_from_serio(serio);
return handler(atkbd, buf); return handler(atkbd, buf);
} }
...@@ -1398,7 +1405,7 @@ static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t ...@@ -1398,7 +1405,7 @@ static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t
ssize_t (*handler)(struct atkbd *, const char *, size_t)) ssize_t (*handler)(struct atkbd *, const char *, size_t))
{ {
struct serio *serio = to_serio_port(dev); struct serio *serio = to_serio_port(dev);
struct atkbd *atkbd = serio_get_drvdata(serio); struct atkbd *atkbd = atkbd_from_serio(serio);
int retval; int retval;
retval = mutex_lock_interruptible(&atkbd->mutex); retval = mutex_lock_interruptible(&atkbd->mutex);
......
...@@ -116,6 +116,13 @@ static DEFINE_MUTEX(psmouse_mutex); ...@@ -116,6 +116,13 @@ static DEFINE_MUTEX(psmouse_mutex);
static struct workqueue_struct *kpsmoused_wq; static struct workqueue_struct *kpsmoused_wq;
struct psmouse *psmouse_from_serio(struct serio *serio)
{
struct ps2dev *ps2dev = serio_get_drvdata(serio);
return container_of(ps2dev, struct psmouse, ps2dev);
}
void psmouse_report_standard_buttons(struct input_dev *dev, u8 buttons) void psmouse_report_standard_buttons(struct input_dev *dev, u8 buttons)
{ {
input_report_key(dev, BTN_LEFT, buttons & BIT(0)); input_report_key(dev, BTN_LEFT, buttons & BIT(0));
...@@ -336,7 +343,7 @@ static void psmouse_handle_oob_data(struct psmouse *psmouse, u8 data) ...@@ -336,7 +343,7 @@ static void psmouse_handle_oob_data(struct psmouse *psmouse, u8 data)
static irqreturn_t psmouse_interrupt(struct serio *serio, static irqreturn_t psmouse_interrupt(struct serio *serio,
u8 data, unsigned int flags) u8 data, unsigned int flags)
{ {
struct psmouse *psmouse = serio_get_drvdata(serio); struct psmouse *psmouse = psmouse_from_serio(serio);
if (psmouse->state == PSMOUSE_IGNORE) if (psmouse->state == PSMOUSE_IGNORE)
goto out; goto out;
...@@ -1344,7 +1351,7 @@ static void psmouse_resync(struct work_struct *work) ...@@ -1344,7 +1351,7 @@ static void psmouse_resync(struct work_struct *work)
goto out; goto out;
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
parent = serio_get_drvdata(serio->parent); parent = psmouse_from_serio(serio->parent);
psmouse_deactivate(parent); psmouse_deactivate(parent);
} }
...@@ -1428,13 +1435,13 @@ static void psmouse_resync(struct work_struct *work) ...@@ -1428,13 +1435,13 @@ static void psmouse_resync(struct work_struct *work)
*/ */
static void psmouse_cleanup(struct serio *serio) static void psmouse_cleanup(struct serio *serio)
{ {
struct psmouse *psmouse = serio_get_drvdata(serio); struct psmouse *psmouse = psmouse_from_serio(serio);
struct psmouse *parent = NULL; struct psmouse *parent = NULL;
mutex_lock(&psmouse_mutex); mutex_lock(&psmouse_mutex);
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
parent = serio_get_drvdata(serio->parent); parent = psmouse_from_serio(serio->parent);
psmouse_deactivate(parent); psmouse_deactivate(parent);
} }
...@@ -1476,7 +1483,7 @@ static void psmouse_cleanup(struct serio *serio) ...@@ -1476,7 +1483,7 @@ static void psmouse_cleanup(struct serio *serio)
*/ */
static void psmouse_disconnect(struct serio *serio) static void psmouse_disconnect(struct serio *serio)
{ {
struct psmouse *psmouse = serio_get_drvdata(serio); struct psmouse *psmouse = psmouse_from_serio(serio);
struct psmouse *parent = NULL; struct psmouse *parent = NULL;
mutex_lock(&psmouse_mutex); mutex_lock(&psmouse_mutex);
...@@ -1489,7 +1496,7 @@ static void psmouse_disconnect(struct serio *serio) ...@@ -1489,7 +1496,7 @@ static void psmouse_disconnect(struct serio *serio)
mutex_lock(&psmouse_mutex); mutex_lock(&psmouse_mutex);
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
parent = serio_get_drvdata(serio->parent); parent = psmouse_from_serio(serio->parent);
psmouse_deactivate(parent); psmouse_deactivate(parent);
} }
...@@ -1588,7 +1595,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv) ...@@ -1588,7 +1595,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
* connected to this port can be successfully identified * connected to this port can be successfully identified
*/ */
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
parent = serio_get_drvdata(serio->parent); parent = psmouse_from_serio(serio->parent);
psmouse_deactivate(parent); psmouse_deactivate(parent);
} }
...@@ -1604,8 +1611,6 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv) ...@@ -1604,8 +1611,6 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
serio_set_drvdata(serio, psmouse);
error = serio_open(serio, drv); error = serio_open(serio, drv);
if (error) if (error)
goto err_clear_drvdata; goto err_clear_drvdata;
...@@ -1676,7 +1681,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv) ...@@ -1676,7 +1681,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
static int __psmouse_reconnect(struct serio *serio, bool fast_reconnect) static int __psmouse_reconnect(struct serio *serio, bool fast_reconnect)
{ {
struct psmouse *psmouse = serio_get_drvdata(serio); struct psmouse *psmouse = psmouse_from_serio(serio);
struct psmouse *parent = NULL; struct psmouse *parent = NULL;
int (*reconnect_handler)(struct psmouse *); int (*reconnect_handler)(struct psmouse *);
enum psmouse_type type; enum psmouse_type type;
...@@ -1695,7 +1700,7 @@ static int __psmouse_reconnect(struct serio *serio, bool fast_reconnect) ...@@ -1695,7 +1700,7 @@ static int __psmouse_reconnect(struct serio *serio, bool fast_reconnect)
} }
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
parent = serio_get_drvdata(serio->parent); parent = psmouse_from_serio(serio->parent);
psmouse_deactivate(parent); psmouse_deactivate(parent);
} }
...@@ -1794,7 +1799,7 @@ ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *de ...@@ -1794,7 +1799,7 @@ ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *de
{ {
struct serio *serio = to_serio_port(dev); struct serio *serio = to_serio_port(dev);
struct psmouse_attribute *attr = to_psmouse_attr(devattr); struct psmouse_attribute *attr = to_psmouse_attr(devattr);
struct psmouse *psmouse = serio_get_drvdata(serio); struct psmouse *psmouse = psmouse_from_serio(serio);
if (psmouse->protocol->smbus_companion && if (psmouse->protocol->smbus_companion &&
devattr != &psmouse_attr_protocol.dattr) devattr != &psmouse_attr_protocol.dattr)
...@@ -1815,7 +1820,7 @@ ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *dev ...@@ -1815,7 +1820,7 @@ ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *dev
if (retval) if (retval)
goto out; goto out;
psmouse = serio_get_drvdata(serio); psmouse = psmouse_from_serio(serio);
if (psmouse->protocol->smbus_companion && if (psmouse->protocol->smbus_companion &&
devattr != &psmouse_attr_protocol.dattr) { devattr != &psmouse_attr_protocol.dattr) {
...@@ -1830,7 +1835,7 @@ ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *dev ...@@ -1830,7 +1835,7 @@ ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *dev
} }
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
parent = serio_get_drvdata(serio->parent); parent = psmouse_from_serio(serio->parent);
psmouse_deactivate(parent); psmouse_deactivate(parent);
} }
...@@ -1925,7 +1930,7 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co ...@@ -1925,7 +1930,7 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
} }
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
parent = serio_get_drvdata(serio->parent); parent = psmouse_from_serio(serio->parent);
if (parent->pt_deactivate) if (parent->pt_deactivate)
parent->pt_deactivate(parent); parent->pt_deactivate(parent);
} }
......
...@@ -130,6 +130,8 @@ struct psmouse { ...@@ -130,6 +130,8 @@ struct psmouse {
void (*pt_deactivate)(struct psmouse *psmouse); void (*pt_deactivate)(struct psmouse *psmouse);
}; };
struct psmouse *psmouse_from_serio(struct serio *serio);
void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work, void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
unsigned long delay); unsigned long delay);
int psmouse_reset(struct psmouse *psmouse); int psmouse_reset(struct psmouse *psmouse);
......
...@@ -628,7 +628,7 @@ static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate) ...@@ -628,7 +628,7 @@ static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
****************************************************************************/ ****************************************************************************/
static int synaptics_pt_write(struct serio *serio, u8 c) static int synaptics_pt_write(struct serio *serio, u8 c)
{ {
struct psmouse *parent = serio_get_drvdata(serio->parent); struct psmouse *parent = psmouse_from_serio(serio->parent);
u8 rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */ u8 rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
int error; int error;
...@@ -645,7 +645,7 @@ static int synaptics_pt_write(struct serio *serio, u8 c) ...@@ -645,7 +645,7 @@ static int synaptics_pt_write(struct serio *serio, u8 c)
static int synaptics_pt_start(struct serio *serio) static int synaptics_pt_start(struct serio *serio)
{ {
struct psmouse *parent = serio_get_drvdata(serio->parent); struct psmouse *parent = psmouse_from_serio(serio->parent);
struct synaptics_data *priv = parent->private; struct synaptics_data *priv = parent->private;
serio_pause_rx(parent->ps2dev.serio); serio_pause_rx(parent->ps2dev.serio);
...@@ -657,7 +657,7 @@ static int synaptics_pt_start(struct serio *serio) ...@@ -657,7 +657,7 @@ static int synaptics_pt_start(struct serio *serio)
static void synaptics_pt_stop(struct serio *serio) static void synaptics_pt_stop(struct serio *serio)
{ {
struct psmouse *parent = serio_get_drvdata(serio->parent); struct psmouse *parent = psmouse_from_serio(serio->parent);
struct synaptics_data *priv = parent->private; struct synaptics_data *priv = parent->private;
serio_pause_rx(parent->ps2dev.serio); serio_pause_rx(parent->ps2dev.serio);
...@@ -672,7 +672,7 @@ static int synaptics_is_pt_packet(u8 *buf) ...@@ -672,7 +672,7 @@ static int synaptics_is_pt_packet(u8 *buf)
static void synaptics_pass_pt_packet(struct serio *ptport, u8 *packet) static void synaptics_pass_pt_packet(struct serio *ptport, u8 *packet)
{ {
struct psmouse *child = serio_get_drvdata(ptport); struct psmouse *child = psmouse_from_serio(ptport);
if (child && child->state == PSMOUSE_ACTIVATED) { if (child && child->state == PSMOUSE_ACTIVATED) {
serio_interrupt(ptport, packet[1], 0); serio_interrupt(ptport, packet[1], 0);
...@@ -688,7 +688,7 @@ static void synaptics_pass_pt_packet(struct serio *ptport, u8 *packet) ...@@ -688,7 +688,7 @@ static void synaptics_pass_pt_packet(struct serio *ptport, u8 *packet)
static void synaptics_pt_activate(struct psmouse *psmouse) static void synaptics_pt_activate(struct psmouse *psmouse)
{ {
struct synaptics_data *priv = psmouse->private; struct synaptics_data *priv = psmouse->private;
struct psmouse *child = serio_get_drvdata(priv->pt_port); struct psmouse *child = psmouse_from_serio(priv->pt_port);
/* adjust the touchpad to child's choice of protocol */ /* adjust the touchpad to child's choice of protocol */
if (child) { if (child) {
......
...@@ -216,7 +216,7 @@ static umode_t trackpoint_is_attr_visible(struct kobject *kobj, ...@@ -216,7 +216,7 @@ static umode_t trackpoint_is_attr_visible(struct kobject *kobj,
{ {
struct device *dev = kobj_to_dev(kobj); struct device *dev = kobj_to_dev(kobj);
struct serio *serio = to_serio_port(dev); struct serio *serio = to_serio_port(dev);
struct psmouse *psmouse = serio_get_drvdata(serio); struct psmouse *psmouse = psmouse_from_serio(serio);
return trackpoint_is_attr_available(psmouse, attr) ? attr->mode : 0; return trackpoint_is_attr_available(psmouse, attr) ? attr->mode : 0;
} }
......
...@@ -382,6 +382,7 @@ void ps2_init(struct ps2dev *ps2dev, struct serio *serio) ...@@ -382,6 +382,7 @@ void ps2_init(struct ps2dev *ps2dev, struct serio *serio)
lockdep_set_subclass(&ps2dev->cmd_mutex, serio->depth); lockdep_set_subclass(&ps2dev->cmd_mutex, serio->depth);
init_waitqueue_head(&ps2dev->wait); init_waitqueue_head(&ps2dev->wait);
ps2dev->serio = serio; ps2dev->serio = serio;
serio_set_drvdata(serio, ps2dev);
} }
EXPORT_SYMBOL(ps2_init); EXPORT_SYMBOL(ps2_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment