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 | */ |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 7 | /* |
| 8 | * AB8500 register access |
| 9 | * ====================== |
| 10 | * |
| 11 | * read: |
| 12 | * # echo BANK > <debugfs>/ab8500/register-bank |
| 13 | * # echo ADDR > <debugfs>/ab8500/register-address |
| 14 | * # cat <debugfs>/ab8500/register-value |
| 15 | * |
| 16 | * write: |
| 17 | * # echo BANK > <debugfs>/ab8500/register-bank |
| 18 | * # echo ADDR > <debugfs>/ab8500/register-address |
| 19 | * # echo VALUE > <debugfs>/ab8500/register-value |
| 20 | * |
| 21 | * read all registers from a bank: |
| 22 | * # echo BANK > <debugfs>/ab8500/register-bank |
| 23 | * # cat <debugfs>/ab8500/all-bank-register |
| 24 | * |
| 25 | * BANK target AB8500 register bank |
| 26 | * ADDR target AB8500 register address |
| 27 | * VALUE decimal or 0x-prefixed hexadecimal |
| 28 | * |
| 29 | * |
| 30 | * User Space notification on AB8500 IRQ |
| 31 | * ===================================== |
| 32 | * |
| 33 | * Allows user space entity to be notified when target AB8500 IRQ occurs. |
| 34 | * When subscribed, a sysfs entry is created in ab8500.i2c platform device. |
| 35 | * One can pool this file to get target IRQ occurence information. |
| 36 | * |
| 37 | * subscribe to an AB8500 IRQ: |
| 38 | * # echo IRQ > <debugfs>/ab8500/irq-subscribe |
| 39 | * |
| 40 | * unsubscribe from an AB8500 IRQ: |
| 41 | * # echo IRQ > <debugfs>/ab8500/irq-unsubscribe |
| 42 | * |
| 43 | * |
| 44 | * AB8500 register formated read/write access |
| 45 | * ========================================== |
| 46 | * |
| 47 | * Read: read data, data>>SHIFT, data&=MASK, output data |
| 48 | * [0xABCDEF98] shift=12 mask=0xFFF => 0x00000CDE |
| 49 | * Write: read data, data &= ~(MASK<<SHIFT), data |= (VALUE<<SHIFT), write data |
| 50 | * [0xABCDEF98] shift=12 mask=0xFFF value=0x123 => [0xAB123F98] |
| 51 | * |
| 52 | * Usage: |
| 53 | * # echo "CMD [OPTIONS] BANK ADRESS [VALUE]" > $debugfs/ab8500/hwreg |
| 54 | * |
| 55 | * CMD read read access |
| 56 | * write write access |
| 57 | * |
| 58 | * BANK target reg bank |
| 59 | * ADDRESS target reg address |
| 60 | * VALUE (write) value to be updated |
| 61 | * |
| 62 | * OPTIONS |
| 63 | * -d|-dec (read) output in decimal |
| 64 | * -h|-hexa (read) output in 0x-hexa (default) |
| 65 | * -l|-w|-b 32bit (default), 16bit or 8bit reg access |
| 66 | * -m|-mask MASK 0x-hexa mask (default 0xFFFFFFFF) |
| 67 | * -s|-shift SHIFT bit shift value (read:left, write:right) |
| 68 | * -o|-offset OFFSET address offset to add to ADDRESS value |
| 69 | * |
| 70 | * Warning: bit shift operation is applied to bit-mask. |
| 71 | * Warning: bit shift direction depends on read or right command. |
| 72 | */ |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 73 | |
| 74 | #include <linux/seq_file.h> |
| 75 | #include <linux/uaccess.h> |
| 76 | #include <linux/fs.h> |
Paul Gortmaker | 4e36dd3 | 2011-07-03 15:13:27 -0400 | [diff] [blame] | 77 | #include <linux/module.h> |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 78 | #include <linux/debugfs.h> |
| 79 | #include <linux/platform_device.h> |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 80 | #include <linux/interrupt.h> |
| 81 | #include <linux/kobject.h> |
| 82 | #include <linux/slab.h> |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 83 | #include <linux/irq.h> |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 84 | |
| 85 | #include <linux/mfd/abx500.h> |
Linus Walleij | 0cd5b6d0 | 2013-02-06 23:23:01 +0100 | [diff] [blame] | 86 | #include <linux/mfd/abx500/ab8500.h> |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 87 | #include <linux/mfd/abx500/ab8500-gpadc.h> |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 88 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 89 | #ifdef CONFIG_DEBUG_FS |
| 90 | #include <linux/string.h> |
| 91 | #include <linux/ctype.h> |
| 92 | #endif |
| 93 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 94 | static u32 debug_bank; |
| 95 | static u32 debug_address; |
| 96 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 97 | static int irq_first; |
| 98 | static int irq_last; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 99 | static u32 *irq_count; |
| 100 | static int num_irqs; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 101 | |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 102 | static struct device_attribute **dev_attr; |
| 103 | static char **event_name; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 104 | |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 105 | static u8 avg_sample = SAMPLE_16; |
| 106 | static u8 trig_edge = RISING_EDGE; |
| 107 | static u8 conv_type = ADC_SW; |
| 108 | static u8 trig_timer; |
| 109 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 110 | /** |
| 111 | * struct ab8500_reg_range |
| 112 | * @first: the first address of the range |
| 113 | * @last: the last address of the range |
| 114 | * @perm: access permissions for the range |
| 115 | */ |
| 116 | struct ab8500_reg_range { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 117 | u8 first; |
| 118 | u8 last; |
| 119 | u8 perm; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | /** |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 123 | * struct ab8500_prcmu_ranges |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 124 | * @num_ranges: the number of ranges in the list |
| 125 | * @bankid: bank identifier |
| 126 | * @range: the list of register ranges |
| 127 | */ |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 128 | struct ab8500_prcmu_ranges { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 129 | u8 num_ranges; |
| 130 | u8 bankid; |
| 131 | const struct ab8500_reg_range *range; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 132 | }; |
| 133 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 134 | /* hwreg- "mask" and "shift" entries ressources */ |
| 135 | struct hwreg_cfg { |
| 136 | u32 bank; /* target bank */ |
| 137 | u32 addr; /* target address */ |
| 138 | uint fmt; /* format */ |
| 139 | uint mask; /* read/write mask, applied before any bit shift */ |
| 140 | int shift; /* bit shift (read:right shift, write:left shift */ |
| 141 | }; |
| 142 | /* fmt bit #0: 0=hexa, 1=dec */ |
| 143 | #define REG_FMT_DEC(c) ((c)->fmt & 0x1) |
| 144 | #define REG_FMT_HEX(c) (!REG_FMT_DEC(c)) |
| 145 | |
| 146 | static struct hwreg_cfg hwreg_cfg = { |
| 147 | .addr = 0, /* default: invalid phys addr */ |
| 148 | .fmt = 0, /* default: 32bit access, hex output */ |
| 149 | .mask = 0xFFFFFFFF, /* default: no mask */ |
| 150 | .shift = 0, /* default: no bit shift */ |
| 151 | }; |
| 152 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 153 | #define AB8500_NAME_STRING "ab8500" |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 154 | #define AB8500_ADC_NAME_STRING "gpadc" |
Philippe Langlais | 40c064e | 2011-10-17 09:48:55 +0200 | [diff] [blame] | 155 | #define AB8500_NUM_BANKS 24 |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 156 | |
| 157 | #define AB8500_REV_REG 0x80 |
| 158 | |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 159 | static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 160 | [0x0] = { |
| 161 | .num_ranges = 0, |
Lee Jones | fad55a8 | 2013-01-14 17:17:34 +0000 | [diff] [blame] | 162 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 163 | }, |
| 164 | [AB8500_SYS_CTRL1_BLOCK] = { |
| 165 | .num_ranges = 3, |
| 166 | .range = (struct ab8500_reg_range[]) { |
| 167 | { |
| 168 | .first = 0x00, |
| 169 | .last = 0x02, |
| 170 | }, |
| 171 | { |
| 172 | .first = 0x42, |
| 173 | .last = 0x42, |
| 174 | }, |
| 175 | { |
| 176 | .first = 0x80, |
| 177 | .last = 0x81, |
| 178 | }, |
| 179 | }, |
| 180 | }, |
| 181 | [AB8500_SYS_CTRL2_BLOCK] = { |
| 182 | .num_ranges = 4, |
| 183 | .range = (struct ab8500_reg_range[]) { |
| 184 | { |
| 185 | .first = 0x00, |
| 186 | .last = 0x0D, |
| 187 | }, |
| 188 | { |
| 189 | .first = 0x0F, |
| 190 | .last = 0x17, |
| 191 | }, |
| 192 | { |
| 193 | .first = 0x30, |
| 194 | .last = 0x30, |
| 195 | }, |
| 196 | { |
| 197 | .first = 0x32, |
| 198 | .last = 0x33, |
| 199 | }, |
| 200 | }, |
| 201 | }, |
| 202 | [AB8500_REGU_CTRL1] = { |
| 203 | .num_ranges = 3, |
| 204 | .range = (struct ab8500_reg_range[]) { |
| 205 | { |
| 206 | .first = 0x00, |
| 207 | .last = 0x00, |
| 208 | }, |
| 209 | { |
| 210 | .first = 0x03, |
| 211 | .last = 0x10, |
| 212 | }, |
| 213 | { |
| 214 | .first = 0x80, |
| 215 | .last = 0x84, |
| 216 | }, |
| 217 | }, |
| 218 | }, |
| 219 | [AB8500_REGU_CTRL2] = { |
| 220 | .num_ranges = 5, |
| 221 | .range = (struct ab8500_reg_range[]) { |
| 222 | { |
| 223 | .first = 0x00, |
| 224 | .last = 0x15, |
| 225 | }, |
| 226 | { |
| 227 | .first = 0x17, |
| 228 | .last = 0x19, |
| 229 | }, |
| 230 | { |
| 231 | .first = 0x1B, |
| 232 | .last = 0x1D, |
| 233 | }, |
| 234 | { |
| 235 | .first = 0x1F, |
| 236 | .last = 0x22, |
| 237 | }, |
| 238 | { |
| 239 | .first = 0x40, |
| 240 | .last = 0x44, |
| 241 | }, |
| 242 | /* 0x80-0x8B is SIM registers and should |
| 243 | * not be accessed from here */ |
| 244 | }, |
| 245 | }, |
| 246 | [AB8500_USB] = { |
| 247 | .num_ranges = 2, |
| 248 | .range = (struct ab8500_reg_range[]) { |
| 249 | { |
| 250 | .first = 0x80, |
| 251 | .last = 0x83, |
| 252 | }, |
| 253 | { |
| 254 | .first = 0x87, |
| 255 | .last = 0x8A, |
| 256 | }, |
| 257 | }, |
| 258 | }, |
| 259 | [AB8500_TVOUT] = { |
| 260 | .num_ranges = 9, |
| 261 | .range = (struct ab8500_reg_range[]) { |
| 262 | { |
| 263 | .first = 0x00, |
| 264 | .last = 0x12, |
| 265 | }, |
| 266 | { |
| 267 | .first = 0x15, |
| 268 | .last = 0x17, |
| 269 | }, |
| 270 | { |
| 271 | .first = 0x19, |
| 272 | .last = 0x21, |
| 273 | }, |
| 274 | { |
| 275 | .first = 0x27, |
| 276 | .last = 0x2C, |
| 277 | }, |
| 278 | { |
| 279 | .first = 0x41, |
| 280 | .last = 0x41, |
| 281 | }, |
| 282 | { |
| 283 | .first = 0x45, |
| 284 | .last = 0x5B, |
| 285 | }, |
| 286 | { |
| 287 | .first = 0x5D, |
| 288 | .last = 0x5D, |
| 289 | }, |
| 290 | { |
| 291 | .first = 0x69, |
| 292 | .last = 0x69, |
| 293 | }, |
| 294 | { |
| 295 | .first = 0x80, |
| 296 | .last = 0x81, |
| 297 | }, |
| 298 | }, |
| 299 | }, |
| 300 | [AB8500_DBI] = { |
| 301 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 302 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 303 | }, |
| 304 | [AB8500_ECI_AV_ACC] = { |
| 305 | .num_ranges = 1, |
| 306 | .range = (struct ab8500_reg_range[]) { |
| 307 | { |
| 308 | .first = 0x80, |
| 309 | .last = 0x82, |
| 310 | }, |
| 311 | }, |
| 312 | }, |
| 313 | [0x9] = { |
| 314 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 315 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 316 | }, |
| 317 | [AB8500_GPADC] = { |
| 318 | .num_ranges = 1, |
| 319 | .range = (struct ab8500_reg_range[]) { |
| 320 | { |
| 321 | .first = 0x00, |
| 322 | .last = 0x08, |
| 323 | }, |
| 324 | }, |
| 325 | }, |
| 326 | [AB8500_CHARGER] = { |
Philippe Langlais | 40c064e | 2011-10-17 09:48:55 +0200 | [diff] [blame] | 327 | .num_ranges = 9, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 328 | .range = (struct ab8500_reg_range[]) { |
| 329 | { |
| 330 | .first = 0x00, |
| 331 | .last = 0x03, |
| 332 | }, |
| 333 | { |
| 334 | .first = 0x05, |
| 335 | .last = 0x05, |
| 336 | }, |
| 337 | { |
| 338 | .first = 0x40, |
| 339 | .last = 0x40, |
| 340 | }, |
| 341 | { |
| 342 | .first = 0x42, |
| 343 | .last = 0x42, |
| 344 | }, |
| 345 | { |
| 346 | .first = 0x44, |
| 347 | .last = 0x44, |
| 348 | }, |
| 349 | { |
| 350 | .first = 0x50, |
| 351 | .last = 0x55, |
| 352 | }, |
| 353 | { |
| 354 | .first = 0x80, |
| 355 | .last = 0x82, |
| 356 | }, |
| 357 | { |
| 358 | .first = 0xC0, |
| 359 | .last = 0xC2, |
| 360 | }, |
Philippe Langlais | 40c064e | 2011-10-17 09:48:55 +0200 | [diff] [blame] | 361 | { |
| 362 | .first = 0xf5, |
| 363 | .last = 0xf6, |
| 364 | }, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 365 | }, |
| 366 | }, |
| 367 | [AB8500_GAS_GAUGE] = { |
| 368 | .num_ranges = 3, |
| 369 | .range = (struct ab8500_reg_range[]) { |
| 370 | { |
| 371 | .first = 0x00, |
| 372 | .last = 0x00, |
| 373 | }, |
| 374 | { |
| 375 | .first = 0x07, |
| 376 | .last = 0x0A, |
| 377 | }, |
| 378 | { |
| 379 | .first = 0x10, |
| 380 | .last = 0x14, |
| 381 | }, |
| 382 | }, |
| 383 | }, |
Philippe Langlais | 40c064e | 2011-10-17 09:48:55 +0200 | [diff] [blame] | 384 | [AB8500_DEVELOPMENT] = { |
| 385 | .num_ranges = 1, |
| 386 | .range = (struct ab8500_reg_range[]) { |
| 387 | { |
| 388 | .first = 0x00, |
| 389 | .last = 0x00, |
| 390 | }, |
| 391 | }, |
| 392 | }, |
| 393 | [AB8500_DEBUG] = { |
| 394 | .num_ranges = 1, |
| 395 | .range = (struct ab8500_reg_range[]) { |
| 396 | { |
| 397 | .first = 0x05, |
| 398 | .last = 0x07, |
| 399 | }, |
| 400 | }, |
| 401 | }, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 402 | [AB8500_AUDIO] = { |
| 403 | .num_ranges = 1, |
| 404 | .range = (struct ab8500_reg_range[]) { |
| 405 | { |
| 406 | .first = 0x00, |
| 407 | .last = 0x6F, |
| 408 | }, |
| 409 | }, |
| 410 | }, |
| 411 | [AB8500_INTERRUPT] = { |
| 412 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 413 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 414 | }, |
| 415 | [AB8500_RTC] = { |
| 416 | .num_ranges = 1, |
| 417 | .range = (struct ab8500_reg_range[]) { |
| 418 | { |
| 419 | .first = 0x00, |
| 420 | .last = 0x0F, |
| 421 | }, |
| 422 | }, |
| 423 | }, |
| 424 | [AB8500_MISC] = { |
| 425 | .num_ranges = 8, |
| 426 | .range = (struct ab8500_reg_range[]) { |
| 427 | { |
| 428 | .first = 0x00, |
| 429 | .last = 0x05, |
| 430 | }, |
| 431 | { |
| 432 | .first = 0x10, |
| 433 | .last = 0x15, |
| 434 | }, |
| 435 | { |
| 436 | .first = 0x20, |
| 437 | .last = 0x25, |
| 438 | }, |
| 439 | { |
| 440 | .first = 0x30, |
| 441 | .last = 0x35, |
| 442 | }, |
| 443 | { |
| 444 | .first = 0x40, |
| 445 | .last = 0x45, |
| 446 | }, |
| 447 | { |
| 448 | .first = 0x50, |
| 449 | .last = 0x50, |
| 450 | }, |
| 451 | { |
| 452 | .first = 0x60, |
| 453 | .last = 0x67, |
| 454 | }, |
| 455 | { |
| 456 | .first = 0x80, |
| 457 | .last = 0x80, |
| 458 | }, |
| 459 | }, |
| 460 | }, |
| 461 | [0x11] = { |
| 462 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 463 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 464 | }, |
| 465 | [0x12] = { |
| 466 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 467 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 468 | }, |
| 469 | [0x13] = { |
| 470 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 471 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 472 | }, |
| 473 | [0x14] = { |
| 474 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 475 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 476 | }, |
| 477 | [AB8500_OTP_EMUL] = { |
| 478 | .num_ranges = 1, |
| 479 | .range = (struct ab8500_reg_range[]) { |
| 480 | { |
| 481 | .first = 0x01, |
| 482 | .last = 0x0F, |
| 483 | }, |
| 484 | }, |
| 485 | }, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 486 | }; |
| 487 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 488 | static irqreturn_t ab8500_debug_handler(int irq, void *data) |
| 489 | { |
| 490 | char buf[16]; |
| 491 | struct kobject *kobj = (struct kobject *)data; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 492 | unsigned int irq_abb = irq - irq_first; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 493 | |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 494 | if (irq_abb < num_irqs) |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 495 | irq_count[irq_abb]++; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 496 | /* |
| 497 | * This makes it possible to use poll for events (POLLPRI | POLLERR) |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 498 | * from userspace on sysfs file named <irq-nr> |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 499 | */ |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 500 | sprintf(buf, "%d", irq); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 501 | sysfs_notify(kobj, NULL, buf); |
| 502 | |
| 503 | return IRQ_HANDLED; |
| 504 | } |
| 505 | |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 506 | /* Prints to seq_file or log_buf */ |
| 507 | static int ab8500_registers_print(struct device *dev, u32 bank, |
| 508 | struct seq_file *s) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 509 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 510 | unsigned int i; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 511 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 512 | for (i = 0; i < debug_ranges[bank].num_ranges; i++) { |
| 513 | u32 reg; |
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 | for (reg = debug_ranges[bank].range[i].first; |
| 516 | reg <= debug_ranges[bank].range[i].last; |
| 517 | reg++) { |
| 518 | u8 value; |
| 519 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 520 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 521 | err = abx500_get_register_interruptible(dev, |
| 522 | (u8)bank, (u8)reg, &value); |
| 523 | if (err < 0) { |
| 524 | dev_err(dev, "ab->read fail %d\n", err); |
| 525 | return err; |
| 526 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 527 | |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 528 | if (s) { |
Mattias Wallin | cfc0849 | 2012-05-28 15:53:58 +0200 | [diff] [blame] | 529 | err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 530 | bank, reg, value); |
| 531 | if (err < 0) { |
| 532 | dev_err(dev, |
Mattias Wallin | cfc0849 | 2012-05-28 15:53:58 +0200 | [diff] [blame] | 533 | "seq_printf overflow bank=0x%02X reg=0x%02X\n", |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 534 | bank, reg); |
| 535 | /* Error is not returned here since |
| 536 | * the output is wanted in any case */ |
| 537 | return 0; |
| 538 | } |
| 539 | } else { |
Mattias Wallin | cfc0849 | 2012-05-28 15:53:58 +0200 | [diff] [blame] | 540 | printk(KERN_INFO" [0x%02X/0x%02X]: 0x%02X\n", |
| 541 | bank, reg, value); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | } |
| 545 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 546 | } |
| 547 | |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 548 | static int ab8500_print_bank_registers(struct seq_file *s, void *p) |
| 549 | { |
| 550 | struct device *dev = s->private; |
| 551 | u32 bank = debug_bank; |
| 552 | |
| 553 | seq_printf(s, AB8500_NAME_STRING " register values:\n"); |
| 554 | |
Mattias Wallin | cfc0849 | 2012-05-28 15:53:58 +0200 | [diff] [blame] | 555 | seq_printf(s, " bank 0x%02X:\n", bank); |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 556 | |
| 557 | ab8500_registers_print(dev, bank, s); |
| 558 | return 0; |
| 559 | } |
| 560 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 561 | static int ab8500_registers_open(struct inode *inode, struct file *file) |
| 562 | { |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 563 | return single_open(file, ab8500_print_bank_registers, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | static const struct file_operations ab8500_registers_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 567 | .open = ab8500_registers_open, |
| 568 | .read = seq_read, |
| 569 | .llseek = seq_lseek, |
| 570 | .release = single_release, |
| 571 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 572 | }; |
| 573 | |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 574 | static int ab8500_print_all_banks(struct seq_file *s, void *p) |
| 575 | { |
| 576 | struct device *dev = s->private; |
| 577 | unsigned int i; |
| 578 | int err; |
| 579 | |
| 580 | seq_printf(s, AB8500_NAME_STRING " register values:\n"); |
| 581 | |
| 582 | for (i = 1; i < AB8500_NUM_BANKS; i++) { |
Mattias Wallin | cfc0849 | 2012-05-28 15:53:58 +0200 | [diff] [blame] | 583 | err = seq_printf(s, " bank 0x%02X:\n", i); |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 584 | if (err < 0) |
Mattias Wallin | cfc0849 | 2012-05-28 15:53:58 +0200 | [diff] [blame] | 585 | dev_err(dev, "seq_printf overflow, bank=0x%02X\n", i); |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 586 | |
| 587 | ab8500_registers_print(dev, i, s); |
| 588 | } |
| 589 | return 0; |
| 590 | } |
| 591 | |
Mian Yousaf Kaukab | 1d843a6 | 2012-01-27 11:35:41 +0100 | [diff] [blame] | 592 | /* Dump registers to kernel log */ |
| 593 | void ab8500_dump_all_banks(struct device *dev) |
| 594 | { |
| 595 | unsigned int i; |
| 596 | |
| 597 | printk(KERN_INFO"ab8500 register values:\n"); |
| 598 | |
| 599 | for (i = 1; i < AB8500_NUM_BANKS; i++) { |
Mattias Wallin | cfc0849 | 2012-05-28 15:53:58 +0200 | [diff] [blame] | 600 | printk(KERN_INFO" bank 0x%02X:\n", i); |
Mian Yousaf Kaukab | 1d843a6 | 2012-01-27 11:35:41 +0100 | [diff] [blame] | 601 | ab8500_registers_print(dev, i, NULL); |
| 602 | } |
| 603 | } |
| 604 | |
Lee Jones | 5ff9090 | 2013-02-12 14:35:28 +0000 | [diff] [blame] | 605 | /* Space for 500 registers. */ |
| 606 | #define DUMP_MAX_REGS 700 |
| 607 | struct ab8500_register_dump |
| 608 | { |
| 609 | u8 bank; |
| 610 | u8 reg; |
| 611 | u8 value; |
Lee Jones | 5ff9090 | 2013-02-12 14:35:28 +0000 | [diff] [blame] | 612 | } ab8500_complete_register_dump[DUMP_MAX_REGS]; |
| 613 | |
| 614 | extern int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size); |
| 615 | |
| 616 | /* This shall only be called upon kernel panic! */ |
| 617 | void ab8500_dump_all_banks_to_mem(void) |
| 618 | { |
| 619 | int i, r = 0; |
| 620 | u8 bank; |
Jonas Aaberg | 222460c | 2012-06-18 10:35:28 +0200 | [diff] [blame] | 621 | int err = 0; |
Lee Jones | 5ff9090 | 2013-02-12 14:35:28 +0000 | [diff] [blame] | 622 | |
| 623 | pr_info("Saving all ABB registers at \"ab8500_complete_register_dump\" " |
| 624 | "for crash analyze.\n"); |
| 625 | |
| 626 | for (bank = 1; bank < AB8500_NUM_BANKS; bank++) { |
| 627 | for (i = 0; i < debug_ranges[bank].num_ranges; i++) { |
| 628 | u8 reg; |
| 629 | |
| 630 | for (reg = debug_ranges[bank].range[i].first; |
| 631 | reg <= debug_ranges[bank].range[i].last; |
| 632 | reg++) { |
| 633 | u8 value; |
Lee Jones | 5ff9090 | 2013-02-12 14:35:28 +0000 | [diff] [blame] | 634 | |
| 635 | err = prcmu_abb_read(bank, reg, &value, 1); |
| 636 | |
Jonas Aaberg | 222460c | 2012-06-18 10:35:28 +0200 | [diff] [blame] | 637 | if (err < 0) |
| 638 | goto out; |
| 639 | |
Lee Jones | 5ff9090 | 2013-02-12 14:35:28 +0000 | [diff] [blame] | 640 | ab8500_complete_register_dump[r].bank = bank; |
| 641 | ab8500_complete_register_dump[r].reg = reg; |
| 642 | ab8500_complete_register_dump[r].value = value; |
| 643 | |
| 644 | r++; |
| 645 | |
| 646 | if (r >= DUMP_MAX_REGS) { |
| 647 | pr_err("%s: too many register to dump!\n", |
| 648 | __func__); |
Jonas Aaberg | 222460c | 2012-06-18 10:35:28 +0200 | [diff] [blame] | 649 | err = -EINVAL; |
| 650 | goto out; |
Lee Jones | 5ff9090 | 2013-02-12 14:35:28 +0000 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | } |
| 654 | } |
Jonas Aaberg | 222460c | 2012-06-18 10:35:28 +0200 | [diff] [blame] | 655 | out: |
| 656 | if (err >= 0) |
| 657 | pr_info("Saved all ABB registers.\n"); |
| 658 | else |
| 659 | pr_info("Failed to save all ABB registers.\n"); |
Lee Jones | 5ff9090 | 2013-02-12 14:35:28 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 662 | static int ab8500_all_banks_open(struct inode *inode, struct file *file) |
| 663 | { |
| 664 | struct seq_file *s; |
| 665 | int err; |
| 666 | |
| 667 | err = single_open(file, ab8500_print_all_banks, inode->i_private); |
| 668 | if (!err) { |
| 669 | /* Default buf size in seq_read is not enough */ |
| 670 | s = (struct seq_file *)file->private_data; |
| 671 | s->size = (PAGE_SIZE * 2); |
| 672 | s->buf = kmalloc(s->size, GFP_KERNEL); |
| 673 | if (!s->buf) { |
| 674 | single_release(inode, file); |
| 675 | err = -ENOMEM; |
| 676 | } |
| 677 | } |
| 678 | return err; |
| 679 | } |
| 680 | |
| 681 | static const struct file_operations ab8500_all_banks_fops = { |
| 682 | .open = ab8500_all_banks_open, |
| 683 | .read = seq_read, |
| 684 | .llseek = seq_lseek, |
| 685 | .release = single_release, |
| 686 | .owner = THIS_MODULE, |
| 687 | }; |
| 688 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 689 | static int ab8500_bank_print(struct seq_file *s, void *p) |
| 690 | { |
Mattias Wallin | cfc0849 | 2012-05-28 15:53:58 +0200 | [diff] [blame] | 691 | return seq_printf(s, "0x%02X\n", debug_bank); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | static int ab8500_bank_open(struct inode *inode, struct file *file) |
| 695 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 696 | return single_open(file, ab8500_bank_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | static ssize_t ab8500_bank_write(struct file *file, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 700 | const char __user *user_buf, |
| 701 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 702 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 703 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 704 | unsigned long user_bank; |
| 705 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 706 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 707 | /* Get userspace string and assure termination */ |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 708 | err = kstrtoul_from_user(user_buf, count, 0, &user_bank); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 709 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 710 | return err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 711 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 712 | if (user_bank >= AB8500_NUM_BANKS) { |
| 713 | dev_err(dev, "debugfs error input > number of banks\n"); |
| 714 | return -EINVAL; |
| 715 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 716 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 717 | debug_bank = user_bank; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 718 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 719 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | static int ab8500_address_print(struct seq_file *s, void *p) |
| 723 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 724 | return seq_printf(s, "0x%02X\n", debug_address); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | static int ab8500_address_open(struct inode *inode, struct file *file) |
| 728 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 729 | return single_open(file, ab8500_address_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | static ssize_t ab8500_address_write(struct file *file, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 733 | const char __user *user_buf, |
| 734 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 735 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 736 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 737 | unsigned long user_address; |
| 738 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 739 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 740 | /* Get userspace string and assure termination */ |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 741 | err = kstrtoul_from_user(user_buf, count, 0, &user_address); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 742 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 743 | return err; |
| 744 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 745 | if (user_address > 0xff) { |
| 746 | dev_err(dev, "debugfs error input > 0xff\n"); |
| 747 | return -EINVAL; |
| 748 | } |
| 749 | debug_address = user_address; |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 750 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | static int ab8500_val_print(struct seq_file *s, void *p) |
| 754 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 755 | struct device *dev = s->private; |
| 756 | int ret; |
| 757 | u8 regvalue; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 758 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 759 | ret = abx500_get_register_interruptible(dev, |
| 760 | (u8)debug_bank, (u8)debug_address, ®value); |
| 761 | if (ret < 0) { |
| 762 | dev_err(dev, "abx500_get_reg fail %d, %d\n", |
| 763 | ret, __LINE__); |
| 764 | return -EINVAL; |
| 765 | } |
| 766 | seq_printf(s, "0x%02X\n", regvalue); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 767 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 768 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | static int ab8500_val_open(struct inode *inode, struct file *file) |
| 772 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 773 | return single_open(file, ab8500_val_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | static ssize_t ab8500_val_write(struct file *file, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 777 | const char __user *user_buf, |
| 778 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 779 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 780 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 781 | unsigned long user_val; |
| 782 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 783 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 784 | /* Get userspace string and assure termination */ |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 785 | err = kstrtoul_from_user(user_buf, count, 0, &user_val); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 786 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 787 | return err; |
| 788 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 789 | if (user_val > 0xff) { |
| 790 | dev_err(dev, "debugfs error input > 0xff\n"); |
| 791 | return -EINVAL; |
| 792 | } |
| 793 | err = abx500_set_register_interruptible(dev, |
| 794 | (u8)debug_bank, debug_address, (u8)user_val); |
| 795 | if (err < 0) { |
| 796 | printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__); |
| 797 | return -EINVAL; |
| 798 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 799 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 800 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 801 | } |
| 802 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 803 | /* |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 804 | * Interrupt status |
| 805 | */ |
| 806 | static u32 num_interrupts[AB8500_MAX_NR_IRQS]; |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 807 | static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS]; |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 808 | static int num_interrupt_lines; |
| 809 | |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 810 | bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int) |
| 811 | { |
| 812 | return false; |
| 813 | } |
| 814 | |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 815 | void ab8500_debug_register_interrupt(int line) |
| 816 | { |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 817 | if (line < num_interrupt_lines) { |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 818 | num_interrupts[line]++; |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 819 | if (suspend_test_wake_cause_interrupt_is_mine(IRQ_DB8500_AB8500)) |
| 820 | num_wake_interrupts[line]++; |
| 821 | } |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | static int ab8500_interrupts_print(struct seq_file *s, void *p) |
| 825 | { |
| 826 | int line; |
| 827 | |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 828 | seq_printf(s, "name: number: number of: wake:\n"); |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 829 | |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 830 | for (line = 0; line < num_interrupt_lines; line++) { |
| 831 | struct irq_desc *desc = irq_to_desc(line + irq_first); |
| 832 | struct irqaction *action = desc->action; |
| 833 | |
| 834 | seq_printf(s, "%3i: %6i %4i", line, |
| 835 | num_interrupts[line], |
| 836 | num_wake_interrupts[line]); |
| 837 | |
| 838 | if (desc && desc->name) |
| 839 | seq_printf(s, "-%-8s", desc->name); |
| 840 | if (action) { |
| 841 | seq_printf(s, " %s", action->name); |
| 842 | while ((action = action->next) != NULL) |
| 843 | seq_printf(s, ", %s", action->name); |
| 844 | } |
| 845 | seq_putc(s, '\n'); |
| 846 | } |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 847 | |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | static int ab8500_interrupts_open(struct inode *inode, struct file *file) |
| 852 | { |
| 853 | return single_open(file, ab8500_interrupts_print, inode->i_private); |
| 854 | } |
| 855 | |
| 856 | /* |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 857 | * - HWREG DB8500 formated routines |
| 858 | */ |
| 859 | static int ab8500_hwreg_print(struct seq_file *s, void *d) |
| 860 | { |
| 861 | struct device *dev = s->private; |
| 862 | int ret; |
| 863 | u8 regvalue; |
| 864 | |
| 865 | ret = abx500_get_register_interruptible(dev, |
| 866 | (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, ®value); |
| 867 | if (ret < 0) { |
| 868 | dev_err(dev, "abx500_get_reg fail %d, %d\n", |
| 869 | ret, __LINE__); |
| 870 | return -EINVAL; |
| 871 | } |
| 872 | |
| 873 | if (hwreg_cfg.shift >= 0) |
| 874 | regvalue >>= hwreg_cfg.shift; |
| 875 | else |
| 876 | regvalue <<= -hwreg_cfg.shift; |
| 877 | regvalue &= hwreg_cfg.mask; |
| 878 | |
| 879 | if (REG_FMT_DEC(&hwreg_cfg)) |
| 880 | seq_printf(s, "%d\n", regvalue); |
| 881 | else |
| 882 | seq_printf(s, "0x%02X\n", regvalue); |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | static int ab8500_hwreg_open(struct inode *inode, struct file *file) |
| 887 | { |
| 888 | return single_open(file, ab8500_hwreg_print, inode->i_private); |
| 889 | } |
| 890 | |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 891 | static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p) |
| 892 | { |
| 893 | int bat_ctrl_raw; |
| 894 | int bat_ctrl_convert; |
| 895 | struct ab8500_gpadc *gpadc; |
| 896 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 897 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 898 | bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL, |
| 899 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 900 | bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 901 | BAT_CTRL, bat_ctrl_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 902 | |
| 903 | return seq_printf(s, "%d,0x%X\n", |
| 904 | bat_ctrl_convert, bat_ctrl_raw); |
| 905 | } |
| 906 | |
| 907 | static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file) |
| 908 | { |
| 909 | return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private); |
| 910 | } |
| 911 | |
| 912 | static const struct file_operations ab8500_gpadc_bat_ctrl_fops = { |
| 913 | .open = ab8500_gpadc_bat_ctrl_open, |
| 914 | .read = seq_read, |
| 915 | .llseek = seq_lseek, |
| 916 | .release = single_release, |
| 917 | .owner = THIS_MODULE, |
| 918 | }; |
| 919 | |
| 920 | static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p) |
| 921 | { |
| 922 | int btemp_ball_raw; |
| 923 | int btemp_ball_convert; |
| 924 | struct ab8500_gpadc *gpadc; |
| 925 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 926 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 927 | btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL, |
| 928 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 929 | btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 930 | btemp_ball_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 931 | |
| 932 | return seq_printf(s, |
| 933 | "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw); |
| 934 | } |
| 935 | |
| 936 | static int ab8500_gpadc_btemp_ball_open(struct inode *inode, |
| 937 | struct file *file) |
| 938 | { |
| 939 | return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private); |
| 940 | } |
| 941 | |
| 942 | static const struct file_operations ab8500_gpadc_btemp_ball_fops = { |
| 943 | .open = ab8500_gpadc_btemp_ball_open, |
| 944 | .read = seq_read, |
| 945 | .llseek = seq_lseek, |
| 946 | .release = single_release, |
| 947 | .owner = THIS_MODULE, |
| 948 | }; |
| 949 | |
| 950 | static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p) |
| 951 | { |
| 952 | int main_charger_v_raw; |
| 953 | int main_charger_v_convert; |
| 954 | struct ab8500_gpadc *gpadc; |
| 955 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 956 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 957 | main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V, |
| 958 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 959 | main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 960 | MAIN_CHARGER_V, main_charger_v_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 961 | |
| 962 | return seq_printf(s, "%d,0x%X\n", |
| 963 | main_charger_v_convert, main_charger_v_raw); |
| 964 | } |
| 965 | |
| 966 | static int ab8500_gpadc_main_charger_v_open(struct inode *inode, |
| 967 | struct file *file) |
| 968 | { |
| 969 | return single_open(file, ab8500_gpadc_main_charger_v_print, |
| 970 | inode->i_private); |
| 971 | } |
| 972 | |
| 973 | static const struct file_operations ab8500_gpadc_main_charger_v_fops = { |
| 974 | .open = ab8500_gpadc_main_charger_v_open, |
| 975 | .read = seq_read, |
| 976 | .llseek = seq_lseek, |
| 977 | .release = single_release, |
| 978 | .owner = THIS_MODULE, |
| 979 | }; |
| 980 | |
| 981 | static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p) |
| 982 | { |
| 983 | int acc_detect1_raw; |
| 984 | int acc_detect1_convert; |
| 985 | struct ab8500_gpadc *gpadc; |
| 986 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 987 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 988 | acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1, |
| 989 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 990 | acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 991 | acc_detect1_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 992 | |
| 993 | return seq_printf(s, "%d,0x%X\n", |
| 994 | acc_detect1_convert, acc_detect1_raw); |
| 995 | } |
| 996 | |
| 997 | static int ab8500_gpadc_acc_detect1_open(struct inode *inode, |
| 998 | struct file *file) |
| 999 | { |
| 1000 | return single_open(file, ab8500_gpadc_acc_detect1_print, |
| 1001 | inode->i_private); |
| 1002 | } |
| 1003 | |
| 1004 | static const struct file_operations ab8500_gpadc_acc_detect1_fops = { |
| 1005 | .open = ab8500_gpadc_acc_detect1_open, |
| 1006 | .read = seq_read, |
| 1007 | .llseek = seq_lseek, |
| 1008 | .release = single_release, |
| 1009 | .owner = THIS_MODULE, |
| 1010 | }; |
| 1011 | |
| 1012 | static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p) |
| 1013 | { |
| 1014 | int acc_detect2_raw; |
| 1015 | int acc_detect2_convert; |
| 1016 | struct ab8500_gpadc *gpadc; |
| 1017 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1018 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1019 | acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2, |
| 1020 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1021 | acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1022 | ACC_DETECT2, acc_detect2_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1023 | |
| 1024 | return seq_printf(s, "%d,0x%X\n", |
| 1025 | acc_detect2_convert, acc_detect2_raw); |
| 1026 | } |
| 1027 | |
| 1028 | static int ab8500_gpadc_acc_detect2_open(struct inode *inode, |
| 1029 | struct file *file) |
| 1030 | { |
| 1031 | return single_open(file, ab8500_gpadc_acc_detect2_print, |
| 1032 | inode->i_private); |
| 1033 | } |
| 1034 | |
| 1035 | static const struct file_operations ab8500_gpadc_acc_detect2_fops = { |
| 1036 | .open = ab8500_gpadc_acc_detect2_open, |
| 1037 | .read = seq_read, |
| 1038 | .llseek = seq_lseek, |
| 1039 | .release = single_release, |
| 1040 | .owner = THIS_MODULE, |
| 1041 | }; |
| 1042 | |
| 1043 | static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p) |
| 1044 | { |
| 1045 | int aux1_raw; |
| 1046 | int aux1_convert; |
| 1047 | struct ab8500_gpadc *gpadc; |
| 1048 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1049 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1050 | aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1, |
| 1051 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1052 | aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1053 | aux1_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1054 | |
| 1055 | return seq_printf(s, "%d,0x%X\n", |
| 1056 | aux1_convert, aux1_raw); |
| 1057 | } |
| 1058 | |
| 1059 | static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file) |
| 1060 | { |
| 1061 | return single_open(file, ab8500_gpadc_aux1_print, inode->i_private); |
| 1062 | } |
| 1063 | |
| 1064 | static const struct file_operations ab8500_gpadc_aux1_fops = { |
| 1065 | .open = ab8500_gpadc_aux1_open, |
| 1066 | .read = seq_read, |
| 1067 | .llseek = seq_lseek, |
| 1068 | .release = single_release, |
| 1069 | .owner = THIS_MODULE, |
| 1070 | }; |
| 1071 | |
| 1072 | static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p) |
| 1073 | { |
| 1074 | int aux2_raw; |
| 1075 | int aux2_convert; |
| 1076 | struct ab8500_gpadc *gpadc; |
| 1077 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1078 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1079 | aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2, |
| 1080 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1081 | aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1082 | aux2_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1083 | |
| 1084 | return seq_printf(s, "%d,0x%X\n", |
| 1085 | aux2_convert, aux2_raw); |
| 1086 | } |
| 1087 | |
| 1088 | static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file) |
| 1089 | { |
| 1090 | return single_open(file, ab8500_gpadc_aux2_print, inode->i_private); |
| 1091 | } |
| 1092 | |
| 1093 | static const struct file_operations ab8500_gpadc_aux2_fops = { |
| 1094 | .open = ab8500_gpadc_aux2_open, |
| 1095 | .read = seq_read, |
| 1096 | .llseek = seq_lseek, |
| 1097 | .release = single_release, |
| 1098 | .owner = THIS_MODULE, |
| 1099 | }; |
| 1100 | |
| 1101 | static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p) |
| 1102 | { |
| 1103 | int main_bat_v_raw; |
| 1104 | int main_bat_v_convert; |
| 1105 | struct ab8500_gpadc *gpadc; |
| 1106 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1107 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1108 | main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V, |
| 1109 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1110 | main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1111 | main_bat_v_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1112 | |
| 1113 | return seq_printf(s, "%d,0x%X\n", |
| 1114 | main_bat_v_convert, main_bat_v_raw); |
| 1115 | } |
| 1116 | |
| 1117 | static int ab8500_gpadc_main_bat_v_open(struct inode *inode, |
| 1118 | struct file *file) |
| 1119 | { |
| 1120 | return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private); |
| 1121 | } |
| 1122 | |
| 1123 | static const struct file_operations ab8500_gpadc_main_bat_v_fops = { |
| 1124 | .open = ab8500_gpadc_main_bat_v_open, |
| 1125 | .read = seq_read, |
| 1126 | .llseek = seq_lseek, |
| 1127 | .release = single_release, |
| 1128 | .owner = THIS_MODULE, |
| 1129 | }; |
| 1130 | |
| 1131 | static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p) |
| 1132 | { |
| 1133 | int vbus_v_raw; |
| 1134 | int vbus_v_convert; |
| 1135 | struct ab8500_gpadc *gpadc; |
| 1136 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1137 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1138 | vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V, |
| 1139 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1140 | vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1141 | vbus_v_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1142 | |
| 1143 | return seq_printf(s, "%d,0x%X\n", |
| 1144 | vbus_v_convert, vbus_v_raw); |
| 1145 | } |
| 1146 | |
| 1147 | static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file) |
| 1148 | { |
| 1149 | return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private); |
| 1150 | } |
| 1151 | |
| 1152 | static const struct file_operations ab8500_gpadc_vbus_v_fops = { |
| 1153 | .open = ab8500_gpadc_vbus_v_open, |
| 1154 | .read = seq_read, |
| 1155 | .llseek = seq_lseek, |
| 1156 | .release = single_release, |
| 1157 | .owner = THIS_MODULE, |
| 1158 | }; |
| 1159 | |
| 1160 | static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p) |
| 1161 | { |
| 1162 | int main_charger_c_raw; |
| 1163 | int main_charger_c_convert; |
| 1164 | struct ab8500_gpadc *gpadc; |
| 1165 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1166 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1167 | main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C, |
| 1168 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1169 | main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1170 | MAIN_CHARGER_C, main_charger_c_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1171 | |
| 1172 | return seq_printf(s, "%d,0x%X\n", |
| 1173 | main_charger_c_convert, main_charger_c_raw); |
| 1174 | } |
| 1175 | |
| 1176 | static int ab8500_gpadc_main_charger_c_open(struct inode *inode, |
| 1177 | struct file *file) |
| 1178 | { |
| 1179 | return single_open(file, ab8500_gpadc_main_charger_c_print, |
| 1180 | inode->i_private); |
| 1181 | } |
| 1182 | |
| 1183 | static const struct file_operations ab8500_gpadc_main_charger_c_fops = { |
| 1184 | .open = ab8500_gpadc_main_charger_c_open, |
| 1185 | .read = seq_read, |
| 1186 | .llseek = seq_lseek, |
| 1187 | .release = single_release, |
| 1188 | .owner = THIS_MODULE, |
| 1189 | }; |
| 1190 | |
| 1191 | static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p) |
| 1192 | { |
| 1193 | int usb_charger_c_raw; |
| 1194 | int usb_charger_c_convert; |
| 1195 | struct ab8500_gpadc *gpadc; |
| 1196 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1197 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1198 | usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C, |
| 1199 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1200 | usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1201 | USB_CHARGER_C, usb_charger_c_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1202 | |
| 1203 | return seq_printf(s, "%d,0x%X\n", |
| 1204 | usb_charger_c_convert, usb_charger_c_raw); |
| 1205 | } |
| 1206 | |
| 1207 | static int ab8500_gpadc_usb_charger_c_open(struct inode *inode, |
| 1208 | struct file *file) |
| 1209 | { |
| 1210 | return single_open(file, ab8500_gpadc_usb_charger_c_print, |
| 1211 | inode->i_private); |
| 1212 | } |
| 1213 | |
| 1214 | static const struct file_operations ab8500_gpadc_usb_charger_c_fops = { |
| 1215 | .open = ab8500_gpadc_usb_charger_c_open, |
| 1216 | .read = seq_read, |
| 1217 | .llseek = seq_lseek, |
| 1218 | .release = single_release, |
| 1219 | .owner = THIS_MODULE, |
| 1220 | }; |
| 1221 | |
| 1222 | static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p) |
| 1223 | { |
| 1224 | int bk_bat_v_raw; |
| 1225 | int bk_bat_v_convert; |
| 1226 | struct ab8500_gpadc *gpadc; |
| 1227 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1228 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1229 | bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V, |
| 1230 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1231 | bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1232 | BK_BAT_V, bk_bat_v_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1233 | |
| 1234 | return seq_printf(s, "%d,0x%X\n", |
| 1235 | bk_bat_v_convert, bk_bat_v_raw); |
| 1236 | } |
| 1237 | |
| 1238 | static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file) |
| 1239 | { |
| 1240 | return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private); |
| 1241 | } |
| 1242 | |
| 1243 | static const struct file_operations ab8500_gpadc_bk_bat_v_fops = { |
| 1244 | .open = ab8500_gpadc_bk_bat_v_open, |
| 1245 | .read = seq_read, |
| 1246 | .llseek = seq_lseek, |
| 1247 | .release = single_release, |
| 1248 | .owner = THIS_MODULE, |
| 1249 | }; |
| 1250 | |
| 1251 | static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p) |
| 1252 | { |
| 1253 | int die_temp_raw; |
| 1254 | int die_temp_convert; |
| 1255 | struct ab8500_gpadc *gpadc; |
| 1256 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1257 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1258 | die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP, |
| 1259 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1260 | die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1261 | die_temp_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1262 | |
| 1263 | return seq_printf(s, "%d,0x%X\n", |
| 1264 | die_temp_convert, die_temp_raw); |
| 1265 | } |
| 1266 | |
| 1267 | static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file) |
| 1268 | { |
| 1269 | return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private); |
| 1270 | } |
| 1271 | |
| 1272 | static const struct file_operations ab8500_gpadc_die_temp_fops = { |
| 1273 | .open = ab8500_gpadc_die_temp_open, |
| 1274 | .read = seq_read, |
| 1275 | .llseek = seq_lseek, |
| 1276 | .release = single_release, |
| 1277 | .owner = THIS_MODULE, |
| 1278 | }; |
| 1279 | |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1280 | static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p) |
| 1281 | { |
| 1282 | return seq_printf(s, "%d\n", avg_sample); |
| 1283 | } |
| 1284 | |
| 1285 | static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file) |
| 1286 | { |
| 1287 | return single_open(file, ab8500_gpadc_avg_sample_print, |
| 1288 | inode->i_private); |
| 1289 | } |
| 1290 | |
| 1291 | static ssize_t ab8500_gpadc_avg_sample_write(struct file *file, |
| 1292 | const char __user *user_buf, |
| 1293 | size_t count, loff_t *ppos) |
| 1294 | { |
| 1295 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
| 1296 | char buf[32]; |
| 1297 | int buf_size; |
| 1298 | unsigned long user_avg_sample; |
| 1299 | int err; |
| 1300 | |
| 1301 | /* Get userspace string and assure termination */ |
| 1302 | buf_size = min(count, (sizeof(buf) - 1)); |
| 1303 | if (copy_from_user(buf, user_buf, buf_size)) |
| 1304 | return -EFAULT; |
| 1305 | buf[buf_size] = 0; |
| 1306 | |
| 1307 | err = strict_strtoul(buf, 0, &user_avg_sample); |
| 1308 | if (err) |
| 1309 | return -EINVAL; |
| 1310 | if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4) |
| 1311 | || (user_avg_sample == SAMPLE_8) |
| 1312 | || (user_avg_sample == SAMPLE_16)) { |
| 1313 | avg_sample = (u8) user_avg_sample; |
| 1314 | } else { |
| 1315 | dev_err(dev, "debugfs error input: " |
| 1316 | "should be egal to 1, 4, 8 or 16\n"); |
| 1317 | return -EINVAL; |
| 1318 | } |
| 1319 | return buf_size; |
| 1320 | } |
| 1321 | |
| 1322 | static const struct file_operations ab8500_gpadc_avg_sample_fops = { |
| 1323 | .open = ab8500_gpadc_avg_sample_open, |
| 1324 | .read = seq_read, |
| 1325 | .write = ab8500_gpadc_avg_sample_write, |
| 1326 | .llseek = seq_lseek, |
| 1327 | .release = single_release, |
| 1328 | .owner = THIS_MODULE, |
| 1329 | }; |
| 1330 | |
| 1331 | static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p) |
| 1332 | { |
| 1333 | return seq_printf(s, "%d\n", trig_edge); |
| 1334 | } |
| 1335 | |
| 1336 | static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file) |
| 1337 | { |
| 1338 | return single_open(file, ab8500_gpadc_trig_edge_print, |
| 1339 | inode->i_private); |
| 1340 | } |
| 1341 | |
| 1342 | static ssize_t ab8500_gpadc_trig_edge_write(struct file *file, |
| 1343 | const char __user *user_buf, |
| 1344 | size_t count, loff_t *ppos) |
| 1345 | { |
| 1346 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
| 1347 | char buf[32]; |
| 1348 | int buf_size; |
| 1349 | unsigned long user_trig_edge; |
| 1350 | int err; |
| 1351 | |
| 1352 | /* Get userspace string and assure termination */ |
| 1353 | buf_size = min(count, (sizeof(buf) - 1)); |
| 1354 | if (copy_from_user(buf, user_buf, buf_size)) |
| 1355 | return -EFAULT; |
| 1356 | buf[buf_size] = 0; |
| 1357 | |
| 1358 | err = strict_strtoul(buf, 0, &user_trig_edge); |
| 1359 | if (err) |
| 1360 | return -EINVAL; |
| 1361 | if ((user_trig_edge == RISING_EDGE) |
| 1362 | || (user_trig_edge == FALLING_EDGE)) { |
| 1363 | trig_edge = (u8) user_trig_edge; |
| 1364 | } else { |
| 1365 | dev_err(dev, "Wrong input:\n" |
| 1366 | "Enter 0. Rising edge\n" |
| 1367 | "Enter 1. Falling edge\n"); |
| 1368 | return -EINVAL; |
| 1369 | } |
| 1370 | return buf_size; |
| 1371 | } |
| 1372 | |
| 1373 | static const struct file_operations ab8500_gpadc_trig_edge_fops = { |
| 1374 | .open = ab8500_gpadc_trig_edge_open, |
| 1375 | .read = seq_read, |
| 1376 | .write = ab8500_gpadc_trig_edge_write, |
| 1377 | .llseek = seq_lseek, |
| 1378 | .release = single_release, |
| 1379 | .owner = THIS_MODULE, |
| 1380 | }; |
| 1381 | |
| 1382 | static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p) |
| 1383 | { |
| 1384 | return seq_printf(s, "%d\n", trig_timer); |
| 1385 | } |
| 1386 | |
| 1387 | static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file) |
| 1388 | { |
| 1389 | return single_open(file, ab8500_gpadc_trig_timer_print, |
| 1390 | inode->i_private); |
| 1391 | } |
| 1392 | |
| 1393 | static ssize_t ab8500_gpadc_trig_timer_write(struct file *file, |
| 1394 | const char __user *user_buf, |
| 1395 | size_t count, loff_t *ppos) |
| 1396 | { |
| 1397 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
| 1398 | char buf[32]; |
| 1399 | int buf_size; |
| 1400 | unsigned long user_trig_timer; |
| 1401 | int err; |
| 1402 | |
| 1403 | /* Get userspace string and assure termination */ |
| 1404 | buf_size = min(count, (sizeof(buf) - 1)); |
| 1405 | if (copy_from_user(buf, user_buf, buf_size)) |
| 1406 | return -EFAULT; |
| 1407 | buf[buf_size] = 0; |
| 1408 | |
| 1409 | err = strict_strtoul(buf, 0, &user_trig_timer); |
| 1410 | if (err) |
| 1411 | return -EINVAL; |
| 1412 | if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) { |
| 1413 | trig_timer = (u8) user_trig_timer; |
| 1414 | } else { |
| 1415 | dev_err(dev, "debugfs error input: " |
| 1416 | "should be beetween 0 to 255\n"); |
| 1417 | return -EINVAL; |
| 1418 | } |
| 1419 | return buf_size; |
| 1420 | } |
| 1421 | |
| 1422 | static const struct file_operations ab8500_gpadc_trig_timer_fops = { |
| 1423 | .open = ab8500_gpadc_trig_timer_open, |
| 1424 | .read = seq_read, |
| 1425 | .write = ab8500_gpadc_trig_timer_write, |
| 1426 | .llseek = seq_lseek, |
| 1427 | .release = single_release, |
| 1428 | .owner = THIS_MODULE, |
| 1429 | }; |
| 1430 | |
| 1431 | static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p) |
| 1432 | { |
| 1433 | return seq_printf(s, "%d\n", conv_type); |
| 1434 | } |
| 1435 | |
| 1436 | static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file) |
| 1437 | { |
| 1438 | return single_open(file, ab8500_gpadc_conv_type_print, |
| 1439 | inode->i_private); |
| 1440 | } |
| 1441 | |
| 1442 | static ssize_t ab8500_gpadc_conv_type_write(struct file *file, |
| 1443 | const char __user *user_buf, |
| 1444 | size_t count, loff_t *ppos) |
| 1445 | { |
| 1446 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
| 1447 | char buf[32]; |
| 1448 | int buf_size; |
| 1449 | unsigned long user_conv_type; |
| 1450 | int err; |
| 1451 | |
| 1452 | /* Get userspace string and assure termination */ |
| 1453 | buf_size = min(count, (sizeof(buf) - 1)); |
| 1454 | if (copy_from_user(buf, user_buf, buf_size)) |
| 1455 | return -EFAULT; |
| 1456 | buf[buf_size] = 0; |
| 1457 | |
| 1458 | err = strict_strtoul(buf, 0, &user_conv_type); |
| 1459 | if (err) |
| 1460 | return -EINVAL; |
| 1461 | if ((user_conv_type == ADC_SW) |
| 1462 | || (user_conv_type == ADC_HW)) { |
| 1463 | conv_type = (u8) user_conv_type; |
| 1464 | } else { |
| 1465 | dev_err(dev, "Wrong input:\n" |
| 1466 | "Enter 0. ADC SW conversion\n" |
| 1467 | "Enter 1. ADC HW conversion\n"); |
| 1468 | return -EINVAL; |
| 1469 | } |
| 1470 | return buf_size; |
| 1471 | } |
| 1472 | |
| 1473 | static const struct file_operations ab8500_gpadc_conv_type_fops = { |
| 1474 | .open = ab8500_gpadc_conv_type_open, |
| 1475 | .read = seq_read, |
| 1476 | .write = ab8500_gpadc_conv_type_write, |
| 1477 | .llseek = seq_lseek, |
| 1478 | .release = single_release, |
| 1479 | .owner = THIS_MODULE, |
| 1480 | }; |
| 1481 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1482 | /* |
| 1483 | * return length of an ASCII numerical value, 0 is string is not a |
| 1484 | * numerical value. |
| 1485 | * string shall start at value 1st char. |
| 1486 | * string can be tailed with \0 or space or newline chars only. |
| 1487 | * value can be decimal or hexadecimal (prefixed 0x or 0X). |
| 1488 | */ |
| 1489 | static int strval_len(char *b) |
| 1490 | { |
| 1491 | char *s = b; |
| 1492 | if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) { |
| 1493 | s += 2; |
| 1494 | for (; *s && (*s != ' ') && (*s != '\n'); s++) { |
| 1495 | if (!isxdigit(*s)) |
| 1496 | return 0; |
| 1497 | } |
| 1498 | } else { |
| 1499 | if (*s == '-') |
| 1500 | s++; |
| 1501 | for (; *s && (*s != ' ') && (*s != '\n'); s++) { |
| 1502 | if (!isdigit(*s)) |
| 1503 | return 0; |
| 1504 | } |
| 1505 | } |
| 1506 | return (int) (s-b); |
| 1507 | } |
| 1508 | |
| 1509 | /* |
| 1510 | * parse hwreg input data. |
| 1511 | * update global hwreg_cfg only if input data syntax is ok. |
| 1512 | */ |
| 1513 | static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg, |
| 1514 | struct device *dev) |
| 1515 | { |
| 1516 | uint write, val = 0; |
| 1517 | u8 regvalue; |
| 1518 | int ret; |
| 1519 | struct hwreg_cfg loc = { |
| 1520 | .bank = 0, /* default: invalid phys addr */ |
| 1521 | .addr = 0, /* default: invalid phys addr */ |
| 1522 | .fmt = 0, /* default: 32bit access, hex output */ |
| 1523 | .mask = 0xFFFFFFFF, /* default: no mask */ |
| 1524 | .shift = 0, /* default: no bit shift */ |
| 1525 | }; |
| 1526 | |
| 1527 | /* read or write ? */ |
| 1528 | if (!strncmp(b, "read ", 5)) { |
| 1529 | write = 0; |
| 1530 | b += 5; |
| 1531 | } else if (!strncmp(b, "write ", 6)) { |
| 1532 | write = 1; |
| 1533 | b += 6; |
| 1534 | } else |
| 1535 | return -EINVAL; |
| 1536 | |
| 1537 | /* OPTIONS -l|-w|-b -s -m -o */ |
| 1538 | while ((*b == ' ') || (*b == '-')) { |
| 1539 | if (*(b-1) != ' ') { |
| 1540 | b++; |
| 1541 | continue; |
| 1542 | } |
| 1543 | if ((!strncmp(b, "-d ", 3)) || |
| 1544 | (!strncmp(b, "-dec ", 5))) { |
| 1545 | b += (*(b+2) == ' ') ? 3 : 5; |
| 1546 | loc.fmt |= (1<<0); |
| 1547 | } else if ((!strncmp(b, "-h ", 3)) || |
| 1548 | (!strncmp(b, "-hex ", 5))) { |
| 1549 | b += (*(b+2) == ' ') ? 3 : 5; |
| 1550 | loc.fmt &= ~(1<<0); |
| 1551 | } else if ((!strncmp(b, "-m ", 3)) || |
| 1552 | (!strncmp(b, "-mask ", 6))) { |
| 1553 | b += (*(b+2) == ' ') ? 3 : 6; |
| 1554 | if (strval_len(b) == 0) |
| 1555 | return -EINVAL; |
| 1556 | loc.mask = simple_strtoul(b, &b, 0); |
| 1557 | } else if ((!strncmp(b, "-s ", 3)) || |
| 1558 | (!strncmp(b, "-shift ", 7))) { |
| 1559 | b += (*(b+2) == ' ') ? 3 : 7; |
| 1560 | if (strval_len(b) == 0) |
| 1561 | return -EINVAL; |
| 1562 | loc.shift = simple_strtol(b, &b, 0); |
| 1563 | } else { |
| 1564 | return -EINVAL; |
| 1565 | } |
| 1566 | } |
| 1567 | /* get arg BANK and ADDRESS */ |
| 1568 | if (strval_len(b) == 0) |
| 1569 | return -EINVAL; |
| 1570 | loc.bank = simple_strtoul(b, &b, 0); |
| 1571 | while (*b == ' ') |
| 1572 | b++; |
| 1573 | if (strval_len(b) == 0) |
| 1574 | return -EINVAL; |
| 1575 | loc.addr = simple_strtoul(b, &b, 0); |
| 1576 | |
| 1577 | if (write) { |
| 1578 | while (*b == ' ') |
| 1579 | b++; |
| 1580 | if (strval_len(b) == 0) |
| 1581 | return -EINVAL; |
| 1582 | val = simple_strtoul(b, &b, 0); |
| 1583 | } |
| 1584 | |
| 1585 | /* args are ok, update target cfg (mainly for read) */ |
| 1586 | *cfg = loc; |
| 1587 | |
| 1588 | #ifdef ABB_HWREG_DEBUG |
| 1589 | pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d" |
| 1590 | "value=0x%X\n", (write) ? "write" : "read", |
| 1591 | REG_FMT_DEC(cfg) ? "decimal" : "hexa", |
| 1592 | cfg->addr, cfg->mask, cfg->shift, val); |
| 1593 | #endif |
| 1594 | |
| 1595 | if (!write) |
| 1596 | return 0; |
| 1597 | |
| 1598 | ret = abx500_get_register_interruptible(dev, |
| 1599 | (u8)cfg->bank, (u8)cfg->addr, ®value); |
| 1600 | if (ret < 0) { |
| 1601 | dev_err(dev, "abx500_get_reg fail %d, %d\n", |
| 1602 | ret, __LINE__); |
| 1603 | return -EINVAL; |
| 1604 | } |
| 1605 | |
| 1606 | if (cfg->shift >= 0) { |
| 1607 | regvalue &= ~(cfg->mask << (cfg->shift)); |
| 1608 | val = (val & cfg->mask) << (cfg->shift); |
| 1609 | } else { |
| 1610 | regvalue &= ~(cfg->mask >> (-cfg->shift)); |
| 1611 | val = (val & cfg->mask) >> (-cfg->shift); |
| 1612 | } |
| 1613 | val = val | regvalue; |
| 1614 | |
| 1615 | ret = abx500_set_register_interruptible(dev, |
| 1616 | (u8)cfg->bank, (u8)cfg->addr, (u8)val); |
| 1617 | if (ret < 0) { |
| 1618 | pr_err("abx500_set_reg failed %d, %d", ret, __LINE__); |
| 1619 | return -EINVAL; |
| 1620 | } |
| 1621 | |
| 1622 | return 0; |
| 1623 | } |
| 1624 | |
| 1625 | static ssize_t ab8500_hwreg_write(struct file *file, |
| 1626 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 1627 | { |
| 1628 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
| 1629 | char buf[128]; |
| 1630 | int buf_size, ret; |
| 1631 | |
| 1632 | /* Get userspace string and assure termination */ |
| 1633 | buf_size = min(count, (sizeof(buf)-1)); |
| 1634 | if (copy_from_user(buf, user_buf, buf_size)) |
| 1635 | return -EFAULT; |
| 1636 | buf[buf_size] = 0; |
| 1637 | |
| 1638 | /* get args and process */ |
| 1639 | ret = hwreg_common_write(buf, &hwreg_cfg, dev); |
| 1640 | return (ret) ? ret : buf_size; |
| 1641 | } |
| 1642 | |
| 1643 | /* |
| 1644 | * - irq subscribe/unsubscribe stuff |
| 1645 | */ |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1646 | static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p) |
| 1647 | { |
| 1648 | seq_printf(s, "%d\n", irq_first); |
| 1649 | |
| 1650 | return 0; |
| 1651 | } |
| 1652 | |
| 1653 | static int ab8500_subscribe_unsubscribe_open(struct inode *inode, |
| 1654 | struct file *file) |
| 1655 | { |
| 1656 | return single_open(file, ab8500_subscribe_unsubscribe_print, |
| 1657 | inode->i_private); |
| 1658 | } |
| 1659 | |
| 1660 | /* |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1661 | * Userspace should use poll() on this file. When an event occur |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1662 | * the blocking poll will be released. |
| 1663 | */ |
| 1664 | static ssize_t show_irq(struct device *dev, |
| 1665 | struct device_attribute *attr, char *buf) |
| 1666 | { |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1667 | unsigned long name; |
| 1668 | unsigned int irq_index; |
| 1669 | int err; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1670 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1671 | err = strict_strtoul(attr->attr.name, 0, &name); |
| 1672 | if (err) |
| 1673 | return err; |
| 1674 | |
| 1675 | irq_index = name - irq_first; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 1676 | if (irq_index >= num_irqs) |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1677 | return -EINVAL; |
| 1678 | else |
| 1679 | return sprintf(buf, "%u\n", irq_count[irq_index]); |
| 1680 | } |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1681 | |
| 1682 | static ssize_t ab8500_subscribe_write(struct file *file, |
| 1683 | const char __user *user_buf, |
| 1684 | size_t count, loff_t *ppos) |
| 1685 | { |
| 1686 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
| 1687 | char buf[32]; |
| 1688 | int buf_size; |
| 1689 | unsigned long user_val; |
| 1690 | int err; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1691 | unsigned int irq_index; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1692 | |
| 1693 | /* Get userspace string and assure termination */ |
| 1694 | buf_size = min(count, (sizeof(buf)-1)); |
| 1695 | if (copy_from_user(buf, user_buf, buf_size)) |
| 1696 | return -EFAULT; |
| 1697 | buf[buf_size] = 0; |
| 1698 | |
| 1699 | err = strict_strtoul(buf, 0, &user_val); |
| 1700 | if (err) |
| 1701 | return -EINVAL; |
| 1702 | if (user_val < irq_first) { |
| 1703 | dev_err(dev, "debugfs error input < %d\n", irq_first); |
| 1704 | return -EINVAL; |
| 1705 | } |
| 1706 | if (user_val > irq_last) { |
| 1707 | dev_err(dev, "debugfs error input > %d\n", irq_last); |
| 1708 | return -EINVAL; |
| 1709 | } |
| 1710 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1711 | irq_index = user_val - irq_first; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 1712 | if (irq_index >= num_irqs) |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1713 | return -EINVAL; |
| 1714 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1715 | /* |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1716 | * This will create a sysfs file named <irq-nr> which userspace can |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1717 | * use to select or poll and get the AB8500 events |
| 1718 | */ |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1719 | dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute), |
| 1720 | GFP_KERNEL); |
| 1721 | event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL); |
| 1722 | sprintf(event_name[irq_index], "%lu", user_val); |
| 1723 | dev_attr[irq_index]->show = show_irq; |
| 1724 | dev_attr[irq_index]->store = NULL; |
| 1725 | dev_attr[irq_index]->attr.name = event_name[irq_index]; |
| 1726 | dev_attr[irq_index]->attr.mode = S_IRUGO; |
| 1727 | err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1728 | if (err < 0) { |
| 1729 | printk(KERN_ERR "sysfs_create_file failed %d\n", err); |
| 1730 | return err; |
| 1731 | } |
| 1732 | |
| 1733 | err = request_threaded_irq(user_val, NULL, ab8500_debug_handler, |
| 1734 | IRQF_SHARED | IRQF_NO_SUSPEND, |
| 1735 | "ab8500-debug", &dev->kobj); |
| 1736 | if (err < 0) { |
| 1737 | printk(KERN_ERR "request_threaded_irq failed %d, %lu\n", |
| 1738 | err, user_val); |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1739 | sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1740 | return err; |
| 1741 | } |
| 1742 | |
| 1743 | return buf_size; |
| 1744 | } |
| 1745 | |
| 1746 | static ssize_t ab8500_unsubscribe_write(struct file *file, |
| 1747 | const char __user *user_buf, |
| 1748 | size_t count, loff_t *ppos) |
| 1749 | { |
| 1750 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
| 1751 | char buf[32]; |
| 1752 | int buf_size; |
| 1753 | unsigned long user_val; |
| 1754 | int err; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1755 | unsigned int irq_index; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1756 | |
| 1757 | /* Get userspace string and assure termination */ |
| 1758 | buf_size = min(count, (sizeof(buf)-1)); |
| 1759 | if (copy_from_user(buf, user_buf, buf_size)) |
| 1760 | return -EFAULT; |
| 1761 | buf[buf_size] = 0; |
| 1762 | |
| 1763 | err = strict_strtoul(buf, 0, &user_val); |
| 1764 | if (err) |
| 1765 | return -EINVAL; |
| 1766 | if (user_val < irq_first) { |
| 1767 | dev_err(dev, "debugfs error input < %d\n", irq_first); |
| 1768 | return -EINVAL; |
| 1769 | } |
| 1770 | if (user_val > irq_last) { |
| 1771 | dev_err(dev, "debugfs error input > %d\n", irq_last); |
| 1772 | return -EINVAL; |
| 1773 | } |
| 1774 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1775 | irq_index = user_val - irq_first; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 1776 | if (irq_index >= num_irqs) |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1777 | return -EINVAL; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1778 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1779 | /* Set irq count to 0 when unsubscribe */ |
| 1780 | irq_count[irq_index] = 0; |
| 1781 | |
| 1782 | if (dev_attr[irq_index]) |
| 1783 | sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); |
| 1784 | |
| 1785 | |
| 1786 | free_irq(user_val, &dev->kobj); |
| 1787 | kfree(event_name[irq_index]); |
| 1788 | kfree(dev_attr[irq_index]); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1789 | |
| 1790 | return buf_size; |
| 1791 | } |
| 1792 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1793 | /* |
| 1794 | * - several deubgfs nodes fops |
| 1795 | */ |
| 1796 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1797 | static const struct file_operations ab8500_bank_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1798 | .open = ab8500_bank_open, |
| 1799 | .write = ab8500_bank_write, |
| 1800 | .read = seq_read, |
| 1801 | .llseek = seq_lseek, |
| 1802 | .release = single_release, |
| 1803 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1804 | }; |
| 1805 | |
| 1806 | static const struct file_operations ab8500_address_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1807 | .open = ab8500_address_open, |
| 1808 | .write = ab8500_address_write, |
| 1809 | .read = seq_read, |
| 1810 | .llseek = seq_lseek, |
| 1811 | .release = single_release, |
| 1812 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1813 | }; |
| 1814 | |
| 1815 | static const struct file_operations ab8500_val_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1816 | .open = ab8500_val_open, |
| 1817 | .write = ab8500_val_write, |
| 1818 | .read = seq_read, |
| 1819 | .llseek = seq_lseek, |
| 1820 | .release = single_release, |
| 1821 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1822 | }; |
| 1823 | |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 1824 | static const struct file_operations ab8500_interrupts_fops = { |
| 1825 | .open = ab8500_interrupts_open, |
| 1826 | .read = seq_read, |
| 1827 | .llseek = seq_lseek, |
| 1828 | .release = single_release, |
| 1829 | .owner = THIS_MODULE, |
| 1830 | }; |
| 1831 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1832 | static const struct file_operations ab8500_subscribe_fops = { |
| 1833 | .open = ab8500_subscribe_unsubscribe_open, |
| 1834 | .write = ab8500_subscribe_write, |
| 1835 | .read = seq_read, |
| 1836 | .llseek = seq_lseek, |
| 1837 | .release = single_release, |
| 1838 | .owner = THIS_MODULE, |
| 1839 | }; |
| 1840 | |
| 1841 | static const struct file_operations ab8500_unsubscribe_fops = { |
| 1842 | .open = ab8500_subscribe_unsubscribe_open, |
| 1843 | .write = ab8500_unsubscribe_write, |
| 1844 | .read = seq_read, |
| 1845 | .llseek = seq_lseek, |
| 1846 | .release = single_release, |
| 1847 | .owner = THIS_MODULE, |
| 1848 | }; |
| 1849 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1850 | static const struct file_operations ab8500_hwreg_fops = { |
| 1851 | .open = ab8500_hwreg_open, |
| 1852 | .write = ab8500_hwreg_write, |
| 1853 | .read = seq_read, |
| 1854 | .llseek = seq_lseek, |
| 1855 | .release = single_release, |
| 1856 | .owner = THIS_MODULE, |
| 1857 | }; |
| 1858 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1859 | static struct dentry *ab8500_dir; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1860 | static struct dentry *ab8500_gpadc_dir; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1861 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 1862 | static int ab8500_debug_probe(struct platform_device *plf) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1863 | { |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1864 | struct dentry *file; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 1865 | int ret = -ENOMEM; |
| 1866 | struct ab8500 *ab8500; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1867 | debug_bank = AB8500_MISC; |
| 1868 | debug_address = AB8500_REV_REG & 0x00FF; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1869 | |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 1870 | ab8500 = dev_get_drvdata(plf->dev.parent); |
| 1871 | num_irqs = ab8500->mask_size; |
| 1872 | |
Ashok G | 70bad04 | 2012-02-28 10:21:00 +0530 | [diff] [blame] | 1873 | irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL); |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 1874 | if (!irq_count) |
| 1875 | return -ENOMEM; |
| 1876 | |
| 1877 | dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL); |
| 1878 | if (!dev_attr) |
| 1879 | goto out_freeirq_count; |
| 1880 | |
| 1881 | event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL); |
| 1882 | if (!event_name) |
| 1883 | goto out_freedev_attr; |
| 1884 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1885 | irq_first = platform_get_irq_byname(plf, "IRQ_FIRST"); |
| 1886 | if (irq_first < 0) { |
| 1887 | dev_err(&plf->dev, "First irq not found, err %d\n", |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1888 | irq_first); |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 1889 | ret = irq_first; |
| 1890 | goto out_freeevent_name; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | irq_last = platform_get_irq_byname(plf, "IRQ_LAST"); |
| 1894 | if (irq_last < 0) { |
| 1895 | dev_err(&plf->dev, "Last irq not found, err %d\n", |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1896 | irq_last); |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 1897 | ret = irq_last; |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 1898 | goto out_freeevent_name; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1901 | ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); |
| 1902 | if (!ab8500_dir) |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1903 | goto err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1904 | |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1905 | ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING, |
| 1906 | ab8500_dir); |
| 1907 | if (!ab8500_gpadc_dir) |
| 1908 | goto err; |
| 1909 | |
| 1910 | file = debugfs_create_file("all-bank-registers", S_IRUGO, |
| 1911 | ab8500_dir, &plf->dev, &ab8500_registers_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1912 | if (!file) |
| 1913 | goto err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1914 | |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1915 | file = debugfs_create_file("all-banks", S_IRUGO, |
| 1916 | ab8500_dir, &plf->dev, &ab8500_all_banks_fops); |
| 1917 | if (!file) |
| 1918 | goto err; |
| 1919 | |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1920 | file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR), |
| 1921 | ab8500_dir, &plf->dev, &ab8500_bank_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1922 | if (!file) |
| 1923 | goto err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1924 | |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1925 | file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR), |
| 1926 | ab8500_dir, &plf->dev, &ab8500_address_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1927 | if (!file) |
| 1928 | goto err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1929 | |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1930 | file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR), |
| 1931 | ab8500_dir, &plf->dev, &ab8500_val_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1932 | if (!file) |
| 1933 | goto err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1934 | |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1935 | file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR), |
| 1936 | ab8500_dir, &plf->dev, &ab8500_subscribe_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1937 | if (!file) |
| 1938 | goto err; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1939 | |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 1940 | if (is_ab8500(ab8500)) |
| 1941 | num_interrupt_lines = AB8500_NR_IRQS; |
| 1942 | else if (is_ab8505(ab8500)) |
| 1943 | num_interrupt_lines = AB8505_NR_IRQS; |
| 1944 | else if (is_ab9540(ab8500)) |
| 1945 | num_interrupt_lines = AB9540_NR_IRQS; |
Lee Jones | e436ddf | 2013-02-26 10:09:41 +0000 | [diff] [blame^] | 1946 | else if (is_ab8540(ab8500)) |
| 1947 | num_interrupt_lines = AB8540_NR_IRQS; |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 1948 | |
| 1949 | file = debugfs_create_file("interrupts", (S_IRUGO), |
| 1950 | ab8500_dir, &plf->dev, &ab8500_interrupts_fops); |
| 1951 | if (!file) |
| 1952 | goto err; |
| 1953 | |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1954 | file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR), |
| 1955 | ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1956 | if (!file) |
| 1957 | goto err; |
| 1958 | |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1959 | file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR), |
| 1960 | ab8500_dir, &plf->dev, &ab8500_hwreg_fops); |
| 1961 | if (!file) |
| 1962 | goto err; |
| 1963 | |
| 1964 | file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR), |
| 1965 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops); |
| 1966 | if (!file) |
| 1967 | goto err; |
| 1968 | |
| 1969 | file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR), |
| 1970 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops); |
| 1971 | if (!file) |
| 1972 | goto err; |
| 1973 | |
| 1974 | file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR), |
| 1975 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops); |
| 1976 | if (!file) |
| 1977 | goto err; |
| 1978 | |
| 1979 | file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR), |
| 1980 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops); |
| 1981 | if (!file) |
| 1982 | goto err; |
| 1983 | |
| 1984 | file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR), |
| 1985 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops); |
| 1986 | if (!file) |
| 1987 | goto err; |
| 1988 | |
| 1989 | file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR), |
| 1990 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops); |
| 1991 | if (!file) |
| 1992 | goto err; |
| 1993 | |
| 1994 | file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR), |
| 1995 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops); |
| 1996 | if (!file) |
| 1997 | goto err; |
| 1998 | |
| 1999 | file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR), |
| 2000 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops); |
| 2001 | if (!file) |
| 2002 | goto err; |
| 2003 | |
| 2004 | file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR), |
| 2005 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops); |
| 2006 | if (!file) |
| 2007 | goto err; |
| 2008 | |
| 2009 | file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR), |
| 2010 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops); |
| 2011 | if (!file) |
| 2012 | goto err; |
| 2013 | |
| 2014 | file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR), |
| 2015 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops); |
| 2016 | if (!file) |
| 2017 | goto err; |
| 2018 | |
| 2019 | file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR), |
| 2020 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops); |
| 2021 | if (!file) |
| 2022 | goto err; |
| 2023 | |
| 2024 | file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR), |
| 2025 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2026 | if (!file) |
| 2027 | goto err; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2028 | |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2029 | file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUGO), |
| 2030 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops); |
| 2031 | if (!file) |
| 2032 | goto err; |
| 2033 | |
| 2034 | file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUGO), |
| 2035 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops); |
| 2036 | if (!file) |
| 2037 | goto err; |
| 2038 | |
| 2039 | file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUGO), |
| 2040 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops); |
| 2041 | if (!file) |
| 2042 | goto err; |
| 2043 | |
| 2044 | file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUGO), |
| 2045 | ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops); |
| 2046 | if (!file) |
| 2047 | goto err; |
| 2048 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 2049 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2050 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2051 | err: |
| 2052 | if (ab8500_dir) |
| 2053 | debugfs_remove_recursive(ab8500_dir); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 2054 | dev_err(&plf->dev, "failed to create debugfs entries.\n"); |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2055 | out_freeevent_name: |
| 2056 | kfree(event_name); |
| 2057 | out_freedev_attr: |
| 2058 | kfree(dev_attr); |
| 2059 | out_freeirq_count: |
| 2060 | kfree(irq_count); |
| 2061 | |
| 2062 | return ret; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2063 | } |
| 2064 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 2065 | static int ab8500_debug_remove(struct platform_device *plf) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2066 | { |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2067 | debugfs_remove_recursive(ab8500_dir); |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2068 | kfree(event_name); |
| 2069 | kfree(dev_attr); |
| 2070 | kfree(irq_count); |
| 2071 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 2072 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | static struct platform_driver ab8500_debug_driver = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 2076 | .driver = { |
| 2077 | .name = "ab8500-debug", |
| 2078 | .owner = THIS_MODULE, |
| 2079 | }, |
| 2080 | .probe = ab8500_debug_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 2081 | .remove = ab8500_debug_remove |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2082 | }; |
| 2083 | |
| 2084 | static int __init ab8500_debug_init(void) |
| 2085 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 2086 | return platform_driver_register(&ab8500_debug_driver); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | static void __exit ab8500_debug_exit(void) |
| 2090 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 2091 | platform_driver_unregister(&ab8500_debug_driver); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2092 | } |
| 2093 | subsys_initcall(ab8500_debug_init); |
| 2094 | module_exit(ab8500_debug_exit); |
| 2095 | |
| 2096 | MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com"); |
| 2097 | MODULE_DESCRIPTION("AB8500 DEBUG"); |
| 2098 | MODULE_LICENSE("GPL v2"); |