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