Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [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 "device.hpp" |
| 18 | |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 19 | #include "chassis.hpp" |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 20 | #include "exception_utils.hpp" |
| 21 | #include "journal.hpp" |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 22 | #include "system.hpp" |
| 23 | |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 24 | #include <exception> |
| 25 | |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 26 | namespace phosphor::power::regulators |
| 27 | { |
| 28 | |
| 29 | void Device::addToIDMap(IDMap& idMap) |
| 30 | { |
| 31 | // Add this device to the map |
| 32 | idMap.addDevice(*this); |
| 33 | |
| 34 | // Add rails to the map |
| 35 | for (std::unique_ptr<Rail>& rail : rails) |
| 36 | { |
| 37 | idMap.addRail(*rail); |
| 38 | } |
| 39 | } |
| 40 | |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 41 | void Device::close() |
| 42 | { |
| 43 | try |
| 44 | { |
| 45 | // Close I2C interface if it is open |
| 46 | if (i2cInterface->isOpen()) |
| 47 | { |
| 48 | i2cInterface->close(); |
| 49 | } |
| 50 | } |
| 51 | catch (const std::exception& e) |
| 52 | { |
| 53 | // Log error messages in journal |
| 54 | exception_utils::log(e); |
| 55 | journal::logErr("Unable to close device " + id); |
| 56 | |
| 57 | // TODO: Create error log entry |
| 58 | } |
| 59 | } |
| 60 | |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 61 | void Device::configure(System& system, Chassis& chassis) |
| 62 | { |
| 63 | // If configuration changes are defined for this device, apply them |
| 64 | if (configuration) |
| 65 | { |
| 66 | configuration->execute(system, chassis, *this); |
| 67 | } |
| 68 | |
| 69 | // Configure rails |
| 70 | for (std::unique_ptr<Rail>& rail : rails) |
| 71 | { |
| 72 | rail->configure(system, chassis, *this); |
| 73 | } |
| 74 | } |
| 75 | |
Bob King | 8e1cd0b | 2020-07-08 13:30:27 +0800 | [diff] [blame] | 76 | void Device::monitorSensors(System& system, Chassis& chassis) |
| 77 | { |
| 78 | |
| 79 | // Monitor sensors in each rail |
| 80 | for (std::unique_ptr<Rail>& rail : rails) |
| 81 | { |
| 82 | rail->monitorSensors(system, chassis, *this); |
| 83 | } |
| 84 | } |
| 85 | |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 86 | } // namespace phosphor::power::regulators |