qcom_gsbi.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2014, The Linux foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License rev 2 and
  6. * only rev 2 as published by the free Software foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or fITNESS fOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/err.h>
  15. #include <linux/io.h>
  16. #include <linux/module.h>
  17. #include <linux/of.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/platform_device.h>
  20. #define GSBI_CTRL_REG 0x0000
  21. #define GSBI_PROTOCOL_SHIFT 4
  22. struct gsbi_info {
  23. struct clk *hclk;
  24. u32 mode;
  25. u32 crci;
  26. };
  27. static int gsbi_probe(struct platform_device *pdev)
  28. {
  29. struct device_node *node = pdev->dev.of_node;
  30. struct resource *res;
  31. void __iomem *base;
  32. struct gsbi_info *gsbi;
  33. gsbi = devm_kzalloc(&pdev->dev, sizeof(*gsbi), GFP_KERNEL);
  34. if (!gsbi)
  35. return -ENOMEM;
  36. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  37. base = devm_ioremap_resource(&pdev->dev, res);
  38. if (IS_ERR(base))
  39. return PTR_ERR(base);
  40. if (of_property_read_u32(node, "qcom,mode", &gsbi->mode)) {
  41. dev_err(&pdev->dev, "missing mode configuration\n");
  42. return -EINVAL;
  43. }
  44. /* not required, so default to 0 if not present */
  45. of_property_read_u32(node, "qcom,crci", &gsbi->crci);
  46. dev_info(&pdev->dev, "GSBI port protocol: %d crci: %d\n",
  47. gsbi->mode, gsbi->crci);
  48. gsbi->hclk = devm_clk_get(&pdev->dev, "iface");
  49. if (IS_ERR(gsbi->hclk))
  50. return PTR_ERR(gsbi->hclk);
  51. clk_prepare_enable(gsbi->hclk);
  52. writel_relaxed((gsbi->mode << GSBI_PROTOCOL_SHIFT) | gsbi->crci,
  53. base + GSBI_CTRL_REG);
  54. /* make sure the gsbi control write is not reordered */
  55. wmb();
  56. platform_set_drvdata(pdev, gsbi);
  57. return of_platform_populate(node, NULL, NULL, &pdev->dev);
  58. }
  59. static int gsbi_remove(struct platform_device *pdev)
  60. {
  61. struct gsbi_info *gsbi = platform_get_drvdata(pdev);
  62. clk_disable_unprepare(gsbi->hclk);
  63. return 0;
  64. }
  65. static const struct of_device_id gsbi_dt_match[] = {
  66. { .compatible = "qcom,gsbi-v1.0.0", },
  67. { },
  68. };
  69. MODULE_DEVICE_TABLE(of, gsbi_dt_match);
  70. static struct platform_driver gsbi_driver = {
  71. .driver = {
  72. .name = "gsbi",
  73. .of_match_table = gsbi_dt_match,
  74. },
  75. .probe = gsbi_probe,
  76. .remove = gsbi_remove,
  77. };
  78. module_platform_driver(gsbi_driver);
  79. MODULE_AUTHOR("Andy Gross <agross@codeaurora.org>");
  80. MODULE_DESCRIPTION("QCOM GSBI driver");
  81. MODULE_LICENSE("GPL v2");