qcom_gsbi.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. static int gsbi_probe(struct platform_device *pdev)
  23. {
  24. struct device_node *node = pdev->dev.of_node;
  25. struct resource *res;
  26. void __iomem *base;
  27. struct clk *hclk;
  28. u32 mode, crci = 0;
  29. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  30. base = devm_ioremap_resource(&pdev->dev, res);
  31. if (IS_ERR(base))
  32. return PTR_ERR(base);
  33. if (of_property_read_u32(node, "qcom,mode", &mode)) {
  34. dev_err(&pdev->dev, "missing mode configuration\n");
  35. return -EINVAL;
  36. }
  37. /* not required, so default to 0 if not present */
  38. of_property_read_u32(node, "qcom,crci", &crci);
  39. dev_info(&pdev->dev, "GSBI port protocol: %d crci: %d\n", mode, crci);
  40. hclk = devm_clk_get(&pdev->dev, "iface");
  41. if (IS_ERR(hclk))
  42. return PTR_ERR(hclk);
  43. clk_prepare_enable(hclk);
  44. writel_relaxed((mode << GSBI_PROTOCOL_SHIFT) | crci,
  45. base + GSBI_CTRL_REG);
  46. /* make sure the gsbi control write is not reordered */
  47. wmb();
  48. clk_disable_unprepare(hclk);
  49. return of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
  50. }
  51. static const struct of_device_id gsbi_dt_match[] = {
  52. { .compatible = "qcom,gsbi-v1.0.0", },
  53. { },
  54. };
  55. MODULE_DEVICE_TABLE(of, gsbi_dt_match);
  56. static struct platform_driver gsbi_driver = {
  57. .driver = {
  58. .name = "gsbi",
  59. .owner = THIS_MODULE,
  60. .of_match_table = gsbi_dt_match,
  61. },
  62. .probe = gsbi_probe,
  63. };
  64. module_platform_driver(gsbi_driver);
  65. MODULE_AUTHOR("Andy Gross <agross@codeaurora.org>");
  66. MODULE_DESCRIPTION("QCOM GSBI driver");
  67. MODULE_LICENSE("GPL v2");