Re: How to use mpc8xxx_gpio.c device driver

2010-08-18 Thread Ravi Gupta
Hi,

Thanks for all your replies. Now I want to enable interrupts on some GPIO
pins(GPIO pins number 224, 225, 226, 227, 228 and 229 i.e gpiochip224's pins
0 to 5). I configured these pins as input(GPIOF_IN) during gpio request. I
am able to request gpio pins successfully.

#define GPIO_CHIP0_BASE192
#define GPIO_CHIP0_COUNT   32

#define GPIO_CHIP1_BASE224
#define GPIO_CHIP1_COUNT   32

#define GPIO(chip, pin) (GPIO_CHIP##chip##_BASE + (pin))

/* Initial GPIO pins setting. */
static struct gpio gpio_pins[] = {
  { GPIO(1,  0), GPIOF_IN,Chip 1, Pin 0  },
  { GPIO(1,  1), GPIOF_IN,Chip 1, Pin 1  },
  { GPIO(1,  2), GPIOF_IN,Chip 1, Pin 2  },
  { GPIO(1,  3), GPIOF_IN,Chip 1, Pin 3  },
  { GPIO(1,  4), GPIOF_IN,Chip 1, Pin 4  },
  { GPIO(1,  5), GPIOF_IN,Chip 1, Pin 5  },
};

static __init int gpio_module_init(void)
{
  int err;
  dev_t devno = 0;

  printk(KERN_INFO GPIO Driver Version 0.1\n);

  /* resuest the gpio pin */
  err = gpio_request_array(gpio_pins, ARRAY_SIZE(gpio_pins));
  if (err) {
  printk(KERN_WARNING gpio: unable to request gpio pins\n);
  return -EBUSY;
  }

  /* register interrupts handlers */
  err = gpio_request_irq_array(gpio_irq_pins, ARRAY_SIZE(gpio_irq_pins));
  if (err) {
  printk(KERN_WARNING gpio: unable to register interrupt handler.\n);
  goto interrupt_fail;
  }
.
.
.
}

Now in order to enable interrupts I have to set the bits corresponding to
these pins in gpiochp Interrupt Mask Register.

My first question is that is there any gpio API call available for doing
this? OR I have to manually memory map the gpio IMR register and set bit
manually? For the time being I have manually set the IMR bit(using memory
map).

Second, in order to register an interrupt handler on a gpio pin, I need a
IRQ number, so how am I going to get that number? From the
Documentation/gpio.txt, it looks to me that gpio_to_irq() function should
give me the irq number, but when I tried to use it, it gives me an error.

#define GPIO_CHIP0_BASE192
#define GPIO_CHIP0_COUNT   32

#define GPIO_CHIP1_BASE224
#define GPIO_CHIP1_COUNT   32

#define GPIO(chip, pin) (GPIO_CHIP##chip##_BASE + (pin))

static struct gpio_irq gpio_irq_pins[] = {
  { GPIO(1, 0), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },
  { GPIO(1, 1), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },
  { GPIO(1, 2), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },
  { GPIO(1, 3), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },
  { GPIO(1, 4), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },
  { GPIO(1, 5), IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW },
};

int gpio_request_irq_array(struct gpio_irq *array, size_t num)
{
  int i, err, irq;

  for (i = 0; i  num; i++, array++) {
/* get the irq number corresponding to the gpio pin */
irq = gpio_to_irq(array-gpio);
if (irq  0) {
  printk(KERN_ERR gpio: Trying to get irq number for GPIO%d\n,
array-gpio);
  err = -EINVAL;
  goto err_free;
}
printd(gpio: irq number for GPIO%d = %d(i=%d)\n, array-gpio, irq, i);


/* set the irq type for the gpio pin */
err = set_irq_type(irq, array-type);
if (err)
  goto err_free;

/* register irq handler */
err = request_irq(irq, gpio_irq_handler, IRQF_SHARED, GPIO Driver,
NULL);
if (err) {
  printk(KERN_ERR gpio: can't get assigned irq for GPIO%d\n,
array-gpio);
  goto err_free;
}
  }
  return 0;

err_free:
  while (i--)
free_irq(gpio_to_irq((--array)-gpio), NULL);
  return err;
}

