hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/i2c/ad5820.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * drivers/media/i2c/ad5820.c
34 *
....@@ -11,15 +12,6 @@
1112 * Sakari Ailus <sakari.ailus@iki.fi>
1213 *
1314 * Based on af_d88.c by Texas Instruments.
14
- *
15
- * This program is free software; you can redistribute it and/or
16
- * modify it under the terms of the GNU General Public License
17
- * version 2 as published by the Free Software Foundation.
18
- *
19
- * This program is distributed in the hope that it will be useful, but
20
- * WITHOUT ANY WARRANTY; without even the implied warranty of
21
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
- * General Public License for more details.
2315 */
2416
2517 #include <linux/errno.h>
....@@ -27,12 +19,11 @@
2719 #include <linux/kernel.h>
2820 #include <linux/module.h>
2921 #include <linux/regulator/consumer.h>
22
+#include <linux/gpio/consumer.h>
3023
3124 #include <media/v4l2-ctrls.h>
3225 #include <media/v4l2-device.h>
3326 #include <media/v4l2-subdev.h>
34
-
35
-#define AD5820_NAME "ad5820"
3627
3728 /* Register definitions */
3829 #define AD5820_POWER_DOWN (1 << 15)
....@@ -54,6 +45,8 @@
5445 u32 focus_absolute;
5546 u32 focus_ramp_time;
5647 u32 focus_ramp_mode;
48
+
49
+ struct gpio_desc *enable_gpio;
5750
5851 struct mutex power_lock;
5952 int power_count;
....@@ -122,6 +115,8 @@
122115 ret = ad5820_update_hw(coil);
123116 }
124117
118
+ gpiod_set_value_cansleep(coil->enable_gpio, 0);
119
+
125120 ret2 = regulator_disable(coil->vana);
126121 if (ret)
127122 return ret;
....@@ -136,6 +131,8 @@
136131 if (ret < 0)
137132 return ret;
138133
134
+ gpiod_set_value_cansleep(coil->enable_gpio, 1);
135
+
139136 if (restore) {
140137 /* Restore the hardware settings. */
141138 coil->standby = false;
....@@ -146,6 +143,7 @@
146143 return 0;
147144
148145 fail:
146
+ gpiod_set_value_cansleep(coil->enable_gpio, 0);
149147 coil->standby = true;
150148 regulator_disable(coil->vana);
151149
....@@ -312,12 +310,22 @@
312310 return ret;
313311 }
314312
313
+ coil->enable_gpio = devm_gpiod_get_optional(&client->dev, "enable",
314
+ GPIOD_OUT_LOW);
315
+ if (IS_ERR(coil->enable_gpio)) {
316
+ ret = PTR_ERR(coil->enable_gpio);
317
+ if (ret != -EPROBE_DEFER)
318
+ dev_err(&client->dev, "could not get enable gpio\n");
319
+ return ret;
320
+ }
321
+
315322 mutex_init(&coil->power_lock);
316323
317324 v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops);
318325 coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
319326 coil->subdev.internal_ops = &ad5820_internal_ops;
320
- strcpy(coil->subdev.name, "ad5820 focus");
327
+ coil->subdev.entity.function = MEDIA_ENT_F_LENS;
328
+ strscpy(coil->subdev.name, "ad5820 focus", sizeof(coil->subdev.name));
321329
322330 ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL);
323331 if (ret < 0)
....@@ -349,17 +357,28 @@
349357 }
350358
351359 static const struct i2c_device_id ad5820_id_table[] = {
352
- { AD5820_NAME, 0 },
360
+ { "ad5820", 0 },
361
+ { "ad5821", 0 },
362
+ { "ad5823", 0 },
353363 { }
354364 };
355365 MODULE_DEVICE_TABLE(i2c, ad5820_id_table);
366
+
367
+static const struct of_device_id ad5820_of_table[] = {
368
+ { .compatible = "adi,ad5820" },
369
+ { .compatible = "adi,ad5821" },
370
+ { .compatible = "adi,ad5823" },
371
+ { }
372
+};
373
+MODULE_DEVICE_TABLE(of, ad5820_of_table);
356374
357375 static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume);
358376
359377 static struct i2c_driver ad5820_i2c_driver = {
360378 .driver = {
361
- .name = AD5820_NAME,
379
+ .name = "ad5820",
362380 .pm = &ad5820_pm,
381
+ .of_match_table = ad5820_of_table,
363382 },
364383 .probe = ad5820_probe,
365384 .remove = ad5820_remove,