blob: 3d99066eb9a7479c6d5b0b2010b87c65af917fe1 [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 Subbanna61675c32016-11-30 15:52:15 +05305#include <fstream>
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +05306#include <sdbusplus/bus.hpp>
7#include <sdbusplus/server/object.hpp>
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +09308#include <string>
Vishwanatha Subbannae0891732017-03-10 15:27:23 +05309#include <xyz/openbmc_project/Led/Physical/server.hpp>
Andrew Jeffery42e02d32018-05-24 13:34:05 +093010
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053011namespace phosphor
12{
13namespace led
14{
Vishwanatha Subbanna61675c32016-11-30 15:52:15 +053015/** @brief Assert LED by writing 255 */
Andrew Jefferyaee9c2c2018-05-25 14:05:40 +093016constexpr unsigned long ASSERT = 255;
Vishwanatha Subbanna61675c32016-11-30 15:52:15 +053017
18/** @brief De-assert by writing "0" */
Andrew Jefferyaee9c2c2018-05-25 14:05:40 +093019constexpr unsigned long DEASSERT = 0;
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053020
21/** @class Physical
22 * @brief Responsible for applying actions on a particular physical LED
23 */
24class Physical : public sdbusplus::server::object::object<
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093025 sdbusplus::xyz::openbmc_project::Led::server::Physical>
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053026{
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093027 public:
28 Physical() = delete;
29 ~Physical() = default;
30 Physical(const Physical&) = delete;
31 Physical& operator=(const Physical&) = delete;
32 Physical(Physical&&) = delete;
33 Physical& operator=(Physical&&) = delete;
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053034
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093035 /** @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
43 */
44 Physical(sdbusplus::bus::bus& bus, const std::string& objPath,
Andrew Jeffery42e02d32018-05-24 13:34:05 +093045 SysfsLed& led) :
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +053046
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093047 sdbusplus::server::object::object<
48 sdbusplus::xyz::openbmc_project::Led::server::Physical>(
49 bus, objPath.c_str(), true),
Andrew Jeffery42e02d32018-05-24 13:34:05 +093050 led(led)
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093051 {
52 // Suppose this is getting launched as part of BMC reboot, then we
53 // need to save what the micro-controller currently has.
54 setInitialState();
55
56 // We are now ready.
57 emit_object_added();
58 }
59
60 /** @brief Overloaded State Property Setter function
61 *
62 * @param[in] value - One of OFF / ON / BLINK
63 * @return - Success or exception thrown
64 */
65 Action state(Action value) override;
66
67 private:
Andrew Jeffery42e02d32018-05-24 13:34:05 +093068 /** @brief Associated LED implementation
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093069 */
Andrew Jeffery42e02d32018-05-24 13:34:05 +093070 SysfsLed& led;
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093071
72 /** @brief Frequency range that the LED can operate on.
73 * Will be removed when frequency is put into interface
74 */
75 uint32_t frequency;
76
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +093077 /** @brief reads sysfs and then setsup the parameteres accordingly
78 *
79 * @return None
80 */
81 void setInitialState();
82
83 /** @brief Applies the user triggered action on the LED
84 * by writing to sysfs
85 *
86 * @param [in] current - Current state of LED
87 * @param [in] request - Requested state
88 *
89 * @return None
90 */
91 void driveLED(Action current, Action request);
92
93 /** @brief Sets the LED to either ON or OFF state
94 *
95 * @param [in] action - Requested action. Could be OFF or ON
96 * @return None
97 */
98 void stableStateOperation(Action action);
99
100 /** @brief Sets the LED to BLINKING
101 *
102 * @return None
103 */
104 void blinkOperation();
Vishwanatha Subbannabda97eb2016-11-30 12:21:25 +0530105};
106
107} // namespace led
Andrew Jefferyc41bf5b2018-05-25 16:39:22 +0930108} // namespace phosphor