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