[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[microblaze-uclinux] GPIOs



Hello,

I am not being able to write GPIOs from uClinux.

I am using an old program somebody wrote for this forum(source
attached).

My instance in mhs file is:

BEGIN opb_gpio
 PARAMETER INSTANCE = gpio_test
 PARAMETER HW_VER = 3.01.b
 PARAMETER C_IS_DUAL = 0
 PARAMETER C_GPIO_WIDTH = 2
 PARAMETER C_IS_BIDIR = 1
 PARAMETER C_BASEADDR = 0xFFFF6400
 PARAMETER C_HIGHADDR = 0xFFFF65FF
 BUS_INTERFACE SOPB = opb_v20_0
 PORT GPIO_IO = gpio_test_io
END

The entry on mss file is:

BEGIN DRIVER
 PARAMETER DRIVER_NAME = gpio
 PARAMETER DRIVER_VER = 2.11.a
 PARAMETER HW_INSTANCE = gpio_test
END

When booting kernel 2.4, gpios are there:
...
Starting kswapd
xgpio #0 at 0xFFFF5400 mapped to 0xFFFF5400
xgpio #1 at 0xFFFF6400 mapped to 0xFFFF6400
Xilinx GPIO registered
...

I use Xilinx tools 9.2, does anybody know if there are some problems
when
using the hw/sw versions I am using??

For the kernel 2.6 I guess I must rewrite the test program, looking at
the xgpio
driver: adapter.c, etc... Did it someone already?

Thanks a lot.

Raul Camaras. R&D Engineer.
Nokian Capacitors GmbH 
Zum Hussenstein 7
D-78642 Konstanz
Nr.: +49 7531 9189649. Handy: +49 151 17337921
Fax 07531/919574
www.nokiancapacitors.de
Geschäftsführer Ralf Jessler
Sitz Konstanz
Registergericht Amtsgericht Freiburg i.Br. HRB381566


-----Ursprüngliche Nachricht-----
Von: owner-microblaze-uclinux@xxxxxxxxxxxxxx
[mailto:owner-microblaze-uclinux@xxxxxxxxxxxxxx] Im Auftrag von
Haudebourg, Mickael (Silica)
Gesendet: Freitag, 1. Februar 2008 09:59
An: microblaze-uclinux@xxxxxxxxxxxxxx
Betreff: [microblaze-uclinux] USB HOST interface

Hi 

 I want to impelement a host USB with microblaze. 
What really supported in terms of drivers and Host ? 
I can not evalaute the difficulte to implement a driver ...

Best regrds 
mickael


-----Original Message-----
From: owner-microblaze-uclinux@xxxxxxxxxxxxxx
[mailto:owner-microblaze-uclinux@xxxxxxxxxxxxxx] On Behalf Of Dr. Johann
Pfefferl
Sent: vendredi 25 janvier 2008 11:53
To: microblaze-uclinux@xxxxxxxxxxxxxx
Subject: Re: [microblaze-uclinux] MDM UART support

Hello John,

yes you are right. It is not the best solution. But if you take a look
inside the function ulite_probe (file ./drivers/serial/uartlite.c) the
"id" number is simply used as an index into the "ports" array. Of course
it would be better to replace the static "ports" array by a dynamically
alocated linked list data structure.

For me it was only a quick and dirty hack to get the MDM uart running in
a system which also includes normal uartlite devices.

Regards,
  Hans

John Williams <jwilliams@xxxxxxxxxxxxxx> wrote:
> Hi Hans,
> 
> Dr. Johann Pfefferl wrote:
> > Hello,
> > 
> > in the macro XILINX_MDMUART_PLATFORM_INITIALISER the "id" field of 
> > the data structure must be set to a different value. For example
> > 
> > .id = (n+6)
> 
> Hmm, I wonder if it wouldn't be better instead for the uartlite driver

> itself to keep track of IDs handed out, and just increment them
itself.
>  Statically forcing a +N nmodifier is fragile, if anyone ever adds 
> more uartlite placeholders in thew platform init code, it will break.
> 
> What do you think?
> 
> John
> ___________________________
> microblaze-uclinux mailing list
> microblaze-uclinux@xxxxxxxxxxxxxx
> Project Home Page : 
> http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
> Mailing List Archive : 
> http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/

-- 
Dr. Johann Pfefferl   ------------   mailto j.pfefferl at eubus dot net
Eubus GmbH          http://www.eubus.net ++++ http://www.ebmhydraxc.com
Gollierstr. 70
D-80339 Muenchen
Phone: +49 (0)89 45 22 578-67     Fax: +49 (0)89 45 22 578-55
Registergericht Muenchen HRB 145 336, Ust-Id Nr. DE 225 783 933
Geschaeftsfuehrer: Volker Ulrich, Peter Sibities ==
 -o)   A computer program does what you tell it to do,
 /\\        not what you want it to do.               
