Skip to content
Permalink
Browse files

Add udev backend, remove hal backend

I don't think the gadget scripts work right now, and they will be
replaced with configs and libusbg, but this is useful progress to
commit.

Currently the device is hardcoded to the n900 usb phy driver.
  • Loading branch information...
MerlijnWajer committed Mar 1, 2018
1 parent 5b8b709 commit 381a33471a0d65375cf8a97341bb8efbb95491be
Showing with 146 additions and 148 deletions.
  1. +2 −2 Makefile
  2. +0 −126 hal-helper.c
  3. +0 −12 hal-helper.h
  4. +120 −0 udev-helper.c
  5. +16 −0 udev-helper.h
  6. +8 −8 usb-plugin.c
@@ -9,7 +9,7 @@ install:
clean:
$(RM) usb_plugin.so

usb_plugin.so: usb-plugin.c hal-helper.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(shell pkg-config --cflags --libs hal libhildondesktop-1) -W -Wall -O2 -shared $^ -o $@
usb_plugin.so: usb-plugin.c udev-helper.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(shell pkg-config --cflags --libs gudev-1.0 libhildondesktop-1) -W -Wall -O2 -shared $^ -o $@

.PHONY: all install clean

This file was deleted.

This file was deleted.

@@ -0,0 +1,120 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include <gudev/gudev.h>

#include "udev-helper.h"


/*
* /sys/class/phy/phy-48070000.i2c\:twl\@48\:twl4030-usb.0
* /sys/class/udc/musb-hdrc.0.auto
*
* /sys/class/phy/phy-48070000.i2c\:twl\@48\:twl4030-usb.0/device/vbus
* /sys/devices/platform/68000000.ocp/480ab000.usb_otg_hs/musb-hdrc.0.auto/vbus
* /sys/devices/platform/68000000.ocp/480ab000.usb_otg_hs/musb-hdrc.0.auto/mode
*/

typedef struct {
gboolean connected;

} PrivData;

/* TODO: Better/non-conflicting(?) names? */
static gpointer user_data = NULL;
static UhCallback user_callback;

static GUdevClient* client = NULL;
static PrivData cache = { .connected = 0 };

static void on_uevent(GUdevClient *client, const char *action, GUdevDevice *device) {
(void)client;

const gchar* subsys = g_udev_device_get_subsystem(device);
const gchar* devtype = g_udev_device_get_devtype(device);
const gchar* name = g_udev_device_get_name(device);

fprintf(stderr, "subsys: %s; devtype: %s; name: %s; action: %s\n",
subsys, devtype, name, action);

if (strcmp(name, "48070000.i2c:twl@48:twl4030-usb") == 0) {
cache.connected = (strcmp(action, "online") == 0);

if (user_callback) {
user_callback(cache.connected, user_data);
}
fprintf(stderr, "Match\n");
}
return;
}

int setup_udev(void) {
const gchar *subsystems[] = { NULL};
client = g_udev_client_new(subsystems);
if (!client)
return 1;

g_signal_connect(client, "uevent", G_CALLBACK(on_uevent), NULL);

return 0;
}

int uh_init() {
client = NULL;
user_data = NULL;
user_callback = NULL;

return setup_udev();
}

int uh_destroy() {
if (client) {
/* TODO: Figure out how to free - just unref ? */
}

return 0;
}

void uh_set_callback(UhCallback cb, gpointer data) {
user_data = data;
user_callback = cb;

return;
}

gboolean uh_query_state() {
return cache.connected;
}

/* TODO */
char *uh_get_device_name() {
return NULL;
}

#if 0
static void test_callback(gboolean cable_connected, gpointer data) {
fprintf(stderr, "test_callback: %d - %p.\n", cable_connected, data);
}

static int main_loop(void) {
static GMainLoop *loop = NULL;

setup_udev();
uh_set_callback((UhCallback)test_callback, (void*)42);

loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);

return 0;
}

int
main (int argc, char *argv[])
{
(void)argc;
(void)argv;

return main_loop();
}
#endif
@@ -0,0 +1,16 @@
#ifndef __UDEV_HELPER_H__
#define __UDEV_HELPER_H__
typedef void (*UhCallback)(gboolean, gpointer);


int uh_init();
int uh_destroy();
void uh_set_callback(UhCallback cb, gpointer data);
gboolean uh_query_state();

/* TODO */
char *uh_get_device_name();



#endif /* __UDEV_HELPER_H__ */
@@ -3,7 +3,7 @@
#include <hildon/hildon-button.h>
#include <hildon/hildon-helper.h>

#include "hal-helper.h"
#include "udev-helper.h"

#define USB_TYPE_STATUS_MENU_ITEM (usb_status_menu_item_get_type ())

@@ -126,7 +126,7 @@ static void usb_status_menu_item_finalize(GObject *object)
UsbStatusMenuItemPrivate *priv;

priv = plugin->priv;
hh_destroy();
uh_destroy();
usb_status_menu_show(plugin, FALSE, FALSE);

if (priv) {
@@ -204,7 +204,7 @@ static void usb_status_menu_enable_mode(UsbStatusMenuItem *plugin,
UsbStatusMenuItemPrivate *priv = plugin->priv;

if (priv->tries_count <= 29) {
if (hh_query_state() == 1) {
if (uh_query_state() == 1) {
DBusMessage *message;
DBusConnection *connection;
DBusPendingCall *pending = NULL;
@@ -261,7 +261,7 @@ static gboolean is_cable_detached(UsbStatusMenuItem *plugin)
{
gboolean rv;

rv = !hh_query_state();
rv = !uh_query_state();
if (rv) {
g_warning("usb-plugin::warning Cable detached before reply from ke-recv");
stop_enable_usb_mode_timeout(plugin);
@@ -474,7 +474,7 @@ static void usb_status_menu_create_dialog(UsbStatusMenuItem *plugin)
hildon_gtk_window_set_portrait_flags(GTK_WINDOW(priv->dialog),
HILDON_PORTRAIT_MODE_SUPPORT);

s = hh_get_device_name();
s = uh_get_device_name();
if (s && *s)
title =
g_strdup_printf(g_dgettext("hildon-status-bar-usb",
@@ -717,8 +717,8 @@ static void usb_status_menu_item_init(UsbStatusMenuItem *plugin)
gtk_widget_show_all(GTK_WIDGET(priv->status_menu_button));

priv->dialog = 0;
hh_init();
hh_set_callback((HhCallback)usb_status_menu_item_hal_cb, plugin);
uh_init();
uh_set_callback((UhCallback)usb_status_menu_item_hal_cb, plugin);

s = NULL;
if (g_file_get_contents("/tmp/.current_usb_mode", &s, NULL, NULL))
@@ -737,7 +737,7 @@ static void usb_status_menu_item_init(UsbStatusMenuItem *plugin)
if (!s)
s = g_strdup("<no data>");

cable_connected = hh_query_state();
cable_connected = uh_query_state();

if (!cable_connected) {
g_message("usb-plugin::init [saved_state='%s', usb_conn='%s']", s, "false");

0 comments on commit 381a334

Please sign in to comment.
You can’t perform that action at this time.