Hi Niklas,
On Fri, Apr 28, 2017 at 12:41:52AM +0200, Niklas Söderlund wrote:
> On Gen3 the CSI-2 routing is controlled by the VnCSI_IFMD register. One
> feature of this register is that it's only present in the VIN0 and VIN4
> instances. The register in VIN0 controls the routing for VIN0-3 and the
> register in VIN4 controls routing for VIN4-7.
>
> To be able to control routing from a media device these functions need
> to control runtime PM for the subgroup master (VIN0 and VIN4). The
> subgroup master must be switched on before the register is manipulated,
> once the operation is complete it's safe to switch the master off and
> the new routing will still be in effect.
>
> Signed-off-by: Niklas Söderlund <[email protected]>
> ---
> drivers/media/platform/rcar-vin/rcar-dma.c | 43
> ++++++++++++++++++++++++++++++
> drivers/media/platform/rcar-vin/rcar-vin.h | 3 +++
> 2 files changed, 46 insertions(+)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c
> b/drivers/media/platform/rcar-vin/rcar-dma.c
> index 7fecb616b6c45a32..fef31aac0ed40979 100644
> --- a/drivers/media/platform/rcar-vin/rcar-dma.c
> +++ b/drivers/media/platform/rcar-vin/rcar-dma.c
> @@ -16,6 +16,7 @@
>
> #include <linux/delay.h>
> #include <linux/interrupt.h>
> +#include <linux/pm_runtime.h>
>
> #include <media/videobuf2-dma-contig.h>
>
> @@ -1240,3 +1241,45 @@ int rvin_dma_probe(struct rvin_dev *vin, int irq)
>
> return ret;
> }
> +
> +/*
> -----------------------------------------------------------------------------
> + * Gen3 CHSEL manipulation
> + */
> +
> +int rvin_set_chsel(struct rvin_dev *vin, u8 chsel)
> +{
> + u32 ifmd;
> +
> + pm_runtime_get_sync(vin->dev);
Can this fail? Just wondering.
> +
> + /*
> + * Undocumented feature: Writing to VNCSI_IFMD_REG will go
> + * through and on read back look correct but won't have
> + * any effect if VNMC_REG is not first set to 0.
> + */
> + rvin_write(vin, 0, VNMC_REG);
> +
> + ifmd = VNCSI_IFMD_DES2 | VNCSI_IFMD_DES1 | VNCSI_IFMD_DES0 |
> + VNCSI_IFMD_CSI_CHSEL(chsel);
> +
> + rvin_write(vin, ifmd, VNCSI_IFMD_REG);
> +
> + vin_dbg(vin, "Set IFMD 0x%x\n", ifmd);
> +
> + pm_runtime_put(vin->dev);
> +
> + return 0;
If you always return zero, how about void instead?
> +}
> +
> +int rvin_get_chsel(struct rvin_dev *vin)
> +{
> + int chsel;
> +
> + pm_runtime_get_sync(vin->dev);
Same here.
> +
> + chsel = rvin_read(vin, VNCSI_IFMD_REG) & VNCSI_IFMD_CSI_CHSEL_MASK;
> +
> + pm_runtime_put(vin->dev);
> +
> + return chsel;
> +}
> diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h
> b/drivers/media/platform/rcar-vin/rcar-vin.h
> index 09fc70e192699f35..b1cd0abba9ca9c94 100644
> --- a/drivers/media/platform/rcar-vin/rcar-vin.h
> +++ b/drivers/media/platform/rcar-vin/rcar-vin.h
> @@ -163,4 +163,7 @@ void rvin_v4l2_remove(struct rvin_dev *vin);
>
> const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
>
> +int rvin_set_chsel(struct rvin_dev *vin, u8 chsel);
> +int rvin_get_chsel(struct rvin_dev *vin);
> +
> #endif
--
Kind regards,
Sakari Ailus
e-mail: [email protected] XMPP: [email protected]