Index: firmware/export/config/samsungypr0.h =================================================================== --- firmware/export/config/samsungypr0.h (revision 31464) +++ firmware/export/config/samsungypr0.h (working copy) @@ -33,7 +33,6 @@ #define HAVE_LCD_COLOR /* define this if the LCD needs to be shutdown */ -/* TODO: Our framebuffer must be closed... */ #define HAVE_LCD_SHUTDOWN /* define this if you want album art for this target */ @@ -90,7 +89,6 @@ //#define HAVE_RTC_RAM /* define this if you have a real-time clock */ -//#define CONFIG_RTC APPLICATION #define CONFIG_RTC RTC_AS3514 #define HAVE_RTC_ALARM @@ -122,8 +120,7 @@ /* #define CONFIG_TUNER SI4700 */ /* #define HAVE_TUNER_PWR_CTRL*/ -/*TODO: In R0 there is an interrupt for this (figure out ioctls)*/ -/* #define HAVE_HEADPHONE_DETECTION */ +#define HAVE_HEADPHONE_DETECTION /* Define current usage levels. */ /* TODO: to be filled with correct values after implementing power management */ Index: firmware/SOURCES =================================================================== --- firmware/SOURCES (revision 31464) +++ firmware/SOURCES (working copy) @@ -82,6 +82,7 @@ #endif target/hosted/ypr0/ascodec-ypr0.c target/hosted/ypr0/powermgmt-ypr0.c +target/hosted/ypr0/gpio_ypr0.c #endif /* Maemo specific files */ Index: firmware/target/hosted/ypr0/button-ypr0.c =================================================================== --- firmware/target/hosted/ypr0/button-ypr0.c (revision 31464) +++ firmware/target/hosted/ypr0/button-ypr0.c (working copy) @@ -28,6 +28,7 @@ #include "kernel.h" #include "system.h" #include "button-target.h" +#include /* For headphones sense */ /* R0 physical key codes */ enum ypr0_buttons { @@ -45,6 +46,7 @@ static int r0_btn_fd = 0; + /* Samsung keypad driver doesn't allow multiple key combinations :( */ static enum ypr0_buttons r0_read_key(void) { @@ -82,6 +84,11 @@ return key_to_button(r0_read_key()); } +bool headphones_inserted(void) +{ + /* GPIO low - 0 - means headphones inserted */ + return (gpio_control(MXC_GET_GPIO_DATAIN, GPIO_HEADPHONE_SENSE) == 1) ? false : true; +} /* Open the keypad device: it is offered by r0Btn.ko module */ void button_init_device(void) @@ -89,6 +96,9 @@ r0_btn_fd = open("/dev/r0Btn", O_RDONLY); if (r0_btn_fd < 0) printf("/dev/r0Btn open error!"); + + /* As done in the OF...But it's not necessary (or is the ioctl that doesn't work :D) */ + gpio_control(MXC_SET_GPIO_DIRECTION_TO_INPUT, GPIO_HEADPHONE_SENSE); } #ifdef BUTTON_DRIVER_CLOSE Index: firmware/target/hosted/ypr0/button-target.h =================================================================== --- firmware/target/hosted/ypr0/button-target.h (revision 31464) +++ firmware/target/hosted/ypr0/button-target.h (working copy) @@ -5,7 +5,7 @@ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ - * $Id: button-target.h 29248 2011-02-08 20:05:25Z thomasjfox $ + * $Id$ * * Copyright (C) 2011 by Lorenzo Miori * @@ -25,6 +25,8 @@ #include #include "config.h" +bool headphones_inserted(void); + void button_init_device(void); void button_close_device(void); int button_read_device(void); Index: firmware/target/hosted/ypr0/gpio_ypr0.c =================================================================== --- firmware/target/hosted/ypr0/gpio_ypr0.c (revision 0) +++ firmware/target/hosted/ypr0/gpio_ypr0.c (revision 0) @@ -0,0 +1,53 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: ascodec-target.h 26116 2010-05-17 20:53:25Z funman $ + * + * Module wrapper for GPIO, using /dev/r0GPIO (r0Gpio.ko) of Samsung YP-R0 + * + * Copyright (c) 2011 Lorenzo Miori + * + * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include +#include +#include +#include + +static int r0_gpio_dev = 0; + +void gpio_init(void) +{ + /* to_be_removed ... Had to place the opening there, since otherwise rockbox seemed to be like freezed, if + * I put the file opening in the headphones_inserted function. Shouldn't we perhaps also take care about + * charger_inserted function? + * It seems that opening the device just one time it's a lot better for performances... + */ + r0_gpio_dev = open("/dev/r0GPIO", O_RDONLY); + if (r0_gpio_dev < 0) + printf("/dev/r0GPIO open error!"); +} + +void gpio_close(void) +{ + if (r0_gpio_dev < 0) + close(r0_gpio_dev); +} + +int gpio_control(int request, int pin) +{ + return ioctl(r0_gpio_dev, request, &pin); +} \ No newline at end of file Index: firmware/target/hosted/ypr0/system-ypr0.c =================================================================== --- firmware/target/hosted/ypr0/system-ypr0.c (revision 31464) +++ firmware/target/hosted/ypr0/system-ypr0.c (working copy) @@ -31,6 +31,7 @@ #endif #include "ascodec-target.h" +#include void sim_do_exit(void) { @@ -41,6 +42,7 @@ { /* Something that we need to do before exit on our platform YPR0 */ ascodec_close(); + gpio_close(); sim_do_exit(); } @@ -57,6 +59,7 @@ #endif /* Here begins our platform specific initilization for various things */ ascodec_init(); + gpio_init(); } Index: firmware/target/hosted/ypr0/gpio_ypr0.h =================================================================== --- firmware/target/hosted/ypr0/gpio_ypr0.h (revision 0) +++ firmware/target/hosted/ypr0/gpio_ypr0.h (revision 0) @@ -0,0 +1,57 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: ascodec-target.h 26116 2010-05-17 20:53:25Z funman $ + * + * Module wrapper for GPIO, using /dev/r0GPIO (r0Gpio.ko) of Samsung YP-R0 + * + * Copyright (c) 2011 Lorenzo Miori + * + * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef GPIO_YPR0_H +#define GPIO_YPR0_H + +/* Defines for the available ioctls for the device */ + +#define MXC_REQUEST_IOMUX 0x400C4700 +#define MXC_IOMUX_SET_PAD 0x400C4701 +#define MXC_FREE_IOMUX 0x400C4702 +#define MXC_SET_GPIO_DIRECTION_TO_OUTPUT 0x400C4703 +#define MXC_SET_GPIO_DIRECTION_TO_INPUT 0x400C4704 +#define MXC_SET_GPIO_DATAOUT_TO_1 0x400C4705 +#define MXC_SET_GPIO_DATAOUT_TO_0 0x400C4706 +/* The first appears to be 7 in IDA, but it's 8 in a reversed OF lib + Maybe, some IDs are to be switched by 1...CHECK THAT! +*/ +/* Perhaps this isn't used... */ +#define MXC_GET_GPIO_DATAIN_UNKNOWN 0x400C4707 +/* This one works fine */ +#define MXC_GET_GPIO_DATAIN 0x400C4708 + +/* Don't know if it is correct...*/ +#define PINS 145 + +/* Some meaningful pins that are used on R0 */ + +#define GPIO_HEADPHONE_SENSE 5 +#define GPIO_EXT_PWR_SENSE 26 +#define GPIO_SD_SENSE 59 + +void gpio_init(void); +void gpio_close(void); +int gpio_control(int request, int pin); + +#endif \ No newline at end of file