msm_sharedmem.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Copyright (c) 2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #define pr_fmt(fmt) "%s: " fmt, __func__
  13. #include <linux/uio_driver.h>
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/err.h>
  17. #define DRIVER_NAME "msm_sharedmem"
  18. static int msm_sharedmem_probe(struct platform_device *pdev)
  19. {
  20. int ret = 0;
  21. struct uio_info *info = NULL;
  22. struct resource *clnt_res = NULL;
  23. /* Get the addresses from platform-data */
  24. if (!pdev->dev.of_node) {
  25. pr_err("Node not found\n");
  26. ret = -ENODEV;
  27. goto out;
  28. }
  29. clnt_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  30. if (!clnt_res) {
  31. pr_err("resource not found\n");
  32. return -ENODEV;
  33. }
  34. info = devm_kzalloc(&pdev->dev, sizeof(struct uio_info), GFP_KERNEL);
  35. if (!info)
  36. return -ENOMEM;
  37. info->name = clnt_res->name;
  38. info->version = "1.0";
  39. info->mem[0].addr = clnt_res->start;
  40. info->mem[0].size = resource_size(clnt_res);
  41. info->mem[0].memtype = UIO_MEM_PHYS;
  42. /* Setup device */
  43. ret = uio_register_device(&pdev->dev, info);
  44. if (ret)
  45. goto out;
  46. dev_set_drvdata(&pdev->dev, info);
  47. pr_debug("Device created for client '%s'\n", clnt_res->name);
  48. out:
  49. return ret;
  50. }
  51. static int msm_sharedmem_remove(struct platform_device *pdev)
  52. {
  53. struct uio_info *info = dev_get_drvdata(&pdev->dev);
  54. uio_unregister_device(info);
  55. return 0;
  56. }
  57. static struct of_device_id msm_sharedmem_of_match[] = {
  58. {.compatible = "qcom,sharedmem-uio",},
  59. {},
  60. };
  61. MODULE_DEVICE_TABLE(of, msm_sharedmem_of_match);
  62. static struct platform_driver msm_sharedmem_driver = {
  63. .probe = msm_sharedmem_probe,
  64. .remove = msm_sharedmem_remove,
  65. .driver = {
  66. .name = DRIVER_NAME,
  67. .owner = THIS_MODULE,
  68. .of_match_table = msm_sharedmem_of_match,
  69. },
  70. };
  71. module_platform_driver(msm_sharedmem_driver);
  72. MODULE_LICENSE("GPL v2");