Shawn McCarney | 6663abf | 2020-02-29 17:25:48 -0600 | [diff] [blame] | 1 | /** |
| 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 | |
| 19 | namespace phosphor::power::regulators::pmbus_utils |
| 20 | { |
| 21 | |
| 22 | void 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 King | d6820bb | 2020-04-28 15:37:02 +0800 | [diff] [blame] | 61 | std::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 | |
| 76 | std::string toString(SensorValueType type) |
| 77 | { |
| 78 | std::string returnValue{}; |
| 79 | switch (type) |
| 80 | { |
| 81 | case SensorValueType::iout: |
| 82 | returnValue = "iout"; |
| 83 | break; |
| 84 | case SensorValueType::iout_peak: |
| 85 | returnValue = "iout_peak"; |
| 86 | break; |
| 87 | case SensorValueType::iout_valley: |
| 88 | returnValue = "iout_valley"; |
| 89 | break; |
| 90 | case SensorValueType::pout: |
| 91 | returnValue = "pout"; |
| 92 | break; |
| 93 | case SensorValueType::temperature: |
| 94 | returnValue = "temperature"; |
| 95 | break; |
| 96 | case SensorValueType::temperature_peak: |
| 97 | returnValue = "temperature_peak"; |
| 98 | break; |
| 99 | case SensorValueType::vout: |
| 100 | returnValue = "vout"; |
| 101 | break; |
| 102 | case SensorValueType::vout_peak: |
| 103 | returnValue = "vout_peak"; |
| 104 | break; |
| 105 | case SensorValueType::vout_valley: |
| 106 | returnValue = "vout_valley"; |
| 107 | break; |
| 108 | } |
| 109 | return returnValue; |
| 110 | } |
| 111 | |
| 112 | std::string toString(VoutDataFormat format) |
| 113 | { |
| 114 | std::string returnValue{}; |
| 115 | switch (format) |
| 116 | { |
| 117 | case VoutDataFormat::linear: |
| 118 | returnValue = "linear"; |
| 119 | break; |
| 120 | case VoutDataFormat::vid: |
| 121 | returnValue = "vid"; |
| 122 | break; |
| 123 | case VoutDataFormat::direct: |
| 124 | returnValue = "direct"; |
| 125 | break; |
| 126 | case VoutDataFormat::ieee: |
| 127 | returnValue = "ieee"; |
| 128 | break; |
| 129 | } |
| 130 | return returnValue; |
| 131 | } |
| 132 | |
Shawn McCarney | 6663abf | 2020-02-29 17:25:48 -0600 | [diff] [blame] | 133 | } // namespace phosphor::power::regulators::pmbus_utils |