Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 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 | |
Srinivas Kandagatla | fa9eb32 | 2014-09-23 20:20:54 +0100 | [diff] [blame] | 25 | struct gsbi_info { |
| 26 | struct clk *hclk; |
| 27 | u32 mode; |
| 28 | u32 crci; |
| 29 | }; |
| 30 | |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 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; |
Srinivas Kandagatla | fa9eb32 | 2014-09-23 20:20:54 +0100 | [diff] [blame] | 36 | struct gsbi_info *gsbi; |
| 37 | |
| 38 | gsbi = devm_kzalloc(&pdev->dev, sizeof(*gsbi), GFP_KERNEL); |
| 39 | |
| 40 | if (!gsbi) |
| 41 | return -ENOMEM; |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 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 | |
Srinivas Kandagatla | fa9eb32 | 2014-09-23 20:20:54 +0100 | [diff] [blame] | 48 | if (of_property_read_u32(node, "qcom,mode", &gsbi->mode)) { |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 49 | dev_err(&pdev->dev, "missing mode configuration\n"); |
| 50 | return -EINVAL; |
| 51 | } |
| 52 | |
| 53 | /* not required, so default to 0 if not present */ |
Srinivas Kandagatla | fa9eb32 | 2014-09-23 20:20:54 +0100 | [diff] [blame] | 54 | of_property_read_u32(node, "qcom,crci", &gsbi->crci); |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 55 | |
Srinivas Kandagatla | fa9eb32 | 2014-09-23 20:20:54 +0100 | [diff] [blame] | 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); |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 61 | |
Srinivas Kandagatla | fa9eb32 | 2014-09-23 20:20:54 +0100 | [diff] [blame] | 62 | clk_prepare_enable(gsbi->hclk); |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 63 | |
Srinivas Kandagatla | fa9eb32 | 2014-09-23 20:20:54 +0100 | [diff] [blame] | 64 | writel_relaxed((gsbi->mode << GSBI_PROTOCOL_SHIFT) | gsbi->crci, |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 65 | base + GSBI_CTRL_REG); |
| 66 | |
| 67 | /* make sure the gsbi control write is not reordered */ |
| 68 | wmb(); |
| 69 | |
Srinivas Kandagatla | fa9eb32 | 2014-09-23 20:20:54 +0100 | [diff] [blame] | 70 | platform_set_drvdata(pdev, gsbi); |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 71 | |
Srinivas Kandagatla | fa9eb32 | 2014-09-23 20:20:54 +0100 | [diff] [blame] | 72 | return of_platform_populate(node, NULL, NULL, &pdev->dev); |
| 73 | } |
| 74 | |
| 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; |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static const struct of_device_id gsbi_dt_match[] = { |
| 85 | { .compatible = "qcom,gsbi-v1.0.0", }, |
Arnd Bergmann | 1b7f0c7 | 2014-05-26 18:07:05 +0200 | [diff] [blame] | 86 | { }, |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | MODULE_DEVICE_TABLE(of, gsbi_dt_match); |
| 90 | |
| 91 | static struct platform_driver gsbi_driver = { |
| 92 | .driver = { |
| 93 | .name = "gsbi", |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 94 | .of_match_table = gsbi_dt_match, |
| 95 | }, |
| 96 | .probe = gsbi_probe, |
Srinivas Kandagatla | fa9eb32 | 2014-09-23 20:20:54 +0100 | [diff] [blame] | 97 | .remove = gsbi_remove, |
Andy Gross | 5d144e3 | 2014-04-24 11:31:21 -0500 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | module_platform_driver(gsbi_driver); |
| 101 | |
| 102 | MODULE_AUTHOR("Andy Gross <agross@codeaurora.org>"); |
| 103 | MODULE_DESCRIPTION("QCOM GSBI driver"); |
| 104 | MODULE_LICENSE("GPL v2"); |