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