Commit d898692e authored by Janusz Krzysztofik's avatar Janusz Krzysztofik Committed by Mauro Carvalho Chehab

media: ov6650: Simplify clock divisor calculation

As appears from an analysis of to_clkrc() helper code after its
pclk_limit argument has been dropped, its result no longer depends on
another argument - pclk_max.  Moreover, assuming that a constant value
of FRAME_RATE_MAX is always used as a denominator of the only
significant argument left - a struct v4l2_fract, the result in fact
depends only on the numerator value of that argument.  As a further
consequence, it no longer makes sense to recalculate frame intervals by
converting them forth and back with a GET_CLKRC_DIV(to_clkrc(tpf))
construct.

Drop use of GET_CLKRC_DIV() on results of to_clkrc() where possible -
use the frame interval value directly.  Furthermore, replace the
to_clkrc() helper function with a simple macro and update its users to
always use FRAME_RATE_MAX as frame interval denominator and pass only
its numerator as an argument.
Signed-off-by: default avatarJanusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent b1c57943
...@@ -545,18 +545,7 @@ static bool is_unscaled_ok(int width, int height, struct v4l2_rect *rect) ...@@ -545,18 +545,7 @@ static bool is_unscaled_ok(int width, int height, struct v4l2_rect *rect)
return width > rect->width >> 1 || height > rect->height >> 1; return width > rect->width >> 1 || height > rect->height >> 1;
} }
static u8 to_clkrc(struct v4l2_fract *timeperframe, unsigned long pclk_max) #define to_clkrc(div) ((div) - 1)
{
unsigned long pclk;
if (timeperframe->numerator && timeperframe->denominator)
pclk = pclk_max * timeperframe->denominator /
(FRAME_RATE_MAX * timeperframe->numerator);
else
pclk = pclk_max;
return (pclk_max - 1) / pclk;
}
/* set the format we will capture in */ /* set the format we will capture in */
static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
...@@ -650,7 +639,7 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) ...@@ -650,7 +639,7 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
mclk = 12000000; mclk = 12000000;
dev_dbg(&client->dev, "using 12MHz input clock\n"); dev_dbg(&client->dev, "using 12MHz input clock\n");
clkrc |= to_clkrc(&priv->tpf, priv->pclk_max); clkrc |= to_clkrc(priv->tpf.numerator);
pclk = priv->pclk_max / GET_CLKRC_DIV(clkrc); pclk = priv->pclk_max / GET_CLKRC_DIV(clkrc);
dev_dbg(&client->dev, "pixel clock divider: %ld.%ld\n", dev_dbg(&client->dev, "pixel clock divider: %ld.%ld\n",
...@@ -749,9 +738,7 @@ static int ov6650_g_frame_interval(struct v4l2_subdev *sd, ...@@ -749,9 +738,7 @@ static int ov6650_g_frame_interval(struct v4l2_subdev *sd,
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
struct ov6650 *priv = to_ov6650(client); struct ov6650 *priv = to_ov6650(client);
ival->interval.numerator = GET_CLKRC_DIV(to_clkrc(&priv->tpf, ival->interval = priv->tpf;
priv->pclk_max));
ival->interval.denominator = FRAME_RATE_MAX;
dev_dbg(&client->dev, "Frame interval: %u/%u s\n", dev_dbg(&client->dev, "Frame interval: %u/%u s\n",
ival->interval.numerator, ival->interval.denominator); ival->interval.numerator, ival->interval.denominator);
...@@ -766,7 +753,6 @@ static int ov6650_s_frame_interval(struct v4l2_subdev *sd, ...@@ -766,7 +753,6 @@ static int ov6650_s_frame_interval(struct v4l2_subdev *sd,
struct ov6650 *priv = to_ov6650(client); struct ov6650 *priv = to_ov6650(client);
struct v4l2_fract *tpf = &ival->interval; struct v4l2_fract *tpf = &ival->interval;
int div, ret; int div, ret;
u8 clkrc;
if (tpf->numerator == 0 || tpf->denominator == 0) if (tpf->numerator == 0 || tpf->denominator == 0)
div = 1; /* Reset to full rate */ div = 1; /* Reset to full rate */
...@@ -778,14 +764,9 @@ static int ov6650_s_frame_interval(struct v4l2_subdev *sd, ...@@ -778,14 +764,9 @@ static int ov6650_s_frame_interval(struct v4l2_subdev *sd,
else if (div > GET_CLKRC_DIV(CLKRC_DIV_MASK)) else if (div > GET_CLKRC_DIV(CLKRC_DIV_MASK))
div = GET_CLKRC_DIV(CLKRC_DIV_MASK); div = GET_CLKRC_DIV(CLKRC_DIV_MASK);
tpf->numerator = div; ret = ov6650_reg_rmw(client, REG_CLKRC, to_clkrc(div), CLKRC_DIV_MASK);
tpf->denominator = FRAME_RATE_MAX;
clkrc = to_clkrc(tpf, priv->pclk_max);
ret = ov6650_reg_rmw(client, REG_CLKRC, clkrc, CLKRC_DIV_MASK);
if (!ret) { if (!ret) {
priv->tpf.numerator = GET_CLKRC_DIV(clkrc); priv->tpf.numerator = div;
priv->tpf.denominator = FRAME_RATE_MAX; priv->tpf.denominator = FRAME_RATE_MAX;
*tpf = priv->tpf; *tpf = priv->tpf;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment