fmc-trivial.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_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. index = fmc_validate(fmc, &t_drv);
  43. if (index < 0)
  44. return -EINVAL; /* not our device: invalid */
  45. ret = fmc_irq_request(fmc, t_handler, "fmc-trivial", IRQF_SHARED);
  46. if (ret < 0)
  47. return ret;
  48. /* ignore error code of call below, we really don't care */
  49. fmc_gpio_config(fmc, t_gpio, ARRAY_SIZE(t_gpio));
  50. ret = fmc_reprogram(fmc, &t_drv, "", 0);
  51. if (ret == -EPERM) /* programming not supported */
  52. ret = 0;
  53. if (ret < 0)
  54. fmc_irq_free(fmc);
  55. /* FIXME: reprogram LM32 too */
  56. return ret;
  57. }
  58. static int t_remove(struct fmc_device *fmc)
  59. {
  60. fmc_irq_free(fmc);
  61. return 0;
  62. }
  63. static struct fmc_driver t_drv = {
  64. .version = FMC_VERSION,
  65. .driver.name = KBUILD_MODNAME,
  66. .probe = t_probe,
  67. .remove = t_remove,
  68. /* no table, as the current match just matches everything */
  69. };
  70. /* We accept the generic parameters */
  71. FMC_PARAM_BUSID(t_drv);
  72. FMC_PARAM_GATEWARE(t_drv);
  73. static int t_init(void)
  74. {
  75. int ret;
  76. ret = fmc_driver_register(&t_drv);
  77. return ret;
  78. }
  79. static void t_exit(void)
  80. {
  81. fmc_driver_unregister(&t_drv);
  82. }
  83. module_init(t_init);
  84. module_exit(t_exit);
  85. MODULE_LICENSE("Dual BSD/GPL");