shdma-of.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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,
  31. (void *)(uintptr_t)id);
  32. if (chan)
  33. to_shdma_chan(chan)->hw_req = id;
  34. return chan;
  35. }
  36. static int shdma_of_probe(struct platform_device *pdev)
  37. {
  38. const struct of_dev_auxdata *lookup = dev_get_platdata(&pdev->dev);
  39. int ret;
  40. ret = of_dma_controller_register(pdev->dev.of_node,
  41. shdma_of_xlate, pdev);
  42. if (ret < 0)
  43. return ret;
  44. ret = of_platform_populate(pdev->dev.of_node, NULL, lookup, &pdev->dev);
  45. if (ret < 0)
  46. of_dma_controller_free(pdev->dev.of_node);
  47. return ret;
  48. }
  49. static const struct of_device_id shdma_of_match[] = {
  50. { .compatible = "renesas,shdma-mux", },
  51. { }
  52. };
  53. MODULE_DEVICE_TABLE(of, sh_dmae_of_match);
  54. static struct platform_driver shdma_of = {
  55. .driver = {
  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>");