Brad Bishop | de6ed12 | 2016-08-30 20:14:57 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 2 | |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 3 | import gobject |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 4 | import dbus |
| 5 | import dbus.service |
| 6 | import dbus.mainloop.glib |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 7 | import os |
Brad Bishop | 84e73b5 | 2016-05-12 15:57:52 -0400 | [diff] [blame] | 8 | from obmc.dbuslib.bindings import DbusProperties, DbusObjectManager, get_dbus |
| 9 | import obmc.enums |
Brad Bishop | 0b380f7 | 2016-06-10 00:29:50 -0400 | [diff] [blame] | 10 | import obmc_system_config as System |
Brad Bishop | a7ac805 | 2016-09-21 09:17:05 -0400 | [diff] [blame] | 11 | import obmc.system |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 12 | |
| 13 | DBUS_NAME = 'org.openbmc.managers.System' |
| 14 | OBJ_NAME = '/org/openbmc/managers/System' |
Ratan Gupta | 520f8b0 | 2016-09-06 21:47:05 +0530 | [diff] [blame] | 15 | |
Norman James | cf74f95 | 2015-10-28 12:45:18 -0500 | [diff] [blame] | 16 | |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 17 | class SystemManager(DbusProperties, DbusObjectManager): |
| 18 | def __init__(self, bus, obj_name): |
Brad Bishop | f47f5fa | 2016-09-08 22:29:01 -0400 | [diff] [blame] | 19 | super(SystemManager, self).__init__( |
| 20 | conn=bus, |
| 21 | object_path=obj_name) |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 22 | self.bus = bus |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 23 | |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 24 | print "SystemManager Init Done" |
Brad Bishop | 4de4264 | 2016-06-29 21:55:47 -0400 | [diff] [blame] | 25 | |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 26 | @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 Wang | 605620d | 2016-09-21 12:46:29 -0700 | [diff] [blame] | 32 | # TODO: Better error handling |
| 33 | msg = "ERROR: "+name+" not found in GPIO config table" |
| 34 | print msg |
| 35 | raise Exception(msg) |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 36 | 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 Bishop | a7ac805 | 2016-09-21 09:17:05 -0400 | [diff] [blame] | 44 | gpio_num = obmc.system.convertGpio(gpio['gpio_pin']) |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 45 | else: |
Xo Wang | 605620d | 2016-09-21 12:46:29 -0700 | [diff] [blame] | 46 | msg = "ERROR: SystemManager - GPIO lookup failed for "+name |
| 47 | print msg |
| 48 | raise Exception(msg) |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 49 | |
| 50 | if (gpio_num != -1): |
| 51 | r = [obmc.enums.GPIO_DEV, gpio_num, gpio['direction']] |
| 52 | return r |
| 53 | |
Xo Wang | 3f87de8 | 2016-09-22 11:17:01 -0700 | [diff] [blame] | 54 | @dbus.service.method(DBUS_NAME, in_signature='', |
Adriana Kobylak | 24341f9 | 2018-01-26 15:07:23 -0600 | [diff] [blame] | 55 | out_signature='ssa(sb)a(sb)a(sbb)ssssa(sb)') |
Lei YU | 75a18a2 | 2016-11-22 01:47:47 +0800 | [diff] [blame] | 56 | 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 YU | a42400f | 2017-08-22 17:04:43 +0800 | [diff] [blame] | 62 | pci_reset_outs = power_config.get('pci_reset_outs', []) |
Lei YU | 75a18a2 | 2016-11-22 01:47:47 +0800 | [diff] [blame] | 63 | 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 Kobylak | 24341f9 | 2018-01-26 15:07:23 -0600 | [diff] [blame] | 69 | 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 Wang | 3f87de8 | 2016-09-22 11:17:01 -0700 | [diff] [blame] | 72 | print "Power GPIO config: " + str(r) |
| 73 | return r |
| 74 | |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 75 | |
| 76 | if __name__ == '__main__': |
| 77 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
Brad Bishop | 84e73b5 | 2016-05-12 15:57:52 -0400 | [diff] [blame] | 78 | bus = get_dbus() |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 79 | obj = SystemManager(bus, OBJ_NAME) |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 80 | mainloop = gobject.MainLoop() |
Brad Bishop | f0f3efe | 2016-06-29 23:20:24 -0400 | [diff] [blame] | 81 | obj.unmask_signals() |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 82 | name = dbus.service.BusName(DBUS_NAME, bus) |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 83 | |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 84 | print "Running SystemManager" |
| 85 | mainloop.run() |
Brad Bishop | 5306675 | 2016-09-21 08:48:04 -0400 | [diff] [blame] | 86 | |
| 87 | # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |