.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * LED Flash class interface |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2015 Samsung Electronics Co., Ltd. |
---|
5 | 6 | * Author: Jacek Anaszewski <j.anaszewski@samsung.com> |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License version 2 as |
---|
9 | | - * published by the Free Software Foundation. |
---|
10 | 7 | */ |
---|
11 | 8 | |
---|
12 | 9 | #include <linux/device.h> |
---|
.. | .. |
---|
285 | 282 | led_cdev->groups = flash_groups; |
---|
286 | 283 | } |
---|
287 | 284 | |
---|
288 | | -int led_classdev_flash_register(struct device *parent, |
---|
289 | | - struct led_classdev_flash *fled_cdev) |
---|
| 285 | +int led_classdev_flash_register_ext(struct device *parent, |
---|
| 286 | + struct led_classdev_flash *fled_cdev, |
---|
| 287 | + struct led_init_data *init_data) |
---|
290 | 288 | { |
---|
291 | 289 | struct led_classdev *led_cdev; |
---|
292 | 290 | const struct led_flash_ops *ops; |
---|
.. | .. |
---|
312 | 310 | } |
---|
313 | 311 | |
---|
314 | 312 | /* Register led class device */ |
---|
315 | | - ret = led_classdev_register(parent, led_cdev); |
---|
| 313 | + ret = led_classdev_register_ext(parent, led_cdev, init_data); |
---|
316 | 314 | if (ret < 0) |
---|
317 | 315 | return ret; |
---|
318 | 316 | |
---|
319 | 317 | return 0; |
---|
320 | 318 | } |
---|
321 | | -EXPORT_SYMBOL_GPL(led_classdev_flash_register); |
---|
| 319 | +EXPORT_SYMBOL_GPL(led_classdev_flash_register_ext); |
---|
322 | 320 | |
---|
323 | 321 | void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) |
---|
324 | 322 | { |
---|
.. | .. |
---|
329 | 327 | } |
---|
330 | 328 | EXPORT_SYMBOL_GPL(led_classdev_flash_unregister); |
---|
331 | 329 | |
---|
| 330 | +static void devm_led_classdev_flash_release(struct device *dev, void *res) |
---|
| 331 | +{ |
---|
| 332 | + led_classdev_flash_unregister(*(struct led_classdev_flash **)res); |
---|
| 333 | +} |
---|
| 334 | + |
---|
| 335 | +int devm_led_classdev_flash_register_ext(struct device *parent, |
---|
| 336 | + struct led_classdev_flash *fled_cdev, |
---|
| 337 | + struct led_init_data *init_data) |
---|
| 338 | +{ |
---|
| 339 | + struct led_classdev_flash **dr; |
---|
| 340 | + int ret; |
---|
| 341 | + |
---|
| 342 | + dr = devres_alloc(devm_led_classdev_flash_release, sizeof(*dr), |
---|
| 343 | + GFP_KERNEL); |
---|
| 344 | + if (!dr) |
---|
| 345 | + return -ENOMEM; |
---|
| 346 | + |
---|
| 347 | + ret = led_classdev_flash_register_ext(parent, fled_cdev, init_data); |
---|
| 348 | + if (ret) { |
---|
| 349 | + devres_free(dr); |
---|
| 350 | + return ret; |
---|
| 351 | + } |
---|
| 352 | + |
---|
| 353 | + *dr = fled_cdev; |
---|
| 354 | + devres_add(parent, dr); |
---|
| 355 | + |
---|
| 356 | + return 0; |
---|
| 357 | +} |
---|
| 358 | +EXPORT_SYMBOL_GPL(devm_led_classdev_flash_register_ext); |
---|
| 359 | + |
---|
| 360 | +static int devm_led_classdev_flash_match(struct device *dev, |
---|
| 361 | + void *res, void *data) |
---|
| 362 | +{ |
---|
| 363 | + struct led_classdev_flash **p = res; |
---|
| 364 | + |
---|
| 365 | + if (WARN_ON(!p || !*p)) |
---|
| 366 | + return 0; |
---|
| 367 | + |
---|
| 368 | + return *p == data; |
---|
| 369 | +} |
---|
| 370 | + |
---|
| 371 | +void devm_led_classdev_flash_unregister(struct device *dev, |
---|
| 372 | + struct led_classdev_flash *fled_cdev) |
---|
| 373 | +{ |
---|
| 374 | + WARN_ON(devres_release(dev, |
---|
| 375 | + devm_led_classdev_flash_release, |
---|
| 376 | + devm_led_classdev_flash_match, fled_cdev)); |
---|
| 377 | +} |
---|
| 378 | +EXPORT_SYMBOL_GPL(devm_led_classdev_flash_unregister); |
---|
| 379 | + |
---|
332 | 380 | static void led_clamp_align(struct led_flash_setting *s) |
---|
333 | 381 | { |
---|
334 | 382 | u32 v, offset; |
---|