blob: 14b7655231c7fd8e0f9a0b78c6913a1fcc87848f [file] [log] [blame]
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +05301#pragma once
2
Andrew Jeffery42e02d32018-05-24 13:34:05 +09303#include "sysfs.hpp"
4
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +05305#include <sdbusplus/bus.hpp>
6#include <sdbusplus/server/object.hpp>
Vishwanatha Subbannae0891732017-03-10 15:27:23 +05307#include <xyz/openbmc_project/Led/Physical/server.hpp>
Andrew Jeffery42e02d32018-05-24 13:34:05 +09308
George Liu61b90632020-06-22 10:55:13 +08009#include <fstream>
10#include <string>
11
Jayashree Dhanapale48bf952022-08-17 17:34:32 +053012namespace fs = std::filesystem;
13
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053014namespace phosphor
15{
16namespace led
17{
Andrew Jeffery5b1417b2019-03-18 17:20:37 +103018/** @brief De-assert value */
Andrew Jeffery8e852282023-02-06 19:29:43 +103019constexpr unsigned long deasserted = 0;
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053020
Patrick Williams97db22f2022-03-30 15:01:07 -050021using PhysicalIfaces = sdbusplus::server::object_t<
22 sdbusplus::xyz::openbmc_project::Led::server::Physical>;
Patrick Williams97db22f2022-03-30 15:01:07 -050023
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053024/** @class Physical
25 * @brief Responsible for applying actions on a particular physical LED
26 */
Patrick Williams97db22f2022-03-30 15:01:07 -050027class Physical : public PhysicalIfaces
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053028{
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093029 public:
30 Physical() = delete;
Andrew Jefferyc060c282023-02-07 15:54:43 +103031 ~Physical() override = default;
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093032 Physical(const Physical&) = delete;
33 Physical& operator=(const Physical&) = delete;
34 Physical(Physical&&) = delete;
35 Physical& operator=(Physical&&) = delete;
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053036
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093037 /** @brief Constructs LED object. Argument 'true' says that we hold off
38 * from sending the signals since we need to do some house keeping and
39 * only when we finish that, we are considered active and can then
40 * broadcast the signal.
41 *
42 * @param[in] bus - system dbus handler
43 * @param[in] objPath - The Dbus path that hosts physical LED
44 * @param[in] ledPath - sysfs path where this LED is exported
Alexander Soldatov97ddb722019-04-16 09:10:00 +030045 * @param[in] color - led color name
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093046 */
Jayashree Dhanapale48bf952022-08-17 17:34:32 +053047
48 Physical(sdbusplus::bus_t& bus, const std::string& objPath,
49 std::unique_ptr<phosphor::led::SysfsLed> led,
Patrick Williamsff3d5382022-07-22 19:26:55 -050050 const std::string& color = "") :
Patrick Williams97db22f2022-03-30 15:01:07 -050051 PhysicalIfaces(bus, objPath.c_str(),
52 PhysicalIfaces::action::defer_emit),
Jayashree Dhanapale48bf952022-08-17 17:34:32 +053053 led(std::move(led))
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093054 {
55 // Suppose this is getting launched as part of BMC reboot, then we
56 // need to save what the micro-controller currently has.
57 setInitialState();
58
Manojkiran Eda29bd56b2024-06-17 14:46:52 +053059 // Read led color from environment and set it in DBus.
Alexander Soldatov97ddb722019-04-16 09:10:00 +030060 setLedColor(color);
61
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093062 // We are now ready.
63 emit_object_added();
64 }
65
66 /** @brief Overloaded State Property Setter function
67 *
68 * @param[in] value - One of OFF / ON / BLINK
69 * @return - Success or exception thrown
70 */
71 Action state(Action value) override;
72
Manojkiran Eda29bd56b2024-06-17 14:46:52 +053073 /** @brief Overridden State Property Getter function
Vishwanatha Subbannadb21bc02021-03-26 00:32:46 -050074 *
75 * @return - One of OFF / ON / BLINK
76 */
77 Action state() const override;
78
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093079 private:
Andrew Jeffery42e02d32018-05-24 13:34:05 +093080 /** @brief Associated LED implementation
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093081 */
Jayashree Dhanapale48bf952022-08-17 17:34:32 +053082 std::unique_ptr<phosphor::led::SysfsLed> led;
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093083
Andrew Jeffery5b1417b2019-03-18 17:20:37 +103084 /** @brief The value that will assert the LED */
Andrew Jeffery478d0a72023-02-07 15:57:12 +103085 unsigned long assert{};
Andrew Jeffery5b1417b2019-03-18 17:20:37 +103086
Manojkiran Eda29bd56b2024-06-17 14:46:52 +053087 /** @brief reads sysfs and then setup the parameters accordingly
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093088 *
89 * @return None
90 */
91 void setInitialState();
92
93 /** @brief Applies the user triggered action on the LED
94 * by writing to sysfs
95 *
96 * @param [in] current - Current state of LED
97 * @param [in] request - Requested state
98 *
99 * @return None
100 */
101 void driveLED(Action current, Action request);
102
103 /** @brief Sets the LED to either ON or OFF state
104 *
105 * @param [in] action - Requested action. Could be OFF or ON
106 * @return None
107 */
108 void stableStateOperation(Action action);
109
110 /** @brief Sets the LED to BLINKING
111 *
112 * @return None
113 */
114 void blinkOperation();
Alexander Soldatov97ddb722019-04-16 09:10:00 +0300115
116 /** @brief set led color property in DBus
117 *
118 * @param[in] color - led color name
119 */
120 void setLedColor(const std::string& color);
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +0530121};
122
123} // namespace led
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +0930124} // namespace phosphor