265
static int iwl_read_otp_word(struct iwl_priv *priv, u16 addr, u16 *eeprom_data)
271
_iwl_write32(priv, CSR_EEPROM_REG,
272
CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
273
ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG,
274
CSR_EEPROM_REG_READ_VALID_MSK,
275
IWL_EEPROM_ACCESS_TIMEOUT);
277
IWL_ERR(priv, "Time out reading OTP[%d]\n", addr);
280
r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
281
/* check for ECC errors: */
282
otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
283
if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
284
/* stop in this case */
285
/* set the uncorrectable OTP ECC bit for acknowledgement */
286
iwl_set_bit(priv, CSR_OTP_GP_REG,
287
CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
288
IWL_ERR(priv, "Uncorrectable OTP ECC error, abort OTP read\n");
291
if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
292
/* continue in this case */
293
/* set the correctable OTP ECC bit for acknowledgement */
294
iwl_set_bit(priv, CSR_OTP_GP_REG,
295
CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
296
IWL_ERR(priv, "Correctable OTP ECC error, continue read\n");
298
*eeprom_data = le16_to_cpu((__force __le16)(r >> 16));
303
* iwl_is_otp_empty: check for empty OTP
305
static bool iwl_is_otp_empty(struct iwl_priv *priv)
307
u16 next_link_addr = 0, link_value;
308
bool is_empty = false;
310
/* locate the beginning of OTP link list */
311
if (!iwl_read_otp_word(priv, next_link_addr, &link_value)) {
313
IWL_ERR(priv, "OTP is empty\n");
317
IWL_ERR(priv, "Unable to read first block of OTP list.\n");
326
* iwl_find_otp_image: find EEPROM image in OTP
327
* finding the OTP block that contains the EEPROM image.
328
* the last valid block on the link list (the block _before_ the last block)
329
* is the block we should read and used to configure the device.
330
* If all the available OTP blocks are full, the last block will be the block
331
* we should read and used to configure the device.
332
* only perform this operation if shadow RAM is disabled
334
static int iwl_find_otp_image(struct iwl_priv *priv,
337
u16 next_link_addr = 0, link_value = 0, valid_addr;
340
/* set addressing mode to absolute to traverse the link list */
341
iwl_set_otp_access(priv, IWL_OTP_ACCESS_ABSOLUTE);
343
/* checking for empty OTP or error */
344
if (iwl_is_otp_empty(priv))
348
* start traverse link list
349
* until reach the max number of OTP blocks
350
* different devices have different number of OTP blocks
353
/* save current valid block address
354
* check for more block on the link list
356
valid_addr = next_link_addr;
357
next_link_addr = link_value * sizeof(u16);
358
IWL_DEBUG_INFO(priv, "OTP blocks %d addr 0x%x\n",
359
usedblocks, next_link_addr);
360
if (iwl_read_otp_word(priv, next_link_addr, &link_value))
364
* reach the end of link list, return success and
365
* set address point to the starting address
368
*validblockaddr = valid_addr;
369
/* skip first 2 bytes (link list pointer) */
370
*validblockaddr += 2;
373
/* more in the link list, continue */
375
} while (usedblocks <= priv->cfg->max_ll_items);
377
/* OTP has no valid blocks */
378
IWL_DEBUG_INFO(priv, "OTP has no valid blocks\n");
383
253
* iwl_eeprom_init - read EEPROM contents
428
299
IWL_ERR(priv, "Failed to initialize OTP access.\n");
432
303
_iwl_write32(priv, CSR_EEPROM_GP,
433
304
iwl_read32(priv, CSR_EEPROM_GP) &
434
305
~CSR_EEPROM_GP_IF_OWNER_MSK);
436
iwl_set_bit(priv, CSR_OTP_GP_REG,
307
_iwl_write32(priv, CSR_OTP_GP_REG,
308
iwl_read32(priv, CSR_OTP_GP_REG) |
437
309
CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
438
310
CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
439
/* traversing the linked list if no shadow ram supported */
440
if (!priv->cfg->shadow_ram_support) {
441
if (iwl_find_otp_image(priv, &validblockaddr)) {
446
for (addr = validblockaddr; addr < validblockaddr + sz;
447
addr += sizeof(u16)) {
450
ret = iwl_read_otp_word(priv, addr, &eeprom_data);
453
e[cache_addr / 2] = eeprom_data;
454
cache_addr += sizeof(u16);
312
for (addr = 0; addr < sz; addr += sizeof(u16)) {
315
_iwl_write32(priv, CSR_EEPROM_REG,
316
CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
318
ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG,
319
CSR_EEPROM_REG_READ_VALID_MSK,
320
IWL_EEPROM_ACCESS_TIMEOUT);
322
IWL_ERR(priv, "Time out reading OTP[%d]\n", addr);
325
r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
326
/* check for ECC errors: */
327
otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
328
if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
329
/* stop in this case */
330
IWL_ERR(priv, "Uncorrectable OTP ECC error, Abort OTP read\n");
333
if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
334
/* continue in this case */
335
_iwl_write32(priv, CSR_OTP_GP_REG,
336
iwl_read32(priv, CSR_OTP_GP_REG) |
337
CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
338
IWL_ERR(priv, "Correctable OTP ECC error, continue read\n");
340
e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
457
343
/* eeprom is an array of 16bit values */