staging: erofs: integrate decompression inplace
[linux/fpc-iii.git] / drivers / fmc / fmc-dump.c
blob6c81dbde1d169f6e9c98bbb55bfb4da0e039b324
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2013 CERN (www.cern.ch)
4 * Author: Alessandro Rubini <rubini@gnudd.com>
6 * This work is part of the White Rabbit project, a research effort led
7 * by CERN, the European Institute for Nuclear Research.
8 */
9 #include <linux/kernel.h>
10 #include <linux/moduleparam.h>
11 #include <linux/device.h>
12 #include <linux/fmc.h>
13 #include <linux/fmc-sdb.h>
15 static int fmc_must_dump_eeprom;
16 module_param_named(dump_eeprom, fmc_must_dump_eeprom, int, 0644);
18 #define LINELEN 16
20 /* Dumping 8k takes oh so much: avoid duplicate lines */
21 static const uint8_t *dump_line(int addr, const uint8_t *line,
22 const uint8_t *prev)
24 int i;
26 if (!prev || memcmp(line, prev, LINELEN)) {
27 pr_info("%04x: ", addr);
28 for (i = 0; i < LINELEN; ) {
29 printk(KERN_CONT "%02x", line[i]);
30 i++;
31 printk(i & 3 ? " " : i & (LINELEN - 1) ? " " : "\n");
33 return line;
35 /* repeated line */
36 if (line == prev + LINELEN)
37 pr_info("[...]\n");
38 return prev;
41 void fmc_dump_eeprom(const struct fmc_device *fmc)
43 const uint8_t *line, *prev;
44 int i;
46 if (!fmc_must_dump_eeprom)
47 return;
49 pr_info("FMC: %s (%s), slot %i, device %s\n", dev_name(fmc->hwdev),
50 fmc->carrier_name, fmc->slot_id, dev_name(&fmc->dev));
51 pr_info("FMC: dumping eeprom 0x%x (%i) bytes\n", fmc->eeprom_len,
52 fmc->eeprom_len);
54 line = fmc->eeprom;
55 prev = NULL;
56 for (i = 0; i < fmc->eeprom_len; i += LINELEN, line += LINELEN)
57 prev = dump_line(i, line, prev);