Linux 4.19.133
[linux/fpc-iii.git] / drivers / fmc / fmc-dump.c
blobcd1df475b254380b6dfe09b7e7fb07b734e0de9a
1 /*
2 * Copyright (C) 2013 CERN (www.cern.ch)
3 * Author: Alessandro Rubini <rubini@gnudd.com>
5 * Released according to the GNU GPL, version 2 or any later version.
7 * This work is part of the White Rabbit project, a research effort led
8 * by CERN, the European Institute for Nuclear Research.
9 */
10 #include <linux/kernel.h>
11 #include <linux/moduleparam.h>
12 #include <linux/device.h>
13 #include <linux/fmc.h>
14 #include <linux/fmc-sdb.h>
16 static int fmc_must_dump_eeprom;
17 module_param_named(dump_eeprom, fmc_must_dump_eeprom, int, 0644);
19 #define LINELEN 16
21 /* Dumping 8k takes oh so much: avoid duplicate lines */
22 static const uint8_t *dump_line(int addr, const uint8_t *line,
23 const uint8_t *prev)
25 int i;
27 if (!prev || memcmp(line, prev, LINELEN)) {
28 pr_info("%04x: ", addr);
29 for (i = 0; i < LINELEN; ) {
30 printk(KERN_CONT "%02x", line[i]);
31 i++;
32 printk(i & 3 ? " " : i & (LINELEN - 1) ? " " : "\n");
34 return line;
36 /* repeated line */
37 if (line == prev + LINELEN)
38 pr_info("[...]\n");
39 return prev;
42 void fmc_dump_eeprom(const struct fmc_device *fmc)
44 const uint8_t *line, *prev;
45 int i;
47 if (!fmc_must_dump_eeprom)
48 return;
50 pr_info("FMC: %s (%s), slot %i, device %s\n", dev_name(fmc->hwdev),
51 fmc->carrier_name, fmc->slot_id, dev_name(&fmc->dev));
52 pr_info("FMC: dumping eeprom 0x%x (%i) bytes\n", fmc->eeprom_len,
53 fmc->eeprom_len);
55 line = fmc->eeprom;
56 prev = NULL;
57 for (i = 0; i < fmc->eeprom_len; i += LINELEN, line += LINELEN)
58 prev = dump_line(i, line, prev);