.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Regulator driver for PWM Regulators |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2014 - STMicroelectronics Inc. |
---|
5 | 6 | * |
---|
6 | 7 | * 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. |
---|
11 | 8 | */ |
---|
12 | 9 | |
---|
13 | 10 | #include <linux/module.h> |
---|
.. | .. |
---|
39 | 36 | |
---|
40 | 37 | /* regulator descriptor */ |
---|
41 | 38 | struct regulator_desc desc; |
---|
42 | | - |
---|
43 | | - /* Regulator ops */ |
---|
44 | | - struct regulator_ops ops; |
---|
45 | 39 | |
---|
46 | 40 | int state; |
---|
47 | 41 | |
---|
.. | .. |
---|
242 | 236 | return 0; |
---|
243 | 237 | } |
---|
244 | 238 | |
---|
245 | | -static struct regulator_ops pwm_regulator_voltage_table_ops = { |
---|
| 239 | +static const struct regulator_ops pwm_regulator_voltage_table_ops = { |
---|
246 | 240 | .set_voltage_sel = pwm_regulator_set_voltage_sel, |
---|
247 | 241 | .get_voltage_sel = pwm_regulator_get_voltage_sel, |
---|
248 | 242 | .list_voltage = pwm_regulator_list_voltage, |
---|
.. | .. |
---|
252 | 246 | .is_enabled = pwm_regulator_is_enabled, |
---|
253 | 247 | }; |
---|
254 | 248 | |
---|
255 | | -static struct regulator_ops pwm_regulator_voltage_continuous_ops = { |
---|
| 249 | +static const struct regulator_ops pwm_regulator_voltage_continuous_ops = { |
---|
256 | 250 | .get_voltage = pwm_regulator_get_voltage, |
---|
257 | 251 | .set_voltage = pwm_regulator_set_voltage, |
---|
258 | 252 | .enable = pwm_regulator_enable, |
---|
.. | .. |
---|
260 | 254 | .is_enabled = pwm_regulator_is_enabled, |
---|
261 | 255 | }; |
---|
262 | 256 | |
---|
263 | | -static struct regulator_desc pwm_regulator_desc = { |
---|
| 257 | +static const struct regulator_desc pwm_regulator_desc = { |
---|
264 | 258 | .name = "pwm-regulator", |
---|
265 | 259 | .type = REGULATOR_VOLTAGE, |
---|
266 | 260 | .owner = THIS_MODULE, |
---|
.. | .. |
---|
298 | 292 | |
---|
299 | 293 | drvdata->state = -ENOTRECOVERABLE; |
---|
300 | 294 | 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; |
---|
304 | 296 | drvdata->desc.n_voltages = length / sizeof(*duty_cycle_table); |
---|
305 | 297 | |
---|
306 | 298 | return 0; |
---|
.. | .. |
---|
312 | 304 | u32 dutycycle_range[2] = { 0, 100 }; |
---|
313 | 305 | u32 dutycycle_unit = 100; |
---|
314 | 306 | |
---|
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; |
---|
318 | 308 | drvdata->desc.continuous_voltage_range = true; |
---|
319 | 309 | |
---|
320 | 310 | of_property_read_u32_array(pdev->dev.of_node, |
---|
.. | .. |
---|
379 | 369 | drvdata->pwm = devm_pwm_get(&pdev->dev, NULL); |
---|
380 | 370 | if (IS_ERR(drvdata->pwm)) { |
---|
381 | 371 | 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); |
---|
383 | 377 | return ret; |
---|
384 | 378 | } |
---|
385 | 379 | |
---|
.. | .. |
---|
411 | 405 | return 0; |
---|
412 | 406 | } |
---|
413 | 407 | |
---|
414 | | -static const struct of_device_id pwm_of_match[] = { |
---|
| 408 | +static const struct of_device_id __maybe_unused pwm_of_match[] = { |
---|
415 | 409 | { .compatible = "pwm-regulator" }, |
---|
416 | 410 | { }, |
---|
417 | 411 | }; |
---|
.. | .. |
---|
425 | 419 | .probe = pwm_regulator_probe, |
---|
426 | 420 | }; |
---|
427 | 421 | |
---|
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 |
---|
441 | 422 | module_platform_driver(pwm_regulator_driver); |
---|
442 | | -#endif |
---|
443 | 423 | |
---|
444 | 424 | MODULE_LICENSE("GPL"); |
---|
445 | 425 | MODULE_AUTHOR("Lee Jones <lee.jones@linaro.org>"); |
---|