hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/regulator/pwm-regulator.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Regulator driver for PWM Regulators
34 *
45 * Copyright (C) 2014 - STMicroelectronics Inc.
56 *
67 * Author: Lee Jones <lee.jones@linaro.org>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
1310 #include <linux/module.h>
....@@ -39,9 +36,6 @@
3936
4037 /* regulator descriptor */
4138 struct regulator_desc desc;
42
-
43
- /* Regulator ops */
44
- struct regulator_ops ops;
4539
4640 int state;
4741
....@@ -242,7 +236,7 @@
242236 return 0;
243237 }
244238
245
-static struct regulator_ops pwm_regulator_voltage_table_ops = {
239
+static const struct regulator_ops pwm_regulator_voltage_table_ops = {
246240 .set_voltage_sel = pwm_regulator_set_voltage_sel,
247241 .get_voltage_sel = pwm_regulator_get_voltage_sel,
248242 .list_voltage = pwm_regulator_list_voltage,
....@@ -252,7 +246,7 @@
252246 .is_enabled = pwm_regulator_is_enabled,
253247 };
254248
255
-static struct regulator_ops pwm_regulator_voltage_continuous_ops = {
249
+static const struct regulator_ops pwm_regulator_voltage_continuous_ops = {
256250 .get_voltage = pwm_regulator_get_voltage,
257251 .set_voltage = pwm_regulator_set_voltage,
258252 .enable = pwm_regulator_enable,
....@@ -260,7 +254,7 @@
260254 .is_enabled = pwm_regulator_is_enabled,
261255 };
262256
263
-static struct regulator_desc pwm_regulator_desc = {
257
+static const struct regulator_desc pwm_regulator_desc = {
264258 .name = "pwm-regulator",
265259 .type = REGULATOR_VOLTAGE,
266260 .owner = THIS_MODULE,
....@@ -298,9 +292,7 @@
298292
299293 drvdata->state = -ENOTRECOVERABLE;
300294 drvdata->duty_cycle_table = duty_cycle_table;
301
- memcpy(&drvdata->ops, &pwm_regulator_voltage_table_ops,
302
- sizeof(drvdata->ops));
303
- drvdata->desc.ops = &drvdata->ops;
295
+ drvdata->desc.ops = &pwm_regulator_voltage_table_ops;
304296 drvdata->desc.n_voltages = length / sizeof(*duty_cycle_table);
305297
306298 return 0;
....@@ -312,9 +304,7 @@
312304 u32 dutycycle_range[2] = { 0, 100 };
313305 u32 dutycycle_unit = 100;
314306
315
- memcpy(&drvdata->ops, &pwm_regulator_voltage_continuous_ops,
316
- sizeof(drvdata->ops));
317
- drvdata->desc.ops = &drvdata->ops;
307
+ drvdata->desc.ops = &pwm_regulator_voltage_continuous_ops;
318308 drvdata->desc.continuous_voltage_range = true;
319309
320310 of_property_read_u32_array(pdev->dev.of_node,
....@@ -379,7 +369,11 @@
379369 drvdata->pwm = devm_pwm_get(&pdev->dev, NULL);
380370 if (IS_ERR(drvdata->pwm)) {
381371 ret = PTR_ERR(drvdata->pwm);
382
- dev_err(&pdev->dev, "Failed to get PWM: %d\n", ret);
372
+ if (ret == -EPROBE_DEFER)
373
+ dev_dbg(&pdev->dev,
374
+ "Failed to get PWM, deferring probe\n");
375
+ else
376
+ dev_err(&pdev->dev, "Failed to get PWM: %d\n", ret);
383377 return ret;
384378 }
385379
....@@ -411,7 +405,7 @@
411405 return 0;
412406 }
413407
414
-static const struct of_device_id pwm_of_match[] = {
408
+static const struct of_device_id __maybe_unused pwm_of_match[] = {
415409 { .compatible = "pwm-regulator" },
416410 { },
417411 };
....@@ -425,21 +419,7 @@
425419 .probe = pwm_regulator_probe,
426420 };
427421
428
-#ifdef CONFIG_ROCKCHIP_THUNDER_BOOT
429
-static int __init pwm_regulator_driver_init(void)
430
-{
431
- return platform_driver_register(&pwm_regulator_driver);
432
-}
433
-subsys_initcall_sync(pwm_regulator_driver_init);
434
-
435
-static void __exit pwm_regulator_driver_exit(void)
436
-{
437
- platform_driver_unregister(&pwm_regulator_driver);
438
-}
439
-module_exit(pwm_regulator_driver_exit);
440
-#else
441422 module_platform_driver(pwm_regulator_driver);
442
-#endif
443423
444424 MODULE_LICENSE("GPL");
445425 MODULE_AUTHOR("Lee Jones <lee.jones@linaro.org>");