2 # SPDX-License-Identifier: GPL-2.0
4 led_common_defs_path
="include/dt-bindings/leds/common.h"
7 if [ $num_args -eq 1 ]; then
8 linux_top
=$
(dirname `realpath $0` |
awk -F/ \
11 while (i <= NF - 2) { \
16 led_defs_path
=$linux_top/$led_common_defs_path
17 elif [ $num_args -eq 2 ]; then
18 led_defs_path
=`realpath $2`
20 echo "Usage: get_led_device_info.sh LED_CDEV_PATH [LED_COMMON_DEFS_PATH]"
24 if [ ! -f $led_defs_path ]; then
25 echo "$led_defs_path doesn't exist"
29 led_cdev_path
=`echo $1 | sed s'/\/$//'`
31 ls "$led_cdev_path/brightness" > /dev
/null
2>&1
33 echo "Device \"$led_cdev_path\" does not exist."
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
42 if [ "$bus" = "input" ]; then
43 input_node
=`readlink $led_cdev_path/device | sed s'/.*\///'`
44 if [ ! -z "$usb_subdev" ]; then
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}'`
56 idVendor
=`cat idVendor`
57 idProduct
=`cat idProduct`
58 manufacturer
=`cat manufacturer`
60 elif [ "$bus" = "input" ]; then
62 product
=`cat device/name`
63 driver
=`cat device/device/driver/description`
64 elif [ $of_node_missing -eq 0 ]; then
66 compatible
=`cat device/of_node/compatible`
67 if [ "$compatible" = "gpio-leds" ]; then
69 elif [ "$compatible" = "pwm-leds" ]; then
72 manufacturer
=`echo $compatible | awk -F, '{print $1}'`
73 product
=`echo $compatible | awk -F, '{print $2}'`
76 echo "Unknown device type."
80 printf "\n#####################################\n"
81 printf "# LED class device hardware details #\n"
82 printf "#####################################\n\n"
84 printf "bus:\t\t\t$bus\n"
86 if [ ! -z "$idVendor" ]; then
87 printf "idVendor:\t\t$idVendor\n"
90 if [ ! -z "$idProduct" ]; then
91 printf "idProduct:\t\t$idProduct\n"
94 if [ ! -z "$manufacturer" ]; then
95 printf "manufacturer:\t\t$manufacturer\n"
98 if [ ! -z "$product" ]; then
99 printf "product:\t\t$product\n"
102 if [ ! -z "$driver" ]; then
103 printf "driver:\t\t\t$driver\n"
106 if [ ! -z "$input_node" ]; then
107 printf "associated input node:\t$input_node\n"
110 printf "\n####################################\n"
111 printf "# LED class device name validation #\n"
112 printf "####################################\n\n"
114 led_name
=`echo $led_cdev_path | sed s'/.*\///'`
116 num_sections
=`echo $led_name | awk -F: '{print NF}'`
118 if [ $num_sections -eq 1 ]; then
119 printf "\":\" delimiter not detected.\t[ FAILED ]\n"
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`
129 printf "Detected %d sections in the LED class device name - should the script be updated?\n" $num_sections
140 local section_name
="$1"
141 local section_val
="$2"
143 printf "$section_name :\t%-${status_tab}.${status_tab}s %s %s\n" "$section_val" "[ OK ] " "$msg"
148 local section_name
="$1"
149 local section_val
="$2"
151 printf "$section_name :\t%-${status_tab}.${status_tab}s %s %s\n" "$section_val" "[ FAILED ]" "$msg"
154 if [ ! -z "$input_node" ]; then
155 expected_devname
=$input_node
156 elif [ ! -z "$wifi_phy" ]; then
157 expected_devname
=$wifi_phy
160 if [ ! -z "$devicename" ]; then
161 if [ ! -z "$expected_devname" ]; then
162 if [ "$devicename" = "$expected_devname" ]; then
163 print_msg_ok
"$S_DEV" "$devicename"
165 print_msg_failed
"$S_DEV" "$devicename" "Expected: $expected_devname"
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"
173 print_msg_failed
"$S_DEV" "$devicename" "Unknown devicename - should the script be updated?"
176 elif [ ! -z "$expected_devname" ]; then
177 print_msg_failed
"$S_DEV" "blank" "Expected: $expected_devname"
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"
186 print_msg_failed
"$S_CLR" "$color" "Definition not found in $led_defs_path"
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"
198 print_msg_failed
"$S_FUN" "$function" "Definition not found in $led_defs_path"