Project

General

Profile

FPGA Core Device Drivers

Critical Link provides the device driver code for our FPGA IP under the GPL license. The source code is included the the MDK/BSP installation files.

Linux Device Driver Architecture

Building the Drivers

The reference filesystems included in the MDK a kernel image (uImage) that will work with the Industrial I/O host board and a set of installed drivers. You can load FPGA modules simply by using the modprobe tool, e.g.,

root@mitydsp> modprobe fpga_ctrl
The drivers are located underneath the directory "/lib/modules/kernel-version-number/...".

If you have tailored or modified your kernel configuration, you may need to recompile the drivers in order to successfully install them. This is because the kernel and modules must agree on the location / layout of the kernel symbol table. You can rebuild the drivers using a valid ARM gcc tool chain and having installed the MDK/BSP. To build the kernel, change directories to "$MDK/sw/ARM/linux/drivers/fpga" and run the command:

root@buildmachine> make -C /path/to/your/kernel M=`pwd` ARCH=arm CROSS_COMPILE=arm-angstrom-linux-gnueabi- modules

The /path/to/your/kernel is typically $MDK/sw/ARM/linux/linux-davinci or ../../linux-davinci if you are compiling the kernel object from within the MDK directory.

That will create the kernel object files in the local directory. If your filesystem image is accessible (via NFS mount, etc.) from your build machine, you can also automatically install them using the "modules_install" target, e.g.,

root@buildmachine> make -C /path/to/your/kernel M=`pwd` ARCH=arm CROSS_COMPILE=arm-angstrom-linux-gnueabi- INSTALL_MOD_PATH=/path/to/your/target/rootfs modules_install

On your target, you'll need to update the module dependencies for modprobe to work correctly. Do this with the command "depmod -a".

Alternatively, you can copy the .ko files to a local directory and insert them using the "insmod" command.

FPGA SPI Core Example

  • Required Items:
    • The latest MDK, which can be downloaded from the Files section on this site.
      • If you are registered and logged in, there should be a "Files" tab at the top of this page.
    • An FPGA image with Critical Link's SPI core built in properly.
      • See $MDK/examples/industrial_io/fpga/vhdl/IndustrialIO_top.vhd for an example of proper core usage.
      • Note: Make sure that the SPI core you add to your project has the IRQ level selected to match ARM usage so that core is enumerated by Linux (IRQ Level = 0 for a core should make Linux enumerate the core by default).
    • Latest fpga_ctrl.ko and fpga_spi.ko kernel modules.
      • Note: Built kernel modules can be found in $MDK/images/modules/ directory.
    • A copy of the latest kernel source.
      • Details on building and obtaining the latest kernel can be found on the Linux_Kernel page.
  1. Create or edit an existing baseboard file in $kernel/arch/arm/mach-davinci
    • Note: For details on the baseboard files see Linux_Kernel.
  2. Add a structure to the baseboard file to describe the SPI device(s) that you want to be created:
    /**
     * Info for SPI devices on various FPGA chip selects.
     */
    static struct spi_board_info spifpga_info[] = {
            [0] = {
                    .modalias               = "spidev",
                    .max_speed_hz           = 1000000,
                    .bus_num                = 3,
                    .chip_select            = 0,
            },
            [1] = {
                    .modalias               = "spidev",
                    .max_speed_hz           = 10000000,
                    .bus_num                = 3,
                    .chip_select            = 1,
            },
            [2] = {
                    .modalias               = "spidev",
                    .max_speed_hz           = 10000000,
                    .bus_num                = 3,
                    .chip_select            = 2,
            },
            [3] = {
                    .modalias               = "spidev",
                    .max_speed_hz           = 10000000,
                    .bus_num                = 4,
                    .chip_select            = 0,
            },
    };
    
    • Note: When the FPGA SPI core is enumerated by fpga_ctrl.ko the bus_num defaults to start at 3 and increments by one for each successive core that is enumerated. Make sure that you take this into account in your spi_board_info struct array.
      • If you wish to change this default (i.e. to 4) specify the desired starting bus_num when inserting the kernel object:
        root@mityomapl138:~# insmod fpga_spi.ko bus_num=4
        
  3. Register the SPI board info in the baseboard_init() function:
    static int __init baseboard_init(void)
    {
    ...
            /* Register the FPGA spi devices for each chip select*/
            ret = spi_register_board_info(spifpga_info, ARRAY_SIZE(spifpga_info));
            if (ret)
                    pr_warning("%s: Unable to register SPI1 Info: %d", __func__,
                                    ret);
    ...
    }
    
  4. Make sure the modified baseboard is selected and rebuild the kernel.
    • See Linux_Kernel for details on selecting a different baseboard file.
  5. Load the newly built kernel and reboot your system.
  6. Once the system boots:
    1. Program the FPGA (see Programming_the_FPGA for details)
    2. Run the following commands:
      root@mityomapl138:~# insmod fpga_ctrl.ko
      root@mityomapl138:~# insmod fpga_spi.ko
      
  7. Files to access the different SPIs and their chip selects should have been created in /dev/
    root@mityomapl138:~# ls /dev/sp*
    /dev/spidev3.0  /dev/spidev3.1  /dev/spidev3.2  /dev/spidev4.0
    

FPGA GPIO Core Example

Reference: The_GPIO_Core

  • Required Items:
    • The latest MDK, which can be downloaded from the Files section on this site.
      • If you are registered and logged in, there should be a "Files" tab at the top of this page.
    • An FPGA image with Critical Link's GPIO core built in properly.
      • See $MDK/examples/industrial_io/fpga/vhdl/IndustrialIO_top.vhd for an example of proper core usage.
      • Note: Make sure that the GPIO core you add to your project has the IRQ level selected to match ARM usage so that core is enumerated by Linux (IRQ Level = 0 for a core should make Linux enumerate the core by default).
    • Latest fpga_ctrl.ko and fpga_gpio.ko kernel modules.
      • Note: Built kernel modules can be found in $MDK/images/modules/ directory.
    • Examples for modifying vhdl: https://support.criticallink.com/redmine/boards/12/topics/2224?r=2230#message-2230
  1. Load an FPGA image with a GPIO core component.
  2. Load the kernel modules:
    root@mityomapl138:~# insmod fpga_ctrl.ko
    root@mityomapl138:~# insmod fpga_gpio.ko
    
  3. Change directory to /sys/class/gpio
    • In addition to gpiochip0, gpiochip32, ..., gpiochip128, you should see gpiochip144.
    • The FPGA GPIO Core pins start at pin #144 on the Linux side of things.
      • So pin #144 will map to the first gpio in the first gpio core. The gpio core will then be connected to a net name which gets mapped to a fpga pin name in the .ucf file. See $MDK/examples/industrial_io/fpga/vhdl/IndustrialIO_rev_C.ucf for example.
  4. Create a file to access a GPIO Core pin (i.e. pin 146):
    root@mityomapl138:~# echo "146" > /sys/class/gpio/export
    
  5. Set directionality of pin to be an output:
    root@mityomapl138:~# echo "out" > /sys/class/gpio/gpio146/direction 
    
  6. Set output value for pin (there is also a polarity file you can echo to, but it's active high by default):
    root@mityomapl138:~# echo "1" > /sys/class/gpio/gpio146/value 
    
  7. For additional details on GPIO usage and options, read the kernel documentation located in the kernel source at linux-davinci/Documentation/gpio.txt.

Go to top
Add picture from clipboard (Maximum size: 1 GB)