bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0777-media-i2c-Rename-ad5398-to-ad5398_vcm.patch
1 From 31bcdc66bb6bb5ae9b700693786a5ab46231484c 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 @@ -21,7 +21,7 @@ obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o
22 obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
23 obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o
24 obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.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_AK7375) += ak7375.o
29 obj-$(CONFIG_VIDEO_DW9714) += dw9714.o
30 --- a/drivers/media/i2c/ad5398.c
31 +++ /dev/null
32 @@ -1,342 +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 int 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 - return 0;
343 -}
344 -
345 -static const struct i2c_device_id ad5398_id_table[] = {
346 - { "ad5398", 0 },
347 - { }
348 -};
349 -MODULE_DEVICE_TABLE(i2c, ad5398_id_table);
350 -
351 -static const struct of_device_id ad5398_of_table[] = {
352 - { .compatible = "adi,ad5398" },
353 - { }
354 -};
355 -MODULE_DEVICE_TABLE(of, ad5398_of_table);
356 -
357 -static SIMPLE_DEV_PM_OPS(ad5398_pm, ad5398_suspend, ad5398_resume);
358 -
359 -static struct i2c_driver ad5398_i2c_driver = {
360 - .driver = {
361 - .name = "ad5398",
362 - .pm = &ad5398_pm,
363 - .of_match_table = ad5398_of_table,
364 - },
365 - .probe = ad5398_probe,
366 - .remove = ad5398_remove,
367 - .id_table = ad5398_id_table,
368 -};
369 -
370 -module_i2c_driver(ad5398_i2c_driver);
371 -
372 -MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.com>");
373 -MODULE_DESCRIPTION("AD5398 camera lens driver");
374 -MODULE_LICENSE("GPL");
375 --- /dev/null
376 +++ b/drivers/media/i2c/ad5398_vcm.c
377 @@ -0,0 +1,342 @@
378 +// SPDX-License-Identifier: GPL-2.0-only
379 +/*
380 + * AD5398 DAC driver for camera voice coil focus.
381 + * Copyright (C) 2021 Raspberry Pi (Trading) Ltd.
382 + *
383 + * Based on AD5820 DAC driver by Nokia and TI.
384 + *
385 + * This driver uses the regulator framework notification hooks on the
386 + * assumption that the VCM and sensor share a regulator. This means the VCM
387 + * position will be restored when either the sensor or VCM subdevices are opened
388 + * or powered up. The client can therefore choose to ignore the VCM subdevice,
389 + * and the lens position will be as previously requested. Without that, there
390 + * is a hard requirement to have the VCM subdevice open in order for the VCM
391 + * to be powered and at the requested position.
392 + */
393 +
394 +#include <linux/errno.h>
395 +#include <linux/i2c.h>
396 +#include <linux/kernel.h>
397 +#include <linux/module.h>
398 +#include <linux/regulator/consumer.h>
399 +#include <linux/gpio/consumer.h>
400 +
401 +#include <media/v4l2-ctrls.h>
402 +#include <media/v4l2-device.h>
403 +#include <media/v4l2-subdev.h>
404 +
405 +/* Register definitions */
406 +#define AD5398_POWER_DOWN BIT(15)
407 +#define AD5398_DAC_SHIFT 4
408 +
409 +#define to_ad5398_device(sd) container_of(sd, struct ad5398_device, subdev)
410 +
411 +struct ad5398_device {
412 + struct v4l2_subdev subdev;
413 + struct ad5398_platform_data *platform_data;
414 + struct regulator *vana;
415 + struct notifier_block nb;
416 +
417 + struct v4l2_ctrl_handler ctrls;
418 + u32 focus_absolute;
419 +
420 + bool standby;
421 +};
422 +
423 +static int ad5398_write(struct ad5398_device *coil, u16 data)
424 +{
425 + struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev);
426 + struct i2c_msg msg;
427 + __be16 be_data;
428 + int r;
429 +
430 + if (!client->adapter)
431 + return -ENODEV;
432 +
433 + be_data = cpu_to_be16(data);
434 + msg.addr = client->addr;
435 + msg.flags = 0;
436 + msg.len = 2;
437 + msg.buf = (u8 *)&be_data;
438 +
439 + r = i2c_transfer(client->adapter, &msg, 1);
440 + if (r < 0) {
441 + dev_err(&client->dev, "write failed, error %d\n", r);
442 + return r;
443 + }
444 +
445 + return 0;
446 +}
447 +
448 +/*
449 + * Calculate status word and write it to the device based on current
450 + * values of V4L2 controls. It is assumed that the stored V4L2 control
451 + * values are properly limited and rounded.
452 + */
453 +static int ad5398_update_hw(struct ad5398_device *coil)
454 +{
455 + u16 status;
456 +
457 + status = coil->focus_absolute << AD5398_DAC_SHIFT;
458 +
459 + if (coil->standby)
460 + status |= AD5398_POWER_DOWN;
461 +
462 + return ad5398_write(coil, status);
463 +}
464 +
465 +/*
466 + * Power handling
467 + */
468 +static int ad5398_power_off(struct ad5398_device *coil)
469 +{
470 + int ret = 0;
471 +
472 + coil->standby = true;
473 + ret = ad5398_update_hw(coil);
474 +
475 + return ret;
476 +}
477 +
478 +static int ad5398_power_on(struct ad5398_device *coil)
479 +{
480 + int ret;
481 +
482 + /* Restore the hardware settings. */
483 + coil->standby = false;
484 + ret = ad5398_update_hw(coil);
485 + if (ret)
486 + goto fail;
487 +
488 + return 0;
489 +
490 +fail:
491 + coil->standby = true;
492 +
493 + return ret;
494 +}
495 +
496 +/*
497 + * V4L2 controls
498 + */
499 +static int ad5398_set_ctrl(struct v4l2_ctrl *ctrl)
500 +{
501 + struct ad5398_device *coil =
502 + container_of(ctrl->handler, struct ad5398_device, ctrls);
503 +
504 + switch (ctrl->id) {
505 + case V4L2_CID_FOCUS_ABSOLUTE:
506 + coil->focus_absolute = ctrl->val;
507 + return ad5398_update_hw(coil);
508 + }
509 +
510 + return 0;
511 +}
512 +
513 +static const struct v4l2_ctrl_ops ad5398_ctrl_ops = {
514 + .s_ctrl = ad5398_set_ctrl,
515 +};
516 +
517 +static int ad5398_init_controls(struct ad5398_device *coil)
518 +{
519 + v4l2_ctrl_handler_init(&coil->ctrls, 1);
520 +
521 + /*
522 + * V4L2_CID_FOCUS_ABSOLUTE
523 + *
524 + * Minimum current is 0 mA, maximum is 120 mA. Thus, 1 code is
525 + * equivalent to 120/1023 = 0.1173 mA. Nevertheless, we do not use [mA]
526 + * for focus position, because it is meaningless for user. Meaningful
527 + * would be to use focus distance or even its inverse, but since the
528 + * driver doesn't have sufficient knowledge to do the conversion, we
529 + * will just use abstract codes here. In any case, smaller value = focus
530 + * position farther from camera. The default zero value means focus at
531 + * infinity, and also least current consumption.
532 + */
533 + v4l2_ctrl_new_std(&coil->ctrls, &ad5398_ctrl_ops,
534 + V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0);
535 +
536 + if (coil->ctrls.error)
537 + return coil->ctrls.error;
538 +
539 + coil->focus_absolute = 0;
540 +
541 + coil->subdev.ctrl_handler = &coil->ctrls;
542 +
543 + return 0;
544 +}
545 +
546 +/*
547 + * V4L2 subdev operations
548 + */
549 +static int ad5398_registered(struct v4l2_subdev *subdev)
550 +{
551 + struct ad5398_device *coil = to_ad5398_device(subdev);
552 +
553 + return ad5398_init_controls(coil);
554 +}
555 +
556 +static int
557 +ad5398_set_power(struct v4l2_subdev *subdev, int on)
558 +{
559 + struct ad5398_device *coil = to_ad5398_device(subdev);
560 + int ret;
561 +
562 + if (on)
563 + ret = regulator_enable(coil->vana);
564 + else
565 + ret = regulator_disable(coil->vana);
566 +
567 + return ret;
568 +}
569 +
570 +static int ad5398_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
571 +{
572 + struct ad5398_device *coil = to_ad5398_device(sd);
573 +
574 + return regulator_enable(coil->vana);
575 +}
576 +
577 +static int ad5398_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
578 +{
579 + struct ad5398_device *coil = to_ad5398_device(sd);
580 +
581 + return regulator_disable(coil->vana);
582 +}
583 +
584 +static const struct v4l2_subdev_core_ops ad5398_core_ops = {
585 + .s_power = ad5398_set_power,
586 +};
587 +
588 +static const struct v4l2_subdev_ops ad5398_ops = {
589 + .core = &ad5398_core_ops,
590 +};
591 +
592 +static const struct v4l2_subdev_internal_ops ad5398_internal_ops = {
593 + .registered = ad5398_registered,
594 + .open = ad5398_open,
595 + .close = ad5398_close,
596 +};
597 +
598 +/*
599 + * I2C driver
600 + */
601 +static int __maybe_unused ad5398_suspend(struct device *dev)
602 +{
603 + struct i2c_client *client = container_of(dev, struct i2c_client, dev);
604 + struct v4l2_subdev *subdev = i2c_get_clientdata(client);
605 + struct ad5398_device *coil = to_ad5398_device(subdev);
606 +
607 + return regulator_enable(coil->vana);
608 +}
609 +
610 +static int __maybe_unused ad5398_resume(struct device *dev)
611 +{
612 + struct i2c_client *client = container_of(dev, struct i2c_client, dev);
613 + struct v4l2_subdev *subdev = i2c_get_clientdata(client);
614 + struct ad5398_device *coil = to_ad5398_device(subdev);
615 +
616 + return regulator_disable(coil->vana);
617 +}
618 +
619 +static int ad5398_regulator_notifier(struct notifier_block *nb,
620 + unsigned long event,
621 + void *ignored)
622 +{
623 + struct ad5398_device *coil = container_of(nb, struct ad5398_device, nb);
624 +
625 + if (event == REGULATOR_EVENT_ENABLE)
626 + ad5398_power_on(coil);
627 + else if (event == REGULATOR_EVENT_PRE_DISABLE)
628 + ad5398_power_off(coil);
629 +
630 + return NOTIFY_OK;
631 +}
632 +
633 +static int ad5398_probe(struct i2c_client *client,
634 + const struct i2c_device_id *devid)
635 +{
636 + struct ad5398_device *coil;
637 + int ret;
638 +
639 + coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL);
640 + if (!coil)
641 + return -ENOMEM;
642 +
643 + coil->vana = devm_regulator_get(&client->dev, "VANA");
644 + if (IS_ERR(coil->vana)) {
645 + ret = PTR_ERR(coil->vana);
646 + if (ret != -EPROBE_DEFER)
647 + dev_err(&client->dev, "could not get regulator for vana\n");
648 + return ret;
649 + }
650 +
651 + v4l2_i2c_subdev_init(&coil->subdev, client, &ad5398_ops);
652 + coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
653 + coil->subdev.internal_ops = &ad5398_internal_ops;
654 + coil->subdev.entity.function = MEDIA_ENT_F_LENS;
655 + strscpy(coil->subdev.name, "ad5398 focus", sizeof(coil->subdev.name));
656 +
657 + coil->nb.notifier_call = &ad5398_regulator_notifier;
658 + ret = regulator_register_notifier(coil->vana, &coil->nb);
659 + if (ret < 0)
660 + return ret;
661 +
662 + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL);
663 + if (ret < 0)
664 + goto cleanup2;
665 +
666 + ret = v4l2_async_register_subdev(&coil->subdev);
667 + if (ret < 0)
668 + goto cleanup;
669 +
670 + return ret;
671 +
672 +cleanup:
673 + media_entity_cleanup(&coil->subdev.entity);
674 +cleanup2:
675 + regulator_unregister_notifier(coil->vana, &coil->nb);
676 + return ret;
677 +}
678 +
679 +static int ad5398_remove(struct i2c_client *client)
680 +{
681 + struct v4l2_subdev *subdev = i2c_get_clientdata(client);
682 + struct ad5398_device *coil = to_ad5398_device(subdev);
683 +
684 + v4l2_async_unregister_subdev(&coil->subdev);
685 + v4l2_ctrl_handler_free(&coil->ctrls);
686 + media_entity_cleanup(&coil->subdev.entity);
687 + return 0;
688 +}
689 +
690 +static const struct i2c_device_id ad5398_id_table[] = {
691 + { "ad5398", 0 },
692 + { }
693 +};
694 +MODULE_DEVICE_TABLE(i2c, ad5398_id_table);
695 +
696 +static const struct of_device_id ad5398_of_table[] = {
697 + { .compatible = "adi,ad5398" },
698 + { }
699 +};
700 +MODULE_DEVICE_TABLE(of, ad5398_of_table);
701 +
702 +static SIMPLE_DEV_PM_OPS(ad5398_pm, ad5398_suspend, ad5398_resume);
703 +
704 +static struct i2c_driver ad5398_i2c_driver = {
705 + .driver = {
706 + .name = "ad5398",
707 + .pm = &ad5398_pm,
708 + .of_match_table = ad5398_of_table,
709 + },
710 + .probe = ad5398_probe,
711 + .remove = ad5398_remove,
712 + .id_table = ad5398_id_table,
713 +};
714 +
715 +module_i2c_driver(ad5398_i2c_driver);
716 +
717 +MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.com>");
718 +MODULE_DESCRIPTION("AD5398 camera lens driver");
719 +MODULE_LICENSE("GPL");