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