Tanure

dma test driver

Apr 23rd, 2020
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. /*
  2. * Test SPI DMA
  3. *
  4. * Copyright (C) 2020 Cirrus Logic, Inc. and
  5. * Cirrus Logic International Semiconductor Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11.  
  12. #include <linux/module.h>
  13. #include <linux/err.h>
  14. #include <linux/spi/spi.h>
  15. #include <linux/regmap.h>
  16.  
  17. #define TEST_SIZE 20428
  18.  
  19. static struct regmap_config test_spi_regmap = {
  20. .name = "test_spi",
  21. .reg_bits = 32,
  22. .pad_bits = 32,
  23. .val_bits = 32,
  24. .reg_stride = 4,
  25.  
  26. .max_register = 0xFFFFFFFF,
  27. .cache_type = REGCACHE_NONE,
  28. };
  29.  
  30. static int test_spi_probe(struct spi_device *spi)
  31. {
  32. int i, ret = 0;
  33. struct regmap *regmap;
  34. char *buffer;
  35. char *buffer2;
  36.  
  37. pr_info("%s",__func__);
  38.  
  39. regmap = devm_regmap_init_spi(spi, &test_spi_regmap);
  40. if (IS_ERR(regmap)) {
  41. ret = PTR_ERR(regmap);
  42. dev_err(&spi->dev, "Failed to allocate register map: %d\n", ret);
  43. }
  44.  
  45. buffer = vmalloc(TEST_SIZE);
  46. buffer2 = kmalloc(TEST_SIZE, GFP_KERNEL);
  47. for (i = 0; i < TEST_SIZE; i++){
  48. buffer[i] = i % 0xff;
  49. buffer2[i] = i % 0xff;
  50. }
  51.  
  52. regmap_raw_write(regmap, 0, buffer, TEST_SIZE);
  53.  
  54. mdelay(50);
  55.  
  56. regmap_raw_write(regmap, 0, buffer2, TEST_SIZE);
  57.  
  58. kfree(buffer);
  59.  
  60. return ret;
  61. }
  62.  
  63. static const struct of_device_id test_spi_match[] = {
  64. { .compatible = "spi-dma-test", },
  65. {},
  66. };
  67. MODULE_DEVICE_TABLE(of, test_spi_match);
  68.  
  69. static struct spi_driver test_spi_driver = {
  70. .driver = {
  71. .name = "spi-dma-test",
  72. .of_match_table = test_spi_match,
  73. },
  74. .probe = &test_spi_probe,
  75. };
  76.  
  77. module_spi_driver(test_spi_driver);
  78.  
  79. MODULE_DESCRIPTION("Test RPI4 SPI BUG");
  80. MODULE_AUTHOR("Lucas Tanure <[email protected]>");
  81. MODULE_LICENSE("GPL v2");
  82.  
  83.  
  84.  
  85. ###################################################################################################
  86. Device tree
  87.  
  88. /dts-v1/;
  89. /plugin/;
  90.  
  91. / {
  92. compatible = "brcm,bcm2835";
  93.  
  94. fragment@0 {
  95. target = <&spi0>;
  96. __overlay__ {
  97. #address-cells = <1>;
  98. #size-cells = <0>;
  99. status = "okay";
  100.  
  101. spidev@1{
  102. status = "disabled";
  103. };
  104.  
  105. spi_test@1{
  106. spi-max-frequency = <12500000>;
  107. reg = <1>;
  108. compatible = "spi-dma-test";
  109. };
  110. };
  111. };
  112. };
Advertisement
Add Comment
Please, Sign In to add comment