hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/media/radio/si470x/radio-si470x-i2c.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * drivers/media/radio/si470x/radio-si470x-i2c.c
34 *
....@@ -5,16 +6,6 @@
56 *
67 * Copyright (c) 2009 Samsung Electronics Co.Ltd
78 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- * GNU General Public License for more details.
189 */
1910
2011
....@@ -28,6 +19,7 @@
2819 #include <linux/i2c.h>
2920 #include <linux/slab.h>
3021 #include <linux/delay.h>
22
+#include <linux/gpio/consumer.h>
3123 #include <linux/interrupt.h>
3224
3325 #include "radio-si470x.h"
....@@ -229,12 +221,8 @@
229221 static int si470x_vidioc_querycap(struct file *file, void *priv,
230222 struct v4l2_capability *capability)
231223 {
232
- strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
233
- strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
234
- capability->device_caps = V4L2_CAP_HW_FREQ_SEEK | V4L2_CAP_READWRITE |
235
- V4L2_CAP_TUNER | V4L2_CAP_RADIO | V4L2_CAP_RDS_CAPTURE;
236
- capability->capabilities = capability->device_caps | V4L2_CAP_DEVICE_CAPS;
237
-
224
+ strscpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
225
+ strscpy(capability->card, DRIVER_CARD, sizeof(capability->card));
238226 return 0;
239227 }
240228
....@@ -342,15 +330,14 @@
342330 /*
343331 * si470x_i2c_probe - probe for the device
344332 */
345
-static int si470x_i2c_probe(struct i2c_client *client,
346
- const struct i2c_device_id *id)
333
+static int si470x_i2c_probe(struct i2c_client *client)
347334 {
348335 struct si470x_device *radio;
349336 int retval = 0;
350337 unsigned char version_warning = 0;
351338
352339 /* private data allocation and initialization */
353
- radio = kzalloc(sizeof(struct si470x_device), GFP_KERNEL);
340
+ radio = devm_kzalloc(&client->dev, sizeof(*radio), GFP_KERNEL);
354341 if (!radio) {
355342 retval = -ENOMEM;
356343 goto err_initial;
....@@ -370,7 +357,7 @@
370357 retval = v4l2_device_register(&client->dev, &radio->v4l2_dev);
371358 if (retval < 0) {
372359 dev_err(&client->dev, "couldn't register v4l2_device\n");
373
- goto err_radio;
360
+ goto err_initial;
374361 }
375362
376363 v4l2_ctrl_handler_init(&radio->hdl, 2);
....@@ -390,20 +377,34 @@
390377 radio->videodev.lock = &radio->lock;
391378 radio->videodev.v4l2_dev = &radio->v4l2_dev;
392379 radio->videodev.release = video_device_release_empty;
380
+ radio->videodev.device_caps =
381
+ V4L2_CAP_HW_FREQ_SEEK | V4L2_CAP_READWRITE | V4L2_CAP_TUNER |
382
+ V4L2_CAP_RADIO | V4L2_CAP_RDS_CAPTURE;
393383 video_set_drvdata(&radio->videodev, radio);
384
+
385
+ radio->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset",
386
+ GPIOD_OUT_LOW);
387
+ if (IS_ERR(radio->gpio_reset)) {
388
+ retval = PTR_ERR(radio->gpio_reset);
389
+ dev_err(&client->dev, "Failed to request gpio: %d\n", retval);
390
+ goto err_all;
391
+ }
392
+
393
+ if (radio->gpio_reset)
394
+ gpiod_set_value(radio->gpio_reset, 1);
394395
395396 /* power up : need 110ms */
396397 radio->registers[POWERCFG] = POWERCFG_ENABLE;
397398 if (si470x_set_register(radio, POWERCFG) < 0) {
398399 retval = -EIO;
399
- goto err_ctrl;
400
+ goto err_all;
400401 }
401402 msleep(110);
402403
403404 /* get device and chip versions */
404405 if (si470x_get_all_registers(radio) < 0) {
405406 retval = -EIO;
406
- goto err_ctrl;
407
+ goto err_all;
407408 }
408409 dev_info(&client->dev, "DeviceID=0x%4.4hx ChipID=0x%4.4hx\n",
409410 radio->registers[DEVICEID], radio->registers[SI_CHIPID]);
....@@ -430,10 +431,10 @@
430431
431432 /* rds buffer allocation */
432433 radio->buf_size = rds_buf * 3;
433
- radio->buffer = kmalloc(radio->buf_size, GFP_KERNEL);
434
+ radio->buffer = devm_kmalloc(&client->dev, radio->buf_size, GFP_KERNEL);
434435 if (!radio->buffer) {
435436 retval = -EIO;
436
- goto err_ctrl;
437
+ goto err_all;
437438 }
438439
439440 /* rds buffer configuration */
....@@ -441,12 +442,13 @@
441442 radio->rd_index = 0;
442443 init_waitqueue_head(&radio->read_queue);
443444
444
- retval = request_threaded_irq(client->irq, NULL, si470x_i2c_interrupt,
445
- IRQF_TRIGGER_FALLING | IRQF_ONESHOT, DRIVER_NAME,
446
- radio);
445
+ retval = devm_request_threaded_irq(&client->dev, client->irq, NULL,
446
+ si470x_i2c_interrupt,
447
+ IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
448
+ DRIVER_NAME, radio);
447449 if (retval) {
448450 dev_err(&client->dev, "Failed to register interrupt\n");
449
- goto err_rds;
451
+ goto err_all;
450452 }
451453
452454 /* register video device */
....@@ -460,14 +462,8 @@
460462
461463 return 0;
462464 err_all:
463
- free_irq(client->irq, radio);
464
-err_rds:
465
- kfree(radio->buffer);
466
-err_ctrl:
467465 v4l2_ctrl_handler_free(&radio->hdl);
468466 v4l2_device_unregister(&radio->v4l2_dev);
469
-err_radio:
470
- kfree(radio);
471467 err_initial:
472468 return retval;
473469 }
....@@ -480,12 +476,13 @@
480476 {
481477 struct si470x_device *radio = i2c_get_clientdata(client);
482478
483
- free_irq(client->irq, radio);
484479 video_unregister_device(&radio->videodev);
480
+
481
+ if (radio->gpio_reset)
482
+ gpiod_set_value(radio->gpio_reset, 0);
485483
486484 v4l2_ctrl_handler_free(&radio->hdl);
487485 v4l2_device_unregister(&radio->v4l2_dev);
488
- kfree(radio);
489486 return 0;
490487 }
491488
....@@ -528,6 +525,13 @@
528525 static SIMPLE_DEV_PM_OPS(si470x_i2c_pm, si470x_i2c_suspend, si470x_i2c_resume);
529526 #endif
530527
528
+#if IS_ENABLED(CONFIG_OF)
529
+static const struct of_device_id si470x_of_match[] = {
530
+ { .compatible = "silabs,si470x" },
531
+ { },
532
+};
533
+MODULE_DEVICE_TABLE(of, si470x_of_match);
534
+#endif
531535
532536 /*
533537 * si470x_i2c_driver - i2c driver interface
....@@ -535,11 +539,12 @@
535539 static struct i2c_driver si470x_i2c_driver = {
536540 .driver = {
537541 .name = "si470x",
542
+ .of_match_table = of_match_ptr(si470x_of_match),
538543 #ifdef CONFIG_PM_SLEEP
539544 .pm = &si470x_i2c_pm,
540545 #endif
541546 },
542
- .probe = si470x_i2c_probe,
547
+ .probe_new = si470x_i2c_probe,
543548 .remove = si470x_i2c_remove,
544549 .id_table = si470x_i2c_id,
545550 };