drivers/mtd/nand/raw/sm_common.c

Source file repositories/reference/linux-study-clean/drivers/mtd/nand/raw/sm_common.c

File Facts

System
Linux kernel
Corpus path
drivers/mtd/nand/raw/sm_common.c
Extension
.c
Size
5821 bytes
Lines
211
Domain
Driver Families
Bucket
drivers/mtd
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright © 2009 - Maxim Levitsky
 * Common routines & support for xD format
 */
#include <linux/kernel.h>
#include <linux/mtd/rawnand.h>
#include <linux/module.h>
#include <linux/sizes.h>
#include "sm_common.h"

static int oob_sm_ooblayout_ecc(struct mtd_info *mtd, int section,
				struct mtd_oob_region *oobregion)
{
	if (section > 1)
		return -ERANGE;

	oobregion->length = 3;
	oobregion->offset = ((section + 1) * 8) - 3;

	return 0;
}

static int oob_sm_ooblayout_free(struct mtd_info *mtd, int section,
				 struct mtd_oob_region *oobregion)
{
	switch (section) {
	case 0:
		/* reserved */
		oobregion->offset = 0;
		oobregion->length = 4;
		break;
	case 1:
		/* LBA1 */
		oobregion->offset = 6;
		oobregion->length = 2;
		break;
	case 2:
		/* LBA2 */
		oobregion->offset = 11;
		oobregion->length = 2;
		break;
	default:
		return -ERANGE;
	}

	return 0;
}

static const struct mtd_ooblayout_ops oob_sm_ops = {
	.ecc = oob_sm_ooblayout_ecc,
	.free = oob_sm_ooblayout_free,
};

/* NOTE: This layout is not compatible with SmartMedia, */
/* because the 256 byte devices have page dependent oob layout */
/* However it does preserve the bad block markers */
/* If you use smftl, it will bypass this and work correctly */
/* If you not, then you break SmartMedia compliance anyway */

static int oob_sm_small_ooblayout_ecc(struct mtd_info *mtd, int section,
				      struct mtd_oob_region *oobregion)
{
	if (section)
		return -ERANGE;

	oobregion->length = 3;
	oobregion->offset = 0;

	return 0;
}

static int oob_sm_small_ooblayout_free(struct mtd_info *mtd, int section,
				       struct mtd_oob_region *oobregion)
{
	switch (section) {
	case 0:
		/* reserved */
		oobregion->offset = 3;
		oobregion->length = 2;
		break;
	case 1:
		/* LBA1 */
		oobregion->offset = 6;
		oobregion->length = 2;
		break;
	default:
		return -ERANGE;
	}

Annotation

Implementation Notes