blob: ed62515d6fdbc3fe60440770558201f7d3adc5a1 [file] [log] [blame]
Shawn McCarney6663abf2020-02-29 17:25:48 -06001/**
2 * Copyright © 2020 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
17#include "pmbus_utils.hpp"
18
19namespace phosphor::power::regulators::pmbus_utils
20{
21
22void parseVoutMode(uint8_t voutModeValue, VoutDataFormat& format,
23 int8_t& parameter)
24{
25 // Get the mode field from bits [6:5] in the VOUT_MODE value
26 uint8_t modeField = (voutModeValue & 0b0110'0000u) >> 5;
27
28 // Get data format from mode field
29 switch (modeField)
30 {
31 case 0b00u:
32 format = VoutDataFormat::linear;
33 break;
34 case 0b01u:
35 format = VoutDataFormat::vid;
36 break;
37 case 0b10u:
38 format = VoutDataFormat::direct;
39 break;
40 case 0b11u:
41 format = VoutDataFormat::ieee;
42 break;
43 }
44
45 // Get the parameter field from bits [4:0] in the VOUT_MODE value
46 uint8_t parameterField = voutModeValue & 0b0001'1111u;
47
48 // Get parameter value from parameter field
49 if (format == VoutDataFormat::linear)
50 {
51 // Extend sign bit if necessary because parameter is an exponent in
52 // two's complement format
53 if (parameterField & 0b0001'0000u)
54 {
55 parameterField |= 0b1110'0000u;
56 }
57 }
58 parameter = static_cast<int8_t>(parameterField);
59}
60
Bob Kingd6820bb2020-04-28 15:37:02 +080061std::string toString(SensorDataFormat format)
62{
63 std::string returnValue{};
64 switch (format)
65 {
66 case SensorDataFormat::linear_11:
67 returnValue = "linear_11";
68 break;
69 case SensorDataFormat::linear_16:
70 returnValue = "linear_16";
71 break;
72 }
73 return returnValue;
74}
75
Bob Kingd6820bb2020-04-28 15:37:02 +080076std::string toString(VoutDataFormat format)
77{
78 std::string returnValue{};
79 switch (format)
80 {
81 case VoutDataFormat::linear:
82 returnValue = "linear";
83 break;
84 case VoutDataFormat::vid:
85 returnValue = "vid";
86 break;
87 case VoutDataFormat::direct:
88 returnValue = "direct";
89 break;
90 case VoutDataFormat::ieee:
91 returnValue = "ieee";
92 break;
93 }
94 return returnValue;
95}
96
Shawn McCarney6663abf2020-02-29 17:25:48 -060097} // namespace phosphor::power::regulators::pmbus_utils