/* * This driver handles the DiskOnChip G3 flash memory. * * As no specification is available from M-Systems/Sandisk, this drivers lacks * several functions available on the chip, as : * - IPL write * * The bus data width (8bits versus 16bits) is not handled (if_cfg flag), and * the driver assumes a 16bits data bus. * * DocG3 relies on 2 ECC algorithms, which are handled in hardware : * - a 1 byte Hamming code stored in the OOB for each page * - a 7 bytes BCH code stored in the OOB for each page * The BCH ECC is : * - BCH is in GF(2^14) * - BCH is over data of 520 bytes (512 page + 7 page_info bytes * + 1 hamming byte) * - BCH can correct up to 4 bits (t = 4) * - BCH syndroms are calculated in hardware, and checked in hardware as well *
*/
staticunsignedint reliable_mode;
module_param(reliable_mode, uint, 0);
MODULE_PARM_DESC(reliable_mode, "Set the docg3 mode (0=normal MLC, 1=fast, " "2=reliable) : MLC normal operations are in normal mode");
staticint docg3_ooblayout_ecc(struct mtd_info *mtd, int section, struct mtd_oob_region *oobregion)
{ if (section) return -ERANGE;
/* byte 7 is Hamming ECC, byte 8-14 are BCH ECC */
oobregion->offset = 7;
oobregion->length = 8;
return 0;
}
staticint docg3_ooblayout_free(struct mtd_info *mtd, int section, struct mtd_oob_region *oobregion)
{ if (section > 1) return -ERANGE;
/** * doc_delay - delay docg3 operations * @docg3: the device * @nbNOPs: the number of NOPs to issue * * As no specification is available, the right timings between chip commands are * unknown. The only available piece of information are the observed nops on a * working docg3 chip. * Therefore, doc_delay relies on a busy loop of NOPs, instead of scheduler * friendlier msleep() functions or blocking mdelay().
*/ staticvoid doc_delay(struct docg3 *docg3, int nbNOPs)
{ int i;
doc_vdbg("NOP x %d\n", nbNOPs); for (i = 0; i < nbNOPs; i++)
doc_writeb(docg3, 0, DOC_NOP);
}
staticint is_prot_seq_error(struct docg3 *docg3)
{ int ctrl;
/** * doc_read_data_area - Read data from data area * @docg3: the device * @buf: the buffer to fill in (might be NULL is dummy reads) * @len: the length to read * @first: first time read, DOC_READADDRESS should be set * * Reads bytes from flash data. Handles the single byte / even bytes reads.
*/ staticvoid doc_read_data_area(struct docg3 *docg3, void *buf, int len, int first)
{ int i, cdr, len4;
u16 data16, *dst16;
u8 data8, *dst8;
doc_dbg("doc_read_data_area(buf=%p, len=%d)\n", buf, len);
cdr = len & 0x1;
len4 = len - cdr;
if (first)
doc_writew(docg3, DOC_IOSPACE_DATA, DOC_READADDRESS);
dst16 = buf; for (i = 0; i < len4; i += 2) {
data16 = doc_readw(docg3, DOC_IOSPACE_DATA); if (dst16) {
*dst16 = data16;
dst16++;
}
}
if (cdr) {
doc_writew(docg3, DOC_IOSPACE_DATA | DOC_READADDR_ONE_BYTE,
DOC_READADDRESS);
doc_delay(docg3, 1);
dst8 = (u8 *)dst16; for (i = 0; i < cdr; i++) {
data8 = doc_readb(docg3, DOC_IOSPACE_DATA); if (dst8) {
*dst8 = data8;
dst8++;
}
}
}
}
/** * doc_write_data_area - Write data into data area * @docg3: the device * @buf: the buffer to get input bytes from * @len: the length to write * * Writes bytes into flash data. Handles the single byte / even bytes writes.
*/ staticvoid doc_write_data_area(struct docg3 *docg3, constvoid *buf, int len)
{ int i, cdr, len4;
u16 *src16;
u8 *src8;
doc_dbg("doc_write_data_area(buf=%p, len=%d)\n", buf, len);
cdr = len & 0x3;
len4 = len - cdr;
doc_writew(docg3, DOC_IOSPACE_DATA, DOC_READADDRESS);
src16 = (u16 *)buf; for (i = 0; i < len4; i += 2) {
doc_writew(docg3, *src16, DOC_IOSPACE_DATA);
src16++;
}
src8 = (u8 *)src16; for (i = 0; i < cdr; i++) {
doc_writew(docg3, DOC_IOSPACE_DATA | DOC_READADDR_ONE_BYTE,
DOC_READADDRESS);
doc_writeb(docg3, *src8, DOC_IOSPACE_DATA);
src8++;
}
}
/** * doc_set_reliable_mode - Sets the flash to normal or reliable data mode * @docg3: the device * * The reliable data mode is a bit slower than the fast mode, but less errors * occur. Entering the reliable mode cannot be done without entering the fast * mode first. * * In reliable mode, pages 2*n and 2*n+1 are clones. Writing to page 0 of blocks * (4,5) make the hardware write also to page 1 of blocks blocks(4,5). Reading * from page 0 of blocks (4,5) or from page 1 of blocks (4,5) gives the same * result, which is a logical and between bytes from page 0 and page 1 (which is * consistent with the fact that writing to a page is _clearing_ bits of that * page).
*/ staticvoid doc_set_reliable_mode(struct docg3 *docg3)
{ staticchar *strmode[] = { "normal", "fast", "reliable", "invalid" };
/** * doc_set_asic_mode - Set the ASIC mode * @docg3: the device * @mode: the mode * * The ASIC can work in 3 modes : * - RESET: all registers are zeroed * - NORMAL: receives and handles commands * - POWERDOWN: minimal poweruse, flash parts shut off
*/ staticvoid doc_set_asic_mode(struct docg3 *docg3, u8 mode)
{ int i;
for (i = 0; i < 12; i++)
doc_readb(docg3, DOC_IOSPACE_IPL);
/** * doc_set_device_id - Sets the devices id for cascaded G3 chips * @docg3: the device * @id: the chip to select (amongst 0, 1, 2, 3) * * There can be 4 cascaded G3 chips. This function selects the one which will * should be the active one.
*/ staticvoid doc_set_device_id(struct docg3 *docg3, int id)
{
u8 ctrl;
/** * doc_set_extra_page_mode - Change flash page layout * @docg3: the device * * Normally, the flash page is split into the data (512 bytes) and the out of * band data (16 bytes). For each, 4 more bytes can be accessed, where the wear * leveling counters are stored. To access this last area of 4 bytes, a special * mode must be input to the flash ASIC. * * Returns 0 if no error occurred, -EIO else.
*/ staticint doc_set_extra_page_mode(struct docg3 *docg3)
{ int fctrl;
/** * doc_setup_addr_sector - Setup blocks/page/ofs address for one plane * @docg3: the device * @sector: the sector
*/ staticvoid doc_setup_addr_sector(struct docg3 *docg3, int sector)
{
doc_delay(docg3, 1);
doc_flash_address(docg3, sector & 0xff);
doc_flash_address(docg3, (sector >> 8) & 0xff);
doc_flash_address(docg3, (sector >> 16) & 0xff);
doc_delay(docg3, 1);
}
/** * doc_setup_writeaddr_sector - Setup blocks/page/ofs address for one plane * @docg3: the device * @sector: the sector * @ofs: the offset in the page, between 0 and (512 + 16 + 512)
*/ staticvoid doc_setup_writeaddr_sector(struct docg3 *docg3, int sector, int ofs)
{
ofs = ofs >> 2;
doc_delay(docg3, 1);
doc_flash_address(docg3, ofs & 0xff);
doc_flash_address(docg3, sector & 0xff);
doc_flash_address(docg3, (sector >> 8) & 0xff);
doc_flash_address(docg3, (sector >> 16) & 0xff);
doc_delay(docg3, 1);
}
/** * doc_read_seek - Set both flash planes to the specified block, page for reading * @docg3: the device * @block0: the first plane block index * @block1: the second plane block index * @page: the page index within the block * @wear: if true, read will occur on the 4 extra bytes of the wear area * @ofs: offset in page to read * * Programs the flash even and odd planes to the specific block and page. * Alternatively, programs the flash to the wear area of the specified page.
*/ staticint doc_read_seek(struct docg3 *docg3, int block0, int block1, int page, int wear, int ofs)
{ int sector, ret = 0;
/** * doc_write_seek - Set both flash planes to the specified block, page for writing * @docg3: the device * @block0: the first plane block index * @block1: the second plane block index * @page: the page index within the block * @ofs: offset in page to write * * Programs the flash even and odd planes to the specific block and page. * Alternatively, programs the flash to the wear area of the specified page.
*/ staticint doc_write_seek(struct docg3 *docg3, int block0, int block1, int page, int ofs)
{ int ret = 0, sector;
/** * doc_read_page_ecc_init - Initialize hardware ECC engine * @docg3: the device * @len: the number of bytes covered by the ECC (BCH covered) * * The function does initialize the hardware ECC engine to compute the Hamming * ECC (on 1 byte) and the BCH hardware ECC (on 7 bytes). * * Return 0 if succeeded, -EIO on error
*/ staticint doc_read_page_ecc_init(struct docg3 *docg3, int len)
{
doc_writew(docg3, DOC_ECCCONF0_READ_MODE
| DOC_ECCCONF0_BCH_ENABLE | DOC_ECCCONF0_HAMMING_ENABLE
| (len & DOC_ECCCONF0_DATA_BYTES_MASK),
DOC_ECCCONF0);
doc_delay(docg3, 4);
doc_register_readb(docg3, DOC_FLASHCONTROL); return doc_wait_ready(docg3);
}
/** * doc_write_page_ecc_init - Initialize hardware BCH ECC engine * @docg3: the device * @len: the number of bytes covered by the ECC (BCH covered) * * The function does initialize the hardware ECC engine to compute the Hamming * ECC (on 1 byte) and the BCH hardware ECC (on 7 bytes). * * Return 0 if succeeded, -EIO on error
*/ staticint doc_write_page_ecc_init(struct docg3 *docg3, int len)
{
doc_writew(docg3, DOC_ECCCONF0_WRITE_MODE
| DOC_ECCCONF0_BCH_ENABLE | DOC_ECCCONF0_HAMMING_ENABLE
| (len & DOC_ECCCONF0_DATA_BYTES_MASK),
DOC_ECCCONF0);
doc_delay(docg3, 4);
doc_register_readb(docg3, DOC_FLASHCONTROL); return doc_wait_ready(docg3);
}
/** * doc_ecc_disable - Disable Hamming and BCH ECC hardware calculator * @docg3: the device * * Disables the hardware ECC generator and checker, for unchecked reads (as when * reading OOB only or write status byte).
*/ staticvoid doc_ecc_disable(struct docg3 *docg3)
{
doc_writew(docg3, DOC_ECCCONF0_READ_MODE, DOC_ECCCONF0);
doc_delay(docg3, 4);
}
/** * doc_hamming_ecc_init - Initialize hardware Hamming ECC engine * @docg3: the device * @nb_bytes: the number of bytes covered by the ECC (Hamming covered) * * This function programs the ECC hardware to compute the hamming code on the * last provided N bytes to the hardware generator.
*/ staticvoid doc_hamming_ecc_init(struct docg3 *docg3, int nb_bytes)
{
u8 ecc_conf1;
/** * doc_ecc_bch_fix_data - Fix if need be read data from flash * @docg3: the device * @buf: the buffer of read data (512 + 7 + 1 bytes) * @hwecc: the hardware calculated ECC. * It's in fact recv_ecc ^ calc_ecc, where recv_ecc was read from OOB * area data, and calc_ecc the ECC calculated by the hardware generator. * * Checks if the received data matches the ECC, and if an error is detected, * tries to fix the bit flips (at most 4) in the buffer buf. As the docg3 * understands the (data, ecc, syndroms) in an inverted order in comparison to * the BCH library, the function reverses the order of bits (ie. bit7 and bit0, * bit6 and bit 1, ...) for all ECC data. * * The hardware ecc unit produces oob_ecc ^ calc_ecc. The kernel's bch * algorithm is used to decode this. However the hw operates on page * data in a bit order that is the reverse of that of the bch alg, * requiring that the bits be reversed on the result. Thanks to Ivan * Djelic for his analysis. * * Returns number of fixed bits (0, 1, 2, 3, 4) or -EBADMSG if too many bit * errors were detected and cannot be fixed.
*/ staticint doc_ecc_bch_fix_data(struct docg3 *docg3, void *buf, u8 *hwecc)
{
u8 ecc[DOC_ECC_BCH_SIZE]; int errorpos[DOC_ECC_BCH_T], i, numerrs;
for (i = 0; i < DOC_ECC_BCH_SIZE; i++)
ecc[i] = bitrev8(hwecc[i]);
numerrs = bch_decode(docg3->cascade->bch, NULL,
DOC_ECC_BCH_COVERED_BYTES,
NULL, ecc, NULL, errorpos);
BUG_ON(numerrs == -EINVAL); if (numerrs < 0) goto out;
for (i = 0; i < numerrs; i++)
errorpos[i] = (errorpos[i] & ~7) | (7 - (errorpos[i] & 7)); for (i = 0; i < numerrs; i++) if (errorpos[i] < DOC_ECC_BCH_COVERED_BYTES*8) /* error is located in data, correct it */
change_bit(errorpos[i], buf);
out:
doc_dbg("doc_ecc_bch_fix_data: flipped %d bits\n", numerrs); return numerrs;
}
/** * doc_read_page_prepare - Prepares reading data from a flash page * @docg3: the device * @block0: the first plane block index on flash memory * @block1: the second plane block index on flash memory * @page: the page index in the block * @offset: the offset in the page (must be a multiple of 4) * * Prepares the page to be read in the flash memory : * - tell ASIC to map the flash pages * - tell ASIC to be in read mode * * After a call to this method, a call to doc_read_page_finish is mandatory, * to end the read cycle of the flash. * * Read data from a flash page. The length to be read must be between 0 and * (page_size + oob_size + wear_size), ie. 532, and a multiple of 4 (because * the extra bytes reading is not implemented). * * As pages are grouped by 2 (in 2 planes), reading from a page must be done * in two steps: * - one read of 512 bytes at offset 0 * - one read of 512 bytes at offset 512 + 16 * * Returns 0 if successful, -EIO if a read error occurred.
*/ staticint doc_read_page_prepare(struct docg3 *docg3, int block0, int block1, int page, int offset)
{ int wear_area = 0, ret = 0;
/** * doc_read_page_getbytes - Reads bytes from a prepared page * @docg3: the device * @len: the number of bytes to be read (must be a multiple of 4) * @buf: the buffer to be filled in (or NULL is forget bytes) * @first: 1 if first time read, DOC_READADDRESS should be set * @last_odd: 1 if last read ended up on an odd byte * * Reads bytes from a prepared page. There is a trickery here : if the last read * ended up on an odd offset in the 1024 bytes double page, ie. between the 2 * planes, the first byte must be read apart. If a word (16bit) read was used, * the read would return the byte of plane 2 as low *and* high endian, which * will mess the read. *
*/ staticint doc_read_page_getbytes(struct docg3 *docg3, int len, u_char *buf, int first, int last_odd)
{ if (last_odd && len > 0) {
doc_read_data_area(docg3, buf, 1, first);
doc_read_data_area(docg3, buf ? buf + 1 : buf, len - 1, 0);
} else {
doc_read_data_area(docg3, buf, len, first);
}
doc_delay(docg3, 2); return len;
}
/** * doc_write_page_putbytes - Writes bytes into a prepared page * @docg3: the device * @len: the number of bytes to be written * @buf: the buffer of input bytes *
*/ staticvoid doc_write_page_putbytes(struct docg3 *docg3, int len, const u_char *buf)
{
doc_write_data_area(docg3, buf, len);
doc_delay(docg3, 2);
}
/** * doc_get_bch_hw_ecc - Get hardware calculated BCH ECC * @docg3: the device * @hwecc: the array of 7 integers where the hardware ecc will be stored
*/ staticvoid doc_get_bch_hw_ecc(struct docg3 *docg3, u8 *hwecc)
{ int i;
for (i = 0; i < DOC_ECC_BCH_SIZE; i++)
hwecc[i] = doc_register_readb(docg3, DOC_BCH_HW_ECC(i));
}
/** * doc_page_finish - Ends reading/writing of a flash page * @docg3: the device
*/ staticvoid doc_page_finish(struct docg3 *docg3)
{
doc_writeb(docg3, 0, DOC_DATAEND);
doc_delay(docg3, 2);
}
/** * doc_read_page_finish - Ends reading of a flash page * @docg3: the device * * As a side effect, resets the chip selector to 0. This ensures that after each * read operation, the floor 0 is selected. Therefore, if the systems halts, the * reboot will boot on floor 0, where the IPL is.
*/ staticvoid doc_read_page_finish(struct docg3 *docg3)
{
doc_page_finish(docg3);
doc_set_device_id(docg3, 0);
}
/** * calc_block_sector - Calculate blocks, pages and ofs. * * @from: offset in flash * @block0: first plane block index calculated * @block1: second plane block index calculated * @page: page calculated * @ofs: offset in page * @reliable: 0 if docg3 in normal mode, 1 if docg3 in fast mode, 2 if docg3 in * reliable mode. * * The calculation is based on the reliable/normal mode. In normal mode, the 64 * pages of a block are available. In reliable mode, as pages 2*n and 2*n+1 are * clones, only 32 pages per block are available.
*/ staticvoid calc_block_sector(loff_t from, int *block0, int *block1, int *page, int *ofs, int reliable)
{
uint sector, pages_biblock;
/** * doc_block_isbad - Checks whether a block is good or not * @mtd: the device * @from: the offset to find the correct block * * Returns 1 if block is bad, 0 if block is good
*/ staticint doc_block_isbad(struct mtd_info *mtd, loff_t from)
{ struct docg3 *docg3 = mtd->priv; int block0, block1, page, ofs, is_good;
#if 0 /** * doc_get_erase_count - Get block erase count * @docg3: the device * @from: the offset in which the block is. * * Get the number of times a block was erased. The number is the maximum of * erase times between first and second plane (which should be equal normally). * * Returns The number of erases, or -EINVAL or -EIO on error.
*/ staticint doc_get_erase_count(struct docg3 *docg3, loff_t from)
{
u8 buf[DOC_LAYOUT_WEAR_SIZE]; int ret, plane1_erase_count, plane2_erase_count; int block0, block1, page, ofs;
ret = doc_reset_seq(docg3); if (!ret)
ret = doc_read_page_prepare(docg3, block0, block1, page,
ofs + DOC_LAYOUT_WEAR_OFFSET, 0); if (!ret)
ret = doc_read_page_getbytes(docg3, DOC_LAYOUT_WEAR_SIZE,
buf, 1, 0);
doc_read_page_finish(docg3);
/** * doc_get_op_status - get erase/write operation status * @docg3: the device * * Queries the status from the chip, and returns it * * Returns the status (bits DOC_PLANES_STATUS_*)
*/ staticint doc_get_op_status(struct docg3 *docg3)
{
u8 status;
/** * doc_write_erase_wait_status - wait for write or erase completion * @docg3: the device * * Wait for the chip to be ready again after erase or write operation, and check * erase/write status. * * Returns 0 if erase successful, -EIO if erase/write issue, -ETIMEOUT if * timeout
*/ staticint doc_write_erase_wait_status(struct docg3 *docg3)
{ int i, status, ret = 0;
for (i = 0; !doc_is_ready(docg3) && i < 5; i++)
msleep(20); if (!doc_is_ready(docg3)) {
doc_dbg("Timeout reached and the chip is still not ready\n");
ret = -EAGAIN; goto out;
}
status = doc_get_op_status(docg3); if (status & DOC_PLANES_STATUS_FAIL) {
doc_dbg("Erase/Write failed on (a) plane(s), status = %x\n",
status);
ret = -EIO;
}
out:
doc_page_finish(docg3); return ret;
}
/** * doc_erase_block - Erase a couple of blocks * @docg3: the device * @block0: the first block to erase (leftmost plane) * @block1: the second block to erase (rightmost plane) * * Erase both blocks, and return operation status * * Returns 0 if erase successful, -EIO if erase issue, -ETIMEOUT if chip not * ready for too long
*/ staticint doc_erase_block(struct docg3 *docg3, int block0, int block1)
{ int ret, sector;
doc_dbg("doc_erase_block(blocks=(%d,%d))\n", block0, block1);
ret = doc_reset_seq(docg3); if (ret) return -EIO;
/** * doc_erase - Erase a portion of the chip * @mtd: the device * @info: the erase info * * Erase a bunch of contiguous blocks, by pairs, as a "mtd" page of 1024 is * split into 2 pages of 512 bytes on 2 contiguous blocks. * * Returns 0 if erase successful, -EINVAL if addressing error, -EIO if erase * issue
*/ staticint doc_erase(struct mtd_info *mtd, struct erase_info *info)
{ struct docg3 *docg3 = mtd->priv;
uint64_t len; int block0, block1, page, ret = 0, ofs = 0;
calc_block_sector(info->addr, &block0, &block1, &page, &ofs,
docg3->reliable);
mutex_lock(&docg3->cascade->lock);
doc_set_device_id(docg3, docg3->device_id);
doc_set_reliable_mode(docg3); for (len = info->len; !ret && len > 0; len -= mtd->erasesize) {
ret = doc_erase_block(docg3, block0, block1);
block0 += 2;
block1 += 2;
}
mutex_unlock(&docg3->cascade->lock);
return ret;
}
/** * doc_write_page - Write a single page to the chip * @docg3: the device * @to: the offset from first block and first page, in bytes, aligned on page * size * @buf: buffer to get bytes from * @oob: buffer to get out of band bytes from (can be NULL if no OOB should be * written) * @autoecc: if 0, all 16 bytes from OOB are taken, regardless of HW Hamming or * BCH computations. If 1, only bytes 0-7 and byte 15 are taken, * remaining ones are filled with hardware Hamming and BCH * computations. Its value is not meaningfull is oob == NULL. * * Write one full page (ie. 1 page split on two planes), of 512 bytes, with the * OOB data. The OOB ECC is automatically computed by the hardware Hamming and * BCH generator if autoecc is not null. * * Returns 0 if write successful, -EIO if write error, -EAGAIN if timeout
*/ staticint doc_write_page(struct docg3 *docg3, loff_t to, const u_char *buf, const u_char *oob, int autoecc)
{ int block0, block1, page, ret, ofs = 0;
u8 hwecc[DOC_ECC_BCH_SIZE], hamming;
/* * The wait status will perform another doc_page_finish() call, but that * seems to please the docg3, so leave it.
*/
ret = doc_write_erase_wait_status(docg3); return ret;
err:
doc_read_page_finish(docg3); return ret;
}
/** * doc_guess_autoecc - Guess autoecc mode from mbd_oob_ops * @ops: the oob operations * * Returns 0 or 1 if success, -EINVAL if invalid oob mode
*/ staticint doc_guess_autoecc(struct mtd_oob_ops *ops)
{ int autoecc;
switch (ops->mode) { case MTD_OPS_PLACE_OOB: case MTD_OPS_AUTO_OOB:
autoecc = 1; break; case MTD_OPS_RAW:
autoecc = 0; break; default:
autoecc = -EINVAL;
} return autoecc;
}
/** * doc_fill_autooob - Fill a 16 bytes OOB from 8 non-ECC bytes * @dst: the target 16 bytes OOB buffer * @oobsrc: the source 8 bytes non-ECC OOB buffer *
*/ staticvoid doc_fill_autooob(u8 *dst, u8 *oobsrc)
{
memcpy(dst, oobsrc, DOC_LAYOUT_OOB_PAGEINFO_SZ);
dst[DOC_LAYOUT_OOB_UNUSED_OFS] = oobsrc[DOC_LAYOUT_OOB_PAGEINFO_SZ];
}
/** * doc_backup_oob - Backup OOB into docg3 structure * @docg3: the device * @to: the page offset in the chip * @ops: the OOB size and buffer * * As the docg3 should write a page with its OOB in one pass, and some userland * applications do write_oob() to setup the OOB and then write(), store the OOB * into a temporary storage. This is very dangerous, as 2 concurrent * applications could store an OOB, and then write their pages (which will * result into one having its OOB corrupted). * * The only reliable way would be for userland to call doc_write_oob() with both * the page data _and_ the OOB area. * * Returns 0 if success, -EINVAL if ops content invalid
*/ staticint doc_backup_oob(struct docg3 *docg3, loff_t to, struct mtd_oob_ops *ops)
{ int ooblen = ops->ooblen, autoecc;
if (ooblen != DOC_LAYOUT_OOB_SIZE) return -EINVAL;
autoecc = doc_guess_autoecc(ops); if (autoecc < 0) return autoecc;
/** * doc_write_oob - Write out of band bytes to flash * @mtd: the device * @ofs: the offset from first block and first page, in bytes, aligned on page * size * @ops: the mtd oob structure * * Either write OOB data into a temporary buffer, for the subsequent write * page. The provided OOB should be 16 bytes long. If a data buffer is provided * as well, issue the page write. * Or provide data without OOB, and then a all zeroed OOB will be used (ECC will * still be filled in if asked for). * * Returns 0 is successful, EINVAL if length is not 14 bytes
*/ staticint doc_write_oob(struct mtd_info *mtd, loff_t ofs, struct mtd_oob_ops *ops)
{ struct docg3 *docg3 = mtd->priv; int ret, autoecc, oobdelta;
u8 *oobbuf = ops->oobbuf;
u8 *buf = ops->datbuf;
size_t len, ooblen;
u8 oob[DOC_LAYOUT_OOB_SIZE];
if (buf)
len = ops->len; else
len = 0; if (oobbuf)
ooblen = ops->ooblen; else
ooblen = 0;
if (oobbuf && ops->mode == MTD_OPS_PLACE_OOB)
oobbuf += ops->ooboffs;
staticint doc_register_sysfs(struct platform_device *pdev, struct docg3_cascade *cascade)
{ struct device *dev = &pdev->dev; int floor; int ret; int i;
for (floor = 0;
floor < DOC_MAX_NBFLOORS && cascade->floors[floor];
floor++) { for (i = 0; i < 4; i++) {
ret = device_create_file(dev, &doc_sys_attrs[floor][i]); if (ret) goto remove_files;
}
}
return 0;
remove_files: do { while (--i >= 0)
device_remove_file(dev, &doc_sys_attrs[floor][i]);
i = 4;
} while (--floor >= 0);
if (IS_ERR_OR_NULL(root)) { if (IS_ENABLED(CONFIG_DEBUG_FS) &&
!IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER))
dev_warn(floor->dev.parent, "CONFIG_MTD_PARTITIONED_MASTER must be enabled to expose debugfs stuff\n"); return;
}
/** * doc_set_driver_info - Fill the mtd_info structure and docg3 structure * @chip_id: The chip ID of the supported chip * @mtd: The structure to fill
*/ staticint __init doc_set_driver_info(int chip_id, struct mtd_info *mtd)
{ struct docg3 *docg3 = mtd->priv; int cfg;
/** * doc_probe_device - Check if a device is available * @cascade: the cascade of chips this devices will belong to * @floor: the floor of the probed device * @dev: the device * * Checks whether a device at the specified IO range, and floor is available. * * Returns a mtd_info struct if there is a device, ENODEV if none found, ENOMEM * if a memory allocation failed. If floor 0 is checked, a reset of the ASIC is * launched.
*/ staticstruct mtd_info * __init
doc_probe_device(struct docg3_cascade *cascade, int floor, struct device *dev)
{ int ret, bbt_nbpages;
u16 chip_id, chip_id_inv; struct docg3 *docg3; struct mtd_info *mtd;
ret = 0; if (chip_id != (u16)(~chip_id_inv)) { goto nomem4;
}
switch (chip_id) { case DOC_CHIPID_G3:
doc_info("Found a G3 DiskOnChip at addr %p, floor %d\n",
docg3->cascade->base, floor); break; default:
doc_err("Chip id %04x is not a DiskOnChip G3 chip\n", chip_id); goto nomem4;
}
ret = doc_set_driver_info(chip_id, mtd); if (ret) goto nomem4;
doc_dbg("docg3_resume()\n"); for (i = 0; i < 12; i++)
doc_readb(docg3, DOC_IOSPACE_IPL); return 0;
}
/** * docg3_suspend - Put in low power mode the docg3 floor * @pdev: platform device * @state: power state * * Shuts off most of docg3 circuitery to lower power consumption. * * Returns 0 if suspend succeeded, -EIO if chip refused suspend
*/ staticint docg3_suspend(struct platform_device *pdev, pm_message_t state)
{ int floor, i; struct docg3_cascade *cascade; struct mtd_info **docg3_floors, *mtd; struct docg3 *docg3;
u8 ctrl, pwr_down;
/** * docg3_probe - Probe the IO space for a DiskOnChip G3 chip * @pdev: platform device * * Probes for a G3 chip at the specified IO space in the platform data * ressources. The floor 0 must be available. * * Returns 0 on success, -ENOMEM, -ENXIO on error
*/ staticint __init docg3_probe(struct platform_device *pdev)
{ struct device *dev = &pdev->dev; struct mtd_info *mtd; struct resource *ress; void __iomem *base; int ret, floor; struct docg3_cascade *cascade;
ret = -ENXIO;
ress = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!ress) {
dev_err(dev, "No I/O memory resource defined\n"); return ret;
}
ret = -ENOMEM;
base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE); if (!base) {
dev_err(dev, "devm_ioremap dev failed\n"); return ret;
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Robert Jarzmik ");
MODULE_DESCRIPTION("MTD driver for DiskOnChip G3");
Messung V0.5
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.62Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.