Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/types.h>
- #include <linux/kdev_t.h>
- #include <linux/fs.h>
- #include <linux/device.h>
- #include <linux/cdev.h>
- #include <asm/uaccess.h>
- #include <linux/init.h>
- #include <linux/mutex.h>
- #include <linux/slab.h>
- #include <linux/string.h>
- #include <linux/interrupt.h>
- #include <linux/irq.h>
- #include <linux/spi/spi.h>
- #include <linux/gpio.h>
- #include "fpgaSPI.h"
- #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
- const char this_driver_name[] = "fpgaSPI";
- struct cardConfig
- {
- int cardPosition;
- int readLatch;
- int writeLatch;
- int bus;
- unsigned int interrupt;
- unsigned int irq;
- };
- static struct cardConfig cards[] =
- {
- {
- .cardPosition = 0,
- .readLatch = GPIO_TO_PIN(1,16),
- .writeLatch = GPIO_TO_PIN(1,17),
- .bus = 2,
- .interrupt = 60,
- },
- {
- .cardPosition = 1,
- .readLatch = GPIO_TO_PIN(3,21),
- .writeLatch = GPIO_TO_PIN(3,19),
- .bus = 2,
- },
- {
- .cardPosition = 2,
- .readLatch = GPIO_TO_PIN(1,6),
- .writeLatch = GPIO_TO_PIN(1,15),
- .bus = 1,
- },
- };
- /****************
- * IRQ Handling *
- ***************/
- static irqreturn_t fpgaSPI_irqHandler(int irq, void* devID)
- {
- pr_debug("%s: IRQ: %d\n", __func__, irq);
- return IRQ_HANDLED;
- }
- /*****************************************
- * Module Intialisation/Deinitialisation *
- *****************************************/
- static int __init fpgaSPI_init(void)
- {
- unsigned int irq_num;
- int status = 0;
- pr_debug("%s: Inititialising Driver fpgaSPI-v2\n", __func__);
- status = gpio_request_one(cards[0].interrupt, GPIOF_IN, "Card 0 Interrupt");
- if (status < 0)
- {
- pr_debug("%s: Failed to aquire gpio, bailing: -%d\n", __func__, status);
- return 0;
- }
- gpio_direction_input(cards[0].interrupt);
- irq_num = gpio_to_irq(cards[0].interrupt);
- if (irq_num < 0)
- {
- pr_debug("%s: Failed to aquire irq_num: -%d\n", __func__, irq_num);
- goto err0;
- }
- cards[0].irq = request_irq(irq_num, fpgaSPI_irqHandler, IRQF_SHARED | IRQF_TRIGGER_FALLING, "Card 0 Interrupt IRQ", NULL);
- if (cards[0].irq < 0)
- {
- pr_debug("%s: Failed to requst irq: %d\n", __func__, cards[0].irq);
- goto err0;
- }
- return 0;
- err0:
- gpio_free(cards[0].interrupt);
- return 0;
- }
- static void __exit fpgaSPI_exit(void)
- {
- gpio_free(cards[0].interrupt);
- if (cards[0].irq)
- {
- free_irq(cards[0].irq, NULL);
- }
- pr_debug("%s: Exiting Driver fpgaSPI-v2\n", __func__);
- }
- module_init(fpgaSPI_init);
- module_exit(fpgaSPI_exit);
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("Jack Mitchell <jack.mitchell@dbbroadcast.co.uk>");
- MODULE_DESCRIPTION("fpgaSPI driver");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement