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