Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. |
| 2 | * |
Paul Gortmaker | 941943c | 2016-02-17 17:52:03 -0700 | [diff] [blame] | 3 | * Description: CoreSight Replicator driver |
| 4 | * |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 and |
| 7 | * only version 2 as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 16 | #include <linux/device.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/err.h> |
| 20 | #include <linux/slab.h> |
Linus Walleij | 9875cd9 | 2015-05-19 10:55:18 -0600 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 22 | #include <linux/clk.h> |
| 23 | #include <linux/of.h> |
| 24 | #include <linux/coresight.h> |
| 25 | |
| 26 | #include "coresight-priv.h" |
| 27 | |
| 28 | /** |
| 29 | * struct replicator_drvdata - specifics associated to a replicator component |
| 30 | * @dev: the device entity associated with this component |
Linus Walleij | 9875cd9 | 2015-05-19 10:55:18 -0600 | [diff] [blame] | 31 | * @atclk: optional clock for the core parts of the replicator. |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 32 | * @csdev: component vitals needed by the framework |
| 33 | */ |
| 34 | struct replicator_drvdata { |
| 35 | struct device *dev; |
Linus Walleij | 9875cd9 | 2015-05-19 10:55:18 -0600 | [diff] [blame] | 36 | struct clk *atclk; |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 37 | struct coresight_device *csdev; |
| 38 | }; |
| 39 | |
| 40 | static int replicator_enable(struct coresight_device *csdev, int inport, |
| 41 | int outport) |
| 42 | { |
| 43 | struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
| 44 | |
| 45 | dev_info(drvdata->dev, "REPLICATOR enabled\n"); |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static void replicator_disable(struct coresight_device *csdev, int inport, |
| 50 | int outport) |
| 51 | { |
| 52 | struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
| 53 | |
| 54 | dev_info(drvdata->dev, "REPLICATOR disabled\n"); |
| 55 | } |
| 56 | |
| 57 | static const struct coresight_ops_link replicator_link_ops = { |
| 58 | .enable = replicator_enable, |
| 59 | .disable = replicator_disable, |
| 60 | }; |
| 61 | |
| 62 | static const struct coresight_ops replicator_cs_ops = { |
| 63 | .link_ops = &replicator_link_ops, |
| 64 | }; |
| 65 | |
| 66 | static int replicator_probe(struct platform_device *pdev) |
| 67 | { |
Linus Walleij | 9875cd9 | 2015-05-19 10:55:18 -0600 | [diff] [blame] | 68 | int ret; |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 69 | struct device *dev = &pdev->dev; |
| 70 | struct coresight_platform_data *pdata = NULL; |
| 71 | struct replicator_drvdata *drvdata; |
| 72 | struct coresight_desc *desc; |
| 73 | struct device_node *np = pdev->dev.of_node; |
| 74 | |
| 75 | if (np) { |
| 76 | pdata = of_get_coresight_platform_data(dev, np); |
| 77 | if (IS_ERR(pdata)) |
| 78 | return PTR_ERR(pdata); |
| 79 | pdev->dev.platform_data = pdata; |
| 80 | } |
| 81 | |
| 82 | drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); |
| 83 | if (!drvdata) |
| 84 | return -ENOMEM; |
| 85 | |
| 86 | drvdata->dev = &pdev->dev; |
Linus Walleij | 9875cd9 | 2015-05-19 10:55:18 -0600 | [diff] [blame] | 87 | drvdata->atclk = devm_clk_get(&pdev->dev, "atclk"); /* optional */ |
| 88 | if (!IS_ERR(drvdata->atclk)) { |
| 89 | ret = clk_prepare_enable(drvdata->atclk); |
| 90 | if (ret) |
| 91 | return ret; |
| 92 | } |
| 93 | pm_runtime_get_noresume(&pdev->dev); |
| 94 | pm_runtime_set_active(&pdev->dev); |
| 95 | pm_runtime_enable(&pdev->dev); |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 96 | platform_set_drvdata(pdev, drvdata); |
| 97 | |
| 98 | desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); |
Linus Walleij | 9875cd9 | 2015-05-19 10:55:18 -0600 | [diff] [blame] | 99 | if (!desc) { |
| 100 | ret = -ENOMEM; |
| 101 | goto out_disable_pm; |
| 102 | } |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 103 | |
| 104 | desc->type = CORESIGHT_DEV_TYPE_LINK; |
Kaixu Xia | 410d841 | 2015-01-26 09:22:17 -0700 | [diff] [blame] | 105 | desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT; |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 106 | desc->ops = &replicator_cs_ops; |
| 107 | desc->pdata = pdev->dev.platform_data; |
| 108 | desc->dev = &pdev->dev; |
| 109 | drvdata->csdev = coresight_register(desc); |
Linus Walleij | 9875cd9 | 2015-05-19 10:55:18 -0600 | [diff] [blame] | 110 | if (IS_ERR(drvdata->csdev)) { |
| 111 | ret = PTR_ERR(drvdata->csdev); |
| 112 | goto out_disable_pm; |
| 113 | } |
| 114 | |
| 115 | pm_runtime_put(&pdev->dev); |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 116 | |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 117 | return 0; |
Linus Walleij | 9875cd9 | 2015-05-19 10:55:18 -0600 | [diff] [blame] | 118 | |
| 119 | out_disable_pm: |
| 120 | if (!IS_ERR(drvdata->atclk)) |
| 121 | clk_disable_unprepare(drvdata->atclk); |
| 122 | pm_runtime_put_noidle(&pdev->dev); |
| 123 | pm_runtime_disable(&pdev->dev); |
| 124 | |
| 125 | return ret; |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Linus Walleij | 9875cd9 | 2015-05-19 10:55:18 -0600 | [diff] [blame] | 128 | #ifdef CONFIG_PM |
| 129 | static int replicator_runtime_suspend(struct device *dev) |
| 130 | { |
| 131 | struct replicator_drvdata *drvdata = dev_get_drvdata(dev); |
| 132 | |
| 133 | if (drvdata && !IS_ERR(drvdata->atclk)) |
| 134 | clk_disable_unprepare(drvdata->atclk); |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static int replicator_runtime_resume(struct device *dev) |
| 140 | { |
| 141 | struct replicator_drvdata *drvdata = dev_get_drvdata(dev); |
| 142 | |
| 143 | if (drvdata && !IS_ERR(drvdata->atclk)) |
| 144 | clk_prepare_enable(drvdata->atclk); |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | #endif |
| 149 | |
| 150 | static const struct dev_pm_ops replicator_dev_pm_ops = { |
| 151 | SET_RUNTIME_PM_OPS(replicator_runtime_suspend, |
| 152 | replicator_runtime_resume, NULL) |
| 153 | }; |
| 154 | |
Fabian Frederick | 160b7da | 2015-03-16 20:20:33 +0100 | [diff] [blame] | 155 | static const struct of_device_id replicator_match[] = { |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 156 | {.compatible = "arm,coresight-replicator"}, |
| 157 | {} |
| 158 | }; |
| 159 | |
| 160 | static struct platform_driver replicator_driver = { |
| 161 | .probe = replicator_probe, |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 162 | .driver = { |
| 163 | .name = "coresight-replicator", |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 164 | .of_match_table = replicator_match, |
Linus Walleij | 9875cd9 | 2015-05-19 10:55:18 -0600 | [diff] [blame] | 165 | .pm = &replicator_dev_pm_ops, |
Mathieu Poirier | b15f0fb | 2016-02-02 14:14:00 -0700 | [diff] [blame] | 166 | .suppress_bind_attrs = true, |
Pratik Patel | ceacc1d | 2014-11-03 11:07:40 -0700 | [diff] [blame] | 167 | }, |
| 168 | }; |
Vaishali Thakkar | c35aaa1 | 2015-07-31 09:37:23 -0600 | [diff] [blame] | 169 | builtin_platform_driver(replicator_driver); |