Norman James | fa2e76e | 2015-08-26 17:41:20 -0500 | [diff] [blame] | 1 | #include <stdio.h>
|
| 2 | #include <stdlib.h>
|
| 3 | #include <string.h>
|
| 4 | #include <fcntl.h>
|
| 5 | #include <unistd.h>
|
| 6 | #include <sys/stat.h>
|
| 7 | #include <sys/mman.h>
|
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 8 | #include "interfaces/control.h"
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 9 | #include "openbmc.h"
|
| 10 | #include "gpio.h"
|
Norman James | fa2e76e | 2015-08-26 17:41:20 -0500 | [diff] [blame] | 11 |
|
| 12 |
|
| 13 | /* ---------------------------------------------------------------------------------------------------- */
|
| 14 | static const gchar* dbus_object_path = "/org/openbmc/control/Host";
|
| 15 | static const gchar* dbus_name = "org.openbmc.control.Host";
|
| 16 |
|
| 17 | static GDBusObjectManagerServer *manager = NULL;
|
Norman James | fa2e76e | 2015-08-26 17:41:20 -0500 | [diff] [blame] | 18 |
|
| 19 | GPIO fsi_data = (GPIO){ "FSI_DATA" };
|
| 20 | GPIO fsi_clk = (GPIO){ "FSI_CLK" };
|
| 21 | GPIO fsi_enable = (GPIO){ "FSI_ENABLE" };
|
| 22 | GPIO cronus_sel = (GPIO){ "CRONUS_SEL" };
|
| 23 |
|
| 24 |
|
| 25 | static gboolean
|
| 26 | on_boot (ControlHost *host,
|
| 27 | GDBusMethodInvocation *invocation,
|
| 28 | gpointer user_data)
|
| 29 | {
|
| 30 | // TODO: Implement gpio toggling
|
| 31 | g_print("Boot\n");
|
| 32 |
|
| 33 | control_host_complete_boot(host,invocation);
|
| 34 |
|
| 35 | gpio_open(&fsi_clk);
|
| 36 | gpio_open(&fsi_data);
|
| 37 | gpio_open(&fsi_enable);
|
| 38 | gpio_open(&cronus_sel);
|
| 39 |
|
| 40 | gpio_write(&cronus_sel,1);
|
| 41 | //putcfam pu 281c 30000000 -p0
|
| 42 | char a[] = "000011111111110101111000111001100111111111111111111111111111101111111111";
|
| 43 | //putcfam pu 281c B0000000 -p0
|
| 44 | char b[] = "000011111111110101111000111000100111111111111111111111111111101101111111";
|
| 45 |
|
| 46 | gpio_write(&fsi_enable,1);
|
| 47 | gpio_write(&fsi_clk,1);
|
| 48 | gpio_write(&fsi_data,1);
|
| 49 | gpio_clock_cycle(&fsi_clk,5000);
|
| 50 | gpio_write(&fsi_data,0);
|
| 51 | gpio_clock_cycle(&fsi_clk,256);
|
| 52 | gpio_write(&fsi_data,1);
|
| 53 | gpio_clock_cycle(&fsi_clk,50);
|
| 54 | uint16_t i=0;
|
| 55 | for(i=0;i<strlen(a);i++) {
|
| 56 | gpio_writec(&fsi_data,a[i]);
|
| 57 | gpio_clock_cycle(&fsi_clk,1);
|
| 58 | }
|
| 59 | gpio_write(&fsi_data,1); /* Data standby state */
|
| 60 | gpio_clock_cycle(&fsi_clk,5000);
|
| 61 |
|
| 62 | for(i=0;i<strlen(b);i++) {
|
| 63 | gpio_writec(&fsi_data,b[i]);
|
| 64 | gpio_clock_cycle(&fsi_clk,1);
|
| 65 | }
|
| 66 | gpio_write(&fsi_data,1); /* Data standby state */
|
| 67 | gpio_clock_cycle(&fsi_clk,2);
|
| 68 |
|
| 69 | gpio_write(&fsi_clk,0); /* hold clk low for clock mux */
|
| 70 | gpio_write(&fsi_enable,0);
|
| 71 | gpio_clock_cycle(&fsi_clk,16);
|
| 72 | gpio_write(&fsi_clk,0); /* Data standby state */
|
| 73 |
|
| 74 | gpio_close(&fsi_clk);
|
| 75 | gpio_close(&fsi_data);
|
| 76 | gpio_close(&fsi_enable);
|
| 77 | gpio_close(&cronus_sel);
|
| 78 |
|
| 79 | control_host_emit_booted(host);
|
| 80 | return TRUE;
|
| 81 | }
|
| 82 |
|
| 83 | static void
|
| 84 | on_bus_acquired (GDBusConnection *connection,
|
| 85 | const gchar *name,
|
| 86 | gpointer user_data)
|
| 87 | {
|
| 88 | ObjectSkeleton *object;
|
| 89 | g_print ("Acquired a message bus connection: %s\n",name);
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 90 | cmdline *cmd = user_data;
|
| 91 | if (cmd->argc < 2)
|
| 92 | {
|
| 93 | g_print("No objects created. Put object name(s) on command line\n");
|
| 94 | return;
|
| 95 | }
|
| 96 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
| 97 | int i=0;
|
| 98 | for (i=1;i<cmd->argc;i++)
|
| 99 | {
|
| 100 | gchar *s;
|
| 101 | s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
|
| 102 | object = object_skeleton_new (s);
|
| 103 | g_free (s);
|
| 104 | ControlHost* control_host = control_host_skeleton_new ();
|
| 105 | object_skeleton_set_control_host (object, control_host);
|
| 106 | g_object_unref (control_host);
|
Norman James | fa2e76e | 2015-08-26 17:41:20 -0500 | [diff] [blame] | 107 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 108 | //define method callbacks here
|
| 109 | g_signal_connect (control_host,
|
Norman James | fa2e76e | 2015-08-26 17:41:20 -0500 | [diff] [blame] | 110 | "handle-boot",
|
| 111 | G_CALLBACK (on_boot),
|
| 112 | NULL); /* user_data */
|
| 113 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 114 | /* Export the object (@manager takes its own reference to @object) */
|
| 115 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 116 | g_object_unref (object);
|
| 117 | }
|
Norman James | fa2e76e | 2015-08-26 17:41:20 -0500 | [diff] [blame] | 118 | /* Export all objects */
|
| 119 | g_dbus_object_manager_server_set_connection (manager, connection);
|
| 120 |
|
| 121 | gpio_init(connection,&fsi_data);
|
| 122 | gpio_init(connection,&fsi_clk);
|
| 123 | gpio_init(connection,&fsi_enable);
|
| 124 | gpio_init(connection,&cronus_sel);
|
| 125 |
|
| 126 | }
|
| 127 |
|
| 128 | static void
|
| 129 | on_name_acquired (GDBusConnection *connection,
|
| 130 | const gchar *name,
|
| 131 | gpointer user_data)
|
| 132 | {
|
| 133 | g_print ("Acquired the name %s\n", name);
|
| 134 | }
|
| 135 |
|
| 136 | static void
|
| 137 | on_name_lost (GDBusConnection *connection,
|
| 138 | const gchar *name,
|
| 139 | gpointer user_data)
|
| 140 | {
|
| 141 | g_print ("Lost the name %s\n", name);
|
| 142 | }
|
| 143 |
|
| 144 | gint
|
| 145 | main (gint argc, gchar *argv[])
|
| 146 | {
|
| 147 | GMainLoop *loop;
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 148 | cmdline cmd;
|
| 149 | cmd.argc = argc;
|
| 150 | cmd.argv = argv;
|
Norman James | fa2e76e | 2015-08-26 17:41:20 -0500 | [diff] [blame] | 151 |
|
| 152 | guint id;
|
Norman James | fa2e76e | 2015-08-26 17:41:20 -0500 | [diff] [blame] | 153 | loop = g_main_loop_new (NULL, FALSE);
|
| 154 |
|
| 155 | id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
| 156 | dbus_name,
|
| 157 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 158 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 159 | on_bus_acquired,
|
| 160 | on_name_acquired,
|
| 161 | on_name_lost,
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 162 | &cmd,
|
Norman James | fa2e76e | 2015-08-26 17:41:20 -0500 | [diff] [blame] | 163 | NULL);
|
| 164 |
|
| 165 | g_main_loop_run (loop);
|
| 166 |
|
| 167 | g_bus_unown_name (id);
|
| 168 | g_main_loop_unref (loop);
|
| 169 | return 0;
|
| 170 | }
|