Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Andrew Jeffery | 42e02d3 | 2018-05-24 13:34:05 +0930 | [diff] [blame] | 3 | #include "sysfs.hpp" |
| 4 | |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include <sdbusplus/server/object.hpp> |
Vishwanatha Subbanna | e089173 | 2017-03-10 15:27:23 +0530 | [diff] [blame] | 7 | #include <xyz/openbmc_project/Led/Physical/server.hpp> |
Andrew Jeffery | 42e02d3 | 2018-05-24 13:34:05 +0930 | [diff] [blame] | 8 | |
George Liu | 61b9063 | 2020-06-22 10:55:13 +0800 | [diff] [blame] | 9 | #include <fstream> |
| 10 | #include <string> |
| 11 | |
Jayashree Dhanapal | e48bf95 | 2022-08-17 17:34:32 +0530 | [diff] [blame] | 12 | namespace fs = std::filesystem; |
| 13 | |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 14 | namespace phosphor |
| 15 | { |
| 16 | namespace led |
| 17 | { |
Andrew Jeffery | 5b1417b | 2019-03-18 17:20:37 +1030 | [diff] [blame] | 18 | /** @brief De-assert value */ |
Andrew Jeffery | 8e85228 | 2023-02-06 19:29:43 +1030 | [diff] [blame] | 19 | constexpr unsigned long deasserted = 0; |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 20 | |
Patrick Williams | 97db22f | 2022-03-30 15:01:07 -0500 | [diff] [blame] | 21 | using PhysicalIfaces = sdbusplus::server::object_t< |
| 22 | sdbusplus::xyz::openbmc_project::Led::server::Physical>; |
Patrick Williams | 97db22f | 2022-03-30 15:01:07 -0500 | [diff] [blame] | 23 | |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 24 | /** @class Physical |
| 25 | * @brief Responsible for applying actions on a particular physical LED |
| 26 | */ |
Patrick Williams | 97db22f | 2022-03-30 15:01:07 -0500 | [diff] [blame] | 27 | class Physical : public PhysicalIfaces |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 28 | { |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 29 | public: |
| 30 | Physical() = delete; |
Andrew Jeffery | c060c28 | 2023-02-07 15:54:43 +1030 | [diff] [blame] | 31 | ~Physical() override = default; |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 32 | Physical(const Physical&) = delete; |
| 33 | Physical& operator=(const Physical&) = delete; |
| 34 | Physical(Physical&&) = delete; |
| 35 | Physical& operator=(Physical&&) = delete; |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 36 | |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 37 | /** @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 Soldatov | 97ddb72 | 2019-04-16 09:10:00 +0300 | [diff] [blame] | 45 | * @param[in] color - led color name |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 46 | */ |
Jayashree Dhanapal | e48bf95 | 2022-08-17 17:34:32 +0530 | [diff] [blame] | 47 | |
| 48 | Physical(sdbusplus::bus_t& bus, const std::string& objPath, |
| 49 | std::unique_ptr<phosphor::led::SysfsLed> led, |
Patrick Williams | ff3d538 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 50 | const std::string& color = "") : |
Patrick Williams | 97db22f | 2022-03-30 15:01:07 -0500 | [diff] [blame] | 51 | PhysicalIfaces(bus, objPath.c_str(), |
| 52 | PhysicalIfaces::action::defer_emit), |
Jayashree Dhanapal | e48bf95 | 2022-08-17 17:34:32 +0530 | [diff] [blame] | 53 | led(std::move(led)) |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 54 | { |
| 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 Eda | 29bd56b | 2024-06-17 14:46:52 +0530 | [diff] [blame] | 59 | // Read led color from environment and set it in DBus. |
Alexander Soldatov | 97ddb72 | 2019-04-16 09:10:00 +0300 | [diff] [blame] | 60 | setLedColor(color); |
| 61 | |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 62 | // 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 Eda | 29bd56b | 2024-06-17 14:46:52 +0530 | [diff] [blame] | 73 | /** @brief Overridden State Property Getter function |
Vishwanatha Subbanna | db21bc0 | 2021-03-26 00:32:46 -0500 | [diff] [blame] | 74 | * |
| 75 | * @return - One of OFF / ON / BLINK |
| 76 | */ |
| 77 | Action state() const override; |
| 78 | |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 79 | private: |
Andrew Jeffery | 42e02d3 | 2018-05-24 13:34:05 +0930 | [diff] [blame] | 80 | /** @brief Associated LED implementation |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 81 | */ |
Jayashree Dhanapal | e48bf95 | 2022-08-17 17:34:32 +0530 | [diff] [blame] | 82 | std::unique_ptr<phosphor::led::SysfsLed> led; |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 83 | |
Andrew Jeffery | 5b1417b | 2019-03-18 17:20:37 +1030 | [diff] [blame] | 84 | /** @brief The value that will assert the LED */ |
Andrew Jeffery | 478d0a7 | 2023-02-07 15:57:12 +1030 | [diff] [blame] | 85 | unsigned long assert{}; |
Andrew Jeffery | 5b1417b | 2019-03-18 17:20:37 +1030 | [diff] [blame] | 86 | |
Manojkiran Eda | 29bd56b | 2024-06-17 14:46:52 +0530 | [diff] [blame] | 87 | /** @brief reads sysfs and then setup the parameters accordingly |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 88 | * |
| 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 Soldatov | 97ddb72 | 2019-04-16 09:10:00 +0300 | [diff] [blame] | 115 | |
| 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 Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | } // namespace led |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 124 | } // namespace phosphor |