forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/iio/adc/rcar-gyroadc.c
....@@ -1,17 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Renesas R-Car GyroADC driver
34 *
45 * Copyright 2016 Marek Vasut <marek.vasut@gmail.com>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
156 */
167
178 #include <linux/module.h>
....@@ -343,8 +334,8 @@
343334 for_each_child_of_node(np, child) {
344335 of_id = of_match_node(rcar_gyroadc_child_match, child);
345336 if (!of_id) {
346
- dev_err(dev, "Ignoring unsupported ADC \"%s\".",
347
- child->name);
337
+ dev_err(dev, "Ignoring unsupported ADC \"%pOFn\".",
338
+ child);
348339 continue;
349340 }
350341
....@@ -366,7 +357,7 @@
366357 num_channels = ARRAY_SIZE(rcar_gyroadc_iio_channels_3);
367358 break;
368359 default:
369
- return -EINVAL;
360
+ goto err_e_inval;
370361 }
371362
372363 /*
....@@ -381,17 +372,17 @@
381372 ret = of_property_read_u32(child, "reg", &reg);
382373 if (ret) {
383374 dev_err(dev,
384
- "Failed to get child reg property of ADC \"%s\".\n",
385
- child->name);
386
- return ret;
375
+ "Failed to get child reg property of ADC \"%pOFn\".\n",
376
+ child);
377
+ goto err_of_node_put;
387378 }
388379
389380 /* Channel number is too high. */
390381 if (reg >= num_channels) {
391382 dev_err(dev,
392
- "Only %i channels supported with %s, but reg = <%i>.\n",
393
- num_channels, child->name, reg);
394
- return -EINVAL;
383
+ "Only %i channels supported with %pOFn, but reg = <%i>.\n",
384
+ num_channels, child, reg);
385
+ goto err_e_inval;
395386 }
396387 }
397388
....@@ -400,7 +391,7 @@
400391 dev_err(dev,
401392 "Channel %i uses different ADC mode than the rest.\n",
402393 reg);
403
- return -EINVAL;
394
+ goto err_e_inval;
404395 }
405396
406397 /* Channel is valid, grab the regulator. */
....@@ -410,7 +401,8 @@
410401 if (IS_ERR(vref)) {
411402 dev_dbg(dev, "Channel %i 'vref' supply not connected.\n",
412403 reg);
413
- return PTR_ERR(vref);
404
+ ret = PTR_ERR(vref);
405
+ goto err_of_node_put;
414406 }
415407
416408 priv->vref[reg] = vref;
....@@ -434,8 +426,10 @@
434426 * attached to the GyroADC at a time, so if we found it,
435427 * we can stop parsing here.
436428 */
437
- if (childmode == RCAR_GYROADC_MODE_SELECT_1_MB88101A)
429
+ if (childmode == RCAR_GYROADC_MODE_SELECT_1_MB88101A) {
430
+ of_node_put(child);
438431 break;
432
+ }
439433 }
440434
441435 if (first) {
....@@ -444,6 +438,12 @@
444438 }
445439
446440 return 0;
441
+
442
+err_e_inval:
443
+ ret = -EINVAL;
444
+err_of_node_put:
445
+ of_node_put(child);
446
+ return ret;
447447 }
448448
449449 static void rcar_gyroadc_deinit_supplies(struct iio_dev *indio_dev)
....@@ -490,30 +490,23 @@
490490 struct device *dev = &pdev->dev;
491491 struct rcar_gyroadc *priv;
492492 struct iio_dev *indio_dev;
493
- struct resource *mem;
494493 int ret;
495494
496495 indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
497
- if (!indio_dev) {
498
- dev_err(dev, "Failed to allocate IIO device.\n");
496
+ if (!indio_dev)
499497 return -ENOMEM;
500
- }
501498
502499 priv = iio_priv(indio_dev);
503500 priv->dev = dev;
504501
505
- mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
506
- priv->regs = devm_ioremap_resource(dev, mem);
502
+ priv->regs = devm_platform_ioremap_resource(pdev, 0);
507503 if (IS_ERR(priv->regs))
508504 return PTR_ERR(priv->regs);
509505
510506 priv->clk = devm_clk_get(dev, "fck");
511
- if (IS_ERR(priv->clk)) {
512
- ret = PTR_ERR(priv->clk);
513
- if (ret != -EPROBE_DEFER)
514
- dev_err(dev, "Failed to get IF clock (ret=%i)\n", ret);
515
- return ret;
516
- }
507
+ if (IS_ERR(priv->clk))
508
+ return dev_err_probe(dev, PTR_ERR(priv->clk),
509
+ "Failed to get IF clock\n");
517510
518511 ret = rcar_gyroadc_parse_subdevs(indio_dev);
519512 if (ret)
....@@ -529,8 +522,6 @@
529522 platform_set_drvdata(pdev, indio_dev);
530523
531524 indio_dev->name = DRIVER_NAME;
532
- indio_dev->dev.parent = dev;
533
- indio_dev->dev.of_node = pdev->dev.of_node;
534525 indio_dev->info = &rcar_gyroadc_iio_info;
535526 indio_dev->modes = INDIO_DIRECT_MODE;
536527