Skip to content

Commit 3aaf037

Browse files
committed
media: apple: isp: Parse firmware version from device tree
Required since t8112-isp uses a 32-bit address in the CISP_CMD_CH_SET_FILE_LOAD command with the macOS 12.4 firmware. Signed-off-by: Janne Grunau <[email protected]>
1 parent de69629 commit 3aaf037

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

drivers/media/platform/apple/isp/isp-cmd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Copyright 2023 Eileen Yoon <[email protected]> */
33

44
#include "isp-cmd.h"
5+
#include "isp-drv.h"
56
#include "isp-iommu.h"
67
#include "isp-ipc.h"
78

@@ -261,7 +262,7 @@ int isp_cmd_ch_buffer_return(struct apple_isp *isp, u32 chan)
261262
int isp_cmd_ch_set_file_load(struct apple_isp *isp, u32 chan, u64 addr,
262263
u32 size)
263264
{
264-
if (isp->hw->gen >= ISP_GEN_T8112) {
265+
if (isp->fw_compat >= ISP_FIRMWARE_V_13_5) {
265266
struct cmd_ch_set_file_load64 args = {
266267
.opcode = CISP_OPCODE(CISP_CMD_CH_SET_FILE_LOAD),
267268
.chan = chan,

drivers/media/platform/apple/isp/isp-drv.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,72 @@ static int apple_isp_init_presets(struct apple_isp *isp)
224224
return err;
225225
}
226226

227+
static const char * isp_fw2str(enum isp_firmware_version version)
228+
{
229+
switch (version) {
230+
case ISP_FIRMWARE_V_12_3:
231+
return "12.3";
232+
case ISP_FIRMWARE_V_12_4:
233+
return "12.4";
234+
case ISP_FIRMWARE_V_13_5:
235+
return "13.5";
236+
default:
237+
return "unknown";
238+
}
239+
}
240+
241+
#define ISP_FW_VERSION_MIN_LEN 3
242+
#define ISP_FW_VERSION_MAX_LEN 5
243+
244+
static enum isp_firmware_version isp_read_fw_version(struct device *dev,
245+
const char *name)
246+
{
247+
u32 ver[ISP_FW_VERSION_MAX_LEN];
248+
int len = of_property_read_variable_u32_array(dev->of_node, name, ver,
249+
ISP_FW_VERSION_MIN_LEN,
250+
ISP_FW_VERSION_MAX_LEN);
251+
252+
switch (len) {
253+
case 3:
254+
if (ver[0] == 12 && ver[1] == 3 && ver[2] <= 1)
255+
return ISP_FIRMWARE_V_12_3;
256+
else if (ver[0] == 12 && ver[1] == 4 && ver[2] == 0)
257+
return ISP_FIRMWARE_V_12_4;
258+
else if (ver[0] == 13 && ver[1] == 5 && ver[2] == 0)
259+
return ISP_FIRMWARE_V_13_5;
260+
261+
dev_warn(dev, "unknown %s: %d.%d.%d\n", name, ver[0], ver[1], ver[2]);
262+
break;
263+
case 4:
264+
dev_warn(dev, "unknown %s: %d.%d.%d.%d\n", name, ver[0], ver[1],
265+
ver[2], ver[3]);
266+
break;
267+
case 5:
268+
dev_warn(dev, "unknown %s: %d.%d.%d.%d.%d\n", name, ver[0],
269+
ver[1], ver[2], ver[3], ver[4]);
270+
break;
271+
default:
272+
dev_warn(dev, "could not parse %s: %d\n", name, len);
273+
break;
274+
}
275+
276+
return ISP_FIRMWARE_V_UNKNOWN;
277+
}
278+
279+
static enum isp_firmware_version isp_check_firmware_version(struct device *dev)
280+
{
281+
enum isp_firmware_version version, compat;
282+
283+
/* firmware version is just informative */
284+
version = isp_read_fw_version(dev, "apple,firmware-version");
285+
compat = isp_read_fw_version(dev, "apple,firmware-compat");
286+
287+
dev_info(dev, "ISP firmware-compat: %s (FW: %s)\n", isp_fw2str(compat),
288+
isp_fw2str(version));
289+
290+
return compat;
291+
}
292+
227293
static int apple_isp_probe(struct platform_device *pdev)
228294
{
229295
struct device *dev = &pdev->dev;
@@ -243,6 +309,11 @@ static int apple_isp_probe(struct platform_device *pdev)
243309
platform_set_drvdata(pdev, isp);
244310
dev_set_drvdata(dev, isp);
245311

312+
/* Differences between firmware versions are rather minor so try to work
313+
* with unknown firmware.
314+
*/
315+
isp->fw_compat = isp_check_firmware_version(dev);
316+
246317
err = of_property_read_u32(dev->of_node, "apple,platform-id",
247318
&isp->platform_id);
248319
if (err) {

drivers/media/platform/apple/isp/isp-drv.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ enum isp_generation {
3232
ISP_GEN_T8112,
3333
};
3434

35+
enum isp_firmware_version {
36+
ISP_FIRMWARE_V_UNKNOWN,
37+
ISP_FIRMWARE_V_12_3,
38+
ISP_FIRMWARE_V_12_4,
39+
ISP_FIRMWARE_V_13_5,
40+
};
41+
3542
struct isp_surf {
3643
struct drm_mm_node *mm;
3744
struct list_head head;
@@ -180,6 +187,7 @@ struct isp_format {
180187
struct apple_isp {
181188
struct device *dev;
182189
const struct apple_isp_hw *hw;
190+
enum isp_firmware_version fw_compat;
183191
u32 platform_id;
184192
u32 temporal_filter;
185193
struct isp_preset *presets;

0 commit comments

Comments
 (0)