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