Given above is my driver code, I have implemented a function named
gpio_request_irq_array which works in same manner as that of
gpio_request_array. I am calling in the init function, see the init code
given initially. Now when I load it on my MPC837xERDB board, it gives the
following errors.

[ 1812.776420] GPIO Driver Version 0.1
[ 1812.779985] gpio: Trying to get irq number for GPIO224
[ 1812.785126] gpio: unable to register interrupt handler.
insmod: error inserting './gpio.ko': -1 Invalid parameters

Thanks in advance
Ravi Gupta
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: How to use mpc8xxx_gpio.c device driver

2010-08-13 Thread Ravi Gupta
On Wed, Aug 11, 2010 at 10:15 PM, Anton Vorontsov cbouatmai...@gmail.comwrote:

 Hi,

 On Wed, Aug 11, 2010 at 06:57:16PM +0530, Ravi Gupta wrote:
  I am new to device driver development. I am trying to access the GPIO of
  MPC837xERDB eval board. I have upgraded its kernel to linux-2.6.28.9 and
  enable support for mpc8xxx_gpio.c. On boot up, it successfully detect two
  gpio controllers. Now my question is how I am going to use it to
 communicate
  with the gpio pins? Do I have to modify the code in mpc8xxx_gpio.c file
 to
  do whatever I want to do with gpios or I can use the standard gpio API
  provided in kernel ( gpio_request()/gpio_free() ). I also tries the
 standard
  kernel API, but it fails. Here is my code :

 No, you don't have to modify anything, and yes, you can
 use standard kernel GPIO API.

  #include linux/module.h
  #include linux/errno.h  /* error codes */
  #include linux/gpio.h
 
  static __init int sample_module_init(void)
  {
int ret;
 
int i;
for (i=1; i32; i++) {
  ret = gpio_request(i, Sample Driver);

 Before issing gpio_request() you must get GPIO number from the
 of_get_gpio() or of_get_gpio_flags() calls (the _flags variant
 will also retreive flags such as 'active-low').

 The calls assume that you have gpio =  specifier in the
 device tree, see arch/powerpc/boot/dts/mpc8377_rdb.dts's
 leds node as an example.

 As you want GPIO LEDs, you can use drivers/leds/leds-gpio.c
 (see of_gpio_leds_probe() call, it gets gpio numbers via
 of_get_gpio_flags() and then requests them via gpio_request()).

 Also see

 Documentation/powerpc/dts-bindings/gpio/gpio.txt
 Documentation/powerpc/dts-bindings/gpio/led.txt

  if (ret) {
printk(KERN_WARNING sample_driver: unable to request GPIO_PG%d\n,
  i);
//return ret;
  }
}
 
return 0;
  }


 On Wed, Aug 11, 2010 at 07:49:40PM +0530, Ravi Gupta wrote:
  Also, when I try to export a gpio in sysfs
 
  echo 9  /sys/class/gpio/export

 The gpio numbers are global, i.e. GPIO controller base + GPIO
 number within the controller.

 [...]
  drwxr-xr-x3 root root0 Jan  1 00:00 gpiochip192

 So, if you want GPIO9 within gpiochip192, you should issue
 echo 201  export.

 Thanks,

 --
 Anton Vorontsov
 email: cbouatmai...@gmail.com
 irc://irc.freenode.net/bd2


Hi Anton,

Thanks for the reply.
I had added the entries for gpio pin 9 for both controllers(I was not sure
with controller's pin is connected to LED, but now I know it is pin no. 233
i.e 224+9) in the mpc8377_rdb.dts file. Below is a portion of my dts file, I
have attached the complete dts file as attachment.

i...@e000 {
#address-cells = 1;
#size-cells = 1;
device_type = soc;
compatible = simple-bus;
ranges = 0x0 0xe000 0x0010;
reg = 0xe000 0x0200;
bus-frequency = 0;

w...@200 {
device_type = watchdog;
compatible = mpc83xx_wdt;
reg = 0x200 0x100;
};

gpio1: gpio-control...@c00 {
#gpio-cells = 2;
compatible = fsl,mpc8377-gpio, fsl,mpc8349-gpio;
reg = 0xc00 0x100;
interrupts = 74 0x8;
interrupt-parent = ipic;
gpio-controller;
};

gpio2: gpio-control...@d00 {
#gpio-cells = 2;
compatible = fsl,mpc8377-gpio, fsl,mpc8349-gpio;
reg = 0xd00 0x100;
interrupts = 75 0x8;
interrupt-parent = ipic;
gpio-controller;
};

   * l...@0 {
compatible = gpio-leds;
label = hdd;
gpios = gpio1 9 0;
};

l...@1 {
compatible = gpio-leds;
label = rom;
gpios = gpio2 9 0;
};*
.
.
.
.
};


Also I have enabled drivers/leds/leds-gpio.c in my kernel. To test whether
the leds entires in dts file get attached to leds-gpio driver, I added
printks in the probe function of the driver.

static int gpio_led_probe(struct platform_device *pdev)
{
  struct gpio_led_platform_data *pdata = pdev-dev.platform_data;
  struct gpio_led *cur_led;
  struct gpio_led_data *leds_data, *led_dat;
  int i, ret = 0;

  *printk(KERN_INFO led: inside gpio_led_probe.\n);*

  
}

But I couldn't see led: inside gpio_led_probe. message in dmesg. I checked
sysfs and I can see entries of leds. Here is contents of sysfs on my
machine.

# ls /sys/devices/ -la
drwxr-xr-x7 root root0 Jan  1 01:58 .
drwxr-xr-x   12 root root0 Jan  1 00:00 ..
drwxr-xr-x   22 root root0 Jan  1 01:58 *e000.immr*
drwxr-xr-x5 root root0 Jan  1 01:58 e0005000.localbus
drwxr-xr-x4 root root0 Jan  1 01:58 pci:00
drwxr-xr-x9 root root0 Jan  1 01:58 platform
drwxr-xr-x8 root root0 Jan  1 01:58 system


# ls /sys/devices/e000.immr/
bus   e0004600.serial   *led1.0*
devspece0007000.spi   *led2.1*
e200.wdte00082a8.dma modalias

Re: How to use mpc8xxx_gpio.c device driver

2010-08-13 Thread Ravi Gupta
 Looking at the device tree for this board, it appears U-Boot remaps the
 IMMR registers to 0xe000. They are no longer accessible at
 0xff40.

 I would recommend studying arch/powerpc/boot/dts/mpc8377_rdb.dts in the
 Linux source code. That describes the device layout on your board after
 U-Boot has run.

 A wonderful tool for testing devices from userspace is busybox devmem.
 It allows you to poke any physical address with any value. The output of
 busybox devmem --help should get you started. As a quick example,
 busybox devmem 0xec00 w 0x1 will write the 32-bit value 0x1 to
 address 0xec00.

 I would also recommend using the built-in Linux GPIO API. It works, you
 just need to figure out how to use it. It will be much easier to get
 your code upstream if you use the provided APIs.

 The Documentation/gpio.txt file should help you in understanding the
 in-kernel Linux GPIO API. I'm afraid I don't have much experience other
 than accessing it via sysfs from userspace.

 Ira


Hi Ira,

Thanks for another great reply. Now I can also access gpio memory map
registers.

Thanks and Regards,
Ravi Gupta
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: How to use mpc8xxx_gpio.c device driver

