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 | |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 12 | namespace phosphor |
| 13 | { |
| 14 | namespace led |
| 15 | { |
Andrew Jeffery | 5b1417b | 2019-03-18 17:20:37 +1030 | [diff] [blame] | 16 | /** @brief De-assert value */ |
Andrew Jeffery | aee9c2c | 2018-05-25 14:05:40 +0930 | [diff] [blame] | 17 | constexpr unsigned long DEASSERT = 0; |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 18 | |
Patrick Williams | 97db22f | 2022-03-30 15:01:07 -0500 | [diff] [blame] | 19 | namespace |
| 20 | { |
| 21 | using PhysicalIfaces = sdbusplus::server::object_t< |
| 22 | sdbusplus::xyz::openbmc_project::Led::server::Physical>; |
| 23 | } |
| 24 | |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 25 | /** @class Physical |
| 26 | * @brief Responsible for applying actions on a particular physical LED |
| 27 | */ |
Patrick Williams | 97db22f | 2022-03-30 15:01:07 -0500 | [diff] [blame] | 28 | class Physical : public PhysicalIfaces |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 29 | { |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 30 | public: |
| 31 | Physical() = delete; |
| 32 | ~Physical() = default; |
| 33 | Physical(const Physical&) = delete; |
| 34 | Physical& operator=(const Physical&) = delete; |
| 35 | Physical(Physical&&) = delete; |
| 36 | Physical& operator=(Physical&&) = delete; |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 37 | |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 38 | /** @brief Constructs LED object. Argument 'true' says that we hold off |
| 39 | * from sending the signals since we need to do some house keeping and |
| 40 | * only when we finish that, we are considered active and can then |
| 41 | * broadcast the signal. |
| 42 | * |
| 43 | * @param[in] bus - system dbus handler |
| 44 | * @param[in] objPath - The Dbus path that hosts physical LED |
| 45 | * @param[in] ledPath - sysfs path where this LED is exported |
Alexander Soldatov | 97ddb72 | 2019-04-16 09:10:00 +0300 | [diff] [blame] | 46 | * @param[in] color - led color name |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 47 | */ |
Patrick Williams | ff3d538 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 48 | Physical(sdbusplus::bus_t& bus, const std::string& objPath, SysfsLed& led, |
| 49 | const std::string& color = "") : |
Patrick Williams | 97db22f | 2022-03-30 15:01:07 -0500 | [diff] [blame] | 50 | PhysicalIfaces(bus, objPath.c_str(), |
| 51 | PhysicalIfaces::action::defer_emit), |
Andrew Jeffery | 42e02d3 | 2018-05-24 13:34:05 +0930 | [diff] [blame] | 52 | led(led) |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 53 | { |
| 54 | // Suppose this is getting launched as part of BMC reboot, then we |
| 55 | // need to save what the micro-controller currently has. |
| 56 | setInitialState(); |
| 57 | |
Alexander Soldatov | 97ddb72 | 2019-04-16 09:10:00 +0300 | [diff] [blame] | 58 | // Read led color from enviroment and set it in DBus. |
| 59 | setLedColor(color); |
| 60 | |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 61 | // We are now ready. |
| 62 | emit_object_added(); |
| 63 | } |
| 64 | |
| 65 | /** @brief Overloaded State Property Setter function |
| 66 | * |
| 67 | * @param[in] value - One of OFF / ON / BLINK |
| 68 | * @return - Success or exception thrown |
| 69 | */ |
| 70 | Action state(Action value) override; |
| 71 | |
Vishwanatha Subbanna | db21bc0 | 2021-03-26 00:32:46 -0500 | [diff] [blame] | 72 | /** @brief Overriden State Property Getter function |
| 73 | * |
| 74 | * @return - One of OFF / ON / BLINK |
| 75 | */ |
| 76 | Action state() const override; |
| 77 | |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 78 | private: |
Andrew Jeffery | 42e02d3 | 2018-05-24 13:34:05 +0930 | [diff] [blame] | 79 | /** @brief Associated LED implementation |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 80 | */ |
Andrew Jeffery | 42e02d3 | 2018-05-24 13:34:05 +0930 | [diff] [blame] | 81 | SysfsLed& led; |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 82 | |
Andrew Jeffery | 5b1417b | 2019-03-18 17:20:37 +1030 | [diff] [blame] | 83 | /** @brief The value that will assert the LED */ |
| 84 | unsigned long assert; |
| 85 | |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 86 | /** @brief reads sysfs and then setsup the parameteres accordingly |
| 87 | * |
| 88 | * @return None |
| 89 | */ |
| 90 | void setInitialState(); |
| 91 | |
| 92 | /** @brief Applies the user triggered action on the LED |
| 93 | * by writing to sysfs |
| 94 | * |
| 95 | * @param [in] current - Current state of LED |
| 96 | * @param [in] request - Requested state |
| 97 | * |
| 98 | * @return None |
| 99 | */ |
| 100 | void driveLED(Action current, Action request); |
| 101 | |
| 102 | /** @brief Sets the LED to either ON or OFF state |
| 103 | * |
| 104 | * @param [in] action - Requested action. Could be OFF or ON |
| 105 | * @return None |
| 106 | */ |
| 107 | void stableStateOperation(Action action); |
| 108 | |
| 109 | /** @brief Sets the LED to BLINKING |
| 110 | * |
| 111 | * @return None |
| 112 | */ |
| 113 | void blinkOperation(); |
Alexander Soldatov | 97ddb72 | 2019-04-16 09:10:00 +0300 | [diff] [blame] | 114 | |
| 115 | /** @brief set led color property in DBus |
| 116 | * |
| 117 | * @param[in] color - led color name |
| 118 | */ |
| 119 | void setLedColor(const std::string& color); |
Vishwanatha Subbanna | bda97eb | 2016-11-30 12:21:25 +0530 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | } // namespace led |
Andrew Jeffery | c41bf5b | 2018-05-25 16:39:22 +0930 | [diff] [blame] | 123 | } // namespace phosphor |