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/of.h>
- #include <linux/interrupt.h>
- #include <linux/irq.h>
- #include <linux/spi/spi.h>
- #include <linux/gpio.h>
- #include <linux/pinctrl/consumer.h>
- #include "r0005spi.h"
- #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
- const char this_driver_name[] = "r0005spi";
- static int r0005spi_probe(struct spi_device *pdev);
- static int r0005spi_remove(struct spi_device *pdev);
- static const struct of_device_id db_r0005spi_of_ids[] = {
- {
- .compatible = "dbbroadcast,r0005spi",
- },
- { },
- };
- MODULE_DEVICE_TABLE(of, db_r0005spi_of_ids);
- static struct spi_driver r0005spi_driver =
- {
- .driver = {
- .name = this_driver_name,
- .owner = THIS_MODULE,
- .of_match_table = db_r0005spi_of_ids,
- },
- .probe = r0005spi_probe,
- .remove = r0005spi_remove,
- };
- static struct card_config 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 r0005spi_irq_handler(int irq, void* devID)
- {
- pr_debug("%s: IRQ: %d\n", __func__, irq);
- return IRQ_HANDLED;
- }
- /***********
- * Probing *
- * ********/
- static int r0005spi_probe(struct spi_device *spi)
- {
- struct device_node *np = spi->dev.of_node;
- struct device_node *nc;
- pr_debug("%s: SPI Bus: %d probed\n", __func__, spi->master->bus_num);
- if (IS_ERR(np))
- {
- pr_debug("%s: Failed to get parent node\n", __func__);
- }
- pr_debug("%s: Got node %s\n", __func__, np->name);
- for_each_child_of_node(np, nc)
- {
- pr_debug("%s: Found node\n", __func__);
- }
- return 0;
- }
- static int r0005spi_remove(struct spi_device *pdev)
- {
- pr_debug("%s: Removed\n", __func__);
- return 0;
- }
- /*****************************************
- * Module Intialisation/Deinitialisation *
- *****************************************/
- static int r0005spi_init(void)
- {
- pr_debug("%s: Inititialising Driver r0005spi\n", __func__);
- return spi_register_driver(&r0005spi_driver);
- }
- static void r0005spi_exit(void)
- {
- spi_unregister_driver(&r0005spi_driver);
- pr_debug("%s: Exiting Driver r0005spi\n", __func__);
- }
- module_init(r0005spi_init);
- module_exit(r0005spi_exit);
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("Jack Mitchell <jack.mitchell@dbbroadcast.co.uk>");
- MODULE_DESCRIPTION("r0005spi driver");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement