Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson SA 2010 |
| 3 | * |
| 4 | * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson. |
| 5 | * License Terms: GNU General Public License v2 |
| 6 | */ |
| 7 | |
| 8 | #include <linux/seq_file.h> |
| 9 | #include <linux/uaccess.h> |
| 10 | #include <linux/fs.h> |
Paul Gortmaker | 4e36dd3 | 2011-07-03 15:13:27 -0400 | [diff] [blame] | 11 | #include <linux/module.h> |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 12 | #include <linux/debugfs.h> |
| 13 | #include <linux/platform_device.h> |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/kobject.h> |
| 16 | #include <linux/slab.h> |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 17 | |
| 18 | #include <linux/mfd/abx500.h> |
Linus Walleij | ee66e65 | 2011-12-02 14:16:33 +0100 | [diff] [blame] | 19 | #include <linux/mfd/abx500/ab8500.h> |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 20 | |
| 21 | static u32 debug_bank; |
| 22 | static u32 debug_address; |
| 23 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 24 | static int irq_first; |
| 25 | static int irq_last; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 26 | static u32 irq_count[AB8500_NR_IRQS]; |
| 27 | |
| 28 | static struct device_attribute *dev_attr[AB8500_NR_IRQS]; |
| 29 | static char *event_name[AB8500_NR_IRQS]; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 30 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 31 | /** |
| 32 | * struct ab8500_reg_range |
| 33 | * @first: the first address of the range |
| 34 | * @last: the last address of the range |
| 35 | * @perm: access permissions for the range |
| 36 | */ |
| 37 | struct ab8500_reg_range { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 38 | u8 first; |
| 39 | u8 last; |
| 40 | u8 perm; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | /** |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 44 | * struct ab8500_prcmu_ranges |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 45 | * @num_ranges: the number of ranges in the list |
| 46 | * @bankid: bank identifier |
| 47 | * @range: the list of register ranges |
| 48 | */ |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 49 | struct ab8500_prcmu_ranges { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 50 | u8 num_ranges; |
| 51 | u8 bankid; |
| 52 | const struct ab8500_reg_range *range; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | #define AB8500_NAME_STRING "ab8500" |
| 56 | #define AB8500_NUM_BANKS 22 |
| 57 | |
| 58 | #define AB8500_REV_REG 0x80 |
| 59 | |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 60 | static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 61 | [0x0] = { |
| 62 | .num_ranges = 0, |
| 63 | .range = 0, |
| 64 | }, |
| 65 | [AB8500_SYS_CTRL1_BLOCK] = { |
| 66 | .num_ranges = 3, |
| 67 | .range = (struct ab8500_reg_range[]) { |
| 68 | { |
| 69 | .first = 0x00, |
| 70 | .last = 0x02, |
| 71 | }, |
| 72 | { |
| 73 | .first = 0x42, |
| 74 | .last = 0x42, |
| 75 | }, |
| 76 | { |
| 77 | .first = 0x80, |
| 78 | .last = 0x81, |
| 79 | }, |
| 80 | }, |
| 81 | }, |
| 82 | [AB8500_SYS_CTRL2_BLOCK] = { |
| 83 | .num_ranges = 4, |
| 84 | .range = (struct ab8500_reg_range[]) { |
| 85 | { |
| 86 | .first = 0x00, |
| 87 | .last = 0x0D, |
| 88 | }, |
| 89 | { |
| 90 | .first = 0x0F, |
| 91 | .last = 0x17, |
| 92 | }, |
| 93 | { |
| 94 | .first = 0x30, |
| 95 | .last = 0x30, |
| 96 | }, |
| 97 | { |
| 98 | .first = 0x32, |
| 99 | .last = 0x33, |
| 100 | }, |
| 101 | }, |
| 102 | }, |
| 103 | [AB8500_REGU_CTRL1] = { |
| 104 | .num_ranges = 3, |
| 105 | .range = (struct ab8500_reg_range[]) { |
| 106 | { |
| 107 | .first = 0x00, |
| 108 | .last = 0x00, |
| 109 | }, |
| 110 | { |
| 111 | .first = 0x03, |
| 112 | .last = 0x10, |
| 113 | }, |
| 114 | { |
| 115 | .first = 0x80, |
| 116 | .last = 0x84, |
| 117 | }, |
| 118 | }, |
| 119 | }, |
| 120 | [AB8500_REGU_CTRL2] = { |
| 121 | .num_ranges = 5, |
| 122 | .range = (struct ab8500_reg_range[]) { |
| 123 | { |
| 124 | .first = 0x00, |
| 125 | .last = 0x15, |
| 126 | }, |
| 127 | { |
| 128 | .first = 0x17, |
| 129 | .last = 0x19, |
| 130 | }, |
| 131 | { |
| 132 | .first = 0x1B, |
| 133 | .last = 0x1D, |
| 134 | }, |
| 135 | { |
| 136 | .first = 0x1F, |
| 137 | .last = 0x22, |
| 138 | }, |
| 139 | { |
| 140 | .first = 0x40, |
| 141 | .last = 0x44, |
| 142 | }, |
| 143 | /* 0x80-0x8B is SIM registers and should |
| 144 | * not be accessed from here */ |
| 145 | }, |
| 146 | }, |
| 147 | [AB8500_USB] = { |
| 148 | .num_ranges = 2, |
| 149 | .range = (struct ab8500_reg_range[]) { |
| 150 | { |
| 151 | .first = 0x80, |
| 152 | .last = 0x83, |
| 153 | }, |
| 154 | { |
| 155 | .first = 0x87, |
| 156 | .last = 0x8A, |
| 157 | }, |
| 158 | }, |
| 159 | }, |
| 160 | [AB8500_TVOUT] = { |
| 161 | .num_ranges = 9, |
| 162 | .range = (struct ab8500_reg_range[]) { |
| 163 | { |
| 164 | .first = 0x00, |
| 165 | .last = 0x12, |
| 166 | }, |
| 167 | { |
| 168 | .first = 0x15, |
| 169 | .last = 0x17, |
| 170 | }, |
| 171 | { |
| 172 | .first = 0x19, |
| 173 | .last = 0x21, |
| 174 | }, |
| 175 | { |
| 176 | .first = 0x27, |
| 177 | .last = 0x2C, |
| 178 | }, |
| 179 | { |
| 180 | .first = 0x41, |
| 181 | .last = 0x41, |
| 182 | }, |
| 183 | { |
| 184 | .first = 0x45, |
| 185 | .last = 0x5B, |
| 186 | }, |
| 187 | { |
| 188 | .first = 0x5D, |
| 189 | .last = 0x5D, |
| 190 | }, |
| 191 | { |
| 192 | .first = 0x69, |
| 193 | .last = 0x69, |
| 194 | }, |
| 195 | { |
| 196 | .first = 0x80, |
| 197 | .last = 0x81, |
| 198 | }, |
| 199 | }, |
| 200 | }, |
| 201 | [AB8500_DBI] = { |
| 202 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 203 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 204 | }, |
| 205 | [AB8500_ECI_AV_ACC] = { |
| 206 | .num_ranges = 1, |
| 207 | .range = (struct ab8500_reg_range[]) { |
| 208 | { |
| 209 | .first = 0x80, |
| 210 | .last = 0x82, |
| 211 | }, |
| 212 | }, |
| 213 | }, |
| 214 | [0x9] = { |
| 215 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 216 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 217 | }, |
| 218 | [AB8500_GPADC] = { |
| 219 | .num_ranges = 1, |
| 220 | .range = (struct ab8500_reg_range[]) { |
| 221 | { |
| 222 | .first = 0x00, |
| 223 | .last = 0x08, |
| 224 | }, |
| 225 | }, |
| 226 | }, |
| 227 | [AB8500_CHARGER] = { |
| 228 | .num_ranges = 8, |
| 229 | .range = (struct ab8500_reg_range[]) { |
| 230 | { |
| 231 | .first = 0x00, |
| 232 | .last = 0x03, |
| 233 | }, |
| 234 | { |
| 235 | .first = 0x05, |
| 236 | .last = 0x05, |
| 237 | }, |
| 238 | { |
| 239 | .first = 0x40, |
| 240 | .last = 0x40, |
| 241 | }, |
| 242 | { |
| 243 | .first = 0x42, |
| 244 | .last = 0x42, |
| 245 | }, |
| 246 | { |
| 247 | .first = 0x44, |
| 248 | .last = 0x44, |
| 249 | }, |
| 250 | { |
| 251 | .first = 0x50, |
| 252 | .last = 0x55, |
| 253 | }, |
| 254 | { |
| 255 | .first = 0x80, |
| 256 | .last = 0x82, |
| 257 | }, |
| 258 | { |
| 259 | .first = 0xC0, |
| 260 | .last = 0xC2, |
| 261 | }, |
| 262 | }, |
| 263 | }, |
| 264 | [AB8500_GAS_GAUGE] = { |
| 265 | .num_ranges = 3, |
| 266 | .range = (struct ab8500_reg_range[]) { |
| 267 | { |
| 268 | .first = 0x00, |
| 269 | .last = 0x00, |
| 270 | }, |
| 271 | { |
| 272 | .first = 0x07, |
| 273 | .last = 0x0A, |
| 274 | }, |
| 275 | { |
| 276 | .first = 0x10, |
| 277 | .last = 0x14, |
| 278 | }, |
| 279 | }, |
| 280 | }, |
| 281 | [AB8500_AUDIO] = { |
| 282 | .num_ranges = 1, |
| 283 | .range = (struct ab8500_reg_range[]) { |
| 284 | { |
| 285 | .first = 0x00, |
| 286 | .last = 0x6F, |
| 287 | }, |
| 288 | }, |
| 289 | }, |
| 290 | [AB8500_INTERRUPT] = { |
| 291 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 292 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 293 | }, |
| 294 | [AB8500_RTC] = { |
| 295 | .num_ranges = 1, |
| 296 | .range = (struct ab8500_reg_range[]) { |
| 297 | { |
| 298 | .first = 0x00, |
| 299 | .last = 0x0F, |
| 300 | }, |
| 301 | }, |
| 302 | }, |
| 303 | [AB8500_MISC] = { |
| 304 | .num_ranges = 8, |
| 305 | .range = (struct ab8500_reg_range[]) { |
| 306 | { |
| 307 | .first = 0x00, |
| 308 | .last = 0x05, |
| 309 | }, |
| 310 | { |
| 311 | .first = 0x10, |
| 312 | .last = 0x15, |
| 313 | }, |
| 314 | { |
| 315 | .first = 0x20, |
| 316 | .last = 0x25, |
| 317 | }, |
| 318 | { |
| 319 | .first = 0x30, |
| 320 | .last = 0x35, |
| 321 | }, |
| 322 | { |
| 323 | .first = 0x40, |
| 324 | .last = 0x45, |
| 325 | }, |
| 326 | { |
| 327 | .first = 0x50, |
| 328 | .last = 0x50, |
| 329 | }, |
| 330 | { |
| 331 | .first = 0x60, |
| 332 | .last = 0x67, |
| 333 | }, |
| 334 | { |
| 335 | .first = 0x80, |
| 336 | .last = 0x80, |
| 337 | }, |
| 338 | }, |
| 339 | }, |
| 340 | [0x11] = { |
| 341 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 342 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 343 | }, |
| 344 | [0x12] = { |
| 345 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 346 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 347 | }, |
| 348 | [0x13] = { |
| 349 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 350 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 351 | }, |
| 352 | [0x14] = { |
| 353 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 354 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 355 | }, |
| 356 | [AB8500_OTP_EMUL] = { |
| 357 | .num_ranges = 1, |
| 358 | .range = (struct ab8500_reg_range[]) { |
| 359 | { |
| 360 | .first = 0x01, |
| 361 | .last = 0x0F, |
| 362 | }, |
| 363 | }, |
| 364 | }, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 365 | }; |
| 366 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 367 | static irqreturn_t ab8500_debug_handler(int irq, void *data) |
| 368 | { |
| 369 | char buf[16]; |
| 370 | struct kobject *kobj = (struct kobject *)data; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 371 | unsigned int irq_abb = irq - irq_first; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 372 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 373 | if (irq_abb < AB8500_NR_IRQS) |
| 374 | irq_count[irq_abb]++; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 375 | /* |
| 376 | * This makes it possible to use poll for events (POLLPRI | POLLERR) |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 377 | * from userspace on sysfs file named <irq-nr> |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 378 | */ |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 379 | sprintf(buf, "%d", irq); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 380 | sysfs_notify(kobj, NULL, buf); |
| 381 | |
| 382 | return IRQ_HANDLED; |
| 383 | } |
| 384 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 385 | static int ab8500_registers_print(struct seq_file *s, void *p) |
| 386 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 387 | struct device *dev = s->private; |
| 388 | unsigned int i; |
| 389 | u32 bank = debug_bank; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 390 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 391 | seq_printf(s, AB8500_NAME_STRING " register values:\n"); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 392 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 393 | seq_printf(s, " bank %u:\n", bank); |
| 394 | for (i = 0; i < debug_ranges[bank].num_ranges; i++) { |
| 395 | u32 reg; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 396 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 397 | for (reg = debug_ranges[bank].range[i].first; |
| 398 | reg <= debug_ranges[bank].range[i].last; |
| 399 | reg++) { |
| 400 | u8 value; |
| 401 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 402 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 403 | err = abx500_get_register_interruptible(dev, |
| 404 | (u8)bank, (u8)reg, &value); |
| 405 | if (err < 0) { |
| 406 | dev_err(dev, "ab->read fail %d\n", err); |
| 407 | return err; |
| 408 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 409 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 410 | err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", bank, |
| 411 | reg, value); |
| 412 | if (err < 0) { |
| 413 | dev_err(dev, "seq_printf overflow\n"); |
| 414 | /* Error is not returned here since |
| 415 | * the output is wanted in any case */ |
| 416 | return 0; |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static int ab8500_registers_open(struct inode *inode, struct file *file) |
| 424 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 425 | return single_open(file, ab8500_registers_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static const struct file_operations ab8500_registers_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 429 | .open = ab8500_registers_open, |
| 430 | .read = seq_read, |
| 431 | .llseek = seq_lseek, |
| 432 | .release = single_release, |
| 433 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 434 | }; |
| 435 | |
| 436 | static int ab8500_bank_print(struct seq_file *s, void *p) |
| 437 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 438 | return seq_printf(s, "%d\n", debug_bank); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static int ab8500_bank_open(struct inode *inode, struct file *file) |
| 442 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 443 | return single_open(file, ab8500_bank_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | static ssize_t ab8500_bank_write(struct file *file, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 447 | const char __user *user_buf, |
| 448 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 449 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 450 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 451 | unsigned long user_bank; |
| 452 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 453 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 454 | /* Get userspace string and assure termination */ |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 455 | err = kstrtoul_from_user(user_buf, count, 0, &user_bank); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 456 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 457 | return err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 458 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 459 | if (user_bank >= AB8500_NUM_BANKS) { |
| 460 | dev_err(dev, "debugfs error input > number of banks\n"); |
| 461 | return -EINVAL; |
| 462 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 463 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 464 | debug_bank = user_bank; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 465 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 466 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | static int ab8500_address_print(struct seq_file *s, void *p) |
| 470 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 471 | return seq_printf(s, "0x%02X\n", debug_address); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static int ab8500_address_open(struct inode *inode, struct file *file) |
| 475 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 476 | return single_open(file, ab8500_address_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | static ssize_t ab8500_address_write(struct file *file, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 480 | const char __user *user_buf, |
| 481 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 482 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 483 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 484 | unsigned long user_address; |
| 485 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 486 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 487 | /* Get userspace string and assure termination */ |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 488 | err = kstrtoul_from_user(user_buf, count, 0, &user_address); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 489 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 490 | return err; |
| 491 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 492 | if (user_address > 0xff) { |
| 493 | dev_err(dev, "debugfs error input > 0xff\n"); |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | debug_address = user_address; |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 497 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | static int ab8500_val_print(struct seq_file *s, void *p) |
| 501 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 502 | struct device *dev = s->private; |
| 503 | int ret; |
| 504 | u8 regvalue; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 505 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 506 | ret = abx500_get_register_interruptible(dev, |
| 507 | (u8)debug_bank, (u8)debug_address, ®value); |
| 508 | if (ret < 0) { |
| 509 | dev_err(dev, "abx500_get_reg fail %d, %d\n", |
| 510 | ret, __LINE__); |
| 511 | return -EINVAL; |
| 512 | } |
| 513 | seq_printf(s, "0x%02X\n", regvalue); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 514 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 515 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static int ab8500_val_open(struct inode *inode, struct file *file) |
| 519 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 520 | return single_open(file, ab8500_val_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static ssize_t ab8500_val_write(struct file *file, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 524 | const char __user *user_buf, |
| 525 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 526 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 527 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 528 | unsigned long user_val; |
| 529 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 530 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 531 | /* Get userspace string and assure termination */ |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 532 | err = kstrtoul_from_user(user_buf, count, 0, &user_val); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 533 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 534 | return err; |
| 535 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 536 | if (user_val > 0xff) { |
| 537 | dev_err(dev, "debugfs error input > 0xff\n"); |
| 538 | return -EINVAL; |
| 539 | } |
| 540 | err = abx500_set_register_interruptible(dev, |
| 541 | (u8)debug_bank, debug_address, (u8)user_val); |
| 542 | if (err < 0) { |
| 543 | printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__); |
| 544 | return -EINVAL; |
| 545 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 546 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 547 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 548 | } |
| 549 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 550 | static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p) |
| 551 | { |
| 552 | seq_printf(s, "%d\n", irq_first); |
| 553 | |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | static int ab8500_subscribe_unsubscribe_open(struct inode *inode, |
| 558 | struct file *file) |
| 559 | { |
| 560 | return single_open(file, ab8500_subscribe_unsubscribe_print, |
| 561 | inode->i_private); |
| 562 | } |
| 563 | |
| 564 | /* |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 565 | * Userspace should use poll() on this file. When an event occur |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 566 | * the blocking poll will be released. |
| 567 | */ |
| 568 | static ssize_t show_irq(struct device *dev, |
| 569 | struct device_attribute *attr, char *buf) |
| 570 | { |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 571 | unsigned long name; |
| 572 | unsigned int irq_index; |
| 573 | int err; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 574 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 575 | err = strict_strtoul(attr->attr.name, 0, &name); |
| 576 | if (err) |
| 577 | return err; |
| 578 | |
| 579 | irq_index = name - irq_first; |
| 580 | if (irq_index >= AB8500_NR_IRQS) |
| 581 | return -EINVAL; |
| 582 | else |
| 583 | return sprintf(buf, "%u\n", irq_count[irq_index]); |
| 584 | } |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 585 | |
| 586 | static ssize_t ab8500_subscribe_write(struct file *file, |
| 587 | const char __user *user_buf, |
| 588 | size_t count, loff_t *ppos) |
| 589 | { |
| 590 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
| 591 | char buf[32]; |
| 592 | int buf_size; |
| 593 | unsigned long user_val; |
| 594 | int err; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 595 | unsigned int irq_index; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 596 | |
| 597 | /* Get userspace string and assure termination */ |
| 598 | buf_size = min(count, (sizeof(buf)-1)); |
| 599 | if (copy_from_user(buf, user_buf, buf_size)) |
| 600 | return -EFAULT; |
| 601 | buf[buf_size] = 0; |
| 602 | |
| 603 | err = strict_strtoul(buf, 0, &user_val); |
| 604 | if (err) |
| 605 | return -EINVAL; |
| 606 | if (user_val < irq_first) { |
| 607 | dev_err(dev, "debugfs error input < %d\n", irq_first); |
| 608 | return -EINVAL; |
| 609 | } |
| 610 | if (user_val > irq_last) { |
| 611 | dev_err(dev, "debugfs error input > %d\n", irq_last); |
| 612 | return -EINVAL; |
| 613 | } |
| 614 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 615 | irq_index = user_val - irq_first; |
| 616 | if (irq_index >= AB8500_NR_IRQS) |
| 617 | return -EINVAL; |
| 618 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 619 | /* |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 620 | * This will create a sysfs file named <irq-nr> which userspace can |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 621 | * use to select or poll and get the AB8500 events |
| 622 | */ |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 623 | dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute), |
| 624 | GFP_KERNEL); |
| 625 | event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL); |
| 626 | sprintf(event_name[irq_index], "%lu", user_val); |
| 627 | dev_attr[irq_index]->show = show_irq; |
| 628 | dev_attr[irq_index]->store = NULL; |
| 629 | dev_attr[irq_index]->attr.name = event_name[irq_index]; |
| 630 | dev_attr[irq_index]->attr.mode = S_IRUGO; |
| 631 | err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 632 | if (err < 0) { |
| 633 | printk(KERN_ERR "sysfs_create_file failed %d\n", err); |
| 634 | return err; |
| 635 | } |
| 636 | |
| 637 | err = request_threaded_irq(user_val, NULL, ab8500_debug_handler, |
| 638 | IRQF_SHARED | IRQF_NO_SUSPEND, |
| 639 | "ab8500-debug", &dev->kobj); |
| 640 | if (err < 0) { |
| 641 | printk(KERN_ERR "request_threaded_irq failed %d, %lu\n", |
| 642 | err, user_val); |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 643 | sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 644 | return err; |
| 645 | } |
| 646 | |
| 647 | return buf_size; |
| 648 | } |
| 649 | |
| 650 | static ssize_t ab8500_unsubscribe_write(struct file *file, |
| 651 | const char __user *user_buf, |
| 652 | size_t count, loff_t *ppos) |
| 653 | { |
| 654 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
| 655 | char buf[32]; |
| 656 | int buf_size; |
| 657 | unsigned long user_val; |
| 658 | int err; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 659 | unsigned int irq_index; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 660 | |
| 661 | /* Get userspace string and assure termination */ |
| 662 | buf_size = min(count, (sizeof(buf)-1)); |
| 663 | if (copy_from_user(buf, user_buf, buf_size)) |
| 664 | return -EFAULT; |
| 665 | buf[buf_size] = 0; |
| 666 | |
| 667 | err = strict_strtoul(buf, 0, &user_val); |
| 668 | if (err) |
| 669 | return -EINVAL; |
| 670 | if (user_val < irq_first) { |
| 671 | dev_err(dev, "debugfs error input < %d\n", irq_first); |
| 672 | return -EINVAL; |
| 673 | } |
| 674 | if (user_val > irq_last) { |
| 675 | dev_err(dev, "debugfs error input > %d\n", irq_last); |
| 676 | return -EINVAL; |
| 677 | } |
| 678 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 679 | irq_index = user_val - irq_first; |
| 680 | if (irq_index >= AB8500_NR_IRQS) |
| 681 | return -EINVAL; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 682 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame^] | 683 | /* Set irq count to 0 when unsubscribe */ |
| 684 | irq_count[irq_index] = 0; |
| 685 | |
| 686 | if (dev_attr[irq_index]) |
| 687 | sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); |
| 688 | |
| 689 | |
| 690 | free_irq(user_val, &dev->kobj); |
| 691 | kfree(event_name[irq_index]); |
| 692 | kfree(dev_attr[irq_index]); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 693 | |
| 694 | return buf_size; |
| 695 | } |
| 696 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 697 | static const struct file_operations ab8500_bank_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 698 | .open = ab8500_bank_open, |
| 699 | .write = ab8500_bank_write, |
| 700 | .read = seq_read, |
| 701 | .llseek = seq_lseek, |
| 702 | .release = single_release, |
| 703 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 704 | }; |
| 705 | |
| 706 | static const struct file_operations ab8500_address_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 707 | .open = ab8500_address_open, |
| 708 | .write = ab8500_address_write, |
| 709 | .read = seq_read, |
| 710 | .llseek = seq_lseek, |
| 711 | .release = single_release, |
| 712 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 713 | }; |
| 714 | |
| 715 | static const struct file_operations ab8500_val_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 716 | .open = ab8500_val_open, |
| 717 | .write = ab8500_val_write, |
| 718 | .read = seq_read, |
| 719 | .llseek = seq_lseek, |
| 720 | .release = single_release, |
| 721 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 722 | }; |
| 723 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 724 | static const struct file_operations ab8500_subscribe_fops = { |
| 725 | .open = ab8500_subscribe_unsubscribe_open, |
| 726 | .write = ab8500_subscribe_write, |
| 727 | .read = seq_read, |
| 728 | .llseek = seq_lseek, |
| 729 | .release = single_release, |
| 730 | .owner = THIS_MODULE, |
| 731 | }; |
| 732 | |
| 733 | static const struct file_operations ab8500_unsubscribe_fops = { |
| 734 | .open = ab8500_subscribe_unsubscribe_open, |
| 735 | .write = ab8500_unsubscribe_write, |
| 736 | .read = seq_read, |
| 737 | .llseek = seq_lseek, |
| 738 | .release = single_release, |
| 739 | .owner = THIS_MODULE, |
| 740 | }; |
| 741 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 742 | static struct dentry *ab8500_dir; |
| 743 | static struct dentry *ab8500_reg_file; |
| 744 | static struct dentry *ab8500_bank_file; |
| 745 | static struct dentry *ab8500_address_file; |
| 746 | static struct dentry *ab8500_val_file; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 747 | static struct dentry *ab8500_subscribe_file; |
| 748 | static struct dentry *ab8500_unsubscribe_file; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 749 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 750 | static int ab8500_debug_probe(struct platform_device *plf) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 751 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 752 | debug_bank = AB8500_MISC; |
| 753 | debug_address = AB8500_REV_REG & 0x00FF; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 754 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 755 | irq_first = platform_get_irq_byname(plf, "IRQ_FIRST"); |
| 756 | if (irq_first < 0) { |
| 757 | dev_err(&plf->dev, "First irq not found, err %d\n", |
| 758 | irq_first); |
| 759 | return irq_first; |
| 760 | } |
| 761 | |
| 762 | irq_last = platform_get_irq_byname(plf, "IRQ_LAST"); |
| 763 | if (irq_last < 0) { |
| 764 | dev_err(&plf->dev, "Last irq not found, err %d\n", |
| 765 | irq_last); |
| 766 | return irq_last; |
| 767 | } |
| 768 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 769 | ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); |
| 770 | if (!ab8500_dir) |
| 771 | goto exit_no_debugfs; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 772 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 773 | ab8500_reg_file = debugfs_create_file("all-bank-registers", |
| 774 | S_IRUGO, ab8500_dir, &plf->dev, &ab8500_registers_fops); |
| 775 | if (!ab8500_reg_file) |
| 776 | goto exit_destroy_dir; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 777 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 778 | ab8500_bank_file = debugfs_create_file("register-bank", |
Vasiliy Kulikov | 44bdcb5 | 2011-02-04 15:23:43 +0300 | [diff] [blame] | 779 | (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_bank_fops); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 780 | if (!ab8500_bank_file) |
| 781 | goto exit_destroy_reg; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 782 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 783 | ab8500_address_file = debugfs_create_file("register-address", |
Vasiliy Kulikov | 44bdcb5 | 2011-02-04 15:23:43 +0300 | [diff] [blame] | 784 | (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 785 | &ab8500_address_fops); |
| 786 | if (!ab8500_address_file) |
| 787 | goto exit_destroy_bank; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 788 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 789 | ab8500_val_file = debugfs_create_file("register-value", |
Vasiliy Kulikov | 44bdcb5 | 2011-02-04 15:23:43 +0300 | [diff] [blame] | 790 | (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_val_fops); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 791 | if (!ab8500_val_file) |
| 792 | goto exit_destroy_address; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 793 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 794 | ab8500_subscribe_file = |
| 795 | debugfs_create_file("irq-subscribe", |
| 796 | (S_IRUGO | S_IWUGO), ab8500_dir, &plf->dev, |
| 797 | &ab8500_subscribe_fops); |
| 798 | if (!ab8500_subscribe_file) |
| 799 | goto exit_destroy_val; |
| 800 | |
| 801 | ab8500_unsubscribe_file = |
| 802 | debugfs_create_file("irq-unsubscribe", |
| 803 | (S_IRUGO | S_IWUGO), ab8500_dir, &plf->dev, |
| 804 | &ab8500_unsubscribe_fops); |
| 805 | if (!ab8500_unsubscribe_file) |
| 806 | goto exit_destroy_subscribe; |
| 807 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 808 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 809 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 810 | exit_destroy_subscribe: |
| 811 | debugfs_remove(ab8500_subscribe_file); |
| 812 | exit_destroy_val: |
| 813 | debugfs_remove(ab8500_val_file); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 814 | exit_destroy_address: |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 815 | debugfs_remove(ab8500_address_file); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 816 | exit_destroy_bank: |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 817 | debugfs_remove(ab8500_bank_file); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 818 | exit_destroy_reg: |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 819 | debugfs_remove(ab8500_reg_file); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 820 | exit_destroy_dir: |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 821 | debugfs_remove(ab8500_dir); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 822 | exit_no_debugfs: |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 823 | dev_err(&plf->dev, "failed to create debugfs entries.\n"); |
| 824 | return -ENOMEM; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 825 | } |
| 826 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 827 | static int ab8500_debug_remove(struct platform_device *plf) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 828 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 829 | debugfs_remove(ab8500_val_file); |
| 830 | debugfs_remove(ab8500_address_file); |
| 831 | debugfs_remove(ab8500_bank_file); |
| 832 | debugfs_remove(ab8500_reg_file); |
| 833 | debugfs_remove(ab8500_dir); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 834 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 835 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | static struct platform_driver ab8500_debug_driver = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 839 | .driver = { |
| 840 | .name = "ab8500-debug", |
| 841 | .owner = THIS_MODULE, |
| 842 | }, |
| 843 | .probe = ab8500_debug_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 844 | .remove = ab8500_debug_remove |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 845 | }; |
| 846 | |
| 847 | static int __init ab8500_debug_init(void) |
| 848 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 849 | return platform_driver_register(&ab8500_debug_driver); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | static void __exit ab8500_debug_exit(void) |
| 853 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 854 | platform_driver_unregister(&ab8500_debug_driver); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 855 | } |
| 856 | subsys_initcall(ab8500_debug_init); |
| 857 | module_exit(ab8500_debug_exit); |
| 858 | |
| 859 | MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com"); |
| 860 | MODULE_DESCRIPTION("AB8500 DEBUG"); |
| 861 | MODULE_LICENSE("GPL v2"); |