• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
14 #include <linux/clk.h>
15 #include <linux/err.h>
16 #include <linux/io.h>
17 #include <linux/module.h>
18 #include <linux/of.h>
19 #include <linux/of_platform.h>
20 #include <linux/platform_device.h>
21 
22 #define GSBI_CTRL_REG		0x0000
23 #define GSBI_PROTOCOL_SHIFT	4
24 
25 struct gsbi_info {
26 	struct clk *hclk;
27 	u32 mode;
28 	u32 crci;
29 };
30 
gsbi_probe(struct platform_device * pdev)31 static int gsbi_probe(struct platform_device *pdev)
32 {
33 	struct device_node *node = pdev->dev.of_node;
34 	struct resource *res;
35 	void __iomem *base;
36 	struct gsbi_info *gsbi;
37 
38 	gsbi = devm_kzalloc(&pdev->dev, sizeof(*gsbi), GFP_KERNEL);
39 
40 	if (!gsbi)
41 		return -ENOMEM;
42 
43 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
44 	base = devm_ioremap_resource(&pdev->dev, res);
45 	if (IS_ERR(base))
46 		return PTR_ERR(base);
47 
48 	if (of_property_read_u32(node, "qcom,mode", &gsbi->mode)) {
49 		dev_err(&pdev->dev, "missing mode configuration\n");
50 		return -EINVAL;
51 	}
52 
53 	/* not required, so default to 0 if not present */
54 	of_property_read_u32(node, "qcom,crci", &gsbi->crci);
55 
56 	dev_info(&pdev->dev, "GSBI port protocol: %d crci: %d\n",
57 		 gsbi->mode, gsbi->crci);
58 	gsbi->hclk = devm_clk_get(&pdev->dev, "iface");
59 	if (IS_ERR(gsbi->hclk))
60 		return PTR_ERR(gsbi->hclk);
61 
62 	clk_prepare_enable(gsbi->hclk);
63 
64 	writel_relaxed((gsbi->mode << GSBI_PROTOCOL_SHIFT) | gsbi->crci,
65 				base + GSBI_CTRL_REG);
66 
67 	/* make sure the gsbi control write is not reordered */
68 	wmb();
69 
70 	platform_set_drvdata(pdev, gsbi);
71 
72 	return of_platform_populate(node, NULL, NULL, &pdev->dev);
73 }
74 
gsbi_remove(struct platform_device * pdev)75 static int gsbi_remove(struct platform_device *pdev)
76 {
77 	struct gsbi_info *gsbi = platform_get_drvdata(pdev);
78 
79 	clk_disable_unprepare(gsbi->hclk);
80 
81 	return 0;
82 }
83 
84 static const struct of_device_id gsbi_dt_match[] = {
85 	{ .compatible = "qcom,gsbi-v1.0.0", },
86 	{ },
87 };
88 
89 MODULE_DEVICE_TABLE(of, gsbi_dt_match);
90 
91 static struct platform_driver gsbi_driver = {
92 	.driver = {
93 		.name		= "gsbi",
94 		.owner		= THIS_MODULE,
95 		.of_match_table	= gsbi_dt_match,
96 	},
97 	.probe = gsbi_probe,
98 	.remove	= gsbi_remove,
99 };
100 
101 module_platform_driver(gsbi_driver);
102 
103 MODULE_AUTHOR("Andy Gross <agross@codeaurora.org>");
104 MODULE_DESCRIPTION("QCOM GSBI driver");
105 MODULE_LICENSE("GPL v2");
106