Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -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> |
Pratik Patel | cf41862 | 2011-09-22 11:15:11 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/device.h> |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/io.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/fs.h> |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 22 | #include <linux/slab.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/smp.h> |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 25 | #include <linux/wakelock.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 26 | #include <linux/pm_qos.h> |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 27 | #include <linux/sysfs.h> |
| 28 | #include <linux/stat.h> |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 29 | #include <linux/mutex.h> |
Pratik Patel | f17b147 | 2012-05-25 22:23:52 -0700 | [diff] [blame] | 30 | #include <linux/clk.h> |
Pratik Patel | 5f6d1af | 2012-06-13 15:48:13 -0700 | [diff] [blame] | 31 | #include <linux/of_coresight.h> |
Pratik Patel | 1746b8f | 2012-06-02 21:11:41 -0700 | [diff] [blame] | 32 | #include <linux/coresight.h> |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 33 | #include <asm/sections.h> |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 34 | #include <mach/socinfo.h> |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 35 | |
Pratik Patel | 1746b8f | 2012-06-02 21:11:41 -0700 | [diff] [blame] | 36 | #include "coresight-priv.h" |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 37 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 38 | |
| 39 | #define etm_writel(drvdata, val, off) \ |
| 40 | __raw_writel((val), drvdata->base + off) |
| 41 | #define etm_readl(drvdata, off) \ |
| 42 | __raw_readl(drvdata->base + off) |
| 43 | |
| 44 | #define ETM_LOCK(drvdata) \ |
| 45 | do { \ |
| 46 | mb(); \ |
| 47 | etm_writel(drvdata, 0x0, CORESIGHT_LAR); \ |
| 48 | } while (0) |
| 49 | #define ETM_UNLOCK(drvdata) \ |
| 50 | do { \ |
| 51 | etm_writel(drvdata, CORESIGHT_UNLOCK, CORESIGHT_LAR); \ |
| 52 | mb(); \ |
| 53 | } while (0) |
| 54 | |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 55 | |
| 56 | /* |
| 57 | * Device registers: |
| 58 | * 0x000 - 0x2FC: Trace registers |
| 59 | * 0x300 - 0x314: Management registers |
| 60 | * 0x318 - 0xEFC: Trace registers |
| 61 | * |
| 62 | * Coresight registers |
| 63 | * 0xF00 - 0xF9C: Management registers |
| 64 | * 0xFA0 - 0xFA4: Management registers in PFTv1.0 |
| 65 | * Trace registers in PFTv1.1 |
| 66 | * 0xFA8 - 0xFFC: Management registers |
| 67 | */ |
| 68 | |
| 69 | /* Trace registers (0x000-0x2FC) */ |
| 70 | #define ETMCR (0x000) |
| 71 | #define ETMCCR (0x004) |
| 72 | #define ETMTRIGGER (0x008) |
| 73 | #define ETMSR (0x010) |
| 74 | #define ETMSCR (0x014) |
| 75 | #define ETMTSSCR (0x018) |
| 76 | #define ETMTEEVR (0x020) |
| 77 | #define ETMTECR1 (0x024) |
| 78 | #define ETMFFLR (0x02C) |
| 79 | #define ETMACVRn(n) (0x040 + (n * 4)) |
| 80 | #define ETMACTRn(n) (0x080 + (n * 4)) |
| 81 | #define ETMCNTRLDVRn(n) (0x140 + (n * 4)) |
| 82 | #define ETMCNTENRn(n) (0x150 + (n * 4)) |
| 83 | #define ETMCNTRLDEVRn(n) (0x160 + (n * 4)) |
| 84 | #define ETMCNTVRn(n) (0x170 + (n * 4)) |
| 85 | #define ETMSQ12EVR (0x180) |
| 86 | #define ETMSQ21EVR (0x184) |
| 87 | #define ETMSQ23EVR (0x188) |
Pratik Patel | d5bbc76 | 2012-01-29 14:13:21 -0800 | [diff] [blame] | 88 | #define ETMSQ31EVR (0x18C) |
| 89 | #define ETMSQ32EVR (0x190) |
| 90 | #define ETMSQ13EVR (0x194) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 91 | #define ETMSQR (0x19C) |
| 92 | #define ETMEXTOUTEVRn(n) (0x1A0 + (n * 4)) |
| 93 | #define ETMCIDCVRn(n) (0x1B0 + (n * 4)) |
| 94 | #define ETMCIDCMR (0x1BC) |
| 95 | #define ETMIMPSPEC0 (0x1C0) |
| 96 | #define ETMIMPSPEC1 (0x1C4) |
| 97 | #define ETMIMPSPEC2 (0x1C8) |
| 98 | #define ETMIMPSPEC3 (0x1CC) |
| 99 | #define ETMIMPSPEC4 (0x1D0) |
| 100 | #define ETMIMPSPEC5 (0x1D4) |
| 101 | #define ETMIMPSPEC6 (0x1D8) |
| 102 | #define ETMIMPSPEC7 (0x1DC) |
| 103 | #define ETMSYNCFR (0x1E0) |
| 104 | #define ETMIDR (0x1E4) |
| 105 | #define ETMCCER (0x1E8) |
| 106 | #define ETMEXTINSELR (0x1EC) |
| 107 | #define ETMTESSEICR (0x1F0) |
| 108 | #define ETMEIBCR (0x1F4) |
| 109 | #define ETMTSEVR (0x1F8) |
| 110 | #define ETMAUXCR (0x1FC) |
| 111 | #define ETMTRACEIDR (0x200) |
Pratik Patel | d5bbc76 | 2012-01-29 14:13:21 -0800 | [diff] [blame] | 112 | #define ETMVMIDCVR (0x240) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 113 | /* Management registers (0x300-0x314) */ |
| 114 | #define ETMOSLAR (0x300) |
| 115 | #define ETMOSLSR (0x304) |
| 116 | #define ETMOSSRR (0x308) |
| 117 | #define ETMPDCR (0x310) |
| 118 | #define ETMPDSR (0x314) |
| 119 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 120 | |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 121 | #define ETM_MAX_ADDR_CMP (16) |
| 122 | #define ETM_MAX_CNTR (4) |
| 123 | #define ETM_MAX_CTXID_CMP (3) |
| 124 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 125 | #define ETM_MODE_EXCLUDE BIT(0) |
| 126 | #define ETM_MODE_CYCACC BIT(1) |
| 127 | #define ETM_MODE_STALL BIT(2) |
| 128 | #define ETM_MODE_TIMESTAMP BIT(3) |
| 129 | #define ETM_MODE_CTXID BIT(4) |
| 130 | #define ETM_MODE_ALL (0x1F) |
| 131 | |
| 132 | #define ETM_EVENT_MASK (0x1FFFF) |
| 133 | #define ETM_SYNC_MASK (0xFFF) |
| 134 | #define ETM_ALL_MASK (0xFFFFFFFF) |
| 135 | |
| 136 | #define ETM_SEQ_STATE_MAX_VAL (0x2) |
| 137 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 138 | enum etm_addr_type { |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 139 | ETM_ADDR_TYPE_NONE, |
| 140 | ETM_ADDR_TYPE_SINGLE, |
| 141 | ETM_ADDR_TYPE_RANGE, |
| 142 | ETM_ADDR_TYPE_START, |
| 143 | ETM_ADDR_TYPE_STOP, |
| 144 | }; |
| 145 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 146 | |
Pratik Patel | 29cba15 | 2012-01-03 11:40:26 -0800 | [diff] [blame] | 147 | #ifdef CONFIG_MSM_QDSS_ETM_DEFAULT_ENABLE |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 148 | static int boot_enable = 1; |
Pratik Patel | 29cba15 | 2012-01-03 11:40:26 -0800 | [diff] [blame] | 149 | #else |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 150 | static int boot_enable; |
Pratik Patel | 29cba15 | 2012-01-03 11:40:26 -0800 | [diff] [blame] | 151 | #endif |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 152 | module_param_named( |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 153 | boot_enable, boot_enable, int, S_IRUGO |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 154 | ); |
| 155 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 156 | struct etm_drvdata { |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 157 | void __iomem *base; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 158 | struct device *dev; |
| 159 | struct coresight_device *csdev; |
| 160 | struct clk *clk; |
| 161 | struct mutex mutex; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 162 | struct wake_lock wake_lock; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 163 | struct pm_qos_request qos_req; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 164 | int cpu; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 165 | uint8_t arch; |
| 166 | uint8_t nr_addr_cmp; |
| 167 | uint8_t nr_cntr; |
| 168 | uint8_t nr_ext_inp; |
| 169 | uint8_t nr_ext_out; |
| 170 | uint8_t nr_ctxid_cmp; |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 171 | uint8_t reset; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 172 | uint32_t mode; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 173 | uint32_t ctrl; |
| 174 | uint32_t trigger_event; |
| 175 | uint32_t startstop_ctrl; |
| 176 | uint32_t enable_event; |
| 177 | uint32_t enable_ctrl1; |
| 178 | uint32_t fifofull_level; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 179 | uint8_t addr_idx; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 180 | uint32_t addr_val[ETM_MAX_ADDR_CMP]; |
| 181 | uint32_t addr_acctype[ETM_MAX_ADDR_CMP]; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 182 | uint32_t addr_type[ETM_MAX_ADDR_CMP]; |
| 183 | uint8_t cntr_idx; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 184 | uint32_t cntr_rld_val[ETM_MAX_CNTR]; |
| 185 | uint32_t cntr_event[ETM_MAX_CNTR]; |
| 186 | uint32_t cntr_rld_event[ETM_MAX_CNTR]; |
| 187 | uint32_t cntr_val[ETM_MAX_CNTR]; |
| 188 | uint32_t seq_12_event; |
| 189 | uint32_t seq_21_event; |
| 190 | uint32_t seq_23_event; |
| 191 | uint32_t seq_31_event; |
| 192 | uint32_t seq_32_event; |
| 193 | uint32_t seq_13_event; |
| 194 | uint32_t seq_curr_state; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 195 | uint8_t ctxid_idx; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 196 | uint32_t ctxid_val[ETM_MAX_CTXID_CMP]; |
| 197 | uint32_t ctxid_mask; |
| 198 | uint32_t sync_freq; |
| 199 | uint32_t timestamp_event; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 200 | }; |
| 201 | |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 202 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 203 | /* ETM clock is derived from the processor clock and gets enabled on a |
| 204 | * logical OR of below items on Krait (pass2 onwards): |
| 205 | * 1.CPMR[ETMCLKEN] is 1 |
| 206 | * 2.ETMCR[PD] is 0 |
| 207 | * 3.ETMPDCR[PU] is 1 |
| 208 | * 4.Reset is asserted (core or debug) |
| 209 | * 5.APB memory mapped requests (eg. EDAP access) |
| 210 | * |
| 211 | * 1., 2. and 3. above are permanent enables whereas 4. and 5. are temporary |
| 212 | * enables |
| 213 | * |
| 214 | * We rely on 5. to be able to access ETMCR and then use 2. above for ETM |
| 215 | * clock vote in the driver and the save-restore code uses 1. above |
| 216 | * for its vote |
| 217 | */ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 218 | static void etm_set_pwrdwn(struct etm_drvdata *drvdata) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 219 | { |
| 220 | uint32_t etmcr; |
| 221 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 222 | etmcr = etm_readl(drvdata, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 223 | etmcr |= BIT(0); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 224 | etm_writel(drvdata, etmcr, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 227 | static void etm_clr_pwrdwn(struct etm_drvdata *drvdata) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 228 | { |
| 229 | uint32_t etmcr; |
| 230 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 231 | etmcr = etm_readl(drvdata, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 232 | etmcr &= ~BIT(0); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 233 | etm_writel(drvdata, etmcr, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 236 | static void etm_set_prog(struct etm_drvdata *drvdata) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 237 | { |
| 238 | uint32_t etmcr; |
| 239 | int count; |
| 240 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 241 | etmcr = etm_readl(drvdata, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 242 | etmcr |= BIT(10); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 243 | etm_writel(drvdata, etmcr, ETMCR); |
| 244 | for (count = TIMEOUT_US; BVAL(etm_readl(drvdata, ETMSR), 1) != 1 |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 245 | && count > 0; count--) |
| 246 | udelay(1); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 247 | WARN(count == 0, "timeout while setting prog bit, ETMSR: %#x\n", |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 248 | etm_readl(drvdata, ETMSR)); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 251 | static void etm_clr_prog(struct etm_drvdata *drvdata) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 252 | { |
| 253 | uint32_t etmcr; |
| 254 | int count; |
| 255 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 256 | etmcr = etm_readl(drvdata, ETMCR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 257 | etmcr &= ~BIT(10); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 258 | etm_writel(drvdata, etmcr, ETMCR); |
| 259 | for (count = TIMEOUT_US; BVAL(etm_readl(drvdata, ETMSR), 1) != 0 |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 260 | && count > 0; count--) |
| 261 | udelay(1); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 262 | WARN(count == 0, "timeout while clearing prog bit, ETMSR: %#x\n", |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 263 | etm_readl(drvdata, ETMSR)); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 266 | static void __etm_enable(struct etm_drvdata *drvdata) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 267 | { |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 268 | int i; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 269 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 270 | ETM_UNLOCK(drvdata); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 271 | /* Vote for ETM power/clock enable */ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 272 | etm_clr_pwrdwn(drvdata); |
| 273 | etm_set_prog(drvdata); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 274 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 275 | etm_writel(drvdata, drvdata->ctrl | BIT(10), ETMCR); |
| 276 | etm_writel(drvdata, drvdata->trigger_event, ETMTRIGGER); |
| 277 | etm_writel(drvdata, drvdata->startstop_ctrl, ETMTSSCR); |
| 278 | etm_writel(drvdata, drvdata->enable_event, ETMTEEVR); |
| 279 | etm_writel(drvdata, drvdata->enable_ctrl1, ETMTECR1); |
| 280 | etm_writel(drvdata, drvdata->fifofull_level, ETMFFLR); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 281 | for (i = 0; i < drvdata->nr_addr_cmp; i++) { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 282 | etm_writel(drvdata, drvdata->addr_val[i], ETMACVRn(i)); |
| 283 | etm_writel(drvdata, drvdata->addr_acctype[i], ETMACTRn(i)); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 284 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 285 | for (i = 0; i < drvdata->nr_cntr; i++) { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 286 | etm_writel(drvdata, drvdata->cntr_rld_val[i], ETMCNTRLDVRn(i)); |
| 287 | etm_writel(drvdata, drvdata->cntr_event[i], ETMCNTENRn(i)); |
| 288 | etm_writel(drvdata, drvdata->cntr_rld_event[i], |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 289 | ETMCNTRLDEVRn(i)); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 290 | etm_writel(drvdata, drvdata->cntr_val[i], ETMCNTVRn(i)); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 291 | } |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 292 | etm_writel(drvdata, drvdata->seq_12_event, ETMSQ12EVR); |
| 293 | etm_writel(drvdata, drvdata->seq_21_event, ETMSQ21EVR); |
| 294 | etm_writel(drvdata, drvdata->seq_23_event, ETMSQ23EVR); |
| 295 | etm_writel(drvdata, drvdata->seq_31_event, ETMSQ31EVR); |
| 296 | etm_writel(drvdata, drvdata->seq_32_event, ETMSQ32EVR); |
| 297 | etm_writel(drvdata, drvdata->seq_13_event, ETMSQ13EVR); |
| 298 | etm_writel(drvdata, drvdata->seq_curr_state, ETMSQR); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 299 | for (i = 0; i < drvdata->nr_ext_out; i++) |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 300 | etm_writel(drvdata, 0x0000406F, ETMEXTOUTEVRn(i)); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 301 | for (i = 0; i < drvdata->nr_ctxid_cmp; i++) |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 302 | etm_writel(drvdata, drvdata->ctxid_val[i], ETMCIDCVRn(i)); |
| 303 | etm_writel(drvdata, drvdata->ctxid_mask, ETMCIDCMR); |
| 304 | etm_writel(drvdata, drvdata->sync_freq, ETMSYNCFR); |
| 305 | etm_writel(drvdata, 0x00000000, ETMEXTINSELR); |
| 306 | etm_writel(drvdata, drvdata->timestamp_event, ETMTSEVR); |
| 307 | etm_writel(drvdata, 0x00000000, ETMAUXCR); |
| 308 | etm_writel(drvdata, drvdata->cpu + 1, ETMTRACEIDR); |
| 309 | etm_writel(drvdata, 0x00000000, ETMVMIDCVR); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 310 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 311 | etm_clr_prog(drvdata); |
| 312 | ETM_LOCK(drvdata); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 315 | static int etm_enable(struct coresight_device *csdev) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 316 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 317 | struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
| 318 | int ret; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 319 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 320 | wake_lock(&drvdata->wake_lock); |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 321 | /* 1. causes all online cpus to come out of idle PC |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 322 | * 2. prevents idle PC until save restore flag is enabled atomically |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 323 | * |
| 324 | * we rely on the user to prevent hotplug on/off racing with this |
| 325 | * operation and to ensure cores where trace is expected to be turned |
| 326 | * on are already hotplugged on |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 327 | */ |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 328 | pm_qos_update_request(&drvdata->qos_req, 0); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 329 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 330 | ret = clk_prepare_enable(drvdata->clk); |
Pratik Patel | f17b147 | 2012-05-25 22:23:52 -0700 | [diff] [blame] | 331 | if (ret) |
| 332 | goto err_clk; |
| 333 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 334 | mutex_lock(&drvdata->mutex); |
| 335 | __etm_enable(drvdata); |
| 336 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 337 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 338 | pm_qos_update_request(&drvdata->qos_req, PM_QOS_DEFAULT_VALUE); |
| 339 | wake_unlock(&drvdata->wake_lock); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 340 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 341 | dev_info(drvdata->dev, "ETM tracing enabled\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 342 | return 0; |
Pratik Patel | f17b147 | 2012-05-25 22:23:52 -0700 | [diff] [blame] | 343 | err_clk: |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 344 | pm_qos_update_request(&drvdata->qos_req, PM_QOS_DEFAULT_VALUE); |
| 345 | wake_unlock(&drvdata->wake_lock); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 346 | return ret; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 349 | static void __etm_disable(struct etm_drvdata *drvdata) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 350 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 351 | ETM_UNLOCK(drvdata); |
| 352 | etm_set_prog(drvdata); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 353 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 354 | /* program trace enable to low by using always false event */ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 355 | etm_writel(drvdata, 0x6F | BIT(14), ETMTEEVR); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 356 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 357 | /* Vote for ETM power/clock disable */ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 358 | etm_set_pwrdwn(drvdata); |
| 359 | ETM_LOCK(drvdata); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 362 | static void etm_disable(struct coresight_device *csdev) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 363 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 364 | struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 365 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 366 | wake_lock(&drvdata->wake_lock); |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 367 | /* 1. causes all online cpus to come out of idle PC |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 368 | * 2. prevents idle PC until save restore flag is disabled atomically |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 369 | * |
| 370 | * we rely on the user to prevent hotplug on/off racing with this |
| 371 | * operation and to ensure cores where trace is expected to be turned |
| 372 | * off are already hotplugged on |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 373 | */ |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 374 | pm_qos_update_request(&drvdata->qos_req, 0); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 375 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 376 | mutex_lock(&drvdata->mutex); |
| 377 | __etm_disable(drvdata); |
| 378 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 379 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 380 | clk_disable_unprepare(drvdata->clk); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 381 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 382 | pm_qos_update_request(&drvdata->qos_req, PM_QOS_DEFAULT_VALUE); |
| 383 | wake_unlock(&drvdata->wake_lock); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 384 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 385 | dev_info(drvdata->dev, "ETM tracing disabled\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 388 | static const struct coresight_ops_source etm_source_ops = { |
| 389 | .enable = etm_enable, |
| 390 | .disable = etm_disable, |
| 391 | }; |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 392 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 393 | static const struct coresight_ops etm_cs_ops = { |
| 394 | .source_ops = &etm_source_ops, |
| 395 | }; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 396 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 397 | static ssize_t etm_show_nr_addr_cmp(struct device *dev, |
| 398 | struct device_attribute *attr, char *buf) |
| 399 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 400 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 401 | unsigned long val = drvdata->nr_addr_cmp; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 402 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 403 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 404 | } |
| 405 | static DEVICE_ATTR(nr_addr_cmp, S_IRUGO, etm_show_nr_addr_cmp, NULL); |
| 406 | |
| 407 | static ssize_t etm_show_nr_cntr(struct device *dev, |
| 408 | struct device_attribute *attr, char *buf) |
| 409 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 410 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 411 | unsigned long val = drvdata->nr_cntr; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 412 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 413 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 414 | } |
| 415 | static DEVICE_ATTR(nr_cntr, S_IRUGO, etm_show_nr_cntr, NULL); |
| 416 | |
| 417 | static ssize_t etm_show_nr_ctxid_cmp(struct device *dev, |
| 418 | struct device_attribute *attr, char *buf) |
| 419 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 420 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 421 | unsigned long val = drvdata->nr_ctxid_cmp; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 422 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 423 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 424 | } |
| 425 | static DEVICE_ATTR(nr_ctxid_cmp, S_IRUGO, etm_show_nr_ctxid_cmp, NULL); |
| 426 | |
| 427 | static ssize_t etm_show_reset(struct device *dev, struct device_attribute *attr, |
| 428 | char *buf) |
| 429 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 430 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 431 | unsigned long val = drvdata->reset; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 432 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 433 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 434 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 435 | |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 436 | /* Reset to trace everything i.e. exclude nothing. */ |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 437 | static ssize_t etm_store_reset(struct device *dev, |
| 438 | struct device_attribute *attr, const char *buf, |
| 439 | size_t size) |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 440 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 441 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 442 | int i; |
| 443 | unsigned long val; |
| 444 | |
| 445 | if (sscanf(buf, "%lx", &val) != 1) |
| 446 | return -EINVAL; |
| 447 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 448 | mutex_lock(&drvdata->mutex); |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 449 | if (val) { |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 450 | drvdata->mode = ETM_MODE_EXCLUDE; |
| 451 | drvdata->ctrl = 0x0; |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 452 | if (cpu_is_krait_v1()) { |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 453 | drvdata->mode |= ETM_MODE_CYCACC; |
| 454 | drvdata->ctrl |= BIT(12); |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 455 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 456 | drvdata->trigger_event = 0x406F; |
| 457 | drvdata->startstop_ctrl = 0x0; |
| 458 | drvdata->enable_event = 0x6F; |
| 459 | drvdata->enable_ctrl1 = 0x1000000; |
| 460 | drvdata->fifofull_level = 0x28; |
| 461 | drvdata->addr_idx = 0x0; |
| 462 | for (i = 0; i < drvdata->nr_addr_cmp; i++) { |
| 463 | drvdata->addr_val[i] = 0x0; |
| 464 | drvdata->addr_acctype[i] = 0x0; |
| 465 | drvdata->addr_type[i] = ETM_ADDR_TYPE_NONE; |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 466 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 467 | drvdata->cntr_idx = 0x0; |
| 468 | for (i = 0; i < drvdata->nr_cntr; i++) { |
| 469 | drvdata->cntr_rld_val[i] = 0x0; |
| 470 | drvdata->cntr_event[i] = 0x406F; |
| 471 | drvdata->cntr_rld_event[i] = 0x406F; |
| 472 | drvdata->cntr_val[i] = 0x0; |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 473 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 474 | drvdata->seq_12_event = 0x406F; |
| 475 | drvdata->seq_21_event = 0x406F; |
| 476 | drvdata->seq_23_event = 0x406F; |
| 477 | drvdata->seq_31_event = 0x406F; |
| 478 | drvdata->seq_32_event = 0x406F; |
| 479 | drvdata->seq_13_event = 0x406F; |
| 480 | drvdata->seq_curr_state = 0x0; |
| 481 | drvdata->ctxid_idx = 0x0; |
| 482 | for (i = 0; i < drvdata->nr_ctxid_cmp; i++) |
| 483 | drvdata->ctxid_val[i] = 0x0; |
| 484 | drvdata->ctxid_mask = 0x0; |
Pratik Patel | 77b9063 | 2012-07-17 17:54:51 -0700 | [diff] [blame^] | 485 | /* Bits[7:0] of ETMSYNCFR are reserved on Krait pass3 onwards */ |
| 486 | if (cpu_is_krait() && !cpu_is_krait_v1() && !cpu_is_krait_v2()) |
| 487 | drvdata->sync_freq = 0x100; |
| 488 | else |
| 489 | drvdata->sync_freq = 0x80; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 490 | drvdata->timestamp_event = 0x406F; |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 491 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 492 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 493 | return size; |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 494 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 495 | static DEVICE_ATTR(reset, S_IRUGO | S_IWUSR, etm_show_reset, etm_store_reset); |
Pratik Patel | d30deda | 2012-02-01 14:40:55 -0800 | [diff] [blame] | 496 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 497 | static ssize_t etm_show_mode(struct device *dev, struct device_attribute *attr, |
| 498 | char *buf) |
| 499 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 500 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 501 | unsigned long val = drvdata->mode; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 502 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 503 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 504 | } |
| 505 | |
| 506 | static ssize_t etm_store_mode(struct device *dev, struct device_attribute *attr, |
| 507 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 508 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 509 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 510 | unsigned long val; |
| 511 | |
| 512 | if (sscanf(buf, "%lx", &val) != 1) |
| 513 | return -EINVAL; |
| 514 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 515 | mutex_lock(&drvdata->mutex); |
| 516 | drvdata->mode = val & ETM_MODE_ALL; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 517 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 518 | if (drvdata->mode & ETM_MODE_EXCLUDE) |
| 519 | drvdata->enable_ctrl1 |= BIT(24); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 520 | else |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 521 | drvdata->enable_ctrl1 &= ~BIT(24); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 522 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 523 | if (drvdata->mode & ETM_MODE_CYCACC) |
| 524 | drvdata->ctrl |= BIT(12); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 525 | else |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 526 | drvdata->ctrl &= ~BIT(12); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 527 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 528 | if (drvdata->mode & ETM_MODE_STALL) |
| 529 | drvdata->ctrl |= BIT(7); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 530 | else |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 531 | drvdata->ctrl &= ~BIT(7); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 532 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 533 | if (drvdata->mode & ETM_MODE_TIMESTAMP) |
| 534 | drvdata->ctrl |= BIT(28); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 535 | else |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 536 | drvdata->ctrl &= ~BIT(28); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 537 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 538 | if (drvdata->mode & ETM_MODE_CTXID) |
| 539 | drvdata->ctrl |= (BIT(14) | BIT(15)); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 540 | else |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 541 | drvdata->ctrl &= ~(BIT(14) | BIT(15)); |
| 542 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 543 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 544 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 545 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 546 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, etm_show_mode, etm_store_mode); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 547 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 548 | static ssize_t etm_show_trigger_event(struct device *dev, |
| 549 | struct device_attribute *attr, char *buf) |
| 550 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 551 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 552 | unsigned long val = drvdata->trigger_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 553 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 554 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 555 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 556 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 557 | static ssize_t etm_store_trigger_event(struct device *dev, |
| 558 | struct device_attribute *attr, |
| 559 | const char *buf, size_t size) |
| 560 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 561 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 562 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 563 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 564 | if (sscanf(buf, "%lx", &val) != 1) |
| 565 | return -EINVAL; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 566 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 567 | drvdata->trigger_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 568 | return size; |
| 569 | } |
| 570 | static DEVICE_ATTR(trigger_event, S_IRUGO | S_IWUSR, etm_show_trigger_event, |
| 571 | etm_store_trigger_event); |
| 572 | |
| 573 | static ssize_t etm_show_enable_event(struct device *dev, |
| 574 | struct device_attribute *attr, char *buf) |
| 575 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 576 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 577 | unsigned long val = drvdata->enable_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 578 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 579 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 580 | } |
| 581 | |
| 582 | static ssize_t etm_store_enable_event(struct device *dev, |
| 583 | struct device_attribute *attr, |
| 584 | const char *buf, size_t size) |
| 585 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 586 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 587 | unsigned long val; |
| 588 | |
| 589 | if (sscanf(buf, "%lx", &val) != 1) |
| 590 | return -EINVAL; |
| 591 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 592 | drvdata->enable_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 593 | return size; |
| 594 | } |
| 595 | static DEVICE_ATTR(enable_event, S_IRUGO | S_IWUSR, etm_show_enable_event, |
| 596 | etm_store_enable_event); |
| 597 | |
| 598 | static ssize_t etm_show_fifofull_level(struct device *dev, |
| 599 | struct device_attribute *attr, char *buf) |
| 600 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 601 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 602 | unsigned long val = drvdata->fifofull_level; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 603 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 604 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 605 | } |
| 606 | |
| 607 | static ssize_t etm_store_fifofull_level(struct device *dev, |
| 608 | struct device_attribute *attr, |
| 609 | const char *buf, size_t size) |
| 610 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 611 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 612 | unsigned long val; |
| 613 | |
| 614 | if (sscanf(buf, "%lx", &val) != 1) |
| 615 | return -EINVAL; |
| 616 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 617 | drvdata->fifofull_level = val; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 618 | return size; |
| 619 | } |
| 620 | static DEVICE_ATTR(fifofull_level, S_IRUGO | S_IWUSR, etm_show_fifofull_level, |
| 621 | etm_store_fifofull_level); |
| 622 | |
| 623 | static ssize_t etm_show_addr_idx(struct device *dev, |
| 624 | struct device_attribute *attr, char *buf) |
| 625 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 626 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 627 | unsigned long val = drvdata->addr_idx; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 628 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 629 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 630 | } |
| 631 | |
| 632 | static ssize_t etm_store_addr_idx(struct device *dev, |
| 633 | struct device_attribute *attr, |
| 634 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 635 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 636 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 637 | unsigned long val; |
| 638 | |
| 639 | if (sscanf(buf, "%lx", &val) != 1) |
| 640 | return -EINVAL; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 641 | if (val >= drvdata->nr_addr_cmp) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 642 | return -EINVAL; |
| 643 | |
| 644 | /* Use mutex to ensure index doesn't change while it gets dereferenced |
| 645 | * multiple times within a mutex block elsewhere. |
| 646 | */ |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 647 | mutex_lock(&drvdata->mutex); |
| 648 | drvdata->addr_idx = val; |
| 649 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 650 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 651 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 652 | static DEVICE_ATTR(addr_idx, S_IRUGO | S_IWUSR, etm_show_addr_idx, |
| 653 | etm_store_addr_idx); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 654 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 655 | static ssize_t etm_show_addr_single(struct device *dev, |
| 656 | struct device_attribute *attr, char *buf) |
| 657 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 658 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 659 | unsigned long val; |
| 660 | uint8_t idx; |
| 661 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 662 | mutex_lock(&drvdata->mutex); |
| 663 | idx = drvdata->addr_idx; |
| 664 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 665 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_SINGLE)) { |
| 666 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 667 | return -EPERM; |
| 668 | } |
| 669 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 670 | val = drvdata->addr_val[idx]; |
| 671 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 672 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 673 | } |
| 674 | |
| 675 | static ssize_t etm_store_addr_single(struct device *dev, |
| 676 | struct device_attribute *attr, |
| 677 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 678 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 679 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 680 | unsigned long val; |
| 681 | uint8_t idx; |
| 682 | |
| 683 | if (sscanf(buf, "%lx", &val) != 1) |
| 684 | return -EINVAL; |
| 685 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 686 | mutex_lock(&drvdata->mutex); |
| 687 | idx = drvdata->addr_idx; |
| 688 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 689 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_SINGLE)) { |
| 690 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 691 | return -EPERM; |
| 692 | } |
| 693 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 694 | drvdata->addr_val[idx] = val; |
| 695 | drvdata->addr_type[idx] = ETM_ADDR_TYPE_SINGLE; |
| 696 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 697 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 698 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 699 | static DEVICE_ATTR(addr_single, S_IRUGO | S_IWUSR, etm_show_addr_single, |
| 700 | etm_store_addr_single); |
| 701 | |
| 702 | static ssize_t etm_show_addr_range(struct device *dev, |
| 703 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 704 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 705 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 706 | unsigned long val1, val2; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 707 | uint8_t idx; |
| 708 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 709 | mutex_lock(&drvdata->mutex); |
| 710 | idx = drvdata->addr_idx; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 711 | if (idx % 2 != 0) { |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 712 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 713 | return -EPERM; |
| 714 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 715 | if (!((drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE && |
| 716 | drvdata->addr_type[idx + 1] == ETM_ADDR_TYPE_NONE) || |
| 717 | (drvdata->addr_type[idx] == ETM_ADDR_TYPE_RANGE && |
| 718 | drvdata->addr_type[idx + 1] == ETM_ADDR_TYPE_RANGE))) { |
| 719 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 720 | return -EPERM; |
| 721 | } |
| 722 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 723 | val1 = drvdata->addr_val[idx]; |
| 724 | val2 = drvdata->addr_val[idx + 1]; |
| 725 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 726 | return scnprintf(buf, PAGE_SIZE, "%#lx %#lx\n", val1, val2); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 727 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 728 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 729 | static ssize_t etm_store_addr_range(struct device *dev, |
| 730 | struct device_attribute *attr, |
| 731 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 732 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 733 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 734 | unsigned long val1, val2; |
| 735 | uint8_t idx; |
| 736 | |
| 737 | if (sscanf(buf, "%lx %lx", &val1, &val2) != 2) |
| 738 | return -EINVAL; |
| 739 | /* lower address comparator cannot have a higher address value */ |
| 740 | if (val1 > val2) |
| 741 | return -EINVAL; |
| 742 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 743 | mutex_lock(&drvdata->mutex); |
| 744 | idx = drvdata->addr_idx; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 745 | if (idx % 2 != 0) { |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 746 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 747 | return -EPERM; |
| 748 | } |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 749 | if (!((drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE && |
| 750 | drvdata->addr_type[idx + 1] == ETM_ADDR_TYPE_NONE) || |
| 751 | (drvdata->addr_type[idx] == ETM_ADDR_TYPE_RANGE && |
| 752 | drvdata->addr_type[idx + 1] == ETM_ADDR_TYPE_RANGE))) { |
| 753 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 754 | return -EPERM; |
| 755 | } |
| 756 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 757 | drvdata->addr_val[idx] = val1; |
| 758 | drvdata->addr_type[idx] = ETM_ADDR_TYPE_RANGE; |
| 759 | drvdata->addr_val[idx + 1] = val2; |
| 760 | drvdata->addr_type[idx + 1] = ETM_ADDR_TYPE_RANGE; |
| 761 | drvdata->enable_ctrl1 |= (1 << (idx/2)); |
| 762 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 763 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 764 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 765 | static DEVICE_ATTR(addr_range, S_IRUGO | S_IWUSR, etm_show_addr_range, |
| 766 | etm_store_addr_range); |
| 767 | |
| 768 | static ssize_t etm_show_addr_start(struct device *dev, |
| 769 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 770 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 771 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 772 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 773 | uint8_t idx; |
| 774 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 775 | mutex_lock(&drvdata->mutex); |
| 776 | idx = drvdata->addr_idx; |
| 777 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 778 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_START)) { |
| 779 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 780 | return -EPERM; |
| 781 | } |
| 782 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 783 | val = drvdata->addr_val[idx]; |
| 784 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 785 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 786 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 787 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 788 | static ssize_t etm_store_addr_start(struct device *dev, |
| 789 | struct device_attribute *attr, |
| 790 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 791 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 792 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 793 | unsigned long val; |
| 794 | uint8_t idx; |
| 795 | |
| 796 | if (sscanf(buf, "%lx", &val) != 1) |
| 797 | return -EINVAL; |
| 798 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 799 | mutex_lock(&drvdata->mutex); |
| 800 | idx = drvdata->addr_idx; |
| 801 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 802 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_START)) { |
| 803 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 804 | return -EPERM; |
| 805 | } |
| 806 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 807 | drvdata->addr_val[idx] = val; |
| 808 | drvdata->addr_type[idx] = ETM_ADDR_TYPE_START; |
| 809 | drvdata->startstop_ctrl |= (1 << idx); |
| 810 | drvdata->enable_ctrl1 |= BIT(25); |
| 811 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 812 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 813 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 814 | static DEVICE_ATTR(addr_start, S_IRUGO | S_IWUSR, etm_show_addr_start, |
| 815 | etm_store_addr_start); |
| 816 | |
| 817 | static ssize_t etm_show_addr_stop(struct device *dev, |
| 818 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 819 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 820 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 821 | unsigned long val; |
| 822 | uint8_t idx; |
| 823 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 824 | mutex_lock(&drvdata->mutex); |
| 825 | idx = drvdata->addr_idx; |
| 826 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 827 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_STOP)) { |
| 828 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 829 | return -EPERM; |
| 830 | } |
| 831 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 832 | val = drvdata->addr_val[idx]; |
| 833 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 834 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 835 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 836 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 837 | static ssize_t etm_store_addr_stop(struct device *dev, |
| 838 | struct device_attribute *attr, |
| 839 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 840 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 841 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 842 | unsigned long val; |
| 843 | uint8_t idx; |
| 844 | |
| 845 | if (sscanf(buf, "%lx", &val) != 1) |
| 846 | return -EINVAL; |
| 847 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 848 | mutex_lock(&drvdata->mutex); |
| 849 | idx = drvdata->addr_idx; |
| 850 | if (!(drvdata->addr_type[idx] == ETM_ADDR_TYPE_NONE || |
| 851 | drvdata->addr_type[idx] == ETM_ADDR_TYPE_STOP)) { |
| 852 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 853 | return -EPERM; |
| 854 | } |
| 855 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 856 | drvdata->addr_val[idx] = val; |
| 857 | drvdata->addr_type[idx] = ETM_ADDR_TYPE_STOP; |
| 858 | drvdata->startstop_ctrl |= (1 << (idx + 16)); |
| 859 | drvdata->enable_ctrl1 |= BIT(25); |
| 860 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 861 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 862 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 863 | static DEVICE_ATTR(addr_stop, S_IRUGO | S_IWUSR, etm_show_addr_stop, |
| 864 | etm_store_addr_stop); |
| 865 | |
| 866 | static ssize_t etm_show_addr_acctype(struct device *dev, |
| 867 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 868 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 869 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 870 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 871 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 872 | mutex_lock(&drvdata->mutex); |
| 873 | val = drvdata->addr_acctype[drvdata->addr_idx]; |
| 874 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 875 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 876 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 877 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 878 | static ssize_t etm_store_addr_acctype(struct device *dev, |
| 879 | struct device_attribute *attr, |
| 880 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 881 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 882 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 883 | unsigned long val; |
| 884 | |
| 885 | if (sscanf(buf, "%lx", &val) != 1) |
| 886 | return -EINVAL; |
| 887 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 888 | mutex_lock(&drvdata->mutex); |
| 889 | drvdata->addr_acctype[drvdata->addr_idx] = val; |
| 890 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 891 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 892 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 893 | static DEVICE_ATTR(addr_acctype, S_IRUGO | S_IWUSR, etm_show_addr_acctype, |
| 894 | etm_store_addr_acctype); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 895 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 896 | static ssize_t etm_show_cntr_idx(struct device *dev, |
| 897 | struct device_attribute *attr, char *buf) |
| 898 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 899 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 900 | unsigned long val = drvdata->addr_idx; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 901 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 902 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 903 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 904 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 905 | static ssize_t etm_store_cntr_idx(struct device *dev, |
| 906 | struct device_attribute *attr, |
| 907 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 908 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 909 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 910 | unsigned long val; |
| 911 | |
| 912 | if (sscanf(buf, "%lx", &val) != 1) |
| 913 | return -EINVAL; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 914 | if (val >= drvdata->nr_cntr) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 915 | return -EINVAL; |
| 916 | |
| 917 | /* Use mutex to ensure index doesn't change while it gets dereferenced |
| 918 | * multiple times within a mutex block elsewhere. |
| 919 | */ |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 920 | mutex_lock(&drvdata->mutex); |
| 921 | drvdata->cntr_idx = val; |
| 922 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 923 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 924 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 925 | static DEVICE_ATTR(cntr_idx, S_IRUGO | S_IWUSR, etm_show_cntr_idx, |
| 926 | etm_store_cntr_idx); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 927 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 928 | static ssize_t etm_show_cntr_rld_val(struct device *dev, |
| 929 | struct device_attribute *attr, char *buf) |
| 930 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 931 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 932 | unsigned long val; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 933 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 934 | mutex_lock(&drvdata->mutex); |
| 935 | val = drvdata->cntr_rld_val[drvdata->cntr_idx]; |
| 936 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 937 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 938 | } |
| 939 | |
| 940 | static ssize_t etm_store_cntr_rld_val(struct device *dev, |
| 941 | struct device_attribute *attr, |
| 942 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 943 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 944 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 945 | unsigned long val; |
| 946 | |
| 947 | if (sscanf(buf, "%lx", &val) != 1) |
| 948 | return -EINVAL; |
| 949 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 950 | mutex_lock(&drvdata->mutex); |
| 951 | drvdata->cntr_rld_val[drvdata->cntr_idx] = val; |
| 952 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 953 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 954 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 955 | static DEVICE_ATTR(cntr_rld_val, S_IRUGO | S_IWUSR, etm_show_cntr_rld_val, |
| 956 | etm_store_cntr_rld_val); |
| 957 | |
| 958 | static ssize_t etm_show_cntr_event(struct device *dev, |
| 959 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 960 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 961 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 962 | unsigned long val; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 963 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 964 | mutex_lock(&drvdata->mutex); |
| 965 | val = drvdata->cntr_event[drvdata->cntr_idx]; |
| 966 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 967 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 968 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 969 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 970 | static ssize_t etm_store_cntr_event(struct device *dev, |
| 971 | struct device_attribute *attr, |
| 972 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 973 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 974 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 975 | unsigned long val; |
| 976 | |
| 977 | if (sscanf(buf, "%lx", &val) != 1) |
| 978 | return -EINVAL; |
| 979 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 980 | mutex_lock(&drvdata->mutex); |
| 981 | drvdata->cntr_event[drvdata->cntr_idx] = val & ETM_EVENT_MASK; |
| 982 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 983 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 984 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 985 | static DEVICE_ATTR(cntr_event, S_IRUGO | S_IWUSR, etm_show_cntr_event, |
| 986 | etm_store_cntr_event); |
| 987 | |
| 988 | static ssize_t etm_show_cntr_rld_event(struct device *dev, |
| 989 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 990 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 991 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 992 | unsigned long val; |
| 993 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 994 | mutex_lock(&drvdata->mutex); |
| 995 | val = drvdata->cntr_rld_event[drvdata->cntr_idx]; |
| 996 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 997 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 998 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 999 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1000 | static ssize_t etm_store_cntr_rld_event(struct device *dev, |
| 1001 | struct device_attribute *attr, |
| 1002 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1003 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1004 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1005 | unsigned long val; |
| 1006 | |
| 1007 | if (sscanf(buf, "%lx", &val) != 1) |
| 1008 | return -EINVAL; |
| 1009 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1010 | mutex_lock(&drvdata->mutex); |
| 1011 | drvdata->cntr_rld_event[drvdata->cntr_idx] = val & ETM_EVENT_MASK; |
| 1012 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1013 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1014 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1015 | static DEVICE_ATTR(cntr_rld_event, S_IRUGO | S_IWUSR, etm_show_cntr_rld_event, |
| 1016 | etm_store_cntr_rld_event); |
| 1017 | |
| 1018 | static ssize_t etm_show_cntr_val(struct device *dev, |
| 1019 | struct device_attribute *attr, char *buf) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1020 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1021 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1022 | unsigned long val; |
| 1023 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1024 | mutex_lock(&drvdata->mutex); |
| 1025 | val = drvdata->cntr_val[drvdata->cntr_idx]; |
| 1026 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1027 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1028 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1029 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1030 | static ssize_t etm_store_cntr_val(struct device *dev, |
| 1031 | struct device_attribute *attr, |
| 1032 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1033 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1034 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1035 | unsigned long val; |
| 1036 | |
| 1037 | if (sscanf(buf, "%lx", &val) != 1) |
| 1038 | return -EINVAL; |
| 1039 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1040 | mutex_lock(&drvdata->mutex); |
| 1041 | drvdata->cntr_val[drvdata->cntr_idx] = val; |
| 1042 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1043 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1044 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1045 | static DEVICE_ATTR(cntr_val, S_IRUGO | S_IWUSR, etm_show_cntr_val, |
| 1046 | etm_store_cntr_val); |
| 1047 | |
| 1048 | static ssize_t etm_show_seq_12_event(struct device *dev, |
| 1049 | struct device_attribute *attr, char *buf) |
| 1050 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1051 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1052 | unsigned long val = drvdata->seq_12_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1053 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1054 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1055 | } |
| 1056 | |
| 1057 | static ssize_t etm_store_seq_12_event(struct device *dev, |
| 1058 | struct device_attribute *attr, |
| 1059 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1060 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1061 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1062 | unsigned long val; |
| 1063 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1064 | if (sscanf(buf, "%lx", &val) != 1) |
| 1065 | return -EINVAL; |
| 1066 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1067 | drvdata->seq_12_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1068 | return size; |
| 1069 | } |
| 1070 | static DEVICE_ATTR(seq_12_event, S_IRUGO | S_IWUSR, etm_show_seq_12_event, |
| 1071 | etm_store_seq_12_event); |
| 1072 | |
| 1073 | static ssize_t etm_show_seq_21_event(struct device *dev, |
| 1074 | struct device_attribute *attr, char *buf) |
| 1075 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1076 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1077 | unsigned long val = drvdata->seq_21_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1078 | |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1079 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1080 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1081 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1082 | static ssize_t etm_store_seq_21_event(struct device *dev, |
| 1083 | struct device_attribute *attr, |
| 1084 | const char *buf, size_t size) |
| 1085 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1086 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1087 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1088 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1089 | if (sscanf(buf, "%lx", &val) != 1) |
| 1090 | return -EINVAL; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1091 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1092 | drvdata->seq_21_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1093 | return size; |
| 1094 | } |
| 1095 | static DEVICE_ATTR(seq_21_event, S_IRUGO | S_IWUSR, etm_show_seq_21_event, |
| 1096 | etm_store_seq_21_event); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1097 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1098 | static ssize_t etm_show_seq_23_event(struct device *dev, |
| 1099 | struct device_attribute *attr, char *buf) |
| 1100 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1101 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1102 | unsigned long val = drvdata->seq_23_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1103 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1104 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1105 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1106 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1107 | static ssize_t etm_store_seq_23_event(struct device *dev, |
| 1108 | struct device_attribute *attr, |
| 1109 | const char *buf, size_t size) |
| 1110 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1111 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1112 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1113 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1114 | if (sscanf(buf, "%lx", &val) != 1) |
| 1115 | return -EINVAL; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1116 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1117 | drvdata->seq_23_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1118 | return size; |
| 1119 | } |
| 1120 | static DEVICE_ATTR(seq_23_event, S_IRUGO | S_IWUSR, etm_show_seq_23_event, |
| 1121 | etm_store_seq_23_event); |
| 1122 | |
| 1123 | static ssize_t etm_show_seq_31_event(struct device *dev, |
| 1124 | struct device_attribute *attr, char *buf) |
| 1125 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1126 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1127 | unsigned long val = drvdata->seq_31_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1128 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1129 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1130 | } |
| 1131 | |
| 1132 | static ssize_t etm_store_seq_31_event(struct device *dev, |
| 1133 | struct device_attribute *attr, |
| 1134 | const char *buf, size_t size) |
| 1135 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1136 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1137 | unsigned long val; |
| 1138 | |
| 1139 | if (sscanf(buf, "%lx", &val) != 1) |
| 1140 | return -EINVAL; |
| 1141 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1142 | drvdata->seq_31_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1143 | return size; |
| 1144 | } |
| 1145 | static DEVICE_ATTR(seq_31_event, S_IRUGO | S_IWUSR, etm_show_seq_31_event, |
| 1146 | etm_store_seq_31_event); |
| 1147 | |
| 1148 | static ssize_t etm_show_seq_32_event(struct device *dev, |
| 1149 | struct device_attribute *attr, char *buf) |
| 1150 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1151 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1152 | unsigned long val = drvdata->seq_32_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1153 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1154 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1155 | } |
| 1156 | |
| 1157 | static ssize_t etm_store_seq_32_event(struct device *dev, |
| 1158 | struct device_attribute *attr, |
| 1159 | const char *buf, size_t size) |
| 1160 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1161 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1162 | unsigned long val; |
| 1163 | |
| 1164 | if (sscanf(buf, "%lx", &val) != 1) |
| 1165 | return -EINVAL; |
| 1166 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1167 | drvdata->seq_32_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1168 | return size; |
| 1169 | } |
| 1170 | static DEVICE_ATTR(seq_32_event, S_IRUGO | S_IWUSR, etm_show_seq_32_event, |
| 1171 | etm_store_seq_32_event); |
| 1172 | |
| 1173 | static ssize_t etm_show_seq_13_event(struct device *dev, |
| 1174 | struct device_attribute *attr, char *buf) |
| 1175 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1176 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1177 | unsigned long val = drvdata->seq_13_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1178 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1179 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1180 | } |
| 1181 | |
| 1182 | static ssize_t etm_store_seq_13_event(struct device *dev, |
| 1183 | struct device_attribute *attr, |
| 1184 | const char *buf, size_t size) |
| 1185 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1186 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1187 | unsigned long val; |
| 1188 | |
| 1189 | if (sscanf(buf, "%lx", &val) != 1) |
| 1190 | return -EINVAL; |
| 1191 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1192 | drvdata->seq_13_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1193 | return size; |
| 1194 | } |
| 1195 | static DEVICE_ATTR(seq_13_event, S_IRUGO | S_IWUSR, etm_show_seq_13_event, |
| 1196 | etm_store_seq_13_event); |
| 1197 | |
| 1198 | static ssize_t etm_show_seq_curr_state(struct device *dev, |
| 1199 | struct device_attribute *attr, char *buf) |
| 1200 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1201 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1202 | unsigned long val = drvdata->seq_curr_state; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1203 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1204 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1205 | } |
| 1206 | |
| 1207 | static ssize_t etm_store_seq_curr_state(struct device *dev, |
| 1208 | struct device_attribute *attr, |
| 1209 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1210 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1211 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1212 | unsigned long val; |
| 1213 | |
| 1214 | if (sscanf(buf, "%lx", &val) != 1) |
| 1215 | return -EINVAL; |
| 1216 | if (val > ETM_SEQ_STATE_MAX_VAL) |
| 1217 | return -EINVAL; |
| 1218 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1219 | drvdata->seq_curr_state = val; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1220 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1221 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1222 | static DEVICE_ATTR(seq_curr_state, S_IRUGO | S_IWUSR, etm_show_seq_curr_state, |
| 1223 | etm_store_seq_curr_state); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1224 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1225 | static ssize_t etm_show_ctxid_idx(struct device *dev, |
| 1226 | struct device_attribute *attr, char *buf) |
| 1227 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1228 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1229 | unsigned long val = drvdata->ctxid_idx; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1230 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1231 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1232 | } |
| 1233 | |
| 1234 | static ssize_t etm_store_ctxid_idx(struct device *dev, |
| 1235 | struct device_attribute *attr, |
| 1236 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1237 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1238 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1239 | unsigned long val; |
| 1240 | |
| 1241 | if (sscanf(buf, "%lx", &val) != 1) |
| 1242 | return -EINVAL; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1243 | if (val >= drvdata->nr_ctxid_cmp) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1244 | return -EINVAL; |
| 1245 | |
| 1246 | /* Use mutex to ensure index doesn't change while it gets dereferenced |
| 1247 | * multiple times within a mutex block elsewhere. |
| 1248 | */ |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1249 | mutex_lock(&drvdata->mutex); |
| 1250 | drvdata->ctxid_idx = val; |
| 1251 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1252 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1253 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1254 | static DEVICE_ATTR(ctxid_idx, S_IRUGO | S_IWUSR, etm_show_ctxid_idx, |
| 1255 | etm_store_ctxid_idx); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1256 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1257 | static ssize_t etm_show_ctxid_val(struct device *dev, |
| 1258 | struct device_attribute *attr, char *buf) |
| 1259 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1260 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1261 | unsigned long val; |
| 1262 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1263 | mutex_lock(&drvdata->mutex); |
| 1264 | val = drvdata->ctxid_val[drvdata->ctxid_idx]; |
| 1265 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1266 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1267 | } |
| 1268 | |
| 1269 | static ssize_t etm_store_ctxid_val(struct device *dev, |
| 1270 | struct device_attribute *attr, |
| 1271 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1272 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1273 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1274 | unsigned long val; |
| 1275 | |
| 1276 | if (sscanf(buf, "%lx", &val) != 1) |
| 1277 | return -EINVAL; |
| 1278 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1279 | mutex_lock(&drvdata->mutex); |
| 1280 | drvdata->ctxid_val[drvdata->ctxid_idx] = val; |
| 1281 | mutex_unlock(&drvdata->mutex); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1282 | return size; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1283 | } |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1284 | static DEVICE_ATTR(ctxid_val, S_IRUGO | S_IWUSR, etm_show_ctxid_val, |
| 1285 | etm_store_ctxid_val); |
| 1286 | |
| 1287 | static ssize_t etm_show_ctxid_mask(struct device *dev, |
| 1288 | struct device_attribute *attr, char *buf) |
| 1289 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1290 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1291 | unsigned long val = drvdata->ctxid_mask; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1292 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1293 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1294 | } |
| 1295 | |
| 1296 | static ssize_t etm_store_ctxid_mask(struct device *dev, |
| 1297 | struct device_attribute *attr, |
| 1298 | const char *buf, size_t size) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1299 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1300 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1301 | unsigned long val; |
| 1302 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1303 | if (sscanf(buf, "%lx", &val) != 1) |
| 1304 | return -EINVAL; |
| 1305 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1306 | drvdata->ctxid_mask = val; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1307 | return size; |
| 1308 | } |
| 1309 | static DEVICE_ATTR(ctxid_mask, S_IRUGO | S_IWUSR, etm_show_ctxid_mask, |
| 1310 | etm_store_ctxid_mask); |
| 1311 | |
| 1312 | static ssize_t etm_show_sync_freq(struct device *dev, |
| 1313 | struct device_attribute *attr, char *buf) |
| 1314 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1315 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1316 | unsigned long val = drvdata->sync_freq; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1317 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1318 | } |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1319 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1320 | static ssize_t etm_store_sync_freq(struct device *dev, |
| 1321 | struct device_attribute *attr, |
| 1322 | const char *buf, size_t size) |
| 1323 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1324 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1325 | unsigned long val; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1326 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1327 | if (sscanf(buf, "%lx", &val) != 1) |
| 1328 | return -EINVAL; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1329 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1330 | drvdata->sync_freq = val & ETM_SYNC_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1331 | return size; |
| 1332 | } |
| 1333 | static DEVICE_ATTR(sync_freq, S_IRUGO | S_IWUSR, etm_show_sync_freq, |
| 1334 | etm_store_sync_freq); |
| 1335 | |
| 1336 | static ssize_t etm_show_timestamp_event(struct device *dev, |
| 1337 | struct device_attribute *attr, |
| 1338 | char *buf) |
| 1339 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1340 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1341 | unsigned long val = drvdata->timestamp_event; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1342 | |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1343 | return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); |
| 1344 | } |
| 1345 | |
| 1346 | static ssize_t etm_store_timestamp_event(struct device *dev, |
| 1347 | struct device_attribute *attr, |
| 1348 | const char *buf, size_t size) |
| 1349 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1350 | struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1351 | unsigned long val; |
| 1352 | |
| 1353 | if (sscanf(buf, "%lx", &val) != 1) |
| 1354 | return -EINVAL; |
| 1355 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1356 | drvdata->timestamp_event = val & ETM_EVENT_MASK; |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1357 | return size; |
| 1358 | } |
| 1359 | static DEVICE_ATTR(timestamp_event, S_IRUGO | S_IWUSR, etm_show_timestamp_event, |
| 1360 | etm_store_timestamp_event); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1361 | |
| 1362 | static struct attribute *etm_attrs[] = { |
Pratik Patel | a9c0e06 | 2012-05-28 13:45:35 -0700 | [diff] [blame] | 1363 | &dev_attr_nr_addr_cmp.attr, |
| 1364 | &dev_attr_nr_cntr.attr, |
| 1365 | &dev_attr_nr_ctxid_cmp.attr, |
| 1366 | &dev_attr_reset.attr, |
| 1367 | &dev_attr_mode.attr, |
| 1368 | &dev_attr_trigger_event.attr, |
| 1369 | &dev_attr_enable_event.attr, |
| 1370 | &dev_attr_fifofull_level.attr, |
| 1371 | &dev_attr_addr_idx.attr, |
| 1372 | &dev_attr_addr_single.attr, |
| 1373 | &dev_attr_addr_range.attr, |
| 1374 | &dev_attr_addr_start.attr, |
| 1375 | &dev_attr_addr_stop.attr, |
| 1376 | &dev_attr_addr_acctype.attr, |
| 1377 | &dev_attr_cntr_idx.attr, |
| 1378 | &dev_attr_cntr_rld_val.attr, |
| 1379 | &dev_attr_cntr_event.attr, |
| 1380 | &dev_attr_cntr_rld_event.attr, |
| 1381 | &dev_attr_cntr_val.attr, |
| 1382 | &dev_attr_seq_12_event.attr, |
| 1383 | &dev_attr_seq_21_event.attr, |
| 1384 | &dev_attr_seq_23_event.attr, |
| 1385 | &dev_attr_seq_31_event.attr, |
| 1386 | &dev_attr_seq_32_event.attr, |
| 1387 | &dev_attr_seq_13_event.attr, |
| 1388 | &dev_attr_seq_curr_state.attr, |
| 1389 | &dev_attr_ctxid_idx.attr, |
| 1390 | &dev_attr_ctxid_val.attr, |
| 1391 | &dev_attr_ctxid_mask.attr, |
| 1392 | &dev_attr_sync_freq.attr, |
| 1393 | &dev_attr_timestamp_event.attr, |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1394 | NULL, |
| 1395 | }; |
| 1396 | |
| 1397 | static struct attribute_group etm_attr_grp = { |
| 1398 | .attrs = etm_attrs, |
| 1399 | }; |
| 1400 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1401 | static const struct attribute_group *etm_attr_grps[] = { |
| 1402 | &etm_attr_grp, |
| 1403 | NULL, |
| 1404 | }; |
| 1405 | |
| 1406 | /* Memory mapped writes to clear os lock not supported */ |
| 1407 | static void etm_os_unlock(void *unused) |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1408 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1409 | unsigned long value = 0x0; |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1410 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1411 | asm("mcr p14, 1, %0, c1, c0, 4\n\t" : : "r" (value)); |
| 1412 | asm("isb\n\t"); |
Pratik Patel | 6630ebe | 2012-03-06 16:44:22 -0800 | [diff] [blame] | 1413 | } |
| 1414 | |
Stephen Boyd | a951050 | 2012-04-24 16:23:34 -0700 | [diff] [blame] | 1415 | static bool __devinit etm_arch_supported(uint8_t arch) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1416 | { |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1417 | switch (arch) { |
| 1418 | case PFT_ARCH_V1_1: |
| 1419 | break; |
| 1420 | default: |
| 1421 | return false; |
| 1422 | } |
| 1423 | return true; |
| 1424 | } |
| 1425 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1426 | static int __devinit etm_init_arch_data(struct etm_drvdata *drvdata) |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1427 | { |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1428 | int ret; |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1429 | uint32_t etmidr; |
| 1430 | uint32_t etmccr; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1431 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 1432 | /* Unlock OS lock first to allow memory mapped reads and writes */ |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1433 | etm_os_unlock(NULL); |
| 1434 | smp_call_function(etm_os_unlock, NULL, 1); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1435 | ETM_UNLOCK(drvdata); |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 1436 | /* Vote for ETM power/clock enable */ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1437 | etm_clr_pwrdwn(drvdata); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1438 | /* Set prog bit. It will be set from reset but this is included to |
| 1439 | * ensure it is set |
| 1440 | */ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1441 | etm_set_prog(drvdata); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1442 | |
| 1443 | /* find all capabilities */ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1444 | etmidr = etm_readl(drvdata, ETMIDR); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1445 | drvdata->arch = BMVAL(etmidr, 4, 11); |
| 1446 | if (etm_arch_supported(drvdata->arch) == false) { |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1447 | ret = -EINVAL; |
| 1448 | goto err; |
| 1449 | } |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1450 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1451 | etmccr = etm_readl(drvdata, ETMCCR); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1452 | drvdata->nr_addr_cmp = BMVAL(etmccr, 0, 3) * 2; |
| 1453 | drvdata->nr_cntr = BMVAL(etmccr, 13, 15); |
| 1454 | drvdata->nr_ext_inp = BMVAL(etmccr, 17, 19); |
| 1455 | drvdata->nr_ext_out = BMVAL(etmccr, 20, 22); |
| 1456 | drvdata->nr_ctxid_cmp = BMVAL(etmccr, 24, 25); |
Pratik Patel | 2d0c7b6 | 2012-02-24 19:04:37 -0800 | [diff] [blame] | 1457 | |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 1458 | /* Vote for ETM power/clock disable */ |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1459 | etm_set_pwrdwn(drvdata); |
| 1460 | ETM_LOCK(drvdata); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1461 | |
| 1462 | return 0; |
| 1463 | err: |
| 1464 | return ret; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1467 | static void __devinit etm_init_default_data(struct etm_drvdata *drvdata) |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1468 | { |
| 1469 | int i; |
| 1470 | |
| 1471 | drvdata->trigger_event = 0x406F; |
| 1472 | drvdata->enable_event = 0x6F; |
| 1473 | drvdata->enable_ctrl1 = 0x1; |
| 1474 | drvdata->fifofull_level = 0x28; |
| 1475 | if (drvdata->nr_addr_cmp >= 2) { |
| 1476 | drvdata->addr_val[0] = (uint32_t) _stext; |
| 1477 | drvdata->addr_val[1] = (uint32_t) _etext; |
| 1478 | drvdata->addr_type[0] = ETM_ADDR_TYPE_RANGE; |
| 1479 | drvdata->addr_type[1] = ETM_ADDR_TYPE_RANGE; |
| 1480 | } |
| 1481 | for (i = 0; i < drvdata->nr_cntr; i++) { |
| 1482 | drvdata->cntr_event[i] = 0x406F; |
| 1483 | drvdata->cntr_rld_event[i] = 0x406F; |
| 1484 | } |
| 1485 | drvdata->seq_12_event = 0x406F; |
| 1486 | drvdata->seq_21_event = 0x406F; |
| 1487 | drvdata->seq_23_event = 0x406F; |
| 1488 | drvdata->seq_31_event = 0x406F; |
| 1489 | drvdata->seq_32_event = 0x406F; |
| 1490 | drvdata->seq_13_event = 0x406F; |
Pratik Patel | 77b9063 | 2012-07-17 17:54:51 -0700 | [diff] [blame^] | 1491 | /* Bits[7:0] of ETMSYNCFR are reserved on Krait pass3 onwards */ |
| 1492 | if (cpu_is_krait() && !cpu_is_krait_v1() && !cpu_is_krait_v2()) |
| 1493 | drvdata->sync_freq = 0x100; |
| 1494 | else |
| 1495 | drvdata->sync_freq = 0x80; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1496 | drvdata->timestamp_event = 0x406F; |
| 1497 | |
| 1498 | /* Overrides for Krait pass1 */ |
| 1499 | if (cpu_is_krait_v1()) { |
| 1500 | /* Krait pass1 doesn't support include filtering and non-cycle |
| 1501 | * accurate tracing |
| 1502 | */ |
| 1503 | drvdata->mode = (ETM_MODE_EXCLUDE | ETM_MODE_CYCACC); |
| 1504 | drvdata->ctrl = 0x1000; |
| 1505 | drvdata->enable_ctrl1 = 0x1000000; |
| 1506 | for (i = 0; i < drvdata->nr_addr_cmp; i++) { |
| 1507 | drvdata->addr_val[i] = 0x0; |
| 1508 | drvdata->addr_acctype[i] = 0x0; |
| 1509 | drvdata->addr_type[i] = ETM_ADDR_TYPE_NONE; |
| 1510 | } |
| 1511 | } |
| 1512 | } |
| 1513 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1514 | static int __devinit etm_probe(struct platform_device *pdev) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1515 | { |
Pratik Patel | e577179 | 2011-09-17 18:33:54 -0700 | [diff] [blame] | 1516 | int ret; |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1517 | struct device *dev = &pdev->dev; |
Pratik Patel | 5f6d1af | 2012-06-13 15:48:13 -0700 | [diff] [blame] | 1518 | struct coresight_platform_data *pdata; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1519 | struct etm_drvdata *drvdata; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1520 | struct resource *res; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1521 | static int etm_count; |
| 1522 | struct coresight_desc *desc; |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1523 | |
Pratik Patel | 5f6d1af | 2012-06-13 15:48:13 -0700 | [diff] [blame] | 1524 | if (pdev->dev.of_node) { |
| 1525 | pdata = of_get_coresight_platform_data(dev, pdev->dev.of_node); |
| 1526 | if (IS_ERR(pdata)) |
| 1527 | return PTR_ERR(pdata); |
| 1528 | pdev->dev.platform_data = pdata; |
| 1529 | } |
| 1530 | |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1531 | drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); |
| 1532 | if (!drvdata) |
| 1533 | return -ENOMEM; |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1534 | drvdata->dev = &pdev->dev; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1535 | platform_set_drvdata(pdev, drvdata); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1536 | |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1537 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1538 | if (!res) |
| 1539 | return -ENODEV; |
| 1540 | drvdata->base = devm_ioremap(dev, res->start, resource_size(res)); |
| 1541 | if (!drvdata->base) |
| 1542 | return -ENOMEM; |
| 1543 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1544 | mutex_init(&drvdata->mutex); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1545 | wake_lock_init(&drvdata->wake_lock, WAKE_LOCK_SUSPEND, "coresight-etm"); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1546 | pm_qos_add_request(&drvdata->qos_req, PM_QOS_CPU_DMA_LATENCY, |
| 1547 | PM_QOS_DEFAULT_VALUE); |
Pratik Patel | e10a77c | 2012-03-20 10:35:16 -0700 | [diff] [blame] | 1548 | |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1549 | drvdata->clk = devm_clk_get(dev, "core_clk"); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1550 | if (IS_ERR(drvdata->clk)) { |
| 1551 | ret = PTR_ERR(drvdata->clk); |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1552 | goto err0; |
Pratik Patel | f17b147 | 2012-05-25 22:23:52 -0700 | [diff] [blame] | 1553 | } |
Pratik Patel | 6fb3834 | 2012-06-03 14:51:38 -0700 | [diff] [blame] | 1554 | ret = clk_set_rate(drvdata->clk, CORESIGHT_CLK_RATE_TRACE); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1555 | if (ret) |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1556 | goto err0; |
| 1557 | |
| 1558 | drvdata->cpu = etm_count++; |
| 1559 | |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1560 | ret = clk_prepare_enable(drvdata->clk); |
Pratik Patel | f17b147 | 2012-05-25 22:23:52 -0700 | [diff] [blame] | 1561 | if (ret) |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1562 | goto err0; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1563 | ret = etm_init_arch_data(drvdata); |
Pratik Patel | 61de730 | 2012-03-07 12:06:10 -0800 | [diff] [blame] | 1564 | if (ret) |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1565 | goto err1; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1566 | etm_init_default_data(drvdata); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1567 | clk_disable_unprepare(drvdata->clk); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1568 | |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1569 | desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1570 | if (!desc) { |
| 1571 | ret = -ENOMEM; |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1572 | goto err0; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1573 | } |
| 1574 | desc->type = CORESIGHT_DEV_TYPE_SOURCE; |
| 1575 | desc->subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_PROC; |
| 1576 | desc->ops = &etm_cs_ops; |
| 1577 | desc->pdata = pdev->dev.platform_data; |
| 1578 | desc->dev = &pdev->dev; |
| 1579 | desc->groups = etm_attr_grps; |
| 1580 | desc->owner = THIS_MODULE; |
| 1581 | drvdata->csdev = coresight_register(desc); |
| 1582 | if (IS_ERR(drvdata->csdev)) { |
| 1583 | ret = PTR_ERR(drvdata->csdev); |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1584 | goto err0; |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1585 | } |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1586 | |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1587 | dev_info(dev, "ETM initialized\n"); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1588 | |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1589 | if (boot_enable) |
| 1590 | coresight_enable(drvdata->csdev); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1591 | |
| 1592 | return 0; |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1593 | err1: |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1594 | clk_disable_unprepare(drvdata->clk); |
Pratik Patel | 4a1b252 | 2012-06-17 15:31:15 -0700 | [diff] [blame] | 1595 | err0: |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1596 | pm_qos_remove_request(&drvdata->qos_req); |
| 1597 | wake_lock_destroy(&drvdata->wake_lock); |
| 1598 | mutex_destroy(&drvdata->mutex); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1599 | return ret; |
| 1600 | } |
| 1601 | |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1602 | static int __devexit etm_remove(struct platform_device *pdev) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1603 | { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1604 | struct etm_drvdata *drvdata = platform_get_drvdata(pdev); |
| 1605 | |
| 1606 | coresight_unregister(drvdata->csdev); |
Pratik Patel | 16aefdb | 2012-05-30 10:41:23 -0700 | [diff] [blame] | 1607 | pm_qos_remove_request(&drvdata->qos_req); |
| 1608 | wake_lock_destroy(&drvdata->wake_lock); |
| 1609 | mutex_destroy(&drvdata->mutex); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1610 | return 0; |
| 1611 | } |
| 1612 | |
Pratik Patel | 9eae482 | 2012-05-14 17:34:53 -0700 | [diff] [blame] | 1613 | static struct of_device_id etm_match[] = { |
Pratik Patel | 5f6d1af | 2012-06-13 15:48:13 -0700 | [diff] [blame] | 1614 | {.compatible = "arm,coresight-etm"}, |
Pratik Patel | 9eae482 | 2012-05-14 17:34:53 -0700 | [diff] [blame] | 1615 | {} |
| 1616 | }; |
| 1617 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1618 | static struct platform_driver etm_driver = { |
| 1619 | .probe = etm_probe, |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1620 | .remove = __devexit_p(etm_remove), |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1621 | .driver = { |
Pratik Patel | 3b0ca88 | 2012-06-01 16:54:14 -0700 | [diff] [blame] | 1622 | .name = "coresight-etm", |
Pratik Patel | 9eae482 | 2012-05-14 17:34:53 -0700 | [diff] [blame] | 1623 | .owner = THIS_MODULE, |
| 1624 | .of_match_table = etm_match, |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1625 | }, |
| 1626 | }; |
| 1627 | |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1628 | int __init etm_init(void) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1629 | { |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1630 | return platform_driver_register(&etm_driver); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1631 | } |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1632 | module_init(etm_init); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1633 | |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1634 | void __exit etm_exit(void) |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1635 | { |
Pratik Patel | 492b301 | 2012-03-06 14:22:30 -0800 | [diff] [blame] | 1636 | platform_driver_unregister(&etm_driver); |
Pratik Patel | 7831c08 | 2011-06-08 21:44:37 -0700 | [diff] [blame] | 1637 | } |
Pratik Patel | f6fe918 | 2012-03-20 14:04:18 -0700 | [diff] [blame] | 1638 | module_exit(etm_exit); |
| 1639 | |
| 1640 | MODULE_LICENSE("GPL v2"); |
| 1641 | MODULE_DESCRIPTION("CoreSight Program Flow Trace driver"); |