public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* OSK5912 GPIO
@ 2007-11-16 11:59 Azhar Mr.
  2007-11-18  3:12 ` andrzej zaborowski
  0 siblings, 1 reply; 4+ messages in thread
From: Azhar Mr. @ 2007-11-16 11:59 UTC (permalink / raw)
  To: linux-omap-open-source

Hi,
   
  I AM WORKING ON OMAP5912 OSK.

I am writing a keyboard based gpio program to write a value '1' to the free gpio pin when a key was pressed.

For that I modified the gpio-switch.c program. I am using the up arrow
key which is mapped to gpio7. By pressing this key I am able to write 
a value '1' to the gpio pin 23.

At the shell prompt I am able to see a logic '1' value at gpio pin 23 with the following message

value of pin # 23 = 1
up (GPIO 7) is now disconnected


But through  the Cathode Ray Oscilloscope  I am unable to observe the GPIO pin 23 value as ‘1’. There is no change in the Oscilloscope.

Here is my gpio-switch code


#define OMAP_GPIO_SW_POLL_DELAY    10

#define LED_GPIO 23

const struct omap_gpio_switch_config omap_left_switch = {
    .name = "left",
    .type = OMAP_GPIO_SWITCH_TYPE_CONNECTION,
    .gpio = 6,
    .flags = OMAP_GPIO_SWITCH_FLAG_INVERTED,
    .key_code = KEY_LEFT
};

const struct omap_gpio_switch_config omap_enter_switch = {
    .name = "enter",
    .type = OMAP_GPIO_SWITCH_TYPE_CONNECTION,
    .gpio = 12,
    .flags = OMAP_GPIO_SWITCH_FLAG_INVERTED,
    .key_code = KEY_ENTER
};

const struct omap_gpio_switch_config omap_up_switch = {
    .name = "up",
    .type = OMAP_GPIO_SWITCH_TYPE_CONNECTION,
    .gpio = 7,
    .flags = OMAP_GPIO_SWITCH_FLAG_INVERTED,
    .key_code = KEY_UP
};

const struct omap_gpio_switch_config omap_down_switch = {
    .name = "down",
    .type = OMAP_GPIO_SWITCH_TYPE_CONNECTION,
    .gpio = 15,
    .flags = OMAP_GPIO_SWITCH_FLAG_INVERTED,
    .key_code = KEY_DOWN
};

const struct omap_gpio_switch_config *omap_switches[] = {
    &omap_left_switch,
    &omap_enter_switch,
    &omap_up_switch,
    &omap_down_switch,
    NULL              /* Guard */    
};

static void gpio_sw_handler(void *data)
{
    struct gpio_switch *sw = data;
    int state = gpio_sw_get_state(sw);

    if (sw->state == state)
          return;

    if (sw->type == OMAP_GPIO_SWITCH_TYPE_CONNECTION)
          kobject_uevent(&sw->pdev.dev.kobj, KOBJ_CHANGE,
                    &dev_attr_connection_switch.attr);
    else
          kobject_uevent(&sw->pdev.dev.kobj, KOBJ_CHANGE,
                    &dev_attr_cover_switch.attr);
    sw->state = state;
    input_report_key(&omap_sw_kp_dev, sw->key_code, state);
    
    /*** [START]: code for writing some value to GPIO 17 ***/

    if(sw->key_code==KEY_UP)
    {
          if(led_glow(sw))
              printk(KERN_ERR "led_glow:failed ");
    }    
    
    /*** [END]: code for writing some value to GPIO 17 ***/          

static int led_glow(struct gpio_switch *ctrlsw)
{
    /* requesting for LED_GPIO */
    if(omap_request_gpio(LED_GPIO)<0)
          return -1;
    
    /* setting LED_GPIO as output pin */
    omap_set_gpio_direction(LED_GPIO,0);

    /* writing to LED_GPIO the state of KEY_UP */
    omap_set_gpio_dataout(LED_GPIO,ctrlsw->state);

    /* printing the value of led_gpio pin */
    printk("value of pin # %d = %d\n",LED_GPIO,omap_get_gpio_datain(LED_GPIO));

    return 0;
    

}


please suggest where I had gone wrong.

With Regards
  Azharuddin, India

       
---------------------------------
 5, 50, 500, 5000 - Store N number of mails in your inbox. Click here.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: OSK5912 GPIO
  2007-11-16 11:59 OSK5912 GPIO Azhar Mr.
@ 2007-11-18  3:12 ` andrzej zaborowski
  0 siblings, 0 replies; 4+ messages in thread
