Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'leds-for-5.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds

Pull LED updates from Jacek Anaszewski:
"In this cycle we've finally managed to contribute the patch set
sorting out LED naming issues. Besides that there are many changes
scattered among various LED class drivers and triggers.

LED naming related improvements:

- add new 'function' and 'color' fwnode properties and deprecate
'label' property which has been frequently abused for conveying
vendor specific names that have been available in sysfs anyway

- introduce a set of standard LED_FUNCTION* definitions

- introduce a set of standard LED_COLOR_ID* definitions

- add a new {devm_}led_classdev_register_ext() API with the
capability of automatic LED name composition basing on the
properties available in the passed fwnode; the function is
backwards compatible in a sense that it uses 'label' data, if
present in the fwnode, for creating LED name

- add tools/leds/get_led_device_info.sh script for retrieving LED
vendor, product and bus names, if applicable; it also performs
basic validation of an LED name

- update following drivers and their DT bindings to use the new LED
registration API:

- leds-an30259a, leds-gpio, leds-as3645a, leds-aat1290, leds-cr0014114,
leds-lm3601x, leds-lm3692x, leds-lp8860, leds-lt3593, leds-sc27xx-blt

Other LED class improvements:

- replace {devm_}led_classdev_register() macros with inlines

- allow to call led_classdev_unregister() unconditionally

- switch to use fwnode instead of be stuck with OF one

LED triggers improvements:

- led-triggers:
- fix dereferencing of null pointer
- fix a memory leak bug

- ledtrig-gpio:
- GPIO 0 is valid

Drop superseeded apu2/3 support from leds-apu since for apu2+ a newer,
more complete driver exists, based on a generic driver for the AMD
SOCs gpio-controller, supporting LEDs as well other devices:

- drop profile field from priv data

- drop iosize field from priv data

- drop enum_apu_led_platform_types

- drop superseeded apu2/3 led support

- add pr_fmt prefix for better log output

- fix error message on probing failure

Other misc fixes and improvements to existing LED class drivers:

- leds-ns2, leds-max77650:
- add of_node_put() before return

- leds-pwm, leds-is31fl32xx:
- use struct_size() helper

- leds-lm3697, leds-lm36274, leds-lm3532:
- switch to use fwnode_property_count_uXX()

- leds-lm3532:
- fix brightness control for i2c mode
- change the define for the fs current register
- fixes for the driver for stability
- add full scale current configuration
- dt: Add property for full scale current.
- avoid potentially unpaired regulator calls
- move static keyword to the front of declarations
- fix optional led-max-microamp prop error handling

- leds-max77650:
- add of_node_put() before return
- add MODULE_ALIAS()
- Switch to fwnode property API

- leds-as3645a:
- fix misuse of strlcpy

- leds-netxbig:
- add of_node_put() in netxbig_leds_get_of_pdata()
- remove legacy board-file support

- leds-is31fl319x:
- simplify getting the adapter of a client

- leds-ti-lmu-common:
- fix coccinelle issue
- move static keyword to the front of declaration

- leds-syscon:
- use resource managed variant of device register

- leds-ktd2692:
- fix a typo in the name of a constant

- leds-lp5562:
- allow firmware files up to the maximum length

- leds-an30259a:
- fix typo

- leds-pca953x:
- include the right header"

* tag 'leds-for-5.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds: (72 commits)
leds: lm3532: Fix optional led-max-microamp prop error handling
led: triggers: Fix dereferencing of null pointer
leds: ti-lmu-common: Move static keyword to the front of declaration
leds: lm3532: Move static keyword to the front of declarations
leds: trigger: gpio: GPIO 0 is valid
leds: pwm: Use struct_size() helper
leds: is31fl32xx: Use struct_size() helper
leds: ti-lmu-common: Fix coccinelle issue in TI LMU
leds: lm3532: Avoid potentially unpaired regulator calls
leds: syscon: Use resource managed variant of device register
leds: Replace {devm_}led_classdev_register() macros with inlines
leds: Allow to call led_classdev_unregister() unconditionally
leds: lm3532: Add full scale current configuration
dt: lm3532: Add property for full scale current.
leds: lm3532: Fixes for the driver for stability
leds: lm3532: Change the define for the fs current register
leds: lm3532: Fix brightness control for i2c mode
leds: Switch to use fwnode instead of be stuck with OF one
leds: max77650: Switch to fwnode property API
led: triggers: Fix a memory leak bug
...

+1482 -997
+14 -8
Documentation/devicetree/bindings/leds/ams,as3645a.txt
··· 39 39 Optional properties of the flash child node 40 40 =========================================== 41 41 42 - label : The label of the flash LED. 42 + function : See Documentation/devicetree/bindings/leds/common.txt. 43 + color : See Documentation/devicetree/bindings/leds/common.txt. 44 + label : See Documentation/devicetree/bindings/leds/common.txt (deprecated). 43 45 44 46 45 47 Required properties of the indicator child node (1) ··· 54 52 Optional properties of the indicator child node 55 53 =============================================== 56 54 57 - label : The label of the indicator LED. 55 + function : See Documentation/devicetree/bindings/leds/common.txt. 56 + color : See Documentation/devicetree/bindings/leds/common.txt. 57 + label : See Documentation/devicetree/bindings/leds/common.txt (deprecated). 58 58 59 59 60 60 Example 61 61 ======= 62 62 63 + #include <dt-bindings/leds/common.h> 64 + 63 65 as3645a@30 { 64 - #address-cells: 1 65 - #size-cells: 0 66 + #address-cells = <1>; 67 + #size-cells = <0>; 66 68 reg = <0x30>; 67 69 compatible = "ams,as3645a"; 68 - flash@0 { 70 + led@0 { 69 71 reg = <0x0>; 70 72 flash-timeout-us = <150000>; 71 73 flash-max-microamp = <320000>; 72 74 led-max-microamp = <60000>; 73 75 ams,input-max-microamp = <1750000>; 74 - label = "as3645a:flash"; 76 + function = LED_FUNCTION_FLASH; 75 77 }; 76 - indicator@1 { 78 + led@1 { 77 79 reg = <0x1>; 78 80 led-max-microamp = <10000>; 79 - label = "as3645a:indicator"; 81 + function = LED_FUNCTION_INDICATOR; 80 82 }; 81 83 };
+54 -8
Documentation/devicetree/bindings/leds/common.txt
··· 10 10 have to be tightly coupled with the LED device binding. They are represented 11 11 by child nodes of the parent LED device binding. 12 12 13 + 13 14 Optional properties for child nodes: 14 15 - led-sources : List of device current outputs the LED is connected to. The 15 16 outputs are identified by the numbers that must be defined 16 17 in the LED device binding documentation. 18 + 19 + - function: LED functon. Use one of the LED_FUNCTION_* prefixed definitions 20 + from the header include/dt-bindings/leds/common.h. 21 + If there is no matching LED_FUNCTION available, add a new one. 22 + 23 + - color : Color of the LED. Use one of the LED_COLOR_ID_* prefixed definitions 24 + from the header include/dt-bindings/leds/common.h. 25 + If there is no matching LED_COLOR_ID available, add a new one. 26 + 27 + - function-enumerator: Integer to be used when more than one instance 28 + of the same function is needed, differing only with 29 + an ordinal number. 30 + 17 31 - label : The label for this LED. If omitted, the label is taken from the node 18 32 name (excluding the unit address). It has to uniquely identify 19 33 a device, i.e. no other LED class device can be assigned the same 20 - label. 34 + label. This property is deprecated - use 'function' and 'color' 35 + properties instead. function-enumerator has no effect when this 36 + property is present. 21 37 22 38 - default-state : The initial state of the LED. Valid values are "on", "off", 23 39 and "keep". If the LED is already on or off and the default-state property is ··· 115 99 116 100 * Examples 117 101 118 - gpio-leds { 102 + #include <dt-bindings/leds/common.h> 103 + 104 + led-controller@0 { 119 105 compatible = "gpio-leds"; 120 106 121 - system-status { 122 - label = "Status"; 107 + led0 { 108 + function = LED_FUNCTION_STATUS; 123 109 linux,default-trigger = "heartbeat"; 124 110 gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>; 125 111 }; 126 112 127 - usb { 113 + led1 { 114 + function = LED_FUNCTION_USB; 128 115 gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>; 129 116 trigger-sources = <&ohci_port1>, <&ehci_port1>; 130 117 }; 131 118 }; 132 119 133 - max77693-led { 120 + led-controller@0 { 134 121 compatible = "maxim,max77693-led"; 135 122 136 - camera-flash { 137 - label = "Flash"; 123 + led { 124 + function = LED_FUNCTION_FLASH; 125 + color = <LED_COLOR_ID_WHITE>; 138 126 led-sources = <0>, <1>; 139 127 led-max-microamp = <50000>; 140 128 flash-max-microamp = <320000>; 141 129 flash-max-timeout-us = <500000>; 142 130 }; 131 + }; 132 + 133 + led-controller@30 { 134 + compatible = "panasonic,an30259a"; 135 + reg = <0x30>; 136 + #address-cells = <1>; 137 + #size-cells = <0>; 138 + 139 + led@1 { 140 + reg = <1>; 141 + linux,default-trigger = "heartbeat"; 142 + function = LED_FUNCTION_INDICATOR; 143 + function-enumerator = <1>; 144 + }; 145 + 146 + led@2 { 147 + reg = <2>; 148 + function = LED_FUNCTION_INDICATOR; 149 + function-enumerator = <2>; 150 + }; 151 + 152 + led@3 { 153 + reg = <3>; 154 + function = LED_FUNCTION_INDICATOR; 155 + function-enumerator = <3>; 156 + }; 143 157 };
+8 -4
Documentation/devicetree/bindings/leds/leds-aat1290.txt
··· 32 32 formula: T = 8.82 * 10^9 * Ct. 33 33 34 34 Optional properties of the LED child node: 35 - - label : see Documentation/devicetree/bindings/leds/common.txt 35 + - function : see Documentation/devicetree/bindings/leds/common.txt 36 + - color : see Documentation/devicetree/bindings/leds/common.txt 37 + - label : see Documentation/devicetree/bindings/leds/common.txt (deprecated) 36 38 37 39 Example (by Ct = 220nF, Rset = 160kohm and exynos4412-trats2 board with 38 40 a switch that allows for routing strobe signal either from the host or from 39 41 the camera sensor): 40 42 41 43 #include "exynos4412.dtsi" 44 + #include <dt-bindings/leds/common.h> 42 45 43 - aat1290 { 46 + led-controller { 44 47 compatible = "skyworks,aat1290"; 45 48 flen-gpios = <&gpj1 1 GPIO_ACTIVE_HIGH>; 46 49 enset-gpios = <&gpj1 2 GPIO_ACTIVE_HIGH>; ··· 53 50 pinctrl-1 = <&camera_flash_host>; 54 51 pinctrl-2 = <&camera_flash_isp>; 55 52 56 - camera_flash: flash-led { 57 - label = "aat1290-flash"; 53 + camera_flash: led { 54 + function = LED_FUNCTION_FLASH; 55 + color = <LED_COLOR_ID_WHITE>; 58 56 led-max-microamp = <520833>; 59 57 flash-max-microamp = <1012500>; 60 58 flash-max-timeout-us = <1940000>;
+17 -5
Documentation/devicetree/bindings/leds/leds-an30259a.txt
··· 15 15 - reg: Pin that the LED is connected to. Must be 1, 2, or 3. 16 16 17 17 Optional sub-node properties: 18 - - label: see Documentation/devicetree/bindings/leds/common.txt 19 - - linux,default-trigger: see Documentation/devicetree/bindings/leds/common.txt 18 + - function : 19 + see Documentation/devicetree/bindings/leds/common.txt 20 + - color : 21 + see Documentation/devicetree/bindings/leds/common.txt 22 + - label : 23 + see Documentation/devicetree/bindings/leds/common.txt (deprecated) 24 + - linux,default-trigger : 25 + see Documentation/devicetree/bindings/leds/common.txt 20 26 21 27 Example: 28 + 29 + #include <dt-bindings/leds/common.h> 30 + 22 31 led-controller@30 { 23 32 compatible = "panasonic,an30259a"; 24 33 reg = <0x30>; ··· 37 28 led@1 { 38 29 reg = <1>; 39 30 linux,default-trigger = "heartbeat"; 40 - label = "red:indicator"; 31 + function = LED_FUNCTION_INDICATOR; 32 + color = <LED_COLOR_ID_RED>; 41 33 }; 42 34 43 35 led@2 { 44 36 reg = <2>; 45 - label = "green:indicator"; 37 + function = LED_FUNCTION_INDICATOR; 38 + color = <LED_COLOR_ID_GREEN>; 46 39 }; 47 40 48 41 led@3 { 49 42 reg = <3>; 50 - label = "blue:indicator"; 43 + function = LED_FUNCTION_INDICATOR; 44 + color = <LED_COLOR_ID_BLUE>; 51 45 }; 52 46 };
+19 -7
Documentation/devicetree/bindings/leds/leds-cr0014114.txt
··· 11 11 apply. In particular, "reg" and "spi-max-frequency" properties must be given. 12 12 13 13 LED sub-node properties: 14 - - label : 14 + - function : 15 15 see Documentation/devicetree/bindings/leds/common.txt 16 + - color : 17 + see Documentation/devicetree/bindings/leds/common.txt 18 + - label : 19 + see Documentation/devicetree/bindings/leds/common.txt (deprecated) 16 20 - linux,default-trigger : (optional) 17 21 see Documentation/devicetree/bindings/leds/common.txt 18 22 19 23 Example 20 24 ------- 25 + 26 + #include <dt-bindings/leds/common.h> 21 27 22 28 led-controller@0 { 23 29 compatible = "crane,cr0014114"; ··· 34 28 35 29 led@0 { 36 30 reg = <0>; 37 - label = "red:coin"; 31 + function = "coin"; 32 + color = <LED_COLOR_ID_RED>; 38 33 }; 39 34 led@1 { 40 35 reg = <1>; 41 - label = "green:coin"; 36 + function = "coin"; 37 + color = <LED_COLOR_ID_GREEN>; 42 38 }; 43 39 led@2 { 44 40 reg = <2>; 45 - label = "blue:coin"; 41 + function = "coin"; 42 + color = <LED_COLOR_ID_BLUE>; 46 43 }; 47 44 led@3 { 48 45 reg = <3>; 49 - label = "red:bill"; 46 + function = "bill"; 47 + color = <LED_COLOR_ID_RED>; 50 48 }; 51 49 led@4 { 52 50 reg = <4>; 53 - label = "green:bill"; 51 + function = "bill"; 52 + color = <LED_COLOR_ID_GREEN>; 54 53 }; 55 54 led@5 { 56 55 reg = <5>; 57 - label = "blue:bill"; 56 + function = "bill"; 57 + color = <LED_COLOR_ID_BLUE>; 58 58 }; 59 59 ... 60 60 };
+16 -7
Documentation/devicetree/bindings/leds/leds-gpio.txt
··· 10 10 - gpios : Should specify the LED's GPIO, see "gpios property" in 11 11 Documentation/devicetree/bindings/gpio/gpio.txt. Active low LEDs should be 12 12 indicated using flags in the GPIO specifier. 13 - - label : (optional) 13 + - function : (optional) 14 14 see Documentation/devicetree/bindings/leds/common.txt 15 + - color : (optional) 16 + see Documentation/devicetree/bindings/leds/common.txt 17 + - label : (optional) 18 + see Documentation/devicetree/bindings/leds/common.txt (deprecated) 15 19 - linux,default-trigger : (optional) 16 20 see Documentation/devicetree/bindings/leds/common.txt 17 21 - default-state: (optional) The initial state of the LED. ··· 31 27 Examples: 32 28 33 29 #include <dt-bindings/gpio/gpio.h> 30 + #include <dt-bindings/leds/common.h> 34 31 35 32 leds { 36 33 compatible = "gpio-leds"; 37 - hdd { 38 - label = "Disk Activity"; 34 + led0 { 39 35 gpios = <&mcu_pio 0 GPIO_ACTIVE_LOW>; 40 36 linux,default-trigger = "disk-activity"; 37 + function = LED_FUNCTION_DISK; 41 38 }; 42 39 43 - fault { 40 + led1 { 44 41 gpios = <&mcu_pio 1 GPIO_ACTIVE_HIGH>; 45 42 /* Keep LED on if BIOS detected hardware fault */ 46 43 default-state = "keep"; 44 + function = LED_FUNCTION_FAULT; 47 45 }; 48 46 }; 49 47 50 48 run-control { 51 49 compatible = "gpio-leds"; 52 - red { 50 + led0 { 53 51 gpios = <&mpc8572 6 GPIO_ACTIVE_HIGH>; 52 + color = <LED_COLOR_ID_RED>; 54 53 default-state = "off"; 55 54 }; 56 - green { 55 + led1 { 57 56 gpios = <&mpc8572 7 GPIO_ACTIVE_HIGH>; 57 + color = <LED_COLOR_ID_GREEN>; 58 58 default-state = "on"; 59 59 }; 60 60 }; ··· 66 58 leds { 67 59 compatible = "gpio-leds"; 68 60 69 - charger-led { 61 + led0 { 70 62 gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; 71 63 linux,default-trigger = "max8903-charger-charging"; 72 64 retain-state-suspended; 65 + function = LED_FUNCTION_CHARGE; 73 66 }; 74 67 };
+4
Documentation/devicetree/bindings/leds/leds-lm3532.txt
··· 62 62 - label : see Documentation/devicetree/bindings/leds/common.txt 63 63 - linux,default-trigger : 64 64 see Documentation/devicetree/bindings/leds/common.txt 65 + - led-max-microamp : Defines the full scale current value for each control 66 + bank. The range is from 5000uA-29800uA in increments 67 + of 800uA. 65 68 66 69 Example: 67 70 led-controller@38 { ··· 88 85 reg = <0>; 89 86 led-sources = <2>; 90 87 ti,led-mode = <1>; 88 + led-max-microamp = <21800>; 91 89 label = ":backlight"; 92 90 linux,default-trigger = "backlight"; 93 91 };
+8 -2
Documentation/devicetree/bindings/leds/leds-lm3601x.txt
··· 22 22 - led-max-microamp : Range from 2.4mA - 376mA 23 23 24 24 Optional child properties: 25 - - label : see Documentation/devicetree/bindings/leds/common.txt 25 + - function : see Documentation/devicetree/bindings/leds/common.txt 26 + - color : see Documentation/devicetree/bindings/leds/common.txt 27 + - label : see Documentation/devicetree/bindings/leds/common.txt (deprecated) 26 28 27 29 Example: 30 + 31 + #include <dt-bindings/leds/common.h> 32 + 28 33 led-controller@64 { 29 34 compatible = "ti,lm36010"; 30 35 #address-cells = <1>; ··· 38 33 39 34 led@0 { 40 35 reg = <1>; 41 - label = "white:torch"; 36 + function = LED_FUNCTION_TORCH; 37 + color = <LED_COLOR_ID_WHITE>; 42 38 led-max-microamp = <376000>; 43 39 flash-max-microamp = <1500000>; 44 40 flash-max-timeout-us = <1600000>;
+7 -2
Documentation/devicetree/bindings/leds/leds-lm3692x.txt
··· 26 26 3 - Will enable the LED3 sync (LM36923 only) 27 27 28 28 Optional child properties: 29 - - label : see Documentation/devicetree/bindings/leds/common.txt 29 + - function : see Documentation/devicetree/bindings/leds/common.txt 30 + - color : see Documentation/devicetree/bindings/leds/common.txt 31 + - label : see Documentation/devicetree/bindings/leds/common.txt (deprecated) 30 32 - linux,default-trigger : 31 33 see Documentation/devicetree/bindings/leds/common.txt 32 34 33 35 Example: 36 + 37 + #include <dt-bindings/leds/common.h> 34 38 35 39 led-controller@36 { 36 40 compatible = "ti,lm3692x"; ··· 47 43 48 44 led@0 { 49 45 reg = <0>; 50 - label = "white:backlight_cluster"; 46 + function = LED_FUNCTION_BACKLIGHT; 47 + color = <LED_COLOR_ID_WHITE>; 51 48 linux,default-trigger = "backlight"; 52 49 }; 53 50 }
+7 -2
Documentation/devicetree/bindings/leds/leds-lp8860.txt
··· 20 20 - reg : 0 21 21 22 22 Optional child properties: 23 - - label : see Documentation/devicetree/bindings/leds/common.txt 23 + - function : see Documentation/devicetree/bindings/leds/common.txt 24 + - color : see Documentation/devicetree/bindings/leds/common.txt 25 + - label : see Documentation/devicetree/bindings/leds/common.txt (deprecated) 24 26 - linux,default-trigger : 25 27 see Documentation/devicetree/bindings/leds/common.txt 26 28 27 29 Example: 30 + 31 + #include <dt-bindings/leds/common.h> 28 32 29 33 led-controller@2d { 30 34 compatible = "ti,lp8860"; ··· 40 36 41 37 led@0 { 42 38 reg = <0>; 43 - label = "white:backlight"; 39 + function = LED_FUNCTION_BACKLIGHT; 40 + color = <LED_COLOR_ID_WHITE>; 44 41 linux,default-trigger = "backlight"; 45 42 }; 46 43 }
+8 -3
Documentation/devicetree/bindings/leds/leds-lt3593.txt
··· 9 9 configured in a sub-node in the device node. 10 10 11 11 Optional sub-node properties: 12 - - label: A label for the LED. If none is given, the LED will be 13 - named "lt3595::". 12 + - function: See Documentation/devicetree/bindings/leds/common.txt 13 + - color: See Documentation/devicetree/bindings/leds/common.txt 14 + - label: A label for the LED. If none is given, the LED will be 15 + named "lt3595::" (deprecated) 14 16 - linux,default-trigger: The default trigger for the LED. 15 17 See Documentation/devicetree/bindings/leds/common.txt 16 18 - default-state: The initial state of the LED. ··· 23 21 24 22 Example: 25 23 24 + #include <dt-bindings/leds/common.h> 25 + 26 26 led-controller { 27 27 compatible = "lltc,lt3593"; 28 28 lltc,ctrl-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>; 29 29 30 30 led { 31 - label = "white:backlight"; 31 + function = LED_FUNCTION_BACKLIGHT; 32 + color = <LED_COLOR_ID_WHITE>; 32 33 default-state = "on"; 33 34 }; 34 35 };
+6 -4
Documentation/devicetree/bindings/leds/leds-sc27xx-bltc.txt
··· 14 14 - reg: Port this LED is connected to. 15 15 16 16 Optional child properties: 17 - - label: See Documentation/devicetree/bindings/leds/common.txt. 17 + - function: See Documentation/devicetree/bindings/leds/common.txt. 18 + - color: See Documentation/devicetree/bindings/leds/common.txt. 19 + - label: See Documentation/devicetree/bindings/leds/common.txt (deprecated). 18 20 19 21 Examples: 20 22 ··· 27 25 reg = <0x200>; 28 26 29 27 led@0 { 30 - label = "red"; 28 + color = <LED_COLOR_ID_RED>; 31 29 reg = <0x0>; 32 30 }; 33 31 34 32 led@1 { 35 - label = "green"; 33 + color = <LED_COLOR_ID_GREEN>; 36 34 reg = <0x1>; 37 35 }; 38 36 39 37 led@2 { 40 - label = "blue"; 38 + color = <LED_COLOR_ID_BLUE>; 41 39 reg = <0x2>; 42 40 }; 43 41 };
+66 -2
Documentation/leds/leds-class.rst
··· 43 43 44 44 Is currently of the form: 45 45 46 - "devicename:colour:function" 46 + "devicename:color:function" 47 47 48 - There have been calls for LED properties such as colour to be exported as 48 + - devicename: 49 + it should refer to a unique identifier created by the kernel, 50 + like e.g. phyN for network devices or inputN for input devices, rather 51 + than to the hardware; the information related to the product and the bus 52 + to which given device is hooked is available in sysfs and can be 53 + retrieved using get_led_device_info.sh script from tools/leds; generally 54 + this section is expected mostly for LEDs that are somehow associated with 55 + other devices. 56 + 57 + - color: 58 + one of LED_COLOR_ID_* definitions from the header 59 + include/dt-bindings/leds/common.h. 60 + 61 + - function: 62 + one of LED_FUNCTION_* definitions from the header 63 + include/dt-bindings/leds/common.h. 64 + 65 + If required color or function is missing, please submit a patch 66 + to linux-leds@vger.kernel.org. 67 + 68 + It is possible that more than one LED with the same color and function will 69 + be required for given platform, differing only with an ordinal number. 70 + In this case it is preferable to just concatenate the predefined LED_FUNCTION_* 71 + name with required "-N" suffix in the driver. fwnode based drivers can use 72 + function-enumerator property for that and then the concatenation will be handled 73 + automatically by the LED core upon LED class device registration. 74 + 75 + LED subsystem has also a protection against name clash, that may occur 76 + when LED class device is created by a driver of hot-pluggable device and 77 + it doesn't provide unique devicename section. In this case numerical 78 + suffix (e.g. "_1", "_2", "_3" etc.) is added to the requested LED class 79 + device name. 80 + 81 + There might be still LED class drivers around using vendor or product name 82 + for devicename, but this approach is now deprecated as it doesn't convey 83 + any added value. Product information can be found in other places in sysfs 84 + (see tools/leds/get_led_device_info.sh). 85 + 86 + Examples of proper LED names: 87 + 88 + - "red:disk" 89 + - "white:flash" 90 + - "red:indicator" 91 + - "phy1:green:wlan" 92 + - "phy3::wlan" 93 + - ":kbd_backlight" 94 + - "input5::kbd_backlight" 95 + - "input3::numlock" 96 + - "input3::scrolllock" 97 + - "input3::capslock" 98 + - "mmc1::status" 99 + - "white:status" 100 + 101 + get_led_device_info.sh script can be used for verifying if the LED name 102 + meets the requirements pointed out here. It performs validation of the LED class 103 + devicename sections and gives hints on expected value for a section in case 104 + the validation fails for it. So far the script supports validation 105 + of associations between LEDs and following types of devices: 106 + 107 + - input devices 108 + - ieee80211 compliant USB devices 109 + 110 + The script is open to extensions. 111 + 112 + There have been calls for LED properties such as color to be exported as 49 113 individual led class attributes. As a solution which doesn't incur as much 50 114 overhead, I suggest these become part of the device name. The naming scheme 51 115 above leaves scope for further attributes should they be needed. If sections
+1 -10
drivers/amba/tegra-ahb.c
··· 134 134 } 135 135 136 136 #ifdef CONFIG_TEGRA_IOMMU_SMMU 137 - static int tegra_ahb_match_by_smmu(struct device *dev, const void *data) 138 - { 139 - struct tegra_ahb *ahb = dev_get_drvdata(dev); 140 - const struct device_node *dn = data; 141 - 142 - return (ahb->dev->of_node == dn) ? 1 : 0; 143 - } 144 - 145 137 int tegra_ahb_enable_smmu(struct device_node *dn) 146 138 { 147 139 struct device *dev; 148 140 u32 val; 149 141 struct tegra_ahb *ahb; 150 142 151 - dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn, 152 - tegra_ahb_match_by_smmu); 143 + dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn); 153 144 if (!dev) 154 145 return -EPROBE_DEFER; 155 146 ahb = dev_get_drvdata(dev);
-24
drivers/base/bus.c
··· 342 342 } 343 343 EXPORT_SYMBOL_GPL(bus_find_device); 344 344 345 - static int match_name(struct device *dev, const void *data) 346 - { 347 - const char *name = data; 348 - 349 - return sysfs_streq(name, dev_name(dev)); 350 - } 351 - 352 - /** 353 - * bus_find_device_by_name - device iterator for locating a particular device of a specific name 354 - * @bus: bus type 355 - * @start: Device to begin with 356 - * @name: name of the device to match 357 - * 358 - * This is similar to the bus_find_device() function above, but it handles 359 - * searching by a name automatically, no need to write another strcmp matching 360 - * function. 361 - */ 362 - struct device *bus_find_device_by_name(struct bus_type *bus, 363 - struct device *start, const char *name) 364 - { 365 - return bus_find_device(bus, start, (void *)name, match_name); 366 - } 367 - EXPORT_SYMBOL_GPL(bus_find_device_by_name); 368 - 369 345 /** 370 346 * subsys_find_device_by_id - find a device with a specific enumeration number 371 347 * @subsys: subsystem
+31 -8
drivers/base/core.c
··· 2944 2944 } 2945 2945 EXPORT_SYMBOL_GPL(device_create_with_groups); 2946 2946 2947 - static int __match_devt(struct device *dev, const void *data) 2948 - { 2949 - const dev_t *devt = data; 2950 - 2951 - return dev->devt == *devt; 2952 - } 2953 - 2954 2947 /** 2955 2948 * device_destroy - removes a device that was created with device_create() 2956 2949 * @class: pointer to the struct class that this device was registered with ··· 2956 2963 { 2957 2964 struct device *dev; 2958 2965 2959 - dev = class_find_device(class, NULL, &devt, __match_devt); 2966 + dev = class_find_device_by_devt(class, devt); 2960 2967 if (dev) { 2961 2968 put_device(dev); 2962 2969 device_unregister(dev); ··· 3427 3434 } 3428 3435 EXPORT_SYMBOL_GPL(device_set_of_node_from_dev); 3429 3436 3437 + int device_match_name(struct device *dev, const void *name) 3438 + { 3439 + return sysfs_streq(dev_name(dev), name); 3440 + } 3441 + EXPORT_SYMBOL_GPL(device_match_name); 3442 + 3430 3443 int device_match_of_node(struct device *dev, const void *np) 3431 3444 { 3432 3445 return dev->of_node == np; 3433 3446 } 3434 3447 EXPORT_SYMBOL_GPL(device_match_of_node); 3448 + 3449 + int device_match_fwnode(struct device *dev, const void *fwnode) 3450 + { 3451 + return dev_fwnode(dev) == fwnode; 3452 + } 3453 + EXPORT_SYMBOL_GPL(device_match_fwnode); 3454 + 3455 + int device_match_devt(struct device *dev, const void *pdevt) 3456 + { 3457 + return dev->devt == *(dev_t *)pdevt; 3458 + } 3459 + EXPORT_SYMBOL_GPL(device_match_devt); 3460 + 3461 + int device_match_acpi_dev(struct device *dev, const void *adev) 3462 + { 3463 + return ACPI_COMPANION(dev) == adev; 3464 + } 3465 + EXPORT_SYMBOL(device_match_acpi_dev); 3466 + 3467 + int device_match_any(struct device *dev, const void *unused) 3468 + { 3469 + return 1; 3470 + } 3471 + EXPORT_SYMBOL_GPL(device_match_any);
+1 -7
drivers/base/devcon.c
··· 133 133 NULL, 134 134 }; 135 135 136 - static int device_fwnode_match(struct device *dev, const void *fwnode) 137 - { 138 - return dev_fwnode(dev) == fwnode; 139 - } 140 - 141 136 static void *device_connection_fwnode_match(struct device_connection *con) 142 137 { 143 138 struct bus_type *bus; 144 139 struct device *dev; 145 140 146 141 for (bus = generic_match_buses[0]; bus; bus++) { 147 - dev = bus_find_device(bus, NULL, (void *)con->fwnode, 148 - device_fwnode_match); 142 + dev = bus_find_device_by_fwnode(bus, con->fwnode); 149 143 if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id))) 150 144 return dev; 151 145
+14
drivers/base/platform.c
··· 1202 1202 }; 1203 1203 EXPORT_SYMBOL_GPL(platform_bus_type); 1204 1204 1205 + /** 1206 + * platform_find_device_by_driver - Find a platform device with a given 1207 + * driver. 1208 + * @start: The device to start the search from. 1209 + * @drv: The device driver to look for. 1210 + */ 1211 + struct device *platform_find_device_by_driver(struct device *start, 1212 + const struct device_driver *drv) 1213 + { 1214 + return bus_find_device(&platform_bus_type, start, drv, 1215 + (void *)platform_match); 1216 + } 1217 + EXPORT_SYMBOL_GPL(platform_find_device_by_driver); 1218 + 1205 1219 int __init platform_bus_init(void) 1206 1220 { 1207 1221 int error;
+1 -7
drivers/fpga/fpga-bridge.c
··· 19 19 /* Lock for adding/removing bridges to linked lists*/ 20 20 static spinlock_t bridge_list_lock; 21 21 22 - static int fpga_bridge_of_node_match(struct device *dev, const void *data) 23 - { 24 - return dev->of_node == data; 25 - } 26 - 27 22 /** 28 23 * fpga_bridge_enable - Enable transactions on the bridge 29 24 * ··· 99 104 { 100 105 struct device *dev; 101 106 102 - dev = class_find_device(fpga_bridge_class, NULL, np, 103 - fpga_bridge_of_node_match); 107 + dev = class_find_device_by_of_node(fpga_bridge_class, np); 104 108 if (!dev) 105 109 return ERR_PTR(-ENODEV); 106 110
+1 -7
drivers/fpga/fpga-mgr.c
··· 482 482 } 483 483 EXPORT_SYMBOL_GPL(fpga_mgr_get); 484 484 485 - static int fpga_mgr_of_node_match(struct device *dev, const void *data) 486 - { 487 - return dev->of_node == data; 488 - } 489 - 490 485 /** 491 486 * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr. 492 487 * ··· 493 498 { 494 499 struct device *dev; 495 500 496 - dev = class_find_device(fpga_mgr_class, NULL, node, 497 - fpga_mgr_of_node_match); 501 + dev = class_find_device_by_of_node(fpga_mgr_class, node); 498 502 if (!dev) 499 503 return ERR_PTR(-ENODEV); 500 504
+1 -6
drivers/gpu/drm/drm_mipi_dsi.c
··· 93 93 .pm = &mipi_dsi_device_pm_ops, 94 94 }; 95 95 96 - static int of_device_match(struct device *dev, const void *data) 97 - { 98 - return dev->of_node == data; 99 - } 100 - 101 96 /** 102 97 * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a 103 98 * device tree node ··· 105 110 { 106 111 struct device *dev; 107 112 108 - dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match); 113 + dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np); 109 114 110 115 return dev ? to_mipi_dsi_device(dev) : NULL; 111 116 }
+3 -6
drivers/gpu/drm/exynos/exynos_drm_drv.c
··· 242 242 if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER)) 243 243 continue; 244 244 245 - while ((d = bus_find_device(&platform_bus_type, p, 246 - &info->driver->driver, 247 - (void *)platform_bus_type.match))) { 245 + while ((d = platform_find_device_by_driver(p, &info->driver->driver))) { 248 246 put_device(p); 249 247 250 248 if (!(info->flags & DRM_FIMC_DEVICE) || ··· 410 412 if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE)) 411 413 continue; 412 414 413 - while ((dev = bus_find_device(&platform_bus_type, NULL, 414 - &info->driver->driver, 415 - (void *)platform_bus_type.match))) { 415 + while ((dev = platform_find_device_by_driver(NULL, 416 + &info->driver->driver))) { 416 417 put_device(dev); 417 418 platform_device_unregister(to_platform_device(dev)); 418 419 }
+1 -2
drivers/gpu/drm/mcde/mcde_drv.c
··· 477 477 struct device_driver *drv = &mcde_component_drivers[i]->driver; 478 478 struct device *p = NULL, *d; 479 479 480 - while ((d = bus_find_device(&platform_bus_type, p, drv, 481 - (void *)platform_bus_type.match))) { 480 + while ((d = platform_find_device_by_driver(p, drv))) { 482 481 put_device(p); 483 482 component_match_add(dev, &match, mcde_compare_dev, d); 484 483 p = d;
+1 -2
drivers/gpu/drm/rockchip/rockchip_drm_drv.c
··· 330 330 struct device *p = NULL, *d; 331 331 332 332 do { 333 - d = bus_find_device(&platform_bus_type, p, &drv->driver, 334 - (void *)platform_bus_type.match); 333 + d = platform_find_device_by_driver(p, &drv->driver); 335 334 put_device(p); 336 335 p = d; 337 336
+1 -2
drivers/gpu/drm/vc4/vc4_drv.c
··· 237 237 struct device_driver *drv = &drivers[i]->driver; 238 238 struct device *p = NULL, *d; 239 239 240 - while ((d = bus_find_device(&platform_bus_type, p, drv, 241 - (void *)platform_bus_type.match))) { 240 + while ((d = platform_find_device_by_driver(p, drv))) { 242 241 put_device(p); 243 242 component_match_add(dev, match, compare_dev, d); 244 243 p = d;
+2 -9
drivers/hwtracing/coresight/coresight-platform.c
··· 37 37 return 0; 38 38 } 39 39 40 - int coresight_device_fwnode_match(struct device *dev, const void *fwnode) 41 - { 42 - return dev_fwnode(dev) == fwnode; 43 - } 44 - 45 40 static struct device * 46 41 coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) 47 42 { ··· 46 51 * If we have a non-configurable replicator, it will be found on the 47 52 * platform bus. 48 53 */ 49 - dev = bus_find_device(&platform_bus_type, NULL, 50 - fwnode, coresight_device_fwnode_match); 54 + dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); 51 55 if (dev) 52 56 return dev; 53 57 ··· 54 60 * We have a configurable component - circle through the AMBA bus 55 61 * looking for the device that matches the endpoint node. 56 62 */ 57 - return bus_find_device(&amba_bustype, NULL, 58 - fwnode, coresight_device_fwnode_match); 63 + return bus_find_device_by_fwnode(&amba_bustype, fwnode); 59 64 } 60 65 61 66 #ifdef CONFIG_OF
-2
drivers/hwtracing/coresight/coresight-priv.h
··· 202 202 203 203 void coresight_release_platform_data(struct coresight_platform_data *pdata); 204 204 205 - int coresight_device_fwnode_match(struct device *dev, const void *fwnode); 206 - 207 205 #endif
+1 -3
drivers/hwtracing/coresight/coresight.c
··· 1046 1046 struct coresight_connection *conn = &csdev->pdata->conns[i]; 1047 1047 struct device *dev = NULL; 1048 1048 1049 - dev = bus_find_device(&coresight_bustype, NULL, 1050 - (void *)conn->child_fwnode, 1051 - coresight_device_fwnode_match); 1049 + dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode); 1052 1050 if (dev) { 1053 1051 conn->child_dev = to_coresight_device(dev); 1054 1052 /* and put reference from 'bus_find_device()' */
+1 -9
drivers/hwtracing/intel_th/core.c
··· 789 789 return 0; 790 790 } 791 791 792 - static int match_devt(struct device *dev, const void *data) 793 - { 794 - dev_t devt = (dev_t)(unsigned long)(void *)data; 795 - return dev->devt == devt; 796 - } 797 - 798 792 static int intel_th_output_open(struct inode *inode, struct file *file) 799 793 { 800 794 const struct file_operations *fops; ··· 796 802 struct device *dev; 797 803 int err; 798 804 799 - dev = bus_find_device(&intel_th_bus, NULL, 800 - (void *)(unsigned long)inode->i_rdev, 801 - match_devt); 805 + dev = bus_find_device_by_devt(&intel_th_bus, inode->i_rdev); 802 806 if (!dev || !dev->driver) 803 807 return -ENODEV; 804 808
+1 -8
drivers/hwtracing/stm/core.c
··· 89 89 .dev_groups = stm_groups, 90 90 }; 91 91 92 - static int stm_dev_match(struct device *dev, const void *data) 93 - { 94 - const char *name = data; 95 - 96 - return sysfs_streq(name, dev_name(dev)); 97 - } 98 - 99 92 /** 100 93 * stm_find_device() - find stm device by name 101 94 * @buf: character buffer containing the name ··· 109 116 if (!stm_core_up) 110 117 return NULL; 111 118 112 - dev = class_find_device(&stm_class, NULL, buf, stm_dev_match); 119 + dev = class_find_device_by_name(&stm_class, buf); 113 120 if (!dev) 114 121 return NULL; 115 122
+1 -7
drivers/i2c/busses/i2c-amd-mp2-pci.c
··· 457 457 }; 458 458 module_pci_driver(amd_mp2_pci_driver); 459 459 460 - static int amd_mp2_device_match(struct device *dev, const void *data) 461 - { 462 - return 1; 463 - } 464 - 465 460 struct amd_mp2_dev *amd_mp2_find_device(void) 466 461 { 467 462 struct device *dev; 468 463 struct pci_dev *pci_dev; 469 464 470 - dev = driver_find_device(&amd_mp2_pci_driver.driver, NULL, NULL, 471 - amd_mp2_device_match); 465 + dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL); 472 466 if (!dev) 473 467 return NULL; 474 468
+2 -20
drivers/i2c/i2c-core-acpi.c
··· 344 344 } 345 345 EXPORT_SYMBOL_GPL(i2c_acpi_find_bus_speed); 346 346 347 - static int i2c_acpi_find_match_adapter(struct device *dev, const void *data) 348 - { 349 - struct i2c_adapter *adapter = i2c_verify_adapter(dev); 350 - 351 - if (!adapter) 352 - return 0; 353 - 354 - return ACPI_HANDLE(dev) == (acpi_handle)data; 355 - } 356 - 357 - static int i2c_acpi_find_match_device(struct device *dev, const void *data) 358 - { 359 - return ACPI_COMPANION(dev) == data; 360 - } 361 - 362 347 struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle) 363 348 { 364 - struct device *dev; 349 + struct device *dev = bus_find_device_by_acpi_dev(&i2c_bus_type, handle); 365 350 366 - dev = bus_find_device(&i2c_bus_type, NULL, handle, 367 - i2c_acpi_find_match_adapter); 368 351 return dev ? i2c_verify_adapter(dev) : NULL; 369 352 } 370 353 EXPORT_SYMBOL_GPL(i2c_acpi_find_adapter_by_handle); ··· 356 373 { 357 374 struct device *dev; 358 375 359 - dev = bus_find_device(&i2c_bus_type, NULL, adev, 360 - i2c_acpi_find_match_device); 376 + dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev); 361 377 return dev ? i2c_verify_client(dev) : NULL; 362 378 } 363 379
+1 -6
drivers/i2c/i2c-core-of.c
··· 113 113 of_node_put(bus); 114 114 } 115 115 116 - static int of_dev_node_match(struct device *dev, const void *data) 117 - { 118 - return dev->of_node == data; 119 - } 120 - 121 116 static int of_dev_or_parent_node_match(struct device *dev, const void *data) 122 117 { 123 118 if (dev->of_node == data) ··· 130 135 struct device *dev; 131 136 struct i2c_client *client; 132 137 133 - dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match); 138 + dev = bus_find_device_by_of_node(&i2c_bus_type, node); 134 139 if (!dev) 135 140 return NULL; 136 141
+1 -7
drivers/infiniband/hw/hns/hns_roce_hw_v1.c
··· 4501 4501 }; 4502 4502 MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match); 4503 4503 4504 - static int hns_roce_node_match(struct device *dev, const void *fwnode) 4505 - { 4506 - return dev->fwnode == fwnode; 4507 - } 4508 - 4509 4504 static struct 4510 4505 platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode) 4511 4506 { 4512 4507 struct device *dev; 4513 4508 4514 4509 /* get the 'device' corresponding to the matching 'fwnode' */ 4515 - dev = bus_find_device(&platform_bus_type, NULL, 4516 - fwnode, hns_roce_node_match); 4510 + dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); 4517 4511 /* get the platform device */ 4518 4512 return dev ? to_platform_device(dev) : NULL; 4519 4513 }
+2 -7
drivers/iommu/arm-smmu-v3.c
··· 2503 2503 2504 2504 static struct platform_driver arm_smmu_driver; 2505 2505 2506 - static int arm_smmu_match_node(struct device *dev, const void *data) 2507 - { 2508 - return dev->fwnode == data; 2509 - } 2510 - 2511 2506 static 2512 2507 struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) 2513 2508 { 2514 - struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL, 2515 - fwnode, arm_smmu_match_node); 2509 + struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver, 2510 + fwnode); 2516 2511 put_device(dev); 2517 2512 return dev ? dev_get_drvdata(dev) : NULL; 2518 2513 }
+2 -7
drivers/iommu/arm-smmu.c
··· 1299 1299 } 1300 1300 } 1301 1301 1302 - static int arm_smmu_match_node(struct device *dev, const void *data) 1303 - { 1304 - return dev->fwnode == data; 1305 - } 1306 - 1307 1302 static 1308 1303 struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) 1309 1304 { 1310 - struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL, 1311 - fwnode, arm_smmu_match_node); 1305 + struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver, 1306 + fwnode); 1312 1307 put_device(dev); 1313 1308 return dev ? dev_get_drvdata(dev) : NULL; 1314 1309 }
+5 -1
drivers/leds/Kconfig
··· 74 74 depends on LEDS_CLASS 75 75 depends on X86 && DMI 76 76 help 77 - This driver makes the PC Engines APU/APU2/APU3 front panel LEDs 77 + This driver makes the PC Engines APU1 front panel LEDs 78 78 accessible from userspace programs through the LED subsystem. 79 + 80 + If you're looking for APU2/3, use the pcengines-apu2 driver. 81 + (symbol CONFIG_PCENGINES_APU2) 79 82 80 83 To compile this driver as a module, choose M here: the 81 84 module will be called leds-apu. ··· 590 587 tristate "LED support for Big Network series LEDs" 591 588 depends on LEDS_CLASS 592 589 depends on MACH_KIRKWOOD 590 + depends on OF_GPIO 593 591 default y 594 592 help 595 593 This option enables support for LEDs found on the LaCie 2Big
+5 -4
drivers/leds/led-class-flash.c
··· 282 282 led_cdev->groups = flash_groups; 283 283 } 284 284 285 - int led_classdev_flash_register(struct device *parent, 286 - 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) 287 288 { 288 289 struct led_classdev *led_cdev; 289 290 const struct led_flash_ops *ops; ··· 310 309 } 311 310 312 311 /* Register led class device */ 313 - ret = led_classdev_register(parent, led_cdev); 312 + ret = led_classdev_register_ext(parent, led_cdev, init_data); 314 313 if (ret < 0) 315 314 return ret; 316 315 317 316 return 0; 318 317 } 319 - EXPORT_SYMBOL_GPL(led_classdev_flash_register); 318 + EXPORT_SYMBOL_GPL(led_classdev_flash_register_ext); 320 319 321 320 void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) 322 321 {
+39 -23
drivers/leds/led-class.c
··· 14 14 #include <linux/leds.h> 15 15 #include <linux/list.h> 16 16 #include <linux/module.h> 17 + #include <linux/property.h> 17 18 #include <linux/slab.h> 18 19 #include <linux/spinlock.h> 19 20 #include <linux/timer.h> ··· 214 213 215 214 static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume); 216 215 217 - static int match_name(struct device *dev, const void *data) 218 - { 219 - if (!dev_name(dev)) 220 - return 0; 221 - return !strcmp(dev_name(dev), (char *)data); 222 - } 223 - 224 216 static int led_classdev_next_name(const char *init_name, char *name, 225 217 size_t len) 226 218 { ··· 224 230 strlcpy(name, init_name, len); 225 231 226 232 while ((ret < len) && 227 - (dev = class_find_device(leds_class, NULL, name, match_name))) { 233 + (dev = class_find_device_by_name(leds_class, name))) { 228 234 put_device(dev); 229 235 ret = snprintf(name, len, "%s_%u", init_name, ++i); 230 236 } ··· 236 242 } 237 243 238 244 /** 239 - * of_led_classdev_register - register a new object of led_classdev class. 245 + * led_classdev_register_ext - register a new object of led_classdev class 246 + * with init data. 240 247 * 241 248 * @parent: parent of LED device 242 249 * @led_cdev: the led_classdev structure for this device. 243 - * @np: DT node describing this LED 250 + * @init_data: LED class device initialization data 244 251 */ 245 - int of_led_classdev_register(struct device *parent, struct device_node *np, 246 - struct led_classdev *led_cdev) 252 + int led_classdev_register_ext(struct device *parent, 253 + struct led_classdev *led_cdev, 254 + struct led_init_data *init_data) 247 255 { 248 - char name[LED_MAX_NAME_SIZE]; 256 + char composed_name[LED_MAX_NAME_SIZE]; 257 + char final_name[LED_MAX_NAME_SIZE]; 258 + const char *proposed_name = composed_name; 249 259 int ret; 250 260 251 - ret = led_classdev_next_name(led_cdev->name, name, sizeof(name)); 261 + if (init_data) { 262 + if (init_data->devname_mandatory && !init_data->devicename) { 263 + dev_err(parent, "Mandatory device name is missing"); 264 + return -EINVAL; 265 + } 266 + ret = led_compose_name(parent, init_data, composed_name); 267 + if (ret < 0) 268 + return ret; 269 + } else { 270 + proposed_name = led_cdev->name; 271 + } 272 + 273 + ret = led_classdev_next_name(proposed_name, final_name, sizeof(final_name)); 252 274 if (ret < 0) 253 275 return ret; 254 276 255 277 mutex_init(&led_cdev->led_access); 256 278 mutex_lock(&led_cdev->led_access); 257 279 led_cdev->dev = device_create_with_groups(leds_class, parent, 0, 258 - led_cdev, led_cdev->groups, "%s", name); 280 + led_cdev, led_cdev->groups, "%s", final_name); 259 281 if (IS_ERR(led_cdev->dev)) { 260 282 mutex_unlock(&led_cdev->led_access); 261 283 return PTR_ERR(led_cdev->dev); 262 284 } 263 - led_cdev->dev->of_node = np; 285 + if (init_data && init_data->fwnode) 286 + led_cdev->dev->fwnode = init_data->fwnode; 264 287 265 288 if (ret) 266 289 dev_warn(parent, "Led %s renamed to %s due to name collision", ··· 287 276 ret = led_add_brightness_hw_changed(led_cdev); 288 277 if (ret) { 289 278 device_unregister(led_cdev->dev); 279 + led_cdev->dev = NULL; 290 280 mutex_unlock(&led_cdev->led_access); 291 281 return ret; 292 282 } ··· 323 311 324 312 return 0; 325 313 } 326 - EXPORT_SYMBOL_GPL(of_led_classdev_register); 314 + EXPORT_SYMBOL_GPL(led_classdev_register_ext); 327 315 328 316 /** 329 317 * led_classdev_unregister - unregisters a object of led_properties class. ··· 333 321 */ 334 322 void led_classdev_unregister(struct led_classdev *led_cdev) 335 323 { 324 + if (IS_ERR_OR_NULL(led_cdev->dev)) 325 + return; 326 + 336 327 #ifdef CONFIG_LEDS_TRIGGERS 337 328 down_write(&led_cdev->trigger_lock); 338 329 if (led_cdev->trigger) ··· 371 356 } 372 357 373 358 /** 374 - * devm_of_led_classdev_register - resource managed led_classdev_register() 359 + * devm_led_classdev_register_ext - resource managed led_classdev_register_ext() 375 360 * 376 361 * @parent: parent of LED device 377 362 * @led_cdev: the led_classdev structure for this device. 363 + * @init_data: LED class device initialization data 378 364 */ 379 - int devm_of_led_classdev_register(struct device *parent, 380 - struct device_node *np, 381 - struct led_classdev *led_cdev) 365 + int devm_led_classdev_register_ext(struct device *parent, 366 + struct led_classdev *led_cdev, 367 + struct led_init_data *init_data) 382 368 { 383 369 struct led_classdev **dr; 384 370 int rc; ··· 388 372 if (!dr) 389 373 return -ENOMEM; 390 374 391 - rc = of_led_classdev_register(parent, np, led_cdev); 375 + rc = led_classdev_register_ext(parent, led_cdev, init_data); 392 376 if (rc) { 393 377 devres_free(dr); 394 378 return rc; ··· 399 383 400 384 return 0; 401 385 } 402 - EXPORT_SYMBOL_GPL(devm_of_led_classdev_register); 386 + EXPORT_SYMBOL_GPL(devm_led_classdev_register_ext); 403 387 404 388 static int devm_led_classdev_match(struct device *dev, void *res, void *data) 405 389 {
+130 -6
drivers/leds/led-core.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/mutex.h> 15 15 #include <linux/of.h> 16 + #include <linux/property.h> 16 17 #include <linux/rwsem.h> 17 18 #include <linux/slab.h> 19 + #include <uapi/linux/uleds.h> 18 20 #include "leds.h" 19 21 20 22 DECLARE_RWSEM(leds_list_lock); ··· 24 22 25 23 LIST_HEAD(leds_list); 26 24 EXPORT_SYMBOL_GPL(leds_list); 25 + 26 + const char * const led_colors[LED_COLOR_ID_MAX] = { 27 + [LED_COLOR_ID_WHITE] = "white", 28 + [LED_COLOR_ID_RED] = "red", 29 + [LED_COLOR_ID_GREEN] = "green", 30 + [LED_COLOR_ID_BLUE] = "blue", 31 + [LED_COLOR_ID_AMBER] = "amber", 32 + [LED_COLOR_ID_VIOLET] = "violet", 33 + [LED_COLOR_ID_YELLOW] = "yellow", 34 + [LED_COLOR_ID_IR] = "ir", 35 + }; 36 + EXPORT_SYMBOL_GPL(led_colors); 27 37 28 38 static int __led_set_brightness(struct led_classdev *led_cdev, 29 39 enum led_brightness value) ··· 324 310 325 311 u32 *led_get_default_pattern(struct led_classdev *led_cdev, unsigned int *size) 326 312 { 327 - struct device_node *np = dev_of_node(led_cdev->dev); 313 + struct fwnode_handle *fwnode = led_cdev->dev->fwnode; 328 314 u32 *pattern; 329 315 int count; 330 316 331 - if (!np) 332 - return NULL; 333 - 334 - count = of_property_count_u32_elems(np, "led-pattern"); 317 + count = fwnode_property_count_u32(fwnode, "led-pattern"); 335 318 if (count < 0) 336 319 return NULL; 337 320 ··· 336 325 if (!pattern) 337 326 return NULL; 338 327 339 - if (of_property_read_u32_array(np, "led-pattern", pattern, count)) { 328 + if (fwnode_property_read_u32_array(fwnode, "led-pattern", pattern, count)) { 340 329 kfree(pattern); 341 330 return NULL; 342 331 } ··· 364 353 led_cdev->flags &= ~LED_SYSFS_DISABLE; 365 354 } 366 355 EXPORT_SYMBOL_GPL(led_sysfs_enable); 356 + 357 + static void led_parse_fwnode_props(struct device *dev, 358 + struct fwnode_handle *fwnode, 359 + struct led_properties *props) 360 + { 361 + int ret; 362 + 363 + if (!fwnode) 364 + return; 365 + 366 + if (fwnode_property_present(fwnode, "label")) { 367 + ret = fwnode_property_read_string(fwnode, "label", &props->label); 368 + if (ret) 369 + dev_err(dev, "Error parsing 'label' property (%d)\n", ret); 370 + return; 371 + } 372 + 373 + if (fwnode_property_present(fwnode, "color")) { 374 + ret = fwnode_property_read_u32(fwnode, "color", &props->color); 375 + if (ret) 376 + dev_err(dev, "Error parsing 'color' property (%d)\n", ret); 377 + else if (props->color >= LED_COLOR_ID_MAX) 378 + dev_err(dev, "LED color identifier out of range\n"); 379 + else 380 + props->color_present = true; 381 + } 382 + 383 + 384 + if (!fwnode_property_present(fwnode, "function")) 385 + return; 386 + 387 + ret = fwnode_property_read_string(fwnode, "function", &props->function); 388 + if (ret) { 389 + dev_err(dev, 390 + "Error parsing 'function' property (%d)\n", 391 + ret); 392 + } 393 + 394 + if (!fwnode_property_present(fwnode, "function-enumerator")) 395 + return; 396 + 397 + ret = fwnode_property_read_u32(fwnode, "function-enumerator", 398 + &props->func_enum); 399 + if (ret) { 400 + dev_err(dev, 401 + "Error parsing 'function-enumerator' property (%d)\n", 402 + ret); 403 + } else { 404 + props->func_enum_present = true; 405 + } 406 + } 407 + 408 + int led_compose_name(struct device *dev, struct led_init_data *init_data, 409 + char *led_classdev_name) 410 + { 411 + struct led_properties props = {}; 412 + struct fwnode_handle *fwnode = init_data->fwnode; 413 + const char *devicename = init_data->devicename; 414 + 415 + if (!led_classdev_name) 416 + return -EINVAL; 417 + 418 + led_parse_fwnode_props(dev, fwnode, &props); 419 + 420 + if (props.label) { 421 + /* 422 + * If init_data.devicename is NULL, then it indicates that 423 + * DT label should be used as-is for LED class device name. 424 + * Otherwise the label is prepended with devicename to compose 425 + * the final LED class device name. 426 + */ 427 + if (!devicename) { 428 + strscpy(led_classdev_name, props.label, 429 + LED_MAX_NAME_SIZE); 430 + } else { 431 + snprintf(led_classdev_name, LED_MAX_NAME_SIZE, "%s:%s", 432 + devicename, props.label); 433 + } 434 + } else if (props.function || props.color_present) { 435 + char tmp_buf[LED_MAX_NAME_SIZE]; 436 + 437 + if (props.func_enum_present) { 438 + snprintf(tmp_buf, LED_MAX_NAME_SIZE, "%s:%s-%d", 439 + props.color_present ? led_colors[props.color] : "", 440 + props.function ?: "", props.func_enum); 441 + } else { 442 + snprintf(tmp_buf, LED_MAX_NAME_SIZE, "%s:%s", 443 + props.color_present ? led_colors[props.color] : "", 444 + props.function ?: ""); 445 + } 446 + if (init_data->devname_mandatory) { 447 + snprintf(led_classdev_name, LED_MAX_NAME_SIZE, "%s:%s", 448 + devicename, tmp_buf); 449 + } else { 450 + strscpy(led_classdev_name, tmp_buf, LED_MAX_NAME_SIZE); 451 + 452 + } 453 + } else if (init_data->default_label) { 454 + if (!devicename) { 455 + dev_err(dev, "Legacy LED naming requires devicename segment"); 456 + return -EINVAL; 457 + } 458 + snprintf(led_classdev_name, LED_MAX_NAME_SIZE, "%s:%s", 459 + devicename, init_data->default_label); 460 + } else if (is_of_node(fwnode)) { 461 + strscpy(led_classdev_name, to_of_node(fwnode)->name, 462 + LED_MAX_NAME_SIZE); 463 + } else 464 + return -EINVAL; 465 + 466 + return 0; 467 + } 468 + EXPORT_SYMBOL_GPL(led_compose_name);
+3 -2
drivers/leds/led-triggers.c
··· 167 167 trig->deactivate(led_cdev); 168 168 err_activate: 169 169 170 - led_cdev->trigger = NULL; 171 - led_cdev->trigger_data = NULL; 172 170 write_lock_irqsave(&led_cdev->trigger->leddev_list_lock, flags); 173 171 list_del(&led_cdev->trig_list); 174 172 write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags); 173 + led_cdev->trigger = NULL; 174 + led_cdev->trigger_data = NULL; 175 175 led_set_brightness(led_cdev, LED_OFF); 176 + kfree(event); 176 177 177 178 return ret; 178 179 }
+9 -7
drivers/leds/leds-aat1290.c
··· 42 42 #define AAT1290_FLASH_TM_NUM_LEVELS 16 43 43 #define AAT1290_MM_CURRENT_SCALE_SIZE 15 44 44 45 + #define AAT1290_NAME "aat1290" 46 + 45 47 46 48 struct aat1290_led_config_data { 47 49 /* maximum LED current in movie mode */ ··· 77 75 int *mm_current_scale; 78 76 /* device mode */ 79 77 bool movie_mode; 80 - 81 78 /* brightness cache */ 82 79 unsigned int torch_brightness; 83 80 }; ··· 216 215 struct aat1290_led_config_data *cfg, 217 216 struct device_node **sub_node) 218 217 { 219 - struct led_classdev *led_cdev = &led->fled_cdev.led_cdev; 220 218 struct device *dev = &led->pdev->dev; 221 219 struct device_node *child_node; 222 220 #if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS) ··· 253 253 dev_err(dev, "No DT child node found for connected LED.\n"); 254 254 return -EINVAL; 255 255 } 256 - 257 - led_cdev->name = of_get_property(child_node, "label", NULL) ? : 258 - child_node->name; 259 256 260 257 ret = of_property_read_u32(child_node, "led-max-microamp", 261 258 &cfg->max_mm_current); ··· 425 428 struct led_classdev *led_cdev = &led->fled_cdev.led_cdev; 426 429 struct led_flash_setting *s; 427 430 428 - strlcpy(v4l2_sd_cfg->dev_name, led_cdev->name, 431 + strlcpy(v4l2_sd_cfg->dev_name, led_cdev->dev->kobj.name, 429 432 sizeof(v4l2_sd_cfg->dev_name)); 430 433 431 434 s = &v4l2_sd_cfg->intensity; ··· 463 466 struct aat1290_led *led; 464 467 struct led_classdev *led_cdev; 465 468 struct led_classdev_flash *fled_cdev; 469 + struct led_init_data init_data = {}; 466 470 struct aat1290_led_config_data led_cfg = {}; 467 471 struct v4l2_flash_config v4l2_sd_cfg = {}; 468 472 int ret; ··· 492 494 493 495 aat1290_init_flash_timeout(led, &led_cfg); 494 496 497 + init_data.fwnode = of_fwnode_handle(sub_node); 498 + init_data.devicename = AAT1290_NAME; 499 + 495 500 /* Register LED Flash class device */ 496 - ret = led_classdev_flash_register(&pdev->dev, fled_cdev); 501 + ret = led_classdev_flash_register_ext(&pdev->dev, fled_cdev, 502 + &init_data); 497 503 if (ret < 0) 498 504 goto err_flash_register; 499 505
+15 -14
drivers/leds/leds-an30259a.c
··· 13 13 #include <linux/mutex.h> 14 14 #include <linux/of.h> 15 15 #include <linux/regmap.h> 16 - #include <uapi/linux/uleds.h> 17 16 18 17 #define AN30259A_MAX_LEDS 3 19 18 ··· 53 54 #define AN30259A_BLINK_MAX_TIME 7500 /* ms */ 54 55 #define AN30259A_SLOPE_RESOLUTION 500 /* ms */ 55 56 57 + #define AN30259A_NAME "an30259a" 58 + 56 59 #define STATE_OFF 0 57 60 #define STATE_KEEP 1 58 61 #define STATE_ON 2 ··· 63 62 64 63 struct an30259a_led { 65 64 struct an30259a *chip; 65 + struct fwnode_handle *fwnode; 66 66 struct led_classdev cdev; 67 67 u32 num; 68 68 u32 default_state; 69 69 bool sloping; 70 - char label[LED_MAX_NAME_SIZE]; 71 70 }; 72 71 73 72 struct an30259a { ··· 227 226 228 227 led->num = source; 229 228 led->chip = chip; 230 - 231 - if (of_property_read_string(child, "label", &str)) 232 - snprintf(led->label, sizeof(led->label), "an30259a::"); 233 - else 234 - snprintf(led->label, sizeof(led->label), "an30259a:%s", 235 - str); 236 - 237 - led->cdev.name = led->label; 229 + led->fwnode = of_fwnode_handle(child); 238 230 239 231 if (!of_property_read_string(child, "default-state", &str)) { 240 232 if (!strcmp(str, "on")) ··· 306 312 chip->regmap = devm_regmap_init_i2c(client, &an30259a_regmap_config); 307 313 308 314 for (i = 0; i < chip->num_leds; i++) { 315 + struct led_init_data init_data = {}; 316 + 309 317 an30259a_init_default_state(&chip->leds[i]); 310 318 chip->leds[i].cdev.brightness_set_blocking = 311 319 an30259a_brightness_set; 312 320 chip->leds[i].cdev.blink_set = an30259a_blink_set; 313 321 314 - err = devm_led_classdev_register(&client->dev, 315 - &chip->leds[i].cdev); 322 + init_data.fwnode = chip->leds[i].fwnode; 323 + init_data.devicename = AN30259A_NAME; 324 + init_data.default_label = ":"; 325 + 326 + err = devm_led_classdev_register_ext(&client->dev, 327 + &chip->leds[i].cdev, 328 + &init_data); 316 329 if (err < 0) 317 330 goto exit; 318 331 } ··· 354 353 355 354 static struct i2c_driver an30259a_driver = { 356 355 .driver = { 357 - .name = "leds-an32059a", 356 + .name = "leds-an30259a", 358 357 .of_match_table = of_match_ptr(an30259a_match_table), 359 358 }, 360 359 .probe_new = an30259a_probe, ··· 365 364 module_i2c_driver(an30259a_driver); 366 365 367 366 MODULE_AUTHOR("Simon Shields <simon@lineageos.org>"); 368 - MODULE_DESCRIPTION("AN32059A LED driver"); 367 + MODULE_DESCRIPTION("AN30259A LED driver"); 369 368 MODULE_LICENSE("GPL v2");
+14 -143
drivers/leds/leds-apu.c
··· 31 31 * POSSIBILITY OF SUCH DAMAGE. 32 32 */ 33 33 34 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 35 + 34 36 #include <linux/dmi.h> 35 37 #include <linux/err.h> 36 38 #include <linux/init.h> ··· 48 46 #define APU1_LEDOFF 0xC8 49 47 #define APU1_NUM_GPIO 3 50 48 #define APU1_IOSIZE sizeof(u8) 51 - 52 - #define APU2_FCH_ACPI_MMIO_BASE 0xFED80000 53 - #define APU2_FCH_GPIO_BASE (APU2_FCH_ACPI_MMIO_BASE + 0x1500) 54 - #define APU2_GPIO_BIT_WRITE 22 55 - #define APU2_APU2_NUM_GPIO 4 56 - #define APU2_IOSIZE sizeof(u32) 57 49 58 50 /* LED access parameters */ 59 51 struct apu_param { ··· 68 72 unsigned long offset; /* for devm_ioremap */ 69 73 }; 70 74 71 - /* Supported platform types */ 72 - enum apu_led_platform_types { 73 - APU1_LED_PLATFORM, 74 - APU2_LED_PLATFORM, 75 - }; 76 - 77 75 struct apu_led_pdata { 78 76 struct platform_device *pdev; 79 77 struct apu_led_priv *pled; 80 - const struct apu_led_profile *profile; 81 - enum apu_led_platform_types platform; 82 - int num_led_instances; 83 - int iosize; /* for devm_ioremap() */ 84 78 spinlock_t lock; 85 79 }; 86 80 ··· 82 96 { "apu:green:3", LED_OFF, APU1_FCH_GPIO_BASE + 2 * APU1_IOSIZE }, 83 97 }; 84 98 85 - static const struct apu_led_profile apu2_led_profile[] = { 86 - { "apu2:green:1", LED_ON, APU2_FCH_GPIO_BASE + 68 * APU2_IOSIZE }, 87 - { "apu2:green:2", LED_OFF, APU2_FCH_GPIO_BASE + 69 * APU2_IOSIZE }, 88 - { "apu2:green:3", LED_OFF, APU2_FCH_GPIO_BASE + 70 * APU2_IOSIZE }, 89 - }; 90 - 91 - /* Same as apu2_led_profile, but with "3" in the LED names. */ 92 - static const struct apu_led_profile apu3_led_profile[] = { 93 - { "apu3:green:1", LED_ON, APU2_FCH_GPIO_BASE + 68 * APU2_IOSIZE }, 94 - { "apu3:green:2", LED_OFF, APU2_FCH_GPIO_BASE + 69 * APU2_IOSIZE }, 95 - { "apu3:green:3", LED_OFF, APU2_FCH_GPIO_BASE + 70 * APU2_IOSIZE }, 96 - }; 97 - 98 99 static const struct dmi_system_id apu_led_dmi_table[] __initconst = { 99 100 { 100 101 .ident = "apu", 101 102 .matches = { 102 103 DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), 103 104 DMI_MATCH(DMI_PRODUCT_NAME, "APU") 104 - } 105 - }, 106 - /* PC Engines APU2 with "Legacy" bios < 4.0.8 */ 107 - { 108 - .ident = "apu2", 109 - .matches = { 110 - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), 111 - DMI_MATCH(DMI_BOARD_NAME, "APU2") 112 - } 113 - }, 114 - /* PC Engines APU2 with "Legacy" bios >= 4.0.8 */ 115 - { 116 - .ident = "apu2", 117 - .matches = { 118 - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), 119 - DMI_MATCH(DMI_BOARD_NAME, "apu2") 120 - } 121 - }, 122 - /* PC Engines APU2 with "Mainline" bios */ 123 - { 124 - .ident = "apu2", 125 - .matches = { 126 - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), 127 - DMI_MATCH(DMI_BOARD_NAME, "PC Engines apu2") 128 - } 129 - }, 130 - /* PC Engines APU3 with "Legacy" bios < 4.0.8 */ 131 - { 132 - .ident = "apu3", 133 - .matches = { 134 - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), 135 - DMI_MATCH(DMI_BOARD_NAME, "APU3") 136 - } 137 - }, 138 - /* PC Engines APU3 with "Legacy" bios >= 4.0.8 */ 139 - { 140 - .ident = "apu3", 141 - .matches = { 142 - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), 143 - DMI_MATCH(DMI_BOARD_NAME, "apu3") 144 - } 145 - }, 146 - /* PC Engines APU2 with "Mainline" bios */ 147 - { 148 - .ident = "apu3", 149 - .matches = { 150 - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), 151 - DMI_MATCH(DMI_BOARD_NAME, "PC Engines apu3") 152 105 } 153 106 }, 154 107 {} ··· 103 178 spin_unlock(&apu_led->lock); 104 179 } 105 180 106 - static void apu2_led_brightness_set(struct led_classdev *led, enum led_brightness value) 107 - { 108 - struct apu_led_priv *pled = cdev_to_priv(led); 109 - u32 value_new; 110 - 111 - spin_lock(&apu_led->lock); 112 - 113 - value_new = ioread32(pled->param.addr); 114 - 115 - if (value) 116 - value_new &= ~BIT(APU2_GPIO_BIT_WRITE); 117 - else 118 - value_new |= BIT(APU2_GPIO_BIT_WRITE); 119 - 120 - iowrite32(value_new, pled->param.addr); 121 - 122 - spin_unlock(&apu_led->lock); 123 - } 124 - 125 181 static int apu_led_config(struct device *dev, struct apu_led_pdata *apuld) 126 182 { 127 183 int i; 128 184 int err; 129 185 130 186 apu_led->pled = devm_kcalloc(dev, 131 - apu_led->num_led_instances, sizeof(struct apu_led_priv), 187 + ARRAY_SIZE(apu1_led_profile), sizeof(struct apu_led_priv), 132 188 GFP_KERNEL); 133 189 134 190 if (!apu_led->pled) 135 191 return -ENOMEM; 136 192 137 - for (i = 0; i < apu_led->num_led_instances; i++) { 193 + for (i = 0; i < ARRAY_SIZE(apu1_led_profile); i++) { 138 194 struct apu_led_priv *pled = &apu_led->pled[i]; 139 195 struct led_classdev *led_cdev = &pled->cdev; 140 196 141 - led_cdev->name = apu_led->profile[i].name; 142 - led_cdev->brightness = apu_led->profile[i].brightness; 197 + led_cdev->name = apu1_led_profile[i].name; 198 + led_cdev->brightness = apu1_led_profile[i].brightness; 143 199 led_cdev->max_brightness = 1; 144 200 led_cdev->flags = LED_CORE_SUSPENDRESUME; 145 - if (apu_led->platform == APU1_LED_PLATFORM) 146 - led_cdev->brightness_set = apu1_led_brightness_set; 147 - else if (apu_led->platform == APU2_LED_PLATFORM) 148 - led_cdev->brightness_set = apu2_led_brightness_set; 201 + led_cdev->brightness_set = apu1_led_brightness_set; 149 202 150 203 pled->param.addr = devm_ioremap(dev, 151 - apu_led->profile[i].offset, apu_led->iosize); 204 + apu1_led_profile[i].offset, APU1_IOSIZE); 152 205 if (!pled->param.addr) { 153 206 err = -ENOMEM; 154 207 goto error; ··· 136 233 if (err) 137 234 goto error; 138 235 139 - led_cdev->brightness_set(led_cdev, apu_led->profile[i].brightness); 236 + apu1_led_brightness_set(led_cdev, apu1_led_profile[i].brightness); 140 237 } 141 238 142 239 return 0; ··· 157 254 158 255 apu_led->pdev = pdev; 159 256 160 - if (dmi_match(DMI_PRODUCT_NAME, "APU")) { 161 - apu_led->profile = apu1_led_profile; 162 - apu_led->platform = APU1_LED_PLATFORM; 163 - apu_led->num_led_instances = ARRAY_SIZE(apu1_led_profile); 164 - apu_led->iosize = APU1_IOSIZE; 165 - } else if (dmi_match(DMI_BOARD_NAME, "APU2") || 166 - dmi_match(DMI_BOARD_NAME, "apu2") || 167 - dmi_match(DMI_BOARD_NAME, "PC Engines apu2")) { 168 - apu_led->profile = apu2_led_profile; 169 - apu_led->platform = APU2_LED_PLATFORM; 170 - apu_led->num_led_instances = ARRAY_SIZE(apu2_led_profile); 171 - apu_led->iosize = APU2_IOSIZE; 172 - } else if (dmi_match(DMI_BOARD_NAME, "APU3") || 173 - dmi_match(DMI_BOARD_NAME, "apu3") || 174 - dmi_match(DMI_BOARD_NAME, "PC Engines apu3")) { 175 - apu_led->profile = apu3_led_profile; 176 - /* Otherwise identical to APU2. */ 177 - apu_led->platform = APU2_LED_PLATFORM; 178 - apu_led->num_led_instances = ARRAY_SIZE(apu3_led_profile); 179 - apu_led->iosize = APU2_IOSIZE; 180 - } 181 - 182 257 spin_lock_init(&apu_led->lock); 183 258 return apu_led_config(&pdev->dev, apu_led); 184 259 } ··· 172 291 struct platform_device *pdev; 173 292 int err; 174 293 175 - if (!dmi_match(DMI_SYS_VENDOR, "PC Engines")) { 176 - pr_err("No PC Engines board detected\n"); 177 - return -ENODEV; 178 - } 179 - if (!(dmi_match(DMI_PRODUCT_NAME, "APU") || 180 - dmi_match(DMI_PRODUCT_NAME, "APU2") || 181 - dmi_match(DMI_PRODUCT_NAME, "apu2") || 182 - dmi_match(DMI_PRODUCT_NAME, "PC Engines apu2") || 183 - dmi_match(DMI_PRODUCT_NAME, "APU3") || 184 - dmi_match(DMI_PRODUCT_NAME, "apu3") || 185 - dmi_match(DMI_PRODUCT_NAME, "PC Engines apu3"))) { 186 - pr_err("Unknown PC Engines board: %s\n", 187 - dmi_get_system_info(DMI_PRODUCT_NAME)); 294 + if (!(dmi_match(DMI_SYS_VENDOR, "PC Engines") && 295 + dmi_match(DMI_PRODUCT_NAME, "APU"))) { 296 + pr_err("No PC Engines APUv1 board detected. For APUv2,3 support, enable CONFIG_PCENGINES_APU2\n"); 188 297 return -ENODEV; 189 298 } 190 299 ··· 197 326 { 198 327 int i; 199 328 200 - for (i = 0; i < apu_led->num_led_instances; i++) 329 + for (i = 0; i < ARRAY_SIZE(apu1_led_profile); i++) 201 330 led_classdev_unregister(&apu_led->pled[i].cdev); 202 331 203 332 platform_device_unregister(apu_led->pdev); ··· 208 337 module_exit(apu_led_exit); 209 338 210 339 MODULE_AUTHOR("Alan Mizrahi"); 211 - MODULE_DESCRIPTION("PC Engines APU family LED driver"); 340 + MODULE_DESCRIPTION("PC Engines APU1 front LED driver"); 212 341 MODULE_LICENSE("GPL v2"); 213 342 MODULE_ALIAS("platform:leds_apu");
+28 -46
drivers/leds/leds-as3645a.c
··· 124 124 u32 peak; 125 125 }; 126 126 127 - struct as3645a_names { 128 - char flash[32]; 129 - char indicator[32]; 130 - }; 131 - 132 127 struct as3645a { 133 128 struct i2c_client *client; 134 129 ··· 479 484 } 480 485 481 486 static int as3645a_parse_node(struct as3645a *flash, 482 - struct as3645a_names *names, 483 487 struct fwnode_handle *fwnode) 484 488 { 485 489 struct as3645a_config *cfg = &flash->cfg; 486 490 struct fwnode_handle *child; 487 - const char *name; 488 491 int rval; 489 492 490 493 fwnode_for_each_child_node(fwnode, child) { ··· 508 515 if (!flash->flash_node) { 509 516 dev_err(&flash->client->dev, "can't find flash node\n"); 510 517 return -ENODEV; 511 - } 512 - 513 - rval = fwnode_property_read_string(flash->flash_node, "label", &name); 514 - if (!rval) { 515 - strlcpy(names->flash, name, sizeof(names->flash)); 516 - } else if (is_of_node(fwnode)) { 517 - snprintf(names->flash, sizeof(names->flash), 518 - "%pOFn:flash", to_of_node(fwnode)); 519 - } else { 520 - dev_err(&flash->client->dev, "flash node has no label!\n"); 521 - return -EINVAL; 522 518 } 523 519 524 520 rval = fwnode_property_read_u32(flash->flash_node, "flash-timeout-us", ··· 547 565 goto out_err; 548 566 } 549 567 550 - rval = fwnode_property_read_string(flash->indicator_node, "label", 551 - &name); 552 - if (!rval) { 553 - strlcpy(names->indicator, name, sizeof(names->indicator)); 554 - } else if (is_of_node(fwnode)) { 555 - snprintf(names->indicator, sizeof(names->indicator), 556 - "%pOFn:indicator", to_of_node(fwnode)); 557 - } else { 558 - dev_err(&flash->client->dev, "indicator node has no label!\n"); 559 - return -EINVAL; 560 - } 561 568 562 569 rval = fwnode_property_read_u32(flash->indicator_node, 563 570 "led-max-microamp", ··· 566 595 return rval; 567 596 } 568 597 569 - static int as3645a_led_class_setup(struct as3645a *flash, 570 - struct as3645a_names *names) 598 + static int as3645a_led_class_setup(struct as3645a *flash) 571 599 { 572 600 struct led_classdev *fled_cdev = &flash->fled.led_cdev; 573 601 struct led_classdev *iled_cdev = &flash->iled_cdev; 602 + struct led_init_data init_data = {}; 574 603 struct led_flash_setting *cfg; 575 604 int rval; 576 605 577 - iled_cdev->name = names->indicator; 578 606 iled_cdev->brightness_set_blocking = as3645a_set_indicator_brightness; 579 607 iled_cdev->max_brightness = 580 608 flash->cfg.indicator_max_ua / AS_INDICATOR_INTENSITY_STEP; 581 609 iled_cdev->flags = LED_CORE_SUSPENDRESUME; 582 610 583 - rval = led_classdev_register(&flash->client->dev, iled_cdev); 611 + init_data.fwnode = flash->indicator_node; 612 + init_data.devicename = AS_NAME; 613 + init_data.default_label = "indicator"; 614 + 615 + rval = led_classdev_register_ext(&flash->client->dev, iled_cdev, 616 + &init_data); 584 617 if (rval < 0) 585 618 return rval; 586 619 ··· 602 627 603 628 flash->fled.ops = &as3645a_led_flash_ops; 604 629 605 - fled_cdev->name = names->flash; 606 630 fled_cdev->brightness_set_blocking = as3645a_set_assist_brightness; 607 631 /* Value 0 is off in LED class. */ 608 632 fled_cdev->max_brightness = ··· 609 635 flash->cfg.assist_max_ua) + 1; 610 636 fled_cdev->flags = LED_DEV_CAP_FLASH | LED_CORE_SUSPENDRESUME; 611 637 612 - rval = led_classdev_flash_register(&flash->client->dev, &flash->fled); 613 - if (rval) { 614 - led_classdev_unregister(iled_cdev); 615 - dev_err(&flash->client->dev, 616 - "led_classdev_flash_register() failed, error %d\n", 617 - rval); 618 - } 638 + init_data.fwnode = flash->flash_node; 639 + init_data.devicename = AS_NAME; 640 + init_data.default_label = "flash"; 619 641 642 + rval = led_classdev_flash_register_ext(&flash->client->dev, 643 + &flash->fled, &init_data); 644 + if (rval) 645 + goto out_err; 646 + 647 + return rval; 648 + 649 + out_err: 650 + led_classdev_unregister(iled_cdev); 651 + dev_err(&flash->client->dev, 652 + "led_classdev_flash_register() failed, error %d\n", 653 + rval); 620 654 return rval; 621 655 } 622 656 ··· 649 667 }, 650 668 }; 651 669 652 - strlcpy(cfg.dev_name, led->name, sizeof(cfg.dev_name)); 653 - strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfg.dev_name)); 670 + strlcpy(cfg.dev_name, led->dev->kobj.name, sizeof(cfg.dev_name)); 671 + strlcpy(cfgind.dev_name, flash->iled_cdev.dev->kobj.name, 672 + sizeof(cfgind.dev_name)); 654 673 655 674 flash->vf = v4l2_flash_init( 656 675 &flash->client->dev, flash->flash_node, &flash->fled, NULL, ··· 672 689 673 690 static int as3645a_probe(struct i2c_client *client) 674 691 { 675 - struct as3645a_names names; 676 692 struct as3645a *flash; 677 693 int rval; 678 694 ··· 684 702 685 703 flash->client = client; 686 704 687 - rval = as3645a_parse_node(flash, &names, dev_fwnode(&client->dev)); 705 + rval = as3645a_parse_node(flash, dev_fwnode(&client->dev)); 688 706 if (rval < 0) 689 707 return rval; 690 708 ··· 699 717 if (rval) 700 718 goto out_mutex_destroy; 701 719 702 - rval = as3645a_led_class_setup(flash, &names); 720 + rval = as3645a_led_class_setup(flash); 703 721 if (rval) 704 722 goto out_mutex_destroy; 705 723
+11 -22
drivers/leds/leds-cr0014114.c
··· 8 8 #include <linux/of_device.h> 9 9 #include <linux/spi/spi.h> 10 10 #include <linux/workqueue.h> 11 - #include <uapi/linux/uleds.h> 12 11 13 12 /* 14 13 * CR0014114 SPI protocol descrtiption: ··· 39 40 #define CR_FW_DELAY_MSEC 10 40 41 #define CR_RECOUNT_DELAY (HZ * 3600) 41 42 43 + #define CR_DEV_NAME "cr0014114" 44 + 42 45 struct cr0014114_led { 43 - char name[LED_MAX_NAME_SIZE]; 44 46 struct cr0014114 *priv; 45 47 struct led_classdev ldev; 46 48 u8 brightness; ··· 167 167 struct cr0014114_led, 168 168 ldev); 169 169 170 - dev_dbg(led->priv->dev, "Set brightness of %s to %d\n", 171 - led->name, brightness); 170 + dev_dbg(led->priv->dev, "Set brightness to %d\n", brightness); 172 171 173 172 mutex_lock(&led->priv->lock); 174 173 led->brightness = (u8)brightness; ··· 182 183 size_t i = 0; 183 184 struct cr0014114_led *led; 184 185 struct fwnode_handle *child; 185 - struct device_node *np; 186 + struct led_init_data init_data = {}; 186 187 int ret; 187 - const char *str; 188 188 189 189 device_for_each_child_node(priv->dev, child) { 190 - np = to_of_node(child); 191 190 led = &priv->leds[i]; 192 - 193 - ret = fwnode_property_read_string(child, "label", &str); 194 - if (ret) 195 - snprintf(led->name, sizeof(led->name), 196 - "cr0014114::"); 197 - else 198 - snprintf(led->name, sizeof(led->name), 199 - "cr0014114:%s", str); 200 191 201 192 fwnode_property_read_string(child, "linux,default-trigger", 202 193 &led->ldev.default_trigger); 203 194 204 195 led->priv = priv; 205 - led->ldev.name = led->name; 206 196 led->ldev.max_brightness = CR_MAX_BRIGHTNESS; 207 197 led->ldev.brightness_set_blocking = cr0014114_set_sync; 208 198 209 - ret = devm_of_led_classdev_register(priv->dev, np, 210 - &led->ldev); 199 + init_data.fwnode = child; 200 + init_data.devicename = CR_DEV_NAME; 201 + init_data.default_label = ":"; 202 + 203 + ret = devm_led_classdev_register_ext(priv->dev, &led->ldev, 204 + &init_data); 211 205 if (ret) { 212 206 dev_err(priv->dev, 213 - "failed to register LED device %s, err %d", 214 - led->name, ret); 207 + "failed to register LED device, err %d", ret); 215 208 fwnode_handle_put(child); 216 209 return ret; 217 210 } 218 - 219 - led->ldev.dev->of_node = np; 220 211 221 212 i++; 222 213 }
+13 -13
drivers/leds/leds-gpio.c
··· 73 73 74 74 static int create_gpio_led(const struct gpio_led *template, 75 75 struct gpio_led_data *led_dat, struct device *parent, 76 - struct device_node *np, gpio_blink_set_t blink_set) 76 + struct fwnode_handle *fwnode, gpio_blink_set_t blink_set) 77 77 { 78 + struct led_init_data init_data = {}; 78 79 int ret, state; 79 80 80 - led_dat->cdev.name = template->name; 81 81 led_dat->cdev.default_trigger = template->default_trigger; 82 82 led_dat->can_sleep = gpiod_cansleep(led_dat->gpiod); 83 83 if (!led_dat->can_sleep) ··· 108 108 if (ret < 0) 109 109 return ret; 110 110 111 - return devm_of_led_classdev_register(parent, np, &led_dat->cdev); 111 + if (template->name) { 112 + led_dat->cdev.name = template->name; 113 + ret = devm_led_classdev_register(parent, &led_dat->cdev); 114 + } else { 115 + init_data.fwnode = fwnode; 116 + ret = devm_led_classdev_register_ext(parent, &led_dat->cdev, 117 + &init_data); 118 + } 119 + 120 + return ret; 112 121 } 113 122 114 123 struct gpio_leds_priv { ··· 150 141 struct gpio_led_data *led_dat = &priv->leds[priv->num_leds]; 151 142 struct gpio_led led = {}; 152 143 const char *state = NULL; 153 - struct device_node *np = to_of_node(child); 154 - 155 - ret = fwnode_property_read_string(child, "label", &led.name); 156 - if (ret && IS_ENABLED(CONFIG_OF) && np) 157 - led.name = np->name; 158 - if (!led.name) { 159 - fwnode_handle_put(child); 160 - return ERR_PTR(-EINVAL); 161 - } 162 144 163 145 led.gpiod = devm_fwnode_get_gpiod_from_child(dev, NULL, child, 164 146 GPIOD_ASIS, ··· 181 181 if (fwnode_property_present(child, "panic-indicator")) 182 182 led.panic_indicator = 1; 183 183 184 - ret = create_gpio_led(&led, led_dat, dev, np, NULL); 184 + ret = create_gpio_led(&led, led_dat, dev, child, NULL); 185 185 if (ret < 0) { 186 186 fwnode_handle_put(child); 187 187 return ERR_PTR(ret);
+1 -2
drivers/leds/leds-is31fl319x.c
··· 333 333 { 334 334 struct is31fl319x_chip *is31; 335 335 struct device *dev = &client->dev; 336 - struct i2c_adapter *adapter = to_i2c_adapter(dev->parent); 337 336 int err; 338 337 int i = 0; 339 338 u32 aggregated_led_microamp = IS31FL319X_CURRENT_MAX; 340 339 341 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) 340 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 342 341 return -EIO; 343 342 344 343 is31 = devm_kzalloc(&client->dev, sizeof(*is31), GFP_KERNEL);
+1 -7
drivers/leds/leds-is31fl32xx.c
··· 324 324 return 0; 325 325 } 326 326 327 - static inline size_t sizeof_is31fl32xx_priv(int num_leds) 328 - { 329 - return sizeof(struct is31fl32xx_priv) + 330 - (sizeof(struct is31fl32xx_led_data) * num_leds); 331 - } 332 - 333 327 static int is31fl32xx_parse_child_dt(const struct device *dev, 334 328 const struct device_node *child, 335 329 struct is31fl32xx_led_data *led_data) ··· 444 450 if (!count) 445 451 return -EINVAL; 446 452 447 - priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), 453 + priv = devm_kzalloc(dev, struct_size(priv, leds, count), 448 454 GFP_KERNEL); 449 455 if (!priv) 450 456 return -ENOMEM;
+2 -2
drivers/leds/leds-ktd2692.c
··· 19 19 /* Value related the movie mode */ 20 20 #define KTD2692_MOVIE_MODE_CURRENT_LEVELS 16 21 21 #define KTD2692_MM_TO_FL_RATIO(x) ((x) / 3) 22 - #define KTD2962_MM_MIN_CURR_THRESHOLD_SCALE 8 22 + #define KTD2692_MM_MIN_CURR_THRESHOLD_SCALE 8 23 23 24 24 /* Value related the flash mode */ 25 25 #define KTD2692_FLASH_MODE_TIMEOUT_LEVELS 8 ··· 250 250 ktd2692_expresswire_reset(led); 251 251 gpiod_direction_output(led->aux_gpio, KTD2692_LOW); 252 252 253 - ktd2692_expresswire_write(led, (KTD2962_MM_MIN_CURR_THRESHOLD_SCALE - 1) 253 + ktd2692_expresswire_write(led, (KTD2692_MM_MIN_CURR_THRESHOLD_SCALE - 1) 254 254 | KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE); 255 255 ktd2692_expresswire_write(led, KTD2692_FLASH_MODE_CURR_PERCENT(45) 256 256 | KTD2692_REG_FLASH_CURRENT_BASE);
+105 -33
drivers/leds/leds-lm3532.c
··· 23 23 #define LM3532_REG_PWM_B_CFG 0x14 24 24 #define LM3532_REG_PWM_C_CFG 0x15 25 25 #define LM3532_REG_ZONE_CFG_A 0x16 26 - #define LM3532_REG_CTRL_A_BRT 0x17 26 + #define LM3532_REG_CTRL_A_FS_CURR 0x17 27 27 #define LM3532_REG_ZONE_CFG_B 0x18 28 - #define LM3532_REG_CTRL_B_BRT 0x19 28 + #define LM3532_REG_CTRL_B_FS_CURR 0x19 29 29 #define LM3532_REG_ZONE_CFG_C 0x1a 30 - #define LM3532_REG_CTRL_C_BRT 0x1b 30 + #define LM3532_REG_CTRL_C_FS_CURR 0x1b 31 31 #define LM3532_REG_ENABLE 0x1d 32 32 #define LM3532_ALS_CONFIG 0x23 33 33 #define LM3532_REG_ZN_0_HI 0x60 ··· 38 38 #define LM3532_REG_ZN_2_LO 0x65 39 39 #define LM3532_REG_ZN_3_HI 0x66 40 40 #define LM3532_REG_ZN_3_LO 0x67 41 + #define LM3532_REG_ZONE_TRGT_A 0x70 42 + #define LM3532_REG_ZONE_TRGT_B 0x75 43 + #define LM3532_REG_ZONE_TRGT_C 0x7a 41 44 #define LM3532_REG_MAX 0x7e 42 45 43 - /* Contorl Enable */ 46 + /* Control Enable */ 44 47 #define LM3532_CTRL_A_ENABLE BIT(0) 45 48 #define LM3532_CTRL_B_ENABLE BIT(1) 46 49 #define LM3532_CTRL_C_ENABLE BIT(2) ··· 89 86 #define LM3532_NUM_AVG_VALS 8 90 87 #define LM3532_NUM_IMP_VALS 32 91 88 89 + #define LM3532_FS_CURR_MIN 5000 90 + #define LM3532_FS_CURR_MAX 29800 91 + #define LM3532_FS_CURR_STEP 800 92 + 92 93 /* 93 94 * struct lm3532_als_data 94 95 * @config - value of ALS configuration register ··· 123 116 * @priv - Pointer the device data structure 124 117 * @control_bank - Control bank the LED is associated to 125 118 * @mode - Mode of the LED string 119 + * @ctrl_brt_pointer - Zone target register that controls the sink 126 120 * @num_leds - Number of LED strings are supported in this array 121 + * @full_scale_current - The full-scale current setting for the current sink. 127 122 * @led_strings - The LED strings supported in this array 123 + * @enabled - Enabled status 128 124 * @label - LED label 129 125 */ 130 126 struct lm3532_led { ··· 136 126 137 127 int control_bank; 138 128 int mode; 129 + int ctrl_brt_pointer; 139 130 int num_leds; 131 + int full_scale_current; 132 + int enabled:1; 140 133 u32 led_strings[LM3532_MAX_CONTROL_BANKS]; 141 134 char label[LED_MAX_NAME_SIZE]; 142 135 }; ··· 181 168 {LM3532_REG_PWM_B_CFG, 0x82}, 182 169 {LM3532_REG_PWM_C_CFG, 0x82}, 183 170 {LM3532_REG_ZONE_CFG_A, 0xf1}, 184 - {LM3532_REG_CTRL_A_BRT, 0xf3}, 171 + {LM3532_REG_CTRL_A_FS_CURR, 0xf3}, 185 172 {LM3532_REG_ZONE_CFG_B, 0xf1}, 186 - {LM3532_REG_CTRL_B_BRT, 0xf3}, 173 + {LM3532_REG_CTRL_B_FS_CURR, 0xf3}, 187 174 {LM3532_REG_ZONE_CFG_C, 0xf1}, 188 - {LM3532_REG_CTRL_C_BRT, 0xf3}, 175 + {LM3532_REG_CTRL_C_FS_CURR, 0xf3}, 189 176 {LM3532_REG_ENABLE, 0xf8}, 190 177 {LM3532_ALS_CONFIG, 0x44}, 191 178 {LM3532_REG_ZN_0_HI, 0x35}, ··· 208 195 .cache_type = REGCACHE_FLAT, 209 196 }; 210 197 211 - const static int als_imp_table[LM3532_NUM_IMP_VALS] = {37000, 18500, 12330, 198 + static const int als_imp_table[LM3532_NUM_IMP_VALS] = {37000, 18500, 12330, 212 199 92500, 7400, 6170, 5290, 213 200 4630, 4110, 3700, 3360, 214 201 3080, 2850, 2640, 2440, ··· 265 252 return -EINVAL; 266 253 } 267 254 268 - const static int als_avrg_table[LM3532_NUM_AVG_VALS] = {17920, 35840, 71680, 255 + static const int als_avrg_table[LM3532_NUM_AVG_VALS] = {17920, 35840, 71680, 269 256 1433360, 286720, 573440, 270 257 1146880, 2293760}; 271 258 static int lm3532_get_als_avg_index(int avg_time) ··· 280 267 avg_time); 281 268 } 282 269 283 - const static int ramp_table[LM3532_NUM_RAMP_VALS] = { 8, 1024, 2048, 4096, 8192, 270 + static const int ramp_table[LM3532_NUM_RAMP_VALS] = { 8, 1024, 2048, 4096, 8192, 284 271 16384, 32768, 65536}; 285 272 static int lm3532_get_ramp_index(int ramp_time) 286 273 { ··· 294 281 ramp_time); 295 282 } 296 283 284 + /* Caller must take care of locking */ 297 285 static int lm3532_led_enable(struct lm3532_led *led_data) 298 286 { 299 287 int ctrl_en_val = BIT(led_data->control_bank); 300 288 int ret; 289 + 290 + if (led_data->enabled) 291 + return 0; 301 292 302 293 ret = regmap_update_bits(led_data->priv->regmap, LM3532_REG_ENABLE, 303 294 ctrl_en_val, ctrl_en_val); ··· 310 293 return ret; 311 294 } 312 295 313 - return regulator_enable(led_data->priv->regulator); 296 + ret = regulator_enable(led_data->priv->regulator); 297 + if (ret < 0) 298 + return ret; 299 + 300 + led_data->enabled = 1; 301 + 302 + return 0; 314 303 } 315 304 305 + /* Caller must take care of locking */ 316 306 static int lm3532_led_disable(struct lm3532_led *led_data) 317 307 { 318 308 int ctrl_en_val = BIT(led_data->control_bank); 319 309 int ret; 320 310 311 + if (!led_data->enabled) 312 + return 0; 313 + 321 314 ret = regmap_update_bits(led_data->priv->regmap, LM3532_REG_ENABLE, 322 - ctrl_en_val, ~ctrl_en_val); 315 + ctrl_en_val, 0); 323 316 if (ret) { 324 317 dev_err(led_data->priv->dev, "Failed to set ctrl:%d\n", ret); 325 318 return ret; 326 319 } 327 320 328 - return regulator_disable(led_data->priv->regulator); 321 + ret = regulator_disable(led_data->priv->regulator); 322 + if (ret < 0) 323 + return ret; 324 + 325 + led_data->enabled = 0; 326 + 327 + return 0; 329 328 } 330 329 331 330 static int lm3532_brightness_set(struct led_classdev *led_cdev, ··· 354 321 355 322 mutex_lock(&led->priv->lock); 356 323 357 - if (led->mode == LM3532_BL_MODE_ALS) { 324 + if (led->mode == LM3532_ALS_CTRL) { 358 325 if (brt_val > LED_OFF) 359 326 ret = lm3532_led_enable(led); 360 327 else ··· 372 339 if (ret) 373 340 goto unlock; 374 341 375 - brightness_reg = LM3532_REG_CTRL_A_BRT + led->control_bank * 2; 376 - brt_val = brt_val / LM3532_BRT_VAL_ADJUST; 342 + brightness_reg = LM3532_REG_ZONE_TRGT_A + led->control_bank * 5 + 343 + (led->ctrl_brt_pointer >> 2); 377 344 378 345 ret = regmap_write(led->priv->regmap, brightness_reg, brt_val); 379 346 ··· 389 356 unsigned int output_cfg_val = 0; 390 357 unsigned int output_cfg_shift = 0; 391 358 unsigned int output_cfg_mask = 0; 359 + unsigned int brightness_config_reg; 360 + unsigned int brightness_config_val; 361 + int fs_current_reg; 362 + int fs_current_val; 392 363 int ret, i; 364 + 365 + if (drvdata->enable_gpio) 366 + gpiod_direction_output(drvdata->enable_gpio, 1); 367 + 368 + brightness_config_reg = LM3532_REG_ZONE_CFG_A + led->control_bank * 2; 369 + /* 370 + * This could be hard coded to the default value but the control 371 + * brightness register may have changed during boot. 372 + */ 373 + ret = regmap_read(drvdata->regmap, brightness_config_reg, 374 + &led->ctrl_brt_pointer); 375 + if (ret) 376 + return ret; 377 + 378 + led->ctrl_brt_pointer &= LM3532_ZONE_MASK; 379 + brightness_config_val = led->ctrl_brt_pointer | led->mode; 380 + ret = regmap_write(drvdata->regmap, brightness_config_reg, 381 + brightness_config_val); 382 + if (ret) 383 + return ret; 384 + 385 + if (led->full_scale_current) { 386 + fs_current_reg = LM3532_REG_CTRL_A_FS_CURR + led->control_bank * 2; 387 + fs_current_val = (led->full_scale_current - LM3532_FS_CURR_MIN) / 388 + LM3532_FS_CURR_STEP; 389 + 390 + ret = regmap_write(drvdata->regmap, fs_current_reg, 391 + fs_current_val); 392 + if (ret) 393 + return ret; 394 + } 393 395 394 396 for (i = 0; i < led->num_leds; i++) { 395 397 output_cfg_shift = led->led_strings[i] * 2; ··· 450 382 struct lm3532_als_data *als = priv->als_data; 451 383 u32 als_vmin, als_vmax, als_vstep; 452 384 int zone_reg = LM3532_REG_ZN_0_HI; 453 - int brightnes_config_reg; 454 385 int ret; 455 386 int i; 456 387 ··· 478 411 als->config = (als->als_avrg_time | (LM3532_ENABLE_ALS) | 479 412 (als->als_input_mode << LM3532_ALS_SEL_SHIFT)); 480 413 481 - ret = regmap_write(priv->regmap, LM3532_ALS_CONFIG, als->config); 482 - if (ret) 483 - return ret; 484 - 485 - brightnes_config_reg = LM3532_REG_ZONE_CFG_A + led->control_bank * 2; 486 - 487 - return regmap_update_bits(priv->regmap, brightnes_config_reg, 488 - LM3532_I2C_CTRL, LM3532_ALS_CTRL); 414 + return regmap_write(priv->regmap, LM3532_ALS_CONFIG, als->config); 489 415 } 490 416 491 417 static int lm3532_parse_als(struct lm3532_data *priv) ··· 601 541 goto child_out; 602 542 } 603 543 544 + if (fwnode_property_present(child, "led-max-microamp") && 545 + fwnode_property_read_u32(child, "led-max-microamp", 546 + &led->full_scale_current)) 547 + dev_err(&priv->client->dev, 548 + "Failed getting led-max-microamp\n"); 549 + else 550 + led->full_scale_current = min(led->full_scale_current, 551 + LM3532_FS_CURR_MAX); 552 + 604 553 if (led->mode == LM3532_BL_MODE_ALS) { 554 + led->mode = LM3532_ALS_CTRL; 605 555 ret = lm3532_parse_als(priv); 606 556 if (ret) 607 557 dev_err(&priv->client->dev, "Failed to parse als\n"); 608 558 else 609 559 lm3532_als_configure(priv, led); 560 + } else { 561 + led->mode = LM3532_I2C_CTRL; 610 562 } 611 563 612 - led->num_leds = fwnode_property_read_u32_array(child, 613 - "led-sources", 614 - NULL, 0); 615 - 564 + led->num_leds = fwnode_property_count_u32(child, "led-sources"); 616 565 if (led->num_leds > LM3532_MAX_LED_STRINGS) { 617 566 dev_err(&priv->client->dev, "To many LED string defined\n"); 618 567 continue; ··· 659 590 goto child_out; 660 591 } 661 592 662 - lm3532_init_registers(led); 593 + ret = lm3532_init_registers(led); 594 + if (ret) { 595 + dev_err(&priv->client->dev, "register init err: %d\n", 596 + ret); 597 + fwnode_handle_put(child); 598 + goto child_out; 599 + } 663 600 664 601 i++; 665 602 } ··· 711 636 dev_err(&client->dev, "Failed to parse node\n"); 712 637 return ret; 713 638 } 714 - 715 - if (drvdata->enable_gpio) 716 - gpiod_direction_output(drvdata->enable_gpio, 1); 717 639 718 640 return ret; 719 641 }
+17 -21
drivers/leds/leds-lm3601x.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/regmap.h> 12 12 #include <linux/slab.h> 13 - #include <uapi/linux/uleds.h> 14 13 15 14 #define LM3601X_LED_IR 0x0 16 15 #define LM3601X_LED_TORCH 0x1 ··· 88 89 struct i2c_client *client; 89 90 struct regmap *regmap; 90 91 struct mutex lock; 91 - 92 - char led_name[LED_MAX_NAME_SIZE]; 93 92 94 93 unsigned int flash_timeout; 95 94 unsigned int last_flag; ··· 319 322 .fault_get = lm3601x_flash_fault_get, 320 323 }; 321 324 322 - static int lm3601x_register_leds(struct lm3601x_led *led) 325 + static int lm3601x_register_leds(struct lm3601x_led *led, 326 + struct fwnode_handle *fwnode) 323 327 { 324 328 struct led_classdev *led_cdev; 325 329 struct led_flash_setting *setting; 330 + struct led_init_data init_data = {}; 326 331 327 332 led->fled_cdev.ops = &flash_ops; 328 333 ··· 341 342 setting->val = led->flash_current_max; 342 343 343 344 led_cdev = &led->fled_cdev.led_cdev; 344 - led_cdev->name = led->led_name; 345 345 led_cdev->brightness_set_blocking = lm3601x_brightness_set; 346 346 led_cdev->max_brightness = DIV_ROUND_UP(led->torch_current_max, 347 347 LM3601X_TORCH_REG_DIV); 348 348 led_cdev->flags |= LED_DEV_CAP_FLASH; 349 349 350 - return led_classdev_flash_register(&led->client->dev, &led->fled_cdev); 350 + init_data.fwnode = fwnode; 351 + init_data.devicename = led->client->name; 352 + init_data.default_label = (led->led_mode == LM3601X_LED_TORCH) ? 353 + "torch" : "infrared"; 354 + 355 + return led_classdev_flash_register_ext(&led->client->dev, 356 + &led->fled_cdev, &init_data); 351 357 } 352 358 353 - static int lm3601x_parse_node(struct lm3601x_led *led) 359 + static int lm3601x_parse_node(struct lm3601x_led *led, 360 + struct fwnode_handle **fwnode) 354 361 { 355 362 struct fwnode_handle *child = NULL; 356 363 int ret = -ENODEV; 357 - const char *name; 358 364 359 365 child = device_get_next_child_node(&led->client->dev, child); 360 366 if (!child) { ··· 379 375 ret = -EINVAL; 380 376 goto out_err; 381 377 } 382 - 383 - ret = fwnode_property_read_string(child, "label", &name); 384 - if (ret) { 385 - if (led->led_mode == LM3601X_LED_TORCH) 386 - name = "torch"; 387 - else 388 - name = "infrared"; 389 - } 390 - 391 - snprintf(led->led_name, sizeof(led->led_name), 392 - "%s:%s", led->client->name, name); 393 378 394 379 ret = fwnode_property_read_u32(child, "led-max-microamp", 395 380 &led->torch_current_max); ··· 404 411 goto out_err; 405 412 } 406 413 414 + *fwnode = child; 415 + 407 416 out_err: 408 417 fwnode_handle_put(child); 409 418 return ret; ··· 414 419 static int lm3601x_probe(struct i2c_client *client) 415 420 { 416 421 struct lm3601x_led *led; 422 + struct fwnode_handle *fwnode; 417 423 int ret; 418 424 419 425 led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); ··· 424 428 led->client = client; 425 429 i2c_set_clientdata(client, led); 426 430 427 - ret = lm3601x_parse_node(led); 431 + ret = lm3601x_parse_node(led, &fwnode); 428 432 if (ret) 429 433 return -ENODEV; 430 434 ··· 438 442 439 443 mutex_init(&led->lock); 440 444 441 - return lm3601x_register_leds(led); 445 + return lm3601x_register_leds(led, fwnode); 442 446 } 443 447 444 448 static int lm3601x_remove(struct i2c_client *client)
+1 -3
drivers/leds/leds-lm36274.c
··· 90 90 snprintf(label, sizeof(label), 91 91 "%s:%s", lm36274_data->pdev->name, name); 92 92 93 - lm36274_data->num_leds = fwnode_property_read_u32_array(child, 94 - "led-sources", 95 - NULL, 0); 93 + lm36274_data->num_leds = fwnode_property_count_u32(child, "led-sources"); 96 94 if (lm36274_data->num_leds <= 0) 97 95 return -ENODEV; 98 96
+6 -16
drivers/leds/leds-lm3692x.c
··· 13 13 #include <linux/regmap.h> 14 14 #include <linux/regulator/consumer.h> 15 15 #include <linux/slab.h> 16 - #include <uapi/linux/uleds.h> 17 16 18 17 #define LM36922_MODEL 0 19 18 #define LM36923_MODEL 1 ··· 102 103 * @regmap - Devices register map 103 104 * @enable_gpio - VDDIO/EN gpio to enable communication interface 104 105 * @regulator - LED supply regulator pointer 105 - * @label - LED label 106 106 * @led_enable - LED sync to be enabled 107 107 * @model_id - Current device model ID enumerated 108 108 */ ··· 112 114 struct regmap *regmap; 113 115 struct gpio_desc *enable_gpio; 114 116 struct regulator *regulator; 115 - char label[LED_MAX_NAME_SIZE]; 116 117 int led_enable; 117 118 int model_id; 118 119 }; ··· 322 325 static int lm3692x_probe_dt(struct lm3692x_led *led) 323 326 { 324 327 struct fwnode_handle *child = NULL; 325 - const char *name; 328 + struct led_init_data init_data = {}; 326 329 int ret; 327 330 328 331 led->enable_gpio = devm_gpiod_get_optional(&led->client->dev, ··· 347 350 fwnode_property_read_string(child, "linux,default-trigger", 348 351 &led->led_dev.default_trigger); 349 352 350 - ret = fwnode_property_read_string(child, "label", &name); 351 - if (ret) 352 - snprintf(led->label, sizeof(led->label), 353 - "%s::", led->client->name); 354 - else 355 - snprintf(led->label, sizeof(led->label), 356 - "%s:%s", led->client->name, name); 357 - 358 353 ret = fwnode_property_read_u32(child, "reg", &led->led_enable); 359 354 if (ret) { 360 355 dev_err(&led->client->dev, "reg DT property missing\n"); 361 356 return ret; 362 357 } 363 358 364 - led->led_dev.name = led->label; 359 + init_data.fwnode = child; 360 + init_data.devicename = led->client->name; 361 + init_data.default_label = ":"; 365 362 366 - ret = devm_led_classdev_register(&led->client->dev, &led->led_dev); 363 + ret = devm_led_classdev_register_ext(&led->client->dev, &led->led_dev, 364 + &init_data); 367 365 if (ret) { 368 366 dev_err(&led->client->dev, "led register err: %d\n", ret); 369 367 return ret; 370 368 } 371 - 372 - led->led_dev.dev->of_node = to_of_node(child); 373 369 374 370 return 0; 375 371 }
+1 -4
drivers/leds/leds-lm3697.c
··· 244 244 led->lmu_data.lsb_brightness_reg = LM3697_CTRL_A_BRT_LSB + 245 245 led->control_bank * 2; 246 246 247 - led->num_leds = fwnode_property_read_u32_array(child, 248 - "led-sources", 249 - NULL, 0); 250 - 247 + led->num_leds = fwnode_property_count_u32(child, "led-sources"); 251 248 if (led->num_leds > LM3697_MAX_LED_STRINGS) { 252 249 dev_err(&priv->client->dev, "To many LED strings defined\n"); 253 250 continue;
+5 -1
drivers/leds/leds-lp5562.c
··· 260 260 { 261 261 const struct firmware *fw = chip->fw; 262 262 263 - if (fw->size > LP5562_PROGRAM_LENGTH) { 263 + /* 264 + * the firmware is encoded in ascii hex character, with 2 chars 265 + * per byte 266 + */ 267 + if (fw->size > (LP5562_PROGRAM_LENGTH * 2)) { 264 268 dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", 265 269 fw->size); 266 270 return;
+15 -18
drivers/leds/leds-lp8860.c
··· 18 18 #include <linux/of_gpio.h> 19 19 #include <linux/gpio/consumer.h> 20 20 #include <linux/slab.h> 21 - #include <uapi/linux/uleds.h> 22 21 23 22 #define LP8860_DISP_CL1_BRT_MSB 0x00 24 23 #define LP8860_DISP_CL1_BRT_LSB 0x01 ··· 82 83 83 84 #define LP8860_CLEAR_FAULTS 0x01 84 85 86 + #define LP8860_NAME "lp8860" 87 + 85 88 /** 86 89 * struct lp8860_led - 87 90 * @lock - Lock for reading/writing the device ··· 93 92 * @eeprom_regmap - EEPROM register map 94 93 * @enable_gpio - VDDIO/EN gpio to enable communication interface 95 94 * @regulator - LED supply regulator pointer 96 - * @label - LED label 97 95 */ 98 96 struct lp8860_led { 99 97 struct mutex lock; ··· 102 102 struct regmap *eeprom_regmap; 103 103 struct gpio_desc *enable_gpio; 104 104 struct regulator *regulator; 105 - char label[LED_MAX_NAME_SIZE]; 106 105 }; 107 106 108 107 struct lp8860_eeprom_reg { ··· 382 383 struct lp8860_led *led; 383 384 struct device_node *np = client->dev.of_node; 384 385 struct device_node *child_node; 385 - const char *name; 386 + struct led_init_data init_data = {}; 386 387 387 388 led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); 388 389 if (!led) 389 390 return -ENOMEM; 390 391 391 - for_each_available_child_of_node(np, child_node) { 392 - led->led_dev.default_trigger = of_get_property(child_node, 393 - "linux,default-trigger", 394 - NULL); 392 + child_node = of_get_next_available_child(np, NULL); 393 + if (!child_node) 394 + return -EINVAL; 395 395 396 - ret = of_property_read_string(child_node, "label", &name); 397 - if (!ret) 398 - snprintf(led->label, sizeof(led->label), "%s:%s", 399 - id->name, name); 400 - else 401 - snprintf(led->label, sizeof(led->label), 402 - "%s::display_cluster", id->name); 403 - } 396 + led->led_dev.default_trigger = of_get_property(child_node, 397 + "linux,default-trigger", 398 + NULL); 404 399 405 400 led->enable_gpio = devm_gpiod_get_optional(&client->dev, 406 401 "enable", GPIOD_OUT_LOW); ··· 409 416 led->regulator = NULL; 410 417 411 418 led->client = client; 412 - led->led_dev.name = led->label; 413 419 led->led_dev.brightness_set_blocking = lp8860_brightness_set; 414 420 415 421 mutex_init(&led->lock); ··· 435 443 if (ret) 436 444 return ret; 437 445 438 - ret = devm_led_classdev_register(&client->dev, &led->led_dev); 446 + init_data.fwnode = of_fwnode_handle(child_node); 447 + init_data.devicename = LP8860_NAME; 448 + init_data.default_label = ":display_cluster"; 449 + 450 + ret = devm_led_classdev_register_ext(&client->dev, &led->led_dev, 451 + &init_data); 439 452 if (ret) { 440 453 dev_err(&client->dev, "led register err: %d\n", ret); 441 454 return ret;
+8 -12
drivers/leds/leds-lt3593.c
··· 10 10 #include <linux/slab.h> 11 11 #include <linux/module.h> 12 12 #include <linux/of.h> 13 - #include <uapi/linux/uleds.h> 13 + 14 + #define LED_LT3593_NAME "lt3593" 14 15 15 16 struct lt3593_led_data { 16 - char name[LED_MAX_NAME_SIZE]; 17 17 struct led_classdev cdev; 18 18 struct gpio_desc *gpiod; 19 19 }; ··· 66 66 struct lt3593_led_data *led_data; 67 67 struct fwnode_handle *child; 68 68 int ret, state = LEDS_GPIO_DEFSTATE_OFF; 69 + struct led_init_data init_data = {}; 69 70 const char *tmp; 70 71 71 72 if (!dev->of_node) ··· 87 86 88 87 child = device_get_next_child_node(dev, NULL); 89 88 90 - ret = fwnode_property_read_string(child, "label", &tmp); 91 - if (ret < 0) 92 - snprintf(led_data->name, sizeof(led_data->name), 93 - "lt3593::"); 94 - else 95 - snprintf(led_data->name, sizeof(led_data->name), 96 - "lt3593:%s", tmp); 97 - 98 89 fwnode_property_read_string(child, "linux,default-trigger", 99 90 &led_data->cdev.default_trigger); 100 91 ··· 95 102 state = LEDS_GPIO_DEFSTATE_ON; 96 103 } 97 104 98 - led_data->cdev.name = led_data->name; 99 105 led_data->cdev.brightness_set_blocking = lt3593_led_set; 100 106 led_data->cdev.brightness = state ? LED_FULL : LED_OFF; 101 107 102 - ret = devm_led_classdev_register(dev, &led_data->cdev); 108 + init_data.fwnode = child; 109 + init_data.devicename = LED_LT3593_NAME; 110 + init_data.default_label = ":"; 111 + 112 + ret = devm_led_classdev_register_ext(dev, &led_data->cdev, &init_data); 103 113 if (ret < 0) { 104 114 fwnode_handle_put(child); 105 115 return ret;
+24 -20
drivers/leds/leds-max77650.c
··· 62 62 63 63 static int max77650_led_probe(struct platform_device *pdev) 64 64 { 65 - struct device_node *of_node, *child; 65 + struct fwnode_handle *child; 66 66 struct max77650_led *leds, *led; 67 67 struct device *dev; 68 68 struct regmap *map; ··· 71 71 u32 reg; 72 72 73 73 dev = &pdev->dev; 74 - of_node = dev->of_node; 75 - 76 - if (!of_node) 77 - return -ENODEV; 78 74 79 75 leds = devm_kcalloc(dev, sizeof(*leds), 80 76 MAX77650_LED_NUM_LEDS, GFP_KERNEL); ··· 81 85 if (!map) 82 86 return -ENODEV; 83 87 84 - num_leds = of_get_child_count(of_node); 88 + num_leds = device_get_child_node_count(dev); 85 89 if (!num_leds || num_leds > MAX77650_LED_NUM_LEDS) 86 90 return -ENODEV; 87 91 88 - for_each_child_of_node(of_node, child) { 89 - rv = of_property_read_u32(child, "reg", &reg); 90 - if (rv || reg >= MAX77650_LED_NUM_LEDS) 91 - return -EINVAL; 92 + device_for_each_child_node(dev, child) { 93 + rv = fwnode_property_read_u32(child, "reg", &reg); 94 + if (rv || reg >= MAX77650_LED_NUM_LEDS) { 95 + rv = -EINVAL; 96 + goto err_node_put; 97 + } 92 98 93 99 led = &leds[reg]; 94 100 led->map = map; ··· 99 101 led->cdev.brightness_set_blocking = max77650_led_brightness_set; 100 102 led->cdev.max_brightness = MAX77650_LED_MAX_BRIGHTNESS; 101 103 102 - label = of_get_property(child, "label", NULL); 103 - if (!label) { 104 + rv = fwnode_property_read_string(child, "label", &label); 105 + if (rv) { 104 106 led->cdev.name = "max77650::"; 105 107 } else { 106 108 led->cdev.name = devm_kasprintf(dev, GFP_KERNEL, 107 109 "max77650:%s", label); 108 - if (!led->cdev.name) 109 - return -ENOMEM; 110 + if (!led->cdev.name) { 111 + rv = -ENOMEM; 112 + goto err_node_put; 113 + } 110 114 } 111 115 112 - of_property_read_string(child, "linux,default-trigger", 113 - &led->cdev.default_trigger); 116 + fwnode_property_read_string(child, "linux,default-trigger", 117 + &led->cdev.default_trigger); 114 118 115 - rv = devm_of_led_classdev_register(dev, child, &led->cdev); 119 + rv = devm_led_classdev_register(dev, &led->cdev); 116 120 if (rv) 117 - return rv; 121 + goto err_node_put; 118 122 119 123 rv = regmap_write(map, led->regA, MAX77650_LED_A_DEFAULT); 120 124 if (rv) 121 - return rv; 125 + goto err_node_put; 122 126 123 127 rv = regmap_write(map, led->regB, MAX77650_LED_B_DEFAULT); 124 128 if (rv) 125 - return rv; 129 + goto err_node_put; 126 130 } 127 131 128 132 return regmap_write(map, 129 133 MAX77650_REG_CNFG_LED_TOP, 130 134 MAX77650_LED_TOP_DEFAULT); 135 + err_node_put: 136 + fwnode_handle_put(child); 137 + return rv; 131 138 } 132 139 133 140 static struct platform_driver max77650_led_driver = { ··· 146 143 MODULE_DESCRIPTION("MAXIM 77650/77651 LED driver"); 147 144 MODULE_AUTHOR("Bartosz Golaszewski <bgolaszewski@baylibre.com>"); 148 145 MODULE_LICENSE("GPL v2"); 146 + MODULE_ALIAS("platform:max77650-led");
+54 -22
drivers/leds/leds-netxbig.c
··· 15 15 #include <linux/gpio.h> 16 16 #include <linux/of_gpio.h> 17 17 #include <linux/leds.h> 18 - #include <linux/platform_data/leds-kirkwood-netxbig.h> 18 + 19 + struct netxbig_gpio_ext { 20 + unsigned int *addr; 21 + int num_addr; 22 + unsigned int *data; 23 + int num_data; 24 + unsigned int enable; 25 + }; 26 + 27 + enum netxbig_led_mode { 28 + NETXBIG_LED_OFF, 29 + NETXBIG_LED_ON, 30 + NETXBIG_LED_SATA, 31 + NETXBIG_LED_TIMER1, 32 + NETXBIG_LED_TIMER2, 33 + NETXBIG_LED_MODE_NUM, 34 + }; 35 + 36 + #define NETXBIG_LED_INVALID_MODE NETXBIG_LED_MODE_NUM 37 + 38 + struct netxbig_led_timer { 39 + unsigned long delay_on; 40 + unsigned long delay_off; 41 + enum netxbig_led_mode mode; 42 + }; 43 + 44 + struct netxbig_led { 45 + const char *name; 46 + const char *default_trigger; 47 + int mode_addr; 48 + int *mode_val; 49 + int bright_addr; 50 + int bright_max; 51 + }; 52 + 53 + struct netxbig_led_platform_data { 54 + struct netxbig_gpio_ext *gpio_ext; 55 + struct netxbig_led_timer *timer; 56 + int num_timer; 57 + struct netxbig_led *leds; 58 + int num_leds; 59 + }; 19 60 20 61 /* 21 62 * GPIO extension bus. ··· 347 306 return devm_led_classdev_register(&pdev->dev, &led_dat->cdev); 348 307 } 349 308 350 - #ifdef CONFIG_OF_GPIO 351 309 static int gpio_ext_get_of_pdata(struct device *dev, struct device_node *np, 352 310 struct netxbig_gpio_ext *gpio_ext) 353 311 { ··· 428 388 } 429 389 430 390 gpio_ext = devm_kzalloc(dev, sizeof(*gpio_ext), GFP_KERNEL); 431 - if (!gpio_ext) 391 + if (!gpio_ext) { 392 + of_node_put(gpio_ext_np); 432 393 return -ENOMEM; 394 + } 433 395 ret = gpio_ext_get_of_pdata(dev, gpio_ext_np, gpio_ext); 396 + of_node_put(gpio_ext_np); 434 397 if (ret) 435 398 return ret; 436 - of_node_put(gpio_ext_np); 437 399 pdata->gpio_ext = gpio_ext; 438 400 439 401 /* Timers (optional) */ ··· 564 522 {}, 565 523 }; 566 524 MODULE_DEVICE_TABLE(of, of_netxbig_leds_match); 567 - #else 568 - static inline int 569 - netxbig_leds_get_of_pdata(struct device *dev, 570 - struct netxbig_led_platform_data *pdata) 571 - { 572 - return -ENODEV; 573 - } 574 - #endif /* CONFIG_OF_GPIO */ 575 525 576 526 static int netxbig_led_probe(struct platform_device *pdev) 577 527 { 578 - struct netxbig_led_platform_data *pdata = dev_get_platdata(&pdev->dev); 528 + struct netxbig_led_platform_data *pdata; 579 529 struct netxbig_led_data *leds_data; 580 530 int i; 581 531 int ret; 582 532 583 - if (!pdata) { 584 - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 585 - if (!pdata) 586 - return -ENOMEM; 587 - ret = netxbig_leds_get_of_pdata(&pdev->dev, pdata); 588 - if (ret) 589 - return ret; 590 - } 533 + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 534 + if (!pdata) 535 + return -ENOMEM; 536 + ret = netxbig_leds_get_of_pdata(&pdev->dev, pdata); 537 + if (ret) 538 + return ret; 591 539 592 540 leds_data = devm_kcalloc(&pdev->dev, 593 541 pdata->num_leds, sizeof(*leds_data), ··· 603 571 .probe = netxbig_led_probe, 604 572 .driver = { 605 573 .name = "leds-netxbig", 606 - .of_match_table = of_match_ptr(of_netxbig_leds_match), 574 + .of_match_table = of_netxbig_leds_match, 607 575 }, 608 576 }; 609 577
+14 -7
drivers/leds/leds-ns2.c
··· 245 245 struct device_node *np = dev->of_node; 246 246 struct device_node *child; 247 247 struct ns2_led *led, *leds; 248 - int num_leds = 0; 248 + int ret, num_leds = 0; 249 249 250 250 num_leds = of_get_child_count(np); 251 251 if (!num_leds) ··· 259 259 led = leds; 260 260 for_each_child_of_node(np, child) { 261 261 const char *string; 262 - int ret, i, num_modes; 262 + int i, num_modes; 263 263 struct ns2_led_modval *modval; 264 264 265 265 ret = of_get_named_gpio(child, "cmd-gpio", 0); 266 266 if (ret < 0) 267 - return ret; 267 + goto err_node_put; 268 268 led->cmd = ret; 269 269 ret = of_get_named_gpio(child, "slow-gpio", 0); 270 270 if (ret < 0) 271 - return ret; 271 + goto err_node_put; 272 272 led->slow = ret; 273 273 ret = of_property_read_string(child, "label", &string); 274 274 led->name = (ret == 0) ? string : child->name; ··· 281 281 if (ret < 0 || ret % 3) { 282 282 dev_err(dev, 283 283 "Missing or malformed modes-map property\n"); 284 - return -EINVAL; 284 + ret = -EINVAL; 285 + goto err_node_put; 285 286 } 286 287 287 288 num_modes = ret / 3; ··· 290 289 num_modes, 291 290 sizeof(struct ns2_led_modval), 292 291 GFP_KERNEL); 293 - if (!modval) 294 - return -ENOMEM; 292 + if (!modval) { 293 + ret = -ENOMEM; 294 + goto err_node_put; 295 + } 295 296 296 297 for (i = 0; i < num_modes; i++) { 297 298 of_property_read_u32_index(child, ··· 317 314 pdata->num_leds = num_leds; 318 315 319 316 return 0; 317 + 318 + err_node_put: 319 + of_node_put(child); 320 + return ret; 320 321 } 321 322 322 323 static const struct of_device_id of_ns2_leds_match[] = {
+1 -1
drivers/leds/leds-pca9532.c
··· 16 16 #include <linux/mutex.h> 17 17 #include <linux/workqueue.h> 18 18 #include <linux/leds-pca9532.h> 19 - #include <linux/gpio.h> 19 + #include <linux/gpio/driver.h> 20 20 #include <linux/of.h> 21 21 #include <linux/of_device.h> 22 22
+2 -9
drivers/leds/leds-pwm.c
··· 65 65 return 0; 66 66 } 67 67 68 - static inline size_t sizeof_pwm_leds_priv(int num_leds) 69 - { 70 - return sizeof(struct led_pwm_priv) + 71 - (sizeof(struct led_pwm_data) * num_leds); 72 - } 73 - 74 68 static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv, 75 69 struct led_pwm *led, struct fwnode_handle *fwnode) 76 70 { ··· 105 111 if (!led_data->period && (led->pwm_period_ns > 0)) 106 112 led_data->period = led->pwm_period_ns; 107 113 108 - ret = devm_of_led_classdev_register(dev, to_of_node(fwnode), 109 - &led_data->cdev); 114 + ret = devm_led_classdev_register(dev, &led_data->cdev); 110 115 if (ret == 0) { 111 116 priv->num_leds++; 112 117 led_pwm_set(&led_data->cdev, led_data->cdev.brightness); ··· 168 175 if (!count) 169 176 return -EINVAL; 170 177 171 - priv = devm_kzalloc(&pdev->dev, sizeof_pwm_leds_priv(count), 178 + priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds, count), 172 179 GFP_KERNEL); 173 180 if (!priv) 174 181 return -ENOMEM;
+9 -13
drivers/leds/leds-sc27xx-bltc.c
··· 6 6 #include <linux/of.h> 7 7 #include <linux/platform_device.h> 8 8 #include <linux/regmap.h> 9 - #include <uapi/linux/uleds.h> 10 9 11 10 /* PMIC global control register definition */ 12 11 #define SC27XX_MODULE_EN0 0xc08 ··· 45 46 #define SC27XX_DELTA_T_MAX (SC27XX_LEDS_STEP * 255) 46 47 47 48 struct sc27xx_led { 48 - char name[LED_MAX_NAME_SIZE]; 49 + struct fwnode_handle *fwnode; 49 50 struct led_classdev ldev; 50 51 struct sc27xx_led_priv *priv; 51 52 u8 line; ··· 248 249 249 250 for (i = 0; i < SC27XX_LEDS_MAX; i++) { 250 251 struct sc27xx_led *led = &priv->leds[i]; 252 + struct led_init_data init_data = {}; 251 253 252 254 if (!led->active) 253 255 continue; 254 256 255 257 led->line = i; 256 258 led->priv = priv; 257 - led->ldev.name = led->name; 258 259 led->ldev.brightness_set_blocking = sc27xx_led_set; 259 260 led->ldev.pattern_set = sc27xx_led_pattern_set; 260 261 led->ldev.pattern_clear = sc27xx_led_pattern_clear; 261 262 led->ldev.default_trigger = "pattern"; 262 263 263 - err = devm_led_classdev_register(dev, &led->ldev); 264 + init_data.fwnode = led->fwnode; 265 + init_data.devicename = "sc27xx"; 266 + init_data.default_label = ":"; 267 + 268 + err = devm_led_classdev_register_ext(dev, &led->ldev, 269 + &init_data); 264 270 if (err) 265 271 return err; 266 272 } ··· 278 274 struct device *dev = &pdev->dev; 279 275 struct device_node *np = dev->of_node, *child; 280 276 struct sc27xx_led_priv *priv; 281 - const char *str; 282 277 u32 base, count, reg; 283 278 int err; 284 279 ··· 319 316 return -EINVAL; 320 317 } 321 318 319 + priv->leds[reg].fwnode = of_fwnode_handle(child); 322 320 priv->leds[reg].active = true; 323 - 324 - err = of_property_read_string(child, "label", &str); 325 - if (err) 326 - snprintf(priv->leds[reg].name, LED_MAX_NAME_SIZE, 327 - "sc27xx::"); 328 - else 329 - snprintf(priv->leds[reg].name, LED_MAX_NAME_SIZE, 330 - "sc27xx:%s", str); 331 321 } 332 322 333 323 err = sc27xx_led_register(dev, priv);
+1 -1
drivers/leds/leds-syscon.c
··· 115 115 } 116 116 sled->cdev.brightness_set = syscon_led_set; 117 117 118 - ret = led_classdev_register(dev, &sled->cdev); 118 + ret = devm_led_classdev_register(dev, &sled->cdev); 119 119 if (ret < 0) 120 120 return ret; 121 121
+6 -9
drivers/leds/leds-ti-lmu-common.c
··· 11 11 12 12 #include <linux/leds-ti-lmu-common.h> 13 13 14 - const static int ramp_table[16] = {2048, 262000, 524000, 1049000, 2090000, 15 - 4194000, 8389000, 16780000, 33550000, 41940000, 16 - 50330000, 58720000, 67110000, 83880000, 17 - 100660000, 117440000}; 14 + static const unsigned int ramp_table[16] = {2048, 262000, 524000, 1049000, 15 + 2090000, 4194000, 8389000, 16780000, 33550000, 16 + 41940000, 50330000, 58720000, 67110000, 17 + 83880000, 100660000, 117440000}; 18 18 19 19 static int ti_lmu_common_update_brightness(struct ti_lmu_bank *lmu_bank, 20 20 int brightness) ··· 54 54 } 55 55 EXPORT_SYMBOL(ti_lmu_common_set_brightness); 56 56 57 - static int ti_lmu_common_convert_ramp_to_index(unsigned int usec) 57 + static unsigned int ti_lmu_common_convert_ramp_to_index(unsigned int usec) 58 58 { 59 59 int size = ARRAY_SIZE(ramp_table); 60 60 int i; ··· 78 78 } 79 79 } 80 80 81 - return -EINVAL; 81 + return 0; 82 82 } 83 83 84 84 int ti_lmu_common_set_ramp(struct ti_lmu_bank *lmu_bank) ··· 93 93 ramp_up = ti_lmu_common_convert_ramp_to_index(lmu_bank->ramp_up_usec); 94 94 ramp_down = ti_lmu_common_convert_ramp_to_index(lmu_bank->ramp_down_usec); 95 95 } 96 - 97 - if (ramp_up < 0 || ramp_down < 0) 98 - return -EINVAL; 99 96 100 97 ramp = (ramp_up << 4) | ramp_down; 101 98
+1
drivers/leds/leds.h
··· 27 27 extern struct rw_semaphore leds_list_lock; 28 28 extern struct list_head leds_list; 29 29 extern struct list_head trigger_list; 30 + extern const char * const led_colors[LED_COLOR_ID_MAX]; 30 31 31 32 #endif /* __LEDS_H_INCLUDED */
+7 -5
drivers/leds/trigger/ledtrig-gpio.c
··· 131 131 if (gpio_data->gpio == gpio) 132 132 return n; 133 133 134 - if (!gpio) { 135 - if (gpio_data->gpio != 0) 134 + if (!gpio_is_valid(gpio)) { 135 + if (gpio_is_valid(gpio_data->gpio)) 136 136 free_irq(gpio_to_irq(gpio_data->gpio), led); 137 - gpio_data->gpio = 0; 137 + gpio_data->gpio = gpio; 138 138 return n; 139 139 } 140 140 ··· 144 144 if (ret) { 145 145 dev_err(dev, "request_irq failed with error %d\n", ret); 146 146 } else { 147 - if (gpio_data->gpio != 0) 147 + if (gpio_is_valid(gpio_data->gpio)) 148 148 free_irq(gpio_to_irq(gpio_data->gpio), led); 149 149 gpio_data->gpio = gpio; 150 150 /* After changing the GPIO, we need to update the LED. */ ··· 172 172 return -ENOMEM; 173 173 174 174 gpio_data->led = led; 175 + gpio_data->gpio = -ENOENT; 176 + 175 177 led_set_trigger_data(led, gpio_data); 176 178 177 179 return 0; ··· 183 181 { 184 182 struct gpio_trig_data *gpio_data = led_get_trigger_data(led); 185 183 186 - if (gpio_data->gpio != 0) 184 + if (gpio_is_valid(gpio_data->gpio)) 187 185 free_irq(gpio_to_irq(gpio_data->gpio), led); 188 186 kfree(gpio_data); 189 187 }
+2 -12
drivers/mfd/altera-sysmgr.c
··· 88 88 }; 89 89 90 90 /** 91 - * sysmgr_match_phandle 92 - * Matching function used by driver_find_device(). 93 - * Return: True if match is found, otherwise false. 94 - */ 95 - static int sysmgr_match_phandle(struct device *dev, const void *data) 96 - { 97 - return dev->of_node == (const struct device_node *)data; 98 - } 99 - 100 - /** 101 91 * altr_sysmgr_regmap_lookup_by_phandle 102 92 * Find the sysmgr previous configured in probe() and return regmap property. 103 93 * Return: regmap if found or error if not found. ··· 107 117 if (!sysmgr_np) 108 118 return ERR_PTR(-ENODEV); 109 119 110 - dev = driver_find_device(&altr_sysmgr_driver.driver, NULL, 111 - (void *)sysmgr_np, sysmgr_match_phandle); 120 + dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver, 121 + (void *)sysmgr_np); 112 122 of_node_put(sysmgr_np); 113 123 if (!dev) 114 124 return ERR_PTR(-EPROBE_DEFER);
+1 -8
drivers/misc/mei/main.c
··· 858 858 } 859 859 static DEVICE_ATTR_RO(dev_state); 860 860 861 - static int match_devt(struct device *dev, const void *data) 862 - { 863 - const dev_t *devt = data; 864 - 865 - return dev->devt == *devt; 866 - } 867 - 868 861 /** 869 862 * dev_set_devstate: set to new device state and notify sysfs file. 870 863 * ··· 873 880 874 881 dev->dev_state = state; 875 882 876 - clsdev = class_find_device(mei_class, NULL, &dev->cdev.dev, match_devt); 883 + clsdev = class_find_device_by_devt(mei_class, dev->cdev.dev); 877 884 if (clsdev) { 878 885 sysfs_notify(&clsdev->kobj, NULL, "dev_state"); 879 886 put_device(clsdev);
+1 -6
drivers/mux/core.c
··· 405 405 } 406 406 EXPORT_SYMBOL_GPL(mux_control_deselect); 407 407 408 - static int of_dev_node_match(struct device *dev, const void *data) 409 - { 410 - return dev->of_node == data; 411 - } 412 - 413 408 /* Note this function returns a reference to the mux_chip dev. */ 414 409 static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np) 415 410 { 416 411 struct device *dev; 417 412 418 - dev = class_find_device(&mux_class, NULL, np, of_dev_node_match); 413 + dev = class_find_device_by_of_node(&mux_class, np); 419 414 420 415 return dev ? to_mux_chip(dev) : NULL; 421 416 }
+1 -7
drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
··· 754 754 return (void *)misc_op; 755 755 } 756 756 757 - static int hns_dsaf_dev_match(struct device *dev, const void *fwnode) 758 - { 759 - return dev->fwnode == fwnode; 760 - } 761 - 762 757 struct 763 758 platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode) 764 759 { 765 760 struct device *dev; 766 761 767 - dev = bus_find_device(&platform_bus_type, NULL, 768 - fwnode, hns_dsaf_dev_match); 762 + dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); 769 763 return dev ? to_platform_device(dev) : NULL; 770 764 }
+1 -8
drivers/net/phy/mdio_bus.c
··· 262 262 }; 263 263 264 264 #if IS_ENABLED(CONFIG_OF_MDIO) 265 - /* Helper function for of_mdio_find_bus */ 266 - static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np) 267 - { 268 - return dev->of_node == mdio_bus_np; 269 - } 270 265 /** 271 266 * of_mdio_find_bus - Given an mii_bus node, find the mii_bus. 272 267 * @mdio_bus_np: Pointer to the mii_bus. ··· 282 287 if (!mdio_bus_np) 283 288 return NULL; 284 289 285 - d = class_find_device(&mdio_bus_class, NULL, mdio_bus_np, 286 - of_mdio_bus_match); 287 - 290 + d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np); 288 291 return d ? to_mii_bus(d) : NULL; 289 292 } 290 293 EXPORT_SYMBOL(of_mdio_find_bus);
+1 -6
drivers/nvmem/core.c
··· 76 76 .name = "nvmem", 77 77 }; 78 78 79 - static int of_nvmem_match(struct device *dev, const void *nvmem_np) 80 - { 81 - return dev->of_node == nvmem_np; 82 - } 83 - 84 79 static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) 85 80 { 86 81 struct device *d; ··· 83 88 if (!nvmem_np) 84 89 return NULL; 85 90 86 - d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match); 91 + d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np); 87 92 88 93 if (!d) 89 94 return NULL;
+1 -7
drivers/of/of_mdio.c
··· 280 280 } 281 281 EXPORT_SYMBOL(of_mdiobus_register); 282 282 283 - /* Helper function for of_phy_find_device */ 284 - static int of_phy_match(struct device *dev, const void *phy_np) 285 - { 286 - return dev->of_node == phy_np; 287 - } 288 - 289 283 /** 290 284 * of_phy_find_device - Give a PHY node, find the phy_device 291 285 * @phy_np: Pointer to the phy's device tree node ··· 295 301 if (!phy_np) 296 302 return NULL; 297 303 298 - d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match); 304 + d = bus_find_device_by_of_node(&mdio_bus_type, phy_np); 299 305 if (d) { 300 306 mdiodev = to_mdio_device(d); 301 307 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
+1 -6
drivers/of/platform.c
··· 37 37 {} /* Empty terminated list */ 38 38 }; 39 39 40 - static int of_dev_node_match(struct device *dev, const void *data) 41 - { 42 - return dev->of_node == data; 43 - } 44 - 45 40 /** 46 41 * of_find_device_by_node - Find the platform_device associated with a node 47 42 * @np: Pointer to device tree node ··· 50 55 { 51 56 struct device *dev; 52 57 53 - dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match); 58 + dev = bus_find_device_by_of_node(&platform_bus_type, np); 54 59 return dev ? to_platform_device(dev) : NULL; 55 60 } 56 61 EXPORT_SYMBOL(of_find_device_by_node);
+1 -6
drivers/pci/probe.c
··· 64 64 return &r->res; 65 65 } 66 66 67 - static int find_anything(struct device *dev, const void *data) 68 - { 69 - return 1; 70 - } 71 - 72 67 /* 73 68 * Some device drivers need know if PCI is initiated. 74 69 * Basically, we think PCI is not initiated when there ··· 74 79 struct device *dev; 75 80 int no_devices; 76 81 77 - dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything); 82 + dev = bus_find_next_device(&pci_bus_type, NULL); 78 83 no_devices = (dev == NULL); 79 84 put_device(dev); 80 85 return no_devices;
+1 -6
drivers/regulator/of_regulator.c
··· 462 462 return NULL; 463 463 } 464 464 465 - static int of_node_match(struct device *dev, const void *data) 466 - { 467 - return dev->of_node == data; 468 - } 469 - 470 465 struct regulator_dev *of_find_regulator_by_node(struct device_node *np) 471 466 { 472 467 struct device *dev; 473 468 474 - dev = class_find_device(&regulator_class, NULL, np, of_node_match); 469 + dev = class_find_device_by_of_node(&regulator_class, np); 475 470 476 471 return dev ? dev_to_rdev(dev) : NULL; 477 472 }
+1 -10
drivers/rtc/interface.c
··· 663 663 } 664 664 EXPORT_SYMBOL_GPL(rtc_update_irq); 665 665 666 - static int __rtc_match(struct device *dev, const void *data) 667 - { 668 - const char *name = data; 669 - 670 - if (strcmp(dev_name(dev), name) == 0) 671 - return 1; 672 - return 0; 673 - } 674 - 675 666 struct rtc_device *rtc_class_open(const char *name) 676 667 { 677 668 struct device *dev; 678 669 struct rtc_device *rtc = NULL; 679 670 680 - dev = class_find_device(rtc_class, NULL, name, __rtc_match); 671 + dev = class_find_device_by_name(rtc_class, name); 681 672 if (dev) 682 673 rtc = to_rtc_device(dev); 683 674
+2 -16
drivers/s390/cio/ccwgroup.c
··· 581 581 } 582 582 EXPORT_SYMBOL(ccwgroup_driver_register); 583 583 584 - static int __ccwgroup_match_all(struct device *dev, const void *data) 585 - { 586 - return 1; 587 - } 588 - 589 584 /** 590 585 * ccwgroup_driver_unregister() - deregister a ccw group driver 591 586 * @cdriver: driver to be deregistered ··· 592 597 struct device *dev; 593 598 594 599 /* We don't want ccwgroup devices to live longer than their driver. */ 595 - while ((dev = driver_find_device(&cdriver->driver, NULL, NULL, 596 - __ccwgroup_match_all))) { 600 + while ((dev = driver_find_next_device(&cdriver->driver, NULL))) { 597 601 struct ccwgroup_device *gdev = to_ccwgroupdev(dev); 598 602 599 603 ccwgroup_ungroup(gdev); ··· 601 607 driver_unregister(&cdriver->driver); 602 608 } 603 609 EXPORT_SYMBOL(ccwgroup_driver_unregister); 604 - 605 - static int __ccwgroupdev_check_busid(struct device *dev, const void *id) 606 - { 607 - const char *bus_id = id; 608 - 609 - return (strcmp(bus_id, dev_name(dev)) == 0); 610 - } 611 610 612 611 /** 613 612 * get_ccwgroupdev_by_busid() - obtain device from a bus id ··· 618 631 { 619 632 struct device *dev; 620 633 621 - dev = driver_find_device(&gdrv->driver, NULL, bus_id, 622 - __ccwgroupdev_check_busid); 634 + dev = driver_find_device_by_name(&gdrv->driver, bus_id); 623 635 624 636 return dev ? to_ccwgroupdev(dev) : NULL; 625 637 }
+1 -14
drivers/s390/cio/device.c
··· 1695 1695 EXPORT_SYMBOL_GPL(ccw_device_force_console); 1696 1696 #endif 1697 1697 1698 - /* 1699 - * get ccw_device matching the busid, but only if owned by cdrv 1700 - */ 1701 - static int 1702 - __ccwdev_check_busid(struct device *dev, const void *id) 1703 - { 1704 - const char *bus_id = id; 1705 - 1706 - return (strcmp(bus_id, dev_name(dev)) == 0); 1707 - } 1708 - 1709 - 1710 1698 /** 1711 1699 * get_ccwdev_by_busid() - obtain device from a bus id 1712 1700 * @cdrv: driver the device is owned by ··· 1711 1723 { 1712 1724 struct device *dev; 1713 1725 1714 - dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id, 1715 - __ccwdev_check_busid); 1726 + dev = driver_find_device_by_name(&cdrv->driver, bus_id); 1716 1727 1717 1728 return dev ? to_ccwdev(dev) : NULL; 1718 1729 }
+2 -20
drivers/s390/crypto/zcrypt_api.c
··· 134 134 static int zcdn_create(const char *name); 135 135 static int zcdn_destroy(const char *name); 136 136 137 - /* helper function, matches the name for find_zcdndev_by_name() */ 138 - static int __match_zcdn_name(struct device *dev, const void *data) 139 - { 140 - return strcmp(dev_name(dev), (const char *)data) == 0; 141 - } 142 - 143 - /* helper function, matches the devt value for find_zcdndev_by_devt() */ 144 - static int __match_zcdn_devt(struct device *dev, const void *data) 145 - { 146 - return dev->devt == *((dev_t *) data); 147 - } 148 - 149 137 /* 150 138 * Find zcdn device by name. 151 139 * Returns reference to the zcdn device which needs to be released ··· 141 153 */ 142 154 static inline struct zcdn_device *find_zcdndev_by_name(const char *name) 143 155 { 144 - struct device *dev = 145 - class_find_device(zcrypt_class, NULL, 146 - (void *) name, 147 - __match_zcdn_name); 156 + struct device *dev = class_find_device_by_name(zcrypt_class, name); 148 157 149 158 return dev ? to_zcdn_dev(dev) : NULL; 150 159 } ··· 153 168 */ 154 169 static inline struct zcdn_device *find_zcdndev_by_devt(dev_t devt) 155 170 { 156 - struct device *dev = 157 - class_find_device(zcrypt_class, NULL, 158 - (void *) &devt, 159 - __match_zcdn_devt); 171 + struct device *dev = class_find_device_by_devt(zcrypt_class, devt); 160 172 161 173 return dev ? to_zcdn_dev(dev) : NULL; 162 174 }
+2 -7
drivers/scsi/scsi_proc.c
··· 372 372 return err; 373 373 } 374 374 375 - static int always_match(struct device *dev, const void *data) 376 - { 377 - return 1; 378 - } 379 - 380 375 static inline struct device *next_scsi_device(struct device *start) 381 376 { 382 - struct device *next = bus_find_device(&scsi_bus_type, start, NULL, 383 - always_match); 377 + struct device *next = bus_find_next_device(&scsi_bus_type, start); 378 + 384 379 put_device(start); 385 380 return next; 386 381 }
+5 -23
drivers/spi/spi.c
··· 3655 3655 /*-------------------------------------------------------------------------*/ 3656 3656 3657 3657 #if IS_ENABLED(CONFIG_OF) 3658 - static int __spi_of_device_match(struct device *dev, const void *data) 3659 - { 3660 - return dev->of_node == data; 3661 - } 3662 - 3663 3658 /* must call put_device() when done with returned spi_device device */ 3664 3659 struct spi_device *of_find_spi_device_by_node(struct device_node *node) 3665 3660 { 3666 - struct device *dev = bus_find_device(&spi_bus_type, NULL, node, 3667 - __spi_of_device_match); 3661 + struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node); 3662 + 3668 3663 return dev ? to_spi_device(dev) : NULL; 3669 3664 } 3670 3665 EXPORT_SYMBOL_GPL(of_find_spi_device_by_node); 3671 3666 #endif /* IS_ENABLED(CONFIG_OF) */ 3672 3667 3673 3668 #if IS_ENABLED(CONFIG_OF_DYNAMIC) 3674 - static int __spi_of_controller_match(struct device *dev, const void *data) 3675 - { 3676 - return dev->of_node == data; 3677 - } 3678 - 3679 3669 /* the spi controllers are not using spi_bus, so we find it with another way */ 3680 3670 static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node) 3681 3671 { 3682 3672 struct device *dev; 3683 3673 3684 - dev = class_find_device(&spi_master_class, NULL, node, 3685 - __spi_of_controller_match); 3674 + dev = class_find_device_by_of_node(&spi_master_class, node); 3686 3675 if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) 3687 - dev = class_find_device(&spi_slave_class, NULL, node, 3688 - __spi_of_controller_match); 3676 + dev = class_find_device_by_of_node(&spi_slave_class, node); 3689 3677 if (!dev) 3690 3678 return NULL; 3691 3679 ··· 3744 3756 return ACPI_COMPANION(dev->parent) == data; 3745 3757 } 3746 3758 3747 - static int spi_acpi_device_match(struct device *dev, const void *data) 3748 - { 3749 - return ACPI_COMPANION(dev) == data; 3750 - } 3751 - 3752 3759 static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev) 3753 3760 { 3754 3761 struct device *dev; ··· 3763 3780 { 3764 3781 struct device *dev; 3765 3782 3766 - dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match); 3767 - 3783 + dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev); 3768 3784 return dev ? to_spi_device(dev) : NULL; 3769 3785 } 3770 3786
+1 -7
drivers/tty/tty_io.c
··· 2952 2952 2953 2953 EXPORT_SYMBOL(do_SAK); 2954 2954 2955 - static int dev_match_devt(struct device *dev, const void *data) 2956 - { 2957 - const dev_t *devt = data; 2958 - return dev->devt == *devt; 2959 - } 2960 - 2961 2955 /* Must put_device() after it's unused! */ 2962 2956 static struct device *tty_get_device(struct tty_struct *tty) 2963 2957 { 2964 2958 dev_t devt = tty_devnum(tty); 2965 - return class_find_device(tty_class, NULL, &devt, dev_match_devt); 2959 + return class_find_device_by_devt(tty_class, devt); 2966 2960 } 2967 2961 2968 2962
+1 -7
drivers/usb/core/devio.c
··· 942 942 return ret; 943 943 } 944 944 945 - static int match_devt(struct device *dev, const void *data) 946 - { 947 - return dev->devt == (dev_t)(unsigned long)(void *)data; 948 - } 949 - 950 945 static struct usb_device *usbdev_lookup_by_devt(dev_t devt) 951 946 { 952 947 struct device *dev; 953 948 954 - dev = bus_find_device(&usb_bus_type, NULL, 955 - (void *) (unsigned long) devt, match_devt); 949 + dev = bus_find_device_by_devt(&usb_bus_type, devt); 956 950 if (!dev) 957 951 return NULL; 958 952 return to_usb_device(dev);
+2 -14
drivers/usb/roles/class.c
··· 85 85 } 86 86 EXPORT_SYMBOL_GPL(usb_role_switch_get_role); 87 87 88 - static int switch_fwnode_match(struct device *dev, const void *fwnode) 89 - { 90 - return dev_fwnode(dev) == fwnode; 91 - } 92 - 93 - static int switch_name_match(struct device *dev, const void *name) 94 - { 95 - return !strcmp((const char *)name, dev_name(dev)); 96 - } 97 - 98 88 static void *usb_role_switch_match(struct device_connection *con, int ep, 99 89 void *data) 100 90 { ··· 94 104 if (con->id && !fwnode_property_present(con->fwnode, con->id)) 95 105 return NULL; 96 106 97 - dev = class_find_device(role_class, NULL, con->fwnode, 98 - switch_fwnode_match); 107 + dev = class_find_device_by_fwnode(role_class, con->fwnode); 99 108 } else { 100 - dev = class_find_device(role_class, NULL, con->endpoint[ep], 101 - switch_name_match); 109 + dev = class_find_device_by_name(role_class, con->endpoint[ep]); 102 110 } 103 111 104 112 return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
+2 -14
drivers/usb/typec/class.c
··· 205 205 put_device(&adev->dev); 206 206 } 207 207 208 - static int typec_port_fwnode_match(struct device *dev, const void *fwnode) 209 - { 210 - return dev_fwnode(dev) == fwnode; 211 - } 212 - 213 - static int typec_port_name_match(struct device *dev, const void *name) 214 - { 215 - return !strcmp((const char *)name, dev_name(dev)); 216 - } 217 - 218 208 static void *typec_port_match(struct device_connection *con, int ep, void *data) 219 209 { 220 210 struct device *dev; ··· 214 224 * we need to return ERR_PTR(-PROBE_DEFER) when there is no device. 215 225 */ 216 226 if (con->fwnode) 217 - return class_find_device(typec_class, NULL, con->fwnode, 218 - typec_port_fwnode_match); 227 + return class_find_device_by_fwnode(typec_class, con->fwnode); 219 228 220 - dev = class_find_device(typec_class, NULL, con->endpoint[ep], 221 - typec_port_name_match); 229 + dev = class_find_device_by_name(typec_class, con->endpoint[ep]); 222 230 223 231 return dev ? dev : ERR_PTR(-EPROBE_DEFER); 224 232 }
+54 -1
include/dt-bindings/leds/common.h
··· 3 3 * This header provides macros for the common LEDs device tree bindings. 4 4 * 5 5 * Copyright (C) 2015, Samsung Electronics Co., Ltd. 6 - * 7 6 * Author: Jacek Anaszewski <j.anaszewski@samsung.com> 7 + * 8 + * Copyright (C) 2019 Jacek Anaszewski <jacek.anaszewski@gmail.com> 8 9 */ 9 10 10 11 #ifndef __DT_BINDINGS_LEDS_H ··· 19 18 #define LEDS_BOOST_OFF 0 20 19 #define LEDS_BOOST_ADAPTIVE 1 21 20 #define LEDS_BOOST_FIXED 2 21 + 22 + /* Standard LED colors */ 23 + #define LED_COLOR_ID_WHITE 0 24 + #define LED_COLOR_ID_RED 1 25 + #define LED_COLOR_ID_GREEN 2 26 + #define LED_COLOR_ID_BLUE 3 27 + #define LED_COLOR_ID_AMBER 4 28 + #define LED_COLOR_ID_VIOLET 5 29 + #define LED_COLOR_ID_YELLOW 6 30 + #define LED_COLOR_ID_IR 7 31 + #define LED_COLOR_ID_MAX 8 32 + 33 + /* Standard LED functions */ 34 + #define LED_FUNCTION_ACTIVITY "activity" 35 + #define LED_FUNCTION_ALARM "alarm" 36 + #define LED_FUNCTION_BACKLIGHT "backlight" 37 + #define LED_FUNCTION_BLUETOOTH "bluetooth" 38 + #define LED_FUNCTION_BOOT "boot" 39 + #define LED_FUNCTION_CPU "cpu" 40 + #define LED_FUNCTION_CAPSLOCK "capslock" 41 + #define LED_FUNCTION_CHARGING "charging" 42 + #define LED_FUNCTION_DEBUG "debug" 43 + #define LED_FUNCTION_DISK "disk" 44 + #define LED_FUNCTION_DISK_ACTIVITY "disk-activity" 45 + #define LED_FUNCTION_DISK_ERR "disk-err" 46 + #define LED_FUNCTION_DISK_READ "disk-read" 47 + #define LED_FUNCTION_DISK_WRITE "disk-write" 48 + #define LED_FUNCTION_FAULT "fault" 49 + #define LED_FUNCTION_FLASH "flash" 50 + #define LED_FUNCTION_HEARTBEAT "heartbeat" 51 + #define LED_FUNCTION_INDICATOR "indicator" 52 + #define LED_FUNCTION_KBD_BACKLIGHT "kbd_backlight" 53 + #define LED_FUNCTION_LAN "lan" 54 + #define LED_FUNCTION_MAIL "mail" 55 + #define LED_FUNCTION_MTD "mtd" 56 + #define LED_FUNCTION_MICMUTE "micmute" 57 + #define LED_FUNCTION_MUTE "mute" 58 + #define LED_FUNCTION_NUMLOCK "numlock" 59 + #define LED_FUNCTION_PANIC "panic" 60 + #define LED_FUNCTION_PROGRAMMING "programming" 61 + #define LED_FUNCTION_POWER "power" 62 + #define LED_FUNCTION_RX "rx" 63 + #define LED_FUNCTION_SD "sd" 64 + #define LED_FUNCTION_SCROLLLOCK "scrolllock" 65 + #define LED_FUNCTION_STANDBY "standby" 66 + #define LED_FUNCTION_STATUS "status" 67 + #define LED_FUNCTION_TORCH "torch" 68 + #define LED_FUNCTION_TX "tx" 69 + #define LED_FUNCTION_USB "usb" 70 + #define LED_FUNCTION_WAN "wan" 71 + #define LED_FUNCTION_WLAN "wlan" 72 + #define LED_FUNCTION_WPS "wps" 22 73 23 74 #endif /* __DT_BINDINGS_LEDS_H */
+234 -3
include/linux/device.h
··· 164 164 struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); 165 165 void subsys_dev_iter_exit(struct subsys_dev_iter *iter); 166 166 167 + int device_match_name(struct device *dev, const void *name); 167 168 int device_match_of_node(struct device *dev, const void *np); 169 + int device_match_fwnode(struct device *dev, const void *fwnode); 170 + int device_match_devt(struct device *dev, const void *pdevt); 171 + int device_match_acpi_dev(struct device *dev, const void *adev); 172 + int device_match_any(struct device *dev, const void *unused); 168 173 169 174 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, 170 175 int (*fn)(struct device *dev, void *data)); 171 176 struct device *bus_find_device(struct bus_type *bus, struct device *start, 172 177 const void *data, 173 178 int (*match)(struct device *dev, const void *data)); 174 - struct device *bus_find_device_by_name(struct bus_type *bus, 175 - struct device *start, 176 - const char *name); 179 + /** 180 + * bus_find_device_by_name - device iterator for locating a particular device 181 + * of a specific name. 182 + * @bus: bus type 183 + * @start: Device to begin with 184 + * @name: name of the device to match 185 + */ 186 + static inline struct device *bus_find_device_by_name(struct bus_type *bus, 187 + struct device *start, 188 + const char *name) 189 + { 190 + return bus_find_device(bus, start, name, device_match_name); 191 + } 192 + 193 + /** 194 + * bus_find_device_by_of_node : device iterator for locating a particular device 195 + * matching the of_node. 196 + * @bus: bus type 197 + * @np: of_node of the device to match. 198 + */ 199 + static inline struct device * 200 + bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np) 201 + { 202 + return bus_find_device(bus, NULL, np, device_match_of_node); 203 + } 204 + 205 + /** 206 + * bus_find_device_by_fwnode : device iterator for locating a particular device 207 + * matching the fwnode. 208 + * @bus: bus type 209 + * @fwnode: fwnode of the device to match. 210 + */ 211 + static inline struct device * 212 + bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode) 213 + { 214 + return bus_find_device(bus, NULL, fwnode, device_match_fwnode); 215 + } 216 + 217 + /** 218 + * bus_find_device_by_devt : device iterator for locating a particular device 219 + * matching the device type. 220 + * @bus: bus type 221 + * @devt: device type of the device to match. 222 + */ 223 + static inline struct device *bus_find_device_by_devt(struct bus_type *bus, 224 + dev_t devt) 225 + { 226 + return bus_find_device(bus, NULL, &devt, device_match_devt); 227 + } 228 + 229 + /** 230 + * bus_find_next_device - Find the next device after a given device in a 231 + * given bus. 232 + */ 233 + static inline struct device * 234 + bus_find_next_device(struct bus_type *bus,struct device *cur) 235 + { 236 + return bus_find_device(bus, cur, NULL, device_match_any); 237 + } 238 + 239 + #ifdef CONFIG_ACPI 240 + struct acpi_device; 241 + 242 + /** 243 + * bus_find_device_by_acpi_dev : device iterator for locating a particular device 244 + * matching the ACPI COMPANION device. 245 + * @bus: bus type 246 + * @adev: ACPI COMPANION device to match. 247 + */ 248 + static inline struct device * 249 + bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev) 250 + { 251 + return bus_find_device(bus, NULL, adev, device_match_acpi_dev); 252 + } 253 + #else 254 + static inline struct device * 255 + bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev) 256 + { 257 + return NULL; 258 + } 259 + #endif 260 + 177 261 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, 178 262 struct device *hint); 179 263 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, ··· 426 342 struct device *start, const void *data, 427 343 int (*match)(struct device *dev, const void *data)); 428 344 345 + /** 346 + * driver_find_device_by_name - device iterator for locating a particular device 347 + * of a specific name. 348 + * @driver: the driver we're iterating 349 + * @name: name of the device to match 350 + */ 351 + static inline struct device *driver_find_device_by_name(struct device_driver *drv, 352 + const char *name) 353 + { 354 + return driver_find_device(drv, NULL, name, device_match_name); 355 + } 356 + 357 + /** 358 + * driver_find_device_by_of_node- device iterator for locating a particular device 359 + * by of_node pointer. 360 + * @driver: the driver we're iterating 361 + * @np: of_node pointer to match. 362 + */ 363 + static inline struct device * 364 + driver_find_device_by_of_node(struct device_driver *drv, 365 + const struct device_node *np) 366 + { 367 + return driver_find_device(drv, NULL, np, device_match_of_node); 368 + } 369 + 370 + /** 371 + * driver_find_device_by_fwnode- device iterator for locating a particular device 372 + * by fwnode pointer. 373 + * @driver: the driver we're iterating 374 + * @fwnode: fwnode pointer to match. 375 + */ 376 + static inline struct device * 377 + driver_find_device_by_fwnode(struct device_driver *drv, 378 + const struct fwnode_handle *fwnode) 379 + { 380 + return driver_find_device(drv, NULL, fwnode, device_match_fwnode); 381 + } 382 + 383 + /** 384 + * driver_find_device_by_devt- device iterator for locating a particular device 385 + * by devt. 386 + * @driver: the driver we're iterating 387 + * @devt: devt pointer to match. 388 + */ 389 + static inline struct device *driver_find_device_by_devt(struct device_driver *drv, 390 + dev_t devt) 391 + { 392 + return driver_find_device(drv, NULL, &devt, device_match_devt); 393 + } 394 + 395 + static inline struct device *driver_find_next_device(struct device_driver *drv, 396 + struct device *start) 397 + { 398 + return driver_find_device(drv, start, NULL, device_match_any); 399 + } 400 + 401 + #ifdef CONFIG_ACPI 402 + /** 403 + * driver_find_device_by_acpi_dev : device iterator for locating a particular 404 + * device matching the ACPI_COMPANION device. 405 + * @driver: the driver we're iterating 406 + * @adev: ACPI_COMPANION device to match. 407 + */ 408 + static inline struct device * 409 + driver_find_device_by_acpi_dev(struct device_driver *drv, 410 + const struct acpi_device *adev) 411 + { 412 + return driver_find_device(drv, NULL, adev, device_match_acpi_dev); 413 + } 414 + #else 415 + static inline struct device * 416 + driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev) 417 + { 418 + return NULL; 419 + } 420 + #endif 421 + 429 422 void driver_deferred_probe_add(struct device *dev); 430 423 int driver_deferred_probe_check_state(struct device *dev); 431 424 int driver_deferred_probe_check_state_continue(struct device *dev); ··· 631 470 extern struct device *class_find_device(struct class *class, 632 471 struct device *start, const void *data, 633 472 int (*match)(struct device *, const void *)); 473 + 474 + /** 475 + * class_find_device_by_name - device iterator for locating a particular device 476 + * of a specific name. 477 + * @class: class type 478 + * @name: name of the device to match 479 + */ 480 + static inline struct device *class_find_device_by_name(struct class *class, 481 + const char *name) 482 + { 483 + return class_find_device(class, NULL, name, device_match_name); 484 + } 485 + 486 + /** 487 + * class_find_device_by_of_node : device iterator for locating a particular device 488 + * matching the of_node. 489 + * @class: class type 490 + * @np: of_node of the device to match. 491 + */ 492 + static inline struct device * 493 + class_find_device_by_of_node(struct class *class, const struct device_node *np) 494 + { 495 + return class_find_device(class, NULL, np, device_match_of_node); 496 + } 497 + 498 + /** 499 + * class_find_device_by_fwnode : device iterator for locating a particular device 500 + * matching the fwnode. 501 + * @class: class type 502 + * @fwnode: fwnode of the device to match. 503 + */ 504 + static inline struct device * 505 + class_find_device_by_fwnode(struct class *class, 506 + const struct fwnode_handle *fwnode) 507 + { 508 + return class_find_device(class, NULL, fwnode, device_match_fwnode); 509 + } 510 + 511 + /** 512 + * class_find_device_by_devt : device iterator for locating a particular device 513 + * matching the device type. 514 + * @class: class type 515 + * @devt: device type of the device to match. 516 + */ 517 + static inline struct device *class_find_device_by_devt(struct class *class, 518 + dev_t devt) 519 + { 520 + return class_find_device(class, NULL, &devt, device_match_devt); 521 + } 522 + 523 + #ifdef CONFIG_ACPI 524 + struct acpi_device; 525 + /** 526 + * class_find_device_by_acpi_dev : device iterator for locating a particular 527 + * device matching the ACPI_COMPANION device. 528 + * @class: class type 529 + * @adev: ACPI_COMPANION device to match. 530 + */ 531 + static inline struct device * 532 + class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev) 533 + { 534 + return class_find_device(class, NULL, adev, device_match_acpi_dev); 535 + } 536 + #else 537 + static inline struct device * 538 + class_find_device_by_acpi_dev(struct class *class, const void *adev) 539 + { 540 + return NULL; 541 + } 542 + #endif 634 543 635 544 struct class_attribute { 636 545 struct attribute attr;
+10 -5
include/linux/led-class-flash.h
··· 86 86 } 87 87 88 88 /** 89 - * led_classdev_flash_register - register a new object of led_classdev class 90 - * with support for flash LEDs 91 - * @parent: the flash LED to register 89 + * led_classdev_flash_register_ext - register a new object of LED class with 90 + * init data and with support for flash LEDs 91 + * @parent: LED flash controller device this flash LED is driven by 92 92 * @fled_cdev: the led_classdev_flash structure for this device 93 + * @init_data: the LED class flash device initialization data 93 94 * 94 95 * Returns: 0 on success or negative error value on failure 95 96 */ 96 - extern int led_classdev_flash_register(struct device *parent, 97 - struct led_classdev_flash *fled_cdev); 97 + extern int led_classdev_flash_register_ext(struct device *parent, 98 + struct led_classdev_flash *fled_cdev, 99 + struct led_init_data *init_data); 100 + 101 + #define led_classdev_flash_register(parent, fled_cdev) \ 102 + led_classdev_flash_register_ext(parent, fled_cdev, NULL) 98 103 99 104 /** 100 105 * led_classdev_flash_unregister - unregisters an object of led_classdev class
+90 -10
include/linux/leds.h
··· 8 8 #ifndef __LINUX_LEDS_H_INCLUDED 9 9 #define __LINUX_LEDS_H_INCLUDED 10 10 11 + #include <dt-bindings/leds/common.h> 11 12 #include <linux/device.h> 12 13 #include <linux/kernfs.h> 13 14 #include <linux/list.h> ··· 29 28 LED_ON = 1, 30 29 LED_HALF = 127, 31 30 LED_FULL = 255, 31 + }; 32 + 33 + struct led_init_data { 34 + /* device fwnode handle */ 35 + struct fwnode_handle *fwnode; 36 + /* 37 + * default <color:function> tuple, for backward compatibility 38 + * with in-driver hard-coded LED names used as a fallback when 39 + * DT "label" property is absent; it should be set to NULL 40 + * in new LED class drivers. 41 + */ 42 + const char *default_label; 43 + /* 44 + * string to be used for devicename section of LED class device 45 + * either for label based LED name composition path or for fwnode 46 + * based when devname_mandatory is true 47 + */ 48 + const char *devicename; 49 + /* 50 + * indicates if LED name should always comprise devicename section; 51 + * only LEDs exposed by drivers of hot-pluggable devices should 52 + * set it to true 53 + */ 54 + bool devname_mandatory; 32 55 }; 33 56 34 57 struct led_classdev { ··· 150 125 struct mutex led_access; 151 126 }; 152 127 153 - extern int of_led_classdev_register(struct device *parent, 154 - struct device_node *np, 155 - struct led_classdev *led_cdev); 156 - #define led_classdev_register(parent, led_cdev) \ 157 - of_led_classdev_register(parent, NULL, led_cdev) 158 - extern int devm_of_led_classdev_register(struct device *parent, 159 - struct device_node *np, 160 - struct led_classdev *led_cdev); 161 - #define devm_led_classdev_register(parent, led_cdev) \ 162 - devm_of_led_classdev_register(parent, NULL, led_cdev) 128 + /** 129 + * led_classdev_register_ext - register a new object of LED class with 130 + * init data 131 + * @parent: LED controller device this LED is driven by 132 + * @led_cdev: the led_classdev structure for this device 133 + * @init_data: the LED class device initialization data 134 + * 135 + * Register a new object of LED class, with name derived from init_data. 136 + * 137 + * Returns: 0 on success or negative error value on failure 138 + */ 139 + extern int led_classdev_register_ext(struct device *parent, 140 + struct led_classdev *led_cdev, 141 + struct led_init_data *init_data); 142 + 143 + /** 144 + * led_classdev_register - register a new object of LED class 145 + * @parent: LED controller device this LED is driven by 146 + * @led_cdev: the led_classdev structure for this device 147 + * 148 + * Register a new object of LED class, with name derived from the name property 149 + * of passed led_cdev argument. 150 + * 151 + * Returns: 0 on success or negative error value on failure 152 + */ 153 + static inline int led_classdev_register(struct device *parent, 154 + struct led_classdev *led_cdev) 155 + { 156 + return led_classdev_register_ext(parent, led_cdev, NULL); 157 + } 158 + 159 + extern int devm_led_classdev_register_ext(struct device *parent, 160 + struct led_classdev *led_cdev, 161 + struct led_init_data *init_data); 162 + 163 + static inline int devm_led_classdev_register(struct device *parent, 164 + struct led_classdev *led_cdev) 165 + { 166 + return devm_led_classdev_register_ext(parent, led_cdev, NULL); 167 + } 163 168 extern void led_classdev_unregister(struct led_classdev *led_cdev); 164 169 extern void devm_led_classdev_unregister(struct device *parent, 165 170 struct led_classdev *led_cdev); ··· 297 242 * Enable the led_cdev's sysfs interface. 298 243 */ 299 244 extern void led_sysfs_enable(struct led_classdev *led_cdev); 245 + 246 + /** 247 + * led_compose_name - compose LED class device name 248 + * @dev: LED controller device object 249 + * @child: child fwnode_handle describing a LED or a group of synchronized LEDs; 250 + * it must be provided only for fwnode based LEDs 251 + * @led_classdev_name: composed LED class device name 252 + * 253 + * Create LED class device name basing on the provided init_data argument. 254 + * The name can have <devicename:color:function> or <color:function>. 255 + * form, depending on the init_data configuration. 256 + * 257 + * Returns: 0 on success or negative error value on failure 258 + */ 259 + extern int led_compose_name(struct device *dev, struct led_init_data *init_data, 260 + char *led_classdev_name); 300 261 301 262 /** 302 263 * led_sysfs_is_disabled - check if LED sysfs interface is disabled ··· 489 418 struct led_platform_data { 490 419 int num_leds; 491 420 struct led_info *leds; 421 + }; 422 + 423 + struct led_properties { 424 + u32 color; 425 + bool color_present; 426 + const char *function; 427 + u32 func_enum; 428 + bool func_enum_present; 429 + const char *label; 492 430 }; 493 431 494 432 struct gpio_desc;
-54
include/linux/platform_data/leds-kirkwood-netxbig.h
··· 1 - /* 2 - * Platform data structure for netxbig LED driver 3 - * 4 - * This file is licensed under the terms of the GNU General Public 5 - * License version 2. This program is licensed "as is" without any 6 - * warranty of any kind, whether express or implied. 7 - */ 8 - 9 - #ifndef __LEDS_KIRKWOOD_NETXBIG_H 10 - #define __LEDS_KIRKWOOD_NETXBIG_H 11 - 12 - struct netxbig_gpio_ext { 13 - unsigned *addr; 14 - int num_addr; 15 - unsigned *data; 16 - int num_data; 17 - unsigned enable; 18 - }; 19 - 20 - enum netxbig_led_mode { 21 - NETXBIG_LED_OFF, 22 - NETXBIG_LED_ON, 23 - NETXBIG_LED_SATA, 24 - NETXBIG_LED_TIMER1, 25 - NETXBIG_LED_TIMER2, 26 - NETXBIG_LED_MODE_NUM, 27 - }; 28 - 29 - #define NETXBIG_LED_INVALID_MODE NETXBIG_LED_MODE_NUM 30 - 31 - struct netxbig_led_timer { 32 - unsigned long delay_on; 33 - unsigned long delay_off; 34 - enum netxbig_led_mode mode; 35 - }; 36 - 37 - struct netxbig_led { 38 - const char *name; 39 - const char *default_trigger; 40 - int mode_addr; 41 - int *mode_val; 42 - int bright_addr; 43 - int bright_max; 44 - }; 45 - 46 - struct netxbig_led_platform_data { 47 - struct netxbig_gpio_ext *gpio_ext; 48 - struct netxbig_led_timer *timer; 49 - int num_timer; 50 - struct netxbig_led *leds; 51 - int num_leds; 52 - }; 53 - 54 - #endif /* __LEDS_KIRKWOOD_NETXBIG_H */
+3
include/linux/platform_device.h
··· 51 51 extern void arch_setup_pdev_archdata(struct platform_device *); 52 52 extern struct resource *platform_get_resource(struct platform_device *, 53 53 unsigned int, unsigned int); 54 + extern struct device * 55 + platform_find_device_by_driver(struct device *start, 56 + const struct device_driver *drv); 54 57 extern void __iomem * 55 58 devm_platform_ioremap_resource(struct platform_device *pdev, 56 59 unsigned int index);
+1 -6
net/ieee802154/core.c
··· 23 23 LIST_HEAD(cfg802154_rdev_list); 24 24 int cfg802154_rdev_list_generation; 25 25 26 - static int wpan_phy_match(struct device *dev, const void *data) 27 - { 28 - return !strcmp(dev_name(dev), (const char *)data); 29 - } 30 - 31 26 struct wpan_phy *wpan_phy_find(const char *str) 32 27 { 33 28 struct device *dev; ··· 30 35 if (WARN_ON(!str)) 31 36 return NULL; 32 37 33 - dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match); 38 + dev = class_find_device_by_name(&wpan_phy_class, str); 34 39 if (!dev) 35 40 return NULL; 36 41
+2 -7
sound/soc/rockchip/rk3399_gru_sound.c
··· 422 422 }, 423 423 }; 424 424 425 - static int of_dev_node_match(struct device *dev, const void *data) 426 - { 427 - return dev->of_node == data; 428 - } 429 - 430 425 static int rockchip_sound_codec_node_match(struct device_node *np_codec) 431 426 { 432 427 struct device *dev; ··· 433 438 continue; 434 439 435 440 if (dailink_match[i].bus_type) { 436 - dev = bus_find_device(dailink_match[i].bus_type, NULL, 437 - np_codec, of_dev_node_match); 441 + dev = bus_find_device_by_of_node(dailink_match[i].bus_type, 442 + np_codec); 438 443 if (!dev) 439 444 continue; 440 445 put_device(dev);
+201
tools/leds/get_led_device_info.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + led_common_defs_path="include/dt-bindings/leds/common.h" 5 + 6 + num_args=$# 7 + if [ $num_args -eq 1 ]; then 8 + linux_top=$(dirname `realpath $0` | awk -F/ \ 9 + '{ \ 10 + i=1; \ 11 + while (i <= NF - 2) { \ 12 + printf $i"/"; \ 13 + i++; \ 14 + }; \ 15 + }') 16 + led_defs_path=$linux_top/$led_common_defs_path 17 + elif [ $num_args -eq 2 ]; then 18 + led_defs_path=`realpath $2` 19 + else 20 + echo "Usage: get_led_device_info.sh LED_CDEV_PATH [LED_COMMON_DEFS_PATH]" 21 + exit 1 22 + fi 23 + 24 + if [ ! -f $led_defs_path ]; then 25 + echo "$led_defs_path doesn't exist" 26 + exit 1 27 + fi 28 + 29 + led_cdev_path=`echo $1 | sed s'/\/$//'` 30 + 31 + ls "$led_cdev_path/brightness" > /dev/null 2>&1 32 + if [ $? -ne 0 ]; then 33 + echo "Device \"$led_cdev_path\" does not exist." 34 + exit 1 35 + fi 36 + 37 + bus=`readlink $led_cdev_path/device/subsystem | sed s'/.*\///'` 38 + usb_subdev=`readlink $led_cdev_path | grep usb | sed s'/\(.*usb[0-9]*\/[0-9]*-[0-9]*\)\/.*/\1/'` 39 + ls "$led_cdev_path/device/of_node/compatible" > /dev/null 2>&1 40 + of_node_missing=$? 41 + 42 + if [ "$bus" = "input" ]; then 43 + input_node=`readlink $led_cdev_path/device | sed s'/.*\///'` 44 + if [ ! -z "$usb_subdev" ]; then 45 + bus="usb" 46 + fi 47 + fi 48 + 49 + if [ "$bus" = "usb" ]; then 50 + usb_interface=`readlink $led_cdev_path | sed s'/.*\(usb[0-9]*\)/\1/' | cut -d\/ -f3` 51 + cd $led_cdev_path/../$usb_subdev 52 + driver=`readlink $usb_interface/driver | sed s'/.*\///'` 53 + if [ -d "$usb_interface/ieee80211" ]; then 54 + wifi_phy=`ls -l $usb_interface/ieee80211 | grep phy | awk '{print $9}'` 55 + fi 56 + idVendor=`cat idVendor` 57 + idProduct=`cat idProduct` 58 + manufacturer=`cat manufacturer` 59 + product=`cat product` 60 + elif [ "$bus" = "input" ]; then 61 + cd $led_cdev_path 62 + product=`cat device/name` 63 + driver=`cat device/device/driver/description` 64 + elif [ $of_node_missing -eq 0 ]; then 65 + cd $led_cdev_path 66 + compatible=`cat device/of_node/compatible` 67 + if [ "$compatible" = "gpio-leds" ]; then 68 + driver="leds-gpio" 69 + elif [ "$compatible" = "pwm-leds" ]; then 70 + driver="leds-pwm" 71 + else 72 + manufacturer=`echo $compatible | awk -F, '{print $1}'` 73 + product=`echo $compatible | awk -F, '{print $2}'` 74 + fi 75 + else 76 + echo "Unknown device type." 77 + exit 1 78 + fi 79 + 80 + printf "\n#####################################\n" 81 + printf "# LED class device hardware details #\n" 82 + printf "#####################################\n\n" 83 + 84 + printf "bus:\t\t\t$bus\n" 85 + 86 + if [ ! -z "$idVendor" ]; then 87 + printf "idVendor:\t\t$idVendor\n" 88 + fi 89 + 90 + if [ ! -z "$idProduct" ]; then 91 + printf "idProduct:\t\t$idProduct\n" 92 + fi 93 + 94 + if [ ! -z "$manufacturer" ]; then 95 + printf "manufacturer:\t\t$manufacturer\n" 96 + fi 97 + 98 + if [ ! -z "$product" ]; then 99 + printf "product:\t\t$product\n" 100 + fi 101 + 102 + if [ ! -z "$driver" ]; then 103 + printf "driver:\t\t\t$driver\n" 104 + fi 105 + 106 + if [ ! -z "$input_node" ]; then 107 + printf "associated input node:\t$input_node\n" 108 + fi 109 + 110 + printf "\n####################################\n" 111 + printf "# LED class device name validation #\n" 112 + printf "####################################\n\n" 113 + 114 + led_name=`echo $led_cdev_path | sed s'/.*\///'` 115 + 116 + num_sections=`echo $led_name | awk -F: '{print NF}'` 117 + 118 + if [ $num_sections -eq 1 ]; then 119 + printf "\":\" delimiter not detected.\t[ FAILED ]\n" 120 + exit 1 121 + elif [ $num_sections -eq 2 ]; then 122 + color=`echo $led_name | cut -d: -f1` 123 + function=`echo $led_name | cut -d: -f2` 124 + elif [ $num_sections -eq 3 ]; then 125 + devicename=`echo $led_name | cut -d: -f1` 126 + color=`echo $led_name | cut -d: -f2` 127 + function=`echo $led_name | cut -d: -f3` 128 + else 129 + printf "Detected %d sections in the LED class device name - should the script be updated?\n" $num_sections 130 + exit 1 131 + fi 132 + 133 + S_DEV="devicename" 134 + S_CLR="color " 135 + S_FUN="function " 136 + status_tab=20 137 + 138 + print_msg_ok() 139 + { 140 + local section_name="$1" 141 + local section_val="$2" 142 + local msg="$3" 143 + printf "$section_name :\t%-${status_tab}.${status_tab}s %s %s\n" "$section_val" "[ OK ] " "$msg" 144 + } 145 + 146 + print_msg_failed() 147 + { 148 + local section_name="$1" 149 + local section_val="$2" 150 + local msg="$3" 151 + printf "$section_name :\t%-${status_tab}.${status_tab}s %s %s\n" "$section_val" "[ FAILED ]" "$msg" 152 + } 153 + 154 + if [ ! -z "$input_node" ]; then 155 + expected_devname=$input_node 156 + elif [ ! -z "$wifi_phy" ]; then 157 + expected_devname=$wifi_phy 158 + fi 159 + 160 + if [ ! -z "$devicename" ]; then 161 + if [ ! -z "$expected_devname" ]; then 162 + if [ "$devicename" = "$expected_devname" ]; then 163 + print_msg_ok "$S_DEV" "$devicename" 164 + else 165 + print_msg_failed "$S_DEV" "$devicename" "Expected: $expected_devname" 166 + fi 167 + else 168 + if [ "$devicename" = "$manufacturer" ]; then 169 + print_msg_failed "$S_DEV" "$devicename" "Redundant: use of vendor name is discouraged" 170 + elif [ "$devicename" = "$product" ]; then 171 + print_msg_failed "$S_DEV" "$devicename" "Redundant: use of product name is discouraged" 172 + else 173 + print_msg_failed "$S_DEV" "$devicename" "Unknown devicename - should the script be updated?" 174 + fi 175 + fi 176 + elif [ ! -z "$expected_devname" ]; then 177 + print_msg_failed "$S_DEV" "blank" "Expected: $expected_devname" 178 + fi 179 + 180 + if [ ! -z "$color" ]; then 181 + color_upper=`echo $color | tr [:lower:] [:upper:]` 182 + color_id_definition=$(cat $led_defs_path | grep "_$color_upper\s" | awk '{print $2}') 183 + if [ ! -z "$color_id_definition" ]; then 184 + print_msg_ok "$S_CLR" "$color" "Matching definition: $color_id_definition" 185 + else 186 + print_msg_failed "$S_CLR" "$color" "Definition not found in $led_defs_path" 187 + fi 188 + 189 + fi 190 + 191 + if [ ! -z "$function" ]; then 192 + # strip optional enumerator 193 + function=`echo $function | sed s'/\(.*\)-[0-9]*$/\1/'` 194 + fun_definition=$(cat $led_defs_path | grep "\"$function\"" | awk '{print $2}') 195 + if [ ! -z "$fun_definition" ]; then 196 + print_msg_ok "$S_FUN" "$function" "Matching definition: $fun_definition" 197 + else 198 + print_msg_failed "$S_FUN" "$function" "Definition not found in $led_defs_path" 199 + fi 200 + 201 + fi