Name Date Size #Lines LOC

..--

inc/H--1,377796

service_files/H--2720

src/H--1,8871,446

subprojects/H--4230

.clang-formatH A D01-Feb-20253.7 KiB137135

.clang-tidyH A D18-Aug-2025147 96

.gitignoreH A D20-Jun-202241 33

LICENSEH A D02-Aug-201811.1 KiB202169

OWNERSH A D24-Feb-20251.7 KiB5348

README.mdH A D09-Oct-20259.7 KiB411348

meson.buildH A D09-Jul-20252.6 KiB10088

meson.optionsH A D03-Mar-2025946 4337

meson_config.hpp.inH A D08-Nov-20241.4 KiB3629

README.md

1# phosphor-buttons
2
3Phosphor-buttons has a collection of IO event handler interfaces for physical
4inputs which are typically part of some sort of panel.
5
6It defines an individual dbus interface object for each physical button/switch
7inputs such as power button, reset button etc. Each button interface monitors
8its associated IO for event changes and emits signals that the button-handler
9application listens for.
10
11## Button Behavior
12
13### Power Button
14
15All events occur when the button is released.
16
17If the power is off, power on the host.
18
19If the power is on, it depends on how long the press was and which options are
20enabled:
21
22- Short press: Do a host power off
23- Long press, as determined by the 'long-press-time-ms' meson option: Do a
24  chassis (hard) power off.
25
26#### Custom Power Button Profiles
27
28The 'power-button-profile' meson option can be used to select custom power
29button profiles that have different behaviors.
30
31Available profiles are:
32
33- host_then_chassis_poweroff: When power is on, short presses are ignored and a
34  long press issues a host power off first and then a chassis power off if held
35  past a certain time. [This class](inc/host_then_chassis_poweroff.hpp) has
36  additional details.
37
38### Multi-Host Buttons
39
40See [this section below](#group-gpio-config).
41
42### Reset Button
43
44When released:
45
46- If 'reset-button-do-warm-reboot' meson option is set to enabled, does warm
47  reboot the host.
48- Otherwise, reboots the host (default behavior)
49
50### ID Button
51
52When released, toggles the 'enclosure_identify' LED group provided by the
53phosphor-led-manager repository. The group name can be changed using the
54'id-led-group' meson option.
55
56## Gpio defs config
57
58In order to monitor a button/input interface the respective gpio config details
59should be mentioned in the gpio defs json file -
60`/etc/default/obmc/gpio/gpio_defs.json`
61
621. The button interface type name.
632. An array consists of single or multiple gpio configs associated with the
64   specific button interface.
65
66A gpio can be mapped using the "pin" or "num" keyword. The "pin" key uses
67alphanumerical references while the "num" key supports the integer pin number.
68
69## example gpio def Json config
70
71```json
72{
73  "gpio_definitions": [
74    {
75      "name": "POWER_BUTTON",
76      "pin": "D0",
77      "direction": "both"
78    },
79    {
80      "name": "RESET_BUTTON",
81      "pin": "AB0",
82      "direction": "both"
83    },
84    {
85      "name": "HOST_SELECTOR",
86
87      "group_gpio_config": [
88        {
89          "pin": "AA4",
90          "direction": "both"
91        },
92        {
93          "pin": "AA5",
94          "direction": "both"
95        },
96        {
97          "pin": "AA6",
98          "direction": "both"
99        },
100        {
101          "pin": "AA7",
102          "direction": "both"
103        }
104      ]
105    }
106  ]
107}
108```
109
110## Single gpio config
111
112This config is original config which can be used for configs with only single
113gpio such as power button,reset button, OCP debug card host select button.
114
115```json
116{
117  "name": "POWER_BUTTON",
118  "pin": "D0",
119  "direction": "both"
120}
121```
122
123**Note:** this config is used by most of the other platforms so this format is
124kept as it is so that existing gpio configs do not get affected.
125
126## Group gpio config
127
128The following configs are related to multi-host bmc systems more info explained
129in the design:
130<https://github.com/openbmc/docs/blob/master/designs/multihost-phosphor-buttons.md>
131
132### Host selector gpio config example
133
134The host selector has four gpios associated. So the related gpios are mentioned
135in a json array named group_gpio_config.
136
137- name - This is name of the specific gpio line
138- pin - This represents the pin number from linux dts file.
139- polarity - polarity type of the gpio
140- max_position - This represents the max number of hosts in the multi-host bmc
141  system.
142- host_selector_map - This map is oem specific host position map which has how
143  the value read from the host selector gpios is mapped to the respective host
144  number.
145
146**Optional: Polling Configuration** Some platforms expose the host selector via
147a CPLD as GPIO inputs without edge-triggered interrupt support (e.g., no edge
148detection on GPIOs). In such situations, software-based polling mode can be
149enabled using the following optional fields in the JSON configuration:
150
151- **polling_mode** : Set to `true` to enable polling mode.
152- **polling_interval_ms** (optional): Polling interval in milliseconds. Defaults
153  to `1000` ms if not specified.
154
155**Optional: Virtual Button Configuration** Some platforms implement HostSelector
156objects without actual power button control functionality. To prevent
157interference with multi-power button mode detection:
158
159- **virtual_button** : Set to `true` when not used as power button, e.g., OCP
160  debug card. Defaults to false if not specified.
161
162### Config Example
163
164#### A.Interrupt example
165
166Example : The value of "7" derived from the 4 host select gpio lines are mapped
167to host position 1.
168
169```json
170{
171  "name": "HOST_SELECTOR",
172
173  "group_gpio_config": [
174    {
175      "name": "host_select_0",
176      "pin": "AA4",
177      "direction": "both",
178      "polarity": "active_high"
179    },
180    {
181      "name": "host_select_1",
182      "pin": "AA5",
183      "direction": "both",
184      "polarity": "active_high"
185    },
186    {
187      "name": "host_select_2",
188      "pin": "AA6",
189      "direction": "both",
190      "polarity": "active_high"
191    },
192    {
193      "name": "host_select_3",
194      "pin": "AA7",
195      "direction": "both",
196      "polarity": "active_high"
197    }
198  ],
199  "max_position": 4,
200  "host_selector_map": {
201    "6": 0,
202    "7": 1,
203    "8": 2,
204    "9": 3,
205    "10": 4,
206    "11": 0,
207    "12": 1,
208    "13": 2,
209    "14": 3,
210    "15": 4
211  }
212}
213```
214
215#### B.Polling example
216
217```json
218{
219  "name": "HOST_SELECTOR",
220  "polling_mode": true,
221  "polling_interval_ms": 3000,
222  "group_gpio_config": [
223    {
224      "name": "host_select_sel_0",
225      "num": 2340,
226      "direction": "in",
227      "polarity": "active_low"
228    },
229    {
230      "name": "host_select_sel_1",
231      "num": 2341,
232      "direction": "in",
233      "polarity": "active_low"
234    },
235    {
236      "name": "host_select_sel_2",
237      "num": 2342,
238      "direction": "in",
239      "polarity": "active_low"
240    },
241    {
242      "name": "host_select_sel_3",
243      "num": 2343,
244      "direction": "in",
245      "polarity": "active_low"
246    }
247  ],
248  "max_position": 8,
249  "host_selector_map": {
250    "0": 0,
251    "1": 1,
252    "2": 2,
253    "3": 3,
254    "4": 4,
255    "5": 5,
256    "6": 6,
257    "7": 7,
258    "8": 8
259  }
260}
261```
262
263### Host selector cpld config example
264
265There are also some systems that get the host selector selection from the CPLD,
266the configuration is provided below.
267
268- name - The button interface type name.
269- i2c_bus - The i2c bus of cpld
270- i2c_address - The i2c address of cpld
271- register_name - The register file name exported by CLD driver for IO event
272  listen
273- max_position - This represents the max number of hosts in the multi-host bmc
274  system.
275
276```json
277{
278  "cpld_definitions": [
279    {
280      "name": "HOST_SELECTOR",
281      "i2c_bus": 12,
282      "i2c_address": 15,
283      "register_name": "uart-selection-debug-card",
284      "max_position": 4
285    }
286  ]
287}
288```
289
290### Serial uart mux config
291
292Similar to host selector there are multiple gpios associated with the serial
293uart mux. These gpio configs are specified as part of json array
294"group_gpio_config".
295
296Here the serial uart mux output is accessed via OCP debug card. SO the OCP debug
297card present gpio is mentioned part of the group_gpio_config. The debug card
298present gpio is identified by its name "debug_card_present".
299
300The other gpios part of the group gpio config is serial uart MUX gpio select
301lines and serial_uart_rx line.
302
303- name - this is name of the specific gpio line
304- pin - this represents the pin number from linux dts file.
305- polarity - polarity type of the gpio
306- serial_uart_mux_map - This is the map for selected host position to the serial
307  uart mux select output value
308
309```json
310{
311  "name": "SERIAL_UART_MUX",
312
313  "group_gpio_config": [
314    {
315      "name": "serial_uart_sel_0",
316      "pin": "E0",
317      "direction": "out",
318      "polarity": "active_high"
319    },
320    {
321      "name": "serial_uart_sel_1",
322      "pin": "E1",
323      "direction": "out",
324      "polarity": "active_high"
325    },
326    {
327      "name": "serial_uart_sel_2",
328      "pin": "E2",
329      "direction": "out",
330      "polarity": "active_high"
331    },
332    {
333      "name": "serial_uart_sel_3",
334      "pin": "E3",
335      "direction": "out",
336      "polarity": "active_high"
337    },
338    {
339      "name": "serial_uart_rx",
340      "pin": "E4",
341      "direction": "out",
342      "polarity": "active_high"
343    },
344    {
345      "name": "debug_card_present",
346      "pin": "R3",
347      "direction": "both",
348      "polarity": "active_high"
349    }
350  ],
351  "serial_uart_mux_map": {
352    "0": 4,
353    "1": 0,
354    "2": 1,
355    "3": 2,
356    "4": 3
357  }
358}
359```
360
361## Multiple power gpio config example
362
363This config is used for configs with multiple power buttons on each slots and
364whole sled, or for which needs multi-level chassis power control behavior.
365
366name - this is name of the specific gpio line, "POWER_BUTTON" + the index of
367chassis instance
368
369- pin - this represents the pin number from linux dts file.
370- multi-action - default no action, set the corresponding behavior with
371  following format:
372- duration - activate when pulling gpio over this value (unit: millisecond)
373- action - chassis power control behavior
374
375```json
376{
377  "gpio_definitions": [
378    {
379      "name": "POWER_BUTTON0",
380      "pin": "I6",
381      "direction": "both",
382      "multi-action": [
383        {
384          "duration": 4000,
385          "action": "chassis cycle"
386        }
387      ]
388    },
389    {
390      "name": "POWER_BUTTON1",
391      "pin": "V0",
392      "direction": "both",
393      "multi-action": [
394        {
395          "duration": 0,
396          "action": "chassis on"
397        },
398        {
399          "duration": 4000,
400          "action": "chassis cycle"
401        },
402        {
403          "duration": 8000,
404          "action": "chassis off"
405        }
406      ]
407    }
408  ]
409}
410```
411