Skip to content

Commit a61d119

Browse files
dillon-mingregkh
authored andcommitted
media: i2c: ov2659: Use clk_{prepare_enable,disable_unprepare}() to set xvclk on/off
[ Upstream commit 24786cc ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9fa8542 commit a61d119

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;
@@ -1270,6 +1271,8 @@ static int ov2659_power_off(struct device *dev)
12701271

12711272
gpiod_set_value(ov2659->pwdn_gpio, 1);
12721273

1274+
clk_disable_unprepare(ov2659->clk);
1275+
12731276
return 0;
12741277
}
12751278

@@ -1278,9 +1281,17 @@ static int ov2659_power_on(struct device *dev)
12781281
struct i2c_client *client = to_i2c_client(dev);
12791282
struct v4l2_subdev *sd = i2c_get_clientdata(client);
12801283
struct ov2659 *ov2659 = to_ov2659(sd);
1284+
int ret;
12811285

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

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

12861297
if (ov2659->resetb_gpio) {
@@ -1425,7 +1436,6 @@ static int ov2659_probe(struct i2c_client *client)
14251436
const struct ov2659_platform_data *pdata = ov2659_get_pdata(client);
14261437
struct v4l2_subdev *sd;
14271438
struct ov2659 *ov2659;
1428-
struct clk *clk;
14291439
int ret;
14301440

14311441
if (!pdata) {
@@ -1440,11 +1450,11 @@ static int ov2659_probe(struct i2c_client *client)
14401450
ov2659->pdata = pdata;
14411451
ov2659->client = client;
14421452

1443-
clk = devm_clk_get(&client->dev, "xvclk");
1444-
if (IS_ERR(clk))
1445-
return PTR_ERR(clk);
1453+
ov2659->clk = devm_clk_get(&client->dev, "xvclk");
1454+
if (IS_ERR(ov2659->clk))
1455+
return PTR_ERR(ov2659->clk);
14461456

1447-
ov2659->xvclk_frequency = clk_get_rate(clk);
1457+
ov2659->xvclk_frequency = clk_get_rate(ov2659->clk);
14481458
if (ov2659->xvclk_frequency < 6000000 ||
14491459
ov2659->xvclk_frequency > 27000000)
14501460
return -EINVAL;
@@ -1506,7 +1516,9 @@ static int ov2659_probe(struct i2c_client *client)
15061516
ov2659->frame_size = &ov2659_framesizes[2];
15071517
ov2659->format_ctrl_regs = ov2659_formats[0].format_ctrl_regs;
15081518

1509-
ov2659_power_on(&client->dev);
1519+
ret = ov2659_power_on(&client->dev);
1520+
if (ret < 0)
1521+
goto error;
15101522

15111523
ret = ov2659_detect(sd);
15121524
if (ret < 0)

0 commit comments

Comments
 (0)