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 | */ |
| 7 | |
| 8 | #include <linux/seq_file.h> |
| 9 | #include <linux/uaccess.h> |
| 10 | #include <linux/fs.h> |
Paul Gortmaker | 4e36dd3 | 2011-07-03 15:13:27 -0400 | [diff] [blame] | 11 | #include <linux/module.h> |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 12 | #include <linux/debugfs.h> |
| 13 | #include <linux/platform_device.h> |
| 14 | |
| 15 | #include <linux/mfd/abx500.h> |
Linus Walleij | ee66e65 | 2011-12-02 14:16:33 +0100 | [diff] [blame] | 16 | #include <linux/mfd/abx500/ab8500.h> |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 17 | |
| 18 | static u32 debug_bank; |
| 19 | static u32 debug_address; |
| 20 | |
| 21 | /** |
| 22 | * struct ab8500_reg_range |
| 23 | * @first: the first address of the range |
| 24 | * @last: the last address of the range |
| 25 | * @perm: access permissions for the range |
| 26 | */ |
| 27 | struct ab8500_reg_range { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 28 | u8 first; |
| 29 | u8 last; |
| 30 | u8 perm; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | /** |
| 34 | * struct ab8500_i2c_ranges |
| 35 | * @num_ranges: the number of ranges in the list |
| 36 | * @bankid: bank identifier |
| 37 | * @range: the list of register ranges |
| 38 | */ |
| 39 | struct ab8500_i2c_ranges { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 40 | u8 num_ranges; |
| 41 | u8 bankid; |
| 42 | const struct ab8500_reg_range *range; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | #define AB8500_NAME_STRING "ab8500" |
| 46 | #define AB8500_NUM_BANKS 22 |
| 47 | |
| 48 | #define AB8500_REV_REG 0x80 |
| 49 | |
| 50 | static struct ab8500_i2c_ranges debug_ranges[AB8500_NUM_BANKS] = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 51 | [0x0] = { |
| 52 | .num_ranges = 0, |
| 53 | .range = 0, |
| 54 | }, |
| 55 | [AB8500_SYS_CTRL1_BLOCK] = { |
| 56 | .num_ranges = 3, |
| 57 | .range = (struct ab8500_reg_range[]) { |
| 58 | { |
| 59 | .first = 0x00, |
| 60 | .last = 0x02, |
| 61 | }, |
| 62 | { |
| 63 | .first = 0x42, |
| 64 | .last = 0x42, |
| 65 | }, |
| 66 | { |
| 67 | .first = 0x80, |
| 68 | .last = 0x81, |
| 69 | }, |
| 70 | }, |
| 71 | }, |
| 72 | [AB8500_SYS_CTRL2_BLOCK] = { |
| 73 | .num_ranges = 4, |
| 74 | .range = (struct ab8500_reg_range[]) { |
| 75 | { |
| 76 | .first = 0x00, |
| 77 | .last = 0x0D, |
| 78 | }, |
| 79 | { |
| 80 | .first = 0x0F, |
| 81 | .last = 0x17, |
| 82 | }, |
| 83 | { |
| 84 | .first = 0x30, |
| 85 | .last = 0x30, |
| 86 | }, |
| 87 | { |
| 88 | .first = 0x32, |
| 89 | .last = 0x33, |
| 90 | }, |
| 91 | }, |
| 92 | }, |
| 93 | [AB8500_REGU_CTRL1] = { |
| 94 | .num_ranges = 3, |
| 95 | .range = (struct ab8500_reg_range[]) { |
| 96 | { |
| 97 | .first = 0x00, |
| 98 | .last = 0x00, |
| 99 | }, |
| 100 | { |
| 101 | .first = 0x03, |
| 102 | .last = 0x10, |
| 103 | }, |
| 104 | { |
| 105 | .first = 0x80, |
| 106 | .last = 0x84, |
| 107 | }, |
| 108 | }, |
| 109 | }, |
| 110 | [AB8500_REGU_CTRL2] = { |
| 111 | .num_ranges = 5, |
| 112 | .range = (struct ab8500_reg_range[]) { |
| 113 | { |
| 114 | .first = 0x00, |
| 115 | .last = 0x15, |
| 116 | }, |
| 117 | { |
| 118 | .first = 0x17, |
| 119 | .last = 0x19, |
| 120 | }, |
| 121 | { |
| 122 | .first = 0x1B, |
| 123 | .last = 0x1D, |
| 124 | }, |
| 125 | { |
| 126 | .first = 0x1F, |
| 127 | .last = 0x22, |
| 128 | }, |
| 129 | { |
| 130 | .first = 0x40, |
| 131 | .last = 0x44, |
| 132 | }, |
| 133 | /* 0x80-0x8B is SIM registers and should |
| 134 | * not be accessed from here */ |
| 135 | }, |
| 136 | }, |
| 137 | [AB8500_USB] = { |
| 138 | .num_ranges = 2, |
| 139 | .range = (struct ab8500_reg_range[]) { |
| 140 | { |
| 141 | .first = 0x80, |
| 142 | .last = 0x83, |
| 143 | }, |
| 144 | { |
| 145 | .first = 0x87, |
| 146 | .last = 0x8A, |
| 147 | }, |
| 148 | }, |
| 149 | }, |
| 150 | [AB8500_TVOUT] = { |
| 151 | .num_ranges = 9, |
| 152 | .range = (struct ab8500_reg_range[]) { |
| 153 | { |
| 154 | .first = 0x00, |
| 155 | .last = 0x12, |
| 156 | }, |
| 157 | { |
| 158 | .first = 0x15, |
| 159 | .last = 0x17, |
| 160 | }, |
| 161 | { |
| 162 | .first = 0x19, |
| 163 | .last = 0x21, |
| 164 | }, |
| 165 | { |
| 166 | .first = 0x27, |
| 167 | .last = 0x2C, |
| 168 | }, |
| 169 | { |
| 170 | .first = 0x41, |
| 171 | .last = 0x41, |
| 172 | }, |
| 173 | { |
| 174 | .first = 0x45, |
| 175 | .last = 0x5B, |
| 176 | }, |
| 177 | { |
| 178 | .first = 0x5D, |
| 179 | .last = 0x5D, |
| 180 | }, |
| 181 | { |
| 182 | .first = 0x69, |
| 183 | .last = 0x69, |
| 184 | }, |
| 185 | { |
| 186 | .first = 0x80, |
| 187 | .last = 0x81, |
| 188 | }, |
| 189 | }, |
| 190 | }, |
| 191 | [AB8500_DBI] = { |
| 192 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 193 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 194 | }, |
| 195 | [AB8500_ECI_AV_ACC] = { |
| 196 | .num_ranges = 1, |
| 197 | .range = (struct ab8500_reg_range[]) { |
| 198 | { |
| 199 | .first = 0x80, |
| 200 | .last = 0x82, |
| 201 | }, |
| 202 | }, |
| 203 | }, |
| 204 | [0x9] = { |
| 205 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 206 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 207 | }, |
| 208 | [AB8500_GPADC] = { |
| 209 | .num_ranges = 1, |
| 210 | .range = (struct ab8500_reg_range[]) { |
| 211 | { |
| 212 | .first = 0x00, |
| 213 | .last = 0x08, |
| 214 | }, |
| 215 | }, |
| 216 | }, |
| 217 | [AB8500_CHARGER] = { |
| 218 | .num_ranges = 8, |
| 219 | .range = (struct ab8500_reg_range[]) { |
| 220 | { |
| 221 | .first = 0x00, |
| 222 | .last = 0x03, |
| 223 | }, |
| 224 | { |
| 225 | .first = 0x05, |
| 226 | .last = 0x05, |
| 227 | }, |
| 228 | { |
| 229 | .first = 0x40, |
| 230 | .last = 0x40, |
| 231 | }, |
| 232 | { |
| 233 | .first = 0x42, |
| 234 | .last = 0x42, |
| 235 | }, |
| 236 | { |
| 237 | .first = 0x44, |
| 238 | .last = 0x44, |
| 239 | }, |
| 240 | { |
| 241 | .first = 0x50, |
| 242 | .last = 0x55, |
| 243 | }, |
| 244 | { |
| 245 | .first = 0x80, |
| 246 | .last = 0x82, |
| 247 | }, |
| 248 | { |
| 249 | .first = 0xC0, |
| 250 | .last = 0xC2, |
| 251 | }, |
| 252 | }, |
| 253 | }, |
| 254 | [AB8500_GAS_GAUGE] = { |
| 255 | .num_ranges = 3, |
| 256 | .range = (struct ab8500_reg_range[]) { |
| 257 | { |
| 258 | .first = 0x00, |
| 259 | .last = 0x00, |
| 260 | }, |
| 261 | { |
| 262 | .first = 0x07, |
| 263 | .last = 0x0A, |
| 264 | }, |
| 265 | { |
| 266 | .first = 0x10, |
| 267 | .last = 0x14, |
| 268 | }, |
| 269 | }, |
| 270 | }, |
| 271 | [AB8500_AUDIO] = { |
| 272 | .num_ranges = 1, |
| 273 | .range = (struct ab8500_reg_range[]) { |
| 274 | { |
| 275 | .first = 0x00, |
| 276 | .last = 0x6F, |
| 277 | }, |
| 278 | }, |
| 279 | }, |
| 280 | [AB8500_INTERRUPT] = { |
| 281 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 282 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 283 | }, |
| 284 | [AB8500_RTC] = { |
| 285 | .num_ranges = 1, |
| 286 | .range = (struct ab8500_reg_range[]) { |
| 287 | { |
| 288 | .first = 0x00, |
| 289 | .last = 0x0F, |
| 290 | }, |
| 291 | }, |
| 292 | }, |
| 293 | [AB8500_MISC] = { |
| 294 | .num_ranges = 8, |
| 295 | .range = (struct ab8500_reg_range[]) { |
| 296 | { |
| 297 | .first = 0x00, |
| 298 | .last = 0x05, |
| 299 | }, |
| 300 | { |
| 301 | .first = 0x10, |
| 302 | .last = 0x15, |
| 303 | }, |
| 304 | { |
| 305 | .first = 0x20, |
| 306 | .last = 0x25, |
| 307 | }, |
| 308 | { |
| 309 | .first = 0x30, |
| 310 | .last = 0x35, |
| 311 | }, |
| 312 | { |
| 313 | .first = 0x40, |
| 314 | .last = 0x45, |
| 315 | }, |
| 316 | { |
| 317 | .first = 0x50, |
| 318 | .last = 0x50, |
| 319 | }, |
| 320 | { |
| 321 | .first = 0x60, |
| 322 | .last = 0x67, |
| 323 | }, |
| 324 | { |
| 325 | .first = 0x80, |
| 326 | .last = 0x80, |
| 327 | }, |
| 328 | }, |
| 329 | }, |
| 330 | [0x11] = { |
| 331 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 332 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 333 | }, |
| 334 | [0x12] = { |
| 335 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 336 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 337 | }, |
| 338 | [0x13] = { |
| 339 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 340 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 341 | }, |
| 342 | [0x14] = { |
| 343 | .num_ranges = 0, |
Mark Brown | 87fff23 | 2010-12-13 14:06:47 +0000 | [diff] [blame] | 344 | .range = NULL, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 345 | }, |
| 346 | [AB8500_OTP_EMUL] = { |
| 347 | .num_ranges = 1, |
| 348 | .range = (struct ab8500_reg_range[]) { |
| 349 | { |
| 350 | .first = 0x01, |
| 351 | .last = 0x0F, |
| 352 | }, |
| 353 | }, |
| 354 | }, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | static int ab8500_registers_print(struct seq_file *s, void *p) |
| 358 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 359 | struct device *dev = s->private; |
| 360 | unsigned int i; |
| 361 | u32 bank = debug_bank; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 362 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 363 | seq_printf(s, AB8500_NAME_STRING " register values:\n"); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 364 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 365 | seq_printf(s, " bank %u:\n", bank); |
| 366 | for (i = 0; i < debug_ranges[bank].num_ranges; i++) { |
| 367 | u32 reg; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 368 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 369 | for (reg = debug_ranges[bank].range[i].first; |
| 370 | reg <= debug_ranges[bank].range[i].last; |
| 371 | reg++) { |
| 372 | u8 value; |
| 373 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 374 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 375 | err = abx500_get_register_interruptible(dev, |
| 376 | (u8)bank, (u8)reg, &value); |
| 377 | if (err < 0) { |
| 378 | dev_err(dev, "ab->read fail %d\n", err); |
| 379 | return err; |
| 380 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 381 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 382 | err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", bank, |
| 383 | reg, value); |
| 384 | if (err < 0) { |
| 385 | dev_err(dev, "seq_printf overflow\n"); |
| 386 | /* Error is not returned here since |
| 387 | * the output is wanted in any case */ |
| 388 | return 0; |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static int ab8500_registers_open(struct inode *inode, struct file *file) |
| 396 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 397 | return single_open(file, ab8500_registers_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | static const struct file_operations ab8500_registers_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 401 | .open = ab8500_registers_open, |
| 402 | .read = seq_read, |
| 403 | .llseek = seq_lseek, |
| 404 | .release = single_release, |
| 405 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 406 | }; |
| 407 | |
| 408 | static int ab8500_bank_print(struct seq_file *s, void *p) |
| 409 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 410 | return seq_printf(s, "%d\n", debug_bank); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static int ab8500_bank_open(struct inode *inode, struct file *file) |
| 414 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 415 | return single_open(file, ab8500_bank_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | static ssize_t ab8500_bank_write(struct file *file, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 419 | const char __user *user_buf, |
| 420 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 421 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 422 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 423 | unsigned long user_bank; |
| 424 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 425 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 426 | /* Get userspace string and assure termination */ |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 427 | err = kstrtoul_from_user(user_buf, count, 0, &user_bank); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 428 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 429 | return err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 430 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 431 | if (user_bank >= AB8500_NUM_BANKS) { |
| 432 | dev_err(dev, "debugfs error input > number of banks\n"); |
| 433 | return -EINVAL; |
| 434 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 435 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 436 | debug_bank = user_bank; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 437 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 438 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static int ab8500_address_print(struct seq_file *s, void *p) |
| 442 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 443 | return seq_printf(s, "0x%02X\n", debug_address); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | static int ab8500_address_open(struct inode *inode, struct file *file) |
| 447 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 448 | return single_open(file, ab8500_address_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | static ssize_t ab8500_address_write(struct file *file, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 452 | const char __user *user_buf, |
| 453 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 454 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 455 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 456 | unsigned long user_address; |
| 457 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 458 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 459 | /* Get userspace string and assure termination */ |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 460 | err = kstrtoul_from_user(user_buf, count, 0, &user_address); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 461 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 462 | return err; |
| 463 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 464 | if (user_address > 0xff) { |
| 465 | dev_err(dev, "debugfs error input > 0xff\n"); |
| 466 | return -EINVAL; |
| 467 | } |
| 468 | debug_address = user_address; |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 469 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | static int ab8500_val_print(struct seq_file *s, void *p) |
| 473 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 474 | struct device *dev = s->private; |
| 475 | int ret; |
| 476 | u8 regvalue; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 477 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 478 | ret = abx500_get_register_interruptible(dev, |
| 479 | (u8)debug_bank, (u8)debug_address, ®value); |
| 480 | if (ret < 0) { |
| 481 | dev_err(dev, "abx500_get_reg fail %d, %d\n", |
| 482 | ret, __LINE__); |
| 483 | return -EINVAL; |
| 484 | } |
| 485 | seq_printf(s, "0x%02X\n", regvalue); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 486 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 487 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | static int ab8500_val_open(struct inode *inode, struct file *file) |
| 491 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 492 | return single_open(file, ab8500_val_print, inode->i_private); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static ssize_t ab8500_val_write(struct file *file, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 496 | const char __user *user_buf, |
| 497 | size_t count, loff_t *ppos) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 498 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 499 | struct device *dev = ((struct seq_file *)(file->private_data))->private; |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 500 | unsigned long user_val; |
| 501 | int err; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 502 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 503 | /* Get userspace string and assure termination */ |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 504 | err = kstrtoul_from_user(user_buf, count, 0, &user_val); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 505 | if (err) |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 506 | return err; |
| 507 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 508 | if (user_val > 0xff) { |
| 509 | dev_err(dev, "debugfs error input > 0xff\n"); |
| 510 | return -EINVAL; |
| 511 | } |
| 512 | err = abx500_set_register_interruptible(dev, |
| 513 | (u8)debug_bank, debug_address, (u8)user_val); |
| 514 | if (err < 0) { |
| 515 | printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__); |
| 516 | return -EINVAL; |
| 517 | } |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 518 | |
Peter Huewe | 8504d63 | 2011-06-06 22:43:32 +0200 | [diff] [blame] | 519 | return count; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static const struct file_operations ab8500_bank_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 523 | .open = ab8500_bank_open, |
| 524 | .write = ab8500_bank_write, |
| 525 | .read = seq_read, |
| 526 | .llseek = seq_lseek, |
| 527 | .release = single_release, |
| 528 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | static const struct file_operations ab8500_address_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 532 | .open = ab8500_address_open, |
| 533 | .write = ab8500_address_write, |
| 534 | .read = seq_read, |
| 535 | .llseek = seq_lseek, |
| 536 | .release = single_release, |
| 537 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 538 | }; |
| 539 | |
| 540 | static const struct file_operations ab8500_val_fops = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 541 | .open = ab8500_val_open, |
| 542 | .write = ab8500_val_write, |
| 543 | .read = seq_read, |
| 544 | .llseek = seq_lseek, |
| 545 | .release = single_release, |
| 546 | .owner = THIS_MODULE, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 547 | }; |
| 548 | |
| 549 | static struct dentry *ab8500_dir; |
| 550 | static struct dentry *ab8500_reg_file; |
| 551 | static struct dentry *ab8500_bank_file; |
| 552 | static struct dentry *ab8500_address_file; |
| 553 | static struct dentry *ab8500_val_file; |
| 554 | |
| 555 | static int __devinit ab8500_debug_probe(struct platform_device *plf) |
| 556 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 557 | debug_bank = AB8500_MISC; |
| 558 | debug_address = AB8500_REV_REG & 0x00FF; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 559 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 560 | ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); |
| 561 | if (!ab8500_dir) |
| 562 | goto exit_no_debugfs; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 563 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 564 | ab8500_reg_file = debugfs_create_file("all-bank-registers", |
| 565 | S_IRUGO, ab8500_dir, &plf->dev, &ab8500_registers_fops); |
| 566 | if (!ab8500_reg_file) |
| 567 | goto exit_destroy_dir; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 568 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 569 | ab8500_bank_file = debugfs_create_file("register-bank", |
Vasiliy Kulikov | 44bdcb5 | 2011-02-04 15:23:43 +0300 | [diff] [blame] | 570 | (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_bank_fops); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 571 | if (!ab8500_bank_file) |
| 572 | goto exit_destroy_reg; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 573 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 574 | ab8500_address_file = debugfs_create_file("register-address", |
Vasiliy Kulikov | 44bdcb5 | 2011-02-04 15:23:43 +0300 | [diff] [blame] | 575 | (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 576 | &ab8500_address_fops); |
| 577 | if (!ab8500_address_file) |
| 578 | goto exit_destroy_bank; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 579 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 580 | ab8500_val_file = debugfs_create_file("register-value", |
Vasiliy Kulikov | 44bdcb5 | 2011-02-04 15:23:43 +0300 | [diff] [blame] | 581 | (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_val_fops); |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 582 | if (!ab8500_val_file) |
| 583 | goto exit_destroy_address; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 584 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 585 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 586 | |
| 587 | exit_destroy_address: |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 588 | debugfs_remove(ab8500_address_file); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 589 | exit_destroy_bank: |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 590 | debugfs_remove(ab8500_bank_file); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 591 | exit_destroy_reg: |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 592 | debugfs_remove(ab8500_reg_file); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 593 | exit_destroy_dir: |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 594 | debugfs_remove(ab8500_dir); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 595 | exit_no_debugfs: |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 596 | dev_err(&plf->dev, "failed to create debugfs entries.\n"); |
| 597 | return -ENOMEM; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static int __devexit ab8500_debug_remove(struct platform_device *plf) |
| 601 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 602 | debugfs_remove(ab8500_val_file); |
| 603 | debugfs_remove(ab8500_address_file); |
| 604 | debugfs_remove(ab8500_bank_file); |
| 605 | debugfs_remove(ab8500_reg_file); |
| 606 | debugfs_remove(ab8500_dir); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 607 | |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 608 | return 0; |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | static struct platform_driver ab8500_debug_driver = { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 612 | .driver = { |
| 613 | .name = "ab8500-debug", |
| 614 | .owner = THIS_MODULE, |
| 615 | }, |
| 616 | .probe = ab8500_debug_probe, |
| 617 | .remove = __devexit_p(ab8500_debug_remove) |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 618 | }; |
| 619 | |
| 620 | static int __init ab8500_debug_init(void) |
| 621 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 622 | return platform_driver_register(&ab8500_debug_driver); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | static void __exit ab8500_debug_exit(void) |
| 626 | { |
Mattias Wallin | d7b9f32 | 2010-11-26 13:06:39 +0100 | [diff] [blame] | 627 | platform_driver_unregister(&ab8500_debug_driver); |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 628 | } |
| 629 | subsys_initcall(ab8500_debug_init); |
| 630 | module_exit(ab8500_debug_exit); |
| 631 | |
| 632 | MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com"); |
| 633 | MODULE_DESCRIPTION("AB8500 DEBUG"); |
| 634 | MODULE_LICENSE("GPL v2"); |