xilinx-selectmap.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Xilinx Spartan6 and 7 Series SelectMAP interface driver
  4. *
  5. * (C) 2024 Charles Perry <charles.perry@savoirfairelinux.com>
  6. *
  7. * Manage Xilinx FPGA firmware loaded over the SelectMAP configuration
  8. * interface.
  9. */
  10. #include "xilinx-core.h"
  11. #include <linux/gpio/consumer.h>
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/mod_devicetable.h>
  15. #include <linux/of.h>
  16. #include <linux/platform_device.h>
  17. struct xilinx_selectmap_conf {
  18. struct xilinx_fpga_core core;
  19. void __iomem *base;
  20. };
  21. #define to_xilinx_selectmap_conf(obj) \
  22. container_of(obj, struct xilinx_selectmap_conf, core)
  23. static int xilinx_selectmap_write(struct xilinx_fpga_core *core,
  24. const char *buf, size_t count)
  25. {
  26. struct xilinx_selectmap_conf *conf = to_xilinx_selectmap_conf(core);
  27. size_t i;
  28. for (i = 0; i < count; ++i)
  29. writeb(buf[i], conf->base);
  30. return 0;
  31. }
  32. static int xilinx_selectmap_probe(struct platform_device *pdev)
  33. {
  34. struct xilinx_selectmap_conf *conf;
  35. struct gpio_desc *gpio;
  36. void __iomem *base;
  37. conf = devm_kzalloc(&pdev->dev, sizeof(*conf), GFP_KERNEL);
  38. if (!conf)
  39. return -ENOMEM;
  40. conf->core.dev = &pdev->dev;
  41. conf->core.write = xilinx_selectmap_write;
  42. base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
  43. if (IS_ERR(base))
  44. return dev_err_probe(&pdev->dev, PTR_ERR(base),
  45. "ioremap error\n");
  46. conf->base = base;
  47. /* CSI_B is active low */
  48. gpio = devm_gpiod_get_optional(&pdev->dev, "csi", GPIOD_OUT_HIGH);
  49. if (IS_ERR(gpio))
  50. return dev_err_probe(&pdev->dev, PTR_ERR(gpio),
  51. "Failed to get CSI_B gpio\n");
  52. /* RDWR_B is active low */
  53. gpio = devm_gpiod_get_optional(&pdev->dev, "rdwr", GPIOD_OUT_HIGH);
  54. if (IS_ERR(gpio))
  55. return dev_err_probe(&pdev->dev, PTR_ERR(gpio),
  56. "Failed to get RDWR_B gpio\n");
  57. return xilinx_core_probe(&conf->core);
  58. }
  59. static const struct of_device_id xlnx_selectmap_of_match[] = {
  60. { .compatible = "xlnx,fpga-xc7s-selectmap", }, // Spartan-7
  61. { .compatible = "xlnx,fpga-xc7a-selectmap", }, // Artix-7
  62. { .compatible = "xlnx,fpga-xc7k-selectmap", }, // Kintex-7
  63. { .compatible = "xlnx,fpga-xc7v-selectmap", }, // Virtex-7
  64. {},
  65. };
  66. MODULE_DEVICE_TABLE(of, xlnx_selectmap_of_match);
  67. static struct platform_driver xilinx_selectmap_driver = {
  68. .driver = {
  69. .name = "xilinx-selectmap",
  70. .of_match_table = xlnx_selectmap_of_match,
  71. },
  72. .probe = xilinx_selectmap_probe,
  73. };
  74. module_platform_driver(xilinx_selectmap_driver);
  75. MODULE_LICENSE("GPL");
  76. MODULE_AUTHOR("Charles Perry <charles.perry@savoirfairelinux.com>");
  77. MODULE_DESCRIPTION("Load Xilinx FPGA firmware over SelectMap");