Skip to content

Commit

Permalink
media: apple: isp: Parse firmware version from device tree
Browse files Browse the repository at this point in the history
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 <j@jannau.net>
  • Loading branch information
jannau committed Nov 19, 2024
1 parent de69629 commit 3aaf037
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/media/platform/apple/isp/isp-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Copyright 2023 Eileen Yoon <eyn@gmx.com> */

#include "isp-cmd.h"
#include "isp-drv.h"
#include "isp-iommu.h"
#include "isp-ipc.h"

Expand Down Expand Up @@ -261,7 +262,7 @@ int isp_cmd_ch_buffer_return(struct apple_isp *isp, u32 chan)
int isp_cmd_ch_set_file_load(struct apple_isp *isp, u32 chan, u64 addr,
u32 size)
{
if (isp->hw->gen >= ISP_GEN_T8112) {
if (isp->fw_compat >= ISP_FIRMWARE_V_13_5) {
struct cmd_ch_set_file_load64 args = {
.opcode = CISP_OPCODE(CISP_CMD_CH_SET_FILE_LOAD),
.chan = chan,
Expand Down
71 changes: 71 additions & 0 deletions drivers/media/platform/apple/isp/isp-drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,72 @@ static int apple_isp_init_presets(struct apple_isp *isp)
return err;
}

static const char * isp_fw2str(enum isp_firmware_version version)
{
switch (version) {
case ISP_FIRMWARE_V_12_3:
return "12.3";
case ISP_FIRMWARE_V_12_4:
return "12.4";
case ISP_FIRMWARE_V_13_5:
return "13.5";
default:
return "unknown";
}
}

#define ISP_FW_VERSION_MIN_LEN 3
#define ISP_FW_VERSION_MAX_LEN 5

static enum isp_firmware_version isp_read_fw_version(struct device *dev,
const char *name)
{
u32 ver[ISP_FW_VERSION_MAX_LEN];
int len = of_property_read_variable_u32_array(dev->of_node, name, ver,
ISP_FW_VERSION_MIN_LEN,
ISP_FW_VERSION_MAX_LEN);

switch (len) {
case 3:
if (ver[0] == 12 && ver[1] == 3 && ver[2] <= 1)
return ISP_FIRMWARE_V_12_3;
else if (ver[0] == 12 && ver[1] == 4 && ver[2] == 0)
return ISP_FIRMWARE_V_12_4;
else if (ver[0] == 13 && ver[1] == 5 && ver[2] == 0)
return ISP_FIRMWARE_V_13_5;

dev_warn(dev, "unknown %s: %d.%d.%d\n", name, ver[0], ver[1], ver[2]);
break;
case 4:
dev_warn(dev, "unknown %s: %d.%d.%d.%d\n", name, ver[0], ver[1],
ver[2], ver[3]);
break;
case 5:
dev_warn(dev, "unknown %s: %d.%d.%d.%d.%d\n", name, ver[0],
ver[1], ver[2], ver[3], ver[4]);
break;
default:
dev_warn(dev, "could not parse %s: %d\n", name, len);
break;
}

return ISP_FIRMWARE_V_UNKNOWN;
}

static enum isp_firmware_version isp_check_firmware_version(struct device *dev)
{
enum isp_firmware_version version, compat;

/* firmware version is just informative */
version = isp_read_fw_version(dev, "apple,firmware-version");
compat = isp_read_fw_version(dev, "apple,firmware-compat");

dev_info(dev, "ISP firmware-compat: %s (FW: %s)\n", isp_fw2str(compat),
isp_fw2str(version));

return compat;
}

static int apple_isp_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
Expand All @@ -243,6 +309,11 @@ static int apple_isp_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, isp);
dev_set_drvdata(dev, isp);

/* Differences between firmware versions are rather minor so try to work
* with unknown firmware.
*/
isp->fw_compat = isp_check_firmware_version(dev);

err = of_property_read_u32(dev->of_node, "apple,platform-id",
&isp->platform_id);
if (err) {
Expand Down
8 changes: 8 additions & 0 deletions drivers/media/platform/apple/isp/isp-drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ enum isp_generation {
ISP_GEN_T8112,
};

enum isp_firmware_version {
ISP_FIRMWARE_V_UNKNOWN,
ISP_FIRMWARE_V_12_3,
ISP_FIRMWARE_V_12_4,
ISP_FIRMWARE_V_13_5,
};

struct isp_surf {
struct drm_mm_node *mm;
struct list_head head;
Expand Down Expand Up @@ -180,6 +187,7 @@ struct isp_format {
struct apple_isp {
struct device *dev;
const struct apple_isp_hw *hw;
enum isp_firmware_version fw_compat;
u32 platform_id;
u32 temporal_filter;
struct isp_preset *presets;
Expand Down

0 comments on commit 3aaf037

Please sign in to comment.