11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * MTD driver for the 28F160F3 Flash Memory (non-CFI) on LART. 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Author: Abraham vd Merwe <abraham@2d3d.co.za> 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (c) 2001, 2d3D, Inc. 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This code is free software; you can redistribute it and/or modify 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it under the terms of the GNU General Public License version 2 as 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * published by the Free Software Foundation. 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * References: 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * [1] 3 Volt Fast Boot Block Flash Memory" Intel Datasheet 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * - Order Number: 290644-005 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * - January 2000 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * [2] MTD internal API documentation 20631dd1a885b6d7e9f6f51b4e5b311c2bb04c323cJustin P. Mattock * - http://www.linux-mtd.infradead.org/ 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Limitations: 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Even though this driver is written for 3 Volt Fast Boot 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Block Flash Memory, it is rather specific to LART. With 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Minor modifications, notably the without data/address line 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * mangling and different bus settings, etc. it should be 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * trivial to adapt to other platforms. 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If somebody would sponsor me a different board, I'll 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * adapt the driver (: 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* debugging */ 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds//#define LART_DEBUG 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/kernel.h> 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h> 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/types.h> 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h> 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/errno.h> 424e57b6817880946a3a78d5d8cad1ace363f7e449Tim Schmielau#include <linux/string.h> 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/mtd/mtd.h> 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/mtd/partitions.h> 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef CONFIG_SA1100_LART 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#error This is for LART architecture only 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic char module_name[] = "lart"; 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * These values is specific to 28Fxxxx3 flash memory. 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * See section 2.3.1 in "3 Volt Fast Boot Block Flash Memory" Intel Datasheet 551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_BLOCKSIZE_PARAM (4096 * BUSWIDTH) 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_NUMBLOCKS_16m_PARAM 8 581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_NUMBLOCKS_8m_PARAM 8 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * These values is specific to 28Fxxxx3 flash memory. 621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * See section 2.3.2 in "3 Volt Fast Boot Block Flash Memory" Intel Datasheet 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_BLOCKSIZE_MAIN (32768 * BUSWIDTH) 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_NUMBLOCKS_16m_MAIN 31 661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_NUMBLOCKS_8m_MAIN 15 671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * These values are specific to LART 701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* general */ 731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define BUSWIDTH 4 /* don't change this - a lot of the code _will_ break if you change this */ 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_OFFSET 0xe8000000 /* see linux/arch/arm/mach-sa1100/lart.c */ 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* blob */ 771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NUM_BLOB_BLOCKS FLASH_NUMBLOCKS_16m_PARAM 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define BLOB_START 0x00000000 791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define BLOB_LEN (NUM_BLOB_BLOCKS * FLASH_BLOCKSIZE_PARAM) 801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* kernel */ 821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NUM_KERNEL_BLOCKS 7 831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define KERNEL_START (BLOB_START + BLOB_LEN) 841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define KERNEL_LEN (NUM_KERNEL_BLOCKS * FLASH_BLOCKSIZE_MAIN) 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* initial ramdisk */ 871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NUM_INITRD_BLOCKS 24 881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define INITRD_START (KERNEL_START + KERNEL_LEN) 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define INITRD_LEN (NUM_INITRD_BLOCKS * FLASH_BLOCKSIZE_MAIN) 901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * See section 4.0 in "3 Volt Fast Boot Block Flash Memory" Intel Datasheet 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define READ_ARRAY 0x00FF00FF /* Read Array/Reset */ 951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define READ_ID_CODES 0x00900090 /* Read Identifier Codes */ 961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ERASE_SETUP 0x00200020 /* Block Erase */ 971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ERASE_CONFIRM 0x00D000D0 /* Block Erase and Program Resume */ 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define PGM_SETUP 0x00400040 /* Program */ 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define STATUS_READ 0x00700070 /* Read Status Register */ 1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define STATUS_CLEAR 0x00500050 /* Clear Status Register */ 1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define STATUS_BUSY 0x00800080 /* Write State Machine Status (WSMS) */ 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define STATUS_ERASE_ERR 0x00200020 /* Erase Status (ES) */ 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define STATUS_PGM_ERR 0x00100010 /* Program Status (PS) */ 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * See section 4.2 in "3 Volt Fast Boot Block Flash Memory" Intel Datasheet 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_MANUFACTURER 0x00890089 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_DEVICE_8mbit_TOP 0x88f188f1 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_DEVICE_8mbit_BOTTOM 0x88f288f2 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_DEVICE_16mbit_TOP 0x88f388f3 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_DEVICE_16mbit_BOTTOM 0x88f488f4 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/***************************************************************************************************/ 1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The data line mapping on LART is as follows: 118e5580fbe8a950131b9ccccce0f962811dfb9ef43Thomas Gleixner * 1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * U2 CPU | U3 CPU 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ------------------- 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 0 20 | 0 12 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1 22 | 1 14 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2 19 | 2 11 1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3 17 | 3 9 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 4 24 | 4 0 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 5 26 | 5 2 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 6 31 | 6 7 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 7 29 | 7 5 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 8 21 | 8 13 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 9 23 | 9 15 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 10 18 | 10 10 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 11 16 | 11 8 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 12 25 | 12 1 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 13 27 | 13 3 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 14 30 | 14 6 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 15 28 | 15 4 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Mangle data (x) */ 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DATA_TO_FLASH(x) \ 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ( \ 1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x08009000) >> 11) + \ 1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00002000) >> 10) + \ 1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x04004000) >> 8) + \ 1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000010) >> 4) + \ 1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x91000820) >> 3) + \ 1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x22080080) >> 2) + \ 1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ((x) & 0x40000400) + \ 1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00040040) << 1) + \ 1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00110000) << 4) + \ 1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00220100) << 5) + \ 1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00800208) << 6) + \ 1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00400004) << 9) + \ 1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000001) << 12) + \ 1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000002) << 13) \ 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ) 1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Unmangle data (x) */ 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_TO_DATA(x) \ 1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ( \ 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00010012) << 11) + \ 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000008) << 10) + \ 1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00040040) << 8) + \ 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000001) << 4) + \ 1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x12200104) << 3) + \ 1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x08820020) << 2) + \ 1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ((x) & 0x40000400) + \ 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00080080) >> 1) + \ 1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x01100000) >> 4) + \ 1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x04402000) >> 5) + \ 1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x20008200) >> 6) + \ 1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x80000800) >> 9) + \ 1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00001000) >> 12) + \ 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00004000) >> 13) \ 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ) 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 177e5580fbe8a950131b9ccccce0f962811dfb9ef43Thomas Gleixner/* 1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The address line mapping on LART is as follows: 1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * U3 CPU | U2 CPU 1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ------------------- 1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 0 2 | 0 2 1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1 3 | 1 3 1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2 9 | 2 9 1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3 13 | 3 8 1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 4 8 | 4 7 1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 5 12 | 5 6 1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 6 11 | 6 5 1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 7 10 | 7 4 1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 8 4 | 8 10 1911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 9 5 | 9 11 1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 10 6 | 10 12 1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 11 7 | 11 13 1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * BOOT BLOCK BOUNDARY 1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 12 15 | 12 15 1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 13 14 | 13 14 1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 14 16 | 14 16 200e5580fbe8a950131b9ccccce0f962811dfb9ef43Thomas Gleixner * 2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * MAIN BLOCK BOUNDARY 2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 15 17 | 15 18 2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 16 18 | 16 17 2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 17 20 | 17 20 2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 18 19 | 18 19 2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 19 21 | 19 21 2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * As we can see from above, the addresses aren't mangled across 2101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * block boundaries, so we don't need to worry about address 2111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * translations except for sending/reading commands during 2121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * initialization 2131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Mangle address (x) on chip U2 */ 2161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADDR_TO_FLASH_U2(x) \ 2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ( \ 2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000f00) >> 4) + \ 2191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00042000) << 1) + \ 2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x0009c003) << 2) + \ 2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00021080) << 3) + \ 2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000010) << 4) + \ 2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000040) << 5) + \ 2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000024) << 7) + \ 2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000008) << 10) \ 2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ) 2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Unmangle address (x) on chip U2 */ 2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_U2_TO_ADDR(x) \ 2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ( \ 2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) << 4) & 0x00000f00) + \ 2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 1) & 0x00042000) + \ 2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 2) & 0x0009c003) + \ 2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 3) & 0x00021080) + \ 2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 4) & 0x00000010) + \ 2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 5) & 0x00000040) + \ 2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 7) & 0x00000024) + \ 2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 10) & 0x00000008) \ 2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ) 2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Mangle address (x) on chip U3 */ 2421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ADDR_TO_FLASH_U3(x) \ 2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ( \ 2441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000080) >> 3) + \ 2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000040) >> 1) + \ 2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00052020) << 1) + \ 2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00084f03) << 2) + \ 2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00029010) << 3) + \ 2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000008) << 5) + \ 2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) & 0x00000004) << 7) \ 2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ) 2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Unmangle address (x) on chip U3 */ 2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FLASH_U3_TO_ADDR(x) \ 2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ( \ 2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) << 3) & 0x00000080) + \ 2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) << 1) & 0x00000040) + \ 2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 1) & 0x00052020) + \ 2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 2) & 0x00084f03) + \ 2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 3) & 0x00029010) + \ 2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 5) & 0x00000008) + \ 2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (((x) >> 7) & 0x00000004) \ 2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ) 2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/***************************************************************************************************/ 2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic __u8 read8 (__u32 offset) 2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds volatile __u8 *data = (__u8 *) (FLASH_OFFSET + offset); 2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef LART_DEBUG 271cb53b3b99992b6c548d56cdf47bc710640ee2ee1Harvey Harrison printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.2x\n", __func__, offset, *data); 2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (*data); 2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic __u32 read32 (__u32 offset) 2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset); 2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef LART_DEBUG 280cb53b3b99992b6c548d56cdf47bc710640ee2ee1Harvey Harrison printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.8x\n", __func__, offset, *data); 2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (*data); 2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void write32 (__u32 x,__u32 offset) 2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset); 2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *data = x; 2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef LART_DEBUG 290cb53b3b99992b6c548d56cdf47bc710640ee2ee1Harvey Harrison printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, *data); 2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/***************************************************************************************************/ 2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Probe for 16mbit flash memory on a LART board without doing 2981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * too much damage. Since we need to write 1 dword to memory, 2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * we're f**cked if this happens to be DRAM since we can't 3001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * restore the memory (otherwise we might exit Read Array mode). 3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Returns 1 if we found 16mbit flash memory on LART, 0 otherwise. 3031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int flash_probe (void) 3051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 manufacturer,devtype; 3071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* setup "Read Identifier Codes" mode */ 3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds write32 (DATA_TO_FLASH (READ_ID_CODES),0x00000000); 3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* probe U2. U2/U3 returns the same data since the first 3 3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * address lines is mangled in the same way */ 3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds manufacturer = FLASH_TO_DATA (read32 (ADDR_TO_FLASH_U2 (0x00000000))); 3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds devtype = FLASH_TO_DATA (read32 (ADDR_TO_FLASH_U2 (0x00000001))); 3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* put the flash back into command mode */ 3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds write32 (DATA_TO_FLASH (READ_ARRAY),0x00000000); 3181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3190bdf77f85bd89d5e00d32af0fb7d2dac63ce8ff5Roel Kluin return (manufacturer == FLASH_MANUFACTURER && (devtype == FLASH_DEVICE_16mbit_TOP || devtype == FLASH_DEVICE_16mbit_BOTTOM)); 3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 3231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Erase one block of flash memory at offset ``offset'' which is any 3241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * address within the block which should be erased. 3251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Returns 1 if successful, 0 otherwise. 3271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int erase_block (__u32 offset) 3291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 status; 3311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef LART_DEBUG 333cb53b3b99992b6c548d56cdf47bc710640ee2ee1Harvey Harrison printk (KERN_DEBUG "%s(): 0x%.8x\n", __func__, offset); 3341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 3351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* erase and confirm */ 3371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds write32 (DATA_TO_FLASH (ERASE_SETUP),offset); 3381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds write32 (DATA_TO_FLASH (ERASE_CONFIRM),offset); 3391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* wait for block erase to finish */ 3411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds do 3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 3431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds write32 (DATA_TO_FLASH (STATUS_READ),offset); 3441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds status = FLASH_TO_DATA (read32 (offset)); 3451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while ((~status & STATUS_BUSY) != 0); 3471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* put the flash back into command mode */ 3491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds write32 (DATA_TO_FLASH (READ_ARRAY),offset); 3501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 35125985edcedea6396277003854657b5f3cb31a628Lucas De Marchi /* was the erase successful? */ 3521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((status & STATUS_ERASE_ERR)) 3531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 3541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk (KERN_WARNING "%s: erase error at address 0x%.8x.\n",module_name,offset); 3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (0); 3561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (1); 3591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int flash_erase (struct mtd_info *mtd,struct erase_info *instr) 3621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 addr,len; 3641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i,first; 3651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef LART_DEBUG 367cb53b3b99992b6c548d56cdf47bc710640ee2ee1Harvey Harrison printk (KERN_DEBUG "%s(addr = 0x%.8x, len = %d)\n", __func__, instr->addr, instr->len); 3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * check that both start and end of the requested erase are 3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * aligned with the erasesize at the appropriate addresses. 3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * skip all erase regions which are ended before the start of 3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the requested erase. Actually, to save on the calculations, 3761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * we skip to the first erase region which starts after the 3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * start of the requested erase, and then go back one. 3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i = 0; i < mtd->numeraseregions && instr->addr >= mtd->eraseregions[i].offset; i++) ; 3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i--; 3811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 3831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ok, now i is pointing at the erase region in which this 3841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * erase request starts. Check the start of the requested 3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * erase range is aligned with the erase size which is in 3861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * effect here. 3871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3884c1e6b2ce13b154a4a69cee220c98976f4b784dfRoel Kluin if (i < 0 || (instr->addr & (mtd->eraseregions[i].erasesize - 1))) 3894c1e6b2ce13b154a4a69cee220c98976f4b784dfRoel Kluin return -EINVAL; 3901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Remember the erase region we start on */ 3921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds first = i; 3931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 3951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * next, check that the end of the requested erase is aligned 3961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * with the erase region at that address. 3971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * as before, drop back one to point at the region in which 3991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the address actually falls 4001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 4011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (; i < mtd->numeraseregions && instr->addr + instr->len >= mtd->eraseregions[i].offset; i++) ; 4021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i--; 4031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* is the end aligned on a block boundary? */ 4054c1e6b2ce13b154a4a69cee220c98976f4b784dfRoel Kluin if (i < 0 || ((instr->addr + instr->len) & (mtd->eraseregions[i].erasesize - 1))) 4064c1e6b2ce13b154a4a69cee220c98976f4b784dfRoel Kluin return -EINVAL; 4071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds addr = instr->addr; 4091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len = instr->len; 4101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i = first; 4121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* now erase those blocks */ 4141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (len) 4151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 4161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!erase_block (addr)) 4171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 4181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds instr->state = MTD_ERASE_FAILED; 4191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (-EIO); 4201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds addr += mtd->eraseregions[i].erasesize; 4231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len -= mtd->eraseregions[i].erasesize; 4241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (addr == mtd->eraseregions[i].offset + (mtd->eraseregions[i].erasesize * mtd->eraseregions[i].numblocks)) i++; 4261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds instr->state = MTD_ERASE_DONE; 4291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd_erase_callback(instr); 4301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (0); 4321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 4331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int flash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf) 4351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 4361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef LART_DEBUG 437cb53b3b99992b6c548d56cdf47bc710640ee2ee1Harvey Harrison printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n", __func__, (__u32)from, len); 4381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 4391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* we always read len bytes */ 4411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *retlen = len; 4421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* first, we read bytes until we reach a dword boundary */ 4441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (from & (BUSWIDTH - 1)) 4451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 4461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int gap = BUSWIDTH - (from & (BUSWIDTH - 1)); 4471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (len && gap--) *buf++ = read8 (from++), len--; 4491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* now we read dwords until we reach a non-dword boundary */ 4521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (len >= BUSWIDTH) 4531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 4541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *((__u32 *) buf) = read32 (from); 4551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds buf += BUSWIDTH; 4571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds from += BUSWIDTH; 4581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len -= BUSWIDTH; 4591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* top up the last unaligned bytes */ 4621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (len & (BUSWIDTH - 1)) 4631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (len--) *buf++ = read8 (from++); 4641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (0); 4661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 4671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 4691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Write one dword ``x'' to flash memory at offset ``offset''. ``offset'' 4701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * must be 32 bits, i.e. it must be on a dword boundary. 4711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 4721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Returns 1 if successful, 0 otherwise. 4731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 4741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int write_dword (__u32 offset,__u32 x) 4751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 4761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 status; 4771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef LART_DEBUG 479cb53b3b99992b6c548d56cdf47bc710640ee2ee1Harvey Harrison printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, x); 4801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 4811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* setup writing */ 4831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds write32 (DATA_TO_FLASH (PGM_SETUP),offset); 4841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* write the data */ 4861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds write32 (x,offset); 4871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* wait for the write to finish */ 4891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds do 4901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 4911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds write32 (DATA_TO_FLASH (STATUS_READ),offset); 4921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds status = FLASH_TO_DATA (read32 (offset)); 4931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while ((~status & STATUS_BUSY) != 0); 4951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* put the flash back into command mode */ 4971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds write32 (DATA_TO_FLASH (READ_ARRAY),offset); 4981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 49925985edcedea6396277003854657b5f3cb31a628Lucas De Marchi /* was the write successful? */ 5001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((status & STATUS_PGM_ERR) || read32 (offset) != x) 5011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 5021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk (KERN_WARNING "%s: write error at address 0x%.8x.\n",module_name,offset); 5031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (0); 5041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (1); 5071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen,const u_char *buf) 5101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 5111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u8 tmp[4]; 5121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i,n; 5131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef LART_DEBUG 515cb53b3b99992b6c548d56cdf47bc710640ee2ee1Harvey Harrison printk (KERN_DEBUG "%s(to = 0x%.8x, len = %d)\n", __func__, (__u32)to, len); 5161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 5171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* sanity checks */ 5191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!len) return (0); 5201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* first, we write a 0xFF.... padded byte until we reach a dword boundary */ 5221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (to & (BUSWIDTH - 1)) 5231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 5241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __u32 aligned = to & ~(BUSWIDTH - 1); 5251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int gap = to - aligned; 5261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i = n = 0; 5281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (gap--) tmp[i++] = 0xFF; 5301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (len && i < BUSWIDTH) tmp[i++] = buf[n++], len--; 5311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (i < BUSWIDTH) tmp[i++] = 0xFF; 5321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!write_dword (aligned,*((__u32 *) tmp))) return (-EIO); 5341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds to += n; 5361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds buf += n; 5371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *retlen += n; 5381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* now we write dwords until we reach a non-dword boundary */ 5411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (len >= BUSWIDTH) 5421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 5431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!write_dword (to,*((__u32 *) buf))) return (-EIO); 5441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds to += BUSWIDTH; 5461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds buf += BUSWIDTH; 5471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *retlen += BUSWIDTH; 5481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len -= BUSWIDTH; 5491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* top up the last unaligned bytes, padded with 0xFF.... */ 5521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (len & (BUSWIDTH - 1)) 5531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 5541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i = n = 0; 5551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (len--) tmp[i++] = buf[n++]; 5571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (i < BUSWIDTH) tmp[i++] = 0xFF; 5581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!write_dword (to,*((__u32 *) tmp))) return (-EIO); 5601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *retlen += n; 5621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (0); 5651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/***************************************************************************************************/ 5681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct mtd_info mtd; 5701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct mtd_erase_region_info erase_regions[] = { 5721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* parameter blocks */ 5731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 5741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .offset = 0x00000000, 5751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .erasesize = FLASH_BLOCKSIZE_PARAM, 5761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .numblocks = FLASH_NUMBLOCKS_16m_PARAM, 5771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds }, 5781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* main blocks */ 5791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 5801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .offset = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM, 5811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .erasesize = FLASH_BLOCKSIZE_MAIN, 5821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .numblocks = FLASH_NUMBLOCKS_16m_MAIN, 5831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 5851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct mtd_partition lart_partitions[] = { 5871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* blob */ 5881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 5891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .name = "blob", 5901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .offset = BLOB_START, 5911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .size = BLOB_LEN, 5921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds }, 5931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* kernel */ 5941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 5951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .name = "kernel", 5961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .offset = KERNEL_START, /* MTDPART_OFS_APPEND */ 5971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .size = KERNEL_LEN, 5981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds }, 5991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* initial ramdisk / file system */ 6001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 6011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .name = "file system", 6021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .offset = INITRD_START, /* MTDPART_OFS_APPEND */ 6031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .size = INITRD_LEN, /* MTDPART_SIZ_FULL */ 6041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 6063761a6ddacc83e5a6b4482d98fbf212805381486Dmitry Eremin-Solenikov#define NUM_PARTITIONS ARRAY_SIZE(lart_partitions) 6071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 608e4582ea71cb651e02924fb39c9373a9e737088ceDmitri Vorobievstatic int __init lart_flash_init (void) 6091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int result; 6111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memset (&mtd,0,sizeof (mtd)); 6121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk ("MTD driver for LART. Written by Abraham vd Merwe <abraham@2d3d.co.za>\n"); 6131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk ("%s: Probing for 28F160x3 flash on LART...\n",module_name); 6141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!flash_probe ()) 6151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { 6161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk (KERN_WARNING "%s: Found no LART compatible flash device\n",module_name); 6171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (-ENXIO); 6181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk ("%s: This looks like a LART board to me.\n",module_name); 6201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd.name = module_name; 6211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd.type = MTD_NORFLASH; 622783ed81ff39d3f938a6b2efd09fbad96e41e5c1fArtem B. Bityutskiy mtd.writesize = 1; 623fcc44a07dae0af16e84e93425fc8afe642ddc603Artem Bityutskiy mtd.writebufsize = 4; 6241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd.flags = MTD_CAP_NORFLASH; 6251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd.size = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM + FLASH_BLOCKSIZE_MAIN * FLASH_NUMBLOCKS_16m_MAIN; 6261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd.erasesize = FLASH_BLOCKSIZE_MAIN; 62787d10f3c7954d143e509a2af2bca2a27aeb3114dTobias Klauser mtd.numeraseregions = ARRAY_SIZE(erase_regions); 6281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd.eraseregions = erase_regions; 6293c3c10bba1e4ccb75b41442e45c1a072f6cded19Artem Bityutskiy mtd._erase = flash_erase; 6303c3c10bba1e4ccb75b41442e45c1a072f6cded19Artem Bityutskiy mtd._read = flash_read; 6313c3c10bba1e4ccb75b41442e45c1a072f6cded19Artem Bityutskiy mtd._write = flash_write; 6321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd.owner = THIS_MODULE; 6331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef LART_DEBUG 6351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk (KERN_DEBUG 6361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "mtd.name = %s\n" 6371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "mtd.size = 0x%.8x (%uM)\n" 6381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "mtd.erasesize = 0x%.8x (%uK)\n" 6391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "mtd.numeraseregions = %d\n", 6401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd.name, 6411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd.size,mtd.size / (1024*1024), 6421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd.erasesize,mtd.erasesize / 1024, 6431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mtd.numeraseregions); 6441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (mtd.numeraseregions) 6461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (result = 0; result < mtd.numeraseregions; result++) 6471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk (KERN_DEBUG 6481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "\n\n" 6491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "mtd.eraseregions[%d].offset = 0x%.8x\n" 6501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "mtd.eraseregions[%d].erasesize = 0x%.8x (%uK)\n" 6511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "mtd.eraseregions[%d].numblocks = %d\n", 6521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds result,mtd.eraseregions[result].offset, 6531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds result,mtd.eraseregions[result].erasesize,mtd.eraseregions[result].erasesize / 1024, 6541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds result,mtd.eraseregions[result].numblocks); 6551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 65687d10f3c7954d143e509a2af2bca2a27aeb3114dTobias Klauser printk ("\npartitions = %d\n", ARRAY_SIZE(lart_partitions)); 6571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 65887d10f3c7954d143e509a2af2bca2a27aeb3114dTobias Klauser for (result = 0; result < ARRAY_SIZE(lart_partitions); result++) 6591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk (KERN_DEBUG 6601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "\n\n" 6611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "lart_partitions[%d].name = %s\n" 6621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "lart_partitions[%d].offset = 0x%.8x\n" 6631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "lart_partitions[%d].size = 0x%.8x (%uK)\n", 6641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds result,lart_partitions[result].name, 6651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds result,lart_partitions[result].offset, 6661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds result,lart_partitions[result].size,lart_partitions[result].size / 1024); 6671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 6681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 669ee0e87b174bb41f0310cf089262bf5dd8f95a212Jamie Iles result = mtd_device_register(&mtd, lart_partitions, 670ee0e87b174bb41f0310cf089262bf5dd8f95a212Jamie Iles ARRAY_SIZE(lart_partitions)); 6711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (result); 6731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 675e4582ea71cb651e02924fb39c9373a9e737088ceDmitri Vorobievstatic void __exit lart_flash_exit (void) 6761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 677ee0e87b174bb41f0310cf089262bf5dd8f95a212Jamie Iles mtd_device_unregister(&mtd); 6781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_init (lart_flash_init); 6811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_exit (lart_flash_exit); 6821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL"); 6841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_AUTHOR("Abraham vd Merwe <abraham@2d3d.co.za>"); 6851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_DESCRIPTION("MTD driver for Intel 28F160F3 on LART board"); 686