Skip to content

Commit 1c004ef

Browse files
Vladimir ZapolskiyHans Verkuil
authored andcommitted
media: i2c: og01a1b: Add stubs of runtime power management functions
Rearrange initializations and checks in probe before population of the power management functions. Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
1 parent 4f6bec9 commit 1c004ef

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

drivers/media/i2c/og01a1b.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,19 @@ static int og01a1b_check_hwcfg(struct device *dev)
967967
return ret;
968968
}
969969

970+
/* Power/clock management functions */
971+
static int og01a1b_power_on(struct device *dev)
972+
{
973+
/* Device is already turned on by i2c-core with ACPI domain PM. */
974+
975+
return 0;
976+
}
977+
978+
static int og01a1b_power_off(struct device *dev)
979+
{
980+
return 0;
981+
}
982+
970983
static void og01a1b_remove(struct i2c_client *client)
971984
{
972985
struct v4l2_subdev *sd = i2c_get_clientdata(client);
@@ -984,22 +997,28 @@ static int og01a1b_probe(struct i2c_client *client)
984997
struct og01a1b *og01a1b;
985998
int ret;
986999

1000+
og01a1b = devm_kzalloc(&client->dev, sizeof(*og01a1b), GFP_KERNEL);
1001+
if (!og01a1b)
1002+
return -ENOMEM;
1003+
1004+
v4l2_i2c_subdev_init(&og01a1b->sd, client, &og01a1b_subdev_ops);
1005+
9871006
ret = og01a1b_check_hwcfg(&client->dev);
9881007
if (ret) {
9891008
dev_err(&client->dev, "failed to check HW configuration: %d",
9901009
ret);
9911010
return ret;
9921011
}
9931012

994-
og01a1b = devm_kzalloc(&client->dev, sizeof(*og01a1b), GFP_KERNEL);
995-
if (!og01a1b)
996-
return -ENOMEM;
1013+
/* The sensor must be powered on to read the CHIP_ID register */
1014+
ret = og01a1b_power_on(&client->dev);
1015+
if (ret)
1016+
return ret;
9971017

998-
v4l2_i2c_subdev_init(&og01a1b->sd, client, &og01a1b_subdev_ops);
9991018
ret = og01a1b_identify_module(og01a1b);
10001019
if (ret) {
10011020
dev_err(&client->dev, "failed to find sensor: %d", ret);
1002-
return ret;
1021+
goto power_off;
10031022
}
10041023

10051024
mutex_init(&og01a1b->mutex);
@@ -1028,10 +1047,7 @@ static int og01a1b_probe(struct i2c_client *client)
10281047
goto probe_error_media_entity_cleanup;
10291048
}
10301049

1031-
/*
1032-
* Device is already turned on by i2c-core with ACPI domain PM.
1033-
* Enable runtime PM and turn off the device.
1034-
*/
1050+
/* Enable runtime PM and turn off the device */
10351051
pm_runtime_set_active(&client->dev);
10361052
pm_runtime_enable(&client->dev);
10371053
pm_runtime_idle(&client->dev);
@@ -1045,9 +1061,16 @@ static int og01a1b_probe(struct i2c_client *client)
10451061
v4l2_ctrl_handler_free(og01a1b->sd.ctrl_handler);
10461062
mutex_destroy(&og01a1b->mutex);
10471063

1064+
power_off:
1065+
og01a1b_power_off(&client->dev);
1066+
10481067
return ret;
10491068
}
10501069

1070+
static const struct dev_pm_ops og01a1b_pm_ops = {
1071+
SET_RUNTIME_PM_OPS(og01a1b_power_off, og01a1b_power_on, NULL)
1072+
};
1073+
10511074
#ifdef CONFIG_ACPI
10521075
static const struct acpi_device_id og01a1b_acpi_ids[] = {
10531076
{"OVTI01AC"},
@@ -1066,6 +1089,7 @@ MODULE_DEVICE_TABLE(of, og01a1b_of_match);
10661089
static struct i2c_driver og01a1b_i2c_driver = {
10671090
.driver = {
10681091
.name = "og01a1b",
1092+
.pm = &og01a1b_pm_ops,
10691093
.acpi_match_table = ACPI_PTR(og01a1b_acpi_ids),
10701094
.of_match_table = og01a1b_of_match,
10711095
},

0 commit comments

Comments
 (0)