From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F341E227599; Thu, 17 Apr 2025 09:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744882187; cv=none; b=FD3PTuUey99IL7NrVKui2RXxhSCPGVthACOs63GjoQTOySYYuqqaWcmtkbq5CldqeJrhUxmEi+om3DJ9htFeV38lzh8W5hp2f03nWz7YevP+IPGWnVTm5gPR5Za/PFLGaxZazzdttI48fX3N50V3FNPGnN9Oov2H60TKWowvazM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744882187; c=relaxed/simple; bh=jKpJba4dEPM6Wq97cZgAQa33L1aL5jzdDWrPeujLEZg=; h=From:Date:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=JnxlZE8PjngkJ5QN2GaSLTDnCSb3VJEqT1FZqaSMZaZSFO/q62kY0de0IQULRjSinAsd70u+9AWKDtDQHnCVrcXEb9pp/Jn2sU3h6DJApItbGpdtm4E1dZuFbKouBi755fDFXdFbTv0lIEkpUNuPSEojviYcRTo3olNeKIXl770= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=F++yPZjN; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="F++yPZjN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744882186; x=1776418186; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=jKpJba4dEPM6Wq97cZgAQa33L1aL5jzdDWrPeujLEZg=; b=F++yPZjNVzBzgSMR6EiA+SYL8+hSZZj12Asy+nvQo4RmaFDMMgXyYypA ZFMbWZZBp+RAqiuAld98zN9wz0E0N3h1jrgP0HD5Rh3Vd+aFBj0rRqeqm 9DLjH7cBSuA5mo7n40ebbAXZVCancWQiHXiUyuRn7Qew91ZeOH3+23H/5 ia6ZCk3JfFL/fQ5dgxnUraQj1dIrA3Ppi6dXJXKOXrzZt0sGcJXsOVR41 xKpJEm3VyVbsNeJTLI2HAWXTD0G1ihloiiJmsMC1ZNydvaHIAB5MIOMb6 Rc5AJdw/Qgr0lsIWUbvcCaaCB06fnSi+bgntIUcEC5hC39AkZvnht6xHp A==; X-CSE-ConnectionGUID: YDviK5GQTFS3DNdwUxiMPg== X-CSE-MsgGUID: z+hK1wHsSDu/lUAf7tcrGw== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="57831110" X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="57831110" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2025 02:29:45 -0700 X-CSE-ConnectionGUID: xTYKNgPjQ5SsSYxaGixWdw== X-CSE-MsgGUID: w2bZW0I/ScupLNAe0wVdwA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="130738936" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.144]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2025 02:29:40 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Thu, 17 Apr 2025 12:29:37 +0300 (EEST) To: Pratap Nirujogi cc: Hans de Goede , W_Armin@gmx.de, mario.limonciello@amd.com, platform-driver-x86@vger.kernel.org, LKML , benjamin.chan@amd.com, bin.du@amd.com, gjorgji.rosikopulos@amd.com, king.li@amd.com, dantony@amd.com Subject: Re: [PATCH v6] platform/x86: Add AMD ISP platform config for OV05C10 In-Reply-To: <20250416191411.1482060-1-pratap.nirujogi@amd.com> Message-ID: <1ae7245f-54e3-8fef-db0a-43479ed514b3@linux.intel.com> References: <20250416191411.1482060-1-pratap.nirujogi@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Wed, 16 Apr 2025, Pratap Nirujogi wrote: > 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. > > Co-developed-by: Benjamin Chan > Signed-off-by: Benjamin Chan > Signed-off-by: Pratap Nirujogi > --- > Changes v5 -> v6: > > * Cleanup header files > * Avoid unnecessary casts > * Fix coding error with software_node_unregister_node_group() > * Use i2c_client_has_driver() to validate i2c client handle > * Address other cosmetic errors > > drivers/platform/x86/amd/Kconfig | 11 ++ > drivers/platform/x86/amd/Makefile | 1 + > drivers/platform/x86/amd/amd_isp4.c | 278 ++++++++++++++++++++++++++++ > 3 files changed, 290 insertions(+) > create mode 100644 drivers/platform/x86/amd/amd_isp4.c > > diff --git a/drivers/platform/x86/amd/Kconfig b/drivers/platform/x86/amd/Kconfig > index c3e086ea64fc..ec755b5fc93c 100644 > --- a/drivers/platform/x86/amd/Kconfig > +++ b/drivers/platform/x86/amd/Kconfig > @@ -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 > + tristate "AMD ISP4 platform driver" > + depends on I2C && X86_64 && ACPI && AMD_ISP4 > + help > + Platform driver for AMD platforms containing image signal processor > + gen 4. Provides camera sensor module board information to allow > + sensor and V4L drivers to work properly. > + > + This driver can also be built as a module. If so, the module > + will be called amd_isp4. > diff --git a/drivers/platform/x86/amd/Makefile b/drivers/platform/x86/amd/Makefile > index c6c40bdcbded..b0e284b5d497 100644 > --- a/drivers/platform/x86/amd/Makefile > +++ b/drivers/platform/x86/amd/Makefile > @@ -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 > diff --git a/drivers/platform/x86/amd/amd_isp4.c b/drivers/platform/x86/amd/amd_isp4.c > new file mode 100644 > index 000000000000..9d1abbcc915f > --- /dev/null > +++ b/drivers/platform/x86/amd/amd_isp4.c > @@ -0,0 +1,278 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * AMD ISP platform driver for sensor i2-client instantiation > + * > + * Copyright 2025 Advanced Micro Devices, Inc. > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +#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 properties > + * missing in the ACPI table. > + */ > +struct amdisp_platform { > + const char *name; > + u8 i2c_addr; > + u8 max_num_swnodes; > + struct i2c_board_info board_info; > + struct notifier_block i2c_nb; > + struct i2c_client *i2c_dev; > + const struct software_node **swnodes; > +}; > + > +/* Top-level OV05C10 camera node property table */ > +static const struct property_entry ov05c10_camera_props[] = { > + PROPERTY_ENTRY_U32("clock-frequency", 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[] = { > + SOFTWARE_NODE_REFERENCE(&remote_ep_isp_node), > +}; > + > +/* OV05C supports one single link frequency */ > +static const u64 ov05c10_link_freqs[] = { > + 925 * HZ_PER_MHZ, > +}; > + > +/* OV05C supports only 2-lane configuration */ > +static const u32 ov05c10_data_lanes[] = { > + 1, > + 2, > +}; > + > +/* OV05C10 endpoint node properties table */ > +static const struct property_entry ov05c10_endpoint_props[] = { > + 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 = ov05c10_nodes, > +}; > + > +static const struct acpi_device_id amdisp_sensor_ids[] = { > + { AMDISP_OV05C10_HID }, > + { } > +}; > +MODULE_DEVICE_TABLE(acpi, amdisp_sensor_ids); > + > +static inline bool is_isp_i2c_adapter(struct i2c_adapter *adap) > +{ > + return !strcmp(adap->owner->name, "i2c_designware_amdisp"); > +} > + > +static void instantiate_isp_i2c_client(struct amdisp_platform *ov05c10, struct i2c_adapter *adap) > +{ > + struct i2c_board_info *info = &ov05c10->board_info; > + struct i2c_client *i2c_dev; > + > + if (ov05c10->i2c_dev) > + return; > + > + if (!info->addr) { > + dev_err(&adap->dev, "invalid i2c_addr 0x%x detected\n", ov05c10->i2c_addr); > + return; > + } > + > + i2c_dev = i2c_new_client_device(adap, info); > + if (!i2c_client_has_driver(i2c_dev)) { > + dev_err(&adap->dev, "error %pe registering isp i2c_client\n", i2c_dev); > + return; > + } > + ov05c10->i2c_dev = i2c_dev; > +} > + > +static int isp_i2c_bus_notify(struct notifier_block *nb, > + unsigned long action, void *data) > +{ > + struct amdisp_platform *ov05c10 = container_of(nb, struct amdisp_platform, i2c_nb); > + struct device *dev = data; > + struct i2c_client *client; > + struct i2c_adapter *adap; > + > + 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(ov05c10, adap); > + break; > + case BUS_NOTIFY_REMOVED_DEVICE: > + client = i2c_verify_client(dev); > + if (!client) > + break; > + if (ov05c10->i2c_dev == client) { > + dev_dbg(&client->adapter->dev, "amdisp i2c_client removed\n"); > + ov05c10->i2c_dev = NULL; > + } > + break; > + default: > + break; > + } > + > + return NOTIFY_DONE; > +} > + > +static struct amdisp_platform *prepare_amdisp_platform(const struct amdisp_platform *src) > +{ > + struct amdisp_platform *isp_ov05c10; > + const struct software_node **sw_nodes; > + struct i2c_board_info *info; > + int ret; > + > + isp_ov05c10 = kmemdup(src, sizeof(*isp_ov05c10), GFP_KERNEL); > + if (!isp_ov05c10) > + return ERR_PTR(-ENOMEM); > + > + info = &isp_ov05c10->board_info; > + > + sw_nodes = (const struct software_node **)src->swnodes; Did you forget to remove this cast? -- i. > + ret = software_node_register_node_group(sw_nodes); > + if (ret) > + goto error_free_platform; > + > + info->swnode = src->swnodes[0]; > + > + return isp_ov05c10; > + > +error_free_platform: > + kfree(isp_ov05c10); > + return ERR_PTR(ret); > +} > + > +static int amd_isp_probe(struct platform_device *pdev) > +{ > + struct amdisp_platform *ov05c10; > + int ret; > + > + ov05c10 = prepare_amdisp_platform(&amdisp_ov05c10_platform_config); > + if (IS_ERR(ov05c10)) > + return dev_err_probe(&pdev->dev, PTR_ERR(ov05c10), > + "failed to prepare AMD ISP platform fwnode\n"); > + > + ov05c10->i2c_nb.notifier_call = isp_i2c_bus_notify; > + ret = bus_register_notifier(&i2c_bus_type, &ov05c10->i2c_nb); > + if (ret) > + goto error_free_platform; > + > + platform_set_drvdata(pdev, ov05c10); > + return 0; > + > +error_free_platform: > + kfree(ov05c10); > + return ret; > +} > + > +static void amd_isp_remove(struct platform_device *pdev) > +{ > + struct amdisp_platform *ov05c10 = platform_get_drvdata(pdev); > + > + bus_unregister_notifier(&i2c_bus_type, &ov05c10->i2c_nb); > + i2c_unregister_device(ov05c10->i2c_dev); > + software_node_unregister_node_group(ov05c10->swnodes); > + kfree(ov05c10); > +} > + > +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 "); > +MODULE_AUTHOR("Pratap Nirujogi "); > +MODULE_DESCRIPTION("AMD ISP4 Platform Driver"); > +MODULE_LICENSE("GPL"); >