// SPDX-License-Identifier: GPL-2.0-only /* * (C) 2005, 2006 Red Hat Inc. * * Author: David Woodhouse <dwmw2@infradead.org> * Tom Sylla <tom.sylla@amd.com> * * Overview: * This is a device driver for the NAND flash controller found on * the AMD CS5535/CS5536 companion chipsets for the Geode processor. * mtd-id for command line partitioning is cs553x_nand_cs[0-3] * where 0-3 reflects the chip select for NAND.
*/
/* NAND BAR MSRs */ #define MSR_DIVIL_LBAR_FLSH0 0x51400010 /* Flash Chip Select 0 */ #define MSR_DIVIL_LBAR_FLSH1 0x51400011 /* Flash Chip Select 1 */ #define MSR_DIVIL_LBAR_FLSH2 0x51400012 /* Flash Chip Select 2 */ #define MSR_DIVIL_LBAR_FLSH3 0x51400013 /* Flash Chip Select 3 */ /* Each made up of... */ #define FLSH_LBAR_EN (1ULL<<32) #define FLSH_NOR_NAND (1ULL<<33) /* 1 for NAND */ #define FLSH_MEM_IO (1ULL<<34) /* 1 for MMIO */ /* I/O BARs have BASE_ADDR in bits 15:4, IO_MASK in 47:36 */ /* MMIO BARs have BASE_ADDR in bits 31:12, MEM_MASK in 63:44 */
/* Pin function selection MSR (IDE vs. flash on the IDE pins) */ #define MSR_DIVIL_BALL_OPTS 0x51400015 #define PIN_OPT_IDE (1<<0) /* 0 for flash, 1 for IDE */
/* Registers within the NAND flash controller BAR -- memory mapped */ #define MM_NAND_DATA 0x00 /* 0 to 0x7ff, in fact */ #define MM_NAND_CTL 0x800 /* Any even address 0x800-0x80e */ #define MM_NAND_IO 0x801 /* Any odd address 0x801-0x80f */ #define MM_NAND_STS 0x810 #define MM_NAND_ECC_LSB 0x811 #define MM_NAND_ECC_MSB 0x812 #define MM_NAND_ECC_COL 0x813 #define MM_NAND_LAC 0x814 #define MM_NAND_ECC_CTL 0x815
/* Registers within the NAND flash controller BAR -- I/O mapped */ #define IO_NAND_DATA 0x00 /* 0 to 3, in fact */ #define IO_NAND_CTL 0x04 #define IO_NAND_IO 0x05 #define IO_NAND_STS 0x06 #define IO_NAND_ECC_CTL 0x08 #define IO_NAND_ECC_LSB 0x09 #define IO_NAND_ECC_MSB 0x0a #define IO_NAND_ECC_COL 0x0b #define IO_NAND_LAC 0x0c
staticint cs553x_exec_instr(struct cs553x_nand_controller *cs553x, conststruct nand_op_instr *instr)
{ unsignedint i; int ret = 0;
switch (instr->type) { case NAND_OP_CMD_INSTR:
ret = cs553x_write_ctrl_byte(cs553x, CS_NAND_CTL_CLE,
instr->ctx.cmd.opcode); break;
case NAND_OP_ADDR_INSTR: for (i = 0; i < instr->ctx.addr.naddrs; i++) {
ret = cs553x_write_ctrl_byte(cs553x, CS_NAND_CTL_ALE,
instr->ctx.addr.addrs[i]); if (ret) break;
} break;
case NAND_OP_DATA_IN_INSTR:
cs553x_data_in(cs553x, instr->ctx.data.buf.in,
instr->ctx.data.len); break;
case NAND_OP_DATA_OUT_INSTR:
cs553x_data_out(cs553x, instr->ctx.data.buf.out,
instr->ctx.data.len); break;
case NAND_OP_WAITRDY_INSTR:
ret = cs553x_wait_ready(cs553x, instr->ctx.waitrdy.timeout_ms); break;
}
/* De-assert the CE pin */
writeb(0, cs553x->mmio + MM_NAND_CTL); for (i = 0; i < op->ninstrs; i++) {
ret = cs553x_exec_instr(cs553x, &op->instrs[i]); if (ret) break;
}
/* Re-assert the CE pin. */
writeb(CS_NAND_CTL_CE, cs553x->mmio + MM_NAND_CTL);
staticint is_geode(void)
{ /* These are the CPUs which will have a CS553[56] companion chip */ if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
boot_cpu_data.x86 == 5 &&
boot_cpu_data.x86_model == 10) return 1; /* Geode LX */
staticint __init cs553x_init(void)
{ int err = -ENXIO; int i;
uint64_t val;
/* If the CPU isn't a Geode GX or LX, abort */ if (!is_geode()) return -ENXIO;
/* If it doesn't have the CS553[56], abort */
rdmsrq(MSR_DIVIL_GLD_CAP, val);
val &= ~0xFFULL; if (val != CAP_CS5535 && val != CAP_CS5536) return -ENXIO;
/* If it doesn't have the NAND controller enabled, abort */
rdmsrq(MSR_DIVIL_BALL_OPTS, val); if (val & PIN_OPT_IDE) {
pr_info("CS553x NAND controller: Flash I/O not enabled in MSR_DIVIL_BALL_OPTS.\n"); return -ENXIO;
}
for (i = 0; i < NR_CS553X_CONTROLLERS; i++) {
rdmsrq(MSR_DIVIL_LBAR_FLSH0 + i, val);
if ((val & (FLSH_LBAR_EN|FLSH_NOR_NAND)) == (FLSH_LBAR_EN|FLSH_NOR_NAND))
err = cs553x_init_one(i, !!(val & FLSH_MEM_IO), val & 0xFFFFFFFF);
}
/* Register all devices together here. This means we can easily hack it to
do mtdconcat etc. if we want to. */ for (i = 0; i < NR_CS553X_CONTROLLERS; i++) { if (controllers[i]) { /* If any devices registered, return success. Else the last error. */
mtd_device_register(nand_to_mtd(&controllers[i]->chip),
NULL, 0);
err = 0;
}
}
return err;
}
module_init(cs553x_init);
staticvoid __exit cs553x_cleanup(void)
{ int i;
for (i = 0; i < NR_CS553X_CONTROLLERS; i++) { struct cs553x_nand_controller *controller = controllers[i]; struct nand_chip *this = &controller->chip; struct mtd_info *mtd = nand_to_mtd(this); int ret;
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.