1*49b45700SJayashree Dhanapal# Physical LED Design Support
2*49b45700SJayashree Dhanapal
3*49b45700SJayashree DhanapalAuthor: Velumani T (Velu), [velumanit@hcl](mailto:velumanit@hcl.com) Jayashree D
4*49b45700SJayashree Dhanapal(Jayashree), [jayashree-d@hcl](mailto:jayashree-d@hcl.com)
5*49b45700SJayashree Dhanapal
6*49b45700SJayashree DhanapalOther contributors: None
7*49b45700SJayashree Dhanapal
8*49b45700SJayashree DhanapalCreated: July 10, 2022
9*49b45700SJayashree Dhanapal
10*49b45700SJayashree Dhanapal## Problem Description
11*49b45700SJayashree Dhanapal
12*49b45700SJayashree DhanapalThe existing phosphor-led-sysfs design exposes one service per LED configuration
13*49b45700SJayashree Dhanapalin device tree. Hence, multiple services will be created for multiple GPIO pins
14*49b45700SJayashree Dhanapalconfigured for LEDs.
15*49b45700SJayashree Dhanapal
16*49b45700SJayashree DhanapalThere are cases where multiple LEDs were configured in the device tree for each
17*49b45700SJayashree Dhanapalhost and needs to be paired as a group of LEDs for the specified host in the
18*49b45700SJayashree Dhanapalmulti host platform.
19*49b45700SJayashree Dhanapal
20*49b45700SJayashree DhanapalFor example, Power LED and System Identification LED combines into a single
21*49b45700SJayashree Dhanapalbicolor blue-yellow LED per host. A total of 4 × LEDs will be placed along the
22*49b45700SJayashree Dhanapalfront edge of the board in a grid. The grid will be 2 × rows of 2 × LEDs to
23*49b45700SJayashree Dhanapalmatch the layout of the card slots.
24*49b45700SJayashree Dhanapal
25*49b45700SJayashree DhanapalDepending on the status of each host, blue or yellow LED needs to be Blink, OFF
26*49b45700SJayashree Dhanapalor ON and other LEDs needs to be in OFF state. Therefore, bi-color LED needs to
27*49b45700SJayashree Dhanapalbe paired as a group and exposed in the userspace.
28*49b45700SJayashree Dhanapal
29*49b45700SJayashree DhanapalBased on the current design in phosphor-led-sysfs application, pairing groups
30*49b45700SJayashree Dhanapalwill be difficult, since it exposes one service per LED. To abstract this method
31*49b45700SJayashree Dhanapaland also to create LEDs under a single service, a new application is proposed.
32*49b45700SJayashree Dhanapal
33*49b45700SJayashree Dhanapal## Background and References
34*49b45700SJayashree Dhanapal
35*49b45700SJayashree DhanapalThe below diagram represents the overview for current physical LED design.
36*49b45700SJayashree Dhanapal
37*49b45700SJayashree Dhanapal```
38*49b45700SJayashree Dhanapal
39*49b45700SJayashree Dhanapal      KERNEL                 META-PHOSPHOR           PHOSPHOR-LED-SYSFS SERVICE
40*49b45700SJayashree Dhanapal
41*49b45700SJayashree Dhanapal   +------------+  Event 1   +----------+  LED 1  +-----------------------------+
42*49b45700SJayashree Dhanapal   |            |----------->|          |-------->|                             |
43*49b45700SJayashree Dhanapal   |    LED 1   |  Event 2   |          |  LED 2  | Service 1 :                 |
44*49b45700SJayashree Dhanapal   |            |----------->|   UDEV   |-------->|   xyz.openbmc_project.      |
45*49b45700SJayashree Dhanapal   |    LED 2   |   .....    |  Events  |  ....   |        Led.Controller.LED1  |
46*49b45700SJayashree Dhanapal   |            |   .....    |          |  ....   | Service 2 :                 |
47*49b45700SJayashree Dhanapal   |    LED 3   |  Event N   |          |  LED N  |   xyz.openbmc_project.      |
48*49b45700SJayashree Dhanapal   |            |----------->|          |-------->|        Led.Controller.LED2  |
49*49b45700SJayashree Dhanapal   |    LED 4   |            +----------+         |          .......            |
50*49b45700SJayashree Dhanapal   |            |                                 |          .......            |
51*49b45700SJayashree Dhanapal   |  .......   |                                 | Service N :                 |
52*49b45700SJayashree Dhanapal   |  .......   |                                 |   xyz.openbmc_project.      |
53*49b45700SJayashree Dhanapal   |  .......   |                                 |        Led.Controller.LEDN  |
54*49b45700SJayashree Dhanapal   |            |                                 +-----------------------------+
55*49b45700SJayashree Dhanapal   |    LED N   |                                             |
56*49b45700SJayashree Dhanapal   |            |                                             |
57*49b45700SJayashree Dhanapal   +------------+                                             V
58*49b45700SJayashree Dhanapal                                             +----------------------------------+
59*49b45700SJayashree Dhanapal                                             |                                  |
60*49b45700SJayashree Dhanapal                                             | Service 1 :                      |
61*49b45700SJayashree Dhanapal                                             |    /xyz/openbmc_project/<led1>   |
62*49b45700SJayashree Dhanapal                                             |                                  |
63*49b45700SJayashree Dhanapal                                             | Service 2 :                      |
64*49b45700SJayashree Dhanapal                                             |    /xyz/openbmc_project/<led2>   |
65*49b45700SJayashree Dhanapal                                             |          .......                 |
66*49b45700SJayashree Dhanapal                                             |          .......                 |
67*49b45700SJayashree Dhanapal                                             |                                  |
68*49b45700SJayashree Dhanapal                                             | Service N :                      |
69*49b45700SJayashree Dhanapal                                             |    /xyz/openbmc_project/<ledN>   |
70*49b45700SJayashree Dhanapal                                             |                                  |
71*49b45700SJayashree Dhanapal                                             +----------------------------------+
72*49b45700SJayashree Dhanapal
73*49b45700SJayashree Dhanapal                                                 PHOSPHSOR-LED-SYSFS DAEMON
74*49b45700SJayashree Dhanapal
75*49b45700SJayashree Dhanapal```
76*49b45700SJayashree Dhanapal
77*49b45700SJayashree DhanapalThe existing design uses sysfs entry as udev events for particular LED and
78*49b45700SJayashree Dhanapaltriggers the necessary action to generate the dbus object path and interface for
79*49b45700SJayashree Dhanapalthat specified service. It exposes one service per LED.
80*49b45700SJayashree Dhanapal
81*49b45700SJayashree Dhanapal**Example**
82*49b45700SJayashree Dhanapal
83*49b45700SJayashree Dhanapal```
84*49b45700SJayashree Dhanapal     busctl tree xyz.openbmc_project.LED.Controller.led1
85*49b45700SJayashree Dhanapal     `-/xyz
86*49b45700SJayashree Dhanapal       `-/xyz/openbmc_project
87*49b45700SJayashree Dhanapal         `-/xyz/openbmc_project/led
88*49b45700SJayashree Dhanapal           `-/xyz/openbmc_project/led/physical
89*49b45700SJayashree Dhanapal             `-/xyz/openbmc_project/led/physical/led1
90*49b45700SJayashree Dhanapal
91*49b45700SJayashree Dhanapal     busctl tree xyz.openbmc_project.LED.Controller.led2
92*49b45700SJayashree Dhanapal     `-/xyz
93*49b45700SJayashree Dhanapal       `-/xyz/openbmc_project
94*49b45700SJayashree Dhanapal         `-/xyz/openbmc_project/led
95*49b45700SJayashree Dhanapal           `-/xyz/openbmc_project/led/physical
96*49b45700SJayashree Dhanapal             `-/xyz/openbmc_project/led/physical/led2
97*49b45700SJayashree Dhanapal
98*49b45700SJayashree Dhanapal```
99*49b45700SJayashree Dhanapal
100*49b45700SJayashree Dhanapal## Requirements
101*49b45700SJayashree Dhanapal
102*49b45700SJayashree Dhanapal- To support the systemd service to trigger script.
103*49b45700SJayashree Dhanapal
104*49b45700SJayashree Dhanapal- Add DBUS API method for phosphor-led-sysfs daemon.
105*49b45700SJayashree Dhanapal
106*49b45700SJayashree Dhanapal## Proposed Design
107*49b45700SJayashree Dhanapal
108*49b45700SJayashree DhanapalThe below diagram represents the overview for proposed physical LED design.
109*49b45700SJayashree Dhanapal
110*49b45700SJayashree Dhanapal```
111*49b45700SJayashree Dhanapal
112*49b45700SJayashree Dhanapal      KERNEL                               PHOSPHOR-LED-SYSFS DAEMON
113*49b45700SJayashree Dhanapal
114*49b45700SJayashree Dhanapal   +------------+  Event 1   +--------+      +---------+      +--------------+
115*49b45700SJayashree Dhanapal   |            |----------> |        |      |         |      |              |
116*49b45700SJayashree Dhanapal   |   LED 1    |  Event 2   |  UDEV  |      |  SYSFS  |      |  EXECUTABLE  |
117*49b45700SJayashree Dhanapal   |            |----------> | Events |----->| SERVICE |----->| (DBUS Method |
118*49b45700SJayashree Dhanapal   |   LED 2    |  .....     |        |      |         |      |    call)     |
119*49b45700SJayashree Dhanapal   |            |  Event N   |        |      |         |      |              |
120*49b45700SJayashree Dhanapal   |   LED 3    |----------> +--------+      +---------+      +--------------+
121*49b45700SJayashree Dhanapal   |            |                                                  |
122*49b45700SJayashree Dhanapal   |            |                                                  V
123*49b45700SJayashree Dhanapal   |   LED 4    |           +------------------------------------------------------+
124*49b45700SJayashree Dhanapal   |            |           |  +-----------+   +---------------------------------+ |
125*49b45700SJayashree Dhanapal   |  .......   |           |  |           |   | Service :                       | |
126*49b45700SJayashree Dhanapal   |  .......   |           |  |  SYSTEMD  |   |                                 | |
127*49b45700SJayashree Dhanapal   |  .......   |           |  |  SERVICE  |   |  /xyz/openbmc_project/led/<led1>| |
128*49b45700SJayashree Dhanapal   |            |           |  |  ( LED.   |-->|  /xyz/openbmc_project/led/<led2>| |
129*49b45700SJayashree Dhanapal   |   LED N    |           |  |Controller)|   |               .....             | |
130*49b45700SJayashree Dhanapal   |            |           |  |           |   |               .....             | |
131*49b45700SJayashree Dhanapal   |            |           |  |           |   |  /xyz/openbmc_project/led/<ledN>| |
132*49b45700SJayashree Dhanapal   +------------+           |  +-----------+   +---------------------------------+ |
133*49b45700SJayashree Dhanapal                            +------------------------------------------------------+
134*49b45700SJayashree Dhanapal
135*49b45700SJayashree Dhanapal```
136*49b45700SJayashree Dhanapal
137*49b45700SJayashree DhanapalThis document proposes a new design for physical LED implementation.
138*49b45700SJayashree Dhanapal
139*49b45700SJayashree Dhanapal- Physical Leds are defined in the device tree under "leds" section and
140*49b45700SJayashree Dhanapal  corresponding GPIO pins are configured.
141*49b45700SJayashree Dhanapal
142*49b45700SJayashree Dhanapal```
143*49b45700SJayashree Dhanapal        leds {
144*49b45700SJayashree Dhanapal                compatible = "gpio-leds";
145*49b45700SJayashree Dhanapal
146*49b45700SJayashree Dhanapal                ledName {
147*49b45700SJayashree Dhanapal                        label = "devicename:color:function";
148*49b45700SJayashree Dhanapal                        gpios = <&gpio ASPEED_GPIO(M, 0) GPIO_ACTIVE_HIGH>;
149*49b45700SJayashree Dhanapal                };
150*49b45700SJayashree Dhanapal        };
151*49b45700SJayashree Dhanapal```
152*49b45700SJayashree Dhanapal
153*49b45700SJayashree Dhanapal- Dbus API method will be created in the phosphor-led-sysfs repository under
154*49b45700SJayashree Dhanapal  **_xyz.openbmc_project.Led.Sysfs.Internal_** interface name to add or remove
155*49b45700SJayashree Dhanapal  the LED, which will be coming from each udev LED event.
156*49b45700SJayashree Dhanapal
157*49b45700SJayashree Dhanapal```
158*49b45700SJayashree Dhanapal    NAME                                   TYPE      SIGNATURE  RESULT/VALUE  FLAGS
159*49b45700SJayashree Dhanapal
160*49b45700SJayashree Dhanapal    xyz.openbmc_project.Led.Sysfs.Internal interface -          -             -
161*49b45700SJayashree Dhanapal    .AddLED                                method    s          -             -
162*49b45700SJayashree Dhanapal    .RemoveLED                             method    s          -             -
163*49b45700SJayashree Dhanapal
164*49b45700SJayashree Dhanapal```
165*49b45700SJayashree Dhanapal
166*49b45700SJayashree Dhanapal- udev event will be triggered for each LED and service will be invoked to run
167*49b45700SJayashree Dhanapal  the executable for each LED event.
168*49b45700SJayashree Dhanapal
169*49b45700SJayashree Dhanapal- Executable will call Dbus API method in the phosphor-led-sysfs repository to
170*49b45700SJayashree Dhanapal  pass LED name as argument from udev, after the primary service started.
171*49b45700SJayashree Dhanapal
172*49b45700SJayashree Dhanapal- Phosphor-led-sysfs will have a single systemd service (primary service)
173*49b45700SJayashree Dhanapal  **_(xyz.openbmc_project.LED.Controller.service)_** running by default at
174*49b45700SJayashree Dhanapal  system startup.
175*49b45700SJayashree Dhanapal
176*49b45700SJayashree Dhanapal- Once Dbus API method call invoked, phosphor-led-sysfs daemon will retrieve the
177*49b45700SJayashree Dhanapal  LED name as parameter and map the name with /sys/class/leds path in the
178*49b45700SJayashree Dhanapal  hardware. Next, the dbus pbject path and interface will be created under
179*49b45700SJayashree Dhanapal  single systemd service (xyz.openbmc_project.LED.Controller).
180*49b45700SJayashree Dhanapal
181*49b45700SJayashree Dhanapal- The schema will be implemented in the phosphor-led-sysfs daemon. A group of
182*49b45700SJayashree Dhanapal  LEDs is paired for each host and the schema handles color control for that
183*49b45700SJayashree Dhanapal  group to activate one LED which must be Blink/ON/OFF state and set the
184*49b45700SJayashree Dhanapal  remaining LEDs in the group as OFF state.
185*49b45700SJayashree Dhanapal
186*49b45700SJayashree Dhanapal**_Example_**
187*49b45700SJayashree Dhanapal
188*49b45700SJayashree Dhanapal```
189*49b45700SJayashree Dhanapal
190*49b45700SJayashree Dhanapal   SERVICE        xyz.openbmc_project.LED.Controller
191*49b45700SJayashree Dhanapal
192*49b45700SJayashree Dhanapal   INTERFACE      xyz.openbmc_project.LED.Physical
193*49b45700SJayashree Dhanapal
194*49b45700SJayashree Dhanapal   OBJECT PATH
195*49b45700SJayashree Dhanapal
196*49b45700SJayashree Dhanapal     busctl tree xyz.openbmc_project.LED.Controller
197*49b45700SJayashree Dhanapal     `-/xyz
198*49b45700SJayashree Dhanapal       `-/xyz/openbmc_project
199*49b45700SJayashree Dhanapal         `-/xyz/openbmc_project/led
200*49b45700SJayashree Dhanapal           `-/xyz/openbmc_project/led/physical
201*49b45700SJayashree Dhanapal             `-/xyz/openbmc_project/led/physical/led1
202*49b45700SJayashree Dhanapal             `-/xyz/openbmc_project/led/physical/led2
203*49b45700SJayashree Dhanapal                         ............
204*49b45700SJayashree Dhanapal                         ............
205*49b45700SJayashree Dhanapal             `-/xyz/openbmc_project/led/physical/ledN
206*49b45700SJayashree Dhanapal```
207*49b45700SJayashree Dhanapal
208*49b45700SJayashree Dhanapal## Alternatives Considered
209*49b45700SJayashree Dhanapal
210*49b45700SJayashree Dhanapal**Approach 1**
211*49b45700SJayashree Dhanapal
212*49b45700SJayashree DhanapalWhen the udev event is initialized for the LED, it will save those LED names in
213*49b45700SJayashree Dhanapala file utilizing the script. Phosphor-led-sysfs will monitor the file using
214*49b45700SJayashree Dhanapalinotify to handle the changes. By reading the file, all the LEDs name will be
215*49b45700SJayashree Dhanapalretrieved and dbus path will be created for all the LEDs under single systemd
216*49b45700SJayashree Dhanapalservice.
217*49b45700SJayashree Dhanapal
218*49b45700SJayashree Dhanapalinotify will monitor the file continuously and it needs to communicate between
219*49b45700SJayashree Dhanapaludev events and phosphor-led-sysfs application. Since, udev events can be
220*49b45700SJayashree Dhanapalgenerated before systemd service, inotify does not need to monitor the file
221*49b45700SJayashree Dhanapalafterwards and also it is not a well used mechanism to communicate.
222*49b45700SJayashree Dhanapal
223*49b45700SJayashree DhanapalExecutable for Dbus method is a better way to communicate with the application
224*49b45700SJayashree Dhanapalafter the system startup and populate the dbus path for LEDs under single
225*49b45700SJayashree Dhanapalservice.
226*49b45700SJayashree Dhanapal
227*49b45700SJayashree Dhanapal## Impacts
228*49b45700SJayashree Dhanapal
229*49b45700SJayashree DhanapalThese changes will have API impact since the dbus objects will exposes multiple
230*49b45700SJayashree DhanapalLEDs path in single service. The systemd service will have single name
231*49b45700SJayashree Dhanapal**_xyz.openbmc_project.LED.Controller_** instead of multiple services.
232*49b45700SJayashree Dhanapal
233*49b45700SJayashree Dhanapal## Testing
234*49b45700SJayashree Dhanapal
235*49b45700SJayashree DhanapalThe proposed design is tested in a multiple hosts platform.
236*49b45700SJayashree Dhanapal
237*49b45700SJayashree Dhanapal**_Manual Test_** - The physical LEDs status will be tested using busctl
238*49b45700SJayashree Dhanapalcommands in the hardware.
239*49b45700SJayashree Dhanapal
240*49b45700SJayashree Dhanapal**_Robot Test_** - The physical LEDs will be tested under robotframework using
241*49b45700SJayashree DhanapalREST API in the system LEDs suite.
242*49b45700SJayashree Dhanapal
243*49b45700SJayashree Dhanapal**_Unit Test_** - The proposed code can be covered by the unit tests which are
244*49b45700SJayashree Dhanapalalready present.
245