From: andrzej zaborowski @ 2007-11-18  3:12 UTC (permalink / raw)
  To: Azhar Mr.; +Cc: linux-omap-open-source

On 16/11/2007, Azhar Mr. <shaik.azharuddin@yahoo.co.in> wrote:
> Hi,
>
>   I AM WORKING ON OMAP5912 OSK.
>
> I am writing a keyboard based gpio program to write a value '1' to the free gpio pin when a key was pressed.
>
> For that I modified the gpio-switch.c program. I am using the up arrow
> key which is mapped to gpio7. By pressing this key I am able to write
> a value '1' to the gpio pin 23.
>
> At the shell prompt I am able to see a logic '1' value at gpio pin 23 with the following message
>
> value of pin # 23 = 1
> up (GPIO 7) is now disconnected
>
>
> But through  the Cathode Ray Oscilloscope  I am unable to observe the GPIO pin 23 value as '1'. There is no change in the Oscilloscope.
>
> Here is my gpio-switch code
>
>
> #define OMAP_GPIO_SW_POLL_DELAY    10
>
> #define LED_GPIO 23
>
> const struct omap_gpio_switch_config omap_left_switch = {
>     .name = "left",
>     .type = OMAP_GPIO_SWITCH_TYPE_CONNECTION,
>     .gpio = 6,
>     .flags = OMAP_GPIO_SWITCH_FLAG_INVERTED,
>     .key_code = KEY_LEFT
> };
>
> const struct omap_gpio_switch_config omap_enter_switch = {
>     .name = "enter",
>     .type = OMAP_GPIO_SWITCH_TYPE_CONNECTION,
>     .gpio = 12,
>     .flags = OMAP_GPIO_SWITCH_FLAG_INVERTED,
>     .key_code = KEY_ENTER
> };
>
> const struct omap_gpio_switch_config omap_up_switch = {
>     .name = "up",
>     .type = OMAP_GPIO_SWITCH_TYPE_CONNECTION,
>     .gpio = 7,
>     .flags = OMAP_GPIO_SWITCH_FLAG_INVERTED,
>     .key_code = KEY_UP
> };
>
> const struct omap_gpio_switch_config omap_down_switch = {
>     .name = "down",
>     .type = OMAP_GPIO_SWITCH_TYPE_CONNECTION,
>     .gpio = 15,
>     .flags = OMAP_GPIO_SWITCH_FLAG_INVERTED,
>     .key_code = KEY_DOWN
> };
>
> const struct omap_gpio_switch_config *omap_switches[] = {
>     &omap_left_switch,
>     &omap_enter_switch,
>     &omap_up_switch,
>     &omap_down_switch,
>     NULL              /* Guard */
> };
>
> static void gpio_sw_handler(void *data)
> {
>     struct gpio_switch *sw = data;
>     int state = gpio_sw_get_state(sw);
>
>     if (sw->state == state)
>           return;
>
>     if (sw->type == OMAP_GPIO_SWITCH_TYPE_CONNECTION)
>           kobject_uevent(&sw->pdev.dev.kobj, KOBJ_CHANGE,
>                     &dev_attr_connection_switch.attr);
>     else
>           kobject_uevent(&sw->pdev.dev.kobj, KOBJ_CHANGE,
>                     &dev_attr_cover_switch.attr);
>     sw->state = state;
>     input_report_key(&omap_sw_kp_dev, sw->key_code, state);
>
>     /*** [START]: code for writing some value to GPIO 17 ***/
>
>     if(sw->key_code==KEY_UP)
>     {
>           if(led_glow(sw))
>               printk(KERN_ERR "led_glow:failed ");
>     }
>
>     /*** [END]: code for writing some value to GPIO 17 ***/
>
> static int led_glow(struct gpio_switch *ctrlsw)
> {
>     /* requesting for LED_GPIO */
>     if(omap_request_gpio(LED_GPIO)<0)
>           return -1;
>
>     /* setting LED_GPIO as output pin */
>     omap_set_gpio_direction(LED_GPIO,0);
>
>     /* writing to LED_GPIO the state of KEY_UP */
>     omap_set_gpio_dataout(LED_GPIO,ctrlsw->state);
>
>     /* printing the value of led_gpio pin */
>     printk("value of pin # %d = %d\n",LED_GPIO,omap_get_gpio_datain(LED_GPIO));
>
>     return 0;
>
>
> }

Generally it looks okay, but:

 - omap_request_gpio() and omap_set_gpio_direction() should only be
used once, in the initialisation, not on every key event.

 - omap_get_gpio_datain() should not be used with an output pin, only
for input pins. Otherwise the returned value may be false.

 - I don't know why the pin 23 stays low on your oscilloscope, but it
may be a multiplexing not set up on the pin. You may need to call
omap_cfg_reg() with some parameter, see if there is anything
concerning this pin in include/asm-arm/arch-omap/mux.h and in the
reference manual.

Regards

^ permalink raw reply	[flat|nested] 4+ messages in thread

* OSK5912 GPIO
@ 2007-11-20 13:20 Azhar Mr.
  2007-11-20 14:03 ` Daniel Stone
  0 siblings, 1 reply; 4+ messages in thread
From: Azhar Mr. @ 2007-11-20 13:20 UTC (permalink / raw)
  To: linux-omap-open-source

Dear all,

I AM WORKING ON OMAP5912 OSK

I am trying to write a simple GPIO program to change
the state of  a gpio pin.

For that I am using the gpio-switch.c located at
linux/arch/arm/plat-omap.

In the gpio-switch.c program I included the follwing
function

#define LED_GPIO 23

static int led_glow()
{
	/* requesting for LED_GPIO */
	
      if(omap_request_gpio(LED_GPIO)<0)
		return -1;
	
	/* setting LED_GPIO as output pin */
	omap_set_gpio_direction(LED_GPIO,0);

	/* writing to LED_GPIO the state of KEY_UP */

	omap_set_gpio_dataout(LED_GPIO,1);

	/* printing the value of led_gpio pin */
	
  printk("value of pin # %d =
%d\n",LED_GPIO,omap_get_gpio_datain(LED_GPIO));

	return 0;
	

}
 
I am calling the function "led_glow()" again in the
following function

static int __init gpio_sw_init(void)
{
	int r;

	printk(KERN_INFO "OMAP GPIO switch handler
initializing\n");

	r = driver_register(&gpio_sw_driver);
	if (r)
		return r;

	gpio_sw_platform_dev =
platform_device_register_simple("gpio-switch",
							       -1, NULL, 0);
	if (IS_ERR(gpio_sw_platform_dev)) {
		driver_unregister(&gpio_sw_driver);
		return PTR_ERR(gpio_sw_platform_dev);
	}

	r = add_atag_switches();
	if (r < 0) {
		platform_device_unregister(gpio_sw_platform_dev);
		driver_unregister(&gpio_sw_driver);
		gpio_sw_cleanup();
		return r;
	}

	report_initial_state();

	return 0;
        led_glow();
        
}
  
I complied and ported this to OSK5912

But I am getting neither the print statement nor the
response at the gpio pin 23 in the C.R.O. 

Even I changed the various gpio pins and tried I could
not see any response in the C.R.O

Please help me by an example code.


Regards

Azhar


      Bring your gang together - do your thing. Go to http://in.promos.yahoo.com/groups

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: OSK5912 GPIO
  2007-11-20 13:20 Azhar Mr.
@ 2007-11-20 14:03 ` Daniel Stone
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Stone @ 2007-11-20 14:03 UTC (permalink / raw)
  To: ext Azhar Mr.; +Cc: linux-omap-open-source

On Tue, Nov 20, 2007 at 01:20:34PM +0000, ext Azhar Mr. wrote:
> 	return 0;
>         led_glow();

'return' exits the function.  led_glow() will never be called.  I'd
recommend consulting some books on C (e.g. the C Programming Language by
Kernigan and Ritchie) before continuing much further, to be honest.

Cheers,
Daniel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-11-20 14:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-16 11:59 OSK5912 GPIO Azhar Mr.
2007-11-18  3:12 ` andrzej zaborowski
  -- strict thread matches above, loose matches on Subject: below --
2007-11-20 13:20 Azhar Mr.
2007-11-20 14:03 ` Daniel Stone

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox