LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Grant Likely" <grant.likely@secretlab.ca>
To: "Bruno Monteiro" <bms.monteiro@gmail.com>
Cc: John Linn <John.Linn@xilinx.com>, linuxppc-embedded@ozlabs.org
Subject: Re: Compile program using XGpio
Date: Thu, 23 Oct 2008 11:46:21 -0600	[thread overview]
Message-ID: <fa686aa40810231046k783099d2gddec1dbbede86b7@mail.gmail.com> (raw)
In-Reply-To: <d43ae5a00810230958w147d810v363263ab55dc1550@mail.gmail.com>

On Thu, Oct 23, 2008 at 10:58 AM, Bruno Monteiro <bms.monteiro@gmail.com> wrote:
> Hi,
>
> I'm a new driver writer and i'm trying to understand how to deal with XGpio.
> My goal is writing a small piece of code that can turn leds on and off. I
> think this driver should do it:
>
>
> #include <linux/init.h>
> #include <linux/module.h>
>
> #include "xgpio.h"
> #include "xgpio_ioctl.h"
> #include "xparameters.h"
>
> XGpio led;
>
> static int myteste_init(void)
> {
>     XGpio_Initialize (&led, LEDs_4Bit);
>     XGpio_SetDataDirection(&led,1,0);
>     XGpio_DiscreteWrite(&led,1,0xf);
>     printk (KERN_ALERT "LEDS: Turn off\n");
>
>     return 0;
> }
>
> static int myteste_exit(void)
> {
>
>     XGpio_DiscreteWrite(&led,1,0x0);
>     printk (KERN_ALERT "LEDS: Turn on\n");
>     return 0;
> }
>
> module_init(myteste_init);
> module_exit(myteste_exit);
>
> But i have this error:
> ERROR: "XGpio_SetDataDirection" [drivers/char/mytest/mytest.ko] undefined!
> ERROR: "XGpio_Initialize" [drivers/char/mytest/mytest.ko] undefined!
> ERROR: "XGpio_DiscreteWrite" [drivers/char/mytest/mytest.ko] undefined!

None of the XGpio functions are available in Linux.  You need to use
the Linux kernel memory access functions instead (in_be32() and
out_be32()).

You also need to use the ioremap() function to map the physical
address of the GPIO block into a virtual address that the kernel can
use:

ie:
static int myteste_init(void)
{
    u32 __iomem *regs;

    regs = ioremap([address of GPIO block], 0x100);
    if (regs == NULL)
        return -ENOMEM;

    /* configure as output */
    out_be32(regs + 4, 0);
    /* turn on leds */
    out_be32(regs, 0);
    printk (KERN_ALERT "LEDS: Turn on\n");
    return 0;
}

This is just a simple example though.  You should follow the pattern
of other device drivers and bind against the of_platform_bus so your
device can be described in the device tree (.dts) file.

Or, better yet, use the existing driver from the Xilinx linux-2.6 git tree.

g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

  reply	other threads:[~2008-10-23 17:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-21 14:35 Compile program using XGpio Bruno Monteiro
2008-10-21 20:08 ` John Linn
2008-10-23 16:58   ` Bruno Monteiro
2008-10-23 17:46     ` Grant Likely [this message]
2008-10-23 17:58       ` John Linn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fa686aa40810231046k783099d2gddec1dbbede86b7@mail.gmail.com \
    --to=grant.likely@secretlab.ca \
    --cc=John.Linn@xilinx.com \
    --cc=bms.monteiro@gmail.com \
    --cc=linuxppc-embedded@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox