blob: 87226193e8c644984963a56d5813b01800d4b9d5 [file] [log] [blame]
Norman Jamesfa2e76e2015-08-26 17:41:20 -05001#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 James471ab592015-08-30 22:29:40 -05008#include "interfaces/control.h"
Norman James10ff6a32015-08-27 14:24:17 -05009#include "openbmc.h"
10#include "gpio.h"
Norman Jamesfa2e76e2015-08-26 17:41:20 -050011
12
13/* ---------------------------------------------------------------------------------------------------- */
14static const gchar* dbus_object_path = "/org/openbmc/control/Host";
15static const gchar* dbus_name = "org.openbmc.control.Host";
16
17static GDBusObjectManagerServer *manager = NULL;
Norman Jamesfa2e76e2015-08-26 17:41:20 -050018
19GPIO fsi_data = (GPIO){ "FSI_DATA" };
20GPIO fsi_clk = (GPIO){ "FSI_CLK" };
21GPIO fsi_enable = (GPIO){ "FSI_ENABLE" };
22GPIO cronus_sel = (GPIO){ "CRONUS_SEL" };
23
24
25static gboolean
26on_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
83static void
84on_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 James10ff6a32015-08-27 14:24:17 -050090 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 Jamesfa2e76e2015-08-26 17:41:20 -0500107
Norman James10ff6a32015-08-27 14:24:17 -0500108 //define method callbacks here
109 g_signal_connect (control_host,
Norman Jamesfa2e76e2015-08-26 17:41:20 -0500110 "handle-boot",
111 G_CALLBACK (on_boot),
112 NULL); /* user_data */
113
Norman James10ff6a32015-08-27 14:24:17 -0500114 /* 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 Jamesfa2e76e2015-08-26 17:41:20 -0500118 /* 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
128static void
129on_name_acquired (GDBusConnection *connection,
130 const gchar *name,
131 gpointer user_data)
132{
133 g_print ("Acquired the name %s\n", name);
134}
135
136static void
137on_name_lost (GDBusConnection *connection,
138 const gchar *name,
139 gpointer user_data)
140{
141 g_print ("Lost the name %s\n", name);
142}
143
144gint
145main (gint argc, gchar *argv[])
146{
147 GMainLoop *loop;
Norman James952b38d2015-08-27 21:30:06 -0500148 cmdline cmd;
149 cmd.argc = argc;
150 cmd.argv = argv;
Norman Jamesfa2e76e2015-08-26 17:41:20 -0500151
152 guint id;
Norman Jamesfa2e76e2015-08-26 17:41:20 -0500153 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 James952b38d2015-08-27 21:30:06 -0500162 &cmd,
Norman Jamesfa2e76e2015-08-26 17:41:20 -0500163 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}