static int __devinit bfin_flash_probe(struct platform_device *pdev) { int ret; struct physmap_flash_data *pdata = pdev->dev.platform_data; struct resource *memory = platform_get_resource(pdev, IORESOURCE_MEM, 0); struct resource *flash_ambctl = platform_get_resource(pdev, IORESOURCE_MEM, 1); struct async_state *state; state = kzalloc(sizeof(*state), GFP_KERNEL); if (!state) return -ENOMEM; state->map.name = DRIVER_NAME; state->map.read = bfin_flash_read; state->map.copy_from = bfin_flash_copy_from; state->map.write = bfin_flash_write; state->map.copy_to = bfin_flash_copy_to; state->map.bankwidth = pdata->width; state->map.size = resource_size(memory); state->map.virt = (void __iomem *)memory->start; state->map.phys = memory->start; state->map.map_priv_1 = (unsigned long)state; state->enet_flash_pin = platform_get_irq(pdev, 0); state->flash_ambctl0 = flash_ambctl->start; state->flash_ambctl1 = flash_ambctl->end; if (gpio_request(state->enet_flash_pin, DRIVER_NAME)) { pr_devinit(KERN_ERR DRIVER_NAME ": Failed to request gpio %d\n", state->enet_flash_pin); kfree(state); return -EBUSY; } gpio_direction_output(state->enet_flash_pin, 1); pr_devinit(KERN_NOTICE DRIVER_NAME ": probing %d-bit flash bus\n", state->map.bankwidth * 8); state->mtd = do_map_probe(memory->name, &state->map); if (!state->mtd) { gpio_free(state->enet_flash_pin); kfree(state); return -ENXIO; } ret = parse_mtd_partitions(state->mtd, part_probe_types, &pdata->parts, 0); if (ret > 0) { pr_devinit(KERN_NOTICE DRIVER_NAME ": Using commandline partition definition\n"); mtd_device_register(state->mtd, pdata->parts, ret); state->parts = pdata->parts; } else if (pdata->nr_parts) { pr_devinit(KERN_NOTICE DRIVER_NAME ": Using board partition definition\n"); mtd_device_register(state->mtd, pdata->parts, pdata->nr_parts); } else { pr_devinit(KERN_NOTICE DRIVER_NAME ": no partition info available, registering whole flash at once\n"); mtd_device_register(state->mtd, NULL, 0); } platform_set_drvdata(pdev, state); return 0; }
static int __devinit generic_onenand_probe(struct platform_device *pdev) { struct onenand_info *info; struct onenand_platform_data *pdata = pdev->dev.platform_data; struct resource *res = pdev->resource; unsigned long size = resource_size(res); int err; info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL); if (!info) return -ENOMEM; if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) { err = -EBUSY; goto out_free_info; } info->onenand.base = ioremap(res->start, size); if (!info->onenand.base) { err = -ENOMEM; goto out_release_mem_region; } info->onenand.mmcontrol = pdata ? pdata->mmcontrol : 0; info->onenand.irq = platform_get_irq(pdev, 0); info->mtd.name = dev_name(&pdev->dev); info->mtd.priv = &info->onenand; info->mtd.owner = THIS_MODULE; if (onenand_scan(&info->mtd, 1)) { err = -ENXIO; goto out_iounmap; } err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0); if (err > 0) mtd_device_register(&info->mtd, info->parts, err); else if (err <= 0 && pdata && pdata->parts) mtd_device_register(&info->mtd, pdata->parts, pdata->nr_parts); else err = mtd_device_register(&info->mtd, NULL, 0); platform_set_drvdata(pdev, info); return 0; out_iounmap: iounmap(info->onenand.base); out_release_mem_region: release_mem_region(res->start, size); out_free_info: kfree(info); return err; }
static int __init init_sc520cdp(void) { int i, devices_found = 0; #ifdef REPROGRAM_PAR /* reprogram PAR registers so flash appears at the desired addresses */ sc520cdp_setup_par(); #endif for (i = 0; i < NUM_FLASH_BANKS; i++) { #ifdef CONFIG_DEBUG_PRINTK printk(KERN_NOTICE "SC520 CDP flash device: 0x%Lx at 0x%Lx\n", (unsigned long long)sc520cdp_map[i].size, (unsigned long long)sc520cdp_map[i].phys); #else ; #endif sc520cdp_map[i].virt = ioremap_nocache(sc520cdp_map[i].phys, sc520cdp_map[i].size); if (!sc520cdp_map[i].virt) { #ifdef CONFIG_DEBUG_PRINTK printk("Failed to ioremap_nocache\n"); #else ; #endif return -EIO; } simple_map_init(&sc520cdp_map[i]); mymtd[i] = do_map_probe("cfi_probe", &sc520cdp_map[i]); if(!mymtd[i]) mymtd[i] = do_map_probe("jedec_probe", &sc520cdp_map[i]); if(!mymtd[i]) mymtd[i] = do_map_probe("map_rom", &sc520cdp_map[i]); if (mymtd[i]) { mymtd[i]->owner = THIS_MODULE; ++devices_found; } else { iounmap(sc520cdp_map[i].virt); } } if(devices_found >= 2) { /* Combine the two flash banks into a single MTD device & register it: */ merged_mtd = mtd_concat_create(mymtd, 2, "SC520CDP Flash Banks #0 and #1"); if(merged_mtd) mtd_device_register(merged_mtd, NULL, 0); } if(devices_found == 3) /* register the third (DIL-Flash) device */ mtd_device_register(mymtd[2], NULL, 0); return(devices_found ? 0 : -ENXIO); }
int mtdram_init_device(struct mtd_info *mtd, void *mapped_address, unsigned long size, const char *name) { memset(mtd, 0, sizeof(*mtd)); /* Setup the MTD structure */ mtd->name = name; mtd->type = MTD_RAM; mtd->flags = MTD_CAP_RAM; mtd->size = size; mtd->writesize = 1; mtd->writebufsize = writebuf_size; mtd->erasesize = MTDRAM_ERASE_SIZE; mtd->priv = mapped_address; mtd->owner = THIS_MODULE; mtd->_erase = ram_erase; mtd->_point = ram_point; mtd->_unpoint = ram_unpoint; mtd->_read = ram_read; mtd->_write = ram_write; if (mtd_device_register(mtd, NULL, 0)) return -EIO; return 0; }
static int __init init_ts5500_map(void) { int rc = 0; ts5500_map.virt = ioremap_nocache(ts5500_map.phys, ts5500_map.size); if (!ts5500_map.virt) { printk(KERN_ERR "Failed to ioremap_nocache\n"); rc = -EIO; goto err2; } simple_map_init(&ts5500_map); mymtd = do_map_probe("jedec_probe", &ts5500_map); if (!mymtd) mymtd = do_map_probe("map_rom", &ts5500_map); if (!mymtd) { rc = -ENXIO; goto err1; } mymtd->owner = THIS_MODULE; mtd_device_register(mymtd, ts5500_partitions, NUM_PARTITIONS); return 0; err1: iounmap(ts5500_map.virt); err2: return rc; }
static int __init init_rpxlite(void) { #ifdef CONFIG_DEBUG_PRINTK printk(KERN_NOTICE "RPX Lite or CLLF flash device: %x at %x\n", WINDOW_SIZE*4, WINDOW_ADDR); #else ; #endif rpxlite_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE * 4); if (!rpxlite_map.virt) { #ifdef CONFIG_DEBUG_PRINTK printk("Failed to ioremap\n"); #else ; #endif return -EIO; } simple_map_init(&rpxlite_map); mymtd = do_map_probe("cfi_probe", &rpxlite_map); if (mymtd) { mymtd->owner = THIS_MODULE; mtd_device_register(mymtd, NULL, 0); return 0; } iounmap((void *)rpxlite_map.virt); return -ENXIO; }
/** * powernv_flash_probe * @pdev: platform device * * Returns 0 on success, -ENOMEM, -ENXIO on error */ static int powernv_flash_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct powernv_flash *data; int ret; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) { ret = -ENOMEM; goto out; } data->mtd.priv = data; ret = of_property_read_u32(dev->of_node, "ibm,opal-id", &(data->id)); if (ret) { dev_err(dev, "no device property 'ibm,opal-id'\n"); goto out; } ret = powernv_flash_set_driver_info(dev, &data->mtd); if (ret) goto out; dev_set_drvdata(dev, data); /* * The current flash that skiboot exposes is one contiguous flash chip * with an ffs partition at the start, it should prove easier for users * to deal with partitions or not as they see fit */ ret = mtd_device_register(&data->mtd, NULL, 0); out: return ret; }
static int __init init_netsc520(void) { printk(KERN_NOTICE "NetSc520 flash device: 0x%Lx at 0x%Lx\n", (unsigned long long)netsc520_map.size, (unsigned long long)netsc520_map.phys); netsc520_map.virt = ioremap_nocache(netsc520_map.phys, netsc520_map.size); if (!netsc520_map.virt) { printk("Failed to ioremap_nocache\n"); return -EIO; } simple_map_init(&netsc520_map); mymtd = do_map_probe("cfi_probe", &netsc520_map); if(!mymtd) mymtd = do_map_probe("map_ram", &netsc520_map); if(!mymtd) mymtd = do_map_probe("map_rom", &netsc520_map); if (!mymtd) { iounmap(netsc520_map.virt); return -ENXIO; } mymtd->owner = THIS_MODULE; mtd_device_register(mymtd, partition_info, NUM_PARTITIONS); return 0; }
static int rknand_add_partitions(struct rknand_info *nand_info) { #ifdef CONFIG_MTD_CMDLINE_PARTS int num_partitions = 0; // 从命令行解析分区的信息 num_partitions = parse_mtd_partitions(&(rknand_mtd), part_probes, &rknand_parts, 0); NAND_DEBUG(NAND_DEBUG_LEVEL0,"num_partitions = %d\n",num_partitions); if(num_partitions > 0) { int i; for (i = 0; i < num_partitions; i++) { rknand_parts[i].offset *= 0x200; rknand_parts[i].size *=0x200; } rknand_parts[num_partitions - 1].size = rknand_mtd.size - rknand_parts[num_partitions - 1].offset; g_num_partitions = num_partitions; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0)) return mtd_device_register(&rknand_mtd, rknand_parts, num_partitions); #else return add_mtd_partitions(&(rknand_mtd), rknand_parts, num_partitions); #endif } #endif g_num_partitions = 0; return 0; }
static int __init init_dbox2_flash(void) { printk(KERN_NOTICE "D-Box 2 flash driver (size->0x%X mem->0x%X)\n", WINDOW_SIZE, WINDOW_ADDR); dbox2_flash_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE); if (!dbox2_flash_map.virt) { printk("Failed to ioremap\n"); return -EIO; } simple_map_init(&dbox2_flash_map); // Probe for dual Intel 28F320 or dual AMD mymtd = do_map_probe("cfi_probe", &dbox2_flash_map); if (!mymtd) { // Probe for single Intel 28F640 dbox2_flash_map.bankwidth = 2; mymtd = do_map_probe("cfi_probe", &dbox2_flash_map); } if (mymtd) { mymtd->owner = THIS_MODULE; /* Create MTD devices for each partition. */ mtd_device_register(mymtd, partition_info, NUM_PARTITIONS); return 0; } iounmap((void *)dbox2_flash_map.virt); return -ENXIO; }
static int __init init_flagadm(void) { printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n", FLASH_SIZE, FLASH_PHYS_ADDR); flagadm_map.phys = FLASH_PHYS_ADDR; flagadm_map.virt = ioremap(FLASH_PHYS_ADDR, FLASH_SIZE); if (!flagadm_map.virt) { printk("Failed to ioremap\n"); return -EIO; } simple_map_init(&flagadm_map); mymtd = do_map_probe("cfi_probe", &flagadm_map); if (mymtd) { mymtd->owner = THIS_MODULE; mtd_device_register(mymtd, flagadm_parts, PARTITION_COUNT); printk(KERN_NOTICE "FlagaDM flash device initialized\n"); return 0; } iounmap((void __iomem *)flagadm_map.virt); return -ENXIO; }
int sm_register_device(struct mtd_info *mtd, int smartmedia) { struct nand_chip *chip = mtd->priv; int ret; chip->options |= NAND_SKIP_BBTSCAN; /* Scan for card properties */ ret = nand_scan_ident(mtd, 1, smartmedia ? nand_smartmedia_flash_ids : nand_xd_flash_ids); if (ret) return ret; /* Bad block marker position */ chip->badblockpos = 0x05; chip->badblockbits = 7; chip->block_markbad = sm_block_markbad; /* ECC layout */ if (mtd->writesize == SM_SECTOR_SIZE) chip->ecc.layout = &nand_oob_sm; else if (mtd->writesize == SM_SMALL_PAGE) chip->ecc.layout = &nand_oob_sm_small; else return -ENODEV; ret = nand_scan_tail(mtd); if (ret) return ret; return mtd_device_register(mtd, NULL, 0); }
static void mtd_concat_add_work(struct work_struct *work) { struct mtd_info *mtd; mtd = mtd_concat_create(concat_devs, ARRAY_SIZE(concat_devs), "flash"); mtd_device_register(mtd, multi_pdata->parts, multi_pdata->nr_parts); }
int __init init_alteramap(void) { static const char *rom_probe_types[] = {"cfi_probe", "jedec_probe", 0 }; const char **type; ndk_amd_map.virt = (unsigned long *)ioremap_nocache(WINDOW_ADDR, WINDOW_SIZE); /* if (!ndk_amd_map.virt) { printk("Failed to ioremap\n"); return -EIO; } */ simple_map_init(&ndk_amd_map); mymtd = 0; type = rom_probe_types; for(; !mymtd && *type; type++) { mymtd = do_map_probe(*type, &ndk_amd_map); } if (mymtd) { mymtd->owner = THIS_MODULE; mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes, &mtd_parts, 0); if (mtd_parts_nb > 0) { mtd_device_register(mymtd, mtd_parts, mtd_parts_nb); return 0; } if (NUM_PARTITIONS != 0) { printk(KERN_NOTICE "Using Altera NDK partition definition\n"); mtd_device_register(mymtd, alteramap_partitions, NUM_PARTITIONS); return 0; } return 0; } iounmap((void *)ndk_amd_map.virt); return -ENXIO; }
static void mtd_concat_add_work(struct work_struct *work) { struct mtd_info *mtd; mtd = mtd_concat_create(concat_devs, ARRAY_SIZE(concat_devs), "flash"); mtd_device_register(mtd, wzrhpag300h_flash_partitions, ARRAY_SIZE(wzrhpag300h_flash_partitions)); }
int mtdsf_init_device(struct mtd_info *mtd, unsigned long size, char *name) { int nr_parts, cut_parts = 0; char *part_type = NULL; mtd->name = name; mtd->type = MTD_NORFLASH; mtd->flags = MTD_CAP_NORFLASH; mtd->size = size; mtd->erasesize = MTDSF_ERASE_SIZE; mtd->owner = THIS_MODULE; mtd->erase = sf_erase; mtd->read = sf_read; mtd->write = sf_write; mtd->writesize = 1; boot_partitions[5].offset = size - boot_partitions[5].size; boot_partitions[4].offset = boot_partitions[5].offset - boot_partitions[4].size; boot_partitions[3].offset = boot_partitions[4].offset - boot_partitions[3].size; boot_partitions[2].offset = boot_partitions[3].offset - boot_partitions[2].size; if (boot_partitions[2].offset > 0x00280000) { boot_partitions[1].offset = boot_partitions[2].offset - boot_partitions[1].size; if (boot_partitions[1].offset > 0) boot_partitions[0].size = boot_partitions[1].offset; else { shift_partition_content(1); cut_parts = 1; } } else if (boot_partitions[2].offset > 0) { boot_partitions[1].size = boot_partitions[2].offset; boot_partitions[1].offset = 0; shift_partition_content(1); cut_parts = 1; } else { shift_partition_content(2); cut_parts = 2; } nr_parts = parse_mtd_partitions(mtd, part_probes, &parts, 0); if (nr_parts > 0) { part_type = "command line"; cut_parts = 0; } if (nr_parts <= 0) { parts = boot_partitions; nr_parts = NUM_SF_PARTITIONS; part_type = "builtin"; } printk(KERN_INFO "SF Using %s partition table count=%d\n", part_type, nr_parts - cut_parts); mtd_device_register(mtd, parts, nr_parts - cut_parts); //add_mtd_partitions(mtd, boot_partitions, ARRAY_SIZE(boot_partitions)); return 0; }
static int __devinit vr_nor_init_partitions(struct vr_nor_mtd *p) { struct mtd_partition *parts; static const char *part_probes[] = { "cmdlinepart", NULL }; /* register the flash bank */ /* partition the flash bank */ p->nr_parts = parse_mtd_partitions(p->info, part_probes, &parts, 0); return mtd_device_register(p->info, parts, p->nr_parts); }
static int __devinit mtd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { struct mtd_pci_info *info = (struct mtd_pci_info *)id->driver_data; struct map_pci_info *map = NULL; struct mtd_info *mtd = NULL; int err; err = pci_enable_device(dev); if (err) goto out; err = pci_request_regions(dev, "pci mtd"); if (err) goto out; map = kmalloc(sizeof(*map), GFP_KERNEL); err = -ENOMEM; if (!map) goto release; map->map = mtd_pci_map; map->map.name = pci_name(dev); map->dev = dev; map->exit = info->exit; map->translate = info->translate; err = info->init(dev, map); if (err) goto release; /* tsk - do_map_probe should take const char * */ mtd = do_map_probe((char *)info->map_name, &map->map); err = -ENODEV; if (!mtd) goto release; mtd->owner = THIS_MODULE; mtd_device_register(mtd, NULL, 0); pci_set_drvdata(dev, mtd); return 0; release: if (map) { map->exit(dev, map); kfree(map); } pci_release_regions(dev); out: return err; }
/* * Initialize chip structure */ static int ndfc_chip_init(struct ndfc_controller *ndfc, struct device_node *node) { struct device_node *flash_np; struct nand_chip *chip = &ndfc->chip; struct mtd_info *mtd = nand_to_mtd(chip); int ret; chip->IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA; chip->IO_ADDR_W = ndfc->ndfcbase + NDFC_DATA; chip->cmd_ctrl = ndfc_hwcontrol; chip->dev_ready = ndfc_ready; chip->select_chip = ndfc_select_chip; chip->chip_delay = 50; chip->controller = &ndfc->ndfc_control; chip->read_buf = ndfc_read_buf; chip->write_buf = ndfc_write_buf; chip->ecc.correct = nand_correct_data; chip->ecc.hwctl = ndfc_enable_hwecc; chip->ecc.calculate = ndfc_calculate_ecc; chip->ecc.mode = NAND_ECC_HW; chip->ecc.size = 256; chip->ecc.bytes = 3; chip->ecc.strength = 1; nand_set_controller_data(chip, ndfc); mtd->dev.parent = &ndfc->ofdev->dev; flash_np = of_get_next_child(node, NULL); if (!flash_np) return -ENODEV; nand_set_flash_node(chip, flash_np); mtd->name = kasprintf(GFP_KERNEL, "%s.%s", dev_name(&ndfc->ofdev->dev), flash_np->name); if (!mtd->name) { ret = -ENOMEM; goto err; } ret = nand_scan(mtd, 1); if (ret) goto err; ret = mtd_device_register(mtd, NULL, 0); err: of_node_put(flash_np); if (ret) kfree(mtd->name); return ret; }
static int __init init_mbx(void) { printk(KERN_NOTICE "Motorola MBX flash device: 0x%x at 0x%x\n", WINDOW_SIZE*4, WINDOW_ADDR); mbx_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE * 4); if (!mbx_map.virt) { printk("Failed to ioremap\n"); return -EIO; } simple_map_init(&mbx_map); mymtd = do_map_probe("jedec_probe", &mbx_map); if (mymtd) { mymtd->owner = THIS_MODULE; mtd_device_register(mymtd, NULL, 0); mtd_device_register(mymtd, partition_info, NUM_PARTITIONS); return 0; } iounmap((void *)mbx_map.virt); return -ENXIO; }
static int __init init_vmax301(void) { int i; unsigned long iomapadr; // Print out our little header.. #ifdef CONFIG_DEBUG_PRINTK printk("Tempustech VMAX 301 MEM:0x%x-0x%x\n",WINDOW_START, WINDOW_START+4*WINDOW_LENGTH); #else ; #endif iomapadr = (unsigned long)ioremap(WINDOW_START, WINDOW_LENGTH*4); if (!iomapadr) { #ifdef CONFIG_DEBUG_PRINTK printk("Failed to ioremap memory region\n"); #else ; #endif return -EIO; } /* Put the address in the map's private data area. We store the actual MTD IO address rather than the address of the first half, because it's used more often. */ vmax_map[0].map_priv_2 = iomapadr + WINDOW_START; vmax_map[1].map_priv_2 = iomapadr + (3*WINDOW_START); for (i=0; i<2; i++) { vmax_mtd[i] = do_map_probe("cfi_probe", &vmax_map[i]); if (!vmax_mtd[i]) vmax_mtd[i] = do_map_probe("jedec", &vmax_map[i]); if (!vmax_mtd[i]) vmax_mtd[i] = do_map_probe("map_ram", &vmax_map[i]); if (!vmax_mtd[i]) vmax_mtd[i] = do_map_probe("map_rom", &vmax_map[i]); if (vmax_mtd[i]) { vmax_mtd[i]->owner = THIS_MODULE; mtd_device_register(vmax_mtd[i], NULL, 0); } } if (!vmax_mtd[0] && !vmax_mtd[1]) { iounmap((void *)iomapadr); return -ENXIO; } return 0; }
static int __init uclinux_mtd_init(void) { struct mtd_info *mtd; struct map_info *mapp; mapp = &uclinux_ram_map; if (!mapp->size) mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8)))); mapp->bankwidth = 4; printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n", (int) mapp->phys, (int) mapp->size); /* * The filesystem is guaranteed to be in direct mapped memory. It is * directly following the kernels own bss region. Following the same * mechanism used by architectures setting up traditional initrds we * use phys_to_virt to get the virtual address of its start. */ mapp->virt = phys_to_virt(mapp->phys); if (mapp->virt == 0) { printk("uclinux[mtd]: no virtual mapping?\n"); return(-EIO); } simple_map_init(mapp); mtd = do_map_probe("map_ram", mapp); if (!mtd) { printk("uclinux[mtd]: failed to find a mapping?\n"); return(-ENXIO); } mtd->owner = THIS_MODULE; mtd->_point = uclinux_point; mtd->priv = mapp; uclinux_ram_mtdinfo = mtd; mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS); return(0); }
/* * Initialize FLASH support */ static int __init h720x_mtd_init(void) { char *part_type = NULL; h720x_map.virt = ioremap(h720x_map.phys, h720x_map.size); if (!h720x_map.virt) { printk(KERN_ERR "H720x-MTD: ioremap failed\n"); return -EIO; } simple_map_init(&h720x_map); // Probe for flash bankwidth 4 printk (KERN_INFO "H720x-MTD probing 32bit FLASH\n"); mymtd = do_map_probe("cfi_probe", &h720x_map); if (!mymtd) { printk (KERN_INFO "H720x-MTD probing 16bit FLASH\n"); // Probe for bankwidth 2 h720x_map.bankwidth = 2; mymtd = do_map_probe("cfi_probe", &h720x_map); } if (mymtd) { mymtd->owner = THIS_MODULE; nr_mtd_parts = parse_mtd_partitions(mymtd, probes, &mtd_parts, 0); if (nr_mtd_parts > 0) part_type = "command line"; if (nr_mtd_parts <= 0) { mtd_parts = h720x_partitions; nr_mtd_parts = NUM_PARTITIONS; part_type = "builtin"; } printk(KERN_INFO "Using %s partition table\n", part_type); mtd_device_register(mymtd, mtd_parts, nr_mtd_parts); return 0; } iounmap((void *)h720x_map.virt); return -ENXIO; }
static int __init init_soleng_maps(void) { /* First probe at offset 0 */ soleng_flash_map.phys = 0; soleng_flash_map.virt = (void __iomem *)P2SEGADDR(0); soleng_eprom_map.phys = 0x01000000; soleng_eprom_map.virt = (void __iomem *)P1SEGADDR(0x01000000); simple_map_init(&soleng_eprom_map); simple_map_init(&soleng_flash_map); printk(KERN_NOTICE "Probing for flash chips at 0x00000000:\n"); flash_mtd = do_map_probe("cfi_probe", &soleng_flash_map); if (!flash_mtd) { /* Not there. Try swapping */ printk(KERN_NOTICE "Probing for flash chips at 0x01000000:\n"); soleng_flash_map.phys = 0x01000000; soleng_flash_map.virt = P2SEGADDR(0x01000000); soleng_eprom_map.phys = 0; soleng_eprom_map.virt = P1SEGADDR(0); flash_mtd = do_map_probe("cfi_probe", &soleng_flash_map); if (!flash_mtd) { /* Eep. */ printk(KERN_NOTICE "Flash chips not detected at either possible location.\n"); return -ENXIO; } } printk(KERN_NOTICE "Solution Engine: Flash at 0x%08lx, EPROM at 0x%08lx\n", soleng_flash_map.phys & 0x1fffffff, soleng_eprom_map.phys & 0x1fffffff); flash_mtd->owner = THIS_MODULE; eprom_mtd = do_map_probe("map_rom", &soleng_eprom_map); if (eprom_mtd) { eprom_mtd->owner = THIS_MODULE; mtd_device_register(eprom_mtd, NULL, 0); } mtd_device_parse_register(flash_mtd, probes, NULL, superh_se_partitions, NUM_PARTITIONS); return 0; }
static int __init init_sbc_gxx(void) { iomapadr = ioremap(WINDOW_START, WINDOW_LENGTH); if (!iomapadr) { printk( KERN_ERR"%s: failed to ioremap memory region\n", sbc_gxx_map.name ); return -EIO; } if (!request_region( PAGE_IO, PAGE_IO_SIZE, "SBC-GXx flash")) { printk( KERN_ERR"%s: IO ports 0x%x-0x%x in use\n", sbc_gxx_map.name, PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1 ); iounmap(iomapadr); return -EAGAIN; } #ifdef CONFIG_DEBUG_PRINTK printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n", sbc_gxx_map.name, PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1, WINDOW_START, WINDOW_START+WINDOW_LENGTH-1 ); #else ; #endif /* Probe for chip. */ all_mtd = do_map_probe( "cfi_probe", &sbc_gxx_map ); if( !all_mtd ) { cleanup_sbc_gxx(); return -ENXIO; } all_mtd->owner = THIS_MODULE; /* Create MTD devices for each partition. */ mtd_device_register(all_mtd, partition_info, NUM_PARTITIONS); return 0; }
int sm_register_device(struct mtd_info *mtd, int smartmedia) { struct nand_chip *chip = mtd_to_nand(mtd); struct nand_flash_dev *flash_ids; int ret; chip->options |= NAND_SKIP_BBTSCAN; /* Scan for card properties */ chip->dummy_controller.ops = &sm_controller_ops; flash_ids = smartmedia ? nand_smartmedia_flash_ids : nand_xd_flash_ids; ret = nand_scan_with_ids(chip, 1, flash_ids); if (ret) return ret; ret = mtd_device_register(mtd, NULL, 0); if (ret) nand_cleanup(chip); return ret; }
int efx_mtd_add(struct efx_nic *efx, struct efx_mtd_partition *parts, size_t n_parts, size_t sizeof_part) { struct efx_mtd_partition *part; size_t i; for (i = 0; i < n_parts; i++) { part = (struct efx_mtd_partition *)((char *)parts + i * sizeof_part); part->mtd.writesize = 1; part->mtd.owner = THIS_MODULE; part->mtd.priv = efx; part->mtd.name = part->name; part->mtd._erase = efx_mtd_erase; part->mtd._read = efx->type->mtd_read; part->mtd._write = efx->type->mtd_write; part->mtd._sync = efx_mtd_sync; efx->type->mtd_rename(part); if (mtd_device_register(&part->mtd, NULL, 0)) goto fail; /* Add to list in order - efx_mtd_remove() depends on this */ list_add_tail(&part->node, &efx->mtd_list); } return 0; fail: while (i--) { part = (struct efx_mtd_partition *)((char *)parts + i * sizeof_part); efx_mtd_remove_partition(part); } /* Failure is unlikely here, but probably means we're out of memory */ return -ENOMEM; }
static int efx_mtd_probe_device(struct efx_nic *efx, struct efx_mtd *efx_mtd) { struct efx_mtd_partition *part; efx_mtd->efx = efx; efx_mtd_rename_device(efx_mtd); efx_for_each_partition(part, efx_mtd) { part->mtd.writesize = 1; part->mtd.owner = THIS_MODULE; part->mtd.priv = efx_mtd; part->mtd.name = part->name; part->mtd.erase = efx_mtd_erase; part->mtd.read = efx_mtd->ops->read; part->mtd.write = efx_mtd->ops->write; part->mtd.sync = efx_mtd_sync; if (mtd_device_register(&part->mtd, NULL, 0)) goto fail; }
static int __init uclinux_mtd_init(void) { struct mtd_info *mtd; struct map_info *mapp; mapp = &uclinux_ram_map; if (!mapp->size) mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8)))); mapp->bankwidth = 4; printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n", (int) mapp->phys, (int) mapp->size); mapp->virt = ioremap_nocache(mapp->phys, mapp->size); if (mapp->virt == 0) { printk("uclinux[mtd]: ioremap_nocache() failed\n"); return(-EIO); } simple_map_init(mapp); mtd = do_map_probe("map_ram", mapp); if (!mtd) { printk("uclinux[mtd]: failed to find a mapping?\n"); iounmap(mapp->virt); return(-ENXIO); } mtd->owner = THIS_MODULE; mtd->_point = uclinux_point; mtd->priv = mapp; uclinux_ram_mtdinfo = mtd; mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS); return(0); }
/** * Module/ driver initialization. * * Returns Zero on success */ static int __init flash_init(void) { /* * Read the bootbus region 0 setup to determine the base * address of the flash. */ union cvmx_mio_boot_reg_cfgx region_cfg; region_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(0)); if (region_cfg.s.en) { /* * The bootloader always takes the flash and sets its * address so the entire flash fits below * 0x1fc00000. This way the flash aliases to * 0x1fc00000 for booting. Software can access the * full flash at the true address, while core boot can * access 4MB. */ /* Use this name so old part lines work */ flash_map.name = "phys_mapped_flash"; flash_map.phys = region_cfg.s.base << 16; flash_map.size = 0x1fc00000 - flash_map.phys; flash_map.bankwidth = 1; flash_map.virt = ioremap(flash_map.phys, flash_map.size); pr_notice("Bootbus flash: Setting flash for %luMB flash at " "0x%08llx\n", flash_map.size >> 20, flash_map.phys); simple_map_init(&flash_map); mymtd = do_map_probe("cfi_probe", &flash_map); if (mymtd) { mymtd->owner = THIS_MODULE; nr_parts = parse_mtd_partitions(mymtd, part_probe_types, &parts, 0); mtd_device_register(mymtd, parts, nr_parts); } else { pr_err("Failed to register MTD device for flash\n"); } }