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