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