Move and staticize the tegra_csi_error_recover() and tegra_csi_calc_settle_time() helpers from the common CSI file into the Tegra210-specific code, since they are used exclusively by the HW rev. 3 Video Input found in Tegra210.
The tegra_csi_calc_settle_time() helper uses a custom MHZ definition which corresponds to the standard HZ_PER_MHZ. The custom MHZ macro is replaced by HZ_PER_MHZ, with this change folded into this commit. Signed-off-by: Svyatoslav Ryhel <[email protected]> --- .../media/platform/nvidia/tegra-video/csi.c | 72 ------------------- .../media/platform/nvidia/tegra-video/csi.h | 5 -- .../platform/nvidia/tegra-video/tegra210.c | 70 ++++++++++++++++++ 3 files changed, 70 insertions(+), 77 deletions(-) diff --git a/drivers/media/platform/nvidia/tegra-video/csi.c b/drivers/media/platform/nvidia/tegra-video/csi.c index aaab884d99f54..fb4b4c0c7cfcd 100644 --- a/drivers/media/platform/nvidia/tegra-video/csi.c +++ b/drivers/media/platform/nvidia/tegra-video/csi.c @@ -19,8 +19,6 @@ #include "csi.h" #include "video.h" -#define MHZ 1000000 - /* * Test pattern generator configuration */ @@ -263,65 +261,6 @@ static int tegra_csi_tpg_init_state(struct v4l2_subdev *sd, return 0; } -static unsigned int csi_get_pixel_rate(struct tegra_csi_channel *csi_chan) -{ - struct v4l2_subdev *subdev = &csi_chan->subdev; - struct v4l2_subdev *src_subdev; - struct v4l2_ctrl *ctrl; - struct media_pad *pad; - - pad = media_entity_remote_source_pad_unique(&subdev->entity); - if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) - dev_err_probe(csi_chan->csi->dev, -ENODEV, - "failed to get source entity\n"); - - src_subdev = media_entity_to_v4l2_subdev(pad->entity); - ctrl = v4l2_ctrl_find(src_subdev->ctrl_handler, V4L2_CID_PIXEL_RATE); - if (ctrl) - return v4l2_ctrl_g_ctrl_int64(ctrl); - - return 0; -} - -void tegra_csi_calc_settle_time(struct tegra_csi_channel *csi_chan, - u8 csi_port_num, - u8 *clk_settle_time, - u8 *ths_settle_time) -{ - struct tegra_csi *csi = csi_chan->csi; - unsigned int cil_clk_mhz; - unsigned int pix_clk_mhz; - int clk_idx = (csi_port_num >> 1) + 1; - - cil_clk_mhz = clk_get_rate(csi->clks[clk_idx].clk) / MHZ; - pix_clk_mhz = csi_get_pixel_rate(csi_chan) / MHZ; - - /* - * CLK Settle time is the interval during which HS receiver should - * ignore any clock lane HS transitions, starting from the beginning - * of T-CLK-PREPARE. - * Per DPHY specification, T-CLK-SETTLE should be between 95ns ~ 300ns - * - * 95ns < (clk-settle-programmed + 7) * lp clk period < 300ns - * midpoint = 197.5 ns - */ - *clk_settle_time = ((95 + 300) * cil_clk_mhz - 14000) / 2000; - - /* - * THS Settle time is the interval during which HS receiver should - * ignore any data lane HS transitions, starting from the beginning - * of THS-PREPARE. - * - * Per DPHY specification, T-HS-SETTLE should be between 85ns + 6UI - * and 145ns+10UI. - * 85ns + 6UI < (Ths-settle-prog + 5) * lp_clk_period < 145ns + 10UI - * midpoint = 115ns + 8UI - */ - if (pix_clk_mhz) - *ths_settle_time = (115 * cil_clk_mhz + 8000 * cil_clk_mhz - / (2 * pix_clk_mhz) - 5000) / 1000; -} - /* * Proper CSI configuration */ @@ -867,17 +806,6 @@ static int tegra_csi_channel_init(struct tegra_csi_channel *chan) return 0; } -void tegra_csi_error_recover(struct v4l2_subdev *sd) -{ - struct tegra_csi_channel *csi_chan = to_csi_chan(sd); - struct tegra_csi *csi = csi_chan->csi; - - /* stop streaming during error recovery */ - csi->ops->csi_stop_streaming(csi_chan); - csi->ops->csi_err_recover(csi_chan); - csi->ops->csi_start_streaming(csi_chan); -} - static int tegra_csi_channels_init(struct tegra_csi *csi) { struct tegra_csi_channel *chan; diff --git a/drivers/media/platform/nvidia/tegra-video/csi.h b/drivers/media/platform/nvidia/tegra-video/csi.h index 25aff2581f069..addd1b82685e9 100644 --- a/drivers/media/platform/nvidia/tegra-video/csi.h +++ b/drivers/media/platform/nvidia/tegra-video/csi.h @@ -175,9 +175,4 @@ static inline struct tegra_csi_channel *to_csi_chan(struct v4l2_subdev *subdev) return container_of(subdev, struct tegra_csi_channel, subdev); } -void tegra_csi_error_recover(struct v4l2_subdev *subdev); -void tegra_csi_calc_settle_time(struct tegra_csi_channel *csi_chan, - u8 csi_port_num, - u8 *clk_settle_time, - u8 *ths_settle_time); #endif diff --git a/drivers/media/platform/nvidia/tegra-video/tegra210.c b/drivers/media/platform/nvidia/tegra-video/tegra210.c index 90d984790696f..474f906e8bcc6 100644 --- a/drivers/media/platform/nvidia/tegra-video/tegra210.c +++ b/drivers/media/platform/nvidia/tegra-video/tegra210.c @@ -13,6 +13,7 @@ #include <linux/delay.h> #include <linux/host1x.h> #include <linux/kthread.h> +#include <linux/units.h> #include "csi.h" #include "vi.h" @@ -334,6 +335,17 @@ static void tegra_channel_vi_soft_reset(struct tegra_vi_channel *chan, tegra_vi_write(chan, TEGRA_VI_CFG_CG_CTRL, VI_CG_2ND_LEVEL_EN); } +static void tegra_csi_error_recover(struct v4l2_subdev *sd) +{ + struct tegra_csi_channel *csi_chan = to_csi_chan(sd); + struct tegra_csi *csi = csi_chan->csi; + + /* stop streaming during error recovery */ + csi->ops->csi_stop_streaming(csi_chan); + csi->ops->csi_err_recover(csi_chan); + csi->ops->csi_start_streaming(csi_chan); +} + static void tegra_channel_capture_error_recover(struct tegra_vi_channel *chan, u8 portno) { @@ -979,6 +991,64 @@ static void tegra210_csi_error_recover(struct tegra_csi_channel *csi_chan) tegra210_csi_port_recover(csi_chan, portnos[i]); } +static unsigned int csi_get_pixel_rate(struct tegra_csi_channel *csi_chan) +{ + struct v4l2_subdev *subdev = &csi_chan->subdev; + struct v4l2_subdev *src_subdev; + struct v4l2_ctrl *ctrl; + struct media_pad *pad; + + pad = media_entity_remote_source_pad_unique(&subdev->entity); + if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) + dev_err_probe(csi_chan->csi->dev, -ENODEV, + "failed to get source entity\n"); + + src_subdev = media_entity_to_v4l2_subdev(pad->entity); + ctrl = v4l2_ctrl_find(src_subdev->ctrl_handler, V4L2_CID_PIXEL_RATE); + if (ctrl) + return v4l2_ctrl_g_ctrl_int64(ctrl); + + return 0; +} + +static void tegra_csi_calc_settle_time(struct tegra_csi_channel *csi_chan, + u8 csi_port_num, u8 *clk_settle_time, + u8 *ths_settle_time) +{ + struct tegra_csi *csi = csi_chan->csi; + unsigned int cil_clk_mhz; + unsigned int pix_clk_mhz; + int clk_idx = (csi_port_num >> 1) + 1; + + cil_clk_mhz = clk_get_rate(csi->clks[clk_idx].clk) / HZ_PER_MHZ; + pix_clk_mhz = csi_get_pixel_rate(csi_chan) / HZ_PER_MHZ; + + /* + * CLK Settle time is the interval during which HS receiver should + * ignore any clock lane HS transitions, starting from the beginning + * of T-CLK-PREPARE. + * Per DPHY specification, T-CLK-SETTLE should be between 95ns ~ 300ns + * + * 95ns < (clk-settle-programmed + 7) * lp clk period < 300ns + * midpoint = 197.5 ns + */ + *clk_settle_time = ((95 + 300) * cil_clk_mhz - 14000) / 2000; + + /* + * THS Settle time is the interval during which HS receiver should + * ignore any data lane HS transitions, starting from the beginning + * of THS-PREPARE. + * + * Per DPHY specification, T-HS-SETTLE should be between 85ns + 6UI + * and 145ns+10UI. + * 85ns + 6UI < (Ths-settle-prog + 5) * lp_clk_period < 145ns + 10UI + * midpoint = 115ns + 8UI + */ + if (pix_clk_mhz) + *ths_settle_time = (115 * cil_clk_mhz + 8000 * cil_clk_mhz + / (2 * pix_clk_mhz) - 5000) / 1000; +} + static int tegra210_csi_port_start_streaming(struct tegra_csi_channel *csi_chan, u8 portno) -- 2.53.0
