[Armadeus-commitlog] SF.net SVN: armadeus:[868] trunk/target/linux/modules/fpga
Brought to you by:
sszy
|
From: <Fa...@us...> - 2008-08-05 15:28:29
|
Revision: 868
http://armadeus.svn.sourceforge.net/armadeus/?rev=868&view=rev
Author: FabM
Date: 2008-08-05 15:28:22 +0000 (Tue, 05 Aug 2008)
Log Message:
-----------
[LINUX] Changing fpga driver tree
Modified Paths:
--------------
trunk/target/linux/modules/fpga/Kconfig
trunk/target/linux/modules/fpga/Makefile
Added Paths:
-----------
trunk/target/linux/modules/fpga/POD/
trunk/target/linux/modules/fpga/dev_tools/
trunk/target/linux/modules/fpga/dev_tools/Kconfig
trunk/target/linux/modules/fpga/dev_tools/Makefile
trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/
trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/Kconfig
trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/Makefile
trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpga-loader.c
trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpga-loader.h
trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpgaloader.sh
trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/target-fpga-loader.c
trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/target-fpga-loader.h
trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/xilinx-fpga-loader.c
trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/xilinx-fpga-loader.h
trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/
trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/.tmp_versions/
trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/.tmp_versions/fpgaaccess.mod
trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/Kconfig
trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/Makefile
trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/Module.symvers
trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaaccess.c
trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaaccess.h
trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaregs
trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaregs.c
trunk/target/linux/modules/fpga/others/
trunk/target/linux/modules/fpga/others/Kconfig
trunk/target/linux/modules/fpga/others/Makefile
trunk/target/linux/modules/fpga/others/Wb_button/
trunk/target/linux/modules/fpga/others/Wb_button/Kconfig
trunk/target/linux/modules/fpga/others/Wb_button/Makefile
trunk/target/linux/modules/fpga/others/Wb_button/button.c
trunk/target/linux/modules/fpga/others/Wb_button/button.h
trunk/target/linux/modules/fpga/others/Wb_button/button_specific.h
trunk/target/linux/modules/fpga/others/Wb_button/testbutton.c
trunk/target/linux/modules/fpga/others/Wb_led/
trunk/target/linux/modules/fpga/others/Wb_led/Kconfig
trunk/target/linux/modules/fpga/others/Wb_led/Makefile
trunk/target/linux/modules/fpga/others/Wb_led/led.c
trunk/target/linux/modules/fpga/others/Wb_led/led.h
trunk/target/linux/modules/fpga/others/Wb_led/led_specific.h
trunk/target/linux/modules/fpga/others/i2ctest/
trunk/target/linux/modules/fpga/others/i2ctest/Kconfig
trunk/target/linux/modules/fpga/others/i2ctest/Makefile
trunk/target/linux/modules/fpga/others/i2ctest/README
trunk/target/linux/modules/fpga/others/i2ctest/i2ctest.c
trunk/target/linux/modules/fpga/others/i2ctest/i2ctest.h
trunk/target/linux/modules/fpga/others/ps2keyboard/
trunk/target/linux/modules/fpga/others/ps2keyboard/Kconfig
trunk/target/linux/modules/fpga/others/ps2keyboard/Makefile
trunk/target/linux/modules/fpga/others/ps2keyboard/README
trunk/target/linux/modules/fpga/others/ps2keyboard/core.c
Removed Paths:
-------------
trunk/target/linux/modules/fpga/Wb_button/
trunk/target/linux/modules/fpga/Wb_led/
trunk/target/linux/modules/fpga/fpga_devtools/
trunk/target/linux/modules/fpga/fpgaaccess/
trunk/target/linux/modules/fpga/i2ctest/
trunk/target/linux/modules/fpga/irq_manager/
trunk/target/linux/modules/fpga/ps2keyboard/
trunk/target/linux/modules/fpga/serial/
Modified: trunk/target/linux/modules/fpga/Kconfig
===================================================================
--- trunk/target/linux/modules/fpga/Kconfig 2008-08-05 09:44:44 UTC (rev 867)
+++ trunk/target/linux/modules/fpga/Kconfig 2008-08-05 15:28:22 UTC (rev 868)
@@ -6,26 +6,14 @@
#
config ARMADEUS_FPGA_DRIVERS
- boolean "Support for FPGA specific drivers"
+ boolean "Support FPGA specific drivers"
default n
---help---
All drivers for FPGA components
-source "drivers/armadeus/fpga/fpga_devtools/Kconfig"
+source "drivers/armadeus/fpga/dev_tools/Kconfig"
-source "drivers/armadeus/fpga/ps2keyboard/Kconfig"
+source "drivers/armadeus/fpga/others/Kconfig"
-source "drivers/armadeus/fpga/Wb_led/Kconfig"
-
-source "drivers/armadeus/fpga/Wb_button/Kconfig"
-
-source "drivers/armadeus/fpga/i2ctest/Kconfig"
-
-source "drivers/armadeus/fpga/fpgaaccess/Kconfig"
-
-source "drivers/armadeus/fpga/serial/Kconfig"
-
-source "drivers/armadeus/fpga/irq_manager/Kconfig"
-
endmenu
Modified: trunk/target/linux/modules/fpga/Makefile
===================================================================
--- trunk/target/linux/modules/fpga/Makefile 2008-08-05 09:44:44 UTC (rev 867)
+++ trunk/target/linux/modules/fpga/Makefile 2008-08-05 15:28:22 UTC (rev 868)
@@ -8,8 +8,7 @@
# Part executed when called from kernel build system:
-obj-$(CONFIG_ARMADEUS_FPGA_DRIVERS) += ps2keyboard/ fpga_devtools/ Wb_led/ Wb_button/ \
- i2ctest/ fpgaaccess/ serial/ irq_manager/
+obj-$(CONFIG_ARMADEUS_FPGA_DRIVERS) += dev_tools/ others/
else
Added: trunk/target/linux/modules/fpga/dev_tools/Kconfig
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/Kconfig (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/Kconfig 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,12 @@
+#
+# Armadeus custom drivers configuration
+#
+config ARMADEUS_FPGA_TEST
+ boolean "Driver for configuring and testing fpga"
+ default n
+ depends on ARMADEUS_FPGA_DRIVERS
+ ---help---
+ All drivers for FPGA components
+
+source "drivers/armadeus/fpga/dev_tools/fpga_devtools/Kconfig"
+source "drivers/armadeus/fpga/dev_tools/fpgaaccess/Kconfig"
Added: trunk/target/linux/modules/fpga/dev_tools/Makefile
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/Makefile (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/Makefile 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,41 @@
+#
+# Main Makefile for the Armadeus FPGA related drivers
+#
+# Add your subdirectories to obj- target
+#
+
+ifneq ($(KERNELRELEASE),)
+
+# Part executed when called from kernel build system:
+
+obj-$(CONFIG_ARMADEUS_FPGA_TEST) += fpga_devtools/ fpgaaccess/
+
+else
+
+# Part executed when called from standard make in this directory:
+
+BASE_DIR:=../../../../buildroot/
+REL:=$(shell grep "BR2_PACKAGE_LINUX_VERSION=" $(BASE_DIR).config | \
+ sed -e 's/BR2_PACKAGE_LINUX_VERSION=//' | sed -e 's/"//g')
+#`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)
+ifeq ($(LINUX_DIR),)
+LINUX_DIR:=$(ARMADEUS_KERNEL_DIR)
+endif
+PWD:= $(shell pwd)
+
+default:
+ echo "Your Linux source dir is: $(LINUX_DIR)"
+ $(MAKE) -C $(LINUX_DIR) SUBDIRS=$(PWD) zImage modules
+
+clean:
+ echo "Your Linux source dir is: $(LINUX_DIR)"
+ $(MAKE) -C $(LINUX_DIR) SUBDIRS=$(PWD) clean
+
+install:
+ echo "Installing Armadeus drivers..."
+ $(MAKE) -C $(LINUX_DIR) SUBDIRS=$(PWD) INSTALL_MOD_PATH=$(TARGET_DIR) modules_install
+
+endif
+
Added: trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/Kconfig
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/Kconfig (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/Kconfig 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,9 @@
+#
+
+#
+config ARMADEUS_FPGA_TOOL_DRIVER
+ tristate "Armadeus FPGA configuration driver"
+ default n
+ depends on ARMADEUS_FPGA_TEST
+ ---help---
+
Added: trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/Makefile
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/Makefile (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/Makefile 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,36 @@
+#
+# Makefile for the Armadeus FPGA loader driver
+# PATH=$HOME/nico/test/buildroot/build_arm_nofpu/staging_dir/bin:$PATH
+# make ARCH=arm
+# tftp -gr fpgaloader.ko -l /lib/modules/drivers/fpgaloader.ko 192.168.0.3
+# tftp -gr fpga_test.bit 192.168.0.3
+# insmod /lib/modules/drivers/fpgaloader.ko
+# dd if=fpga_test.bit of=/dev/fpga/loader
+
+
+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)
+
+ifneq ($(KERNELRELEASE),)
+
+obj-$(CONFIG_ARMADEUS_FPGA_TOOL_DRIVER) += fpgaloader.o
+fpgaloader-objs := target-fpga-loader.o xilinx-fpga-loader.o fpga-loader.o
+
+else
+KDIR := $(ARMADEUS_KERNEL_DIR)
+PWD := $(shell pwd)
+
+default:
+ $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
+
+clean:
+ rm -f *.*o \
+ rm -f Module.symvers
+
+
+endif
+
Added: trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpga-loader.c
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpga-loader.c (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpga-loader.c 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,284 @@
+/*
+ ***********************************************************************
+ *
+ * (c) Copyright 2006 Armadeus project
+ * Julien Boibessot <jul...@ar...>
+ * Nicolas Colombain <nic...@ar...>
+ * Generic Xilinx FPGA loader
+ *
+ * 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 <linux/version.h>
+#include "fpga-loader.h"
+#include "xilinx-fpga-loader.h"
+#include <asm/arch/imx-regs.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
+#include <linux/config.h>
+#endif
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/fs.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/proc_fs.h>
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/fcntl.h>
+#include <asm/system.h>
+#include <asm/io.h>
+#include <asm/uaccess.h>
+
+//static unsigned long init_map;
+struct semaphore fpga_sema;
+
+/* global variables */
+static int fpga_major = FPGA_MAJOR;
+Xilinx_desc* g_current_desc = NULL;
+
+static unsigned char fpga_descriptor = 0; // use default target_fpga_desc
+module_param( fpga_descriptor, byte, 0 );
+
+#define FPGA_BUFFER_SIZE 4096
+static unsigned char g_buffer[FPGA_BUFFER_SIZE];
+static unsigned char g_nb_users = 0;
+
+
+void __exit armadeus_fpga_cleanup(void);
+
+
+//------------------------------------------------
+//
+// Handles write() done on /dev/fpgaxx
+//
+static ssize_t armadeus_fpga_write(struct file *file, const char* pData, size_t count, loff_t *f_pos)
+{
+ ssize_t ret = 0;
+
+ // Get exclusive access
+ if (down_interruptible(&fpga_sema))
+ return -ERESTARTSYS;
+
+ if( count > FPGA_BUFFER_SIZE ) {
+ count = FPGA_BUFFER_SIZE;
+ }
+
+ // Get value to write from user space
+ ret = __copy_from_user( g_buffer, pData, count);
+ if (ret != 0) {
+ ret = -EFAULT;
+ goto out;
+ }
+
+ ret = xilinx_load( g_current_desc, g_buffer, count );
+
+out:
+ // Release exclusive access
+ up(&fpga_sema);
+
+ return( ret );
+}
+
+static int armadeus_fpga_open(struct inode *inode, struct file *file)
+{
+ int ret;
+
+ // Only one access at a time is permitted
+ if( g_nb_users > 0 )
+ return( -EBUSY );
+
+ g_nb_users++;
+ ret = xilinx_init_load( g_current_desc );
+
+ PRINTF("Opening /dev/fpga/loader%d file, %d %d\n", MINOR(inode->i_rdev), fpga_descriptor, ret);
+ return ret;
+}
+
+static int armadeus_fpga_release(struct inode *inode, struct file *file)
+{
+ if( g_nb_users > 0 )
+ g_nb_users--;
+
+ PRINTF("Closing access to /dev/fpga/loader%d\n", MINOR(inode->i_rdev));
+ return 0;
+}
+
+//------------------------------------------------
+// PROC file
+//
+static int procfile_fpga_read( char *buffer, __attribute__ ((unused)) char **start, off_t offset, int buffer_length, int *eof, __attribute__ ((unused)) void* data)
+{
+ int ret;
+
+ // We give all of our information in one go, so if the user asks us if we have more information the answer should always be no.
+ // This is important because the standard read function from the library would continue to issue the read system call until
+ // the kernel replies that it has no more information, or until its buffer is filled.
+ if( offset > 0 ) {
+ /* we have finished to read, return 0 */
+ ret = 0;
+ } else {
+ if ( data == NULL ){
+ ret = xilinx_get_descriptor_info( -1, buffer );
+ }
+ else {
+ ret = xilinx_get_descriptor_info( *((unsigned char*)data), buffer );
+ }
+ }
+
+ return ret;
+}
+
+
+static int procfile_fpga_write( __attribute__ ((unused)) struct file *file, const char *buf, unsigned long count, void *data)
+{
+ return count;
+}
+
+//------------------------------------------------
+// Handling of IOCTL calls
+//
+int armadeus_fpga_ioctl( struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg )
+{
+ int err = 0; int ret = 0;
+ unsigned int minor;
+
+ PRINTF( DRIVER_NAME " ## IOCTL received: (0x%x) ##\n", cmd );
+
+ // Extract the type and number bitfields, and don't decode wrong cmds: return ENOTTY (inappropriate ioctl) before access_ok()
+ if (_IOC_TYPE(cmd) != FPGA_IOCTL) return -ENOTTY;
+
+ // The direction is a bitmask, and VERIFY_WRITE catches R/W transfers. `Type' is user-oriented, while access_ok is kernel-oriented,
+ // so the concept of "read" and "write" is reversed
+ if (_IOC_DIR(cmd) & _IOC_READ)
+ err = !access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd));
+ else if (_IOC_DIR(cmd) & _IOC_WRITE)
+ err = !access_ok(VERIFY_READ, (void *)arg, _IOC_SIZE(cmd));
+
+ if (err) return -EFAULT;
+
+ // Obtain exclusive access
+ if (down_interruptible(&fpga_sema))
+ return -ERESTARTSYS;
+ // Extract and test minor
+ minor = MINOR(inode->i_rdev);
+ if( minor > FPGA_MAX_MINOR ) {
+ printk("Minor outside range: %d !\n", minor);
+ return -EFAULT;
+ }
+
+ switch(cmd)
+ {
+ default:
+ return -ENOTTY;
+ break;
+ }
+ // Release exclusive access
+ up(&fpga_sema);
+
+ return ret;
+}
+
+//
+// Create /proc entries for direct access (with echo/cat) to GPIOs config
+//
+static int createProcEntries( void )
+{
+ static struct proc_dir_entry *fpga_Proc_File;
+
+ // Create main directory
+ proc_mkdir(FPGA_PROC_DIRNAME, NULL);
+ // Create proc file to handle GPIO values
+ fpga_Proc_File = create_proc_entry( FPGA_PROC_FILENAME, S_IWUSR |S_IRUSR | S_IRGRP | S_IROTH, NULL );
+
+ if( fpga_Proc_File == NULL )
+ {
+ printk(FPGA_DRIVER_NAME ": Could not register a" FPGA_PROC_FILENAME ". Terminating\n");
+ armadeus_fpga_cleanup();
+ return -ENOMEM;
+ }
+ else
+ {
+ fpga_Proc_File->read_proc = procfile_fpga_read;
+ fpga_Proc_File->write_proc = procfile_fpga_write;
+ }
+
+ return(0);
+}
+
+static struct file_operations fpga_fops = {
+ .owner = THIS_MODULE,
+ .write = armadeus_fpga_write,
+// .read = armadeus_fpga_read,
+ .open = armadeus_fpga_open,
+ .release = armadeus_fpga_release,
+ .ioctl = armadeus_fpga_ioctl,
+};
+
+//
+// Module's initialization function
+//
+int __init armadeus_fpga_init(void)
+{
+ static int result;
+
+ // Register the driver by getting a major number
+ result = register_chrdev(fpga_major, FPGA_DRIVER_NAME, &fpga_fops);
+ if (result < 0)
+ {
+ printk(KERN_WARNING FPGA_DRIVER_NAME ": can't get major %d\n", fpga_major);
+ return result;
+ }
+ if( fpga_major == 0 ) fpga_major = result; // dynamic Major allocation
+
+ // Creating /proc entries
+ result = createProcEntries();
+ if( result < 0 ) return( result );
+
+ // Initialise FPGA semaphore
+ sema_init(&fpga_sema, 1);
+
+ // initialize the current fpga descriptor with the one by default
+ g_current_desc = xilinx_get_descriptor(fpga_descriptor);
+ if( g_current_desc == NULL ){
+ return -EINVAL;
+ }
+
+ printk(FPGA_DRIVER_NAME " module " FPGA_DRIVER_VERSION " successfully loaded !\n");
+ return(0);
+}
+
+//
+// Module's cleanup function
+//
+void __exit armadeus_fpga_cleanup(void)
+{
+ PRINTF("Removing " FPGA_DRIVER_NAME " module: ");
+
+ // Remove /proc entries
+ remove_proc_entry(FPGA_PROC_FILENAME, NULL);
+ // De-register /dev interface
+ unregister_chrdev(fpga_major, FPGA_DRIVER_NAME);
+
+ PRINTF("Ok !\n ");
+}
+
+//------------------------------------------------
+
+module_init(armadeus_fpga_init);
+module_exit(armadeus_fpga_cleanup);
+
+MODULE_AUTHOR("JB / NC");
+MODULE_DESCRIPTION("Armadeus fpga's loading driver");
+MODULE_LICENSE("GPL");
Added: trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpga-loader.h
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpga-loader.h (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpga-loader.h 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,40 @@
+/*
+ ***********************************************************************
+ *
+ * (c) Copyright 2006 Armadeus project
+ * Julien Boibessot <jul...@ar...>
+ * Nicolas Colombain <nic...@ar...>
+ * Generic Xilinx FPGA loader
+ *
+ * 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 __FPGA_LOADER_H__
+#define __FPGA_LOADER_H__
+
+#define FPGA_PROC_DIRNAME "driver/fpga"
+#define FPGA_PROC_FILENAME FPGA_PROC_DIRNAME "/loader"
+
+#define FPGA_DRIVER_VERSION "v0.0.6"
+#define FPGA_DRIVER_NAME "fpgaloader"
+
+// By default, we use dynamic allocation of major numbers
+#define FPGA_MAJOR 0
+#define FPGA_MAX_MINOR 254
+
+#define FPGA_IOCTL 0x10000000 // !! TO BE BETTER DEFINED !!
+
+#endif // __FPGA_LOADER_H__
Added: trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpgaloader.sh
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpgaloader.sh (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/fpgaloader.sh 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,11 @@
+#!/bin/sh
+# Load FPGA main module
+modprobe fpgaloader fpga_descriptor=0
+
+FPGA_MAJOR=`cat /proc/devices | grep fpgaloader | cut -d " " -f 1`
+mkdir -p /dev/fpga
+
+# For general usage
+if [ ! -e /dev/fpga/fpgaloader ] ; then
+ mknod /dev/fpga/fpgaloader c $FPGA_MAJOR 0
+fi
Added: trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/target-fpga-loader.c
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/target-fpga-loader.c (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/target-fpga-loader.c 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,116 @@
+/*
+ **********************************************************************
+ * 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.
+ **********************************************************************
+
+ (c) Copyright 2006 Armadeus project
+ Eric Jarrige <eri...@ar...>
+ Nicolas Colombain <nic...@ar...>
+ Target Xilinx FPGA support
+*/
+
+#include "target-fpga-loader.h"
+#include "xilinx-fpga-loader.h"
+#include <asm/arch/hardware.h>
+#include <asm/io.h>
+
+#define GPIO_PORT(x) ((x >> 5) & 3)
+#define GPIO_SET(x) (DR(GPIO_PORT(x)) |= (1<<(x & GPIO_PIN_MASK)))
+#define GPIO_CLEAR(x) (DR(GPIO_PORT(x)) &= ~(1<<(x & GPIO_PIN_MASK)))
+#define GPIO_WRITE(x,y) ( y ? GPIO_SET(x) : GPIO_CLEAR(x) )
+#define GPIO_READ(x) ((SSR (GPIO_PORT(x)) & (1<<(x & GPIO_PIN_MASK))))
+
+/*
+ * Set the FPGA's active-low program line to the specified level
+ */
+int fpga_pgm_fn( int assert )
+{
+ GPIO_WRITE( FPGA_PROGRAM, !assert);
+ return assert;
+}
+
+/*
+ * Set the FPGA's active-high clock line to the specified level
+ */
+int fpga_clk_fn( int assert_clk )
+{
+ GPIO_WRITE( FPGA_CLOCK, assert_clk);
+ return assert_clk;
+}
+
+/*
+ * Test the state of the active-low FPGA INIT line. Return 1 on INIT
+ * asserted (low).
+ */
+int fpga_init_fn( void )
+{
+ return(!GPIO_READ(FPGA_INIT));
+}
+
+/*
+ * Test the state of the active-high FPGA DONE pin
+ */
+int fpga_done_fn( void )
+{
+ return(GPIO_READ(FPGA_DONE));
+}
+
+/*
+ * Set the FPGA's data line to the specified level
+ */
+int fpga_wr_fn( int assert_write )
+{
+ GPIO_WRITE( FPGA_DIN, assert_write);
+ return assert_write;
+}
+
+int fpga_pre_fn( void )
+{
+ // Initialize GPIO pins
+ imx_gpio_mode (FPGA_INIT | GPIO_GIUS | GPIO_DR | GPIO_IN );
+ imx_gpio_mode (FPGA_DONE | GPIO_GIUS | GPIO_DR | GPIO_IN );
+ imx_gpio_mode (FPGA_DIN | GPIO_GIUS | GPIO_DR | GPIO_OUT );
+ imx_gpio_mode (FPGA_PROGRAM | GPIO_GIUS | GPIO_DR | GPIO_OUT );
+ imx_gpio_mode (FPGA_CLOCK | GPIO_GIUS | GPIO_DR | GPIO_OUT );
+ return 1;
+}
+
+
+Xilinx_Spartan_Slave_Serial_fns fpga_fns = {
+ fpga_pre_fn,
+ fpga_pgm_fn,
+ fpga_clk_fn,
+ fpga_init_fn,
+ fpga_done_fn,
+ fpga_wr_fn,
+};
+
+Xilinx_desc target_fpga_desc[NB_TARGET_DESC] = {
+
+ { // first supported configuration (default)
+ Xilinx_Spartan,
+ slave_serial,
+ XILINX_XC3S200_SIZE,
+ (void *) &fpga_fns
+ },
+
+ { // second one
+ Xilinx_Spartan,
+ slave_serial,
+ XILINX_XC3S400_SIZE,
+ (void *) &fpga_fns
+ }
+};
+
Added: trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/target-fpga-loader.h
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/target-fpga-loader.h (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/target-fpga-loader.h 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,40 @@
+/*
+ **********************************************************************
+ * 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.
+ **********************************************************************
+
+ (c) Copyright 2006 Armadeus project
+ Eric Jarrige <eri...@ar...>
+ Nicolas Colombain <nic...@ar...>
+ Target Xilinx FPGA support
+
+*/
+#ifndef __TARGET_FPGA_LOADER_H__
+#define __TARGET_FPGA_LOADER_H__
+
+
+#include "xilinx-fpga-loader.h"
+#include <asm/arch/imx-regs.h>
+#include <asm/io.h>
+
+#define FPGA_INIT (GPIO_PORTB | 15) /* FPGA init pin (SSI input) */
+#define FPGA_DONE (GPIO_PORTB | 16) /* FPGA done pin (SSI input) */
+#define FPGA_DIN (GPIO_PORTB | 17) /* FPGA data pin (SSI output) */
+#define FPGA_PROGRAM (GPIO_PORTB | 18) /* FPGA prog pin (SSI output) */
+#define FPGA_CLOCK (GPIO_PORTB | 19) /* FPGA clk pin (SSI output) */
+
+#define NB_TARGET_DESC 2
+
+#endif // __TARGET_FPGA_LOADER_H__
Added: trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/xilinx-fpga-loader.c
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/xilinx-fpga-loader.c (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/xilinx-fpga-loader.c 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,277 @@
+/*
+ * (c) Copyright 2006 Armadeus project
+ * Nicolas Colombain <nic...@ar...>
+ * Xilinx FPGA support
+ *
+ * Based on the implementation(uBoot) of:
+ * Rich Ireland, Enterasys Networks, rir...@en....
+ * Keith Outwater, kei...@mv...
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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 of
+ * the License, 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include "xilinx-fpga-loader.h"
+#include "target-fpga-loader.h"
+#include <asm/arch/imx-regs.h>
+#include <asm/io.h>
+#include <linux/time.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+
+#define CONFIG_FPGA_DELAY()
+#define CFG_FPGA_WAIT 4000 // uS
+
+size_t bytecount = 0; // total bytes received
+extern Xilinx_desc target_fpga_desc[]; // target descriptor table
+
+/*
+ * Timeout function
+ */
+static unsigned long get_timer(unsigned long initTime)
+{
+ struct timeval tv;
+ do_gettimeofday(&tv);
+ if( tv.tv_usec > initTime ) // avoid overflow pb
+ return tv.tv_usec - initTime;
+ else
+ return initTime - tv.tv_usec;
+}
+
+/*
+ * dump the given descriptor infos
+ */
+static int xilinx_dump_descriptor_info( Xilinx_desc *desc, char* buffer )
+{
+ int len;
+ len = sprintf( buffer, "%s %s %u\n",
+ (desc->family == Xilinx_Spartan) ? "spartan":"unknown",
+ (desc->iface == slave_serial) ? "slave serial":"unknown",
+ desc->size );
+ return len;
+}
+
+/**
+ * program the FPGA.
+ * return 0 if success, >0 while programming, <0 if error detected
+ */
+static size_t spartan_serial_load (Xilinx_desc *desc, const char* buf, size_t bsize)
+{
+ Xilinx_Spartan_Slave_Serial_fns *fn = desc->iface_fns;
+ if (fn) {
+ unsigned long ts; /* timestamp */
+
+ /* Load the data */
+ if( bytecount<=desc->size ) {
+ int i;
+ unsigned char val;
+ size_t nbbyte = 0; // init local counter
+
+ while (nbbyte < bsize) {
+
+ /* Xilinx detects an error if INIT goes low (active)
+ while DONE is low (inactive) */
+ if ((*fn->done)() == 0 && (*fn->init)()) {
+ PRINTF ("** CRC error during FPGA load.\n");
+ return -ETIMEDOUT;
+ }
+ val = buf[nbbyte ++];
+ bytecount++;
+ i = 8;
+ do {
+ /* Deassert the clock */
+ (*fn->clk)(0);
+ CONFIG_FPGA_DELAY ();
+ /* Write data */
+ (*fn->wr)(val & 0x80);
+ CONFIG_FPGA_DELAY ();
+ /* Assert the clock */
+ (*fn->clk)(1);
+ CONFIG_FPGA_DELAY ();
+ val <<= 1;
+ i --;
+ } while (i > 0);
+ }
+ }
+ if( bytecount>=desc->size )
+ {
+ CONFIG_FPGA_DELAY ();
+
+ /* now check for done signal */
+ ts = get_timer(0); /* get current time */
+ (*fn->wr)(1);
+
+ while (! (*fn->done)()) {
+ CONFIG_FPGA_DELAY ();
+ (*fn->clk)(0); /* Deassert the clock pin */
+ CONFIG_FPGA_DELAY ();
+ (*fn->clk)(1); /* Assert the clock pin */
+
+ if (get_timer (ts) > CFG_FPGA_WAIT) { /* check the time */
+ PRINTF ("** Timeout waiting for DONE.\n");
+ return -ETIMEDOUT;
+ }
+ }
+ }
+ return bsize;
+ }
+ return -EINVAL;
+}
+
+/**
+ * initialize the FPGA programming interface.
+ * return 0 if success, <0 if error detected
+ */
+static int spartan_serial_init (Xilinx_desc *desc)
+{
+ Xilinx_Spartan_Slave_Serial_fns *fn = desc->iface_fns;
+ if (fn) {
+ unsigned long ts; /* timestamp */
+
+ if(*fn->pre){
+ (*fn->pre)(); //Run the pre configuration function if there is one.
+ }
+
+ /* Establish the initial state */
+ (*fn->pgm)(1); /* Assert the program, commit */
+
+ /* Wait for INIT state (init low) */
+ ts = get_timer(0); /* get current time */
+ do {
+ CONFIG_FPGA_DELAY ();
+ if (get_timer (ts) > CFG_FPGA_WAIT) { /* check the time */
+ PRINTF ("** Timeout waiting for INIT to start.\n");
+ return -ETIMEDOUT;
+ }
+ } while (!(*fn->init)());
+
+ /* Get ready for the burn */
+ CONFIG_FPGA_DELAY ();
+ (*fn->pgm)(0); /* Deassert the program, commit */
+
+ ts = get_timer(0); /* get current time */
+ /* Now wait for INIT to go high */
+ do {
+ CONFIG_FPGA_DELAY ();
+ if (get_timer (ts) > CFG_FPGA_WAIT) { /* check the time */
+ PRINTF ("** Timeout waiting for INIT to clear.\n");
+ return -ETIMEDOUT;
+ }
+ } while ((*fn->init)());
+
+ bytecount = 0; // reset byte count
+ return 0; // success
+ }
+ return -EINVAL;
+}
+
+/**
+ * program the FPGA.
+ * return 0 if success, >0 while programming, <0 if error detected
+ */
+size_t xilinx_load( Xilinx_desc *desc, const char *buf, size_t bsize )
+{
+ int ret = 0;
+
+ if( desc ) {
+ switch( desc->family ) // check family
+ {
+ case Xilinx_Spartan:
+ {
+ switch( desc->iface ) // check donwload hardware interface
+ {
+ case slave_serial: ret = spartan_serial_load( desc, buf, bsize ); break;
+ default: PRINTF("interface not supported!\n"); ret = -ENOSYS; break;
+ }
+ }
+ break;
+ default: PRINTF("family not supported!\n"); ret = -ENOSYS; break;
+ }
+ }
+ else {
+ PRINTF("invalid FPGA descriptor!\n");
+ ret = -EINVAL;
+ }
+ return ret;
+}
+
+/**
+ * initialize the FPGA programming interface.
+ * return 0 if success, <0 if error detected
+ */
+int xilinx_init_load( Xilinx_desc *desc )
+{
+ int ret = 0;
+
+ if( desc ) {
+ switch( desc->family ) // check family
+ {
+ case Xilinx_Spartan:
+ {
+ switch( desc->iface ) // check donwload hardware interface
+ {
+ case slave_serial: ret = spartan_serial_init( desc ); break;
+ default: PRINTF("interface not supported!\n"); ret = -ENOSYS; break;
+ }
+ }
+ break;
+ default: PRINTF("family not supported!\n"); ret = -ENOSYS; break;
+ }
+ }
+ else {
+ PRINTF("invalid FPGA descriptor!\n");
+ ret = -EINVAL;
+ }
+ return ret;
+}
+
+/**
+ * get the descriptor corresponding to desc_id
+ * return NULL if error
+ */
+Xilinx_desc * xilinx_get_descriptor( unsigned char desc_id )
+{
+ if( desc_id < NB_TARGET_DESC ){
+ return &(target_fpga_desc[desc_id]);
+ }
+ return NULL;
+}
+
+/**
+ * get the descriptor infos
+ */
+int xilinx_get_descriptor_info( int desc_id, char* buffer )
+{
+ int len = 0;
+
+ if( desc_id >= 0 ) {
+ len = xilinx_dump_descriptor_info( &target_fpga_desc[desc_id], buffer );
+ }
+ else { // all desc requested
+ unsigned char i;
+ for( i=0; i<NB_TARGET_DESC; i++ ) {
+ len += xilinx_dump_descriptor_info( &target_fpga_desc[i], buffer+len );
+ }
+ }
+
+ return len;
+}
+
+
+
Added: trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/xilinx-fpga-loader.h
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/xilinx-fpga-loader.h (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpga_devtools/xilinx-fpga-loader.h 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,117 @@
+/*
+ * (c) Copyright 2006 Armadeus project
+ * Nicolas Colombain <nic...@ar...>
+ * Xilinx FPGA support
+ *
+ * Based on the implementation(uBoot) of:
+ * Rich Ireland, Enterasys Networks, rir...@en....
+ * Keith Outwater, kei...@mv...
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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 of
+ * the License, 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+#ifndef __XILINX_FPGA_H__
+#define __XILINX_FPGA_H__
+
+#include <linux/types.h>
+
+//#define FPGA_DEBUG
+#undef FPGA_DEBUG
+
+#ifdef FPGA_DEBUG
+#define PRINTF(fmt,args...) printk (fmt ,##args)
+#else
+#define PRINTF(fmt,args...)
+#endif
+
+
+
+/* Spartan-III */
+#define XILINX_XC3S50_SIZE 439264/8
+#define XILINX_XC3S200_SIZE 1047616/8
+#define XILINX_XC3S400_SIZE 1699136/8
+#define XILINX_XC3S1000_SIZE 3223488/8
+#define XILINX_XC3S1500_SIZE 5214784/8
+#define XILINX_XC3S2000_SIZE 7673024/8
+#define XILINX_XC3S4000_SIZE 11316864/8
+#define XILINX_XC3S5000_SIZE 13271936/8
+
+
+typedef enum { /* typedef Xilinx_iface */
+ min_xilinx_iface_type, /* low range check value */
+ slave_serial, /* serial data and external clock */
+ max_xilinx_iface_type /* insert all new types before this */
+} Xilinx_iface; /* end, typedef Xilinx_iface */
+
+typedef enum { /* typedef Xilinx_Family */
+ min_xilinx_type, /* low range check value */
+ Xilinx_Spartan, /* Spartan-II Family */
+ max_xilinx_type /* insert all new types before this */
+} Xilinx_Family; /* end, typedef Xilinx_Family */
+
+typedef struct { /* typedef Xilinx_desc */
+ Xilinx_Family family; /* part type */
+ Xilinx_iface iface; /* interface type */
+ size_t size; /* bytes of data part can accept */
+ void * iface_fns; /* interface function table */
+} Xilinx_desc; /* end, typedef Xilinx_desc */
+
+
+/** pointer to target specific low level function */
+typedef int (*Xilinx_pgm_fn)( int assert_pgm );
+typedef int (*Xilinx_init_fn)(void);
+typedef int (*Xilinx_done_fn)(void);
+typedef int (*Xilinx_clk_fn)( int assert_clk );
+typedef int (*Xilinx_wr_fn)( int assert_write );
+typedef int (*Xilinx_pre_fn)(void);
+
+/** struct of target specific low level functions */
+typedef struct {
+ Xilinx_pre_fn pre;
+ Xilinx_pgm_fn pgm;
+ Xilinx_clk_fn clk;
+ Xilinx_init_fn init;
+ Xilinx_done_fn done;
+ Xilinx_wr_fn wr;
+} Xilinx_Spartan_Slave_Serial_fns;
+
+/**
+ * program the FPGA.
+ * return 0 if success, >0 while programming, <0 if error detected
+ */
+size_t xilinx_load( Xilinx_desc *desc, const char *buf, size_t bsize );
+
+/**
+ * initialize the FPGA programming interface.
+ * return 0 if success, <0 if error detected
+ */
+int xilinx_init_load( Xilinx_desc *desc );
+
+/**
+ * get the descriptor infos, return the number of char placed in the buffer
+ */
+int xilinx_get_descriptor_info( int desc_id, char* buffer);
+
+/**
+ * get the descriptor corresponding to desc_id
+ * return NULL if error
+ */
+Xilinx_desc * xilinx_get_descriptor( unsigned char desc_id );
+
+#endif // __XILINX_FPGA_H__
Added: trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/.tmp_versions/fpgaaccess.mod
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/.tmp_versions/fpgaaccess.mod (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/.tmp_versions/fpgaaccess.mod 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,2 @@
+/home/fabien/armadeus/target/linux/modules/fpga/fpgaaccess/fpgaaccess.ko
+/home/fabien/armadeus/target/linux/modules/fpga/fpgaaccess/fpgaaccess.o
Added: trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/Kconfig
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/Kconfig (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/Kconfig 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,8 @@
+#
+#
+
+config ARMADEUS_FPGAACCESS_DRIVER
+ tristate "fpgaaccess driver"
+ default n
+ depends on ARMADEUS_FPGA_TEST
+ ---help---
Added: trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/Makefile
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/Makefile (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/Makefile 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,34 @@
+#
+# 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
+
+fpgaregs: fpgaregs.c
+ $(BASE_DIR)build_arm/staging_dir/bin/arm-linux-gcc -Wall fpgaregs.c -o fpgaregs
+
+clean:
+ rm -f *.*o \
+ rm -f Module.symvers
+
+endif
+
Property changes on: trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/Makefile
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaaccess.c
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaaccess.c (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaaccess.c 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,178 @@
+/*
+ ***********************************************************************
+ * 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;
+ u32 data=0;
+
+ if(*offp >= FPGA_SIZE || ((*offp)%2 != 0)){ /* offset must be pair */
+ return 0;
+ }
+
+ if(count > 4) /* 32bits max*/
+ count = 4;
+
+ if (count == 2)
+ data = ioread16(sdev->fpga_virtual_base_address + *offp);
+ else
+ data = ioread32(sdev->fpga_virtual_base_address + *offp);
+
+ /* return data for user */
+ if(copy_to_user(buff,&data,count)){
+ 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;
+ u32 data=0;
+
+ if(*offp >= FPGA_SIZE || ((*offp)%2 != 0)){ /* offset must be pair */
+ return 0;
+ }
+
+ if(count > 4) /* 32 bits max)*/
+ count = 4;
+
+ if(copy_from_user(&data,buff,count)){
+ printk(KERN_WARNING "write : copy from user error\n");
+ return -EFAULT;
+ }
+
+ if (count == 2)
+ iowrite16(data,sdev->fpga_virtual_base_address + *offp);
+ else
+ iowrite32(data,sdev->fpga_virtual_base_address + *offp);
+
+ return count;
+}
+
+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;
+ 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/dev_tools/fpgaaccess/fpgaaccess.h
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaaccess.h (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaaccess.h 2008-08-05 15:28:22 UTC (rev 868)
@@ -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);
Property changes on: trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaregs
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaregs.c
===================================================================
--- trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaregs.c (rev 0)
+++ trunk/target/linux/modules/fpga/dev_tools/fpgaaccess/fpgaregs.c 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,110 @@
+/************************************************************************
+ * a program to write/read 16/32bits 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>
+
+
+#define WORD_ACCESS (2)
+#define LONG_ACCESS (4)
+
+void displayResult(char* text, unsigned int accesstype, unsigned int value, unsigned int address)
+{
+ if( accesstype == WORD_ACCESS )
+ printf("%s %04x at %08x\n",text, (unsigned short)value,address);
+ else
+ printf("%s %08x at %08x\n",text, value,address);
+}
+
+
+int main(int argc, char *argv[])
+{
+ unsigned short address;
+ unsigned int value ;
+ int retval, error = EXIT_SUCCESS;
+ int ffpga, accesstype = LONG_ACCESS;
+
+ if((argc < 3) || (argc > 4)){
+ printf("invalid arguments number\nfpgaregs [w,l] fpga_reg_add [value].\n\tw: word access, l: long access\n\
+\tEx: fpgaregs w 0x10 0x1234, fpgaregs l 0x10 0x12345678\n");
+ exit(EXIT_FAILURE);
+ }
+
+ ffpga=open("/dev/fpgaaccess",O_RDWR);
+ if(ffpga<0){
+ printf("can't open file /dev/fpgaaccess\n");
+ exit(EXIT_FAILURE);
+ }
+
+ address = (unsigned int)strtol(argv[2], (char **)NULL, 16);
+
+ if(argc<3){
+ printf("invalid command line");
+ }
+ else {
+ if( *(argv[1]) == 'w' )
+ accesstype = WORD_ACCESS;
+
+ /* write value at address */
+ if(argc == 4){
+ value = strtoul(argv[3], (char **)NULL, 16);
+ retval = pwrite(ffpga,(void *)&value,accesstype,address);
+ if(retval<0){
+ printf("write error\n");
+ error = EXIT_FAILURE;
+ }
+ else
+ displayResult("Write", accesstype, value, address);
+
+ /* read address value */
+ }else if(argc == 3){
+ retval = pread(ffpga,(void *)&value,accesstype,address);
+ if(retval<0){
+ perror("Read error\n");
+ error = EXIT_FAILURE;
+ }
+ else
+ displayResult("Read", accesstype, value, address);
+ }
+ }
+ close(ffpga);
+ exit(error);
+}
+
Added: trunk/target/linux/modules/fpga/others/Kconfig
===================================================================
--- trunk/target/linux/modules/fpga/others/Kconfig (rev 0)
+++ trunk/target/linux/modules/fpga/others/Kconfig 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,17 @@
+#
+# Armadeus custom drivers configuration
+#
+#
+
+#
+config ARMADEUS_FPGA_OTHERS_DRIVERS
+ boolean "Others drivers for FPGA"
+ default n
+ depends on ARMADEUS_FPGA_DRIVERS
+ ---help---
+ All drivers for FPGA components
+
+source "drivers/armadeus/fpga/others/Wb_button/Kconfig"
+source "drivers/armadeus/fpga/others/Wb_led/Kconfig"
+source "drivers/armadeus/fpga/others/i2ctest/Kconfig"
+source "drivers/armadeus/fpga/others/ps2keyboard/Kconfig"
Added: trunk/target/linux/modules/fpga/others/Makefile
===================================================================
--- trunk/target/linux/modules/fpga/others/Makefile (rev 0)
+++ trunk/target/linux/modules/fpga/others/Makefile 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,41 @@
+#
+# Main Makefile for the Armadeus FPGA related drivers
+#
+# Add your subdirectories to obj- target
+#
+
+ifneq ($(KERNELRELEASE),)
+
+# Part executed when called from kernel build system:
+
+obj-$(CONFIG_ARMADEUS_FPGA_OTHERS_DRIVERS) += Wb_button/ Wb_led/ i2ctest/ ps2keyboard/
+
+else
+
+# Part executed when called from standard make in this directory:
+
+BASE_DIR:=../../../../buildroot/
+REL:=$(shell grep "BR2_PACKAGE_LINUX_VERSION=" $(BASE_DIR).config | \
+ sed -e 's/BR2_PACKAGE_LINUX_VERSION=//' | sed -e 's/"//g')
+#`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)
+ifeq ($(LINUX_DIR),)
+LINUX_DIR:=$(ARMADEUS_KERNEL_DIR)
+endif
+PWD:= $(shell pwd)
+
+default:
+ echo "Your Linux source dir is: $(LINUX_DIR)"
+ $(MAKE) -C $(LINUX_DIR) SUBDIRS=$(PWD) zImage modules
+
+clean:
+ echo "Your Linux source dir is: $(LINUX_DIR)"
+ $(MAKE) -C $(LINUX_DIR) SUBDIRS=$(PWD) clean
+
+install:
+ echo "Installing Armadeus drivers..."
+ $(MAKE) -C $(LINUX_DIR) SUBDIRS=$(PWD) INSTALL_MOD_PATH=$(TARGET_DIR) modules_install
+
+endif
+
Property changes on: trunk/target/linux/modules/fpga/others/Makefile
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/target/linux/modules/fpga/others/Wb_button/Kconfig
===================================================================
--- trunk/target/linux/modules/fpga/others/Wb_button/Kconfig (rev 0)
+++ trunk/target/linux/modules/fpga/others/Wb_button/Kconfig 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,8 @@
+#
+#
+
+config ARMADEUS_BUTTON_DRIVER
+ tristate "Wishbone Button driver"
+ default n
+ depends on ARMADEUS_FPGA_OTHERS_DRIVERS
+ ---help---
Added: trunk/target/linux/modules/fpga/others/Wb_button/Makefile
===================================================================
--- trunk/target/linux/modules/fpga/others/Wb_button/Makefile (rev 0)
+++ trunk/target/linux/modules/fpga/others/Wb_button/Makefile 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,38 @@
+#
+# Makefile for the Armadeus Wb_button 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_BUTTON_DRIVER) += button.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 button.ko /tftpboot/
+
+test:
+ ~/armadeus/buildroot/build_arm/staging_dir/bin/arm-linux-gcc testbutton.c -o testbutton
+ chmod 755 testbutton
+ cp testbutton /tftpboot/
+
+clean:
+ rm -f *.*o \
+ rm -f Module.symvers
+
+endif
+
Property changes on: trunk/target/linux/modules/fpga/others/Wb_button/Makefile
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/target/linux/modules/fpga/others/Wb_button/button.c
===================================================================
--- trunk/target/linux/modules/fpga/others/Wb_button/button.c (rev 0)
+++ trunk/target/linux/modules/fpga/others/Wb_button/button.c 2008-08-05 15:28:22 UTC (rev 868)
@@ -0,0 +1,226 @@
+/*
+ ***********************************************************************
+ *
+ * (c) Copyright 2007 Armadeus project
+ * Fabien Marteau <fab...@ar...>
+ * Driver for Wb_button 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.
+ **********************************************************************
+ */
+
+#include "button.h"
+
+/*********************************
+ * simple fpga read/write
+ *********************************/
+
+
+static ssize_t button_fpga_read(void * addr,u16 *data,struct button_dev *dev){
+ *data = ioread16(addr);/* read the button value */
+ return 2;
+}
+
+
+static ssize_t button_fpga_write(void * addr,u16 *data,struct button_dev *dev){
+ ssize_t retval;
+
+ iowrite16(*data,addr);/* write the button value */
+ retval = 2;
+ return retval;
+}
+
+/**********************************
+ * irq management
+ * awake read process
+ * *****...
[truncated message content] |