.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* Copyright (c) 2010, 2011, 2016 The Linux Foundation. All rights reserved. |
---|
2 | | - * |
---|
3 | | - * This program is free software; you can redistribute it and/or modify |
---|
4 | | - * it under the terms of the GNU General Public License version 2 and |
---|
5 | | - * only version 2 as published by the Free Software Foundation. |
---|
6 | | - * |
---|
7 | | - * This program is distributed in the hope that it will be useful, |
---|
8 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
9 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
10 | | - * GNU General Public License for more details. |
---|
11 | 3 | */ |
---|
12 | 4 | #include <linux/leds.h> |
---|
13 | 5 | #include <linux/module.h> |
---|
.. | .. |
---|
95 | 87 | |
---|
96 | 88 | static int pm8058_led_probe(struct platform_device *pdev) |
---|
97 | 89 | { |
---|
| 90 | + struct led_init_data init_data = {}; |
---|
| 91 | + struct device *dev = &pdev->dev; |
---|
98 | 92 | struct pm8058_led *led; |
---|
99 | | - struct device_node *np = pdev->dev.of_node; |
---|
| 93 | + struct device_node *np; |
---|
100 | 94 | int ret; |
---|
101 | 95 | struct regmap *map; |
---|
102 | 96 | const char *state; |
---|
103 | 97 | enum led_brightness maxbright; |
---|
104 | 98 | |
---|
105 | | - led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); |
---|
| 99 | + led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); |
---|
106 | 100 | if (!led) |
---|
107 | 101 | return -ENOMEM; |
---|
108 | 102 | |
---|
109 | | - led->ledtype = (u32)(unsigned long)of_device_get_match_data(&pdev->dev); |
---|
| 103 | + led->ledtype = (u32)(unsigned long)of_device_get_match_data(dev); |
---|
110 | 104 | |
---|
111 | | - map = dev_get_regmap(pdev->dev.parent, NULL); |
---|
| 105 | + map = dev_get_regmap(dev->parent, NULL); |
---|
112 | 106 | if (!map) { |
---|
113 | | - dev_err(&pdev->dev, "Parent regmap unavailable.\n"); |
---|
| 107 | + dev_err(dev, "Parent regmap unavailable.\n"); |
---|
114 | 108 | return -ENXIO; |
---|
115 | 109 | } |
---|
116 | 110 | led->map = map; |
---|
117 | 111 | |
---|
| 112 | + np = dev_of_node(dev); |
---|
| 113 | + |
---|
118 | 114 | ret = of_property_read_u32(np, "reg", &led->reg); |
---|
119 | 115 | if (ret) { |
---|
120 | | - dev_err(&pdev->dev, "no register offset specified\n"); |
---|
| 116 | + dev_err(dev, "no register offset specified\n"); |
---|
121 | 117 | return -EINVAL; |
---|
122 | 118 | } |
---|
123 | 119 | |
---|
124 | | - /* Use label else node name */ |
---|
125 | | - led->cdev.name = of_get_property(np, "label", NULL) ? : np->name; |
---|
126 | | - led->cdev.default_trigger = |
---|
127 | | - of_get_property(np, "linux,default-trigger", NULL); |
---|
128 | 120 | led->cdev.brightness_set = pm8058_led_set; |
---|
129 | 121 | led->cdev.brightness_get = pm8058_led_get; |
---|
130 | 122 | if (led->ledtype == PM8058_LED_TYPE_COMMON) |
---|
.. | .. |
---|
150 | 142 | led->ledtype == PM8058_LED_TYPE_FLASH) |
---|
151 | 143 | led->cdev.flags = LED_CORE_SUSPENDRESUME; |
---|
152 | 144 | |
---|
153 | | - ret = devm_led_classdev_register(&pdev->dev, &led->cdev); |
---|
154 | | - if (ret) { |
---|
155 | | - dev_err(&pdev->dev, "unable to register led \"%s\"\n", |
---|
156 | | - led->cdev.name); |
---|
157 | | - return ret; |
---|
158 | | - } |
---|
| 145 | + init_data.fwnode = of_fwnode_handle(np); |
---|
159 | 146 | |
---|
160 | | - return 0; |
---|
| 147 | + ret = devm_led_classdev_register_ext(dev, &led->cdev, &init_data); |
---|
| 148 | + if (ret) |
---|
| 149 | + dev_err(dev, "Failed to register LED for %pOF\n", np); |
---|
| 150 | + |
---|
| 151 | + return ret; |
---|
161 | 152 | } |
---|
162 | 153 | |
---|
163 | 154 | static const struct of_device_id pm8058_leds_id_table[] = { |
---|