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