Lines Matching refs:params
34 static void row_address_set(struct cadence_nand_params *params, uint32_t *local_row_address, in row_address_set() argument
39 block_number = ((page_set) / (params->npages_per_block)); in row_address_set()
41 *local_row_address |= ROW_VAL_SET((params->page_size_bit) - 1, 0, in row_address_set()
42 ((page_set) % (params->npages_per_block))); in row_address_set()
44 ROW_VAL_SET((params->block_size_bit) - 1, (params->page_size_bit), block_number); in row_address_set()
45 *local_row_address |= ROW_VAL_SET((params->lun_size_bit) - 1, (params->block_size_bit), in row_address_set()
46 (block_number / params->nblocks_per_lun)); in row_address_set()
55 static int cdns_nand_device_info(struct cadence_nand_params *params) in cdns_nand_device_info() argument
62 base_address = params->nand_base; in cdns_nand_device_info()
81 params->nluns = CNF_GET_NLUNS(reg_value); in cdns_nand_device_info()
82 LOG_INF("Number of LUMs %hhx", params->nluns); in cdns_nand_device_info()
86 params->npages_per_block = GET_PAGES_PER_BLOCK(reg_value); in cdns_nand_device_info()
90 params->page_size = GET_PAGE_SIZE(reg_value); in cdns_nand_device_info()
91 params->spare_size = GET_SPARE_SIZE(reg_value); in cdns_nand_device_info()
94 params->nblocks_per_lun = sys_read32(CNF_CTRLPARAM(base_address, DEV_BLOCKS_PLUN)); in cdns_nand_device_info()
97 params->block_size = (params->npages_per_block * params->page_size); in cdns_nand_device_info()
98 params->device_size = ((long long)params->block_size * in cdns_nand_device_info()
99 (long long)(params->nblocks_per_lun * params->nluns)); in cdns_nand_device_info()
100 LOG_INF("block size %x total device size %llx", params->block_size, params->device_size); in cdns_nand_device_info()
103 params->page_size_bit = find_msb_set((params->npages_per_block) - 1); in cdns_nand_device_info()
104 params->block_size_bit = find_msb_set((params->nblocks_per_lun) - 1); in cdns_nand_device_info()
105 params->lun_size_bit = find_msb_set((params->nluns) - 1); in cdns_nand_device_info()
351 int cdns_nand_init(struct cadence_nand_params *params) in cdns_nand_init() argument
354 uintptr_t base_address = params->nand_base; in cdns_nand_init()
355 uint8_t datarate_mode = params->datarate_mode; in cdns_nand_init()
369 ret = cdns_nand_device_info(params); in cdns_nand_init()
424 params->total_bit_row = find_msb_set(((params->npages_per_block) - 1)) + in cdns_nand_init()
425 find_msb_set((params->nblocks_per_lun) - 1); in cdns_nand_init()
489 struct cadence_nand_params *params) in cdns_transfer_complete() argument
494 NAND_INT_SEM_TAKE(params); in cdns_transfer_complete()
495 sys_write32(NF_TDEF_TRD_NUM, (params->nand_base + CMD_STATUS_PTR_ADDR)); in cdns_transfer_complete()
496 status = sys_read32((params->nand_base + CMD_STAT_CMD_STATUS)); in cdns_transfer_complete()
507 ARG_UNUSED(params); in cdns_transfer_complete()
555 static int cdns_cdma_desc_transfer_finish(struct cadence_nand_params *params, uint32_t page_count, in cdns_cdma_desc_transfer_finish() argument
575 base_address = params->nand_base; in cdns_cdma_desc_transfer_finish()
578 row_address_set(params, &row_address, cond_start); in cdns_cdma_desc_transfer_finish()
601 buffer = buffer + (max_page_desc * params->page_size); in cdns_cdma_desc_transfer_finish()
604 ret = cdns_transfer_complete(cdma_desc, params); in cdns_cdma_desc_transfer_finish()
625 static int cdns_nand_cdma_write(struct cadence_nand_params *params, uint32_t start_page_number, in cdns_nand_cdma_write() argument
630 ret = cdns_cdma_desc_transfer_finish(params, page_count, CONFIG_FLASH_CDNS_CDMA_PAGE_COUNT, in cdns_nand_cdma_write()
645 static int cdns_nand_cdma_read(struct cadence_nand_params *params, uint32_t start_page_number, in cdns_nand_cdma_read() argument
650 ret = cdns_cdma_desc_transfer_finish(params, page_count, CONFIG_FLASH_CDNS_CDMA_PAGE_COUNT, in cdns_nand_cdma_read()
664 static int cdns_nand_cdma_erase(struct cadence_nand_params *params, uint32_t start_block_number, in cdns_nand_cdma_erase() argument
669 ret = cdns_cdma_desc_transfer_finish(params, block_count, in cdns_nand_cdma_erase()
690 static int cdns_nand_pio_erase(struct cadence_nand_params *params, uint8_t thread, uint8_t bank, in cdns_nand_pio_erase() argument
699 base_address = params->nand_base; in cdns_nand_pio_erase()
707 row_address_set(params, &row_address, (start_block * params->npages_per_block)); in cdns_nand_pio_erase()
718 NAND_INT_SEM_TAKE(params); in cdns_nand_pio_erase()
779 static int cdns_nand_pio_write(struct cadence_nand_params *params, uint32_t row_address, in cdns_nand_pio_write() argument
785 base_address = params->nand_base; in cdns_nand_pio_write()
793 NAND_INT_SEM_TAKE(params); in cdns_nand_pio_write()
810 static int cdns_nand_pio_read(struct cadence_nand_params *params, uint32_t row_address, in cdns_nand_pio_read() argument
816 base_address = params->nand_base; in cdns_nand_pio_read()
825 NAND_INT_SEM_TAKE(params); in cdns_nand_pio_read()
844 static int cdns_nand_pio_read_write(struct cadence_nand_params *params, uint32_t start_page_number, in cdns_nand_pio_read_write() argument
852 row_address_set(params, &pio_row_address, start_page_number++); in cdns_nand_pio_read_write()
854 ret = cdns_nand_pio_read(params, pio_row_address, in cdns_nand_pio_read_write()
855 buffer + (index * (params->page_size))); in cdns_nand_pio_read_write()
857 ret = cdns_nand_pio_write(params, pio_row_address, in cdns_nand_pio_read_write()
858 buffer + (index * (params->page_size))); in cdns_nand_pio_read_write()
873 static int cdns_generic_send_cmd(struct cadence_nand_params *params, uint64_t mini_ctrl_cmd) in cdns_generic_send_cmd() argument
880 base_address = params->nand_base; in cdns_generic_send_cmd()
909 static int cdns_generic_cmd_data(struct cadence_nand_params *params, uint8_t mode, in cdns_generic_cmd_data() argument
921 ret = cdns_generic_send_cmd(params, mini_ctrl_cmd); in cdns_generic_cmd_data()
983 static int cdns_generic_page_read(struct cadence_nand_params *params, uint64_t read_address, in cdns_generic_page_read() argument
987 uintptr_t base_address = params->nand_base; in cdns_generic_page_read()
992 if ((params->nluns > 1) || (params->total_bit_row > 16)) { in cdns_generic_page_read()
998 ret = cdns_generic_send_cmd(params, mini_ctrl_cmd); in cdns_generic_page_read()
1002 NAND_INT_SEM_TAKE(params); in cdns_generic_page_read()
1003 ret = cdns_generic_cmd_data(params, CDNS_READ, params->page_size); in cdns_generic_page_read()
1007 NAND_INT_SEM_TAKE(params); in cdns_generic_page_read()
1012 sdma_buffer_copy_out(params->sdma_base, data_buffer, params->page_size); in cdns_generic_page_read()
1024 static int cdns_generic_page_write(struct cadence_nand_params *params, uint64_t write_address, in cdns_generic_page_write() argument
1030 uintptr_t base_address = params->nand_base; in cdns_generic_page_write()
1034 if ((params->nluns > 1) || (params->total_bit_row > BIT16_CHECK)) { in cdns_generic_page_write()
1040 ret = cdns_generic_send_cmd(params, mini_ctrl_cmd); in cdns_generic_page_write()
1044 NAND_INT_SEM_TAKE(params); in cdns_generic_page_write()
1045 ret = cdns_generic_cmd_data(params, CDNS_WRITE, params->page_size); in cdns_generic_page_write()
1049 sdma_buffer_copy_in(params->sdma_base, data_buffer, params->page_size); in cdns_generic_page_write()
1050 NAND_INT_SEM_TAKE(params); in cdns_generic_page_write()
1055 ret = cdns_generic_send_cmd(params, mini_ctrl_cmd); in cdns_generic_page_write()
1059 NAND_INT_SEM_TAKE(params); in cdns_generic_page_write()
1074 static int cdns_nand_gen_read_write(struct cadence_nand_params *params, uint32_t start_page_number, in cdns_nand_gen_read_write() argument
1083 row_address_set(params, &gen_row_address, start_page_number++); in cdns_nand_gen_read_write()
1086 ret = cdns_generic_page_read(params, address, in cdns_nand_gen_read_write()
1087 buffer + (index * (params->page_size))); in cdns_nand_gen_read_write()
1093 ret = cdns_generic_page_write(params, address, in cdns_nand_gen_read_write()
1094 buffer + (index * (params->page_size))); in cdns_nand_gen_read_write()
1112 static int cdns_nand_gen_erase(struct cadence_nand_params *params, uint32_t start_block, in cdns_nand_gen_erase() argument
1122 row_address_set(params, &gen_row_address, (start_block * params->npages_per_block)); in cdns_nand_gen_erase()
1124 base_address = params->nand_base; in cdns_nand_gen_erase()
1129 ret = cdns_generic_send_cmd(params, mini_ctrl_cmd); in cdns_nand_gen_erase()
1133 NAND_INT_SEM_TAKE(params); in cdns_nand_gen_erase()
1142 static inline int cdns_read_data(struct cadence_nand_params *params, uint32_t start_page_number, in cdns_read_data() argument
1148 ret = cdns_nand_cdma_read(params, start_page_number, (char *)buffer, page_count); in cdns_read_data()
1150 ret = cdns_nand_pio_read_write(params, start_page_number, (char *)buffer, page_count, in cdns_read_data()
1153 ret = cdns_nand_gen_read_write(params, start_page_number, (char *)buffer, page_count, in cdns_read_data()
1168 int cdns_nand_read(struct cadence_nand_params *params, const void *buffer, uint32_t offset, in cdns_nand_read() argument
1183 if (params == NULL) { in cdns_nand_read()
1192 if ((offset >= params->device_size) || (size > (params->device_size - offset))) { in cdns_nand_read()
1197 start_page_number = offset / (params->page_size); in cdns_nand_read()
1198 end_page_number = ((offset + size) - 1) / ((params->page_size)); in cdns_nand_read()
1200 if ((offset % params->page_size) == 0) { in cdns_nand_read()
1203 if (((offset + size) % params->page_size) == 0) { in cdns_nand_read()
1209 ret = cdns_read_data(params, start_page_number, (char *)buffer, page_count); in cdns_nand_read()
1217 first_end_page = (char *)k_malloc(sizeof(char) * (params->page_size)); in cdns_nand_read()
1219 memset(first_end_page, 0xFF, sizeof(char) * (params->page_size)); in cdns_nand_read()
1224 ret = cdns_read_data(params, start_page_number, first_end_page, page_count); in cdns_nand_read()
1229 memcpy((char *)buffer, first_end_page + (offset % (params->page_size)), size); in cdns_nand_read()
1234 first_end_page = (char *)k_malloc(sizeof(char) * (params->page_size * 2)); in cdns_nand_read()
1236 memset(first_end_page, 0xFF, sizeof(char) * (params->page_size * 2)); in cdns_nand_read()
1241 ret = cdns_read_data(params, start_page_number, first_end_page, page_count); in cdns_nand_read()
1246 memcpy((char *)buffer, first_end_page + (offset % (params->page_size)), size); in cdns_nand_read()
1250 first_end_page = (char *)k_malloc(sizeof(char) * (params->page_size)); in cdns_nand_read()
1252 memset(first_end_page, 0xFF, sizeof(char) * (params->page_size)); in cdns_nand_read()
1257 ret = cdns_read_data(params, end_page_number, first_end_page, 1); in cdns_nand_read()
1262 r_bytes = (offset + size) % (params->page_size); in cdns_nand_read()
1263 ret = cdns_read_data(params, start_page_number, (char *)buffer, (--page_count)); in cdns_nand_read()
1269 memcpy((char *)buffer + ((page_count - 1) * params->page_size), first_end_page, in cdns_nand_read()
1274 first_end_page = (char *)k_malloc(sizeof(char) * (params->page_size)); in cdns_nand_read()
1276 memset(first_end_page, 0xFF, sizeof(char) * (params->page_size)); in cdns_nand_read()
1281 ret = cdns_read_data(params, start_page_number, first_end_page, 1); in cdns_nand_read()
1286 r_bytes = (offset) % (params->page_size); in cdns_nand_read()
1287 bytes_dif = (((start_page_number + 1) * params->page_size) - r_bytes); in cdns_nand_read()
1288 r_bytes = (offset + size) % (params->page_size); in cdns_nand_read()
1289 ret = cdns_read_data(params, (++start_page_number), ((char *)buffer + bytes_dif), in cdns_nand_read()
1298 first_end_page = (char *)k_malloc(sizeof(char) * (params->page_size)); in cdns_nand_read()
1299 last_end_page = (char *)k_malloc(sizeof(char) * (params->page_size)); in cdns_nand_read()
1301 memset(first_end_page, 0xFF, sizeof(char) * (params->page_size)); in cdns_nand_read()
1302 memset(last_end_page, 0xFF, sizeof(char) * (params->page_size)); in cdns_nand_read()
1307 ret = cdns_read_data(params, start_page_number, first_end_page, 1); in cdns_nand_read()
1313 r_bytes = (offset) % (params->page_size); in cdns_nand_read()
1314 bytes_dif = (((start_page_number + 1) * params->page_size) - r_bytes); in cdns_nand_read()
1315 lp_bytes_dif = (offset + size) % (params->page_size); in cdns_nand_read()
1316 ret = cdns_read_data(params, end_page_number, last_end_page, 1); in cdns_nand_read()
1322 r_bytes = (offset + size) % (params->page_size); in cdns_nand_read()
1323 ret = cdns_read_data(params, (++start_page_number), ((char *)buffer + bytes_dif), in cdns_nand_read()
1332 ((page_count - 2) * (params->npages_per_block))), in cdns_nand_read()
1348 int cdns_nand_write(struct cadence_nand_params *params, const void *buffer, uint32_t offset, in cdns_nand_write() argument
1356 if (params == NULL) { in cdns_nand_write()
1365 if ((offset >= params->device_size) || (len > (params->device_size - offset))) { in cdns_nand_write()
1370 if ((offset % params->page_size) != 0) { in cdns_nand_write()
1371 LOG_ERR("offset not page aligned!!! Page size = 0x%x", params->page_size); in cdns_nand_write()
1375 if ((len % params->page_size) != 0) { in cdns_nand_write()
1376 LOG_ERR("length not page aligned!!! Page size = 0x%x", params->page_size); in cdns_nand_write()
1380 start_page_number = offset / (params->page_size); in cdns_nand_write()
1381 end_page_number = ((offset + len) - 1) / ((params->page_size)); in cdns_nand_write()
1385 ret = cdns_nand_cdma_write(params, start_page_number, (char *)buffer, ++page_count); in cdns_nand_write()
1387 ret = cdns_nand_pio_read_write(params, start_page_number, (char *)buffer, ++page_count, in cdns_nand_write()
1390 ret = cdns_nand_gen_read_write(params, start_page_number, (char *)buffer, ++page_count, in cdns_nand_write()
1408 int cdns_nand_erase(struct cadence_nand_params *params, uint32_t offset, uint32_t size) in cdns_nand_erase() argument
1415 if (params == NULL) { in cdns_nand_erase()
1424 if ((offset >= params->device_size) || (size > (params->device_size - offset))) { in cdns_nand_erase()
1428 if ((offset % (params->block_size)) != 0) { in cdns_nand_erase()
1430 params->block_size); in cdns_nand_erase()
1433 if ((size % (params->block_size)) != 0) { in cdns_nand_erase()
1435 params->block_size); in cdns_nand_erase()
1439 start_block_number = (offset / ((params->page_size))) / (params->npages_per_block); in cdns_nand_erase()
1441 (((offset + size) - 1) / ((params->page_size))) / (params->npages_per_block); in cdns_nand_erase()
1444 ret = cdns_nand_cdma_erase(params, start_block_number, ++block_count); in cdns_nand_erase()
1446 ret = cdns_nand_pio_erase(params, NF_TDEF_TRD_NUM, NF_TDEF_DEV_NUM, start_block_number, in cdns_nand_erase()
1449 ret = cdns_nand_gen_erase(params, start_block_number, ++block_count); in cdns_nand_erase()
1459 void cdns_nand_irq_handler_ll(struct cadence_nand_params *params) in cdns_nand_irq_handler_ll() argument
1464 status = sys_read32(params->nand_base + THREAD_INTERRUPT_STATUS); in cdns_nand_irq_handler_ll()
1469 sys_write32(BIT((thread_num - 1)), params->nand_base + THREAD_INTERRUPT_STATUS); in cdns_nand_irq_handler_ll()