From patchwork Tue Apr 16 19:33:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 13632484 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 9125D13B2A2 for ; Tue, 16 Apr 2024 19:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713296057; cv=none; b=iboz5i3iTzBHMxBYuJ7tPnmmq76jB3pTERMMqul7PzCmPXuAPC3Qe6eC1rU07birYHyTPmxc6YHo7blhNtP41jr/H544WLOLIcQSMbG89eBfoz4Nnb8PmLCwT/YE534KKMIktVjq82Ri7r9PmzKX7JkPZfPkF041bS4p0Ggn/bA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713296057; c=relaxed/simple; bh=VseC5ZEVpd8Y3HMrTxnUxiJzqqyabBAr8R5/lBopHaY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bsvc3HwZ3eMOID++/rR9gxQxGNKKxlH8/SD4oa4rg8Hu96jeKE57jPotSqs+ti3S2u3UKIYOYYiartdKbT7oafK8jZZJJtfa4RWS+IdpOvhpvbYysHS5Lk8GJfzdkak1ji6Bx1iXzHUkfYtE+LOBeA1TglT7KZ5j6ikQtPZttCY= 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=Yr/hejd0; arc=none smtp.client-ip=192.198.163.15 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="Yr/hejd0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713296056; x=1744832056; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VseC5ZEVpd8Y3HMrTxnUxiJzqqyabBAr8R5/lBopHaY=; b=Yr/hejd017IXTU/9vljaX6naAyc3ITsIkPOJCq0EnQrBjhdlLn1kGW8P 2c3uD3bdYvMJIHwHmIMfvYZSjBaxPb2kBzT0j9G3KKs4g611+jsFein1R 4vLCviQWAMkxFDPe9TaY3kCYMKjnK7IYU51rfSKNF3xW5m0z1QGIvYOEb 3nDpOkCTPWcu7snLIpC9la9Lx/ZM2drInY3TjXX3F18EdPGgGQVZxZRrn 8kXWQRzmzBoPWP7iZ0nzn9CWUhnINGtWf3Git8nz6IBrq/C13jKtofqU3 WwRD7gJYqR1WmeYXaVf4A3svYnaXKvVwNgVG55Ulx7/4iCN84lEfz8H0H A==; X-CSE-ConnectionGUID: mDpWB9SsQm69ZKR5NTlABg== X-CSE-MsgGUID: TzuxF3A+Qh2e9lBq0+cz/A== X-IronPort-AV: E=McAfee;i="6600,9927,11046"; a="8929867" X-IronPort-AV: E=Sophos;i="6.07,206,1708416000"; d="scan'208";a="8929867" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2024 12:34:14 -0700 X-CSE-ConnectionGUID: QlZmTjp5RD6X9jSV0rjiSg== X-CSE-MsgGUID: uNMFb56DQeOa4Wh4cSz9DA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,206,1708416000"; d="scan'208";a="22380247" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2024 12:34:11 -0700 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 3216611F879; Tue, 16 Apr 2024 22:34:07 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: Laurent Pinchart , tomi.valkeinen@ideasonboard.com, bingbu.cao@intel.com, hongju.wang@intel.com, hverkuil@xs4all.nl, Andrey Konovalov , Jacopo Mondi , Dmitry Perchanov , "Ng, Khai Wen" , Alain Volmat Subject: [PATCH v9 33/46] media: ccs: Compute binning configuration from sub-device state Date: Tue, 16 Apr 2024 22:33:06 +0300 Message-Id: <20240416193319.778192-34-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240416193319.778192-1-sakari.ailus@linux.intel.com> References: <20240416193319.778192-1-sakari.ailus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Calculate binning configuration from sub-device state so the state related configuration can be removed from the driver's device context struct. Signed-off-by: Sakari Ailus Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ccs/ccs-core.c | 56 +++++++++++++++++++------------- drivers/media/i2c/ccs/ccs.h | 3 -- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/drivers/media/i2c/ccs/ccs-core.c b/drivers/media/i2c/ccs/ccs-core.c index f82f3ec37c7c..08e719d611fb 100644 --- a/drivers/media/i2c/ccs/ccs-core.c +++ b/drivers/media/i2c/ccs/ccs-core.c @@ -511,13 +511,36 @@ static int ccs_pll_try(struct ccs_sensor *sensor, struct ccs_pll *pll) return ccs_pll_calculate(&client->dev, &lim, pll); } +static void +ccs_get_binning(struct ccs_sensor *sensor, u8 *binning_mode, u8 *binh, u8 *binv) +{ + struct v4l2_subdev_state *state = + v4l2_subdev_get_locked_active_state(&sensor->binner->sd); + const struct v4l2_rect *sink_crop = + v4l2_subdev_state_get_crop(state, CCS_PAD_SINK, + CCS_STREAM_PIXEL); + const struct v4l2_rect *sink_comp = + v4l2_subdev_state_get_compose(state, CCS_PAD_SINK, + CCS_STREAM_PIXEL); + + if (binning_mode) + *binning_mode = sink_crop->width == sink_comp->width && + sink_crop->height == sink_comp->height ? 0 : 1; + + *binh = sink_crop->width / sink_comp->width; + *binv = sink_crop->height / sink_comp->height; +} + static int ccs_pll_update(struct ccs_sensor *sensor) { struct ccs_pll *pll = &sensor->pll; + u8 binh, binv; int rval; - pll->binning_horizontal = sensor->binning_horizontal; - pll->binning_vertical = sensor->binning_vertical; + ccs_get_binning(sensor, NULL, &binh, &binv); + + pll->binning_horizontal = binh; + pll->binning_vertical = binv; pll->link_freq = sensor->link_freq->qmenu_int[sensor->link_freq->val]; pll->scale_m = sensor->scale_m; @@ -1241,8 +1264,11 @@ static void ccs_update_blanking(struct ccs_sensor *sensor, struct v4l2_ctrl *hblank = sensor->hblank; u16 min_fll, max_fll, min_llp, max_llp, min_lbp; int min, max; + u8 binh, binv; + + ccs_get_binning(sensor, NULL, &binh, &binv); - if (sensor->binning_vertical > 1 || sensor->binning_horizontal > 1) { + if (binv > 1 || binh > 1) { min_fll = CCS_LIM(sensor, MIN_FRAME_LENGTH_LINES_BIN); max_fll = CCS_LIM(sensor, MAX_FRAME_LENGTH_LINES_BIN); min_llp = CCS_LIM(sensor, MIN_LINE_LENGTH_PCK_BIN); @@ -1814,7 +1840,7 @@ static int ccs_enable_streams(struct v4l2_subdev *subdev, v4l2_subdev_state_get_crop(src_state, CCS_PAD_SRC, CCS_STREAM_PIXEL); struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd); - unsigned int binning_mode; + u8 binning_mode, binh, binv; int rval; if (pad != CCS_PAD_SRC) @@ -1836,19 +1862,12 @@ static int ccs_enable_streams(struct v4l2_subdev *subdev, goto err_pm_put; /* Binning configuration */ - if (sensor->binning_horizontal == 1 && - sensor->binning_vertical == 1) { - binning_mode = 0; - } else { - u8 binning_type = - (sensor->binning_horizontal << 4) - | sensor->binning_vertical; + ccs_get_binning(sensor, &binning_mode, &binh, &binv); - rval = ccs_write(sensor, BINNING_TYPE, binning_type); + if (binning_mode) { + rval = ccs_write(sensor, BINNING_TYPE, (binh << 4) | binv); if (rval < 0) goto err_pm_put; - - binning_mode = 1; } rval = ccs_write(sensor, BINNING_MODE, binning_mode); if (rval < 0) @@ -2254,9 +2273,6 @@ static void ccs_propagate(struct v4l2_subdev *subdev, sensor->scale_m = CCS_LIM(sensor, SCALER_N_MIN); sensor->scaling_mode = CCS_SCALING_MODE_NO_SCALING; - } else if (ssd == sensor->binner) { - sensor->binning_horizontal = 1; - sensor->binning_vertical = 1; } } fallthrough; @@ -2530,10 +2546,6 @@ static void ccs_set_compose_binner(struct v4l2_subdev *subdev, best = this; } } - if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) { - sensor->binning_vertical = binv; - sensor->binning_horizontal = binh; - } sel->r.width = (sink_crop->width / binh) & ~1; sel->r.height = (sink_crop->height / binv) & ~1; @@ -3715,8 +3727,6 @@ static int ccs_probe(struct i2c_client *client) sensor->binning_subtypes[i].vertical); } } - sensor->binning_horizontal = 1; - sensor->binning_vertical = 1; if (device_create_file(&client->dev, &dev_attr_ident) != 0) { dev_err(&client->dev, "sysfs ident entry creation failed\n"); diff --git a/drivers/media/i2c/ccs/ccs.h b/drivers/media/i2c/ccs/ccs.h index dcca3f88ea67..aadbd4302607 100644 --- a/drivers/media/i2c/ccs/ccs.h +++ b/drivers/media/i2c/ccs/ccs.h @@ -237,9 +237,6 @@ struct ccs_sensor { u32 embedded_mbus_code; u8 emb_data_ctrl; - u8 binning_horizontal; - u8 binning_vertical; - u8 scale_m; u8 scaling_mode;