omhacks-0.16/0000755000175000017500000000000011652547334012057 5ustar lindilindiomhacks-0.16/src/0000755000175000017500000000000011540103642012630 5ustar lindilindiomhacks-0.16/src/om-cmdline.c0000644000175000017500000005721311540103642015030 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "om-cmdline.h" #include #include #include #include #include #include const char* argv0; struct opt_t opts; int om_flags_sysfs = 0; int om_flags_backlight = 0; int om_flags_touchscreen = 0; int om_flags_bt = 0; int om_flags_gsm = 0; int om_flags_gps = 0; int om_flags_wifi = 0; int om_flags_resume_reason = 0; int om_flags_led = 0; int om_flags_uevent = 0; static const char* om_usage_lead = NULL; void usage_lead_reset() { om_usage_lead = "Usage: "; } const char* usage_lead() { const char* res = om_usage_lead; om_usage_lead = " or: "; return res; } void usage_sysfs(FILE* out) { fprintf(out, "%s %s sysfs name [name...]\n", usage_lead(), argv0); } int do_sysfs(int argc, char *const *argv) { int i; if (argc == 1) { usage_sysfs(stderr); return 1; } for (i = 1; i < argc; ++i) { const char* res = om_sysfs_path(argv[i]); if (res == NULL) { fprintf(stderr, "%s not found\n", argv[i]); return 1; } puts(res); } return 0; } void usage_backlight(FILE* out) { fprintf(out, "%s %s backlight brightness [0-100]\n", usage_lead(), argv0); fprintf(out, "%s %s backlight\n", usage_lead(), argv0); fprintf(out, "%s %s backlight get-max\n", usage_lead(), argv0); fprintf(out, "%s %s backlight \n", usage_lead(), argv0); } static int fixpoint_new(int x) { return x * 256; } static int fixpoint_return(int x) { return x / 256; } static int fixpoint_mul(int a, int b) { return (a * b) / 256; } static int fixpoint_div(int a, int b) { return (a * 256) / b; } static int fixpoint_round(int x) { return (x + 128) & ~0xff; } int do_backlight(int argc, char *const *argv) { if (argc == 1) { int val = om_screen_brightness_get(); if (val < 0) { perror("getting brightness"); return 1; } printf("%d\n", val); } else { if (strcmp(argv[1], "get-max") == 0) { int val = om_screen_brightness_get_max(); if (val < 0) { perror("getting max brightness value"); return 1; } printf("%d\n", val); } else if (strcmp(argv[1], "brightness") == 0) { int max = om_screen_brightness_get_max(); if (max < 0) { perror("getting max brightness value"); return 1; } if (argc == 2) { int val = om_screen_brightness_get(); if (val < 0) { perror("getting brightness"); return 1; } printf("%d\n", fixpoint_return(fixpoint_round( fixpoint_div(fixpoint_mul(fixpoint_new(val), fixpoint_new(100)), fixpoint_new(max))))); } else if (opts.swap) { int old_val = om_screen_brightness_swap( fixpoint_return(fixpoint_round( fixpoint_div(fixpoint_mul(fixpoint_new(atoi(argv[2])), fixpoint_new(max)), fixpoint_new(100))))); if (old_val < 0) { perror("getting/setting brightness"); return 1; } printf("%d\n", fixpoint_return(fixpoint_round( fixpoint_div(fixpoint_mul(fixpoint_new(old_val), fixpoint_new(100)), fixpoint_new(max))))); } else { int res = om_screen_brightness_set( fixpoint_return(fixpoint_round( fixpoint_div(fixpoint_mul(fixpoint_new(atoi(argv[2])), fixpoint_new(max)), fixpoint_new(100))))); if (res < 0) { perror("setting brightness"); return 1; } } } else if (opts.swap) { int old_val = om_screen_brightness_swap(atoi(argv[1])); if (old_val < 0) { perror("getting/setting brightness"); return 1; } printf("%d\n", old_val); } else { int res = om_screen_brightness_set(atoi(argv[1])); if (res < 0) { perror("setting brightness"); return 1; } } } return 0; } void usage_screen(FILE* out) { fprintf(out, "%s %s screen power [1/0]\n", usage_lead(), argv0); fprintf(out, "%s %s screen resolution [normal|qvga-normal]\n", usage_lead(), argv0); fprintf(out, "%s %s screen glamo-bus-timings [4-4-4|2-4-2]\n", usage_lead(), argv0); } int do_screen(int argc, char *const *argv) { if (argc == 1) { usage_screen(stderr); return 1; } if (strcmp(argv[1], "power")== 0) { if (argc == 2) { int res = om_screen_power_get(); if (res < 0) { perror("reading screen power"); return 1; } printf("%d\n", res); } else { int res = om_screen_power_set(atoi(argv[2])); if (res < 0) { perror("setting screen power"); return 1; } } } else if (strcmp(argv[1], "resolution") == 0) { if (argc == 2) { const char* res = om_screen_resolution_get(); if (res == NULL) { perror("reading screen resolution"); return 1; } puts(res); } else { int res = om_screen_resolution_set(argv[2]); if (res < 0) { perror("setting screen resolution"); return 1; } } } else if (strcmp(argv[1], "glamo-bus-timings") == 0) { if (argc == 2) { const char* res = om_screen_glamo_bus_timings_get(); if (res == NULL) { perror("reading screen glamo bus timings"); return 1; } puts(res); } else { int res = om_screen_glamo_bus_timings_set(argv[2]); if (res < 0) { perror("setting screen glamo bus timings"); return 1; } } } else { usage_screen(stderr); return 1; } return 0; } void usage_touchscreen(FILE* out) { fprintf(out, "%s %s touchscreen lock\n", usage_lead(), argv0); } int do_touchscreen(int argc, char *const *argv) { if (argc == 1 || strcmp(argv[1], "lock") != 0) { usage_touchscreen(stderr); return 1; } int ts = om_touchscreen_open(); if (ts < 0) { perror("opening touchscreen"); return 1; } if (om_touchscreen_lock(ts) < 0) { perror("locking touchscreen"); return 1; } pause(); if (close(ts) < 0) { perror("closing touchscreen"); return 1; } return 0; } void usage_bt(FILE* out) { fprintf(out, "%s %s bt [--swap] power [1/0]\n", usage_lead(), argv0); } int do_bt(int argc, char *const *argv) { if (argc == 1) { usage_bt(stderr); return 1; } if (strcmp(argv[1], "power") == 0) { if (argc == 2) { int res = om_bt_power_get(); if (res < 0) { perror("reading BlueTooth power"); return 1; } printf("%d\n", res); } else { if (opts.swap) { int res = om_bt_power_swap(atoi(argv[2])); if (res < 0) { perror("reading/setting BlueTooth power"); return 1; } printf("%d\n", res); } else { int res = om_bt_power_set(atoi(argv[2])); if (res < 0) { perror("setting BlueTooth power"); return 1; } } } } else { usage_bt(stderr); return 1; } return 0; } void usage_gsm(FILE* out) { fprintf(out, "%s %s gsm [--swap] power [1/0]\n", usage_lead(), argv0); fprintf(out, "%s %s gsm flowcontrol [1/0]\n", usage_lead(), argv0); } int do_gsm(int argc, char *const *argv) { if (argc == 1) { usage_gsm(stderr); return 1; } if (strcmp(argv[1], "power") == 0) { if (argc == 2) { int res = om_gsm_power_get(); if (res < 0) { perror("reading GSM power"); return 1; } printf("%d\n", res); } else { if (opts.swap) { int res = om_gsm_power_swap(atoi(argv[2])); if (res < 0) { perror("reading/setting GSM power"); return 1; } printf("%d\n", res); } else { int res = om_gsm_power_set(atoi(argv[2])); if (res < 0) { perror("setting GSM power"); return 1; } } } } else if (strcmp(argv[1], "flowcontrol") == 0) { if (argc == 2) { int res = om_gsm_flowcontrol_get(); if (res < 0) { perror("reading GSM flowcontrol"); return 1; } printf("%d\n", res); } else { int res = om_gsm_flowcontrol_set(atoi(argv[2])); if (res < 0) { perror("settings GSM flowcontrol"); return 1; } } } else { usage_gsm(stderr); return 1; } return 0; } void usage_gps(FILE* out) { fprintf(out, "%s %s gps [--swap] power [1/0]\n", usage_lead(), argv0); fprintf(out, "%s %s gps [--swap] keep-on-in-suspend [1/0]\n", usage_lead(), argv0); fprintf(out, "%s %s gps send-ubx [payload_byte0] [payload_byte1] ...\n", usage_lead(), argv0); } int do_gps(int argc, char *const *argv) { if (argc == 1) { usage_gps(stderr); return 1; } if (strcmp(argv[1], "power") == 0) { if (argc == 2) { int res = om_gps_power_get(); if (res < 0) { perror("reading GPS power"); return 1; } printf("%d\n", res); } else { if (opts.swap) { int res = om_gps_power_swap(atoi(argv[2])); if (res < 0) { perror("reading/setting GPS power"); return 1; } printf("%d\n", res); } else { int res = om_gps_power_set(atoi(argv[2])); if (res < 0) { perror("setting GPS power"); return 1; } } } } else if (strcmp(argv[1], "keep-on-in-suspend") == 0) { if (argc == 2) { int res = om_gps_keep_on_in_suspend_get(); if (res < 0) { perror("reading GPS keep-on-in-suspend"); return 1; } printf("%d\n", res); } else { if (opts.swap) { int res = om_gps_keep_on_in_suspend_swap(atoi(argv[2])); if (res < 0) { perror("reading/setting GPS keep-on-in-suspend"); return 1; } printf("%d\n", res); } else { int res = om_gps_keep_on_in_suspend_set(atoi(argv[2])); if (res < 0) { perror("setting GPS keep-on-in-suspend"); return 1; } } } } else if (strcmp(argv[1], "send-ubx") == 0) { if (argc < 4) { usage_gps(stderr); return 1; } else { char *payload; int klass, type, payloadlen, fd, res, i; fd = om_gps_open(); if (fd < 0) { perror("opening GPS device"); return 1; } klass = strtol(argv[2], NULL, 16); type = strtol(argv[3], NULL, 16); payloadlen = argc - 4; payload = malloc(payloadlen); if (payload == NULL) { perror("allocating memory for UBX packet"); return 1; } for (i = 0; i < payloadlen; i++) { payload[i] = strtol(argv[4 + i], NULL, 16); } res = om_gps_ubx_send(fd, klass, type, payload, payloadlen); if (res < 0) { perror("sending UBX packet"); } om_gps_close(fd); free(payload); return (res < 0) ? 1 : 0; } } else { usage_gps(stderr); return 1; } return 0; } void usage_wifi(FILE* out) { fprintf(out, "%s %s wifi [--swap] power [1/0]\n", usage_lead(), argv0); fprintf(out, "%s %s wifi maxperf [1/0]\n", usage_lead(), argv0); fprintf(out, "%s %s wifi keep-bus-on-in-suspend [1/0]\n", usage_lead(), argv0); } int do_wifi(int argc, char *const *argv) { if (argc == 1) { usage_wifi(stderr); return 1; } if (strcmp(argv[1], "power") == 0) { if (argc == 2) { int res = om_wifi_power_get(); if (res < 0) { perror("reading WiFi power"); return 1; } printf("%d\n", res); } else { if (opts.swap) { int res = om_wifi_power_swap(atoi(argv[2])); if (res < 0) { perror("reading/setting WiFi power"); return 1; } printf("%d\n", res); } else { int res = om_wifi_power_set(atoi(argv[2])); if (res < 0) { perror("setting WiFi power"); return 1; } } } } else if (strcmp(argv[1], "maxperf") == 0) { if (argc == 3) { int res = om_wifi_maxperf_get(argv[2]); if (res < 0) { perror("reading WiFi maxperf"); return 1; } printf("%d\n", res); } else if (argc == 4) { int res = om_wifi_maxperf_set(argv[2], atoi(argv[3])); if (res < 0) { perror("setting WiFi maxperf"); return 1; } } else { usage_wifi(stderr); return 1; } } else if (strcmp(argv[1], "keep-bus-on-in-suspend") == 0) { if (argc == 2) { int res = om_wifi_keep_bus_on_in_suspend_get(); if (res < 0) { perror("reading WiFi keep-bus-on-in-suspend"); return 1; } printf("%d\n", res); } else if (argc == 3) { int res = om_wifi_keep_bus_on_in_suspend_set(atoi(argv[2])); if (res < 0) { perror("setting WiFi keep-bus-on-in-suspend"); return 1; } } else { usage_wifi(stderr); return 1; } } else { usage_wifi(stderr); return 1; } return 0; } void usage_battery(FILE* out) { fprintf(out, "%s %s battery temperature\n", usage_lead(), argv0); fprintf(out, "%s %s battery energy\n", usage_lead(), argv0); fprintf(out, "%s %s battery consumption\n", usage_lead(), argv0); fprintf(out, "%s %s battery charger-limit [0-500]\n", usage_lead(), argv0); } int do_battery(int argc, char *const *argv) { if (argc == 1) { usage_battery(stderr); return 1; } if (strcmp(argv[1], "temperature") == 0) { if (argc == 2) { float temperature; int res = om_battery_temperature_get(&temperature); if (res < 0) { perror("reading battery temperature"); return 1; } printf("%.2f\n", temperature); } else { usage_battery(stderr); return 1; } } else if (strcmp(argv[1], "energy") == 0) { if (argc == 2) { int res = om_battery_energy_get(); if (res < 0) { perror("reading battery energy"); return 1; } printf("%d\n", res); } else { usage_battery(stderr); return 1; } } else if (strcmp(argv[1], "consumption") == 0) { if (argc == 2) { int consumption; int res = om_battery_consumption_get(&consumption); if (res < 0) { perror("reading battery consumption"); return 1; } printf("%d\n", consumption); } else { usage_battery(stderr); return 1; } } else if (strcmp(argv[1], "charger-limit") == 0) { if (argc == 2) { int res = om_battery_charger_limit_get(); if (res < 0) { perror("reading battery charger limit"); return 1; } printf("%d\n", res); return 0; } else if (argc == 3) { int res = om_battery_charger_limit_set(atoi(argv[2])); if (res < 0) { perror("setting battery charger limit"); return 1; } return 0; } } else { usage_battery(stderr); return 1; } return 0; } void usage_power(FILE* out) { fprintf(out, "%s %s power\n", usage_lead(), argv0); fprintf(out, "%s %s power all-off\n", usage_lead(), argv0); } int do_power(int argc, char *const *argv) { if (argc == 1) { int val; if ((val = om_bt_power_get()) < 0) return val; printf("bt power %d\n", val); if ((val = om_gsm_power_get()) < 0) return val; printf("gsm power %d\n", val); if ((val = om_gps_power_get()) < 0) return val; printf("gps power %d\n", val); if ((val = om_gps_keep_on_in_suspend_get()) < 0) return val; printf("gps keep-on-in-suspend %d\n", val); if ((val = om_wifi_power_get()) < 0) return val; printf("wifi power %d\n", val); } else if (strcmp(argv[1], "all-off") == 0) { if (om_bt_power_set(0) < 0) return 1; if (om_gsm_power_set(0) < 0) return 1; if (om_gps_power_set(0) < 0) return 1; if (om_wifi_power_set(0) < 0) return 1; } else { usage_power(stderr); return 1; } return 0; } void usage_resume_reason(FILE* out) { fprintf(out, "%s %s resume-reason\n", usage_lead(), argv0); fprintf(out, "%s %s resume-reason contains \n", usage_lead(), argv0); } int do_resume_reason(int argc, char *const *argv) { const char** res = om_resume_reason(); if (res == NULL) { perror("getting resume reason"); return 1; } if (argc == 1) { for ( ; *res != NULL; ++res) puts(*res); } else if (strcmp(argv[1], "contains") == 0 && argc == 3) { int found = 0; for ( ; *res != NULL && !found; ++res) if (strcmp(*res, argv[2]) == 0) found = 1; if (!found) return 1; } else { usage_power(stderr); return 1; } return 0; } void usage_led(FILE* out, const char* ledname) { const char* ledcmd; if (om_flags_led & OM_FLAGS_LED_STANDALONE) ledcmd = ""; else ledcmd = " led"; if (ledname == NULL) ledname = ""; fprintf(out, "%s %s %s %s\n", usage_lead(), argv0, ledcmd, ledname); fprintf(out, "%s %s %s %s \n", usage_lead(), argv0, ledcmd, ledname); fprintf(out, "%s %s %s %s timer \n", usage_lead(), argv0, ledcmd, ledname); } static int led_read_extra_args(struct om_led* led, int argc, char *const *argv) { if (argc == 0) { strcpy(led->trigger, "none"); led->delay_on = led->delay_off = 0; } else if (strcmp(argv[0], "timer") == 0 && argc == 3) { strcpy(led->trigger, "timer"); led->delay_on = atoi(argv[1]); led->delay_off = atoi(argv[2]); } else if (strcmp(argv[0], "timer") != 0) { strncpy(led->trigger, argv[0], 254); led->trigger[254] = 0; led->delay_on = led->delay_off = 0; } else { usage_led(stderr, led->name); return 1; } return 0; } static void print_led(const struct om_led* led) { if (strcmp(led->trigger, "none") == 0) { printf("%d\n", led->brightness); } else if (strcmp(led->trigger, "timer") == 0) { printf("%d timer %d %d\n", led->brightness, led->delay_on, led->delay_off); } else { printf("%d %s\n", led->brightness, led->trigger); } } int do_led(int argc, char *const *argv) { struct om_led led; if (argc == 1) { // TODO: list all leds and their status instead DIR* dir = opendir("/sys/class/leds/"); struct dirent* d; if (dir == NULL) { perror("opening /sys/class/leds"); return 1; } while ((d = readdir(dir)) != NULL) { if (d->d_name[0] == '.') continue; printf("%s ", d->d_name); if (om_led_init(&led, d->d_name) != 0) { perror("accessing led"); return 1; } if (om_led_get(&led) != 0) { perror("getting led status"); return 1; } print_led(&led); } closedir(dir); return 0; } if (om_led_init(&led, argv[1]) != 0) { perror("validating led name"); return 1; } if (argc == 2) { // Get status if (om_led_get(&led) != 0) { perror("getting led status"); return 1; } print_led(&led); } else { if (opts.swap) { if (om_led_get(&led) != 0) { perror("getting led status"); return 1; } print_led(&led); } led.brightness = atoi(argv[2]); if (led_read_extra_args(&led, argc-3, argv+3) != 0) return 1; if (om_led_set(&led) != 0) { perror("setting led status"); return 1; } } return 0; } void usage_uevent(FILE* out) { fprintf(out, "%s %s uevent dump\n", usage_lead(), argv0); } int do_uevent(int argc, char *const *argv) { if (argc == 1) { usage_uevent(stderr); return 1; } else if (strcmp(argv[1], "dump") == 0 && argc == 2) { int sock = om_uevent_open(); struct om_uevent ou; if (sock < 0) { perror("opening uevent socket"); return 1; } while (1) { if (om_uevent_read(sock, &ou) < 0) { perror("reading from uevent socket"); return 1; } if (om_uevent_parse(&ou) == 0) { int i; printf("OU_ACTION=%s\n", ou.action); printf("OU_DEVPATH=%s\n", ou.devpath); for (i = 0; ou.envp[i] != NULL; i++) printf("%s\n", ou.envp[i]); putchar('\n'); } else { fprintf(stderr, "Skipping unparsed event %s\n", ou.buffer); } } } else { usage_uevent(stderr); return 1; } return 0; } void usage_usb(FILE* out) { fprintf(out, "%s %s usb mode [device|host]\n", usage_lead(), argv0); fprintf(out, "%s %s usb charger-mode [charge-battery|power-usb]\n", usage_lead(), argv0); fprintf(out, "%s %s usb charger-limit [0|100|500]\n", usage_lead(), argv0); } int do_usb(int argc, char *const *argv) { if (argc == 1) { usage_usb(stderr); } else if (strcmp(argv[1], "mode") == 0) { if (argc == 2) { int res = om_usb_mode_get(); if (res < 0 || res > 1) { perror("reading usb mode"); return 1; } printf("%s\n", res == 0 ? "device" : "host"); } else if (argc == 3) { int res; if (strcmp(argv[2], "device") == 0) { res = om_usb_mode_set(0); } else if (strcmp(argv[2], "host") == 0) { res = om_usb_mode_set(1); } else { usage_usb(stderr); return 1; } if (res < 0) { perror("setting usb mode"); return 1; } return 0; } else { usage_usb(stderr); return 1; } } else if (strcmp(argv[1], "charger-mode") == 0) { if (argc == 2) { int res = om_usb_charger_mode_get(); if (res < 0) { perror("reading usb charger mode"); return 1; } printf("%s\n", res == 0 ? "charge-battery" : "power-usb"); } else if (argc == 3) { int res; if (strcmp(argv[2], "charge-battery") == 0) { res = om_usb_charger_mode_set(0); } else if (strcmp(argv[2], "power-usb") == 0) { res = om_usb_charger_mode_set(1); } else { usage_usb(stderr); return 1; } if (res < 0) { perror("setting usb charger mode"); return 1; } return 0; } } else if (strcmp(argv[1], "charger-limit") == 0) { if (argc == 2) { int res = om_usb_charger_limit_get(); if (res < 0) { perror("reading usb charger limit"); return 1; } printf("%d\n", res); return 0; } else if (argc == 3) { int res = om_usb_charger_limit_set(atoi(argv[2])); if (res < 0) { perror("setting usb charger limit"); return 1; } return 0; } } else { usage_usb(stderr); return 1; } return 0; } int do_version(int argc, char *const *argv) { printf("%s version %s\n", argv0, VERSION); return 0; } void usage_options(FILE* out) { fprintf(out, "Options:\n"); fprintf(out, " --help\tprint this help message\n"); fprintf(out, " --version\tprint version and exit\n"); fprintf(out, " --swap\tset new value and print old value\n"); } int parse_options(int argc, char *const *argv) { argv0 = argv[0]; memset(&opts, 0, sizeof(struct opt_t)); int option_index = 0; static struct option long_options[] = { {"help", 0, &opts.help, 1}, {"version", 0, &opts.version, 1}, /* {"brightness", 1, 0, 0}, {"on", 0, 0, 0}, {"off", 0, 0, 0}, {"on-time", 1, 0, 0}, {"off-time", 1, 0, 0}, {"blink", 0, 0, 0}, {"no-blink", 0, 0, 0}, {"verbose", 0, 0, 0}, */ {"swap", 0, &opts.swap, 1}, {0, 0, 0, 0} }; while (1) { int ret = getopt_long(argc, argv, "", long_options, &option_index); switch (ret) { case -1: return 0; case 0: break; default: return -1; } } } omhacks-0.16/src/om.help2man0000644000175000017500000002127411462027257014713 0ustar lindilindi[OPTIONS] .TP \fBom backlight brightness [0-100]\fR Reads or sets backlight brightness. Units are percentage of maximum brightness. Reports true brightness only if the screen has not been blanked with \fBom screen power 0\fR. .TP \fBom backlight \fR Set backlight brightness. Units are driver specific, maximum value can be queried with \fBom backlight get\-max\fR. This interface is not recommended but is kept for compatibility reasons. .TP \fBom backlight get\-max\fR Get maximum value of brightness. Typically the maximum value is 255 under Linux 2.6.29 and 63 under Linux 2.6.34. .TP \fBom backlight\fR Read backlight brightness. This is an integer between zero and what \fBom backlight get\-max\fR returns. Reports true brightness only if the screen has not been blanked with \fBom screen power 0\fR. This interface is not recommended but is kept for compatibility reasons. .TP \fBom touchscreen lock\fR Locks touchscreen and waits for any signal to unlock it. This is useful when you want to keep the phone running in a pocket and don't want the backlight to turn on every time you accidentally touch the screen. Locking is done in a way that does not depend on X so if X server crashes and restarts your screen will still stay locked. .TP \fBom screen power [1/0]\fR Reads or sets the power state of the screen. Note that Xorg and fso-frameworkd do not know how to read the power status of the screen (frameworkd reads it on startup only). If Xorg turns the screen and after that you turn the screen off with omhacks then touching the screen won't turn the screen on (Xorg thinks the screen is still on and does not bother to try to power it on). .TP \fBom screen resolution [normal|qvga-normal]\fR Reads or sets the screen resolution. This lowlevel interface should not be used when Xorg is running but is useful when using applications that can draw directly to the framebuffer (like mplayer -vo fbdev). The argument \fBnormal\fR means 480x640 and \fBqvga-normal\fR means 240x320. After you have changed the screen resolution you also need to change the framebuffer resolution with e.g. the fbset tool using for example the following /etc/fb.modes entries: .TS l. mode "480x640" geometry 480 640 480 1280 16 timings 40816 8 16 2 16 8 2 rgba 5/11,6/5,5/0,0/0 endmode mode "240x320" geometry 240 420 240 320 16 timings 100000 8 88 2 2 8 2 accel false endmode .TE .TP \fBom screen glamo-bus-timings [4-4-4|2-4-2]\fR Reads or sets the timings of the memory bus between the CPU and the glamo graphics chip. Numbers are SRAM interface timings of the CPU. According to http://lists.openmoko.org/pipermail/community/2010-July/062495.html using 2-4-2 is more appropriate, view that article and following discussion for more details. .TP \fBom bt [\-\-swap] power [1/0]\fR Reads or sets the power state of bluetooth. Bluetooth is connected to USB bus so it might take a while for it to appear in lsusb and be usable after power on. .TP \fBom power\fR List the power status of various devices. .TP \fBom power all-off\fR Disable power to bluetooth, GSM, GPS and WLAN. .TP \fBom gsm [\-\-swap] power [1/0]\fR Reads or sets the power state of GSM. .TP \fBom gsm flowcontrol [1/0]\fR Reads or sets the state of GSM flowcontrol. When flowcontrol is enabled GSM chip will generate an interrupt when it has data and will not try to send it over serial port until flowcontrol is disabled. Enabling flowcontrol before suspend and disabling it after resume is required to make sure no data is lost during suspend. .TP \fBom gps [\-\-swap] power [1/0]\fR Reads or sets the power state of GPS. .TP \fBom gps [\-\-swap] keep\-on\-in\-suspend [1/0]\fR Reads or sets the flag that causes GPS to stay powered on during suspend. This is useful if you want to keep GPS fix during suspend. .TP \fBom gps send\-ubx [payload_byte0] [payload_byte1] ...\fR Send arbitrary UBX protocol command to the GPS chip. Please read "ANTARIS_Protocol_Specification(GPS.G3-X-03002).chm" to understand the protocol. Here are examples of commands that are tested to work: .TS l l l l. class type payload description 06 01 f0 01 00 disable GPGLL messages 06 01 f0 02 00 disable GPGSA messages 06 01 f0 03 00 disable GPGSV messages 06 01 f0 05 00 disable GPGTG messages 06 01 f0 08 00 disable GPZDA messages 06 08 fa 00 01 00 00 00 report position 4 times/s 06 08 f4 01 01 00 00 00 report position 2 times/s .TE .TP \fBom wifi [\-\-swap] power [1/0]\fR Reads or sets the power state of WLAN. .TP \fBom wifi maxperf [1/0]\fR Reads or sets the maxperf mode of WLAN. Enabling this increases energy consumption but lowers latency. Note that root privileges are not currently required for tuning this wifi parameter so a local user can cause DoS by constantly disabling maximum performance mode. .TP \fBom wifi keep-bus-on-in-suspend [1/0]\fR Reads or sets the the flag that controls whether the MCI bus between wifi and CPU will be kept powered on during suspend. You need to keep it powered on if you want to use wake-on-wireless. .TP \fBom battery temperature\fR Reads battery temperature. Units are degrees Centigrade. .TP \fBom battery energy\fR Reads the current energy percentage of the battery. .TP \fBom battery consumption\fR Reads the current energy consumption as measure by the battery. Units are microamperes. Negative value indicates that battery is being charged. .TP \fBom battery charger\-limit [0\-500]\fR Reads or sets the upper limit for battery charger current. Units are milliamperes. Normally USB charger limit and battery charger limit have the same value. However, sometimes it is useful to charger battery very slowly or not at all and still power rest of the system from USB. This allows one for example to keep battery at its recommended storage capacity of 40% without having to physically remove the battery. Note that kernel will round the limit to nearest suitable value which is usually a few milliamperes lower than the supplied limit. Changing USB charger limit will reset also this limit to the same value so you must first set the USB charger limit and only then the battery charger limit. .TP \fBom resume\-reason\fR Read the reason for the most recent resume. If there are multiple resume reasons they are separated by newlines. Possible values include (but are not limited to) .TS l. EINT01_GSM EINT05_WLAN EINT09_PMU:button EINT09_PMU:usb_connect EINT09_PMU:usb_disconnect EINT09_PMU:rtc_alarm EINT09_PMU:low_battery .TE .TP \fBom resume\-reason contains \fR Checks if resume reasons include the given string. .TP \fBom led\fR Lists the state of all LED devices. The printed names are native kernel names and can change between kernel versions. .TP \fBom led \fR Lists the state of the given LED device. In addition to native kernel names you can also use the aliases vibrator, power_orange, power_blue and aux_red to get portability across different kernel versions. .TP \fBom led \fR Sets the brightness of the given LED device to the given brightness. Brightness is an integer from 0 to 255 but only the vibrator device really cares about the brightness value. See \fBom led\fR for a list of supported aliases. .TP \fBom led timer \fR In addition to above also makes the LED blink. Ontime and offtime are in milliseconds. See \fBom led\fR for a list of supported aliases. .TP \fBom uevent dump\fR Dump uevent events to stdout. .TP \fBom usb mode [device|host]\fR Read or set the USB mode. In device mode the phone can talk to USB hosts (PCs or phones in host mode). In host mode the phone can talk to USB devices. See also the \fBom usb charger\-mode\fR option. .TP \fBom usb charger\-mode [charge\-battery|power\-usb]\fR Reads or sets the USB charger mode. Normally you want to charge the battery in device mode and power the USB bus in host mode but it is possible to for example use an external battery power the USB bus so that the phone can be in host mode and still charge itself over USB. .TP \fBom usb charger\-limit [0|100|500]\fR Reads or sets the charger limit of USB. Units are in milliamperes and control the current that the phone will draw from the USB bus. When the phone is in device mode and some gadget driver is loaded it will negotiate the highest allowed charging current automatically. However, if you are using a dumb external USB battery it might be necessary to force larger limit than the default of 100 mA. Do not set the limit to be too large if your charger can not handle it! .TP \fBom sysfs name [name...]\fR Shows the sysfs path associated with internal \fBom\fR path. This option is only useful for debugging \fBom\fR itself. Examples of valid arguments include actual_brightness, battery, brightness, chg_curlim, max_brightness, pm-bt, pm-gps, pm-gsm, pm-wlan, resume_reason, resume_reason2, screen_resolution, usb_charger_mode, usb_mode. omhacks-0.16/src/om.c0000644000175000017500000000662511346516615013434 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "om-cmdline.h" static void usage_help(FILE* out) { fprintf(out, "%s %s help\n", usage_lead(), argv0); fprintf(out, "%s %s --help\n", usage_lead(), argv0); fprintf(out, "%s %s --version\n", usage_lead(), argv0); } static void usage(FILE* out) { printf("om provides a command line interface to various OpenMoko specific pieces of hardware.\n" "Note that om talks directly to the kernel and might not properly co-exist with\n" "fso-frameworkd that also wants to control the same pieces of hardware. However, using om\n" "to read the state of the hardware should be safe even when using fso-frameworkd.\n\n"); usage_lead_reset(); usage_help(out); usage_sysfs(out); usage_backlight(out); usage_touchscreen(out); usage_screen(out); usage_bt(out); usage_gsm(out); usage_gps(out); usage_wifi(out); usage_battery(out); usage_power(out); usage_resume_reason(out); usage_led(out, NULL); usage_uevent(out); usage_usb(out); putchar('\n'); usage_options(out); } static int do_help(int argc, char *const *argv) { usage(stdout); return 0; } int main(int argc, char *const *argv) { if (parse_options(argc, argv) != 0) { usage(stderr); return 1; } argc -= optind; argv += optind; if (opts.help) return do_help(argc, argv); if (opts.version) return do_version(argc, argv); if (argc == 0) { usage(stderr); return 1; } if (strcmp(argv[0], "help") == 0) return do_help(argc, argv); else if (strcmp(argv[0], "sysfs") == 0) return do_sysfs(argc, argv); else if (strcmp(argv[0], "backlight") == 0) return do_backlight(argc, argv); else if (strcmp(argv[0], "screen") == 0) return do_screen(argc, argv); else if (strcmp(argv[0], "touchscreen") == 0) return do_touchscreen(argc, argv); else if (strcmp(argv[0], "bt") == 0) return do_bt(argc, argv); else if (strcmp(argv[0], "gsm") == 0) return do_gsm(argc, argv); else if (strcmp(argv[0], "gps") == 0) return do_gps(argc, argv); else if (strcmp(argv[0], "wifi") == 0) return do_wifi(argc, argv); else if (strcmp(argv[0], "battery") == 0) return do_battery(argc, argv); else if (strcmp(argv[0], "power") == 0) return do_power(argc, argv); else if (strcmp(argv[0], "resume-reason") == 0) return do_resume_reason(argc, argv); else if (strcmp(argv[0], "led") == 0) return do_led(argc, argv); else if (strcmp(argv[0], "uevent") == 0) return do_uevent(argc, argv); else if (strcmp(argv[0], "usb") == 0) return do_usb(argc, argv); else { fprintf(stderr, "Unknown argument: %s\n", argv[0]); return 1; } return 0; } omhacks-0.16/src/CMakeLists.txt0000644000175000017500000000175411341210163015373 0ustar lindilindiinclude_directories(..) link_libraries(omhacks) add_definitions(-Wall -Werror -DVERSION="${omhacks_version}") add_executable(om om.c om-cmdline.c) add_executable(om-led om-led.c om-cmdline.c) set( bindir ${CMAKE_CURRENT_BINARY_DIR} ) set( srcdir ${CMAKE_CURRENT_SOURCE_DIR} ) find_program(HELP2MAN help2man) if (HELP2MAN) message("-- help2man found at ${HELP2MAN}: building man page") add_custom_command( TARGET om POST_BUILD DEPENDS om COMMAND ${HELP2MAN} -n "control OpenMoko phone hardware" --no-info -I${srcdir}/om.help2man ${bindir}/om > ${bindir}/om.1 ) add_custom_command( TARGET om-led POST_BUILD DEPENDS om-led COMMAND ${HELP2MAN} -n "control OpenMoko phone LEDs" --no-info -I${srcdir}/om-led.help2man ${bindir}/om-led > ${bindir}/om-led.1 ) install(FILES ${bindir}/om.1 ${bindir}/om-led.1 DESTINATION share/man/man1 ) else () message("-- help2man not found: not building man page") endif () install(TARGETS om om-led RUNTIME DESTINATION bin) omhacks-0.16/src/om-cmdline.h0000644000175000017500000000542211321673445015042 0ustar lindilindi#ifndef OM_CMDLINE_H #define OM_CMDLINE_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include struct opt_t { int help; int version; /* int verbose; int brightness; int ontime; int offtime; const char *led; int on; int off; int blink; int no_blink; */ int swap; }; extern const char* argv0; extern struct opt_t opts; extern int om_flags_sysfs; void usage_sysfs(FILE* out); int do_sysfs(int argc, char *const *argv); extern int om_flags_backlight; void usage_backlight(FILE* out); int do_backlight(int argc, char *const *argv); void usage_screen(FILE* out); int do_screen(int argc, char *const *argv); extern int om_flags_touchscreen; void usage_touchscreen(FILE* out); int do_touchscreen(int argc, char *const *argv); extern int om_flags_bt; void usage_bt(FILE* out); int do_bt(int argc, char *const *argv); extern int om_flags_gsm; void usage_gsm(FILE* out); int do_gsm(int argc, char *const *argv); extern int om_flags_gps; void usage_gps(FILE* out); int do_gps(int argc, char *const *argv); extern int om_flags_wifi; void usage_wifi(FILE* out); int do_wifi(int argc, char *const *argv); void usage_battery(FILE* out); int do_battery(int argc, char *const *argv); void usage_power(FILE* out); int do_power(int argc, char *const *argv); extern int om_flags_resume_reason; void usage_resume_reason(FILE* out); int do_resume_reason(int argc, char *const *argv); #define OM_FLAGS_LED_STANDALONE 1 extern int om_flags_led; void usage_led(FILE* out, const char* ledname); int do_led(int argc, char *const *argv); extern int om_flags_uevent; void usage_uevent(FILE* out); int do_uevent(int argc, char *const *argv); void usage_usb(FILE* out); int do_usb(int argc, char *const *argv); int do_version(int argc, char *const *argv); void usage_options(FILE* out); /* Reset the initial "Usage: " string to "Usage: " */ void usage_lead_reset(); /* Return "Usage: " just after a usage lead reset, or " or: " */ const char* usage_lead(); int parse_options(int argc, char *const *argv); #endif omhacks-0.16/src/om-led.c0000644000175000017500000000354111341210163014150 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include "om-cmdline.h" static void usage_help(FILE* out) { fprintf(out, "%s %s help\n", usage_lead(), argv0); } static void usage(FILE* out) { usage_lead_reset(); usage_help(out); usage_led(out, NULL); putchar('\n'); printf("om-led provides the same functionality as \"om led\" but as a separate executable\n" "so that it can be made suid-root. No proper security audit has been done so\n" "you should only do this at your own risk.\n\n"); usage_options(out); } static int do_help(int argc, char *const *argv) { usage(stdout); return 0; } int main(int argc, char *const *argv) { om_flags_led = OM_FLAGS_LED_STANDALONE; if (parse_options(argc, argv) != 0) { usage(stderr); return 1; } argc -= optind-1; argv += optind-1; if (opts.help) return do_help(argc, argv); if (opts.version) return do_version(argc, argv); if (argc == 0) { usage(stderr); return 1; } return do_led(argc, argv); return 0; } omhacks-0.16/INSTALL0000644000175000017500000000012411462027257013101 0ustar lindilindiMinimal installation instructions: mkdir build cd build cmake .. make make install omhacks-0.16/hooks/0000755000175000017500000000000011462027271013172 5ustar lindilindiomhacks-0.16/hooks/omhacks.c0000644000175000017500000000725011462027271014767 0ustar lindilindi#include #include #include #include #include #include #include typedef int hook_function(int argc, const char* argv[]); extern void hooks_add_function(const char* name, hook_function func); static struct om_led status_led; static struct om_led status_led_saved; static int screen_brightness_saved = 255; static int touchscreen_fd = -1; static int hook_00_status_led(int argc, const char* argv[]) { if (argc < 2) return 254; if (strcmp(argv[1], "suspend") == 0) { // Save blue led state and turn it on if (om_led_get(&status_led_saved) < 0) { perror("reading blue led status"); status_led.brightness = -1; } else { status_led.brightness = 255; om_led_set(&status_led); } return 0; } else if (strcmp(argv[1], "resume") == 0) { // Restore blue led state if (status_led.brightness != -1) om_led_set(&status_led_saved); return 0; } return 254; } static int hook_99_status_led(int argc, const char* argv[]) { if (argc < 2) return 254; if (strcmp(argv[1], "suspend") == 0) { // Turn off blue state before suspend if (status_led.brightness != -1) { status_led.brightness = 0; om_led_set(&status_led); } return 0; } else if (strcmp(argv[1], "resume") == 0) { // Turn on blue led after resume if (status_led.brightness != -1) { status_led.brightness = 255; om_led_set(&status_led); } return 0; } return 254; } static int hook_screen(int argc, const char* argv[]) { if (argc < 2) return 254; if (strcmp(argv[1], "suspend") == 0) { // Lock touchscreen touchscreen_fd = om_touchscreen_open(); if (touchscreen_fd < 0) perror("opening touchscreen"); else if (om_touchscreen_lock(touchscreen_fd) < 0) perror("locking touchscreen"); // Save current backlight brightness and turn it off screen_brightness_saved = om_screen_brightness_swap(0); if (screen_brightness_saved < 0) screen_brightness_saved = om_screen_brightness_get_max(); return 0; } else if (strcmp(argv[1], "resume") == 0) { // Restore saved backlight brightness om_screen_brightness_set(screen_brightness_saved); // Unlock touchscreen if (touchscreen_fd >= 0) { if (close(touchscreen_fd) < 0) perror("closing touchscreen"); touchscreen_fd = -1; } return 0; } return 254; } static int hook_cancel_on_usb_disconnect(int argc, const char* argv[]) { if (argc < 2) return 254; if (strcmp(argv[1], "resume") == 0) { const char** resume_reason = om_resume_reason(); if (resume_reason == NULL) { perror("getting resume reason"); return 254; } for ( ; *resume_reason != NULL; ++resume_reason) if (strcmp(*resume_reason, "EINT09_PMU:usb_disconnect") == 0) return 250; return 0; } return 254; } void init() { if (om_led_init(&status_led, "gta02-power:blue") == 0 && om_led_init_copy(&status_led_saved, &status_led) == 0) { hooks_add_function("00-statusled", hook_00_status_led); hooks_add_function("99-statusled", hook_99_status_led); } hooks_add_function("74-screen", hook_screen); hooks_add_function("98-cancel-on-usb-disconnect", hook_cancel_on_usb_disconnect); } omhacks-0.16/hooks/00at0000755000175000017500000000302111415150154013653 0ustar lindilindi#!/usr/bin/python # This is an example pm-suspend hook that uses omhacks to # schedule the system to wake from suspend to run atd jobs. # To activate this example symlink it to /etc/pm/sleep.d import sys import time import subprocess import os STORAGEDIR="%s/%s/storage" % (os.environ["PM_UTILS_RUNDIR"], os.environ["STASHNAME"]) def first_in_at_queue(): first = None atq = subprocess.Popen(["atq"], stdout=subprocess.PIPE).communicate()[0] for line in atq.split("\n"): if not line: continue qid, rest = line.split("\t") date, queue, user = rest.rsplit(' ', 2) t = time.mktime(time.strptime(date, "%a %b %d %H:%M:%S %Y")) if first is None: first = t elif t < first: first = t return first def suspend(): first = first_in_at_queue() if first is None: return now = time.time() # Wake up 2 seconds after, so that atd -s runs pending jobs right away delay = first - now - +2 if delay < 15: delay = 15 subprocess.check_call(["rtcwake", "-m", "no", "-s", str(int(delay))]) print "Wakeup scheduled in %d seconds" % delay def resume(): # Touch last-resume flagfile open(STORAGEDIR+"/last-resume", "w").close() if subprocess.call(["om", "resume-reason", "contains", "EINT09_PMU:rtc_alarm"]) == 0: print "Running atd -s" subprocess.check_call(["atd", "-s"]) if sys.argv[1] in ["hibernate", "suspend"]: suspend() elif sys.argv[1] in ["thaw", "resume"]: resume() else: sys.exit(254) sys.exit(0) omhacks-0.16/hooks/at.c0000644000175000017500000000340511313401312013727 0ustar lindilindi#include typedef int hook_function(int argc, const char* argv[]); extern void hooks_add_function(const char* name, hook_function func); static time_t first_in_at_queue() { time_t first = 0; #if 0 // TODO atq = subprocess.Popen(["atq"], stdout=subprocess.PIPE).communicate()[0] for line in atq.split("\n"): if not line: continue qid, rest = line.split("\t") date, queue, user = rest.rsplit(' ', 2) t = time.mktime(time.strptime(date, "%a %b %d %H:%M:%S %Y")) if first is None: first = t elif t < first: first = t #endif return first } static int hook_at(int argc, const char* argv[]) { if (argc < 2) return 254; if (strcmp(argv[1], "suspend") == 0) { time_t first = first_in_at_queue(); if (first != 0) { time_t now = time(NULL); // Wake up 2 seconds after, so that atd -s runs pending jobs right away int delay = first - now - 2; if (delay < 15) delay = 15; #if 0 // TODO subprocess.check_call(["rtcwake", "-m", "no", "-s", str(int(delay))]) print "Wakeup scheduled in %d seconds" % delay #endif } return 0; } else if (strcmp(argv[1], "resume") == 0) { #if 0 STORAGEDIR="%s/%s/storage" % (os.environ["PM_UTILS_RUNDIR"], os.environ["STASHNAME"]) // TODO # Touch last-resume flagfile open(STORAGEDIR+"/last-resume", "w").close() if subprocess.call(["om", "resume-reason", "contains", "EINT09_PMU:rtc_alarm"]) == 0: print "Running atd -s" subprocess.check-call(["atd", "-s"]) #endif return 0; } return 254; } void init() { hooks_add_function("00at", hook_at); } omhacks-0.16/hooks/CMakeLists.txt0000644000175000017500000000107111415150154015724 0ustar lindilindiinclude_directories(..) add_definitions(-Wall -Werror) add_library(hook_omhacks SHARED omhacks.c) set_target_properties(hook_omhacks PROPERTIES PREFIX "" OUTPUT_NAME "omhacks" CLEAN_DIRECT_OUTPUT 1) target_link_libraries(hook_omhacks omhacks) #add_library(hook_at SHARED at.c) #set_target_properties(hook_at PROPERTIES OUTPUT_NAME "at" CLEAN_DIRECT_OUTPUT 1) install(TARGETS hook_omhacks LIBRARY DESTINATION lib/pm-utils/sleep.d/) #install(TARGETS hook_at LIBRARY DESTINATION lib/pm-utils/sleep.d/) install(PROGRAMS 00at DESTINATION share/doc/omhacks/examples/) omhacks-0.16/hooks/97-lindi0000755000175000017500000000710311302302200014432 0ustar lindilindi#!/bin/sh PATH="$PATH:/root/omhacks/src" STORAGEDIR="$PM_UTILS_RUNDIR/$STASHNAME/storage" suspend() { # TODO if ip link | grep ppp0: | grep UP; then # TODO # Shutdown GPRS connection gracefully, otherwise it will wake us # TODO # up very soon. # TODO gprs-stop # TODO : # TODO fi # TODO # TODO wlan=0 # TODO if ip link | grep eth0: | grep UP; then # TODO wlan=1 # TODO essid="$(iwconfig eth0 | tr ' ' '\n' | grep ESSID | cut -d':' -f2|sed 's/^.//;s/.$//;')" # TODO ap="$(iwconfig eth0 | grep 'Access Point'|cut -d':' -f4-|cut -d' ' -f2)" # TODO ip="$(ip addr show eth0 | grep inet | awk '{print $2}'|cut -d'/' -f1)" # TODO ip route | grep eth0 > /tmp/eth0-routes # TODO device stop wifi # TODO fi # TODO monitor="$(xset q | grep "^ Monitor is")" # TODO touch /tmp/frameworkd.pid # TODO dbus-send --type=method_call --system --dest=org.freesmartphone.ogsmd /org/freesmartphone/GSM/Device org.freesmartphone.Resource.Suspend amixer -q -d sset "Amp Spk" mute # TODO sleep 3 # TODO sync # TODO sync # TODO sync # TODO sleep 1 # TODO echo 0 > /proc/sysrq-trigger # TODO rtcwake -m no -s 3600 > /dev/null } resume() { resume_reason="$(om resume-reason)" # TODO temperature="$(temperature)" # TODO consumption="$(consumption)" # TODO energy="$(energy)" # TODO logger "susp.real: resuming (reason $resume_reason) (temperature $temperature) (consumption $consumption) (energy $energy)" # TODO if [ "$ret" != 0 ]; then # TODO logger "suspend failed with $ret" # TODO resume_reason="suspend_failed" # TODO fi if [ "$resume_reason" = "EINT09_PMU:rtc_alarm" ] then echo "Resume on RTC alarm" # TODO if [ "$energy" -lt 3 ]; then # TODO if [ ! -e /tmp/silent ]; then # TODO alsactl -f /tmp/saved.state store # TODO alsactl -f /etc/alsa-scenarios/stereoout-maxvolume.state restore # TODO aplay --quiet $HOME/etc/akku-on-tyhja.wav # TODO alsactl -f /tmp/saved.state restore # TODO fi # TODO shutdown -h now # TODO while true; do # TODO sleep 1 # TODO done # TODO fi # TODO if [ "$energy" -lt 20 ]; then # TODO if [ ! -e /tmp/silent ]; then # TODO alsactl -f /tmp/saved.state store # TODO alsactl -f /etc/alsa-scenarios/stereoout-maxvolume.state restore # TODO aplay --quiet $HOME/etc/akku-lahes-tyhja.wav # TODO alsactl -f /tmp/saved.state restore # TODO fi # TODO fi # TODO rtcwake -m no -s 3600 > /dev/null # TODO continue (return 250 / CA) fi if [ "$resume_reason" = "EINT09_PMU:usb_connect" ] then echo "Resume on USB connect" # TODO logger "waiting for usb charging" # TODO sleep 6 # TODO logger "suspending" # TODO continue (return 250 / CA) fi # TODO echo $temperature > /tmp/temperature-on-resume # TODO echo $consumption > /tmp/consumption-on-resume # TODO # TODO if [ "$monitor" = " Monitor is Off" ]; then # TODO xset dpms force off # TODO fi # TODO amixer -q -d sset "Amp Spk" unmute # TODO /etc/init.d/set-clock start # TODO touch /tmp/frameworkd.pid # TODO dbus-send --type=method_call --system --dest=org.freesmartphone.ogsmd /org/freesmartphone/GSM/Device org.freesmartphone.Resource.Resume # TODO echo 8 > /proc/sysrq-trigger # TODO # TODO if [ "$wlan" = "1" ]; then # TODO device start wifi # TODO sleep 3 # TODO iwconfig eth0 essid "$essid" # TODO iwconfig eth0 ap "$ap" # TODO ifconfig eth0 "$ip" # TODO cat /tmp/eth0-routes | while read route; do # TODO ip route replace $route # TODO done # TODO fi } case "$1" in hibernate|suspend) suspend ;; thaw|resume) resume ;; *) exit $NA ;; esac exit 0 omhacks-0.16/README0000644000175000017500000002450311462027257012737 0ustar lindilindi*** README for omhacks It is a fast and simple library of common openmoko utility functions. There is a very simple command line front-end called "om", which exposes all the library functions. Just run om to get its command line help. The extra om-led executable is the same as running "om led", but is also provided separately so that it's possible to make "om-led" suid but not "om". If you need another function in the library, please send a patch. Please try to keep in the minimalist spirit of the library, and also provide a command line front end. omhacks can optionally be hooked to suspend/resume in various ways. /usr/share/doc/omhacks/examples/00at is an example on how to configure the phone to wake up using RTC alarm to run at jobs. /usr/lib/pm-utils/sleep.d/omhacks.so is a hook that is used only if pm-utils-light is installed, normal pm-utils ignores it. It turns the blue LED on during suspend/resume so that you an easily see if the phone gets stuck while executing suspend/resume scripts. It also automatically resuspends the phone if it was woken up by usb disconnect event. The touchscreen and backlight are kept disabled when this resuspending is taking place. When you unplug the usb cable you should only see the blue LED light for a few seconds. ** pm-utils-light omhacks.so hooks omhacks installs some pm-utils-light suspend hooks, using its dynamic hooks feature to have fast, lightweight hooks implemented in C. The hooks provided by omhacks.so are: Name On suspend On resume 00-statusled Turn on blue led Turn on blue led 74-screen Turn off screen Turn on screen 98-cancel-on-usb-disconnect - Cancel resume if reason is USB disconnect 99-statusled Turn off blue led Turn off blue led If you do not want one of these hooks to run, just create an empty file /etc/pm/sleep.d/NN-HOOKNAME and make sure it is not executable. It will override and disable the hook in /usr as pm-utils hooks are expected to do. *** TODO list - Write the at hook also as a shlib, and package it so that it works both with pm-utils and with pm-utils-light 18:00 #openmoko-debian < lindi-> enrico: btw, how about using "on|off" instead of 0 and 1? 18:00 #openmoko-debian < enrico> lindi-: I thought about it, since I keep using 'on' and turning things off because atoi("on") is 0 18:01 #openmoko-debian < lindi-> but 1 and 0 sound very odd indeed. almost no command uses that kind of logic - get rid of *_swap() in omhacks - instead of keeping a table of sysfs names, scan things and create symlink in /var/run/omhacks/ http://wiki.openmoko.org/wiki/GTA02_sysfs enrico> lindi-: after reading that thread on -kernel, I decided that the way to go is a symlink farm in /var/run/omhacks enrico> lindi-: yes, there's a lot of code duplication. I think it's ok so far, eventually we'll see a way to collapse it into something sensible lindi-> enrico: when is /var/run available? can you use omhacks on initramfs? lindi-> enrico: i'd like to be able to force 500 mA charging in the very beginning of initramfs lindi-> enrico: it's always a tradeoff :( lindi-> enrico: any idea why running plain 'om' opens /dev/urandom? enrico> lindi-: erhm, I see wrt initramfs. You have a point enrico> lindi-: OTOH, we can fail gracefully and return the real pathname instead of the symlink lindi-> enrico: I already dim backlight in the very beginning of boot to make my phone boot with low battery enrico> lindi-: and just use the symlink instead of the cache, as a sort of persistent cache. If there's no /var/run, then skip the symlink enrico> no idea why plain om opens urandom. I really can't think why lindi-> enrico: ok using the symlink as a fallback is probably good idea enrico> maybe "break open" in gdb should tell you when it happens 20:16 #openmoko-debian < lindi-> enrico: also, access() is useless 20:16 #openmoko-debian < lindi-> enrico: why could just have "FILE *try_open(const char *list_of_alternatives[])" that tries to fopen() each alternative and returns NULL if all failed 20:17 #openmoko-debian < lindi-> s/why/we/ 20:17 #openmoko-debian < lindi-> then one of the alternatives could be the symlink path 20:19 #openmoko-debian < enrico> lindi-: I thought access was faster than open 20:20 #openmoko-debian < enrico> lindi-: ah, you mean, combining the search with the opening, like a sysfs_open 20:20 #openmoko-debian < enrico> lindi-: interesting... clever... 22:14 #openmoko-debian < lindi-> enrico: it stays asleep and when i resume using button it still has fix 22:14 #openmoko-debian < lindi-> enrico: so works perfectly. now just implement "om gps ubx /dev/gps go-to-low-power-state" to make it also save energy - recreate lindi's suspend/resume scripts http://lindi.iki.fi/lindi/openmoko/custom-scripts.txt - My goals - stand-alone pppd + turn gsm on/off (done) - turn gsm really on (can be done in pppd's chatscript) http://lindi.iki.fi/lindi/openmoko/manual-call.txt - wake up alarm + at hook, date +%s > $STORAGE/last-resume - "alert" script redone - for desktop and moko - with config file - on/off go back to sleep if triggered within 1 minute from resume (no need to look at resume_reason) - on/off moko specific - inputs (listen to aux button instead of keyboard/mouse) - audio (fiddle with mixer) - vibration / leds (flash aux so one can see what to push in the dark) - X display to use if undefined - ringtone - run maximised enrico> lindi-: the hook works! scheduling jobs with at will wake up the phone and at will run the scheduled job *right away* enrico> lindi-: now I need to tweak your alert script a bit, so that if it's run within one minute from resume and noone pushes aux while it's being noisy, then it goes back to sleep enrico> lindi-: then any at job can be followed by a run of that alert script, and it solves the issue of going back to sleep at the end of the job enrico> lindi-: for extra kicks, the at script can have an option to run a program in background and also wait for it to end before suspending - Example of an at job that goes back to sleep at the end, if resume reason was rtcwake and there has been no meaningful input - GSM - turn on all, inc. PIN - GPS - suspend/resume GPS, saving/restoring status - lindi-> enrico: http://lists.openmoko.org/nabble.html#nabble-td2476690 has info about low power mode - 00:08 #openmoko-debian < lindi-> enrico: | http://downloads.openmoko.org/developer/sources/svn/omgps.googlecode.com/svn/trunk/omgps/src/ubx.c seems to have routines for this 00:09 #openmoko-debian < lindi-> enrico: README from Jul 2009 says 'Omgps is a GPS application for OpenMolo mobile phone.' 00:10 #openmoko-debian < lindi-> enrico: so we have yet another GPS program :) - set funky parameters - keep GPS on during suspend - set stationary threshold for different profiles (Automotive = 3, pedestrian = 2, stationary = 1) http://lists.linuxtogo.org/pipermail/smartphones-userland/2009-October/002037.html http://wiki.openmoko.org/wiki/Neo_FreeRunner_GPS#UBX_protocol http://lists.openmoko.org/pipermail/openmoko-kernel/2008-July/004047.html http://people.openmoko.org/tony_tu/src/u-blox/AssistNowOfflineServerSampleImplementation/ http://svn.openmoko.org/developers/matt_hsu/agps-online/ 00:29 #openmoko-debian < lindi-> enrico: 'om gps keep-on-in-suspend' does not say anything to the gps chip. does this really work? won't it wake up the main cpu since it is sending coordinates constantly? 00:30 #openmoko-debian < enrico> lindi-: I have *no* idea 00:30 #openmoko-debian < enrico> lindi-: it's too cold outside now to test it 00:30 #openmoko-debian < lindi-> since there's some UBX command to put the GPS chip to a "keep fix but don't actively track and report coordinates" mode 20:37 #openmoko-debian < enrico> lindi-: in fact I can code that ubxgen in C 20:37 #openmoko-debian < lindi-> enrico: yes 20:38 #openmoko-debian < lindi-> enrico: together with manual page that has examples it would be very useful tool - Wifi - ask the kernel people what is the proper way to turn it on/off, and to check if it's on - .vapi for omhacks, to use in zavai - battery - read, monitor 20:18 #openmoko-debian < lindi-> enrico: how about adding "energy" and "consumption" to om? 20:19 #openmoko-debian < lindi-> enrico: and usb_curlimit 20:19 #openmoko-debian < lindi-> and host/device modes - fork pm-utils-light off omhacks - reduce the size of lindi's ~/bin/ http://lindi.iki.fi/lindi/openmoko/custom-scripts.txt 16:18 #openmoko-debian < enrico> lindi-: a few questions: 16:18 #openmoko-debian < enrico> lindi-: 2. what's the fiddling with sysrq-trigger? 16:19 #openmoko-debian < enrico> lindi-: 3. why touch /tmp/frameworkd.pid ? ------------------------------------------------------------------------------------------------------------------- 16:40 #openmoko-debian < lindi-> enrico: 2. sysrq trigger just makes sure kernel does not log anything on resume to display, this used to slow things down a lot with debugging information 16:40 #openmoko-debian < lindi-> enrico: 3. gsm-watchdog looks at the freshness of /tmp/frameworkd.pid 16:41 #openmoko-debian < lindi-> enrico: 3. (Right after resume ogsmd won't respond to dbus. touching pid file makes sure the watchdog does not immediately kill ogsmd in this case but waits for a while) - leds http://www.mjmwired.net/kernel/Documentation/leds-class.txt From: Richard Purdie Cc: openmoko-kernel Subject: Re: Renaming of devices in 2.6.31 [...] Note that the sysfs people hate me for this. They would want you to go through each directory in /sys/class/leds/ opening the /sys/class/leds/*/function file and reading it to find what you want. So it could be much worse! omhacks-0.16/CMakeLists.txt0000644000175000017500000000023111652547334014613 0ustar lindilindicmake_minimum_required(VERSION 2.6) project(omhacks) set(omhacks_version "0.16") add_subdirectory(omhacks) add_subdirectory(src) add_subdirectory(hooks) omhacks-0.16/COPYING0000644000175000017500000004310311312714715013103 0ustar lindilindi GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. omhacks-0.16/omhacks/0000755000175000017500000000000011652541741013500 5ustar lindilindiomhacks-0.16/omhacks/resumereason.c0000644000175000017500000000737711462027257016372 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "resumereason.h" #include "sysfs.h" #include #include #include #define ORR_BUFSIZE 512 #define ORR_ARRSIZE 32 static struct orr_t { char buf[ORR_BUFSIZE]; int buf_size; char* arr[ORR_ARRSIZE]; int arr_size; } orr; static void orr_append_str(const char* line) { if (orr.buf_size >= ORR_BUFSIZE) return; for ( ; *line && *line != '\n' && orr.buf_size < ORR_BUFSIZE-1; ++line) orr.buf[orr.buf_size++] = *line; orr.buf[orr.buf_size++] = 0; } const char** om_resume_reason() { static char line[256]; orr.buf_size = 0; orr.arr_size = 0; const char* fname = om_sysfs_path("resume_reason"); if (fname == NULL) return NULL; FILE* in = fopen(fname, "r"); if (in == NULL) return NULL; while (fgets(line, 256, in) && orr.buf_size < ORR_BUFSIZE && orr.arr_size < ORR_ARRSIZE - 1) { // Skip empty or inactive lines if (line[0] != '*' || line[1] == 0) continue; if (strcmp(line + 2, "EINT09_PMU\n") != 0) { orr.arr[orr.arr_size] = orr.buf + orr.buf_size; orr_append_str(line + 2); ++orr.arr_size; } else { const char* reason2; unsigned long long resume_reason_pmu; reason2 = om_sysfs_get("resume_reason2"); if (reason2 == NULL) return NULL; if (strlen(reason2) < 10) return NULL; resume_reason_pmu = strtoull(reason2, NULL, 16); while (resume_reason_pmu) { if (resume_reason_pmu & 0x0002000000ULL) { resume_reason_pmu &= ~0x0002000000ULL; orr.arr[orr.arr_size] = orr.buf + orr.buf_size; orr_append_str(line + 2); orr.buf[orr.buf_size-1] = ':'; orr_append_str("button"); } else if (resume_reason_pmu & 0x0400000000ULL) { resume_reason_pmu &= ~0x0400000000ULL; orr.arr[orr.arr_size] = orr.buf + orr.buf_size; orr_append_str(line + 2); orr.buf[orr.buf_size-1] = ':'; orr_append_str("usb_connect"); } else if (resume_reason_pmu & 0x4000000000ULL) { resume_reason_pmu &= ~0x4000000000ULL; orr.arr[orr.arr_size] = orr.buf + orr.buf_size; orr_append_str(line + 2); orr.buf[orr.buf_size-1] = ':'; orr_append_str("rtc_alarm"); } else if (resume_reason_pmu & 0x0800000000ULL) { resume_reason_pmu &= ~0x0800000000ULL; orr.arr[orr.arr_size] = orr.buf + orr.buf_size; orr_append_str(line + 2); orr.buf[orr.buf_size-1] = ':'; orr_append_str("usb_disconnect"); } else if (resume_reason_pmu & 0x0000000200ULL) { resume_reason_pmu &= ~0x0000000200ULL; orr.arr[orr.arr_size] = orr.buf + orr.buf_size; orr_append_str(line + 2); orr.buf[orr.buf_size-1] = ':'; orr_append_str("low_battery"); } else { resume_reason_pmu = 0; orr.arr[orr.arr_size] = orr.buf + orr.buf_size; orr_append_str(line + 2); orr.buf[orr.buf_size-1] = ':'; orr_append_str(reason2); } ++orr.arr_size; } } } fclose(in); orr.arr[orr.arr_size] = NULL; return (const char**)orr.arr; } omhacks-0.16/omhacks/gsm.c0000644000175000017500000000742211303325660014430 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "gsm.h" #include "sysfs.h" #include #include #include #include static char gsm_power_path[PATH_MAX]; static int gsm_power_path_found = 0; static char gsm_reset_path[PATH_MAX]; static int gsm_reset_path_found = 0; static char gsm_flowcontrol_path[PATH_MAX]; static int gsm_flowcontrol_path_found = 0; static const char* om_gsm_power_path() { if (!gsm_power_path_found) { const char* root = om_sysfs_path("pm-gsm"); if (root == NULL) return NULL; snprintf(gsm_power_path, PATH_MAX, "%s/power_on", root); if (access(gsm_power_path, F_OK) != 0) return NULL; gsm_power_path_found = 1; } return gsm_power_path; } static const char* om_gsm_reset_path() { if (!gsm_reset_path_found) { const char* root = om_sysfs_path("pm-gsm"); if (root == NULL) return NULL; snprintf(gsm_reset_path, PATH_MAX, "%s/reset", root); if (access(gsm_reset_path, F_OK) != 0) return NULL; gsm_reset_path_found = 1; } return gsm_reset_path; } static const char* om_gsm_flowcontrol_path() { if (!gsm_flowcontrol_path_found) { const char* root = om_sysfs_path("pm-gsm"); if (root == NULL) return NULL; snprintf(gsm_flowcontrol_path, PATH_MAX, "%s/flowcontrolled", root); if (access(gsm_flowcontrol_path, F_OK) != 0) return NULL; gsm_flowcontrol_path_found = 1; } return gsm_flowcontrol_path; } int om_gsm_power_get() { const char* path = om_gsm_power_path(); if (path == NULL) return -1; const char* val = om_sysfs_readfile(path); if (val == NULL) return -1; return atoi(val); } int om_gsm_power_set(int value) { // This feels rather silly at the moment, but it makes sense to have // some consistency in the various get/set/swap APIs. int res = om_gsm_power_swap(value); if (res < 0) return res; return 0; } int om_gsm_power_swap(int value) { const char* power_path = om_gsm_power_path(); if (power_path == NULL) return -1; const char* val = om_sysfs_readfile(power_path); if (val == NULL) return -1; int old_val = atoi(val); // If we are setting it to what it already is, don't bother if (value == old_val) return old_val; if (value) { // Note: the logic here is Enrico cargo-culting Lindi // Turn on const char* reset_path = om_gsm_reset_path(); if (reset_path == NULL) return -1; if (om_sysfs_writefile(power_path, "0\n") < 0) return -1; if (om_sysfs_writefile(power_path, "1\n") < 0) return -1; if (om_sysfs_writefile(reset_path, "1\n") < 0) return -1; } else { // Turn off if (om_sysfs_writefile(power_path, "0\n") < 0) return -1; } return old_val; } int om_gsm_flowcontrol_get() { const char* path = om_gsm_flowcontrol_path(); if (path == NULL) return -1; const char* val = om_sysfs_readfile(path); if (val == NULL) return -1; return atoi(val); } int om_gsm_flowcontrol_set(int value) { const char* flowcontrol_path = om_gsm_flowcontrol_path(); if (flowcontrol_path == NULL) return -1; if (om_sysfs_writefile(flowcontrol_path, value ? "1\n" : "0\n") < 0) return -1; return 0; } omhacks-0.16/omhacks/wifi.c0000644000175000017500000001366411652541741014614 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "wifi.h" #include "sysfs.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static char wifi_bind_path[PATH_MAX]; static int wifi_bind_path_found = 0; static char wifi_unbind_path[PATH_MAX]; static int wifi_unbind_path_found = 0; #define WIFI_MCI_PERSIST_PATH "/sys/module/s3cmci/parameters/persist" #define AR6000_XIOCTRL_WMI_GET_POWER_MODE 34 #define AR6000_IOCTL_EXTENDED (SIOCIWFIRSTPRIV+31) #define AR6000_IOCTL_WMI_SETPWR (SIOCIWFIRSTPRIV+11) #define MAX_PERF_POWER 2 static const char* om_wifi_bind_path() { if (!wifi_bind_path_found) { const char* root = om_sysfs_path("wifi_root"); if (root == NULL) return NULL; snprintf(wifi_bind_path, PATH_MAX, "%s/bind", root); if (access(wifi_bind_path, F_OK) != 0) return NULL; wifi_bind_path_found = 1; } return wifi_bind_path; } static const char* om_wifi_unbind_path() { if (!wifi_unbind_path_found) { const char* root = om_sysfs_path("wifi_root"); if (root == NULL) return NULL; snprintf(wifi_unbind_path, PATH_MAX, "%s/unbind", root); if (access(wifi_unbind_path, F_OK) != 0) return NULL; wifi_unbind_path_found = 1; } return wifi_unbind_path; } /* * Block or unblock rfkill enabled driver by its name * * This has currently only been tested with wifi where the driver is * named "ar6000\n". If the function seems to be generally useful it * might make sense to put it to a separate rfkill.h and expose it to * users of the library. * * @driver_name name of driver (plus a newline) * @block 1 to block, 0 to unblock * * Returns 0 on success and negative value on error. * Returns -1 if the system does not support rfkill. * */ static int om_rfkill_block_by_name(const char *driver_name, int block) { int i; { struct stat st; int ret; ret = stat("/sys/class/rfkill", &st); if (ret < 0) { return -1; } if (!(st.st_mode & S_IFDIR)) { return -2; } } for (i = 0; i < 10; i++) { char buf[128]; const char *name; sprintf(buf, "/sys/class/rfkill/rfkill%d/name", i); name = om_sysfs_readfile(buf); if (name && !strcmp(name, driver_name)) { struct rfkill_event event; int fd, ret; event.idx = i; event.type = 0; event.op = RFKILL_OP_CHANGE; event.soft = !!block; event.hard = 0; fd = open("/dev/rfkill", O_RDWR); if (fd < 0) { return -4; } ret = write(fd, &event, sizeof(event)); if (ret != sizeof(event)) { close(fd); return -5; } close(fd); return 0; } } return -3; } int om_wifi_power_get() { /* Caching this path (as static) does not make sense since we use its existence to check if wlan is bound or not. */ char wifi_bound_path[PATH_MAX]; const char* root = om_sysfs_path("wifi_root"); if (root == NULL) return -1; snprintf(wifi_bound_path, PATH_MAX, "%s/s3c2440-sdi", root); int res = access(wifi_bound_path, F_OK); if (res == 0) return 1; if (errno == ENOENT) return 0; return res; } int om_wifi_power_set(int value) { // This feels rather silly at the moment, but it makes sense to have // some consistency in the various get/set/swap APIs. int res = om_wifi_power_swap(value); if (res < 0) return res; res = om_rfkill_block_by_name("ar6000\n", !value); if (res < -1) return res; return 0; } int om_wifi_power_swap(int value) { int old_val = om_wifi_power_get(); // If we are setting it to what it already is, don't bother if (value == old_val) return old_val; if (value) { // Turn on const char* path = om_wifi_bind_path(); if (path == NULL) return -1; if (om_sysfs_writefile(path, "s3c2440-sdi\n") < 0) return -1; } else { // Turn off const char* path = om_wifi_unbind_path(); if (path == NULL) return -1; if (om_sysfs_writefile(path, "s3c2440-sdi\n") < 0) return -1; } return old_val; } int om_wifi_maxperf_get(const char *ifname) { int sock, ret; struct ifreq ifr; int buf[64]; sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) return -1; memset(ifr.ifr_name, '\0', sizeof(ifr.ifr_name)); strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); buf[0] = AR6000_XIOCTRL_WMI_GET_POWER_MODE; ifr.ifr_data = buf; ret = ioctl(sock, AR6000_IOCTL_EXTENDED, &ifr); if (ret != 0) return -2; return ((char *)buf)[0] == MAX_PERF_POWER; } int om_wifi_maxperf_set(const char *ifname, int mode) { int sock, ret; struct ifreq ifr; int buf[64]; sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) return -1; memset(ifr.ifr_name, '\0', sizeof(ifr.ifr_name)); strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); buf[0] = mode ? MAX_PERF_POWER : 0; ifr.ifr_data = buf; ret = ioctl(sock, AR6000_IOCTL_WMI_SETPWR, &ifr); if (ret != 0) return -2; return 0; } int om_wifi_keep_bus_on_in_suspend_get() { const char* val = om_sysfs_readfile(WIFI_MCI_PERSIST_PATH); if (val == NULL) return -1; return atoi(val); } int om_wifi_keep_bus_on_in_suspend_set(int value) { return om_sysfs_writefile(WIFI_MCI_PERSIST_PATH, value ? "1\n" : "0\n"); } omhacks-0.16/omhacks/wifi.h0000644000175000017500000000513011346522430014600 0ustar lindilindi#ifndef OMHACKS_WIFI_H #define OMHACKS_WIFI_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Return the power status of the Wifi chip. * * Returns 1 if on, 0 if off, a negative value in case of problems. */ int om_wifi_power_get(); /* * Turn on/off the Wifi chip * * If value is true, turn on the Wifi. Else, turn it off. */ int om_wifi_power_set(int value); /* * Turn on/off the Wifi chip, and return the previous status. * * If value is true, turn on the Wifi. Else, turn it off. * * Returns 1 if on, 0 if off, a negative value in case of problems. */ int om_wifi_power_swap(int value); /* * Return status maximum performance mode of the wifi chip. * * Returns 0 if wifi if maximum performance mode is disable, 1 if it * is enabled and negative value on error. */ int om_wifi_maxperf_get(const char *ifname); /* * Enable/disable wifi maximum performance mode * * If value is true, enable maximum performance mode. Else, turn it * off. Performance mode reduces latency but consumes more energy. * * Note that root privileges are not currently required for tuning * this wifi parameter so a local user can cause DoS by constantly * disabling maximum performance mode. * * Returns 0 on success and negative value on error. */ int om_wifi_maxperf_set(const char *ifname, int value); /* * Return status of MCI bus during suspend. MCI bus connects wifi to * CPU and is required for Wake-on-Wireless to work. * * Returns 0 if MCI bus will be powered down during suspend, 1 if it * will be kept powered and negative value in case of problems. */ int om_wifi_keep_bus_on_in_suspend_get(); /* * Enable/disable the MCI bus during suspend. * * If value is true, MCI bus will be powered down during * suspend. Else, it gets switched off. */ int om_wifi_keep_bus_on_in_suspend_set(int value); #endif omhacks-0.16/omhacks/gsm.h0000644000175000017500000000332611303300752014427 0ustar lindilindi#ifndef OMHACKS_GSM_H #define OMHACKS_GSM_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Return the power status of the GSM chip. * * Returns 1 if on, 0 if off, a negative value in case of problems. */ int om_gsm_power_get(); /* * Turn on/off the GSM chip * * If value is true, turn on the GSM. Else, turn it off. */ int om_gsm_power_set(int value); /* * Turn on/off the GSM chip, and return the previous status. * * If value is true, turn on the GSM. Else, turn it off. * * Returns 1 if on, 0 if off, a negative value in case of problems. */ int om_gsm_power_swap(int value); /* * Return flow control status of GSM serial port. * * Returns 1 if port is flow contolled, 0 if it is not and negative if an error occured. */ int om_gsm_flowcontrol_get(); /* * Set GSM serial port flow control status * * If value is true, enable flow contorl. Else, disable it. * */ int om_gsm_flowcontrol_set(int value); #endif omhacks-0.16/omhacks/usb.h0000644000175000017500000000431111312767710014440 0ustar lindilindi#ifndef OMHACKS_USB_H #define OMHACKS_USB_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Return the mode in which the USB controller is. * * Returns 0 for device mode, 1 for host mode and negative for * failure. */ int om_usb_mode_get(); /* * Set mode of the USB controller. * * If mode is 0 controller will be put to device mode and if it is 1 * it will be put to host mode. * * Returns 0 on success and negative value on failure. */ int om_usb_mode_set(int mode); /* * Get status of battery charger. * * Returns 0 if charger charges the battery from USB power. * Returns 1 if charger is disabled and power from battery is provided to USB bus. * Returns negative value on failure. */ int om_usb_charger_mode_get(); /* * Set status of battery charger. * * See above for description of the two possible modes. * * Returns 0 on success and negative value on failure. */ int om_usb_charger_mode_set(int value); /* * Get the charger current limit. * * Returns current limit in milliamperes or negative value on error. */ int om_usb_charger_limit_get(); /* * Set the charger current limit. * * By default kernel will draw 100 mA but try to negotiate more * if possible. This API can be used to override this selection. * Do not set the limit to be too large if your charger can not handle it! * * Returns 0 on success and negative value on failure. */ int om_usb_charger_limit_set(int limit); #endif omhacks-0.16/omhacks/uevent.h0000644000175000017500000000343311312714715015156 0ustar lindilindi#ifndef OMHACKS_UEVENT_H #define OMHACKS_UEVENT_H /* * uevent - Listen to uevent events * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #define OM_UEVENT_ENV_MAX 32 /* UEvent information */ struct om_uevent { char buffer[1024 + 512]; // Buffer with the raw uevent data // At the beginning of the buffer, is the // null-terminated action@devpath string size_t buflen; // Buffer length const char *action; // Parsed action const char *devpath; // Parsed device path const char *envp[OM_UEVENT_ENV_MAX]; // Parsed environment }; /** * Open a uevent socket. * * The socket is a normal unix file descriptor, to be closed using normal * close() * * Returns the socket, or a negative value in case of problems. */ int om_uevent_open(); /** * Read a uevent record */ int om_uevent_read(int sock, struct om_uevent* ou); /** * Parse the raw uevent buffer in its components * * Returns 0 if all parsed correctly, -1 if this record does not parse properly * and should be skipped. */ int om_uevent_parse(struct om_uevent* ou); #endif omhacks-0.16/omhacks/bt.c0000644000175000017500000000566511302302200014236 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "bt.h" #include "sysfs.h" #include #include #include #include static char bt_power_path[PATH_MAX]; static int bt_power_path_found = 0; static char bt_reset_path[PATH_MAX]; static int bt_reset_path_found = 0; static const char* om_bt_power_path() { if (!bt_power_path_found) { const char* root = om_sysfs_path("pm-bt"); if (root == NULL) return NULL; snprintf(bt_power_path, PATH_MAX, "%s/power_on", root); if (access(bt_power_path, F_OK) != 0) return NULL; bt_power_path_found = 1; } return bt_power_path; } static const char* om_bt_reset_path() { if (!bt_reset_path_found) { const char* root = om_sysfs_path("pm-bt"); if (root == NULL) return NULL; snprintf(bt_reset_path, PATH_MAX, "%s/reset", root); if (access(bt_reset_path, F_OK) != 0) return NULL; bt_reset_path_found = 1; } return bt_reset_path; } int om_bt_power_get() { const char* path = om_bt_power_path(); if (path == NULL) return -1; const char* val = om_sysfs_readfile(path); if (val == NULL) return -1; return atoi(val); } int om_bt_power_set(int value) { // This feels rather silly at the moment, but it makes sense to have // some consistency in the various get/set/swap APIs. int res = om_bt_power_swap(value); if (res < 0) return res; return 0; } int om_bt_power_swap(int value) { const char* power_path = om_bt_power_path(); if (power_path == NULL) return -1; const char* reset_path = om_bt_reset_path(); if (reset_path == NULL) return -1; const char* val = om_sysfs_readfile(power_path); if (val == NULL) return -1; int old_val = atoi(val); // If we are setting it to what it already is, don't bother if (value == old_val) return old_val; if (value) { // Note: the logic here is Enrico cargo-culting Lindi // Turn on if (om_sysfs_writefile(power_path, "1\n") < 0) return -1; if (om_sysfs_writefile(reset_path, "0\n") < 0) return -1; } else { // Note: the logic here is Enrico cargo-culting Lindi // Turn off if (om_sysfs_writefile(reset_path, "1\n") < 0) return -1; if (om_sysfs_writefile(power_path, "0\n") < 0) return -1; } return old_val; } omhacks-0.16/omhacks/all.h0000644000175000017500000000226011312752335014415 0ustar lindilindi#ifndef OMHACKS_ALL_H #define OMHACKS_ALL_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #endif omhacks-0.16/omhacks/resumereason.h0000644000175000017500000000231211462027257016357 0ustar lindilindi#ifndef OMHACKS_RESUME_REASON_H #define OMHACKS_RESUME_REASON_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Return a NULL-terminated string array with the reasons for the last * resume or NULL if there was an error while trying to determine * resume reason. * * Note that the strings are in a statically allocated buffer that is rewritten * at every invocation. */ const char** om_resume_reason(); #endif omhacks-0.16/omhacks/screen.c0000644000175000017500000001120711515552203015115 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "screen.h" #include "sysfs.h" #include #include #include #include #include #include #include #include #include #include #include #ifndef EVIOCGRAB #define EVIOCGRAB 0x40044590 #endif int om_screen_brightness_get() { const char* res = om_sysfs_get("brightness"); if (res == NULL) return -1; return atoi(res); } static int om_screen_actual_brightness_get() { const char* res = om_sysfs_get("actual_brightness"); if (res == NULL) return -1; return atoi(res); } int om_screen_brightness_get_max() { const char* res = om_sysfs_get("max_brightness"); if (res == NULL) return -1; return atoi(res); } int om_screen_brightness_set(int val) { char sval[20]; snprintf(sval, 20, "%d", val); return om_sysfs_set("brightness", sval) == 0 ? 0 : -1; } int om_screen_brightness_swap(int val) { char sval[20]; snprintf(sval, 20, "%d", val); const char* res = om_sysfs_swap("brightness", sval); if (res == NULL) return -1; return atoi(res); } int om_touchscreen_open() { return open("/dev/input/event1", O_RDONLY); } int om_touchscreen_lock(int fd) { return ioctl(fd, EVIOCGRAB, 1); } int om_touchscreen_unlock(int fd) { return ioctl(fd, EVIOCGRAB, 0); } int om_screen_power_get() { int brightness, actual_brightness; if ((brightness = om_screen_brightness_get()) < 0) return -1; if ((actual_brightness = om_screen_actual_brightness_get()) < 0) return -2; /* This is a hack but there is really no other way to retrieve * this information from userland. Xorg never reads power * status and fso-frameworkd uses this same trick on startup. */ return brightness == actual_brightness; } int om_screen_power_set(int val) { int fd, ret; fd = open("/dev/fb0", O_RDWR); if (fd < 0) return -1; ret = ioctl(fd, FBIOBLANK, val ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN); close(fd); if (ret != 0) return -2; return 0; } const char* om_screen_resolution_get() { const char* res = om_sysfs_get("screen_resolution"); if (res) { if (strcmp(res, "normal\n") == 0) return "normal"; if (strcmp(res, "qvga-normal\n") == 0) return "qvga-normal"; return NULL; } res = om_sysfs_get("screen_resolution2"); if (res) { if (strcmp(res, "vga\n") == 0) return "normal"; if (strcmp(res, "qvga\n") == 0) return "qvga-normal"; return NULL; } return NULL; } int om_screen_resolution_set(const char *val) { int res; res = om_sysfs_set("screen_resolution", val); if (res >= 0) return res; if (strcmp(val, "normal") == 0) return om_sysfs_set("screen_resolution2", "vga"); if (strcmp(val, "qvga-normal") == 0) return om_sysfs_set("screen_resolution2", "qvga"); return -1; } #define TIMINGS_444 0x1bc0 #define TIMINGS_242 0x1380 const char* om_screen_glamo_bus_timings_get() { int fd; uint8_t* glamo; uint32_t timings; fd = open("/dev/mem", O_RDONLY); if (fd < 0) return NULL; glamo = mmap(NULL, 4096, PROT_READ, MAP_SHARED, fd, 0x48000000); if (glamo == MAP_FAILED) { close(fd); return NULL; } timings = *(uint32_t*)(glamo + 8); munmap(glamo, 4096); close(fd); if (timings == TIMINGS_444) return "4-4-4"; if (timings == TIMINGS_242) return "2-4-2"; return NULL; } int om_screen_glamo_bus_timings_set(const char* val) { int fd; uint8_t* glamo; uint32_t timings; if (strcmp(val, "4-4-4") == 0) timings = TIMINGS_444; else if (strcmp(val, "2-4-2") == 0) timings = TIMINGS_242; else return -1; fd = open("/dev/mem", O_RDWR); if (fd < 0) return -2; glamo = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x48000000); if (glamo == MAP_FAILED) { close(fd); return -3; } *(uint32_t*)(glamo + 8) = timings; munmap(glamo, 4096); close(fd); return 0; } omhacks-0.16/omhacks/battery.c0000644000175000017500000000713011406356565015324 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "battery.h" #include "sysfs.h" #include #include #include #include #include #include #include #include #include static char battery_temperature_path[PATH_MAX]; static int battery_temperature_path_found = 0; static char battery_energy_path[PATH_MAX]; static int battery_energy_path_found = 0; static char battery_consumption_path[PATH_MAX]; static int battery_consumption_path_found = 0; static const char *om_battery_temperature_path() { if (!battery_temperature_path_found) { const char *root = om_sysfs_path("battery"); if (root == NULL) return NULL; snprintf(battery_temperature_path, PATH_MAX, "%s/temp", root); if (access(battery_temperature_path, F_OK) != 0) return NULL; battery_temperature_path_found = 1; } return battery_temperature_path; } int om_battery_temperature_get(float *temperature) { const char *path = om_battery_temperature_path(); if (path == NULL) return -1; const char *val = om_sysfs_readfile(path); if (val == NULL) return -1; *temperature = atoi(val) / 10.0; return 0; } static const char *om_battery_energy_path() { if (!battery_energy_path_found) { const char *root = om_sysfs_path("battery"); if (root == NULL) return NULL; snprintf(battery_energy_path, PATH_MAX, "%s/capacity", root); if (access(battery_energy_path, F_OK) != 0) return NULL; battery_energy_path_found = 1; } return battery_energy_path; } int om_battery_energy_get() { const char *path = om_battery_energy_path(); if (path == NULL) return -1; const char *val = om_sysfs_readfile(path); if (val == NULL) return -1; return atoi(val); } static const char *om_battery_consumption_path() { if (!battery_consumption_path_found) { const char *root = om_sysfs_path("battery"); if (root == NULL) return NULL; snprintf(battery_consumption_path, PATH_MAX, "%s/current_now", root); if (access(battery_consumption_path, F_OK) != 0) return NULL; battery_consumption_path_found = 1; } return battery_consumption_path; } int om_battery_consumption_get(int *consumption) { const char *path = om_battery_consumption_path(); if (path == NULL) return -1; const char *val = om_sysfs_readfile(path); if (val == NULL) return -1; *consumption = atoi(val); return 0; } int om_battery_charger_limit_get(void) { const char* res = om_sysfs_get("chg_curlim"); if (res == NULL) return -1; return atoi(res); } int om_battery_charger_limit_set(int limit) { char buf[128]; snprintf(buf, sizeof(buf), "%d\n", limit); return om_sysfs_set("chg_curlim", buf) == 0 ? 0 : -1; } omhacks-0.16/omhacks/libomhacks.pc.in0000644000175000017500000000034511302302200016520 0ustar lindilindiprefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: libomhacks Description: Library of useful OpemMoko functions Version: @omhacks_version@ Cflags: -I${includedir} Libs: -L${libdir} -lomhacks omhacks-0.16/omhacks/gps.c0000644000175000017500000001173311406356565014447 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "gps.h" #include "sysfs.h" #include #include #include #include #include static char gps_power_path[PATH_MAX]; static int gps_power_path_found = 0; static char gps_keep_on_in_suspend_path[PATH_MAX]; static int gps_keep_on_in_suspend_path_found = 0; static const char* om_gps_power_path() { if (!gps_power_path_found) { const char* root = om_sysfs_path("pm-gps"); if (root == NULL) return NULL; snprintf(gps_power_path, PATH_MAX, "%s/power_on", root); if (access(gps_power_path, F_OK) != 0) return NULL; gps_power_path_found = 1; } return gps_power_path; } static const char* om_gps_keep_on_in_suspend_path() { if (!gps_keep_on_in_suspend_path_found) { const char* root = om_sysfs_path("pm-gps"); if (root == NULL) return NULL; snprintf(gps_keep_on_in_suspend_path, PATH_MAX, "%s/keep_on_in_suspend", root); if (access(gps_keep_on_in_suspend_path, F_OK) != 0) return NULL; gps_keep_on_in_suspend_path_found = 1; } return gps_keep_on_in_suspend_path; } int om_gps_power_get() { const char* path = om_gps_power_path(); if (path == NULL) return -1; const char* val = om_sysfs_readfile(path); if (val == NULL) return -1; return atoi(val); } int om_gps_power_set(int value) { // This feels rather silly at the moment, but it makes sense to have // some consistency in the various get/set/swap APIs. int res = om_gps_power_swap(value); if (res < 0) return res; return 0; } int om_gps_power_swap(int value) { const char* power_path = om_gps_power_path(); if (power_path == NULL) return -1; const char* val = om_sysfs_readfile(power_path); if (val == NULL) return -1; int old_val = atoi(val); // If we are setting it to what it already is, don't bother if (value == old_val) return old_val; if (value) { // Turn on if (om_sysfs_writefile(power_path, "1\n") < 0) return -1; } else { // Workaround bug http://docs.openmoko.org/trac/ticket/2293 // Turn off if (om_sysfs_writefile(power_path, "0\n") < 0) return -1; // Is it off? const char* val = om_sysfs_readfile(power_path); if (val == NULL) return -1; if (val[0] == '1') { // No, try again if (om_sysfs_writefile(power_path, "1\n") < 0) return -1; if (om_sysfs_writefile(power_path, "0\n") < 0) return -1; } } return old_val; } int om_gps_keep_on_in_suspend_get() { const char* path = om_gps_keep_on_in_suspend_path(); if (path == NULL) return -1; const char* val = om_sysfs_readfile(path); if (val == NULL) return -1; return atoi(val); } int om_gps_keep_on_in_suspend_set(int value) { const char* path = om_gps_keep_on_in_suspend_path(); if (path == NULL) return -1; return om_sysfs_writefile(path, value ? "1\n" : "0\n"); } int om_gps_keep_on_in_suspend_swap(int value) { const char* keep_on_in_suspend_path = om_gps_keep_on_in_suspend_path(); if (keep_on_in_suspend_path == NULL) return -1; const char* val = om_sysfs_readfile(keep_on_in_suspend_path); if (val == NULL) return -1; int old_val = atoi(val); // If we are setting it to what it already is, don't bother if (value == old_val) return old_val; if (om_sysfs_writefile(keep_on_in_suspend_path, value ? "1\n" : "0\n") < 0) return -1; return old_val; } int om_gps_open(void) { return open("/dev/ttySAC1", O_RDWR); } void om_gps_close(int fd) { close(fd); } int om_gps_ubx_send(int fd, int klass, int type, const char *payload, int payloadlen) { char *packet; int i, res = 0, packetlen = 2 + 1 + 1 + 2 + payloadlen + 2; ssize_t count; packet = malloc(packetlen); if (packet == NULL) return -1; packet[0] = 0xb5; packet[1] = 0x62; packet[2] = klass; packet[3] = type; packet[4] = payloadlen & 0xff; packet[5] = (payloadlen >> 8) & 0xff; for (i = 0; i < payloadlen; i++) { packet[6 + i] = payload[i]; } { unsigned char sum[2] = { 0, 0 }; for (i = 0; i < packetlen - 4; i++) { sum[0] += packet[2 + i]; sum[1] += sum[0]; } packet[packetlen - 2] = sum[0]; packet[packetlen - 1] = sum[1]; } count = write(fd, packet, packetlen); if (count != packetlen) res = -3; free(packet); return res; } omhacks-0.16/omhacks/screen.h0000644000175000017500000000647111462027257015140 0ustar lindilindi#ifndef OMHACKS_SCREEN_H #define OMHACKS_SCREEN_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Read screen brightness. * * If the result is negative, then an error happened. */ int om_screen_brightness_get(); /* * Read the maximum allowed brightness value * * If the result is negative, then an error happened. */ int om_screen_brightness_get_max(); /* Set screen brightness */ int om_screen_brightness_set(int val); /* * Set screen brightness and read the old value * * If the result is negative, then an error happened. */ int om_screen_brightness_swap(int val); /* * Open the touchscreen input device. * * The result is a file descriptor that can be closed with a normal close() */ int om_touchscreen_open(); /* * Lock the touchscreen input device */ int om_touchscreen_lock(int fd); /* * Unlock the touchscreen input device */ int om_touchscreen_unlock(int fd); /* * Return the power status of the display * * Returns 1 if on, 0 if off and a negative value in case of problems. */ int om_screen_power_get(); /* * Turn on/off the display. * * If value is true, turn on the screen. Else, turn it off. * * Note that Xorg and fso-frameworkd do not know how to read the power * status of the screen (frameworkd reads it on startup only). If Xorg * turns the screen and after that you turn the screen off with * omhacks then touching the screen won't turn the screen on (Xorg * thinks the screen is still on and does not bother to try to power * it on). */ int om_screen_power_set(int val); /* * Read current screen resolution * * Possible values are "normal" for 640x480 and "qvga-normal" for * 320x240. Return value is NULL on error. */ const char *om_screen_resolution_get(); /* * Set screen resolution * * Argument should be pointer to string describing the resolution. see * om_screen_resolution_get() for list of options. * * If the result is negative, then an error happened. */ int om_screen_resolution_set(const char *val); /* * Read timings of memory bus between the CPU and the glamo graphics * chip. Read "man om" for more information. * * Return value is either "4-4-4" or "2-4-2" on success and NULL on * failure. */ const char* om_screen_glamo_bus_timings_get(); /* * Set timings of the memory bus between the CPU and the glamo * graphics chip. Read "man om" for more information. * * The argument must be a string listed in om_screen_glamo_timings_get * above. * * If the result is negative, then an error happened. */ int om_screen_glamo_bus_timings_set(const char* val); #endif omhacks-0.16/omhacks/uevent.c0000644000175000017500000000452011312714715015147 0ustar lindilindi/* * uevent - Listen to uevent events * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "uevent.h" #include #include #include #include #include int om_uevent_open() { int sock, retval; struct sockaddr_nl snl; memset(&snl, 0x00, sizeof(struct sockaddr_nl)); snl.nl_family = AF_NETLINK; snl.nl_pid = getpid(); snl.nl_groups = 0xffffffff; sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); if (sock == -1) return sock; retval = bind(sock, (struct sockaddr *) &snl, sizeof(struct sockaddr_nl)); if (retval < 0) return retval; return sock; } int om_uevent_read(int sock, struct om_uevent* ou) { ssize_t buflen = recv(sock, ou, sizeof(ou->buffer), 0); if (buflen < 0) return -1; if ((size_t)buflen > sizeof(ou->buffer)-1) buflen = sizeof(ou->buffer)-1; ou->buflen = buflen; ou->buffer[buflen] = '\0'; return 0; } int om_uevent_parse(struct om_uevent* ou) { // See uevent_listen.c int i; /* Save start of payload */ size_t bufpos = strlen(ou->buffer) + 1; /* Split action string and sysfs path */ char* pos = strchr(ou->buffer, '@'); if (pos == NULL) return -1; pos[0] = '\0'; /* Action string */ ou->action = ou->buffer; /* Sysfs path */ ou->devpath = &pos[1]; /* Events have the environment attached - reconstruct envp[] */ for (i = 0; (bufpos < ou->buflen) && (i < OM_UEVENT_ENV_MAX - 1); ++i) { int keylen; char *key; key = &ou->buffer[bufpos]; keylen = strlen(key); ou->envp[i] = key; bufpos += keylen + 1; } ou->envp[i] = NULL; return 0; } omhacks-0.16/omhacks/usb.c0000644000175000017500000000504711515534033014435 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "usb.h" #include "sysfs.h" #include #include #include #include #include int om_usb_mode_get() { const char* usb_mode_path = om_sysfs_path("usb_mode"); if (usb_mode_path == NULL) return -3; const char *mode = om_sysfs_readfile(usb_mode_path); if (mode == NULL) return -1; if (!strcmp(mode, "device\n")) { return 0; } else if (!strcmp(mode, "host\n")) { return 1; } else { return -2; } } int om_usb_mode_set(int mode) { const char* usb_mode_path = om_sysfs_path("usb_mode"); if (usb_mode_path == NULL) return -3; if (mode == 0) { if (om_sysfs_writefile(usb_mode_path, "device\n") < 0) return -1; } else if (mode == 1) { if (om_sysfs_writefile(usb_mode_path, "host\n") < 0) return -1; } else { return -2; } return 0; } int om_usb_charger_mode_get() { const char* usb_charger_mode_path = om_sysfs_path("usb_charger_mode"); if (usb_charger_mode_path == NULL) return -2; const char *mode = om_sysfs_readfile(usb_charger_mode_path); if (mode == NULL) return -1; return atoi(mode); } int om_usb_charger_mode_set(int mode) { const char* usb_charger_mode_path = om_sysfs_path("usb_charger_mode"); if (usb_charger_mode_path == NULL) return -2; if (om_sysfs_writefile(usb_charger_mode_path, mode ? "1\n" : "0\n") < 0) return -1; return 0; } int om_usb_charger_limit_get() { const char* res = om_sysfs_get("usb_curlim"); if (res == NULL) return -1; return atoi(res); } int om_usb_charger_limit_set(int limit) { char buf[128]; snprintf(buf, sizeof(buf), "%d\n", limit); return om_sysfs_set("usb_curlim", buf) == 0 ? 0 : -1; } omhacks-0.16/omhacks/led.c0000644000175000017500000001221011406356565014411 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "led.h" #include "sysfs.h" #include #include #include #include #include #include #include #include #include static int om_led_exists(const char *name) { char buf[PATH_MAX]; if (snprintf(buf, PATH_MAX, "/sys/class/leds/%s", name) >= PATH_MAX) return 0; return access(buf, F_OK) == 0; } static const char* om_led_lookup(const char* alias) { if (strcmp(alias, "vibrator") == 0) { if (om_led_exists("neo1973:vibrator")) return "neo1973:vibrator"; if (om_led_exists("gta02::vibrator")) return "gta02::vibrator"; } else if (strcmp(alias, "power_orange") == 0) { if (om_led_exists("gta02-power:orange")) return "gta02-power:orange"; if (om_led_exists("gta02:orange:power")) return "gta02:orange:power"; } else if (strcmp(alias, "power_blue") == 0) { if (om_led_exists("gta02-power:blue")) return "gta02-power:blue"; if (om_led_exists("gta02:blue:power")) return "gta02:blue:power"; } else if (strcmp(alias, "aux_red") == 0) { if (om_led_exists("gta02-aux:red")) return "gta02-aux:red"; if (om_led_exists("gta02:red:aux")) return "gta02:red:aux"; } return NULL; } int om_led_init(struct om_led* led, const char* name) { const char* kernel_name = om_led_lookup(name); if (kernel_name != NULL) name = kernel_name; if (strchr(name, '/') != NULL) { errno = EINVAL; return -1; } strncpy(led->name, name, 254); led->name[254] = 0; led->dir = (char*)malloc(PATH_MAX); if (led->dir == NULL) return -1; led->dir_len = snprintf(led->dir, PATH_MAX, "/sys/class/leds/%s/", name); //led->dir_len = snprintf(led->dir, PATH_MAX, "/tmp/%s/", name); if (access(led->dir, F_OK) != 0) { free(led->dir); return -1; } strcpy(led->trigger, "none"); led->brightness = led->delay_on = led->delay_off = 0; return 0; } int om_led_init_copy(struct om_led* dstled, const struct om_led* srcled) { dstled->dir = (char*)malloc(PATH_MAX); if (dstled->dir == NULL) return -1; strcpy(dstled->dir, srcled->dir); strncpy(dstled->name, srcled->name, 254); dstled->name[254] = 0; dstled->dir_len = srcled->dir_len; strcpy(dstled->trigger, srcled->trigger); dstled->brightness = srcled->brightness; dstled->delay_on = srcled->delay_on; dstled->delay_off = srcled->delay_off; return 0; } static const char* led_get(struct om_led* led, const char* param) { strncpy(led->dir + led->dir_len, param, PATH_MAX - led->dir_len); led->dir[PATH_MAX-1] = 0; return om_sysfs_readfile(led->dir); } static int led_set(struct om_led* led, const char* param, const char* val) { strncpy(led->dir + led->dir_len, param, PATH_MAX - led->dir_len); led->dir[PATH_MAX-1] = 0; return om_sysfs_writefile(led->dir, val); } static int led_read_current_trigger(struct om_led* led) { const char* trigger = led_get(led, "trigger"); int s, t, copy = 0; if (trigger == NULL) return -1; for (s = t = 0; trigger[s] != 0 && trigger[s] != '\n' && t < 254; ++s) { switch (trigger[s]) { case '[': copy = 1; break; case ']': copy = 0; break; default: if (copy) led->trigger[t++] = trigger[s]; break; } } if (t == 0) strcpy(led->trigger, "none"); else led->trigger[t] = 0; return 0; } int om_led_get(struct om_led* led) { const char* res; if ((res = led_get(led, "brightness")) == NULL) return -1; led->brightness = atoi(res); if (led_read_current_trigger(led) != 0) return -1; if (strcmp(led->trigger, "timer") == 0) { if ((res = led_get(led, "delay_on")) == NULL) return -1; led->delay_on = atoi(res); if ((res = led_get(led, "delay_off")) == NULL) return -1; led->delay_off = atoi(res); } else { led->delay_on = led->delay_off = 0; } if (strcmp(led->trigger, "none") != 0 && led->brightness == 0) led->brightness = 255; return 0; } int om_led_set(struct om_led* led) { char val[30]; snprintf(val, 30, "%d\n", led->brightness); if (led_set(led, "brightness", val) != 0) return -1; snprintf(val, 30, "%s\n", led->trigger); if (led_set(led, "trigger", val) != 0) return -1; if (strcmp(led->trigger, "timer") == 0) { snprintf(val, 30, "%d\n", led->delay_on); if (led_set(led, "delay_on", val) != 0) return -1; snprintf(val, 30, "%d\n", led->delay_off); if (led_set(led, "delay_off", val) != 0) return -1; } return 0; } omhacks-0.16/omhacks/CMakeLists.txt0000644000175000017500000000160211537707512016241 0ustar lindilindiinclude_directories(..) file(GLOB ohsrc *.c) file(GLOB ohhdr *.h) add_definitions(-Wall -Werror) add_library(omhacks SHARED ${ohsrc}) add_library(omhacks-static STATIC ${ohsrc}) set_target_properties(omhacks PROPERTIES VERSION ${omhacks_version} SOVERSION 0 CLEAN_DIRECT_OUTPUT 1) set_target_properties(omhacks-static PROPERTIES VERSION ${omhacks_version} SOVERSION 0 OUTPUT_NAME "omhacks" CLEAN_DIRECT_OUTPUT 1) set(prefix "${CMAKE_INSTALL_PREFIX}") set(exec_prefix "${prefix}/bin") set(libdir "${prefix}/lib") set(includedir "${prefix}/include") configure_file(${omhacks_SOURCE_DIR}/omhacks/libomhacks.pc.in ${omhacks_BINARY_DIR}/omhacks/libomhacks.pc @ONLY) install(TARGETS omhacks omhacks-static LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(FILES ${ohhdr} DESTINATION include/omhacks) install(FILES ${omhacks_BINARY_DIR}/omhacks/libomhacks.pc DESTINATION lib/pkgconfig) omhacks-0.16/omhacks/battery.h0000644000175000017500000000473411321073575015331 0ustar lindilindi#ifndef OMHACKS_BATTERY_H #define OMHACKS_BATTERY_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Read temperature of battery (in celsius degrees) * * Writes result to supplied pointer. Returns zero on success and * negative on error. */ int om_battery_temperature_get(float *temperature); /* * Read battery energy percentage. * * Returns 0-100 on success and negative on error. */ int om_battery_energy_get(); /* * Read battery consumption. * * Writes battery current in microamperes is to supplied * pointer. Negative current means that battery is being * charged. Return value is zero on success and negative on error. */ int om_battery_consumption_get(int *consumption); /* * Read battery charger current limit. * * Returns battery charger current limit in milliamperes or negative value on error. * */ int om_battery_charger_limit_get(void); /* * Set battery charger current limit. * * Normally usb charger limit and battery charger limit have the same * value. However, sometimes it is useful to charger battery very * slowly or not at all and still power rest of the system from * USB. This allows one for example to keep battery at its recommended * storage capacity of 40% without having to physically remove the * battery. * * Note that kernel will round the limit to nearest suitable value * which is usually a few milliamperes lower than the supplied limit. * * Also note that changing usb charger limit will reset also this * battery charger limit to the same value so you must first set usb * charger limit and only then battery charger limit. * * Returns 0 on success and negative value on failure. */ int om_battery_charger_limit_set(int limit); #endif omhacks-0.16/omhacks/sysfs.c0000644000175000017500000003114611613510225015006 0ustar lindilindi/* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "sysfs.h" #include #include #include #include #include #include #include #include #include struct om_sysfs_name { const char* name; const char* (*scanner)(void); const char* cached_value; }; static int exists(const char* fname) { return access(fname, F_OK) == 0; } static const char* scan_battery() { // TODO sys_battery=`find /sys -wholename "*/power_supply/battery" -o -wholename "*/power_supply/bat" -type d` if (exists("/sys/class/power_supply/battery")) return "/sys/class/power_supply/battery"; if (exists("/sys/class/power_supply/bat")) return "/sys/class/power_supply/bat"; return NULL; } static const char* scan_brightness() { // TODO sys_brightness=\"$(find /sys -wholename "*backlight*/brightness")\" if (exists("/sys/class/backlight/gta02-bl/brightness")) return "/sys/class/backlight/gta02-bl/brightness"; if (exists("/sys/devices/virtual/backlight/acpi_video0/brightness")) return "/sys/devices/virtual/backlight/acpi_video0/brightness"; if (exists("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight.0/backlight/pcf50633-backlight/brightness")) return "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight.0/backlight/pcf50633-backlight/brightness"; if (exists("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight/backlight/pcf50633-backlight/brightness")) return "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight/backlight/pcf50633-backlight/brightness"; return NULL; } static const char* scan_max_brightness() { // TODO sys_brightness=\"$(find /sys -wholename "*backlight*/brightness")\" if (exists("/sys/class/backlight/gta02-bl/max_brightness")) return "/sys/class/backlight/gta02-bl/max_brightness"; if (exists("/sys/devices/virtual/backlight/acpi_video0/max_brightness")) return "/sys/devices/virtual/backlight/acpi_video0/max_brightness"; if (exists("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight.0/backlight/pcf50633-backlight/max_brightness")) return "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight.0/backlight/pcf50633-backlight/max_brightness"; if (exists("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight/backlight/pcf50633-backlight/max_brightness")) return "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight/backlight/pcf50633-backlight/max_brightness"; return NULL; } static const char* scan_actual_brightness() { if (exists("/sys/class/backlight/gta02-bl/actual_brightness")) return "/sys/class/backlight/gta02-bl/actual_brightness"; if (exists("/sys/devices/virtual/backlight/acpi_video0/actual_brightness")) return "/sys/devices/virtual/backlight/acpi_video0/actual_brightness"; if (exists("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight.0/backlight/pcf50633-backlight/actual_brightness")) return "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight.0/backlight/pcf50633-backlight/actual_brightness"; if (exists("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight/backlight/pcf50633-backlight/actual_brightness")) return "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-backlight/backlight/pcf50633-backlight/actual_brightness"; return NULL; } static const char* scan_chg_curlim() { if (exists("/sys/class/i2c-adapter/i2c-0/0-0073/pcf50633-mbc/chg_curlim")) return "/sys/class/i2c-adapter/i2c-0/0-0073/pcf50633-mbc/chg_curlim"; if (exists("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-mbc/chg_curlim")) return "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-mbc/chg_curlim"; if (exists("/sys/bus/platform/devices/pcf50633-mbc/chg_curlim")) return "/sys/bus/platform/devices/pcf50633-mbc/chg_curlim"; if (exists("/sys/bus/platform/devices/pcf50633-mbc.0/chg_curlim")) return "/sys/bus/platform/devices/pcf50633-mbc.0/chg_curlim"; return NULL; } static const char* scan_usb_curlim() { if (exists("/sys/class/i2c-adapter/i2c-0/0-0073/pcf50633-mbc/usb_curlim")) return "/sys/class/i2c-adapter/i2c-0/0-0073/pcf50633-mbc/usb_curlim"; if (exists("/sys/bus/platform/devices/pcf50633-mbc.0/usb_curlim")) return "/sys/bus/platform/devices/pcf50633-mbc.0/usb_curlim"; if (exists("/sys/bus/platform/devices/pcf50633-mbc/usb_curlim")) return "/sys/bus/platform/devices/pcf50633-mbc/usb_curlim"; return NULL; } static const char* scan_resume_reason() { // TODO return \"$(find /sys -wholename "*neo1973-resume.0/resume_reason")\" if (exists("/sys/class/i2c-adapter/i2c-0/0-0073/neo1973-resume.0/resume_reason")) return "/sys/class/i2c-adapter/i2c-0/0-0073/neo1973-resume.0/resume_reason"; if (exists("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/neo1973-resume.0/resume_reason")) return "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/neo1973-resume.0/resume_reason"; return NULL; } static const char* scan_resume_reason2() { // TODO return \"$(find /sys -wholename "*/0-0073/resume_reason")\" if (exists("/sys/class/i2c-adapter/i2c-0/0-0073/resume_reason")) return "/sys/class/i2c-adapter/i2c-0/0-0073/resume_reason"; if (exists("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/resume_reason")) return "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/resume_reason"; return NULL; } static const char* scan_pm_bt() { // TODO return \"$(find /sys -wholename "*pm-bt*/power_on" -o -wholename "*pm-bt*/pwron")\" if (exists("/sys/class/i2c-adapter/i2c-0/0-0073/pcf50633-regltr.6/neo1973-pm-bt.0")) return "/sys/class/i2c-adapter/i2c-0/0-0073/pcf50633-regltr.6/neo1973-pm-bt.0"; if (exists("/sys/devices/platform/gta02-pm-bt.0")) return "/sys/devices/platform/gta02-pm-bt.0"; return NULL; } static const char* scan_pm_gps() { // TODO return $(find /sys -wholename "*pm-gps*/power_on" -o -wholename "*pm-gps*/pwron") if (exists("/sys/class/i2c-adapter/i2c-0/0-0073/pcf50633-regltr.7/neo1973-pm-gps.0")) return "/sys/class/i2c-adapter/i2c-0/0-0073/pcf50633-regltr.7/neo1973-pm-gps.0"; if (exists("/sys/class/i2c-adapter/i2c-0/0-0073/pcf50633-regltr.7/gta02-pm-gps.0")) return "/sys/class/i2c-adapter/i2c-0/0-0073/pcf50633-regltr.7/gta02-pm-gps.0"; if (exists("/sys/devices/platform/gta02-pm-gps.0")) return "/sys/devices/platform/gta02-pm-gps.0"; return NULL; } static const char* scan_pm_gsm() { // TODO return $(find /sys -name neo1973-pm-gsm.0 -type d) // TODO sys_pm_gsm_power=\"$(find /sys -wholename "*pm-gsm*/power_on" -o -wholename "*pm-gsm*/pwron")\" if (exists("/sys/class/i2c-adapter/i2c-0/0-0073/neo1973-pm-gsm.0")) return "/sys/class/i2c-adapter/i2c-0/0-0073/neo1973-pm-gsm.0"; if (exists("/sys/class/i2c-adapter/i2c-0/0-0073/gta02-pm-gsm.0")) return "/sys/class/i2c-adapter/i2c-0/0-0073/gta02-pm-gsm.0"; if (exists("/sys/bus/platform/devices/gta02-pm-gsm.0")) return "/sys/bus/platform/devices/gta02-pm-gsm.0"; return NULL; } static const char* scan_pm_wlan() { // TODO sys_pm_wlan=\"$(find /sys -wholename "*gta02-pm-wlan/gta02-pm-wlan.0")\" if (exists("/sys/bus/platform/drivers/gta02-pm-wlan/gta02-pm-wlan.0")) return "/sys/bus/platform/drivers/gta02-pm-wlan/gta02-pm-wlan.0"; return NULL; } static const char* scan_screen_resolution() { if (exists("/sys/devices/platform/s3c2440-i2c/i2c-adapter/i2c-0/0-0073/pcf50633-regltr.9/glamo3362.0/glamo-spi-gpio.0/spi2.0/state")) return "/sys/devices/platform/s3c2440-i2c/i2c-adapter/i2c-0/0-0073/pcf50633-regltr.9/glamo3362.0/glamo-spi-gpio.0/spi2.0/state"; return NULL; } static const char* scan_screen_resolution2() { if (exists("/sys/class/lcd/jbt6k74-lcd/device/resolution")) return "/sys/class/lcd/jbt6k74-lcd/device/resolution"; return NULL; } static const char* scan_usb_charger_mode() { if (exists("/sys/class/i2c-adapter/i2c-0/0-0073/neo1973-pm-host.0/hostmode")) return "/sys/class/i2c-adapter/i2c-0/0-0073/neo1973-pm-host.0/hostmode"; if (exists("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on")) return "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on"; if (exists("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio.0/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on")) return "/sys/devices/platform/s3c2440-i2c/i2c-0/0-0073/pcf50633-gpio.0/reg-fixed-voltage.2/gta02-pm-usbhost.0/power_on"; return NULL; } static const char* scan_usb_mode() { // TODO sys_usb_mode=\"$(find /sys -name usb_mode)\" if (exists("/sys/devices/platform/s3c-ohci/usb_mode")) return "/sys/devices/platform/s3c-ohci/usb_mode"; if (exists("/sys/devices/platform/s3c2410-ohci/usb_mode")) return "/sys/devices/platform/s3c2410-ohci/usb_mode"; return NULL; } static const char* scan_wifi_root() { if (exists("/sys/bus/platform/drivers/s3c2440-sdi")) return "/sys/bus/platform/drivers/s3c2440-sdi"; if (exists("/sys/bus/platform/drivers/s3c-sdi")) return "/sys/bus/platform/drivers/s3c-sdi"; return NULL; } static struct om_sysfs_name om_sysfs_names[] = { { "actual_brightness", scan_actual_brightness, NULL }, { "battery", scan_battery, NULL }, { "brightness", scan_brightness, NULL }, { "chg_curlim", scan_chg_curlim, NULL }, { "max_brightness", scan_max_brightness, NULL }, // TODO sys_force_usb_limit_dangerous=\"$(find /sys -name force_usb_limit_dangerous -o -name usb_curlim)\" // TODO sys_hostmode=\"$(find /sys -name hostmode)\" { "pm-bt", scan_pm_bt, NULL }, { "pm-gps", scan_pm_gps, NULL }, { "pm-gsm", scan_pm_gsm, NULL }, { "pm-wlan", scan_pm_wlan, NULL }, { "resume_reason", scan_resume_reason, NULL }, { "resume_reason2", scan_resume_reason2, NULL }, { "screen_resolution", scan_screen_resolution, NULL }, { "screen_resolution2", scan_screen_resolution2, NULL }, { "usb_charger_mode", scan_usb_charger_mode, NULL }, { "usb_curlim", scan_usb_curlim, NULL }, { "usb_mode", scan_usb_mode, NULL }, { "wifi_root", scan_wifi_root, NULL }, }; static const int om_sysfs_names_size = sizeof(om_sysfs_names) / sizeof(om_sysfs_names[0]); static struct om_sysfs_name* om_sysfs_find_name(const char* name) { int begin, end; /* Binary search */ begin = -1, end = om_sysfs_names_size; while (end - begin > 1) { int cur = (end + begin) / 2; if (strcmp(om_sysfs_names[cur].name, name) > 0) end = cur; else begin = cur; } if (begin == -1 || strcmp(om_sysfs_names[begin].name, name) != 0) return NULL; else return &om_sysfs_names[begin]; } const char* om_sysfs_path(const char* name) { struct om_sysfs_name* n = om_sysfs_find_name(name); if (n == NULL) return NULL; if (n->cached_value == NULL) n->cached_value = n->scanner(); return n->cached_value; } const char* om_sysfs_readfile(const char* pathname) { static char buf[1024]; const char* res = NULL; ssize_t count; int fd = -1; fd = open(pathname, O_RDONLY); if (fd < 0) return NULL; count = read(fd, buf, 1023); if (count < 0) goto cleanup; buf[count] = 0; res = buf; cleanup: if (fd >= 0) close(fd); return res; } int om_sysfs_writefile(const char* pathname, const char* str) { int res = 0; size_t ssize = strlen(str); ssize_t count; int fd = -1; fd = open(pathname, O_WRONLY); if (fd < 0) return fd; count = write(fd, str, ssize); if (count != ssize) res = count; if (fd >= 0) close(fd); return res; } const char* om_sysfs_get(const char* name) { const char* path = om_sysfs_path(name); if (path == NULL) return NULL; return om_sysfs_readfile(path); } int om_sysfs_set(const char* name, const char* val) { const char* path = om_sysfs_path(name); if (path == NULL) return -1; return om_sysfs_writefile(path, val); } const char* om_sysfs_swap(const char* name, const char* val) { const char* path = om_sysfs_path(name); const char* res = NULL; if (path == NULL) return NULL; res = om_sysfs_readfile(path); if (om_sysfs_writefile(path, val) != 0) return NULL; return res; } omhacks-0.16/omhacks/sysfs.h0000644000175000017500000000376311515552332015025 0ustar lindilindi#ifndef OMHACKS_SYSFS_H #define OMHACKS_SYSFS_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Get the sysfs path of a useful file * * Returns a pointer to a string stored in read-only section, not * static buffer. Returns NULL on error. */ const char* om_sysfs_path(const char* name); /* * Read the contents of a sysfs file * * Note: the result is returned in a static buffer that will be overwritten by * following invocations. Returns NULL on error. */ const char* om_sysfs_get(const char* name); /* * Set a sysfs value * * Returns zero on success and a negative value on error. */ int om_sysfs_set(const char* name, const char* val); /* * Combination of set and set: return the old value and set a new one * Returns a negative value on error. */ const char* om_sysfs_swap(const char* name, const char* val); /* * Read the first 1024 bytes of the given file * * Note: the result is returned in a static buffer that will be overwritten by * following invocations. Returns NULL on error. */ const char* om_sysfs_readfile(const char* pathname); /* * Write a string to the given file * Returns a negative value on error. */ int om_sysfs_writefile(const char* pathname, const char* str); #endif omhacks-0.16/omhacks/bt.h0000644000175000017500000000263611302302200014236 0ustar lindilindi#ifndef OMHACKS_BT_H #define OMHACKS_BT_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Return the power status of the BlueTooth chip. * * Returns 1 if on, 0 if off, a negative value in case of problems. */ int om_bt_power_get(); /* * Turn on/off the BlueTooth chip * * If value is true, turn on the BlueTooth. Else, turn it off. */ int om_bt_power_set(int value); /* * Turn on/off the BlueTooth chip, and return the previous status. * * If value is true, turn on the BlueTooth. Else, turn it off. * * Returns 1 if on, 0 if off, a negative value in case of problems. */ int om_bt_power_swap(int value); #endif omhacks-0.16/omhacks/gps.h0000644000175000017500000000641311313752603014441 0ustar lindilindi#ifndef OMHACKS_GPS_H #define OMHACKS_GPS_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Return the power status of the GPS chip. * * Returns 1 if on, 0 if off, a negative value in case of problems. */ int om_gps_power_get(); /* * Turn on/off the GPS chip * * If value is true, turn on the GPS. Else, turn it off. */ int om_gps_power_set(int value); /* * Turn on/off the GPS chip, and return the previous status. * * If value is true, turn on the GPS. Else, turn it off. * * Returns 1 if on, 0 if off, a negative value in case of problems. */ int om_gps_power_swap(int value); /* * Return the keep_on_in_suspend status of the GPS chip. * * Returns 1 if on, 0 if off, a negative value in case of problems. */ int om_gps_keep_on_in_suspend_get(); /* * Turn on/off the keep_on_in_suspend bit on the GPS chip * * If value is true, GPS stays on during suspend. Else, it gets switched off. */ int om_gps_keep_on_in_suspend_set(int value); /* * Turn on/off the keep_on_in_suspend bit on the GPS chip, and return the * previous value. * * If value is true, GPS stays on during suspend. Else, it gets switched off. * * Returns 1 if on, 0 if off, a negative value in case of problems. */ int om_gps_keep_on_in_suspend_swap(int value); /* * Open a connection to the GPS chip. * * Returns a connection handle (file descriptor) or negative value on * error. */ int om_gps_open(void); /* * Close a connection to the GPS chip. * * The parameter should be a value returned by om_gps_open. */ void om_gps_close(int fd); /* * Send an arbitrary UBX packet to the GPS chip. * * @param fd handle returned by om_gps_open * @param klass UBX packet class * @param type UBX packet type * @param payload actual payload of the packet * @param payloadlen length of payload. * @return 0 on success and a negative value in case of problems. * * Please read "ANTARIS_Protocol_Specification(GPS.G3-X-03002).chm" to * understand the protocol. Here are examples of commands that are * tested to work: * * type class payload # description * 06 01 f0 01 00 # disable GPGLL messages * 06 01 f0 02 00 # disable GPGSA messages * 06 01 f0 03 00 # disable GPGSV messages * 06 01 f0 05 00 # disable GPGTG messages * 06 01 f0 08 00 # disable GPZDA messages * 06 08 fa 00 01 00 00 00 # report position 4 times/s * 06 08 f4 01 01 00 00 00 # report position 2 times/s * */ int om_gps_ubx_send(int fd, int klass, int type, const char *payload, int payloadlen); #endif omhacks-0.16/omhacks/led.h0000644000175000017500000000303011303205476014404 0ustar lindilindi#ifndef OMHACKS_LED_H #define OMHACKS_LED_H /* * omhacks - Various useful utility functions for the FreeRunner * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Led status information */ struct om_led { char name[255]; // Led name char* dir; // Cached led dir name int dir_len; // Cached length of dir string int brightness; // 0 if off char trigger[255]; // Trigger name int delay_on; // 0 if not blinking int delay_off; // 0 if not blinking }; /* Initialise an om_led structure */ int om_led_init(struct om_led* led, const char* name); /* Initialise an om_led structure with the contents of another one */ int om_led_init_copy(struct om_led* dstled, const struct om_led* srcled); /* Read led status */ int om_led_get(struct om_led* led); /* Set led status */ int om_led_set(struct om_led* led); #endif