platform/x86: Add AMD ISP platform config for OV05C10
PATCH v3 1/1 platform/x86: Add AMD ISP platform config for OV05C10
ISP device specific configuration is not available in ACPI. Add swnode graph to configure the missing device properties for the OV05C10 camera device supported on amdisp platform.
Add support to create i2c-client dynamically when amdisp i2c adapter is available.
---
v2 -> v3:
- Remodelled as ACPI driver to bind the device when matching acpi sensor device is detected. This eliminated the need for dmi checks for platform validation.
- Added software nodes to align with camera device-tree format to capture the camera device properties missing in the ACPI.
- Constructed swnode graph in the below format to successfully parse the endpoint node using v4l2_fwnode_endpoint_alloc_parse().
OMNI5C10 {
refclk = 24MHz;
ports {
port@ {
endpoint {
bus-type = 4;
data-lanes = <1 2>;
link-frequencies = 925MHz;
remote-endpoint = &ov05c10_refs;
};
};
};
};- GPIO sensor lookup is moved out of this driver scope, it is taken care in isp driver module init.
- This platform driver is specific to AMD ISP4, hence renamed driver name as "amd-isp4".
drivers/platform/x86/amd/Kconfig | 11 + drivers/platform/x86/amd/Makefile | 1 + drivers/platform/x86/amd/amd_isp4.c | 354 ++++++++++++++++++++++++++++ 3 files changed, 366 insertions(+) create mode 100644 drivers/platform/x86/amd/amd_isp4.c
drivers/platform/x86/amd/Kconfig +11 -0
@@ -32,3 +32,14 @@ config AMD_WBRF This mechanism will only be activated on platforms that advertise a need for it. + +config AMD_ISP_PLATFORM + bool "AMD platform with ISP4 that supports Camera sensor device" + depends on I2C && X86_64 && AMD_ISP4 + help + For AMD platform that support Image signal processor generation 4, it + is necessary to add platform specific camera sensor module board info + which includes the sensor driver device id and the i2c address. + + If you have a AMD platform that support ISP4 and with a sensor + connected to it, say Y here
drivers/platform/x86/amd/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-$(CONFIG_AMD_PMC) += pmc/ obj-$(CONFIG_AMD_HSMP) += hsmp/ obj-$(CONFIG_AMD_PMF) += pmf/ obj-$(CONFIG_AMD_WBRF) += wbrf.o +obj-$(CONFIG_AMD_ISP_PLATFORM) += amd_isp4.o
drivers/platform/x86/amd/amd_isp4.c new file +354 -0
354 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 39 lines · Pratap Nirujogi
ISP device specific configuration is not available in ACPI. Add swnode graph to configure the missing device properties for the OV05C10 camera device supported on amdisp platform.
Add support to create i2c-client dynamically when amdisp i2c adapter is available.
Signed-off-by Pratap Nirujogi <[email protected]>Signed-off-by Benjamin Chan <[email protected]>---
v2 -> v3:- Remodelled as ACPI driver to bind the device when matching acpi sensor device is detected. This eliminated the need for dmi checks for platform validation.
- Added software nodes to align with camera device-tree format to capture the camera device properties missing in the ACPI.
- Constructed swnode graph in the below format to successfully parse the endpoint node using
v4l2_fwnode_endpoint_alloc_parse().OMNI5C10 { refclk = 24MHz; ports { port@ { endpoint { bus-type = 4; data-lanes = <1 2>; link-frequencies = 925MHz; remote-endpoint = &ov05c10_refs; }; }; }; };- GPIO sensor lookup is moved out of this driver scope, it is taken care in isp driver module init.
Quoted 8 lines
- This platform driver is specific to AMD ISP4, hence renamed driver name as "amd-isp4".
drivers/platform/x86/amd/Kconfig | 11 + drivers/platform/x86/amd/Makefile | 1 + drivers/platform/x86/amd/amd_isp4.c | 354 ++++++++++++++++++++++++++++ 3 files changed, 366 insertions(+)create mode 100644
drivers/platform/x86/amd/amd_isp4.c
Pratap,
Overall I like the direction of this improvement. A few small comments I notice below.
drivers/platform/x86/amd/Kconfig config AMD_WBRF · line 37
Quoted 12 lines
drivers/platform/x86/amd/Kconfig +3
-0@@ -32,3 +32,14 @@ config AMD_WBRF This mechanism will only be activated on platforms that advertise a need for it. + +config AMD_ISP_PLATFORM + bool "AMD platform with ISP4 that supports Camera sensor device"
Now that this is an ACPI driver this should be tristate because it can now be a module.
drivers/platform/x86/amd/Kconfig config AMD_WBRF · line 38
Quoted 1 line
drivers/platform/x86/amd/Kconfig +1
-0+ depends on I2C && X86_64 && AMD_ISP4
Now that this is an ACPI driver there should be a:
depends on ACPI
Quoted 40 lines
drivers/platform/x86/amd/Kconfig +7
-0+ help + For AMD platform that support Image signal processor generation 4, it + is necessary to add platform specific camera sensor module board info + which includes the sensor driver device id and the i2c address. + + If you have a AMD platform that support ISP4 and with a sensor + connected to it, say Y heredrivers/platform/x86/amd/Makefile +1
-0@@ -10,3 +10,4 @@ obj-$(CONFIG_AMD_PMC) += pmc/ obj-$(CONFIG_AMD_HSMP) += hsmp/ obj-$(CONFIG_AMD_PMF) += pmf/ obj-$(CONFIG_AMD_WBRF) += wbrf.o +obj-$(CONFIG_AMD_ISP_PLATFORM) += amd_isp4.odrivers/platform/x86/amd/amd_isp4.c new file +18
-0@@ -0,0 +1,354 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* AMD ISP platform driver for sensor i2-client instantiation +* +* Copyright 2025 Advanced Micro Devices, Inc. +*/ + +#include <linux/acpi.h> +#include <linux/device/bus.h> +#include <linux/dmi.h> +#include <linux/gpio/machine.h> +#include <linux/init.h> +#include <linux/i2c.h> +#include <linux/kernel.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/property.h>
drivers/platform/x86/amd/amd_isp4.c line 28
Quoted 10 lines
drivers/platform/x86/amd/amd_isp4.c new file +10
-0+#include <linux/units.h> + +#define AMDISP_OV05C10_I2C_ADDR 0x10 +#define AMDISP_OV05C10_PLAT_NAME "amdisp_ov05c10_platform" +#define AMDISP_OV05C10_HID "OMNI5C10" +#define AMDISP_OV05C10_REMOTE_EP_NAME "ov05c10_isp_4_1_1" +#define AMD_ISP_PLAT_DRV_NAME "amd-isp4" + +/* +* AMD ISP platform definition to configure the device properites
properties
Quoted 326 lines
drivers/platform/x86/amd/amd_isp4.c new file +326
-0+* missing in the ACPI table. +*/ +struct amdisp_platform { +const char *name; +struct i2c_board_info board_info; +u8 i2c_addr; +struct i2c_client *i2c_dev; +u8 max_num_swnodes; +struct software_node **swnodes; +}; + +static struct amdisp_platform *ov05c10_amdisp; + +/* Top-level OV05C10 camera node property table */ +static const struct property_entry ov05c10_camera_props[]__initconst = { +PROPERTY_ENTRY_U32 ("refclk" ,24 *HZ_PER_MHZ ), + { } +}; + +/* Root AMD ISP OV05C10 camera node definition */ +static const struct software_node camera_node = { + .name =AMDISP_OV05C10_HID , + .properties = ov05c10_camera_props, +}; + +/* +* AMD ISP OV05C10 Ports node definition. No properties defined for +* ports node for OV05C10. +*/ +static const struct software_node ports = { + .name ="ports" , + .parent = &camera_node, +}; + +/* +* AMD ISP OV05C10 Port node definition. No properties defined for +* port node for OV05C10. +*/ +static const struct software_node port_node = { + .name ="port@" , + .parent = &ports, +}; + +/* +* Remote endpoint AMD ISP node definition. No properties defined for +* remote endpoint node for OV05C10. +*/ +static const struct software_node remote_ep_isp_node = { + .name =AMDISP_OV05C10_REMOTE_EP_NAME , +}; + +/* +* Remote endpoint reference for isp node included in the +* OV05C10 endpoint. +*/ +static const struct software_node_ref_args ov05c10_refs[]__initconst = { +SOFTWARE_NODE_REFERENCE (&remote_ep_isp_node), +}; + +/* OV05C supports one single link frequency */ +static const u64 ov05c10_link_freqs[]__initconst = { +925 *HZ_PER_MHZ , +}; + +/* OV05C supports only 2-lane configuration */ +static const u32 ov05c10_data_lanes[]__initconst = { +1 , +2 , +}; + +/* OV05C10 endpoint node properties table */ +static const struct property_entry ov05c10_endpoint_props[]__initconst = { +PROPERTY_ENTRY_U32 ("bus-type" ,4 ), +PROPERTY_ENTRY_U32_ARRAY_LEN ("data-lanes" , ov05c10_data_lanes, +ARRAY_SIZE (ov05c10_data_lanes)), +PROPERTY_ENTRY_U64_ARRAY_LEN ("link-frequencies" , ov05c10_link_freqs, +ARRAY_SIZE (ov05c10_link_freqs)), +PROPERTY_ENTRY_REF_ARRAY ("remote-endpoint" , ov05c10_refs), + { } +}; + +/* AMD ISP endpoint node definition */ +static const struct software_node endpoint_node = { + .name ="endpoint" , + .parent = &port_node, + .properties = ov05c10_endpoint_props, +}; + +/* +* AMD ISP swnode graph uses 5 nodes and also its relationship is +* fixed to align with the structure that v4l2 expects for successful +* endpoint fwnode parsing. +* +* It is only the node property_entries that will vary for each platform +* supporting different sensor modules. +*/ +#define NUM_SW_NODES 5 + +static const struct software_node *ov05c10_nodes[NUM_SW_NODES +1 ] = { + &camera_node, + &ports, + &port_node, + &endpoint_node, + &remote_ep_isp_node, +NULL +}; + +/* OV05C10 specific AMD ISP platform configuration */ +static const struct amdisp_platform amdisp_ov05c10_platform_config = { + .name =AMDISP_OV05C10_PLAT_NAME , + .board_info = { + .dev_name ="ov05c10" , +I2C_BOARD_INFO ("ov05c10" ,AMDISP_OV05C10_I2C_ADDR ), + }, + .i2c_addr =AMDISP_OV05C10_I2C_ADDR , + .max_num_swnodes =NUM_SW_NODES , + .swnodes = (struct software_node **)ov05c10_nodes, +}; + +static const struct acpi_device_id amdisp_sensor_ids[] = { + {AMDISP_OV05C10_HID }, + { } +}; +MODULE_DEVICE_TABLE (acpi, amdisp_sensor_ids); + +static bool is_isp_i2c_adapter (struct i2c_adapter *adap) +{ +return !strncmp (adap->owner->name,"i2c_designware_amdisp" ,48 ); +} + +static void instantiate_isp_i2c_client (struct i2c_adapter *adap) +{ +struct i2c_board_info *info = &ov05c10_amdisp->board_info; +struct i2c_client *i2c_dev = ov05c10_amdisp->i2c_dev; + +if (i2c_dev) +return ; + +if (!info->addr) { +dev_err (&adap->dev,"invalid i2c_addr 0x%x detected\n" , + ov05c10_amdisp->i2c_addr); +return ; + } + + i2c_dev =i2c_new_client_device (adap, info); +if (IS_ERR (i2c_dev)) { +dev_err (&adap->dev,"error %ld registering isp i2c_client\n" , +PTR_ERR (i2c_dev)); + i2c_dev =NULL ; + }else { +dev_dbg (&adap->dev,"registered amdisp i2c_client on address 0x%02x\n" , + info->addr); + } +i2c_put_adapter (adap); +} + +static int isp_i2c_bus_notify (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct device *dev = data; +struct i2c_client *client; +struct i2c_adapter *adap; +struct i2c_client *i2c_dev = ov05c10_amdisp->i2c_dev; + +switch (action) { +case BUS_NOTIFY_ADD_DEVICE : + adap =i2c_verify_adapter (dev); +if (!adap) +break ; +if (is_isp_i2c_adapter (adap)) +instantiate_isp_i2c_client (adap); +break ; +case BUS_NOTIFY_REMOVED_DEVICE : + client =i2c_verify_client (dev); +if (!client) +break ; +if (i2c_dev == client) { +dev_dbg (&client->adapter->dev,"amdisp i2c_client removed\n" ); + i2c_dev =NULL ; + } +break ; +default : +break ; + } + +return NOTIFY_DONE ; +} + +static struct notifier_block isp_i2c_nb = { .notifier_call = isp_i2c_bus_notify }; + +static int release_amdisp_swnode_props (struct software_node **swnodes, +u8 num_swnodes) +{ +int i; + +for (i =0 ; i < num_swnodes; i++) { +if (swnodes[i] && + !IS_ERR_OR_NULL (swnodes[i]->properties)) { +property_entries_free (swnodes[i]->properties); + } + } + +return 0 ; +} + +static int initialize_ov05c10_swnode_props (struct amdisp_platform *p) +{ +struct software_node *sw_node; +int ret; +int i; + +if (strncmp (p->name,AMDISP_OV05C10_PLAT_NAME , +strlen (AMDISP_OV05C10_PLAT_NAME ))) +return -EINVAL ; + +/* Initialize platform specific props for each node */ +for (i =0 ; i < p->max_num_swnodes; i++) { + sw_node = p->swnodes[i]; + +if (sw_node->properties) { + sw_node->properties =property_entries_dup (sw_node->properties); +if (IS_ERR (sw_node->properties)) { + ret =PTR_ERR (sw_node->properties); + goto error_release_node_props; + } + } + } + +return 0 ; + +error_release_node_props: +release_amdisp_swnode_props (p->swnodes, p->max_num_swnodes); +return ret; +} + +static struct amdisp_platform *prepare_amdisp_platform (const struct amdisp_platform *src) +{ +struct amdisp_platform *isp_ov05c10; +const struct software_node **sw_nodes; +const struct software_node *sw_node; +struct i2c_board_info *info; +int ret; + + isp_ov05c10 =kmemdup (src,sizeof (*isp_ov05c10),GFP_KERNEL ); +if (!isp_ov05c10) +return ERR_PTR (-ENOMEM ); + + ret =initialize_ov05c10_swnode_props (isp_ov05c10); +if (ret) + goto error_free_platform; + + info = &isp_ov05c10->board_info; + + sw_nodes = (const struct software_node **)src->swnodes; + ret =software_node_register_node_group (sw_nodes); +if (ret) + goto error_unregister_sw_node; + + sw_node = (const struct software_node *)src->swnodes[0 ]; + info->fwnode =software_node_fwnode (sw_node); +if (IS_ERR (info->fwnode)) { + ret =PTR_ERR (info->fwnode); + goto error_unregister_sw_node; + } + +return isp_ov05c10; + +error_unregister_sw_node: +software_node_unregister_node_group (sw_nodes); + +error_free_platform: +kfree (isp_ov05c10); +return ERR_PTR (ret); +} + +static int amd_isp_probe (struct platform_device *pdev) +{ +int ret; + + ov05c10_amdisp =prepare_amdisp_platform (&amdisp_ov05c10_platform_config); +if (IS_ERR (ov05c10_amdisp)) { +pr_err ("failed to prepare amdisp platform fw node" ); +return PTR_ERR (ov05c10_amdisp); + } + +/* +* Register notifier to instantiate i2c client when AMD ISP adapter +* is ready. +*/ + ret =bus_register_notifier (&i2c_bus_type, &isp_i2c_nb); +if (ret) + goto error_free_platform; + +return ret; + +error_free_platform: +kfree (ov05c10_amdisp); +return ret; +} + +static void amd_isp_remove (struct platform_device *pdev) +{ +bus_unregister_notifier (&i2c_bus_type, &isp_i2c_nb); +i2c_unregister_device (ov05c10_amdisp->i2c_dev); +release_amdisp_swnode_props (ov05c10_amdisp->swnodes, + ov05c10_amdisp->max_num_swnodes); +software_node_unregister_node_group ((const struct software_node **) + ov05c10_amdisp->swnodes); +kfree (ov05c10_amdisp); +} + +static struct platform_driver amd_isp_platform_driver = { + .driver = { + .name =AMD_ISP_PLAT_DRV_NAME , + .acpi_match_table = amdisp_sensor_ids, + }, + .probe = amd_isp_probe, + .remove = amd_isp_remove, +}; + +module_platform_driver (amd_isp_platform_driver); + +MODULE_AUTHOR ("Benjamin Chan <[email protected]>" ); +MODULE_AUTHOR ("Pratap Nirujogi <[email protected]>" ); +MODULE_DESCRIPTION ("AMD ISP4 Platform Driver" ); +MODULE_LICENSE ("GPL" );
Hi Mario,
Thanks for the review.
Thanks,
Pratap
Quoted 49 lines · Mario Limonciello
Quoted 39 lines · Pratap Nirujogi
ISP device specific configuration is not available in ACPI. Add swnode graph to configure the missing device properties for the OV05C10 camera device supported on amdisp platform.
Add support to create i2c-client dynamically when amdisp i2c adapter is available.
Signed-off-by Pratap Nirujogi <[email protected]>Signed-off-by Benjamin Chan <[email protected]>---
v2 -> v3:- Remodelled as ACPI driver to bind the device when matching acpi sensor device is detected. This eliminated the need for dmi checks for platform validation.
- Added software nodes to align with camera device-tree format to capture the camera device properties missing in the ACPI.
- Constructed swnode graph in the below format to successfully parse the endpoint node using
v4l2_fwnode_endpoint_alloc_parse().OMNI5C10 {
refclk = 24MHz;
ports {
port@ {
endpoint {
bus-type = 4;
data-lanes = <1 2>;
link-frequencies = 925MHz;
remote-endpoint =&ov05c10_refs;
};
};
};
};- GPIO sensor lookup is moved out of this driver scope, it is taken care in isp driver module init.
Quoted 8 lines
- This platform driver is specific to AMD ISP4, hence renamed driver name as "amd-isp4".
drivers/platform/x86/amd/Kconfig | 11 + drivers/platform/x86/amd/Makefile | 1 +
drivers/platform/x86/amd/amd_isp4.c| 354 ++++++++++++++++++++++++++++3 files changed, 366 insertions(+)create mode 100644
drivers/platform/x86/amd/amd_isp4.c
Quoted 4 lines
Pratap,
Overall I like the direction of this improvement. A few small comments I notice below.
Thanks Mario. Sure, will address them in V4.
Quoted 14 lines
drivers/platform/x86/amd/Kconfig config AMD_WBRF · line 37
Quoted 11 lines
drivers/platform/x86/amd/Kconfig +0
-0@@ -32,3 +32,14 @@ config AMD_WBRFThis mechanism will only be activated on platforms that advertise a need for it.
drivers/platform/x86/amd/Kconfig +3
-0+ +config AMD_ISP_PLATFORM + bool "AMD platform with ISP4 that supports Camera sensor device"Now that this is an ACPI driver this should be tristate because it can now be a module.
Thanks. Will fix this in V4.
Quoted 52 lines
Quoted 1 line
+ depends on I2C &&
X86_64&&AMD_ISP4Now that this is an ACPI driver there should be a:
depends on ACPI
Quoted 46 lines
+ help
+ For AMD platform that support Image signal processor generation 4, it
+ is necessary to add platform specific camera sensor module board info
+ which includes the sensor driver device id and the i2c address.drivers/platform/x86/amd/Kconfig +3
-0+ + If you have a AMD platform that support ISP4 and with a sensor + connected to it, say Y heredrivers/platform/x86/amd/Makefile +0
-0@@ -10,3 +10,4 @@ obj-$(CONFIG_AMD_PMC) += pmc/obj-$(CONFIG_AMD_HSMP) += hsmp/
obj-$(CONFIG_AMD_PMF) += pmf/
obj-$(CONFIG_AMD_WBRF) += wbrf.odrivers/platform/x86/amd/Makefile +1
-0+obj-$(CONFIG_AMD_ISP_PLATFORM) += amd_isp4.odrivers/platform/x86/amd/amd_isp4.c new file +22
-0@@ -0,0 +1,354 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* AMD ISP platform driver for sensor i2-client instantiation +* +* Copyright 2025 Advanced Micro Devices, Inc. +*/ + +#include <linux/acpi.h> +#include <linux/device/bus.h> +#include <linux/dmi.h> +#include <linux/gpio/machine.h> +#include <linux/init.h> +#include <linux/i2c.h> +#include <linux/kernel.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/property.h> +#include <linux/units.h> + +#define AMDISP_OV05C10_I2C_ADDR 0x10 +#define AMDISP_OV05C10_PLAT_NAME "amdisp_ov05c10_platform"
Quoted 9 lines
drivers/platform/x86/amd/amd_isp4.c line 28
Quoted 6 lines
drivers/platform/x86/amd/amd_isp4.c new file +6
-0+#define AMDISP_OV05C10_HID "OMNI5C10" +#define AMDISP_OV05C10_REMOTE_EP_NAME "ov05c10_isp_4_1_1" +#define AMD_ISP_PLAT_DRV_NAME "amd-isp4" + +/* +* AMD ISP platform definition to configure the device properites properties
sure, will correct the typo error in V4.
Quoted 336 lines
Quoted 335 lines
drivers/platform/x86/amd/amd_isp4.c new file +15
-0+* missing in the ACPI table. +*/ +struct amdisp_platform { + const char *name; + struct i2c_board_info board_info; + u8 i2c_addr; + struct i2c_client *i2c_dev; + u8 max_num_swnodes; + struct software_node **swnodes; +}; + +static struct amdisp_platform *ov05c10_amdisp; + +/* Top-level OV05C10 camera node property table */ +static const struct property_entry ov05c10_camera_props[]__initconst = {
+PROPERTY_ENTRY_U32("refclk", 24 * HZ_PER_MHZ), + { }drivers/platform/x86/amd/amd_isp4.c new file +39
-0+}; + +/* Root AMD ISP OV05C10 camera node definition */ +static const struct software_node camera_node = { + .name = AMDISP_OV05C10_HID, + .properties = ov05c10_camera_props, +}; + +/* +* AMD ISP OV05C10 Ports node definition. No properties defined for +* ports node for OV05C10. +*/ +static const struct software_node ports = { + .name = "ports", + .parent = &camera_node, +}; + +/* +* AMD ISP OV05C10 Port node definition. No properties defined for +* port node for OV05C10. +*/ +static const struct software_node port_node = { + .name = "port@", + .parent = &ports, +}; + +/* +* Remote endpoint AMD ISP node definition. No properties defined for +* remote endpoint node for OV05C10. +*/ +static const struct software_node remote_ep_isp_node = { + .name = AMDISP_OV05C10_REMOTE_EP_NAME, +}; + +/* +* Remote endpoint reference for isp node included in the +* OV05C10 endpoint. +*/ +static const struct software_node_ref_args ov05c10_refs[]__initconst = {
+SOFTWARE_NODE_REFERENCE(&remote_ep_isp_node),drivers/platform/x86/amd/amd_isp4.c new file +15
-0+}; + +/* OV05C supports one single link frequency */ +static const u64 ov05c10_link_freqs[]__initconst = { + 925 * HZ_PER_MHZ, +}; + +/* OV05C supports only 2-lane configuration */ +static const u32 ov05c10_data_lanes[]__initconst = { + 1, + 2, +}; + +/* OV05C10 endpoint node properties table */ +static const struct property_entry ov05c10_endpoint_props[]
__initconst= {
+PROPERTY_ENTRY_U32("bus-type", 4),
+ PROPERTY_ENTRY_U32_ARRAY_LEN("data-lanes",ov05c10_data_lanes, +ARRAY_SIZE(ov05c10_data_lanes)),
+ PROPERTY_ENTRY_U64_ARRAY_LEN("link-frequencies",ov05c10_link_freqs, +ARRAY_SIZE(ov05c10_link_freqs)),
+PROPERTY_ENTRY_REF_ARRAY("remote-endpoint", ov05c10_refs), + { }drivers/platform/x86/amd/amd_isp4.c new file +72
-0+}; + +/* AMD ISP endpoint node definition */ +static const struct software_node endpoint_node = { + .name = "endpoint", + .parent = &port_node, + .properties = ov05c10_endpoint_props, +}; + +/* +* AMD ISP swnode graph uses 5 nodes and also its relationship is +* fixed to align with the structure that v4l2 expects for successful +* endpoint fwnode parsing. +* +* It is only the node property_entries that will vary for each platform +* supporting different sensor modules. +*/ +#define NUM_SW_NODES 5 + +static const struct software_node *ov05c10_nodes[NUM_SW_NODES +1 ] = { + &camera_node, + &ports, + &port_node, + &endpoint_node, + &remote_ep_isp_node, + NULL +}; + +/* OV05C10 specific AMD ISP platform configuration */ +static const struct amdisp_platform amdisp_ov05c10_platform_config = { + .name = AMDISP_OV05C10_PLAT_NAME, + .board_info = { + .dev_name = "ov05c10", + I2C_BOARD_INFO("ov05c10", AMDISP_OV05C10_I2C_ADDR), + }, + .i2c_addr = AMDISP_OV05C10_I2C_ADDR, + .max_num_swnodes = NUM_SW_NODES, + .swnodes = (struct software_node **)ov05c10_nodes, +}; + +static const struct acpi_device_id amdisp_sensor_ids[] = { + { AMDISP_OV05C10_HID }, + { } +}; +MODULE_DEVICE_TABLE (acpi, amdisp_sensor_ids); + +static bool is_isp_i2c_adapter (struct i2c_adapter *adap) +{ + return !strncmp(adap->owner->name, "i2c_designware_amdisp", 48); +} + +static void instantiate_isp_i2c_client (struct i2c_adapter *adap) +{ + struct i2c_board_info *info = &ov05c10_amdisp->board_info; + struct i2c_client *i2c_dev = ov05c10_amdisp->i2c_dev; + + if (i2c_dev) + return; + + if (!info->addr) { + dev_err(&adap->dev, "invalid i2c_addr 0x%x detected\n", + ov05c10_amdisp->i2c_addr); + return; + } + + i2c_dev = i2c_new_client_device(adap, info); + if (IS_ERR(i2c_dev)) { + dev_err(&adap->dev, "error %ld registering isp i2c_client\n", + PTR_ERR(i2c_dev)); + i2c_dev = NULL; + } else { + dev_dbg(&adap->dev, "registered amdisp i2c_client on address0x%02x\n",
+info->addr);
+ }
+i2c_put_adapter(adap);drivers/platform/x86/amd/amd_isp4.c new file +24
-0+} + +static int isp_i2c_bus_notify (struct notifier_block *nb, + unsigned long action, void *data) +{ + struct device *dev = data; + struct i2c_client *client; + struct i2c_adapter *adap; + struct i2c_client *i2c_dev = ov05c10_amdisp->i2c_dev; + + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: + adap = i2c_verify_adapter(dev); + if (!adap) + break; + if (is_isp_i2c_adapter(adap)) + instantiate_isp_i2c_client(adap); + break; + case BUS_NOTIFY_REMOVED_DEVICE: + client = i2c_verify_client(dev); + if (!client) + break; + if (i2c_dev == client) { + dev_dbg(&client->adapter->dev, "amdisp i2c_clientremoved\n");
+i2c_dev= NULL;
+ }
+ break;
+ default:
+ break;
+ }drivers/platform/x86/amd/amd_isp4.c new file +5
-0+ + return NOTIFY_DONE; +} + +static struct notifier_block isp_i2c_nb = { .notifier_call =
isp_i2c_bus_notify};drivers/platform/x86/amd/amd_isp4.c new file +32
-0+ +static int release_amdisp_swnode_props (struct software_node **swnodes, + u8 num_swnodes) +{ + int i; + + for (i = 0; i < num_swnodes; i++) { + if (swnodes[i] && + !IS_ERR_OR_NULL(swnodes[i]->properties)) { + property_entries_free(swnodes[i]->properties); + } + } + + return 0; +} + +static int initialize_ov05c10_swnode_props (struct amdisp_platform *p) +{ + struct software_node *sw_node; + int ret; + int i; + + if (strncmp(p->name, AMDISP_OV05C10_PLAT_NAME, + strlen(AMDISP_OV05C10_PLAT_NAME))) + return -EINVAL; + + /* Initialize platform specific props for each node */ + for (i = 0; i < p->max_num_swnodes; i++) { + sw_node = p->swnodes[i]; + + if (sw_node->properties) { + sw_node->properties = property_entries_dup(sw_node-Quoted 1 line
properties);
+ if (
IS_ERR(sw_node->properties)) { + ret =PTR_ERR(sw_node->properties); + gotoerror_release_node_props; + }
+ }
+ }drivers/platform/x86/amd/amd_isp4.c new file +9
-0+ + return 0; + +error_release_node_props: + release_amdisp_swnode_props(p->swnodes, p->max_num_swnodes); + return ret; +} + +static struct amdisp_platform *prepare_amdisp_platform(const struct
amdisp_platform*src)drivers/platform/x86/amd/amd_isp4.c new file +44
-0+{ + struct amdisp_platform *isp_ov05c10; + const struct software_node **sw_nodes; + const struct software_node *sw_node; + struct i2c_board_info *info; + int ret; + + isp_ov05c10 = kmemdup(src, sizeof(*isp_ov05c10), GFP_KERNEL); + if (!isp_ov05c10) + return ERR_PTR(-ENOMEM); + + ret = initialize_ov05c10_swnode_props(isp_ov05c10); + if (ret) + goto error_free_platform; + + info = &isp_ov05c10->board_info; + + sw_nodes = (const struct software_node **)src->swnodes; + ret = software_node_register_node_group(sw_nodes); + if (ret) + goto error_unregister_sw_node; + + sw_node = (const struct software_node *)src->swnodes[0]; + info->fwnode = software_node_fwnode(sw_node); + if (IS_ERR(info->fwnode)) { + ret = PTR_ERR(info->fwnode); + goto error_unregister_sw_node; + } + + return isp_ov05c10; + +error_unregister_sw_node: + software_node_unregister_node_group(sw_nodes); + +error_free_platform: + kfree(isp_ov05c10); + return ERR_PTR(ret); +} + +static int amd_isp_probe (struct platform_device *pdev) +{ + int ret; + + ov05c10_amdisp =
prepare_amdisp_platform(&amdisp_ov05c10_platform_config); + if (IS_ERR(ov05c10_amdisp)) {
+pr_err("failed to prepare amdisp platform fw node"); + returnPTR_ERR(ov05c10_amdisp);
+ }drivers/platform/x86/amd/amd_isp4.c new file +42
-0+ + /* + * Register notifier to instantiate i2c client when AMD ISP adapter + * is ready. + */ + ret = bus_register_notifier(&i2c_bus_type, &isp_i2c_nb); + if (ret) + goto error_free_platform; + + return ret; + +error_free_platform: + kfree(ov05c10_amdisp); + return ret; +} + +static void amd_isp_remove (struct platform_device *pdev) +{ + bus_unregister_notifier(&i2c_bus_type, &isp_i2c_nb); + i2c_unregister_device(ov05c10_amdisp->i2c_dev); + release_amdisp_swnode_props(ov05c10_amdisp->swnodes, + ov05c10_amdisp->max_num_swnodes); + software_node_unregister_node_group((const struct software_node **) + ov05c10_amdisp->swnodes); + kfree(ov05c10_amdisp); +} + +static struct platform_driver amd_isp_platform_driver = { + .driver = { + .name = AMD_ISP_PLAT_DRV_NAME, + .acpi_match_table = amdisp_sensor_ids, + }, + .probe = amd_isp_probe, + .remove = amd_isp_remove, +}; + +module_platform_driver (amd_isp_platform_driver); + +MODULE_AUTHOR ("Benjamin Chan <[email protected]>" ); +MODULE_AUTHOR ("Pratap Nirujogi <[email protected]>" ); +MODULE_DESCRIPTION ("AMD ISP4 Platform Driver" ); +MODULE_LICENSE ("GPL" );
Ilpo Järvinen
maintainerQuoted 108 lines · Pratap Nirujogi
ISP device specific configuration is not available in ACPI. Add swnode graph to configure the missing device properties for the OV05C10 camera device supported on amdisp platform.
Add support to create i2c-client dynamically when amdisp i2c adapter is available.
Signed-off-by Pratap Nirujogi <[email protected]>Signed-off-by Benjamin Chan <[email protected]>---
v2 -> v3:- Remodelled as ACPI driver to bind the device when matching acpi sensor device is detected. This eliminated the need for dmi checks for platform validation.
- Added software nodes to align with camera device-tree format to capture the camera device properties missing in the ACPI.
- Constructed swnode graph in the below format to successfully parse the endpoint node using
v4l2_fwnode_endpoint_alloc_parse().OMNI5C10 { refclk = 24MHz; ports { port@ { endpoint { bus-type = 4; data-lanes = <1 2>; link-frequencies = 925MHz; remote-endpoint = &ov05c10_refs; }; }; }; };- GPIO sensor lookup is moved out of this driver scope, it is taken care in isp driver module init.
- This platform driver is specific to AMD ISP4, hence renamed driver name as "amd-isp4".
drivers/platform/x86/amd/Kconfig | 11 + drivers/platform/x86/amd/Makefile | 1 + drivers/platform/x86/amd/amd_isp4.c | 354 ++++++++++++++++++++++++++++ 3 files changed, 366 insertions(+) create mode 100644 drivers/platform/x86/amd/amd_isp4.cdrivers/platform/x86/amd/Kconfig +11
-0@@ -32,3 +32,14 @@ config AMD_WBRF This mechanism will only be activated on platforms that advertise a need for it. + +config AMD_ISP_PLATFORM + bool "AMD platform with ISP4 that supports Camera sensor device" + depends on I2C && X86_64 && AMD_ISP4 + help + For AMD platform that support Image signal processor generation 4, it + is necessary to add platform specific camera sensor module board info + which includes the sensor driver device id and the i2c address. + + If you have a AMD platform that support ISP4 and with a sensor + connected to it, say Y heredrivers/platform/x86/amd/Makefile +1
-0@@ -10,3 +10,4 @@ obj-$(CONFIG_AMD_PMC) += pmc/ obj-$(CONFIG_AMD_HSMP) += hsmp/ obj-$(CONFIG_AMD_PMF) += pmf/ obj-$(CONFIG_AMD_WBRF) += wbrf.o +obj-$(CONFIG_AMD_ISP_PLATFORM) += amd_isp4.odrivers/platform/x86/amd/amd_isp4.c new file +26
-0@@ -0,0 +1,354 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* AMD ISP platform driver for sensor i2-client instantiation +* +* Copyright 2025 Advanced Micro Devices, Inc. +*/ + +#include <linux/acpi.h> +#include <linux/device/bus.h> +#include <linux/dmi.h> +#include <linux/gpio/machine.h> +#include <linux/init.h> +#include <linux/i2c.h> +#include <linux/kernel.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/property.h> +#include <linux/units.h> + +#define AMDISP_OV05C10_I2C_ADDR 0x10 +#define AMDISP_OV05C10_PLAT_NAME "amdisp_ov05c10_platform" +#define AMDISP_OV05C10_HID "OMNI5C10" +#define AMDISP_OV05C10_REMOTE_EP_NAME "ov05c10_isp_4_1_1" +#define AMD_ISP_PLAT_DRV_NAME "amd-isp4" +
drivers/platform/x86/amd/amd_isp4.c line 36
Quoted 10 lines
drivers/platform/x86/amd/amd_isp4.c new file +10
-0+/* +* AMD ISP platform definition to configure the device properites +* missing in the ACPI table. +*/ +struct amdisp_platform { +const char *name; +struct i2c_board_info board_info; +u8 i2c_addr; +struct i2c_client *i2c_dev; +u8 max_num_swnodes;
I'd put u8 next to each other to avoid having unnecessary gaps in the layout (I understand you put them in this order likely due to logical connection between the integer and pointer but having u8 sprinkled around here and there leaves holes into the layout).
Quoted 110 lines
drivers/platform/x86/amd/amd_isp4.c new file +110
-0+struct software_node **swnodes; +}; + +static struct amdisp_platform *ov05c10_amdisp; + +/* Top-level OV05C10 camera node property table */ +static const struct property_entry ov05c10_camera_props[]__initconst = { +PROPERTY_ENTRY_U32 ("refclk" ,24 *HZ_PER_MHZ ), + { } +}; + +/* Root AMD ISP OV05C10 camera node definition */ +static const struct software_node camera_node = { + .name =AMDISP_OV05C10_HID , + .properties = ov05c10_camera_props, +}; + +/* +* AMD ISP OV05C10 Ports node definition. No properties defined for +* ports node for OV05C10. +*/ +static const struct software_node ports = { + .name ="ports" , + .parent = &camera_node, +}; + +/* +* AMD ISP OV05C10 Port node definition. No properties defined for +* port node for OV05C10. +*/ +static const struct software_node port_node = { + .name ="port@" , + .parent = &ports, +}; + +/* +* Remote endpoint AMD ISP node definition. No properties defined for +* remote endpoint node for OV05C10. +*/ +static const struct software_node remote_ep_isp_node = { + .name =AMDISP_OV05C10_REMOTE_EP_NAME , +}; + +/* +* Remote endpoint reference for isp node included in the +* OV05C10 endpoint. +*/ +static const struct software_node_ref_args ov05c10_refs[]__initconst = { +SOFTWARE_NODE_REFERENCE (&remote_ep_isp_node), +}; + +/* OV05C supports one single link frequency */ +static const u64 ov05c10_link_freqs[]__initconst = { +925 *HZ_PER_MHZ , +}; + +/* OV05C supports only 2-lane configuration */ +static const u32 ov05c10_data_lanes[]__initconst = { +1 , +2 , +}; + +/* OV05C10 endpoint node properties table */ +static const struct property_entry ov05c10_endpoint_props[]__initconst = { +PROPERTY_ENTRY_U32 ("bus-type" ,4 ), +PROPERTY_ENTRY_U32_ARRAY_LEN ("data-lanes" , ov05c10_data_lanes, +ARRAY_SIZE (ov05c10_data_lanes)), +PROPERTY_ENTRY_U64_ARRAY_LEN ("link-frequencies" , ov05c10_link_freqs, +ARRAY_SIZE (ov05c10_link_freqs)), +PROPERTY_ENTRY_REF_ARRAY ("remote-endpoint" , ov05c10_refs), + { } +}; + +/* AMD ISP endpoint node definition */ +static const struct software_node endpoint_node = { + .name ="endpoint" , + .parent = &port_node, + .properties = ov05c10_endpoint_props, +}; + +/* +* AMD ISP swnode graph uses 5 nodes and also its relationship is +* fixed to align with the structure that v4l2 expects for successful +* endpoint fwnode parsing. +* +* It is only the node property_entries that will vary for each platform +* supporting different sensor modules. +*/ +#define NUM_SW_NODES 5 + +static const struct software_node *ov05c10_nodes[NUM_SW_NODES +1 ] = { + &camera_node, + &ports, + &port_node, + &endpoint_node, + &remote_ep_isp_node, +NULL +}; + +/* OV05C10 specific AMD ISP platform configuration */ +static const struct amdisp_platform amdisp_ov05c10_platform_config = { + .name =AMDISP_OV05C10_PLAT_NAME , + .board_info = { + .dev_name ="ov05c10" , +I2C_BOARD_INFO ("ov05c10" ,AMDISP_OV05C10_I2C_ADDR ), + }, + .i2c_addr =AMDISP_OV05C10_I2C_ADDR , + .max_num_swnodes =NUM_SW_NODES , + .swnodes = (struct software_node **)ov05c10_nodes, +};
drivers/platform/x86/amd/amd_isp4.c line 156
Quoted 10 lines
drivers/platform/x86/amd/amd_isp4.c new file +10
-0+ +static const struct acpi_device_id amdisp_sensor_ids[] = { + {AMDISP_OV05C10_HID }, + { } +}; +MODULE_DEVICE_TABLE (acpi, amdisp_sensor_ids); + +static bool is_isp_i2c_adapter (struct i2c_adapter *adap) +{ +return !strncmp (adap->owner->name,"i2c_designware_amdisp" ,48 );
Eh, where that magic 48 comes from??? Why do you even need str_n_cmp() variant here?
Quoted 10 lines
drivers/platform/x86/amd/amd_isp4.c new file +10
-0+} + +static void instantiate_isp_i2c_client (struct i2c_adapter *adap) +{ +struct i2c_board_info *info = &ov05c10_amdisp->board_info; +struct i2c_client *i2c_dev = ov05c10_amdisp->i2c_dev; + +if (i2c_dev) +return ; +
drivers/platform/x86/amd/amd_isp4.c line 176
Quoted 10 lines
drivers/platform/x86/amd/amd_isp4.c new file +10
-0+if (!info->addr) { +dev_err (&adap->dev,"invalid i2c_addr 0x%x detected\n" , + ov05c10_amdisp->i2c_addr); +return ; + } + + i2c_dev =i2c_new_client_device (adap, info); +if (IS_ERR (i2c_dev)) { +dev_err (&adap->dev,"error %ld registering isp i2c_client\n" , +PTR_ERR (i2c_dev));
Please use %pe.
Quoted 36 lines
drivers/platform/x86/amd/amd_isp4.c new file +36
-0+ i2c_dev =NULL ; + }else { +dev_dbg (&adap->dev,"registered amdisp i2c_client on address 0x%02x\n" , + info->addr); + } +i2c_put_adapter (adap); +} + +static int isp_i2c_bus_notify (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct device *dev = data; +struct i2c_client *client; +struct i2c_adapter *adap; +struct i2c_client *i2c_dev = ov05c10_amdisp->i2c_dev; + +switch (action) { +case BUS_NOTIFY_ADD_DEVICE : + adap =i2c_verify_adapter (dev); +if (!adap) +break ; +if (is_isp_i2c_adapter (adap)) +instantiate_isp_i2c_client (adap); +break ; +case BUS_NOTIFY_REMOVED_DEVICE : + client =i2c_verify_client (dev); +if (!client) +break ; +if (i2c_dev == client) { +dev_dbg (&client->adapter->dev,"amdisp i2c_client removed\n" ); + i2c_dev =NULL ; + } +break ; +default : +break ; + }
drivers/platform/x86/amd/amd_isp4.c line 222
Quoted 10 lines
drivers/platform/x86/amd/amd_isp4.c new file +10
-0+ +return NOTIFY_DONE ; +} + +static struct notifier_block isp_i2c_nb = { .notifier_call = isp_i2c_bus_notify }; + +static int release_amdisp_swnode_props (struct software_node **swnodes, +u8 num_swnodes) +{ +int i;
unsigned int
drivers/platform/x86/amd/amd_isp4.c line 226
Quoted 4 lines
drivers/platform/x86/amd/amd_isp4.c new file +4
-0+ +for (i =0 ; i < num_swnodes; i++) { +if (swnodes[i] && + !IS_ERR_OR_NULL (swnodes[i]->properties)) {
This fits to a sinle line and you can remove the braces too then.
drivers/platform/x86/amd/amd_isp4.c line 238
Quoted 12 lines
drivers/platform/x86/amd/amd_isp4.c new file +12
-0+property_entries_free (swnodes[i]->properties); + } + } + +return 0 ; +} + +static int initialize_ov05c10_swnode_props (struct amdisp_platform *p) +{ +struct software_node *sw_node; +int ret; +int i;
unsigned int, please move it before ret as it will be then longer than "int ret;"
drivers/platform/x86/amd/amd_isp4.c line 241
Quoted 3 lines
drivers/platform/x86/amd/amd_isp4.c new file +3
-0+ +if (strncmp (p->name,AMDISP_OV05C10_PLAT_NAME , +strlen (AMDISP_OV05C10_PLAT_NAME )))
Why you need str_n_cmp()?? AMDISP_OV05C10_PLAT_NAME is NUL terminated so strlen(AMDISP_OV05C10_PLAT_NAME) "stop point" is meaningless.
drivers/platform/x86/amd/amd_isp4.c line 244
Quoted 3 lines
drivers/platform/x86/amd/amd_isp4.c new file +3
-0+return -EINVAL ; + +/* Initialize platform specific props for each node */
This seems pretty unnecessary comment given the name of this function. I'd just drop it as it doesn't add much vlaue.
drivers/platform/x86/amd/amd_isp4.c line 248
Quoted 4 lines
drivers/platform/x86/amd/amd_isp4.c new file +4
-0+for (i =0 ; i < p->max_num_swnodes; i++) { + sw_node = p->swnodes[i]; + +if (sw_node->properties) {
Please reverse the logic and use continue.
Quoted 52 lines
drivers/platform/x86/amd/amd_isp4.c new file +52
-0+ sw_node->properties =property_entries_dup (sw_node->properties); +if (IS_ERR (sw_node->properties)) { + ret =PTR_ERR (sw_node->properties); + goto error_release_node_props; + } + } + } + +return 0 ; + +error_release_node_props: +release_amdisp_swnode_props (p->swnodes, p->max_num_swnodes); +return ret; +} + +static struct amdisp_platform *prepare_amdisp_platform (const struct amdisp_platform *src) +{ +struct amdisp_platform *isp_ov05c10; +const struct software_node **sw_nodes; +const struct software_node *sw_node; +struct i2c_board_info *info; +int ret; + + isp_ov05c10 =kmemdup (src,sizeof (*isp_ov05c10),GFP_KERNEL ); +if (!isp_ov05c10) +return ERR_PTR (-ENOMEM ); + + ret =initialize_ov05c10_swnode_props (isp_ov05c10); +if (ret) + goto error_free_platform; + + info = &isp_ov05c10->board_info; + + sw_nodes = (const struct software_node **)src->swnodes; + ret =software_node_register_node_group (sw_nodes); +if (ret) + goto error_unregister_sw_node; + + sw_node = (const struct software_node *)src->swnodes[0 ]; + info->fwnode =software_node_fwnode (sw_node); +if (IS_ERR (info->fwnode)) { + ret =PTR_ERR (info->fwnode); + goto error_unregister_sw_node; + } + +return isp_ov05c10; + +error_unregister_sw_node: +software_node_unregister_node_group (sw_nodes); + +error_free_platform: +kfree (isp_ov05c10);
drivers/platform/x86/amd/amd_isp4.c line 310
Quoted 10 lines
drivers/platform/x86/amd/amd_isp4.c new file +10
-0+return ERR_PTR (ret); +} + +static int amd_isp_probe (struct platform_device *pdev) +{ +int ret; + + ov05c10_amdisp =prepare_amdisp_platform (&amdisp_ov05c10_platform_config); +if (IS_ERR (ov05c10_amdisp)) { +pr_err ("failed to prepare amdisp platform fw node" );
Missing \n
dev_err_probe()
drivers/platform/x86/amd/amd_isp4.c line 316
Quoted 6 lines
drivers/platform/x86/amd/amd_isp4.c new file +6
-0+return PTR_ERR (ov05c10_amdisp); + } + +/* +* Register notifier to instantiate i2c client when AMD ISP adapter +* is ready.
How is "when AMD ISP adapter is ready" related to what the code does below this comment?? If it only refers to "once we've setup everything", that's what probe is doing in general so why comment such obvious expectation. The first part of the comment can be read from the code below so I think this entire comment is useless.
drivers/platform/x86/amd/amd_isp4.c line 325
Quoted 9 lines
drivers/platform/x86/amd/amd_isp4.c new file +9
-0+*/ + ret =bus_register_notifier (&i2c_bus_type, &isp_i2c_nb); +if (ret) + goto error_free_platform; + +return ret; + +error_free_platform: +kfree (ov05c10_amdisp);
Is this really all you have to rollback??? It seems that prepare_amdisp_platform() does more rollback itself if it fails in the middle (and so does amd_isp_remove) so why those same rollbacks do not need to be done here?
drivers/platform/x86/amd/amd_isp4.c line 332
Quoted 7 lines
drivers/platform/x86/amd/amd_isp4.c new file +7
-0+return ret; +} + +static void amd_isp_remove (struct platform_device *pdev) +{ +bus_unregister_notifier (&i2c_bus_type, &isp_i2c_nb); +i2c_unregister_device (ov05c10_amdisp->i2c_dev);
I've my reservations about this when it comes to things being properly synchronized.
Quoted 23 lines
drivers/platform/x86/amd/amd_isp4.c new file +22
-0+release_amdisp_swnode_props (ov05c10_amdisp->swnodes, + ov05c10_amdisp->max_num_swnodes); +software_node_unregister_node_group ((const struct software_node **) + ov05c10_amdisp->swnodes); +kfree (ov05c10_amdisp); +} + +static struct platform_driver amd_isp_platform_driver = { + .driver = { + .name =AMD_ISP_PLAT_DRV_NAME , + .acpi_match_table = amdisp_sensor_ids, + }, + .probe = amd_isp_probe, + .remove = amd_isp_remove, +}; + +module_platform_driver (amd_isp_platform_driver); + +MODULE_AUTHOR ("Benjamin Chan <[email protected]>" ); +MODULE_AUTHOR ("Pratap Nirujogi <[email protected]>" ); +MODULE_DESCRIPTION ("AMD ISP4 Platform Driver" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
i.
Hi Ilpo,
Thanks for the review.
Thanks,
Pratap
Quoted 120 lines · Ilpo Järvinen
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 115 lines · Pratap Nirujogi
ISP device specific configuration is not available in ACPI. Add swnode graph to configure the missing device properties for the OV05C10 camera device supported on amdisp platform.
Add support to create i2c-client dynamically when amdisp i2c adapter is available.
Signed-off-by Pratap Nirujogi <[email protected]>Signed-off-by Benjamin Chan <[email protected]>---
v2 -> v3:- Remodelled as ACPI driver to bind the device when matching acpi sensor device is detected. This eliminated the need for dmi checks for platform validation.
- Added software nodes to align with camera device-tree format to capture the camera device properties missing in the ACPI.
- Constructed swnode graph in the below format to successfully parse the endpoint node using
v4l2_fwnode_endpoint_alloc_parse().OMNI5C10 { refclk = 24MHz; ports { port@ { endpoint { bus-type = 4; data-lanes = <1 2>; link-frequencies = 925MHz; remote-endpoint = &ov05c10_refs; }; }; }; };- GPIO sensor lookup is moved out of this driver scope, it is taken care in isp driver module init.
- This platform driver is specific to AMD ISP4, hence renamed driver name as "amd-isp4".
drivers/platform/x86/amd/Kconfig | 11 + drivers/platform/x86/amd/Makefile | 1 + drivers/platform/x86/amd/amd_isp4.c | 354 ++++++++++++++++++++++++++++ 3 files changed, 366 insertions(+)create mode 100644
drivers/platform/x86/amd/amd_isp4.cdrivers/platform/x86/amd/Kconfig +11
-0@@ -32,3 +32,14 @@ config AMD_WBRF This mechanism will only be activated on platforms that advertise a need for it. + +config AMD_ISP_PLATFORM + bool "AMD platform with ISP4 that supports Camera sensor device" + depends on I2C && X86_64 && AMD_ISP4 + help + For AMD platform that support Image signal processor generation 4, it + is necessary to add platform specific camera sensor module board info + which includes the sensor driver device id and the i2c address. + + If you have a AMD platform that support ISP4 and with a sensor + connected to it, say Y heredrivers/platform/x86/amd/Makefile +1
-0@@ -10,3 +10,4 @@ obj-$(CONFIG_AMD_PMC) += pmc/ obj-$(CONFIG_AMD_HSMP) += hsmp/ obj-$(CONFIG_AMD_PMF) += pmf/ obj-$(CONFIG_AMD_WBRF) += wbrf.o +obj-$(CONFIG_AMD_ISP_PLATFORM) += amd_isp4.odrivers/platform/x86/amd/amd_isp4.c new file +33
-0@@ -0,0 +1,354 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* AMD ISP platform driver for sensor i2-client instantiation +* +* Copyright 2025 Advanced Micro Devices, Inc. +*/ + +#include <linux/acpi.h> +#include <linux/device/bus.h> +#include <linux/dmi.h> +#include <linux/gpio/machine.h> +#include <linux/init.h> +#include <linux/i2c.h> +#include <linux/kernel.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/property.h> +#include <linux/units.h> + +#define AMDISP_OV05C10_I2C_ADDR 0x10 +#define AMDISP_OV05C10_PLAT_NAME "amdisp_ov05c10_platform" +#define AMDISP_OV05C10_HID "OMNI5C10" +#define AMDISP_OV05C10_REMOTE_EP_NAME "ov05c10_isp_4_1_1" +#define AMD_ISP_PLAT_DRV_NAME "amd-isp4" + +/* +* AMD ISP platform definition to configure the device properites +* missing in the ACPI table. +*/ +struct amdisp_platform { +const char *name; +struct i2c_board_info board_info;
Quoted 9 lines
drivers/platform/x86/amd/amd_isp4.c line 36
Quoted 3 lines
drivers/platform/x86/amd/amd_isp4.c new file +3
-0+u8 i2c_addr; +struct i2c_client *i2c_dev; +u8 max_num_swnodes;I'd put u8 next to each other to avoid having unnecessary gaps in the layout (I understand you put them in this order likely due to logical connection between the integer and pointer but having u8 sprinkled around here and there leaves holes into the layout).
thanks, will update the order of variables to avoid holes in the next V4 submission.
Quoted 115 lines
Quoted 115 lines
drivers/platform/x86/amd/amd_isp4.c new file +115
-0+struct software_node **swnodes; +}; + +static struct amdisp_platform *ov05c10_amdisp; + +/* Top-level OV05C10 camera node property table */ +static const struct property_entry ov05c10_camera_props[]__initconst = { +PROPERTY_ENTRY_U32 ("refclk" ,24 *HZ_PER_MHZ ), + { } +}; + +/* Root AMD ISP OV05C10 camera node definition */ +static const struct software_node camera_node = { + .name =AMDISP_OV05C10_HID , + .properties = ov05c10_camera_props, +}; + +/* +* AMD ISP OV05C10 Ports node definition. No properties defined for +* ports node for OV05C10. +*/ +static const struct software_node ports = { + .name ="ports" , + .parent = &camera_node, +}; + +/* +* AMD ISP OV05C10 Port node definition. No properties defined for +* port node for OV05C10. +*/ +static const struct software_node port_node = { + .name ="port@" , + .parent = &ports, +}; + +/* +* Remote endpoint AMD ISP node definition. No properties defined for +* remote endpoint node for OV05C10. +*/ +static const struct software_node remote_ep_isp_node = { + .name =AMDISP_OV05C10_REMOTE_EP_NAME , +}; + +/* +* Remote endpoint reference for isp node included in the +* OV05C10 endpoint. +*/ +static const struct software_node_ref_args ov05c10_refs[]__initconst = { +SOFTWARE_NODE_REFERENCE (&remote_ep_isp_node), +}; + +/* OV05C supports one single link frequency */ +static const u64 ov05c10_link_freqs[]__initconst = { +925 *HZ_PER_MHZ , +}; + +/* OV05C supports only 2-lane configuration */ +static const u32 ov05c10_data_lanes[]__initconst = { +1 , +2 , +}; + +/* OV05C10 endpoint node properties table */ +static const struct property_entry ov05c10_endpoint_props[]__initconst = { +PROPERTY_ENTRY_U32 ("bus-type" ,4 ), +PROPERTY_ENTRY_U32_ARRAY_LEN ("data-lanes" , ov05c10_data_lanes, +ARRAY_SIZE (ov05c10_data_lanes)), +PROPERTY_ENTRY_U64_ARRAY_LEN ("link-frequencies" , ov05c10_link_freqs, +ARRAY_SIZE (ov05c10_link_freqs)), +PROPERTY_ENTRY_REF_ARRAY ("remote-endpoint" , ov05c10_refs), + { } +}; + +/* AMD ISP endpoint node definition */ +static const struct software_node endpoint_node = { + .name ="endpoint" , + .parent = &port_node, + .properties = ov05c10_endpoint_props, +}; + +/* +* AMD ISP swnode graph uses 5 nodes and also its relationship is +* fixed to align with the structure that v4l2 expects for successful +* endpoint fwnode parsing. +* +* It is only the node property_entries that will vary for each platform +* supporting different sensor modules. +*/ +#define NUM_SW_NODES 5 + +static const struct software_node *ov05c10_nodes[NUM_SW_NODES +1 ] = { + &camera_node, + &ports, + &port_node, + &endpoint_node, + &remote_ep_isp_node, +NULL +}; + +/* OV05C10 specific AMD ISP platform configuration */ +static const struct amdisp_platform amdisp_ov05c10_platform_config = { + .name =AMDISP_OV05C10_PLAT_NAME , + .board_info = { + .dev_name ="ov05c10" , +I2C_BOARD_INFO ("ov05c10" ,AMDISP_OV05C10_I2C_ADDR ), + }, + .i2c_addr =AMDISP_OV05C10_I2C_ADDR , + .max_num_swnodes =NUM_SW_NODES , + .swnodes = (struct software_node **)ov05c10_nodes, +}; + +static const struct acpi_device_id amdisp_sensor_ids[] = { + {AMDISP_OV05C10_HID }, + { } +};
Quoted 8 lines
drivers/platform/x86/amd/amd_isp4.c line 156
Quoted 5 lines
drivers/platform/x86/amd/amd_isp4.c new file +5
-0+MODULE_DEVICE_TABLE (acpi, amdisp_sensor_ids); + +static bool is_isp_i2c_adapter (struct i2c_adapter *adap) +{ +return !strncmp (adap->owner->name,"i2c_designware_amdisp" ,48 );Eh, where that magic 48 comes from??? Why do you even need
str_n_cmp()variant here?
My bad I missed to update the max count. Initially I was using adap->name for checking, which is fixed to 48 chars. But later moved to adap->owner->name and missed to update the count.
https://github.com/torvalds/linux/blob/master/include/linux/i2c.h#L754
Ideally str_n_cmp() is not required in this case, strcmp is safe to use as both strings are known to be NULL terminated.
Will replace str_n_cmp() with strcmp() in V4.
Quoted 15 lines
Quoted 15 lines
drivers/platform/x86/amd/amd_isp4.c new file +14
-0+} + +static void instantiate_isp_i2c_client (struct i2c_adapter *adap) +{ +struct i2c_board_info *info = &ov05c10_amdisp->board_info; +struct i2c_client *i2c_dev = ov05c10_amdisp->i2c_dev; + +if (i2c_dev) +return ; + +if (!info->addr) { +dev_err (&adap->dev,"invalid i2c_addr 0x%x detected\n" , + ov05c10_amdisp->i2c_addr); +return ;
Quoted 9 lines
drivers/platform/x86/amd/amd_isp4.c line 176
Quoted 6 lines
drivers/platform/x86/amd/amd_isp4.c new file +6
-0+ } + + i2c_dev =i2c_new_client_device (adap, info); +if (IS_ERR (i2c_dev)) { +dev_err (&adap->dev,"error %ld registering isp i2c_client\n" , +PTR_ERR (i2c_dev));Please use %pe.
sure, will use %pe in V4.
Quoted 40 lines
Quoted 40 lines
drivers/platform/x86/amd/amd_isp4.c new file +40
-0+ i2c_dev =NULL ; + }else { +dev_dbg (&adap->dev,"registered amdisp i2c_client on address 0x%02x\n" , + info->addr); + } +i2c_put_adapter (adap); +} + +static int isp_i2c_bus_notify (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct device *dev = data; +struct i2c_client *client; +struct i2c_adapter *adap; +struct i2c_client *i2c_dev = ov05c10_amdisp->i2c_dev; + +switch (action) { +case BUS_NOTIFY_ADD_DEVICE : + adap =i2c_verify_adapter (dev); +if (!adap) +break ; +if (is_isp_i2c_adapter (adap)) +instantiate_isp_i2c_client (adap); +break ; +case BUS_NOTIFY_REMOVED_DEVICE : + client =i2c_verify_client (dev); +if (!client) +break ; +if (i2c_dev == client) { +dev_dbg (&client->adapter->dev,"amdisp i2c_client removed\n" ); + i2c_dev =NULL ; + } +break ; +default : +break ; + } + +return NOTIFY_DONE ; +} +
Quoted 9 lines
drivers/platform/x86/amd/amd_isp4.c line 222
Quoted 6 lines
drivers/platform/x86/amd/amd_isp4.c new file +6
-0+static struct notifier_block isp_i2c_nb = { .notifier_call = isp_i2c_bus_notify }; + +static int release_amdisp_swnode_props (struct software_node **swnodes, +u8 num_swnodes) +{ +int i;unsigned int
sure, will update in V4.
Quoted 7 lines
drivers/platform/x86/amd/amd_isp4.c line 226
Quoted 4 lines
drivers/platform/x86/amd/amd_isp4.c new file +4
-0+ +for (i =0 ; i < num_swnodes; i++) { +if (swnodes[i] && + !IS_ERR_OR_NULL (swnodes[i]->properties)) {This fits to a sinle line and you can remove the braces too then.
Quoted 16 lines
drivers/platform/x86/amd/amd_isp4.c line 238
Quoted 12 lines
drivers/platform/x86/amd/amd_isp4.c new file +12
-0+property_entries_free (swnodes[i]->properties); + } + } + +return 0 ; +} + +static int initialize_ov05c10_swnode_props (struct amdisp_platform *p) +{ +struct software_node *sw_node; +int ret; +int i;unsigned int, please move it before ret as it will be then longer than "int ret;"
sure, will address this in V4.
Quoted 7 lines
drivers/platform/x86/amd/amd_isp4.c line 241
Quoted 3 lines
drivers/platform/x86/amd/amd_isp4.c new file +3
-0+ +if (strncmp (p->name,AMDISP_OV05C10_PLAT_NAME , +strlen (AMDISP_OV05C10_PLAT_NAME )))Why you need
str_n_cmp()??AMDISP_OV05C10_PLAT_NAMEis NUL terminated sostrlen(AMDISP_OV05C10_PLAT_NAME)"stop point" is meaningless.
yeah, I agree, str_n_cmp() is not required, will use strcmp() in V4.
Quoted 7 lines
drivers/platform/x86/amd/amd_isp4.c line 244
Quoted 3 lines
drivers/platform/x86/amd/amd_isp4.c new file +3
-0+return -EINVAL ; + +/* Initialize platform specific props for each node */ This seems pretty unnecessary comment given the name of this function. I'd just drop it as it doesn't add much vlaue.
Quoted 7 lines
drivers/platform/x86/amd/amd_isp4.c line 248
Quoted 4 lines
drivers/platform/x86/amd/amd_isp4.c new file +4
-0+for (i =0 ; i < p->max_num_swnodes; i++) { + sw_node = p->swnodes[i]; + +if (sw_node->properties) {Please reverse the logic and use continue.
sure, will update using if(!sw_node->properties) in V4.
Quoted 65 lines
Quoted 52 lines
drivers/platform/x86/amd/amd_isp4.c new file +52
-0+ sw_node->properties =property_entries_dup (sw_node->properties); +if (IS_ERR (sw_node->properties)) { + ret =PTR_ERR (sw_node->properties); + goto error_release_node_props; + } + } + } + +return 0 ; + +error_release_node_props: +release_amdisp_swnode_props (p->swnodes, p->max_num_swnodes); +return ret; +} + +static struct amdisp_platform *prepare_amdisp_platform (const struct amdisp_platform *src) +{ +struct amdisp_platform *isp_ov05c10; +const struct software_node **sw_nodes; +const struct software_node *sw_node; +struct i2c_board_info *info; +int ret; + + isp_ov05c10 =kmemdup (src,sizeof (*isp_ov05c10),GFP_KERNEL ); +if (!isp_ov05c10) +return ERR_PTR (-ENOMEM ); + + ret =initialize_ov05c10_swnode_props (isp_ov05c10); +if (ret) + goto error_free_platform; + + info = &isp_ov05c10->board_info; + + sw_nodes = (const struct software_node **)src->swnodes; + ret =software_node_register_node_group (sw_nodes); +if (ret) + goto error_unregister_sw_node; + + sw_node = (const struct software_node *)src->swnodes[0 ]; + info->fwnode =software_node_fwnode (sw_node); +if (IS_ERR (info->fwnode)) { + ret =PTR_ERR (info->fwnode); + goto error_unregister_sw_node; + } + +return isp_ov05c10; + +error_unregister_sw_node: +software_node_unregister_node_group (sw_nodes); + +error_free_platform: +kfree (isp_ov05c10);drivers/platform/x86/amd/amd_isp4.c line 310
Quoted 10 lines
drivers/platform/x86/amd/amd_isp4.c new file +10
-0+return ERR_PTR (ret); +} + +static int amd_isp_probe (struct platform_device *pdev) +{ +int ret; + + ov05c10_amdisp =prepare_amdisp_platform (&amdisp_ov05c10_platform_config); +if (IS_ERR (ov05c10_amdisp)) { +pr_err ("failed to prepare amdisp platform fw node" );Missing \n
Quoted 2 lines
dev_err_probe()
sure, will take care of both \n and dev_err_probe() suggestions in V4.
Quoted 13 lines
drivers/platform/x86/amd/amd_isp4.c line 316
Quoted 6 lines
drivers/platform/x86/amd/amd_isp4.c new file +6
-0+return PTR_ERR (ov05c10_amdisp); + } + +/* +* Register notifier to instantiate i2c client when AMD ISP adapter +* is ready. How is "when AMD ISP adapter is ready" related to what the code does below this comment?? If it only refers to "once we've setup everything", that's what probe is doing in general so why comment such obvious expectation. The first part of the comment can be read from the code below so I think this entire comment is useless.
Quoted 15 lines
drivers/platform/x86/amd/amd_isp4.c line 325
Quoted 9 lines
drivers/platform/x86/amd/amd_isp4.c new file +9
-0+*/ + ret =bus_register_notifier (&i2c_bus_type, &isp_i2c_nb); +if (ret) + goto error_free_platform; + +return ret; + +error_free_platform: +kfree (ov05c10_amdisp);Is this really all you have to rollback??? It seems that
prepare_amdisp_platform()does more rollback itself if it fails in the middle (and so doesamd_isp_remove) so why those same rollbacks do not need to be done here?
This rollback is added to free the ov05c10_amdisp handle which is allocated in prepare_amdisp_platform().
Quoted 11 lines
drivers/platform/x86/amd/amd_isp4.c line 332
Quoted 7 lines
drivers/platform/x86/amd/amd_isp4.c new file +7
-0+return ret; +} + +static void amd_isp_remove (struct platform_device *pdev) +{ +bus_unregister_notifier (&i2c_bus_type, &isp_i2c_nb); +i2c_unregister_device (ov05c10_amdisp->i2c_dev);I've my reservations about this when it comes to things being properly synchronized.
I need check if i2c framework has any protections. Any recommedations or references please on how to gurantee the synchronization for safe i2c_unregister_device().
Quoted 27 lines
Quoted 13 lines
drivers/platform/x86/amd/amd_isp4.c new file +12
-0+release_amdisp_swnode_props (ov05c10_amdisp->swnodes, + ov05c10_amdisp->max_num_swnodes); +software_node_unregister_node_group ((const struct software_node **) + ov05c10_amdisp->swnodes); +kfree (ov05c10_amdisp); +} + +static struct platform_driver amd_isp_platform_driver = { + .driver = { + .name =AMD_ISP_PLAT_DRV_NAME , + .acpi_match_table = amdisp_sensor_ids, + },drivers/platform/x86/amd/amd_isp4.c line 354
Quoted 10 lines
drivers/platform/x86/amd/amd_isp4.c new file +10
-0+ .probe = amd_isp_probe, + .remove = amd_isp_remove, +}; + +module_platform_driver (amd_isp_platform_driver); + +MODULE_AUTHOR ("Benjamin Chan <[email protected]>" ); +MODULE_AUTHOR ("Pratap Nirujogi <[email protected]>" ); +MODULE_DESCRIPTION ("AMD ISP4 Platform Driver" ); +MODULE_LICENSE ("GPL" );--
i.