| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * LED driver for Mediatek MT6323 PMIC |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2017 Sean Wang <sean.wang@mediatek.com> |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or |
|---|
| 7 | | - * modify it under the terms of the GNU General Public License as |
|---|
| 8 | | - * published by the Free Software Foundation; either version 2 of |
|---|
| 9 | | - * the License, or (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. |
|---|
| 15 | 6 | */ |
|---|
| 16 | 7 | #include <linux/kernel.h> |
|---|
| 17 | 8 | #include <linux/leds.h> |
|---|
| .. | .. |
|---|
| 258 | 249 | int ret; |
|---|
| 259 | 250 | |
|---|
| 260 | 251 | /* |
|---|
| 261 | | - * Units are in ms, if over the hardware able |
|---|
| 262 | | - * to support, fallback into software blink |
|---|
| 263 | | - */ |
|---|
| 264 | | - period = *delay_on + *delay_off; |
|---|
| 265 | | - |
|---|
| 266 | | - if (period > MT6323_MAX_PERIOD) |
|---|
| 267 | | - return -EINVAL; |
|---|
| 268 | | - |
|---|
| 269 | | - /* |
|---|
| 270 | 252 | * LED subsystem requires a default user |
|---|
| 271 | 253 | * friendly blink pattern for the LED so using |
|---|
| 272 | 254 | * 1Hz duty cycle 50% here if without specific |
|---|
| .. | .. |
|---|
| 276 | 258 | *delay_on = 500; |
|---|
| 277 | 259 | *delay_off = 500; |
|---|
| 278 | 260 | } |
|---|
| 261 | + |
|---|
| 262 | + /* |
|---|
| 263 | + * Units are in ms, if over the hardware able |
|---|
| 264 | + * to support, fallback into software blink |
|---|
| 265 | + */ |
|---|
| 266 | + period = *delay_on + *delay_off; |
|---|
| 267 | + |
|---|
| 268 | + if (period > MT6323_MAX_PERIOD) |
|---|
| 269 | + return -EINVAL; |
|---|
| 279 | 270 | |
|---|
| 280 | 271 | /* |
|---|
| 281 | 272 | * Calculate duty_hw based on the percentage of period during |
|---|
| .. | .. |
|---|
| 351 | 342 | const char *state; |
|---|
| 352 | 343 | int ret = 0; |
|---|
| 353 | 344 | |
|---|
| 354 | | - led->cdev.name = of_get_property(np, "label", NULL) ? : np->name; |
|---|
| 355 | | - led->cdev.default_trigger = of_get_property(np, |
|---|
| 356 | | - "linux,default-trigger", |
|---|
| 357 | | - NULL); |
|---|
| 358 | | - |
|---|
| 359 | 345 | state = of_get_property(np, "default-state", NULL); |
|---|
| 360 | 346 | if (state) { |
|---|
| 361 | 347 | if (!strcmp(state, "keep")) { |
|---|
| .. | .. |
|---|
| 378 | 364 | static int mt6323_led_probe(struct platform_device *pdev) |
|---|
| 379 | 365 | { |
|---|
| 380 | 366 | struct device *dev = &pdev->dev; |
|---|
| 381 | | - struct device_node *np = pdev->dev.of_node; |
|---|
| 367 | + struct device_node *np = dev_of_node(dev); |
|---|
| 382 | 368 | struct device_node *child; |
|---|
| 383 | | - struct mt6397_chip *hw = dev_get_drvdata(pdev->dev.parent); |
|---|
| 369 | + struct mt6397_chip *hw = dev_get_drvdata(dev->parent); |
|---|
| 384 | 370 | struct mt6323_leds *leds; |
|---|
| 385 | 371 | struct mt6323_led *led; |
|---|
| 386 | 372 | int ret; |
|---|
| .. | .. |
|---|
| 411 | 397 | } |
|---|
| 412 | 398 | |
|---|
| 413 | 399 | for_each_available_child_of_node(np, child) { |
|---|
| 400 | + struct led_init_data init_data = {}; |
|---|
| 401 | + |
|---|
| 414 | 402 | ret = of_property_read_u32(child, "reg", ®); |
|---|
| 415 | 403 | if (ret) { |
|---|
| 416 | 404 | dev_err(dev, "Failed to read led 'reg' property\n"); |
|---|
| .. | .. |
|---|
| 446 | 434 | goto put_child_node; |
|---|
| 447 | 435 | } |
|---|
| 448 | 436 | |
|---|
| 449 | | - ret = devm_led_classdev_register(dev, &leds->led[reg]->cdev); |
|---|
| 437 | + init_data.fwnode = of_fwnode_handle(child); |
|---|
| 438 | + |
|---|
| 439 | + ret = devm_led_classdev_register_ext(dev, &leds->led[reg]->cdev, |
|---|
| 440 | + &init_data); |
|---|
| 450 | 441 | if (ret) { |
|---|
| 451 | | - dev_err(&pdev->dev, "Failed to register LED: %d\n", |
|---|
| 452 | | - ret); |
|---|
| 442 | + dev_err(dev, "Failed to register LED: %d\n", ret); |
|---|
| 453 | 443 | goto put_child_node; |
|---|
| 454 | 444 | } |
|---|
| 455 | | - leds->led[reg]->cdev.dev->of_node = child; |
|---|
| 456 | 445 | } |
|---|
| 457 | 446 | |
|---|
| 458 | 447 | return 0; |
|---|