blob: 062ff2745c79d38cad6e3629a6a22fd57021abd6 [file] [log] [blame]
Shawn McCarneydb0b8332020-04-06 14:13:04 -05001/**
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 McCarneyeb7bec42020-04-14 09:38:15 -050019#include "chassis.hpp"
Shawn McCarneyb4d18a42020-06-02 10:27:05 -050020#include "exception_utils.hpp"
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050021#include "system.hpp"
22
Shawn McCarneyb4d18a42020-06-02 10:27:05 -050023#include <exception>
24
Shawn McCarneydb0b8332020-04-06 14:13:04 -050025namespace phosphor::power::regulators
26{
27
28void Device::addToIDMap(IDMap& idMap)
29{
30 // Add this device to the map
31 idMap.addDevice(*this);
32
33 // Add rails to the map
34 for (std::unique_ptr<Rail>& rail : rails)
35 {
36 idMap.addRail(*rail);
37 }
38}
39
Bob Kingd692d6d2020-09-14 13:42:57 +080040void Device::close(Services& services)
Shawn McCarneyb4d18a42020-06-02 10:27:05 -050041{
42 try
43 {
44 // Close I2C interface if it is open
45 if (i2cInterface->isOpen())
46 {
47 i2cInterface->close();
48 }
49 }
50 catch (const std::exception& e)
51 {
52 // Log error messages in journal
Bob Kingd692d6d2020-09-14 13:42:57 +080053 services.getJournal().logError(exception_utils::getMessages(e));
54 services.getJournal().logError("Unable to close device " + id);
Shawn McCarneyb4d18a42020-06-02 10:27:05 -050055
56 // TODO: Create error log entry
57 }
58}
59
Bob King23243f82020-07-29 10:38:57 +080060void Device::configure(Services& services, System& system, Chassis& chassis)
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050061{
62 // If configuration changes are defined for this device, apply them
63 if (configuration)
64 {
Bob King23243f82020-07-29 10:38:57 +080065 configuration->execute(services, system, chassis, *this);
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050066 }
67
68 // Configure rails
69 for (std::unique_ptr<Rail>& rail : rails)
70 {
Bob King23243f82020-07-29 10:38:57 +080071 rail->configure(services, system, chassis, *this);
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050072 }
73}
74
Bob King8a552922020-08-05 17:02:31 +080075void Device::monitorSensors(Services& services, System& system,
76 Chassis& chassis)
Bob King8e1cd0b2020-07-08 13:30:27 +080077{
78
79 // Monitor sensors in each rail
80 for (std::unique_ptr<Rail>& rail : rails)
81 {
Bob King8a552922020-08-05 17:02:31 +080082 rail->monitorSensors(services, system, chassis, *this);
Bob King8e1cd0b2020-07-08 13:30:27 +080083 }
84}
85
Shawn McCarneydb0b8332020-04-06 14:13:04 -050086} // namespace phosphor::power::regulators