add raggedstone fpga device support

git-svn-id: svn+ssh://en.codiert.org/home/staff/ben/dev/misc.svn/projects/fpgafs@385 766a2236-cff9-0310-b0c0-a81a5f92509a
This commit is contained in:
ben 2007-09-08 19:18:53 +00:00
parent 971209b04e
commit 638cd927bb
2 changed files with 124 additions and 0 deletions

View File

@ -9,6 +9,7 @@ fpgafs-objs := files.o inode.o llmgmt.o
# low level driver
obj-m += fpgafs_lldrv_dbg.o
obj-m += fpgafs_lldrv_cham.o
obj-m += fpgafs_lldrv_rag.o
all :
$(MAKE) -C $(KERNEL_BUILDROOT) SUBDIRS=$(BUILDROOT) modules

123
fpgafs_lldrv_rag.c Normal file
View File

@ -0,0 +1,123 @@
/*********************************************
* Benjamin Krill <ben@codiert.org>
*********************************************/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/pci.h>
#include "fpgafs.h"
#define VENDOR_ID_ALTERA 0x1172
#define DEVICE_ID_ALTERA 0x0100
static void *vaddr = 0;
static unsigned long memstart = 0, memlen = 0;
/* len must 2 or higher ... */
static int fpgafs_send_data_rag(struct fpga_context *ctx, const char __user *buf, int len)
{
int i;
for(i=0; i < len; i+=2)
writew((buf[i+1] << 8)|buf[i], vaddr);
return i;
}
/* len must 2 or higher ... */
static int fpgafs_recv_data_rag(struct fpga_context *ctx, unsigned char *buf, int len)
{
int i; unsigned short d;
for(i=0; i < len; i+=2) {
d=readw((void *)((unsigned int)vaddr | 0x20));
buf[i] = d & 0xff;
buf[i+1] = d >> 8;
}
return i;
}
int fpgafs_device_probe_rag(struct pci_dev *dev, const struct pci_device_id *id)
{
int ret;
ret = pci_enable_device(dev);
if (ret < 0) {
printk(KERN_WARNING "FPGAFS_RAG: unable to initialize PCI device\n");
return ret;
}
ret = pci_request_regions(dev, "FPGAFS_RAG");
if (ret < 0) {
printk(KERN_WARNING "FPGAFS_RAG: unable to reserve PCI resources\n");
pci_disable_device(dev);
return ret;
}
memstart = pci_resource_start(dev, 0); /* 0 for BAR0 */
memlen = pci_resource_len(dev, 0);
printk(KERN_WARNING "FPGAFS_RAG: memstart=0x%lx memlen=%li\n", memstart, memlen);
vaddr = ioremap(memstart, memlen);
printk(KERN_INFO "FPGAFS_RAG: device_probe successful\n");
return ret;
}
void fpgafs_device_remove_rag(struct pci_dev *dev)
{
iounmap(vaddr);
pci_release_regions(dev);
pci_disable_device(dev);
printk(KERN_INFO "FPGAFS_RAG: device removed\n");
}
static struct pci_device_id pci_device_id_fpgafs_rag[] =
{
{VENDOR_ID_ALTERA, DEVICE_ID_ALTERA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
{} /* EOL */
};
struct pci_driver pci_driver_fpgafs_rag =
{
name: "FPGAFS_RAG",
id_table: pci_device_id_fpgafs_rag,
probe: fpgafs_device_probe_rag,
remove: fpgafs_device_remove_rag
};
static int fpgafs_init_rag(void)
{
printk(KERN_INFO "FPGFS_RAG: PCI init\n");
return pci_register_driver(&pci_driver_fpgafs_rag);
}
static int fpgafs_exit_rag(void)
{
printk(KERN_INFO "FPGFS_RAG: PCI fini\n");
pci_unregister_driver(&pci_driver_fpgafs_rag);
return 0;
}
static struct fpgafs_lldrv fpgafs_lldrv_rag = {
.name = "rag",
.init = &fpgafs_init_rag,
.exit = &fpgafs_exit_rag,
.send = &fpgafs_send_data_rag,
.recv = &fpgafs_recv_data_rag,
.read_load = NULL,
.write_load = NULL,
};
/* init exit functions ... */
int __init fpgafs_lldrv_rag_init(void)
{
return fpgafs_register_lldrv(&fpgafs_lldrv_rag);
}
void __exit fpgafs_lldrv_rag_exit(void)
{
fpgafs_unregister_lldrv(&fpgafs_lldrv_rag);
}
module_init(fpgafs_lldrv_rag_init);
module_exit(fpgafs_lldrv_rag_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Benjamin Krill <ben@codiert.org>");