From patchwork Mon Feb 13 02:23:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Wentong" X-Patchwork-Id: 13137672 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85CADC64EC7 for ; Mon, 13 Feb 2023 02:21:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229770AbjBMCVl (ORCPT ); Sun, 12 Feb 2023 21:21:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbjBMCVi (ORCPT ); Sun, 12 Feb 2023 21:21:38 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E5E2FF20; Sun, 12 Feb 2023 18:21:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676254896; x=1707790896; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KnoS9p4eIAalvVPZV4jeKXSqw8vkjgt000lCjCdd5kc=; b=GdhzbqOCCLOXwL7tQ0QkVNn662han9EOwFqhetSVaISiIo1CA3z/m+Hz aHUsZh6DyzFfJemyPHpfqwaeRcW4NyNxciFgc4Hy7T5OKiEugkDtPeXn/ 1VZ70EYdKIs4lbsqeEwMbZI2AVV/LDfLpBUCFcPxpPA5jeRwnfesJHDJl AWgG9uflpuGQ7H5aGJK4Sy2eGumujYZMzWKgcxDOBQ1+wdQifuQJ+IC89 eKbAH4UvEa8vN/smqlTLSPuK3FEymJpgndKqLZlSxDuc3ZlgLHrE5WL3i TI0B6wJtuUT0Hn/iQod3qn0uXXOSA/Jm3Amt7SVEPqnj/t4/l1fpXrB2H w==; X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="310424827" X-IronPort-AV: E=Sophos;i="5.97,291,1669104000"; d="scan'208";a="310424827" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2023 18:21:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="701103140" X-IronPort-AV: E=Sophos;i="5.97,291,1669104000"; d="scan'208";a="701103140" Received: from wentongw-hp-z228-microtower-workstation.sh.intel.com ([10.239.153.109]) by orsmga001.jf.intel.com with ESMTP; 12 Feb 2023 18:21:32 -0800 From: Wentong Wu To: mchehab@kernel.org, sakari.ailus@linux.intel.com, linux-media@vger.kernel.org Cc: srinivas.pandruvada@intel.com, pierre-louis.bossart@linux.intel.com, zhifeng.wang@intel.com, xiang.ye@intel.com, tian.shu.qiu@intel.com, bingbu.cao@intel.com, linux-kernel@vger.kernel.org, Wentong Wu Subject: [PATCH v2 1/3] media: pci: intel: ivsc: Add CSI submodule Date: Mon, 13 Feb 2023 10:23:45 +0800 Message-Id: <20230213022347.2480307-2-wentong.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213022347.2480307-1-wentong.wu@intel.com> References: <20230213022347.2480307-1-wentong.wu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org CSI is a submodule of IVSC which can route camera sensor data to the outbound MIPI CSI-2 interface. The interface communicating with firmware is via MEI. There is a separate MEI UUID, which this driver uses to enumerate. To route camera sensor data to host, the caller specifies link frequency and number of data lanes. This information is sent to firmware by sending MEI command. Two APIs are exported: csi_set_link_owner is used to switch ownership of CSI-2 link, and csi_set_link_cfg is to configure CSI-2 link when routing camera sensor data to host. CSI also provides a privacy mode. When privacy mode is turned on, camera sensor can't be used. This means that both IVSC and host Image Processing Unit(IPU) can't get image data. And when this mode is turned on, host Image Processing Unit(IPU) driver is informed via the registered callback, so that user can be notified. Signed-off-by: Wentong Wu --- drivers/media/pci/Kconfig | 1 + drivers/media/pci/intel/Makefile | 2 + drivers/media/pci/intel/ivsc/Kconfig | 12 + drivers/media/pci/intel/ivsc/Makefile | 5 + drivers/media/pci/intel/ivsc/mei_csi.c | 342 +++++++++++++++++++++++++ drivers/media/pci/intel/ivsc/mei_csi.h | 60 +++++ include/linux/ivsc.h | 19 ++ 7 files changed, 441 insertions(+) create mode 100644 drivers/media/pci/intel/ivsc/Kconfig create mode 100644 drivers/media/pci/intel/ivsc/Makefile create mode 100644 drivers/media/pci/intel/ivsc/mei_csi.c create mode 100644 drivers/media/pci/intel/ivsc/mei_csi.h create mode 100644 include/linux/ivsc.h diff --git a/drivers/media/pci/Kconfig b/drivers/media/pci/Kconfig index 1224d908713a..16661ab0b816 100644 --- a/drivers/media/pci/Kconfig +++ b/drivers/media/pci/Kconfig @@ -74,6 +74,7 @@ config VIDEO_PCI_SKELETON when developing new drivers. source "drivers/media/pci/intel/ipu3/Kconfig" +source "drivers/media/pci/intel/ivsc/Kconfig" endif #MEDIA_PCI_SUPPORT endif #PCI diff --git a/drivers/media/pci/intel/Makefile b/drivers/media/pci/intel/Makefile index 0b4236c4db49..d27ca636c860 100644 --- a/drivers/media/pci/intel/Makefile +++ b/drivers/media/pci/intel/Makefile @@ -4,3 +4,5 @@ # obj-y += ipu3/ + +obj-$(CONFIG_INTEL_VSC) += ivsc/ diff --git a/drivers/media/pci/intel/ivsc/Kconfig b/drivers/media/pci/intel/ivsc/Kconfig new file mode 100644 index 000000000000..9535ac10f4f7 --- /dev/null +++ b/drivers/media/pci/intel/ivsc/Kconfig @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2023, Intel Corporation. All rights reserved. + +config INTEL_VSC + tristate "Intel Visual Sensing Controller" + depends on INTEL_MEI + help + This adds support for Intel Visual Sensing Controller (IVSC). + + Enables the IVSC firmware services required for controlling + camera sensor ownership and CSI-2 link through Image Processing + Unit(IPU) driver of Intel. diff --git a/drivers/media/pci/intel/ivsc/Makefile b/drivers/media/pci/intel/ivsc/Makefile new file mode 100644 index 000000000000..1825aad45cff --- /dev/null +++ b/drivers/media/pci/intel/ivsc/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2023, Intel Corporation. All rights reserved. + +obj-$(CONFIG_INTEL_VSC) += mei_csi.o diff --git a/drivers/media/pci/intel/ivsc/mei_csi.c b/drivers/media/pci/intel/ivsc/mei_csi.c new file mode 100644 index 000000000000..309e52387502 --- /dev/null +++ b/drivers/media/pci/intel/ivsc/mei_csi.c @@ -0,0 +1,342 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * Intel Visual Sensing Controller CSI Linux driver + */ + +/* + * To set ownership of CSI-2 link and to configure CSI-2 link, there + * are specific commands, which are sent via MEI protocol. The send + * command function uses "completion" as a synchronization mechanism. + * The response for command is received via a mei callback which wakes + * up the caller. There can be only one outstanding command at a time. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mei_csi.h" + +#define MEI_CSI_DRIVER_NAME "ivsc_csi" + +/* the 5s used here is based on experiment */ +#define CSI_CMD_TIMEOUT (5 * HZ) +/* to setup CSI-2 link an extra delay needed and determined experimentally */ +#define CSI_FW_READY_DELAY_MS 100 +/* link frequency unit is 100kHz */ +#define CSI_LINK_FREQ(x) ((u32)(div_u64(x, 100 * HZ_PER_KHZ))) + +/* + * identify the command id supported by firmware + * IPC, as well as the privacy notification id + * used when processing privacy event. + */ +enum csi_cmd_id { + /* used to set csi ownership */ + CSI_SET_OWNER = 0, + + /* used to configure CSI-2 link */ + CSI_SET_CONF = 2, + + /* privacy notification id used when privacy state changes */ + CSI_PRIVACY_NOTIF = 6, +}; + +/* configuration of the CSI-2 link between host and IVSC */ +struct csi_link_cfg { + /* number of data lanes used on the CSI-2 link */ + u32 nr_of_lanes; + + /* frequency of the CSI-2 link */ + u32 link_freq; + + /* for future use */ + u32 rsvd[2]; +} __packed; + +/* CSI command structure */ +struct csi_cmd { + u32 cmd_id; + union _cmd_param { + u32 param; + struct csi_link_cfg conf; + } param; +} __packed; + +/* CSI notification structure */ +struct csi_notif { + u32 cmd_id; + int status; + union _resp_cont { + u32 cont; + struct csi_link_cfg conf; + } cont; +} __packed; + +struct mei_csi { + struct mei_cl_device *cldev; + + /* command response */ + struct csi_notif cmd_response; + /* used to wait for command response from firmware */ + struct completion cmd_completion; + + /* work element used to handle firmware event */ + struct work_struct event_work; + + /* privacy status */ + enum ivsc_privacy_status status; + /* privacy callback */ + void (*callback)(void *, enum ivsc_privacy_status); + /* privacy callback runtime context */ + void *context; +}; + +/* only one for now */ +static struct mei_csi *csi; +/* lock used to prevent multiple call to csi */ +static DEFINE_MUTEX(csi_mutex); + +/* send a command to firmware and mutex must be held by caller */ +static int mei_csi_send(u8 *buf, size_t len) +{ + struct csi_cmd *cmd = (struct csi_cmd *)buf; + int ret; + + reinit_completion(&csi->cmd_completion); + + ret = mei_cldev_send(csi->cldev, buf, len); + if (ret < 0) + goto out; + + ret = wait_for_completion_killable_timeout(&csi->cmd_completion, + CSI_CMD_TIMEOUT); + if (ret < 0) { + goto out; + } else if (!ret) { + ret = -ETIMEDOUT; + goto out; + } + + /* command response status */ + ret = csi->cmd_response.status; + if (ret) { + ret = -EINVAL; + goto out; + } + + if (csi->cmd_response.cmd_id != cmd->cmd_id) + ret = -EINVAL; + +out: + return ret; +} + +int csi_set_link_owner(enum csi_link_owner owner, + void (*callback)(void *, enum ivsc_privacy_status), + void *context) +{ + struct csi_cmd cmd = { 0 }; + size_t cmd_size; + int ret; + + cmd.cmd_id = CSI_SET_OWNER; + cmd.param.param = owner; + cmd_size = sizeof(cmd.cmd_id) + sizeof(cmd.param.param); + + mutex_lock(&csi_mutex); + if (unlikely(!csi)) { + mutex_unlock(&csi_mutex); + return -EAGAIN; + } + + ret = mei_csi_send((u8 *)&cmd, cmd_size); + + /* + * cancel possible event work and wait for it to finish + * to make sure no work running for the ongoing changes + * to callback and context. + */ + cancel_work_sync(&csi->event_work); + csi->callback = callback; + csi->context = context; + mutex_unlock(&csi_mutex); + + return ret; +} +EXPORT_SYMBOL_NS_GPL(csi_set_link_owner, IVSC); + +int csi_set_link_cfg(u32 nr_of_lanes, u64 link_freq) +{ + struct csi_cmd cmd = { 0 }; + size_t cmd_size; + int ret; + + cmd.cmd_id = CSI_SET_CONF; + cmd.param.conf.nr_of_lanes = nr_of_lanes; + cmd.param.conf.link_freq = CSI_LINK_FREQ(link_freq); + cmd_size = sizeof(cmd.cmd_id) + sizeof(cmd.param.conf); + + mutex_lock(&csi_mutex); + if (unlikely(!csi)) { + mutex_unlock(&csi_mutex); + return -EAGAIN; + } + + ret = mei_csi_send((u8 *)&cmd, cmd_size); + /* + * wait configuration ready if download success. placing + * delay under mutex is to make sure current command flow + * completed before starting a possible new one. + */ + if (!ret) + msleep(CSI_FW_READY_DELAY_MS); + mutex_unlock(&csi_mutex); + + return ret; +} +EXPORT_SYMBOL_NS_GPL(csi_set_link_cfg, IVSC); + +/* event handling routine */ +static void mei_csi_event_work(struct work_struct *work) +{ + if (csi->callback) + csi->callback(csi->context, READ_ONCE(csi->status)); +} + +/* callback for receive */ +static void mei_csi_rx(struct mei_cl_device *cldev) +{ + struct csi_notif notif = { 0 }; + int ret; + + ret = mei_cldev_recv(cldev, (u8 *)¬if, sizeof(notif)); + if (ret < 0) { + dev_err(&cldev->dev, "recv error: %d\n", ret); + return; + } + + switch (notif.cmd_id) { + case CSI_PRIVACY_NOTIF: + if (notif.cont.cont < IVSC_PRIVACY_MAX) { + WRITE_ONCE(csi->status, notif.cont.cont); + + schedule_work(&csi->event_work); + } + break; + case CSI_SET_OWNER: + case CSI_SET_CONF: + memcpy(&csi->cmd_response, ¬if, ret); + + complete(&csi->cmd_completion); + break; + default: + break; + } +} + +static int mei_csi_probe(struct mei_cl_device *cldev, + const struct mei_cl_device_id *id) +{ + int ret; + + mutex_lock(&csi_mutex); + /* + * only instance is possible in the current hardware, + * but adding protection for future hardware. + */ + if (csi) { + ret = -EBUSY; + goto err_unlock; + } + + csi = kzalloc(sizeof(*csi), GFP_KERNEL); + if (!csi) { + ret = -ENOMEM; + goto err_unlock; + } + + csi->cldev = cldev; + init_completion(&csi->cmd_completion); + INIT_WORK(&csi->event_work, mei_csi_event_work); + + mei_cldev_set_drvdata(cldev, csi); + + ret = mei_cldev_enable(cldev); + if (ret < 0) { + dev_err(&cldev->dev, "mei_cldev_enable failed: %d\n", ret); + goto err_free; + } + + ret = mei_cldev_register_rx_cb(cldev, mei_csi_rx); + if (ret) { + dev_err(&cldev->dev, "event cb registration failed: %d\n", ret); + goto err_disable; + } + mutex_unlock(&csi_mutex); + + return 0; + +err_disable: + mei_cldev_disable(cldev); + +err_free: + kfree(csi); + /* disable csi */ + csi = NULL; + +err_unlock: + mutex_unlock(&csi_mutex); + + return ret; +} + +static void mei_csi_remove(struct mei_cl_device *cldev) +{ + mutex_lock(&csi_mutex); + /* disable mei csi client device */ + mei_cldev_disable(cldev); + + /* cancel event work and wait for it to finish */ + cancel_work_sync(&csi->event_work); + + kfree(csi); + /* disable csi */ + csi = NULL; + mutex_unlock(&csi_mutex); +} + +#define MEI_CSI_UUID UUID_LE(0x92335FCF, 0x3203, 0x4472, \ + 0xAF, 0x93, 0x7b, 0x44, 0x53, 0xAC, 0x29, 0xDA) + +static const struct mei_cl_device_id mei_csi_tbl[] = { + { MEI_CSI_DRIVER_NAME, MEI_CSI_UUID, MEI_CL_VERSION_ANY }, + + /* required last entry */ + { } +}; +MODULE_DEVICE_TABLE(mei, mei_csi_tbl); + +static struct mei_cl_driver mei_csi_driver = { + .id_table = mei_csi_tbl, + .name = MEI_CSI_DRIVER_NAME, + + .probe = mei_csi_probe, + .remove = mei_csi_remove, +}; + +module_mei_cl_driver(mei_csi_driver); + +MODULE_AUTHOR("Wentong Wu "); +MODULE_AUTHOR("Zhifeng Wang "); +MODULE_DESCRIPTION("Device driver for IVSC CSI"); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/pci/intel/ivsc/mei_csi.h b/drivers/media/pci/intel/ivsc/mei_csi.h new file mode 100644 index 000000000000..0cc51e6a5250 --- /dev/null +++ b/drivers/media/pci/intel/ivsc/mei_csi.h @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * Intel Visual Sensing Controller CSI external interface + */ + +#ifndef _MEI_CSI_H_ +#define _MEI_CSI_H_ + +#include + +/* CSI-2 link ownership definition */ +enum csi_link_owner { + CSI_LINK_IVSC, + CSI_LINK_HOST, +}; + +#if IS_ENABLED(CONFIG_INTEL_VSC) +/* + * @brief set CSI-2 link ownership + * + * @param owner The csi ownership being set + * @param callback The pointer of privacy callback being set + * @param context Privacy callback runtime context + * + * @return 0 on success, negative on failure + */ +int csi_set_link_owner(enum csi_link_owner owner, + void (*callback)(void *, enum ivsc_privacy_status), + void *context); + +/* + * @brief configure CSI-2 link between host and IVSC + * with provided parameters + * + * @param nr_of_lanes The number of data lanes being used + * on the CSI-2 link + * @param link_freq The frequency being set on the CSI-2 link + * + * @return 0 on success, negative on failure + */ +int csi_set_link_cfg(u32 nr_of_lanes, u64 link_freq); + +#else +static inline +int csi_set_link_owner(enum csi_link_owner owner, + void (*callback)(void *, enum ivsc_privacy_status), + void *context) +{ + return 0; +} + +static inline int csi_set_link_cfg(u32 nr_of_lanes, u64 link_freq) +{ + return 0; +} + +#endif + +#endif diff --git a/include/linux/ivsc.h b/include/linux/ivsc.h new file mode 100644 index 000000000000..6572ca4f340c --- /dev/null +++ b/include/linux/ivsc.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * Intel Visual Sensing Controller interface + */ + +#ifndef _LINUX_IVSC_H_ +#define _LINUX_IVSC_H_ + +#include + +/* IVSC privacy status definition */ +enum ivsc_privacy_status { + IVSC_PRIVACY_OFF, + IVSC_PRIVACY_ON, + IVSC_PRIVACY_MAX, +}; + +#endif From patchwork Mon Feb 13 02:23:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Wentong" X-Patchwork-Id: 13137673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75A2AC636D7 for ; Mon, 13 Feb 2023 02:21:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229789AbjBMCVp (ORCPT ); Sun, 12 Feb 2023 21:21:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbjBMCVn (ORCPT ); Sun, 12 Feb 2023 21:21:43 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D680FF3F; Sun, 12 Feb 2023 18:21:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676254900; x=1707790900; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tot06ZrpgRqpaHJjI93sCmTTQ7KdekHTBwRcoXQLrnE=; b=cPu0oV78/q7ZQr1xcsDaVuEmKy/Hei5skYLQQVKQjjL2ZRrwj5tybnjO O2D82pV3d5/FtoDoWCLSFCrl3x/Rp+//kKgACsXsCilUx5BFKWpVFjPXV pJDHgx1KtbFY34naO2mg6ZfhqT3ILOQHKB4rDKW/OE/xA6dVZ5ElaG+Pg UOj6Y31kkn6F72HfHeupIAjqF6LRiCvEKg8j7BKW8NKPjPVaK07ReceN0 qYXzlSbe2mVf5Ek/tqi8t05iMi5IXsW/EYpy35Zfc2c3oEZcGx5qFnSvD oNxS4TuWInDKusmKgq+PHOCQZ4wIWuVJgRPQscz6OUgZfsxOMMMB6L8fI w==; X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="310424833" X-IronPort-AV: E=Sophos;i="5.97,291,1669104000"; d="scan'208";a="310424833" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2023 18:21:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="701103157" X-IronPort-AV: E=Sophos;i="5.97,291,1669104000"; d="scan'208";a="701103157" Received: from wentongw-hp-z228-microtower-workstation.sh.intel.com ([10.239.153.109]) by orsmga001.jf.intel.com with ESMTP; 12 Feb 2023 18:21:36 -0800 From: Wentong Wu To: mchehab@kernel.org, sakari.ailus@linux.intel.com, linux-media@vger.kernel.org Cc: srinivas.pandruvada@intel.com, pierre-louis.bossart@linux.intel.com, zhifeng.wang@intel.com, xiang.ye@intel.com, tian.shu.qiu@intel.com, bingbu.cao@intel.com, linux-kernel@vger.kernel.org, Wentong Wu Subject: [PATCH v2 2/3] media: pci: intel: ivsc: Add ACE submodule Date: Mon, 13 Feb 2023 10:23:46 +0800 Message-Id: <20230213022347.2480307-3-wentong.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213022347.2480307-1-wentong.wu@intel.com> References: <20230213022347.2480307-1-wentong.wu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org ACE is a submodule of IVSC which controls camera sensor's ownership, belonging to host or IVSC. When IVSC owns camera sensor, it is for algorithm computing. When host wants to control camera sensor, ACE module needs to be informed of ownership with defined interface. The interface is via MEI. There is a separate MEI UUID, which this driver uses to enumerate. To switch ownership of camera sensor between IVSC and host, the caller specifies the defined ownership information which will be sent to firmware by sending MEI command. The only exported API ace_set_camera_owner is to switch ownership of camera sensor. Signed-off-by: Wentong Wu --- drivers/media/pci/intel/ivsc/Makefile | 1 + drivers/media/pci/intel/ivsc/mei_ace.c | 472 +++++++++++++++++++++++++ drivers/media/pci/intel/ivsc/mei_ace.h | 36 ++ 3 files changed, 509 insertions(+) create mode 100644 drivers/media/pci/intel/ivsc/mei_ace.c create mode 100644 drivers/media/pci/intel/ivsc/mei_ace.h diff --git a/drivers/media/pci/intel/ivsc/Makefile b/drivers/media/pci/intel/ivsc/Makefile index 1825aad45cff..de0a425c22c2 100644 --- a/drivers/media/pci/intel/ivsc/Makefile +++ b/drivers/media/pci/intel/ivsc/Makefile @@ -3,3 +3,4 @@ # Copyright (C) 2023, Intel Corporation. All rights reserved. obj-$(CONFIG_INTEL_VSC) += mei_csi.o +obj-$(CONFIG_INTEL_VSC) += mei_ace.o diff --git a/drivers/media/pci/intel/ivsc/mei_ace.c b/drivers/media/pci/intel/ivsc/mei_ace.c new file mode 100644 index 000000000000..3dbd885d11a1 --- /dev/null +++ b/drivers/media/pci/intel/ivsc/mei_ace.c @@ -0,0 +1,472 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * Intel Visual Sensing Controller ACE Linux driver + */ + +/* + * To set ownership of camera sensor, there is specific command, which + * is sent via MEI protocol. That's a two-step scheme where the firmware + * first acks receipt of the command and later responses the command was + * executed. The command sending function uses "completion" as the + * synchronization mechanism. The notification for command is received + * via a mei callback which wakes up the caller. There can be only one + * outstanding command at a time. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mei_ace.h" + +#define MEI_ACE_DRIVER_NAME "ivsc_ace" + +/* indicating driver message */ +#define ACE_DRV_MSG 1 +/* indicating set command */ +#define ACE_CMD_SET 4 +/* command timeout determined experimentally */ +#define ACE_CMD_TIMEOUT (5 * HZ) +/* indicating the first command block */ +#define ACE_CMD_INIT_BLOCK 1 +/* indicating the last command block */ +#define ACE_CMD_FINAL_BLOCK 1 +/* size of camera status notification content */ +#define ACE_CAMERA_STATUS_SIZE 5 + +/* UUID used to get firmware id */ +#define ACE_GET_FW_ID_UUID UUID_LE(0x6167DCFB, 0x72F1, 0x4584, 0xBF, \ + 0xE3, 0x84, 0x17, 0x71, 0xAA, 0x79, 0x0B) + +/* identify firmware event type */ +enum ace_event_type { + /* firmware ready */ + ACE_FW_READY = 0x8, + + /* command response */ + ACE_CMD_RESPONSE = 0x10, +}; + +/* identify the command id supported by firmware IPC */ +enum ace_cmd_id { + /* used to switch camera sensor to host */ + ACE_SWITCH_CAMERA_TO_HOST = 0x13, + + /* used to switch camera sensor to IVSC */ + ACE_SWITCH_CAMERA_TO_IVSC = 0x14, + + /* used to get firmware id */ + ACE_GET_FW_ID = 0x1A, +}; + +/* ACE command header structure */ +struct ace_cmd_hdr { + u32 firmware_id : 16; + u32 instance_id : 8; + u32 type : 5; + u32 rsp : 1; + u32 msg_tgt : 1; + u32 _hw_rsvd_1 : 1; + u32 param_size : 20; + u32 cmd_id : 8; + u32 final_block : 1; + u32 init_block : 1; + u32 _hw_rsvd_2 : 2; +} __packed; + +/* ACE command parameter structure */ +union ace_cmd_param { + uuid_le uuid; + u32 param; +}; + +/* ACE command structure */ +struct ace_cmd { + struct ace_cmd_hdr hdr; + union ace_cmd_param param; +} __packed; + +/* ACE notification header */ +union ace_notif_hdr { + struct _confirm { + u32 status : 24; + u32 type : 5; + u32 rsp : 1; + u32 msg_tgt : 1; + u32 _hw_rsvd_1 : 1; + u32 param_size : 20; + u32 cmd_id : 8; + u32 final_block : 1; + u32 init_block : 1; + u32 _hw_rsvd_2 : 2; + } __packed ack; + + struct _event { + u32 rsvd1 : 16; + u32 event_type : 8; + u32 type : 5; + u32 ack : 1; + u32 msg_tgt : 1; + u32 _hw_rsvd_1 : 1; + u32 rsvd2 : 30; + u32 _hw_rsvd_2 : 2; + } __packed event; + + struct _response { + u32 event_id : 16; + u32 notif_type : 8; + u32 type : 5; + u32 rsp : 1; + u32 msg_tgt : 1; + u32 _hw_rsvd_1 : 1; + u32 event_data_size : 16; + u32 request_target : 1; + u32 request_type : 5; + u32 cmd_id : 8; + u32 _hw_rsvd_2 : 2; + } __packed response; +}; + +/* ACE notification content */ +union ace_notif_cont { + u16 firmware_id; + u8 state_notif; + u8 camera_status[ACE_CAMERA_STATUS_SIZE]; +}; + +/* ACE notification structure */ +struct ace_notif { + union ace_notif_hdr hdr; + union ace_notif_cont cont; +} __packed; + +struct mei_ace { + struct mei_cl_device *cldev; + + /* command ack */ + struct ace_notif cmd_ack; + /* command response */ + struct ace_notif cmd_response; + /* used to wait for command ack and response */ + struct completion cmd_completion; + + /* used to construct command */ + u16 firmware_id; +}; + +/* only one for now */ +static struct mei_ace *ace; +/* lock used to prevent multiple call to ace */ +static DEFINE_MUTEX(ace_mutex); + +static inline void init_cmd_hdr(struct ace_cmd_hdr *hdr) +{ + memset(hdr, 0, sizeof(struct ace_cmd_hdr)); + + hdr->type = ACE_CMD_SET; + hdr->msg_tgt = ACE_DRV_MSG; + hdr->init_block = ACE_CMD_INIT_BLOCK; + hdr->final_block = ACE_CMD_FINAL_BLOCK; +} + +static int construct_command(struct ace_cmd *cmd, enum ace_cmd_id cmd_id) +{ + union ace_cmd_param *param = &cmd->param; + struct ace_cmd_hdr *hdr = &cmd->hdr; + + init_cmd_hdr(hdr); + + hdr->cmd_id = cmd_id; + switch (cmd_id) { + case ACE_GET_FW_ID: + param->uuid = ACE_GET_FW_ID_UUID; + hdr->param_size = sizeof(param->uuid); + break; + case ACE_SWITCH_CAMERA_TO_IVSC: + param->param = 0; + hdr->firmware_id = ace->firmware_id; + hdr->param_size = sizeof(param->param); + break; + case ACE_SWITCH_CAMERA_TO_HOST: + hdr->firmware_id = ace->firmware_id; + break; + default: + return -EINVAL; + } + + return hdr->param_size + sizeof(cmd->hdr); +} + +/* send a command to firmware and mutex must be held by caller */ +static int mei_ace_send(struct ace_cmd *cmd, size_t len, bool only_ack) +{ + union ace_notif_hdr *resp_hdr = &ace->cmd_response.hdr; + union ace_notif_hdr *ack_hdr = &ace->cmd_ack.hdr; + struct ace_cmd_hdr *cmd_hdr = &cmd->hdr; + int ret; + + reinit_completion(&ace->cmd_completion); + + ret = mei_cldev_send(ace->cldev, (u8 *)cmd, len); + if (ret < 0) + goto out; + + ret = wait_for_completion_killable_timeout(&ace->cmd_completion, + ACE_CMD_TIMEOUT); + if (ret < 0) { + goto out; + } else if (!ret) { + ret = -ETIMEDOUT; + goto out; + } + + if (ack_hdr->ack.cmd_id != cmd_hdr->cmd_id) { + ret = -EINVAL; + goto out; + } + + /* command ack status */ + ret = ack_hdr->ack.status; + if (ret) { + ret = -EIO; + goto out; + } + + if (only_ack) + goto out; + + ret = wait_for_completion_killable_timeout(&ace->cmd_completion, + ACE_CMD_TIMEOUT); + if (ret < 0) { + goto out; + } else if (!ret) { + ret = -ETIMEDOUT; + goto out; + } + + if (resp_hdr->response.cmd_id != cmd_hdr->cmd_id) + ret = -EINVAL; + +out: + return ret; +} + +int ace_set_camera_owner(enum ace_camera_owner owner) +{ + enum ace_cmd_id cmd_id; + struct ace_cmd cmd; + int cmd_size; + int ret; + + if (owner == ACE_CAMERA_IVSC) + cmd_id = ACE_SWITCH_CAMERA_TO_IVSC; + else + cmd_id = ACE_SWITCH_CAMERA_TO_HOST; + + mutex_lock(&ace_mutex); + if (unlikely(!ace)) { + mutex_unlock(&ace_mutex); + return -EAGAIN; + } + + cmd_size = construct_command(&cmd, cmd_id); + if (cmd_size >= 0) + ret = mei_ace_send(&cmd, cmd_size, false); + else + ret = cmd_size; + mutex_unlock(&ace_mutex); + + return ret; +} +EXPORT_SYMBOL_NS_GPL(ace_set_camera_owner, IVSC); + +/* the first command downloaded to firmware */ +static inline int ace_get_firmware_id(void) +{ + struct ace_cmd cmd; + int cmd_size; + int ret; + + cmd_size = construct_command(&cmd, ACE_GET_FW_ID); + if (cmd_size >= 0) + ret = mei_ace_send(&cmd, cmd_size, true); + else + ret = cmd_size; + + return ret; +} + +static void handle_command_response(struct ace_notif *resp, int len) +{ + union ace_notif_hdr *hdr = &resp->hdr; + + switch (hdr->response.cmd_id) { + case ACE_SWITCH_CAMERA_TO_IVSC: + case ACE_SWITCH_CAMERA_TO_HOST: + memcpy(&ace->cmd_response, resp, len); + complete(&ace->cmd_completion); + break; + case ACE_GET_FW_ID: + break; + default: + break; + } +} + +static void handle_command_ack(struct ace_notif *ack, int len) +{ + union ace_notif_hdr *hdr = &ack->hdr; + + switch (hdr->ack.cmd_id) { + case ACE_GET_FW_ID: + ace->firmware_id = ack->cont.firmware_id; + fallthrough; + case ACE_SWITCH_CAMERA_TO_IVSC: + case ACE_SWITCH_CAMERA_TO_HOST: + memcpy(&ace->cmd_ack, ack, len); + complete(&ace->cmd_completion); + break; + default: + break; + } +} + +/* callback for receive */ +static void mei_ace_rx(struct mei_cl_device *cldev) +{ + struct ace_notif event; + union ace_notif_hdr *hdr = &event.hdr; + int ret; + + ret = mei_cldev_recv(cldev, (u8 *)&event, sizeof(event)); + if (ret < 0) { + dev_err(&cldev->dev, "recv error: %d\n", ret); + return; + } + + if (hdr->event.ack) { + handle_command_ack(&event, ret); + return; + } + + switch (hdr->event.event_type) { + case ACE_CMD_RESPONSE: + handle_command_response(&event, ret); + break; + case ACE_FW_READY: + /* + * firmware ready notification sent to driver + * after HECI client connected with firmware. + */ + dev_dbg(&cldev->dev, "firmware ready\n"); + break; + default: + break; + } +} + +static int mei_ace_probe(struct mei_cl_device *cldev, + const struct mei_cl_device_id *id) +{ + int ret; + + mutex_lock(&ace_mutex); + /* + * only instance is possible in the current hardware, + * but adding protection for future hardware. + */ + if (ace) { + ret = -EBUSY; + goto err_unlock; + } + + ace = kzalloc(sizeof(struct mei_ace), GFP_KERNEL); + if (!ace) { + ret = -ENOMEM; + goto err_unlock; + } + + ace->cldev = cldev; + init_completion(&ace->cmd_completion); + + mei_cldev_set_drvdata(cldev, ace); + + ret = mei_cldev_enable(cldev); + if (ret < 0) { + dev_err(&cldev->dev, "mei_cldev_enable failed: %d\n", ret); + goto err_free; + } + + ret = mei_cldev_register_rx_cb(cldev, mei_ace_rx); + if (ret) { + dev_err(&cldev->dev, "event cb registration failed: %d\n", ret); + goto err_disable; + } + + ret = ace_get_firmware_id(); + if (ret) { + dev_err(&cldev->dev, "get firmware id failed: %d\n", ret); + goto err_disable; + } + mutex_unlock(&ace_mutex); + + return 0; + +err_disable: + mei_cldev_disable(cldev); + +err_free: + kfree(ace); + /* disable ace */ + ace = NULL; + +err_unlock: + mutex_unlock(&ace_mutex); + + return ret; +} + +static void mei_ace_remove(struct mei_cl_device *cldev) +{ + mutex_lock(&ace_mutex); + /* disable mei ace client device */ + mei_cldev_disable(cldev); + + kfree(ace); + /* disable ace */ + ace = NULL; + mutex_unlock(&ace_mutex); +} + +#define MEI_ACE_UUID UUID_LE(0x5DB76CF6, 0x0A68, 0x4ED6, \ + 0x9B, 0x78, 0x03, 0x61, 0x63, 0x5E, 0x24, 0x47) + +static const struct mei_cl_device_id mei_ace_tbl[] = { + { MEI_ACE_DRIVER_NAME, MEI_ACE_UUID, MEI_CL_VERSION_ANY }, + + /* required last entry */ + { } +}; +MODULE_DEVICE_TABLE(mei, mei_ace_tbl); + +static struct mei_cl_driver mei_ace_driver = { + .id_table = mei_ace_tbl, + .name = MEI_ACE_DRIVER_NAME, + + .probe = mei_ace_probe, + .remove = mei_ace_remove, +}; + +module_mei_cl_driver(mei_ace_driver); + +MODULE_AUTHOR("Wentong Wu "); +MODULE_AUTHOR("Zhifeng Wang "); +MODULE_DESCRIPTION("Device driver for IVSC ACE"); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/pci/intel/ivsc/mei_ace.h b/drivers/media/pci/intel/ivsc/mei_ace.h new file mode 100644 index 000000000000..0302bc899521 --- /dev/null +++ b/drivers/media/pci/intel/ivsc/mei_ace.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * Intel Visual Sensing Controller ACE external interface + */ + +#ifndef _MEI_ACE_H_ +#define _MEI_ACE_H_ + +#include + +/* identify camera sensor ownership */ +enum ace_camera_owner { + ACE_CAMERA_IVSC, + ACE_CAMERA_HOST, +}; + +#if IS_ENABLED(CONFIG_INTEL_VSC) +/* + * @brief set camera sensor ownership + * + * @param owner Camera sensor ownership being set + * + * @return 0 on success, negative on failure + */ +int ace_set_camera_owner(enum ace_camera_owner owner); + +#else +static inline int ace_set_camera_owner(enum ace_camera_owner owner) +{ + return 0; +} + +#endif + +#endif From patchwork Mon Feb 13 02:23:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Wentong" X-Patchwork-Id: 13137674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09ADCC6379F for ; Mon, 13 Feb 2023 02:21:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229786AbjBMCVw (ORCPT ); Sun, 12 Feb 2023 21:21:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229783AbjBMCVp (ORCPT ); Sun, 12 Feb 2023 21:21:45 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17439FF31; Sun, 12 Feb 2023 18:21:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676254904; x=1707790904; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WWB6i1R0hRSQi17PJ41xbkQC2m/YTpM2kB96UwAvNM4=; b=UNqJHYiM3LhyWhu7eMrgkKNfYopxg05cTerUJSCWv7EOzuRa/jfZ3C/H ZrsgJc0RFUi76AvB1B/i4rOBf6pHRRBIz/HXvLRCp3DZWf3seQmQ2pXrh HFbCEaOt4MDXPQKEpbLi3mT2om06Pu2WeLi2p//8CjFKjOEa3B9mkM6Jg UE48lUH2VUCemuYpNKiVVY4Rih+TODi/y+Isji8D9gKp+Q265oT/we8uk MKXlth8IScLSBAiOyynzOHiWcRVvisou/CiHqIIyEPfLJXeL+v90q0od1 g7OFZ/LvkW8EA1cRpTuYQBh714j3fFMpRA8kAw29RSklpOOYrtjTBgr0Y g==; X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="310424839" X-IronPort-AV: E=Sophos;i="5.97,291,1669104000"; d="scan'208";a="310424839" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2023 18:21:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="701103173" X-IronPort-AV: E=Sophos;i="5.97,291,1669104000"; d="scan'208";a="701103173" Received: from wentongw-hp-z228-microtower-workstation.sh.intel.com ([10.239.153.109]) by orsmga001.jf.intel.com with ESMTP; 12 Feb 2023 18:21:41 -0800 From: Wentong Wu To: mchehab@kernel.org, sakari.ailus@linux.intel.com, linux-media@vger.kernel.org Cc: srinivas.pandruvada@intel.com, pierre-louis.bossart@linux.intel.com, zhifeng.wang@intel.com, xiang.ye@intel.com, tian.shu.qiu@intel.com, bingbu.cao@intel.com, linux-kernel@vger.kernel.org, Wentong Wu Subject: [PATCH v2 3/3] media: pci: intel: ivsc: Add acquire/release API for ivsc Date: Mon, 13 Feb 2023 10:23:47 +0800 Message-Id: <20230213022347.2480307-4-wentong.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213022347.2480307-1-wentong.wu@intel.com> References: <20230213022347.2480307-1-wentong.wu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org IVSC directly connects to camera sensor on source side, and on output side it not only connects ISH via I2C, but also exposes MIPI CSI-2 interface to output camera sensor data. IVSC can use the camera sensor data to do AI algorithm, and send the results to ISH. On the other end, IVSC can share camera sensor to host by routing the raw camera sensor data to the exposed MIPI CSI-2 interface. But they can not work at the same time, so software APIs are defined to sync the ownership. This commit defines the interfaces between IVSC and camera sensor driver in include/linux/ivsc.h. The camera driver controls ownership of the CSI-2 link and sensor with the acquire/release APIs. When acquiring camera, lane number and link freq are also required by IVSC frame router. Signed-off-by: Wentong Wu --- drivers/media/pci/intel/ivsc/Makefile | 1 + drivers/media/pci/intel/ivsc/ivsc.c | 84 +++++++++++++++++++++++++++ include/linux/ivsc.h | 55 ++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 drivers/media/pci/intel/ivsc/ivsc.c diff --git a/drivers/media/pci/intel/ivsc/Makefile b/drivers/media/pci/intel/ivsc/Makefile index de0a425c22c2..b8b6fc1083be 100644 --- a/drivers/media/pci/intel/ivsc/Makefile +++ b/drivers/media/pci/intel/ivsc/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_INTEL_VSC) += mei_csi.o obj-$(CONFIG_INTEL_VSC) += mei_ace.o +obj-$(CONFIG_INTEL_VSC) += ivsc.o diff --git a/drivers/media/pci/intel/ivsc/ivsc.c b/drivers/media/pci/intel/ivsc/ivsc.c new file mode 100644 index 000000000000..12996b587639 --- /dev/null +++ b/drivers/media/pci/intel/ivsc/ivsc.c @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * Intel Visual Sensing Controller interface + */ + +#include +#include +#include +#include + +#include "mei_ace.h" +#include "mei_csi.h" + +/* lock for ivsc APIs */ +static DEFINE_MUTEX(ivsc_mutex); + +int ivsc_acquire_camera(u32 nr_of_lanes, u64 link_freq, + void (*callback)(void *, enum ivsc_privacy_status), + void *context) +{ + int ret; + + mutex_lock(&ivsc_mutex); + + /* switch camera sensor ownership to host */ + ret = ace_set_camera_owner(ACE_CAMERA_HOST); + if (ret) + goto error; + + /* switch CSI-2 link to host */ + ret = csi_set_link_owner(CSI_LINK_HOST, callback, context); + if (ret) + goto release_camera; + + /* configure CSI-2 link */ + ret = csi_set_link_cfg(nr_of_lanes, link_freq); + if (ret) + goto release_csi; + + mutex_unlock(&ivsc_mutex); + + return 0; + +release_csi: + csi_set_link_owner(CSI_LINK_IVSC, NULL, NULL); + +release_camera: + ace_set_camera_owner(ACE_CAMERA_IVSC); + +error: + mutex_unlock(&ivsc_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(ivsc_acquire_camera); + +int ivsc_release_camera(void) +{ + int ret; + + mutex_lock(&ivsc_mutex); + + /* switch CSI-2 link to IVSC */ + ret = csi_set_link_owner(CSI_LINK_IVSC, NULL, NULL); + if (ret) + goto error; + + /* switch camera sensor ownership to IVSC */ + ret = ace_set_camera_owner(ACE_CAMERA_IVSC); + +error: + mutex_unlock(&ivsc_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(ivsc_release_camera); + +MODULE_AUTHOR("Wentong Wu "); +MODULE_AUTHOR("Zhifeng Wang "); +MODULE_SOFTDEP("pre: mei_csi mei_ace"); +MODULE_DESCRIPTION("IVSC interface"); +MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS(IVSC); diff --git a/include/linux/ivsc.h b/include/linux/ivsc.h index 6572ca4f340c..bc9006cd6efc 100644 --- a/include/linux/ivsc.h +++ b/include/linux/ivsc.h @@ -16,4 +16,59 @@ enum ivsc_privacy_status { IVSC_PRIVACY_MAX, }; +#if IS_ENABLED(CONFIG_INTEL_VSC) +/* + * @brief Acquire camera sensor ownership to host and setup + * the CSI-2 link between host and IVSC + * + * IVSC provides a privacy mode. When the privacy mode is turned + * on, camera sensor can't be used. This means that both IVSC and + * host Image Processing Unit(IPU) can't get image data. And when + * this mode is turned on, host Image Processing Unit(IPU) driver + * is informed via the registered callback, so that user can be + * notified. + * + * @param nr_of_lanes Number of data lanes used on the CSI-2 link + * @param link_freq Frequency of the CSI-2 link + * @param callback The pointer of privacy callback function + * @param context Privacy callback function runtime context + * + * @retval 0 If success + * @retval -EIO IO error + * @retval -EINVAL Invalid argument + * @retval -EAGAIN IVSC device not ready + * @retval negative values for other errors + */ +int ivsc_acquire_camera(u32 nr_of_lanes, u64 link_freq, + void (*callback)(void *, enum ivsc_privacy_status), + void *context); + +/* + * @brief Release camera sensor ownership and stop the CSI-2 + * link between host and IVSC + * + * @retval 0 If success + * @retval -EIO IO error + * @retval -EINVAL Invalid argument + * @retval -EAGAIN IVSC device not ready + * @retval negative values for other errors + */ +int ivsc_release_camera(void); + +#else +static inline +int ivsc_acquire_camera(u32 nr_of_lanes, u64 link_freq, + void (*callback)(void *, enum ivsc_privacy_status), + void *context) +{ + return 0; +} + +static inline int ivsc_release_camera(void) +{ + return 0; +} + +#endif + #endif