Skip to content

Commit 24786cc

Browse files
dillon-minmchehab
authored andcommitted
media: i2c: ov2659: Use clk_{prepare_enable,disable_unprepare}() to set xvclk on/off
On some platform(imx6q), xvclk might not switch on in advance, also for power save purpose, xvclk should not be always on. so, add clk_prepare_enable(), clk_disable_unprepare() in driver side to set xvclk on/off at proper stage. Add following changes: - add 'struct clk *clk;' in 'struct ov2659 {}' - enable xvclk in ov2659_power_on() - disable xvclk in ov2659_power_off() Signed-off-by: Dillon Min <dillon.minfei@gmail.com> Acked-by: Lad Prabhakar <prabhakar.csengg@gmail.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 2cb2705 commit 24786cc

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

‎drivers/media/i2c/ov2659.c‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ struct ov2659 {
204204
struct i2c_client *client;
205205
struct v4l2_ctrl_handler ctrls;
206206
struct v4l2_ctrl *link_frequency;
207+
struct clk *clk;
207208
const struct ov2659_framesize *frame_size;
208209
struct sensor_register *format_ctrl_regs;
209210
struct ov2659_pll_ctrl pll;
@@ -1268,6 +1269,8 @@ static int ov2659_power_off(struct device *dev)
12681269

12691270
gpiod_set_value(ov2659->pwdn_gpio, 1);
12701271

1272+
clk_disable_unprepare(ov2659->clk);
1273+
12711274
return 0;
12721275
}
12731276

@@ -1276,9 +1279,17 @@ static int ov2659_power_on(struct device *dev)
12761279
struct i2c_client *client = to_i2c_client(dev);
12771280
struct v4l2_subdev *sd = i2c_get_clientdata(client);
12781281
struct ov2659 *ov2659 = to_ov2659(sd);
1282+
int ret;
12791283

12801284
dev_dbg(&client->dev, "%s:\n", __func__);
12811285

1286+
ret = clk_prepare_enable(ov2659->clk);
1287+
if (ret) {
1288+
dev_err(&client->dev, "%s: failed to enable clock\n",
1289+
__func__);
1290+
return ret;
1291+
}
1292+
12821293
gpiod_set_value(ov2659->pwdn_gpio, 0);
12831294

12841295
if (ov2659->resetb_gpio) {
@@ -1423,7 +1434,6 @@ static int ov2659_probe(struct i2c_client *client)
14231434
const struct ov2659_platform_data *pdata = ov2659_get_pdata(client);
14241435
struct v4l2_subdev *sd;
14251436
struct ov2659 *ov2659;
1426-
struct clk *clk;
14271437
int ret;
14281438

14291439
if (!pdata) {
@@ -1438,11 +1448,11 @@ static int ov2659_probe(struct i2c_client *client)
14381448
ov2659->pdata = pdata;
14391449
ov2659->client = client;
14401450

1441-
clk = devm_clk_get(&client->dev, "xvclk");
1442-
if (IS_ERR(clk))
1443-
return PTR_ERR(clk);
1451+
ov2659->clk = devm_clk_get(&client->dev, "xvclk");
1452+
if (IS_ERR(ov2659->clk))
1453+
return PTR_ERR(ov2659->clk);
14441454

1445-
ov2659->xvclk_frequency = clk_get_rate(clk);
1455+
ov2659->xvclk_frequency = clk_get_rate(ov2659->clk);
14461456
if (ov2659->xvclk_frequency < 6000000 ||
14471457
ov2659->xvclk_frequency > 27000000)
14481458
return -EINVAL;
@@ -1504,7 +1514,9 @@ static int ov2659_probe(struct i2c_client *client)
15041514
ov2659->frame_size = &ov2659_framesizes[2];
15051515
ov2659->format_ctrl_regs = ov2659_formats[0].format_ctrl_regs;
15061516

1507-
ov2659_power_on(&client->dev);
1517+
ret = ov2659_power_on(&client->dev);
1518+
if (ret < 0)
1519+
goto error;
15081520

15091521
ret = ov2659_detect(sd);
15101522
if (ret < 0)

0 commit comments

Comments
 (0)