Pratik Patel | 8c86adf | 2012-12-07 13:42:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/io.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/fs.h> |
| 22 | #include <linux/miscdevice.h> |
| 23 | #include <linux/uaccess.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/memory_alloc.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/spinlock.h> |
| 28 | #include <linux/clk.h> |
Pratik Patel | 8c86adf | 2012-12-07 13:42:12 -0800 | [diff] [blame] | 29 | #include <linux/of.h> |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 30 | #include <linux/of_coresight.h> |
| 31 | #include <linux/coresight.h> |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 32 | #include <linux/coresight-cti.h> |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 33 | #include <linux/usb/usb_qdss.h> |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 34 | #include <mach/memory.h> |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 35 | #include <mach/sps.h> |
| 36 | #include <mach/usb_bam.h> |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 37 | #include <mach/msm_memory_dump.h> |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 38 | |
| 39 | #include "coresight-priv.h" |
| 40 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 41 | #define tmc_writel(drvdata, val, off) __raw_writel((val), drvdata->base + off) |
| 42 | #define tmc_readl(drvdata, off) __raw_readl(drvdata->base + off) |
| 43 | |
| 44 | #define TMC_LOCK(drvdata) \ |
| 45 | do { \ |
| 46 | mb(); \ |
| 47 | tmc_writel(drvdata, 0x0, CORESIGHT_LAR); \ |
| 48 | } while (0) |
| 49 | #define TMC_UNLOCK(drvdata) \ |
| 50 | do { \ |
| 51 | tmc_writel(drvdata, CORESIGHT_UNLOCK, CORESIGHT_LAR); \ |
| 52 | mb(); \ |
| 53 | } while (0) |
| 54 | |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 55 | #define TMC_RSZ (0x004) |
| 56 | #define TMC_STS (0x00C) |
| 57 | #define TMC_RRD (0x010) |
| 58 | #define TMC_RRP (0x014) |
| 59 | #define TMC_RWP (0x018) |
| 60 | #define TMC_TRG (0x01C) |
| 61 | #define TMC_CTL (0x020) |
| 62 | #define TMC_RWD (0x024) |
| 63 | #define TMC_MODE (0x028) |
| 64 | #define TMC_LBUFLEVEL (0x02C) |
| 65 | #define TMC_CBUFLEVEL (0x030) |
| 66 | #define TMC_BUFWM (0x034) |
| 67 | #define TMC_RRPHI (0x038) |
| 68 | #define TMC_RWPHI (0x03C) |
| 69 | #define TMC_AXICTL (0x110) |
| 70 | #define TMC_DBALO (0x118) |
| 71 | #define TMC_DBAHI (0x11C) |
| 72 | #define TMC_FFSR (0x300) |
| 73 | #define TMC_FFCR (0x304) |
| 74 | #define TMC_PSCR (0x308) |
| 75 | #define TMC_ITMISCOP0 (0xEE0) |
| 76 | #define TMC_ITTRFLIN (0xEE8) |
| 77 | #define TMC_ITATBDATA0 (0xEEC) |
| 78 | #define TMC_ITATBCTR2 (0xEF0) |
| 79 | #define TMC_ITATBCTR1 (0xEF4) |
| 80 | #define TMC_ITATBCTR0 (0xEF8) |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 81 | |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 82 | #define BYTES_PER_WORD 4 |
| 83 | #define TMC_ETR_BAM_PIPE_INDEX 0 |
| 84 | #define TMC_ETR_BAM_NR_PIPES 2 |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 85 | |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 86 | #define TMC_ETFETB_DUMP_MAGIC_OFF (0) |
| 87 | #define TMC_ETFETB_DUMP_MAGIC (0x5D1DB1BF) |
| 88 | #define TMC_ETFETB_DUMP_VER_OFF (4) |
| 89 | #define TMC_ETFETB_DUMP_VER (1) |
| 90 | #define TMC_REG_DUMP_MAGIC_OFF (0) |
| 91 | #define TMC_REG_DUMP_MAGIC (0x5D1DB1BF) |
| 92 | #define TMC_REG_DUMP_VER_OFF (4) |
| 93 | #define TMC_REG_DUMP_VER (1) |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 94 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 95 | enum tmc_config_type { |
| 96 | TMC_CONFIG_TYPE_ETB, |
| 97 | TMC_CONFIG_TYPE_ETR, |
| 98 | TMC_CONFIG_TYPE_ETF, |
| 99 | }; |
| 100 | |
| 101 | enum tmc_mode { |
| 102 | TMC_MODE_CIRCULAR_BUFFER, |
| 103 | TMC_MODE_SOFTWARE_FIFO, |
| 104 | TMC_MODE_HARDWARE_FIFO, |
| 105 | }; |
| 106 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 107 | enum tmc_etr_out_mode { |
| 108 | TMC_ETR_OUT_MODE_NONE, |
| 109 | TMC_ETR_OUT_MODE_MEM, |
| 110 | TMC_ETR_OUT_MODE_USB, |
| 111 | }; |
| 112 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 113 | enum tmc_mem_intf_width { |
| 114 | TMC_MEM_INTF_WIDTH_32BITS = 0x2, |
| 115 | TMC_MEM_INTF_WIDTH_64BITS = 0x3, |
| 116 | TMC_MEM_INTF_WIDTH_128BITS = 0x4, |
| 117 | TMC_MEM_INTF_WIDTH_256BITS = 0x5, |
| 118 | }; |
| 119 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 120 | struct tmc_etr_bam_data { |
| 121 | struct sps_bam_props props; |
| 122 | uint32_t handle; |
| 123 | struct sps_pipe *pipe; |
| 124 | struct sps_connect connect; |
| 125 | uint32_t src_pipe_idx; |
| 126 | uint32_t dest; |
| 127 | uint32_t dest_pipe_idx; |
| 128 | struct sps_mem_buffer desc_fifo; |
| 129 | struct sps_mem_buffer data_fifo; |
| 130 | bool enable; |
| 131 | }; |
| 132 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 133 | struct tmc_drvdata { |
| 134 | void __iomem *base; |
| 135 | struct device *dev; |
| 136 | struct coresight_device *csdev; |
| 137 | struct miscdevice miscdev; |
| 138 | struct clk *clk; |
| 139 | spinlock_t spinlock; |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 140 | bool reset_flush_race; |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 141 | struct coresight_cti *cti_flush; |
| 142 | struct coresight_cti *cti_reset; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 143 | struct mutex read_lock; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 144 | int read_count; |
| 145 | bool reading; |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 146 | bool aborting; |
| 147 | char *reg_buf; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 148 | char *buf; |
| 149 | unsigned long paddr; |
| 150 | void __iomem *vaddr; |
| 151 | uint32_t size; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 152 | struct mutex usb_lock; |
| 153 | struct usb_qdss_ch *usbch; |
| 154 | struct tmc_etr_bam_data *bamdata; |
| 155 | enum tmc_etr_out_mode out_mode; |
| 156 | bool enable_to_bam; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 157 | bool enable; |
| 158 | enum tmc_config_type config_type; |
| 159 | uint32_t trigger_cntr; |
| 160 | }; |
| 161 | |
Pratik Patel | bfd2de6 | 2013-01-26 12:14:59 -0800 | [diff] [blame] | 162 | static void tmc_wait_for_flush(struct tmc_drvdata *drvdata) |
| 163 | { |
| 164 | int count; |
| 165 | |
| 166 | /* Ensure no flush is in progress */ |
| 167 | for (count = TIMEOUT_US; BVAL(tmc_readl(drvdata, TMC_FFSR), 0) != 0 |
| 168 | && count > 0; count--) |
| 169 | udelay(1); |
| 170 | WARN(count == 0, "timeout while waiting for TMC flush, TMC_FFSR: %#x\n", |
| 171 | tmc_readl(drvdata, TMC_FFSR)); |
| 172 | } |
| 173 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 174 | static void tmc_wait_for_ready(struct tmc_drvdata *drvdata) |
| 175 | { |
| 176 | int count; |
| 177 | |
| 178 | /* Ensure formatter, unformatter and hardware fifo are empty */ |
| 179 | for (count = TIMEOUT_US; BVAL(tmc_readl(drvdata, TMC_STS), 2) != 1 |
| 180 | && count > 0; count--) |
| 181 | udelay(1); |
| 182 | WARN(count == 0, "timeout while waiting for TMC ready, TMC_STS: %#x\n", |
| 183 | tmc_readl(drvdata, TMC_STS)); |
| 184 | } |
| 185 | |
| 186 | static void tmc_flush_and_stop(struct tmc_drvdata *drvdata) |
| 187 | { |
| 188 | int count; |
| 189 | uint32_t ffcr; |
| 190 | |
| 191 | ffcr = tmc_readl(drvdata, TMC_FFCR); |
| 192 | ffcr |= BIT(12); |
| 193 | tmc_writel(drvdata, ffcr, TMC_FFCR); |
| 194 | ffcr |= BIT(6); |
| 195 | tmc_writel(drvdata, ffcr, TMC_FFCR); |
| 196 | /* Ensure flush completes */ |
| 197 | for (count = TIMEOUT_US; BVAL(tmc_readl(drvdata, TMC_FFCR), 6) != 0 |
| 198 | && count > 0; count--) |
| 199 | udelay(1); |
| 200 | WARN(count == 0, "timeout while flushing TMC, TMC_FFCR: %#x\n", |
| 201 | tmc_readl(drvdata, TMC_FFCR)); |
| 202 | |
| 203 | tmc_wait_for_ready(drvdata); |
| 204 | } |
| 205 | |
| 206 | static void __tmc_enable(struct tmc_drvdata *drvdata) |
| 207 | { |
| 208 | tmc_writel(drvdata, 0x1, TMC_CTL); |
| 209 | } |
| 210 | |
| 211 | static void __tmc_disable(struct tmc_drvdata *drvdata) |
| 212 | { |
| 213 | tmc_writel(drvdata, 0x0, TMC_CTL); |
| 214 | } |
| 215 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 216 | static void tmc_etr_fill_usb_bam_data(struct tmc_drvdata *drvdata) |
| 217 | { |
| 218 | struct tmc_etr_bam_data *bamdata = drvdata->bamdata; |
| 219 | |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 220 | get_bam2bam_connection_info(usb_bam_get_qdss_idx(0), |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 221 | &bamdata->dest, |
| 222 | &bamdata->dest_pipe_idx, |
| 223 | &bamdata->src_pipe_idx, |
| 224 | &bamdata->desc_fifo, |
| 225 | &bamdata->data_fifo); |
| 226 | } |
| 227 | |
| 228 | static void __tmc_etr_enable_to_bam(struct tmc_drvdata *drvdata) |
| 229 | { |
| 230 | struct tmc_etr_bam_data *bamdata = drvdata->bamdata; |
| 231 | uint32_t axictl; |
| 232 | |
| 233 | if (drvdata->enable_to_bam) |
| 234 | return; |
| 235 | |
| 236 | /* Configure and enable required CSR registers */ |
| 237 | msm_qdss_csr_enable_bam_to_usb(); |
| 238 | |
| 239 | /* Configure and enable ETR for usb bam output */ |
| 240 | |
| 241 | TMC_UNLOCK(drvdata); |
| 242 | |
| 243 | tmc_writel(drvdata, bamdata->data_fifo.size / BYTES_PER_WORD, |
| 244 | TMC_RSZ); |
| 245 | tmc_writel(drvdata, TMC_MODE_CIRCULAR_BUFFER, TMC_MODE); |
| 246 | |
| 247 | axictl = tmc_readl(drvdata, TMC_AXICTL); |
| 248 | axictl |= (0xF << 8); |
| 249 | tmc_writel(drvdata, axictl, TMC_AXICTL); |
| 250 | axictl &= ~(0x1 << 7); |
| 251 | tmc_writel(drvdata, axictl, TMC_AXICTL); |
| 252 | axictl = (axictl & ~0x3) | 0x2; |
| 253 | tmc_writel(drvdata, axictl, TMC_AXICTL); |
| 254 | |
| 255 | tmc_writel(drvdata, bamdata->data_fifo.phys_base, TMC_DBALO); |
| 256 | tmc_writel(drvdata, 0x0, TMC_DBAHI); |
Pratik Patel | bfd2de6 | 2013-01-26 12:14:59 -0800 | [diff] [blame] | 257 | tmc_writel(drvdata, 0x103, TMC_FFCR); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 258 | tmc_writel(drvdata, drvdata->trigger_cntr, TMC_TRG); |
| 259 | __tmc_enable(drvdata); |
| 260 | |
| 261 | TMC_LOCK(drvdata); |
| 262 | |
| 263 | drvdata->enable_to_bam = true; |
| 264 | } |
| 265 | |
| 266 | static int tmc_etr_bam_enable(struct tmc_drvdata *drvdata) |
| 267 | { |
| 268 | struct tmc_etr_bam_data *bamdata = drvdata->bamdata; |
| 269 | int ret; |
| 270 | |
| 271 | if (bamdata->enable) |
| 272 | return 0; |
| 273 | |
Pratik Patel | aa0e6f9 | 2013-01-26 11:21:03 -0800 | [diff] [blame] | 274 | /* Reset bam to start with */ |
| 275 | ret = sps_device_reset(bamdata->handle); |
| 276 | if (ret) |
| 277 | goto err0; |
| 278 | |
| 279 | /* Now configure and enable bam */ |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 280 | |
| 281 | bamdata->pipe = sps_alloc_endpoint(); |
| 282 | if (!bamdata->pipe) |
| 283 | return -ENOMEM; |
| 284 | |
| 285 | ret = sps_get_config(bamdata->pipe, &bamdata->connect); |
| 286 | if (ret) |
Pratik Patel | aa0e6f9 | 2013-01-26 11:21:03 -0800 | [diff] [blame] | 287 | goto err1; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 288 | |
| 289 | bamdata->connect.mode = SPS_MODE_SRC; |
| 290 | bamdata->connect.source = bamdata->handle; |
| 291 | bamdata->connect.event_thresh = 0x4; |
| 292 | bamdata->connect.src_pipe_index = TMC_ETR_BAM_PIPE_INDEX; |
| 293 | bamdata->connect.options = SPS_O_AUTO_ENABLE; |
| 294 | |
| 295 | bamdata->connect.destination = bamdata->dest; |
| 296 | bamdata->connect.dest_pipe_index = bamdata->dest_pipe_idx; |
| 297 | bamdata->connect.desc = bamdata->desc_fifo; |
| 298 | bamdata->connect.data = bamdata->data_fifo; |
| 299 | |
| 300 | ret = sps_connect(bamdata->pipe, &bamdata->connect); |
| 301 | if (ret) |
Pratik Patel | aa0e6f9 | 2013-01-26 11:21:03 -0800 | [diff] [blame] | 302 | goto err1; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 303 | |
| 304 | bamdata->enable = true; |
| 305 | return 0; |
Pratik Patel | aa0e6f9 | 2013-01-26 11:21:03 -0800 | [diff] [blame] | 306 | err1: |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 307 | sps_free_endpoint(bamdata->pipe); |
Pratik Patel | aa0e6f9 | 2013-01-26 11:21:03 -0800 | [diff] [blame] | 308 | err0: |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 309 | return ret; |
| 310 | } |
| 311 | |
| 312 | static void __tmc_etr_disable_to_bam(struct tmc_drvdata *drvdata) |
| 313 | { |
| 314 | if (!drvdata->enable_to_bam) |
| 315 | return; |
| 316 | |
Pratik Patel | bfd2de6 | 2013-01-26 12:14:59 -0800 | [diff] [blame] | 317 | /* Ensure periodic flush is disabled in CSR block */ |
| 318 | msm_qdss_csr_disable_flush(); |
| 319 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 320 | TMC_UNLOCK(drvdata); |
| 321 | |
Pratik Patel | bfd2de6 | 2013-01-26 12:14:59 -0800 | [diff] [blame] | 322 | tmc_wait_for_flush(drvdata); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 323 | tmc_flush_and_stop(drvdata); |
| 324 | __tmc_disable(drvdata); |
| 325 | |
| 326 | TMC_LOCK(drvdata); |
| 327 | |
Pratik Patel | bfd2de6 | 2013-01-26 12:14:59 -0800 | [diff] [blame] | 328 | /* Disable CSR configuration */ |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 329 | msm_qdss_csr_disable_bam_to_usb(); |
| 330 | drvdata->enable_to_bam = false; |
| 331 | } |
| 332 | |
| 333 | static void tmc_etr_bam_disable(struct tmc_drvdata *drvdata) |
| 334 | { |
| 335 | struct tmc_etr_bam_data *bamdata = drvdata->bamdata; |
| 336 | |
| 337 | if (!bamdata->enable) |
| 338 | return; |
| 339 | |
| 340 | sps_disconnect(bamdata->pipe); |
| 341 | sps_free_endpoint(bamdata->pipe); |
| 342 | bamdata->enable = false; |
| 343 | } |
| 344 | |
| 345 | static void usb_notifier(void *priv, unsigned int event, |
| 346 | struct qdss_request *d_req, struct usb_qdss_ch *ch) |
| 347 | { |
| 348 | struct tmc_drvdata *drvdata = priv; |
| 349 | unsigned long flags; |
| 350 | int ret = 0; |
| 351 | |
| 352 | mutex_lock(&drvdata->usb_lock); |
| 353 | if (event == USB_QDSS_CONNECT) { |
| 354 | tmc_etr_fill_usb_bam_data(drvdata); |
| 355 | ret = tmc_etr_bam_enable(drvdata); |
| 356 | if (ret) |
| 357 | dev_err(drvdata->dev, "ETR BAM enable failed\n"); |
| 358 | |
| 359 | spin_lock_irqsave(&drvdata->spinlock, flags); |
| 360 | __tmc_etr_enable_to_bam(drvdata); |
| 361 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 362 | } else if (event == USB_QDSS_DISCONNECT) { |
| 363 | spin_lock_irqsave(&drvdata->spinlock, flags); |
| 364 | __tmc_etr_disable_to_bam(drvdata); |
| 365 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 366 | tmc_etr_bam_disable(drvdata); |
| 367 | } |
| 368 | mutex_unlock(&drvdata->usb_lock); |
| 369 | } |
| 370 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 371 | static void __tmc_etb_enable(struct tmc_drvdata *drvdata) |
| 372 | { |
| 373 | /* Zero out the memory to help with debug */ |
| 374 | memset(drvdata->buf, 0, drvdata->size); |
| 375 | |
| 376 | TMC_UNLOCK(drvdata); |
| 377 | |
| 378 | tmc_writel(drvdata, TMC_MODE_CIRCULAR_BUFFER, TMC_MODE); |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 379 | tmc_writel(drvdata, 0x1133, TMC_FFCR); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 380 | tmc_writel(drvdata, drvdata->trigger_cntr, TMC_TRG); |
| 381 | __tmc_enable(drvdata); |
| 382 | |
| 383 | TMC_LOCK(drvdata); |
| 384 | } |
| 385 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 386 | static void __tmc_etr_enable_to_mem(struct tmc_drvdata *drvdata) |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 387 | { |
| 388 | uint32_t axictl; |
| 389 | |
| 390 | /* Zero out the memory to help with debug */ |
| 391 | memset(drvdata->vaddr, 0, drvdata->size); |
| 392 | |
| 393 | TMC_UNLOCK(drvdata); |
| 394 | |
| 395 | tmc_writel(drvdata, drvdata->size / BYTES_PER_WORD, TMC_RSZ); |
| 396 | tmc_writel(drvdata, TMC_MODE_CIRCULAR_BUFFER, TMC_MODE); |
| 397 | |
| 398 | axictl = tmc_readl(drvdata, TMC_AXICTL); |
| 399 | axictl |= (0xF << 8); |
| 400 | tmc_writel(drvdata, axictl, TMC_AXICTL); |
| 401 | axictl &= ~(0x1 << 7); |
| 402 | tmc_writel(drvdata, axictl, TMC_AXICTL); |
| 403 | axictl = (axictl & ~0x3) | 0x2; |
| 404 | tmc_writel(drvdata, axictl, TMC_AXICTL); |
| 405 | |
| 406 | tmc_writel(drvdata, drvdata->paddr, TMC_DBALO); |
| 407 | tmc_writel(drvdata, 0x0, TMC_DBAHI); |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 408 | tmc_writel(drvdata, 0x1133, TMC_FFCR); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 409 | tmc_writel(drvdata, drvdata->trigger_cntr, TMC_TRG); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 410 | __tmc_enable(drvdata); |
| 411 | |
| 412 | TMC_LOCK(drvdata); |
| 413 | } |
| 414 | |
| 415 | static void __tmc_etf_enable(struct tmc_drvdata *drvdata) |
| 416 | { |
| 417 | TMC_UNLOCK(drvdata); |
| 418 | |
| 419 | tmc_writel(drvdata, TMC_MODE_HARDWARE_FIFO, TMC_MODE); |
| 420 | tmc_writel(drvdata, 0x3, TMC_FFCR); |
| 421 | tmc_writel(drvdata, 0x0, TMC_BUFWM); |
| 422 | __tmc_enable(drvdata); |
| 423 | |
| 424 | TMC_LOCK(drvdata); |
| 425 | } |
| 426 | |
| 427 | static int tmc_enable(struct tmc_drvdata *drvdata, enum tmc_mode mode) |
| 428 | { |
| 429 | int ret; |
| 430 | unsigned long flags; |
| 431 | |
| 432 | ret = clk_prepare_enable(drvdata->clk); |
| 433 | if (ret) |
| 434 | return ret; |
| 435 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 436 | mutex_lock(&drvdata->usb_lock); |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 437 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) { |
| 438 | coresight_cti_map_trigout(drvdata->cti_flush, 1, 0); |
| 439 | coresight_cti_map_trigin(drvdata->cti_reset, 0, 0); |
| 440 | } else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 441 | if (drvdata->out_mode == TMC_ETR_OUT_MODE_MEM && |
| 442 | !drvdata->reset_flush_race) { |
| 443 | coresight_cti_map_trigout(drvdata->cti_flush, 3, 0); |
| 444 | coresight_cti_map_trigin(drvdata->cti_reset, 0, 0); |
| 445 | } else if (drvdata->out_mode == TMC_ETR_OUT_MODE_USB) { |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 446 | drvdata->usbch = usb_qdss_open("qdss", drvdata, |
| 447 | usb_notifier); |
| 448 | if (IS_ERR(drvdata->usbch)) { |
| 449 | dev_err(drvdata->dev, "usb_qdss_open failed\n"); |
| 450 | ret = PTR_ERR(drvdata->usbch); |
| 451 | goto err0; |
| 452 | } |
| 453 | } |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 454 | } else { |
| 455 | if (mode == TMC_MODE_CIRCULAR_BUFFER) { |
| 456 | coresight_cti_map_trigout(drvdata->cti_flush, 1, 0); |
| 457 | coresight_cti_map_trigin(drvdata->cti_reset, 0, 0); |
| 458 | } |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 461 | spin_lock_irqsave(&drvdata->spinlock, flags); |
| 462 | if (drvdata->reading) { |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 463 | ret = -EBUSY; |
| 464 | goto err1; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) { |
| 468 | __tmc_etb_enable(drvdata); |
| 469 | } else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 470 | if (drvdata->out_mode == TMC_ETR_OUT_MODE_MEM) |
| 471 | __tmc_etr_enable_to_mem(drvdata); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 472 | } else { |
| 473 | if (mode == TMC_MODE_CIRCULAR_BUFFER) |
| 474 | __tmc_etb_enable(drvdata); |
| 475 | else |
| 476 | __tmc_etf_enable(drvdata); |
| 477 | } |
| 478 | drvdata->enable = true; |
| 479 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 480 | mutex_unlock(&drvdata->usb_lock); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 481 | |
| 482 | dev_info(drvdata->dev, "TMC enabled\n"); |
| 483 | return 0; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 484 | err1: |
| 485 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 486 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) |
| 487 | if (drvdata->out_mode == TMC_ETR_OUT_MODE_USB) |
| 488 | usb_qdss_close(drvdata->usbch); |
| 489 | err0: |
| 490 | mutex_unlock(&drvdata->usb_lock); |
| 491 | clk_disable_unprepare(drvdata->clk); |
| 492 | return ret; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static int tmc_enable_sink(struct coresight_device *csdev) |
| 496 | { |
| 497 | struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
| 498 | |
| 499 | return tmc_enable(drvdata, TMC_MODE_CIRCULAR_BUFFER); |
| 500 | } |
| 501 | |
| 502 | static int tmc_enable_link(struct coresight_device *csdev, int inport, |
| 503 | int outport) |
| 504 | { |
| 505 | struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
| 506 | |
| 507 | return tmc_enable(drvdata, TMC_MODE_HARDWARE_FIFO); |
| 508 | } |
| 509 | |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 510 | static void __tmc_reg_dump(struct tmc_drvdata *drvdata) |
| 511 | { |
| 512 | char *reg_hdr; |
| 513 | uint32_t *reg_buf; |
| 514 | |
| 515 | if (!drvdata->reg_buf || !drvdata->aborting) |
| 516 | return; |
| 517 | |
| 518 | reg_hdr = drvdata->reg_buf - PAGE_SIZE; |
| 519 | reg_buf = (uint32_t *)drvdata->reg_buf; |
| 520 | |
| 521 | reg_buf[1] = tmc_readl(drvdata, TMC_RSZ); |
| 522 | reg_buf[3] = tmc_readl(drvdata, TMC_STS); |
| 523 | reg_buf[5] = tmc_readl(drvdata, TMC_RRP); |
| 524 | reg_buf[6] = tmc_readl(drvdata, TMC_RWP); |
| 525 | reg_buf[7] = tmc_readl(drvdata, TMC_TRG); |
| 526 | reg_buf[8] = tmc_readl(drvdata, TMC_CTL); |
| 527 | reg_buf[10] = tmc_readl(drvdata, TMC_MODE); |
| 528 | reg_buf[11] = tmc_readl(drvdata, TMC_LBUFLEVEL); |
| 529 | reg_buf[12] = tmc_readl(drvdata, TMC_CBUFLEVEL); |
| 530 | reg_buf[13] = tmc_readl(drvdata, TMC_BUFWM); |
| 531 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
| 532 | reg_buf[14] = tmc_readl(drvdata, TMC_RRPHI); |
| 533 | reg_buf[15] = tmc_readl(drvdata, TMC_RWPHI); |
| 534 | reg_buf[68] = tmc_readl(drvdata, TMC_AXICTL); |
| 535 | reg_buf[70] = tmc_readl(drvdata, TMC_DBALO); |
| 536 | reg_buf[71] = tmc_readl(drvdata, TMC_DBAHI); |
| 537 | } |
| 538 | reg_buf[192] = tmc_readl(drvdata, TMC_FFSR); |
| 539 | reg_buf[193] = tmc_readl(drvdata, TMC_FFCR); |
| 540 | reg_buf[194] = tmc_readl(drvdata, TMC_PSCR); |
| 541 | reg_buf[1000] = tmc_readl(drvdata, CORESIGHT_CLAIMSET); |
| 542 | reg_buf[1001] = tmc_readl(drvdata, CORESIGHT_CLAIMCLR); |
| 543 | reg_buf[1005] = tmc_readl(drvdata, CORESIGHT_LSR); |
| 544 | reg_buf[1006] = tmc_readl(drvdata, CORESIGHT_AUTHSTATUS); |
| 545 | reg_buf[1010] = tmc_readl(drvdata, CORESIGHT_DEVID); |
| 546 | reg_buf[1011] = tmc_readl(drvdata, CORESIGHT_DEVTYPE); |
| 547 | reg_buf[1012] = tmc_readl(drvdata, CORESIGHT_PERIPHIDR4); |
| 548 | reg_buf[1013] = tmc_readl(drvdata, CORESIGHT_PERIPHIDR5); |
| 549 | reg_buf[1014] = tmc_readl(drvdata, CORESIGHT_PERIPHIDR6); |
| 550 | reg_buf[1015] = tmc_readl(drvdata, CORESIGHT_PERIPHIDR7); |
| 551 | reg_buf[1016] = tmc_readl(drvdata, CORESIGHT_PERIPHIDR0); |
| 552 | reg_buf[1017] = tmc_readl(drvdata, CORESIGHT_PERIPHIDR1); |
| 553 | reg_buf[1018] = tmc_readl(drvdata, CORESIGHT_PERIPHIDR2); |
| 554 | reg_buf[1019] = tmc_readl(drvdata, CORESIGHT_PERIPHIDR3); |
| 555 | reg_buf[1020] = tmc_readl(drvdata, CORESIGHT_COMPIDR0); |
| 556 | reg_buf[1021] = tmc_readl(drvdata, CORESIGHT_COMPIDR1); |
| 557 | reg_buf[1022] = tmc_readl(drvdata, CORESIGHT_COMPIDR2); |
| 558 | reg_buf[1023] = tmc_readl(drvdata, CORESIGHT_COMPIDR3); |
| 559 | |
| 560 | *(uint32_t *)(reg_hdr + TMC_REG_DUMP_MAGIC_OFF) = TMC_REG_DUMP_MAGIC; |
| 561 | } |
| 562 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 563 | static void __tmc_etb_dump(struct tmc_drvdata *drvdata) |
| 564 | { |
| 565 | enum tmc_mem_intf_width memwidth; |
| 566 | uint8_t memwords; |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 567 | char *hdr; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 568 | char *bufp; |
| 569 | uint32_t read_data; |
| 570 | int i; |
| 571 | |
| 572 | memwidth = BMVAL(tmc_readl(drvdata, CORESIGHT_DEVID), 8, 10); |
| 573 | if (memwidth == TMC_MEM_INTF_WIDTH_32BITS) |
| 574 | memwords = 1; |
| 575 | else if (memwidth == TMC_MEM_INTF_WIDTH_64BITS) |
| 576 | memwords = 2; |
| 577 | else if (memwidth == TMC_MEM_INTF_WIDTH_128BITS) |
| 578 | memwords = 4; |
| 579 | else |
| 580 | memwords = 8; |
| 581 | |
| 582 | bufp = drvdata->buf; |
| 583 | while (1) { |
| 584 | for (i = 0; i < memwords; i++) { |
| 585 | read_data = tmc_readl(drvdata, TMC_RRD); |
| 586 | if (read_data == 0xFFFFFFFF) |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 587 | goto out; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 588 | memcpy(bufp, &read_data, BYTES_PER_WORD); |
| 589 | bufp += BYTES_PER_WORD; |
| 590 | } |
| 591 | } |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 592 | |
| 593 | out: |
| 594 | if (drvdata->aborting) { |
| 595 | hdr = drvdata->buf - PAGE_SIZE; |
| 596 | *(uint32_t *)(hdr + TMC_ETFETB_DUMP_MAGIC_OFF) = |
| 597 | TMC_ETFETB_DUMP_MAGIC; |
| 598 | } |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | static void __tmc_etb_disable(struct tmc_drvdata *drvdata) |
| 602 | { |
| 603 | TMC_UNLOCK(drvdata); |
| 604 | |
| 605 | tmc_flush_and_stop(drvdata); |
| 606 | __tmc_etb_dump(drvdata); |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 607 | __tmc_reg_dump(drvdata); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 608 | __tmc_disable(drvdata); |
| 609 | |
| 610 | TMC_LOCK(drvdata); |
| 611 | } |
| 612 | |
| 613 | static void __tmc_etr_dump(struct tmc_drvdata *drvdata) |
| 614 | { |
| 615 | uint32_t rwp, rwphi; |
| 616 | |
| 617 | rwp = tmc_readl(drvdata, TMC_RWP); |
| 618 | rwphi = tmc_readl(drvdata, TMC_RWPHI); |
| 619 | |
| 620 | if (BVAL(tmc_readl(drvdata, TMC_STS), 0)) |
Pratik Patel | 05fe91e | 2012-08-10 10:47:08 -0700 | [diff] [blame] | 621 | drvdata->buf = drvdata->vaddr + rwp - drvdata->paddr; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 622 | else |
| 623 | drvdata->buf = drvdata->vaddr; |
| 624 | } |
| 625 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 626 | static void __tmc_etr_disable_to_mem(struct tmc_drvdata *drvdata) |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 627 | { |
| 628 | TMC_UNLOCK(drvdata); |
| 629 | |
| 630 | tmc_flush_and_stop(drvdata); |
| 631 | __tmc_etr_dump(drvdata); |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 632 | __tmc_reg_dump(drvdata); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 633 | __tmc_disable(drvdata); |
| 634 | |
| 635 | TMC_LOCK(drvdata); |
| 636 | } |
| 637 | |
| 638 | static void __tmc_etf_disable(struct tmc_drvdata *drvdata) |
| 639 | { |
| 640 | TMC_UNLOCK(drvdata); |
| 641 | |
| 642 | tmc_flush_and_stop(drvdata); |
| 643 | __tmc_disable(drvdata); |
| 644 | |
| 645 | TMC_LOCK(drvdata); |
| 646 | } |
| 647 | |
| 648 | static void tmc_disable(struct tmc_drvdata *drvdata, enum tmc_mode mode) |
| 649 | { |
| 650 | unsigned long flags; |
| 651 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 652 | mutex_lock(&drvdata->usb_lock); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 653 | spin_lock_irqsave(&drvdata->spinlock, flags); |
| 654 | if (drvdata->reading) |
| 655 | goto out; |
| 656 | |
| 657 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) { |
| 658 | __tmc_etb_disable(drvdata); |
| 659 | } else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 660 | if (drvdata->out_mode == TMC_ETR_OUT_MODE_MEM) |
| 661 | __tmc_etr_disable_to_mem(drvdata); |
| 662 | else if (drvdata->out_mode == TMC_ETR_OUT_MODE_USB) |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 663 | __tmc_etr_disable_to_bam(drvdata); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 664 | } else { |
| 665 | if (mode == TMC_MODE_CIRCULAR_BUFFER) |
| 666 | __tmc_etb_disable(drvdata); |
| 667 | else |
| 668 | __tmc_etf_disable(drvdata); |
| 669 | } |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 670 | drvdata->enable = false; |
| 671 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 672 | |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 673 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) { |
| 674 | coresight_cti_unmap_trigin(drvdata->cti_reset, 0, 0); |
| 675 | coresight_cti_unmap_trigout(drvdata->cti_flush, 1, 0); |
| 676 | } else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 677 | if (drvdata->out_mode == TMC_ETR_OUT_MODE_MEM && |
| 678 | !drvdata->reset_flush_race) { |
| 679 | coresight_cti_unmap_trigin(drvdata->cti_reset, 0, 0); |
| 680 | coresight_cti_unmap_trigout(drvdata->cti_flush, 3, 0); |
| 681 | } else if (drvdata->out_mode == TMC_ETR_OUT_MODE_USB) { |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 682 | tmc_etr_bam_disable(drvdata); |
| 683 | usb_qdss_close(drvdata->usbch); |
| 684 | } |
| 685 | } else { |
| 686 | if (mode == TMC_MODE_CIRCULAR_BUFFER) { |
| 687 | coresight_cti_unmap_trigin(drvdata->cti_reset, 0, 0); |
| 688 | coresight_cti_unmap_trigout(drvdata->cti_flush, 1, 0); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | mutex_unlock(&drvdata->usb_lock); |
| 692 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 693 | clk_disable_unprepare(drvdata->clk); |
| 694 | |
| 695 | dev_info(drvdata->dev, "TMC disabled\n"); |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 696 | return; |
| 697 | out: |
| 698 | drvdata->enable = false; |
| 699 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 700 | mutex_unlock(&drvdata->usb_lock); |
| 701 | |
| 702 | clk_disable_unprepare(drvdata->clk); |
| 703 | |
| 704 | dev_info(drvdata->dev, "TMC disabled\n"); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | static void tmc_disable_sink(struct coresight_device *csdev) |
| 708 | { |
| 709 | struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
| 710 | |
| 711 | tmc_disable(drvdata, TMC_MODE_CIRCULAR_BUFFER); |
| 712 | } |
| 713 | |
| 714 | static void tmc_disable_link(struct coresight_device *csdev, int inport, |
| 715 | int outport) |
| 716 | { |
| 717 | struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
| 718 | |
| 719 | tmc_disable(drvdata, TMC_MODE_HARDWARE_FIFO); |
| 720 | } |
| 721 | |
Pratik Patel | cf7d045 | 2012-07-02 13:57:20 -0700 | [diff] [blame] | 722 | static void tmc_abort(struct coresight_device *csdev) |
| 723 | { |
| 724 | struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
| 725 | unsigned long flags; |
| 726 | enum tmc_mode mode; |
| 727 | |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 728 | drvdata->aborting = true; |
| 729 | |
Pratik Patel | cf7d045 | 2012-07-02 13:57:20 -0700 | [diff] [blame] | 730 | spin_lock_irqsave(&drvdata->spinlock, flags); |
| 731 | if (drvdata->reading) |
| 732 | goto out0; |
| 733 | |
| 734 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) { |
| 735 | __tmc_etb_disable(drvdata); |
| 736 | } else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 737 | if (drvdata->out_mode == TMC_ETR_OUT_MODE_MEM) |
| 738 | __tmc_etr_disable_to_mem(drvdata); |
Pratik Patel | 89a7662 | 2013-02-09 21:34:41 -0800 | [diff] [blame] | 739 | else if (drvdata->out_mode == TMC_ETR_OUT_MODE_USB) |
| 740 | __tmc_etr_disable_to_bam(drvdata); |
Pratik Patel | cf7d045 | 2012-07-02 13:57:20 -0700 | [diff] [blame] | 741 | } else { |
| 742 | mode = tmc_readl(drvdata, TMC_MODE); |
| 743 | if (mode == TMC_MODE_CIRCULAR_BUFFER) |
| 744 | __tmc_etb_disable(drvdata); |
| 745 | else |
| 746 | goto out1; |
| 747 | } |
| 748 | out0: |
| 749 | drvdata->enable = false; |
| 750 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 751 | |
| 752 | dev_info(drvdata->dev, "TMC aborted\n"); |
| 753 | return; |
| 754 | out1: |
| 755 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 756 | } |
| 757 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 758 | static const struct coresight_ops_sink tmc_sink_ops = { |
| 759 | .enable = tmc_enable_sink, |
| 760 | .disable = tmc_disable_sink, |
Pratik Patel | cf7d045 | 2012-07-02 13:57:20 -0700 | [diff] [blame] | 761 | .abort = tmc_abort, |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 762 | }; |
| 763 | |
| 764 | static const struct coresight_ops_link tmc_link_ops = { |
| 765 | .enable = tmc_enable_link, |
| 766 | .disable = tmc_disable_link, |
| 767 | }; |
| 768 | |
| 769 | static const struct coresight_ops tmc_etb_cs_ops = { |
| 770 | .sink_ops = &tmc_sink_ops, |
| 771 | }; |
| 772 | |
| 773 | static const struct coresight_ops tmc_etr_cs_ops = { |
| 774 | .sink_ops = &tmc_sink_ops, |
| 775 | }; |
| 776 | |
| 777 | static const struct coresight_ops tmc_etf_cs_ops = { |
| 778 | .sink_ops = &tmc_sink_ops, |
| 779 | .link_ops = &tmc_link_ops, |
| 780 | }; |
| 781 | |
| 782 | static int tmc_read_prepare(struct tmc_drvdata *drvdata) |
| 783 | { |
| 784 | int ret; |
| 785 | unsigned long flags; |
| 786 | enum tmc_mode mode; |
| 787 | |
| 788 | spin_lock_irqsave(&drvdata->spinlock, flags); |
| 789 | if (!drvdata->enable) |
| 790 | goto out; |
| 791 | |
| 792 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) { |
| 793 | __tmc_etb_disable(drvdata); |
| 794 | } else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 795 | if (drvdata->out_mode == TMC_ETR_OUT_MODE_MEM) { |
| 796 | __tmc_etr_disable_to_mem(drvdata); |
| 797 | } else { |
| 798 | ret = -ENODEV; |
| 799 | goto err; |
| 800 | } |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 801 | } else { |
| 802 | mode = tmc_readl(drvdata, TMC_MODE); |
| 803 | if (mode == TMC_MODE_CIRCULAR_BUFFER) { |
| 804 | __tmc_etb_disable(drvdata); |
| 805 | } else { |
| 806 | ret = -ENODEV; |
| 807 | goto err; |
| 808 | } |
| 809 | } |
| 810 | out: |
| 811 | drvdata->reading = true; |
| 812 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 813 | |
| 814 | dev_info(drvdata->dev, "TMC read start\n"); |
| 815 | return 0; |
| 816 | err: |
| 817 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 818 | return ret; |
| 819 | } |
| 820 | |
| 821 | static void tmc_read_unprepare(struct tmc_drvdata *drvdata) |
| 822 | { |
| 823 | unsigned long flags; |
| 824 | enum tmc_mode mode; |
| 825 | |
| 826 | spin_lock_irqsave(&drvdata->spinlock, flags); |
| 827 | if (!drvdata->enable) |
| 828 | goto out; |
| 829 | |
| 830 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) { |
| 831 | __tmc_etb_enable(drvdata); |
| 832 | } else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 833 | if (drvdata->out_mode == TMC_ETR_OUT_MODE_MEM) |
| 834 | __tmc_etr_enable_to_mem(drvdata); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 835 | } else { |
| 836 | mode = tmc_readl(drvdata, TMC_MODE); |
| 837 | if (mode == TMC_MODE_CIRCULAR_BUFFER) |
| 838 | __tmc_etb_enable(drvdata); |
| 839 | } |
| 840 | out: |
| 841 | drvdata->reading = false; |
| 842 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 843 | |
| 844 | dev_info(drvdata->dev, "TMC read end\n"); |
| 845 | } |
| 846 | |
| 847 | static int tmc_open(struct inode *inode, struct file *file) |
| 848 | { |
| 849 | struct tmc_drvdata *drvdata = container_of(file->private_data, |
| 850 | struct tmc_drvdata, miscdev); |
| 851 | int ret = 0; |
| 852 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 853 | mutex_lock(&drvdata->read_lock); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 854 | if (drvdata->read_count++) |
| 855 | goto out; |
| 856 | |
| 857 | ret = tmc_read_prepare(drvdata); |
| 858 | if (ret) |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 859 | goto err; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 860 | out: |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 861 | mutex_unlock(&drvdata->read_lock); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 862 | nonseekable_open(inode, file); |
| 863 | |
| 864 | dev_dbg(drvdata->dev, "%s: successfully opened\n", __func__); |
| 865 | return 0; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 866 | err: |
| 867 | drvdata->read_count--; |
| 868 | mutex_unlock(&drvdata->read_lock); |
| 869 | return ret; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | static ssize_t tmc_read(struct file *file, char __user *data, size_t len, |
| 873 | loff_t *ppos) |
| 874 | { |
| 875 | struct tmc_drvdata *drvdata = container_of(file->private_data, |
| 876 | struct tmc_drvdata, miscdev); |
| 877 | char *bufp = drvdata->buf + *ppos; |
| 878 | |
| 879 | if (*ppos + len > drvdata->size) |
| 880 | len = drvdata->size - *ppos; |
| 881 | |
| 882 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
| 883 | if (bufp == (char *)(drvdata->vaddr + drvdata->size)) |
| 884 | bufp = drvdata->vaddr; |
Pratik Patel | 05fe91e | 2012-08-10 10:47:08 -0700 | [diff] [blame] | 885 | else if (bufp > (char *)(drvdata->vaddr + drvdata->size)) |
| 886 | bufp -= drvdata->size; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 887 | if ((bufp + len) > (char *)(drvdata->vaddr + drvdata->size)) |
| 888 | len = (char *)(drvdata->vaddr + drvdata->size) - bufp; |
| 889 | } |
| 890 | |
| 891 | if (copy_to_user(data, bufp, len)) { |
| 892 | dev_dbg(drvdata->dev, "%s: copy_to_user failed\n", __func__); |
| 893 | return -EFAULT; |
| 894 | } |
| 895 | |
| 896 | *ppos += len; |
| 897 | |
| 898 | dev_dbg(drvdata->dev, "%s: %d bytes copied, %d bytes left\n", |
| 899 | __func__, len, (int) (drvdata->size - *ppos)); |
| 900 | return len; |
| 901 | } |
| 902 | |
| 903 | static int tmc_release(struct inode *inode, struct file *file) |
| 904 | { |
| 905 | struct tmc_drvdata *drvdata = container_of(file->private_data, |
| 906 | struct tmc_drvdata, miscdev); |
| 907 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 908 | mutex_lock(&drvdata->read_lock); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 909 | if (--drvdata->read_count) { |
| 910 | if (drvdata->read_count < 0) { |
| 911 | WARN_ONCE(1, "mismatched close\n"); |
| 912 | drvdata->read_count = 0; |
| 913 | } |
| 914 | goto out; |
| 915 | } |
| 916 | |
| 917 | tmc_read_unprepare(drvdata); |
| 918 | out: |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 919 | mutex_unlock(&drvdata->read_lock); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 920 | dev_dbg(drvdata->dev, "%s: released\n", __func__); |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | static const struct file_operations tmc_fops = { |
| 925 | .owner = THIS_MODULE, |
| 926 | .open = tmc_open, |
| 927 | .read = tmc_read, |
| 928 | .release = tmc_release, |
| 929 | .llseek = no_llseek, |
| 930 | }; |
| 931 | |
| 932 | static ssize_t tmc_show_trigger_cntr(struct device *dev, |
| 933 | struct device_attribute *attr, char *buf) |
| 934 | { |
| 935 | struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent); |
| 936 | unsigned long val = drvdata->trigger_cntr; |
| 937 | |
| 938 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 939 | } |
| 940 | |
| 941 | static ssize_t tmc_store_trigger_cntr(struct device *dev, |
| 942 | struct device_attribute *attr, |
| 943 | const char *buf, size_t size) |
| 944 | { |
| 945 | struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent); |
| 946 | unsigned long val; |
| 947 | |
| 948 | if (sscanf(buf, "%lx", &val) != 1) |
| 949 | return -EINVAL; |
| 950 | |
| 951 | drvdata->trigger_cntr = val; |
| 952 | return size; |
| 953 | } |
| 954 | static DEVICE_ATTR(trigger_cntr, S_IRUGO | S_IWUSR, tmc_show_trigger_cntr, |
| 955 | tmc_store_trigger_cntr); |
| 956 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 957 | static ssize_t tmc_etr_show_out_mode(struct device *dev, |
| 958 | struct device_attribute *attr, char *buf) |
| 959 | { |
| 960 | struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent); |
| 961 | |
| 962 | return scnprintf(buf, PAGE_SIZE, "%s\n", |
| 963 | drvdata->out_mode == TMC_ETR_OUT_MODE_MEM ? |
| 964 | "mem" : "usb"); |
| 965 | } |
| 966 | |
| 967 | static ssize_t tmc_etr_store_out_mode(struct device *dev, |
| 968 | struct device_attribute *attr, |
| 969 | const char *buf, size_t size) |
| 970 | { |
| 971 | struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent); |
| 972 | char str[10] = ""; |
| 973 | unsigned long flags; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 974 | int ret; |
| 975 | |
| 976 | if (strlen(buf) >= 10) |
| 977 | return -EINVAL; |
| 978 | if (sscanf(buf, "%s", str) != 1) |
| 979 | return -EINVAL; |
| 980 | |
| 981 | mutex_lock(&drvdata->usb_lock); |
| 982 | if (!strcmp(str, "mem")) { |
| 983 | if (drvdata->out_mode == TMC_ETR_OUT_MODE_MEM) |
| 984 | goto out; |
| 985 | |
| 986 | spin_lock_irqsave(&drvdata->spinlock, flags); |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 987 | if (!drvdata->enable) { |
| 988 | drvdata->out_mode = TMC_ETR_OUT_MODE_MEM; |
| 989 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 990 | goto out; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 991 | } |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 992 | __tmc_etr_disable_to_bam(drvdata); |
| 993 | __tmc_etr_enable_to_mem(drvdata); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 994 | drvdata->out_mode = TMC_ETR_OUT_MODE_MEM; |
| 995 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 996 | |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 997 | if (!drvdata->reset_flush_race) { |
| 998 | coresight_cti_map_trigout(drvdata->cti_flush, 3, 0); |
| 999 | coresight_cti_map_trigin(drvdata->cti_reset, 0, 0); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1000 | } |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 1001 | |
| 1002 | tmc_etr_bam_disable(drvdata); |
| 1003 | usb_qdss_close(drvdata->usbch); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1004 | } else if (!strcmp(str, "usb")) { |
| 1005 | if (drvdata->out_mode == TMC_ETR_OUT_MODE_USB) |
| 1006 | goto out; |
| 1007 | |
| 1008 | spin_lock_irqsave(&drvdata->spinlock, flags); |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 1009 | if (!drvdata->enable) { |
| 1010 | drvdata->out_mode = TMC_ETR_OUT_MODE_USB; |
| 1011 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 1012 | goto out; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1013 | } |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 1014 | if (drvdata->reading) { |
| 1015 | ret = -EBUSY; |
| 1016 | goto err1; |
| 1017 | } |
| 1018 | __tmc_etr_disable_to_mem(drvdata); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1019 | drvdata->out_mode = TMC_ETR_OUT_MODE_USB; |
| 1020 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 1021 | |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 1022 | if (!drvdata->reset_flush_race) { |
| 1023 | coresight_cti_unmap_trigin(drvdata->cti_reset, 0, 0); |
| 1024 | coresight_cti_unmap_trigout(drvdata->cti_flush, 3, 0); |
| 1025 | } |
| 1026 | |
| 1027 | drvdata->usbch = usb_qdss_open("qdss", drvdata, |
| 1028 | usb_notifier); |
| 1029 | if (IS_ERR(drvdata->usbch)) { |
| 1030 | dev_err(drvdata->dev, "usb_qdss_open failed\n"); |
| 1031 | ret = PTR_ERR(drvdata->usbch); |
| 1032 | goto err0; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1033 | } |
| 1034 | } |
| 1035 | out: |
| 1036 | mutex_unlock(&drvdata->usb_lock); |
| 1037 | return size; |
| 1038 | err1: |
| 1039 | spin_unlock_irqrestore(&drvdata->spinlock, flags); |
| 1040 | err0: |
| 1041 | mutex_unlock(&drvdata->usb_lock); |
| 1042 | return ret; |
| 1043 | } |
| 1044 | static DEVICE_ATTR(out_mode, S_IRUGO | S_IWUSR, tmc_etr_show_out_mode, |
| 1045 | tmc_etr_store_out_mode); |
| 1046 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1047 | static struct attribute *tmc_attrs[] = { |
| 1048 | &dev_attr_trigger_cntr.attr, |
| 1049 | NULL, |
| 1050 | }; |
| 1051 | |
| 1052 | static struct attribute_group tmc_attr_grp = { |
| 1053 | .attrs = tmc_attrs, |
| 1054 | }; |
| 1055 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1056 | static struct attribute *tmc_etr_attrs[] = { |
| 1057 | &dev_attr_out_mode.attr, |
| 1058 | NULL, |
| 1059 | }; |
| 1060 | |
| 1061 | static struct attribute_group tmc_etr_attr_grp = { |
| 1062 | .attrs = tmc_etr_attrs, |
| 1063 | }; |
| 1064 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1065 | static const struct attribute_group *tmc_etb_attr_grps[] = { |
| 1066 | &tmc_attr_grp, |
| 1067 | NULL, |
| 1068 | }; |
| 1069 | |
| 1070 | static const struct attribute_group *tmc_etr_attr_grps[] = { |
| 1071 | &tmc_attr_grp, |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1072 | &tmc_etr_attr_grp, |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1073 | NULL, |
| 1074 | }; |
| 1075 | |
| 1076 | static const struct attribute_group *tmc_etf_attr_grps[] = { |
| 1077 | &tmc_attr_grp, |
| 1078 | NULL, |
| 1079 | }; |
| 1080 | |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1081 | static int __devinit tmc_etr_bam_init(struct platform_device *pdev, |
| 1082 | struct tmc_drvdata *drvdata) |
| 1083 | { |
| 1084 | struct device *dev = &pdev->dev; |
| 1085 | struct resource *res; |
| 1086 | struct tmc_etr_bam_data *bamdata; |
| 1087 | |
| 1088 | bamdata = devm_kzalloc(dev, sizeof(*bamdata), GFP_KERNEL); |
| 1089 | if (!bamdata) |
| 1090 | return -ENOMEM; |
| 1091 | drvdata->bamdata = bamdata; |
| 1092 | |
Aparna Das | c990751 | 2013-03-08 10:20:52 -0800 | [diff] [blame] | 1093 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "bam-base"); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1094 | if (!res) |
| 1095 | return -ENODEV; |
| 1096 | |
| 1097 | bamdata->props.phys_addr = res->start; |
| 1098 | bamdata->props.virt_addr = devm_ioremap(dev, res->start, |
| 1099 | resource_size(res)); |
| 1100 | if (!bamdata->props.virt_addr) |
| 1101 | return -ENOMEM; |
| 1102 | bamdata->props.virt_size = resource_size(res); |
| 1103 | |
| 1104 | bamdata->props.event_threshold = 0x4; /* Pipe event threshold */ |
| 1105 | bamdata->props.summing_threshold = 0x10; /* BAM event threshold */ |
| 1106 | bamdata->props.irq = 0; |
| 1107 | bamdata->props.num_pipes = TMC_ETR_BAM_NR_PIPES; |
| 1108 | |
| 1109 | return sps_register_bam_device(&bamdata->props, &bamdata->handle); |
| 1110 | } |
| 1111 | |
| 1112 | static void tmc_etr_bam_exit(struct tmc_drvdata *drvdata) |
| 1113 | { |
| 1114 | struct tmc_etr_bam_data *bamdata = drvdata->bamdata; |
| 1115 | |
| 1116 | if (!bamdata->handle) |
| 1117 | return; |
| 1118 | sps_deregister_bam_device(bamdata->handle); |
| 1119 | } |
| 1120 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1121 | static int __devinit tmc_probe(struct platform_device *pdev) |
| 1122 | { |
| 1123 | int ret; |
| 1124 | uint32_t devid; |
| 1125 | struct device *dev = &pdev->dev; |
| 1126 | struct coresight_platform_data *pdata; |
| 1127 | struct tmc_drvdata *drvdata; |
| 1128 | struct resource *res; |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1129 | uint32_t reg_size; |
| 1130 | static int etfetb_count; |
| 1131 | static int count; |
| 1132 | void *baddr; |
| 1133 | struct msm_client_dump dump; |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 1134 | struct coresight_cti_data *ctidata; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1135 | struct coresight_desc *desc; |
| 1136 | |
| 1137 | if (pdev->dev.of_node) { |
| 1138 | pdata = of_get_coresight_platform_data(dev, pdev->dev.of_node); |
| 1139 | if (IS_ERR(pdata)) |
| 1140 | return PTR_ERR(pdata); |
| 1141 | pdev->dev.platform_data = pdata; |
| 1142 | } |
| 1143 | |
| 1144 | drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); |
| 1145 | if (!drvdata) |
| 1146 | return -ENOMEM; |
| 1147 | drvdata->dev = &pdev->dev; |
| 1148 | platform_set_drvdata(pdev, drvdata); |
| 1149 | |
Aparna Das | c990751 | 2013-03-08 10:20:52 -0800 | [diff] [blame] | 1150 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tmc-base"); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1151 | if (!res) |
| 1152 | return -ENODEV; |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1153 | reg_size = resource_size(res); |
Pratik Patel | 2c09b76 | 2012-07-21 15:54:54 -0700 | [diff] [blame] | 1154 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1155 | drvdata->base = devm_ioremap(dev, res->start, resource_size(res)); |
| 1156 | if (!drvdata->base) |
| 1157 | return -ENOMEM; |
| 1158 | |
| 1159 | spin_lock_init(&drvdata->spinlock); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1160 | mutex_init(&drvdata->read_lock); |
| 1161 | mutex_init(&drvdata->usb_lock); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1162 | |
| 1163 | drvdata->clk = devm_clk_get(dev, "core_clk"); |
| 1164 | if (IS_ERR(drvdata->clk)) |
| 1165 | return PTR_ERR(drvdata->clk); |
Pratik Patel | 2c09b76 | 2012-07-21 15:54:54 -0700 | [diff] [blame] | 1166 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1167 | ret = clk_set_rate(drvdata->clk, CORESIGHT_CLK_RATE_TRACE); |
| 1168 | if (ret) |
| 1169 | return ret; |
| 1170 | |
| 1171 | ret = clk_prepare_enable(drvdata->clk); |
| 1172 | if (ret) |
| 1173 | return ret; |
Pratik Patel | 2c09b76 | 2012-07-21 15:54:54 -0700 | [diff] [blame] | 1174 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1175 | devid = tmc_readl(drvdata, CORESIGHT_DEVID); |
| 1176 | drvdata->config_type = BMVAL(devid, 6, 7); |
Pratik Patel | 2c09b76 | 2012-07-21 15:54:54 -0700 | [diff] [blame] | 1177 | |
Pratik Patel | 8c86adf | 2012-12-07 13:42:12 -0800 | [diff] [blame] | 1178 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
| 1179 | if (pdev->dev.of_node) { |
| 1180 | ret = of_property_read_u32(pdev->dev.of_node, |
| 1181 | "qcom,memory-reservation-size", &drvdata->size); |
| 1182 | if (ret) { |
| 1183 | clk_disable_unprepare(drvdata->clk); |
| 1184 | return ret; |
| 1185 | } |
| 1186 | } |
| 1187 | } else { |
Pratik Patel | e411ac7 | 2012-10-31 16:38:05 -0700 | [diff] [blame] | 1188 | drvdata->size = tmc_readl(drvdata, TMC_RSZ) * BYTES_PER_WORD; |
Pratik Patel | 8c86adf | 2012-12-07 13:42:12 -0800 | [diff] [blame] | 1189 | } |
Pratik Patel | 2c09b76 | 2012-07-21 15:54:54 -0700 | [diff] [blame] | 1190 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1191 | clk_disable_unprepare(drvdata->clk); |
| 1192 | |
| 1193 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
| 1194 | drvdata->paddr = allocate_contiguous_ebi_nomap(drvdata->size, |
| 1195 | SZ_4K); |
| 1196 | if (!drvdata->paddr) |
| 1197 | return -ENOMEM; |
| 1198 | drvdata->vaddr = devm_ioremap(dev, drvdata->paddr, |
| 1199 | drvdata->size); |
| 1200 | if (!drvdata->vaddr) { |
| 1201 | ret = -ENOMEM; |
| 1202 | goto err0; |
| 1203 | } |
| 1204 | memset(drvdata->vaddr, 0, drvdata->size); |
Pratik Patel | cd8ac7a | 2012-10-01 16:05:55 -0700 | [diff] [blame] | 1205 | drvdata->buf = drvdata->vaddr; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1206 | drvdata->out_mode = TMC_ETR_OUT_MODE_MEM; |
| 1207 | |
| 1208 | ret = tmc_etr_bam_init(pdev, drvdata); |
| 1209 | if (ret) |
| 1210 | goto err0; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1211 | } else { |
Pratik Patel | e411ac7 | 2012-10-31 16:38:05 -0700 | [diff] [blame] | 1212 | baddr = devm_kzalloc(dev, PAGE_SIZE + drvdata->size, |
| 1213 | GFP_KERNEL); |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1214 | if (!baddr) |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1215 | return -ENOMEM; |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1216 | drvdata->buf = baddr + PAGE_SIZE; |
| 1217 | *(uint32_t *)(baddr + TMC_ETFETB_DUMP_VER_OFF) = |
| 1218 | TMC_ETFETB_DUMP_VER; |
| 1219 | dump.id = MSM_TMC_ETFETB + etfetb_count; |
| 1220 | dump.start_addr = virt_to_phys(baddr); |
Pratik Patel | e411ac7 | 2012-10-31 16:38:05 -0700 | [diff] [blame] | 1221 | dump.end_addr = dump.start_addr + PAGE_SIZE + drvdata->size; |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1222 | ret = msm_dump_table_register(&dump); |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 1223 | /* |
| 1224 | * Don't free the buffer in case of error since it can still |
| 1225 | * be used to provide dump collection via the device node or |
| 1226 | * as part of abort. |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1227 | */ |
| 1228 | if (ret) |
| 1229 | dev_info(dev, "TMC ETF-ETB dump setup failed\n"); |
| 1230 | etfetb_count++; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1233 | baddr = devm_kzalloc(dev, PAGE_SIZE + reg_size, GFP_KERNEL); |
| 1234 | if (baddr) { |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 1235 | drvdata->reg_buf = baddr + PAGE_SIZE; |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1236 | *(uint32_t *)(baddr + TMC_REG_DUMP_VER_OFF) = TMC_REG_DUMP_VER; |
| 1237 | dump.id = MSM_TMC0_REG + count; |
| 1238 | dump.start_addr = virt_to_phys(baddr); |
| 1239 | dump.end_addr = dump.start_addr + PAGE_SIZE + reg_size; |
| 1240 | ret = msm_dump_table_register(&dump); |
Pratik Patel | 84750b2 | 2012-12-11 21:56:19 -0800 | [diff] [blame] | 1241 | /* |
| 1242 | * Don't free the buffer in case of error since it can still |
| 1243 | * be used to dump registers as part of abort to aid post crash |
| 1244 | * parsing. |
| 1245 | */ |
| 1246 | if (ret) |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1247 | dev_info(dev, "TMC REG dump setup failed\n"); |
Pratik Patel | 2647779 | 2012-09-07 01:35:36 -0700 | [diff] [blame] | 1248 | } else { |
| 1249 | dev_info(dev, "TMC REG dump space allocation failed\n"); |
| 1250 | } |
| 1251 | count++; |
| 1252 | |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 1253 | if (pdev->dev.of_node) { |
Pratik Patel | a554416 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 1254 | drvdata->reset_flush_race = of_property_read_bool( |
| 1255 | pdev->dev.of_node, |
| 1256 | "qcom,reset-flush-race"); |
| 1257 | |
Pratik Patel | 7c0b372 | 2013-02-08 11:57:27 -0800 | [diff] [blame] | 1258 | ctidata = of_get_coresight_cti_data(dev, pdev->dev.of_node); |
| 1259 | if (IS_ERR(ctidata)) { |
| 1260 | dev_err(dev, "invalid cti data\n"); |
| 1261 | } else if (ctidata && ctidata->nr_ctis == 2) { |
| 1262 | drvdata->cti_flush = coresight_cti_get( |
| 1263 | ctidata->names[0]); |
| 1264 | if (IS_ERR(drvdata->cti_flush)) |
| 1265 | dev_err(dev, "failed to get flush cti\n"); |
| 1266 | |
| 1267 | drvdata->cti_reset = coresight_cti_get( |
| 1268 | ctidata->names[1]); |
| 1269 | if (IS_ERR(drvdata->cti_reset)) |
| 1270 | dev_err(dev, "failed to get reset cti\n"); |
| 1271 | } |
| 1272 | } |
| 1273 | |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1274 | desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); |
| 1275 | if (!desc) { |
| 1276 | ret = -ENOMEM; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1277 | goto err1; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1278 | } |
| 1279 | if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) { |
| 1280 | desc->type = CORESIGHT_DEV_TYPE_SINK; |
| 1281 | desc->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER; |
| 1282 | desc->ops = &tmc_etb_cs_ops; |
| 1283 | desc->pdata = pdev->dev.platform_data; |
| 1284 | desc->dev = &pdev->dev; |
| 1285 | desc->groups = tmc_etb_attr_grps; |
| 1286 | desc->owner = THIS_MODULE; |
| 1287 | drvdata->csdev = coresight_register(desc); |
| 1288 | if (IS_ERR(drvdata->csdev)) { |
| 1289 | ret = PTR_ERR(drvdata->csdev); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1290 | goto err1; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1291 | } |
| 1292 | } else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { |
| 1293 | desc->type = CORESIGHT_DEV_TYPE_SINK; |
| 1294 | desc->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER; |
| 1295 | desc->ops = &tmc_etr_cs_ops; |
| 1296 | desc->pdata = pdev->dev.platform_data; |
| 1297 | desc->dev = &pdev->dev; |
| 1298 | desc->groups = tmc_etr_attr_grps; |
| 1299 | desc->owner = THIS_MODULE; |
| 1300 | drvdata->csdev = coresight_register(desc); |
| 1301 | if (IS_ERR(drvdata->csdev)) { |
| 1302 | ret = PTR_ERR(drvdata->csdev); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1303 | goto err1; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1304 | } |
| 1305 | } else { |
| 1306 | desc->type = CORESIGHT_DEV_TYPE_LINKSINK; |
| 1307 | desc->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER; |
| 1308 | desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_FIFO; |
| 1309 | desc->ops = &tmc_etf_cs_ops; |
| 1310 | desc->pdata = pdev->dev.platform_data; |
| 1311 | desc->dev = &pdev->dev; |
| 1312 | desc->groups = tmc_etf_attr_grps; |
| 1313 | desc->owner = THIS_MODULE; |
| 1314 | drvdata->csdev = coresight_register(desc); |
| 1315 | if (IS_ERR(drvdata->csdev)) { |
| 1316 | ret = PTR_ERR(drvdata->csdev); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1317 | goto err1; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | drvdata->miscdev.name = ((struct coresight_platform_data *) |
| 1322 | (pdev->dev.platform_data))->name; |
| 1323 | drvdata->miscdev.minor = MISC_DYNAMIC_MINOR; |
| 1324 | drvdata->miscdev.fops = &tmc_fops; |
| 1325 | ret = misc_register(&drvdata->miscdev); |
| 1326 | if (ret) |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1327 | goto err2; |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1328 | |
| 1329 | dev_info(dev, "TMC initialized\n"); |
| 1330 | return 0; |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1331 | err2: |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1332 | coresight_unregister(drvdata->csdev); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1333 | err1: |
| 1334 | tmc_etr_bam_exit(drvdata); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1335 | err0: |
| 1336 | free_contiguous_memory_by_paddr(drvdata->paddr); |
| 1337 | return ret; |
| 1338 | } |
| 1339 | |
| 1340 | static int __devexit tmc_remove(struct platform_device *pdev) |
| 1341 | { |
| 1342 | struct tmc_drvdata *drvdata = platform_get_drvdata(pdev); |
| 1343 | |
| 1344 | misc_deregister(&drvdata->miscdev); |
| 1345 | coresight_unregister(drvdata->csdev); |
Pratik Patel | b46038f | 2012-07-22 23:09:11 -0700 | [diff] [blame] | 1346 | tmc_etr_bam_exit(drvdata); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1347 | free_contiguous_memory_by_paddr(drvdata->paddr); |
| 1348 | return 0; |
| 1349 | } |
| 1350 | |
| 1351 | static struct of_device_id tmc_match[] = { |
| 1352 | {.compatible = "arm,coresight-tmc"}, |
| 1353 | {} |
| 1354 | }; |
Pratik Patel | fa896c9 | 2012-08-21 09:24:51 -0700 | [diff] [blame] | 1355 | EXPORT_COMPAT("arm,coresight-tmc"); |
Pratik Patel | 2291149 | 2012-06-25 21:38:02 -0700 | [diff] [blame] | 1356 | |
| 1357 | static struct platform_driver tmc_driver = { |
| 1358 | .probe = tmc_probe, |
| 1359 | .remove = __devexit_p(tmc_remove), |
| 1360 | .driver = { |
| 1361 | .name = "coresight-tmc", |
| 1362 | .owner = THIS_MODULE, |
| 1363 | .of_match_table = tmc_match, |
| 1364 | }, |
| 1365 | }; |
| 1366 | |
| 1367 | static int __init tmc_init(void) |
| 1368 | { |
| 1369 | return platform_driver_register(&tmc_driver); |
| 1370 | } |
| 1371 | module_init(tmc_init); |
| 1372 | |
| 1373 | static void __exit tmc_exit(void) |
| 1374 | { |
| 1375 | platform_driver_unregister(&tmc_driver); |
| 1376 | } |
| 1377 | module_exit(tmc_exit); |
| 1378 | |
| 1379 | MODULE_LICENSE("GPL v2"); |
| 1380 | MODULE_DESCRIPTION("CoreSight Trace Memory Controller driver"); |