fmc-trivial.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C) 2012 CERN (www.cern.ch)
  3. * Author: Alessandro Rubini <rubini@gnudd.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * The software is provided "as is"; the copyright holders disclaim
  10. * all warranties and liabilities, to the extent permitted by
  11. * applicable law.
  12. */
  13. /* A trivial fmc driver that can load a gateware file and reports interrupts */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/gpio.h>
  18. #include <linux/fmc.h>
  19. static struct fmc_driver t_drv; /* initialized later */
  20. static irqreturn_t t_handler(int irq, void *dev_id)
  21. {
  22. struct fmc_device *fmc = dev_id;
  23. fmc->op->irq_ack(fmc);
  24. dev_info(&fmc->dev, "received irq %i\n", irq);
  25. return IRQ_HANDLED;
  26. }
  27. static struct fmc_gpio t_gpio[] = {
  28. {
  29. .gpio = FMC_GPIO_IRQ(0),
  30. .mode = GPIOF_DIR_IN,
  31. .irqmode = IRQF_TRIGGER_RISING,
  32. }, {
  33. .gpio = FMC_GPIO_IRQ(1),
  34. .mode = GPIOF_DIR_IN,
  35. .irqmode = IRQF_TRIGGER_RISING,
  36. }
  37. };
  38. static int t_probe(struct fmc_device *fmc)
  39. {
  40. int ret;
  41. int index = 0;
  42. if (fmc->op->validate)
  43. index = fmc->op->validate(fmc, &t_drv);
  44. if (index < 0)
  45. return -EINVAL; /* not our device: invalid */
  46. ret = fmc->op->irq_request(fmc, t_handler, "fmc-trivial", IRQF_SHARED);
  47. if (ret < 0)
  48. return ret;
  49. /* ignore error code of call below, we really don't care */
  50. fmc->op->gpio_config(fmc, t_gpio, ARRAY_SIZE(t_gpio));
  51. /* Reprogram, if asked to. ESRCH == no filename specified */
  52. ret = -ESRCH;
  53. if (fmc->op->reprogram)
  54. ret = fmc->op->reprogram(fmc, &t_drv, "");
  55. if (ret == -ESRCH)
  56. ret = 0;
  57. if (ret < 0)
  58. fmc->op->irq_free(fmc);
  59. /* FIXME: reprogram LM32 too */
  60. return ret;
  61. }
  62. static int t_remove(struct fmc_device *fmc)
  63. {
  64. fmc->op->irq_free(fmc);
  65. return 0;
  66. }
  67. static struct fmc_driver t_drv = {
  68. .version = FMC_VERSION,
  69. .driver.name = KBUILD_MODNAME,
  70. .probe = t_probe,
  71. .remove = t_remove,
  72. /* no table, as the current match just matches everything */
  73. };
  74. /* We accept the generic parameters */
  75. FMC_PARAM_BUSID(t_drv);
  76. FMC_PARAM_GATEWARE(t_drv);
  77. static int t_init(void)
  78. {
  79. int ret;
  80. ret = fmc_driver_register(&t_drv);
  81. return ret;
  82. }
  83. static void t_exit(void)
  84. {
  85. fmc_driver_unregister(&t_drv);
  86. }
  87. module_init(t_init);
  88. module_exit(t_exit);
  89. MODULE_LICENSE("Dual BSD/GPL");