blob: 729425ddfd3e371d04978cdda0871209e2f24885 [file] [log] [blame]
Andy Gross5d144e32014-04-24 11:31:21 -05001/*
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
Srinivas Kandagatlafa9eb322014-09-23 20:20:54 +010025struct gsbi_info {
26 struct clk *hclk;
27 u32 mode;
28 u32 crci;
29};
30
Andy Gross5d144e32014-04-24 11:31:21 -050031static 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;
Srinivas Kandagatlafa9eb322014-09-23 20:20:54 +010036 struct gsbi_info *gsbi;
37
38 gsbi = devm_kzalloc(&pdev->dev, sizeof(*gsbi), GFP_KERNEL);
39
40 if (!gsbi)
41 return -ENOMEM;
Andy Gross5d144e32014-04-24 11:31:21 -050042
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
Srinivas Kandagatlafa9eb322014-09-23 20:20:54 +010048 if (of_property_read_u32(node, "qcom,mode", &gsbi->mode)) {
Andy Gross5d144e32014-04-24 11:31:21 -050049 dev_err(&pdev->dev, "missing mode configuration\n");
50 return -EINVAL;
51 }
52
53 /* not required, so default to 0 if not present */
Srinivas Kandagatlafa9eb322014-09-23 20:20:54 +010054 of_property_read_u32(node, "qcom,crci", &gsbi->crci);
Andy Gross5d144e32014-04-24 11:31:21 -050055
Srinivas Kandagatlafa9eb322014-09-23 20:20:54 +010056 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);
Andy Gross5d144e32014-04-24 11:31:21 -050061
Srinivas Kandagatlafa9eb322014-09-23 20:20:54 +010062 clk_prepare_enable(gsbi->hclk);
Andy Gross5d144e32014-04-24 11:31:21 -050063
Srinivas Kandagatlafa9eb322014-09-23 20:20:54 +010064 writel_relaxed((gsbi->mode << GSBI_PROTOCOL_SHIFT) | gsbi->crci,
Andy Gross5d144e32014-04-24 11:31:21 -050065 base + GSBI_CTRL_REG);
66
67 /* make sure the gsbi control write is not reordered */
68 wmb();
69
Srinivas Kandagatlafa9eb322014-09-23 20:20:54 +010070 platform_set_drvdata(pdev, gsbi);
Andy Gross5d144e32014-04-24 11:31:21 -050071
Srinivas Kandagatlafa9eb322014-09-23 20:20:54 +010072 return of_platform_populate(node, NULL, NULL, &pdev->dev);
73}
74
75static 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;
Andy Gross5d144e32014-04-24 11:31:21 -050082}
83
84static const struct of_device_id gsbi_dt_match[] = {
85 { .compatible = "qcom,gsbi-v1.0.0", },
Arnd Bergmann1b7f0c72014-05-26 18:07:05 +020086 { },
Andy Gross5d144e32014-04-24 11:31:21 -050087};
88
89MODULE_DEVICE_TABLE(of, gsbi_dt_match);
90
91static struct platform_driver gsbi_driver = {
92 .driver = {
93 .name = "gsbi",
Andy Gross5d144e32014-04-24 11:31:21 -050094 .of_match_table = gsbi_dt_match,
95 },
96 .probe = gsbi_probe,
Srinivas Kandagatlafa9eb322014-09-23 20:20:54 +010097 .remove = gsbi_remove,
Andy Gross5d144e32014-04-24 11:31:21 -050098};
99
100module_platform_driver(gsbi_driver);
101
102MODULE_AUTHOR("Andy Gross <agross@codeaurora.org>");
103MODULE_DESCRIPTION("QCOM GSBI driver");
104MODULE_LICENSE("GPL v2");