aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/bcma/sprom.c
diff options
context:
space:
mode:
authorRafał Miłecki <zajec5@gmail.com>2013-05-13 16:07:51 -0400
committerJohn W. Linville <linville@tuxdriver.com>2013-05-22 15:08:40 -0400
commit5179ed7c1bc1d4599f9643f9711c090648602f4b (patch)
treeaa1544226359dc29b3c907a6c3431fb21e938b02 /drivers/bcma/sprom.c
parent224c9c2366efe7f32496c1b7ef82f9b6424817dd (diff)
bcma: don't hardcode SPROM length
Pass it as an argument to all functions. This is requires as newer SPROM revisions have different lengths. Signed-off-by: Rafał Miłecki <zajec5@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/bcma/sprom.c')
-rw-r--r--drivers/bcma/sprom.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/drivers/bcma/sprom.c b/drivers/bcma/sprom.c
index 8934298a638d..5386cddba43e 100644
--- a/drivers/bcma/sprom.c
+++ b/drivers/bcma/sprom.c
@@ -72,12 +72,12 @@ fail:
72 * R/W ops. 72 * R/W ops.
73 **************************************************/ 73 **************************************************/
74 74
75static void bcma_sprom_read(struct bcma_bus *bus, u16 offset, u16 *sprom) 75static void bcma_sprom_read(struct bcma_bus *bus, u16 offset, u16 *sprom,
76 size_t words)
76{ 77{
77 int i; 78 int i;
78 for (i = 0; i < SSB_SPROMSIZE_WORDS_R4; i++) 79 for (i = 0; i < words; i++)
79 sprom[i] = bcma_read16(bus->drv_cc.core, 80 sprom[i] = bcma_read16(bus->drv_cc.core, offset + (i * 2));
80 offset + (i * 2));
81} 81}
82 82
83/************************************************** 83/**************************************************
@@ -124,29 +124,29 @@ static inline u8 bcma_crc8(u8 crc, u8 data)
124 return t[crc ^ data]; 124 return t[crc ^ data];
125} 125}
126 126
127static u8 bcma_sprom_crc(const u16 *sprom) 127static u8 bcma_sprom_crc(const u16 *sprom, size_t words)
128{ 128{
129 int word; 129 int word;
130 u8 crc = 0xFF; 130 u8 crc = 0xFF;
131 131
132 for (word = 0; word < SSB_SPROMSIZE_WORDS_R4 - 1; word++) { 132 for (word = 0; word < words - 1; word++) {
133 crc = bcma_crc8(crc, sprom[word] & 0x00FF); 133 crc = bcma_crc8(crc, sprom[word] & 0x00FF);
134 crc = bcma_crc8(crc, (sprom[word] & 0xFF00) >> 8); 134 crc = bcma_crc8(crc, (sprom[word] & 0xFF00) >> 8);
135 } 135 }
136 crc = bcma_crc8(crc, sprom[SSB_SPROMSIZE_WORDS_R4 - 1] & 0x00FF); 136 crc = bcma_crc8(crc, sprom[words - 1] & 0x00FF);
137 crc ^= 0xFF; 137 crc ^= 0xFF;
138 138
139 return crc; 139 return crc;
140} 140}
141 141
142static int bcma_sprom_check_crc(const u16 *sprom) 142static int bcma_sprom_check_crc(const u16 *sprom, size_t words)
143{ 143{
144 u8 crc; 144 u8 crc;
145 u8 expected_crc; 145 u8 expected_crc;
146 u16 tmp; 146 u16 tmp;
147 147
148 crc = bcma_sprom_crc(sprom); 148 crc = bcma_sprom_crc(sprom, words);
149 tmp = sprom[SSB_SPROMSIZE_WORDS_R4 - 1] & SSB_SPROM_REVISION_CRC; 149 tmp = sprom[words - 1] & SSB_SPROM_REVISION_CRC;
150 expected_crc = tmp >> SSB_SPROM_REVISION_CRC_SHIFT; 150 expected_crc = tmp >> SSB_SPROM_REVISION_CRC_SHIFT;
151 if (crc != expected_crc) 151 if (crc != expected_crc)
152 return -EPROTO; 152 return -EPROTO;
@@ -154,16 +154,16 @@ static int bcma_sprom_check_crc(const u16 *sprom)
154 return 0; 154 return 0;
155} 155}
156 156
157static int bcma_sprom_valid(const u16 *sprom) 157static int bcma_sprom_valid(const u16 *sprom, size_t words)
158{ 158{
159 u16 revision; 159 u16 revision;
160 int err; 160 int err;
161 161
162 err = bcma_sprom_check_crc(sprom); 162 err = bcma_sprom_check_crc(sprom, words);
163 if (err) 163 if (err)
164 return err; 164 return err;
165 165
166 revision = sprom[SSB_SPROMSIZE_WORDS_R4 - 1] & SSB_SPROM_REVISION_REV; 166 revision = sprom[words - 1] & SSB_SPROM_REVISION_REV;
167 if (revision != 8 && revision != 9) { 167 if (revision != 8 && revision != 9) {
168 pr_err("Unsupported SPROM revision: %d\n", revision); 168 pr_err("Unsupported SPROM revision: %d\n", revision);
169 return -ENOENT; 169 return -ENOENT;
@@ -589,13 +589,13 @@ int bcma_sprom_get(struct bcma_bus *bus)
589 bcma_chipco_bcm4331_ext_pa_lines_ctl(&bus->drv_cc, false); 589 bcma_chipco_bcm4331_ext_pa_lines_ctl(&bus->drv_cc, false);
590 590
591 bcma_debug(bus, "SPROM offset 0x%x\n", offset); 591 bcma_debug(bus, "SPROM offset 0x%x\n", offset);
592 bcma_sprom_read(bus, offset, sprom); 592 bcma_sprom_read(bus, offset, sprom, SSB_SPROMSIZE_WORDS_R4);
593 593
594 if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4331 || 594 if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4331 ||
595 bus->chipinfo.id == BCMA_CHIP_ID_BCM43431) 595 bus->chipinfo.id == BCMA_CHIP_ID_BCM43431)
596 bcma_chipco_bcm4331_ext_pa_lines_ctl(&bus->drv_cc, true); 596 bcma_chipco_bcm4331_ext_pa_lines_ctl(&bus->drv_cc, true);
597 597
598 err = bcma_sprom_valid(sprom); 598 err = bcma_sprom_valid(sprom, SSB_SPROMSIZE_WORDS_R4);
599 if (err) { 599 if (err) {
600 bcma_warn(bus, "invalid sprom read from the PCIe card, try to use fallback sprom\n"); 600 bcma_warn(bus, "invalid sprom read from the PCIe card, try to use fallback sprom\n");
601 err = bcma_fill_sprom_with_fallback(bus, &bus->sprom); 601 err = bcma_fill_sprom_with_fallback(bus, &bus->sprom);