Lines Matching +full:pre +full:- +full:packaged

1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright (C) 2003-2005 SAN People (Pty) Ltd
28 * Sometimes DataFlash is packaged in MMC-format cards, although the
57 #define OP_MWRITE_BUFFER1 0x88 /* sector must be pre-erased */
58 #define OP_MWRITE_BUFFER2 0x89 /* sector must be pre-erased */
60 /* write to buffer, then write-erase to flash */
68 /* read flash to buffer, then write-erase to flash */
73 * serial number and OTP bits; and per-sector writeprotect.
129 * This usually takes 5-20 msec or so; more for sector erase.
138 dev_dbg(&spi->dev, "status %d?\n", status); in dataflash_waitready()
156 struct dataflash *priv = mtd->priv; in dataflash_erase()
157 struct spi_device *spi = priv->spi; in dataflash_erase()
160 unsigned blocksize = priv->page_size << 3; in dataflash_erase()
164 dev_dbg(&spi->dev, "erase addr=0x%llx len 0x%llx\n", in dataflash_erase()
165 (long long)instr->addr, (long long)instr->len); in dataflash_erase()
167 div_u64_rem(instr->len, priv->page_size, &rem); in dataflash_erase()
169 return -EINVAL; in dataflash_erase()
170 div_u64_rem(instr->addr, priv->page_size, &rem); in dataflash_erase()
172 return -EINVAL; in dataflash_erase()
176 x.tx_buf = command = priv->command; in dataflash_erase()
180 mutex_lock(&priv->lock); in dataflash_erase()
181 while (instr->len > 0) { in dataflash_erase()
189 pageaddr = div_u64(instr->addr, priv->page_size); in dataflash_erase()
190 do_block = (pageaddr & 0x7) == 0 && instr->len >= blocksize; in dataflash_erase()
191 pageaddr = pageaddr << priv->page_offset; in dataflash_erase()
198 dev_dbg(&spi->dev, "ERASE %s: (%x) %x %x %x [%i]\n", in dataflash_erase()
207 dev_err(&spi->dev, "erase %x, err %d\n", in dataflash_erase()
209 /* REVISIT: can retry instr->retries times; or in dataflash_erase()
210 * giveup and instr->fail_addr = instr->addr; in dataflash_erase()
216 instr->addr += blocksize; in dataflash_erase()
217 instr->len -= blocksize; in dataflash_erase()
219 instr->addr += priv->page_size; in dataflash_erase()
220 instr->len -= priv->page_size; in dataflash_erase()
223 mutex_unlock(&priv->lock); in dataflash_erase()
238 struct dataflash *priv = mtd->priv; in dataflash_read()
245 dev_dbg(&priv->spi->dev, "read 0x%x..0x%x\n", in dataflash_read()
249 addr = (((unsigned)from / priv->page_size) << priv->page_offset) in dataflash_read()
250 + ((unsigned)from % priv->page_size); in dataflash_read()
252 command = priv->command; in dataflash_read()
254 dev_dbg(&priv->spi->dev, "READ: (%x) %x %x %x\n", in dataflash_read()
267 mutex_lock(&priv->lock); in dataflash_read()
279 status = spi_sync(priv->spi, &msg); in dataflash_read()
280 mutex_unlock(&priv->lock); in dataflash_read()
283 *retlen = msg.actual_length - 8; in dataflash_read()
286 dev_dbg(&priv->spi->dev, "read %x..%x --> %d\n", in dataflash_read()
302 struct dataflash *priv = mtd->priv; in dataflash_write()
303 struct spi_device *spi = priv->spi; in dataflash_write()
309 int status = -EINVAL; in dataflash_write()
312 dev_dbg(&spi->dev, "write 0x%x..0x%x\n", in dataflash_write()
317 x[0].tx_buf = command = priv->command; in dataflash_write()
321 pageaddr = ((unsigned)to / priv->page_size); in dataflash_write()
322 offset = ((unsigned)to % priv->page_size); in dataflash_write()
323 if (offset + len > priv->page_size) in dataflash_write()
324 writelen = priv->page_size - offset; in dataflash_write()
328 mutex_lock(&priv->lock); in dataflash_write()
330 dev_dbg(&spi->dev, "write @ %i:%i len=%i\n", in dataflash_write()
342 * Two persistent bits per page, plus a per-sector counter, in dataflash_write()
346 * support boot-from-DataFlash.) in dataflash_write()
349 addr = pageaddr << priv->page_offset; in dataflash_write()
352 if (writelen != priv->page_size) { in dataflash_write()
358 dev_dbg(&spi->dev, "TRANSFER: (%x) %x %x %x\n", in dataflash_write()
363 dev_dbg(&spi->dev, "xfer %u -> %d\n", in dataflash_write()
366 (void) dataflash_waitready(priv->spi); in dataflash_write()
376 dev_dbg(&spi->dev, "PROGRAM: (%x) %x %x %x\n", in dataflash_write()
385 dev_dbg(&spi->dev, "pgm %u/%u -> %d\n", in dataflash_write()
388 (void) dataflash_waitready(priv->spi); in dataflash_write()
394 addr = pageaddr << priv->page_offset; in dataflash_write()
400 dev_dbg(&spi->dev, "COMPARE: (%x) %x %x %x\n", in dataflash_write()
405 dev_dbg(&spi->dev, "compare %u -> %d\n", in dataflash_write()
408 status = dataflash_waitready(priv->spi); in dataflash_write()
412 dev_err(&spi->dev, "compare page %u, err %d\n", in dataflash_write()
415 status = -EIO; in dataflash_write()
422 remaining = remaining - writelen; in dataflash_write()
428 if (remaining > priv->page_size) in dataflash_write()
429 writelen = priv->page_size; in dataflash_write()
433 mutex_unlock(&priv->lock); in dataflash_write()
446 * Unless the user block changed from all-ones, we can't in dataflash_get_otp_info()
449 info->start = 0; in dataflash_get_otp_info()
450 info->length = 64; in dataflash_get_otp_info()
451 info->locked = 1; in dataflash_get_otp_info()
466 return -EINVAL; in otp_read()
469 len = 64 - off; in otp_read()
476 return -ENOMEM; in otp_read()
478 /* OUT: OP_READ_SECURITY, 3 don't-care bytes, zeroes in otp_read()
504 struct dataflash *priv = mtd->priv; in dataflash_read_fact_otp()
507 /* 64 bytes, from 0..63 ... start at 64 on-chip */ in dataflash_read_fact_otp()
508 mutex_lock(&priv->lock); in dataflash_read_fact_otp()
509 status = otp_read(priv->spi, 64, buf, from, len); in dataflash_read_fact_otp()
510 mutex_unlock(&priv->lock); in dataflash_read_fact_otp()
521 struct dataflash *priv = mtd->priv; in dataflash_read_user_otp()
524 /* 64 bytes, from 0..63 ... start at 0 on-chip */ in dataflash_read_user_otp()
525 mutex_lock(&priv->lock); in dataflash_read_user_otp()
526 status = otp_read(priv->spi, 0, buf, from, len); in dataflash_read_user_otp()
527 mutex_unlock(&priv->lock); in dataflash_read_user_otp()
542 struct dataflash *priv = mtd->priv; in dataflash_write_user_otp()
556 len = 64 - from; in dataflash_write_user_otp()
558 /* OUT: OP_WRITE_SECURITY, 3 zeroes, 64 data-or-zero bytes in dataflash_write_user_otp()
563 return -ENOMEM; in dataflash_write_user_otp()
577 mutex_lock(&priv->lock); in dataflash_write_user_otp()
578 dataflash_waitready(priv->spi); in dataflash_write_user_otp()
579 status = spi_sync(priv->spi, &m); in dataflash_write_user_otp()
580 mutex_unlock(&priv->lock); in dataflash_write_user_otp()
593 device->_get_fact_prot_info = dataflash_get_otp_info; in otp_setup()
594 device->_read_fact_prot_reg = dataflash_read_fact_otp; in otp_setup()
595 device->_get_user_prot_info = dataflash_get_otp_info; in otp_setup()
596 device->_read_user_prot_reg = dataflash_read_user_otp; in otp_setup()
602 device->_write_user_prot_reg = dataflash_write_user_otp; in otp_setup()
626 struct flash_platform_data *pdata = dev_get_platdata(&spi->dev); in add_dataflash_otp()
632 return -ENOMEM; in add_dataflash_otp()
634 mutex_init(&priv->lock); in add_dataflash_otp()
635 priv->spi = spi; in add_dataflash_otp()
636 priv->page_size = pagesize; in add_dataflash_otp()
637 priv->page_offset = pageoffset; in add_dataflash_otp()
640 sprintf(priv->name, "spi%d.%d-%s", in add_dataflash_otp()
641 spi->controller->bus_num, spi_get_chipselect(spi, 0), in add_dataflash_otp()
644 device = &priv->mtd; in add_dataflash_otp()
645 device->name = (pdata && pdata->name) ? pdata->name : priv->name; in add_dataflash_otp()
646 device->size = nr_pages * pagesize; in add_dataflash_otp()
647 device->erasesize = pagesize; in add_dataflash_otp()
648 device->writesize = pagesize; in add_dataflash_otp()
649 device->type = MTD_DATAFLASH; in add_dataflash_otp()
650 device->flags = MTD_WRITEABLE; in add_dataflash_otp()
651 device->_erase = dataflash_erase; in add_dataflash_otp()
652 device->_read = dataflash_read; in add_dataflash_otp()
653 device->_write = dataflash_write; in add_dataflash_otp()
654 device->priv = priv; in add_dataflash_otp()
656 device->dev.parent = &spi->dev; in add_dataflash_otp()
657 mtd_set_of_node(device, spi->dev.of_node); in add_dataflash_otp()
662 dev_info(&spi->dev, "%s (%lld KBytes) pagesize %d bytes%s\n", in add_dataflash_otp()
663 name, (long long)((device->size + 1023) >> 10), in add_dataflash_otp()
668 pdata ? pdata->parts : NULL, in add_dataflash_otp()
669 pdata ? pdata->nr_parts : 0); in add_dataflash_otp()
709 * non-2^N byte page size can't name exact chip revisions without
712 * These newer chips also support 128-byte security registers (with
713 * 64 bytes one-time-programmable) and software write-protection.
751 if (use_extid && !(info->flags & SUP_EXTID)) in jedec_lookup()
754 if (info->jedec_id == jedec) { in jedec_lookup()
755 dev_dbg(&spi->dev, "OTP, sector protect%s\n", in jedec_lookup()
756 (info->flags & SUP_POW2PS) ? in jedec_lookup()
758 if (info->flags & SUP_POW2PS) { in jedec_lookup()
761 dev_dbg(&spi->dev, "status error %d\n", in jedec_lookup()
766 if (info->flags & IS_POW2PS) in jedec_lookup()
769 if (!(info->flags & IS_POW2PS)) in jedec_lookup()
777 return ERR_PTR(-ENODEV); in jedec_lookup()
791 * string for after vendor-specific data, after the three bytes in jedec_probe()
800 dev_dbg(&spi->dev, "error %d reading JEDEC ID\n", ret); in jedec_probe()
828 dev_warn(&spi->dev, "JEDEC id %016llx not handled\n", jedec); in jedec_probe()
829 return ERR_PTR(-ENODEV); in jedec_probe()
862 return add_dataflash_otp(spi, info->name, info->nr_pages, in dataflash_probe()
863 info->pagesize, info->pageoffset, in dataflash_probe()
864 (info->flags & SUP_POW2PS) ? 'd' : 'c'); in dataflash_probe()
872 dev_dbg(&spi->dev, "status error %d\n", status); in dataflash_probe()
874 status = -ENODEV; in dataflash_probe()
879 * board setup should have set spi->max_speed_max to in dataflash_probe()
907 dev_info(&spi->dev, "unsupported device (%x)\n", in dataflash_probe()
909 status = -ENODEV; in dataflash_probe()
913 dev_dbg(&spi->dev, "add_dataflash --> %d\n", status); in dataflash_probe()
922 dev_dbg(&spi->dev, "remove\n"); in dataflash_remove()
924 WARN_ON(mtd_device_unregister(&flash->mtd)); in dataflash_remove()