_\_v-                                                 
___________________________
microblaze-uclinux mailing list
microblaze-uclinux@xxxxxxxxxxxxxx
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive :
http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/


___________________________
microblaze-uclinux mailing list
microblaze-uclinux@xxxxxxxxxxxxxx
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive :
http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/ibm_ocp_gpio.h>

static void
usage(char *argv0)
{
	char *basename = strrchr(argv0, '/');
	if (!basename)
		basename = argv0;

	fprintf(stderr,
		"Usage: %s [-d DEVICE] [-n DEV_INSTANCE] [-m MASK] COMMAND\n"
		"  where COMMAND is one of:\n"
		"    -i           Input value from GPIO and print it\n"
		"    -o VALUE     Output value to GPIO\n"
		"    -t VALUE     Set tristate to value\n"
		"    -c           Cylon test pattern\n"
		"    -k           KIT test pattern\n"
		"  DEVICE indicates which GPIO driver to talk to (default is /dev/gpio)\n"
		"  DEV_INSTANCE indicates which GPIO interface to talk to (default is zero)\n"
		"  MASK is ANDed with the value (default is all ones)\n"
		, basename);

	exit(2);
}

static const unsigned long cylon[] = {
	0x80000000, 0x40000000, 0x20000000, 0x10000000,
	0x08000000, 0x04000000, 0x02000000, 0x01000000,
	0x00800000, 0x00400000, 0x00200000, 0x00100000,
	0x00080000, 0x00040000, 0x00020000, 0x00010000,
	0x00008000, 0x00004000, 0x00002000, 0x00001000,
	0x00000800, 0x00000400, 0x00000200, 0x00000100,
	0x00000080, 0x00000040, 0x00000020, 0x00000010,
	0x00000008, 0x00000004, 0x00000002, 0x00000001,
		    0x00000002, 0x00000004, 0x00000008,
	0x00000010, 0x00000020, 0x00000040, 0x00000080,
	0x00000100, 0x00000200, 0x00000400, 0x00000800,
	0x00001000, 0x00002000, 0x00004000, 0x00008000,
	0x00010000, 0x00020000, 0x00040000, 0x00080000,
	0x00100000, 0x00200000, 0x00400000, 0x00800000,
	0x01000000, 0x02000000, 0x04000000, 0x08000000,
	0x10000000, 0x20000000, 0x40000000
};
static const unsigned long kit[] = {
	0x80000000, 0xc0000000,
	0xe0000000, 0x70000000, 0x38000000, 0x1c000000,
	0x0e000000, 0x07000000, 0x03800000, 0x01c00000,
	0x00e00000, 0x00700000, 0x00380000, 0x001c0000,
	0x000e0000, 0x00070000, 0x00038000, 0x0001c000,
	0x0000e000, 0x00007000, 0x00003800, 0x00001c00,
	0x00000e00, 0x00000700, 0x00000380, 0x000001c0,
	0x000000e0, 0x00000070, 0x00000038, 0x0000001c,
	0x0000000e, 0x00000007, 0x00000003, 0x00000001,
		    0x00000003, 0x00000007, 0x0000000e,
	0x0000001c, 0x00000038, 0x00000070, 0x000000e0,
	0x000001c0, 0x00000380, 0x00000700, 0x00000e00,
	0x00001c00, 0x00003800, 0x00007000, 0x0000e000,
	0x0001c000, 0x00038000, 0x00070000, 0x000e0000,
	0x001c0000, 0x00380000, 0x00700000, 0x00e00000,
	0x01c00000, 0x03800000, 0x07000000, 0x0e000000,
	0x1c000000, 0x38000000, 0x70000000, 0xe0000000,
	0xc0000000
};
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))

