Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -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 Trace Port Interface Unit driver |
| 4 | * |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -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 | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/err.h> |
| 20 | #include <linux/slab.h> |
Linus Walleij | b5913d64 | 2015-05-19 10:55:10 -0600 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 22 | #include <linux/coresight.h> |
| 23 | #include <linux/amba/bus.h> |
Linus Walleij | db341d3 | 2015-05-19 10:55:15 -0600 | [diff] [blame] | 24 | #include <linux/clk.h> |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 25 | |
| 26 | #include "coresight-priv.h" |
| 27 | |
| 28 | #define TPIU_SUPP_PORTSZ 0x000 |
| 29 | #define TPIU_CURR_PORTSZ 0x004 |
| 30 | #define TPIU_SUPP_TRIGMODES 0x100 |
| 31 | #define TPIU_TRIG_CNTRVAL 0x104 |
| 32 | #define TPIU_TRIG_MULT 0x108 |
| 33 | #define TPIU_SUPP_TESTPATM 0x200 |
| 34 | #define TPIU_CURR_TESTPATM 0x204 |
| 35 | #define TPIU_TEST_PATREPCNTR 0x208 |
| 36 | #define TPIU_FFSR 0x300 |
| 37 | #define TPIU_FFCR 0x304 |
| 38 | #define TPIU_FSYNC_CNTR 0x308 |
| 39 | #define TPIU_EXTCTL_INPORT 0x400 |
| 40 | #define TPIU_EXTCTL_OUTPORT 0x404 |
| 41 | #define TPIU_ITTRFLINACK 0xee4 |
| 42 | #define TPIU_ITTRFLIN 0xee8 |
| 43 | #define TPIU_ITATBDATA0 0xeec |
| 44 | #define TPIU_ITATBCTR2 0xef0 |
| 45 | #define TPIU_ITATBCTR1 0xef4 |
| 46 | #define TPIU_ITATBCTR0 0xef8 |
| 47 | |
| 48 | /** register definition **/ |
| 49 | /* FFCR - 0x304 */ |
| 50 | #define FFCR_FON_MAN BIT(6) |
| 51 | |
| 52 | /** |
| 53 | * @base: memory mapped base address for this component. |
| 54 | * @dev: the device entity associated to this component. |
Linus Walleij | db341d3 | 2015-05-19 10:55:15 -0600 | [diff] [blame] | 55 | * @atclk: optional clock for the core parts of the TPIU. |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 56 | * @csdev: component vitals needed by the framework. |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 57 | */ |
| 58 | struct tpiu_drvdata { |
| 59 | void __iomem *base; |
| 60 | struct device *dev; |
Linus Walleij | db341d3 | 2015-05-19 10:55:15 -0600 | [diff] [blame] | 61 | struct clk *atclk; |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 62 | struct coresight_device *csdev; |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | static void tpiu_enable_hw(struct tpiu_drvdata *drvdata) |
| 66 | { |
| 67 | CS_UNLOCK(drvdata->base); |
| 68 | |
| 69 | /* TODO: fill this up */ |
| 70 | |
| 71 | CS_LOCK(drvdata->base); |
| 72 | } |
| 73 | |
Mathieu Poirier | e827d45 | 2016-02-17 17:51:59 -0700 | [diff] [blame] | 74 | static int tpiu_enable(struct coresight_device *csdev, u32 mode) |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 75 | { |
| 76 | struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 77 | |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 78 | tpiu_enable_hw(drvdata); |
| 79 | |
| 80 | dev_info(drvdata->dev, "TPIU enabled\n"); |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static void tpiu_disable_hw(struct tpiu_drvdata *drvdata) |
| 85 | { |
| 86 | CS_UNLOCK(drvdata->base); |
| 87 | |
| 88 | /* Clear formatter controle reg. */ |
| 89 | writel_relaxed(0x0, drvdata->base + TPIU_FFCR); |
| 90 | /* Generate manual flush */ |
| 91 | writel_relaxed(FFCR_FON_MAN, drvdata->base + TPIU_FFCR); |
| 92 | |
| 93 | CS_LOCK(drvdata->base); |
| 94 | } |
| 95 | |
| 96 | static void tpiu_disable(struct coresight_device *csdev) |
| 97 | { |
| 98 | struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
| 99 | |
| 100 | tpiu_disable_hw(drvdata); |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 101 | |
| 102 | dev_info(drvdata->dev, "TPIU disabled\n"); |
| 103 | } |
| 104 | |
| 105 | static const struct coresight_ops_sink tpiu_sink_ops = { |
| 106 | .enable = tpiu_enable, |
| 107 | .disable = tpiu_disable, |
| 108 | }; |
| 109 | |
| 110 | static const struct coresight_ops tpiu_cs_ops = { |
| 111 | .sink_ops = &tpiu_sink_ops, |
| 112 | }; |
| 113 | |
| 114 | static int tpiu_probe(struct amba_device *adev, const struct amba_id *id) |
| 115 | { |
Linus Walleij | db341d3 | 2015-05-19 10:55:15 -0600 | [diff] [blame] | 116 | int ret; |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 117 | void __iomem *base; |
| 118 | struct device *dev = &adev->dev; |
| 119 | struct coresight_platform_data *pdata = NULL; |
| 120 | struct tpiu_drvdata *drvdata; |
| 121 | struct resource *res = &adev->res; |
Suzuki K Poulose | 9486295 | 2016-08-25 15:19:05 -0600 | [diff] [blame] | 122 | struct coresight_desc desc = { 0 }; |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 123 | struct device_node *np = adev->dev.of_node; |
| 124 | |
| 125 | if (np) { |
| 126 | pdata = of_get_coresight_platform_data(dev, np); |
| 127 | if (IS_ERR(pdata)) |
| 128 | return PTR_ERR(pdata); |
| 129 | adev->dev.platform_data = pdata; |
| 130 | } |
| 131 | |
| 132 | drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); |
| 133 | if (!drvdata) |
| 134 | return -ENOMEM; |
| 135 | |
| 136 | drvdata->dev = &adev->dev; |
Linus Walleij | db341d3 | 2015-05-19 10:55:15 -0600 | [diff] [blame] | 137 | drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */ |
| 138 | if (!IS_ERR(drvdata->atclk)) { |
| 139 | ret = clk_prepare_enable(drvdata->atclk); |
| 140 | if (ret) |
| 141 | return ret; |
| 142 | } |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 143 | dev_set_drvdata(dev, drvdata); |
| 144 | |
| 145 | /* Validity for the resource is already checked by the AMBA core */ |
| 146 | base = devm_ioremap_resource(dev, res); |
| 147 | if (IS_ERR(base)) |
| 148 | return PTR_ERR(base); |
| 149 | |
| 150 | drvdata->base = base; |
| 151 | |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 152 | /* Disable tpiu to support older devices */ |
| 153 | tpiu_disable_hw(drvdata); |
| 154 | |
Linus Walleij | b5913d64 | 2015-05-19 10:55:10 -0600 | [diff] [blame] | 155 | pm_runtime_put(&adev->dev); |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 156 | |
Suzuki K Poulose | 9486295 | 2016-08-25 15:19:05 -0600 | [diff] [blame] | 157 | desc.type = CORESIGHT_DEV_TYPE_SINK; |
| 158 | desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_PORT; |
| 159 | desc.ops = &tpiu_cs_ops; |
| 160 | desc.pdata = pdata; |
| 161 | desc.dev = dev; |
| 162 | drvdata->csdev = coresight_register(&desc); |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 163 | if (IS_ERR(drvdata->csdev)) |
| 164 | return PTR_ERR(drvdata->csdev); |
| 165 | |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | |
Linus Walleij | db341d3 | 2015-05-19 10:55:15 -0600 | [diff] [blame] | 169 | #ifdef CONFIG_PM |
| 170 | static int tpiu_runtime_suspend(struct device *dev) |
| 171 | { |
| 172 | struct tpiu_drvdata *drvdata = dev_get_drvdata(dev); |
| 173 | |
| 174 | if (drvdata && !IS_ERR(drvdata->atclk)) |
| 175 | clk_disable_unprepare(drvdata->atclk); |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int tpiu_runtime_resume(struct device *dev) |
| 181 | { |
| 182 | struct tpiu_drvdata *drvdata = dev_get_drvdata(dev); |
| 183 | |
| 184 | if (drvdata && !IS_ERR(drvdata->atclk)) |
| 185 | clk_prepare_enable(drvdata->atclk); |
| 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | #endif |
| 190 | |
| 191 | static const struct dev_pm_ops tpiu_dev_pm_ops = { |
| 192 | SET_RUNTIME_PM_OPS(tpiu_runtime_suspend, tpiu_runtime_resume, NULL) |
| 193 | }; |
| 194 | |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 195 | static struct amba_id tpiu_ids[] = { |
| 196 | { |
| 197 | .id = 0x0003b912, |
| 198 | .mask = 0x0003ffff, |
| 199 | }, |
Linus Walleij | 4339b69 | 2015-05-19 10:55:08 -0600 | [diff] [blame] | 200 | { |
| 201 | .id = 0x0004b912, |
| 202 | .mask = 0x0007ffff, |
| 203 | }, |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 204 | { 0, 0}, |
| 205 | }; |
| 206 | |
| 207 | static struct amba_driver tpiu_driver = { |
| 208 | .drv = { |
| 209 | .name = "coresight-tpiu", |
| 210 | .owner = THIS_MODULE, |
Linus Walleij | db341d3 | 2015-05-19 10:55:15 -0600 | [diff] [blame] | 211 | .pm = &tpiu_dev_pm_ops, |
Mathieu Poirier | b15f0fb | 2016-02-02 14:14:00 -0700 | [diff] [blame] | 212 | .suppress_bind_attrs = true, |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 213 | }, |
| 214 | .probe = tpiu_probe, |
Pratik Patel | dc161b9 | 2014-11-03 11:07:37 -0700 | [diff] [blame] | 215 | .id_table = tpiu_ids, |
| 216 | }; |
Paul Gortmaker | 941943c | 2016-02-17 17:52:03 -0700 | [diff] [blame] | 217 | builtin_amba_driver(tpiu_driver); |