From nobody Fri Sep 25 04:44:55 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 53D3A51A736; Wed, 16 Sep 2026 14:35:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569312; cv=none; b=igox/VGZg79STUQlxD+2y63znkOIGtyNKZ2TVsUNJksmjvR+U7vuAKqhgvGGnFhy3+GYjr3nuM0XgQP+reXZkFw/hVDa2gbz8qje/LtLYFEhwcbAkEGI5rcrYPdUpV6j6F7dX0omEJz2V1fvgn8hqevhDlXEmXQlrXrL24MQmP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569312; c=relaxed/simple; bh=FvGUVOZEcuWbC9LQs+V/zTIbuYEusVomNGxq02eco44=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ki5wgo48c6PiDOk9ysMVZBb23Honv+xxRl+xKHIR+pvdpK0BXhRjY33jHbbNW9xdSBhHRu/S1nEXwFE8iYTZ/ddCPVWQ62UqzHiqM2/TGKY948c+N44r10Qpc5iuSgg/kajkGCGMDOJRiqh4t3g/X8GEXwdeK000DCiCLKtc5Cg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=eMFttR/t; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="eMFttR/t" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:85de:a3c9:9357:b164:bf0b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9D7A7C42; Wed, 16 Sep 2026 16:33:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789569205; bh=FvGUVOZEcuWbC9LQs+V/zTIbuYEusVomNGxq02eco44=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eMFttR/t9FQLqeETnJLuJag2cAIPCkhi0pYGmnfJpd8HhuFPyvnL7wrDtPlFKfZt0 ZLV9U8RK0fzalabxOHk578Zz4TSP1eQ+VhqBcumghzm4AGa2g8DCAVXUZ6rZ/1eLhH 9UtW6ATZWJsynsay201hCkSevwUDsa4dyIL2rBaQ= From: Jai Luthra Date: Wed, 16 Sep 2026 20:02:58 +0530 Subject: [PATCH v4 01/10] media: videobuf2-core: Move type check out of vb2_core_expbuf() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-b4-vchiq-isp-v4-1-f668c2017b74@ideasonboard.com> References: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> In-Reply-To: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> To: Florian Fainelli , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Raspberry Pi Kernel Maintenance Cc: Laurent Pinchart , Kieran Bingham , Dave Stevenson , Naushir Patuck , Stefan Wahren , Paul Elder , Hans Verkuil , Tomasz Figa , linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4440; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=FvGUVOZEcuWbC9LQs+V/zTIbuYEusVomNGxq02eco44=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqqqkGCk3aaV9HVW2+A+6AZrJ7VeKT9otmaw0jx EKmuXnM8hqJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaqqpBgAKCRBD3pH5JJpx RSivEACY1JU5qMrt8F0/M/gWupeg0euIJSX2THgAaYFct3DpYBIbbW0ZJjJLEA4Y2ex/wk18rCi 4JP3rW3vYv47DoXVr8CUn1dhaI8I97Kzvbid2YJIJcKCjj+mPHrTIdkRW1228XHos20/N6jXlgt 8SM/evtiI/ADfie2Zuk45HGRSzl6J8EZzpnOMtGo0Q90a6I56hf+NcCDQgQP2NA7jmkBUAaXZPy pT+GJTHLwaXXwmvzQpSg8ZzkZI2qUepm4aMPcjy7399vBKUP5gI1UGCaMQmoPOK0Wrepb/x10Oj LbDh6FqrGXimAeDKF6a8E7jIGihXSgkU62uar367Bi6NNpLInwsuLM5SJCdt6zVT4/vUQFKxUss f8ia+bZUGUjNJLNgmOr+kKOW5Q5qpG+I/giD+pinxhiSE9Q8vQbecVe7rwLTyRDC9QVcilu7//t REIKz+EmtAABWr9dsRG1tHCd6GVVbZDPwsDqDBqAQPVA/BabGanJwu01yg+5aeyzFXFdSWyP9vH /AdyrJVQ+Og1Osj934ETucsXomjTywoj2SO/YvZGwqAqXhD2WUtYGnSXS0rCZbvUgVq5K3ElJks ztit3J3S4n23tCgnR1dC19mw6aarQyeuqTHzpSlIVWl34uyyz8frZTiJz179rvvDVlocqwv50mU Wm3pR0gpY5B8fcg== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 vb2_core_expbuf() takes the type of the exportbuffer as an argument and checks if it matches the type of the vb2 queue. Move that check to the caller (vb2_expbuf). There is only one other user of this, which is dvb-core, where the check was anyway redundant as it passed the vb2 queue type instead. So update it too. Signed-off-by: Jai Luthra Suggested-by: Laurent Pinchart Link: https://lore.kernel.org/all/20260910150454.GP1892234%40killaraus.idea= sonboard.com --- Changes in v4: - New patch in v4 --- drivers/media/common/videobuf2/videobuf2-core.c | 9 ++------- drivers/media/common/videobuf2/videobuf2-v4l2.c | 8 ++++++-- drivers/media/dvb-core/dvb_vb2.c | 3 +-- include/media/videobuf2-core.h | 5 ++--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/medi= a/common/videobuf2/videobuf2-core.c index b0a6084f1757..5e318165659f 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -2419,8 +2419,8 @@ static int __find_plane_by_offset(struct vb2_queue *q= , unsigned long offset, return 0; } =20 -int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, - struct vb2_buffer *vb, unsigned int plane, unsigned int flags) +int vb2_core_expbuf(struct vb2_queue *q, int *fd, struct vb2_buffer *vb, + unsigned int plane, unsigned int flags) { struct vb2_plane *vb_plane; int ret; @@ -2441,11 +2441,6 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, un= signed int type, return -EINVAL; } =20 - if (type !=3D q->type) { - dprintk(q, 1, "invalid buffer type\n"); - return -EINVAL; - } - if (plane >=3D vb->num_planes) { dprintk(q, 1, "buffer plane out of range\n"); return -EINVAL; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/medi= a/common/videobuf2/videobuf2-v4l2.c index 5a1ee5eb9c0f..aee1a9244a7b 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -877,14 +877,18 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_expor= tbuffer *eb) { struct vb2_buffer *vb; =20 + if (eb->type !=3D q->type) { + dprintk(q, 1, "invalid buffer type\n"); + return -EINVAL; + } + vb =3D vb2_get_buffer(q, eb->index); if (!vb) { dprintk(q, 1, "can't find the requested buffer %u\n", eb->index); return -EINVAL; } =20 - return vb2_core_expbuf(q, &eb->fd, eb->type, vb, - eb->plane, eb->flags); + return vb2_core_expbuf(q, &eb->fd, vb, eb->plane, eb->flags); } EXPORT_SYMBOL_GPL(vb2_expbuf); =20 diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_= vb2.c index 672b0efdca21..fe7a6554b30e 100644 --- a/drivers/media/dvb-core/dvb_vb2.c +++ b/drivers/media/dvb-core/dvb_vb2.c @@ -357,8 +357,7 @@ int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, struct dmx_= exportbuffer *exp) return -EINVAL; } =20 - ret =3D vb2_core_expbuf(&ctx->vb_q, &exp->fd, q->type, vb2, - 0, exp->flags); + ret =3D vb2_core_expbuf(&ctx->vb_q, &exp->fd, vb2, 0, exp->flags); if (ret) { dprintk(1, "[%s] index=3D%d errno=3D%d\n", ctx->name, exp->index, ret); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 4b4f4c15c53a..feda638d0064 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -959,7 +959,6 @@ int vb2_core_streamoff(struct vb2_queue *q, unsigned in= t type); * @q: pointer to &struct vb2_queue with videobuf2 queue. * @fd: pointer to the file descriptor associated with DMABUF * (set by driver). - * @type: buffer type. * @vb: pointer to struct &vb2_buffer. * @plane: index of the plane to be exported, 0 for single plane queues * @flags: file flags for newly created file, as defined at @@ -973,8 +972,8 @@ int vb2_core_streamoff(struct vb2_queue *q, unsigned in= t type); * * Return: returns zero on success; an error code otherwise. */ -int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, - struct vb2_buffer *vb, unsigned int plane, unsigned int flags); +int vb2_core_expbuf(struct vb2_queue *q, int *fd, struct vb2_buffer *vb, + unsigned int plane, unsigned int flags); =20 /** * vb2_core_queue_init() - initialize a videobuf2 queue --=20 2.55.0 From nobody Fri Sep 25 04:44:55 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 89190503BD6; Wed, 16 Sep 2026 14:35:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569315; cv=none; b=mO2ETThdD02OQQf7KtM0KTmQ9Au3onQgUaCaHvQQ2F7Z0vF06yl71zqlfojh/ctQu2ACrqJy/dba0kQjqu+0g3kTmrqCFJ/LMrVdn+UQS9yVMPwHDcb88oEdUV2HrgUM2wpDvZECRP5aF7xG/2m7C1rgUkfYaSAzMRFkGxRCYpM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569315; c=relaxed/simple; bh=tzbg7uK5/shkC8bFSCg25CEDhd18zzycIlQF7Bl7Dm4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pHFbZt5RDzo5s6sCT+Muj4G7RZl8yGqv+m/q1L3pe5QDW++GsCdQRoY7v6hPTqykVtNLVRpIImjANh6nXAXxDjThBiCxfbOZRBKrXPxHoWro7x3+ctXgoV+owtKikX96IM9E4pdMhLc3B/iUfKiNMeqeUsK/o0+K0L+ANkkW4Vk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=cRq3EGA9; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cRq3EGA9" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:85de:a3c9:9357:b164:bf0b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BBFC8558; Wed, 16 Sep 2026 16:33:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789569210; bh=tzbg7uK5/shkC8bFSCg25CEDhd18zzycIlQF7Bl7Dm4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=cRq3EGA9s3tXLyKlkiAqhl6/DietXyGcehJcKsDHijGNBw6FNupndiU+4fOpNzFb+ QNUTn4WqoK2lxrhDc+f90UVHXRRP2bOER94vGDdRGJG6Mz1NAKqlnl64X+vXRVd6Jb uuy9ttyucrQbSCdE/pnwcScSC9TGTNJhsrRnTiUM= From: Jai Luthra Date: Wed, 16 Sep 2026 20:02:59 +0530 Subject: [PATCH v4 02/10] platform/raspberrypi: vchiq-mmal: Include missing headers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-b4-vchiq-isp-v4-2-f668c2017b74@ideasonboard.com> References: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> In-Reply-To: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> To: Florian Fainelli , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Raspberry Pi Kernel Maintenance Cc: Laurent Pinchart , Kieran Bingham , Dave Stevenson , Naushir Patuck , Stefan Wahren , Paul Elder , Hans Verkuil , Tomasz Figa , linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1027; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=tzbg7uK5/shkC8bFSCg25CEDhd18zzycIlQF7Bl7Dm4=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqqqkHqgvdDjcklgk3jIZQUjLEBjvIXkYX0fTRd gjpBTV50ZOJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaqqpBwAKCRBD3pH5JJpx Ren8D/9bjXqG5BeWKfJIXufmx78vBS+ow+U0YxDBUFAkVJQGOQbjqkWP02v7LwiLZDPLOtnQsln Xc2fI2twRQxM5OkHNDtrYNQGiFa2+DPDoLN/MVo2YBKhNNNgjR5scYiOUOcivh7+/WKDIe9VmVh 8+V+AavPVPHMVGm4nlL4JkzuEm2HGtqvbRUV+GS/noSNaKHOhsVzWc9q2fXlZ6jdV+YuuMyIEF8 8QyXjOf5q43wF3K+z3nPVie05yE4WaXwAxJJSwzx4qafDC3/8sU1SZ8zyAtsSVMvPgeSvnvU8tt Td91so73hYQAqF/ErBPywTA5ZPkm0ShNjXYDgTKvrJts5Wt36ekZjiYwQS5K1hczpWz3SBQrVg8 Pk9dCu6+gLXU0ELV4MzQXU0oMWSgfcb52/RV1F5SeNxROhfTyVp+kpYW+ZqJxl/N/pwTeyr8mGW Ps2AIWN1LLMPwQX/h/NdI17Wk+7ZGJv4pozDNXZeEVWUWV74fxx16T1D44p6UDqv96L5Olp7yoG T/mCH6CviQt+hmTOrdXPIEfZksZPtTxOHkp7+wc3ixP20l1GfOnaNez9VBfaqm/wnFYOGiFIpu4 FUzMAKC5u6mSrOznTXNQUYLH7TrW7eM+M7WSpqZHCNXJMBkKbu+N4+xcktvkvUg0bdMWgh5almC V0LfX8NVhStH6wg== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 The structures defined in mmal-common.h use types related to lists and videobuf2 framework, but are missing the explicit includes for them. Include those. Reviewed-by: Paul Elder Tested-by: Paul Elder Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h b/driver= s/platform/raspberrypi/vchiq-mmal/mmal-common.h index 6c5092a68b99..c9976bdd7490 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h @@ -16,6 +16,10 @@ #ifndef MMAL_COMMON_H #define MMAL_COMMON_H =20 +#include +#include +#include + #define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24)) #define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l') =20 --=20 2.55.0 From nobody Fri Sep 25 04:44:55 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 615C151E445; Wed, 16 Sep 2026 14:35:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569322; cv=none; b=rJcIJBrVfOngdCiElmeY2eVaa4+eOrap4n0AuIdCTKeP1IXlS75IbFFuzOJ6F1l/vB0YuT+iAJJ4ErOSsoLQn9zTPiD3UDveg7rD64+UB0dDXiWiQ4emUCDMaPRen8xCiUoyqY6HKjkspDHAj1Roro2W75Ji5p99CvD2y5ftRkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569322; c=relaxed/simple; bh=KSSsHTc9gJYpazA8M0o8Qe2DWIJZPucRqQvEDKeihqQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PwJ0eleFC7uiDHRVWrXbmVrZ5Yo0kmXrVedbogEXZ0RphiWLu3oXWF5JdQdBB6ac14N5A9xdKE1rYrq18KZeenD1IdCUBWOnzruP/4H61PcxWfmY4bIeWAiBedacLpWpQC94T3Mcs6aKgtm8QSyoAG5IBjgbc7KMTf6oQohUuso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=GekojWnI; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="GekojWnI" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:85de:a3c9:9357:b164:bf0b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F3FEFC42; Wed, 16 Sep 2026 16:33:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789569215; bh=KSSsHTc9gJYpazA8M0o8Qe2DWIJZPucRqQvEDKeihqQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GekojWnI+WolWKrWhWPUDsOv8f/y7d8/GgaZzFof5+E9jrz5j2Ay39+uzmtO6TntI fbn3PcQ2U1XLIuJHUp1klMRRbWxIrgZl/ec7Fy7MOiHOxveEVXRS3t95Du0sqimAK6 KHhCZbRasgjr5JKLePYbThzR81/UmNceF/eo5q+A= From: Jai Luthra Date: Wed, 16 Sep 2026 20:03:00 +0530 Subject: [PATCH v4 03/10] platform/raspberrypi: vchiq-mmal: Move headers to include/linux Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-b4-vchiq-isp-v4-3-f668c2017b74@ideasonboard.com> References: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> In-Reply-To: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> To: Florian Fainelli , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Raspberry Pi Kernel Maintenance Cc: Laurent Pinchart , Kieran Bingham , Dave Stevenson , Naushir Patuck , Stefan Wahren , Paul Elder , Hans Verkuil , Tomasz Figa , linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4969; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=KSSsHTc9gJYpazA8M0o8Qe2DWIJZPucRqQvEDKeihqQ=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqqqkIvm6Xh6/9IpN1WWwxqCzrZaPcy976Ast6T rgOMr7LmxGJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaqqpCAAKCRBD3pH5JJpx RToRD/4+CK1TAXY3qFzDwL3vohDEKltLkhIcxWU5Y0LE0VJi7APobM0NshJtsYoNbkxl9N+rTdI hsb3+x63inGRN8fiQSLPWu3xK3/RFz9q3DZ/ACzvPLQhQVKia7S2Aass7zQhwPR+Bfdr9rFAPxT /kao5EjBHWph+8MEm/OuWGY8ivp0djtpPzMQmK5aCq3KgDmbS17dfWtegjtmzW+TMoiXPxXfldd hA8KxFUdwxyzHOrParnrGew43ixEfE6Vom/utDVbqjDr4e2gv/AIlg/UwqKIg3Zd4jT/DSIwq5G JoawdyUp81Cwuz87Y446Xmcm0qpL+rWqW0BRK5JoqQ4nk6eJ1TfewkRb1IemWo3pyL4zekQnSKe EHM4Zol4W0sSsD2WPcpt/eXu7XWbcBYvYFOoUEGxrrOed0hGuMZ7HeynVGX0177M6Lo89CBsz7S MnVLTDKAIJUqhOZ9CFrxKpI5CoQNg9VB9601IpSVhRcs5l4ysKDr3cUSjZviONDDfeNPTqSqc/E XNg9mTn9xdngoAxTB3sTCDCiFdPovu8jpI8Wd+OJT7sNAB04oNqoUq4DLCwnykNB2Vp5DyAiooM 0/DrA1O7ulbrUI/d3zPsJfuha/76v1o1tSk+fQu7R2QM1Zku4Y/jbdtc7VZMYzgn8U9OTYx1QRE cCU4rvbNtnqZB1g== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 Now that VCHIQ interface is destaged, different drivers (like ISP or codec) no longer live under the same tree as VCHIQ-MMAL, but in their relevant trees like media or audio. Enable access to the MMAL headers for such drivers by moving them under include/linux/raspberrypi with other VCHIQ headers. Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Tested-by: Paul Elder Signed-off-by: Jai Luthra --- Changes in v4: - None Changes in v3: - Split missing includes patch - Update commit message --- MAINTAINERS | 1 + drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c | 9 ++++-= ---- .../vchiq-mmal =3D> include/linux/raspberrypi}/mmal-common.h | 0 .../vchiq-mmal =3D> include/linux/raspberrypi}/mmal-encodings.h | 0 .../vchiq-mmal =3D> include/linux/raspberrypi}/mmal-msg-common.h | 0 .../vchiq-mmal =3D> include/linux/raspberrypi}/mmal-msg-format.h | 0 .../vchiq-mmal =3D> include/linux/raspberrypi}/mmal-msg-port.h | 0 .../vchiq-mmal =3D> include/linux/raspberrypi}/mmal-msg.h | 0 .../vchiq-mmal =3D> include/linux/raspberrypi}/mmal-parameters.h | 0 .../vchiq-mmal =3D> include/linux/raspberrypi}/mmal-vchiq.h | 0 10 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index b887ac593088..0ac9a9d7b215 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5160,6 +5160,7 @@ F: Documentation/devicetree/bindings/pci/brcm,stb-pci= e.yaml F: drivers/pci/controller/pcie-brcmstb.c F: drivers/platform/raspberrypi/vchiq-* F: drivers/staging/vc04_services +F: include/linux/raspberrypi/mmal* F: include/linux/raspberrypi/vchiq* N: bcm2711 N: bcm2712 diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c b/drivers= /platform/raspberrypi/vchiq-mmal/mmal-vchiq.c index ccd8910c315f..80406e1f4bdc 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c @@ -22,17 +22,16 @@ #include #include #include +#include +#include +#include +#include #include #include #include #include #include =20 -#include "mmal-common.h" -#include "mmal-parameters.h" -#include "mmal-vchiq.h" -#include "mmal-msg.h" - /* * maximum number of components supported. * This matches the maximum permitted by default on the VPU diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h b/includ= e/linux/raspberrypi/mmal-common.h similarity index 100% rename from drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h rename to include/linux/raspberrypi/mmal-common.h diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-encodings.h b/inc= lude/linux/raspberrypi/mmal-encodings.h similarity index 100% rename from drivers/platform/raspberrypi/vchiq-mmal/mmal-encodings.h rename to include/linux/raspberrypi/mmal-encodings.h diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-msg-common.h b/in= clude/linux/raspberrypi/mmal-msg-common.h similarity index 100% rename from drivers/platform/raspberrypi/vchiq-mmal/mmal-msg-common.h rename to include/linux/raspberrypi/mmal-msg-common.h diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-msg-format.h b/in= clude/linux/raspberrypi/mmal-msg-format.h similarity index 100% rename from drivers/platform/raspberrypi/vchiq-mmal/mmal-msg-format.h rename to include/linux/raspberrypi/mmal-msg-format.h diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-msg-port.h b/incl= ude/linux/raspberrypi/mmal-msg-port.h similarity index 100% rename from drivers/platform/raspberrypi/vchiq-mmal/mmal-msg-port.h rename to include/linux/raspberrypi/mmal-msg-port.h diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-msg.h b/include/l= inux/raspberrypi/mmal-msg.h similarity index 100% rename from drivers/platform/raspberrypi/vchiq-mmal/mmal-msg.h rename to include/linux/raspberrypi/mmal-msg.h diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-parameters.h b/in= clude/linux/raspberrypi/mmal-parameters.h similarity index 100% rename from drivers/platform/raspberrypi/vchiq-mmal/mmal-parameters.h rename to include/linux/raspberrypi/mmal-parameters.h diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.h b/include= /linux/raspberrypi/mmal-vchiq.h similarity index 100% rename from drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.h rename to include/linux/raspberrypi/mmal-vchiq.h --=20 2.55.0 From nobody Fri Sep 25 04:44:55 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 80B0451FCA1; Wed, 16 Sep 2026 14:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569330; cv=none; b=UjmqmxCLPHji3xU9tYHJe1LAErcxbD4mqgoFMaXGNzypIcYsddExtNBYJbWvy3klBfu3VdO/lPNEHN71zZQsa58FwKDKqxFagJ7dPSEHqFw4Bcsp/ShUAo/8r4dbhkd8B0dXJ911qrDw62gm1ijYyHKHl5R9CXOJZGUmiJ9+uu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569330; c=relaxed/simple; bh=PtE3Vyu8LhL91vyyfDT/RYd/NOj7T4Vv0mz2W3PFV/A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Oeq7+9Dj/J2b3nwVaCYpCWtllpHtBsXqDAk2ZQAtvg8IE5nK2YZdPh8vRLyxmQKJjj9o7QFMwn4AYutD7uLuXQJGBn0d/NwLfJgBUosaid4Fcf5LVxqrlWIjtO6dyVFh86cTSsmgITutNadQBH/rROmYQpE2aq/Tt0a5+hMKvRs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=SuQVFvSq; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SuQVFvSq" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:85de:a3c9:9357:b164:bf0b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 35AFC558; Wed, 16 Sep 2026 16:33:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789569220; bh=PtE3Vyu8LhL91vyyfDT/RYd/NOj7T4Vv0mz2W3PFV/A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SuQVFvSqynZFImyRdCrd95RL+IsQjWR+v+Nth+k3vcdGTeD4ptAPMKXi8TLFBRCtH ei+pSSkAcYC3UOzI9lb+NvAv/M9Z6Fkl5E31I95i3A8Z4WsB6SzKsWLpYyx1qJyFe0 JV1mkdYK3P8xa/poaaefazgsvpGLYEPO0BfDzLuU= From: Jai Luthra Date: Wed, 16 Sep 2026 20:03:01 +0530 Subject: [PATCH v4 04/10] platform/raspberrypi: vchiq-mmal: Support ISP parameters and stats Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-b4-vchiq-isp-v4-4-f668c2017b74@ideasonboard.com> References: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> In-Reply-To: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> To: Florian Fainelli , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Raspberry Pi Kernel Maintenance Cc: Laurent Pinchart , Kieran Bingham , Dave Stevenson , Naushir Patuck , Stefan Wahren , Paul Elder , Hans Verkuil , Tomasz Figa , linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4934; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=PtE3Vyu8LhL91vyyfDT/RYd/NOj7T4Vv0mz2W3PFV/A=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqqqkJw3Bq4OAd3fIISBcdnNKsiK3cl/AqDiF7y KxyGOokWceJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaqqpCQAKCRBD3pH5JJpx RfyVD/4lW5gy5Z12q0WrIdlxHhH3lFEZayyoHjo9GpvTNAXszfIaxjSoBPEfx8EiPlEwcNQkQ2S cZLWDawiwRxOnUYPCkPggPVnHmfp+s4gTcLfKSOtmvEmOF1SCbZUSCXJxrqEd9QGK6r3Wt/hAlI 68B+j6Pu+i57y3r62ao6QZ3mXIdvgeADqVJLMr13bs6skFEEIcp7LFt/DrY6ARVQ/bLvp0u1jYy lNNOVPBXI5AJxAd5n4evwLHROFa0Jthhwn/hVfFrqd4oWXT1gFx4kQzySA7PzK+aZAtb8HANjZb 4F49dgZSeIX82ywCdlqhPIBqnU5XPdqrbaTkXke9i4UeELbIS25lMpA4zGvj2Emye+0SCk/d2n2 4husk933IYRaMPmVcN3ZzFDCCL5llqDz0YFIqVvPZkOOPPrZabdAjvvIQdBC8tKuQqZ4NUWvsO+ lG1EsKQ56wUVL1W9+JdOhn8P8SMvFkF6i/l6IqxgBc+qFZX0qnfUlGA39ilKLAO237+xusdT298 CC0m5DGuvESS8vLogsBqxol8LFaGrnghi9wFlkshQK4tEj++wNpyKVjPvFbwdAzyKoO9k8qWGUf oG0IUXuj2JEpdjRHIMV4SjSpGkd4+DA3vztCQ6lp7E+5GtO/kTuYTwEAxUaa9KfLoQmOIdKZOfc Tpz4smrkZlkukgA== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 The ISP used on BCM2835 and derivative platforms is behind the VCHIQ bus, where some parameters and statistics are accessed through the MMAL layer. So add the relevant structures, macros and enum values. Reviewed-by: Paul Elder Tested-by: Paul Elder Signed-off-by: Jai Luthra --- include/linux/raspberrypi/mmal-encodings.h | 4 ++ include/linux/raspberrypi/mmal-parameters.h | 86 +++++++++++++++++++++++++= ++++ 2 files changed, 90 insertions(+) diff --git a/include/linux/raspberrypi/mmal-encodings.h b/include/linux/ras= pberrypi/mmal-encodings.h index e15ae7b24f73..eadf2e981408 100644 --- a/include/linux/raspberrypi/mmal-encodings.h +++ b/include/linux/raspberrypi/mmal-encodings.h @@ -73,6 +73,10 @@ */ #define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I') =20 +/** ISP image statistics format + */ +#define MMAL_ENCODING_BRCM_STATS MMAL_FOURCC('S', 'T', 'A', 'T') + /* }@ */ =20 /** \name Pre-defined audio encodings */ diff --git a/include/linux/raspberrypi/mmal-parameters.h b/include/linux/ra= spberrypi/mmal-parameters.h index a0cdd28101f2..6ae5a7a1932c 100644 --- a/include/linux/raspberrypi/mmal-parameters.h +++ b/include/linux/raspberrypi/mmal-parameters.h @@ -223,6 +223,64 @@ enum mmal_parameter_camera_type { MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */ MMAL_PARAMETER_CUSTOM_AWB_GAINS, + /**< Takes a @ref MMAL_PARAMETER_CAMERA_SETTINGS_T */ + MMAL_PARAMETER_CAMERA_SETTINGS, + /**< Takes a @ref MMAL_PARAMETER_PRIVACY_INDICATOR_T */ + MMAL_PARAMETER_PRIVACY_INDICATOR, + /**< Takes a @ref MMAL_PARAMETER_BOOLEAN_T */ + MMAL_PARAMETER_VIDEO_DENOISE, + /**< Takes a @ref MMAL_PARAMETER_BOOLEAN_T */ + MMAL_PARAMETER_STILLS_DENOISE, + /**< Takes a @ref MMAL_PARAMETER_CAMERA_ANNOTATE_T */ + MMAL_PARAMETER_ANNOTATE, + /**< Takes a @ref MMAL_PARAMETER_STEREOSCOPIC_MODE_T */ + MMAL_PARAMETER_STEREOSCOPIC_MODE, + /**< Takes a @ref MMAL_PARAMETER_CAMERA_INTERFACE_T */ + MMAL_PARAMETER_CAMERA_INTERFACE, + /**< Takes a @ref MMAL_PARAMETER_CAMERA_CLOCKING_MODE_T */ + MMAL_PARAMETER_CAMERA_CLOCKING_MODE, + /**< Takes a @ref MMAL_PARAMETER_CAMERA_RX_CONFIG_T */ + MMAL_PARAMETER_CAMERA_RX_CONFIG, + /**< Takes a @ref MMAL_PARAMETER_CAMERA_RX_TIMING_T */ + MMAL_PARAMETER_CAMERA_RX_TIMING, + /**< Takes a @ref MMAL_PARAMETER_UINT32_T */ + MMAL_PARAMETER_DPF_CONFIG, + + /* 0x50 */ + /**< Takes a @ref MMAL_PARAMETER_UINT32_T */ + MMAL_PARAMETER_JPEG_RESTART_INTERVAL, + /**< Takes a @ref MMAL_PARAMETER_UINT32_T */ + MMAL_PARAMETER_CAMERA_ISP_BLOCK_OVERRIDE, + /**< Takes a @ref MMAL_PARAMETER_LENS_SHADING_T */ + MMAL_PARAMETER_LENS_SHADING_OVERRIDE, + /**< Takes a @ref MMAL_PARAMETER_UINT32_T */ + MMAL_PARAMETER_BLACK_LEVEL, + /**< Takes a @ref MMAL_PARAMETER_RESIZE_T */ + MMAL_PARAMETER_RESIZE_PARAMS, + /**< Takes a @ref MMAL_PARAMETER_CROP_T */ + MMAL_PARAMETER_CROP, + /**< Takes a @ref MMAL_PARAMETER_INT32_T */ + MMAL_PARAMETER_OUTPUT_SHIFT, + /**< Takes a @ref MMAL_PARAMETER_INT32_T */ + MMAL_PARAMETER_CCM_SHIFT, + /**< Takes a @ref MMAL_PARAMETER_CUSTOM_CCM_T */ + MMAL_PARAMETER_CUSTOM_CCM, + /**< Takes a @ref MMAL_PARAMETER_RATIONAL_T */ + MMAL_PARAMETER_ANALOG_GAIN, + /**< Takes a @ref MMAL_PARAMETER_RATIONAL_T */ + MMAL_PARAMETER_DIGITAL_GAIN, + /**< Takes a @ref MMAL_PARAMETER_DENOISE_T */ + MMAL_PARAMETER_DENOISE, + /**< Takes a @ref MMAL_PARAMETER_SHARPEN_T */ + MMAL_PARAMETER_SHARPEN, + /**< Takes a @ref MMAL_PARAMETER_GEQ_T */ + MMAL_PARAMETER_GEQ, + /**< Tales a @ref MMAP_PARAMETER_DPC_T */ + MMAL_PARAMETER_DPC, + /**< Tales a @ref MMAP_PARAMETER_GAMMA_T */ + MMAL_PARAMETER_GAMMA, + /**< Takes a @ref MMAL_PARAMETER_CDN_T */ + MMAL_PARAMETER_CDN, }; =20 enum mmal_parameter_camera_config_timestamp_mode { @@ -749,4 +807,32 @@ struct mmal_parameter_camera_info { flashes[MMAL_PARAMETER_CAMERA_INFO_MAX_FLASHES]; }; =20 +enum mmal_parameter_ls_gain_format_type { + MMAL_PARAMETER_LS_GAIN_FORMAT_TYPE_U0P8_1 =3D 0, + MMAL_PARAMETER_LS_GAIN_FORMAT_TYPE_U1P7_0 =3D 1, + MMAL_PARAMETER_LS_GAIN_FORMAT_TYPE_U1P7_1 =3D 2, + MMAL_PARAMETER_LS_GAIN_FORMAT_TYPE_U2P6_0 =3D 3, + MMAL_PARAMETER_LS_GAIN_FORMAT_TYPE_U2P6_1 =3D 4, + MMAL_PARAMETER_LS_GAIN_FORMAT_TYPE_U3P5_0 =3D 5, + MMAL_PARAMETER_LS_GAIN_FORMAT_TYPE_U3P5_1 =3D 6, + MMAL_PARAMETER_LS_GAIN_FORMAT_TYPE_U4P10 =3D 7, + MMAL_PARAMETER_LS_GAIN_FORMAT_TYPE_DUMMY =3D 0x7FFFFFFF +}; + +struct mmal_parameter_lens_shading_v2 { + u32 enabled; + u32 grid_cell_size; + u32 grid_width; + u32 grid_stride; + u32 grid_height; + u32 mem_handle_table; + u32 ref_transform; + u32 corner_sampled; + enum mmal_parameter_ls_gain_format_type gain_format; +}; + +struct mmal_parameter_crop { + struct vchiq_mmal_rect rect; +}; + #endif --=20 2.55.0 From nobody Fri Sep 25 04:44:55 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 1423551FCDF; Wed, 16 Sep 2026 14:35:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569334; cv=none; b=qUN9yTFIJulCDlCEIWTqYSBKeitceyiOaoXSJIwkIdMTeMZHugr3Z2C+R32FdVFkmeA30yatNgaHkA4bo1hv3kHEmTXppc0qOetd+Z+WM72X0HSRBeEkLxwD4VJUAInjlOnFgqhpeZlwyQ8NK5udUjsnELztdQjF/nPsxX67nfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569334; c=relaxed/simple; bh=iCNntByuagri6GX/0cHOmsW0p43nmuVacSBdZuqEa5U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uSqJD+ZEpYU4ke2tXnozfoAVpi25VkVi0O5G3lHoVoC4hf2QdJdRJeYGtQrahN7r7Ix78PvI1JZuNFOz7tKVktgmhI4LkFd0hAC3cjKz54AXuO4AuBM6W+QQjYGVsr1bUNGkPJVctyFB3EcMg3KoUBf1Ep/G/AzFwaOsx6Bje98= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=AaD95zpC; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="AaD95zpC" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:85de:a3c9:9357:b164:bf0b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 80AA9C42; Wed, 16 Sep 2026 16:33:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789569225; bh=iCNntByuagri6GX/0cHOmsW0p43nmuVacSBdZuqEa5U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AaD95zpCA7JqphxXvFn1Z8hcaC2VYDyGvvtFXAOFmv5zfKP8fz341yqs8d+I+upzM qbE8F1PgRdfM6FbmjqgGf8kYTwurku77/ReAP4C/gRt9Qm/YKGIYwMGFWitmuFo3CK VBlowqD1lJ9RvwMwa1/FQVJLuS7kM3mGxNa3mSNI= From: Jai Luthra Date: Wed, 16 Sep 2026 20:03:02 +0530 Subject: [PATCH v4 05/10] platform/raspberrypi: vchiq-mmal: Support bayer and gray formats Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-b4-vchiq-isp-v4-5-f668c2017b74@ideasonboard.com> References: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> In-Reply-To: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> To: Florian Fainelli , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Raspberry Pi Kernel Maintenance Cc: Laurent Pinchart , Kieran Bingham , Dave Stevenson , Naushir Patuck , Stefan Wahren , Paul Elder , Hans Verkuil , Tomasz Figa , linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4390; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=iCNntByuagri6GX/0cHOmsW0p43nmuVacSBdZuqEa5U=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqqqkKqVMsKpIl+BUu4WJMnEGR3YgWLNg1WJby2 U0Bgaxbf7OJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaqqpCgAKCRBD3pH5JJpx RRRxEADMitT8GMDyJdET/NF5LtegEltL/hpczmWuzcX2PImtu+GLMi8+XpAhZ5toDhGZjZ00eJp B12b23i3WD3WWutesbIZBzeiXSAxO7KBntCyyOgz6tBTXPcjzC/J5HaMtoSCcKhQ6O1D05JoyB0 gfGQDQBX9q164rftgNHQInHDeJQulNdKihaf8IDdh1OdvHjfJS96P2lOSkDbhw+xP8TAcodZ6oq LCRanEiSZTxcJ2eeQ4NSL5z8C3hlqMwBzJ6QRZpwo8m4P0NaI0H9e/mT6d7zqNSl5V347jb5hF/ j1QmJhVxQN8ca7YyUPLNzGK72IodK2/T0AyREd74qLGglcLhQTSMXcbunU5gpk5QLZlVHKUQEcb BsQeWytukIKfR/A9309/AAfS7dshNuwXFizoj7Kd4p9RCUa3DHV1hkJeRPEmdlrl5Y75zincshd kYhmDpSH3GuDqBkW0JMSptnSwrugLchB6HbXljwAuWA5FrLjkE5MaclGgMyb4vlq6ADf8pJheFd 9RnoobMPuZ9tEguJ/t9obFgsv8dJ3kVC8XVzQMAe3yeRGqn8RMoS3MD9ldnzqxxS3KvOjamIL4B 9yFSwEOIgNCItVUIxJZJGKGy2IeQ8k/bFp1IAxr2h60IvUVGReSB63+N4tmALFIxHmRlXzkvdcC 9PrbvAsrfvccQUw== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 Raw camera sensors often send data as packed or unpacked bayer and gray formats, which needs to be processed by the ISP. Add macros to support bayer and gray format FOURCCs in the MMAL layer. Tested-by: Paul Elder Signed-off-by: Jai Luthra --- Changes in v4: - Drop comment about FourCC values being copied from V4L2 --- include/linux/raspberrypi/mmal-encodings.h | 63 ++++++++++++++++++++++++++= ++++ 1 file changed, 63 insertions(+) diff --git a/include/linux/raspberrypi/mmal-encodings.h b/include/linux/ras= pberrypi/mmal-encodings.h index eadf2e981408..fd9cd840cb7b 100644 --- a/include/linux/raspberrypi/mmal-encodings.h +++ b/include/linux/raspberrypi/mmal-encodings.h @@ -69,6 +69,69 @@ */ #define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V') =20 +/** + * Bayer formats + */ +/* 8 bit per pixel Bayer formats. */ +#define MMAL_ENCODING_BAYER_SBGGR8 MMAL_FOURCC('B', 'A', '8', '1') +#define MMAL_ENCODING_BAYER_SGBRG8 MMAL_FOURCC('G', 'B', 'R', 'G') +#define MMAL_ENCODING_BAYER_SGRBG8 MMAL_FOURCC('G', 'R', 'B', 'G') +#define MMAL_ENCODING_BAYER_SRGGB8 MMAL_FOURCC('R', 'G', 'G', 'B') + +/* 10 bit per pixel packed Bayer formats. */ +#define MMAL_ENCODING_BAYER_SBGGR10P MMAL_FOURCC('p', 'B', 'A', 'A') +#define MMAL_ENCODING_BAYER_SGRBG10P MMAL_FOURCC('p', 'g', 'A', 'A') +#define MMAL_ENCODING_BAYER_SGBRG10P MMAL_FOURCC('p', 'G', 'A', 'A') +#define MMAL_ENCODING_BAYER_SRGGB10P MMAL_FOURCC('p', 'R', 'A', 'A') + +/* 12 bit per pixel packed Bayer formats. */ +#define MMAL_ENCODING_BAYER_SBGGR12P MMAL_FOURCC('p', 'B', '1', '2') +#define MMAL_ENCODING_BAYER_SGRBG12P MMAL_FOURCC('p', 'g', '1', '2') +#define MMAL_ENCODING_BAYER_SGBRG12P MMAL_FOURCC('p', 'G', '1', '2') +#define MMAL_ENCODING_BAYER_SRGGB12P MMAL_FOURCC('p', 'R', '1', '2') + +/* 14 bit per pixel packed Bayer formats. */ +#define MMAL_ENCODING_BAYER_SBGGR14P MMAL_FOURCC('p', 'B', 'E', 'E') +#define MMAL_ENCODING_BAYER_SGBRG14P MMAL_FOURCC('p', 'G', 'E', 'E') +#define MMAL_ENCODING_BAYER_SGRBG14P MMAL_FOURCC('p', 'g', 'E', 'E') +#define MMAL_ENCODING_BAYER_SRGGB14P MMAL_FOURCC('p', 'R', 'E', 'E') + +/* 16 bit per pixel Bayer formats. */ +#define MMAL_ENCODING_BAYER_SBGGR16 MMAL_FOURCC('B', 'G', '1', '6') +#define MMAL_ENCODING_BAYER_SGBRG16 MMAL_FOURCC('G', 'B', '1', '6') +#define MMAL_ENCODING_BAYER_SGRBG16 MMAL_FOURCC('G', 'R', '1', '6') +#define MMAL_ENCODING_BAYER_SRGGB16 MMAL_FOURCC('R', 'G', '1', '6') + +/* 10 bit per pixel unpacked (16bit) Bayer formats. */ +#define MMAL_ENCODING_BAYER_SBGGR10 MMAL_FOURCC('B', 'G', '1', '0') +#define MMAL_ENCODING_BAYER_SGRBG10 MMAL_FOURCC('B', 'A', '1', '0') +#define MMAL_ENCODING_BAYER_SGBRG10 MMAL_FOURCC('G', 'B', '1', '0') +#define MMAL_ENCODING_BAYER_SRGGB10 MMAL_FOURCC('R', 'G', '1', '0') + +/* 12 bit per pixel unpacked (16bit) Bayer formats */ +#define MMAL_ENCODING_BAYER_SBGGR12 MMAL_FOURCC('B', 'G', '1', '2') +#define MMAL_ENCODING_BAYER_SGRBG12 MMAL_FOURCC('B', 'A', '1', '2') +#define MMAL_ENCODING_BAYER_SGBRG12 MMAL_FOURCC('G', 'B', '1', '2') +#define MMAL_ENCODING_BAYER_SRGGB12 MMAL_FOURCC('R', 'G', '1', '2') + +/* 14 bit per pixel unpacked (16bit) Bayer formats */ +#define MMAL_ENCODING_BAYER_SBGGR14 MMAL_FOURCC('B', 'G', '1', '4') +#define MMAL_ENCODING_BAYER_SGBRG14 MMAL_FOURCC('G', 'B', '1', '4') +#define MMAL_ENCODING_BAYER_SGRBG14 MMAL_FOURCC('G', 'R', '1', '4') +#define MMAL_ENCODING_BAYER_SRGGB14 MMAL_FOURCC('R', 'G', '1', '4') + +/* MIPI packed monochrome images */ +#define MMAL_ENCODING_GREY MMAL_FOURCC('G', 'R', 'E', 'Y') +#define MMAL_ENCODING_Y10P MMAL_FOURCC('Y', '1', '0', 'P') +#define MMAL_ENCODING_Y12P MMAL_FOURCC('Y', '1', '2', 'P') +#define MMAL_ENCODING_Y14P MMAL_FOURCC('Y', '1', '4', 'P') +#define MMAL_ENCODING_Y16 MMAL_FOURCC('Y', '1', '6', ' ') + +/* Unpacked monochrome formats (16bit per sample, but only N LSBs used) */ +#define MMAL_ENCODING_Y10 MMAL_FOURCC('Y', '1', '0', ' ') +#define MMAL_ENCODING_Y12 MMAL_FOURCC('Y', '1', '2', ' ') +#define MMAL_ENCODING_Y14 MMAL_FOURCC('Y', '1', '4', ' ') + /** An EGL image handle */ #define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I') --=20 2.55.0 From nobody Fri Sep 25 04:44:55 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 662524F30EA; Wed, 16 Sep 2026 14:35:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569338; cv=none; b=i1x21vi7VMke6xKjz+APB7XikHZxwqkXJiEPhYjbA8SyPx9MXZ6kDlsqDXvfz5k4WBmaXVh+Pq2KszUiTqM9UDLRDfRryLZPe6ULhOy0D9lWsGM85fpS9nh+Y6gffRvMCviS+CK3PmIqYaJuOv70KmOx0VgBgVvQM8ceMde5upA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569338; c=relaxed/simple; bh=Xiy1CMZcScJOjJMm6KuN9S/S57ILP1RjqYToK9VmGTM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IIBHF0FAQXkSDPSjoFPWG5uo6XmPrRPm/pwvqclLrei39zWAbFUUJvKVETK+8bHGxq8fCz5gYcUKlW619iZpmhhW4Ohlg4C5k3rPuPy6MI8szvMY48eE6nwm907Zq+xrpR1QCZrVedE3vSpt2dmh4SwOaToaLjVKQFVIYK1snWw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=a4/PH+Tk; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="a4/PH+Tk" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:85de:a3c9:9357:b164:bf0b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5D0E4558; Wed, 16 Sep 2026 16:33:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789569231; bh=Xiy1CMZcScJOjJMm6KuN9S/S57ILP1RjqYToK9VmGTM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=a4/PH+TkOWRoEq51XagslVr7BGs/8NcoVZWk8v4BsAXvJBaPcqT2pE3Ma/LtPtZOS tNZKZMq5YrIG4epc9TwSohk+r8OhEcGwyvFnX9HLcbzFb7v+2likgIECL4oFhJXd8F 21AMAPkdJzQaQvMeI1euUnHC/72ZGtoXLfNgxT8o= From: Jai Luthra Date: Wed, 16 Sep 2026 20:03:03 +0530 Subject: [PATCH v4 06/10] platform/raspberrypi: vchiq: Add helpers for vchiq driver data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-b4-vchiq-isp-v4-6-f668c2017b74@ideasonboard.com> References: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> In-Reply-To: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> To: Florian Fainelli , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Raspberry Pi Kernel Maintenance Cc: Laurent Pinchart , Kieran Bingham , Dave Stevenson , Naushir Patuck , Stefan Wahren , Paul Elder , Hans Verkuil , Tomasz Figa , linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra , Umang Jain X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1204; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=Xiy1CMZcScJOjJMm6KuN9S/S57ILP1RjqYToK9VmGTM=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqqqkL2nDBQYIgQZEMjwHJTOABVuyIDj1tZiGee EivyconD9iJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaqqpCwAKCRBD3pH5JJpx RW4nD/0d6jWs45wpBMZ7V9xmWZpQ8ayU7iMedadpiv5pfNaIdKPKjPv+0UXrQf2n/YDRIKrt8ub AsXJAX499uSMFANgOkQqiEhR+5eRHMYNsJT+Mb8hvPvkEsd51pdKie/Qs5DoPuQ2qYFYuZfzlx1 eOA4K0IJeVHltHv6nYbHLp6Nk+xxqWrNMRhjyh2S2VjpRLQkcnzi5cAAc/9TAylFyfUnY7gT/3m /n4b9f20dGQ8va5O6NNl7rwAJU/78ezLqG4hmx8oq1zL5YzFzkqMOLU27jZzwltXIy1tla2gMs4 US2zXPf5vP/76MCeqgA1EnkekflIoKoNdOfPXtuPaTzoYqgdGG7dZXlNIysPrMHRAgDg/mAwBNR bSZUrs9sB2JfPSHqw6u39l1KPG8JXS47iTzVUVapYepi42R4o9VeB0yFyckt1l0KxnzRRO1bGAx r/50hROlk/AzDC1xE10WkNlFOIBcHxGkMDb8u+swmAI6e2E2LVaP0SjKeqL7XUS60XWp2UlGGus ZgWCp1dfnuLE5dPCP/AgLSnKdukCQXkbi7WCzpxIe8Qf9Y3/RJ/9VWF2ANVh0NLG7Ikc112YsL0 IJEMbUL1jq3zB8bCYwlnRDZtAVlV5yaYWwM2gCmJyi/uvySYw62YQY+Zzq7mqZMik/aZGKxXMR9 i1Wla3sOd8jsfPw== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 Add helpers to set and get vchiq driver data. vchiq_set_drvdata() and vchiq_get_drvdata() wraps dev_set_drvdata() and dev_get_drvdata() respectively. Signed-off-by: Umang Jain Reviewed-by: Paul Elder Tested-by: Paul Elder Signed-off-by: Jai Luthra --- include/linux/raspberrypi/vchiq_bus.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/raspberrypi/vchiq_bus.h b/include/linux/raspberr= ypi/vchiq_bus.h index e52291a3b247..513a144bfbe9 100644 --- a/include/linux/raspberrypi/vchiq_bus.h +++ b/include/linux/raspberrypi/vchiq_bus.h @@ -37,6 +37,16 @@ static inline struct vchiq_driver *to_vchiq_driver(struc= t device_driver *d) return container_of(d, struct vchiq_driver, driver); } =20 +static inline void *vchiq_get_drvdata(const struct vchiq_device *device) +{ + return dev_get_drvdata(&device->dev); +} + +static inline void vchiq_set_drvdata(struct vchiq_device *device, void *da= ta) +{ + dev_set_drvdata(&device->dev, data); +} + extern const struct bus_type vchiq_bus_type; =20 struct vchiq_device * --=20 2.55.0 From nobody Fri Sep 25 04:44:55 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 34D2B526AA0; Wed, 16 Sep 2026 14:35:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569341; cv=none; b=Io/RcZ6DeVRGQsuanQT0hWkYGpRQMFzGwUz+YPfoWuwdiAOuON2NRac3bI/9kslekEi/FA3hA/7nioPo+sazKx7idRTvmxZwr9fMpcIVyExCvzKg+xid5bTZVFwEyOVbrDOKWs38jXF+CspLtcz9r8WhtsBvfvZomSf+6VhFlGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569341; c=relaxed/simple; bh=LiGGpGLE6D6aZj+FpFUOX6l4A/sAgkXWywK+IAQ3x4c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AZK2RfuIc+EDCOH1M3KH6Dfb/9j9m6OZLkM5pXBZcKmje9oO57/O+Ito5oLZ0ZmnFwoqc9r54Syh0sfS3czxKGHv/TihBlc3S1yTQlT4KmexBBVxTcBmHA6ctyGv3LPyqnZRO039RjhbHMnudzRjGLktzAelR/2S+B3fko1R7rQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=lWHpwYXi; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lWHpwYXi" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:85de:a3c9:9357:b164:bf0b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C4D3DC42; Wed, 16 Sep 2026 16:33:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789569237; bh=LiGGpGLE6D6aZj+FpFUOX6l4A/sAgkXWywK+IAQ3x4c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lWHpwYXiU+SVrfLTr4GYvWFG9EkE0HzzbtyUNloEehfjHBgH0gQ9UPUPJoutPQ5MG u2Y/liEzDHl1weaPaplOgdBC1jq5rUiDhChwGRr2Cw/Cb8/ZCzo1/Q7e3WN4kAqgzo 4+q1kOQfJVSwZiceYyGZinKUlk/cJp61ikUxvdAc= From: Jai Luthra Date: Wed, 16 Sep 2026 20:03:04 +0530 Subject: [PATCH v4 07/10] media: videobuf2: Allow exporting of a struct dmabuf Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-b4-vchiq-isp-v4-7-f668c2017b74@ideasonboard.com> References: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> In-Reply-To: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> To: Florian Fainelli , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Raspberry Pi Kernel Maintenance Cc: Laurent Pinchart , Kieran Bingham , Dave Stevenson , Naushir Patuck , Stefan Wahren , Paul Elder , Hans Verkuil , Tomasz Figa , linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4707; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=xG3dyunYI1VbEVnz1f7OyO886qwdzNs2DVKi6UN8ipo=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqqqkMrjqUNFZpjsy46hu1RvRhQ1780ajTP4Z20 PUZT+O7iN2JAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaqqpDAAKCRBD3pH5JJpx RV4bD/9Wu7OInXsb7PnQOApE5ubLZ18Z03BMtw2IL79grAAV0NfBFtRajFNC6hCiWEvg+3KfnGn clyw7nv3N8JwwZojSQFCCPgfdkuiCEWa2dHlA9I7cIRX/do4aBW+KmKpVheU7Pr2xHhJtzrBPj7 Qx555+UkC4SstVuL0P2cvfNyQRXLtjgpEUI/hRYbQeeZ4uC3A177Clhi88XwR/uJ31i7wh/F8sX nVFKT+cgvmavqq0aK21fa0ZeKqAF6cnQRd9pjd83/vqL08mENg5tFRFrNVEt8YubrNSTu5ioTZ5 D0gPus1aBaq/N46izScXBh67MQXNrqNydMaeiAcFEm38f1DwaT52eLiG7FpCz+l/KAd97ZyKRLq In1HmcTd3g2HU2ohZ2mFNE78R771ZqCdF+8r6xVUN1fIyZ1yyRlXzHF+kd/lZe/BgTqkkV/FxwN QzV3lzACh/RP+XKT5uPFVQvV8/RaIlRrrCMOf7UvUwd5tmX/aPFoKPBtOyMQ4W3FJsgLES4fv6k lMBp7Ev5bg6SIYZT/y2fFYQaxJnlUcmW8T/Pvz0sKidAYMXFaNUuH2jFrGduHKPf3eMkzBGAmzB fVTEE2ZgJvTssdRoxvSYsfv7rrfctMz8ug1i+OSdKxOPGHyPPX3rO5UR1k7J0nCP6gMjEgFP8SY zfKSagoooxp+pUw== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson videobuf2 only allowed exporting a dmabuf as a file descriptor, but there are instances where having the struct dma_buf is useful within the kernel. Split the current implementation into two, one step which exports a struct dma_buf, and the second which converts that into an fd. Signed-off-by: Dave Stevenson Reviewed-by: Paul Elder Tested-by: Paul Elder Signed-off-by: Jai Luthra --- Changes in v4: - Return a pointer to struct dmabuf instead of passing it as a double pointer argument and returning an int for errors (Laurent) - Document the return type (Paul) --- drivers/media/common/videobuf2/videobuf2-core.c | 45 ++++++++++++++++-----= ---- include/media/videobuf2-core.h | 17 ++++++++++ 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/medi= a/common/videobuf2/videobuf2-core.c index 5e318165659f..7b99d39d7cb1 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -2419,50 +2419,63 @@ static int __find_plane_by_offset(struct vb2_queue = *q, unsigned long offset, return 0; } =20 -int vb2_core_expbuf(struct vb2_queue *q, int *fd, struct vb2_buffer *vb, - unsigned int plane, unsigned int flags) +struct dma_buf *vb2_core_expbuf_dmabuf(struct vb2_queue *q, + struct vb2_buffer *vb, + unsigned int plane, unsigned int flags) { struct vb2_plane *vb_plane; - int ret; - struct dma_buf *dbuf; + struct dma_buf *dmabuf; =20 if (q->memory !=3D VB2_MEMORY_MMAP) { dprintk(q, 1, "queue is not currently set up for mmap\n"); - return -EINVAL; + return ERR_PTR(-EINVAL); } =20 if (!q->mem_ops->get_dmabuf) { dprintk(q, 1, "queue does not support DMA buffer exporting\n"); - return -EINVAL; + return ERR_PTR(-EINVAL); } =20 if (flags & ~(O_CLOEXEC | O_ACCMODE)) { - dprintk(q, 1, "queue does support only O_CLOEXEC and access mode flags\n= "); - return -EINVAL; + dprintk(q, 1, "queue supports only O_CLOEXEC and access mode flags\n"); + return ERR_PTR(-EINVAL); } =20 if (plane >=3D vb->num_planes) { dprintk(q, 1, "buffer plane out of range\n"); - return -EINVAL; + return ERR_PTR(-EINVAL); } =20 if (vb2_fileio_is_active(q)) { dprintk(q, 1, "expbuf: file io in progress\n"); - return -EBUSY; + return ERR_PTR(-EBUSY); } =20 vb_plane =3D &vb->planes[plane]; =20 - dbuf =3D call_ptr_memop(get_dmabuf, - vb, - vb_plane->mem_priv, - flags & O_ACCMODE); - if (IS_ERR_OR_NULL(dbuf)) { + dmabuf =3D call_ptr_memop(get_dmabuf, vb, vb_plane->mem_priv, + flags & O_ACCMODE); + if (IS_ERR_OR_NULL(dmabuf)) { dprintk(q, 1, "failed to export buffer %d, plane %d\n", vb->index, plane); - return -EINVAL; + if (!dmabuf) + dmabuf =3D ERR_PTR(-EINVAL); } =20 + return dmabuf; +} +EXPORT_SYMBOL_GPL(vb2_core_expbuf_dmabuf); + +int vb2_core_expbuf(struct vb2_queue *q, int *fd, struct vb2_buffer *vb, + unsigned int plane, unsigned int flags) +{ + struct dma_buf *dbuf; + int ret; + + dbuf =3D vb2_core_expbuf_dmabuf(q, vb, plane, flags); + if (IS_ERR(dbuf)) + return PTR_ERR(dbuf); + ret =3D dma_buf_fd(dbuf, flags & ~O_ACCMODE); if (ret < 0) { dprintk(q, 3, "buffer %d, plane %d failed to export (%d)\n", diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index feda638d0064..a73c59f21dcd 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -954,6 +954,23 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned in= t type); */ int vb2_core_streamoff(struct vb2_queue *q, unsigned int type); =20 +/** + * vb2_core_expbuf_dmabuf() - Export a buffer as a dma_buf structure + * @q: pointer to &struct vb2_queue with videobuf2 queue + * @vb: pointer to &struct vb2_buffer + * @plane: index of the plane to be exported, 0 for single plane queues + * @flags: file flags for newly created file, as defined at + * include/uapi/asm-generic/fcntl.h. + * Currently, the only used flag is %O_CLOEXEC. + * is supported, refer to manual of open syscall for more details. + * + * Return: returns a pointer to &struct dma_buf on success; an ERR_PTR or = NULL + * otherwise. + */ +struct dma_buf *vb2_core_expbuf_dmabuf(struct vb2_queue *q, + struct vb2_buffer *vb, + unsigned int plane, unsigned int flags); + /** * vb2_core_expbuf() - Export a buffer as a file descriptor. * @q: pointer to &struct vb2_queue with videobuf2 queue. --=20 2.55.0 From nobody Fri Sep 25 04:44:55 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 340BD52BE3D; Wed, 16 Sep 2026 14:35:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569346; cv=none; b=hHVIy3kUVub+xAKXD6q85WdOOhrP/V0gOO4W1y16jNEUX/P5BBmxRG+WvMIVo8xsm8uV52yn5fWKD7mcqg0epKwWKPrppfujJkCNkcN7EReTFu+i4ldT03QGCg8dhTivHzUtzYUAls9kyfSwUc4aiHfOfMJHNfkKClVP/TBYwe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569346; c=relaxed/simple; bh=Xphohe89z0TLV/9BLB5FyAHdcroVAJrXQ51HiX2RHDU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W89olxvucUXjFamywIedmIv+iw4/uzizDKSI2Ivli9gQcRLnUjuIzMYFD8L2dq/gtt3tcjeTnlnOYrdYGJ5mniMiooXUEd8RXMWaZz3n4UdyHMuo/0KVXQr+vQ5l1xnfTPwgoBoHG0FHp0JpSfYldOFZyL0Vaa6dx+0++19IwS8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=SASV+5Cr; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SASV+5Cr" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:85de:a3c9:9357:b164:bf0b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1486EC42; Wed, 16 Sep 2026 16:34:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789569242; bh=Xphohe89z0TLV/9BLB5FyAHdcroVAJrXQ51HiX2RHDU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SASV+5CrvkIF9rg5JKJ+cPxPOlQ4dodcvFl3MtbVn+BIXTx1CVUxkzS1/6AG83/Tf w4hEeAhxJtPV0x9Z3j8TDCTYz3ttP2fgpAiT0BLEfEpXEggWfslD83LWUxW6Gl+8NV +M3yAGtBjSktCDFe+uGXh1PvopNtNECw4XGL4vHA= From: Jai Luthra Date: Wed, 16 Sep 2026 20:03:05 +0530 Subject: [PATCH v4 08/10] media: platform: broadcom: Move unicam driver to subdir Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-b4-vchiq-isp-v4-8-f668c2017b74@ideasonboard.com> References: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> In-Reply-To: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> To: Florian Fainelli , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Raspberry Pi Kernel Maintenance Cc: Laurent Pinchart , Kieran Bingham , Dave Stevenson , Naushir Patuck , Stefan Wahren , Paul Elder , Hans Verkuil , Tomasz Figa , linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5004; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=Xphohe89z0TLV/9BLB5FyAHdcroVAJrXQ51HiX2RHDU=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqqqkNwPBqlbty23UoF4YfS2+UG7CHUYDyGdShd 6Gzabr4OvSJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaqqpDQAKCRBD3pH5JJpx RROnD/4vX7pbew2dB/F8NKexnr7NTFM5tztd2Iw0cRVdgVOq97Msp1oNqpWBjziMTO/gGQulQVj 14/DeJEegRycml6ezvrIMOSetaHhrE21NrFKPSRUyOKEw3PWC71qVvFW/13dA0P8gOhCgHa7ZtR suKgAJvCNBVaZ3cbv8KAxcGo9YdNUaGTSNgdMYsrLa3Jj2uGw5ahX+9N1rW4PPQi9uZeZvn3gm8 jrJYkiezlKXVQ+GRENxBUAAgBl1nFC2H2A8W67pQe8wVO3w5PLx7D+mDNT0wJkFX5Rh0gxIyH6y 8+9UCM8uRaBTUz1A6cFfvsLKg9QDLKGKanh0l2WR6qEtTJN2qXmtcTGYKvHTXZoGwHXpAMwBjU2 s1tb7/V36E4b4bW18T6qk7EYeoZpJtVWth5DyUc8YCJhkc6T0M4epLUBIg3Wy5hyi4uHBPK7TtN m0EGeKx4iTn0ZZIngVKvIth7c1/DgAMWvHg1fbVLT+WY4KNx13OrDv5KOBI5/eVqymqunHmEwmt 61kPbxlqhPpkgnLKapUiPUMkAxiX+CG4miLA4yJeYKLePBe3u008pCFSydrXr9xkY5KavllaMUE EbSQHiZ5PG/M7cMK2u5bVvyjA2Ox2CfTwrpvwlMz2xCXfqWLCtdbpcNc0Yws+Mltg6tGly2CIy4 ZyDfBl7/v0XrJqw== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 The BCM283x/BCM2711x SoCs capture camera frames using CSI-2, and optionally process the raw frames using a VC4 firmware-based ISP block. As the ISP driver will be added subsequently, move the files related to the unicam driver to a separate subdirectory to ease distinction between the two drivers' files. Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Tested-by: Paul Elder Signed-off-by: Jai Luthra --- Changes in v4: - Drop old paragraph in Kconfig that got copied from previous revision --- MAINTAINERS | 2 +- drivers/media/platform/broadcom/Kconfig | 17 ++------------= --- drivers/media/platform/broadcom/Makefile | 2 +- drivers/media/platform/broadcom/bcm2835-unicam/Kconfig | 18 ++++++++++++++= ++++ .../media/platform/broadcom/bcm2835-unicam/Makefile | 3 +++ .../{ =3D> bcm2835-unicam}/bcm2835-unicam-regs.h | 0 .../broadcom/{ =3D> bcm2835-unicam}/bcm2835-unicam.c | 0 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 0ac9a9d7b215..68ef4b2f9db6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5185,7 +5185,7 @@ M: Raspberry Pi Kernel Maintenance L: linux-media@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/media/brcm,bcm2835-unicam.yaml -F: drivers/media/platform/broadcom/bcm2835-unicam* +F: drivers/media/platform/broadcom/bcm2835-unicam/* =20 BROADCOM BCM47XX MIPS ARCHITECTURE M: Hauke Mehrtens diff --git a/drivers/media/platform/broadcom/Kconfig b/drivers/media/platfo= rm/broadcom/Kconfig index 93ba565d9a02..cab44885182c 100644 --- a/drivers/media/platform/broadcom/Kconfig +++ b/drivers/media/platform/broadcom/Kconfig @@ -1,18 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 =20 -config VIDEO_BCM2835_UNICAM - tristate "Broadcom BCM283x/BCM271x Unicam video capture driver" - depends on ARCH_BCM2835 || COMPILE_TEST - depends on COMMON_CLK && PM - depends on VIDEO_DEV - select MEDIA_CONTROLLER - select V4L2_FWNODE - select VIDEO_V4L2_SUBDEV_API - select VIDEOBUF2_DMA_CONTIG - help - Say Y here to enable support for the BCM283x/BCM271x CSI-2 receiver. - This is a V4L2 driver that controls the CSI-2 receiver directly, - independently from the VC4 firmware. +comment "Broadcom BCM283x/BCM271x media platform drivers" =20 - To compile this driver as a module, choose M here. The module will be - called bcm2835-unicam. +source "drivers/media/platform/broadcom/bcm2835-unicam/Kconfig" diff --git a/drivers/media/platform/broadcom/Makefile b/drivers/media/platf= orm/broadcom/Makefile index 03d2045aba2e..33a89bdb0029 100644 --- a/drivers/media/platform/broadcom/Makefile +++ b/drivers/media/platform/broadcom/Makefile @@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 =20 -obj-$(CONFIG_VIDEO_BCM2835_UNICAM) +=3D bcm2835-unicam.o +obj-y +=3D bcm2835-unicam/ diff --git a/drivers/media/platform/broadcom/bcm2835-unicam/Kconfig b/drive= rs/media/platform/broadcom/bcm2835-unicam/Kconfig new file mode 100644 index 000000000000..93ba565d9a02 --- /dev/null +++ b/drivers/media/platform/broadcom/bcm2835-unicam/Kconfig @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0 + +config VIDEO_BCM2835_UNICAM + tristate "Broadcom BCM283x/BCM271x Unicam video capture driver" + depends on ARCH_BCM2835 || COMPILE_TEST + depends on COMMON_CLK && PM + depends on VIDEO_DEV + select MEDIA_CONTROLLER + select V4L2_FWNODE + select VIDEO_V4L2_SUBDEV_API + select VIDEOBUF2_DMA_CONTIG + help + Say Y here to enable support for the BCM283x/BCM271x CSI-2 receiver. + This is a V4L2 driver that controls the CSI-2 receiver directly, + independently from the VC4 firmware. + + To compile this driver as a module, choose M here. The module will be + called bcm2835-unicam. diff --git a/drivers/media/platform/broadcom/bcm2835-unicam/Makefile b/driv= ers/media/platform/broadcom/bcm2835-unicam/Makefile new file mode 100644 index 000000000000..03d2045aba2e --- /dev/null +++ b/drivers/media/platform/broadcom/bcm2835-unicam/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_VIDEO_BCM2835_UNICAM) +=3D bcm2835-unicam.o diff --git a/drivers/media/platform/broadcom/bcm2835-unicam-regs.h b/driver= s/media/platform/broadcom/bcm2835-unicam/bcm2835-unicam-regs.h similarity index 100% rename from drivers/media/platform/broadcom/bcm2835-unicam-regs.h rename to drivers/media/platform/broadcom/bcm2835-unicam/bcm2835-unicam-reg= s.h diff --git a/drivers/media/platform/broadcom/bcm2835-unicam.c b/drivers/med= ia/platform/broadcom/bcm2835-unicam/bcm2835-unicam.c similarity index 100% rename from drivers/media/platform/broadcom/bcm2835-unicam.c rename to drivers/media/platform/broadcom/bcm2835-unicam/bcm2835-unicam.c --=20 2.55.0 From nobody Fri Sep 25 04:44:55 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 3DB1150EC1D; Wed, 16 Sep 2026 14:35:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569360; cv=none; b=eaHbnWQ9SpEMGVH1+2OMqAsnhEjYoTvfR/0er6qqffMyVnk6v0X8eLmHxLEJzFI1G0ACBU57iUjgRuSi/5QzRYYoJ7ZFp3+p6QdTnBAJ9svgcr2fJekJ0ZcotUpj9IXnK1rP77UURQagxMNFugHb4RN+dgmxS5LFmOsrTQS2Ue8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569360; c=relaxed/simple; bh=bRcwzs7Fo3nld6vE3q35gV/FTIAOoVK7cTNUhI3NiyU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XwsWFh4SbmXLD6+eRkLL/NP1RPSbZmWyeQpk0DcK8UYVIJ3gbGOE0SV+/Bd1sXcsCYL9lSAhHHQCDAKAvECehZnyVuLpCpCm0oeFfzovBXKCUZWodGk1cxEAvHLcxQs0XAymX0jwDGGK43Wuge4DzbqVJ/WMsbqyRv/3a6kUeyc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=PacCisA1; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="PacCisA1" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:85de:a3c9:9357:b164:bf0b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3DF13C42; Wed, 16 Sep 2026 16:34:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789569248; bh=bRcwzs7Fo3nld6vE3q35gV/FTIAOoVK7cTNUhI3NiyU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PacCisA19v+Zg/4WSEf+sOsnIuyy5trHAt/mLugl0c+2dQeUQFsoqOASDIC9fjH9c 0T0Kxv7Xg7x0ch1pOIAHytwymZhMoIxTXynlp3YTHe7dtI/GjpEIy/yVn/igp+LUif 4wZAXYD5V/qdeyqj1Js1+yUBe2lg0Sxgttkg1kv0= From: Jai Luthra Date: Wed, 16 Sep 2026 20:03:06 +0530 Subject: [PATCH v4 09/10] media: platform: broadcom: Add bcm2835-isp driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-b4-vchiq-isp-v4-9-f668c2017b74@ideasonboard.com> References: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> In-Reply-To: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> To: Florian Fainelli , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Raspberry Pi Kernel Maintenance Cc: Laurent Pinchart , Kieran Bingham , Dave Stevenson , Naushir Patuck , Stefan Wahren , Paul Elder , Hans Verkuil , Tomasz Figa , linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=121285; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=KSFB6q5pwejLYwsGr6y3HqWuZ6tzDUsHXorCy93c4rk=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqqqkO3b1g1lluVM1YRyavkBxcST3oDxSNaxvhT +oTz60yrmaJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaqqpDgAKCRBD3pH5JJpx RZNeEACaAF9RkGs2fsin67nFOyEAkrg0SU5dEcEdf0ZMVa344nU0epwWyy+7wqvJIRw5T856W7k ghz86XloKxXmhiL+qA2OL+kQWd0K3yn5b7BTYVV3bNisYvn/sKt+G74gRjmNEEm0wyYsvOpQ/yk dviiwPGUKtlQ987m682gVMLR8sn+0/IicV6JdDG5j4rpBf6c/earWauxD/RgP5vJEGLND9+b2so gvv6J+X9PnsG3JMb7wm34miqAO9Z2w+5oqcgXXkMsGIf/IEndd4flVgmxchRyAPxg+qwk4cxzNY YHFA5sr+N9d/9nEhORtNmM96PFAtkXEpSZbJoUKzGUVgI+NdA94wzHz0XXe1iVCv3tdAgtX1tTN iay8NwCVuxfKBjLaQtd8o5y1yorjnDdw2+MnsMB9HUQLfSd49b53mg5eAaoQMOClLokuOPliD0c 28Wb/xH0jZ9+YtS9F8+bTSy10WZiGv8MuJkQf6jd5sMBxm9WnFaKT3oHeASp+3rZ/IJbgbZc6E+ WuN5J59vBuxNzYuATYMbkw5EEAZ5a1l3whPjRYFz4r4j5AGM8jA2JvCoWkt/Y1aCeJqi/lQD5K+ uKSOXwbkiIGtVTdaFTqHmZNq7DEHjaFUaNI5Dkv0ujUBT+wKz8xbR52rTXJOapGG4MsAjnRKDiC wQPc3t0L7dNp4YQ== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Naushir Patuck The BCM2835 ISP is a fixed-function hardware block that performs image processing on Bayer, RGB, and YUV frames. It produces two processed video outputs at different resolutions and can generate statistics for Bayer inputs. The hardware is not accessible directly, so this driver programs it through the VCHIQ MMAL interface. As the topology cannot be represented as a simple V4L2 M2M device, we register a media device with 5 video nodes: one output (sink), two capture (processed frames), one metadata capture (statistics), and one metadata output (config parameters). The VCHIQ firmware supports two concurrent users, so instantiate two identical media graphs. ISP configuration uses the V4L2 extensible parameters framework through the dedicated params node, allowing userspace to batch multiple parameter blocks (black level, gamma, CCM, lens shading, etc.) in a single buffer that is applied on the next frame boundary. Signed-off-by: Naushir Patuck Co-developed-by: Dave Stevenson Signed-off-by: Dave Stevenson Co-developed-by: Jai Luthra Signed-off-by: Jai Luthra Tested-by: Paul Elder --- Changes in v4: - Set ISP_NUM_INSTANCES to 1 until we have proper support for multiplexing ISP instances (Laurent) - Add a new struct mmal_parameter_isp_parameters {} in mmal-parameters.h to send combined updates the firmware (Dave) - Rework bcm2835-isp-params.c to use the above and save expensive messages over IPC boundary (Dave) - Test if the firmware supports the single struct, and fail with an error message asking the user to update their firmware if not (Dave) - Check for retval of isp_set_param() and print error messages if it fails - Various cleanups and suggestions (Paul) Changes in v3: - Rebase on v7.2-rc1 - Drop redundant buffer list and locks for params (we send them immediately to firmware on queue) - Drop .stop_streaming() for params node - Minor cleanups --- Documentation/admin-guide/media/bcm2835-isp.dot | 14 + Documentation/admin-guide/media/bcm2835-isp.rst | 78 + Documentation/admin-guide/media/v4l-drivers.rst | 1 + .../userspace-api/media/v4l/meta-formats.rst | 1 + .../media/v4l/metafmt-bcm2835-isp.rst | 101 ++ MAINTAINERS | 9 + drivers/media/platform/broadcom/Kconfig | 1 + drivers/media/platform/broadcom/Makefile | 1 + .../media/platform/broadcom/bcm2835-isp/Kconfig | 15 + .../media/platform/broadcom/bcm2835-isp/Makefile | 4 + .../broadcom/bcm2835-isp/bcm2835-isp-common.h | 50 + .../broadcom/bcm2835-isp/bcm2835-isp-fmts.h | 558 ++++++++ .../broadcom/bcm2835-isp/bcm2835-isp-params.c | 512 +++++++ .../broadcom/bcm2835-isp/bcm2835-v4l2-isp.c | 1509 ++++++++++++++++= ++++ drivers/media/v4l2-core/v4l2-ioctl.c | 2 + include/linux/raspberrypi/mmal-parameters.h | 121 +- include/uapi/linux/bcm2835-isp.h | 530 +++++++ include/uapi/linux/videodev2.h | 2 + 18 files changed, 3497 insertions(+), 12 deletions(-) diff --git a/Documentation/admin-guide/media/bcm2835-isp.dot b/Documentatio= n/admin-guide/media/bcm2835-isp.dot new file mode 100644 index 000000000000..cda3defe2d99 --- /dev/null +++ b/Documentation/admin-guide/media/bcm2835-isp.dot @@ -0,0 +1,14 @@ +digraph board { + rankdir=3DTB + n00000001 [label=3D"bcm2835-isp-output0\n/dev/video13", shape=3Dbox, styl= e=3Dfilled, fillcolor=3Dyellow] + n00000001 -> n00000015 [style=3Dbold] + n00000005 [label=3D"bcm2835-isp-capture0\n/dev/video14", shape=3Dbox, sty= le=3Dfilled, fillcolor=3Dyellow] + n00000009 [label=3D"bcm2835-isp-capture1\n/dev/video15", shape=3Dbox, sty= le=3Dfilled, fillcolor=3Dyellow] + n0000000d [label=3D"bcm2835-isp-stats2\n/dev/video16", shape=3Dbox, style= =3Dfilled, fillcolor=3Dyellow] + n00000011 [label=3D"bcm2835-isp-params\n/dev/video17", shape=3Dbox, style= =3Dfilled, fillcolor=3Dyellow] + n00000011 -> n00000015 [style=3Dbold] + n00000015 [label=3D"bcm2835-isp\n", shape=3Dbox, style=3Dfilled, fillcolo= r=3Dyellow] + n00000015 -> n00000005 [style=3Dbold] + n00000015 -> n00000009 [style=3Dbold] + n00000015 -> n0000000d [style=3Dbold] +} diff --git a/Documentation/admin-guide/media/bcm2835-isp.rst b/Documentatio= n/admin-guide/media/bcm2835-isp.rst new file mode 100644 index 000000000000..6384cc7b3eb0 --- /dev/null +++ b/Documentation/admin-guide/media/bcm2835-isp.rst @@ -0,0 +1,78 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Broadcom BCM2835 Image Signal Processor (ISP) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The BCM2835 ISP +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The BCM2835 Image Signal Processor (ISP) is a fixed function hardware pipe= line +that performs image processing on frames stored in memory. Frames can be B= ayer, +RGB, or YUV and are submitted to the ISP through a V4L2 output node. The I= SP +produces two processed image outputs at different resolutions and can gene= rate +statistics for Bayer inputs. + +The bcm2835-isp driver +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The bcm2835-isp driver lives under +`drivers/media/platform/broadcom/bcm2835-isp` and registers a set of V4L2 = video +nodes connected through a media graph. The pipeline is configured through = the +V4L2 extensible parameters framework using a dedicated params node. + +The media topology registered by the driver is represented below: + +.. _bcm2835-isp-topology: + +.. kernel-figure:: bcm2835-isp.dot + :alt: Diagram of the default media pipeline topology + :align: center + +The media graph registers the following video device nodes: + +- bcm2835-isp-output0: output device that queues frames to the ISP input. +- bcm2835-isp-capture0: capture device for the main processed output. +- bcm2835-isp-capture1: capture device for the secondary processed output. +- bcm2835-isp-stats2: metadata capture device for ISP statistics. +- bcm2835-isp-params: metadata output device for ISP configuration paramet= ers. + +bcm2835-isp-output0 +------------------- + +Frames to be processed by the ISP are queued to `bcm2835-isp-output0`. Sup= ported +input formats include Bayer, RGB, and YUV. + +bcm2835-isp-capture0, bcm2835-isp-capture1 +------------------------------------------ + +The two capture devices return processed images in YUV or RGB formats. The +secondary output is typically used for a lower-resolution stream. + +bcm2835-isp-stats2 +------------------ + +The `bcm2835-isp-stats2` node provides per-frame statistics for Bayer inpu= ts as +metadata buffers. The metadata format is described at +:ref:`v4l2-meta-fmt-bcm2835-isp-stats`. + +bcm2835-isp-params +------------------ + +The `bcm2835-isp-params` node accepts configuration buffers that define th= e ISP +processing parameters to apply on the next frame boundary. The metadata fo= rmat +is described at :ref:`v4l2-meta-fmt-bcm2835-isp-params`. + +ISP configuration +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The ISP configuration is described solely by the contents of the parameters +buffer queued to `bcm2835-isp-params`. Each buffer uses the V4L2 extensible +parameters format described in :ref:`v4l2-isp`, with block types defined in +``include/uapi/linux/bcm2835-isp.h``. + +Userspace must populate a :c:type:`v4l2_isp_params_buffer` and append one = or +more block structs, each of which embeds a +:c:type:`v4l2_isp_params_block_header` as its first member. The driver app= lies +those parameters on a frame boundary once the buffer is queued. Parameter +structure is defined at :ref:`v4l2-meta-fmt-bcm2835-isp-params`. diff --git a/Documentation/admin-guide/media/v4l-drivers.rst b/Documentatio= n/admin-guide/media/v4l-drivers.rst index 4621eae9fa1e..cfbd9a64557d 100644 --- a/Documentation/admin-guide/media/v4l-drivers.rst +++ b/Documentation/admin-guide/media/v4l-drivers.rst @@ -10,6 +10,7 @@ Video4Linux (V4L) driver-specific documentation :maxdepth: 2 =20 amdisp4-1 + bcm2835-isp bttv c3-isp cafe_ccic diff --git a/Documentation/userspace-api/media/v4l/meta-formats.rst b/Docum= entation/userspace-api/media/v4l/meta-formats.rst index b5455229837e..02f0b6524472 100644 --- a/Documentation/userspace-api/media/v4l/meta-formats.rst +++ b/Documentation/userspace-api/media/v4l/meta-formats.rst @@ -14,6 +14,7 @@ These formats are used for the :ref:`metadata` interface = only. :maxdepth: 1 =20 metafmt-arm-mali-c55 + metafmt-bcm2835-isp metafmt-c3-isp metafmt-d4xx metafmt-generic diff --git a/Documentation/userspace-api/media/v4l/metafmt-bcm2835-isp.rst = b/Documentation/userspace-api/media/v4l/metafmt-bcm2835-isp.rst new file mode 100644 index 000000000000..6ed1d1e7890f --- /dev/null +++ b/Documentation/userspace-api/media/v4l/metafmt-bcm2835-isp.rst @@ -0,0 +1,101 @@ +.. SPDX-License-Identifier: GPL-2.0 +.. c:namespace:: V4L + +**************************************************************************= ********* +V4L2_META_FMT_BCM2835_ISP_STATS ('BSTA'), V4L2_META_FMT_BCM2835_ISP_PARAMS= ('BCMP') +**************************************************************************= ********* + +.. _v4l2-meta-fmt-bcm2835-isp-stats: + +BCM2835 ISP Statistics +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The BCM2835 ISP hardware calculate image statistics for an input Bayer fra= me. +These statistics are obtained from the "bcm2835-isp0-capture3" device node +using the :c:type:`v4l2_meta_format` interface. They are formatted as desc= ribed +by the :c:type:`bcm2835_isp_stats` structure below. + +.. code-block:: c + + #define DEFAULT_AWB_REGIONS_X 16 + #define DEFAULT_AWB_REGIONS_Y 12 + + #define NUM_HISTOGRAMS 2 + #define NUM_HISTOGRAM_BINS 128 + #define AWB_REGIONS (DEFAULT_AWB_REGIONS_X * DEFAULT_AWB_REGIONS_Y) + #define FLOATING_REGIONS 16 + #define AGC_REGIONS 16 + #define FOCUS_REGIONS 12 + +.. kernel-doc:: include/uapi/linux/bcm2835-isp.h + :functions: bcm2835_isp_stats_hist bcm2835_isp_stats_region + bcm2835_isp_stats_focus bcm2835_isp_stats + +.. _v4l2-meta-fmt-bcm2835-isp-params: + +BCM2835 ISP parameters +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The ISP parameters are configured by queuing buffers to the "bcm2835-isp-p= arams" +metadata output node. Parameter buffers use the V4L2 extensible parameters +format described in :ref:`v4l2-isp`. Userspace assembles one or more param= eter +blocks in the data area of :c:type:`v4l2_isp_params_buffer` and submits the +buffer to the driver. + +Each block begins with a :c:type:`v4l2_isp_params_block_header` and embeds= the +block-specific payload. The header ``type`` must be set to a value from +:c:type:`bcm2835_isp_param_block_type`, ``size`` must match the block size= , and +``flags`` can be used to enable or disable the block. + +Example: enqueue two parameter blocks (black level and gamma) +------------------------------------------------------------- + +.. code-block:: c + + struct v4l2_isp_params_buffer *params =3D + (struct v4l2_isp_params_buffer *)buffer; + + params->version =3D BCM2835_ISP_PARAM_BUFFER_V1; + params->data_size =3D 0; + + void *data =3D (void *)params->data; + + struct bcm2835_isp_params_black_level *black =3D + (struct bcm2835_isp_params_black_level *)data; + + black->header.type =3D BCM2835_ISP_PARAM_BLOCK_BLACK_LEVEL; + black->header.flags |=3D V4L2_ISP_PARAMS_FL_BLOCK_ENABLE; + black->header.size =3D sizeof(*black); + + black->black_level.enabled =3D 1; + black->black_level.black_level_r =3D 64; + black->black_level.black_level_g =3D 64; + black->black_level.black_level_b =3D 64; + + data +=3D sizeof(*black); + params->data_size +=3D sizeof(*black); + + struct bcm2835_isp_params_gamma *gamma =3D + (struct bcm2835_isp_params_gamma *)data; + + gamma->header.type =3D BCM2835_ISP_PARAM_BLOCK_GAMMA; + gamma->header.flags |=3D V4L2_ISP_PARAMS_FL_BLOCK_ENABLE; + gamma->header.size =3D sizeof(*gamma); + + gamma->gamma.enabled =3D 1; + /* Fill gamma->gamma.x[] and gamma->gamma.y[] here */ + + params->data_size +=3D sizeof(*gamma); + +The total payload size must not exceed :c:macro:`BCM2835_ISP_PARAMS_MAX_SI= ZE`. +The driver applies parameter buffers on the next frame boundary. + +BCM2835 ISP uAPI data types +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D + +.. kernel-doc:: include/uapi/linux/bcm2835-isp.h + :functions: bcm2835_isp_awb_gains bcm2835_isp_ccm bcm2835_isp_gain_form= at + bcm2835_isp_digital_gain bcm2835_isp_lens_shading + bcm2835_isp_black_level bcm2835_isp_geq bcm2835_isp_gamma + bcm2835_isp_denoise bcm2835_isp_sharpen bcm2835_isp_dpc_mo= de + bcm2835_isp_dpc bcm2835_isp_rational bcm2835_isp_cdn diff --git a/MAINTAINERS b/MAINTAINERS index 68ef4b2f9db6..7417cb31244b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5187,6 +5187,15 @@ S: Maintained F: Documentation/devicetree/bindings/media/brcm,bcm2835-unicam.yaml F: drivers/media/platform/broadcom/bcm2835-unicam/* =20 +BROADCOM BCM2835 ISP DRIVER +M: Raspberry Pi Kernel Maintenance +L: linux-media@vger.kernel.org +S: Maintained +F: Documentation/admin-guide/media/bcm2835-isp.rst +F: Documentation/userspace-api/media/v4l/metafmt-bcm2835-isp.rst +F: drivers/media/platform/broadcom/bcm2835-isp/* +F: include/uapi/linux/bcm2835-isp.h + BROADCOM BCM47XX MIPS ARCHITECTURE M: Hauke Mehrtens M: Rafa=C5=82 Mi=C5=82ecki diff --git a/drivers/media/platform/broadcom/Kconfig b/drivers/media/platfo= rm/broadcom/Kconfig index cab44885182c..0da6c83e97ed 100644 --- a/drivers/media/platform/broadcom/Kconfig +++ b/drivers/media/platform/broadcom/Kconfig @@ -3,3 +3,4 @@ comment "Broadcom BCM283x/BCM271x media platform drivers" =20 source "drivers/media/platform/broadcom/bcm2835-unicam/Kconfig" +source "drivers/media/platform/broadcom/bcm2835-isp/Kconfig" diff --git a/drivers/media/platform/broadcom/Makefile b/drivers/media/platf= orm/broadcom/Makefile index 33a89bdb0029..1d49e586f492 100644 --- a/drivers/media/platform/broadcom/Makefile +++ b/drivers/media/platform/broadcom/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 =20 obj-y +=3D bcm2835-unicam/ +obj-y +=3D bcm2835-isp/ diff --git a/drivers/media/platform/broadcom/bcm2835-isp/Kconfig b/drivers/= media/platform/broadcom/bcm2835-isp/Kconfig new file mode 100644 index 000000000000..3a4db5bf61a1 --- /dev/null +++ b/drivers/media/platform/broadcom/bcm2835-isp/Kconfig @@ -0,0 +1,15 @@ +config VIDEO_ISP_BCM2835 + tristate "BCM2835 ISP support" + depends on MEDIA_SUPPORT + depends on VIDEO_DEV && (ARCH_BCM2835 || COMPILE_TEST) + depends on MEDIA_CONTROLLER + select BCM2835_VCHIQ_MMAL + select V4L2_ISP + select VIDEOBUF2_DMA_CONTIG + help + This is the V4L2 driver for the Broadcom BCM2835 ISP hardware. + This operates over the VCHIQ interface to a service running on + VideoCore. + + To compile this driver as a module, choose M here: the module + will be called bcm2835-isp. diff --git a/drivers/media/platform/broadcom/bcm2835-isp/Makefile b/drivers= /media/platform/broadcom/bcm2835-isp/Makefile new file mode 100644 index 000000000000..21224cb85d5f --- /dev/null +++ b/drivers/media/platform/broadcom/bcm2835-isp/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +bcm2835-isp-objs :=3D bcm2835-v4l2-isp.o bcm2835-isp-params.o + +obj-$(CONFIG_VIDEO_ISP_BCM2835) +=3D bcm2835-isp.o diff --git a/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-common= .h b/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-common.h new file mode 100644 index 000000000000..60be0607b1ab --- /dev/null +++ b/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-common.h @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Broadcom BCM2835 ISP driver - common header + * + * Copyright (c) 2026 Raspberry Pi (Trading) Ltd. + * Copyright (c) 2026 Ideas On Board Oy + */ + +#ifndef BCM2835_ISP_COMMON_H +#define BCM2835_ISP_COMMON_H + +#include +#include +#include +#include + +#include +#include +#include + +struct dma_buf; + +struct bcm2835_isp_params { + struct device *dev; + struct v4l2_device *v4l2_dev; + struct vchiq_mmal_instance *mmal_instance; + struct vchiq_mmal_port *port; + + struct video_device vdev; + struct media_pad pad; + struct vb2_queue queue; + struct mutex lock; /* params node vdev lock */ + + /* Lens shading state */ + struct dma_buf *last_ls_dmabuf; +}; + +struct bcm2835_isp_params * +bcm2835_isp_params_register(struct v4l2_device *v4l2_dev, struct device *d= ev, + struct vchiq_mmal_instance *mmal_instance, + struct vchiq_mmal_port *port, int video_nr); + +void bcm2835_isp_params_unregister(struct bcm2835_isp_params *params); + +int bcm2835_isp_params_drop_ls_ref(struct bcm2835_isp_params *params); + +int bcm2835_isp_node_querycap(struct file *file, void *priv, + struct v4l2_capability *cap); + +#endif /* BCM2835_ISP_COMMON_H */ diff --git a/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-fmts.h= b/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-fmts.h new file mode 100644 index 000000000000..6f3333d33c4f --- /dev/null +++ b/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-fmts.h @@ -0,0 +1,558 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Broadcom BCM2835 ISP driver + * + * Copyright =C2=A9 2019-2026 Raspberry Pi (Trading) Ltd. + * + * Author: Naushir Patuck (naush@raspberrypi.com) + * + */ + +#ifndef BCM2835_ISP_FMTS +#define BCM2835_ISP_FMTS + +#include +#include + +struct bcm2835_isp_fmt { + u32 fourcc; + int depth; + int bytesperline_align; + u32 mmal_fmt; + int size_multiplier_x2; + u32 colorspace_mask; + enum v4l2_colorspace colorspace_default; + unsigned int step_size; +}; + +#define V4L2_COLORSPACE_MASK(colorspace) BIT(colorspace) + +#define V4L2_COLORSPACE_MASK_JPEG V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_JPE= G) +#define V4L2_COLORSPACE_MASK_SMPTE170M V4L2_COLORSPACE_MASK(V4L2_COLORSPAC= E_SMPTE170M) +#define V4L2_COLORSPACE_MASK_REC709 V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_R= EC709) +#define V4L2_COLORSPACE_MASK_SRGB V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_SRG= B) +#define V4L2_COLORSPACE_MASK_RAW V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_RAW) + +/* + * All three colour spaces JPEG, SMPTE170M and REC709 are fundamentally sR= GB + * underneath (as near as makes no difference to us), just with different = YCbCr + * encodings. Therefore the ISP can generate sRGB on its main output and a= ny of + * the others on its low resolution output. Applications should, when usin= g both + * outputs, program the colour spaces on them to be the same, matching wha= tever + * is requested for the low resolution output, even if the main output is + * producing an RGB format. In turn this requires us to allow all these co= lour + * spaces for every YUV/RGB output format. + */ +#define V4L2_COLORSPACE_MASK_ALL_SRGB (V4L2_COLORSPACE_MASK_JPEG | \ + V4L2_COLORSPACE_MASK_SRGB | \ + V4L2_COLORSPACE_MASK_SMPTE170M | \ + V4L2_COLORSPACE_MASK_REC709) + +static const struct bcm2835_isp_fmt supported_formats[] =3D { + { + /* YUV formats */ + .fourcc =3D V4L2_PIX_FMT_YUV420, + .depth =3D 8, + .bytesperline_align =3D 64, + .mmal_fmt =3D MMAL_ENCODING_I420, + .size_multiplier_x2 =3D 3, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_JPEG, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_YVU420, + .depth =3D 8, + .bytesperline_align =3D 64, + .mmal_fmt =3D MMAL_ENCODING_YV12, + .size_multiplier_x2 =3D 3, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SMPTE170M, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_NV12, + .depth =3D 8, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_NV12, + .size_multiplier_x2 =3D 3, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SMPTE170M, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_NV21, + .depth =3D 8, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_NV21, + .size_multiplier_x2 =3D 3, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SMPTE170M, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_YUYV, + .depth =3D 16, + .bytesperline_align =3D 64, + .mmal_fmt =3D MMAL_ENCODING_YUYV, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SMPTE170M, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_UYVY, + .depth =3D 16, + .bytesperline_align =3D 64, + .mmal_fmt =3D MMAL_ENCODING_UYVY, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SMPTE170M, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_YVYU, + .depth =3D 16, + .bytesperline_align =3D 64, + .mmal_fmt =3D MMAL_ENCODING_YVYU, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SMPTE170M, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_VYUY, + .depth =3D 16, + .bytesperline_align =3D 64, + .mmal_fmt =3D MMAL_ENCODING_VYUY, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SMPTE170M, + .step_size =3D 2, + }, { + /* RGB formats */ + .fourcc =3D V4L2_PIX_FMT_RGB24, + .depth =3D 24, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_RGB24, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SRGB, + .step_size =3D 1, + }, { + .fourcc =3D V4L2_PIX_FMT_RGB565, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_RGB16, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SRGB, + .step_size =3D 1, + }, { + .fourcc =3D V4L2_PIX_FMT_BGR24, + .depth =3D 24, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BGR24, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SRGB, + .step_size =3D 1, + }, { + .fourcc =3D V4L2_PIX_FMT_XBGR32, + .depth =3D 32, + .bytesperline_align =3D 64, + .mmal_fmt =3D MMAL_ENCODING_BGRA, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SRGB, + .step_size =3D 1, + }, { + .fourcc =3D V4L2_PIX_FMT_RGBX32, + .depth =3D 32, + .bytesperline_align =3D 64, + .mmal_fmt =3D MMAL_ENCODING_RGBA, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_ALL_SRGB, + .colorspace_default =3D V4L2_COLORSPACE_SRGB, + .step_size =3D 1, + }, { + /* Bayer formats */ + /* 8 bit */ + .fourcc =3D V4L2_PIX_FMT_SRGGB8, + .depth =3D 8, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SRGGB8, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SBGGR8, + .depth =3D 8, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SBGGR8, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGRBG8, + .depth =3D 8, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGRBG8, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGBRG8, + .depth =3D 8, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGBRG8, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 10 bit */ + .fourcc =3D V4L2_PIX_FMT_SRGGB10P, + .depth =3D 10, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SRGGB10P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SBGGR10P, + .depth =3D 10, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SBGGR10P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGRBG10P, + .depth =3D 10, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGRBG10P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGBRG10P, + .depth =3D 10, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGBRG10P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 12 bit */ + .fourcc =3D V4L2_PIX_FMT_SRGGB12P, + .depth =3D 12, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SRGGB12P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SBGGR12P, + .depth =3D 12, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SBGGR12P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGRBG12P, + .depth =3D 12, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGRBG12P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGBRG12P, + .depth =3D 12, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGBRG12P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 14 bit */ + .fourcc =3D V4L2_PIX_FMT_SRGGB14P, + .depth =3D 14, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SRGGB14P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SBGGR14P, + .depth =3D 14, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SBGGR14P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGRBG14P, + .depth =3D 14, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGRBG14P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGBRG14P, + .depth =3D 14, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGBRG14P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 16 bit */ + .fourcc =3D V4L2_PIX_FMT_SRGGB16, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SRGGB16, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SBGGR16, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SBGGR16, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGRBG16, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGRBG16, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGBRG16, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGBRG16, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* Bayer formats unpacked to 16bpp */ + /* 10 bit */ + .fourcc =3D V4L2_PIX_FMT_SRGGB10, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SRGGB10, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SBGGR10, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SBGGR10, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGRBG10, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGRBG10, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGBRG10, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGBRG10, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 12 bit */ + .fourcc =3D V4L2_PIX_FMT_SRGGB12, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SRGGB12, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SBGGR12, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SBGGR12, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGRBG12, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGRBG12, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGBRG12, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGBRG12, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 14 bit */ + .fourcc =3D V4L2_PIX_FMT_SRGGB14, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SRGGB14, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SBGGR14, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SBGGR14, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGRBG14, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGRBG14, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_PIX_FMT_SGBRG14, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_BAYER_SGBRG14, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* Monochrome MIPI formats */ + /* 8 bit */ + .fourcc =3D V4L2_PIX_FMT_GREY, + .depth =3D 8, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_GREY, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 10 bit */ + .fourcc =3D V4L2_PIX_FMT_Y10P, + .depth =3D 10, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_Y10P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 12 bit */ + .fourcc =3D V4L2_PIX_FMT_Y12P, + .depth =3D 12, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_Y12P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 14 bit */ + .fourcc =3D V4L2_PIX_FMT_Y14P, + .depth =3D 14, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_Y14P, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 16 bit */ + .fourcc =3D V4L2_PIX_FMT_Y16, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_Y16, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 10 bit as 16bpp */ + .fourcc =3D V4L2_PIX_FMT_Y10, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_Y10, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 12 bit as 16bpp */ + .fourcc =3D V4L2_PIX_FMT_Y12, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_Y12, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + /* 14 bit as 16bpp */ + .fourcc =3D V4L2_PIX_FMT_Y14, + .depth =3D 16, + .bytesperline_align =3D 32, + .mmal_fmt =3D MMAL_ENCODING_Y14, + .size_multiplier_x2 =3D 2, + .colorspace_mask =3D V4L2_COLORSPACE_MASK_RAW, + .colorspace_default =3D V4L2_COLORSPACE_RAW, + .step_size =3D 2, + }, { + .fourcc =3D V4L2_META_FMT_BCM2835_ISP_STATS, + .depth =3D 8, + .mmal_fmt =3D MMAL_ENCODING_BRCM_STATS, + /* The rest are not valid fields for stats. */ + } +}; + +#endif diff --git a/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-params= .c b/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-params.c new file mode 100644 index 000000000000..0ef3294b1ce2 --- /dev/null +++ b/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-params.c @@ -0,0 +1,512 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Broadcom BCM2835 ISP driver - extensible parameters node + * + * Copyright (c) 2026 Raspberry Pi Ltd. + * Copyright (c) 2026 Ideas On Board Oy + * + * Author: Jai Luthra + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "bcm2835-isp-common.h" + +MODULE_IMPORT_NS("DMA_BUF"); + +#define BCM2835_ISP_PARAMS_NAME "bcm2835-isp-params" + +#define BCM2835_ISP_PARAMS_BUF_SIZE \ + v4l2_isp_buffer_size(BCM2835_ISP_PARAMS_MAX_SIZE) + +/** + * union bcm2835_isp_params_block - Generalisation of a parameter block + * + * @header: Block header pointer for type checking + * @black_level: Black level configuration block + * @geq: Green equalisation configuration block + * @gamma: Gamma curve configuration block + * @denoise: Denoise configuration block + * @sharpen: Sharpen configuration block + * @dpc: Defective pixel correction configuration block + * @cdn: Colour denoise configuration block + * @ccm: Colour correction matrix configuration block + * @ls: Lens shading configuration block + * @awb_gains: AWB gains configuration block + * @digital_gain: Digital gain configuration block + * @data: Raw pointer for block iteration + */ +union bcm2835_isp_params_block { + const struct v4l2_isp_params_block_header *header; + const struct bcm2835_isp_params_black_level *black_level; + const struct bcm2835_isp_params_geq *geq; + const struct bcm2835_isp_params_gamma *gamma; + const struct bcm2835_isp_params_denoise *denoise; + const struct bcm2835_isp_params_sharpen *sharpen; + const struct bcm2835_isp_params_dpc *dpc; + const struct bcm2835_isp_params_cdn *cdn; + const struct bcm2835_isp_params_cc_matrix *ccm; + const struct bcm2835_isp_params_lens_shading *ls; + const struct bcm2835_isp_params_awb_gains *awb_gains; + const struct bcm2835_isp_params_digital_gain *digital_gain; + const __u8 *data; +}; + +typedef void (*bcm2835_isp_params_handler)(struct mmal_parameter_isp_param= eters *mmal_param, + struct bcm2835_isp_params *params, + union bcm2835_isp_params_block block); + +struct bcm2835_isp_params_buffer { + struct vb2_v4l2_buffer vb; + struct list_head list; + void *config; +}; + +#define to_bcm2835_isp_params_buf(vbuf) \ + container_of(vbuf, struct bcm2835_isp_params_buffer, vb) + +static int isp_set_param(struct bcm2835_isp_params *params, u32 parameter, + void *value, u32 value_size) +{ + return vchiq_mmal_port_parameter_set(params->mmal_instance, params->port, + parameter, value, value_size); +} + +static int map_ls_table(struct bcm2835_isp_params *params, + struct dma_buf *dmabuf, u32 *mem_handle_table) +{ + void *vcsm_handle; + int ret; + + if (IS_ERR_OR_NULL(dmabuf)) + return -EINVAL; + + ret =3D vc_sm_cma_import_dmabuf(dmabuf, &vcsm_handle); + if (ret) + return ret; + + *mem_handle_table =3D vc_sm_cma_int_handle(vcsm_handle); + + vc_sm_cma_free(vcsm_handle); + + params->last_ls_dmabuf =3D dmabuf; + + return 0; +} + +/* Block handlers */ + +#define BCM2835_ISP_PARAMS_HANDLER(_name, _param_field, _mmal_field) \ +static void bcm2835_isp_params_##_name(struct mmal_parameter_isp_parameter= s *mmal_param, \ + struct bcm2835_isp_params *params, \ + union bcm2835_isp_params_block block) \ +{ \ + memcpy(&mmal_param->_mmal_field, \ + (void *)&block._param_field->_param_field, \ + sizeof(block._param_field->_param_field)); \ + u32 *ptr =3D (u32 *)&mmal_param->_mmal_field; \ + ptr--; \ + *ptr =3D 1; \ +} + +BCM2835_ISP_PARAMS_HANDLER(black_level, black_level, black_level.enable) +BCM2835_ISP_PARAMS_HANDLER(geq, geq, green_eq.enable) +BCM2835_ISP_PARAMS_HANDLER(gamma, gamma, gamma.enable) +BCM2835_ISP_PARAMS_HANDLER(denoise, denoise, denoise.enable) +BCM2835_ISP_PARAMS_HANDLER(sharpen, sharpen, sharpen.enable) +BCM2835_ISP_PARAMS_HANDLER(dpc, dpc, dpc.enable) +BCM2835_ISP_PARAMS_HANDLER(cdn, cdn, colour_denoise.enable) +BCM2835_ISP_PARAMS_HANDLER(cc_matrix, ccm, ccm.enable) +BCM2835_ISP_PARAMS_HANDLER(awb_gains, awb_gains, awb_gains.r_gain) +BCM2835_ISP_PARAMS_HANDLER(digital_gain, digital_gain, digital_gain.value) + +static void bcm2835_isp_params_lens_shading(struct mmal_parameter_isp_para= meters *mmal_param, + struct bcm2835_isp_params *params, + union bcm2835_isp_params_block block) +{ + struct dma_buf *dmabuf =3D dma_buf_get(block.ls->ls.dmabuf); + u32 prev_handle; + int ret =3D 0; + + /* + * struct bcm2835_isp_lens_shading layout matches with what MMAL + * expects, so we can do a simple memcpy here. The descriptor for + * the table needs special handling though. + */ + prev_handle =3D mmal_param->lens_shading.mem_handle_table; + memcpy(&mmal_param->lens_shading.enabled, &block.ls->ls, + sizeof(block.ls->ls)); + + /* + * Map the DMABUF from userspace to a VCSM CMA handle that the firmware + * can import, reusing the old handle if DMABUF was unchanged. + */ + if (dmabuf !=3D params->last_ls_dmabuf) + ret =3D map_ls_table(params, dmabuf, + &mmal_param->lens_shading.mem_handle_table); + else + mmal_param->lens_shading.mem_handle_table =3D prev_handle; + + if (!ret && mmal_param->lens_shading.mem_handle_table) + mmal_param->lens_shading.update =3D 1; + + dma_buf_put(dmabuf); +} + +static const bcm2835_isp_params_handler bcm2835_isp_params_handlers[] =3D { + [BCM2835_ISP_PARAM_BLOCK_BLACK_LEVEL] =3D bcm2835_isp_params_black_level, + [BCM2835_ISP_PARAM_BLOCK_GEQ] =3D bcm2835_isp_params_geq, + [BCM2835_ISP_PARAM_BLOCK_GAMMA] =3D bcm2835_isp_params_gamma, + [BCM2835_ISP_PARAM_BLOCK_DENOISE] =3D bcm2835_isp_params_denoise, + [BCM2835_ISP_PARAM_BLOCK_SHARPEN] =3D bcm2835_isp_params_sharpen, + [BCM2835_ISP_PARAM_BLOCK_DPC] =3D bcm2835_isp_params_dpc, + [BCM2835_ISP_PARAM_BLOCK_CDN] =3D bcm2835_isp_params_cdn, + [BCM2835_ISP_PARAM_BLOCK_CC_MATRIX] =3D bcm2835_isp_params_cc_matrix, + [BCM2835_ISP_PARAM_BLOCK_LENS_SHADING] =3D bcm2835_isp_params_lens_shadin= g, + [BCM2835_ISP_PARAM_BLOCK_AWB_GAINS] =3D bcm2835_isp_params_awb_gains, + [BCM2835_ISP_PARAM_BLOCK_DIGITAL_GAIN] =3D bcm2835_isp_params_digital_gai= n, +}; + +static const struct v4l2_isp_params_block_type_info +bcm2835_isp_params_block_types_info[] =3D { + [BCM2835_ISP_PARAM_BLOCK_BLACK_LEVEL] =3D { + .size =3D sizeof(struct bcm2835_isp_params_black_level), + }, + [BCM2835_ISP_PARAM_BLOCK_GEQ] =3D { + .size =3D sizeof(struct bcm2835_isp_params_geq), + }, + [BCM2835_ISP_PARAM_BLOCK_GAMMA] =3D { + .size =3D sizeof(struct bcm2835_isp_params_gamma), + }, + [BCM2835_ISP_PARAM_BLOCK_DENOISE] =3D { + .size =3D sizeof(struct bcm2835_isp_params_denoise), + }, + [BCM2835_ISP_PARAM_BLOCK_SHARPEN] =3D { + .size =3D sizeof(struct bcm2835_isp_params_sharpen), + }, + [BCM2835_ISP_PARAM_BLOCK_DPC] =3D { + .size =3D sizeof(struct bcm2835_isp_params_dpc), + }, + [BCM2835_ISP_PARAM_BLOCK_CDN] =3D { + .size =3D sizeof(struct bcm2835_isp_params_cdn), + }, + [BCM2835_ISP_PARAM_BLOCK_CC_MATRIX] =3D { + .size =3D sizeof(struct bcm2835_isp_params_cc_matrix), + }, + [BCM2835_ISP_PARAM_BLOCK_LENS_SHADING] =3D { + .size =3D sizeof(struct bcm2835_isp_params_lens_shading), + }, + [BCM2835_ISP_PARAM_BLOCK_AWB_GAINS] =3D { + .size =3D sizeof(struct bcm2835_isp_params_awb_gains), + }, + [BCM2835_ISP_PARAM_BLOCK_DIGITAL_GAIN] =3D { + .size =3D sizeof(struct bcm2835_isp_params_digital_gain), + }, +}; + +static_assert(ARRAY_SIZE(bcm2835_isp_params_handlers) =3D=3D + ARRAY_SIZE(bcm2835_isp_params_block_types_info)); + +static void bcm2835_isp_params_apply(struct bcm2835_isp_params *params, + struct bcm2835_isp_params_buffer *buf) +{ + const struct v4l2_isp_params_buffer *config =3D buf->config; + size_t block_offset =3D 0; + size_t max_offset =3D config->data_size; + struct mmal_parameter_isp_parameters mmal_param =3D { 0 }; + int ret; + + while (block_offset < max_offset) { + union bcm2835_isp_params_block block; + bcm2835_isp_params_handler handler; + + block.data =3D &config->data[block_offset]; + handler =3D bcm2835_isp_params_handlers[block.header->type]; + handler(&mmal_param, params, block); + + block_offset +=3D block.header->size; + } + + ret =3D isp_set_param(params, MMAL_PARAMETER_ISP_SETTINGS, &mmal_param, + sizeof(mmal_param)); + + if (ret) { + dev_err(params->dev, + "%s: MMAL_PARAMETER_ISP_SETTINGS failed with err %d\n", + __func__, ret); + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); + return; + } + + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); +} + +/* vb2 operations */ + +static int bcm2835_isp_params_queue_setup(struct vb2_queue *q, + unsigned int *num_buffers, + unsigned int *num_planes, + unsigned int sizes[], + struct device *alloc_devs[]) +{ + if (*num_planes && *num_planes > 1) + return -EINVAL; + + if (sizes[0] && sizes[0] < BCM2835_ISP_PARAMS_BUF_SIZE) + return -EINVAL; + + *num_planes =3D 1; + + if (!sizes[0]) + sizes[0] =3D BCM2835_ISP_PARAMS_BUF_SIZE; + + return 0; +} + +static int bcm2835_isp_params_buf_init(struct vb2_buffer *vb) +{ + struct bcm2835_isp_params_buffer *buf =3D + to_bcm2835_isp_params_buf(to_vb2_v4l2_buffer(vb)); + + buf->config =3D kvmalloc(BCM2835_ISP_PARAMS_BUF_SIZE, GFP_KERNEL); + if (!buf->config) + return -ENOMEM; + + return 0; +} + +static void bcm2835_isp_params_buf_cleanup(struct vb2_buffer *vb) +{ + struct bcm2835_isp_params_buffer *buf =3D + to_bcm2835_isp_params_buf(to_vb2_v4l2_buffer(vb)); + + kvfree(buf->config); + buf->config =3D NULL; +} + +static int bcm2835_isp_params_buf_prepare(struct vb2_buffer *vb) +{ + struct bcm2835_isp_params *params =3D vb2_get_drv_priv(vb->vb2_queue); + struct bcm2835_isp_params_buffer *buf =3D + to_bcm2835_isp_params_buf(to_vb2_v4l2_buffer(vb)); + const struct v4l2_isp_params_buffer *config; + int ret; + + ret =3D v4l2_isp_params_validate_buffer_size(params->dev, vb, + BCM2835_ISP_PARAMS_BUF_SIZE); + if (ret) + return ret; + + config =3D vb2_plane_vaddr(vb, 0); + if (config->version !=3D BCM2835_ISP_PARAM_BUFFER_V1) + return -EINVAL; + + /* Copy into scratch buffer */ + memcpy(buf->config, config, BCM2835_ISP_PARAMS_BUF_SIZE); + + return v4l2_isp_params_validate_buffer(params->dev, vb, buf->config, + bcm2835_isp_params_block_types_info, + ARRAY_SIZE(bcm2835_isp_params_block_types_info)); +} + +static void bcm2835_isp_params_buf_queue(struct vb2_buffer *vb) +{ + struct bcm2835_isp_params *params =3D vb2_get_drv_priv(vb->vb2_queue); + struct bcm2835_isp_params_buffer *buf =3D + to_bcm2835_isp_params_buf(to_vb2_v4l2_buffer(vb)); + + /* + * Apply params immediately - the firmware will apply them on the + * next frame boundary. + */ + bcm2835_isp_params_apply(params, buf); +} + +static const struct vb2_ops bcm2835_isp_params_vb2_ops =3D { + .queue_setup =3D bcm2835_isp_params_queue_setup, + .buf_init =3D bcm2835_isp_params_buf_init, + .buf_cleanup =3D bcm2835_isp_params_buf_cleanup, + .buf_prepare =3D bcm2835_isp_params_buf_prepare, + .buf_queue =3D bcm2835_isp_params_buf_queue, +}; + +/* V4L2 ioctls */ + +static int bcm2835_isp_params_enum_fmt(struct file *file, void *fh, + struct v4l2_fmtdesc *f) +{ + if (f->index) + return -EINVAL; + + f->pixelformat =3D V4L2_META_FMT_BCM2835_ISP_PARAMS; + + return 0; +} + +static int bcm2835_isp_params_g_fmt(struct file *file, void *fh, + struct v4l2_format *f) +{ + f->fmt.meta.dataformat =3D V4L2_META_FMT_BCM2835_ISP_PARAMS; + f->fmt.meta.buffersize =3D BCM2835_ISP_PARAMS_BUF_SIZE; + + return 0; +} + +static const struct v4l2_ioctl_ops bcm2835_isp_params_ioctl_ops =3D { + .vidioc_querycap =3D bcm2835_isp_node_querycap, + .vidioc_enum_fmt_meta_out =3D bcm2835_isp_params_enum_fmt, + .vidioc_g_fmt_meta_out =3D bcm2835_isp_params_g_fmt, + .vidioc_s_fmt_meta_out =3D bcm2835_isp_params_g_fmt, + .vidioc_try_fmt_meta_out =3D bcm2835_isp_params_g_fmt, + + .vidioc_reqbufs =3D vb2_ioctl_reqbufs, + .vidioc_querybuf =3D vb2_ioctl_querybuf, + .vidioc_qbuf =3D vb2_ioctl_qbuf, + .vidioc_dqbuf =3D vb2_ioctl_dqbuf, + .vidioc_expbuf =3D vb2_ioctl_expbuf, + .vidioc_create_bufs =3D vb2_ioctl_create_bufs, + .vidioc_prepare_buf =3D vb2_ioctl_prepare_buf, + + .vidioc_streamon =3D vb2_ioctl_streamon, + .vidioc_streamoff =3D vb2_ioctl_streamoff, +}; + +static const struct v4l2_file_operations bcm2835_isp_params_fops =3D { + .owner =3D THIS_MODULE, + .open =3D v4l2_fh_open, + .release =3D vb2_fop_release, + .poll =3D vb2_fop_poll, + .unlocked_ioctl =3D video_ioctl2, + .mmap =3D vb2_fop_mmap, +}; + +struct bcm2835_isp_params * +bcm2835_isp_params_register(struct v4l2_device *v4l2_dev, struct device *d= ev, + struct vchiq_mmal_instance *mmal_instance, + struct vchiq_mmal_port *port, int video_nr) +{ + struct mmal_parameter_isp_parameters mmal_param =3D { 0 }; + struct bcm2835_isp_params *params; + struct video_device *vdev; + struct vb2_queue *q; + int ret; + + params =3D devm_kzalloc(dev, sizeof(*params), GFP_KERNEL); + if (!params) + return ERR_PTR(-ENOMEM); + + params->dev =3D dev; + params->v4l2_dev =3D v4l2_dev; + params->mmal_instance =3D mmal_instance; + params->port =3D port; + + /* Test if the firmware supports a combined parameter buffer */ + ret =3D vchiq_mmal_port_parameter_set(params->mmal_instance, + params->port, + MMAL_PARAMETER_ISP_SETTINGS, + &mmal_param, sizeof(mmal_param)); + if (ret) { + dev_err(dev, "Please update to the latest firmware\n" + "\tMMAL_PARAMETER_ISP_SETTINGS failed with err %d\n", + ret); + return ERR_PTR(-EINVAL); + } + + mutex_init(¶ms->lock); + + /* Initialize vb2 queue */ + q =3D ¶ms->queue; + q->type =3D V4L2_BUF_TYPE_META_OUTPUT; + q->io_modes =3D VB2_MMAP | VB2_DMABUF; + q->drv_priv =3D params; + q->ops =3D &bcm2835_isp_params_vb2_ops; + q->mem_ops =3D &vb2_dma_contig_memops; + q->buf_struct_size =3D sizeof(struct bcm2835_isp_params_buffer); + q->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; + q->dev =3D dev; + q->lock =3D ¶ms->lock; + + ret =3D vb2_queue_init(q); + if (ret) { + dev_err(dev, "Failed to init params vb2 queue\n"); + mutex_destroy(¶ms->lock); + return ERR_PTR(ret); + } + + /* Initialize video device */ + vdev =3D ¶ms->vdev; + vdev->device_caps =3D V4L2_CAP_META_OUTPUT | V4L2_CAP_STREAMING; + vdev->fops =3D &bcm2835_isp_params_fops; + vdev->ioctl_ops =3D &bcm2835_isp_params_ioctl_ops; + vdev->minor =3D -1; + vdev->release =3D video_device_release_empty; + vdev->queue =3D q; + vdev->lock =3D ¶ms->lock; + vdev->v4l2_dev =3D v4l2_dev; + vdev->vfl_dir =3D VFL_DIR_TX; + snprintf(vdev->name, sizeof(vdev->name), "%s", BCM2835_ISP_PARAMS_NAME); + + params->pad.flags =3D MEDIA_PAD_FL_SOURCE; + ret =3D media_entity_pads_init(&vdev->entity, 1, ¶ms->pad); + if (ret) { + vb2_queue_release(q); + mutex_destroy(¶ms->lock); + return ERR_PTR(ret); + } + + video_set_drvdata(vdev, params); + + ret =3D video_register_device(vdev, VFL_TYPE_VIDEO, video_nr); + if (ret) { + dev_err(dev, "Failed to register params device node\n"); + media_entity_cleanup(&vdev->entity); + vb2_queue_release(q); + mutex_destroy(¶ms->lock); + return ERR_PTR(ret); + } + + v4l2_info(v4l2_dev, "Params device node registered as /dev/video%d\n", + vdev->num); + + return params; +} + +void bcm2835_isp_params_unregister(struct bcm2835_isp_params *params) +{ + if (!video_is_registered(¶ms->vdev)) + return; + + v4l2_info(params->v4l2_dev, "Unregistering params device node\n"); + + vb2_video_unregister_device(¶ms->vdev); + media_entity_cleanup(¶ms->vdev.entity); + mutex_destroy(¶ms->lock); +} + +/* + * The ISP component on the firmware has a reference to the dmabuf handle = for + * the lens shading table. + * Pass a null handle to remove that reference. + */ +int bcm2835_isp_params_drop_ls_ref(struct bcm2835_isp_params *params) +{ + struct bcm2835_isp_lens_shading ls =3D { + /* Must set a valid grid size for the FW */ + .grid_cell_size =3D 16, + }; + + params->last_ls_dmabuf =3D NULL; + + return isp_set_param(params, MMAL_PARAMETER_LENS_SHADING_OVERRIDE, &ls, + sizeof(ls)); +} diff --git a/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-v4l2-isp.c= b/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-v4l2-isp.c new file mode 100644 index 000000000000..758684ba862b --- /dev/null +++ b/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-v4l2-isp.c @@ -0,0 +1,1509 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Broadcom BCM2835 ISP driver + * + * Copyright (c) 2019-2026 Raspberry Pi (Trading) Ltd. + * Copyright (c) 2026 Ideas On Board Oy + * + * Author: Naushir Patuck (naush@raspberrypi.com) + * + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "bcm2835-isp-fmts.h" +#include "bcm2835-isp-common.h" + +/* + * There is no standard API today for multiplexing ISP instances, so we ha= rdcode + * the number of instances to 1 here. The firmware backend can work with m= ore. + */ +#define BCM2835_ISP_NUM_INSTANCES 1 + +MODULE_IMPORT_NS("DMA_BUF"); + +static unsigned int debug; +module_param(debug, uint, 0644); +MODULE_PARM_DESC(debug, "activates debug info"); + +static unsigned int video_nr[BCM2835_ISP_NUM_INSTANCES] =3D { 13 }; +module_param_array(video_nr, uint, NULL, 0644); +MODULE_PARM_DESC(video_nr, "base video device numbers"); + +#define BCM2835_ISP_NAME "bcm2835-isp" +#define BCM2835_ISP_ENTITY_NAME_LEN 32 + +#define BCM2835_ISP_NUM_OUTPUTS 1 +#define BCM2835_ISP_NUM_CAPTURES 2 +#define BCM2835_ISP_NUM_METADATA 1 +#define BCM2835_ISP_NUM_PARAMS 1 + +#define BCM2835_ISP_NUM_NODES \ + (BCM2835_ISP_NUM_OUTPUTS + BCM2835_ISP_NUM_CAPTURES + \ + BCM2835_ISP_NUM_METADATA) +#define BCM2835_ISP_PARAMS_PAD BCM2835_ISP_NUM_NODES +#define BCM2835_ISP_NUM_ENTITY_PADS \ + (BCM2835_ISP_NUM_NODES + BCM2835_ISP_NUM_PARAMS) + +/* Default frame dimension of 1280 pixels. */ +#define DEFAULT_DIM 1280U +/* + * Maximum frame dimension of 16384 pixels. Even though the ISP runs in t= iles, + * have a sensible limit so that we do not create an excessive number of t= iles + * to process. + */ +#define MAX_DIM 16384U +/* + * Minimum frame dimension of 64 pixels. Anything lower, and the tiling + * algorithm may not be able to cope when applying filter context. + */ +#define MIN_DIM 64U + +/* Timeout for stop_streaming to allow all buffers to return */ +#define COMPLETE_TIMEOUT (2 * HZ) + +/* Per-queue, driver-specific private data */ +struct bcm2835_isp_q_data { + /* + * These parameters should be treated as gospel, with everything else + * being determined from them. + */ + unsigned int bytesperline; + unsigned int width; + unsigned int height; + unsigned int sizeimage; + enum v4l2_colorspace colorspace; + enum v4l2_ycbcr_encoding ycbcr_enc; + enum v4l2_xfer_func xfer_func; + enum v4l2_quantization quantization; + const struct bcm2835_isp_fmt *fmt; +}; + +/* + * Structure to describe a single node /dev/video which represents a si= ngle + * input or output queue to the ISP device. + */ +struct bcm2835_isp_node { + int vfl_dir; + unsigned int id; + const char *name; + struct vchiq_mmal_port *port; + struct video_device vfd; + struct media_pad pad; + struct mutex lock; /* top level device node lock */ + struct mutex queue_lock; + + struct vb2_queue queue; + unsigned int sequence; + + /* The list of formats supported on the node. */ + struct bcm2835_isp_fmt const **supported_fmts; + unsigned int num_supported_fmts; + + struct bcm2835_isp_q_data q_data; + + /* Parent device structure */ + struct bcm2835_isp_dev *dev; + + bool registered; +}; + +/* + * Structure representing the entire ISP device, comprising several input = and + * output nodes /dev/video. + */ +struct bcm2835_isp_dev { + struct v4l2_device v4l2_dev; + struct device *dev; + struct media_device mdev; + struct media_entity entity; + bool media_device_registered; + bool media_entity_registered; + struct vchiq_mmal_instance *mmal_instance; + struct vchiq_mmal_component *component; + struct completion frame_cmplt; + + struct bcm2835_isp_node node[BCM2835_ISP_NUM_NODES]; + struct media_pad pad[BCM2835_ISP_NUM_ENTITY_PADS]; + atomic_t num_streaming; + + /* Extensible params node */ + struct bcm2835_isp_params *params; +}; + +struct bcm2835_isp_buffer { + struct vb2_v4l2_buffer vb; + struct mmal_buffer mmal; +}; + +#define to_bcm2835_isp_buffer(vbuf) \ + container_of(vbuf, struct bcm2835_isp_buffer, vb) + +static +inline struct bcm2835_isp_dev *node_get_dev(struct bcm2835_isp_node *node) +{ + return node->dev; +} + +static inline bool node_is_output(struct bcm2835_isp_node *node) +{ + return node->queue.type =3D=3D V4L2_BUF_TYPE_VIDEO_OUTPUT; +} + +static inline bool node_is_capture(struct bcm2835_isp_node *node) +{ + return node->queue.type =3D=3D V4L2_BUF_TYPE_VIDEO_CAPTURE; +} + +static inline bool node_is_stats(struct bcm2835_isp_node *node) +{ + return node->queue.type =3D=3D V4L2_BUF_TYPE_META_CAPTURE; +} + +static inline enum v4l2_buf_type index_to_queue_type(int index) +{ + if (index < BCM2835_ISP_NUM_OUTPUTS) + return V4L2_BUF_TYPE_VIDEO_OUTPUT; + else if (index < BCM2835_ISP_NUM_OUTPUTS + BCM2835_ISP_NUM_CAPTURES) + return V4L2_BUF_TYPE_VIDEO_CAPTURE; + else + return V4L2_BUF_TYPE_META_CAPTURE; +} + +static const struct bcm2835_isp_fmt *get_fmt(u32 mmal_fmt) +{ + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(supported_formats); i++) { + if (supported_formats[i].mmal_fmt =3D=3D mmal_fmt) + return &supported_formats[i]; + } + return NULL; +} + +static const +struct bcm2835_isp_fmt *find_format_by_fourcc(unsigned int fourcc, + struct bcm2835_isp_node *node) +{ + const struct bcm2835_isp_fmt *fmt; + unsigned int i; + + for (i =3D 0; i < node->num_supported_fmts; i++) { + fmt =3D node->supported_fmts[i]; + if (fmt->fourcc =3D=3D fourcc) + return fmt; + } + + return NULL; +} + +static const +struct bcm2835_isp_fmt *find_format(struct v4l2_format *f, + struct bcm2835_isp_node *node) +{ + return find_format_by_fourcc(node_is_stats(node) ? + f->fmt.meta.dataformat : + f->fmt.pix.pixelformat, + node); +} + +/* vb2_to_mmal_buffer() - converts vb2 buffer header to MMAL + * + * Copies all the required fields from a VB2 buffer to the MMAL buffer hea= der, + * ready for sending to the VPU. + */ +static void vb2_to_mmal_buffer(struct mmal_buffer *buf, + struct vb2_v4l2_buffer *vb2) +{ + u64 pts; + + buf->mmal_flags =3D 0; + if (vb2->flags & V4L2_BUF_FLAG_KEYFRAME) + buf->mmal_flags |=3D MMAL_BUFFER_HEADER_FLAG_KEYFRAME; + + /* Data must be framed correctly as one frame per buffer. */ + buf->mmal_flags |=3D MMAL_BUFFER_HEADER_FLAG_FRAME_END; + + buf->length =3D vb2->vb2_buf.planes[0].bytesused; + /* + * Minor ambiguity in the V4L2 spec as to whether passing in a 0 length + * buffer, or one with V4L2_BUF_FLAG_LAST set denotes end of stream. + * Handle either. + */ + if (!buf->length || (vb2->flags & V4L2_BUF_FLAG_LAST)) + buf->mmal_flags |=3D MMAL_BUFFER_HEADER_FLAG_EOS; + + /* vb2 timestamps in nsecs, mmal in usecs */ + pts =3D vb2->vb2_buf.timestamp; + do_div(pts, 1000); + buf->pts =3D pts; + buf->dts =3D MMAL_TIME_UNKNOWN; +} + +static void mmal_buffer_cb(struct vchiq_mmal_instance *instance, + struct vchiq_mmal_port *port, int status, + struct mmal_buffer *mmal_buf) +{ + struct bcm2835_isp_buffer *q_buf; + struct bcm2835_isp_node *node =3D port->cb_ctx; + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + struct vb2_v4l2_buffer *vb2; + + q_buf =3D container_of(mmal_buf, struct bcm2835_isp_buffer, mmal); + vb2 =3D &q_buf->vb; + v4l2_dbg(2, debug, &dev->v4l2_dev, + "%s: port:%s[%d], status:%d, buf:%p, dmabuf:%p, length:%lu, flags %u, p= ts %lld\n", + __func__, node_is_output(node) ? "input" : "output", node->id, + status, mmal_buf, mmal_buf->dma_buf, mmal_buf->length, + mmal_buf->mmal_flags, mmal_buf->pts); + + if (status) { + /* error in transfer */ + if (vb2) { + /* there was a buffer with the error so return it */ + vb2_buffer_done(&vb2->vb2_buf, VB2_BUF_STATE_ERROR); + } + return; + } + + /* vb2 timestamps in nsecs, mmal in usecs */ + vb2->vb2_buf.timestamp =3D mmal_buf->pts * 1000; + vb2->sequence =3D node->sequence++; + vb2_set_plane_payload(&vb2->vb2_buf, 0, mmal_buf->length); + vb2_buffer_done(&vb2->vb2_buf, VB2_BUF_STATE_DONE); + + if (!port->enabled) + complete(&dev->frame_cmplt); +} + +struct colorspace_translation { + enum v4l2_colorspace v4l2_value; + u32 mmal_value; +}; + +static u32 translate_color_space(enum v4l2_colorspace color_space) +{ + static const struct colorspace_translation translations[] =3D { + { V4L2_COLORSPACE_DEFAULT, MMAL_COLOR_SPACE_UNKNOWN }, + { V4L2_COLORSPACE_SMPTE170M, MMAL_COLOR_SPACE_ITUR_BT601 }, + { V4L2_COLORSPACE_SMPTE240M, MMAL_COLOR_SPACE_SMPTE240M }, + { V4L2_COLORSPACE_REC709, MMAL_COLOR_SPACE_ITUR_BT709 }, + /* V4L2_COLORSPACE_BT878 unavailable */ + { V4L2_COLORSPACE_470_SYSTEM_M, MMAL_COLOR_SPACE_BT470_2_M }, + { V4L2_COLORSPACE_470_SYSTEM_BG, MMAL_COLOR_SPACE_BT470_2_BG }, + { V4L2_COLORSPACE_JPEG, MMAL_COLOR_SPACE_JPEG_JFIF }, + /* + * We don't have an encoding for SRGB as such, but VideoCore + * will do the right thing if it gets "unknown". + */ + { V4L2_COLORSPACE_SRGB, MMAL_COLOR_SPACE_UNKNOWN }, + /* V4L2_COLORSPACE_OPRGB unavailable */ + /* V4L2_COLORSPACE_BT2020 unavailable */ + /* V4L2_COLORSPACE_RAW unavailable */ + /* V4L2_COLORSPACE_DCI_P3 unavailable */ + }; + + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(translations); i++) { + if (color_space =3D=3D translations[i].v4l2_value) + return translations[i].mmal_value; + } + + return MMAL_COLOR_SPACE_UNKNOWN; +} + +static void setup_mmal_port_format(struct bcm2835_isp_node *node, + struct vchiq_mmal_port *port) +{ + struct bcm2835_isp_q_data *q_data =3D &node->q_data; + + port->format.encoding =3D q_data->fmt->mmal_fmt; + /* Raw image format - set width/height */ + port->es.video.width =3D (q_data->bytesperline << 3) / q_data->fmt->depth; + port->es.video.height =3D q_data->height; + port->es.video.crop.width =3D q_data->width; + port->es.video.crop.height =3D q_data->height; + port->es.video.crop.x =3D 0; + port->es.video.crop.y =3D 0; + port->es.video.color_space =3D translate_color_space(q_data->colorspace); +}; + +static int setup_mmal_port(struct bcm2835_isp_node *node) +{ + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + unsigned int enable =3D 1; + int ret; + + v4l2_dbg(2, debug, &dev->v4l2_dev, "%s: setup %s[%d]\n", __func__, + node->name, node->id); + + vchiq_mmal_port_parameter_set(dev->mmal_instance, node->port, + MMAL_PARAMETER_ZERO_COPY, &enable, + sizeof(enable)); + setup_mmal_port_format(node, node->port); + ret =3D vchiq_mmal_port_set_format(dev->mmal_instance, node->port); + if (ret < 0) { + v4l2_dbg(1, debug, &dev->v4l2_dev, + "%s: vchiq_mmal_port_set_format failed\n", + __func__); + return ret; + } + + if (node->q_data.sizeimage < node->port->minimum_buffer.size) { + v4l2_err(&dev->v4l2_dev, + "buffer size mismatch sizeimage %u < min size %u\n", + node->q_data.sizeimage, + node->port->minimum_buffer.size); + return -EINVAL; + } + + return 0; +} + +static int bcm2835_isp_mmal_buf_cleanup(struct mmal_buffer *mmal_buf) +{ + mmal_vchi_buffer_cleanup(mmal_buf); + + if (mmal_buf->dma_buf) { + dma_buf_put(mmal_buf->dma_buf); + mmal_buf->dma_buf =3D NULL; + } + + return 0; +} + +static int bcm2835_isp_node_queue_setup(struct vb2_queue *q, + unsigned int *nbuffers, + unsigned int *nplanes, + unsigned int sizes[], + struct device *alloc_devs[]) +{ + struct bcm2835_isp_node *node =3D vb2_get_drv_priv(q); + unsigned int size; + + if (setup_mmal_port(node)) + return -EINVAL; + + size =3D node->q_data.sizeimage; + if (size =3D=3D 0) { + v4l2_info(&node_get_dev(node)->v4l2_dev, + "%s: Image size unset in queue_setup for node %s[%d]\n", + __func__, node->name, node->id); + return -EINVAL; + } + + if (*nplanes) + return sizes[0] < size ? -EINVAL : 0; + + *nplanes =3D 1; + sizes[0] =3D size; + + node->port->current_buffer.size =3D size; + + if (*nbuffers < node->port->minimum_buffer.num) + *nbuffers =3D node->port->minimum_buffer.num; + + node->port->current_buffer.num =3D *nbuffers; + + v4l2_dbg(2, debug, &node_get_dev(node)->v4l2_dev, + "%s: Image size %u, nbuffers %u for node %s[%d]\n", + __func__, sizes[0], *nbuffers, node->name, node->id); + return 0; +} + +static int bcm2835_isp_buf_init(struct vb2_buffer *vb) +{ + struct bcm2835_isp_node *node =3D vb2_get_drv_priv(vb->vb2_queue); + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + struct bcm2835_isp_buffer *buf =3D + to_bcm2835_isp_buffer(to_vb2_v4l2_buffer(vb)); + + v4l2_dbg(3, debug, &dev->v4l2_dev, "%s: vb %p\n", __func__, vb); + + buf->mmal.buffer =3D vb2_plane_vaddr(&buf->vb.vb2_buf, 0); + buf->mmal.buffer_size =3D vb2_plane_size(&buf->vb.vb2_buf, 0); + mmal_vchi_buffer_init(dev->mmal_instance, &buf->mmal); + return 0; +} + +static int bcm2835_isp_buf_prepare(struct vb2_buffer *vb) +{ + struct bcm2835_isp_node *node =3D vb2_get_drv_priv(vb->vb2_queue); + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + struct vb2_v4l2_buffer *vb2 =3D to_vb2_v4l2_buffer(vb); + struct bcm2835_isp_buffer *buf =3D to_bcm2835_isp_buffer(vb2); + struct dma_buf *dma_buf; + int ret =3D 0; + + v4l2_dbg(3, debug, &dev->v4l2_dev, "%s: type: %d ptr %p\n", + __func__, vb->vb2_queue->type, vb); + + if (V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) { + if (vb2->field =3D=3D V4L2_FIELD_ANY) + vb2->field =3D V4L2_FIELD_NONE; + if (vb2->field !=3D V4L2_FIELD_NONE) { + v4l2_err(&dev->v4l2_dev, + "%s field isn't supported\n", __func__); + return -EINVAL; + } + } + + if (vb2_plane_size(vb, 0) < node->q_data.sizeimage) { + v4l2_err(&dev->v4l2_dev, + "%s data will not fit into plane (%lu < %u)\n", + __func__, vb2_plane_size(vb, 0), + node->q_data.sizeimage); + return -EINVAL; + } + + if (!V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) + vb2_set_plane_payload(vb, 0, node->q_data.sizeimage); + + switch (vb->memory) { + case VB2_MEMORY_DMABUF: + dma_buf =3D dma_buf_get(vb->planes[0].m.fd); + + if (dma_buf !=3D buf->mmal.dma_buf) { + /* + * dmabuf either hasn't already been mapped, or it has + * changed. + */ + if (buf->mmal.dma_buf) { + v4l2_err(&dev->v4l2_dev, + "%s Buffer changed - why did the core not call cleanup?\n", + __func__); + bcm2835_isp_mmal_buf_cleanup(&buf->mmal); + } + + buf->mmal.dma_buf =3D dma_buf; + } else { + /* + * Already have a reference to the buffer, so release it + * here. + */ + dma_buf_put(dma_buf); + } + break; + case VB2_MEMORY_MMAP: + /* + * We want to do this at init, but vb2_core_expbuf checks that + * the index < q->num_buffers, and q->num_buffers only gets + * updated once all the buffers are allocated. + */ + if (!buf->mmal.dma_buf) { + buf->mmal.dma_buf =3D + vb2_core_expbuf_dmabuf(vb->vb2_queue, vb, 0, + O_CLOEXEC); + v4l2_dbg(3, debug, &dev->v4l2_dev, + "%s: exporting ptr %p to dmabuf %p\n", + __func__, vb, buf->mmal.dma_buf); + if (IS_ERR_OR_NULL(buf->mmal.dma_buf)) { + ret =3D PTR_ERR(buf->mmal.dma_buf); + v4l2_err(&dev->v4l2_dev, + "%s: Failed to expbuf idx %d, ret %d\n", + __func__, vb->index, ret); + buf->mmal.dma_buf =3D NULL; + } + } + break; + default: + ret =3D -EINVAL; + break; + } + + return ret; +} + +static void bcm2835_isp_node_buffer_queue(struct vb2_buffer *buf) +{ + struct bcm2835_isp_node *node =3D vb2_get_drv_priv(buf->vb2_queue); + struct bcm2835_isp_buffer *buffer =3D + to_bcm2835_isp_buffer(to_vb2_v4l2_buffer(buf)); + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + + v4l2_dbg(3, debug, &dev->v4l2_dev, "%s: node %s[%d], buffer %p\n", + __func__, node->name, node->id, buffer); + + vb2_to_mmal_buffer(&buffer->mmal, &buffer->vb); + v4l2_dbg(3, debug, &dev->v4l2_dev, + "%s: node %s[%d] - submitting mmal dmabuf %p\n", __func__, + node->name, node->id, buffer->mmal.dma_buf); + vchiq_mmal_submit_buffer(dev->mmal_instance, node->port, &buffer->mmal); +} + +static void bcm2835_isp_buffer_cleanup(struct vb2_buffer *vb) +{ + struct bcm2835_isp_buffer *buffer =3D + to_bcm2835_isp_buffer(to_vb2_v4l2_buffer(vb)); + + bcm2835_isp_mmal_buf_cleanup(&buffer->mmal); +} + +static int bcm2835_isp_node_start_streaming(struct vb2_queue *q, + unsigned int count) +{ + struct bcm2835_isp_node *node =3D vb2_get_drv_priv(q); + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + int ret; + + v4l2_dbg(1, debug, &dev->v4l2_dev, "%s: node %s[%d] (count %u)\n", + __func__, node->name, node->id, count); + + ret =3D vchiq_mmal_component_enable(dev->mmal_instance, dev->component); + if (ret) { + v4l2_err(&dev->v4l2_dev, "%s: Failed enabling component, ret %d\n", + __func__, ret); + return -EIO; + } + + node->sequence =3D 0; + node->port->cb_ctx =3D node; + ret =3D vchiq_mmal_port_enable(dev->mmal_instance, node->port, + mmal_buffer_cb); + if (!ret) + atomic_inc(&dev->num_streaming); + else + v4l2_err(&dev->v4l2_dev, + "%s: Failed enabling port, ret %d\n", __func__, ret); + + return ret; +} + +static void bcm2835_isp_node_stop_streaming(struct vb2_queue *q) +{ + struct bcm2835_isp_node *node =3D vb2_get_drv_priv(q); + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + int ret; + + v4l2_dbg(1, debug, &dev->v4l2_dev, "%s: node %s[%d], mmal port %p\n", + __func__, node->name, node->id, node->port); + + init_completion(&dev->frame_cmplt); + + /* Disable MMAL port - this will flush buffers back */ + ret =3D vchiq_mmal_port_disable(dev->mmal_instance, node->port); + if (ret) + v4l2_err(&dev->v4l2_dev, + "%s: Failed disabling %s port, ret %d\n", __func__, + node_is_output(node) ? "i/p" : "o/p", + ret); + + while (atomic_read(&node->port->buffers_with_vpu)) { + v4l2_dbg(1, debug, &dev->v4l2_dev, + "%s: Waiting for buffers to be returned - %d outstanding\n", + __func__, atomic_read(&node->port->buffers_with_vpu)); + ret =3D wait_for_completion_timeout(&dev->frame_cmplt, + COMPLETE_TIMEOUT); + if (ret <=3D 0) { + v4l2_err(&dev->v4l2_dev, + "%s: Timeout waiting for buffers to be returned - %d outstanding\n", + __func__, + atomic_read(&node->port->buffers_with_vpu)); + break; + } + } + + atomic_dec(&dev->num_streaming); + /* If all ports disabled, then disable the component */ + if (atomic_read(&dev->num_streaming) =3D=3D 0) { + ret =3D bcm2835_isp_params_drop_ls_ref(dev->params); + if (ret) { + v4l2_err(&dev->v4l2_dev, + "%s: Failed dropping LS buffer, ret %d\n", + __func__, ret); + } + + ret =3D vchiq_mmal_component_disable(dev->mmal_instance, + dev->component); + if (ret) { + v4l2_err(&dev->v4l2_dev, + "%s: Failed disabling component, ret %d\n", + __func__, ret); + } + } + + /* + * Simply wait for any vb2 buffers to finish. We could take steps to + * make them complete more quickly if we care, or even return them + * ourselves. + */ + vb2_wait_for_all_buffers(&node->queue); +} + +static const struct vb2_ops bcm2835_isp_node_queue_ops =3D { + .queue_setup =3D bcm2835_isp_node_queue_setup, + .buf_init =3D bcm2835_isp_buf_init, + .buf_prepare =3D bcm2835_isp_buf_prepare, + .buf_queue =3D bcm2835_isp_node_buffer_queue, + .buf_cleanup =3D bcm2835_isp_buffer_cleanup, + .start_streaming =3D bcm2835_isp_node_start_streaming, + .stop_streaming =3D bcm2835_isp_node_stop_streaming, +}; + +static const +struct bcm2835_isp_fmt *get_default_format(struct bcm2835_isp_node *node) +{ + return node->supported_fmts[0]; +} + +static inline unsigned int get_bytesperline(int width, + const struct bcm2835_isp_fmt *fmt) +{ + /* GPU aligns 24bpp images to a multiple of 32 pixels (not bytes). */ + if (fmt->depth =3D=3D 24) + return ALIGN(width, 32) * 3; + else + return ALIGN((width * fmt->depth) >> 3, fmt->bytesperline_align); +} + +static inline unsigned int get_sizeimage(int bpl, int width, int height, + const struct bcm2835_isp_fmt *fmt) +{ + return (bpl * height * fmt->size_multiplier_x2) >> 1; +} + +static const struct v4l2_file_operations bcm2835_isp_fops =3D { + .owner =3D THIS_MODULE, + .open =3D v4l2_fh_open, + .release =3D vb2_fop_release, + .poll =3D vb2_fop_poll, + .unlocked_ioctl =3D video_ioctl2, + .mmap =3D vb2_fop_mmap +}; + +static int populate_qdata_fmt(struct v4l2_format *f, + struct bcm2835_isp_node *node) +{ + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + struct bcm2835_isp_q_data *q_data =3D &node->q_data; + int ret; + + if (!node_is_stats(node)) { + v4l2_dbg(1, debug, &dev->v4l2_dev, + "%s: Setting pix format for type %d, wxh: %ux%u, fmt: %08x, size %u\n", + __func__, f->type, f->fmt.pix.width, f->fmt.pix.height, + f->fmt.pix.pixelformat, f->fmt.pix.sizeimage); + + q_data->fmt =3D find_format(f, node); + q_data->width =3D f->fmt.pix.width; + q_data->height =3D f->fmt.pix.height; + + /* All parameters should have been set correctly by try_fmt */ + q_data->bytesperline =3D f->fmt.pix.bytesperline; + q_data->sizeimage =3D f->fmt.pix.sizeimage; + q_data->ycbcr_enc =3D f->fmt.pix.ycbcr_enc; + q_data->xfer_func =3D f->fmt.pix.xfer_func; + q_data->quantization =3D f->fmt.pix.quantization; + + /* We must indicate which of the allowed colour spaces we have. */ + q_data->colorspace =3D f->fmt.pix.colorspace; + } else { + v4l2_dbg(1, debug, &dev->v4l2_dev, + "%s: Setting meta format for fmt: %08x, size %u\n", + __func__, f->fmt.meta.dataformat, + f->fmt.meta.buffersize); + + q_data->fmt =3D find_format(f, node); + q_data->width =3D 0; + q_data->height =3D 0; + q_data->bytesperline =3D 0; + q_data->sizeimage =3D f->fmt.meta.buffersize; + + /* This won't mean anything for metadata, but may as well fill it in. */ + q_data->colorspace =3D V4L2_COLORSPACE_DEFAULT; + } + + v4l2_dbg(1, debug, &dev->v4l2_dev, + "%s: Calculated bpl as %u, size %u\n", __func__, + q_data->bytesperline, q_data->sizeimage); + + setup_mmal_port_format(node, node->port); + ret =3D vchiq_mmal_port_set_format(dev->mmal_instance, node->port); + if (ret) { + v4l2_err(&dev->v4l2_dev, + "%s: Failed vchiq_mmal_port_set_format on port, ret %d\n", + __func__, ret); + ret =3D -EINVAL; + } + + if (q_data->sizeimage < node->port->minimum_buffer.size) { + v4l2_err(&dev->v4l2_dev, + "%s: Current buffer size of %u < min buf size %u - driver mismatch to = MMAL\n", + __func__, + q_data->sizeimage, + node->port->minimum_buffer.size); + ret =3D -EINVAL; + } + + v4l2_dbg(1, debug, &dev->v4l2_dev, + "%s: Set format for type %d, wxh: %dx%d, fmt: %08x, size %u\n", + __func__, f->type, q_data->width, q_data->height, + q_data->fmt->fourcc, q_data->sizeimage); + + return ret; +} + +int bcm2835_isp_node_querycap(struct file *file, void *priv, + struct v4l2_capability *cap) +{ + strscpy(cap->driver, BCM2835_ISP_NAME, sizeof(cap->driver)); + strscpy(cap->card, BCM2835_ISP_NAME, sizeof(cap->card)); + snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", + BCM2835_ISP_NAME); + + return 0; +} + +static int bcm2835_isp_node_g_fmt(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct bcm2835_isp_node *node =3D video_drvdata(file); + + if (f->type !=3D node->queue.type) + return -EINVAL; + + if (node_is_stats(node)) { + f->fmt.meta.dataformat =3D V4L2_META_FMT_BCM2835_ISP_STATS; + f->fmt.meta.buffersize =3D + node->port->minimum_buffer.size; + } else { + struct bcm2835_isp_q_data *q_data =3D &node->q_data; + + f->fmt.pix.width =3D q_data->width; + f->fmt.pix.height =3D q_data->height; + f->fmt.pix.field =3D V4L2_FIELD_NONE; + f->fmt.pix.pixelformat =3D q_data->fmt->fourcc; + f->fmt.pix.bytesperline =3D q_data->bytesperline; + f->fmt.pix.sizeimage =3D q_data->sizeimage; + f->fmt.pix.colorspace =3D q_data->colorspace; + f->fmt.pix.ycbcr_enc =3D q_data->ycbcr_enc; + f->fmt.pix.xfer_func =3D q_data->xfer_func; + f->fmt.pix.quantization =3D q_data->quantization; + } + + return 0; +} + +static int bcm2835_isp_node_enum_fmt(struct file *file, void *priv, + struct v4l2_fmtdesc *f) +{ + struct bcm2835_isp_node *node =3D video_drvdata(file); + + if (f->type !=3D node->queue.type) + return -EINVAL; + + if (f->index < node->num_supported_fmts) { + /* Format found */ + f->pixelformat =3D node->supported_fmts[f->index]->fourcc; + f->flags =3D 0; + return 0; + } + + return -EINVAL; +} + +static int bcm2835_isp_enum_framesizes(struct file *file, void *priv, + struct v4l2_frmsizeenum *fsize) +{ + struct bcm2835_isp_node *node =3D video_drvdata(file); + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + const struct bcm2835_isp_fmt *fmt; + + if (node_is_stats(node) || fsize->index) + return -EINVAL; + + fmt =3D find_format_by_fourcc(fsize->pixel_format, node); + if (!fmt) { + v4l2_err(&dev->v4l2_dev, "Invalid pixel code: %x\n", + fsize->pixel_format); + return -EINVAL; + } + + fsize->type =3D V4L2_FRMSIZE_TYPE_STEPWISE; + fsize->stepwise.min_width =3D MIN_DIM; + fsize->stepwise.max_width =3D MAX_DIM; + fsize->stepwise.step_width =3D fmt->step_size; + + fsize->stepwise.min_height =3D MIN_DIM; + fsize->stepwise.max_height =3D MAX_DIM; + fsize->stepwise.step_height =3D fmt->step_size; + + return 0; +} + +static int bcm2835_isp_node_try_fmt(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct bcm2835_isp_node *node =3D video_drvdata(file); + const struct bcm2835_isp_fmt *fmt; + + if (f->type !=3D node->queue.type) + return -EINVAL; + + fmt =3D find_format(f, node); + if (!fmt) + fmt =3D get_default_format(node); + + if (!node_is_stats(node)) { + bool is_rgb; + + f->fmt.pix.width =3D clamp_t(u32, f->fmt.pix.width, MIN_DIM, + MAX_DIM); + f->fmt.pix.height =3D clamp_t(u32, f->fmt.pix.height, MIN_DIM, + MAX_DIM); + f->fmt.pix.pixelformat =3D fmt->fourcc; + + /* + * Fill in the actual colour space when the requested one was + * not supported. This also catches the case when the "default" + * colour space was requested (as that's never in the mask). + */ + if (!(V4L2_COLORSPACE_MASK(f->fmt.pix.colorspace) & fmt->colorspace_mask= )) + f->fmt.pix.colorspace =3D fmt->colorspace_default; + /* In all cases, we only support the defaults for these: */ + f->fmt.pix.ycbcr_enc =3D V4L2_MAP_YCBCR_ENC_DEFAULT(f->fmt.pix.colorspac= e); + f->fmt.pix.xfer_func =3D V4L2_MAP_XFER_FUNC_DEFAULT(f->fmt.pix.colorspac= e); + /* RAW counts as sRGB here so that we get full range. */ + is_rgb =3D f->fmt.pix.colorspace =3D=3D V4L2_COLORSPACE_SRGB || + f->fmt.pix.colorspace =3D=3D V4L2_COLORSPACE_RAW; + f->fmt.pix.quantization =3D V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb, + f->fmt.pix.colorspace, + f->fmt.pix.ycbcr_enc); + + /* Respect any stride value (suitably aligned) that was requested. */ + f->fmt.pix.bytesperline =3D max(get_bytesperline(f->fmt.pix.width, fmt), + ALIGN(f->fmt.pix.bytesperline, + fmt->bytesperline_align)); + f->fmt.pix.field =3D V4L2_FIELD_NONE; + f->fmt.pix.sizeimage =3D + get_sizeimage(f->fmt.pix.bytesperline, f->fmt.pix.width, + f->fmt.pix.height, fmt); + } else { + f->fmt.meta.dataformat =3D fmt->fourcc; + f->fmt.meta.buffersize =3D node->port->minimum_buffer.size; + } + + return 0; +} + +static int bcm2835_isp_node_s_fmt(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct bcm2835_isp_node *node =3D video_drvdata(file); + int ret; + + if (f->type !=3D node->queue.type) + return -EINVAL; + + ret =3D bcm2835_isp_node_try_fmt(file, priv, f); + if (ret) + return ret; + + v4l2_dbg(1, debug, &node_get_dev(node)->v4l2_dev, + "%s: Set format for node %s[%d]\n", + __func__, node->name, node->id); + + return populate_qdata_fmt(f, node); +} + +static int bcm2835_isp_node_s_selection(struct file *file, void *fh, + struct v4l2_selection *s) +{ + struct mmal_parameter_crop crop; + struct bcm2835_isp_node *node =3D video_drvdata(file); + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + + if (!node_is_output(node)) + return -EINVAL; + + if (!s->r.width || !s->r.height) + return -EINVAL; + + /* We can only set crop on the input. */ + switch (s->target) { + case V4L2_SEL_TGT_CROP: + /* + * Adjust the crop window if it goes outside of the frame + * dimensions. + */ + s->r.left =3D clamp_t(unsigned int, s->r.left, 0, + node->q_data.width - MIN_DIM); + s->r.top =3D clamp_t(unsigned int, s->r.top, 0, + node->q_data.height - MIN_DIM); + s->r.width =3D clamp_t(unsigned int, s->r.width, MIN_DIM, + node->q_data.width - s->r.left); + s->r.height =3D clamp_t(unsigned int, s->r.height, MIN_DIM, + node->q_data.height - s->r.top); + break; + default: + return -EINVAL; + } + + crop.rect.x =3D s->r.left; + crop.rect.y =3D s->r.top; + crop.rect.width =3D s->r.width; + crop.rect.height =3D s->r.height; + + return vchiq_mmal_port_parameter_set(dev->mmal_instance, node->port, + MMAL_PARAMETER_CROP, + &crop, sizeof(crop)); +} + +static int bcm2835_isp_node_g_selection(struct file *file, void *fh, + struct v4l2_selection *s) +{ + struct mmal_parameter_crop crop; + struct bcm2835_isp_node *node =3D video_drvdata(file); + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + u32 crop_size =3D sizeof(crop); + int ret; + + if (!node_is_output(node)) + return -EINVAL; + + /* We can only return out an input crop. */ + switch (s->target) { + case V4L2_SEL_TGT_CROP: + ret =3D vchiq_mmal_port_parameter_get(dev->mmal_instance, + node->port, + MMAL_PARAMETER_CROP, + &crop, &crop_size); + if (!ret) { + s->r.left =3D crop.rect.x; + s->r.top =3D crop.rect.y; + s->r.width =3D crop.rect.width; + s->r.height =3D crop.rect.height; + } + break; + case V4L2_SEL_TGT_CROP_DEFAULT: + case V4L2_SEL_TGT_CROP_BOUNDS: + /* Default (i.e. no) crop window. */ + s->r.left =3D 0; + s->r.top =3D 0; + s->r.width =3D node->q_data.width; + s->r.height =3D node->q_data.height; + ret =3D 0; + break; + default: + ret =3D -EINVAL; + } + + return ret; +} + +static const struct v4l2_ioctl_ops bcm2835_isp_node_ioctl_ops =3D { + .vidioc_querycap =3D bcm2835_isp_node_querycap, + .vidioc_g_fmt_vid_cap =3D bcm2835_isp_node_g_fmt, + .vidioc_g_fmt_vid_out =3D bcm2835_isp_node_g_fmt, + .vidioc_g_fmt_meta_cap =3D bcm2835_isp_node_g_fmt, + .vidioc_s_fmt_vid_cap =3D bcm2835_isp_node_s_fmt, + .vidioc_s_fmt_vid_out =3D bcm2835_isp_node_s_fmt, + .vidioc_s_fmt_meta_cap =3D bcm2835_isp_node_s_fmt, + .vidioc_try_fmt_vid_cap =3D bcm2835_isp_node_try_fmt, + .vidioc_try_fmt_vid_out =3D bcm2835_isp_node_try_fmt, + .vidioc_try_fmt_meta_cap =3D bcm2835_isp_node_try_fmt, + .vidioc_s_selection =3D bcm2835_isp_node_s_selection, + .vidioc_g_selection =3D bcm2835_isp_node_g_selection, + + .vidioc_enum_fmt_vid_cap =3D bcm2835_isp_node_enum_fmt, + .vidioc_enum_fmt_vid_out =3D bcm2835_isp_node_enum_fmt, + .vidioc_enum_fmt_meta_cap =3D bcm2835_isp_node_enum_fmt, + .vidioc_enum_framesizes =3D bcm2835_isp_enum_framesizes, + + .vidioc_reqbufs =3D vb2_ioctl_reqbufs, + .vidioc_querybuf =3D vb2_ioctl_querybuf, + .vidioc_qbuf =3D vb2_ioctl_qbuf, + .vidioc_dqbuf =3D vb2_ioctl_dqbuf, + .vidioc_expbuf =3D vb2_ioctl_expbuf, + .vidioc_create_bufs =3D vb2_ioctl_create_bufs, + .vidioc_prepare_buf =3D vb2_ioctl_prepare_buf, + + .vidioc_streamon =3D vb2_ioctl_streamon, + .vidioc_streamoff =3D vb2_ioctl_streamoff, +}; + +/* + * Size of the array to provide to the VPU when asking for the list of sup= ported + * formats. + * + * The ISP component currently advertises 62 input formats, so add a small + * overhead on that. Should the component advertise more formats then the = excess + * will be dropped and a warning logged. + */ +#define MAX_SUPPORTED_ENCODINGS 70 + +/* Populate node->supported_fmts with the formats supported by those ports= . */ +static int bcm2835_isp_get_supported_fmts(struct bcm2835_isp_node *node) +{ + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + struct bcm2835_isp_fmt const **list; + unsigned int i, j, num_encodings; + u32 fourccs[MAX_SUPPORTED_ENCODINGS]; + u32 param_size =3D sizeof(fourccs); + int ret; + + ret =3D vchiq_mmal_port_parameter_get(dev->mmal_instance, node->port, + MMAL_PARAMETER_SUPPORTED_ENCODINGS, + &fourccs, ¶m_size); + + if (ret) { + if (ret =3D=3D MMAL_MSG_STATUS_ENOSPC) { + v4l2_err(&dev->v4l2_dev, + "%s: port has more encodings than we provided space for. Some are dro= pped (%zu vs %u).\n", + __func__, param_size / sizeof(u32), + MAX_SUPPORTED_ENCODINGS); + num_encodings =3D MAX_SUPPORTED_ENCODINGS; + } else { + v4l2_err(&dev->v4l2_dev, "%s: get_param ret %u.\n", + __func__, ret); + return -EINVAL; + } + } else { + num_encodings =3D param_size / sizeof(u32); + } + + /* + * Assume at this stage that all encodings will be supported in V4L2. + * Any that aren't supported will waste a very small amount of memory. + */ + list =3D devm_kzalloc(dev->dev, + sizeof(struct bcm2835_isp_fmt *) * num_encodings, + GFP_KERNEL); + if (!list) + return -ENOMEM; + node->supported_fmts =3D list; + + for (i =3D 0, j =3D 0; i < num_encodings; i++) { + const struct bcm2835_isp_fmt *fmt =3D get_fmt(fourccs[i]); + + if (fmt) { + list[j] =3D fmt; + j++; + } + } + node->num_supported_fmts =3D j; + + return 0; +} + +/* + * Register a device node /dev/video to go along with one of the ISP's = input + * or output nodes. + */ +static int bcm2835_isp_register_node(struct bcm2835_isp_dev *dev, + unsigned int instance, + struct bcm2835_isp_node *node, int index) +{ + struct video_device *vfd; + struct vb2_queue *queue; + bool is_rgb; + int ret; + + mutex_init(&node->lock); + mutex_init(&node->queue_lock); + + node->dev =3D dev; + vfd =3D &node->vfd; + queue =3D &node->queue; + queue->type =3D index_to_queue_type(index); + /* + * Setup the node type-specific params. + */ + switch (queue->type) { + case V4L2_BUF_TYPE_VIDEO_OUTPUT: + vfd->device_caps =3D V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; + node->id =3D index; + node->vfl_dir =3D VFL_DIR_TX; + node->name =3D "output"; + node->port =3D &dev->component->input[node->id]; + break; + case V4L2_BUF_TYPE_VIDEO_CAPTURE: + vfd->device_caps =3D V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; + /* First Capture node starts at id 0, etc. */ + node->id =3D index - BCM2835_ISP_NUM_OUTPUTS; + node->vfl_dir =3D VFL_DIR_RX; + node->name =3D "capture"; + node->port =3D &dev->component->output[node->id]; + break; + case V4L2_BUF_TYPE_META_CAPTURE: + vfd->device_caps =3D V4L2_CAP_META_CAPTURE | V4L2_CAP_STREAMING; + node->id =3D index - BCM2835_ISP_NUM_OUTPUTS; + node->vfl_dir =3D VFL_DIR_RX; + node->name =3D "stats"; + node->port =3D &dev->component->output[node->id]; + break; + } + + ret =3D bcm2835_isp_get_supported_fmts(node); + if (ret) + return ret; + + /* Initialise the video node. */ + vfd->vfl_type =3D VFL_TYPE_VIDEO; + vfd->fops =3D &bcm2835_isp_fops; + vfd->ioctl_ops =3D &bcm2835_isp_node_ioctl_ops; + vfd->minor =3D -1; + vfd->release =3D video_device_release_empty; + vfd->queue =3D &node->queue; + vfd->lock =3D &node->lock; + vfd->v4l2_dev =3D &dev->v4l2_dev; + vfd->vfl_dir =3D node->vfl_dir; + + node->q_data.fmt =3D get_default_format(node); + node->q_data.width =3D DEFAULT_DIM; + node->q_data.height =3D DEFAULT_DIM; + node->q_data.bytesperline =3D + get_bytesperline(DEFAULT_DIM, node->q_data.fmt); + node->q_data.sizeimage =3D node_is_stats(node) ? + node->port->recommended_buffer.size : + get_sizeimage(node->q_data.bytesperline, + node->q_data.width, + node->q_data.height, + node->q_data.fmt); + node->q_data.colorspace =3D node->q_data.fmt->colorspace_default; + node->q_data.ycbcr_enc =3D + V4L2_MAP_YCBCR_ENC_DEFAULT(node->q_data.colorspace); + node->q_data.xfer_func =3D + V4L2_MAP_XFER_FUNC_DEFAULT(node->q_data.colorspace); + is_rgb =3D node->q_data.colorspace =3D=3D V4L2_COLORSPACE_SRGB || + node->q_data.colorspace =3D=3D V4L2_COLORSPACE_RAW; + node->q_data.quantization =3D V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb, + node->q_data.colorspace, + node->q_data.ycbcr_enc); + + queue->io_modes =3D VB2_MMAP | VB2_DMABUF; + queue->drv_priv =3D node; + queue->ops =3D &bcm2835_isp_node_queue_ops; + queue->mem_ops =3D &vb2_dma_contig_memops; + queue->buf_struct_size =3D sizeof(struct bcm2835_isp_buffer); + queue->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; + queue->dev =3D dev->dev; + queue->lock =3D &node->queue_lock; + + ret =3D vb2_queue_init(queue); + if (ret < 0) { + v4l2_info(&dev->v4l2_dev, "vb2_queue_init failed\n"); + return ret; + } + + /* Define the device names */ + snprintf(vfd->name, sizeof(node->vfd.name), "%s-%s%d", BCM2835_ISP_NAME, + node->name, node->id); + + node->pad.flags =3D node_is_output(node) ? MEDIA_PAD_FL_SOURCE : MEDIA_PA= D_FL_SINK; + ret =3D media_entity_pads_init(&node->vfd.entity, 1, &node->pad); + if (ret) + goto queue_cleanup; + + ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, video_nr[instance]); + if (ret) { + v4l2_err(&dev->v4l2_dev, + "Failed to register video %s[%d] device node\n", + node->name, node->id); + goto queue_cleanup; + } + + node->registered =3D true; + video_set_drvdata(vfd, node); + + v4l2_info(&dev->v4l2_dev, + "Device node %s[%d] registered as /dev/video%d\n", + node->name, node->id, vfd->num); + + return 0; + +queue_cleanup: + vb2_queue_release(&node->queue); + return ret; +} + +/* Unregister one of the /dev/video nodes associated with the ISP. */ +static void bcm2835_unregister_node(struct bcm2835_isp_node *node) +{ + struct bcm2835_isp_dev *dev =3D node_get_dev(node); + + v4l2_info(&dev->v4l2_dev, + "Unregistering node %s[%d] device node /dev/video%d\n", + node->name, node->id, node->vfd.num); + + if (node->registered) { + video_unregister_device(&node->vfd); + vb2_queue_release(&node->queue); + } + + /* + * node->supported_fmts.list is free'd automatically + * as a managed resource. + */ + node->supported_fmts =3D NULL; + node->num_supported_fmts =3D 0; + node->registered =3D false; +} + +static void media_controller_unregister(struct bcm2835_isp_dev *dev) +{ + v4l2_info(&dev->v4l2_dev, "Unregister from media controller\n"); + + if (dev->media_device_registered) { + media_device_unregister(&dev->mdev); + media_device_cleanup(&dev->mdev); + dev->media_device_registered =3D false; + } + + kfree(dev->entity.name); + dev->entity.name =3D NULL; + + if (dev->media_entity_registered) { + media_device_unregister_entity(&dev->entity); + dev->media_entity_registered =3D false; + } + + dev->v4l2_dev.mdev =3D NULL; +} + +static int media_controller_register(struct bcm2835_isp_dev *dev) +{ + struct media_entity *entity; + char *name; + unsigned int i; + int ret; + + v4l2_dbg(2, debug, &dev->v4l2_dev, "Registering with media controller\n"); + + name =3D kmalloc(BCM2835_ISP_ENTITY_NAME_LEN, GFP_KERNEL); + if (!name) { + ret =3D -ENOMEM; + goto done; + } + snprintf(name, BCM2835_ISP_ENTITY_NAME_LEN, "bcm2835-isp"); + dev->entity.name =3D name; + dev->entity.obj_type =3D MEDIA_ENTITY_TYPE_BASE; + dev->entity.function =3D MEDIA_ENT_F_PROC_VIDEO_ISP; + + for (i =3D 0; i < BCM2835_ISP_NUM_NODES; i++) { + dev->pad[i].flags =3D node_is_output(&dev->node[i]) ? + MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE; + } + dev->pad[BCM2835_ISP_PARAMS_PAD].flags =3D MEDIA_PAD_FL_SINK; + + ret =3D media_entity_pads_init(&dev->entity, BCM2835_ISP_NUM_ENTITY_PADS, + dev->pad); + if (ret) + goto done; + + ret =3D media_device_register_entity(&dev->mdev, &dev->entity); + if (ret) + goto done; + + dev->media_entity_registered =3D true; + + for (i =3D 0; i < BCM2835_ISP_NUM_NODES; i++) { + entity =3D &dev->node[i].vfd.entity; + int output =3D node_is_output(&dev->node[i]); + + if (output) + ret =3D media_create_pad_link(entity, 0, + &dev->entity, i, + MEDIA_LNK_FL_IMMUTABLE | + MEDIA_LNK_FL_ENABLED); + else + ret =3D media_create_pad_link(&dev->entity, i, + entity, 0, + MEDIA_LNK_FL_IMMUTABLE | + MEDIA_LNK_FL_ENABLED); + if (ret) + goto done; + } + + entity =3D &dev->params->vdev.entity; + ret =3D media_create_pad_link(entity, 0, &dev->entity, BCM2835_ISP_PARAMS= _PAD, + MEDIA_LNK_FL_IMMUTABLE | + MEDIA_LNK_FL_ENABLED); + if (ret) + goto done; + + ret =3D media_device_register(&dev->mdev); + if (!ret) + dev->media_device_registered =3D true; +done: + return ret; +} + +static void bcm2835_isp_remove_instance(struct bcm2835_isp_dev *dev) +{ + unsigned int i; + + if (!IS_ERR_OR_NULL(dev->params)) + bcm2835_isp_params_unregister(dev->params); + + for (i =3D 0; i < BCM2835_ISP_NUM_NODES; i++) + bcm2835_unregister_node(&dev->node[i]); + + v4l2_device_unregister(&dev->v4l2_dev); + media_controller_unregister(dev); + + if (dev->component) + vchiq_mmal_component_finalise(dev->mmal_instance, + dev->component); + + vchiq_mmal_finalise(dev->mmal_instance); +} + +static int bcm2835_isp_probe_instance(struct vchiq_device *device, + struct bcm2835_isp_dev **dev_int, + unsigned int instance) +{ + struct bcm2835_isp_dev *dev; + unsigned int i; + int ret; + + dev =3D devm_kzalloc(&device->dev, sizeof(*dev), GFP_KERNEL); + if (!dev) + return -ENOMEM; + + *dev_int =3D dev; + dev->dev =3D &device->dev; + dev->mdev.dev =3D &device->dev; + + strscpy(dev->mdev.model, BCM2835_ISP_NAME, sizeof(dev->mdev.model)); + snprintf(dev->mdev.bus_info, sizeof(dev->mdev.bus_info), "platform:%s", + BCM2835_ISP_NAME); + media_device_init(&dev->mdev); + + dev->v4l2_dev.mdev =3D &dev->mdev; + + ret =3D v4l2_device_register(&device->dev, &dev->v4l2_dev); + if (ret) + return ret; + + ret =3D vchiq_mmal_init(&device->dev, &dev->mmal_instance); + if (ret) { + v4l2_device_unregister(&dev->v4l2_dev); + return ret; + } + + ret =3D vchiq_mmal_component_init(dev->mmal_instance, "ril.isp", + &dev->component); + if (ret) { + v4l2_err(&dev->v4l2_dev, + "%s: failed to create ril.isp component\n", __func__); + return ret; + } + + if (dev->component->inputs < BCM2835_ISP_NUM_OUTPUTS || + dev->component->outputs < BCM2835_ISP_NUM_CAPTURES + + BCM2835_ISP_NUM_METADATA) { + v4l2_err(&dev->v4l2_dev, + "%s: ril.isp returned %d i/p (%d expected), %d o/p (%d expected) ports= \n", + __func__, dev->component->inputs, + BCM2835_ISP_NUM_OUTPUTS, + dev->component->outputs, + BCM2835_ISP_NUM_CAPTURES + BCM2835_ISP_NUM_METADATA); + return -EINVAL; + } + + atomic_set(&dev->num_streaming, 0); + + for (i =3D 0; i < BCM2835_ISP_NUM_NODES; i++) { + struct bcm2835_isp_node *node =3D &dev->node[i]; + + ret =3D bcm2835_isp_register_node(dev, instance, node, i); + if (ret) + return ret; + } + + /* Register extensible params node */ + dev->params =3D bcm2835_isp_params_register(&dev->v4l2_dev, dev->dev, + dev->mmal_instance, + &dev->component->input[0], + video_nr[instance] + BCM2835_ISP_NUM_NODES); + if (IS_ERR(dev->params)) + return PTR_ERR(dev->params); + + ret =3D media_controller_register(dev); + if (ret) + return ret; + + return 0; +} + +static void bcm2835_isp_remove(struct vchiq_device *device) +{ + struct bcm2835_isp_dev **bcm2835_isp_instances; + unsigned int i; + + bcm2835_isp_instances =3D vchiq_get_drvdata(device); + for (i =3D 0; i < BCM2835_ISP_NUM_INSTANCES; i++) { + if (bcm2835_isp_instances[i]) + bcm2835_isp_remove_instance(bcm2835_isp_instances[i]); + } +} + +static int bcm2835_isp_probe(struct vchiq_device *device) +{ + struct bcm2835_isp_dev **bcm2835_isp_instances; + unsigned int i; + int ret; + + ret =3D dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32)); + if (ret) { + dev_err(&device->dev, "dma_set_mask_and_coherent failed: %d\n", + ret); + return ret; + } + + bcm2835_isp_instances =3D devm_kzalloc(&device->dev, + sizeof(bcm2835_isp_instances) * + BCM2835_ISP_NUM_INSTANCES, + GFP_KERNEL); + if (!bcm2835_isp_instances) + return -ENOMEM; + + vchiq_set_drvdata(device, bcm2835_isp_instances); + + for (i =3D 0; i < BCM2835_ISP_NUM_INSTANCES; i++) { + ret =3D bcm2835_isp_probe_instance(device, + &bcm2835_isp_instances[i], i); + if (ret) + goto error; + } + + dev_info(&device->dev, "Loaded V4L2 %s\n", BCM2835_ISP_NAME); + return 0; + +error: + bcm2835_isp_remove(device); + + return ret; +} + +static struct vchiq_device_id device_id_table[] =3D { + { .name =3D "bcm2835-isp" }, + {} +}; +MODULE_DEVICE_TABLE(vchiq, device_id_table); + +static struct vchiq_driver bcm2835_isp_drv =3D { + .probe =3D bcm2835_isp_probe, + .remove =3D bcm2835_isp_remove, + .id_table =3D device_id_table, + .driver =3D { + .name =3D BCM2835_ISP_NAME, + }, +}; + +module_vchiq_driver(bcm2835_isp_drv); + +MODULE_DESCRIPTION("BCM2835 ISP driver"); +MODULE_AUTHOR("Naushir Patuck "); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core= /v4l2-ioctl.c index 17ba1ae70735..1449de2b64b5 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1490,6 +1490,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) case V4L2_META_FMT_GENERIC_CSI2_16: descr =3D "8-bit Generic Meta, 16b CS= I-2"; break; case V4L2_META_FMT_GENERIC_CSI2_20: descr =3D "8-bit Generic Meta, 20b CS= I-2"; break; case V4L2_META_FMT_GENERIC_CSI2_24: descr =3D "8-bit Generic Meta, 24b CS= I-2"; break; + case V4L2_META_FMT_BCM2835_ISP_STATS: descr =3D "BCM2835 ISP Image Statis= tics"; break; + case V4L2_META_FMT_BCM2835_ISP_PARAMS: descr =3D "BCM2835 ISP Config Para= meters"; break; =20 default: /* Compressed formats */ diff --git a/include/linux/raspberrypi/mmal-parameters.h b/include/linux/ra= spberrypi/mmal-parameters.h index 6ae5a7a1932c..dfce16b06730 100644 --- a/include/linux/raspberrypi/mmal-parameters.h +++ b/include/linux/raspberrypi/mmal-parameters.h @@ -23,6 +23,7 @@ #define MMAL_PARAMETERS_H =20 #include +#include =20 /** Common parameter ID group, used with many types of component. */ #define MMAL_PARAMETER_GROUP_COMMON (0 << 16) @@ -279,8 +280,14 @@ enum mmal_parameter_camera_type { MMAL_PARAMETER_DPC, /**< Tales a @ref MMAP_PARAMETER_GAMMA_T */ MMAL_PARAMETER_GAMMA, + + /* 0x60 */ /**< Takes a @ref MMAL_PARAMETER_CDN_T */ MMAL_PARAMETER_CDN, + /**< Takes a @ref MMAL_PARAMETER_BOOLEAN_T */ + MMAL_PARAMETER_JPEG_IJG_SCALING, + /**< Takes a @ref MMAL_PARAMETER_ISP_SETTINGS_T */ + MMAL_PARAMETER_ISP_SETTINGS, }; =20 enum mmal_parameter_camera_config_timestamp_mode { @@ -819,20 +826,110 @@ enum mmal_parameter_ls_gain_format_type { MMAL_PARAMETER_LS_GAIN_FORMAT_TYPE_DUMMY =3D 0x7FFFFFFF }; =20 -struct mmal_parameter_lens_shading_v2 { - u32 enabled; - u32 grid_cell_size; - u32 grid_width; - u32 grid_stride; - u32 grid_height; - u32 mem_handle_table; - u32 ref_transform; - u32 corner_sampled; - enum mmal_parameter_ls_gain_format_type gain_format; -}; - struct mmal_parameter_crop { struct vchiq_mmal_rect rect; }; =20 +struct mmal_parameter_isp_parameters { + struct { + /* Black level */ + u32 update; + u32 enable; + u16 black_level_r; + u16 black_level_g; + u16 black_level_b; + u8 padding[2]; + } black_level; + + struct { + /* GEQ */ + u32 update; + u32 enable; + u32 offset; + struct bcm2835_isp_rational slope; + u8 padding[4]; + } green_eq; + + struct { + /* Gamma */ + u32 update; + u32 enable; + u16 X[BCM2835_NUM_GAMMA_PTS]; + u16 Y[BCM2835_NUM_GAMMA_PTS]; + } gamma; + + struct { + /* Denoise */ + u32 update; + u32 enable; + u32 constant; + struct bcm2835_isp_rational slope; + struct bcm2835_isp_rational strength; + u8 padding[4]; + } denoise; + + struct { + /* Sharpen */ + u32 update; + u32 enable; + struct bcm2835_isp_rational threshold; + struct bcm2835_isp_rational strength; + struct bcm2835_isp_rational limit; + } sharpen; + + struct { + /* Defective Pixel Correction */ + u32 update; + u32 enable; + u32 strength; + u8 padding[4]; + } dpc; + + struct { + /* Colour denoise */ + u32 update; + u32 enable; + u32 mode; + u8 padding[4]; + } colour_denoise; + + struct { + /* CCM */ + u32 update; + u32 enable; + struct bcm2835_isp_ccm ccm; + u8 padding[4]; + } ccm; + + struct { + /* Lens shading */ + u32 update; + u32 enabled; + u32 grid_cell_size; + u32 grid_width; + u32 grid_stride; + u32 grid_height; + u32 mem_handle_table; + u32 ref_transform; + u32 corner_sampled; + enum mmal_parameter_ls_gain_format_type gain_format; + u8 padding[4]; + } lens_shading; + + struct { + /* AWB Gains */ + u32 update; + struct bcm2835_isp_rational r_gain; + struct bcm2835_isp_rational b_gain; + u8 padding[4]; + } awb_gains; + + struct { + /* Digital Gain */ + u32 update; + struct bcm2835_isp_rational value; + u8 padding[4]; + } digital_gain; +}; + #endif diff --git a/include/uapi/linux/bcm2835-isp.h b/include/uapi/linux/bcm2835-= isp.h new file mode 100644 index 000000000000..d15a4ed18404 --- /dev/null +++ b/include/uapi/linux/bcm2835-isp.h @@ -0,0 +1,530 @@ +/* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-C= lause) */ +/* + * bcm2835-isp.h + * + * BCM2835 ISP driver - user space header file. + * + * Copyright =C2=A9 2019-2026 Raspberry Pi (Trading) Ltd. + * + * Author: Naushir Patuck (naush@raspberrypi.com) + * + */ + +#ifndef __BCM2835_ISP_H_ +#define __BCM2835_ISP_H_ + +#include + +/* + * All structs below are directly mapped from struct + * mmal_parameter_isp_parameters in include/linux/raspberrypi/mmal-paramet= ers.h + * for convenience. + */ + +/** + * struct bcm2835_isp_rational - Rational value type. + * + * @num: Numerator. + * @den: Denominator. + */ +struct bcm2835_isp_rational { + __s32 num; + __u32 den; +}; + +/** + * struct bcm2835_isp_ccm - Colour correction matrix. + * + * @ccm: 3x3 correction matrix coefficients. + * @offsets: 1x3 correction offsets. + */ +struct bcm2835_isp_ccm { + struct bcm2835_isp_rational ccm[3][3]; + __s32 offsets[3]; +}; + +/** + * struct bcm2835_isp_custom_ccm - Custom CCM configuration. + * + * @enabled: Enable custom CCM. + * @ccm: Custom CCM coefficients and offsets. + */ +struct bcm2835_isp_custom_ccm { + __u32 enabled; + struct bcm2835_isp_ccm ccm; +}; + +/** + * enum bcm2835_isp_gain_format - format of the gains in the lens shading + * tables. + * + * @GAIN_FORMAT_U0P8_1: Gains are u0.8 format, starting at 1.0 + * @GAIN_FORMAT_U1P7_0: Gains are u1.7 format, starting at 0.0 + * @GAIN_FORMAT_U1P7_1: Gains are u1.7 format, starting at 1.0 + * @GAIN_FORMAT_U2P6_0: Gains are u2.6 format, starting at 0.0 + * @GAIN_FORMAT_U2P6_1: Gains are u2.6 format, starting at 1.0 + * @GAIN_FORMAT_U3P5_0: Gains are u3.5 format, starting at 0.0 + * @GAIN_FORMAT_U3P5_1: Gains are u3.5 format, starting at 1.0 + * @GAIN_FORMAT_U4P10: Gains are u4.10 format, starting at 0.0 + */ +enum bcm2835_isp_gain_format { + GAIN_FORMAT_U0P8_1 =3D 0, + GAIN_FORMAT_U1P7_0 =3D 1, + GAIN_FORMAT_U1P7_1 =3D 2, + GAIN_FORMAT_U2P6_0 =3D 3, + GAIN_FORMAT_U2P6_1 =3D 4, + GAIN_FORMAT_U3P5_0 =3D 5, + GAIN_FORMAT_U3P5_1 =3D 6, + GAIN_FORMAT_U4P10 =3D 7, +}; + +/** + * struct bcm2835_isp_lens_shading - Lens shading tables. + * + * @enabled: Enable lens shading. + * @grid_cell_size: Size of grid cells in samples (16, 32, 64, 128 or 256). + * @grid_width: Width of lens shading tables in grid cells. + * @grid_stride: Row to row distance (in grid cells) between grid cells + * in the same horizontal location. + * @grid_height: Height of lens shading tables in grid cells. + * @dmabuf: dmabuf file handle containing the table. + * @ref_transform: Reference transform - unsupported, please pass zero. + * @corner_sampled: Whether the gains are sampled at the corner points + * of the grid cells or in the cell centres. + * @gain_format: Format of the gains (see enum &bcm2835_isp_gain_format). + */ +struct bcm2835_isp_lens_shading { + __u32 enabled; + __u32 grid_cell_size; + __u32 grid_width; + __u32 grid_stride; + __u32 grid_height; + __s32 dmabuf; + __u32 ref_transform; + __u32 corner_sampled; + __u32 gain_format; +}; + +/** + * struct bcm2835_isp_black_level - Sensor black level configuration. + * + * @enabled: Enable black level. + * @black_level_r: Black level for red channel. + * @black_level_g: Black level for green channels. + * @black_level_b: Black level for blue channel. + * @padding: Unused padding. + */ +struct bcm2835_isp_black_level { + __u32 enabled; + __u16 black_level_r; + __u16 black_level_g; + __u16 black_level_b; + __u8 padding[2]; /* Unused */ +}; + +/** + * struct bcm2835_isp_geq - Green equalisation parameters. + * + * @enabled: Enable green equalisation. + * @offset: Fixed offset of the green equalisation threshold. + * @slope: Slope of the green equalisation threshold. + */ +struct bcm2835_isp_geq { + __u32 enabled; + __u32 offset; + struct bcm2835_isp_rational slope; +}; + +#define BCM2835_NUM_GAMMA_PTS 33 + +/** + * struct bcm2835_isp_gamma - Gamma parameters. + * + * @enabled: Enable gamma adjustment. + * @x: X values of the points defining the gamma curve. + * Values should be scaled to 16 bits. + * @y: Y values of the points defining the gamma curve. + * Values should be scaled to 16 bits. + */ +struct bcm2835_isp_gamma { + __u32 enabled; + __u16 x[BCM2835_NUM_GAMMA_PTS]; + __u16 y[BCM2835_NUM_GAMMA_PTS]; +}; + +/** + * enum bcm2835_isp_cdn_mode - Mode of operation for colour denoise. + * + * @CDN_MODE_FAST: Fast (but lower quality) colour denoise + * algorithm, typically used for video recording. + * @CDN_MODE_HIGH_QUALITY: High quality (but slower) colour denoise + * algorithm, typically used for stills capture. + */ +enum bcm2835_isp_cdn_mode { + CDN_MODE_FAST =3D 0, + CDN_MODE_HIGH_QUALITY =3D 1, +}; + +/** + * struct bcm2835_isp_cdn - Colour denoise parameters. + * + * @enabled: Enable colour denoise. + * @mode: Colour denoise operating mode (see enum &bcm2835_isp_cdn_mode) + */ +struct bcm2835_isp_cdn { + __u32 enabled; + __u32 mode; +}; + +/** + * struct bcm2835_isp_denoise - Denoise parameters. + * + * @enabled: Enable denoise. + * @constant: Fixed offset of the noise threshold. + * @slope: Slope of the noise threshold. + * @strength: Denoise strength between 0.0 (off) and 1.0 (maximum). + */ +struct bcm2835_isp_denoise { + __u32 enabled; + __u32 constant; + struct bcm2835_isp_rational slope; + struct bcm2835_isp_rational strength; +}; + +/** + * struct bcm2835_isp_sharpen - Sharpen parameters. + * + * @enabled: Enable sharpening. + * @threshold: Threshold at which to start sharpening pixels. + * @strength: Strength with which pixel sharpening increases. + * @limit: Limit to the amount of sharpening applied. + */ +struct bcm2835_isp_sharpen { + __u32 enabled; + struct bcm2835_isp_rational threshold; + struct bcm2835_isp_rational strength; + struct bcm2835_isp_rational limit; +}; + +/** + * enum bcm2835_isp_dpc_mode - defective pixel correction (DPC) strength. + * + * @DPC_MODE_OFF: No DPC. + * @DPC_MODE_NORMAL: Normal DPC. + * @DPC_MODE_STRONG: Strong DPC. + */ +enum bcm2835_isp_dpc_mode { + DPC_MODE_OFF =3D 0, + DPC_MODE_NORMAL =3D 1, + DPC_MODE_STRONG =3D 2, +}; + +/** + * struct bcm2835_isp_dpc - Defective pixel correction (DPC) parameters. + * + * @enabled: Enable DPC. + * @strength: DPC strength (see enum &bcm2835_isp_dpc_mode). + */ +struct bcm2835_isp_dpc { + __u32 enabled; + __u32 strength; +}; + +/** + * struct bcm2835_isp_awb_gains - AWB gains configuration. + * + * @r_gain: Red channel AWB gain. + * @b_gain: Blue channel AWB gain. + */ +struct bcm2835_isp_awb_gains { + struct bcm2835_isp_rational r_gain; + struct bcm2835_isp_rational b_gain; +}; + +/** + * struct bcm2835_isp_digital_gain - Digital gain configuration. + * + * @gain: Digital gain value. + */ +struct bcm2835_isp_digital_gain { + struct bcm2835_isp_rational gain; +}; + +/* + * BCM2835 ISP extensible parameters buffer definitions. + * + * The extensible parameters mechanism allows userspace to submit ISP + * configuration parameters as a buffer containing a series of tagged + * blocks rather than individual V4L2 controls. This enables atomic + * application of multiple parameters in a single operation. + */ + +/** + * enum bcm2835_isp_param_buffer_version - BCM2835 ISP parameters buffer v= ersion + * + * @BCM2835_ISP_PARAM_BUFFER_V1: First version of parameters buffer format + */ +enum bcm2835_isp_param_buffer_version { + BCM2835_ISP_PARAM_BUFFER_V1 =3D V4L2_ISP_PARAMS_VERSION_V1, +}; + +/** + * enum bcm2835_isp_param_block_type - BCM2835 ISP parameter block types + * + * This enumeration defines the types of parameters blocks that can be + * included in the extensible parameters buffer. Each block type correspon= ds + * to a specific ISP processing block configuration. + * + * @BCM2835_ISP_PARAM_BLOCK_BLACK_LEVEL: Black level configuration + * @BCM2835_ISP_PARAM_BLOCK_GEQ: Green equalisation configuration + * @BCM2835_ISP_PARAM_BLOCK_GAMMA: Gamma curve configuration + * @BCM2835_ISP_PARAM_BLOCK_DENOISE: Denoise configuration + * @BCM2835_ISP_PARAM_BLOCK_SHARPEN: Sharpening configuration + * @BCM2835_ISP_PARAM_BLOCK_DPC: Defective pixel correction configuration + * @BCM2835_ISP_PARAM_BLOCK_CDN: Colour denoise configuration + * @BCM2835_ISP_PARAM_BLOCK_CC_MATRIX: Colour correction matrix configurat= ion + * @BCM2835_ISP_PARAM_BLOCK_LENS_SHADING: Lens shading table configuration + * @BCM2835_ISP_PARAM_BLOCK_AWB_GAINS: AWB gains configuration + * @BCM2835_ISP_PARAM_BLOCK_DIGITAL_GAIN: Digital gain configuration + */ +enum bcm2835_isp_param_block_type { + BCM2835_ISP_PARAM_BLOCK_BLACK_LEVEL, + BCM2835_ISP_PARAM_BLOCK_GEQ, + BCM2835_ISP_PARAM_BLOCK_GAMMA, + BCM2835_ISP_PARAM_BLOCK_DENOISE, + BCM2835_ISP_PARAM_BLOCK_SHARPEN, + BCM2835_ISP_PARAM_BLOCK_DPC, + BCM2835_ISP_PARAM_BLOCK_CDN, + BCM2835_ISP_PARAM_BLOCK_CC_MATRIX, + BCM2835_ISP_PARAM_BLOCK_LENS_SHADING, + BCM2835_ISP_PARAM_BLOCK_AWB_GAINS, + BCM2835_ISP_PARAM_BLOCK_DIGITAL_GAIN, +}; + +/** + * struct bcm2835_isp_params_black_level - Black level parameters block + * + * @header: Block header (type =3D BCM2835_ISP_PARAM_BLOCK_BLACK_LEVEL) + * @black_level: Black level configuration + */ +struct bcm2835_isp_params_black_level { + struct v4l2_isp_params_block_header header; + struct bcm2835_isp_black_level black_level; +} __attribute__((aligned(8))); + +/** + * struct bcm2835_isp_params_geq - Green equalisation parameters block + * + * @header: Block header (type =3D BCM2835_ISP_PARAM_BLOCK_GEQ) + * @geq: Green equalisation configuration + */ +struct bcm2835_isp_params_geq { + struct v4l2_isp_params_block_header header; + struct bcm2835_isp_geq geq; +} __attribute__((aligned(8))); + +/** + * struct bcm2835_isp_params_gamma - Gamma parameters block + * + * @header: Block header (type =3D BCM2835_ISP_PARAM_BLOCK_GAMMA) + * @gamma: Gamma curve configuration + */ +struct bcm2835_isp_params_gamma { + struct v4l2_isp_params_block_header header; + struct bcm2835_isp_gamma gamma; +} __attribute__((aligned(8))); + +/** + * struct bcm2835_isp_params_denoise - Denoise parameters block + * + * @header: Block header (type =3D BCM2835_ISP_PARAM_BLOCK_DENOISE) + * @denoise: Denoise configuration + */ +struct bcm2835_isp_params_denoise { + struct v4l2_isp_params_block_header header; + struct bcm2835_isp_denoise denoise; +} __attribute__((aligned(8))); + +/** + * struct bcm2835_isp_params_sharpen - Sharpen parameters block + * + * @header: Block header (type =3D BCM2835_ISP_PARAM_BLOCK_SHARPEN) + * @sharpen: Sharpening configuration + */ +struct bcm2835_isp_params_sharpen { + struct v4l2_isp_params_block_header header; + struct bcm2835_isp_sharpen sharpen; +} __attribute__((aligned(8))); + +/** + * struct bcm2835_isp_params_dpc - Defective pixel correction parameters b= lock + * + * @header: Block header (type =3D BCM2835_ISP_PARAM_BLOCK_DPC) + * @dpc: DPC configuration + */ +struct bcm2835_isp_params_dpc { + struct v4l2_isp_params_block_header header; + struct bcm2835_isp_dpc dpc; +} __attribute__((aligned(8))); + +/** + * struct bcm2835_isp_params_cdn - Colour denoise parameters block + * + * @header: Block header (type =3D BCM2835_ISP_PARAM_BLOCK_CDN) + * @cdn: Colour denoise configuration + */ +struct bcm2835_isp_params_cdn { + struct v4l2_isp_params_block_header header; + struct bcm2835_isp_cdn cdn; +} __attribute__((aligned(8))); + +/** + * struct bcm2835_isp_params_cc_matrix - Colour correction matrix paramete= rs block + * + * @header: Block header (type =3D BCM2835_ISP_PARAM_BLOCK_CC_MATRIX) + * @ccm: Colour correction matrix configuration + */ +struct bcm2835_isp_params_cc_matrix { + struct v4l2_isp_params_block_header header; + struct bcm2835_isp_custom_ccm ccm; +} __attribute__((aligned(8))); + +/** + * struct bcm2835_isp_params_lens_shading - Lens shading parameters block + * + * @header: Block header (type =3D BCM2835_ISP_PARAM_BLOCK_LENS_SHADING) + * @ls: Lens shading configuration (includes dmabuf fd for table data) + */ +struct bcm2835_isp_params_lens_shading { + struct v4l2_isp_params_block_header header; + struct bcm2835_isp_lens_shading ls; +} __attribute__((aligned(8))); + +/** + * struct bcm2835_isp_params_awb_gains - AWB gains parameters block + * + * @header: Block header (type =3D BCM2835_ISP_PARAM_BLOCK_AWB_GAINS) + * @awb_gains: AWB gains configuration + */ +struct bcm2835_isp_params_awb_gains { + struct v4l2_isp_params_block_header header; + struct bcm2835_isp_awb_gains awb_gains; +} __attribute__((aligned(8))); + +/** + * struct bcm2835_isp_params_digital_gain - Digital gain parameters block + * + * @header: Block header (type =3D BCM2835_ISP_PARAM_BLOCK_DIGITAL_GAIN) + * @digital_gain: Digital gain configuration + */ +struct bcm2835_isp_params_digital_gain { + struct v4l2_isp_params_block_header header; + struct bcm2835_isp_digital_gain digital_gain; +} __attribute__((aligned(8))); + +/** + * define BCM2835_ISP_PARAMS_MAX_SIZE - Maximum size of all ISP parameters + * + * This defines the maximum size needed to accommodate all possible parame= ter + * blocks in a single buffer. Drivers use this to allocate appropriately + * sized buffers. + */ +#define BCM2835_ISP_PARAMS_MAX_SIZE \ + (sizeof(struct bcm2835_isp_params_black_level) + \ + sizeof(struct bcm2835_isp_params_geq) + \ + sizeof(struct bcm2835_isp_params_gamma) + \ + sizeof(struct bcm2835_isp_params_denoise) + \ + sizeof(struct bcm2835_isp_params_sharpen) + \ + sizeof(struct bcm2835_isp_params_dpc) + \ + sizeof(struct bcm2835_isp_params_cdn) + \ + sizeof(struct bcm2835_isp_params_cc_matrix) + \ + sizeof(struct bcm2835_isp_params_lens_shading) + \ + sizeof(struct bcm2835_isp_params_awb_gains) + \ + sizeof(struct bcm2835_isp_params_digital_gain)) + +/* + * ISP statistics structures. + * + * The bcm2835_isp_stats structure is generated at the output of the + * statistics node. Note that this does not directly map onto the statist= ics + * output of the ISP HW. Instead, the MMAL firmware code maps the HW stat= istics + * to the bcm2835_isp_stats structure. + */ +#define DEFAULT_AWB_REGIONS_X 16 +#define DEFAULT_AWB_REGIONS_Y 12 + +#define NUM_HISTOGRAMS 2 +#define NUM_HISTOGRAM_BINS 128 +#define AWB_REGIONS (DEFAULT_AWB_REGIONS_X * DEFAULT_AWB_REGIONS_Y) +#define FLOATING_REGIONS 16 +#define AGC_REGIONS 16 +#define FOCUS_REGIONS 12 + +/** + * struct bcm2835_isp_stats_hist - Histogram statistics + * + * @r_hist: Red channel histogram. + * @g_hist: Combined green channel histogram. + * @b_hist: Blue channel histogram. + */ +struct bcm2835_isp_stats_hist { + __u32 r_hist[NUM_HISTOGRAM_BINS]; + __u32 g_hist[NUM_HISTOGRAM_BINS]; + __u32 b_hist[NUM_HISTOGRAM_BINS]; +}; + +/** + * struct bcm2835_isp_stats_region - Region sums. + * + * @counted: The number of 2x2 bayer tiles accumulated. + * @notcounted: The number of 2x2 bayer tiles not accumulated. + * @r_sum: Total sum of counted pixels in the red channel for a region. + * @g_sum: Total sum of counted pixels in the green channel for a region. + * @b_sum: Total sum of counted pixels in the blue channel for a region. + */ +struct bcm2835_isp_stats_region { + __u32 counted; + __u32 notcounted; + __u64 r_sum; + __u64 g_sum; + __u64 b_sum; +}; + +/** + * struct bcm2835_isp_stats_focus - Focus statistics. + * + * @contrast_val: Focus measure - accumulated output of the focus filter. + * In the first dimension, index [0] counts pixels below a + * preset threshold, and index [1] counts pixels above the + * threshold. In the second dimension, index [0] uses the + * first predefined filter, and index [1] uses the second + * predefined filter. + * @contrast_val_num: The number of counted pixels in the above accumulati= on. + */ +struct bcm2835_isp_stats_focus { + __u64 contrast_val[2][2]; + __u32 contrast_val_num[2][2]; +}; + +/** + * struct bcm2835_isp_stats - ISP statistics. + * + * @version: Version of the bcm2835_isp_stats structure. + * @size: Size of the bcm2835_isp_stats structure. + * @hist: Histogram statistics for the entire image. + * @awb_stats: Statistics for the regions defined for AWB calculations. + * @floating_stats: Statistics for arbitrarily placed (floating) regions. + * @agc_stats: Statistics for the regions defined for AGC calculations. + * @focus_stats: Focus filter statistics for the focus regions. + */ +struct bcm2835_isp_stats { + __u32 version; + __u32 size; + struct bcm2835_isp_stats_hist hist[NUM_HISTOGRAMS]; + struct bcm2835_isp_stats_region awb_stats[AWB_REGIONS]; + struct bcm2835_isp_stats_region floating_stats[FLOATING_REGIONS]; + struct bcm2835_isp_stats_region agc_stats[AGC_REGIONS]; + struct bcm2835_isp_stats_focus focus_stats[FOCUS_REGIONS]; +}; + +#endif /* __BCM2835_ISP_H_ */ diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 5373dba640fa..f98977138d9c 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -870,6 +870,8 @@ struct v4l2_pix_format { #define V4L2_META_FMT_D4XX v4l2_fourcc('D', '4', 'X', 'X') /* D4XX = Payload Header metadata */ #define V4L2_META_FMT_UVC_MSXU_1_5 v4l2_fourcc('U', 'V', 'C', 'M') /* UVC= MSXU metadata */ #define V4L2_META_FMT_VIVID v4l2_fourcc('V', 'I', 'V', 'D') /* Vivid Met= adata */ +#define V4L2_META_FMT_BCM2835_ISP_STATS v4l2_fourcc('B', 'S', 'T', 'A') /*= BCM2835 ISP stats */ +#define V4L2_META_FMT_BCM2835_ISP_PARAMS v4l2_fourcc('B', 'C', 'M', 'P') /= * BCM2835 ISP params */ =20 /* Vendor specific - used for RK_ISP1 camera sub-system */ #define V4L2_META_FMT_RK_ISP1_PARAMS v4l2_fourcc('R', 'K', '1', 'P') /* Ro= ckchip ISP1 3A Parameters */ --=20 2.55.0 From nobody Fri Sep 25 04:44:55 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 F22CE4F30EE; Wed, 16 Sep 2026 14:35:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569359; cv=none; b=IXGTQd6+Pd0Ef8cJUsNcqjrDirr7neEmtK5EQyUfgLzfs1DbL4YbM58gDz8EeNwIf3kwVx84i9M5AEZn2EXwRAdgg+8MF3RVFD5P0J53T+YEqAtnF6KNWOj3Ipd7WyDrhyJ+eYHLYRB6tqec/xFgQgKMXl7rdtccXVf9lEGv4nI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789569359; c=relaxed/simple; bh=LGXniHRbm8mD1R6DwtDTLZS75SCRRae8iTN3HxKNoVo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nBl8mRq+KAG41/MoW2ZExcCnW65xKgs622QxDEclQKgiRdFItQ+7+bOOX1awP4+aJLOfVH2Ea6q/sGV64x9bSHrWGTLtGFQCKy519Nt4TdXGsqIpHYEkYM1i7fgQy3PNcVxT/p6IDjqGPF9r23uObP6oDk75MumIKDhbt3bPWrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=GE5JftkM; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="GE5JftkM" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:85de:a3c9:9357:b164:bf0b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B1EB9558; Wed, 16 Sep 2026 16:34:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789569253; bh=LGXniHRbm8mD1R6DwtDTLZS75SCRRae8iTN3HxKNoVo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GE5JftkMxmhhz2lRDKZIXSm0PBXhlbHIRnNdvIHHsBesYXeLmc7sWvRvHxyZP36ED HNq7CwC9ByJcauqOJzZU/7M/9P3ETk9NfJV/npRRLlQFvWBkvy1LZLMEr3mdsOj01V 0BYXekESw3hJi7t+GDKeTCknGfoxckCgmL++0/hY= From: Jai Luthra Date: Wed, 16 Sep 2026 20:03:07 +0530 Subject: [PATCH v4 10/10] platform/raspberrypi: vchiq: Load bcm2835_isp driver from vchiq Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260916-b4-vchiq-isp-v4-10-f668c2017b74@ideasonboard.com> References: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> In-Reply-To: <20260916-b4-vchiq-isp-v4-0-f668c2017b74@ideasonboard.com> To: Florian Fainelli , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Raspberry Pi Kernel Maintenance Cc: Laurent Pinchart , Kieran Bingham , Dave Stevenson , Naushir Patuck , Stefan Wahren , Paul Elder , Hans Verkuil , Tomasz Figa , linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1897; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=kdcnF991dp+5AeQR5W2Z04//jeMR9O01a86oQBDiXeg=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqqqkPGHKhZSGz3KkO+bqBLSpUtwSY9zj/n6CBE xfKPYtznaCJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaqqpDwAKCRBD3pH5JJpx RR7pEACcg9dQeYGKbyZfRla+XIcK51Dnr6ZxZ46bqku4Rg8PFExwuDsZav487I0R4mYHPZimIrB 9Y0oTvP8fkjHCFsOC1q56YtQKSjUp1IqGG7wr/J51stWPgeuRo7BcJaxiyx0GMmNzrFdhu1jvx7 bF1zkMJFayJfKZLXO2mW0DaRqyFIKdJNt72lDJhKiBpekGbiZgyt5B0Jr3E4XfMgyrOf4+4TZ6/ RipWhhLJAagzRt7scuE2hjc8WObBF6/kLeWv5s76Ent9uRYyXoIO65rsyvD5uKlbl0RinCk8JFi kL+lrA37og6Przn5bisma0+WfFHQc0S4Dn5x1cXPJmWjg9en8Qvv1VU79Z3bptENrQ7aaLTxBAF ephxCcSNaX/9xV4c3eo5rZIFUMuj6y+x5G2cDE+0/qHPnXj7i8qG4ZOB3/ZeDLJovj8fp1MWqso 7E9kiolqfQubRPZbVCL+CB3pDeKEvPfQyhKl10OX16O3MgjFbnS6NfaC+W7CpADIYA2Sc3/qFXs 5Jln9g03ouwELNA14cOWQBd1aTvmaVB2PirsfrMak4b4+nMz2eOEWShAIqcmGAlKh2GY4stjp3w emQpEfPS6Ic614SmLVWi0QfAMsx85OLeHhGByomVZO7M8iWUM/P2IKQsUOvVOlNePJQHeIxwn8E TJCF3BGCxeLoTJw== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Naushir Patuck Broadcom BCM2835 ISP driver is managed through the VCHIQ interface, so register it to the VCHIQ driver, similar to the audio and shared memory drivers. Signed-off-by: Naushir Patuck Reviewed-by: Paul Elder Tested-by: Paul Elder Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c | 2 ++ include/linux/raspberrypi/vchiq_arm.h | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c b/dri= vers/platform/raspberrypi/vchiq-interface/vchiq_arm.c index ec951ab19d67..f35b40bdd963 100644 --- a/drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c +++ b/drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c @@ -1415,6 +1415,7 @@ static int vchiq_probe(struct platform_device *pdev) =20 mgmt->audio_dev =3D vchiq_device_register(&pdev->dev, "bcm2835-audio"); mgmt->vcsm_cma_dev =3D vchiq_device_register(&pdev->dev, "vcsm-cma"); + mgmt->isp_dev =3D vchiq_device_register(&pdev->dev, "bcm2835-isp"); =20 return 0; } @@ -1423,6 +1424,7 @@ static void vchiq_remove(struct platform_device *pdev) { struct vchiq_drv_mgmt *mgmt =3D dev_get_drvdata(&pdev->dev); =20 + vchiq_device_unregister(mgmt->isp_dev); vchiq_device_unregister(mgmt->vcsm_cma_dev); vchiq_device_unregister(mgmt->audio_dev); vchiq_debugfs_deinit(); diff --git a/include/linux/raspberrypi/vchiq_arm.h b/include/linux/raspberr= ypi/vchiq_arm.h index d59837eaaa8c..ea1bd419e471 100644 --- a/include/linux/raspberrypi/vchiq_arm.h +++ b/include/linux/raspberrypi/vchiq_arm.h @@ -63,6 +63,7 @@ struct vchiq_drv_mgmt { */ struct vchiq_device *audio_dev; struct vchiq_device *vcsm_cma_dev; + struct vchiq_device *isp_dev; }; =20 struct user_service { --=20 2.55.0