int
main(int argc, char **argv)
{
	extern char *optarg;
	char *cptr;
	enum { NONE, IN, OUT, TRISTATE, CYLON, KIT } operation = NONE;
	char *devfile = "/dev/gpio";
	struct ibm_gpio_ioctl_data ioctl_data;
	int i, fd;

	ioctl_data.device = 0;
	ioctl_data.data = 0;
	ioctl_data.mask = ~0;

	while ((i = getopt(argc, argv, "d:n:m:io:t:ck")) != EOF) {
		switch (i) {
		case 'd':
			devfile = optarg;
			break;
		case 'n':
			ioctl_data.device = strtoul(optarg, &cptr, 0);
			if (cptr == optarg)
				usage(argv[0]);
			break;
		case 'm':
			ioctl_data.mask = strtoul(optarg, &cptr, 0);
			if (cptr == optarg)
				usage(argv[0]);
			break;
		case 'i':
			operation = IN;
			break;
		case 'o':
			operation = OUT;
			ioctl_data.data = strtoul(optarg, &cptr, 0);
			if (cptr == optarg)
				usage(argv[0]);
			break;
		case 't':
			operation = TRISTATE;
			ioctl_data.data = strtoul(optarg, &cptr, 0);
			if (cptr == optarg)
				usage(argv[0]);
			break;
		case 'c':
			operation = CYLON;
			break;
		case 'k':
			operation = KIT;
			break;
		case '?':
			usage(argv[0]);
		}
	}

	if (optind < argc || operation == NONE) {
		usage(argv[0]);
	}

	if ((fd = open(devfile, O_RDWR)) == -1) {
		perror(devfile);
		exit(1);
	}

	switch (operation) {
	case IN:
		if (ioctl(fd, IBMGPIO_IN, &ioctl_data) == -1) {
			perror(devfile);
			exit(1);
		}
		printf("0x%08X\n", ioctl_data.data);
		break;
	case OUT:
		if (ioctl(fd, IBMGPIO_OUT, &ioctl_data) == -1) {
			perror(devfile);
			exit(1);
		}
		break;
	case TRISTATE:
		if (ioctl(fd, IBMGPIO_TRISTATE, &ioctl_data) == -1) {
			perror(devfile);
			exit(1);
		}
		break;
	case CYLON:
#define CYLON_DELAY_USECS (10000)
		for (;;) {
			for (i=0; i<ARRAY_SIZE(cylon); i++) {
				ioctl_data.data = cylon[i];
				if (ioctl(fd, IBMGPIO_OUT, &ioctl_data) == -1) {
					perror(devfile);
					exit(1);
				}
				usleep(CYLON_DELAY_USECS);
			}
		}
		break;
	case KIT:
#define KIT_DELAY_USECS (10000)
		ioctl_data.data = ~0UL;
		if (ioctl(fd, IBMGPIO_OUT, &ioctl_data) == -1) {
			perror(devfile);
			exit(1);
		}
		usleep(KIT_DELAY_USECS);
		for (;;) {
			for (i=0; i<ARRAY_SIZE(kit); i++) {
				ioctl_data.data = kit[i];
				if (ioctl(fd, IBMGPIO_OUT, &ioctl_data) == -1) {
					perror(devfile);
					exit(1);
				}
				usleep(KIT_DELAY_USECS);
			}
		}
		break;
	}
	close(fd);
	return 0;
}