galileo-spi1-spidev.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Register spidev userspace driver with SPI channel 1
  3. *
  4. * Copyright (c) Siemens AG, 2016
  5. *
  6. * Authors:
  7. * Jan Kiszka <jan.kiszka@siemens.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2. See
  10. * the COPYING file in the top-level directory.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/spi/pxa2xx_spi.h>
  14. #include <linux/spi/spi.h>
  15. static struct spi_device *spi_device;
  16. /* Option to allow GPIO 10 to be used for SPI1 chip-select */
  17. static int gpio_cs;
  18. module_param(gpio_cs, int, S_IRUGO | S_IWUSR);
  19. MODULE_PARM_DESC(gpio_cs, "Enable GPIO chip-select for SPI channel 1");
  20. static struct pxa2xx_spi_chip qrk_ffrd_spi_1_cs_0 = {
  21. .gpio_cs = 10,
  22. };
  23. static struct spi_board_info spi1_dev_gpiocs = {
  24. .modalias = "spidev",
  25. .chip_select = 0,
  26. .controller_data = &qrk_ffrd_spi_1_cs_0,
  27. .max_speed_hz = 50000000,
  28. .bus_num = 169,
  29. };
  30. static struct spi_board_info spi1_dev = {
  31. .modalias = "spidev",
  32. .chip_select = 0,
  33. .controller_data = NULL,
  34. .max_speed_hz = 50000000,
  35. .bus_num = 169,
  36. };
  37. int init_module(void)
  38. {
  39. struct spi_board_info *info;
  40. struct spi_master *master;
  41. if (gpio_cs)
  42. info = &spi1_dev_gpiocs;
  43. else
  44. info = &spi1_dev;
  45. master = spi_busnum_to_master(info->bus_num);
  46. if (!master)
  47. return -EINVAL;
  48. spi_device = spi_new_device(master, info);
  49. put_device(&master->dev);
  50. if (!spi_device)
  51. return -EPERM;
  52. return 0;
  53. }
  54. void cleanup_module(void)
  55. {
  56. spi_unregister_device(spi_device);
  57. }
  58. MODULE_LICENSE("GPL");