Re: [PATCH v2] ASoC: rt1320: reads patch code from firmware file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Op 14-09-2024 om 11:05 schreef shumingf@xxxxxxxxxxx:
From: Shuming Fan <shumingf@xxxxxxxxxxx>

This patch removes many lines of the patch code and
reads the patch code from firmware files.

Signed-off-by: Shuming Fan <shumingf@xxxxxxxxxxx>
[...]
+static void rt1320_load_mcu_patch(struct rt1320_sdw_priv *rt1320)
+{
+	struct sdw_slave *slave = rt1320->sdw_slave;
+	const struct firmware *patch;
+	const char *filename;
+	unsigned int addr, val;
+	const unsigned char *ptr;
+	int ret, i;
+
+	if (rt1320->version_id <= RT1320_VB)
+		filename = RT1320_VAB_MCU_PATCH;
+	else
+		filename = RT1320_VC_MCU_PATCH;
+
+	/* load the patch code here */
+	ret = request_firmware(&patch, filename, &slave->dev);
+	if (ret) {
+		dev_err(&slave->dev, "%s: Failed to load %s firmware", __func__, filename);
+		regmap_write(rt1320->regmap, 0xc598, 0x00);
+		regmap_write(rt1320->regmap, 0x10007000, 0x67);
+		regmap_write(rt1320->regmap, 0x10007001, 0x80);
+		regmap_write(rt1320->regmap, 0x10007002, 0x00);
+		regmap_write(rt1320->regmap, 0x10007003, 0x00);
+	} else {
+		ptr = (const unsigned char *)patch->data;
+		if ((patch->size % 8) == 0) {
+			for (i = 0; i < patch->size; i += 8) {
+				addr = (ptr[i] & 0xff) | (ptr[i + 1] & 0xff) << 8 |
+					(ptr[i + 2] & 0xff) << 16 | (ptr[i + 3] & 0xff) << 24;
+				val = (ptr[i + 4] & 0xff) | (ptr[i + 5] & 0xff) << 8 |
+					(ptr[i + 6] & 0xff) << 16 | (ptr[i + 7] & 0xff) << 24;
+
+				if (addr > 0x10007ffff || addr < 0x10007000) {
Oops 0x10007ffff must be 0x10007fff
+					dev_err(&slave->dev, "%s: the address 0x%x is wrong", __func__, addr);
+					goto _exit_;
+				}
+				if (val > 0xff) {
+					dev_err(&slave->dev, "%s: the value 0x%x is wrong", __func__, val);
+					goto _exit_;
+				}
+				regmap_write(rt1320->regmap, addr, val);
+			}
+		}
+_exit_:
+		release_firmware(patch);
+	}
+}





[Index of Archives]     [Pulseaudio]     [Linux Audio Users]     [ALSA Devel]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux