aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/fmc/fmc-write-eeprom.txt77
-rw-r--r--drivers/fmc/fmc-core.c15
2 files changed, 39 insertions, 53 deletions
diff --git a/Documentation/fmc/fmc-write-eeprom.txt b/Documentation/fmc/fmc-write-eeprom.txt
index 44a3bc678bf0..e0a9712156aa 100644
--- a/Documentation/fmc/fmc-write-eeprom.txt
+++ b/Documentation/fmc/fmc-write-eeprom.txt
@@ -9,7 +9,12 @@ Overwriting the EEPROM is not something you should do daily, and it is
9expected to only happen during manufacturing. For this reason, the 9expected to only happen during manufacturing. For this reason, the
10module makes it unlikely for the random user to change a working EEPROM. 10module makes it unlikely for the random user to change a working EEPROM.
11 11
12The module takes the following measures: 12However, since the EEPROM may include application-specific information
13other than the identification, later versions of this packages added
14write-support through sysfs. See *note Accessing the EEPROM::.
15
16To avoid damaging the EEPROM content, the module takes the following
17measures:
13 18
14 * It accepts a `file=' argument (within /lib/firmware) and if no 19 * It accepts a `file=' argument (within /lib/firmware) and if no
15 such argument is received, it doesn't write anything to EEPROM 20 such argument is received, it doesn't write anything to EEPROM
@@ -70,56 +75,24 @@ first time.
70 [ 132.899872] fake-fmc: Product name: FmcDelay1ns4cha 75 [ 132.899872] fake-fmc: Product name: FmcDelay1ns4cha
71 76
72 77
73Writing to the EEPROM 78Accessing the EEPROM
74===================== 79=====================
75 80
76Once you have created a binary file for your EEPROM, you can write it 81The bus creates a sysfs binary file called eeprom for each mezzanine it
77to the storage medium using the fmc-write-eeprom (See *note 82knows about:
78fmc-write-eeprom::, while relying on a carrier driver. The procedure 83
79here shown here uses the SPEC driver 84 spusa.root# cd /sys/bus/fmc/devices; ls -l */eeprom
80(`http://www.ohwr.org/projects/spec-sw'). 85 -r--r--r-- 1 root root 8192 Feb 21 12:30 FmcAdc100m14b4cha-0800/eeprom
81 86 -r--r--r-- 1 root root 8192 Feb 21 12:30 FmcDelay1ns4cha-0200/eeprom
82The example assumes no driver is already loaded (actually, I unloaded 87 -r--r--r-- 1 root root 8192 Feb 21 12:30 FmcDio5cha-0400/eeprom
83them by hand as everything loads automatically at boot time after you 88
84installed the modules), and shows kernel messages together with 89Everybody can read the files and the superuser can also modify it, but
85commands. Here the prompt is spusa.root# and two SPEC cards are plugged 90the operation may on the carrier driver, if the carrier is unable to
86in the system. 91access the I2C bus. For example, the spec driver can access the bus
87 92only with its golden gateware: after a mezzanine driver reprogrammed
88 spusa.root# insmod fmc.ko 93the FPGA with a custom circuit, the carrier is unable to access the
89 spusa.root# insmod spec.ko 94EEPROM and returns ENOTSUPP.
90 [13972.382818] spec 0000:02:00.0: probe for device 0002:0000 95
91 [13972.392773] spec 0000:02:00.0: got file "fmc/spec-init.bin", 1484404 (0x16a674) bytes 96An alternative way to write the EEPROM is the mezzanine driver
92 [13972.591388] spec 0000:02:00.0: FPGA programming successful 97fmc-write-eeprom (See *note fmc-write-eeprom::), but the procedure is
93 [13972.883011] spec 0000:02:00.0: EEPROM has no FRU information 98more complex.
94 [13972.888719] spec 0000:02:00.0: No device_id filled, using index
95 [13972.894676] spec 0000:02:00.0: No mezzanine_name found
96 [13972.899863] /home/rubini/wip/spec-sw/kernel/spec-gpio.c - spec_gpio_init
97 [13972.906578] spec 0000:04:00.0: probe for device 0004:0000
98 [13972.916509] spec 0000:04:00.0: got file "fmc/spec-init.bin", 1484404 (0x16a674) bytes
99 [13973.115096] spec 0000:04:00.0: FPGA programming successful
100 [13973.401798] spec 0000:04:00.0: EEPROM has no FRU information
101 [13973.407474] spec 0000:04:00.0: No device_id filled, using index
102 [13973.413417] spec 0000:04:00.0: No mezzanine_name found
103 [13973.418600] /home/rubini/wip/spec-sw/kernel/spec-gpio.c - spec_gpio_init
104 spusa.root# ls /sys/bus/fmc/devices
105 fmc-0000 fmc-0001
106 spusa.root# insmod fmc-write-eeprom.ko busid=0x0200 file=fdelay-eeprom.bin
107 [14103.966259] spec 0000:02:00.0: Matching an generic driver (no ID)
108 [14103.975519] spec 0000:02:00.0: programming 6155 bytes
109 [14126.373762] spec 0000:02:00.0: write_eeprom: success
110 [14126.378770] spec 0000:04:00.0: Matching an generic driver (no ID)
111 [14126.384903] spec 0000:04:00.0: fmc_write_eeprom: no filename given: not programming
112 [14126.392600] fmc_write_eeprom: probe of fmc-0001 failed with error -2
113
114Reading back the EEPROM
115=======================
116
117In order to read back the binary content of the EEPROM of your
118mezzanine device, the bus creates a read-only sysfs file called eeprom
119for each mezzanine it knows about:
120
121 spusa.root# cd /sys/bus/fmc/devices; ls -l */eeprom
122 -r--r--r-- 1 root root 8192 Apr 9 16:53 FmcDelay1ns4cha-f001/eeprom
123 -r--r--r-- 1 root root 8192 Apr 9 17:19 fake-design-for-testing-f002/eeprom
124 -r--r--r-- 1 root root 8192 Apr 9 17:19 fake-design-for-testing-f003/eeprom
125 -r--r--r-- 1 root root 8192 Apr 9 17:19 fmc-f004/eeprom
diff --git a/drivers/fmc/fmc-core.c b/drivers/fmc/fmc-core.c
index 5a5e616c6324..353fc546fb08 100644
--- a/drivers/fmc/fmc-core.c
+++ b/drivers/fmc/fmc-core.c
@@ -99,10 +99,23 @@ static ssize_t fmc_read_eeprom(struct file *file, struct kobject *kobj,
99 return count; 99 return count;
100} 100}
101 101
102static ssize_t fmc_write_eeprom(struct file *file, struct kobject *kobj,
103 struct bin_attribute *bin_attr,
104 char *buf, loff_t off, size_t count)
105{
106 struct device *dev;
107 struct fmc_device *fmc;
108
109 dev = container_of(kobj, struct device, kobj);
110 fmc = container_of(dev, struct fmc_device, dev);
111 return fmc->op->write_ee(fmc, off, buf, count);
112}
113
102static struct bin_attribute fmc_eeprom_attr = { 114static struct bin_attribute fmc_eeprom_attr = {
103 .attr = { .name = "eeprom", .mode = S_IRUGO, }, 115 .attr = { .name = "eeprom", .mode = S_IRUGO | S_IWUSR, },
104 .size = 8192, /* more or less standard */ 116 .size = 8192, /* more or less standard */
105 .read = fmc_read_eeprom, 117 .read = fmc_read_eeprom,
118 .write = fmc_write_eeprom,
106}; 119};
107 120
108/* 121/*