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