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