From patchwork Wed Sep 4 21:07:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 825453 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D1881487E3; Wed, 4 Sep 2024 21:07:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484066; cv=none; b=JeXMIn3x3hSdIM26XoEyZBD89UX8VBV6rrtH3ZqdZ/QdidwFYYqloctgUybKVMW/1CcY5VOdoX6/sXhK5ixg6ritLvl30OUW3pM5AaedBGIebnfFIjTrY10u7hj88/Mm9A+AZ3FQF+A/Tr1uyQN2M/QnIQMOXspP7ISKq1pDKrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484066; c=relaxed/simple; bh=aY/aJQpV38qNROExL3xJqYKRw9fwpPUOQxSrGJ5yIiU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mhqSJxoR+vEaQKDneJRTSIS84x9fIE8GtSWJy9wbEz7dtcd81diHavKAGAZB6p7dXjwMEUETKfKJQ6Hw599Z6mPfnZFejhql4IuDyy9HRGQ1NFTZA1SZ10Fxa7eFelhDiUcQkbpjXU21KKfDZ4LsO1zBmNQVFyKcOPKp6V/p8aI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=feEMuDac; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="feEMuDac" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-428e0d184b4so57861845e9.2; Wed, 04 Sep 2024 14:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725484064; x=1726088864; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Jc7MVYbBTomhAghG+qJoHxAlGvl31VLQMoetsad1iTQ=; b=feEMuDacp5/8AVwS/GD6natgn8NT90d0yTyx4OxDEePK4QojkrpiSpeudkMuHi/VKP I+WWtMV/oGg/u5oOxzPbpaD3AIrFwJwLl8KMoeosc5TvhhEBcioUd6/fNghA5bqL+SID Ot7WqXAPxdLBDhMrTI1AzGyW2qbiC6IJmupTVxdSw5zoEC2ren7u5PW+gyBk6zPHuKSY 6lfw6VoulZh50AjAg6H0EqbDZnSpt5XT3Hvk5nK17tKrcgyF0xbawSRzbDsVkdl0bjZ1 aSuhB7GiMD90Cu98b8Cyy4Q8OwE9flgw3f/+0y94eFZGMY5DE6Mu5VczAnEpblPM063E 2cBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725484064; x=1726088864; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jc7MVYbBTomhAghG+qJoHxAlGvl31VLQMoetsad1iTQ=; b=Xw62PWbgRqD/xfzsz1v6RwBOUay2kGuebqzJlV9HSaBBf9cNyjcavYEd9yy7l1UrmP IVOtBt7fjZ2eFJSy8VOi6eh0rugGwtR9G7NSIC/SEOnkRDU6z3dUbBH5E9NuSNkdJp5u Q4PQbmAIfu2g7bzikTF1cF/k5yphG2CogpIbAmB2PiQbzBfHvma/eG86n5uhMdujIqrv Ah8iU65GrLrGjAOhW6wu9HIHOLixQGnWye4g+bGULG1ETdMq+ECcwqb73o0Z4MzA7XBm cQWXeKAUzS98vM3oWG1qAOBiuByGftFVowP3OssGmKAvRTvNw2sm7i3Elp1sNtzBns8m TPBw== X-Forwarded-Encrypted: i=1; AJvYcCVyRnwSUBNStIZxe2h+yIl7Dwn64dQtkuRIwEteKBkp0Ga4FgmM5aSHh996WaEq3s2kP7Uk3gOBBGX4SDU=@vger.kernel.org, AJvYcCW2+6dh/I8DgM3aSOJo3NXAtzh7gNxRZ9Qb2wVClKC+kFHfQlhWFrCWYmaYSZd2krwABXJcHKZk/YmhELZx0TcxBUQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzFNiT5ZcO3RKf52dOBI9rAnmoae8+U66SHYmBTmHhmNaW72b/z giQPmo1iWxyvPYcIkaLFXN/LU959p0oOASACVHzt/b08GQrbMVXU X-Google-Smtp-Source: AGHT+IEG1xxnHICBbjgQjyLAhdPkSCuL0iFOVc2UlPBgzSYVPheCM3ApQ1pzzl5GKWc09JGokwSXJg== X-Received: by 2002:a05:600c:3b8f:b0:426:6320:226a with SMTP id 5b1f17b1804b1-42c7b5a8f75mr113452075e9.15.1725484063692; Wed, 04 Sep 2024 14:07:43 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2500:a01:c57c:1e61:792:2ab1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42c7a41bdc8sm158821485e9.3.2024.09.04.14.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 14:07:42 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Sakari Ailus , Laurent Pinchart , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Fabrizio Castro , Lad Prabhakar Subject: [RFC PATCH 01/12] media: i2c: ov5645: Add V4L2_SUBDEV_FL_HAS_EVENTS and subscribe hooks Date: Wed, 4 Sep 2024 22:07:08 +0100 Message-Id: <20240904210719.52466-2-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Lad Prabhakar The OV5645 sensor exposes controls, so the V4L2_SUBDEV_FL_HAS_EVENTS flag should be set and implement subscribe_event and unsubscribe_event hooks. Signed-off-by: Lad Prabhakar --- drivers/media/i2c/ov5645.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index 019979f553b1..6eedd0310b02 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -1042,7 +1043,13 @@ static const struct v4l2_subdev_pad_ops ov5645_subdev_pad_ops = { .get_selection = ov5645_get_selection, }; +static const struct v4l2_subdev_core_ops ov5645_core_ops = { + .subscribe_event = v4l2_ctrl_subdev_subscribe_event, + .unsubscribe_event = v4l2_event_subdev_unsubscribe, +}; + static const struct v4l2_subdev_ops ov5645_subdev_ops = { + .core = &ov5645_core_ops, .video = &ov5645_video_ops, .pad = &ov5645_subdev_pad_ops, }; @@ -1178,7 +1185,7 @@ static int ov5645_probe(struct i2c_client *client) v4l2_i2c_subdev_init(&ov5645->sd, client, &ov5645_subdev_ops); ov5645->sd.internal_ops = &ov5645_internal_ops; - ov5645->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + ov5645->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; ov5645->pad.flags = MEDIA_PAD_FL_SOURCE; ov5645->sd.dev = &client->dev; ov5645->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; From patchwork Wed Sep 4 21:07:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 825452 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31953155730; Wed, 4 Sep 2024 21:07:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484069; cv=none; b=irId6KVbMHZNErwX764JpCSfs0jnCDOgLQKM/qZlImLgofhGG8dnf1+dFGE//I6afLrteryo2IZOjBsOAXxBtebNAl73xn8xGsW7zhIR1YHzIIeey5FmHCk/O2eXMGLmXlguWkQ0qmNZf4daRgk0WpvE3kbSpWaQ+FaRMtmceZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484069; c=relaxed/simple; bh=ZShCPWFSW/sqGfuamWtEEwCfgDxJvKsb2CpN+xf6TmM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qnDjbg4bH6eTVJ5DQNX7oB3rldJaR2nGeKJA95k8inw/L6oaQwhW/qg0NRhSRZxiz7q2bl/iZDqW3HCRrwgppHsm5CuXjdj2uUXOuJdzYUQl+trd7XxEGLDiiIeKILrMuaQo+ZE6UhpVwGJwrI5vvIB+9MnAqGPIezrclqkQd9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SKEh1Qwj; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SKEh1Qwj" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-42bbdf7f860so49602505e9.3; Wed, 04 Sep 2024 14:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725484066; x=1726088866; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bviiKkM7wyJK2q4unJEl7wvx3EhZ5MDlCK2md31apcY=; b=SKEh1QwjrNZB0EgB4tcnkGE5+9061I8DgEkkBZgAyRduODZNwxwuqTVoqPZOlVWVdi WU1A1ZpVoh4K5D1BiCg/MZEYwTuoWwZCafQzVn0I3F3I4penkJtiLdZSeXhVXV8e0Eff YncmKFKvnl7QvCsyDVCXFZYwwbAkMU+rX5bFU2vq8d+kx9+vYpC6NSWFO24VLIkJC9vO AxpnXe5N5pMHK0ku6U1vpyWD40BSsthuyRXifRcujnUJWpdh6mXI6OsBYO4ekX4GE7+V nyNOrwcM9Byg2XdyUpTbiLDsmxUxDRCGti55EBmBQjX+Hlqln58w5dFleLs9h8LYLwUH HIIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725484066; x=1726088866; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bviiKkM7wyJK2q4unJEl7wvx3EhZ5MDlCK2md31apcY=; b=AB+ex+poePJrLb1RTasUQ68xATd1RyIFDWhuCP3y8dioXiJybXuSBtXfagRZDLv8mQ otozLLPBeo+rKtas+u/ROmjfgPO3BypBEj0oI1vtzYLHt6cy9DWItsacM1KLIEKxJymm grLdkuPgDEpbym8CpVzzbMEYtANbVwje9eI9H3+OA0AFGdXKP5ERUHmPY27EY/6vWCkl LnWSxZCpZqyyXqApwzlMu7i8EJ4J/oc6Lzd/5r74d5B2q1vavugk/ptFvpb8TimfYebo wmRLmggLmza1R5IYMrUVFnl8WN8SbfiI/JMHGUk1Laxd1bjnLNnS0HwnND8HWpKX35I7 cyew== X-Forwarded-Encrypted: i=1; AJvYcCUQ8aq7QPqAmPI1b5nXx0bSP1PtwBjJbamD32DbYBopnzbHafCNBOGsPMYGZNqg6PRYvlqEY9kqfDBljtRyDzbyWSw=@vger.kernel.org, AJvYcCXxMQ1hHZE7WSbHh0+AxURNZoSNTvlW88mxnwqwPd4AkBYbQDUUy0QZR36GItXzm1pl/aYcPz9//Ijhpc8=@vger.kernel.org X-Gm-Message-State: AOJu0YyZCziY1EWihUMP9I88oGUZOQEPQAF02MRUySaxXEjKybmYOUWK zzWgDYkZQHnqH1QQ5kgUfYwQpRx87ILrXfbm5kQaYZxK356F/jHBD4TvqN5Y X-Google-Smtp-Source: AGHT+IEoXSP87wrRFdk7Ds9PuCqQ6FnuJW8gUgmKIEgIap4lxBZMxsuTOXKY/agSUQrCywIB2nz3Hw== X-Received: by 2002:a05:600c:1c83:b0:426:5440:8541 with SMTP id 5b1f17b1804b1-42bb01e5f83mr160393635e9.27.1725484066515; Wed, 04 Sep 2024 14:07:46 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2500:a01:c57c:1e61:792:2ab1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42c7a41bdc8sm158821485e9.3.2024.09.04.14.07.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 14:07:45 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Sakari Ailus , Laurent Pinchart , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Fabrizio Castro , Lad Prabhakar Subject: [RFC PATCH 03/12] media: i2c: ov5645: Enable runtime PM after v4l2_async_register_subdev() Date: Wed, 4 Sep 2024 22:07:10 +0100 Message-Id: <20240904210719.52466-4-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Lad Prabhakar To simplify the probe error path, enable runtime PM after the v4l2_async_register_subdev() call. This change ensures that runtime PM is only enabled once the subdevice registration is successful, avoiding unnecessary cleanup in the error path. Signed-off-by: Lad Prabhakar --- drivers/media/i2c/ov5645.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index ab3a419df2df..78b86438c798 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -1239,18 +1239,17 @@ static int ov5645_probe(struct i2c_client *client) goto power_down; } - pm_runtime_set_active(dev); - pm_runtime_get_noresume(dev); - pm_runtime_enable(dev); - ov5645_init_state(&ov5645->sd, NULL); ret = v4l2_async_register_subdev(&ov5645->sd); if (ret < 0) { dev_err(dev, "could not register v4l2 device\n"); - goto err_pm_runtime; + goto power_down; } + pm_runtime_set_active(dev); + pm_runtime_get_noresume(dev); + pm_runtime_enable(dev); pm_runtime_set_autosuspend_delay(dev, 1000); pm_runtime_use_autosuspend(dev); pm_runtime_mark_last_busy(dev); @@ -1258,9 +1257,6 @@ static int ov5645_probe(struct i2c_client *client) return 0; -err_pm_runtime: - pm_runtime_disable(dev); - pm_runtime_put_noidle(dev); power_down: ov5645_set_power_off(dev); free_entity: From patchwork Wed Sep 4 21:07:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 825451 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8245517ADE3; Wed, 4 Sep 2024 21:07:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484072; cv=none; b=sNfZ6z4HEELwcYp6a8IyxTi+7IIw4iCVrgnTeJzitqe85wgilrdRqc5MYci8sLk4TVUL0TbPVbwwob1EeszQULhdzl+7KlBGqgCO525Vm7NtYUGvLe30HdhwcNIqYGBmvCfMoWUMu3pk2gEP2mNEXPUJEpRjE94zxK+YTWoXC8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484072; c=relaxed/simple; bh=Kiv17uNGthDImT4AMacEgbQWK5UrKLL4azvkUaL16aU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cc7oa+06S6f9V5ylA2FOxPxYIgpGAEUPzS1v3hDSDQFOj0V/1btzt1BPHPxBCO13BrMi/VNRbQQpAb54wGNXfFT4ZWPF2pBjZK80gyvbPUn1pybCgY1hN3EKRC/8yn4qPxWGm1zZ0YdY3ogEV5KN07aB4Z55zsytlNLjze0ZIqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jwiWTeu/; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jwiWTeu/" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-42c7a384b18so38409315e9.0; Wed, 04 Sep 2024 14:07:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725484069; x=1726088869; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qbuGE6Z/iK7gyKdugxbHWm8tH5fwf4V7+4tVK51cDIA=; b=jwiWTeu//CaIkc2E0PoXRakN+zvI52qVnwz4Bhwuqsfg1jMWWOLkNPo5n/82Cq4sje XPmwf9VGty05HZ+tpkY7rXaU2oySB4+M1eIEnbqrlKfQz+2WxK/CExMMC5cnTHa6ml2F u7CoKmNWLqyodP9AggOXOBNq+SemasTFgHVId4TObfIDUxb4T4RspFOCuOM9VTJpq7Bd wVfC33AT320atjueAWFKz6QzRLRKyF0gzmw75YKpaH/W5NWulbqur2CuzUmoMf5hyOTr fmfcAdPOPV52R8gy1I/0ZETIvyTiI3P1nGos6Obi2L+Tqz3/v0Xa/Jex0Ijh8mOsAdto mKYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725484069; x=1726088869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qbuGE6Z/iK7gyKdugxbHWm8tH5fwf4V7+4tVK51cDIA=; b=aSkCfsGFA02N0LzlVPflBRbhBhy/4vBxwdVPEaVBhoyx/h56D9oJoxtEgaobfd6V+N 92TLEYOqUQ1t0fJv3THo9lUPolVFmw034dPPTSxhFXP2YJ4V8B3aewh7SZstRlDXAhiX P9HqDu2nJVpdqi+lTFEnAZX5wuuXsdAWUPdbXWlmMn8mymuJ/vLdKlPpiMhfGg+8iDOr cq2i2oMZhnuW0ogA5/UhWoWCkofg8xH0RH9HgMd2QHpaNGiT1VSfzdP6RNqHf3QPht7O mD3SRl9xzYd54PtF+28oj4bCOcgMmKl2b+NI0k2QqVRE1d0xITzOM2SId3E7HnXhvsPO 66NQ== X-Forwarded-Encrypted: i=1; AJvYcCW4v4vllz/5GaOrg0rHkWVa5cd/px9WhYhIInq1rKLf9Ji2y4lit2OclnxMGJScBPDTDA5zaZFqdk3eJYarV+dxb7I=@vger.kernel.org, AJvYcCXhC+BVgZjJhBVzuXFcCvY1H3GlC2onU/zhtxZnQXGD+6ZEr9kDRQDsTZkef7fjgdZIlpSdKoML8hoth1o=@vger.kernel.org X-Gm-Message-State: AOJu0YxmpLIkrT7ZxHrhUK8P67a5O+Q+Wasmy/r7w2C2aq83o4VOmTaC voZcOH3OY0FFQ4d/cyyKs5fSF3iegKG4us2anaum2ZwcP+Yqp/ye X-Google-Smtp-Source: AGHT+IFfoLmN74tHSM1gS2e0hyRY3c4mok1G+mSB4+mlKuPUEVTrGwadMKpokwpNQfXY+mm+ZgMGkA== X-Received: by 2002:a05:600c:3146:b0:428:16a0:1c3f with SMTP id 5b1f17b1804b1-42be48faa09mr124645185e9.32.1725484068909; Wed, 04 Sep 2024 14:07:48 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2500:a01:c57c:1e61:792:2ab1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42c7a41bdc8sm158821485e9.3.2024.09.04.14.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 14:07:48 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Sakari Ailus , Laurent Pinchart , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Fabrizio Castro , Lad Prabhakar Subject: [RFC PATCH 05/12] media: i2c: ov5645: Use v4l2_async_register_subdev_sensor() Date: Wed, 4 Sep 2024 22:07:12 +0100 Message-Id: <20240904210719.52466-6-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Lad Prabhakar Make use v4l2_async_register_subdev_sensor() helper to register the subdev. Signed-off-by: Lad Prabhakar --- drivers/media/i2c/ov5645.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index 9e6ff1f1b9ac..45687d004004 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -1223,7 +1223,7 @@ static int ov5645_probe(struct i2c_client *client) ov5645_init_state(&ov5645->sd, NULL); - ret = v4l2_async_register_subdev(&ov5645->sd); + ret = v4l2_async_register_subdev_sensor(&ov5645->sd); if (ret < 0) { dev_err_probe(dev, ret, "could not register v4l2 device\n"); goto power_down; From patchwork Wed Sep 4 21:07:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 825450 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C14A5186E40; Wed, 4 Sep 2024 21:07:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484074; cv=none; b=t0Mw8nHrutiT353ovHZaWH6dmFpSfH92PJ4pgGLFBMAQej4YvVBCoYNWCAKTEWzNM+Ws7aXlfGyqpqG1598gv6gwK1iz/OWAfdscYgAbq7rpzjJtyjcwkdVHY2rcLumxtz8KMQvczEEo1Vn6xYg1BvAMX/hRdFCG/eGhJgOJfJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484074; c=relaxed/simple; bh=Ht70IJcyQJH4Dhqjjac98yUwsL35MwaRODP3k/kTeYo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y4LwBMrJe1U2W8CAgjRrVCSUt/yMFNRuxL1tnFp5UfrIV9mo87jtm5wMGYAYUZunhzz8WdKRTXjX5+U6L3RACzm+kqQgufeho4aUSiRri3v/1c4YRydrazmNhI1iwEEsmNde7eTSrXnijBtkGXJhpB+eGNUg8WS7Iv9T54/Wnu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hEagMnYG; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hEagMnYG" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-42bbe809b06so45963025e9.1; Wed, 04 Sep 2024 14:07:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725484071; x=1726088871; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a8uiJ1o1t/FLwtZAsye5lzWDkjfsKX1SsElvPj0kYXM=; b=hEagMnYGr5GhEsirkwQSLmXCHOSmMvFWmivbhnHxgtkAgOLXnh7bWt8udcnj5rZS1W 9xb7QJHWuYbk6G3GlEtw4vuqCbJCkUzVLGDQpuwN6Y7DRwsGbSJxCW6cUifX2xg+HWew A+xs/DfkgSNkhJtSDCfblbvuBVSsl0V7EcsBrSze3Il1tQcGg9Y2+jOSHXvch8AaNh9P M4Dn3GQREaT36XUFbZO6mNIe6Mdlb64fAIHVUKePUBNcoaabfEM6Baydk86UO6nX7dud 880/ZSFtjEezs0Ph66HAudLor+/IiMnL3fn9z7B8Sv16dujSsfuLoHPujcrhf6qL+zHD qb9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725484071; x=1726088871; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a8uiJ1o1t/FLwtZAsye5lzWDkjfsKX1SsElvPj0kYXM=; b=B+Y1P0ST0sqSlQiV95WqjeLj+5qf08JGttiUDaX3ocdwc7i9LbufJ8sUtgihloBxqk rBTix7JZfp8yyOvZcsJFCHmWkHqllwFQK+LtNwVAWcNuIRHqw97HGYECxnkkM/P6o4T1 OsN7PMLtmsJXlutrbLHV17tqQVv1JggpavktuWkYswkX2KoACyTNO2rzli/KnYaRwD/b xvJMqYi7qspfZnfJaQXnHaxEIZtGziCK0FJ7KaiVf3VhUqdvLzu6KqcAcN5ANI3MuvqF 3dq/eca8T1+XRVBGHB+ArZve/6Olz7vMPa8dQjhx02pMuvs2E7t4w2+FNedzRSNbPu7P nAhA== X-Forwarded-Encrypted: i=1; AJvYcCUcyJD74lr8Guf2xedrGInCdeO6rxmOu1WCkKpET/cgCketfqjiGXpQ5cBGVyadvu/UguFwO5epC8I0GVeMPam0rSQ=@vger.kernel.org, AJvYcCVJUMFcW8iEc6I/t6hznm71INtb5lOd1yHQOgZBxohRASzkCb089dEbEyuCEEyInDsGsjFnEEklhDuZbFY=@vger.kernel.org X-Gm-Message-State: AOJu0YzVxbLlGydM/zcJtBaIXIa06buleKJshiPSD/0OxrvRg2DOQ4kl XC/hDOJTI6iBhsL9xPVH+3EEk4YEePqiz8pYivPT2LaDqWQ/Ll5eEg8PxYWF X-Google-Smtp-Source: AGHT+IEZS+UfmS3KPR+czSjHyVOuYwvsavbrVZc1vnhF2nnFXsx2e4lTetlRGuvsmV1PL1vuTZaNog== X-Received: by 2002:a05:600c:a07:b0:427:abed:3602 with SMTP id 5b1f17b1804b1-42bb27a9e95mr155931335e9.24.1725484071106; Wed, 04 Sep 2024 14:07:51 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2500:a01:c57c:1e61:792:2ab1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42c7a41bdc8sm158821485e9.3.2024.09.04.14.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 14:07:50 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Sakari Ailus , Laurent Pinchart , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Fabrizio Castro , Lad Prabhakar Subject: [RFC PATCH 07/12] media: i2c: ov5645: Use subdev active state Date: Wed, 4 Sep 2024 22:07:14 +0100 Message-Id: <20240904210719.52466-8-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Lad Prabhakar Port the ov5645 sensor driver to use the subdev active state. Move all the format configuration to the subdevice state and simplify the format handling, locking and initialization. Signed-off-by: Lad Prabhakar --- drivers/media/i2c/ov5645.c | 109 +++++++++++++------------------------ 1 file changed, 39 insertions(+), 70 deletions(-) diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index 25c60afcc0ec..9497ec737cb7 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -89,7 +89,6 @@ struct ov5645 { struct v4l2_subdev sd; struct media_pad pad; struct v4l2_fwnode_endpoint ep; - struct v4l2_mbus_framefmt fmt; struct v4l2_rect crop; struct clk *xclk; @@ -850,49 +849,6 @@ static int ov5645_enum_frame_size(struct v4l2_subdev *subdev, return 0; } -static struct v4l2_mbus_framefmt * -__ov5645_get_pad_format(struct ov5645 *ov5645, - struct v4l2_subdev_state *sd_state, - unsigned int pad, - enum v4l2_subdev_format_whence which) -{ - switch (which) { - case V4L2_SUBDEV_FORMAT_TRY: - return v4l2_subdev_state_get_format(sd_state, pad); - case V4L2_SUBDEV_FORMAT_ACTIVE: - return &ov5645->fmt; - default: - return NULL; - } -} - -static int ov5645_get_format(struct v4l2_subdev *sd, - struct v4l2_subdev_state *sd_state, - struct v4l2_subdev_format *format) -{ - struct ov5645 *ov5645 = to_ov5645(sd); - - format->format = *__ov5645_get_pad_format(ov5645, sd_state, - format->pad, - format->which); - return 0; -} - -static struct v4l2_rect * -__ov5645_get_pad_crop(struct ov5645 *ov5645, - struct v4l2_subdev_state *sd_state, - unsigned int pad, enum v4l2_subdev_format_whence which) -{ - switch (which) { - case V4L2_SUBDEV_FORMAT_TRY: - return v4l2_subdev_state_get_crop(sd_state, pad); - case V4L2_SUBDEV_FORMAT_ACTIVE: - return &ov5645->crop; - default: - return NULL; - } -} - static int ov5645_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *format) @@ -903,33 +859,30 @@ static int ov5645_set_format(struct v4l2_subdev *sd, const struct ov5645_mode_info *new_mode; int ret; - __crop = __ov5645_get_pad_crop(ov5645, sd_state, format->pad, - format->which); - + __crop = v4l2_subdev_state_get_crop(sd_state, 0); new_mode = v4l2_find_nearest_size(ov5645_mode_info_data, - ARRAY_SIZE(ov5645_mode_info_data), - width, height, - format->format.width, format->format.height); + ARRAY_SIZE(ov5645_mode_info_data), + width, height, format->format.width, + format->format.height); __crop->width = new_mode->width; __crop->height = new_mode->height; if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) { - ret = v4l2_ctrl_s_ctrl_int64(ov5645->pixel_clock, - new_mode->pixel_clock); + ret = __v4l2_ctrl_s_ctrl_int64(ov5645->pixel_clock, + new_mode->pixel_clock); if (ret < 0) return ret; - ret = v4l2_ctrl_s_ctrl(ov5645->link_freq, - new_mode->link_freq); + ret = __v4l2_ctrl_s_ctrl(ov5645->link_freq, + new_mode->link_freq); if (ret < 0) return ret; ov5645->current_mode = new_mode; } - __format = __ov5645_get_pad_format(ov5645, sd_state, format->pad, - format->which); + __format = v4l2_subdev_state_get_format(sd_state, 0); __format->width = __crop->width; __format->height = __crop->height; __format->code = MEDIA_BUS_FMT_UYVY8_1X16; @@ -944,11 +897,15 @@ static int ov5645_set_format(struct v4l2_subdev *sd, static int ov5645_init_state(struct v4l2_subdev *subdev, struct v4l2_subdev_state *sd_state) { - struct v4l2_subdev_format fmt = { 0 }; - - fmt.which = sd_state ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE; - fmt.format.width = 1920; - fmt.format.height = 1080; + struct v4l2_subdev_format fmt = { + .which = V4L2_SUBDEV_FORMAT_TRY, + .pad = 0, + .format = { + .code = MEDIA_BUS_FMT_UYVY8_1X16, + .width = ov5645_mode_info_data[1].width, + .height = ov5645_mode_info_data[1].height, + }, + }; ov5645_set_format(subdev, sd_state, &fmt); @@ -959,25 +916,27 @@ static int ov5645_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_selection *sel) { - struct ov5645 *ov5645 = to_ov5645(sd); - if (sel->target != V4L2_SEL_TGT_CROP) return -EINVAL; - sel->r = *__ov5645_get_pad_crop(ov5645, sd_state, sel->pad, - sel->which); + sel->r = *v4l2_subdev_state_get_crop(sd_state, 0); return 0; } static int ov5645_s_stream(struct v4l2_subdev *subdev, int enable) { struct ov5645 *ov5645 = to_ov5645(subdev); + struct v4l2_subdev_state *state; int ret; + state = v4l2_subdev_lock_and_get_active_state(&ov5645->sd); + if (enable) { ret = pm_runtime_resume_and_get(ov5645->dev); - if (ret < 0) + if (ret < 0) { + v4l2_subdev_unlock_state(state); return ret; + } ret = ov5645_set_register_array(ov5645, ov5645->current_mode->data, @@ -988,7 +947,7 @@ static int ov5645_s_stream(struct v4l2_subdev *subdev, int enable) ov5645->current_mode->height); goto err_rpm_put; } - ret = v4l2_ctrl_handler_setup(&ov5645->ctrls); + ret = __v4l2_ctrl_handler_setup(&ov5645->ctrls); if (ret < 0) { dev_err(ov5645->dev, "could not sync v4l2 controls\n"); goto err_rpm_put; @@ -1013,6 +972,7 @@ static int ov5645_s_stream(struct v4l2_subdev *subdev, int enable) goto stream_off_rpm_put; } + v4l2_subdev_unlock_state(state); return 0; err_rpm_put: @@ -1022,6 +982,7 @@ static int ov5645_s_stream(struct v4l2_subdev *subdev, int enable) stream_off_rpm_put: pm_runtime_mark_last_busy(ov5645->dev); pm_runtime_put_autosuspend(ov5645->dev); + v4l2_subdev_unlock_state(state); return ret; } @@ -1032,7 +993,7 @@ static const struct v4l2_subdev_video_ops ov5645_video_ops = { static const struct v4l2_subdev_pad_ops ov5645_subdev_pad_ops = { .enum_mbus_code = ov5645_enum_mbus_code, .enum_frame_size = ov5645_enum_frame_size, - .get_fmt = ov5645_get_format, + .get_fmt = v4l2_subdev_get_fmt, .set_fmt = ov5645_set_format, .get_selection = ov5645_get_selection, }; @@ -1213,12 +1174,17 @@ static int ov5645_probe(struct i2c_client *client) goto power_down; } - ov5645_init_state(&ov5645->sd, NULL); + ov5645->sd.state_lock = ov5645->ctrls.lock; + ret = v4l2_subdev_init_finalize(&ov5645->sd); + if (ret < 0) { + dev_err_probe(dev, ret, "subdev init error\n"); + goto power_down; + } ret = v4l2_async_register_subdev_sensor(&ov5645->sd); if (ret < 0) { dev_err_probe(dev, ret, "could not register v4l2 device\n"); - goto power_down; + goto error_subdev_cleanup; } pm_runtime_set_active(dev); @@ -1231,6 +1197,8 @@ static int ov5645_probe(struct i2c_client *client) return 0; +error_subdev_cleanup: + v4l2_subdev_cleanup(&ov5645->sd); power_down: ov5645_set_power_off(dev); free_entity: @@ -1247,6 +1215,7 @@ static void ov5645_remove(struct i2c_client *client) struct ov5645 *ov5645 = to_ov5645(sd); v4l2_async_unregister_subdev(&ov5645->sd); + v4l2_subdev_cleanup(sd); media_entity_cleanup(&ov5645->sd.entity); v4l2_ctrl_handler_free(&ov5645->ctrls); pm_runtime_disable(ov5645->dev); From patchwork Wed Sep 4 21:07:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 825449 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66B25188A2C; Wed, 4 Sep 2024 21:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484077; cv=none; b=ZvWH1j5IOB1e+34E0z7F/8Rzane759jbM4LHzk5+XDVWHBSq/WKxpcqRfuz3/VE4dwr1Rz26dAGaAcz9w4kVZz3hYqBDMHWc72/Ac3qTT2FxHvAQyiHZ/wLeFxu1rV5DIttFX0AXo3kUeLAWGTgl/oY9HFZ5YcMpADmItBjVUgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484077; c=relaxed/simple; bh=apy/83bf7I4kNRjoOT7IzBaFlyBQwcddIcj61s/vSOk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ksp4+gisodqP5AYIChqE0ldMS3DkWa8Bre4grbNkkZ0cvXMxTm749s7yTbzEn5KvnhZADrPgEAO0UZMgeQ4NYdBQBtCcUj0HS/52AqRg/Zv9t1EDKWyFP5YT8S8Pnju4ST5Ar0Liya+24VyJ+GCEi0i5uasiYN2XfAfFhow4QZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=liuYzK5m; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="liuYzK5m" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-42bb81e795bso57365495e9.1; Wed, 04 Sep 2024 14:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725484074; x=1726088874; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yOjJvonRGcQ+cw3Caitccalck6hyNMNmMbmy0DeHlz0=; b=liuYzK5mAdhVd5kX6MpA5zss6gYpAMvwpd7VRwGDWb4NKT6r2yT4xL4yEEWsU7Cium 3v7+a28Gf+nqgk9USkHe2x1Hosba9cfDOh7LnQc07YIPMdh57qU24qVMRgQXL+ekavkx ZrTKay6PQO/nFH8ZRaQpHCImpajpIcCcEJPkpWgr2Emyd4WL1aTDUIwzPLte7xUKzbvz X9TeNqmbmV1s3hFMElCe/ZqlRSwqwd/jy7dczvSFEp3vVOwh3FXDkitKFV+ACTTYqiWg Ko6Sv0t3d7MR9uT/N6+tI4lzBx0TIU+jBbyNB0WShTuLBQycwFaCdZWGPLhuuvox0PNf AFDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725484074; x=1726088874; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yOjJvonRGcQ+cw3Caitccalck6hyNMNmMbmy0DeHlz0=; b=HeLSb1T9jHiabUi2UBbAYIWKB9tqijbOQqqHKJZ87OWaNzmPKpZmLWb8JzS3ZXf6HF YSCaP+qHF7IhkGBLWcLGOEl/kUJ1WSSMHa4grN55a6wDwSL+JlBV+y4awu/gEnLArTqd sVOUDFsurJHOx/Mysw+6GQoyBfAcDbfn0xxRDrGzrBQpInqzCWQUApP0y762OZAEjmsa x8LljYE7eqYNdB/ZlLh6COd6oQdoCb+ZQsvI7dZfOxfHGWO8IHpVS+TKVW+g7dS1yL6x eZgujCz76vV7HYgjHCWwIMuCbWp6e5VaRgVLaHJL3/By5KmdAljSzUkyHBaJ+C+zUjHD upNA== X-Forwarded-Encrypted: i=1; AJvYcCVwXT8fvOeOOK2d0j0zYc6njzn144gjDpSpC19dWVdJ57iERmeQ4Yql8QM4Mcm2xFVq+RGRvZBrRShXYdWwxxIdC4A=@vger.kernel.org, AJvYcCWo9zdJAPJekn9CnkLDhCHeoM/w0D8SJH1Ocu7vj7Q5WP6AlqkHbcGIyislyppuaHo9GFwM/uPHQ6IuRS0=@vger.kernel.org X-Gm-Message-State: AOJu0YxCUvoyNJwaC9Ah9b8hLmZ3dyXiFLoFost8x1+rpMUiSbBJSISH e0L9QWg3B+lKiPoAGtNFA6/FoxjAm/rxI31a2mjZeDqmrb8HxQ0SNUHcospu X-Google-Smtp-Source: AGHT+IH97t1XBKFiU1zdF2evTW8Pdo2F9taSRES/a0mu/hIDdp0cpPpzDpvb6YqT5ng0+pLMF2l48A== X-Received: by 2002:a05:600c:138e:b0:428:c0a:27ea with SMTP id 5b1f17b1804b1-42bbb205ac6mr134731205e9.12.1725484073747; Wed, 04 Sep 2024 14:07:53 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2500:a01:c57c:1e61:792:2ab1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42c7a41bdc8sm158821485e9.3.2024.09.04.14.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 14:07:52 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Sakari Ailus , Laurent Pinchart , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Fabrizio Castro , Lad Prabhakar Subject: [RFC PATCH 09/12] media: i2c: ov5645: Add internal image sink pad Date: Wed, 4 Sep 2024 22:07:16 +0100 Message-Id: <20240904210719.52466-10-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Lad Prabhakar Use the newly added internal pad API to expose the internal configuration of the sensor to userspace in a standard manner. Signed-off-by: Lad Prabhakar --- drivers/media/i2c/ov5645.c | 100 +++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 25 deletions(-) diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index dc93514608ee..e5ec09f44bec 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -60,6 +60,10 @@ #define OV5645_SDE_SAT_U 0x5583 #define OV5645_SDE_SAT_V 0x5584 +#define OV5645_NATIVE_FORMAT MEDIA_BUS_FMT_UYVY8_1X16 +#define OV5645_NATIVE_WIDTH 2592 +#define OV5645_NATIVE_HEIGHT 1944 + /* regulator supplies */ static const char * const ov5645_supply_name[] = { "vdddo", /* Digital I/O (1.8V) supply */ @@ -69,6 +73,12 @@ static const char * const ov5645_supply_name[] = { #define OV5645_NUM_SUPPLIES ARRAY_SIZE(ov5645_supply_name) +enum ov5645_pad_ids { + OV5645_PAD_SOURCE, + OV5645_PAD_IMAGE, + OV5645_NUM_PADS, +}; + struct reg_value { u16 reg; u8 val; @@ -87,7 +97,7 @@ struct ov5645 { struct i2c_client *i2c_client; struct device *dev; struct v4l2_subdev sd; - struct media_pad pad; + struct media_pad pads[OV5645_NUM_PADS]; struct v4l2_fwnode_endpoint ep; struct v4l2_rect crop; struct clk *xclk; @@ -838,13 +848,23 @@ static int ov5645_enum_frame_size(struct v4l2_subdev *subdev, if (fse->code != MEDIA_BUS_FMT_UYVY8_1X16) return -EINVAL; - if (fse->index >= ARRAY_SIZE(ov5645_mode_info_data)) - return -EINVAL; - - fse->min_width = ov5645_mode_info_data[fse->index].width; - fse->max_width = ov5645_mode_info_data[fse->index].width; - fse->min_height = ov5645_mode_info_data[fse->index].height; - fse->max_height = ov5645_mode_info_data[fse->index].height; + if (fse->pad == OV5645_PAD_IMAGE) { + if (fse->index > 0) + return -EINVAL; + + fse->min_width = OV5645_NATIVE_WIDTH; + fse->max_width = OV5645_NATIVE_WIDTH; + fse->min_height = OV5645_NATIVE_HEIGHT; + fse->max_height = OV5645_NATIVE_HEIGHT; + } else { + if (fse->index >= ARRAY_SIZE(ov5645_mode_info_data)) + return -EINVAL; + + fse->min_width = ov5645_mode_info_data[fse->index].width; + fse->max_width = ov5645_mode_info_data[fse->index].width; + fse->min_height = ov5645_mode_info_data[fse->index].height; + fse->max_height = ov5645_mode_info_data[fse->index].height; + } return 0; } @@ -855,18 +875,55 @@ static int ov5645_set_format(struct v4l2_subdev *sd, { struct ov5645 *ov5645 = to_ov5645(sd); struct v4l2_mbus_framefmt *__format; + struct v4l2_rect *compose; struct v4l2_rect *__crop; const struct ov5645_mode_info *new_mode; int ret; - __crop = v4l2_subdev_state_get_crop(sd_state, 0); + if (format->pad != OV5645_PAD_SOURCE) + return v4l2_subdev_get_fmt(sd, sd_state, format); + new_mode = v4l2_find_nearest_size(ov5645_mode_info_data, ARRAY_SIZE(ov5645_mode_info_data), width, height, format->format.width, format->format.height); - - __crop->width = new_mode->width; - __crop->height = new_mode->height; + format->format.code = MEDIA_BUS_FMT_UYVY8_1X16; + format->format.width = new_mode->width; + format->format.height = new_mode->height; + format->format.field = V4L2_FIELD_NONE; + format->format.colorspace = V4L2_COLORSPACE_SRGB; + format->format.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; + format->format.quantization = V4L2_QUANTIZATION_DEFAULT; + format->format.xfer_func = V4L2_XFER_FUNC_DEFAULT; + + __format = v4l2_subdev_state_get_format(sd_state, OV5645_PAD_IMAGE); + *__format = format->format; + __format->code = OV5645_NATIVE_FORMAT; + __format->width = OV5645_NATIVE_WIDTH; + __format->height = OV5645_NATIVE_HEIGHT; + + __crop = v4l2_subdev_state_get_crop(sd_state, OV5645_PAD_IMAGE); + __crop->width = format->format.width; + __crop->height = format->format.height; + + /* + * The compose rectangle models binning, its size is the sensor output + * size. + */ + compose = v4l2_subdev_state_get_compose(sd_state, OV5645_PAD_IMAGE); + compose->left = 0; + compose->top = 0; + compose->width = format->format.width; + compose->height = format->format.height; + + __crop = v4l2_subdev_state_get_crop(sd_state, OV5645_PAD_SOURCE); + __crop->left = 0; + __crop->top = 0; + __crop->width = format->format.width; + __crop->height = format->format.height; + + __format = v4l2_subdev_state_get_format(sd_state, OV5645_PAD_SOURCE); + *__format = format->format; if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) { ret = __v4l2_ctrl_s_ctrl_int64(ov5645->pixel_clock, @@ -882,14 +939,6 @@ static int ov5645_set_format(struct v4l2_subdev *sd, ov5645->current_mode = new_mode; } - __format = v4l2_subdev_state_get_format(sd_state, 0); - __format->width = __crop->width; - __format->height = __crop->height; - __format->code = MEDIA_BUS_FMT_UYVY8_1X16; - __format->field = V4L2_FIELD_NONE; - __format->colorspace = V4L2_COLORSPACE_SRGB; - - format->format = *__format; return 0; } @@ -899,9 +948,9 @@ static int ov5645_init_state(struct v4l2_subdev *subdev, { struct v4l2_subdev_format fmt = { .which = V4L2_SUBDEV_FORMAT_TRY, - .pad = 0, + .pad = OV5645_PAD_SOURCE, .format = { - .code = MEDIA_BUS_FMT_UYVY8_1X16, + .code = OV5645_NATIVE_FORMAT, .width = ov5645_mode_info_data[1].width, .height = ov5645_mode_info_data[1].height, }, @@ -919,7 +968,7 @@ static int ov5645_get_selection(struct v4l2_subdev *sd, if (sel->target != V4L2_SEL_TGT_CROP) return -EINVAL; - sel->r = *v4l2_subdev_state_get_crop(sd_state, 0); + sel->r = *v4l2_subdev_state_get_crop(sd_state, sel->pad); return 0; } @@ -1123,11 +1172,12 @@ static int ov5645_probe(struct i2c_client *client) v4l2_i2c_subdev_init(&ov5645->sd, client, &ov5645_subdev_ops); ov5645->sd.internal_ops = &ov5645_internal_ops; ov5645->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; - ov5645->pad.flags = MEDIA_PAD_FL_SOURCE; + ov5645->pads[OV5645_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE; + ov5645->pads[OV5645_PAD_IMAGE].flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_INTERNAL; ov5645->sd.dev = dev; ov5645->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; - ret = media_entity_pads_init(&ov5645->sd.entity, 1, &ov5645->pad); + ret = media_entity_pads_init(&ov5645->sd.entity, ARRAY_SIZE(ov5645->pads), ov5645->pads); if (ret < 0) { dev_err_probe(dev, ret, "could not register media entity\n"); goto free_ctrl; From patchwork Wed Sep 4 21:07:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 825448 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACF5D18A6B0; Wed, 4 Sep 2024 21:07:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484079; cv=none; b=g1abEJe8WBksvnoGXIrnuSZuGfoPvfv6ReQVD5fmkmW7f5SCBPhSQKjRf4jJypDxXANGUGZAOrFF5w9eWefre0uCVcU+ZStxV9jfPeQfIXKwrymzz5wdqNyQvY6kVEI5fjiSCnXQ89YoncD8DDiQVge44DfjjUJpxY9/lXI1c0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725484079; c=relaxed/simple; bh=0j/GEeuxLu4HcIR1VojcZGXjpw+NsfuHifXNqadlWm0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WVsStfZWPc6KzRaZUa1+eCvqKi652pZ9WZWIeBQemNPUK2zoahaKHDyZ5qSnpMQep4JSJ+tFZmyeIZZWTmKsqEfGCJ/1LRRIqG08cqLCIIanvGNk2V+3o8s7JacOjYwW2bZZ67hfRuYuv4Vw+637V773AuXx/pLkfj7BSAkamco= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VT1CbOC4; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VT1CbOC4" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-42c79deb7c4so38336455e9.3; Wed, 04 Sep 2024 14:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725484076; x=1726088876; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GkG2UKqmGGAU2ZlTW5zJdnvjcvNezmRv0bTbQ21OpnA=; b=VT1CbOC4Jfuxoiv0UtDJu5MMn5izBQmBZasnFBp1lNHiCwBaqqclG+yO81JseOnb/G xRBIjWoQjLl4LRWLy4miXdP33hFmLARgtFZOtcYM9H6szj/rqpyE5y6P998e8JlxKtST 5nOHxMqDOrA/7XkfusK/k6A12r1g58e6FxczxTAnOQs6oLEP1KhHYe8uJRIE35QH5u8S CjA3gqaD2/dqdfpi1lGRZ3YSTrYl/p7XnUlQulwDLhAC2BnjsFYwr/roVzcCRrOLs2nT TFOlMSkMFiVCIeolnmpnTBUSNO0rd3tyN3Y7gj5rtY9HllxfeIv15c7eIum99E9zXY/4 2RhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725484076; x=1726088876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GkG2UKqmGGAU2ZlTW5zJdnvjcvNezmRv0bTbQ21OpnA=; b=gD+/1BaUzLQ03jKscQfIjBJFWFP1xkfE7jFfNwC/x5qszU85Xc8yBLv2tsOp0yW0YJ ZZZww9VAt1AuW1kDTjJ+bTBWe3ahJ03roWe9RDx4GZQJ1S9qaKW2crLd6EM2O99bzH0a w9bRqXj/bz41tKVL4rDXGDWmqbUrQ7eSP9p55rYHtzrvBmUHzvhnfa4b/yi5muOe27Ek vY3XQE3ywHtC7JjxC6A3MyT4tl+DWlsgBIdvOHASUZG1pUyQo5x14+41beEE/sjlvxNV rjhgugnr/trNvLiaZdVQai2hBmqLkIX9WkvhSIoXm8uE00PUEOzOOl6cKrut2I7ERtkP YfVQ== X-Forwarded-Encrypted: i=1; AJvYcCUzLEDZq9m8VEu3rq1ZziEsO4FF9mAkapyBT3MEVao2m2N2vWK0TMLmOQufkm7jRUFNU09LVf59Lon+XwA=@vger.kernel.org, AJvYcCXVjWVFfRAy6sgf7Nwu8F/746Z6elQ8YpAljsGoMuNtl0XScVf6G98LVnrxOQf4h2lHHPEik8d2IAjbv6CT0rsCPlQ=@vger.kernel.org X-Gm-Message-State: AOJu0YywJEMahVcgAhpylYfUnS0iqNQ0nTZ3tM1wg6l2VZS5acwwSpFt aq9/aSNerlNEkWjnYpsE6IUep5hIzLX9LPkAY5jQqC25cVMknrzT X-Google-Smtp-Source: AGHT+IHmQ8DXYWFTgFm8T4pyrIKvxkeZTrDyn2eWsUQJ7y/Ei26juDuXm8eqUcnMxTZA5qtguLTW9w== X-Received: by 2002:a05:600c:3582:b0:42b:9260:235f with SMTP id 5b1f17b1804b1-42c7b5b4b72mr93342855e9.19.1725484076041; Wed, 04 Sep 2024 14:07:56 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2500:a01:c57c:1e61:792:2ab1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42c7a41bdc8sm158821485e9.3.2024.09.04.14.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 14:07:55 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Sakari Ailus , Laurent Pinchart , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Fabrizio Castro , Lad Prabhakar Subject: [RFC PATCH 11/12] media: i2c: ov5645: Report streams using frame descriptors Date: Wed, 4 Sep 2024 22:07:18 +0100 Message-Id: <20240904210719.52466-12-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20240904210719.52466-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Lad Prabhakar Implement the .get_frame_desc() subdev operation to report information about streams to the connected CSI-2 receiver. This is required to let the CSI-2 receiver driver know about virtual channels and data types for each stream. Signed-off-by: Lad Prabhakar --- drivers/media/i2c/ov5645.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index 14010d328e79..45762783a19f 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -829,6 +830,32 @@ static const struct v4l2_ctrl_ops ov5645_ctrl_ops = { .s_ctrl = ov5645_s_ctrl, }; +static int ov5645_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad, + struct v4l2_mbus_frame_desc *fd) +{ + const struct v4l2_mbus_framefmt *fmt; + struct v4l2_subdev_state *state; + + if (pad != OV5645_PAD_SOURCE) + return -EINVAL; + + state = v4l2_subdev_lock_and_get_active_state(sd); + fmt = v4l2_subdev_state_get_format(state, OV5645_PAD_SOURCE, 0); + v4l2_subdev_unlock_state(state); + + fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2; + fd->num_entries = 1; + + memset(fd->entry, 0, sizeof(fd->entry)); + + fd->entry[0].pixelcode = fmt->code; + fd->entry[0].stream = 0; + fd->entry[0].bus.csi2.vc = 0; + fd->entry[0].bus.csi2.dt = MIPI_CSI2_DT_YUV422_8B; + + return 0; +} + static int ov5645_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) @@ -1061,6 +1088,7 @@ static const struct v4l2_subdev_video_ops ov5645_video_ops = { }; static const struct v4l2_subdev_pad_ops ov5645_subdev_pad_ops = { + .get_frame_desc = ov5645_get_frame_desc, .enum_mbus_code = ov5645_enum_mbus_code, .enum_frame_size = ov5645_enum_frame_size, .get_fmt = v4l2_subdev_get_fmt,