2010-08-13 Thread Anton Vorontsov
Hi,

On Fri, Aug 13, 2010 at 03:29:11PM +0530, Ravi Gupta wrote:
[...]
 Thanks for the reply.
 I had added the entries for gpio pin 9 for both controllers(I was not sure
 with controller's pin is connected to LED, but now I know it is pin no. 233
 i.e 224+9) in the mpc8377_rdb.dts file. Below is a portion of my dts file, I
 have attached the complete dts file as attachment.
 
 i...@e000 {
[...]
* l...@0 {
 compatible = gpio-leds;
 label = hdd;
 gpios = gpio1 9 0;
 };

What kernel version you look at? Please see the latest kernel,
it has MCU GPIO LED nodes already, and you can just add some
additional nodes.

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/powerpc/boot/dts/mpc8377_rdb.dts#l490

[...]
 Also I have enabled drivers/leds/leds-gpio.c in my kernel. To test whether
 the leds entires in dts file get attached to leds-gpio driver, I added
 printks in the probe function of the driver.
 
 static int gpio_led_probe(struct platform_device *pdev)
 {
   struct gpio_led_platform_data *pdata = pdev-dev.platform_data;
   struct gpio_led *cur_led;
   struct gpio_led_data *leds_data, *led_dat;
   int i, ret = 0;
 
   *printk(KERN_INFO led: inside gpio_led_probe.\n);*

You have put the printk into the wrong function. It should
have been of_gpio_leds_probe():

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=drivers/leds/leds-gpio.c#l227

If you don't have that function then you use too old kernel.

Thanks,

-- 
Anton Vorontsov
email: cbouatmai...@gmail.com
irc://irc.freenode.net/bd2
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: How to use mpc8xxx_gpio.c device driver

2010-08-12 Thread Ravi Gupta
On Wed, Aug 11, 2010 at 9:45 PM, MJ embd mj.e...@gmail.com wrote:

 u can directly access GPIO registers in kernel, by ioremap of GPIO
 memory mapped registers.
 you might need to check
 - muxing of gpio

 -mj


Hi MJ,

Thanks for the reply.
I tried memory mapping but it fails, here is my code :

#include linux/module.h
#include linux/errno.h/* error codes */
#include linux/mm.h

void __iomem *ioaddr = NULL;

static __init int sample_module_init(void)
{
ioaddr = ioremap(0xFF400C00, 0x24);
if(ioaddr == NULL) {
printk(KERN_WARNING ioremap failed\n);
}
printk(KERN_WARNING ioremap successed\n);
printk(KERN_WARNING GP1DIR = %u\n, ioread32(ioaddr));
return 0;
}

static __exit void sample_module_exit(void)
{
iounmap(ioaddr);
}

MODULE_LICENSE(GPL);
module_init(sample_module_init);
module_exit(sample_module_exit);

As per the MPC8377ERDB data sheet default IMMRBAR address is 0xFF40_ and
offset of GPIO1 is 0C00 and each GPIO has programmable registers that occupy
24 bytes of memory-mapped space, so I mapped from 24bytes (0x18) starting
from 0xFF40_0C00 address. But when I tried to read the values from the
mapped memory I get the following errors. Is there something I am missing.
Any help with reference to MPC8377ERDB board will be highly appreciable.

# tftp -l ~/immrbar.ko -r immrbar.ko -g 10.20.50.70
# insmod ./immrbar.ko
[  717.825241] ioremap successed
[  717.849215] Machine check in kernel mode.
[  717.853220] Caused by (from SRR1=41000): Transfer error ack signal
[  717.859405] Oops: Machine check, sig: 7 [#1]
[  717.863668] MPC837x RDB
[  717.866106] Modules linked in: immrbar(+)
[  717.870119] NIP: 0900 LR: d1034054 CTR: c0014d50
[  717.875079] REGS: cf895d00 TRAP: 0200   Not tainted  (2.6.28.9)
[  717.880992] MSR: 00041000 ME  CR: 2482  XER: 2000
[  717.886578] TASK = cf8e8640[647] 'insmod' THREAD: cf894000
[  717.891882] GPR00: d103404c cf895db0 cf8e8640  23d5 
c01e
04f4 0002
[  717.900265] GPR08: 0001 c0383f3c 23d5 c0014d50 4c72ff56 10019100
1007
77e0 1007ea98
[  717.908650] GPR16: 10077834 100a 100a 100a bfaf4828 
1009
f23c 1cfc
[  717.917034] GPR24: 1d00 1d24 10012008 c03650e8  d1034000
1001
2018 d103
[  717.925598] NIP [0900] 0x900
[  717.928828] LR [d1034054] sample_module_init+0x54/0xc0 [immrbar]
[  717.934828] Call Trace:
[  717.937273] [cf895db0] [d103404c] sample_module_init+0x4c/0xc0 [immrbar]
(unr
eliable)
[  717.945115] [cf895dc0] [c00038a0] do_one_initcall+0x64/0x18c
[  717.950780] [cf895f20] [c004d7b8] sys_init_module+0xac/0x19c
[  717.956441] [cf895f40] [c00122f0] ret_from_syscall+0x0/0x38
[  717.962013] --- Exception: c01 at 0x48043f6c
[  717.962017] LR = 0x19cc
[  717.969407] Instruction dump:
[  717.972370]      
 XX
XX
[  717.980140]     7d5043a6 
 XX
XX
[  717.987919] ---[ end trace a47be794e2873cef ]---

Thanks in advance
Ravi Gupta
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: How to use mpc8xxx_gpio.c device driver

2010-08-12 Thread Ira W. Snyder
On Thu, Aug 12, 2010 at 03:55:49PM +0530, Ravi Gupta wrote:
 On Wed, Aug 11, 2010 at 9:45 PM, MJ embd mj.e...@gmail.com wrote:
 
  u can directly access GPIO registers in kernel, by ioremap of GPIO
  memory mapped registers.
  you might need to check
  - muxing of gpio
 
  -mj
 
 
 Hi MJ,
 
 Thanks for the reply.
 I tried memory mapping but it fails, here is my code :
 
 #include linux/module.h
 #include linux/errno.h/* error codes */
 #include linux/mm.h
 
 void __iomem *ioaddr = NULL;
 
 static __init int sample_module_init(void)
 {
 ioaddr = ioremap(0xFF400C00, 0x24);
 if(ioaddr == NULL) {
 printk(KERN_WARNING ioremap failed\n);
 }
 printk(KERN_WARNING ioremap successed\n);
 printk(KERN_WARNING GP1DIR = %u\n, ioread32(ioaddr));
 return 0;
 }
 
 static __exit void sample_module_exit(void)
 {
 iounmap(ioaddr);
 }
 
 MODULE_LICENSE(GPL);
 module_init(sample_module_init);
 module_exit(sample_module_exit);
 
 As per the MPC8377ERDB data sheet default IMMRBAR address is 0xFF40_ and
 offset of GPIO1 is 0C00 and each GPIO has programmable registers that occupy
 24 bytes of memory-mapped space, so I mapped from 24bytes (0x18) starting
 from 0xFF40_0C00 address. But when I tried to read the values from the
 mapped memory I get the following errors. Is there something I am missing.
 Any help with reference to MPC8377ERDB board will be highly appreciable.
 
 # tftp -l ~/immrbar.ko -r immrbar.ko -g 10.20.50.70
 # insmod ./immrbar.ko
 [  717.825241] ioremap successed
 [  717.849215] Machine check in kernel mode.
 [  717.853220] Caused by (from SRR1=41000): Transfer error ack signal
 [  717.859405] Oops: Machine check, sig: 7 [#1]
 [  717.863668] MPC837x RDB
 [  717.866106] Modules linked in: immrbar(+)
 [  717.870119] NIP: 0900 LR: d1034054 CTR: c0014d50
 [  717.875079] REGS: cf895d00 TRAP: 0200   Not tainted  (2.6.28.9)
 [  717.880992] MSR: 00041000 ME  CR: 2482  XER: 2000
 [  717.886578] TASK = cf8e8640[647] 'insmod' THREAD: cf894000
 [  717.891882] GPR00: d103404c cf895db0 cf8e8640  23d5 
 c01e
 04f4 0002
 [  717.900265] GPR08: 0001 c0383f3c 23d5 c0014d50 4c72ff56 10019100
 1007
 77e0 1007ea98
 [  717.908650] GPR16: 10077834 100a 100a 100a bfaf4828 
 1009
 f23c 1cfc
 [  717.917034] GPR24: 1d00 1d24 10012008 c03650e8  d1034000
 1001
 2018 d103
 [  717.925598] NIP [0900] 0x900
 [  717.928828] LR [d1034054] sample_module_init+0x54/0xc0 [immrbar]
 [  717.934828] Call Trace:
 [  717.937273] [cf895db0] [d103404c] sample_module_init+0x4c/0xc0 [immrbar]
 (unr
 eliable)
 [  717.945115] [cf895dc0] [c00038a0] do_one_initcall+0x64/0x18c
 [  717.950780] [cf895f20] [c004d7b8] sys_init_module+0xac/0x19c
 [  717.956441] [cf895f40] [c00122f0] ret_from_syscall+0x0/0x38
 [  717.962013] --- Exception: c01 at 0x48043f6c
 [  717.962017] LR = 0x19cc
 [  717.969407] Instruction dump:
 [  717.972370]      
  XX
 XX
 [  717.980140]     7d5043a6 
  XX
 XX
 [  717.987919] ---[ end trace a47be794e2873cef ]---
 

Looking at the device tree for this board, it appears U-Boot remaps the
IMMR registers to 0xe000. They are no longer accessible at
0xff40.

I would recommend studying arch/powerpc/boot/dts/mpc8377_rdb.dts in the
Linux source code. That describes the device layout on your board after
U-Boot has run.

A wonderful tool for testing devices from userspace is busybox devmem.
It allows you to poke any physical address with any value. The output of
busybox devmem --help should get you started. As a quick example,
busybox devmem 0xec00 w 0x1 will write the 32-bit value 0x1 to
address 0xec00.

I would also recommend using the built-in Linux GPIO API. It works, you
just need to figure out how to use it. It will be much easier to get
your code upstream if you use the provided APIs.

The Documentation/gpio.txt file should help you in understanding the
in-kernel Linux GPIO API. I'm afraid I don't have much experience other
than accessing it via sysfs from userspace.

Ira
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: How to use mpc8xxx_gpio.c device driver

2010-08-11 Thread MJ embd
u can directly access GPIO registers in kernel, by ioremap of GPIO
memory mapped registers.
you might need to check
- muxing of gpio

-mj

On Wed, Aug 11, 2010 at 6:57 PM, Ravi Gupta dceravigu...@gmail.com wrote:
 Hi,

 I am new to device driver development. I am trying to access the GPIO of
 MPC837xERDB eval board. I have upgraded its kernel to linux-2.6.28.9 and
 enable support for mpc8xxx_gpio.c. On boot up, it successfully detect two
 gpio controllers. Now my question is how I am going to use it to communicate
 with the gpio pins? Do I have to modify the code in mpc8xxx_gpio.c file to
 do whatever I want to do with gpios or I can use the standard gpio API
 provided in kernel ( gpio_request()/gpio_free() ). I also tries the standard
 kernel API, but it fails. Here is my code :

 #include linux/module.h
 #include linux/errno.h  /* error codes */
 #include linux/gpio.h

 static __init int sample_module_init(void)
 {
   int ret;

   int i;
   for (i=1; i32; i++) {
     ret = gpio_request(i, Sample Driver);
     if (ret) {
   printk(KERN_WARNING sample_driver: unable to request GPIO_PG%d\n,
 i);
   //return ret;
     }
   }

   return 0;
 }

 static __exit void sample_module_exit(void)
 {
   gpio_free(9);
 }

 MODULE_LICENSE(GPL);

 module_init(sample_module_init);
 module_exit(sample_module_exit);

 It give the following O/P:

 [  617.075329] sample_driver: unable to request GPIO_PG1
 [  617.080418] sample_driver: unable to request GPIO_PG2
 [  617.085470] sample_driver: unable to request GPIO_PG3
 [  617.090522] sample_driver: unable to request GPIO_PG4
 [  617.095574] sample_driver: unable to request GPIO_PG5
 [  617.100625] sample_driver: unable to request GPIO_PG6
 [  617.105676] sample_driver: unable to request GPIO_PG7
 [  617.110727] sample_driver: unable to request GPIO_PG8
 [  617.115779] sample_driver: unable to request GPIO_PG9
 [  617.120830] sample_driver: unable to request GPIO_PG10
 [  617.125968] sample_driver: unable to request GPIO_PG11
 [  617.131106] sample_driver: unable to request GPIO_PG12
 [  617.136245] sample_driver: unable to request GPIO_PG13
 [  617.141383] sample_driver: unable to request GPIO_PG14
 [  617.146521] sample_driver: unable to request GPIO_PG15
 [  617.151660] sample_driver: unable to request GPIO_PG16
 [  617.156798] sample_driver: unable to request GPIO_PG17
 [  617.161936] sample_driver: unable to request GPIO_PG18
 [  617.167074] sample_driver: unable to request GPIO_PG19
 [  617.172213] sample_driver: unable to request GPIO_PG20
 [  617.177351] sample_driver: unable to request GPIO_PG21
 [  617.182489] sample_driver: unable to request GPIO_PG22
 [  617.187628] sample_driver: unable to request GPIO_PG23
 [  617.192767] sample_driver: unable to request GPIO_PG24
 [  617.197905] sample_driver: unable to request GPIO_PG25
 [  617.203042] sample_driver: unable to request GPIO_PG26
 [  617.208182] sample_driver: unable to request GPIO_PG27
 [  617.213319] sample_driver: unable to request GPIO_PG28
 [  617.218458] sample_driver: unable to request GPIO_PG29
 [  617.223597] sample_driver: unable to request GPIO_PG30
 [  617.228735] sample_driver: unable to request GPIO_PG31
 [  617.233873] sample_driver: unable to request GPIO_PG32

 Can someone provide me a sample code or something else. Actually I am trying
 to set the GPIO pin no. 9 to active low as it is connected to a LED on
 board.

 Thanks in advance
 Ravi Gupta

 ___
 Linuxppc-dev mailing list
 Linuxppc-dev@lists.ozlabs.org
 https://lists.ozlabs.org/listinfo/linuxppc-dev




-- 
-mj
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: How to use mpc8xxx_gpio.c device driver

2010-08-11 Thread Ravi Gupta
Also, when I try to export a gpio in sysfs

echo 9  /sys/class/gpio/export

It gives me an error in dmesg
gpio_request: gpio-9 (sysfs) status -22
export_store: status -22

Here is a look of sysfs on my machine

# ls /sys/class/gpio/ -la
drwxr-xr-x4 root root0 Jan  1 00:00 .
drwxr-xr-x   24 root root0 Jan  1 00:00 ..
--w---1 root root 4096 Jan  1 00:10 export
drwxr-xr-x3 root root0 Jan  1 00:00 gpiochip192
drwxr-xr-x3 root root0 Jan  1 00:00 gpiochip224
--w---1 root root 4096 Jan  1 00:00 unexport
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: How to use mpc8xxx_gpio.c device driver

2010-08-11 Thread Anton Vorontsov
Hi,

On Wed, Aug 11, 2010 at 06:57:16PM +0530, Ravi Gupta wrote:
 I am new to device driver development. I am trying to access the GPIO of
 MPC837xERDB eval board. I have upgraded its kernel to linux-2.6.28.9 and
 enable support for mpc8xxx_gpio.c. On boot up, it successfully detect two
 gpio controllers. Now my question is how I am going to use it to communicate
 with the gpio pins? Do I have to modify the code in mpc8xxx_gpio.c file to
 do whatever I want to do with gpios or I can use the standard gpio API
 provided in kernel ( gpio_request()/gpio_free() ). I also tries the standard
 kernel API, but it fails. Here is my code :

No, you don't have to modify anything, and yes, you can
use standard kernel GPIO API.

 #include linux/module.h
 #include linux/errno.h  /* error codes */
 #include linux/gpio.h

 static __init int sample_module_init(void)
 {
   int ret;

   int i;
   for (i=1; i32; i++) {
 ret = gpio_request(i, Sample Driver);

Before issing gpio_request() you must get GPIO number from the
of_get_gpio() or of_get_gpio_flags() calls (the _flags variant
will also retreive flags such as 'active-low').

The calls assume that you have gpio =  specifier in the
device tree, see arch/powerpc/boot/dts/mpc8377_rdb.dts's
leds node as an example.

As you want GPIO LEDs, you can use drivers/leds/leds-gpio.c
(see of_gpio_leds_probe() call, it gets gpio numbers via
of_get_gpio_flags() and then requests them via gpio_request()).

Also see

Documentation/powerpc/dts-bindings/gpio/gpio.txt
Documentation/powerpc/dts-bindings/gpio/led.txt

 if (ret) {
   printk(KERN_WARNING sample_driver: unable to request GPIO_PG%d\n,
 i);
   //return ret;
 }
   }

   return 0;
 }


On Wed, Aug 11, 2010 at 07:49:40PM +0530, Ravi Gupta wrote:
 Also, when I try to export a gpio in sysfs
 
 echo 9  /sys/class/gpio/export

The gpio numbers are global, i.e. GPIO controller base + GPIO
number within the controller.

[...]
 drwxr-xr-x3 root root0 Jan  1 00:00 gpiochip192

So, if you want GPIO9 within gpiochip192, you should issue
echo 201  export.

Thanks,

-- 
Anton Vorontsov
email: cbouatmai...@gmail.com
irc://irc.freenode.net/bd2
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: How to use mpc8xxx_gpio.c device driver

2010-08-11 Thread Ira W. Snyder
On Wed, Aug 11, 2010 at 07:49:40PM +0530, Ravi Gupta wrote:
 Also, when I try to export a gpio in sysfs
 
 echo 9  /sys/class/gpio/export
 
 It gives me an error in dmesg
 gpio_request: gpio-9 (sysfs) status -22
 export_store: status -22
 
 Here is a look of sysfs on my machine
 
 # ls /sys/class/gpio/ -la
 drwxr-xr-x4 root root0 Jan  1 00:00 .
 drwxr-xr-x   24 root root0 Jan  1 00:00 ..
 --w---1 root root 4096 Jan  1 00:10 export
 drwxr-xr-x3 root root0 Jan  1 00:00 gpiochip192
 drwxr-xr-x3 root root0 Jan  1 00:00 gpiochip224
 --w---1 root root 4096 Jan  1 00:00 unexport


Your GPIO pins are numbered from 192-223 on one GPIO chip, and 224-255
on the next GPIO chip. You should be exporting GPIO pin 200 or 201
(192+8 or 192+9), depending on whether your pins are numbered from zero
or one.

status -22 is -EINVAL: Invalid Argument. You're doing something which
is invalid, so this makes sense. There is no pin 9.

Ira
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev