From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Florian Fainelli <florian.fainelli@broadcom.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Naushir Patuck <naush@raspberrypi.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
Kieran Bingham <kieran.bingham@ideasonboard.com>
Subject: Re: [PATCH v2 3/4] media: raspberrypi: Add support for RP1-CFE
Date: Thu, 20 Jun 2024 19:23:03 +0300 [thread overview]
Message-ID: <20240620162226.GH30640@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20240620-rp1-cfe-v2-3-b8b48fdba3b3@ideasonboard.com>
On Thu, Jun 20, 2024 at 02:07:52PM +0300, Tomi Valkeinen wrote:
> Add support for Raspberry Pi CFE. The CFE is a hardware block that
> contains:
>
> - MIPI D-PHY
> - MIPI CSI-2 receiver
> - Front End ISP (FE)
>
> The driver has been upported from the Raspberry Pi kernel commit
> 88a681df9623 ("ARM: dts: bcm2712-rpi: Add i2c<n>_pins labels").
>
> Co-developed-by: Naushir Patuck <naush@raspberrypi.com>
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
> MAINTAINERS | 8 +
> drivers/media/platform/raspberrypi/Kconfig | 1 +
> drivers/media/platform/raspberrypi/Makefile | 1 +
> drivers/media/platform/raspberrypi/rp1-cfe/Kconfig | 14 +
> .../media/platform/raspberrypi/rp1-cfe/Makefile | 6 +
> .../media/platform/raspberrypi/rp1-cfe/cfe-fmts.h | 332 +++
> .../media/platform/raspberrypi/rp1-cfe/cfe-trace.h | 196 ++
> drivers/media/platform/raspberrypi/rp1-cfe/cfe.c | 2526 ++++++++++++++++++++
> drivers/media/platform/raspberrypi/rp1-cfe/cfe.h | 43 +
> drivers/media/platform/raspberrypi/rp1-cfe/csi2.c | 583 +++++
> drivers/media/platform/raspberrypi/rp1-cfe/csi2.h | 89 +
> drivers/media/platform/raspberrypi/rp1-cfe/dphy.c | 175 ++
> drivers/media/platform/raspberrypi/rp1-cfe/dphy.h | 27 +
> .../media/platform/raspberrypi/rp1-cfe/pisp-fe.c | 581 +++++
> .../media/platform/raspberrypi/rp1-cfe/pisp-fe.h | 53 +
> .../uapi/linux/media/raspberrypi/pisp_fe_config.h | 273 +++
> .../linux/media/raspberrypi/pisp_fe_statistics.h | 64 +
> 17 files changed, 4972 insertions(+)
[snip]
> diff --git a/drivers/media/platform/raspberrypi/rp1-cfe/dphy.c b/drivers/media/platform/raspberrypi/rp1-cfe/dphy.c
> new file mode 100644
> index 000000000000..c9e4a94fb80c
> --- /dev/null
> +++ b/drivers/media/platform/raspberrypi/rp1-cfe/dphy.c
> @@ -0,0 +1,175 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * RP1 CSI-2 Driver
> + *
> + * Copyright (c) 2021-2024 Raspberry Pi Ltd.
> + * Copyright (c) 2023-2024 Ideas on Board Oy
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/pm_runtime.h>
> +
> +#include "dphy.h"
> +
> +#define dphy_dbg(fmt, arg...) dev_dbg(dphy->dev, fmt, ##arg)
> +#define dphy_err(fmt, arg...) dev_err(dphy->dev, fmt, ##arg)
> +
> +/* DW dphy Host registers */
> +#define DPHY_VERSION 0x000
> +#define DPHY_N_LANES 0x004
> +#define DPHY_RESETN 0x008
> +#define DPHY_PHY_SHUTDOWNZ 0x040
> +#define DPHY_PHY_RSTZ 0x044
> +#define DPHY_PHY_RX 0x048
> +#define DPHY_PHY_STOPSTATE 0x04c
> +#define DPHY_PHY_TST_CTRL0 0x050
> +#define DPHY_PHY_TST_CTRL1 0x054
> +#define DPHY_PHY2_TST_CTRL0 0x058
> +#define DPHY_PHY2_TST_CTRL1 0x05c
Quoting drivers/media/platform/renesas/rcar-csi2.c:
/* V4H BASE registers */
#define V4H_N_LANES_REG 0x0004
#define V4H_CSI2_RESETN_REG 0x0008
#define V4H_PHY_MODE_REG 0x001c
#define V4H_PHY_SHUTDOWNZ_REG 0x0040
#define V4H_DPHY_RSTZ_REG 0x0044
Time for a common PHY driver ?
> +
> +/* DW dphy Host Transactions */
> +#define DPHY_HS_RX_CTRL_LANE0_OFFSET 0x44
> +#define DPHY_PLL_INPUT_DIV_OFFSET 0x17
> +#define DPHY_PLL_LOOP_DIV_OFFSET 0x18
> +#define DPHY_PLL_DIV_CTRL_OFFSET 0x19
> +
> +static u32 dw_csi2_host_read(struct dphy_data *dphy, u32 offset)
> +{
> + return readl(dphy->base + offset);
> +}
> +
> +static void dw_csi2_host_write(struct dphy_data *dphy, u32 offset, u32 data)
> +{
> + writel(data, dphy->base + offset);
> +}
> +
> +static void set_tstclr(struct dphy_data *dphy, u32 val)
> +{
> + u32 ctrl0 = dw_csi2_host_read(dphy, DPHY_PHY_TST_CTRL0);
> +
> + dw_csi2_host_write(dphy, DPHY_PHY_TST_CTRL0, (ctrl0 & ~1) | val);
> +}
> +
> +static void set_tstclk(struct dphy_data *dphy, u32 val)
> +{
> + u32 ctrl0 = dw_csi2_host_read(dphy, DPHY_PHY_TST_CTRL0);
> +
> + dw_csi2_host_write(dphy, DPHY_PHY_TST_CTRL0, (ctrl0 & ~2) | (val << 1));
> +}
> +
> +static uint8_t get_tstdout(struct dphy_data *dphy)
> +{
> + u32 ctrl1 = dw_csi2_host_read(dphy, DPHY_PHY_TST_CTRL1);
> +
> + return ((ctrl1 >> 8) & 0xff);
> +}
> +
> +static void set_testen(struct dphy_data *dphy, u32 val)
> +{
> + u32 ctrl1 = dw_csi2_host_read(dphy, DPHY_PHY_TST_CTRL1);
> +
> + dw_csi2_host_write(dphy, DPHY_PHY_TST_CTRL1,
> + (ctrl1 & ~(1 << 16)) | (val << 16));
> +}
> +
> +static void set_testdin(struct dphy_data *dphy, u32 val)
> +{
> + u32 ctrl1 = dw_csi2_host_read(dphy, DPHY_PHY_TST_CTRL1);
> +
> + dw_csi2_host_write(dphy, DPHY_PHY_TST_CTRL1, (ctrl1 & ~0xff) | val);
> +}
> +
> +static uint8_t dphy_transaction(struct dphy_data *dphy, u8 test_code,
> + uint8_t test_data)
> +{
> + /* See page 101 of the MIPI DPHY databook. */
> + set_tstclk(dphy, 1);
> + set_testen(dphy, 0);
> + set_testdin(dphy, test_code);
> + set_testen(dphy, 1);
> + set_tstclk(dphy, 0);
> + set_testen(dphy, 0);
> + set_testdin(dphy, test_data);
> + set_tstclk(dphy, 1);
> + return get_tstdout(dphy);
> +}
> +
> +static void dphy_set_hsfreqrange(struct dphy_data *dphy, uint32_t mbps)
> +{
> + /* See Table 5-1 on page 65 of dphy databook */
> + static const u16 hsfreqrange_table[][2] = {
> + { 89, 0b000000 }, { 99, 0b010000 }, { 109, 0b100000 },
> + { 129, 0b000001 }, { 139, 0b010001 }, { 149, 0b100001 },
> + { 169, 0b000010 }, { 179, 0b010010 }, { 199, 0b100010 },
> + { 219, 0b000011 }, { 239, 0b010011 }, { 249, 0b100011 },
> + { 269, 0b000100 }, { 299, 0b010100 }, { 329, 0b000101 },
> + { 359, 0b010101 }, { 399, 0b100101 }, { 449, 0b000110 },
> + { 499, 0b010110 }, { 549, 0b000111 }, { 599, 0b010111 },
> + { 649, 0b001000 }, { 699, 0b011000 }, { 749, 0b001001 },
> + { 799, 0b011001 }, { 849, 0b101001 }, { 899, 0b111001 },
> + { 949, 0b001010 }, { 999, 0b011010 }, { 1049, 0b101010 },
> + { 1099, 0b111010 }, { 1149, 0b001011 }, { 1199, 0b011011 },
> + { 1249, 0b101011 }, { 1299, 0b111011 }, { 1349, 0b001100 },
> + { 1399, 0b011100 }, { 1449, 0b101100 }, { 1500, 0b111100 },
> + };
> + unsigned int i;
> +
> + if (mbps < 80 || mbps > 1500)
> + dphy_err("DPHY: Datarate %u Mbps out of range\n", mbps);
> +
> + for (i = 0; i < ARRAY_SIZE(hsfreqrange_table) - 1; i++) {
> + if (mbps <= hsfreqrange_table[i][0])
> + break;
> + }
> +
> + dphy_transaction(dphy, DPHY_HS_RX_CTRL_LANE0_OFFSET,
> + hsfreqrange_table[i][1] << 1);
> +}
> +
> +static void dphy_init(struct dphy_data *dphy)
> +{
> + dw_csi2_host_write(dphy, DPHY_PHY_RSTZ, 0);
> + dw_csi2_host_write(dphy, DPHY_PHY_SHUTDOWNZ, 0);
> + set_tstclk(dphy, 1);
> + set_testen(dphy, 0);
> + set_tstclr(dphy, 1);
> + usleep_range(15, 20);
> + set_tstclr(dphy, 0);
> + usleep_range(15, 20);
> +
> + dphy_set_hsfreqrange(dphy, dphy->dphy_rate);
> +
> + usleep_range(5, 10);
> + dw_csi2_host_write(dphy, DPHY_PHY_SHUTDOWNZ, 1);
> + usleep_range(5, 10);
> + dw_csi2_host_write(dphy, DPHY_PHY_RSTZ, 1);
> +}
> +
> +void dphy_start(struct dphy_data *dphy)
> +{
> + dw_csi2_host_write(dphy, DPHY_N_LANES, (dphy->active_lanes - 1));
> + dphy_init(dphy);
> + dw_csi2_host_write(dphy, DPHY_RESETN, 0xffffffff);
> + usleep_range(10, 50);
> +}
> +
> +void dphy_stop(struct dphy_data *dphy)
> +{
> + /* Set only one lane (lane 0) as active (ON) */
> + dw_csi2_host_write(dphy, DPHY_N_LANES, 0);
> + dw_csi2_host_write(dphy, DPHY_RESETN, 0);
> +}
> +
> +void dphy_probe(struct dphy_data *dphy)
> +{
> + u32 host_ver;
> + u8 host_ver_major, host_ver_minor;
> +
> + host_ver = dw_csi2_host_read(dphy, DPHY_VERSION);
> + host_ver_major = (u8)((host_ver >> 24) - '0');
> + host_ver_minor = (u8)((host_ver >> 16) - '0');
> + host_ver_minor = host_ver_minor * 10;
> + host_ver_minor += (u8)((host_ver >> 8) - '0');
> +
> + dphy_dbg("DW dphy Host HW v%u.%u\n", host_ver_major, host_ver_minor);
> +}
[snip]
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2024-06-20 16:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-20 11:07 [PATCH v2 0/4] media: raspberrypi: Support RPi5's CFE Tomi Valkeinen
2024-06-20 11:07 ` [PATCH v2 1/4] media: uapi: Add meta formats for PiSP FE config and stats Tomi Valkeinen
2024-06-20 11:07 ` [PATCH v2 2/4] dt-bindings: media: Add bindings for raspberrypi,rp1-cfe Tomi Valkeinen
2024-06-20 15:41 ` Krzysztof Kozlowski
2024-08-28 11:06 ` Sakari Ailus
2024-08-28 11:12 ` Laurent Pinchart
2024-08-28 12:14 ` Tomi Valkeinen
2024-08-28 12:30 ` Sakari Ailus
2024-08-28 12:53 ` Laurent Pinchart
2024-06-20 11:07 ` [PATCH v2 3/4] media: raspberrypi: Add support for RP1-CFE Tomi Valkeinen
2024-06-20 16:23 ` Laurent Pinchart [this message]
2024-06-20 11:07 ` [PATCH v2 4/4] media: admin-guide: Document the Raspberry Pi CFE (rp1-cfe) Tomi Valkeinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240620162226.GH30640@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=florian.fainelli@broadcom.com \
--cc=jacopo.mondi@ideasonboard.com \
--cc=kernel-list@raspberrypi.com \
--cc=kieran.bingham@ideasonboard.com \
--cc=krzk+dt@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=naush@raspberrypi.com \
--cc=robh+dt@kernel.org \
--cc=robh@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tomi.valkeinen@ideasonboard.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).