shdma-of.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * SHDMA Device Tree glue
  3. *
  4. * Copyright (C) 2013 Renesas Electronics Inc.
  5. * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/dmaengine.h>
  12. #include <linux/module.h>
  13. #include <linux/of.h>
  14. #include <linux/of_dma.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/shdma-base.h>
  18. #define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
  19. static struct dma_chan *shdma_of_xlate(struct of_phandle_args *dma_spec,
  20. struct of_dma *ofdma)
  21. {
  22. u32 id = dma_spec->args[0];
  23. dma_cap_mask_t mask;
  24. struct dma_chan *chan;
  25. if (dma_spec->args_count != 1)
  26. return NULL;
  27. dma_cap_zero(mask);
  28. /* Only slave DMA channels can be allocated via DT */
  29. dma_cap_set(DMA_SLAVE, mask);
  30. chan = dma_request_channel(mask, shdma_chan_filter, (void *)id);
  31. if (chan)
  32. to_shdma_chan(chan)->hw_req = id;
  33. return chan;
  34. }
  35. static int shdma_of_probe(struct platform_device *pdev)
  36. {
  37. const struct of_dev_auxdata *lookup = dev_get_platdata(&pdev->dev);
  38. int ret;
  39. ret = of_dma_controller_register(pdev->dev.of_node,
  40. shdma_of_xlate, pdev);
  41. if (ret < 0)
  42. return ret;
  43. ret = of_platform_populate(pdev->dev.of_node, NULL, lookup, &pdev->dev);
  44. if (ret < 0)
  45. of_dma_controller_free(pdev->dev.of_node);
  46. return ret;
  47. }
  48. static const struct of_device_id shdma_of_match[] = {
  49. { .compatible = "renesas,shdma-mux", },
  50. { }
  51. };
  52. MODULE_DEVICE_TABLE(of, sh_dmae_of_match);
  53. static struct platform_driver shdma_of = {
  54. .driver = {
  55. .owner = THIS_MODULE,
  56. .name = "shdma-of",
  57. .of_match_table = shdma_of_match,
  58. },
  59. .probe = shdma_of_probe,
  60. };
  61. module_platform_driver(shdma_of);
  62. MODULE_LICENSE("GPL v2");
  63. MODULE_DESCRIPTION("SH-DMA driver DT glue");
  64. MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");