summaryrefslogtreecommitdiffstats
path: root/target/linux/bcm27xx/patches-6.6/950-0357-media-i2c-Rename-ad5398-to-ad5398_vcm.patch
blob: fa5cb51bb0f97888cb843013f94be9392f8dfbad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
From dc49fe193be8eaf6d406052b904f3c8caae35bae Mon Sep 17 00:00:00 2001
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
Date: Thu, 17 Mar 2022 15:13:10 +0000
Subject: [PATCH 0357/1085] media: i2c: Rename ad5398 to ad5398_vcm

There's already a regulator module called ad5398 that exposes
this device through the regulator API. That is meaningless in
the terms that it uses and how it maps to V4L2, so a new driver
was added. However the module name collision wasn't noted, so
rename it now.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
 drivers/media/i2c/Makefile                   | 2 +-
 drivers/media/i2c/{ad5398.c => ad5398_vcm.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename drivers/media/i2c/{ad5398.c => ad5398_vcm.c} (100%)

--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -3,7 +3,7 @@
 msp3400-objs	:=	msp3400-driver.o msp3400-kthreads.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
-obj-$(CONFIG_VIDEO_AD5398)  += ad5398.o
+obj-$(CONFIG_VIDEO_AD5398) += ad5398_vcm.o
 obj-$(CONFIG_VIDEO_AD5820) += ad5820.o
 obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o
 obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
--- a/drivers/media/i2c/ad5398.c
+++ /dev/null
@@ -1,341 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * AD5398 DAC driver for camera voice coil focus.
- * Copyright (C) 2021 Raspberry Pi (Trading) Ltd.
- *
- * Based on AD5820 DAC driver by Nokia and TI.
- *
- * This driver uses the regulator framework notification hooks on the
- * assumption that the VCM and sensor share a regulator. This means the VCM
- * position will be restored when either the sensor or VCM subdevices are opened
- * or powered up. The client can therefore choose to ignore the VCM subdevice,
- * and the lens position will be as previously requested. Without that, there
- * is a hard requirement to have the VCM subdevice open in order for the VCM
- * to be powered and at the requested position.
- */
-
-#include <linux/errno.h>
-#include <linux/i2c.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/regulator/consumer.h>
-#include <linux/gpio/consumer.h>
-
-#include <media/v4l2-ctrls.h>
-#include <media/v4l2-device.h>
-#include <media/v4l2-subdev.h>
-
-/* Register definitions */
-#define AD5398_POWER_DOWN		BIT(15)
-#define AD5398_DAC_SHIFT		4
-
-#define to_ad5398_device(sd)	container_of(sd, struct ad5398_device, subdev)
-
-struct ad5398_device {
-	struct v4l2_subdev subdev;
-	struct ad5398_platform_data *platform_data;
-	struct regulator *vana;
-	struct notifier_block nb;
-
-	struct v4l2_ctrl_handler ctrls;
-	u32 focus_absolute;
-
-	bool standby;
-};
-
-static int ad5398_write(struct ad5398_device *coil, u16 data)
-{
-	struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev);
-	struct i2c_msg msg;
-	__be16 be_data;
-	int r;
-
-	if (!client->adapter)
-		return -ENODEV;
-
-	be_data = cpu_to_be16(data);
-	msg.addr  = client->addr;
-	msg.flags = 0;
-	msg.len   = 2;
-	msg.buf   = (u8 *)&be_data;
-
-	r = i2c_transfer(client->adapter, &msg, 1);
-	if (r < 0) {
-		dev_err(&client->dev, "write failed, error %d\n", r);
-		return r;
-	}
-
-	return 0;
-}
-
-/*
- * Calculate status word and write it to the device based on current
- * values of V4L2 controls. It is assumed that the stored V4L2 control
- * values are properly limited and rounded.
- */
-static int ad5398_update_hw(struct ad5398_device *coil)
-{
-	u16 status;
-
-	status = coil->focus_absolute << AD5398_DAC_SHIFT;
-
-	if (coil->standby)
-		status |= AD5398_POWER_DOWN;
-
-	return ad5398_write(coil, status);
-}
-
-/*
- * Power handling
- */
-static int ad5398_power_off(struct ad5398_device *coil)
-{
-	int ret = 0;
-
-	coil->standby = true;
-	ret = ad5398_update_hw(coil);
-
-	return ret;
-}
-
-static int ad5398_power_on(struct ad5398_device *coil)
-{
-	int ret;
-
-	/* Restore the hardware settings. */
-	coil->standby = false;
-	ret = ad5398_update_hw(coil);
-	if (ret)
-		goto fail;
-
-	return 0;
-
-fail:
-	coil->standby = true;
-
-	return ret;
-}
-
-/*
- * V4L2 controls
- */
-static int ad5398_set_ctrl(struct v4l2_ctrl *ctrl)
-{
-	struct ad5398_device *coil =
-		container_of(ctrl->handler, struct ad5398_device, ctrls);
-
-	switch (ctrl->id) {
-	case V4L2_CID_FOCUS_ABSOLUTE:
-		coil->focus_absolute = ctrl->val;
-		return ad5398_update_hw(coil);
-	}
-
-	return 0;
-}
-
-static const struct v4l2_ctrl_ops ad5398_ctrl_ops = {
-	.s_ctrl = ad5398_set_ctrl,
-};
-
-static int ad5398_init_controls(struct ad5398_device *coil)
-{
-	v4l2_ctrl_handler_init(&coil->ctrls, 1);
-
-	/*
-	 * V4L2_CID_FOCUS_ABSOLUTE
-	 *
-	 * Minimum current is 0 mA, maximum is 120 mA. Thus, 1 code is
-	 * equivalent to 120/1023 = 0.1173 mA. Nevertheless, we do not use [mA]
-	 * for focus position, because it is meaningless for user. Meaningful
-	 * would be to use focus distance or even its inverse, but since the
-	 * driver doesn't have sufficient knowledge to do the conversion, we
-	 * will just use abstract codes here. In any case, smaller value = focus
-	 * position farther from camera. The default zero value means focus at
-	 * infinity, and also least current consumption.
-	 */
-	v4l2_ctrl_new_std(&coil->ctrls, &ad5398_ctrl_ops,
-			  V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0);
-
-	if (coil->ctrls.error)
-		return coil->ctrls.error;
-
-	coil->focus_absolute = 0;
-
-	coil->subdev.ctrl_handler = &coil->ctrls;
-
-	return 0;
-}
-
-/*
- * V4L2 subdev operations
- */
-static int ad5398_registered(struct v4l2_subdev *subdev)
-{
-	struct ad5398_device *coil = to_ad5398_device(subdev);
-
-	return ad5398_init_controls(coil);
-}
-
-static int
-ad5398_set_power(struct v4l2_subdev *subdev, int on)
-{
-	struct ad5398_device *coil = to_ad5398_device(subdev);
-	int ret;
-
-	if (on)
-		ret = regulator_enable(coil->vana);
-	else
-		ret = regulator_disable(coil->vana);
-
-	return ret;
-}
-
-static int ad5398_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
-{
-	struct ad5398_device *coil = to_ad5398_device(sd);
-
-	return regulator_enable(coil->vana);
-}
-
-static int ad5398_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
-{
-	struct ad5398_device *coil = to_ad5398_device(sd);
-
-	return regulator_disable(coil->vana);
-}
-
-static const struct v4l2_subdev_core_ops ad5398_core_ops = {
-	.s_power = ad5398_set_power,
-};
-
-static const struct v4l2_subdev_ops ad5398_ops = {
-	.core = &ad5398_core_ops,
-};
-
-static const struct v4l2_subdev_internal_ops ad5398_internal_ops = {
-	.registered = ad5398_registered,
-	.open = ad5398_open,
-	.close = ad5398_close,
-};
-
-/*
- * I2C driver
- */
-static int __maybe_unused ad5398_suspend(struct device *dev)
-{
-	struct i2c_client *client = container_of(dev, struct i2c_client, dev);
-	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
-	struct ad5398_device *coil = to_ad5398_device(subdev);
-
-	return regulator_enable(coil->vana);
-}
-
-static int __maybe_unused ad5398_resume(struct device *dev)
-{
-	struct i2c_client *client = container_of(dev, struct i2c_client, dev);
-	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
-	struct ad5398_device *coil = to_ad5398_device(subdev);
-
-	return regulator_disable(coil->vana);
-}
-
-static int ad5398_regulator_notifier(struct notifier_block *nb,
-				     unsigned long event,
-				     void *ignored)
-{
-	struct ad5398_device *coil = container_of(nb, struct ad5398_device, nb);
-
-	if (event == REGULATOR_EVENT_ENABLE)
-		ad5398_power_on(coil);
-	else if (event == REGULATOR_EVENT_PRE_DISABLE)
-		ad5398_power_off(coil);
-
-	return NOTIFY_OK;
-}
-
-static int ad5398_probe(struct i2c_client *client,
-			const struct i2c_device_id *devid)
-{
-	struct ad5398_device *coil;
-	int ret;
-
-	coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL);
-	if (!coil)
-		return -ENOMEM;
-
-	coil->vana = devm_regulator_get(&client->dev, "VANA");
-	if (IS_ERR(coil->vana)) {
-		ret = PTR_ERR(coil->vana);
-		if (ret != -EPROBE_DEFER)
-			dev_err(&client->dev, "could not get regulator for vana\n");
-		return ret;
-	}
-
-	v4l2_i2c_subdev_init(&coil->subdev, client, &ad5398_ops);
-	coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
-	coil->subdev.internal_ops = &ad5398_internal_ops;
-	coil->subdev.entity.function = MEDIA_ENT_F_LENS;
-	strscpy(coil->subdev.name, "ad5398 focus", sizeof(coil->subdev.name));
-
-	coil->nb.notifier_call = &ad5398_regulator_notifier;
-	ret = regulator_register_notifier(coil->vana, &coil->nb);
-	if (ret < 0)
-		return ret;
-
-	ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL);
-	if (ret < 0)
-		goto cleanup2;
-
-	ret = v4l2_async_register_subdev(&coil->subdev);
-	if (ret < 0)
-		goto cleanup;
-
-	return ret;
-
-cleanup:
-	media_entity_cleanup(&coil->subdev.entity);
-cleanup2:
-	regulator_unregister_notifier(coil->vana, &coil->nb);
-	return ret;
-}
-
-static void ad5398_remove(struct i2c_client *client)
-{
-	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
-	struct ad5398_device *coil = to_ad5398_device(subdev);
-
-	v4l2_async_unregister_subdev(&coil->subdev);
-	v4l2_ctrl_handler_free(&coil->ctrls);
-	media_entity_cleanup(&coil->subdev.entity);
-}
-
-static const struct i2c_device_id ad5398_id_table[] = {
-	{ "ad5398", 0 },
-	{ }
-};
-MODULE_DEVICE_TABLE(i2c, ad5398_id_table);
-
-static const struct of_device_id ad5398_of_table[] = {
-	{ .compatible = "adi,ad5398" },
-	{ }
-};
-MODULE_DEVICE_TABLE(of, ad5398_of_table);
-
-static SIMPLE_DEV_PM_OPS(ad5398_pm, ad5398_suspend, ad5398_resume);
-
-static struct i2c_driver ad5398_i2c_driver = {
-	.driver		= {
-		.name	= "ad5398",
-		.pm	= &ad5398_pm,
-		.of_match_table = ad5398_of_table,
-	},
-	.probe		= ad5398_probe,
-	.remove		= ad5398_remove,
-	.id_table	= ad5398_id_table,
-};
-
-module_i2c_driver(ad5398_i2c_driver);
-
-MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.com>");
-MODULE_DESCRIPTION("AD5398 camera lens driver");
-MODULE_LICENSE("GPL");
--- /dev/null
+++ b/drivers/media/i2c/ad5398_vcm.c
@@ -0,0 +1,341 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AD5398 DAC driver for camera voice coil focus.
+ * Copyright (C) 2021 Raspberry Pi (Trading) Ltd.
+ *
+ * Based on AD5820 DAC driver by Nokia and TI.
+ *
+ * This driver uses the regulator framework notification hooks on the
+ * assumption that the VCM and sensor share a regulator. This means the VCM
+ * position will be restored when either the sensor or VCM subdevices are opened
+ * or powered up. The client can therefore choose to ignore the VCM subdevice,
+ * and the lens position will be as previously requested. Without that, there
+ * is a hard requirement to have the VCM subdevice open in order for the VCM
+ * to be powered and at the requested position.
+ */
+
+#include <linux/errno.h>
+#include <linux/i2c.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/regulator/consumer.h>
+#include <linux/gpio/consumer.h>
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-subdev.h>
+
+/* Register definitions */
+#define AD5398_POWER_DOWN		BIT(15)
+#define AD5398_DAC_SHIFT		4
+
+#define to_ad5398_device(sd)	container_of(sd, struct ad5398_device, subdev)
+
+struct ad5398_device {
+	struct v4l2_subdev subdev;
+	struct ad5398_platform_data *platform_data;
+	struct regulator *vana;
+	struct notifier_block nb;
+
+	struct v4l2_ctrl_handler ctrls;
+	u32 focus_absolute;
+
+	bool standby;
+};
+
+static int ad5398_write(struct ad5398_device *coil, u16 data)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev);
+	struct i2c_msg msg;
+	__be16 be_data;
+	int r;
+
+	if (!client->adapter)
+		return -ENODEV;
+
+	be_data = cpu_to_be16(data);
+	msg.addr  = client->addr;
+	msg.flags = 0;
+	msg.len   = 2;
+	msg.buf   = (u8 *)&be_data;
+
+	r = i2c_transfer(client->adapter, &msg, 1);
+	if (r < 0) {
+		dev_err(&client->dev, "write failed, error %d\n", r);
+		return r;
+	}
+
+	return 0;
+}
+
+/*
+ * Calculate status word and write it to the device based on current
+ * values of V4L2 controls. It is assumed that the stored V4L2 control
+ * values are properly limited and rounded.
+ */
+static int ad5398_update_hw(struct ad5398_device *coil)
+{
+	u16 status;
+
+	status = coil->focus_absolute << AD5398_DAC_SHIFT;
+
+	if (coil->standby)
+		status |= AD5398_POWER_DOWN;
+
+	return ad5398_write(coil, status);
+}
+
+/*
+ * Power handling
+ */
+static int ad5398_power_off(struct ad5398_device *coil)
+{
+	int ret = 0;
+
+	coil->standby = true;
+	ret = ad5398_update_hw(coil);
+
+	return ret;
+}
+
+static int ad5398_power_on(struct ad5398_device *coil)
+{
+	int ret;
+
+	/* Restore the hardware settings. */
+	coil->standby = false;
+	ret = ad5398_update_hw(coil);
+	if (ret)
+		goto fail;
+
+	return 0;
+
+fail:
+	coil->standby = true;
+
+	return ret;
+}
+
+/*
+ * V4L2 controls
+ */
+static int ad5398_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct ad5398_device *coil =
+		container_of(ctrl->handler, struct ad5398_device, ctrls);
+
+	switch (ctrl->id) {
+	case V4L2_CID_FOCUS_ABSOLUTE:
+		coil->focus_absolute = ctrl->val;
+		return ad5398_update_hw(coil);
+	}
+
+	return 0;
+}
+
+static const struct v4l2_ctrl_ops ad5398_ctrl_ops = {
+	.s_ctrl = ad5398_set_ctrl,
+};
+
+static int ad5398_init_controls(struct ad5398_device *coil)
+{
+	v4l2_ctrl_handler_init(&coil->ctrls, 1);
+
+	/*
+	 * V4L2_CID_FOCUS_ABSOLUTE
+	 *
+	 * Minimum current is 0 mA, maximum is 120 mA. Thus, 1 code is
+	 * equivalent to 120/1023 = 0.1173 mA. Nevertheless, we do not use [mA]
+	 * for focus position, because it is meaningless for user. Meaningful
+	 * would be to use focus distance or even its inverse, but since the
+	 * driver doesn't have sufficient knowledge to do the conversion, we
+	 * will just use abstract codes here. In any case, smaller value = focus
+	 * position farther from camera. The default zero value means focus at
+	 * infinity, and also least current consumption.
+	 */
+	v4l2_ctrl_new_std(&coil->ctrls, &ad5398_ctrl_ops,
+			  V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0);
+
+	if (coil->ctrls.error)
+		return coil->ctrls.error;
+
+	coil->focus_absolute = 0;
+
+	coil->subdev.ctrl_handler = &coil->ctrls;
+
+	return 0;
+}
+
+/*
+ * V4L2 subdev operations
+ */
+static int ad5398_registered(struct v4l2_subdev *subdev)
+{
+	struct ad5398_device *coil = to_ad5398_device(subdev);
+
+	return ad5398_init_controls(coil);
+}
+
+static int
+ad5398_set_power(struct v4l2_subdev *subdev, int on)
+{
+	struct ad5398_device *coil = to_ad5398_device(subdev);
+	int ret;
+
+	if (on)
+		ret = regulator_enable(coil->vana);
+	else
+		ret = regulator_disable(coil->vana);
+
+	return ret;
+}
+
+static int ad5398_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+	struct ad5398_device *coil = to_ad5398_device(sd);
+
+	return regulator_enable(coil->vana);
+}
+
+static int ad5398_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+	struct ad5398_device *coil = to_ad5398_device(sd);
+
+	return regulator_disable(coil->vana);
+}
+
+static const struct v4l2_subdev_core_ops ad5398_core_ops = {
+	.s_power = ad5398_set_power,
+};
+
+static const struct v4l2_subdev_ops ad5398_ops = {
+	.core = &ad5398_core_ops,
+};
+
+static const struct v4l2_subdev_internal_ops ad5398_internal_ops = {
+	.registered = ad5398_registered,
+	.open = ad5398_open,
+	.close = ad5398_close,
+};
+
+/*
+ * I2C driver
+ */
+static int __maybe_unused ad5398_suspend(struct device *dev)
+{
+	struct i2c_client *client = container_of(dev, struct i2c_client, dev);
+	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+	struct ad5398_device *coil = to_ad5398_device(subdev);
+
+	return regulator_enable(coil->vana);
+}
+
+static int __maybe_unused ad5398_resume(struct device *dev)
+{
+	struct i2c_client *client = container_of(dev, struct i2c_client, dev);
+	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+	struct ad5398_device *coil = to_ad5398_device(subdev);
+
+	return regulator_disable(coil->vana);
+}
+
+static int ad5398_regulator_notifier(struct notifier_block *nb,
+				     unsigned long event,
+				     void *ignored)
+{
+	struct ad5398_device *coil = container_of(nb, struct ad5398_device, nb);
+
+	if (event == REGULATOR_EVENT_ENABLE)
+		ad5398_power_on(coil);
+	else if (event == REGULATOR_EVENT_PRE_DISABLE)
+		ad5398_power_off(coil);
+
+	return NOTIFY_OK;
+}
+
+static int ad5398_probe(struct i2c_client *client,
+			const struct i2c_device_id *devid)
+{
+	struct ad5398_device *coil;
+	int ret;
+
+	coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL);
+	if (!coil)
+		return -ENOMEM;
+
+	coil->vana = devm_regulator_get(&client->dev, "VANA");
+	if (IS_ERR(coil->vana)) {
+		ret = PTR_ERR(coil->vana);
+		if (ret != -EPROBE_DEFER)
+			dev_err(&client->dev, "could not get regulator for vana\n");
+		return ret;
+	}
+
+	v4l2_i2c_subdev_init(&coil->subdev, client, &ad5398_ops);
+	coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	coil->subdev.internal_ops = &ad5398_internal_ops;
+	coil->subdev.entity.function = MEDIA_ENT_F_LENS;
+	strscpy(coil->subdev.name, "ad5398 focus", sizeof(coil->subdev.name));
+
+	coil->nb.notifier_call = &ad5398_regulator_notifier;
+	ret = regulator_register_notifier(coil->vana, &coil->nb);
+	if (ret < 0)
+		return ret;
+
+	ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL);
+	if (ret < 0)
+		goto cleanup2;
+
+	ret = v4l2_async_register_subdev(&coil->subdev);
+	if (ret < 0)
+		goto cleanup;
+
+	return ret;
+
+cleanup:
+	media_entity_cleanup(&coil->subdev.entity);
+cleanup2:
+	regulator_unregister_notifier(coil->vana, &coil->nb);
+	return ret;
+}
+
+static void ad5398_remove(struct i2c_client *client)
+{
+	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+	struct ad5398_device *coil = to_ad5398_device(subdev);
+
+	v4l2_async_unregister_subdev(&coil->subdev);
+	v4l2_ctrl_handler_free(&coil->ctrls);
+	media_entity_cleanup(&coil->subdev.entity);
+}
+
+static const struct i2c_device_id ad5398_id_table[] = {
+	{ "ad5398", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, ad5398_id_table);
+
+static const struct of_device_id ad5398_of_table[] = {
+	{ .compatible = "adi,ad5398" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ad5398_of_table);
+
+static SIMPLE_DEV_PM_OPS(ad5398_pm, ad5398_suspend, ad5398_resume);
+
+static struct i2c_driver ad5398_i2c_driver = {
+	.driver		= {
+		.name	= "ad5398",
+		.pm	= &ad5398_pm,
+		.of_match_table = ad5398_of_table,
+	},
+	.probe		= ad5398_probe,
+	.remove		= ad5398_remove,
+	.id_table	= ad5398_id_table,
+};
+
+module_i2c_driver(ad5398_i2c_driver);
+
+MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.com>");
+MODULE_DESCRIPTION("AD5398 camera lens driver");
+MODULE_LICENSE("GPL");