blob: 1e954da1d9ed392614c57119c0fa6c213b49637b [file] [log] [blame]
Naveen Mosesd219fa32022-07-20 00:01:46 +05301
2#pragma once
Naveen Mosesd219fa32022-07-20 00:01:46 +05303#include "button_factory.hpp"
4#include "button_interface.hpp"
5#include "common.hpp"
Delphine CC Chiu15c60e22024-04-12 13:01:32 -05006#include "config.hpp"
Naveen Mosesd219fa32022-07-20 00:01:46 +05307#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 Chen31ce3752024-11-08 14:57:27 +080017static constexpr auto DEBUG_CARD_PRESENT_GPIO = "debug_card_present";
18static constexpr auto SERIAL_CONSOLE_SWITCH = "SERIAL_UART_MUX";
Naveen Mosesd219fa32022-07-20 00:01:46 +053019
20class SerialUartMux final : public ButtonIface
21{
22 public:
23 SerialUartMux(sdbusplus::bus_t& bus, [[maybe_unused]] const char* path,
Delphine CC Chiuccd7db02023-02-09 14:48:53 +080024 EventPtr& event, ButtonConfig& buttonCfg) :
Naveen Mosesd219fa32022-07-20 00:01:46 +053025 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 Chen31ce3752024-11-08 14:57:27 +080060 static constexpr std::string getFormFactorName()
Naveen Mosesd219fa32022-07-20 00:01:46 +053061 {
62 return SERIAL_CONSOLE_SWITCH;
63 }
Rush Chen31ce3752024-11-08 14:57:27 +080064 static constexpr std::string getDbusObjectPath()
Naveen Mosesd219fa32022-07-20 00:01:46 +053065 {
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 Williams0d038f52023-05-10 07:50:40 -050073 void handleEvent(sd_event_source*, int, uint32_t) {}
Naveen Mosesd219fa32022-07-20 00:01:46 +053074
75 protected:
76 size_t gpioLineCount;
77 std::unique_ptr<sdbusplus::bus::match_t> hostPositionChanged;
Delphine CC Chiuccd7db02023-02-09 14:48:53 +080078 GpioInfo debugCardPresentGpio;
Naveen Mosesd219fa32022-07-20 00:01:46 +053079 std::unordered_map<size_t, size_t> serialUartMuxMap;
80};