blob: 818977babbb1d4290258fdf18e60e36df7ebb42e [file] [log] [blame]
Jim Wright1553cd92021-03-31 16:11:59 -05001/**
2 * Copyright © 2021 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jim Wright7945dd22021-04-06 16:55:15 -050017#include "ucd90320_monitor.hpp"
18
Jim Wright56ae78e2021-12-01 14:46:15 -060019#include <fmt/format.h>
20#include <fmt/ranges.h>
21
22#include <phosphor-logging/log.hpp>
Jim Wright56ae78e2021-12-01 14:46:15 -060023
Jim Wright213ffe92022-06-03 08:54:30 -050024#include <span>
Jim Wright7945dd22021-04-06 16:55:15 -050025
26namespace phosphor::power::sequencer
Jim Wright1553cd92021-03-31 16:11:59 -050027{
Jim Wright7945dd22021-04-06 16:55:15 -050028
Jim Wright56ae78e2021-12-01 14:46:15 -060029using namespace phosphor::logging;
Jim Wright71a14132022-01-28 09:46:46 -060030
Patrick Williams7354ce62022-07-22 19:26:56 -050031UCD90320Monitor::UCD90320Monitor(sdbusplus::bus_t& bus, std::uint8_t i2cBus,
Jim Wright7945dd22021-04-06 16:55:15 -050032 std::uint16_t i2cAddress) :
Jim Wrightc48551a2022-12-22 15:43:14 -060033 UCD90xMonitor(bus, i2cBus, i2cAddress, "UCD90320", 32)
34{}
Jim Wright56ae78e2021-12-01 14:46:15 -060035
Jim Wrightc48551a2022-12-22 15:43:14 -060036void UCD90320Monitor::formatGpioValues(
37 const std::vector<int>& values, unsigned int numberLines,
38 std::map<std::string, std::string>& additionalData) const
Jim Wright56ae78e2021-12-01 14:46:15 -060039{
Jim Wrightc48551a2022-12-22 15:43:14 -060040 // Device has 84 GPIO pins so that value is expected
Jim Wrightc91eed02022-07-22 11:27:06 -050041 if (numberLines == 84 && values.size() >= 84)
Jim Wright213ffe92022-06-03 08:54:30 -050042 {
43 log<level::INFO>(fmt::format("MAR01-24 GPIO values: {}",
44 std::span{values}.subspan(0, 24))
45 .c_str());
46 additionalData.emplace(
47 "MAR01_24_GPIO_VALUES",
48 fmt::format("{}", std::span{values}.subspan(0, 24)));
49 log<level::INFO>(fmt::format("EN1-32 GPIO values: {}",
50 std::span{values}.subspan(24, 32))
51 .c_str());
52 additionalData.emplace(
53 "EN1_32_GPIO_VALUES",
54 fmt::format("{}", std::span{values}.subspan(24, 32)));
55 log<level::INFO>(fmt::format("LGP01-16 GPIO values: {}",
56 std::span{values}.subspan(56, 16))
57 .c_str());
58 additionalData.emplace(
59 "LGP01_16_GPIO_VALUES",
60 fmt::format("{}", std::span{values}.subspan(56, 16)));
61 log<level::INFO>(fmt::format("DMON1-8 GPIO values: {}",
62 std::span{values}.subspan(72, 8))
63 .c_str());
64 additionalData.emplace(
65 "DMON1_8_GPIO_VALUES",
66 fmt::format("{}", std::span{values}.subspan(72, 8)));
67 log<level::INFO>(fmt::format("GPIO1-4 GPIO values: {}",
68 std::span{values}.subspan(80, 4))
69 .c_str());
70 additionalData.emplace(
71 "GPIO1_4_GPIO_VALUES",
72 fmt::format("{}", std::span{values}.subspan(80, 4)));
73 }
74 else
75 {
76 log<level::INFO>(fmt::format("GPIO values: {}", values).c_str());
77 additionalData.emplace("GPIO_VALUES", fmt::format("{}", values));
78 }
Jim Wright71a14132022-01-28 09:46:46 -060079}
80
Jim Wright7945dd22021-04-06 16:55:15 -050081} // namespace phosphor::power::sequencer