Naveen Moses | d219fa3 | 2022-07-20 00:01:46 +0530 | [diff] [blame] | 1 | |
| 2 | #pragma once |
Naveen Moses | d219fa3 | 2022-07-20 00:01:46 +0530 | [diff] [blame] | 3 | #include "button_factory.hpp" |
| 4 | #include "button_interface.hpp" |
| 5 | #include "common.hpp" |
Delphine CC Chiu | 15c60e2 | 2024-04-12 13:01:32 -0500 | [diff] [blame] | 6 | #include "config.hpp" |
Naveen Moses | d219fa3 | 2022-07-20 00:01:46 +0530 | [diff] [blame] | 7 | #include "gpio.hpp" |
| 8 | #include "xyz/openbmc_project/Chassis/Buttons/HostSelector/server.hpp" |
| 9 | #include "xyz/openbmc_project/Chassis/Common/error.hpp" |
| 10 | #include "xyz/openbmc_project/Inventory/Item/server.hpp" |
| 11 | |
| 12 | #include <unistd.h> |
| 13 | |
| 14 | #include <phosphor-logging/elog-errors.hpp> |
| 15 | #include <sdbusplus/bus.hpp> |
| 16 | #include <sdbusplus/bus/match.hpp> |
Rush Chen | 31ce375 | 2024-11-08 14:57:27 +0800 | [diff] [blame^] | 17 | static constexpr auto DEBUG_CARD_PRESENT_GPIO = "debug_card_present"; |
| 18 | static constexpr auto SERIAL_CONSOLE_SWITCH = "SERIAL_UART_MUX"; |
Naveen Moses | d219fa3 | 2022-07-20 00:01:46 +0530 | [diff] [blame] | 19 | |
| 20 | class SerialUartMux final : public ButtonIface |
| 21 | { |
| 22 | public: |
| 23 | SerialUartMux(sdbusplus::bus_t& bus, [[maybe_unused]] const char* path, |
Delphine CC Chiu | ccd7db0 | 2023-02-09 14:48:53 +0800 | [diff] [blame] | 24 | EventPtr& event, ButtonConfig& buttonCfg) : |
Naveen Moses | d219fa3 | 2022-07-20 00:01:46 +0530 | [diff] [blame] | 25 | ButtonIface(bus, event, buttonCfg) |
| 26 | { |
| 27 | init(); |
| 28 | |
| 29 | // read the platform specific config of host number to uart mux map |
| 30 | std::unordered_map<std::string, size_t> uartMuxMapJson = |
| 31 | buttonCfg.extraJsonInfo.at("serial_uart_mux_map") |
| 32 | .get<decltype(uartMuxMapJson)>(); |
| 33 | for (auto& [key, value] : uartMuxMapJson) |
| 34 | { |
| 35 | auto index = std::stoi(key); |
| 36 | serialUartMuxMap[index] = value; |
| 37 | } |
| 38 | if (buttonCfg.gpios.size() < 3) |
| 39 | { |
| 40 | throw std::runtime_error("not enough gpio configs found"); |
| 41 | } |
| 42 | |
| 43 | for (auto& gpio : buttonCfg.gpios) |
| 44 | { |
| 45 | if (gpio.name == DEBUG_CARD_PRESENT_GPIO) |
| 46 | { |
| 47 | debugCardPresentGpio = gpio; |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | gpioLineCount = buttonCfg.gpios.size() - 1; |
| 53 | } |
| 54 | |
| 55 | ~SerialUartMux() |
| 56 | { |
| 57 | deInit(); |
| 58 | } |
| 59 | void init() override; |
Rush Chen | 31ce375 | 2024-11-08 14:57:27 +0800 | [diff] [blame^] | 60 | static constexpr std::string getFormFactorName() |
Naveen Moses | d219fa3 | 2022-07-20 00:01:46 +0530 | [diff] [blame] | 61 | { |
| 62 | return SERIAL_CONSOLE_SWITCH; |
| 63 | } |
Rush Chen | 31ce375 | 2024-11-08 14:57:27 +0800 | [diff] [blame^] | 64 | static constexpr std::string getDbusObjectPath() |
Naveen Moses | d219fa3 | 2022-07-20 00:01:46 +0530 | [diff] [blame] | 65 | { |
| 66 | return "NO_DBUS_OBJECT"; |
| 67 | } |
| 68 | |
| 69 | void hostSelectorPositionChanged(sdbusplus::message_t& msg); |
| 70 | void configSerialConsoleMux(size_t position); |
| 71 | bool isOCPDebugCardPresent(); |
| 72 | |
Patrick Williams | 0d038f5 | 2023-05-10 07:50:40 -0500 | [diff] [blame] | 73 | void handleEvent(sd_event_source*, int, uint32_t) {} |
Naveen Moses | d219fa3 | 2022-07-20 00:01:46 +0530 | [diff] [blame] | 74 | |
| 75 | protected: |
| 76 | size_t gpioLineCount; |
| 77 | std::unique_ptr<sdbusplus::bus::match_t> hostPositionChanged; |
Delphine CC Chiu | ccd7db0 | 2023-02-09 14:48:53 +0800 | [diff] [blame] | 78 | GpioInfo debugCardPresentGpio; |
Naveen Moses | d219fa3 | 2022-07-20 00:01:46 +0530 | [diff] [blame] | 79 | std::unordered_map<size_t, size_t> serialUartMuxMap; |
| 80 | }; |