Bluetooth: hci_uart: Use generic functionality from Broadcom module
[linux/fpc-iii.git] / drivers / soc / qcom / qcom_gsbi.c
blob729425ddfd3e371d04978cdda0871209e2f24885
1 /*
2 * Copyright (c) 2014, The Linux foundation. All rights reserved.
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.
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.
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>
22 #define GSBI_CTRL_REG 0x0000
23 #define GSBI_PROTOCOL_SHIFT 4
25 struct gsbi_info {
26 struct clk *hclk;
27 u32 mode;
28 u32 crci;
31 static int gsbi_probe(struct platform_device *pdev)
33 struct device_node *node = pdev->dev.of_node;
34 struct resource *res;
35 void __iomem *base;
36 struct gsbi_info *gsbi;
38 gsbi = devm_kzalloc(&pdev->dev, sizeof(*gsbi), GFP_KERNEL);
40 if (!gsbi)
41 return -ENOMEM;
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);
48 if (of_property_read_u32(node, "qcom,mode", &gsbi->mode)) {
49 dev_err(&pdev->dev, "missing mode configuration\n");
50 return -EINVAL;
53 /* not required, so default to 0 if not present */
54 of_property_read_u32(node, "qcom,crci", &gsbi->crci);
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);
62 clk_prepare_enable(gsbi->hclk);
64 writel_relaxed((gsbi->mode << GSBI_PROTOCOL_SHIFT) | gsbi->crci,
65 base + GSBI_CTRL_REG);
67 /* make sure the gsbi control write is not reordered */
68 wmb();
70 platform_set_drvdata(pdev, gsbi);
72 return of_platform_populate(node, NULL, NULL, &pdev->dev);
75 static int gsbi_remove(struct platform_device *pdev)
77 struct gsbi_info *gsbi = platform_get_drvdata(pdev);
79 clk_disable_unprepare(gsbi->hclk);
81 return 0;
84 static const struct of_device_id gsbi_dt_match[] = {
85 { .compatible = "qcom,gsbi-v1.0.0", },
86 { },
89 MODULE_DEVICE_TABLE(of, gsbi_dt_match);
91 static struct platform_driver gsbi_driver = {
92 .driver = {
93 .name = "gsbi",
94 .of_match_table = gsbi_dt_match,
96 .probe = gsbi_probe,
97 .remove = gsbi_remove,
100 module_platform_driver(gsbi_driver);
102 MODULE_AUTHOR("Andy Gross <agross@codeaurora.org>");
103 MODULE_DESCRIPTION("QCOM GSBI driver");
104 MODULE_LICENSE("GPL v2");