kernel: bump 6.1 to 6.1.66
[openwrt/staging/stintel.git] / target / linux / bcm27xx / patches-6.1 / 950-0399-media-i2c-Rename-ad5398-to-ad5398_vcm.patch
1 From 75bcf465c32541eb20eb5c75c16e073830c5b1d1 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 17 Mar 2022 15:13:10 +0000
4 Subject: [PATCH] media: i2c: Rename ad5398 to ad5398_vcm
5
6 There's already a regulator module called ad5398 that exposes
7 this device through the regulator API. That is meaningless in
8 the terms that it uses and how it maps to V4L2, so a new driver
9 was added. However the module name collision wasn't noted, so
10 rename it now.
11
12 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
13 ---
14 drivers/media/i2c/Makefile | 2 +-
15 drivers/media/i2c/{ad5398.c => ad5398_vcm.c} | 0
16 2 files changed, 1 insertion(+), 1 deletion(-)
17 rename drivers/media/i2c/{ad5398.c => ad5398_vcm.c} (100%)
18
19 --- a/drivers/media/i2c/Makefile
20 +++ b/drivers/media/i2c/Makefile
21 @@ -3,7 +3,7 @@
22 msp3400-objs := msp3400-driver.o msp3400-kthreads.o
23
24 obj-$(CONFIG_SDR_MAX2175) += max2175.o
25 -obj-$(CONFIG_VIDEO_AD5398) += ad5398.o
26 +obj-$(CONFIG_VIDEO_AD5398) += ad5398_vcm.o
27 obj-$(CONFIG_VIDEO_AD5820) += ad5820.o
28 obj-$(CONFIG_VIDEO_AD9389B) += ad9389b.o
29 obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o
30 --- a/drivers/media/i2c/ad5398.c
31 +++ /dev/null
32 @@ -1,341 +0,0 @@
33 -// SPDX-License-Identifier: GPL-2.0-only
34 -/*
35 - * AD5398 DAC driver for camera voice coil focus.
36 - * Copyright (C) 2021 Raspberry Pi (Trading) Ltd.
37 - *
38 - * Based on AD5820 DAC driver by Nokia and TI.
39 - *
40 - * This driver uses the regulator framework notification hooks on the
41 - * assumption that the VCM and sensor share a regulator. This means the VCM
42 - * position will be restored when either the sensor or VCM subdevices are opened
43 - * or powered up. The client can therefore choose to ignore the VCM subdevice,
44 - * and the lens position will be as previously requested. Without that, there
45 - * is a hard requirement to have the VCM subdevice open in order for the VCM
46 - * to be powered and at the requested position.
47 - */
48 -
49 -#include <linux/errno.h>
50 -#include <linux/i2c.h>
51 -#include <linux/kernel.h>
52 -#include <linux/module.h>
53 -#include <linux/regulator/consumer.h>
54 -#include <linux/gpio/consumer.h>
55 -
56 -#include <media/v4l2-ctrls.h>
57 -#include <media/v4l2-device.h>
58 -#include <media/v4l2-subdev.h>
59 -
60 -/* Register definitions */
61 -#define AD5398_POWER_DOWN BIT(15)
62 -#define AD5398_DAC_SHIFT 4
63 -
64 -#define to_ad5398_device(sd) container_of(sd, struct ad5398_device, subdev)
65 -
66 -struct ad5398_device {
67 - struct v4l2_subdev subdev;
68 - struct ad5398_platform_data *platform_data;
69 - struct regulator *vana;
70 - struct notifier_block nb;
71 -
72 - struct v4l2_ctrl_handler ctrls;
73 - u32 focus_absolute;
74 -
75 - bool standby;
76 -};
77 -
78 -static int ad5398_write(struct ad5398_device *coil, u16 data)
79 -{
80 - struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev);
81 - struct i2c_msg msg;
82 - __be16 be_data;
83 - int r;
84 -
85 - if (!client->adapter)
86 - return -ENODEV;
87 -
88 - be_data = cpu_to_be16(data);
89 - msg.addr = client->addr;
90 - msg.flags = 0;
91 - msg.len = 2;
92 - msg.buf = (u8 *)&be_data;
93 -
94 - r = i2c_transfer(client->adapter, &msg, 1);
95 - if (r < 0) {
96 - dev_err(&client->dev, "write failed, error %d\n", r);
97 - return r;
98 - }
99 -
100 - return 0;
101 -}
102 -
103 -/*
104 - * Calculate status word and write it to the device based on current
105 - * values of V4L2 controls. It is assumed that the stored V4L2 control
106 - * values are properly limited and rounded.
107 - */
108 -static int ad5398_update_hw(struct ad5398_device *coil)
109 -{
110 - u16 status;
111 -
112 - status = coil->focus_absolute << AD5398_DAC_SHIFT;
113 -
114 - if (coil->standby)
115 - status |= AD5398_POWER_DOWN;
116 -
117 - return ad5398_write(coil, status);
118 -}
119 -
120 -/*
121 - * Power handling
122 - */
123 -static int ad5398_power_off(struct ad5398_device *coil)
124 -{
125 - int ret = 0;
126 -
127 - coil->standby = true;
128 - ret = ad5398_update_hw(coil);
129 -
130 - return ret;
131 -}
132 -
133 -static int ad5398_power_on(struct ad5398_device *coil)
134 -{
135 - int ret;
136 -
137 - /* Restore the hardware settings. */
138 - coil->standby = false;
139 - ret = ad5398_update_hw(coil);
140 - if (ret)
141 - goto fail;
142 -
143 - return 0;
144 -
145 -fail:
146 - coil->standby = true;
147 -
148 - return ret;
149 -}
150 -
151 -/*
152 - * V4L2 controls
153 - */
154 -static int ad5398_set_ctrl(struct v4l2_ctrl *ctrl)
155 -{
156 - struct ad5398_device *coil =
157 - container_of(ctrl->handler, struct ad5398_device, ctrls);
158 -
159 - switch (ctrl->id) {
160 - case V4L2_CID_FOCUS_ABSOLUTE:
161 - coil->focus_absolute = ctrl->val;
162 - return ad5398_update_hw(coil);
163 - }
164 -
165 - return 0;
166 -}
167 -
168 -static const struct v4l2_ctrl_ops ad5398_ctrl_ops = {
169 - .s_ctrl = ad5398_set_ctrl,
170 -};
171 -
172 -static int ad5398_init_controls(struct ad5398_device *coil)
173 -{
174 - v4l2_ctrl_handler_init(&coil->ctrls, 1);
175 -
176 - /*
177 - * V4L2_CID_FOCUS_ABSOLUTE
178 - *
179 - * Minimum current is 0 mA, maximum is 120 mA. Thus, 1 code is
180 - * equivalent to 120/1023 = 0.1173 mA. Nevertheless, we do not use [mA]
181 - * for focus position, because it is meaningless for user. Meaningful
182 - * would be to use focus distance or even its inverse, but since the
183 - * driver doesn't have sufficient knowledge to do the conversion, we
184 - * will just use abstract codes here. In any case, smaller value = focus
185 - * position farther from camera. The default zero value means focus at
186 - * infinity, and also least current consumption.
187 - */
188 - v4l2_ctrl_new_std(&coil->ctrls, &ad5398_ctrl_ops,
189 - V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0);
190 -
191 - if (coil->ctrls.error)
192 - return coil->ctrls.error;
193 -
194 - coil->focus_absolute = 0;
195 -
196 - coil->subdev.ctrl_handler = &coil->ctrls;
197 -
198 - return 0;
199 -}
200 -
201 -/*
202 - * V4L2 subdev operations
203 - */
204 -static int ad5398_registered(struct v4l2_subdev *subdev)
205 -{
206 - struct ad5398_device *coil = to_ad5398_device(subdev);
207 -
208 - return ad5398_init_controls(coil);
209 -}
210 -
211 -static int
212 -ad5398_set_power(struct v4l2_subdev *subdev, int on)
213 -{
214 - struct ad5398_device *coil = to_ad5398_device(subdev);
215 - int ret;
216 -
217 - if (on)
218 - ret = regulator_enable(coil->vana);
219 - else
220 - ret = regulator_disable(coil->vana);
221 -
222 - return ret;
223 -}
224 -
225 -static int ad5398_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
226 -{
227 - struct ad5398_device *coil = to_ad5398_device(sd);
228 -
229 - return regulator_enable(coil->vana);
230 -}
231 -
232 -static int ad5398_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
233 -{
234 - struct ad5398_device *coil = to_ad5398_device(sd);
235 -
236 - return regulator_disable(coil->vana);
237 -}
238 -
239 -static const struct v4l2_subdev_core_ops ad5398_core_ops = {
240 - .s_power = ad5398_set_power,
241 -};
242 -
243 -static const struct v4l2_subdev_ops ad5398_ops = {
244 - .core = &ad5398_core_ops,
245 -};
246 -
247 -static const struct v4l2_subdev_internal_ops ad5398_internal_ops = {
248 - .registered = ad5398_registered,
249 - .open = ad5398_open,
250 - .close = ad5398_close,
251 -};
252 -
253 -/*
254 - * I2C driver
255 - */
256 -static int __maybe_unused ad5398_suspend(struct device *dev)
257 -{
258 - struct i2c_client *client = container_of(dev, struct i2c_client, dev);
259 - struct v4l2_subdev *subdev = i2c_get_clientdata(client);
260 - struct ad5398_device *coil = to_ad5398_device(subdev);
261 -
262 - return regulator_enable(coil->vana);
263 -}
264 -
265 -static int __maybe_unused ad5398_resume(struct device *dev)
266 -{
267 - struct i2c_client *client = container_of(dev, struct i2c_client, dev);
268 - struct v4l2_subdev *subdev = i2c_get_clientdata(client);
269 - struct ad5398_device *coil = to_ad5398_device(subdev);
270 -
271 - return regulator_disable(coil->vana);
272 -}
273 -
274 -static int ad5398_regulator_notifier(struct notifier_block *nb,
275 - unsigned long event,
276 - void *ignored)
277 -{
278 - struct ad5398_device *coil = container_of(nb, struct ad5398_device, nb);
279 -
280 - if (event == REGULATOR_EVENT_ENABLE)
281 - ad5398_power_on(coil);
282 - else if (event == REGULATOR_EVENT_PRE_DISABLE)
283 - ad5398_power_off(coil);
284 -
285 - return NOTIFY_OK;
286 -}
287 -
288 -static int ad5398_probe(struct i2c_client *client,
289 - const struct i2c_device_id *devid)
290 -{
291 - struct ad5398_device *coil;
292 - int ret;
293 -
294 - coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL);
295 - if (!coil)
296 - return -ENOMEM;
297 -
298 - coil->vana = devm_regulator_get(&client->dev, "VANA");
299 - if (IS_ERR(coil->vana)) {
300 - ret = PTR_ERR(coil->vana);
301 - if (ret != -EPROBE_DEFER)
302 - dev_err(&client->dev, "could not get regulator for vana\n");
303 - return ret;
304 - }
305 -
306 - v4l2_i2c_subdev_init(&coil->subdev, client, &ad5398_ops);
307 - coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
308 - coil->subdev.internal_ops = &ad5398_internal_ops;
309 - coil->subdev.entity.function = MEDIA_ENT_F_LENS;
310 - strscpy(coil->subdev.name, "ad5398 focus", sizeof(coil->subdev.name));
311 -
312 - coil->nb.notifier_call = &ad5398_regulator_notifier;
313 - ret = regulator_register_notifier(coil->vana, &coil->nb);
314 - if (ret < 0)
315 - return ret;
316 -
317 - ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL);
318 - if (ret < 0)
319 - goto cleanup2;
320 -
321 - ret = v4l2_async_register_subdev(&coil->subdev);
322 - if (ret < 0)
323 - goto cleanup;
324 -
325 - return ret;
326 -
327 -cleanup:
328 - media_entity_cleanup(&coil->subdev.entity);
329 -cleanup2:
330 - regulator_unregister_notifier(coil->vana, &coil->nb);
331 - return ret;
332 -}
333 -
334 -static void ad5398_remove(struct i2c_client *client)
335 -{
336 - struct v4l2_subdev *subdev = i2c_get_clientdata(client);
337 - struct ad5398_device *coil = to_ad5398_device(subdev);
338 -
339 - v4l2_async_unregister_subdev(&coil->subdev);
340 - v4l2_ctrl_handler_free(&coil->ctrls);
341 - media_entity_cleanup(&coil->subdev.entity);
342 -}
343 -
344 -static const struct i2c_device_id ad5398_id_table[] = {
345 - { "ad5398", 0 },
346 - { }
347 -};
348 -MODULE_DEVICE_TABLE(i2c, ad5398_id_table);
349 -
350 -static const struct of_device_id ad5398_of_table[] = {
351 - { .compatible = "adi,ad5398" },
352 - { }
353 -};
354 -MODULE_DEVICE_TABLE(of, ad5398_of_table);
355 -
356 -static SIMPLE_DEV_PM_OPS(ad5398_pm, ad5398_suspend, ad5398_resume);
357 -
358 -static struct i2c_driver ad5398_i2c_driver = {
359 - .driver = {
360 - .name = "ad5398",
361 - .pm = &ad5398_pm,
362 - .of_match_table = ad5398_of_table,
363 - },
364 - .probe = ad5398_probe,
365 - .remove = ad5398_remove,
366 - .id_table = ad5398_id_table,
367 -};
368 -
369 -module_i2c_driver(ad5398_i2c_driver);
370 -
371 -MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.com>");
372 -MODULE_DESCRIPTION("AD5398 camera lens driver");
373 -MODULE_LICENSE("GPL");
374 --- /dev/null
375 +++ b/drivers/media/i2c/ad5398_vcm.c
376 @@ -0,0 +1,341 @@
377 +// SPDX-License-Identifier: GPL-2.0-only
378 +/*
379 + * AD5398 DAC driver for camera voice coil focus.
380 + * Copyright (C) 2021 Raspberry Pi (Trading) Ltd.
381 + *
382 + * Based on AD5820 DAC driver by Nokia and TI.
383 + *
384 + * This driver uses the regulator framework notification hooks on the
385 + * assumption that the VCM and sensor share a regulator. This means the VCM
386 + * position will be restored when either the sensor or VCM subdevices are opened
387 + * or powered up. The client can therefore choose to ignore the VCM subdevice,
388 + * and the lens position will be as previously requested. Without that, there
389 + * is a hard requirement to have the VCM subdevice open in order for the VCM
390 + * to be powered and at the requested position.
391 + */
392 +
393 +#include <linux/errno.h>
394 +#include <linux/i2c.h>
395 +#include <linux/kernel.h>
396 +#include <linux/module.h>
397 +#include <linux/regulator/consumer.h>
398 +#include <linux/gpio/consumer.h>
399 +
400 +#include <media/v4l2-ctrls.h>
401 +#include <media/v4l2-device.h>
402 +#include <media/v4l2-subdev.h>
403 +
404 +/* Register definitions */
405 +#define AD5398_POWER_DOWN BIT(15)
406 +#define AD5398_DAC_SHIFT 4
407 +
408 +#define to_ad5398_device(sd) container_of(sd, struct ad5398_device, subdev)
409 +
410 +struct ad5398_device {
411 + struct v4l2_subdev subdev;
412 + struct ad5398_platform_data *platform_data;
413 + struct regulator *vana;
414 + struct notifier_block nb;
415 +
416 + struct v4l2_ctrl_handler ctrls;
417 + u32 focus_absolute;
418 +
419 + bool standby;
420 +};
421 +
422 +static int ad5398_write(struct ad5398_device *coil, u16 data)
423 +{
424 + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev);
425 + struct i2c_msg msg;
426 + __be16 be_data;
427 + int r;
428 +
429 + if (!client->adapter)
430 + return -ENODEV;
431 +
432 + be_data = cpu_to_be16(data);
433 + msg.addr = client->addr;
434 + msg.flags = 0;
435 + msg.len = 2;
436 + msg.buf = (u8 *)&be_data;
437 +
438 + r = i2c_transfer(client->adapter, &msg, 1);
439 + if (r < 0) {
440 + dev_err(&client->dev, "write failed, error %d\n", r);
441 + return r;
442 + }
443 +
444 + return 0;
445 +}
446 +
447 +/*
448 + * Calculate status word and write it to the device based on current
449 + * values of V4L2 controls. It is assumed that the stored V4L2 control
450 + * values are properly limited and rounded.
451 + */
452 +static int ad5398_update_hw(struct ad5398_device *coil)
453 +{
454 + u16 status;
455 +
456 + status = coil->focus_absolute << AD5398_DAC_SHIFT;
457 +
458 + if (coil->standby)
459 + status |= AD5398_POWER_DOWN;
460 +
461 + return ad5398_write(coil, status);
462 +}
463 +
464 +/*
465 + * Power handling
466 + */
467 +static int ad5398_power_off(struct ad5398_device *coil)
468 +{
469 + int ret = 0;
470 +
471 + coil->standby = true;
472 + ret = ad5398_update_hw(coil);
473 +
474 + return ret;
475 +}
476 +
477 +static int ad5398_power_on(struct ad5398_device *coil)
478 +{
479 + int ret;
480 +
481 + /* Restore the hardware settings. */
482 + coil->standby = false;
483 + ret = ad5398_update_hw(coil);
484 + if (ret)
485 + goto fail;
486 +
487 + return 0;
488 +
489 +fail:
490 + coil->standby = true;
491 +
492 + return ret;
493 +}
494 +
495 +/*
496 + * V4L2 controls
497 + */
498 +static int ad5398_set_ctrl(struct v4l2_ctrl *ctrl)
499 +{
500 + struct ad5398_device *coil =
501 + container_of(ctrl->handler, struct ad5398_device, ctrls);
502 +
503 + switch (ctrl->id) {
504 + case V4L2_CID_FOCUS_ABSOLUTE:
505 + coil->focus_absolute = ctrl->val;
506 + return ad5398_update_hw(coil);
507 + }
508 +
509 + return 0;
510 +}
511 +
512 +static const struct v4l2_ctrl_ops ad5398_ctrl_ops = {
513 + .s_ctrl = ad5398_set_ctrl,
514 +};
515 +
516 +static int ad5398_init_controls(struct ad5398_device *coil)
517 +{
518 + v4l2_ctrl_handler_init(&coil->ctrls, 1);
519 +
520 + /*
521 + * V4L2_CID_FOCUS_ABSOLUTE
522 + *
523 + * Minimum current is 0 mA, maximum is 120 mA. Thus, 1 code is
524 + * equivalent to 120/1023 = 0.1173 mA. Nevertheless, we do not use [mA]
525 + * for focus position, because it is meaningless for user. Meaningful
526 + * would be to use focus distance or even its inverse, but since the
527 + * driver doesn't have sufficient knowledge to do the conversion, we
528 + * will just use abstract codes here. In any case, smaller value = focus
529 + * position farther from camera. The default zero value means focus at
530 + * infinity, and also least current consumption.
531 + */
532 + v4l2_ctrl_new_std(&coil->ctrls, &ad5398_ctrl_ops,
533 + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0);
534 +
535 + if (coil->ctrls.error)
536 + return coil->ctrls.error;
537 +
538 + coil->focus_absolute = 0;
539 +
540 + coil->subdev.ctrl_handler = &coil->ctrls;
541 +
542 + return 0;
543 +}
544 +
545 +/*
546 + * V4L2 subdev operations
547 + */
548 +static int ad5398_registered(struct v4l2_subdev *subdev)
549 +{
550 + struct ad5398_device *coil = to_ad5398_device(subdev);
551 +
552 + return ad5398_init_controls(coil);
553 +}
554 +
555 +static int
556 +ad5398_set_power(struct v4l2_subdev *subdev, int on)
557 +{
558 + struct ad5398_device *coil = to_ad5398_device(subdev);
559 + int ret;
560 +
561 + if (on)
562 + ret = regulator_enable(coil->vana);
563 + else
564 + ret = regulator_disable(coil->vana);
565 +
566 + return ret;
567 +}
568 +
569 +static int ad5398_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
570 +{
571 + struct ad5398_device *coil = to_ad5398_device(sd);
572 +
573 + return regulator_enable(coil->vana);
574 +}
575 +
576 +static int ad5398_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
577 +{
578 + struct ad5398_device *coil = to_ad5398_device(sd);
579 +
580 + return regulator_disable(coil->vana);
581 +}
582 +
583 +static const struct v4l2_subdev_core_ops ad5398_core_ops = {
584 + .s_power = ad5398_set_power,
585 +};
586 +
587 +static const struct v4l2_subdev_ops ad5398_ops = {
588 + .core = &ad5398_core_ops,
589 +};
590 +
591 +static const struct v4l2_subdev_internal_ops ad5398_internal_ops = {
592 + .registered = ad5398_registered,
593 + .open = ad5398_open,
594 + .close = ad5398_close,
595 +};
596 +
597 +/*
598 + * I2C driver
599 + */
600 +static int __maybe_unused ad5398_suspend(struct device *dev)
601 +{
602 + struct i2c_client *client = container_of(dev, struct i2c_client, dev);
603 + struct v4l2_subdev *subdev = i2c_get_clientdata(client);
604 + struct ad5398_device *coil = to_ad5398_device(subdev);
605 +
606 + return regulator_enable(coil->vana);
607 +}
608 +
609 +static int __maybe_unused ad5398_resume(struct device *dev)
610 +{
611 + struct i2c_client *client = container_of(dev, struct i2c_client, dev);
612 + struct v4l2_subdev *subdev = i2c_get_clientdata(client);
613 + struct ad5398_device *coil = to_ad5398_device(subdev);
614 +
615 + return regulator_disable(coil->vana);
616 +}
617 +
618 +static int ad5398_regulator_notifier(struct notifier_block *nb,
619 + unsigned long event,
620 + void *ignored)
621 +{
622 + struct ad5398_device *coil = container_of(nb, struct ad5398_device, nb);
623 +
624 + if (event == REGULATOR_EVENT_ENABLE)
625 + ad5398_power_on(coil);
626 + else if (event == REGULATOR_EVENT_PRE_DISABLE)
627 + ad5398_power_off(coil);
628 +
629 + return NOTIFY_OK;
630 +}
631 +
632 +static int ad5398_probe(struct i2c_client *client,
633 + const struct i2c_device_id *devid)
634 +{
635 + struct ad5398_device *coil;
636 + int ret;
637 +
638 + coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL);
639 + if (!coil)
640 + return -ENOMEM;
641 +
642 + coil->vana = devm_regulator_get(&client->dev, "VANA");
643 + if (IS_ERR(coil->vana)) {
644 + ret = PTR_ERR(coil->vana);
645 + if (ret != -EPROBE_DEFER)
646 + dev_err(&client->dev, "could not get regulator for vana\n");
647 + return ret;
648 + }
649 +
650 + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5398_ops);
651 + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
652 + coil->subdev.internal_ops = &ad5398_internal_ops;
653 + coil->subdev.entity.function = MEDIA_ENT_F_LENS;
654 + strscpy(coil->subdev.name, "ad5398 focus", sizeof(coil->subdev.name));
655 +
656 + coil->nb.notifier_call = &ad5398_regulator_notifier;
657 + ret = regulator_register_notifier(coil->vana, &coil->nb);
658 + if (ret < 0)
659 + return ret;
660 +
661 + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL);
662 + if (ret < 0)
663 + goto cleanup2;
664 +
665 + ret = v4l2_async_register_subdev(&coil->subdev);
666 + if (ret < 0)
667 + goto cleanup;
668 +
669 + return ret;
670 +
671 +cleanup:
672 + media_entity_cleanup(&coil->subdev.entity);
673 +cleanup2:
674 + regulator_unregister_notifier(coil->vana, &coil->nb);
675 + return ret;
676 +}
677 +
678 +static void ad5398_remove(struct i2c_client *client)
679 +{
680 + struct v4l2_subdev *subdev = i2c_get_clientdata(client);
681 + struct ad5398_device *coil = to_ad5398_device(subdev);
682 +
683 + v4l2_async_unregister_subdev(&coil->subdev);
684 + v4l2_ctrl_handler_free(&coil->ctrls);
685 + media_entity_cleanup(&coil->subdev.entity);
686 +}
687 +
688 +static const struct i2c_device_id ad5398_id_table[] = {
689 + { "ad5398", 0 },
690 + { }
691 +};
692 +MODULE_DEVICE_TABLE(i2c, ad5398_id_table);
693 +
694 +static const struct of_device_id ad5398_of_table[] = {
695 + { .compatible = "adi,ad5398" },
696 + { }
697 +};
698 +MODULE_DEVICE_TABLE(of, ad5398_of_table);
699 +
700 +static SIMPLE_DEV_PM_OPS(ad5398_pm, ad5398_suspend, ad5398_resume);
701 +
702 +static struct i2c_driver ad5398_i2c_driver = {
703 + .driver = {
704 + .name = "ad5398",
705 + .pm = &ad5398_pm,
706 + .of_match_table = ad5398_of_table,
707 + },
708 + .probe = ad5398_probe,
709 + .remove = ad5398_remove,
710 + .id_table = ad5398_id_table,
711 +};
712 +
713 +module_i2c_driver(ad5398_i2c_driver);
714 +
715 +MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.com>");
716 +MODULE_DESCRIPTION("AD5398 camera lens driver");
717 +MODULE_LICENSE("GPL");