Lines Matching +full:write +full:- +full:protected
4 * SPDX-License-Identifier: Apache-2.0
9 * Nios-II QSPI Controller HAL driver.
77 struct flash_nios2_qspi_config *flash_cfg = dev->data; in flash_nios2_qspi_erase()
78 alt_qspi_controller2_dev *qspi_dev = &flash_cfg->qspi_dev; in flash_nios2_qspi_erase()
85 k_sem_take(&flash_cfg->sem_lock, K_FOREVER); in flash_nios2_qspi_erase()
95 if (((offset + len) > qspi_dev->data_end) || in flash_nios2_qspi_erase()
97 (NIOS2_WRITE_BLOCK_SIZE - 1)))) { in flash_nios2_qspi_erase()
99 rc = -EINVAL; in flash_nios2_qspi_erase()
103 for (i = offset/qspi_dev->sector_size; in flash_nios2_qspi_erase()
104 i < qspi_dev->number_of_sectors; i++) { in flash_nios2_qspi_erase()
116 block_offset = erase_offset & ~(qspi_dev->sector_size - 1); in flash_nios2_qspi_erase()
120 offset_in_block = erase_offset - block_offset; in flash_nios2_qspi_erase()
124 length_to_erase = MIN(qspi_dev->sector_size - offset_in_block, in flash_nios2_qspi_erase()
128 IOWR_32DIRECT(qspi_dev->csr_base, in flash_nios2_qspi_erase()
131 IOWR_32DIRECT(qspi_dev->csr_base, in flash_nios2_qspi_erase()
145 flag_status = IORD_32DIRECT(qspi_dev->csr_base, in flash_nios2_qspi_erase()
152 timeout--; in flash_nios2_qspi_erase()
159 rc = -EIO; in flash_nios2_qspi_erase()
164 remaining_length -= length_to_erase; in flash_nios2_qspi_erase()
175 k_sem_give(&flash_cfg->sem_lock); in flash_nios2_qspi_erase()
185 struct flash_nios2_qspi_config *flash_cfg = dev->data; in flash_nios2_qspi_write_block()
186 alt_qspi_controller2_dev *qspi_dev = &flash_cfg->qspi_dev; in flash_nios2_qspi_write_block()
187 uint32_t buffer_offset = 0U; /* offset into data buffer to get write data */ in flash_nios2_qspi_write_block()
188 int32_t remaining_length = len; /* length left to write */ in flash_nios2_qspi_write_block()
189 uint32_t write_offset = mem_offset; /* offset into flash to write too */ in flash_nios2_qspi_write_block()
195 /* initialize word to write to blank word */ in flash_nios2_qspi_write_block()
205 * we need to make sure the write is word aligned in flash_nios2_qspi_write_block()
208 if (0 != (write_offset & (NIOS2_WRITE_BLOCK_SIZE - 1))) { in flash_nios2_qspi_write_block()
213 padding = write_offset & (NIOS2_WRITE_BLOCK_SIZE - 1); in flash_nios2_qspi_write_block()
219 bytes_to_copy -= padding; in flash_nios2_qspi_write_block()
225 write_offset = write_offset - padding; in flash_nios2_qspi_write_block()
228 (NIOS2_WRITE_BLOCK_SIZE - 1))) { in flash_nios2_qspi_write_block()
229 rc = -EINVAL; in flash_nios2_qspi_write_block()
240 rc = -EINVAL; in flash_nios2_qspi_write_block()
249 /* enable write */ in flash_nios2_qspi_write_block()
250 IOWR_32DIRECT(qspi_dev->csr_base, in flash_nios2_qspi_write_block()
254 /* write to flash 32 bits at a time */ in flash_nios2_qspi_write_block()
255 IOWR_32DIRECT(qspi_dev->data_base, write_offset, word_to_write); in flash_nios2_qspi_write_block()
257 /* check whether write operation is successful */ in flash_nios2_qspi_write_block()
258 flag_status = IORD_32DIRECT(qspi_dev->csr_base, in flash_nios2_qspi_write_block()
263 LOG_ERR("write failed, Flag Status Reg:0x%x", in flash_nios2_qspi_write_block()
265 rc = -EIO; /* sector might be protected */ in flash_nios2_qspi_write_block()
271 remaining_length -= bytes_to_copy; in flash_nios2_qspi_write_block()
282 struct flash_nios2_qspi_config *flash_cfg = dev->data; in flash_nios2_qspi_write()
283 alt_qspi_controller2_dev *qspi_dev = &flash_cfg->qspi_dev; in flash_nios2_qspi_write()
285 uint32_t write_offset = offset; /* address of next byte to write */ in flash_nios2_qspi_write()
290 k_sem_take(&flash_cfg->sem_lock, K_FOREVER); in flash_nios2_qspi_write()
300 if ((data == NULL) || ((offset + len) > qspi_dev->data_end) || in flash_nios2_qspi_write()
302 (NIOS2_WRITE_BLOCK_SIZE - 1)))) { in flash_nios2_qspi_write()
303 LOG_ERR("write failed at offset 0x%lx", (long)offset); in flash_nios2_qspi_write()
304 rc = -EINVAL; in flash_nios2_qspi_write()
308 for (i = offset/qspi_dev->sector_size; in flash_nios2_qspi_write()
309 i < qspi_dev->number_of_sectors; i++) { in flash_nios2_qspi_write()
316 offset_in_block = 0U; /* offset into current sector to write */ in flash_nios2_qspi_write()
317 length_to_write = 0U; /* length to write to current sector */ in flash_nios2_qspi_write()
320 block_offset = write_offset & ~(qspi_dev->sector_size - 1); in flash_nios2_qspi_write()
324 offset_in_block = write_offset - block_offset; in flash_nios2_qspi_write()
328 length_to_write = MIN(qspi_dev->sector_size - offset_in_block, in flash_nios2_qspi_write()
340 remaining_length -= length_to_write; in flash_nios2_qspi_write()
352 k_sem_give(&flash_cfg->sem_lock); in flash_nios2_qspi_write()
359 struct flash_nios2_qspi_config *flash_cfg = dev->data; in flash_nios2_qspi_read()
360 alt_qspi_controller2_dev *qspi_dev = &flash_cfg->qspi_dev; in flash_nios2_qspi_read()
370 if ((data == NULL) || (offset < qspi_dev->data_base) || in flash_nios2_qspi_read()
371 ((offset + len) > qspi_dev->data_end)) { in flash_nios2_qspi_read()
373 return -EINVAL; in flash_nios2_qspi_read()
380 k_sem_take(&flash_cfg->sem_lock, K_FOREVER); in flash_nios2_qspi_read()
383 read_offset &= ~(NIOS2_WRITE_BLOCK_SIZE - 1U); in flash_nios2_qspi_read()
386 bytes_to_copy = NIOS2_WRITE_BLOCK_SIZE - (offset - read_offset); in flash_nios2_qspi_read()
391 word_to_read = IORD_32DIRECT(qspi_dev->data_base, read_offset); in flash_nios2_qspi_read()
392 memcpy((uint8_t *)data, (uint8_t *)&word_to_read + offset - in flash_nios2_qspi_read()
397 remaining_length -= bytes_to_copy; in flash_nios2_qspi_read()
410 word_to_read = IORD_32DIRECT(qspi_dev->data_base, read_offset); in flash_nios2_qspi_read()
416 remaining_length -= bytes_to_copy; in flash_nios2_qspi_read()
419 k_sem_give(&flash_cfg->sem_lock); in flash_nios2_qspi_read()
426 struct flash_nios2_qspi_config *flash_cfg = dev->data; in flash_nios2_qspi_write_protection()
427 alt_qspi_controller2_dev *qspi_dev = &flash_cfg->qspi_dev; in flash_nios2_qspi_write_protection()
431 /* set write enable */ in flash_nios2_qspi_write_protection()
432 IOWR_32DIRECT(qspi_dev->csr_base, in flash_nios2_qspi_write_protection()
436 IOWR_32DIRECT(qspi_dev->csr_base, in flash_nios2_qspi_write_protection()
441 IOWR_32DIRECT(qspi_dev->csr_base, in flash_nios2_qspi_write_protection()
460 IORD_32DIRECT(qspi_dev->csr_base, in flash_nios2_qspi_write_protection()
464 status = IORD_32DIRECT(qspi_dev->csr_base, in flash_nios2_qspi_write_protection()
471 timeout--; in flash_nios2_qspi_write_protection()
475 LOG_ERR("locking failed, status-reg 0x%x", status); in flash_nios2_qspi_write_protection()
476 rc = -EIO; in flash_nios2_qspi_write_protection()
480 IOWR_32DIRECT(qspi_dev->csr_base, in flash_nios2_qspi_write_protection()
495 .write = flash_nios2_qspi_write,
506 struct flash_nios2_qspi_config *flash_cfg = dev->data; in flash_nios2_qspi_init()
508 k_sem_init(&flash_cfg->sem_lock, 1, 1); in flash_nios2_qspi_init()
526 "only one 'altr,nios2-qspi-nor' compatible node may be present");