blob: 77d36a357e842dbecd310b4245ac978149ab9faa [file] [log] [blame]
Brad Bishopde6ed122016-08-30 20:14:57 -04001#!/usr/bin/env python
Norman James89de9162015-08-27 21:41:36 -05002
Norman James6f8d0422015-09-14 18:48:00 -05003import gobject
Norman James89de9162015-08-27 21:41:36 -05004import dbus
5import dbus.service
6import dbus.mainloop.glib
Norman James90baede2015-09-02 20:32:49 -05007import os
Brad Bishop84e73b52016-05-12 15:57:52 -04008from obmc.dbuslib.bindings import DbusProperties, DbusObjectManager, get_dbus
9import obmc.enums
Brad Bishop0b380f72016-06-10 00:29:50 -040010import obmc_system_config as System
Brad Bishopa7ac8052016-09-21 09:17:05 -040011import obmc.system
Norman James89de9162015-08-27 21:41:36 -050012
13DBUS_NAME = 'org.openbmc.managers.System'
14OBJ_NAME = '/org/openbmc/managers/System'
Ratan Gupta520f8b02016-09-06 21:47:05 +053015
Norman Jamescf74f952015-10-28 12:45:18 -050016
Brad Bishop416539d2016-07-22 07:22:42 -040017class SystemManager(DbusProperties, DbusObjectManager):
18 def __init__(self, bus, obj_name):
Brad Bishopf47f5fa2016-09-08 22:29:01 -040019 super(SystemManager, self).__init__(
20 conn=bus,
21 object_path=obj_name)
Brad Bishop416539d2016-07-22 07:22:42 -040022 self.bus = bus
Norman James9e6acf92015-09-08 07:00:04 -050023
Brad Bishop416539d2016-07-22 07:22:42 -040024 print "SystemManager Init Done"
Brad Bishop4de42642016-06-29 21:55:47 -040025
Brad Bishop416539d2016-07-22 07:22:42 -040026 @dbus.service.method(DBUS_NAME, in_signature='s', out_signature='sis')
27 def gpioInit(self, name):
28 gpio_path = ''
29 gpio_num = -1
30 r = ['', gpio_num, '']
31 if name not in System.GPIO_CONFIG:
Xo Wang605620d2016-09-21 12:46:29 -070032 # TODO: Better error handling
33 msg = "ERROR: "+name+" not found in GPIO config table"
34 print msg
35 raise Exception(msg)
Brad Bishop416539d2016-07-22 07:22:42 -040036 else:
37
38 gpio_num = -1
39 gpio = System.GPIO_CONFIG[name]
40 if 'gpio_num' in System.GPIO_CONFIG[name]:
41 gpio_num = gpio['gpio_num']
42 else:
43 if 'gpio_pin' in System.GPIO_CONFIG[name]:
Brad Bishopa7ac8052016-09-21 09:17:05 -040044 gpio_num = obmc.system.convertGpio(gpio['gpio_pin'])
Brad Bishop416539d2016-07-22 07:22:42 -040045 else:
Xo Wang605620d2016-09-21 12:46:29 -070046 msg = "ERROR: SystemManager - GPIO lookup failed for "+name
47 print msg
48 raise Exception(msg)
Brad Bishop416539d2016-07-22 07:22:42 -040049
50 if (gpio_num != -1):
51 r = [obmc.enums.GPIO_DEV, gpio_num, gpio['direction']]
52 return r
53
Xo Wang3f87de82016-09-22 11:17:01 -070054 @dbus.service.method(DBUS_NAME, in_signature='',
Adriana Kobylak24341f92018-01-26 15:07:23 -060055 out_signature='ssa(sb)a(sb)a(sbb)ssssa(sb)')
Lei YU75a18a22016-11-22 01:47:47 +080056 def getGpioConfiguration(self):
57 power_config = System.GPIO_CONFIGS.get('power_config', {})
58 power_good_in = power_config.get('power_good_in', '')
59 latch_out = power_config.get('latch_out', '')
60 power_up_outs = power_config.get('power_up_outs', [])
61 reset_outs = power_config.get('reset_outs', [])
Lei YUa42400f2017-08-22 17:04:43 +080062 pci_reset_outs = power_config.get('pci_reset_outs', [])
Lei YU75a18a22016-11-22 01:47:47 +080063 hostctl_config = System.GPIO_CONFIGS.get('hostctl_config', {})
64 fsi_data = hostctl_config.get('fsi_data', '')
65 fsi_clk = hostctl_config.get('fsi_clk', '')
66 fsi_enable = hostctl_config.get('fsi_enable', '')
67 cronus_sel = hostctl_config.get('cronus_sel', '')
68 optionals = hostctl_config.get('optionals', [])
Adriana Kobylak24341f92018-01-26 15:07:23 -060069 r = [power_good_in, latch_out, power_up_outs, reset_outs,
70 pci_reset_outs, fsi_data, fsi_clk, fsi_enable, cronus_sel,
71 optionals]
Xo Wang3f87de82016-09-22 11:17:01 -070072 print "Power GPIO config: " + str(r)
73 return r
74
Norman James89de9162015-08-27 21:41:36 -050075
76if __name__ == '__main__':
77 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Brad Bishop84e73b52016-05-12 15:57:52 -040078 bus = get_dbus()
Brad Bishop416539d2016-07-22 07:22:42 -040079 obj = SystemManager(bus, OBJ_NAME)
Norman James6f8d0422015-09-14 18:48:00 -050080 mainloop = gobject.MainLoop()
Brad Bishopf0f3efe2016-06-29 23:20:24 -040081 obj.unmask_signals()
Brad Bishop416539d2016-07-22 07:22:42 -040082 name = dbus.service.BusName(DBUS_NAME, bus)
Norman James89de9162015-08-27 21:41:36 -050083
Norman James89de9162015-08-27 21:41:36 -050084 print "Running SystemManager"
85 mainloop.run()
Brad Bishop53066752016-09-21 08:48:04 -040086
87# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4