diff mbox series

[2/3] HID: intel-ish-hid: Use CPU generation string in driver_data

Message ID 20240813034736.812475-3-lixu.zhang@intel.com (mailing list archive)
State Superseded
Delegated to: Jiri Kosina
Headers show
Series hid: intel-ish-hid: Add support for vendor customized firmware loading | expand

Commit Message

Zhang Lixu Aug. 13, 2024, 3:47 a.m. UTC
ISH allows vendors to customize ISH firmware. To differentiate different
vendors and load the correct firmware, Intel defined a firmware file
name format. As part of the filename, there is a "generation" string. To
load correct format the driver must know the generation name to create
file name.

In the absence of any vendor specific firmware, default ISH firmware is
loaded.

Currently full ISH firmware file name is stored as part of driver data.
This file name already includes the generation name. For example, for
Lunar Lake, the name is ish_lnlm.bin, where "lnlm" is the generation.

So instead of storing both generation name and ISH default firmware file
name, just store generation name and create the default ISH firmware
file name string during initialization.

No functional changes are expected.

Signed-off-by: Zhang Lixu <lixu.zhang@intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/hid/intel-ish-hid/ipc/pci-ish.c     |  8 ++++---
 drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h |  8 ++++---
 drivers/hid/intel-ish-hid/ishtp/loader.c    | 23 ++++++++++++++++++---
 3 files changed, 30 insertions(+), 9 deletions(-)

Comments

Zhang Lixu Aug. 15, 2024, 2:23 a.m. UTC | #1
>-----Original Message-----
>From: Zhang, Lixu <lixu.zhang@intel.com>
>Sent: Tuesday, August 13, 2024 11:48 AM
>To: linux-input@vger.kernel.org; srinivas.pandruvada@linux.intel.com;
>jikos@kernel.org; benjamin.tissoires@redhat.com
>Cc: Zhang, Lixu <lixu.zhang@intel.com>; Han, Hemin <hemin.han@intel.com>;
>Wang, Yoshi <yoshi.wang@intel.com>; Xu, Even <even.xu@intel.com>
>Subject: [PATCH 2/3] HID: intel-ish-hid: Use CPU generation string in
>driver_data
>
>
>+#define ISH_FW_FILE_DEFALUT_FMT "intel/ish/ish_%s.bin"
>+
The version 2 has been sent out to address the review comments from ilpo.jarvinen@linux.intel.com.

Thanks,
Lixu

>--
>2.34.1
diff mbox series

Patch

diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
index f82428d7f6c3..f20463082dc4 100644
--- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
+++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
@@ -28,11 +28,13 @@  enum ishtp_driver_data_index {
 	ISHTP_DRIVER_DATA_LNL_M,
 };
 
-#define ISH_FW_FILENAME_LNL_M "intel/ish/ish_lnlm.bin"
+#define ISH_FW_GEN_LNL_M "lnlm"
+
+#define ISH_FIRMWARE_PATH(gen) "intel/ish/ish_" gen ".bin"
 
 static struct ishtp_driver_data ishtp_driver_data[] = {
 	[ISHTP_DRIVER_DATA_LNL_M] = {
-		.fw_filename = ISH_FW_FILENAME_LNL_M,
+		.fw_generation = ISH_FW_GEN_LNL_M,
 	},
 };
 
@@ -397,4 +399,4 @@  MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
 MODULE_DESCRIPTION("Intel(R) Integrated Sensor Hub PCI Device Driver");
 MODULE_LICENSE("GPL");
 
-MODULE_FIRMWARE(ISH_FW_FILENAME_LNL_M);
+MODULE_FIRMWARE(ISH_FIRMWARE_PATH(ISH_FW_GEN_LNL_M));
diff --git a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h
index 181838c3d7ac..cdacce0a4c9d 100644
--- a/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h
+++ b/drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h
@@ -129,13 +129,15 @@  struct ishtp_hw_ops {
  * ISHTP device instance. It allows for the storage of data that is unique to
  * a particular driver or hardware variant.
  *
- * @fw_filename: The firmware filename associated with a specific hardware
+ * @fw_generation: The generation name associated with a specific hardware
  *               variant of the Intel Integrated Sensor Hub (ISH). This allows
  *               the driver to load the correct firmware based on the device's
- *               hardware variant.
+ *               hardware variant. For example, "lnlm" for the Lunar Lake-M
+ *               platform. The generation name must not exceed 8 characters
+ *               in length.
  */
 struct ishtp_driver_data {
-	char *fw_filename;
+	char *fw_generation;
 };
 
 /**
diff --git a/drivers/hid/intel-ish-hid/ishtp/loader.c b/drivers/hid/intel-ish-hid/ishtp/loader.c
index fcca070bdecb..b4b15279c9c4 100644
--- a/drivers/hid/intel-ish-hid/ishtp/loader.c
+++ b/drivers/hid/intel-ish-hid/ishtp/loader.c
@@ -43,6 +43,7 @@ 
 #include <linux/math.h>
 #include <linux/module.h>
 #include <linux/pfn.h>
+#include <linux/sprintf.h>
 #include <linux/string.h>
 #include <linux/types.h>
 #include <linux/wait.h>
@@ -192,6 +193,23 @@  static int prepare_dma_bufs(struct ishtp_device *dev,
 	return 0;
 }
 
+#define ISH_FW_FILE_DEFALUT_FMT "intel/ish/ish_%s.bin"
+
+#define ISH_FW_FILENAME_LEN_MAX 56
+
+static int request_ish_firmware(const struct firmware **firmware_p,
+				struct device *dev)
+{
+	struct ishtp_device *ishtp = dev_get_drvdata(dev);
+	const char *gen;
+	char filename[ISH_FW_FILENAME_LEN_MAX];
+
+	gen = ishtp->driver_data->fw_generation;
+	snprintf(filename, sizeof(filename), ISH_FW_FILE_DEFALUT_FMT, gen);
+
+	return request_firmware(firmware_p, filename, dev);
+}
+
 /**
  * ishtp_loader_work() - Load the ISHTP firmware
  * @work: The work structure
@@ -220,7 +238,6 @@  void ishtp_loader_work(struct work_struct *work)
 	struct loader_xfer_query query = { .header = cpu_to_le32(query_hdr.val32), };
 	struct loader_start start = { .header = cpu_to_le32(start_hdr.val32), };
 	union loader_recv_message recv_msg;
-	char *filename = dev->driver_data->fw_filename;
 	const struct firmware *ish_fw;
 	void *dma_bufs[FRAGMENT_MAX_NUM] = {};
 	u32 fragment_size;
@@ -228,9 +245,9 @@  void ishtp_loader_work(struct work_struct *work)
 	int retry = ISHTP_LOADER_RETRY_TIMES;
 	int rv;
 
-	rv = request_firmware(&ish_fw, filename, dev->devc);
+	rv = request_ish_firmware(&ish_fw, dev->devc);
 	if (rv < 0) {
-		dev_err(dev->devc, "request firmware %s failed:%d\n", filename, rv);
+		dev_err(dev->devc, "request ish firmware failed:%d\n", rv);
 		return;
 	}