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 | 4b3f2b6 | 2016-10-29 21:24:37 -0400 | [diff] [blame] | 77 | #include <linux/init.h> |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 78 | #include <linux/debugfs.h> |
| 79 | #include <linux/platform_device.h> |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 80 | #include <linux/interrupt.h> |
| 81 | #include <linux/kobject.h> |
| 82 | #include <linux/slab.h> |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 83 | #include <linux/irq.h> |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 84 | |
| 85 | #include <linux/mfd/abx500.h> |
Linus Walleij | 0cd5b6d0 | 2013-02-06 23:23:01 +0100 | [diff] [blame] | 86 | #include <linux/mfd/abx500/ab8500.h> |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 87 | #include <linux/mfd/abx500/ab8500-gpadc.h> |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 88 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 89 | #ifdef CONFIG_DEBUG_FS |
| 90 | #include <linux/string.h> |
| 91 | #include <linux/ctype.h> |
| 92 | #endif |
| 93 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 94 | static u32 debug_bank; |
| 95 | static u32 debug_address; |
| 96 | |
Linus Walleij | 6999181 | 2013-04-12 17:02:09 +0200 | [diff] [blame] | 97 | static int irq_ab8500; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 98 | static int irq_first; |
| 99 | static int irq_last; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 100 | static u32 *irq_count; |
| 101 | static int num_irqs; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 102 | |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 103 | static struct device_attribute **dev_attr; |
| 104 | static char **event_name; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 105 | |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 106 | static u8 avg_sample = SAMPLE_16; |
| 107 | static u8 trig_edge = RISING_EDGE; |
| 108 | static u8 conv_type = ADC_SW; |
| 109 | static u8 trig_timer; |
| 110 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 111 | /** |
| 112 | * struct ab8500_reg_range |
| 113 | * @first: the first address of the range |
| 114 | * @last: the last address of the range |
| 115 | * @perm: access permissions for the range |
| 116 | */ |
| 117 | struct ab8500_reg_range { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 118 | u8 first; |
| 119 | u8 last; |
| 120 | u8 perm; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /** |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 124 | * struct ab8500_prcmu_ranges |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 125 | * @num_ranges: the number of ranges in the list |
| 126 | * @bankid: bank identifier |
| 127 | * @range: the list of register ranges |
| 128 | */ |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 129 | struct ab8500_prcmu_ranges { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 130 | u8 num_ranges; |
| 131 | u8 bankid; |
| 132 | const struct ab8500_reg_range *range; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 133 | }; |
| 134 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 135 | /* hwreg- "mask" and "shift" entries ressources */ |
| 136 | struct hwreg_cfg { |
| 137 | u32 bank; /* target bank */ |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 138 | unsigned long addr; /* target address */ |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 139 | uint fmt; /* format */ |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 140 | unsigned long mask; /* read/write mask, applied before any bit shift */ |
| 141 | long shift; /* bit shift (read:right shift, write:left shift */ |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 142 | }; |
| 143 | /* fmt bit #0: 0=hexa, 1=dec */ |
| 144 | #define REG_FMT_DEC(c) ((c)->fmt & 0x1) |
| 145 | #define REG_FMT_HEX(c) (!REG_FMT_DEC(c)) |
| 146 | |
| 147 | static struct hwreg_cfg hwreg_cfg = { |
| 148 | .addr = 0, /* default: invalid phys addr */ |
| 149 | .fmt = 0, /* default: 32bit access, hex output */ |
| 150 | .mask = 0xFFFFFFFF, /* default: no mask */ |
| 151 | .shift = 0, /* default: no bit shift */ |
| 152 | }; |
| 153 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 154 | #define AB8500_NAME_STRING "ab8500" |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 155 | #define AB8500_ADC_NAME_STRING "gpadc" |
Lee Jones | c45eab2 | 2016-09-14 11:14:30 +0100 | [diff] [blame] | 156 | #define AB8500_NUM_BANKS AB8500_DEBUG_FIELD_LAST |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 157 | |
| 158 | #define AB8500_REV_REG 0x80 |
| 159 | |
Lee Jones | 9581ae3 | 2012-07-06 16:11:50 +0200 | [diff] [blame] | 160 | static struct ab8500_prcmu_ranges *debug_ranges; |
| 161 | |
Sachin Kamat | 8455eae | 2013-08-23 17:37:42 +0530 | [diff] [blame] | 162 | static struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = { |
Lee Jones | c45eab2 | 2016-09-14 11:14:30 +0100 | [diff] [blame] | 163 | [AB8500_M_FSM_RANK] = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 164 | .num_ranges = 0, |
Lee Jones | fad55a8 | 2013-01-14 17:17:34 +0000 | [diff] [blame] | 165 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 166 | }, |
| 167 | [AB8500_SYS_CTRL1_BLOCK] = { |
| 168 | .num_ranges = 3, |
| 169 | .range = (struct ab8500_reg_range[]) { |
| 170 | { |
| 171 | .first = 0x00, |
| 172 | .last = 0x02, |
| 173 | }, |
| 174 | { |
| 175 | .first = 0x42, |
| 176 | .last = 0x42, |
| 177 | }, |
| 178 | { |
| 179 | .first = 0x80, |
| 180 | .last = 0x81, |
| 181 | }, |
| 182 | }, |
| 183 | }, |
| 184 | [AB8500_SYS_CTRL2_BLOCK] = { |
| 185 | .num_ranges = 4, |
| 186 | .range = (struct ab8500_reg_range[]) { |
| 187 | { |
| 188 | .first = 0x00, |
| 189 | .last = 0x0D, |
| 190 | }, |
| 191 | { |
| 192 | .first = 0x0F, |
| 193 | .last = 0x17, |
| 194 | }, |
| 195 | { |
| 196 | .first = 0x30, |
| 197 | .last = 0x30, |
| 198 | }, |
| 199 | { |
| 200 | .first = 0x32, |
| 201 | .last = 0x33, |
| 202 | }, |
| 203 | }, |
| 204 | }, |
| 205 | [AB8500_REGU_CTRL1] = { |
| 206 | .num_ranges = 3, |
| 207 | .range = (struct ab8500_reg_range[]) { |
| 208 | { |
| 209 | .first = 0x00, |
| 210 | .last = 0x00, |
| 211 | }, |
| 212 | { |
| 213 | .first = 0x03, |
| 214 | .last = 0x10, |
| 215 | }, |
| 216 | { |
| 217 | .first = 0x80, |
| 218 | .last = 0x84, |
| 219 | }, |
| 220 | }, |
| 221 | }, |
| 222 | [AB8500_REGU_CTRL2] = { |
| 223 | .num_ranges = 5, |
| 224 | .range = (struct ab8500_reg_range[]) { |
| 225 | { |
| 226 | .first = 0x00, |
| 227 | .last = 0x15, |
| 228 | }, |
| 229 | { |
| 230 | .first = 0x17, |
| 231 | .last = 0x19, |
| 232 | }, |
| 233 | { |
| 234 | .first = 0x1B, |
| 235 | .last = 0x1D, |
| 236 | }, |
| 237 | { |
| 238 | .first = 0x1F, |
| 239 | .last = 0x22, |
| 240 | }, |
| 241 | { |
| 242 | .first = 0x40, |
| 243 | .last = 0x44, |
| 244 | }, |
Lee Jones | de6a769 | 2015-10-28 09:27:32 +0000 | [diff] [blame] | 245 | /* |
| 246 | * 0x80-0x8B are SIM registers and should |
| 247 | * not be accessed from here |
| 248 | */ |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 249 | }, |
| 250 | }, |
| 251 | [AB8500_USB] = { |
| 252 | .num_ranges = 2, |
| 253 | .range = (struct ab8500_reg_range[]) { |
| 254 | { |
| 255 | .first = 0x80, |
| 256 | .last = 0x83, |
| 257 | }, |
| 258 | { |
| 259 | .first = 0x87, |
| 260 | .last = 0x8A, |
| 261 | }, |
| 262 | }, |
| 263 | }, |
| 264 | [AB8500_TVOUT] = { |
| 265 | .num_ranges = 9, |
| 266 | .range = (struct ab8500_reg_range[]) { |
| 267 | { |
| 268 | .first = 0x00, |
| 269 | .last = 0x12, |
| 270 | }, |
| 271 | { |
| 272 | .first = 0x15, |
| 273 | .last = 0x17, |
| 274 | }, |
| 275 | { |
| 276 | .first = 0x19, |
| 277 | .last = 0x21, |
| 278 | }, |
| 279 | { |
| 280 | .first = 0x27, |
| 281 | .last = 0x2C, |
| 282 | }, |
| 283 | { |
| 284 | .first = 0x41, |
| 285 | .last = 0x41, |
| 286 | }, |
| 287 | { |
| 288 | .first = 0x45, |
| 289 | .last = 0x5B, |
| 290 | }, |
| 291 | { |
| 292 | .first = 0x5D, |
| 293 | .last = 0x5D, |
| 294 | }, |
| 295 | { |
| 296 | .first = 0x69, |
| 297 | .last = 0x69, |
| 298 | }, |
| 299 | { |
| 300 | .first = 0x80, |
| 301 | .last = 0x81, |
| 302 | }, |
| 303 | }, |
| 304 | }, |
| 305 | [AB8500_DBI] = { |
| 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_ECI_AV_ACC] = { |
| 310 | .num_ranges = 1, |
| 311 | .range = (struct ab8500_reg_range[]) { |
| 312 | { |
| 313 | .first = 0x80, |
| 314 | .last = 0x82, |
| 315 | }, |
| 316 | }, |
| 317 | }, |
Lee Jones | c45eab2 | 2016-09-14 11:14:30 +0100 | [diff] [blame] | 318 | [AB8500_RESERVED] = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 319 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 320 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 321 | }, |
| 322 | [AB8500_GPADC] = { |
| 323 | .num_ranges = 1, |
| 324 | .range = (struct ab8500_reg_range[]) { |
| 325 | { |
| 326 | .first = 0x00, |
| 327 | .last = 0x08, |
| 328 | }, |
| 329 | }, |
| 330 | }, |
| 331 | [AB8500_CHARGER] = { |
Philippe Langlais | 40c064e | 2011-10-17 09:48:55 +0200 | [diff] [blame] | 332 | .num_ranges = 9, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 333 | .range = (struct ab8500_reg_range[]) { |
| 334 | { |
| 335 | .first = 0x00, |
| 336 | .last = 0x03, |
| 337 | }, |
| 338 | { |
| 339 | .first = 0x05, |
| 340 | .last = 0x05, |
| 341 | }, |
| 342 | { |
| 343 | .first = 0x40, |
| 344 | .last = 0x40, |
| 345 | }, |
| 346 | { |
| 347 | .first = 0x42, |
| 348 | .last = 0x42, |
| 349 | }, |
| 350 | { |
| 351 | .first = 0x44, |
| 352 | .last = 0x44, |
| 353 | }, |
| 354 | { |
| 355 | .first = 0x50, |
| 356 | .last = 0x55, |
| 357 | }, |
| 358 | { |
| 359 | .first = 0x80, |
| 360 | .last = 0x82, |
| 361 | }, |
| 362 | { |
| 363 | .first = 0xC0, |
| 364 | .last = 0xC2, |
| 365 | }, |
Philippe Langlais | 40c064e | 2011-10-17 09:48:55 +0200 | [diff] [blame] | 366 | { |
| 367 | .first = 0xf5, |
Lee Jones | 9581ae3 | 2012-07-06 16:11:50 +0200 | [diff] [blame] | 368 | .last = 0xf6, |
Philippe Langlais | 40c064e | 2011-10-17 09:48:55 +0200 | [diff] [blame] | 369 | }, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 370 | }, |
| 371 | }, |
| 372 | [AB8500_GAS_GAUGE] = { |
| 373 | .num_ranges = 3, |
| 374 | .range = (struct ab8500_reg_range[]) { |
| 375 | { |
| 376 | .first = 0x00, |
| 377 | .last = 0x00, |
| 378 | }, |
| 379 | { |
| 380 | .first = 0x07, |
| 381 | .last = 0x0A, |
| 382 | }, |
| 383 | { |
| 384 | .first = 0x10, |
| 385 | .last = 0x14, |
| 386 | }, |
| 387 | }, |
| 388 | }, |
| 389 | [AB8500_AUDIO] = { |
| 390 | .num_ranges = 1, |
| 391 | .range = (struct ab8500_reg_range[]) { |
| 392 | { |
| 393 | .first = 0x00, |
| 394 | .last = 0x6F, |
| 395 | }, |
| 396 | }, |
| 397 | }, |
| 398 | [AB8500_INTERRUPT] = { |
| 399 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 400 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 401 | }, |
| 402 | [AB8500_RTC] = { |
| 403 | .num_ranges = 1, |
| 404 | .range = (struct ab8500_reg_range[]) { |
| 405 | { |
| 406 | .first = 0x00, |
| 407 | .last = 0x0F, |
| 408 | }, |
| 409 | }, |
| 410 | }, |
| 411 | [AB8500_MISC] = { |
| 412 | .num_ranges = 8, |
| 413 | .range = (struct ab8500_reg_range[]) { |
| 414 | { |
| 415 | .first = 0x00, |
| 416 | .last = 0x05, |
| 417 | }, |
| 418 | { |
| 419 | .first = 0x10, |
| 420 | .last = 0x15, |
| 421 | }, |
| 422 | { |
| 423 | .first = 0x20, |
| 424 | .last = 0x25, |
| 425 | }, |
| 426 | { |
| 427 | .first = 0x30, |
| 428 | .last = 0x35, |
| 429 | }, |
| 430 | { |
| 431 | .first = 0x40, |
| 432 | .last = 0x45, |
| 433 | }, |
| 434 | { |
| 435 | .first = 0x50, |
| 436 | .last = 0x50, |
| 437 | }, |
| 438 | { |
| 439 | .first = 0x60, |
| 440 | .last = 0x67, |
| 441 | }, |
| 442 | { |
| 443 | .first = 0x80, |
| 444 | .last = 0x80, |
| 445 | }, |
| 446 | }, |
| 447 | }, |
Lee Jones | c45eab2 | 2016-09-14 11:14:30 +0100 | [diff] [blame] | 448 | [AB8500_DEVELOPMENT] = { |
| 449 | .num_ranges = 1, |
| 450 | .range = (struct ab8500_reg_range[]) { |
| 451 | { |
| 452 | .first = 0x00, |
| 453 | .last = 0x00, |
| 454 | }, |
| 455 | }, |
| 456 | }, |
| 457 | [AB8500_DEBUG] = { |
| 458 | .num_ranges = 1, |
| 459 | .range = (struct ab8500_reg_range[]) { |
| 460 | { |
| 461 | .first = 0x05, |
| 462 | .last = 0x07, |
| 463 | }, |
| 464 | }, |
| 465 | }, |
| 466 | [AB8500_PROD_TEST] = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 467 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 468 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 469 | }, |
Lee Jones | c45eab2 | 2016-09-14 11:14:30 +0100 | [diff] [blame] | 470 | [AB8500_STE_TEST] = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 471 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 472 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 473 | }, |
| 474 | [AB8500_OTP_EMUL] = { |
| 475 | .num_ranges = 1, |
| 476 | .range = (struct ab8500_reg_range[]) { |
| 477 | { |
| 478 | .first = 0x01, |
| 479 | .last = 0x0F, |
| 480 | }, |
| 481 | }, |
| 482 | }, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 483 | }; |
| 484 | |
Sachin Kamat | 8455eae | 2013-08-23 17:37:42 +0530 | [diff] [blame] | 485 | static struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = { |
Lee Jones | 9581ae3 | 2012-07-06 16:11:50 +0200 | [diff] [blame] | 486 | [0x0] = { |
| 487 | .num_ranges = 0, |
| 488 | .range = NULL, |
| 489 | }, |
| 490 | [AB8500_SYS_CTRL1_BLOCK] = { |
| 491 | .num_ranges = 5, |
| 492 | .range = (struct ab8500_reg_range[]) { |
| 493 | { |
| 494 | .first = 0x00, |
| 495 | .last = 0x04, |
| 496 | }, |
| 497 | { |
| 498 | .first = 0x42, |
| 499 | .last = 0x42, |
| 500 | }, |
| 501 | { |
| 502 | .first = 0x52, |
| 503 | .last = 0x52, |
| 504 | }, |
| 505 | { |
| 506 | .first = 0x54, |
| 507 | .last = 0x57, |
| 508 | }, |
| 509 | { |
| 510 | .first = 0x80, |
| 511 | .last = 0x83, |
| 512 | }, |
| 513 | }, |
| 514 | }, |
| 515 | [AB8500_SYS_CTRL2_BLOCK] = { |
| 516 | .num_ranges = 5, |
| 517 | .range = (struct ab8500_reg_range[]) { |
| 518 | { |
| 519 | .first = 0x00, |
| 520 | .last = 0x0D, |
| 521 | }, |
| 522 | { |
| 523 | .first = 0x0F, |
| 524 | .last = 0x17, |
| 525 | }, |
| 526 | { |
| 527 | .first = 0x20, |
| 528 | .last = 0x20, |
| 529 | }, |
| 530 | { |
| 531 | .first = 0x30, |
| 532 | .last = 0x30, |
| 533 | }, |
| 534 | { |
| 535 | .first = 0x32, |
| 536 | .last = 0x3A, |
| 537 | }, |
| 538 | }, |
| 539 | }, |
| 540 | [AB8500_REGU_CTRL1] = { |
| 541 | .num_ranges = 3, |
| 542 | .range = (struct ab8500_reg_range[]) { |
| 543 | { |
| 544 | .first = 0x00, |
| 545 | .last = 0x00, |
| 546 | }, |
| 547 | { |
| 548 | .first = 0x03, |
| 549 | .last = 0x11, |
| 550 | }, |
| 551 | { |
| 552 | .first = 0x80, |
| 553 | .last = 0x86, |
| 554 | }, |
| 555 | }, |
| 556 | }, |
| 557 | [AB8500_REGU_CTRL2] = { |
| 558 | .num_ranges = 6, |
| 559 | .range = (struct ab8500_reg_range[]) { |
| 560 | { |
| 561 | .first = 0x00, |
| 562 | .last = 0x06, |
| 563 | }, |
| 564 | { |
| 565 | .first = 0x08, |
| 566 | .last = 0x15, |
| 567 | }, |
| 568 | { |
| 569 | .first = 0x17, |
| 570 | .last = 0x19, |
| 571 | }, |
| 572 | { |
| 573 | .first = 0x1B, |
| 574 | .last = 0x1D, |
| 575 | }, |
| 576 | { |
| 577 | .first = 0x1F, |
| 578 | .last = 0x30, |
| 579 | }, |
| 580 | { |
| 581 | .first = 0x40, |
| 582 | .last = 0x48, |
| 583 | }, |
Lee Jones | de6a769 | 2015-10-28 09:27:32 +0000 | [diff] [blame] | 584 | /* |
| 585 | * 0x80-0x8B are SIM registers and should |
| 586 | * not be accessed from here |
| 587 | */ |
Lee Jones | 9581ae3 | 2012-07-06 16:11:50 +0200 | [diff] [blame] | 588 | }, |
| 589 | }, |
| 590 | [AB8500_USB] = { |
| 591 | .num_ranges = 3, |
| 592 | .range = (struct ab8500_reg_range[]) { |
| 593 | { |
| 594 | .first = 0x80, |
| 595 | .last = 0x83, |
| 596 | }, |
| 597 | { |
| 598 | .first = 0x87, |
| 599 | .last = 0x8A, |
| 600 | }, |
| 601 | { |
| 602 | .first = 0x91, |
| 603 | .last = 0x94, |
| 604 | }, |
| 605 | }, |
| 606 | }, |
| 607 | [AB8500_TVOUT] = { |
| 608 | .num_ranges = 0, |
| 609 | .range = NULL, |
| 610 | }, |
| 611 | [AB8500_DBI] = { |
| 612 | .num_ranges = 0, |
| 613 | .range = NULL, |
| 614 | }, |
| 615 | [AB8500_ECI_AV_ACC] = { |
| 616 | .num_ranges = 1, |
| 617 | .range = (struct ab8500_reg_range[]) { |
| 618 | { |
| 619 | .first = 0x80, |
| 620 | .last = 0x82, |
| 621 | }, |
| 622 | }, |
| 623 | }, |
| 624 | [AB8500_RESERVED] = { |
| 625 | .num_ranges = 0, |
| 626 | .range = NULL, |
| 627 | }, |
| 628 | [AB8500_GPADC] = { |
| 629 | .num_ranges = 1, |
| 630 | .range = (struct ab8500_reg_range[]) { |
| 631 | { |
| 632 | .first = 0x00, |
| 633 | .last = 0x08, |
| 634 | }, |
| 635 | }, |
| 636 | }, |
| 637 | [AB8500_CHARGER] = { |
| 638 | .num_ranges = 9, |
| 639 | .range = (struct ab8500_reg_range[]) { |
| 640 | { |
| 641 | .first = 0x02, |
| 642 | .last = 0x03, |
| 643 | }, |
| 644 | { |
| 645 | .first = 0x05, |
| 646 | .last = 0x05, |
| 647 | }, |
| 648 | { |
| 649 | .first = 0x40, |
| 650 | .last = 0x44, |
| 651 | }, |
| 652 | { |
| 653 | .first = 0x50, |
| 654 | .last = 0x57, |
| 655 | }, |
| 656 | { |
| 657 | .first = 0x60, |
| 658 | .last = 0x60, |
| 659 | }, |
| 660 | { |
| 661 | .first = 0xA0, |
| 662 | .last = 0xA7, |
| 663 | }, |
| 664 | { |
| 665 | .first = 0xAF, |
| 666 | .last = 0xB2, |
| 667 | }, |
| 668 | { |
| 669 | .first = 0xC0, |
| 670 | .last = 0xC2, |
| 671 | }, |
| 672 | { |
| 673 | .first = 0xF5, |
| 674 | .last = 0xF5, |
| 675 | }, |
| 676 | }, |
| 677 | }, |
| 678 | [AB8500_GAS_GAUGE] = { |
| 679 | .num_ranges = 3, |
| 680 | .range = (struct ab8500_reg_range[]) { |
| 681 | { |
| 682 | .first = 0x00, |
| 683 | .last = 0x00, |
| 684 | }, |
| 685 | { |
| 686 | .first = 0x07, |
| 687 | .last = 0x0A, |
| 688 | }, |
| 689 | { |
| 690 | .first = 0x10, |
| 691 | .last = 0x14, |
| 692 | }, |
| 693 | }, |
| 694 | }, |
| 695 | [AB8500_AUDIO] = { |
| 696 | .num_ranges = 1, |
| 697 | .range = (struct ab8500_reg_range[]) { |
| 698 | { |
| 699 | .first = 0x00, |
| 700 | .last = 0x83, |
| 701 | }, |
| 702 | }, |
| 703 | }, |
| 704 | [AB8500_INTERRUPT] = { |
| 705 | .num_ranges = 11, |
| 706 | .range = (struct ab8500_reg_range[]) { |
| 707 | { |
| 708 | .first = 0x00, |
| 709 | .last = 0x04, |
| 710 | }, |
| 711 | { |
| 712 | .first = 0x06, |
| 713 | .last = 0x07, |
| 714 | }, |
| 715 | { |
| 716 | .first = 0x09, |
| 717 | .last = 0x09, |
| 718 | }, |
| 719 | { |
| 720 | .first = 0x0B, |
| 721 | .last = 0x0C, |
| 722 | }, |
| 723 | { |
| 724 | .first = 0x12, |
| 725 | .last = 0x15, |
| 726 | }, |
| 727 | { |
| 728 | .first = 0x18, |
| 729 | .last = 0x18, |
| 730 | }, |
| 731 | /* Latch registers should not be read here */ |
| 732 | { |
| 733 | .first = 0x40, |
| 734 | .last = 0x44, |
| 735 | }, |
| 736 | { |
| 737 | .first = 0x46, |
| 738 | .last = 0x49, |
| 739 | }, |
| 740 | { |
| 741 | .first = 0x4B, |
| 742 | .last = 0x4D, |
| 743 | }, |
| 744 | { |
| 745 | .first = 0x52, |
| 746 | .last = 0x55, |
| 747 | }, |
| 748 | { |
| 749 | .first = 0x58, |
| 750 | .last = 0x58, |
| 751 | }, |
| 752 | /* LatchHier registers should not be read here */ |
| 753 | }, |
| 754 | }, |
| 755 | [AB8500_RTC] = { |
| 756 | .num_ranges = 2, |
| 757 | .range = (struct ab8500_reg_range[]) { |
| 758 | { |
| 759 | .first = 0x00, |
| 760 | .last = 0x14, |
| 761 | }, |
| 762 | { |
| 763 | .first = 0x16, |
| 764 | .last = 0x17, |
| 765 | }, |
| 766 | }, |
| 767 | }, |
| 768 | [AB8500_MISC] = { |
| 769 | .num_ranges = 8, |
| 770 | .range = (struct ab8500_reg_range[]) { |
| 771 | { |
| 772 | .first = 0x00, |
| 773 | .last = 0x06, |
| 774 | }, |
| 775 | { |
| 776 | .first = 0x10, |
| 777 | .last = 0x16, |
| 778 | }, |
| 779 | { |
| 780 | .first = 0x20, |
| 781 | .last = 0x26, |
| 782 | }, |
| 783 | { |
| 784 | .first = 0x30, |
| 785 | .last = 0x36, |
| 786 | }, |
| 787 | { |
| 788 | .first = 0x40, |
| 789 | .last = 0x46, |
| 790 | }, |
| 791 | { |
| 792 | .first = 0x50, |
| 793 | .last = 0x50, |
| 794 | }, |
| 795 | { |
| 796 | .first = 0x60, |
| 797 | .last = 0x6B, |
| 798 | }, |
| 799 | { |
| 800 | .first = 0x80, |
| 801 | .last = 0x82, |
| 802 | }, |
| 803 | }, |
| 804 | }, |
| 805 | [AB8500_DEVELOPMENT] = { |
| 806 | .num_ranges = 2, |
| 807 | .range = (struct ab8500_reg_range[]) { |
| 808 | { |
| 809 | .first = 0x00, |
| 810 | .last = 0x00, |
| 811 | }, |
| 812 | { |
| 813 | .first = 0x05, |
| 814 | .last = 0x05, |
| 815 | }, |
| 816 | }, |
| 817 | }, |
| 818 | [AB8500_DEBUG] = { |
| 819 | .num_ranges = 1, |
| 820 | .range = (struct ab8500_reg_range[]) { |
| 821 | { |
| 822 | .first = 0x05, |
| 823 | .last = 0x07, |
| 824 | }, |
| 825 | }, |
| 826 | }, |
| 827 | [AB8500_PROD_TEST] = { |
| 828 | .num_ranges = 0, |
| 829 | .range = NULL, |
| 830 | }, |
| 831 | [AB8500_STE_TEST] = { |
| 832 | .num_ranges = 0, |
| 833 | .range = NULL, |
| 834 | }, |
| 835 | [AB8500_OTP_EMUL] = { |
| 836 | .num_ranges = 1, |
| 837 | .range = (struct ab8500_reg_range[]) { |
| 838 | { |
| 839 | .first = 0x01, |
| 840 | .last = 0x15, |
| 841 | }, |
| 842 | }, |
| 843 | }, |
| 844 | }; |
| 845 | |
Sachin Kamat | 8455eae | 2013-08-23 17:37:42 +0530 | [diff] [blame] | 846 | static struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = { |
Lee Jones | 971480f | 2012-11-19 12:20:03 +0100 | [diff] [blame] | 847 | [AB8500_M_FSM_RANK] = { |
| 848 | .num_ranges = 1, |
| 849 | .range = (struct ab8500_reg_range[]) { |
| 850 | { |
| 851 | .first = 0x00, |
| 852 | .last = 0x0B, |
| 853 | }, |
| 854 | }, |
| 855 | }, |
| 856 | [AB8500_SYS_CTRL1_BLOCK] = { |
| 857 | .num_ranges = 6, |
| 858 | .range = (struct ab8500_reg_range[]) { |
| 859 | { |
| 860 | .first = 0x00, |
| 861 | .last = 0x04, |
| 862 | }, |
| 863 | { |
| 864 | .first = 0x42, |
| 865 | .last = 0x42, |
| 866 | }, |
| 867 | { |
| 868 | .first = 0x50, |
| 869 | .last = 0x54, |
| 870 | }, |
| 871 | { |
| 872 | .first = 0x57, |
| 873 | .last = 0x57, |
| 874 | }, |
| 875 | { |
| 876 | .first = 0x80, |
| 877 | .last = 0x83, |
| 878 | }, |
| 879 | { |
| 880 | .first = 0x90, |
| 881 | .last = 0x90, |
| 882 | }, |
| 883 | }, |
| 884 | }, |
| 885 | [AB8500_SYS_CTRL2_BLOCK] = { |
| 886 | .num_ranges = 5, |
| 887 | .range = (struct ab8500_reg_range[]) { |
| 888 | { |
| 889 | .first = 0x00, |
| 890 | .last = 0x0D, |
| 891 | }, |
| 892 | { |
| 893 | .first = 0x0F, |
| 894 | .last = 0x10, |
| 895 | }, |
| 896 | { |
| 897 | .first = 0x20, |
| 898 | .last = 0x21, |
| 899 | }, |
| 900 | { |
| 901 | .first = 0x32, |
| 902 | .last = 0x3C, |
| 903 | }, |
| 904 | { |
| 905 | .first = 0x40, |
| 906 | .last = 0x42, |
| 907 | }, |
| 908 | }, |
| 909 | }, |
| 910 | [AB8500_REGU_CTRL1] = { |
| 911 | .num_ranges = 4, |
| 912 | .range = (struct ab8500_reg_range[]) { |
| 913 | { |
| 914 | .first = 0x03, |
| 915 | .last = 0x15, |
| 916 | }, |
| 917 | { |
| 918 | .first = 0x20, |
| 919 | .last = 0x20, |
| 920 | }, |
| 921 | { |
| 922 | .first = 0x80, |
| 923 | .last = 0x85, |
| 924 | }, |
| 925 | { |
| 926 | .first = 0x87, |
| 927 | .last = 0x88, |
| 928 | }, |
| 929 | }, |
| 930 | }, |
| 931 | [AB8500_REGU_CTRL2] = { |
| 932 | .num_ranges = 8, |
| 933 | .range = (struct ab8500_reg_range[]) { |
| 934 | { |
| 935 | .first = 0x00, |
| 936 | .last = 0x06, |
| 937 | }, |
| 938 | { |
| 939 | .first = 0x08, |
| 940 | .last = 0x15, |
| 941 | }, |
| 942 | { |
| 943 | .first = 0x17, |
| 944 | .last = 0x19, |
| 945 | }, |
| 946 | { |
| 947 | .first = 0x1B, |
| 948 | .last = 0x1D, |
| 949 | }, |
| 950 | { |
| 951 | .first = 0x1F, |
| 952 | .last = 0x2F, |
| 953 | }, |
| 954 | { |
| 955 | .first = 0x31, |
| 956 | .last = 0x3A, |
| 957 | }, |
| 958 | { |
| 959 | .first = 0x43, |
| 960 | .last = 0x44, |
| 961 | }, |
| 962 | { |
| 963 | .first = 0x48, |
| 964 | .last = 0x49, |
| 965 | }, |
| 966 | }, |
| 967 | }, |
| 968 | [AB8500_USB] = { |
| 969 | .num_ranges = 3, |
| 970 | .range = (struct ab8500_reg_range[]) { |
| 971 | { |
| 972 | .first = 0x80, |
| 973 | .last = 0x83, |
| 974 | }, |
| 975 | { |
| 976 | .first = 0x87, |
| 977 | .last = 0x8A, |
| 978 | }, |
| 979 | { |
| 980 | .first = 0x91, |
| 981 | .last = 0x94, |
| 982 | }, |
| 983 | }, |
| 984 | }, |
| 985 | [AB8500_TVOUT] = { |
| 986 | .num_ranges = 0, |
| 987 | .range = NULL |
| 988 | }, |
| 989 | [AB8500_DBI] = { |
| 990 | .num_ranges = 4, |
| 991 | .range = (struct ab8500_reg_range[]) { |
| 992 | { |
| 993 | .first = 0x00, |
| 994 | .last = 0x07, |
| 995 | }, |
| 996 | { |
| 997 | .first = 0x10, |
| 998 | .last = 0x11, |
| 999 | }, |
| 1000 | { |
| 1001 | .first = 0x20, |
| 1002 | .last = 0x21, |
| 1003 | }, |
| 1004 | { |
| 1005 | .first = 0x30, |
| 1006 | .last = 0x43, |
| 1007 | }, |
| 1008 | }, |
| 1009 | }, |
| 1010 | [AB8500_ECI_AV_ACC] = { |
| 1011 | .num_ranges = 2, |
| 1012 | .range = (struct ab8500_reg_range[]) { |
| 1013 | { |
| 1014 | .first = 0x00, |
| 1015 | .last = 0x03, |
| 1016 | }, |
| 1017 | { |
| 1018 | .first = 0x80, |
| 1019 | .last = 0x82, |
| 1020 | }, |
| 1021 | }, |
| 1022 | }, |
| 1023 | [AB8500_RESERVED] = { |
| 1024 | .num_ranges = 0, |
| 1025 | .range = NULL, |
| 1026 | }, |
| 1027 | [AB8500_GPADC] = { |
| 1028 | .num_ranges = 4, |
| 1029 | .range = (struct ab8500_reg_range[]) { |
| 1030 | { |
| 1031 | .first = 0x00, |
| 1032 | .last = 0x01, |
| 1033 | }, |
| 1034 | { |
| 1035 | .first = 0x04, |
| 1036 | .last = 0x06, |
| 1037 | }, |
| 1038 | { |
| 1039 | .first = 0x09, |
| 1040 | .last = 0x0A, |
| 1041 | }, |
| 1042 | { |
| 1043 | .first = 0x10, |
| 1044 | .last = 0x14, |
| 1045 | }, |
| 1046 | }, |
| 1047 | }, |
| 1048 | [AB8500_CHARGER] = { |
| 1049 | .num_ranges = 10, |
| 1050 | .range = (struct ab8500_reg_range[]) { |
| 1051 | { |
| 1052 | .first = 0x00, |
| 1053 | .last = 0x00, |
| 1054 | }, |
| 1055 | { |
| 1056 | .first = 0x02, |
| 1057 | .last = 0x05, |
| 1058 | }, |
| 1059 | { |
| 1060 | .first = 0x40, |
| 1061 | .last = 0x44, |
| 1062 | }, |
| 1063 | { |
| 1064 | .first = 0x50, |
| 1065 | .last = 0x57, |
| 1066 | }, |
| 1067 | { |
| 1068 | .first = 0x60, |
| 1069 | .last = 0x60, |
| 1070 | }, |
| 1071 | { |
| 1072 | .first = 0x70, |
| 1073 | .last = 0x70, |
| 1074 | }, |
| 1075 | { |
| 1076 | .first = 0xA0, |
| 1077 | .last = 0xA9, |
| 1078 | }, |
| 1079 | { |
| 1080 | .first = 0xAF, |
| 1081 | .last = 0xB2, |
| 1082 | }, |
| 1083 | { |
| 1084 | .first = 0xC0, |
| 1085 | .last = 0xC6, |
| 1086 | }, |
| 1087 | { |
| 1088 | .first = 0xF5, |
| 1089 | .last = 0xF5, |
| 1090 | }, |
| 1091 | }, |
| 1092 | }, |
| 1093 | [AB8500_GAS_GAUGE] = { |
| 1094 | .num_ranges = 3, |
| 1095 | .range = (struct ab8500_reg_range[]) { |
| 1096 | { |
| 1097 | .first = 0x00, |
| 1098 | .last = 0x00, |
| 1099 | }, |
| 1100 | { |
| 1101 | .first = 0x07, |
| 1102 | .last = 0x0A, |
| 1103 | }, |
| 1104 | { |
| 1105 | .first = 0x10, |
| 1106 | .last = 0x14, |
| 1107 | }, |
| 1108 | }, |
| 1109 | }, |
| 1110 | [AB8500_AUDIO] = { |
| 1111 | .num_ranges = 1, |
| 1112 | .range = (struct ab8500_reg_range[]) { |
| 1113 | { |
| 1114 | .first = 0x00, |
| 1115 | .last = 0x9f, |
| 1116 | }, |
| 1117 | }, |
| 1118 | }, |
| 1119 | [AB8500_INTERRUPT] = { |
| 1120 | .num_ranges = 6, |
| 1121 | .range = (struct ab8500_reg_range[]) { |
| 1122 | { |
| 1123 | .first = 0x00, |
| 1124 | .last = 0x05, |
| 1125 | }, |
| 1126 | { |
| 1127 | .first = 0x0B, |
| 1128 | .last = 0x0D, |
| 1129 | }, |
| 1130 | { |
| 1131 | .first = 0x12, |
| 1132 | .last = 0x20, |
| 1133 | }, |
| 1134 | /* Latch registers should not be read here */ |
| 1135 | { |
| 1136 | .first = 0x40, |
| 1137 | .last = 0x45, |
| 1138 | }, |
| 1139 | { |
| 1140 | .first = 0x4B, |
| 1141 | .last = 0x4D, |
| 1142 | }, |
| 1143 | { |
| 1144 | .first = 0x52, |
| 1145 | .last = 0x60, |
| 1146 | }, |
| 1147 | /* LatchHier registers should not be read here */ |
| 1148 | }, |
| 1149 | }, |
| 1150 | [AB8500_RTC] = { |
| 1151 | .num_ranges = 3, |
| 1152 | .range = (struct ab8500_reg_range[]) { |
| 1153 | { |
| 1154 | .first = 0x00, |
| 1155 | .last = 0x07, |
| 1156 | }, |
| 1157 | { |
| 1158 | .first = 0x0B, |
| 1159 | .last = 0x18, |
| 1160 | }, |
| 1161 | { |
| 1162 | .first = 0x20, |
| 1163 | .last = 0x25, |
| 1164 | }, |
| 1165 | }, |
| 1166 | }, |
| 1167 | [AB8500_MISC] = { |
| 1168 | .num_ranges = 9, |
| 1169 | .range = (struct ab8500_reg_range[]) { |
| 1170 | { |
| 1171 | .first = 0x00, |
| 1172 | .last = 0x06, |
| 1173 | }, |
| 1174 | { |
| 1175 | .first = 0x10, |
| 1176 | .last = 0x16, |
| 1177 | }, |
| 1178 | { |
| 1179 | .first = 0x20, |
| 1180 | .last = 0x26, |
| 1181 | }, |
| 1182 | { |
| 1183 | .first = 0x30, |
| 1184 | .last = 0x36, |
| 1185 | }, |
| 1186 | { |
| 1187 | .first = 0x40, |
| 1188 | .last = 0x49, |
| 1189 | }, |
| 1190 | { |
| 1191 | .first = 0x50, |
| 1192 | .last = 0x50, |
| 1193 | }, |
| 1194 | { |
| 1195 | .first = 0x60, |
| 1196 | .last = 0x6B, |
| 1197 | }, |
| 1198 | { |
| 1199 | .first = 0x70, |
| 1200 | .last = 0x74, |
| 1201 | }, |
| 1202 | { |
| 1203 | .first = 0x80, |
| 1204 | .last = 0x82, |
| 1205 | }, |
| 1206 | }, |
| 1207 | }, |
| 1208 | [AB8500_DEVELOPMENT] = { |
| 1209 | .num_ranges = 3, |
| 1210 | .range = (struct ab8500_reg_range[]) { |
| 1211 | { |
| 1212 | .first = 0x00, |
| 1213 | .last = 0x01, |
| 1214 | }, |
| 1215 | { |
| 1216 | .first = 0x06, |
| 1217 | .last = 0x06, |
| 1218 | }, |
| 1219 | { |
| 1220 | .first = 0x10, |
| 1221 | .last = 0x21, |
| 1222 | }, |
| 1223 | }, |
| 1224 | }, |
| 1225 | [AB8500_DEBUG] = { |
| 1226 | .num_ranges = 3, |
| 1227 | .range = (struct ab8500_reg_range[]) { |
| 1228 | { |
| 1229 | .first = 0x01, |
| 1230 | .last = 0x0C, |
| 1231 | }, |
| 1232 | { |
| 1233 | .first = 0x0E, |
| 1234 | .last = 0x11, |
| 1235 | }, |
| 1236 | { |
| 1237 | .first = 0x80, |
| 1238 | .last = 0x81, |
| 1239 | }, |
| 1240 | }, |
| 1241 | }, |
| 1242 | [AB8500_PROD_TEST] = { |
| 1243 | .num_ranges = 0, |
| 1244 | .range = NULL, |
| 1245 | }, |
| 1246 | [AB8500_STE_TEST] = { |
| 1247 | .num_ranges = 0, |
| 1248 | .range = NULL, |
| 1249 | }, |
| 1250 | [AB8500_OTP_EMUL] = { |
| 1251 | .num_ranges = 1, |
| 1252 | .range = (struct ab8500_reg_range[]) { |
| 1253 | { |
| 1254 | .first = 0x00, |
| 1255 | .last = 0x3F, |
| 1256 | }, |
| 1257 | }, |
| 1258 | }, |
| 1259 | }; |
| 1260 | |
| 1261 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1262 | static irqreturn_t ab8500_debug_handler(int irq, void *data) |
| 1263 | { |
| 1264 | char buf[16]; |
| 1265 | struct kobject *kobj = (struct kobject *)data; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1266 | unsigned int irq_abb = irq - irq_first; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1267 | |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 1268 | if (irq_abb < num_irqs) |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1269 | irq_count[irq_abb]++; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1270 | /* |
| 1271 | * This makes it possible to use poll for events (POLLPRI | POLLERR) |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1272 | * from userspace on sysfs file named <irq-nr> |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1273 | */ |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 1274 | sprintf(buf, "%d", irq); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 1275 | sysfs_notify(kobj, NULL, buf); |
| 1276 | |
| 1277 | return IRQ_HANDLED; |
| 1278 | } |
| 1279 | |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1280 | /* Prints to seq_file or log_buf */ |
| 1281 | static int ab8500_registers_print(struct device *dev, u32 bank, |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1282 | struct seq_file *s) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1283 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1284 | unsigned int i; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1285 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1286 | for (i = 0; i < debug_ranges[bank].num_ranges; i++) { |
| 1287 | u32 reg; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1288 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1289 | for (reg = debug_ranges[bank].range[i].first; |
| 1290 | reg <= debug_ranges[bank].range[i].last; |
| 1291 | reg++) { |
| 1292 | u8 value; |
| 1293 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1294 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1295 | err = abx500_get_register_interruptible(dev, |
| 1296 | (u8)bank, (u8)reg, &value); |
| 1297 | if (err < 0) { |
| 1298 | dev_err(dev, "ab->read fail %d\n", err); |
| 1299 | return err; |
| 1300 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1301 | |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1302 | if (s) { |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1303 | seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", |
| 1304 | bank, reg, value); |
Lee Jones | de6a769 | 2015-10-28 09:27:32 +0000 | [diff] [blame] | 1305 | /* |
| 1306 | * Error is not returned here since |
| 1307 | * the output is wanted in any case |
| 1308 | */ |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1309 | if (seq_has_overflowed(s)) |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1310 | return 0; |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1311 | } else { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 1312 | dev_info(dev, " [0x%02X/0x%02X]: 0x%02X\n", |
| 1313 | bank, reg, value); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | } |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1317 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1318 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1319 | } |
| 1320 | |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1321 | static int ab8500_print_bank_registers(struct seq_file *s, void *p) |
| 1322 | { |
| 1323 | struct device *dev = s->private; |
| 1324 | u32 bank = debug_bank; |
| 1325 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 1326 | seq_puts(s, AB8500_NAME_STRING " register values:\n"); |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1327 | |
Mattias Wallin | cfc0849 | 2012-05-28 15:53:58 +0200 | [diff] [blame] | 1328 | seq_printf(s, " bank 0x%02X:\n", bank); |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1329 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1330 | return ab8500_registers_print(dev, bank, s); |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1331 | } |
| 1332 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1333 | static int ab8500_registers_open(struct inode *inode, struct file *file) |
| 1334 | { |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1335 | return single_open(file, ab8500_print_bank_registers, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | static const struct file_operations ab8500_registers_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1339 | .open = ab8500_registers_open, |
| 1340 | .read = seq_read, |
| 1341 | .llseek = seq_lseek, |
| 1342 | .release = single_release, |
| 1343 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1344 | }; |
| 1345 | |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1346 | static int ab8500_print_all_banks(struct seq_file *s, void *p) |
| 1347 | { |
| 1348 | struct device *dev = s->private; |
| 1349 | unsigned int i; |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1350 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 1351 | seq_puts(s, AB8500_NAME_STRING " register values:\n"); |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1352 | |
Lee Jones | 971480f | 2012-11-19 12:20:03 +0100 | [diff] [blame] | 1353 | for (i = 0; i < AB8500_NUM_BANKS; i++) { |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1354 | int err; |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1355 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1356 | seq_printf(s, " bank 0x%02X:\n", i); |
| 1357 | err = ab8500_registers_print(dev, i, s); |
| 1358 | if (err) |
| 1359 | return err; |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1360 | } |
| 1361 | return 0; |
| 1362 | } |
| 1363 | |
Mian Yousaf Kaukab | 1d843a6 | 2012-01-27 11:35:41 +0100 | [diff] [blame] | 1364 | /* Dump registers to kernel log */ |
| 1365 | void ab8500_dump_all_banks(struct device *dev) |
| 1366 | { |
| 1367 | unsigned int i; |
| 1368 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 1369 | dev_info(dev, "ab8500 register values:\n"); |
Mian Yousaf Kaukab | 1d843a6 | 2012-01-27 11:35:41 +0100 | [diff] [blame] | 1370 | |
| 1371 | for (i = 1; i < AB8500_NUM_BANKS; i++) { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 1372 | dev_info(dev, " bank 0x%02X:\n", i); |
Mian Yousaf Kaukab | 1d843a6 | 2012-01-27 11:35:41 +0100 | [diff] [blame] | 1373 | ab8500_registers_print(dev, i, NULL); |
| 1374 | } |
| 1375 | } |
| 1376 | |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 1377 | static int ab8500_all_banks_open(struct inode *inode, struct file *file) |
| 1378 | { |
| 1379 | struct seq_file *s; |
| 1380 | int err; |
| 1381 | |
| 1382 | err = single_open(file, ab8500_print_all_banks, inode->i_private); |
| 1383 | if (!err) { |
| 1384 | /* Default buf size in seq_read is not enough */ |
| 1385 | s = (struct seq_file *)file->private_data; |
| 1386 | s->size = (PAGE_SIZE * 2); |
| 1387 | s->buf = kmalloc(s->size, GFP_KERNEL); |
| 1388 | if (!s->buf) { |
| 1389 | single_release(inode, file); |
| 1390 | err = -ENOMEM; |
| 1391 | } |
| 1392 | } |
| 1393 | return err; |
| 1394 | } |
| 1395 | |
| 1396 | static const struct file_operations ab8500_all_banks_fops = { |
| 1397 | .open = ab8500_all_banks_open, |
| 1398 | .read = seq_read, |
| 1399 | .llseek = seq_lseek, |
| 1400 | .release = single_release, |
| 1401 | .owner = THIS_MODULE, |
| 1402 | }; |
| 1403 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1404 | static int ab8500_bank_print(struct seq_file *s, void *p) |
| 1405 | { |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1406 | seq_printf(s, "0x%02X\n", debug_bank); |
| 1407 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | static int ab8500_bank_open(struct inode *inode, struct file *file) |
| 1411 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1412 | return single_open(file, ab8500_bank_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | static ssize_t ab8500_bank_write(struct file *file, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1416 | const char __user *user_buf, |
| 1417 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1418 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1419 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1420 | unsigned long user_bank; |
| 1421 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1422 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 1423 | err = kstrtoul_from_user(user_buf, count, 0, &user_bank); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1424 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 1425 | return err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1426 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1427 | if (user_bank >= AB8500_NUM_BANKS) { |
| 1428 | dev_err(dev, "debugfs error input > number of banks\n"); |
| 1429 | return -EINVAL; |
| 1430 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1431 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1432 | debug_bank = user_bank; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1433 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 1434 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | static int ab8500_address_print(struct seq_file *s, void *p) |
| 1438 | { |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1439 | seq_printf(s, "0x%02X\n", debug_address); |
| 1440 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | static int ab8500_address_open(struct inode *inode, struct file *file) |
| 1444 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1445 | return single_open(file, ab8500_address_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | static ssize_t ab8500_address_write(struct file *file, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 1449 | const char __user *user_buf, |
| 1450 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1451 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1452 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1453 | unsigned long user_address; |
| 1454 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1455 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 1456 | err = kstrtoul_from_user(user_buf, count, 0, &user_address); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1457 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 1458 | return err; |
| 1459 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1460 | if (user_address > 0xff) { |
| 1461 | dev_err(dev, "debugfs error input > 0xff\n"); |
| 1462 | return -EINVAL; |
| 1463 | } |
| 1464 | debug_address = user_address; |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 1465 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 1466 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | static int ab8500_val_print(struct seq_file *s, void *p) |
| 1470 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1471 | struct device *dev = s->private; |
| 1472 | int ret; |
| 1473 | u8 regvalue; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1474 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1475 | ret = abx500_get_register_interruptible(dev, |
| 1476 | (u8)debug_bank, (u8)debug_address, ®value); |
| 1477 | if (ret < 0) { |
| 1478 | dev_err(dev, "abx500_get_reg fail %d, %d\n", |
| 1479 | ret, __LINE__); |
| 1480 | return -EINVAL; |
| 1481 | } |
| 1482 | seq_printf(s, "0x%02X\n", regvalue); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1483 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1484 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | static int ab8500_val_open(struct inode *inode, struct file *file) |
| 1488 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1489 | return single_open(file, ab8500_val_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | static ssize_t ab8500_val_write(struct file *file, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 1493 | const char __user *user_buf, |
| 1494 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1495 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1496 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1497 | unsigned long user_val; |
| 1498 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1499 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 1500 | err = kstrtoul_from_user(user_buf, count, 0, &user_val); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1501 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 1502 | return err; |
| 1503 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1504 | if (user_val > 0xff) { |
| 1505 | dev_err(dev, "debugfs error input > 0xff\n"); |
| 1506 | return -EINVAL; |
| 1507 | } |
| 1508 | err = abx500_set_register_interruptible(dev, |
| 1509 | (u8)debug_bank, debug_address, (u8)user_val); |
| 1510 | if (err < 0) { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 1511 | pr_err("abx500_set_reg failed %d, %d", err, __LINE__); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 1512 | return -EINVAL; |
| 1513 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1514 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 1515 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 1516 | } |
| 1517 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1518 | /* |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 1519 | * Interrupt status |
| 1520 | */ |
| 1521 | static u32 num_interrupts[AB8500_MAX_NR_IRQS]; |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 1522 | static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS]; |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 1523 | static int num_interrupt_lines; |
| 1524 | |
| 1525 | void ab8500_debug_register_interrupt(int line) |
| 1526 | { |
Lee Jones | 364c517 | 2016-09-14 11:56:34 +0100 | [diff] [blame] | 1527 | if (line < num_interrupt_lines) |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 1528 | num_interrupts[line]++; |
| 1529 | } |
| 1530 | |
| 1531 | static int ab8500_interrupts_print(struct seq_file *s, void *p) |
| 1532 | { |
| 1533 | int line; |
| 1534 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 1535 | seq_puts(s, "name: number: number of: wake:\n"); |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 1536 | |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 1537 | for (line = 0; line < num_interrupt_lines; line++) { |
| 1538 | struct irq_desc *desc = irq_to_desc(line + irq_first); |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 1539 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1540 | seq_printf(s, "%3i: %6i %4i", |
| 1541 | line, |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 1542 | num_interrupts[line], |
| 1543 | num_wake_interrupts[line]); |
| 1544 | |
| 1545 | if (desc && desc->name) |
| 1546 | seq_printf(s, "-%-8s", desc->name); |
Dan Carpenter | 7c0b238 | 2013-11-13 10:40:30 +0300 | [diff] [blame] | 1547 | if (desc && desc->action) { |
| 1548 | struct irqaction *action = desc->action; |
| 1549 | |
Jonas Aaberg | 2cf64e2 | 2012-05-31 07:57:07 +0200 | [diff] [blame] | 1550 | seq_printf(s, " %s", action->name); |
| 1551 | while ((action = action->next) != NULL) |
| 1552 | seq_printf(s, ", %s", action->name); |
| 1553 | } |
| 1554 | seq_putc(s, '\n'); |
| 1555 | } |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 1556 | |
| 1557 | return 0; |
| 1558 | } |
| 1559 | |
| 1560 | static int ab8500_interrupts_open(struct inode *inode, struct file *file) |
| 1561 | { |
| 1562 | return single_open(file, ab8500_interrupts_print, inode->i_private); |
| 1563 | } |
| 1564 | |
| 1565 | /* |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 1566 | * - HWREG DB8500 formated routines |
| 1567 | */ |
| 1568 | static int ab8500_hwreg_print(struct seq_file *s, void *d) |
| 1569 | { |
| 1570 | struct device *dev = s->private; |
| 1571 | int ret; |
| 1572 | u8 regvalue; |
| 1573 | |
| 1574 | ret = abx500_get_register_interruptible(dev, |
| 1575 | (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, ®value); |
| 1576 | if (ret < 0) { |
| 1577 | dev_err(dev, "abx500_get_reg fail %d, %d\n", |
| 1578 | ret, __LINE__); |
| 1579 | return -EINVAL; |
| 1580 | } |
| 1581 | |
| 1582 | if (hwreg_cfg.shift >= 0) |
| 1583 | regvalue >>= hwreg_cfg.shift; |
| 1584 | else |
| 1585 | regvalue <<= -hwreg_cfg.shift; |
| 1586 | regvalue &= hwreg_cfg.mask; |
| 1587 | |
| 1588 | if (REG_FMT_DEC(&hwreg_cfg)) |
| 1589 | seq_printf(s, "%d\n", regvalue); |
| 1590 | else |
| 1591 | seq_printf(s, "0x%02X\n", regvalue); |
| 1592 | return 0; |
| 1593 | } |
| 1594 | |
| 1595 | static int ab8500_hwreg_open(struct inode *inode, struct file *file) |
| 1596 | { |
| 1597 | return single_open(file, ab8500_hwreg_print, inode->i_private); |
| 1598 | } |
| 1599 | |
Lee Jones | c7ebaee | 2013-02-26 14:03:33 +0000 | [diff] [blame] | 1600 | #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01 |
| 1601 | #define AB8500_SUPPLY_CONTROL_REG 0x00 |
| 1602 | #define AB8500_FIRST_SIM_REG 0x80 |
| 1603 | #define AB8500_LAST_SIM_REG 0x8B |
| 1604 | #define AB8505_LAST_SIM_REG 0x8C |
| 1605 | |
| 1606 | static int ab8500_print_modem_registers(struct seq_file *s, void *p) |
| 1607 | { |
| 1608 | struct device *dev = s->private; |
| 1609 | struct ab8500 *ab8500; |
| 1610 | int err; |
| 1611 | u8 value; |
| 1612 | u8 orig_value; |
| 1613 | u32 bank = AB8500_REGU_CTRL2; |
| 1614 | u32 last_sim_reg = AB8500_LAST_SIM_REG; |
| 1615 | u32 reg; |
| 1616 | |
| 1617 | ab8500 = dev_get_drvdata(dev->parent); |
| 1618 | dev_warn(dev, "WARNING! This operation can interfer with modem side\n" |
| 1619 | "and should only be done with care\n"); |
| 1620 | |
| 1621 | err = abx500_get_register_interruptible(dev, |
| 1622 | AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value); |
| 1623 | if (err < 0) { |
| 1624 | dev_err(dev, "ab->read fail %d\n", err); |
| 1625 | return err; |
| 1626 | } |
| 1627 | /* Config 1 will allow APE side to read SIM registers */ |
| 1628 | err = abx500_set_register_interruptible(dev, |
| 1629 | AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, |
| 1630 | AB8500_SUPPLY_CONTROL_CONFIG_1); |
| 1631 | if (err < 0) { |
| 1632 | dev_err(dev, "ab->write fail %d\n", err); |
| 1633 | return err; |
| 1634 | } |
| 1635 | |
| 1636 | seq_printf(s, " bank 0x%02X:\n", bank); |
| 1637 | |
| 1638 | if (is_ab9540(ab8500) || is_ab8505(ab8500)) |
| 1639 | last_sim_reg = AB8505_LAST_SIM_REG; |
| 1640 | |
| 1641 | for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) { |
| 1642 | err = abx500_get_register_interruptible(dev, |
| 1643 | bank, reg, &value); |
| 1644 | if (err < 0) { |
| 1645 | dev_err(dev, "ab->read fail %d\n", err); |
| 1646 | return err; |
| 1647 | } |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1648 | seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value); |
Lee Jones | c7ebaee | 2013-02-26 14:03:33 +0000 | [diff] [blame] | 1649 | } |
| 1650 | err = abx500_set_register_interruptible(dev, |
| 1651 | AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value); |
| 1652 | if (err < 0) { |
| 1653 | dev_err(dev, "ab->write fail %d\n", err); |
| 1654 | return err; |
| 1655 | } |
| 1656 | return 0; |
| 1657 | } |
| 1658 | |
| 1659 | static int ab8500_modem_open(struct inode *inode, struct file *file) |
| 1660 | { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 1661 | return single_open(file, ab8500_print_modem_registers, |
| 1662 | inode->i_private); |
Lee Jones | c7ebaee | 2013-02-26 14:03:33 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | static const struct file_operations ab8500_modem_fops = { |
| 1666 | .open = ab8500_modem_open, |
| 1667 | .read = seq_read, |
| 1668 | .llseek = seq_lseek, |
| 1669 | .release = single_release, |
| 1670 | .owner = THIS_MODULE, |
| 1671 | }; |
| 1672 | |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1673 | static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p) |
| 1674 | { |
| 1675 | int bat_ctrl_raw; |
| 1676 | int bat_ctrl_convert; |
| 1677 | struct ab8500_gpadc *gpadc; |
| 1678 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1679 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1680 | bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL, |
| 1681 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1682 | bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1683 | BAT_CTRL, bat_ctrl_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1684 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1685 | seq_printf(s, "%d,0x%X\n", bat_ctrl_convert, bat_ctrl_raw); |
| 1686 | |
| 1687 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file) |
| 1691 | { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 1692 | return single_open(file, ab8500_gpadc_bat_ctrl_print, |
| 1693 | inode->i_private); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | static const struct file_operations ab8500_gpadc_bat_ctrl_fops = { |
| 1697 | .open = ab8500_gpadc_bat_ctrl_open, |
| 1698 | .read = seq_read, |
| 1699 | .llseek = seq_lseek, |
| 1700 | .release = single_release, |
| 1701 | .owner = THIS_MODULE, |
| 1702 | }; |
| 1703 | |
| 1704 | static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p) |
| 1705 | { |
| 1706 | int btemp_ball_raw; |
| 1707 | int btemp_ball_convert; |
| 1708 | struct ab8500_gpadc *gpadc; |
| 1709 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1710 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1711 | btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL, |
| 1712 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1713 | btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1714 | btemp_ball_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1715 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1716 | seq_printf(s, "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw); |
| 1717 | |
| 1718 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | static int ab8500_gpadc_btemp_ball_open(struct inode *inode, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 1722 | struct file *file) |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1723 | { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 1724 | return single_open(file, ab8500_gpadc_btemp_ball_print, |
| 1725 | inode->i_private); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | static const struct file_operations ab8500_gpadc_btemp_ball_fops = { |
| 1729 | .open = ab8500_gpadc_btemp_ball_open, |
| 1730 | .read = seq_read, |
| 1731 | .llseek = seq_lseek, |
| 1732 | .release = single_release, |
| 1733 | .owner = THIS_MODULE, |
| 1734 | }; |
| 1735 | |
| 1736 | static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p) |
| 1737 | { |
| 1738 | int main_charger_v_raw; |
| 1739 | int main_charger_v_convert; |
| 1740 | struct ab8500_gpadc *gpadc; |
| 1741 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1742 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1743 | main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V, |
| 1744 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1745 | main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1746 | MAIN_CHARGER_V, main_charger_v_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1747 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1748 | seq_printf(s, "%d,0x%X\n", main_charger_v_convert, main_charger_v_raw); |
| 1749 | |
| 1750 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | static int ab8500_gpadc_main_charger_v_open(struct inode *inode, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 1754 | struct file *file) |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1755 | { |
| 1756 | return single_open(file, ab8500_gpadc_main_charger_v_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 1757 | inode->i_private); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | static const struct file_operations ab8500_gpadc_main_charger_v_fops = { |
| 1761 | .open = ab8500_gpadc_main_charger_v_open, |
| 1762 | .read = seq_read, |
| 1763 | .llseek = seq_lseek, |
| 1764 | .release = single_release, |
| 1765 | .owner = THIS_MODULE, |
| 1766 | }; |
| 1767 | |
| 1768 | static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p) |
| 1769 | { |
| 1770 | int acc_detect1_raw; |
| 1771 | int acc_detect1_convert; |
| 1772 | struct ab8500_gpadc *gpadc; |
| 1773 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1774 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1775 | acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1, |
| 1776 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1777 | acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1778 | acc_detect1_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1779 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1780 | seq_printf(s, "%d,0x%X\n", acc_detect1_convert, acc_detect1_raw); |
| 1781 | |
| 1782 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | static int ab8500_gpadc_acc_detect1_open(struct inode *inode, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 1786 | struct file *file) |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1787 | { |
| 1788 | return single_open(file, ab8500_gpadc_acc_detect1_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 1789 | inode->i_private); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | static const struct file_operations ab8500_gpadc_acc_detect1_fops = { |
| 1793 | .open = ab8500_gpadc_acc_detect1_open, |
| 1794 | .read = seq_read, |
| 1795 | .llseek = seq_lseek, |
| 1796 | .release = single_release, |
| 1797 | .owner = THIS_MODULE, |
| 1798 | }; |
| 1799 | |
| 1800 | static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p) |
| 1801 | { |
| 1802 | int acc_detect2_raw; |
| 1803 | int acc_detect2_convert; |
| 1804 | struct ab8500_gpadc *gpadc; |
| 1805 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1806 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1807 | acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2, |
| 1808 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1809 | acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1810 | ACC_DETECT2, acc_detect2_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1811 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1812 | seq_printf(s, "%d,0x%X\n", acc_detect2_convert, acc_detect2_raw); |
| 1813 | |
| 1814 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | static int ab8500_gpadc_acc_detect2_open(struct inode *inode, |
| 1818 | struct file *file) |
| 1819 | { |
| 1820 | return single_open(file, ab8500_gpadc_acc_detect2_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 1821 | inode->i_private); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | static const struct file_operations ab8500_gpadc_acc_detect2_fops = { |
| 1825 | .open = ab8500_gpadc_acc_detect2_open, |
| 1826 | .read = seq_read, |
| 1827 | .llseek = seq_lseek, |
| 1828 | .release = single_release, |
| 1829 | .owner = THIS_MODULE, |
| 1830 | }; |
| 1831 | |
| 1832 | static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p) |
| 1833 | { |
| 1834 | int aux1_raw; |
| 1835 | int aux1_convert; |
| 1836 | struct ab8500_gpadc *gpadc; |
| 1837 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1838 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1839 | aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1, |
| 1840 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1841 | aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1842 | aux1_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1843 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1844 | seq_printf(s, "%d,0x%X\n", aux1_convert, aux1_raw); |
| 1845 | |
| 1846 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file) |
| 1850 | { |
| 1851 | return single_open(file, ab8500_gpadc_aux1_print, inode->i_private); |
| 1852 | } |
| 1853 | |
| 1854 | static const struct file_operations ab8500_gpadc_aux1_fops = { |
| 1855 | .open = ab8500_gpadc_aux1_open, |
| 1856 | .read = seq_read, |
| 1857 | .llseek = seq_lseek, |
| 1858 | .release = single_release, |
| 1859 | .owner = THIS_MODULE, |
| 1860 | }; |
| 1861 | |
| 1862 | static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p) |
| 1863 | { |
| 1864 | int aux2_raw; |
| 1865 | int aux2_convert; |
| 1866 | struct ab8500_gpadc *gpadc; |
| 1867 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1868 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1869 | aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2, |
| 1870 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1871 | aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1872 | aux2_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1873 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1874 | seq_printf(s, "%d,0x%X\n", aux2_convert, aux2_raw); |
| 1875 | |
| 1876 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file) |
| 1880 | { |
| 1881 | return single_open(file, ab8500_gpadc_aux2_print, inode->i_private); |
| 1882 | } |
| 1883 | |
| 1884 | static const struct file_operations ab8500_gpadc_aux2_fops = { |
| 1885 | .open = ab8500_gpadc_aux2_open, |
| 1886 | .read = seq_read, |
| 1887 | .llseek = seq_lseek, |
| 1888 | .release = single_release, |
| 1889 | .owner = THIS_MODULE, |
| 1890 | }; |
| 1891 | |
| 1892 | static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p) |
| 1893 | { |
| 1894 | int main_bat_v_raw; |
| 1895 | int main_bat_v_convert; |
| 1896 | struct ab8500_gpadc *gpadc; |
| 1897 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1898 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1899 | main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V, |
| 1900 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1901 | main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1902 | main_bat_v_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1903 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1904 | seq_printf(s, "%d,0x%X\n", main_bat_v_convert, main_bat_v_raw); |
| 1905 | |
| 1906 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | static int ab8500_gpadc_main_bat_v_open(struct inode *inode, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 1910 | struct file *file) |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1911 | { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 1912 | return single_open(file, ab8500_gpadc_main_bat_v_print, |
| 1913 | inode->i_private); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | static const struct file_operations ab8500_gpadc_main_bat_v_fops = { |
| 1917 | .open = ab8500_gpadc_main_bat_v_open, |
| 1918 | .read = seq_read, |
| 1919 | .llseek = seq_lseek, |
| 1920 | .release = single_release, |
| 1921 | .owner = THIS_MODULE, |
| 1922 | }; |
| 1923 | |
| 1924 | static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p) |
| 1925 | { |
| 1926 | int vbus_v_raw; |
| 1927 | int vbus_v_convert; |
| 1928 | struct ab8500_gpadc *gpadc; |
| 1929 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1930 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1931 | vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V, |
| 1932 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1933 | vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1934 | vbus_v_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1935 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1936 | seq_printf(s, "%d,0x%X\n", vbus_v_convert, vbus_v_raw); |
| 1937 | |
| 1938 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file) |
| 1942 | { |
| 1943 | return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private); |
| 1944 | } |
| 1945 | |
| 1946 | static const struct file_operations ab8500_gpadc_vbus_v_fops = { |
| 1947 | .open = ab8500_gpadc_vbus_v_open, |
| 1948 | .read = seq_read, |
| 1949 | .llseek = seq_lseek, |
| 1950 | .release = single_release, |
| 1951 | .owner = THIS_MODULE, |
| 1952 | }; |
| 1953 | |
| 1954 | static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p) |
| 1955 | { |
| 1956 | int main_charger_c_raw; |
| 1957 | int main_charger_c_convert; |
| 1958 | struct ab8500_gpadc *gpadc; |
| 1959 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1960 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1961 | main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C, |
| 1962 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1963 | main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1964 | MAIN_CHARGER_C, main_charger_c_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1965 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1966 | seq_printf(s, "%d,0x%X\n", main_charger_c_convert, main_charger_c_raw); |
| 1967 | |
| 1968 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | static int ab8500_gpadc_main_charger_c_open(struct inode *inode, |
| 1972 | struct file *file) |
| 1973 | { |
| 1974 | return single_open(file, ab8500_gpadc_main_charger_c_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 1975 | inode->i_private); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | static const struct file_operations ab8500_gpadc_main_charger_c_fops = { |
| 1979 | .open = ab8500_gpadc_main_charger_c_open, |
| 1980 | .read = seq_read, |
| 1981 | .llseek = seq_lseek, |
| 1982 | .release = single_release, |
| 1983 | .owner = THIS_MODULE, |
| 1984 | }; |
| 1985 | |
| 1986 | static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p) |
| 1987 | { |
| 1988 | int usb_charger_c_raw; |
| 1989 | int usb_charger_c_convert; |
| 1990 | struct ab8500_gpadc *gpadc; |
| 1991 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 1992 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1993 | usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C, |
| 1994 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1995 | usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 1996 | USB_CHARGER_C, usb_charger_c_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 1997 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 1998 | seq_printf(s, "%d,0x%X\n", usb_charger_c_convert, usb_charger_c_raw); |
| 1999 | |
| 2000 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | static int ab8500_gpadc_usb_charger_c_open(struct inode *inode, |
| 2004 | struct file *file) |
| 2005 | { |
| 2006 | return single_open(file, ab8500_gpadc_usb_charger_c_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2007 | inode->i_private); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | static const struct file_operations ab8500_gpadc_usb_charger_c_fops = { |
| 2011 | .open = ab8500_gpadc_usb_charger_c_open, |
| 2012 | .read = seq_read, |
| 2013 | .llseek = seq_lseek, |
| 2014 | .release = single_release, |
| 2015 | .owner = THIS_MODULE, |
| 2016 | }; |
| 2017 | |
| 2018 | static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p) |
| 2019 | { |
| 2020 | int bk_bat_v_raw; |
| 2021 | int bk_bat_v_convert; |
| 2022 | struct ab8500_gpadc *gpadc; |
| 2023 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 2024 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2025 | bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V, |
| 2026 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2027 | bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2028 | BK_BAT_V, bk_bat_v_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2029 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2030 | seq_printf(s, "%d,0x%X\n", bk_bat_v_convert, bk_bat_v_raw); |
| 2031 | |
| 2032 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file) |
| 2036 | { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2037 | return single_open(file, ab8500_gpadc_bk_bat_v_print, |
| 2038 | inode->i_private); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | static const struct file_operations ab8500_gpadc_bk_bat_v_fops = { |
| 2042 | .open = ab8500_gpadc_bk_bat_v_open, |
| 2043 | .read = seq_read, |
| 2044 | .llseek = seq_lseek, |
| 2045 | .release = single_release, |
| 2046 | .owner = THIS_MODULE, |
| 2047 | }; |
| 2048 | |
| 2049 | static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p) |
| 2050 | { |
| 2051 | int die_temp_raw; |
| 2052 | int die_temp_convert; |
| 2053 | struct ab8500_gpadc *gpadc; |
| 2054 | |
Philippe Langlais | 8908c04 | 2012-04-18 15:52:59 +0200 | [diff] [blame] | 2055 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2056 | die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP, |
| 2057 | avg_sample, trig_edge, trig_timer, conv_type); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2058 | die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP, |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2059 | die_temp_raw); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2060 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2061 | seq_printf(s, "%d,0x%X\n", die_temp_convert, die_temp_raw); |
| 2062 | |
| 2063 | return 0; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file) |
| 2067 | { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2068 | return single_open(file, ab8500_gpadc_die_temp_print, |
| 2069 | inode->i_private); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | static const struct file_operations ab8500_gpadc_die_temp_fops = { |
| 2073 | .open = ab8500_gpadc_die_temp_open, |
| 2074 | .read = seq_read, |
| 2075 | .llseek = seq_lseek, |
| 2076 | .release = single_release, |
| 2077 | .owner = THIS_MODULE, |
| 2078 | }; |
| 2079 | |
Lee Jones | 127629d | 2013-02-26 14:04:37 +0000 | [diff] [blame] | 2080 | static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p) |
| 2081 | { |
| 2082 | int usb_id_raw; |
| 2083 | int usb_id_convert; |
| 2084 | struct ab8500_gpadc *gpadc; |
| 2085 | |
| 2086 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
| 2087 | usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID, |
| 2088 | avg_sample, trig_edge, trig_timer, conv_type); |
| 2089 | usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID, |
| 2090 | usb_id_raw); |
| 2091 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2092 | seq_printf(s, "%d,0x%X\n", usb_id_convert, usb_id_raw); |
| 2093 | |
| 2094 | return 0; |
Lee Jones | 127629d | 2013-02-26 14:04:37 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file) |
| 2098 | { |
| 2099 | return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private); |
| 2100 | } |
| 2101 | |
| 2102 | static const struct file_operations ab8500_gpadc_usb_id_fops = { |
| 2103 | .open = ab8500_gpadc_usb_id_open, |
| 2104 | .read = seq_read, |
| 2105 | .llseek = seq_lseek, |
| 2106 | .release = single_release, |
| 2107 | .owner = THIS_MODULE, |
| 2108 | }; |
| 2109 | |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2110 | static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p) |
| 2111 | { |
| 2112 | int xtal_temp_raw; |
| 2113 | int xtal_temp_convert; |
| 2114 | struct ab8500_gpadc *gpadc; |
| 2115 | |
| 2116 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
| 2117 | xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP, |
| 2118 | avg_sample, trig_edge, trig_timer, conv_type); |
| 2119 | xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP, |
| 2120 | xtal_temp_raw); |
| 2121 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2122 | seq_printf(s, "%d,0x%X\n", xtal_temp_convert, xtal_temp_raw); |
| 2123 | |
| 2124 | return 0; |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file) |
| 2128 | { |
| 2129 | return single_open(file, ab8540_gpadc_xtal_temp_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2130 | inode->i_private); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | static const struct file_operations ab8540_gpadc_xtal_temp_fops = { |
| 2134 | .open = ab8540_gpadc_xtal_temp_open, |
| 2135 | .read = seq_read, |
| 2136 | .llseek = seq_lseek, |
| 2137 | .release = single_release, |
| 2138 | .owner = THIS_MODULE, |
| 2139 | }; |
| 2140 | |
| 2141 | static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p) |
| 2142 | { |
| 2143 | int vbat_true_meas_raw; |
| 2144 | int vbat_true_meas_convert; |
| 2145 | struct ab8500_gpadc *gpadc; |
| 2146 | |
| 2147 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
| 2148 | vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS, |
| 2149 | avg_sample, trig_edge, trig_timer, conv_type); |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2150 | vbat_true_meas_convert = |
| 2151 | ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS, |
| 2152 | vbat_true_meas_raw); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2153 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2154 | seq_printf(s, "%d,0x%X\n", vbat_true_meas_convert, vbat_true_meas_raw); |
| 2155 | |
| 2156 | return 0; |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode, |
| 2160 | struct file *file) |
| 2161 | { |
| 2162 | return single_open(file, ab8540_gpadc_vbat_true_meas_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2163 | inode->i_private); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = { |
| 2167 | .open = ab8540_gpadc_vbat_true_meas_open, |
| 2168 | .read = seq_read, |
| 2169 | .llseek = seq_lseek, |
| 2170 | .release = single_release, |
| 2171 | .owner = THIS_MODULE, |
| 2172 | }; |
| 2173 | |
| 2174 | static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p) |
| 2175 | { |
| 2176 | int bat_ctrl_raw; |
| 2177 | int bat_ctrl_convert; |
| 2178 | int ibat_raw; |
| 2179 | int ibat_convert; |
| 2180 | struct ab8500_gpadc *gpadc; |
| 2181 | |
| 2182 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
| 2183 | bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT, |
| 2184 | avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw); |
| 2185 | |
| 2186 | bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL, |
| 2187 | bat_ctrl_raw); |
| 2188 | ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL, |
| 2189 | ibat_raw); |
| 2190 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2191 | seq_printf(s, |
| 2192 | "%d,0x%X\n" |
| 2193 | "%d,0x%X\n", |
| 2194 | bat_ctrl_convert, bat_ctrl_raw, |
| 2195 | ibat_convert, ibat_raw); |
| 2196 | |
| 2197 | return 0; |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode, |
| 2201 | struct file *file) |
| 2202 | { |
| 2203 | return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2204 | inode->i_private); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = { |
| 2208 | .open = ab8540_gpadc_bat_ctrl_and_ibat_open, |
| 2209 | .read = seq_read, |
| 2210 | .llseek = seq_lseek, |
| 2211 | .release = single_release, |
| 2212 | .owner = THIS_MODULE, |
| 2213 | }; |
| 2214 | |
| 2215 | static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p) |
| 2216 | { |
| 2217 | int vbat_meas_raw; |
| 2218 | int vbat_meas_convert; |
| 2219 | int ibat_raw; |
| 2220 | int ibat_convert; |
| 2221 | struct ab8500_gpadc *gpadc; |
| 2222 | |
| 2223 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
| 2224 | vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT, |
| 2225 | avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw); |
| 2226 | vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V, |
| 2227 | vbat_meas_raw); |
| 2228 | ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL, |
| 2229 | ibat_raw); |
| 2230 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2231 | seq_printf(s, |
| 2232 | "%d,0x%X\n" |
| 2233 | "%d,0x%X\n", |
| 2234 | vbat_meas_convert, vbat_meas_raw, |
| 2235 | ibat_convert, ibat_raw); |
| 2236 | |
| 2237 | return 0; |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode, |
| 2241 | struct file *file) |
| 2242 | { |
| 2243 | return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2244 | inode->i_private); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = { |
| 2248 | .open = ab8540_gpadc_vbat_meas_and_ibat_open, |
| 2249 | .read = seq_read, |
| 2250 | .llseek = seq_lseek, |
| 2251 | .release = single_release, |
| 2252 | .owner = THIS_MODULE, |
| 2253 | }; |
| 2254 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2255 | static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s, |
| 2256 | void *p) |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2257 | { |
| 2258 | int vbat_true_meas_raw; |
| 2259 | int vbat_true_meas_convert; |
| 2260 | int ibat_raw; |
| 2261 | int ibat_convert; |
| 2262 | struct ab8500_gpadc *gpadc; |
| 2263 | |
| 2264 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
| 2265 | vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc, |
| 2266 | VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge, |
| 2267 | trig_timer, conv_type, &ibat_raw); |
| 2268 | vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, |
| 2269 | VBAT_TRUE_MEAS, vbat_true_meas_raw); |
| 2270 | ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL, |
| 2271 | ibat_raw); |
| 2272 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2273 | seq_printf(s, |
| 2274 | "%d,0x%X\n" |
| 2275 | "%d,0x%X\n", |
| 2276 | vbat_true_meas_convert, vbat_true_meas_raw, |
| 2277 | ibat_convert, ibat_raw); |
| 2278 | |
| 2279 | return 0; |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode, |
| 2283 | struct file *file) |
| 2284 | { |
| 2285 | return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2286 | inode->i_private); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2287 | } |
| 2288 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2289 | static const struct file_operations |
| 2290 | ab8540_gpadc_vbat_true_meas_and_ibat_fops = { |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2291 | .open = ab8540_gpadc_vbat_true_meas_and_ibat_open, |
| 2292 | .read = seq_read, |
| 2293 | .llseek = seq_lseek, |
| 2294 | .release = single_release, |
| 2295 | .owner = THIS_MODULE, |
| 2296 | }; |
| 2297 | |
| 2298 | static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p) |
| 2299 | { |
| 2300 | int bat_temp_raw; |
| 2301 | int bat_temp_convert; |
| 2302 | int ibat_raw; |
| 2303 | int ibat_convert; |
| 2304 | struct ab8500_gpadc *gpadc; |
| 2305 | |
| 2306 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
| 2307 | bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT, |
| 2308 | avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw); |
| 2309 | bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL, |
| 2310 | bat_temp_raw); |
| 2311 | ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL, |
| 2312 | ibat_raw); |
| 2313 | |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2314 | seq_printf(s, |
| 2315 | "%d,0x%X\n" |
| 2316 | "%d,0x%X\n", |
| 2317 | bat_temp_convert, bat_temp_raw, |
| 2318 | ibat_convert, ibat_raw); |
| 2319 | |
| 2320 | return 0; |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode, |
| 2324 | struct file *file) |
| 2325 | { |
| 2326 | return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2327 | inode->i_private); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = { |
| 2331 | .open = ab8540_gpadc_bat_temp_and_ibat_open, |
| 2332 | .read = seq_read, |
| 2333 | .llseek = seq_lseek, |
| 2334 | .release = single_release, |
| 2335 | .owner = THIS_MODULE, |
| 2336 | }; |
| 2337 | |
| 2338 | static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p) |
| 2339 | { |
| 2340 | struct ab8500_gpadc *gpadc; |
| 2341 | u16 vmain_l, vmain_h, btemp_l, btemp_h; |
| 2342 | u16 vbat_l, vbat_h, ibat_l, ibat_h; |
| 2343 | |
| 2344 | gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); |
| 2345 | ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h, |
| 2346 | &vbat_l, &vbat_h, &ibat_l, &ibat_h); |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2347 | seq_printf(s, |
| 2348 | "VMAIN_L:0x%X\n" |
| 2349 | "VMAIN_H:0x%X\n" |
| 2350 | "BTEMP_L:0x%X\n" |
| 2351 | "BTEMP_H:0x%X\n" |
| 2352 | "VBAT_L:0x%X\n" |
| 2353 | "VBAT_H:0x%X\n" |
| 2354 | "IBAT_L:0x%X\n" |
| 2355 | "IBAT_H:0x%X\n", |
| 2356 | vmain_l, vmain_h, btemp_l, btemp_h, |
| 2357 | vbat_l, vbat_h, ibat_l, ibat_h); |
| 2358 | |
| 2359 | return 0; |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file) |
| 2363 | { |
| 2364 | return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private); |
| 2365 | } |
| 2366 | |
| 2367 | static const struct file_operations ab8540_gpadc_otp_calib_fops = { |
| 2368 | .open = ab8540_gpadc_otp_cal_open, |
| 2369 | .read = seq_read, |
| 2370 | .llseek = seq_lseek, |
| 2371 | .release = single_release, |
| 2372 | .owner = THIS_MODULE, |
| 2373 | }; |
| 2374 | |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2375 | static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p) |
| 2376 | { |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2377 | seq_printf(s, "%d\n", avg_sample); |
| 2378 | |
| 2379 | return 0; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file) |
| 2383 | { |
| 2384 | return single_open(file, ab8500_gpadc_avg_sample_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2385 | inode->i_private); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | static ssize_t ab8500_gpadc_avg_sample_write(struct file *file, |
| 2389 | const char __user *user_buf, |
| 2390 | size_t count, loff_t *ppos) |
| 2391 | { |
| 2392 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2393 | unsigned long user_avg_sample; |
| 2394 | int err; |
| 2395 | |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2396 | err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2397 | if (err) |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2398 | return err; |
| 2399 | |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2400 | if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4) |
| 2401 | || (user_avg_sample == SAMPLE_8) |
| 2402 | || (user_avg_sample == SAMPLE_16)) { |
| 2403 | avg_sample = (u8) user_avg_sample; |
| 2404 | } else { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2405 | dev_err(dev, |
| 2406 | "debugfs err input: should be egal to 1, 4, 8 or 16\n"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2407 | return -EINVAL; |
| 2408 | } |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2409 | |
| 2410 | return count; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | static const struct file_operations ab8500_gpadc_avg_sample_fops = { |
| 2414 | .open = ab8500_gpadc_avg_sample_open, |
| 2415 | .read = seq_read, |
| 2416 | .write = ab8500_gpadc_avg_sample_write, |
| 2417 | .llseek = seq_lseek, |
| 2418 | .release = single_release, |
| 2419 | .owner = THIS_MODULE, |
| 2420 | }; |
| 2421 | |
| 2422 | static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p) |
| 2423 | { |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2424 | seq_printf(s, "%d\n", trig_edge); |
| 2425 | |
| 2426 | return 0; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file) |
| 2430 | { |
| 2431 | return single_open(file, ab8500_gpadc_trig_edge_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2432 | inode->i_private); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | static ssize_t ab8500_gpadc_trig_edge_write(struct file *file, |
| 2436 | const char __user *user_buf, |
| 2437 | size_t count, loff_t *ppos) |
| 2438 | { |
| 2439 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2440 | unsigned long user_trig_edge; |
| 2441 | int err; |
| 2442 | |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2443 | err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2444 | if (err) |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2445 | return err; |
| 2446 | |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2447 | if ((user_trig_edge == RISING_EDGE) |
| 2448 | || (user_trig_edge == FALLING_EDGE)) { |
| 2449 | trig_edge = (u8) user_trig_edge; |
| 2450 | } else { |
| 2451 | dev_err(dev, "Wrong input:\n" |
| 2452 | "Enter 0. Rising edge\n" |
| 2453 | "Enter 1. Falling edge\n"); |
| 2454 | return -EINVAL; |
| 2455 | } |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2456 | |
| 2457 | return count; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | static const struct file_operations ab8500_gpadc_trig_edge_fops = { |
| 2461 | .open = ab8500_gpadc_trig_edge_open, |
| 2462 | .read = seq_read, |
| 2463 | .write = ab8500_gpadc_trig_edge_write, |
| 2464 | .llseek = seq_lseek, |
| 2465 | .release = single_release, |
| 2466 | .owner = THIS_MODULE, |
| 2467 | }; |
| 2468 | |
| 2469 | static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p) |
| 2470 | { |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2471 | seq_printf(s, "%d\n", trig_timer); |
| 2472 | |
| 2473 | return 0; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file) |
| 2477 | { |
| 2478 | return single_open(file, ab8500_gpadc_trig_timer_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2479 | inode->i_private); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | static ssize_t ab8500_gpadc_trig_timer_write(struct file *file, |
| 2483 | const char __user *user_buf, |
| 2484 | size_t count, loff_t *ppos) |
| 2485 | { |
| 2486 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2487 | unsigned long user_trig_timer; |
| 2488 | int err; |
| 2489 | |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2490 | err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2491 | if (err) |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2492 | return err; |
| 2493 | |
Lee Jones | c3f27a2 | 2014-07-02 11:22:10 +0100 | [diff] [blame] | 2494 | if (user_trig_timer & ~0xFF) { |
| 2495 | dev_err(dev, |
Colin Ian King | c094cf1 | 2016-04-25 22:42:25 +0100 | [diff] [blame] | 2496 | "debugfs error input: should be between 0 to 255\n"); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2497 | return -EINVAL; |
| 2498 | } |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2499 | |
Lee Jones | c3f27a2 | 2014-07-02 11:22:10 +0100 | [diff] [blame] | 2500 | trig_timer = (u8) user_trig_timer; |
| 2501 | |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2502 | return count; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | static const struct file_operations ab8500_gpadc_trig_timer_fops = { |
| 2506 | .open = ab8500_gpadc_trig_timer_open, |
| 2507 | .read = seq_read, |
| 2508 | .write = ab8500_gpadc_trig_timer_write, |
| 2509 | .llseek = seq_lseek, |
| 2510 | .release = single_release, |
| 2511 | .owner = THIS_MODULE, |
| 2512 | }; |
| 2513 | |
| 2514 | static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p) |
| 2515 | { |
Joe Perches | 9a503a7 | 2015-02-21 18:53:43 -0800 | [diff] [blame] | 2516 | seq_printf(s, "%d\n", conv_type); |
| 2517 | |
| 2518 | return 0; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file) |
| 2522 | { |
| 2523 | return single_open(file, ab8500_gpadc_conv_type_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2524 | inode->i_private); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | static ssize_t ab8500_gpadc_conv_type_write(struct file *file, |
| 2528 | const char __user *user_buf, |
| 2529 | size_t count, loff_t *ppos) |
| 2530 | { |
| 2531 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2532 | unsigned long user_conv_type; |
| 2533 | int err; |
| 2534 | |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2535 | err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2536 | if (err) |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2537 | return err; |
| 2538 | |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2539 | if ((user_conv_type == ADC_SW) |
| 2540 | || (user_conv_type == ADC_HW)) { |
| 2541 | conv_type = (u8) user_conv_type; |
| 2542 | } else { |
| 2543 | dev_err(dev, "Wrong input:\n" |
| 2544 | "Enter 0. ADC SW conversion\n" |
| 2545 | "Enter 1. ADC HW conversion\n"); |
| 2546 | return -EINVAL; |
| 2547 | } |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2548 | |
| 2549 | return count; |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | static const struct file_operations ab8500_gpadc_conv_type_fops = { |
| 2553 | .open = ab8500_gpadc_conv_type_open, |
| 2554 | .read = seq_read, |
| 2555 | .write = ab8500_gpadc_conv_type_write, |
| 2556 | .llseek = seq_lseek, |
| 2557 | .release = single_release, |
| 2558 | .owner = THIS_MODULE, |
| 2559 | }; |
| 2560 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2561 | /* |
| 2562 | * return length of an ASCII numerical value, 0 is string is not a |
| 2563 | * numerical value. |
| 2564 | * string shall start at value 1st char. |
| 2565 | * string can be tailed with \0 or space or newline chars only. |
| 2566 | * value can be decimal or hexadecimal (prefixed 0x or 0X). |
| 2567 | */ |
| 2568 | static int strval_len(char *b) |
| 2569 | { |
| 2570 | char *s = b; |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2571 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2572 | if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) { |
| 2573 | s += 2; |
| 2574 | for (; *s && (*s != ' ') && (*s != '\n'); s++) { |
| 2575 | if (!isxdigit(*s)) |
| 2576 | return 0; |
| 2577 | } |
| 2578 | } else { |
| 2579 | if (*s == '-') |
| 2580 | s++; |
| 2581 | for (; *s && (*s != ' ') && (*s != '\n'); s++) { |
| 2582 | if (!isdigit(*s)) |
| 2583 | return 0; |
| 2584 | } |
| 2585 | } |
| 2586 | return (int) (s-b); |
| 2587 | } |
| 2588 | |
| 2589 | /* |
| 2590 | * parse hwreg input data. |
| 2591 | * update global hwreg_cfg only if input data syntax is ok. |
| 2592 | */ |
| 2593 | static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg, |
| 2594 | struct device *dev) |
| 2595 | { |
| 2596 | uint write, val = 0; |
| 2597 | u8 regvalue; |
| 2598 | int ret; |
| 2599 | struct hwreg_cfg loc = { |
| 2600 | .bank = 0, /* default: invalid phys addr */ |
| 2601 | .addr = 0, /* default: invalid phys addr */ |
| 2602 | .fmt = 0, /* default: 32bit access, hex output */ |
| 2603 | .mask = 0xFFFFFFFF, /* default: no mask */ |
| 2604 | .shift = 0, /* default: no bit shift */ |
| 2605 | }; |
| 2606 | |
| 2607 | /* read or write ? */ |
| 2608 | if (!strncmp(b, "read ", 5)) { |
| 2609 | write = 0; |
| 2610 | b += 5; |
| 2611 | } else if (!strncmp(b, "write ", 6)) { |
| 2612 | write = 1; |
| 2613 | b += 6; |
| 2614 | } else |
| 2615 | return -EINVAL; |
| 2616 | |
| 2617 | /* OPTIONS -l|-w|-b -s -m -o */ |
| 2618 | while ((*b == ' ') || (*b == '-')) { |
| 2619 | if (*(b-1) != ' ') { |
| 2620 | b++; |
| 2621 | continue; |
| 2622 | } |
| 2623 | if ((!strncmp(b, "-d ", 3)) || |
| 2624 | (!strncmp(b, "-dec ", 5))) { |
| 2625 | b += (*(b+2) == ' ') ? 3 : 5; |
| 2626 | loc.fmt |= (1<<0); |
| 2627 | } else if ((!strncmp(b, "-h ", 3)) || |
| 2628 | (!strncmp(b, "-hex ", 5))) { |
| 2629 | b += (*(b+2) == ' ') ? 3 : 5; |
| 2630 | loc.fmt &= ~(1<<0); |
| 2631 | } else if ((!strncmp(b, "-m ", 3)) || |
| 2632 | (!strncmp(b, "-mask ", 6))) { |
| 2633 | b += (*(b+2) == ' ') ? 3 : 6; |
| 2634 | if (strval_len(b) == 0) |
| 2635 | return -EINVAL; |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2636 | ret = kstrtoul(b, 0, &loc.mask); |
| 2637 | if (ret) |
| 2638 | return ret; |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2639 | } else if ((!strncmp(b, "-s ", 3)) || |
| 2640 | (!strncmp(b, "-shift ", 7))) { |
| 2641 | b += (*(b+2) == ' ') ? 3 : 7; |
| 2642 | if (strval_len(b) == 0) |
| 2643 | return -EINVAL; |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2644 | ret = kstrtol(b, 0, &loc.shift); |
| 2645 | if (ret) |
| 2646 | return ret; |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2647 | } else { |
| 2648 | return -EINVAL; |
| 2649 | } |
| 2650 | } |
| 2651 | /* get arg BANK and ADDRESS */ |
| 2652 | if (strval_len(b) == 0) |
| 2653 | return -EINVAL; |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2654 | ret = kstrtouint(b, 0, &loc.bank); |
| 2655 | if (ret) |
| 2656 | return ret; |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2657 | while (*b == ' ') |
| 2658 | b++; |
| 2659 | if (strval_len(b) == 0) |
| 2660 | return -EINVAL; |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2661 | ret = kstrtoul(b, 0, &loc.addr); |
| 2662 | if (ret) |
| 2663 | return ret; |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2664 | |
| 2665 | if (write) { |
| 2666 | while (*b == ' ') |
| 2667 | b++; |
| 2668 | if (strval_len(b) == 0) |
| 2669 | return -EINVAL; |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2670 | ret = kstrtouint(b, 0, &val); |
| 2671 | if (ret) |
| 2672 | return ret; |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | /* args are ok, update target cfg (mainly for read) */ |
| 2676 | *cfg = loc; |
| 2677 | |
| 2678 | #ifdef ABB_HWREG_DEBUG |
Lee Jones | de6a769 | 2015-10-28 09:27:32 +0000 | [diff] [blame] | 2679 | pr_warn("HWREG request: %s, %s,\n", (write) ? "write" : "read", |
| 2680 | REG_FMT_DEC(cfg) ? "decimal" : "hexa"); |
| 2681 | pr_warn(" addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n", |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2682 | cfg->addr, cfg->mask, cfg->shift, val); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2683 | #endif |
| 2684 | |
| 2685 | if (!write) |
| 2686 | return 0; |
| 2687 | |
| 2688 | ret = abx500_get_register_interruptible(dev, |
| 2689 | (u8)cfg->bank, (u8)cfg->addr, ®value); |
| 2690 | if (ret < 0) { |
| 2691 | dev_err(dev, "abx500_get_reg fail %d, %d\n", |
| 2692 | ret, __LINE__); |
| 2693 | return -EINVAL; |
| 2694 | } |
| 2695 | |
| 2696 | if (cfg->shift >= 0) { |
| 2697 | regvalue &= ~(cfg->mask << (cfg->shift)); |
| 2698 | val = (val & cfg->mask) << (cfg->shift); |
| 2699 | } else { |
| 2700 | regvalue &= ~(cfg->mask >> (-cfg->shift)); |
| 2701 | val = (val & cfg->mask) >> (-cfg->shift); |
| 2702 | } |
| 2703 | val = val | regvalue; |
| 2704 | |
| 2705 | ret = abx500_set_register_interruptible(dev, |
| 2706 | (u8)cfg->bank, (u8)cfg->addr, (u8)val); |
| 2707 | if (ret < 0) { |
| 2708 | pr_err("abx500_set_reg failed %d, %d", ret, __LINE__); |
| 2709 | return -EINVAL; |
| 2710 | } |
| 2711 | |
| 2712 | return 0; |
| 2713 | } |
| 2714 | |
| 2715 | static ssize_t ab8500_hwreg_write(struct file *file, |
| 2716 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 2717 | { |
| 2718 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
| 2719 | char buf[128]; |
| 2720 | int buf_size, ret; |
| 2721 | |
| 2722 | /* Get userspace string and assure termination */ |
| 2723 | buf_size = min(count, (sizeof(buf)-1)); |
| 2724 | if (copy_from_user(buf, user_buf, buf_size)) |
| 2725 | return -EFAULT; |
| 2726 | buf[buf_size] = 0; |
| 2727 | |
| 2728 | /* get args and process */ |
| 2729 | ret = hwreg_common_write(buf, &hwreg_cfg, dev); |
| 2730 | return (ret) ? ret : buf_size; |
| 2731 | } |
| 2732 | |
| 2733 | /* |
| 2734 | * - irq subscribe/unsubscribe stuff |
| 2735 | */ |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2736 | static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p) |
| 2737 | { |
| 2738 | seq_printf(s, "%d\n", irq_first); |
| 2739 | |
| 2740 | return 0; |
| 2741 | } |
| 2742 | |
| 2743 | static int ab8500_subscribe_unsubscribe_open(struct inode *inode, |
| 2744 | struct file *file) |
| 2745 | { |
| 2746 | return single_open(file, ab8500_subscribe_unsubscribe_print, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 2747 | inode->i_private); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | /* |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2751 | * Userspace should use poll() on this file. When an event occur |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2752 | * the blocking poll will be released. |
| 2753 | */ |
| 2754 | static ssize_t show_irq(struct device *dev, |
| 2755 | struct device_attribute *attr, char *buf) |
| 2756 | { |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2757 | unsigned long name; |
| 2758 | unsigned int irq_index; |
| 2759 | int err; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2760 | |
Jingoo Han | 8420a24 | 2013-06-04 13:11:50 +0900 | [diff] [blame] | 2761 | err = kstrtoul(attr->attr.name, 0, &name); |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2762 | if (err) |
| 2763 | return err; |
| 2764 | |
| 2765 | irq_index = name - irq_first; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2766 | if (irq_index >= num_irqs) |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2767 | return -EINVAL; |
Lee Jones | c3f27a2 | 2014-07-02 11:22:10 +0100 | [diff] [blame] | 2768 | |
| 2769 | return sprintf(buf, "%u\n", irq_count[irq_index]); |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2770 | } |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2771 | |
| 2772 | static ssize_t ab8500_subscribe_write(struct file *file, |
| 2773 | const char __user *user_buf, |
| 2774 | size_t count, loff_t *ppos) |
| 2775 | { |
| 2776 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2777 | unsigned long user_val; |
| 2778 | int err; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2779 | unsigned int irq_index; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2780 | |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2781 | err = kstrtoul_from_user(user_buf, count, 0, &user_val); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2782 | if (err) |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2783 | return err; |
| 2784 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2785 | if (user_val < irq_first) { |
| 2786 | dev_err(dev, "debugfs error input < %d\n", irq_first); |
| 2787 | return -EINVAL; |
| 2788 | } |
| 2789 | if (user_val > irq_last) { |
| 2790 | dev_err(dev, "debugfs error input > %d\n", irq_last); |
| 2791 | return -EINVAL; |
| 2792 | } |
| 2793 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2794 | irq_index = user_val - irq_first; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2795 | if (irq_index >= num_irqs) |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2796 | return -EINVAL; |
| 2797 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2798 | /* |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2799 | * This will create a sysfs file named <irq-nr> which userspace can |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2800 | * use to select or poll and get the AB8500 events |
| 2801 | */ |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2802 | dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute), |
| 2803 | GFP_KERNEL); |
Lee Jones | f840e23 | 2013-07-19 08:44:50 +0100 | [diff] [blame] | 2804 | if (!dev_attr[irq_index]) |
| 2805 | return -ENOMEM; |
| 2806 | |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2807 | event_name[irq_index] = kmalloc(count, GFP_KERNEL); |
Lee Jones | d551c4c | 2013-07-19 08:53:24 +0100 | [diff] [blame] | 2808 | if (!event_name[irq_index]) |
| 2809 | return -ENOMEM; |
| 2810 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2811 | sprintf(event_name[irq_index], "%lu", user_val); |
| 2812 | dev_attr[irq_index]->show = show_irq; |
| 2813 | dev_attr[irq_index]->store = NULL; |
| 2814 | dev_attr[irq_index]->attr.name = event_name[irq_index]; |
| 2815 | dev_attr[irq_index]->attr.mode = S_IRUGO; |
| 2816 | err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2817 | if (err < 0) { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2818 | pr_info("sysfs_create_file failed %d\n", err); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2819 | return err; |
| 2820 | } |
| 2821 | |
| 2822 | err = request_threaded_irq(user_val, NULL, ab8500_debug_handler, |
Fabio Estevam | abe5b47 | 2015-05-16 15:42:15 -0300 | [diff] [blame] | 2823 | IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT, |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2824 | "ab8500-debug", &dev->kobj); |
| 2825 | if (err < 0) { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2826 | pr_info("request_threaded_irq failed %d, %lu\n", |
| 2827 | err, user_val); |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2828 | sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2829 | return err; |
| 2830 | } |
| 2831 | |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2832 | return count; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | static ssize_t ab8500_unsubscribe_write(struct file *file, |
| 2836 | const char __user *user_buf, |
| 2837 | size_t count, loff_t *ppos) |
| 2838 | { |
| 2839 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2840 | unsigned long user_val; |
| 2841 | int err; |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2842 | unsigned int irq_index; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2843 | |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2844 | err = kstrtoul_from_user(user_buf, count, 0, &user_val); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2845 | if (err) |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2846 | return err; |
| 2847 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2848 | if (user_val < irq_first) { |
| 2849 | dev_err(dev, "debugfs error input < %d\n", irq_first); |
| 2850 | return -EINVAL; |
| 2851 | } |
| 2852 | if (user_val > irq_last) { |
| 2853 | dev_err(dev, "debugfs error input > %d\n", irq_last); |
| 2854 | return -EINVAL; |
| 2855 | } |
| 2856 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2857 | irq_index = user_val - irq_first; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2858 | if (irq_index >= num_irqs) |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2859 | return -EINVAL; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2860 | |
Mattias Wallin | 0b337e7 | 2010-11-19 17:55:11 +0100 | [diff] [blame] | 2861 | /* Set irq count to 0 when unsubscribe */ |
| 2862 | irq_count[irq_index] = 0; |
| 2863 | |
| 2864 | if (dev_attr[irq_index]) |
| 2865 | sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); |
| 2866 | |
| 2867 | |
| 2868 | free_irq(user_val, &dev->kobj); |
| 2869 | kfree(event_name[irq_index]); |
| 2870 | kfree(dev_attr[irq_index]); |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2871 | |
srinidhi kasagar | 7b830ae | 2012-11-23 15:11:00 +0530 | [diff] [blame] | 2872 | return count; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2873 | } |
| 2874 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2875 | /* |
| 2876 | * - several deubgfs nodes fops |
| 2877 | */ |
| 2878 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2879 | static const struct file_operations ab8500_bank_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 2880 | .open = ab8500_bank_open, |
| 2881 | .write = ab8500_bank_write, |
| 2882 | .read = seq_read, |
| 2883 | .llseek = seq_lseek, |
| 2884 | .release = single_release, |
| 2885 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2886 | }; |
| 2887 | |
| 2888 | static const struct file_operations ab8500_address_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 2889 | .open = ab8500_address_open, |
| 2890 | .write = ab8500_address_write, |
| 2891 | .read = seq_read, |
| 2892 | .llseek = seq_lseek, |
| 2893 | .release = single_release, |
| 2894 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2895 | }; |
| 2896 | |
| 2897 | static const struct file_operations ab8500_val_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 2898 | .open = ab8500_val_open, |
| 2899 | .write = ab8500_val_write, |
| 2900 | .read = seq_read, |
| 2901 | .llseek = seq_lseek, |
| 2902 | .release = single_release, |
| 2903 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2904 | }; |
| 2905 | |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 2906 | static const struct file_operations ab8500_interrupts_fops = { |
| 2907 | .open = ab8500_interrupts_open, |
| 2908 | .read = seq_read, |
| 2909 | .llseek = seq_lseek, |
| 2910 | .release = single_release, |
| 2911 | .owner = THIS_MODULE, |
| 2912 | }; |
| 2913 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2914 | static const struct file_operations ab8500_subscribe_fops = { |
| 2915 | .open = ab8500_subscribe_unsubscribe_open, |
| 2916 | .write = ab8500_subscribe_write, |
| 2917 | .read = seq_read, |
| 2918 | .llseek = seq_lseek, |
| 2919 | .release = single_release, |
| 2920 | .owner = THIS_MODULE, |
| 2921 | }; |
| 2922 | |
| 2923 | static const struct file_operations ab8500_unsubscribe_fops = { |
| 2924 | .open = ab8500_subscribe_unsubscribe_open, |
| 2925 | .write = ab8500_unsubscribe_write, |
| 2926 | .read = seq_read, |
| 2927 | .llseek = seq_lseek, |
| 2928 | .release = single_release, |
| 2929 | .owner = THIS_MODULE, |
| 2930 | }; |
| 2931 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2932 | static const struct file_operations ab8500_hwreg_fops = { |
| 2933 | .open = ab8500_hwreg_open, |
| 2934 | .write = ab8500_hwreg_write, |
| 2935 | .read = seq_read, |
| 2936 | .llseek = seq_lseek, |
| 2937 | .release = single_release, |
| 2938 | .owner = THIS_MODULE, |
| 2939 | }; |
| 2940 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2941 | static struct dentry *ab8500_dir; |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2942 | static struct dentry *ab8500_gpadc_dir; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2943 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 2944 | static int ab8500_debug_probe(struct platform_device *plf) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2945 | { |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2946 | struct dentry *file; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2947 | struct ab8500 *ab8500; |
Linus Walleij | 6999181 | 2013-04-12 17:02:09 +0200 | [diff] [blame] | 2948 | struct resource *res; |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2949 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 2950 | debug_bank = AB8500_MISC; |
| 2951 | debug_address = AB8500_REV_REG & 0x00FF; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2952 | |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2953 | ab8500 = dev_get_drvdata(plf->dev.parent); |
| 2954 | num_irqs = ab8500->mask_size; |
| 2955 | |
Lee Jones | c18cf6d | 2013-05-23 16:25:05 +0100 | [diff] [blame] | 2956 | irq_count = devm_kzalloc(&plf->dev, |
| 2957 | sizeof(*irq_count)*num_irqs, GFP_KERNEL); |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2958 | if (!irq_count) |
| 2959 | return -ENOMEM; |
| 2960 | |
Lee Jones | c18cf6d | 2013-05-23 16:25:05 +0100 | [diff] [blame] | 2961 | dev_attr = devm_kzalloc(&plf->dev, |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2962 | sizeof(*dev_attr)*num_irqs, GFP_KERNEL); |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2963 | if (!dev_attr) |
Lee Jones | c18cf6d | 2013-05-23 16:25:05 +0100 | [diff] [blame] | 2964 | return -ENOMEM; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2965 | |
Lee Jones | c18cf6d | 2013-05-23 16:25:05 +0100 | [diff] [blame] | 2966 | event_name = devm_kzalloc(&plf->dev, |
| 2967 | sizeof(*event_name)*num_irqs, GFP_KERNEL); |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2968 | if (!event_name) |
Lee Jones | c18cf6d | 2013-05-23 16:25:05 +0100 | [diff] [blame] | 2969 | return -ENOMEM; |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 2970 | |
Linus Walleij | 6999181 | 2013-04-12 17:02:09 +0200 | [diff] [blame] | 2971 | res = platform_get_resource_byname(plf, 0, "IRQ_AB8500"); |
| 2972 | if (!res) { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2973 | dev_err(&plf->dev, "AB8500 irq not found, err %d\n", irq_first); |
| 2974 | return -ENXIO; |
Linus Walleij | 6999181 | 2013-04-12 17:02:09 +0200 | [diff] [blame] | 2975 | } |
| 2976 | irq_ab8500 = res->start; |
| 2977 | |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2978 | irq_first = platform_get_irq_byname(plf, "IRQ_FIRST"); |
| 2979 | if (irq_first < 0) { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2980 | dev_err(&plf->dev, "First irq not found, err %d\n", irq_first); |
Lee Jones | c18cf6d | 2013-05-23 16:25:05 +0100 | [diff] [blame] | 2981 | return irq_first; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | irq_last = platform_get_irq_byname(plf, "IRQ_LAST"); |
| 2985 | if (irq_last < 0) { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2986 | dev_err(&plf->dev, "Last irq not found, err %d\n", irq_last); |
Lee Jones | c18cf6d | 2013-05-23 16:25:05 +0100 | [diff] [blame] | 2987 | return irq_last; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 2988 | } |
| 2989 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 2990 | ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); |
| 2991 | if (!ab8500_dir) |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 2992 | goto err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 2993 | |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2994 | ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING, |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2995 | ab8500_dir); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 2996 | if (!ab8500_gpadc_dir) |
| 2997 | goto err; |
| 2998 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 2999 | file = debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir, |
| 3000 | &plf->dev, &ab8500_registers_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 3001 | if (!file) |
| 3002 | goto err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 3003 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3004 | file = debugfs_create_file("all-banks", S_IRUGO, ab8500_dir, |
| 3005 | &plf->dev, &ab8500_all_banks_fops); |
Mian Yousaf Kaukab | 42002c6 | 2012-01-26 15:39:20 +0100 | [diff] [blame] | 3006 | if (!file) |
| 3007 | goto err; |
| 3008 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3009 | file = debugfs_create_file("register-bank", |
| 3010 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3011 | ab8500_dir, &plf->dev, &ab8500_bank_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 3012 | if (!file) |
| 3013 | goto err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 3014 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3015 | file = debugfs_create_file("register-address", |
| 3016 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3017 | ab8500_dir, &plf->dev, &ab8500_address_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 3018 | if (!file) |
| 3019 | goto err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 3020 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3021 | file = debugfs_create_file("register-value", |
| 3022 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3023 | ab8500_dir, &plf->dev, &ab8500_val_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 3024 | if (!file) |
| 3025 | goto err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 3026 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3027 | file = debugfs_create_file("irq-subscribe", |
| 3028 | (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir, |
| 3029 | &plf->dev, &ab8500_subscribe_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 3030 | if (!file) |
| 3031 | goto err; |
Lee Jones | 4b8ac08 | 2013-01-14 16:10:36 +0000 | [diff] [blame] | 3032 | |
Lee Jones | 9581ae3 | 2012-07-06 16:11:50 +0200 | [diff] [blame] | 3033 | if (is_ab8500(ab8500)) { |
| 3034 | debug_ranges = ab8500_debug_ranges; |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 3035 | num_interrupt_lines = AB8500_NR_IRQS; |
Lee Jones | 9581ae3 | 2012-07-06 16:11:50 +0200 | [diff] [blame] | 3036 | } else if (is_ab8505(ab8500)) { |
| 3037 | debug_ranges = ab8505_debug_ranges; |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 3038 | num_interrupt_lines = AB8505_NR_IRQS; |
Lee Jones | 9581ae3 | 2012-07-06 16:11:50 +0200 | [diff] [blame] | 3039 | } else if (is_ab9540(ab8500)) { |
| 3040 | debug_ranges = ab8505_debug_ranges; |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 3041 | num_interrupt_lines = AB9540_NR_IRQS; |
Lee Jones | 9581ae3 | 2012-07-06 16:11:50 +0200 | [diff] [blame] | 3042 | } else if (is_ab8540(ab8500)) { |
Lee Jones | 971480f | 2012-11-19 12:20:03 +0100 | [diff] [blame] | 3043 | debug_ranges = ab8540_debug_ranges; |
Lee Jones | e436ddf | 2013-02-26 10:09:41 +0000 | [diff] [blame] | 3044 | num_interrupt_lines = AB8540_NR_IRQS; |
Lee Jones | 9581ae3 | 2012-07-06 16:11:50 +0200 | [diff] [blame] | 3045 | } |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 3046 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3047 | file = debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir, |
| 3048 | &plf->dev, &ab8500_interrupts_fops); |
Bengt Jonsson | 8f0eb43 | 2012-02-14 13:01:00 +0100 | [diff] [blame] | 3049 | if (!file) |
| 3050 | goto err; |
| 3051 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3052 | file = debugfs_create_file("irq-unsubscribe", |
| 3053 | (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir, |
| 3054 | &plf->dev, &ab8500_unsubscribe_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 3055 | if (!file) |
| 3056 | goto err; |
| 3057 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3058 | file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3059 | ab8500_dir, &plf->dev, &ab8500_hwreg_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3060 | if (!file) |
| 3061 | goto err; |
| 3062 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3063 | file = debugfs_create_file("all-modem-registers", |
| 3064 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3065 | ab8500_dir, &plf->dev, &ab8500_modem_fops); |
Lee Jones | c7ebaee | 2013-02-26 14:03:33 +0000 | [diff] [blame] | 3066 | if (!file) |
| 3067 | goto err; |
| 3068 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3069 | file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3070 | ab8500_gpadc_dir, &plf->dev, |
| 3071 | &ab8500_gpadc_bat_ctrl_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3072 | if (!file) |
| 3073 | goto err; |
| 3074 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3075 | file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3076 | ab8500_gpadc_dir, |
| 3077 | &plf->dev, &ab8500_gpadc_btemp_ball_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3078 | if (!file) |
| 3079 | goto err; |
| 3080 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3081 | file = debugfs_create_file("main_charger_v", |
| 3082 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3083 | ab8500_gpadc_dir, &plf->dev, |
| 3084 | &ab8500_gpadc_main_charger_v_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3085 | if (!file) |
| 3086 | goto err; |
| 3087 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3088 | file = debugfs_create_file("acc_detect1", |
| 3089 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3090 | ab8500_gpadc_dir, &plf->dev, |
| 3091 | &ab8500_gpadc_acc_detect1_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3092 | if (!file) |
| 3093 | goto err; |
| 3094 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3095 | file = debugfs_create_file("acc_detect2", |
| 3096 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3097 | ab8500_gpadc_dir, &plf->dev, |
| 3098 | &ab8500_gpadc_acc_detect2_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3099 | if (!file) |
| 3100 | goto err; |
| 3101 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3102 | file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3103 | ab8500_gpadc_dir, &plf->dev, |
| 3104 | &ab8500_gpadc_aux1_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3105 | if (!file) |
| 3106 | goto err; |
| 3107 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3108 | file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3109 | ab8500_gpadc_dir, &plf->dev, |
| 3110 | &ab8500_gpadc_aux2_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3111 | if (!file) |
| 3112 | goto err; |
| 3113 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3114 | file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3115 | ab8500_gpadc_dir, &plf->dev, |
| 3116 | &ab8500_gpadc_main_bat_v_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3117 | if (!file) |
| 3118 | goto err; |
| 3119 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3120 | file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3121 | ab8500_gpadc_dir, &plf->dev, |
| 3122 | &ab8500_gpadc_vbus_v_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3123 | if (!file) |
| 3124 | goto err; |
| 3125 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3126 | file = debugfs_create_file("main_charger_c", |
| 3127 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3128 | ab8500_gpadc_dir, &plf->dev, |
| 3129 | &ab8500_gpadc_main_charger_c_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3130 | if (!file) |
| 3131 | goto err; |
| 3132 | |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3133 | file = debugfs_create_file("usb_charger_c", |
| 3134 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3135 | ab8500_gpadc_dir, |
| 3136 | &plf->dev, &ab8500_gpadc_usb_charger_c_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3137 | if (!file) |
| 3138 | goto err; |
| 3139 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3140 | file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3141 | ab8500_gpadc_dir, &plf->dev, |
| 3142 | &ab8500_gpadc_bk_bat_v_fops); |
John Beckett | 1478a31 | 2011-05-31 13:54:27 +0100 | [diff] [blame] | 3143 | if (!file) |
| 3144 | goto err; |
| 3145 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3146 | file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3147 | ab8500_gpadc_dir, &plf->dev, |
| 3148 | &ab8500_gpadc_die_temp_fops); |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 3149 | if (!file) |
| 3150 | goto err; |
Lee Jones | 127629d | 2013-02-26 14:04:37 +0000 | [diff] [blame] | 3151 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3152 | file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3153 | ab8500_gpadc_dir, &plf->dev, |
| 3154 | &ab8500_gpadc_usb_id_fops); |
Lee Jones | 127629d | 2013-02-26 14:04:37 +0000 | [diff] [blame] | 3155 | if (!file) |
| 3156 | goto err; |
| 3157 | |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 3158 | if (is_ab8540(ab8500)) { |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3159 | file = debugfs_create_file("xtal_temp", |
| 3160 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3161 | ab8500_gpadc_dir, &plf->dev, |
| 3162 | &ab8540_gpadc_xtal_temp_fops); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 3163 | if (!file) |
| 3164 | goto err; |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3165 | file = debugfs_create_file("vbattruemeas", |
| 3166 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3167 | ab8500_gpadc_dir, &plf->dev, |
| 3168 | &ab8540_gpadc_vbat_true_meas_fops); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 3169 | if (!file) |
| 3170 | goto err; |
| 3171 | file = debugfs_create_file("batctrl_and_ibat", |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3172 | (S_IRUGO | S_IWUGO), |
| 3173 | ab8500_gpadc_dir, |
| 3174 | &plf->dev, |
| 3175 | &ab8540_gpadc_bat_ctrl_and_ibat_fops); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 3176 | if (!file) |
| 3177 | goto err; |
| 3178 | file = debugfs_create_file("vbatmeas_and_ibat", |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3179 | (S_IRUGO | S_IWUGO), |
| 3180 | ab8500_gpadc_dir, &plf->dev, |
| 3181 | &ab8540_gpadc_vbat_meas_and_ibat_fops); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 3182 | if (!file) |
| 3183 | goto err; |
| 3184 | file = debugfs_create_file("vbattruemeas_and_ibat", |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3185 | (S_IRUGO | S_IWUGO), |
| 3186 | ab8500_gpadc_dir, |
| 3187 | &plf->dev, |
| 3188 | &ab8540_gpadc_vbat_true_meas_and_ibat_fops); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 3189 | if (!file) |
| 3190 | goto err; |
| 3191 | file = debugfs_create_file("battemp_and_ibat", |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3192 | (S_IRUGO | S_IWUGO), |
| 3193 | ab8500_gpadc_dir, |
Lee Jones | 9f9ba15 | 2013-02-26 12:05:15 +0000 | [diff] [blame] | 3194 | &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 3195 | if (!file) |
| 3196 | goto err; |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3197 | file = debugfs_create_file("otp_calib", |
| 3198 | (S_IRUGO | S_IWUSR | S_IWGRP), |
| 3199 | ab8500_gpadc_dir, |
| 3200 | &plf->dev, &ab8540_gpadc_otp_calib_fops); |
Lee Jones | bc6b413 | 2013-02-26 14:02:31 +0000 | [diff] [blame] | 3201 | if (!file) |
| 3202 | goto err; |
| 3203 | } |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3204 | file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3205 | ab8500_gpadc_dir, &plf->dev, |
| 3206 | &ab8500_gpadc_avg_sample_fops); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 3207 | if (!file) |
| 3208 | goto err; |
| 3209 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3210 | file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3211 | ab8500_gpadc_dir, &plf->dev, |
| 3212 | &ab8500_gpadc_trig_edge_fops); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 3213 | if (!file) |
| 3214 | goto err; |
| 3215 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3216 | file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3217 | ab8500_gpadc_dir, &plf->dev, |
| 3218 | &ab8500_gpadc_trig_timer_fops); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 3219 | if (!file) |
| 3220 | goto err; |
| 3221 | |
Lee Jones | f38487f | 2013-02-26 14:09:08 +0000 | [diff] [blame] | 3222 | file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP), |
Lee Jones | 4362175 | 2014-07-14 18:29:16 +0100 | [diff] [blame] | 3223 | ab8500_gpadc_dir, &plf->dev, |
| 3224 | &ab8500_gpadc_conv_type_fops); |
Lee Jones | 7348234 | 2013-02-26 10:06:55 +0000 | [diff] [blame] | 3225 | if (!file) |
| 3226 | goto err; |
| 3227 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 3228 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 3229 | |
carriere etienne | 0fbce76 | 2011-04-08 16:26:36 +0200 | [diff] [blame] | 3230 | err: |
Fabian Frederick | 005d16b | 2014-06-28 13:58:17 +0200 | [diff] [blame] | 3231 | debugfs_remove_recursive(ab8500_dir); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 3232 | dev_err(&plf->dev, "failed to create debugfs entries.\n"); |
Linus Walleij | ddba25f | 2012-02-03 11:19:05 +0100 | [diff] [blame] | 3233 | |
Lee Jones | c18cf6d | 2013-05-23 16:25:05 +0100 | [diff] [blame] | 3234 | return -ENOMEM; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 3235 | } |
| 3236 | |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 3237 | static struct platform_driver ab8500_debug_driver = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 3238 | .driver = { |
| 3239 | .name = "ab8500-debug", |
Paul Gortmaker | 4b3f2b6 | 2016-10-29 21:24:37 -0400 | [diff] [blame] | 3240 | .suppress_bind_attrs = true, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 3241 | }, |
| 3242 | .probe = ab8500_debug_probe, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 3243 | }; |
| 3244 | |
| 3245 | static int __init ab8500_debug_init(void) |
| 3246 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 3247 | return platform_driver_register(&ab8500_debug_driver); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 3248 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 3249 | subsys_initcall(ab8500_debug_init); |