Path: blob/master/arch/mips/cavium-octeon/flash_setup.c
26424 views
/*1* Octeon Bootbus flash setup2*3* This file is subject to the terms and conditions of the GNU General Public4* License. See the file "COPYING" in the main directory of this archive5* for more details.6*7* Copyright (C) 2007, 2008 Cavium Networks8*/9#include <linux/kernel.h>10#include <linux/module.h>11#include <linux/semaphore.h>12#include <linux/mtd/mtd.h>13#include <linux/mtd/map.h>14#include <linux/of.h>15#include <linux/platform_device.h>16#include <linux/mtd/partitions.h>1718#include <asm/octeon/octeon.h>1920static struct map_info flash_map;21static struct mtd_info *mymtd;22static const char *part_probe_types[] = {23"cmdlinepart",24#ifdef CONFIG_MTD_REDBOOT_PARTS25"RedBoot",26#endif27NULL28};2930static map_word octeon_flash_map_read(struct map_info *map, unsigned long ofs)31{32map_word r;3334down(&octeon_bootbus_sem);35r = inline_map_read(map, ofs);36up(&octeon_bootbus_sem);3738return r;39}4041static void octeon_flash_map_write(struct map_info *map, const map_word datum,42unsigned long ofs)43{44down(&octeon_bootbus_sem);45inline_map_write(map, datum, ofs);46up(&octeon_bootbus_sem);47}4849static void octeon_flash_map_copy_from(struct map_info *map, void *to,50unsigned long from, ssize_t len)51{52down(&octeon_bootbus_sem);53inline_map_copy_from(map, to, from, len);54up(&octeon_bootbus_sem);55}5657static void octeon_flash_map_copy_to(struct map_info *map, unsigned long to,58const void *from, ssize_t len)59{60down(&octeon_bootbus_sem);61inline_map_copy_to(map, to, from, len);62up(&octeon_bootbus_sem);63}6465/*66* Module/ driver initialization.67*68* Returns Zero on success69*/70static int octeon_flash_probe(struct platform_device *pdev)71{72union cvmx_mio_boot_reg_cfgx region_cfg;73u32 cs;74int r;75struct device_node *np = pdev->dev.of_node;7677r = of_property_read_u32(np, "reg", &cs);78if (r)79return r;8081/*82* Read the bootbus region 0 setup to determine the base83* address of the flash.84*/85region_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));86if (region_cfg.s.en) {87/*88* The bootloader always takes the flash and sets its89* address so the entire flash fits below90* 0x1fc00000. This way the flash aliases to91* 0x1fc00000 for booting. Software can access the92* full flash at the true address, while core boot can93* access 4MB.94*/95/* Use this name so old part lines work */96flash_map.name = "phys_mapped_flash";97flash_map.phys = region_cfg.s.base << 16;98flash_map.size = 0x1fc00000 - flash_map.phys;99/* 8-bit bus (0 + 1) or 16-bit bus (1 + 1) */100flash_map.bankwidth = region_cfg.s.width + 1;101flash_map.virt = ioremap(flash_map.phys, flash_map.size);102pr_notice("Bootbus flash: Setting flash for %luMB flash at "103"0x%08llx\n", flash_map.size >> 20, flash_map.phys);104WARN_ON(!map_bankwidth_supported(flash_map.bankwidth));105flash_map.read = octeon_flash_map_read;106flash_map.write = octeon_flash_map_write;107flash_map.copy_from = octeon_flash_map_copy_from;108flash_map.copy_to = octeon_flash_map_copy_to;109mymtd = do_map_probe("cfi_probe", &flash_map);110if (mymtd) {111mymtd->owner = THIS_MODULE;112mtd_device_parse_register(mymtd, part_probe_types,113NULL, NULL, 0);114} else {115pr_err("Failed to register MTD device for flash\n");116}117}118return 0;119}120121static const struct of_device_id of_flash_match[] = {122{123.compatible = "cfi-flash",124},125{ },126};127MODULE_DEVICE_TABLE(of, of_flash_match);128129static struct platform_driver of_flash_driver = {130.driver = {131.name = "octeon-of-flash",132.of_match_table = of_flash_match,133},134.probe = octeon_flash_probe,135};136137static int octeon_flash_init(void)138{139return platform_driver_register(&of_flash_driver);140}141late_initcall(octeon_flash_init);142143MODULE_LICENSE("GPL");144145146