[Armadeus-commitlog] SF.net SVN: armadeus: [794] trunk/target/linux/modules
Brought to you by:
sszy
|
From: <Fa...@us...> - 2008-04-08 13:21:06
|
Revision: 794
http://armadeus.svn.sourceforge.net/armadeus/?rev=794&view=rev
Author: FabM
Date: 2008-04-08 06:21:01 -0700 (Tue, 08 Apr 2008)
Log Message:
-----------
[kernel][module] new fpgaregs, to read/write in 16bits on fpga driver+binary
Modified Paths:
--------------
trunk/target/linux/modules/Makefile
trunk/target/linux/modules/backlight/Makefile
trunk/target/linux/modules/fpga/Kconfig
trunk/target/linux/modules/fpga/Wb_button/button.c
trunk/target/linux/modules/fpga/Wb_button/button_specific.h
trunk/target/linux/modules/fpga/Wb_button/testbutton.c
trunk/target/linux/modules/gpio/Makefile
Added Paths:
-----------
trunk/target/linux/modules/fpga/fpgaaccess/
trunk/target/linux/modules/fpga/fpgaaccess/Kconfig
trunk/target/linux/modules/fpga/fpgaaccess/Makefile
trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.c
trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.h
trunk/target/linux/modules/fpga/fpgaaccess/fpgaregs.c
trunk/target/linux/modules/fpga/i2ctest/
trunk/target/linux/modules/fpga/i2ctest/Kconfig
trunk/target/linux/modules/fpga/i2ctest/Makefile
trunk/target/linux/modules/fpga/i2ctest/README
trunk/target/linux/modules/fpga/i2ctest/i2ctest.c
trunk/target/linux/modules/fpga/i2ctest/i2ctest.h
Modified: trunk/target/linux/modules/Makefile
===================================================================
--- trunk/target/linux/modules/Makefile 2008-04-05 09:12:51 UTC (rev 793)
+++ trunk/target/linux/modules/Makefile 2008-04-08 13:21:01 UTC (rev 794)
@@ -8,7 +8,8 @@
ifneq ($(KERNELRELEASE),)
obj-$(CONFIG_ARMADEUS_DRIVERS) += gpio/ pwm/ backlight/ isp1761/ \
- fpga/ps2keyboard/ fpga/keypad/ fpga/fpga_devtools/ fpga/Wb_led/ fpga/Wb_button/
+ fpga/ps2keyboard/ fpga/keypad/ fpga/fpga_devtools/ fpga/Wb_led/ fpga/Wb_button/ \
+ fpga/i2ctest/ fpga/fpgaaccess/
# Part execute when called from standard make in this directory:
else
Modified: trunk/target/linux/modules/backlight/Makefile
===================================================================
--- trunk/target/linux/modules/backlight/Makefile 2008-04-05 09:12:51 UTC (rev 793)
+++ trunk/target/linux/modules/backlight/Makefile 2008-04-08 13:21:01 UTC (rev 794)
@@ -20,7 +20,7 @@
BASE_DIR="../../../../buildroot/"
REL=`grep "BR2_PACKAGE_LINUX_VERSION=" $(BASE_DIR).config | \
sed "s/BR2_PACKAGE_LINUX_VERSION=\\"//" | sed "s/\\"//"`
-ARMADEUS_KERNEL_DIR=$(BASE_DIR)build_arm_nofpu/linux-$(REL)
+ARMADEUS_KERNEL_DIR=$(BASE_DIR)build_arm/linux-$(REL)
KDIR := $(ARMADEUS_KERNEL_DIR)
PWD := $(shell pwd)
Modified: trunk/target/linux/modules/fpga/Kconfig
===================================================================
--- trunk/target/linux/modules/fpga/Kconfig 2008-04-05 09:12:51 UTC (rev 793)
+++ trunk/target/linux/modules/fpga/Kconfig 2008-04-08 13:21:01 UTC (rev 794)
@@ -21,5 +21,9 @@
source "drivers/armadeus/fpga/Wb_button/Kconfig"
+source "drivers/armadeus/fpga/i2ctest/Kconfig"
+
+source "drivers/armadeus/fpga/fpgaaccess/Kconfig"
+
endmenu
Modified: trunk/target/linux/modules/fpga/Wb_button/button.c
===================================================================
--- trunk/target/linux/modules/fpga/Wb_button/button.c 2008-04-05 09:12:51 UTC (rev 793)
+++ trunk/target/linux/modules/fpga/Wb_button/button.c 2008-04-08 13:21:01 UTC (rev 794)
@@ -52,16 +52,17 @@
u16 data;
button_fpga_read(ldev->fpga_virtual_base_address + FPGA_IRQ_PEND,&data,ldev);
+ PDEBUG("Interrupt raised %x\n",data);
if(data&WB_BUTTON_IRQ){
- /* wake up reading process */
- if(ldev->reading)up(&ldev->sem);
- /* acknowledge irq_mngr */
- button_fpga_write(ldev->fpga_virtual_base_address + FPGA_IRQ_ACK,&data,ldev);
- }
- PDEBUG("Interrupt raised %x\n",data);
+ /* wake up reading process */
+ if(ldev->reading)up(&ldev->sem);
+ /* acknowledge irq_mngr */
+ button_fpga_write(ldev->fpga_virtual_base_address + FPGA_IRQ_ACK,&data,ldev);
+ return IRQ_HANDLED;
+ }else
+ return IRQ_NONE;
- return IRQ_HANDLED;
}
/***********************************
@@ -168,7 +169,7 @@
sdev->fpga_virtual_base_address = (void*)IMX_CS1_VIRT;
/* irq unmask */
- data=1;
+ data=1 | ioread16(sdev->fpga_virtual_base_address + FPGA_IRQ_MASK);
if((result=button_fpga_write(sdev->fpga_virtual_base_address + FPGA_IRQ_MASK,&data,sdev))<0)
goto error;
@@ -179,7 +180,7 @@
/* irq registering */
printk(KERN_INFO "button: fpga irq shared gpioa 1\n");
- if(request_irq(IRQ_GPIOA(1),(irq_handler_t)fpga_interrupt,IRQF_SHARED,FPGA_IRQ_NAME,sdev)<0){
+ if(request_irq(IRQ_GPIOA(1),(irq_handler_t)fpga_interrupt,IRQF_SHARED,BUTTON_IRQ_NAME,sdev)<0){
printk(KERN_ERR "Can't request fpga irq\n");
goto error;
}
@@ -203,7 +204,7 @@
static void free_all(void){
struct button_dev *sdev = buttondev;
-
+
/* free irq*/
free_irq(IRQ_GPIOA(1),sdev);
Modified: trunk/target/linux/modules/fpga/Wb_button/button_specific.h
===================================================================
--- trunk/target/linux/modules/fpga/Wb_button/button_specific.h 2008-04-05 09:12:51 UTC (rev 793)
+++ trunk/target/linux/modules/fpga/Wb_button/button_specific.h 2008-04-08 13:21:01 UTC (rev 794)
@@ -7,7 +7,7 @@
/* Fpga base address for led */
#define FPGA_BASE_ADDR IMX_CS1_PHYS
#define FPGA_MEM_SIZE IMX_CS1_SIZE
-#define FPGA_IRQ_NAME "fpga"
+#define BUTTON_IRQ_NAME "button"
/* interrupt position in irq_mngr */
#define WB_BUTTON_IRQ 0x0001
Modified: trunk/target/linux/modules/fpga/Wb_button/testbutton.c
===================================================================
--- trunk/target/linux/modules/fpga/Wb_button/testbutton.c 2008-04-05 09:12:51 UTC (rev 793)
+++ trunk/target/linux/modules/fpga/Wb_button/testbutton.c 2008-04-08 13:21:01 UTC (rev 794)
@@ -1,8 +1,36 @@
-/* a little program to test button driver
+
+ * ***********************************************************************
+/* a program to write/read values on fpga address map
* Fabien Marteau <fab...@ar...>
- * 7 march 2008
+ * 7 april 2008
+ * fpgaaccess.h
+ *
+ * (c) Copyright 2008 Armadeus project
+ * Fabien Marteau <fab...@ar...>
+ *
+ * A simple driver for reading and writing on
+ * fpga throught a character file /dev/fpgaaccess
+ *
+ * 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, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ **********************************************************************
*/
+
+ *
+ */
+
#include <stdio.h>
#include <stdlib.h>
Added: trunk/target/linux/modules/fpga/fpgaaccess/Kconfig
===================================================================
--- trunk/target/linux/modules/fpga/fpgaaccess/Kconfig (rev 0)
+++ trunk/target/linux/modules/fpga/fpgaaccess/Kconfig 2008-04-08 13:21:01 UTC (rev 794)
@@ -0,0 +1,8 @@
+#
+#
+
+config ARMADEUS_FPGAACCESS_DRIVER
+ tristate "fpgaaccess driver"
+ default n
+ depends on ARMADEUS_FPGA_DRIVERS
+ ---help---
Added: trunk/target/linux/modules/fpga/fpgaaccess/Makefile
===================================================================
--- trunk/target/linux/modules/fpga/fpgaaccess/Makefile (rev 0)
+++ trunk/target/linux/modules/fpga/fpgaaccess/Makefile 2008-04-08 13:21:01 UTC (rev 794)
@@ -0,0 +1,37 @@
+#
+# Makefile for the Armadeus Wb_led drivers
+#
+
+BASE_DIR="../../../../../buildroot/"
+
+REL=`grep "BR2_PACKAGE_LINUX_VERSION=" $(BASE_DIR).config | \
+ sed "s/BR2_PACKAGE_LINUX_VERSION=\\"//" | sed "s/\\"//"`
+
+ARMADEUS_KERNEL_DIR=$(BASE_DIR)build_arm/linux-$(REL)
+
+ifneq ($(KERNELRELEASE),)
+
+obj-$(CONFIG_ARMADEUS_FPGAACCESS_DRIVER) += fpgaaccess.o
+
+# Part executed when called from standard make in this directory:
+# (preferably use Makefile in parent directory)
+
+else
+KDIR := $(ARMADEUS_KERNEL_DIR)
+PWD := $(shell pwd)
+
+default:
+ $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
+ -cp fpgaaccess.ko /tftpboot/
+
+fpgaregs: fpgaregs.c
+ ~/armadeus/buildroot/build_arm/staging_dir/bin/arm-linux-gcc -Wall fpgaregs.c -o fpgaregs
+ chmod 755 fpgaregs
+ cp fpgaregs /tftpboot/
+
+clean:
+ rm -f *.*o \
+ rm -f Module.symvers
+
+endif
+
Property changes on: trunk/target/linux/modules/fpga/fpgaaccess/Makefile
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.c
===================================================================
--- trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.c (rev 0)
+++ trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.c 2008-04-08 13:21:01 UTC (rev 794)
@@ -0,0 +1,173 @@
+/*
+ ***********************************************************************
+ * fpgaaccess.c
+ *
+ * (c) Copyright 2008 Armadeus project
+ * Fabien Marteau <fab...@ar...>
+ *
+ * A simple driver for reading and writing on
+ * fpga throught a character file /dev/fpgaaccess
+ *
+ * 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, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ **********************************************************************
+ */
+
+#include "fpgaaccess.h"
+
+/*************************************/
+/* to read write fpgaaccess register */
+/*************************************/
+ssize_t fpgaaccess_read(struct file *fildes, char __user *buff,
+ size_t count, loff_t *offp){
+ struct fpgaaccess_dev *sdev = fildes->private_data;
+ u16 data=0;
+
+ if(*offp >= FPGA_SIZE || ((*offp)%2 != 0)){ /* offset must be pair */
+ return 0;
+ }
+
+ if(count != 2) /* only one word can be wrote (two bytes)*/
+ count = 2;
+
+ data = ioread16(sdev->fpga_virtual_base_address + *offp);
+
+ /* return data for user */
+ if(copy_to_user(buff,&data,2)){
+ printk(KERN_WARNING "read : copy to user data error\n");
+ return -EFAULT;
+ }
+ return 0;
+}
+
+ssize_t fpgaaccess_write(struct file *fildes, const char __user *
+ buff,size_t count, loff_t *offp){
+ struct fpgaaccess_dev *sdev = fildes->private_data;
+ u16 data=0;
+
+ if(*offp >= FPGA_SIZE || ((*offp)%2 != 0)){ /* offset must be pair */
+ return 0;
+ }
+
+ if(count != 2) /* only one word can be wrote (two bytes)*/
+ count = 2;
+
+ if(copy_from_user(&data,buff,2)){
+ printk(KERN_WARNING "write : copy from user error\n");
+ return -EFAULT;
+ }
+
+ iowrite16(data,sdev->fpga_virtual_base_address + *offp);
+
+ return 2;
+}
+
+int fpgaaccess_open(struct inode *inode, struct file *filp){
+ filp->private_data=container_of(inode->i_cdev,struct fpgaaccess_dev,cdev);
+ return 0;
+}
+
+int fpgaaccess_release(struct inode *inode, struct file *filp){
+ filp->private_data=NULL;
+ return 0;
+}
+
+
+
+/********************************/
+/* init and release module */
+/********************************/
+
+static int __init fpgaaccess_init(void){
+ int result;
+ int fpgaaccess_major,fpgaaccess_minor;
+ u16 data;
+ struct fpgaaccess_dev *sdev;
+
+ fpgaaccess_major = 250;
+ fpgaaccess_minor = 0;
+
+ /* Allocate a private structure and reference it as driver's data */
+ PDEBUG("Allocate a private structure and reference it as driver s data\n");
+ sdev = (struct fpgaaccess_dev *)kmalloc(sizeof(struct fpgaaccess_dev),GFP_KERNEL);
+ if(sdev == NULL){
+ printk(KERN_WARNING "FPGAACCESS: unable to allocate private structure\n");
+ return -ENOMEM;
+ }
+
+ fpgaaccessdev = sdev;
+
+ /* Get the major and minor device numbers */
+ PDEBUG("Get the major and minor device numbers\n");
+ if(fpgaaccess_major){
+ devno = MKDEV(fpgaaccess_major,fpgaaccess_minor);
+ result = register_chrdev_region(devno, N_DEV,FPGAACCESS_NAME);
+ }else{
+ result = alloc_chrdev_region(&devno,fpgaaccess_minor,N_DEV,FPGAACCESS_NAME);
+ fpgaaccess_major = MAJOR(devno);
+ }
+ printk(KERN_INFO "fpgaaccess: MAJOR: %d MINOR: %d\n",MAJOR(devno),MINOR(devno));
+ if(result < 0){
+ printk(KERN_ERR "fpgaaccess: can't get major %d\n",fpgaaccess_major);
+ goto mkdev_error;
+ }
+
+ /* Init the cdev structure */
+ PDEBUG("Init the cdev structure\n");
+ cdev_init(&sdev->cdev,&fpgaaccess_fops);
+ sdev->cdev.owner = THIS_MODULE;
+
+ /* Add the device to the kernel, connecting cdev to major/minor number */
+ PDEBUG("Add the device to the kernel, connecting cdev to major/minor number \n");
+ result = cdev_add(&sdev->cdev,devno,1);
+ if(result < 0){
+ printk(KERN_WARNING "FPGAACCESS: can't add cdev\n");
+ goto cdevadd_error;
+ }
+
+ sdev->fpga_virtual_base_address = (void*)FPGA_BASE_ADDR;
+
+ /* ok module insered */
+ fpgaaccessdev=sdev;
+ printk(KERN_INFO "FPGAACCESS module insered\n");
+ return 0;
+
+cdevadd_error:
+ /* free major and minor number */
+ unregister_chrdev_region(devno,N_DEV);
+ printk(KERN_INFO "fpgaaccess module deleted\n");
+mkdev_error:
+ printk(KERN_ERR "%s: not insered\n",FPGAACCESS_NAME);
+ kfree(sdev);
+ return result;
+
+}
+
+static void __exit fpgaaccess_exit(void){
+ struct fpgaaccess_dev *sdev;
+
+ sdev = fpgaaccessdev;
+
+ /* delete the cdev structure */
+ cdev_del(&sdev->cdev);
+
+ /* free major and minor number */
+ unregister_chrdev_region(devno,N_DEV);
+ printk(KERN_INFO "fpgaaccess module deleted\n");
+
+ /* freed structure device */
+ kfree(sdev);
+}
+
+
Added: trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.h
===================================================================
--- trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.h (rev 0)
+++ trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.h 2008-04-08 13:21:01 UTC (rev 794)
@@ -0,0 +1,121 @@
+/*
+ ***********************************************************************
+ * fpgaaccess.h
+ *
+ * (c) Copyright 2008 Armadeus project
+ * Fabien Marteau <fab...@ar...>
+ *
+ * A simple driver for reading and writing on
+ * fpga throught a character file /dev/fpgaaccess
+ *
+ * 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, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ **********************************************************************
+ */
+
+#ifndef __FPGAACCESS_H_
+#define __FPGAACCESS_H_
+
+#include <linux/version.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
+#include <linux/config.h>
+#endif
+
+/* form module/drivers */
+#include <linux/init.h>
+#include <linux/module.h>
+
+/* for file operations */
+#include <linux/fs.h>
+#include <linux/cdev.h>
+
+/* copy_to_user function */
+#include <asm/uaccess.h>
+
+/* readw() writew() */
+#include <asm/io.h>
+
+/* hardware addresses */
+#include <asm/hardware.h>
+
+#endif
+
+/* for debugging messages*/
+#define FPGAACCESS_DEBUG
+
+#undef PDEBUG
+#ifdef FPGAACCESS
+# ifdef __KERNEL__
+ /* for kernel spage */
+# define PDEBUG(fmt,args...) printk(KERN_DEBUG "fpgaaccess : " fmt, ##args)
+# else
+ /* for user space */
+# define PDEBUG(fmt,args...) printk(stderr, fmt, ##args)
+# endif
+#else
+# define PDEBUG(fmt,args...) /* no debbuging message */
+#endif
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Fabien Marteau <fab...@ar...> - ARMadeus Systems");
+MODULE_DESCRIPTION("FPGA access device driver");
+
+/* some defines */
+
+#define FPGAACCESS_NAME "fpgaaccess"
+#define FPGA_BASE_ADDR IMX_CS1_VIRT
+#define FPGA_SIZE IMX_CS1_SIZE
+#define N_DEV 1
+
+
+/*************************/
+/* main device structures */
+/*************************/
+struct fpgaaccess_dev{
+ struct cdev cdev; /* Char device structure */
+ void * fpga_virtual_base_address; /* fpga register base address*/
+};
+
+static dev_t devno;
+struct fpgaaccess_dev *fpgaaccessdev;
+
+/*************************************/
+/* to read write fpgaaccess register */
+/*************************************/
+ssize_t fpgaaccess_read(struct file *fildes, char __user *buff,
+ size_t count, loff_t *offp);
+
+ssize_t fpgaaccess_write(struct file *fildes, const char __user *
+ buff,size_t count, loff_t *offp);
+int fpgaaccess_open(struct inode *inode, struct file *filp);
+
+int fpgaaccess_release(struct inode *, struct file *filp);
+
+struct file_operations fpgaaccess_fops = {
+ .owner = THIS_MODULE,
+ .read = fpgaaccess_read,
+ .write = fpgaaccess_write,
+ .open = fpgaaccess_open,
+ .release = fpgaaccess_release,
+};
+
+/********************************/
+/* init and release module */
+/********************************/
+
+static int __init fpgaaccess_init(void);
+static void __exit fpgaaccess_exit(void);
+
+module_init(fpgaaccess_init);
+module_exit(fpgaaccess_exit);
Added: trunk/target/linux/modules/fpga/fpgaaccess/fpgaregs.c
===================================================================
--- trunk/target/linux/modules/fpga/fpgaaccess/fpgaregs.c (rev 0)
+++ trunk/target/linux/modules/fpga/fpgaaccess/fpgaregs.c 2008-04-08 13:21:01 UTC (rev 794)
@@ -0,0 +1,94 @@
+/************************************************************************
+ * a program to write/read values on fpga address map
+ * 7 april 2008
+ * fpgaregs.c
+ *
+ * (c) Copyright 2008 Armadeus project
+ * Fabien Marteau <fab...@ar...>
+ *
+ * A simple driver for reading and writing on
+ * fpga throught a character file /dev/fpgaaccess
+ *
+ * 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, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ **********************************************************************
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* file management */
+#include <sys/stat.h>
+#include <fcntl.h>
+
+/* as name said */
+#include <signal.h>
+
+/* sleep, write(), read() */
+#include <unistd.h>
+
+/* converting string */
+#include <string.h>
+
+int ffpga;
+
+int main(int argc, char *argv[])
+{
+ unsigned short address;
+ unsigned short value;
+ int retval;
+
+ printf( "Testing button driver\n" );
+
+ if((argc < 2) || (argc > 3)){
+ perror("invalid arguments number\nfpgaregs fpga_reg_add [value]\n");
+ exit(EXIT_FAILURE);
+ }
+
+ ffpga=open("/dev/fpgaaccess",O_RDWR);
+ if(ffpga<0){
+ perror("can't open file /dev/fpgaaccess\n");
+ exit(EXIT_FAILURE);
+ }
+
+ address = (unsigned char )strtol(argv[1], (char **)NULL, 16);
+
+ if(address%2!=0){
+ perror("error address must be pair\n");
+ exit(EXIT_FAILURE);
+ }
+
+ /* write value at address */
+ if(argc == 3){
+ value = (unsigned char )strtol(argv[2], (char **)NULL, 16);
+ retval = pwrite(ffpga,(void *)&value,2,address);
+ if(retval<0){
+ perror("write error\n");
+ exit(EXIT_FAILURE);
+ }
+ printf("Wrote %04x at %08x\n",value,address+0x12000000);
+
+ /* read address value */
+ }else{
+ retval = pread(ffpga,(void *)&value,2,address);
+ if(retval<0){
+ perror("Read error\n");
+ exit(EXIT_FAILURE);
+ }
+ printf("Read %04x at %08x\n",value,address+0x12000000);
+ }
+
+ close(ffpga);
+ exit(0);
+}
Added: trunk/target/linux/modules/fpga/i2ctest/Kconfig
===================================================================
--- trunk/target/linux/modules/fpga/i2ctest/Kconfig (rev 0)
+++ trunk/target/linux/modules/fpga/i2ctest/Kconfig 2008-04-08 13:21:01 UTC (rev 794)
@@ -0,0 +1,8 @@
+#
+#
+
+config ARMADEUS_I2C_OCORE_IRQMNG
+ tristate "Driver for testing wishbone i2c-ocore-irq_mng"
+ default n
+ depends on ARMADEUS_FPGA_DRIVERS
+ ---help---
Added: trunk/target/linux/modules/fpga/i2ctest/Makefile
===================================================================
--- trunk/target/linux/modules/fpga/i2ctest/Makefile (rev 0)
+++ trunk/target/linux/modules/fpga/i2ctest/Makefile 2008-04-08 13:21:01 UTC (rev 794)
@@ -0,0 +1,37 @@
+#
+# Makefile for the Armadeus bus_i2ctest drivers
+#
+
+# Part executed when cali2ctest from kernel build system:
+ifneq ($(KERNELRELEASE),)
+
+obj-m += i2ctest.o
+
+i2ctest := i2ctest.o
+
+# Part executed when called from standard make in this directory:
+# (preferably use Makefile in parent directory)
+else
+
+BASE_DIR="../../../../../buildroot/"
+REL=`grep "BR2_PACKAGE_LINUX_VERSION=" $(BASE_DIR).config | \
+ sed "s/BR2_PACKAGE_LINUX_VERSION=\\"//" | sed "s/\\"//"`
+ARMADEUS_KERNEL_DIR=$(BASE_DIR)build_arm/linux-$(REL)
+KDIR := $(ARMADEUS_KERNEL_DIR)
+PWD := $(shell pwd)
+
+default:
+ $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
+ cp i2ctest.ko /tftpboot/
+
+test:
+ ~/armadeus/buildroot/build_arm/staging_dir/bin/arm-linux-gcc testi2ctest.c -o testi2ctest
+ chmod 755 testi2ctest
+ cp testi2ctest /tftpboot/
+
+clean:
+ rm -f *.*o \
+ rm -f Module.symvers
+
+endif
+
Property changes on: trunk/target/linux/modules/fpga/i2ctest/Makefile
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/target/linux/modules/fpga/i2ctest/README
===================================================================
--- trunk/target/linux/modules/fpga/i2ctest/README (rev 0)
+++ trunk/target/linux/modules/fpga/i2ctest/README 2008-04-08 13:21:01 UTC (rev 794)
@@ -0,0 +1,13 @@
+This is a really simple driver to test reading and writing
+a value on i2c bus throught ocore-irq_mng FPGA IP.
+
+To use it load i2ctest.ko module with insmod
+>insmod i2ctest.ko
+
+Then read /proc/i2c_test with cat
+> cat /proc/i2c_test
+
+This will send write command on component
+
+To read the value you wrote, read /proc/i2c_test2
+> cat /proc/i2c_test2
Added: trunk/target/linux/modules/fpga/i2ctest/i2ctest.c
===================================================================
--- trunk/target/linux/modules/fpga/i2ctest/i2ctest.c (rev 0)
+++ trunk/target/linux/modules/fpga/i2ctest/i2ctest.c 2008-04-08 13:21:01 UTC (rev 794)
@@ -0,0 +1,225 @@
+/* i2ctest.c
+ ***********************************************************************
+ *
+ * (c) Copyright 2008 Armadeus project
+ * Fabien Marteau <fab...@ar...>
+ * Driver for testing i2c IP ocore with irq_mngr
+ *
+ * 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, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ **********************************************************************
+ */
+
+#include "i2ctest.h"
+
+#define VALUE 0xbb
+#define ADDR 0x1D
+#define SUBADDR 0x16
+
+
+/***************************
+ * interrupt management
+ * *************************/
+
+static irqreturn_t fpga_interrupt(int irq,void *stuff,struct pt_regs *reg){
+ static int count = 0;
+ u16 data;
+
+ /**************/
+ /* write 0xbb */
+ /**************/
+ if(count == 0){
+ /*read RxACK bit from Status Register, should be 0 */
+ ioread16(i2cdev->fpga_virtual_base_address + FPGA_I2C_RXT_SR);
+ /* write to Transmit sub address, set WR bit acknowledge interrupt*/
+ iowrite16(SUBADDR<<8|I2C_WR|I2C_IACK,
+ i2cdev->fpga_virtual_base_address + FPGA_I2C_TXR_CR);
+ /* acknowledge irq in irq manager*/
+ iowrite16(0x0002,i2cdev->fpga_virtual_base_address + FPGA_IRQ_ACK);
+ count++;
+ }else if(count == 1){
+ ioread16(i2cdev->fpga_virtual_base_address + FPGA_I2C_RXT_SR);
+ /* write to Transmit sub address, set WR bit acknowledge interrupt*/
+ iowrite16(VALUE<<8|I2C_STO|I2C_WR|I2C_IACK,
+ i2cdev->fpga_virtual_base_address + FPGA_I2C_TXR_CR);
+ /* acknowledge irq in irq manager*/
+ iowrite16(0x0002,i2cdev->fpga_virtual_base_address + FPGA_IRQ_ACK);
+ count ++;
+ }else if(count == 2){
+ ioread16(i2cdev->fpga_virtual_base_address + FPGA_I2C_RXT_SR);
+ iowrite16(0x0000|I2C_IACK|I2C_STO,
+ i2cdev->fpga_virtual_base_address + FPGA_I2C_TXR_CR);
+ /* acknowledge irq in irq manager*/
+ iowrite16(0x0002,i2cdev->fpga_virtual_base_address + FPGA_IRQ_ACK);
+ count++;
+
+ /***********************/
+ /* read the same value */
+ /***********************/
+ }else if(count == 3){
+ /*read RxACK bit from Status Register, should be 0 */
+ ioread16(i2cdev->fpga_virtual_base_address + FPGA_I2C_RXT_SR);
+ /* write 0x2C to Transmit sub address, set WR bit acknowledge interrupt*/
+ iowrite16(SUBADDR<<8|I2C_WR|I2C_IACK,
+ i2cdev->fpga_virtual_base_address + FPGA_I2C_TXR_CR);
+ /* acknowledge irq in irq manager*/
+ iowrite16(0x0002,i2cdev->fpga_virtual_base_address + FPGA_IRQ_ACK);
+ count++;
+ }else if(count == 4){
+ ioread16(i2cdev->fpga_virtual_base_address + FPGA_I2C_RXT_SR);
+ /* write adress on TXR and CTR register repeated start, acknowledge interrupt*/
+ iowrite16(ADDR<<9|I2C_ADD_READ|I2C_STA|I2C_WR|I2C_IACK,
+ i2cdev->fpga_virtual_base_address + FPGA_I2C_TXR_CR);
+ /* acknowledge irq in irq manager*/
+ iowrite16(0x0002,i2cdev->fpga_virtual_base_address + FPGA_IRQ_ACK);
+ count++;
+ }else if(count == 5){
+ /* write on TXR and CTR register, set read bit,acknowledge interrupt*/
+ iowrite16(I2C_RD|I2C_ACK|I2C_IACK|I2C_STO,
+ i2cdev->fpga_virtual_base_address + FPGA_I2C_TXR_CR);
+ /* acknowledge irq in irq manager*/
+ iowrite16(0x0002,i2cdev->fpga_virtual_base_address + FPGA_IRQ_ACK);
+ count++;
+ }else if(count == 6){
+ data = ioread16(i2cdev->fpga_virtual_base_address + FPGA_I2C_RXT_SR);
+ /* write on TXR and CTR register, set read bit,acknowledge interrupt*/
+ iowrite16(I2C_IACK,
+ i2cdev->fpga_virtual_base_address + FPGA_I2C_TXR_CR);
+
+ /* acknowledge irq in irq manager*/
+ iowrite16(0x0002,i2cdev->fpga_virtual_base_address + FPGA_IRQ_ACK);
+
+ printk(KERN_INFO "read %04x\n",data);
+ count++;
+ }
+ return IRQ_HANDLED;
+}
+
+/****************************
+ * read proc
+ * **************************/
+
+static int read_proc(char *page,char **start,off_t offset,int count,int *eof,void *data){
+ /* if(down_interruptible(&i2cdev->sem))
+ return -ERESTARTSYS;*/
+
+ PDEBUG("Trying to write %04x on i2c slave\n",VALUE);
+
+ /* unmask interrupt for i2c in interrupt manager*/
+ iowrite16(0x0002,i2cdev->fpga_virtual_base_address + FPGA_IRQ_MASK);
+ /* set prescale for 400kHz*/
+ iowrite16(0x00BF,i2cdev->fpga_virtual_base_address + FPGA_I2C_PRESC);
+ PDEBUG("Write %04x at %04x\n",0x00BF,FPGA_I2C_PRESC);
+ /* set core enable and interrupt enable*/
+ iowrite16(I2C_EN|I2C_IEN,
+ i2cdev->fpga_virtual_base_address + FPGA_I2C_CTR);
+ PDEBUG("Write %04x at %04x\n",I2C_EN|I2C_IEN,FPGA_I2C_CTR);
+ /* write slave adresse on TXR and CTR register*/
+ iowrite16(ADDR<<9|I2C_STA|I2C_WR|I2C_IACK,i2cdev->fpga_virtual_base_address + FPGA_I2C_TXR_CR);
+
+ PDEBUG("Write %04x at %04x\n",ADDR<<9|I2C_ADD_WRITE|I2C_STA|I2C_WR,FPGA_I2C_TXR_CR);
+
+ /* PDEBUG("Wrote ?\n");*/
+
+/* up(&i2cdev->sem);*/
+ return 0;
+}
+
+static int read_proc2(char *page,char **start,off_t offset,int count,int *eof,void *data){
+
+ PDEBUG("Trying to read on i2c slave\n");
+
+ /* write slave adresse on TXR and CTR register*/
+ iowrite16(ADDR<<9|I2C_ADD_WRITE|I2C_STA|I2C_WR|I2C_IACK,
+ i2cdev->fpga_virtual_base_address + FPGA_I2C_TXR_CR);
+ return 0;
+}
+
+/****************************
+* Module management
+* **************************/
+
+static int __init i2ctest_init(void){
+ int result;
+ u16 data;
+ result = 0;
+
+ mem = NULL;
+
+ /* Allocate a private structure and reference it as driver's data */
+ PDEBUG("Allocate a private structure and reference it as driver s data\n");
+ i2cdev = (struct i2ctest_dev *)kmalloc(sizeof(struct i2ctest_dev),GFP_KERNEL);
+ if(i2cdev == NULL){
+ printk(KERN_WARNING "I2CDEV: unable to allocate private structure\n");
+ return -ENOMEM;
+ }
+
+ /* Requested I/O memory */
+ if((i2cdev->fpga_virtual_base_address = ioremap(IMX_CS1_PHYS,IMX_CS1_SIZE))==NULL){
+ printk(KERN_ERR "ioremap error\n");
+ goto error;
+ }
+
+ /* irq registering */
+ if(request_irq(IRQ_GPIOA(1),(irq_handler_t)fpga_interrupt,IRQF_SHARED,"fpga",i2cdev)<0){
+ printk(KERN_ERR "Can't request fpga irq\n");
+ goto error;
+ }
+ //ioread16(i2cdev->fpga_virtual_base_address + FPGA_IRQ_ACK);
+ /* irq ack */
+ data=1;
+ if((result=iowrite16(data,i2cdev->fpga_virtual_base_address + FPGA_IRQ_ACK))<0)
+ goto error;
+
+ /* create proc entry */
+ create_proc_read_entry("i2c_test",0 /* default mode */,
+ NULL /* parent dir */, read_proc,
+ NULL /* client data */);
+
+ /* create proc entry */
+ create_proc_read_entry("i2c_test2",0 /* default mode */,
+ NULL /* parent dir */, read_proc2,
+ NULL /* client data */);
+
+ /* OK module inserted ! */
+ printk(KERN_INFO "i2ctest module insered\n");
+ return 0;
+
+error:
+ printk(KERN_ERR "%s: not inserted\n",DRIVER_NAME);
+ free_all();
+ return result;
+
+
+}
+
+static void __exit i2ctest_exit(void){
+ free_all();
+}
+
+static void free_all(void){
+
+ /* free irq*/
+ free_irq(IRQ_GPIOA(1),i2cdev);
+
+ /* Free the allocated memory */
+ kfree(i2cdev);
+
+ /* remove proc entry */
+ remove_proc_entry("i2c_test",0);
+
+ printk(KERN_INFO "i2ctest module deleted\n");
+}
+
+
Added: trunk/target/linux/modules/fpga/i2ctest/i2ctest.h
===================================================================
--- trunk/target/linux/modules/fpga/i2ctest/i2ctest.h (rev 0)
+++ trunk/target/linux/modules/fpga/i2ctest/i2ctest.h 2008-04-08 13:21:01 UTC (rev 794)
@@ -0,0 +1,127 @@
+/* i2ctest.h
+ ***********************************************************************
+ *
+ * (c) Copyright 2008 Armadeus project
+ * Fabien Marteau <fab...@ar...>
+ * module for testing i2c_master fpga IP
+ *
+ * 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, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ **********************************************************************
+ --------------------------------------------
+ * 18 mars 2008
+ * initial version
+ */
+
+#ifndef __I2CTEST_H_
+#define __I2CTEST_H_
+
+#include <linux/version.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
+#include <linux/config.h>
+#endif
+
+/* for module */
+#include <linux/init.h>
+#include <linux/module.h>
+
+/* proc entry */
+#include <linux/proc_fs.h>
+
+/* request_mem_region */
+#include <linux/ioport.h>
+
+/* readw() writew() */
+#include <asm/io.h>
+
+/* hardware addresses */
+#include <asm/hardware.h>
+
+/* interruptions */
+#include <linux/interrupt.h>
+#include <asm/irq.h>
+
+/* /proc */
+#include <linux/proc_fs.h>
+
+#endif
+
+/* for debugging messages*/
+//#define LED_DEBUG
+
+#undef PDEBUG
+#ifdef LED_DEBUG
+# ifdef __KERNEL__
+ /* for kernel spage */
+# define PDEBUG(fmt,args...) printk(KERN_DEBUG "i2ctest : " fmt, ##args)
+# else
+ /* for user space */
+# define PDEBUG(fmt,args...) printk(stderr, fmt, ##args)
+# endif
+#else
+# define PDEBUG(fmt,args...) /* no debbuging message */
+#endif
+
+#define FPGA_BUTTON 8
+#define FPGA_LED 4
+#define FPGA_IRQ_MASK 0
+#define FPGA_IRQ_PEND 2
+#define FPGA_IRQ_ACK 2
+
+#define FPGA_I2C_PRESC 0x10
+#define FPGA_I2C_CTR 0x12
+#define FPGA_I2C_TXR_CR 0x14
+#define FPGA_I2C_RXT_SR 0x16
+
+
+/* CTR register */
+#define I2C_EN 0x80
+#define I2C_IEN 0x40
+/* CR register */
+#define I2C_STA 0x80
+#define I2C_STO 0x40
+#define I2C_RD 0x20
+#define I2C_WR 0x10
+#define I2C_ACK 0x08
+#define I2C_IACK 0x01
+
+#define I2C_ADD_READ 0x0100
+#define I2C_ADD_WRITE 0
+
+#define DRIVER_NAME "i2ctest"
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Fabien Marteau <fab...@ar...> - ARMadeus Systems");
+MODULE_DESCRIPTION("I2C tester");
+
+struct i2ctest_dev {
+ struct semaphore sem;
+ void * fpga_virtual_base_address;
+};
+
+struct resource *mem; /* pointer to fpga led */
+
+struct i2ctest_dev *i2cdev;
+
+static int __init i2ctest_init(void);
+static void __exit i2ctest_exit(void);
+
+static int read_proc(char *page,char **start,off_t offset,int count,int *eof,void *data);
+static int read_proc2(char *page,char **start,off_t offset,int count,int *eof,void *data);
+static void free_all(void);
+
+static irqreturn_t fpga_interrupt(int irq,void *stuff,struct pt_regs *reg);
+
+module_init(i2ctest_init);
+module_exit(i2ctest_exit);
Modified: trunk/target/linux/modules/gpio/Makefile
===================================================================
--- trunk/target/linux/modules/gpio/Makefile 2008-04-05 09:12:51 UTC (rev 793)
+++ trunk/target/linux/modules/gpio/Makefile 2008-04-08 13:21:01 UTC (rev 794)
@@ -18,7 +18,7 @@
BASE_DIR="../../../../buildroot/"
REL=`grep "BR2_PACKAGE_LINUX_VERSION=" $(BASE_DIR).config | \
sed "s/BR2_PACKAGE_LINUX_VERSION=\\"//" | sed "s/\\"//"`
-ARMADEUS_KERNEL_DIR=$(BASE_DIR)build_arm_nofpu/linux-$(REL)
+ARMADEUS_KERNEL_DIR=$(BASE_DIR)build_arm/linux-$(REL)
KDIR := $(ARMADEUS_KERNEL_DIR)
PWD := $(shell pwd)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|