hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/hid/intel-ish-hid/ishtp/bus.c
....@@ -1,16 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * ISHTP bus driver
34 *
45 * Copyright (c) 2012-2016, Intel Corporation.
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms and conditions of the GNU General Public License,
8
- * version 2, as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope it will be useful, but WITHOUT
11
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
- * more details.
146 */
157
168 #include <linux/module.h>
....@@ -119,7 +111,7 @@
119111 * Return: This returns IPC send message status.
120112 */
121113 int ishtp_write_message(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr,
122
- unsigned char *buf)
114
+ void *buf)
123115 {
124116 return ishtp_send_msg(dev, hdr, buf, NULL, NULL);
125117 }
....@@ -133,20 +125,55 @@
133125 *
134126 * Return: fw client index or -ENOENT if not found
135127 */
136
-int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const uuid_le *uuid)
128
+int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const guid_t *uuid)
137129 {
138
- int i, res = -ENOENT;
130
+ unsigned int i;
139131
140132 for (i = 0; i < dev->fw_clients_num; ++i) {
141
- if (uuid_le_cmp(*uuid, dev->fw_clients[i].props.protocol_name)
142
- == 0) {
143
- res = i;
144
- break;
145
- }
133
+ if (guid_equal(uuid, &dev->fw_clients[i].props.protocol_name))
134
+ return i;
146135 }
147
- return res;
136
+ return -ENOENT;
148137 }
149138 EXPORT_SYMBOL(ishtp_fw_cl_by_uuid);
139
+
140
+/**
141
+ * ishtp_fw_cl_get_client() - return client information to client
142
+ * @dev: the ishtp device structure
143
+ * @uuid: uuid of the client to search
144
+ *
145
+ * Search firmware client using UUID and reture related client information.
146
+ *
147
+ * Return: pointer of client information on success, NULL on failure.
148
+ */
149
+struct ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev,
150
+ const guid_t *uuid)
151
+{
152
+ int i;
153
+ unsigned long flags;
154
+
155
+ spin_lock_irqsave(&dev->fw_clients_lock, flags);
156
+ i = ishtp_fw_cl_by_uuid(dev, uuid);
157
+ spin_unlock_irqrestore(&dev->fw_clients_lock, flags);
158
+ if (i < 0 || dev->fw_clients[i].props.fixed_address)
159
+ return NULL;
160
+
161
+ return &dev->fw_clients[i];
162
+}
163
+EXPORT_SYMBOL(ishtp_fw_cl_get_client);
164
+
165
+/**
166
+ * ishtp_get_fw_client_id() - Get fw client id
167
+ *
168
+ * This interface is used to reset HW get FW client id.
169
+ *
170
+ * Return: firmware client id.
171
+ */
172
+int ishtp_get_fw_client_id(struct ishtp_fw_client *fw_client)
173
+{
174
+ return fw_client->client_id;
175
+}
176
+EXPORT_SYMBOL(ishtp_get_fw_client_id);
150177
151178 /**
152179 * ishtp_fw_cl_by_id() - return index to fw_clients for client_id
....@@ -195,6 +222,26 @@
195222 return -ENODEV;
196223
197224 return driver->probe(device);
225
+}
226
+
227
+/**
228
+ * ishtp_cl_bus_match() - Bus match() callback
229
+ * @dev: the device structure
230
+ * @drv: the driver structure
231
+ *
232
+ * This is a bus match callback, called when a new ishtp_cl_device is
233
+ * registered during ishtp bus client enumeration. Use the guid_t in
234
+ * drv and dev to decide whether they match or not.
235
+ *
236
+ * Return: 1 if dev & drv matches, 0 otherwise.
237
+ */
238
+static int ishtp_cl_bus_match(struct device *dev, struct device_driver *drv)
239
+{
240
+ struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
241
+ struct ishtp_cl_driver *driver = to_ishtp_cl_driver(drv);
242
+
243
+ return guid_equal(driver->guid,
244
+ &device->fw_client->props.protocol_name);
198245 }
199246
200247 /**
....@@ -350,6 +397,7 @@
350397 .name = "ishtp",
351398 .dev_groups = ishtp_cl_dev_groups,
352399 .probe = ishtp_cl_device_probe,
400
+ .match = ishtp_cl_bus_match,
353401 .remove = ishtp_cl_device_remove,
354402 .pm = &ishtp_cl_bus_dev_pm_ops,
355403 .uevent = ishtp_cl_uevent,
....@@ -376,7 +424,7 @@
376424 * Return: ishtp_cl_device pointer or NULL on failure
377425 */
378426 static struct ishtp_cl_device *ishtp_bus_add_device(struct ishtp_device *dev,
379
- uuid_le uuid, char *name)
427
+ guid_t uuid, char *name)
380428 {
381429 struct ishtp_cl_device *device;
382430 int status;
....@@ -442,7 +490,7 @@
442490 }
443491
444492 /**
445
- * __ishtp_cl_driver_register() - Client driver register
493
+ * ishtp_cl_driver_register() - Client driver register
446494 * @driver: the client driver instance
447495 * @owner: Owner of this driver module
448496 *
....@@ -451,11 +499,9 @@
451499 *
452500 * Return: Return value of driver_register or -ENODEV if not ready
453501 */
454
-int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver,
455
- struct module *owner)
502
+int ishtp_cl_driver_register(struct ishtp_cl_driver *driver,
503
+ struct module *owner)
456504 {
457
- int err;
458
-
459505 if (!ishtp_device_ready)
460506 return -ENODEV;
461507
....@@ -463,13 +509,9 @@
463509 driver->driver.owner = owner;
464510 driver->driver.bus = &ishtp_cl_bus_type;
465511
466
- err = driver_register(&driver->driver);
467
- if (err)
468
- return err;
469
-
470
- return 0;
512
+ return driver_register(&driver->driver);
471513 }
472
-EXPORT_SYMBOL(__ishtp_cl_driver_register);
514
+EXPORT_SYMBOL(ishtp_cl_driver_register);
473515
474516 /**
475517 * ishtp_cl_driver_unregister() - Client driver unregister
....@@ -564,6 +606,47 @@
564606 EXPORT_SYMBOL(ishtp_put_device);
565607
566608 /**
609
+ * ishtp_set_drvdata() - set client driver data
610
+ * @cl_device: client device instance
611
+ * @data: driver data need to be set
612
+ *
613
+ * Set client driver data to cl_device->driver_data.
614
+ */
615
+void ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data)
616
+{
617
+ cl_device->driver_data = data;
618
+}
619
+EXPORT_SYMBOL(ishtp_set_drvdata);
620
+
621
+/**
622
+ * ishtp_get_drvdata() - get client driver data
623
+ * @cl_device: client device instance
624
+ *
625
+ * Get client driver data from cl_device->driver_data.
626
+ *
627
+ * Return: pointer of driver data
628
+ */
629
+void *ishtp_get_drvdata(struct ishtp_cl_device *cl_device)
630
+{
631
+ return cl_device->driver_data;
632
+}
633
+EXPORT_SYMBOL(ishtp_get_drvdata);
634
+
635
+/**
636
+ * ishtp_dev_to_cl_device() - get ishtp_cl_device instance from device instance
637
+ * @device: device instance
638
+ *
639
+ * Get ish_cl_device instance which embeds device instance in it.
640
+ *
641
+ * Return: pointer to ishtp_cl_device instance
642
+ */
643
+struct ishtp_cl_device *ishtp_dev_to_cl_device(struct device *device)
644
+{
645
+ return to_ishtp_cl_device(device);
646
+}
647
+EXPORT_SYMBOL(ishtp_dev_to_cl_device);
648
+
649
+/**
567650 * ishtp_bus_new_client() - Create a new client
568651 * @dev: ISHTP device instance
569652 *
....@@ -577,7 +660,7 @@
577660 int i;
578661 char *dev_name;
579662 struct ishtp_cl_device *cl_device;
580
- uuid_le device_uuid;
663
+ guid_t device_uuid;
581664
582665 /*
583666 * For all reported clients, create an unconnected client and add its
....@@ -587,7 +670,7 @@
587670 */
588671 i = dev->fw_client_presentation_num - 1;
589672 device_uuid = dev->fw_clients[i].props.protocol_name;
590
- dev_name = kasprintf(GFP_KERNEL, "{%pUL}", device_uuid.b);
673
+ dev_name = kasprintf(GFP_KERNEL, "{%pUL}", &device_uuid);
591674 if (!dev_name)
592675 return -ENOMEM;
593676
....@@ -758,6 +841,59 @@
758841 }
759842
760843 /**
844
+ * ishtp_device() - Return device pointer
845
+ *
846
+ * This interface is used to return device pointer from ishtp_cl_device
847
+ * instance.
848
+ *
849
+ * Return: device *.
850
+ */
851
+struct device *ishtp_device(struct ishtp_cl_device *device)
852
+{
853
+ return &device->dev;
854
+}
855
+EXPORT_SYMBOL(ishtp_device);
856
+
857
+/**
858
+ * ishtp_get_pci_device() - Return PCI device dev pointer
859
+ * This interface is used to return PCI device pointer
860
+ * from ishtp_cl_device instance.
861
+ *
862
+ * Return: device *.
863
+ */
864
+struct device *ishtp_get_pci_device(struct ishtp_cl_device *device)
865
+{
866
+ return device->ishtp_dev->devc;
867
+}
868
+EXPORT_SYMBOL(ishtp_get_pci_device);
869
+
870
+/**
871
+ * ishtp_trace_callback() - Return trace callback
872
+ *
873
+ * This interface is used to return trace callback function pointer.
874
+ *
875
+ * Return: void *.
876
+ */
877
+void *ishtp_trace_callback(struct ishtp_cl_device *cl_device)
878
+{
879
+ return cl_device->ishtp_dev->print_log;
880
+}
881
+EXPORT_SYMBOL(ishtp_trace_callback);
882
+
883
+/**
884
+ * ish_hw_reset() - Call HW reset IPC callback
885
+ *
886
+ * This interface is used to reset HW in case of error.
887
+ *
888
+ * Return: value from IPC hw_reset callback
889
+ */
890
+int ish_hw_reset(struct ishtp_device *dev)
891
+{
892
+ return dev->ops->hw_reset(dev);
893
+}
894
+EXPORT_SYMBOL(ish_hw_reset);
895
+
896
+/**
761897 * ishtp_bus_register() - Function to register bus
762898 *
763899 * This register ishtp bus