From patchwork Sun Mar 4 22:00:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 144543 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id C15FDB6EEE for ; Mon, 5 Mar 2012 09:01:27 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DFCF228087; Sun, 4 Mar 2012 23:01:25 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hfCAUxYptCTB; Sun, 4 Mar 2012 23:01:25 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 75E2F28080; Sun, 4 Mar 2012 23:01:18 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3F48028080 for ; Sun, 4 Mar 2012 23:01:12 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id skQkLU59VXv4 for ; Sun, 4 Mar 2012 23:01:10 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by theia.denx.de (Postfix) with ESMTPS id 4CB432807F for ; Sun, 4 Mar 2012 23:01:08 +0100 (CET) Received: from frontend1.mail.m-online.net (frontend1.mail.intern.m-online.net [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3V1J9H4xY9z3hhYG; Sun, 4 Mar 2012 23:01:07 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.8.164]) by mail.m-online.net (Postfix) with ESMTP id 3V1J9H6jsrz4KK4G; Sun, 4 Mar 2012 23:01:07 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from smtp-auth.mnet-online.de ([192.168.8.180]) by localhost (dynscan1.mail.m-online.net [192.168.8.164]) (amavisd-new, port 10024) with ESMTP id blH35rTq2Ckq; Sun, 4 Mar 2012 23:01:06 +0100 (CET) X-Auth-Info: J7daGQa1zgDRTAbQoXHjXEnCEwHGGqWGEVeKDb450dE= Received: from mashiro.lan (host-82-135-33-74.customer.m-online.net [82.135.33.74]) by smtp-auth.mnet-online.de (Postfix) with ESMTPA; Sun, 4 Mar 2012 23:01:05 +0100 (CET) From: Marek Vasut To: u-boot@lists.denx.de Date: Sun, 4 Mar 2012 23:00:57 +0100 Message-Id: <1330898457-12073-1-git-send-email-marex@denx.de> X-Mailer: git-send-email 1.7.9 Cc: Marek Vasut , unsik Kim Subject: [U-Boot] [PATCH] Block: Remove MG DISK support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This driver is unused and obsolete. Signed-off-by: Marek Vasut Cc: Wolfgang Denk Cc: unsik Kim --- common/cmd_mgdisk.c | 71 ------ common/env_mgdisk.c | 76 ------ doc/README.mflash | 94 ------- drivers/block/mg_disk.c | 586 ------------------------------------------- drivers/block/mg_disk_prv.h | 144 ----------- include/mg_disk.h | 51 ---- 6 files changed, 0 insertions(+), 1022 deletions(-) delete mode 100644 common/cmd_mgdisk.c delete mode 100644 common/env_mgdisk.c delete mode 100644 doc/README.mflash delete mode 100644 drivers/block/mg_disk.c delete mode 100644 drivers/block/mg_disk_prv.h delete mode 100644 include/mg_disk.h diff --git a/common/cmd_mgdisk.c b/common/cmd_mgdisk.c deleted file mode 100644 index d99af2d..0000000 --- a/common/cmd_mgdisk.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * (C) Copyright 2009 mGine co. - * unsik Kim - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include -#include - -#include - -int do_mg_disk_cmd (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - u32 from, to, size; - - switch (argc) { - case 2: - if (!strcmp(argv[1], "init")) - mg_disk_init(); - else - return 1; - break; - case 5: - from = simple_strtoul(argv[2], NULL, 0); - to = simple_strtoul(argv[3], NULL, 0); - size = simple_strtoul(argv[4], NULL, 0); - - if (!strcmp(argv[1], "read")) - mg_disk_read(from, (u8 *)to, size); - else if (!strcmp(argv[1], "write")) - mg_disk_write(to, (u8 *)from, size); - else if (!strcmp(argv[1], "readsec")) - mg_disk_read_sects((void *)to, from, size); - else if (!strcmp(argv[1], "writesec")) - mg_disk_write_sects((void *)from, to, size); - else - return 1; - break; - default: - return cmd_usage(cmdtp); - } - return 0; -} - -U_BOOT_CMD( - mgd, 5, 0, do_mg_disk_cmd, - "mgine m[g]flash command\n", - ": mgine mflash IO mode (disk) command\n" - " - initialize : mgd init\n" - " - random read : mgd read [from] [to] [size]\n" - " - random write : mgd write [from] [to] [size]\n" - " - sector read : mgd readsec [sector] [to] [counts]\n" - " - sector write : mgd writesec [from] [sector] [counts]" -); diff --git a/common/env_mgdisk.c b/common/env_mgdisk.c deleted file mode 100644 index d00e141..0000000 --- a/common/env_mgdisk.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * (C) Copyright 2009 mGine co. - * unsik Kim - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include - -char *env_name_spec = "MG_DISK"; - -env_t *env_ptr; - -DECLARE_GLOBAL_DATA_PTR; - -void env_relocate_spec(void) -{ - char buf[CONFIG_ENV_SIZE]; - unsigned int err, rc; - - err = mg_disk_init(); - if (err) { - set_default_env("!mg_disk_init error"); - return; - } - - err = mg_disk_read(CONFIG_ENV_ADDR, buf, CONFIG_ENV_SIZE); - if (err) { - set_default_env("!mg_disk_read error"); - return; - } - - env_import(buf, 1); -} - -int saveenv(void) -{ - unsigned int err; - - env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE); - err = mg_disk_write(CONFIG_ENV_ADDR, (u_char *)env_ptr, - CONFIG_ENV_SIZE); - if (err) - puts("*** Warning - mg_disk_write error\n\n"); - - return err; -} - -int env_init(void) -{ - /* use default */ - gd->env_addr = (ulong)&default_environment[0]; - gd->env_valid = 1; - - return 0; -} diff --git a/doc/README.mflash b/doc/README.mflash deleted file mode 100644 index 50133b4..0000000 --- a/doc/README.mflash +++ /dev/null @@ -1,94 +0,0 @@ - -This document describes m[g]flash support in u-boot. - -Contents - 1. Overview - 2. Porting mflash driver - 3. Mflash command - 4. Misc. - -1. Overview -Mflash and gflash are embedded flash drive. The only difference is mflash is -MCP(Multi Chip Package) device. These two device operate exactly same way. -So the rest mflash repersents mflash and gflash altogether. - -2. Porting mflash driver - -2-1. Board configuration -* Mflash driver support -#define CONFIG_CMD_MG_DISK -#define CONFIG_LIBATA - -* Environment variable support (optional) -#define CONFIG_ENV_IS_IN_MG_DISK -Also CONFIG_ENV_ADDR and CONFIG_ENV_SIZE should be defined. -CONFIG_ENV_ADDR is byte offset starting from 0. - -Following example sets environment variable location to 0x80000 (1024'th -sector) and size of 0x400 (1024 byte) -#define CONFIG_ENV_ADDR 0x80000 -#define CONFIG_ENV_SIZE 0x400 - -* Reserved size config (optional) -If you want to use some reserved area for bootloader, environment variable or -whatever, use CONFIG_MG_DISK_RES. The unit is KB. Mflash's block operation -method use this value as start offset. So any u-boot's partition table parser -and file system command work consistently. You can access this area by using -mflash command. - -Following example sets 10MB of reserved area. -#define CONFIG_MG_DISK_RES 10240 - -2-2. Porting mg_get_drv_data function -Mflash is active device and need some gpio control for proper operation. -This board dependency resolved by using mg_get_drv_data function. -Port this function at your board init file. See include/mg_disk.h - -Here is some pseudo example. - -static void custom_hdrst_pin (u8 level) -{ - if (level) - /* set hard reset pin to high */ - else - /* set hard reset pin to low */ -} - -static void custom_ctrl_pin_init (void) -{ - /* Set hard reset, write protect, deep power down pins - * to gpio. - * Set these pins to output high - */ -} - -struct mg_drv_data* mg_get_drv_data (void) -{ - static struct mg_drv_data prv; - - prv.base = /* base address of mflash */ - prv.mg_ctrl_pin_init = custom_ctrl_pin_init; - prv.mg_hdrst_pin = custom_hdrst_pin; - - return &prv; -} - -3. Mflash command - -* initialize : mgd init -* random read : mgd read [from] [to] [size] - ex) read 256 bytes from 0x300000 of mflash to 0xA0100000 of host memory - mgd read 0x300000 0xA0100000 256 -* random write : mgd write [from] [to] [size] -* sector read : mgd readsec [sector] [to] [count] - ex) read 10 sectors starts from 400 sector to 0xA0100000 - mgd readsec 400 0xA0100000 10 -* sector write : mgd writesec [from] [sector] [count] - -4. Misc. -Mflash's device interface name for block driver is "mgd". -Here is ext2 file system access example. - - mgd init - ext2ls mgd 0:1 /boot - ext2load mgd 0:1 0xa0010000 /boot/uImage 1954156 diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c deleted file mode 100644 index 4407006..0000000 --- a/drivers/block/mg_disk.c +++ /dev/null @@ -1,586 +0,0 @@ -/* - * (C) Copyright 2009 mGine co. - * unsik Kim - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include -#include "mg_disk_prv.h" - -#ifndef CONFIG_MG_DISK_RES -#define CONFIG_MG_DISK_RES 0 -#endif - -#define MG_RES_SEC ((CONFIG_MG_DISK_RES) << 1) - -static struct mg_host host; - -static inline u32 mg_base(void) -{ - return host.drv_data->base; -} - -static block_dev_desc_t mg_disk_dev = { - .if_type = IF_TYPE_ATAPI, - .part_type = PART_TYPE_UNKNOWN, - .type = DEV_TYPE_HARDDISK, - .blksz = MG_SECTOR_SIZE, - .priv = &host }; - -static void mg_dump_status (const char *msg, unsigned int stat, unsigned err) -{ - char *name = MG_DEV_NAME; - - printf("%s: %s: status=0x%02x { ", name, msg, stat & 0xff); - if (stat & MG_REG_STATUS_BIT_BUSY) - printf("Busy "); - if (stat & MG_REG_STATUS_BIT_READY) - printf("DriveReady "); - if (stat & MG_REG_STATUS_BIT_WRITE_FAULT) - printf("WriteFault "); - if (stat & MG_REG_STATUS_BIT_SEEK_DONE) - printf("SeekComplete "); - if (stat & MG_REG_STATUS_BIT_DATA_REQ) - printf("DataRequest "); - if (stat & MG_REG_STATUS_BIT_CORRECTED_ERROR) - printf("CorrectedError "); - if (stat & MG_REG_STATUS_BIT_ERROR) - printf("Error "); - printf("}\n"); - - if ((stat & MG_REG_STATUS_BIT_ERROR)) { - printf("%s: %s: error=0x%02x { ", name, msg, err & 0xff); - if (err & MG_REG_ERR_BBK) - printf("BadSector "); - if (err & MG_REG_ERR_UNC) - printf("UncorrectableError "); - if (err & MG_REG_ERR_IDNF) - printf("SectorIdNotFound "); - if (err & MG_REG_ERR_ABRT) - printf("DriveStatusError "); - if (err & MG_REG_ERR_AMNF) - printf("AddrMarkNotFound "); - printf("}\n"); - } -} - -static unsigned int mg_wait (u32 expect, u32 msec) -{ - u8 status; - u32 from, cur, err; - - err = MG_ERR_NONE; -#ifdef CONFIG_SYS_LOW_RES_TIMER - reset_timer(); -#endif - from = get_timer(0); - - status = readb(mg_base() + MG_REG_STATUS); - do { - cur = get_timer(from); - if (status & MG_REG_STATUS_BIT_BUSY) { - if (expect == MG_REG_STATUS_BIT_BUSY) - break; - } else { - /* Check the error condition! */ - if (status & MG_REG_STATUS_BIT_ERROR) { - err = readb(mg_base() + MG_REG_ERROR); - mg_dump_status("mg_wait", status, err); - break; - } - - if (expect == MG_STAT_READY) - if (MG_READY_OK(status)) - break; - - if (expect == MG_REG_STATUS_BIT_DATA_REQ) - if (status & MG_REG_STATUS_BIT_DATA_REQ) - break; - } - status = readb(mg_base() + MG_REG_STATUS); - } while (cur < msec); - - if (cur >= msec) - err = MG_ERR_TIMEOUT; - - return err; -} - -static int mg_get_disk_id (void) -{ - u16 id[(MG_SECTOR_SIZE / sizeof(u16))]; - hd_driveid_t *iop = (hd_driveid_t *)id; - u32 i, err, res; - - writeb(MG_CMD_ID, mg_base() + MG_REG_COMMAND); - err = mg_wait(MG_REG_STATUS_BIT_DATA_REQ, 3000); - if (err) - return err; - - for(i = 0; i < (MG_SECTOR_SIZE / sizeof(u16)); i++) - id[i] = readw(mg_base() + MG_BUFF_OFFSET + i * 2); - - writeb(MG_CMD_RD_CONF, mg_base() + MG_REG_COMMAND); - err = mg_wait(MG_STAT_READY, 3000); - if (err) - return err; - - ata_swap_buf_le16(id, MG_SECTOR_SIZE / sizeof(u16)); - - if((iop->field_valid & 1) == 0) - return MG_ERR_TRANSLATION; - - ata_id_c_string(id, (unsigned char *)mg_disk_dev.revision, - ATA_ID_FW_REV, sizeof(mg_disk_dev.revision)); - ata_id_c_string(id, (unsigned char *)mg_disk_dev.vendor, - ATA_ID_PROD, sizeof(mg_disk_dev.vendor)); - ata_id_c_string(id, (unsigned char *)mg_disk_dev.product, - ATA_ID_SERNO, sizeof(mg_disk_dev.product)); - -#ifdef __BIG_ENDIAN - iop->lba_capacity = (iop->lba_capacity << 16) | - (iop->lba_capacity >> 16); -#endif /* __BIG_ENDIAN */ - - if (MG_RES_SEC) { - MG_DBG("MG_RES_SEC=%d\n", MG_RES_SEC); - iop->cyls = (iop->lba_capacity - MG_RES_SEC) / - iop->sectors / iop->heads; - res = iop->lba_capacity - - iop->cyls * iop->heads * iop->sectors; - iop->lba_capacity -= res; - printf("mg_disk: %d sectors reserved\n", res); - } - - mg_disk_dev.lba = iop->lba_capacity; - return MG_ERR_NONE; -} - -static int mg_disk_reset (void) -{ - struct mg_drv_data *prv_data = host.drv_data; - s32 err; - u8 init_status; - - /* hdd rst low */ - prv_data->mg_hdrst_pin(0); - err = mg_wait(MG_REG_STATUS_BIT_BUSY, 300); - if(err) - return err; - - /* hdd rst high */ - prv_data->mg_hdrst_pin(1); - err = mg_wait(MG_STAT_READY, 3000); - if(err) - return err; - - /* soft reset on */ - writeb(MG_REG_CTRL_RESET | MG_REG_CTRL_INTR_DISABLE, - mg_base() + MG_REG_DRV_CTRL); - err = mg_wait(MG_REG_STATUS_BIT_BUSY, 3000); - if(err) - return err; - - /* soft reset off */ - writeb(MG_REG_CTRL_INTR_DISABLE, mg_base() + MG_REG_DRV_CTRL); - err = mg_wait(MG_STAT_READY, 3000); - if(err) - return err; - - init_status = readb(mg_base() + MG_REG_STATUS) & 0xf; - - if (init_status == 0xf) - return MG_ERR_INIT_STAT; - - return err; -} - - -static unsigned int mg_out(unsigned int sect_num, - unsigned int sect_cnt, - unsigned int cmd) -{ - u32 err = MG_ERR_NONE; - - err = mg_wait(MG_STAT_READY, 3000); - if (err) - return err; - - writeb((u8)sect_cnt, mg_base() + MG_REG_SECT_CNT); - writeb((u8)sect_num, mg_base() + MG_REG_SECT_NUM); - writeb((u8)(sect_num >> 8), mg_base() + MG_REG_CYL_LOW); - writeb((u8)(sect_num >> 16), mg_base() + MG_REG_CYL_HIGH); - writeb((u8)((sect_num >> 24) | MG_REG_HEAD_LBA_MODE), - mg_base() + MG_REG_DRV_HEAD); - writeb(cmd, mg_base() + MG_REG_COMMAND); - - return err; -} - -static unsigned int mg_do_read_sects(void *buff, u32 sect_num, u32 sect_cnt) -{ - u32 i, j, err; - u8 *buff_ptr = buff; - union mg_uniwb uniwb; - - err = mg_out(sect_num, sect_cnt, MG_CMD_RD); - if (err) - return err; - - for (i = 0; i < sect_cnt; i++) { - err = mg_wait(MG_REG_STATUS_BIT_DATA_REQ, 3000); - if (err) - return err; - - if ((u32)buff_ptr & 1) { - for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) { - uniwb.w = readw(mg_base() + MG_BUFF_OFFSET - + (j << 1)); - *buff_ptr++ = uniwb.b[0]; - *buff_ptr++ = uniwb.b[1]; - } - } else { - for(j = 0; j < MG_SECTOR_SIZE >> 1; j++) { - *(u16 *)buff_ptr = readw(mg_base() + - MG_BUFF_OFFSET + (j << 1)); - buff_ptr += 2; - } - } - writeb(MG_CMD_RD_CONF, mg_base() + MG_REG_COMMAND); - - MG_DBG("%u (0x%8.8x) sector read", sect_num + i, - (sect_num + i) * MG_SECTOR_SIZE); - } - - return err; -} - -unsigned int mg_disk_read_sects(void *buff, u32 sect_num, u32 sect_cnt) -{ - u32 quotient, residue, i, err; - u8 *buff_ptr = buff; - - quotient = sect_cnt >> 8; - residue = sect_cnt % 256; - - for (i = 0; i < quotient; i++) { - MG_DBG("sect num : %u buff : 0x%8.8x", sect_num, (u32)buff_ptr); - err = mg_do_read_sects(buff_ptr, sect_num, 256); - if (err) - return err; - sect_num += 256; - buff_ptr += 256 * MG_SECTOR_SIZE; - } - - if (residue) { - MG_DBG("sect num : %u buff : %8.8x", sect_num, (u32)buff_ptr); - err = mg_do_read_sects(buff_ptr, sect_num, residue); - } - - return err; -} - -unsigned long mg_block_read (int dev, unsigned long start, - lbaint_t blkcnt, void *buffer) -{ - start += MG_RES_SEC; - if (! mg_disk_read_sects(buffer, start, blkcnt)) - return blkcnt; - else - return 0; -} - -unsigned int mg_disk_read (u32 addr, u8 *buff, u32 len) -{ - u8 *sect_buff, *buff_ptr = buff; - u32 cur_addr, next_sec_addr, end_addr, cnt, sect_num; - u32 err = MG_ERR_NONE; - - /* TODO : sanity chk */ - cnt = 0; - cur_addr = addr; - end_addr = addr + len; - - sect_buff = malloc(MG_SECTOR_SIZE); - - if (cur_addr & MG_SECTOR_SIZE_MASK) { - next_sec_addr = (cur_addr + MG_SECTOR_SIZE) & - ~MG_SECTOR_SIZE_MASK; - sect_num = cur_addr >> MG_SECTOR_SIZE_SHIFT; - err = mg_disk_read_sects(sect_buff, sect_num, 1); - if (err) - goto mg_read_exit; - - if (end_addr < next_sec_addr) { - memcpy(buff_ptr, - sect_buff + (cur_addr & MG_SECTOR_SIZE_MASK), - end_addr - cur_addr); - MG_DBG("copies %u byte from sector offset 0x%8.8x", - end_addr - cur_addr, cur_addr); - cur_addr = end_addr; - } else { - memcpy(buff_ptr, - sect_buff + (cur_addr & MG_SECTOR_SIZE_MASK), - next_sec_addr - cur_addr); - MG_DBG("copies %u byte from sector offset 0x%8.8x", - next_sec_addr - cur_addr, cur_addr); - buff_ptr += (next_sec_addr - cur_addr); - cur_addr = next_sec_addr; - } - } - - if (cur_addr < end_addr) { - sect_num = cur_addr >> MG_SECTOR_SIZE_SHIFT; - cnt = ((end_addr & ~MG_SECTOR_SIZE_MASK) - cur_addr) >> - MG_SECTOR_SIZE_SHIFT; - - if (cnt) - err = mg_disk_read_sects(buff_ptr, sect_num, cnt); - if (err) - goto mg_read_exit; - - buff_ptr += cnt * MG_SECTOR_SIZE; - cur_addr += cnt * MG_SECTOR_SIZE; - - if (cur_addr < end_addr) { - sect_num = cur_addr >> MG_SECTOR_SIZE_SHIFT; - err = mg_disk_read_sects(sect_buff, sect_num, 1); - if (err) - goto mg_read_exit; - memcpy(buff_ptr, sect_buff, end_addr - cur_addr); - MG_DBG("copies %u byte", end_addr - cur_addr); - } - } - -mg_read_exit: - free(sect_buff); - - return err; -} -static int mg_do_write_sects(void *buff, u32 sect_num, u32 sect_cnt) -{ - u32 i, j, err; - u8 *buff_ptr = buff; - union mg_uniwb uniwb; - - err = mg_out(sect_num, sect_cnt, MG_CMD_WR); - if (err) - return err; - - for (i = 0; i < sect_cnt; i++) { - err = mg_wait(MG_REG_STATUS_BIT_DATA_REQ, 3000); - if (err) - return err; - - if ((u32)buff_ptr & 1) { - uniwb.b[0] = *buff_ptr++; - uniwb.b[1] = *buff_ptr++; - writew(uniwb.w, mg_base() + MG_BUFF_OFFSET + (j << 1)); - } else { - for(j = 0; j < MG_SECTOR_SIZE >> 1; j++) { - writew(*(u16 *)buff_ptr, - mg_base() + MG_BUFF_OFFSET + - (j << 1)); - buff_ptr += 2; - } - } - writeb(MG_CMD_WR_CONF, mg_base() + MG_REG_COMMAND); - - MG_DBG("%u (0x%8.8x) sector write", - sect_num + i, (sect_num + i) * MG_SECTOR_SIZE); - } - - return err; -} - -unsigned int mg_disk_write_sects(void *buff, u32 sect_num, u32 sect_cnt) -{ - u32 quotient, residue, i; - u32 err = MG_ERR_NONE; - u8 *buff_ptr = buff; - - quotient = sect_cnt >> 8; - residue = sect_cnt % 256; - - for (i = 0; i < quotient; i++) { - MG_DBG("sect num : %u buff : %8.8x", sect_num, (u32)buff_ptr); - err = mg_do_write_sects(buff_ptr, sect_num, 256); - if (err) - return err; - sect_num += 256; - buff_ptr += 256 * MG_SECTOR_SIZE; - } - - if (residue) { - MG_DBG("sect num : %u buff : %8.8x", sect_num, (u32)buff_ptr); - err = mg_do_write_sects(buff_ptr, sect_num, residue); - } - - return err; -} - -unsigned long mg_block_write (int dev, unsigned long start, - lbaint_t blkcnt, const void *buffer) -{ - start += MG_RES_SEC; - if (!mg_disk_write_sects((void *)buffer, start, blkcnt)) - return blkcnt; - else - return 0; -} - -unsigned int mg_disk_write(u32 addr, u8 *buff, u32 len) -{ - u8 *sect_buff, *buff_ptr = buff; - u32 cur_addr, next_sec_addr, end_addr, cnt, sect_num; - u32 err = MG_ERR_NONE; - - /* TODO : sanity chk */ - cnt = 0; - cur_addr = addr; - end_addr = addr + len; - - sect_buff = malloc(MG_SECTOR_SIZE); - - if (cur_addr & MG_SECTOR_SIZE_MASK) { - - next_sec_addr = (cur_addr + MG_SECTOR_SIZE) & - ~MG_SECTOR_SIZE_MASK; - sect_num = cur_addr >> MG_SECTOR_SIZE_SHIFT; - err = mg_disk_read_sects(sect_buff, sect_num, 1); - if (err) - goto mg_write_exit; - - if (end_addr < next_sec_addr) { - memcpy(sect_buff + (cur_addr & MG_SECTOR_SIZE_MASK), - buff_ptr, end_addr - cur_addr); - MG_DBG("copies %u byte to sector offset 0x%8.8x", - end_addr - cur_addr, cur_addr); - cur_addr = end_addr; - } else { - memcpy(sect_buff + (cur_addr & MG_SECTOR_SIZE_MASK), - buff_ptr, next_sec_addr - cur_addr); - MG_DBG("copies %u byte to sector offset 0x%8.8x", - next_sec_addr - cur_addr, cur_addr); - buff_ptr += (next_sec_addr - cur_addr); - cur_addr = next_sec_addr; - } - - err = mg_disk_write_sects(sect_buff, sect_num, 1); - if (err) - goto mg_write_exit; - } - - if (cur_addr < end_addr) { - - sect_num = cur_addr >> MG_SECTOR_SIZE_SHIFT; - cnt = ((end_addr & ~MG_SECTOR_SIZE_MASK) - cur_addr) >> - MG_SECTOR_SIZE_SHIFT; - - if (cnt) - err = mg_disk_write_sects(buff_ptr, sect_num, cnt); - if (err) - goto mg_write_exit; - - buff_ptr += cnt * MG_SECTOR_SIZE; - cur_addr += cnt * MG_SECTOR_SIZE; - - if (cur_addr < end_addr) { - sect_num = cur_addr >> MG_SECTOR_SIZE_SHIFT; - err = mg_disk_read_sects(sect_buff, sect_num, 1); - if (err) - goto mg_write_exit; - memcpy(sect_buff, buff_ptr, end_addr - cur_addr); - MG_DBG("copies %u byte", end_addr - cur_addr); - err = mg_disk_write_sects(sect_buff, sect_num, 1); - } - - } - -mg_write_exit: - free(sect_buff); - - return err; -} - -#ifdef CONFIG_PARTITIONS -block_dev_desc_t *mg_disk_get_dev(int dev) -{ - return ((block_dev_desc_t *) & mg_disk_dev); -} -#endif - -/* must override this function */ -struct mg_drv_data * __attribute__((weak)) mg_get_drv_data (void) -{ - puts ("### WARNING ### port mg_get_drv_data function\n"); - return NULL; -} - -unsigned int mg_disk_init (void) -{ - struct mg_drv_data *prv_data; - u32 err = MG_ERR_NONE; - - prv_data = mg_get_drv_data(); - if (! prv_data) { - printf("%s:%d fail (no driver_data)\n", __func__, __LINE__); - err = MG_ERR_NO_DRV_DATA; - return err; - } - - ((struct mg_host *)mg_disk_dev.priv)->drv_data = prv_data; - - /* init ctrl pin */ - if (prv_data->mg_ctrl_pin_init) - prv_data->mg_ctrl_pin_init(); - - if (! prv_data->mg_hdrst_pin) { - err = MG_ERR_CTRL_RST; - return err; - } - - /* disk reset */ - err = mg_disk_reset(); - if (err) { - printf("%s:%d fail (err code : %d)\n", __func__, __LINE__, err); - return err; - } - - /* get disk id */ - err = mg_get_disk_id(); - if (err) { - printf("%s:%d fail (err code : %d)\n", __func__, __LINE__, err); - return err; - } - - mg_disk_dev.block_read = mg_block_read; - mg_disk_dev.block_write = mg_block_write; - - init_part(&mg_disk_dev); - - dev_print(&mg_disk_dev); - - return err; -} diff --git a/drivers/block/mg_disk_prv.h b/drivers/block/mg_disk_prv.h deleted file mode 100644 index 43e90ea..0000000 --- a/drivers/block/mg_disk_prv.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * (C) Copyright 2009 mGine co. - * unsik Kim - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#ifndef __MG_DISK_PRV_H__ -#define __MG_DISK_PRV_H__ - -#include - -/* name for block device */ -#define MG_DISK_NAME "mgd" -/* name for platform device */ -#define MG_DEV_NAME "mg_disk" - -#define MG_DISK_MAJ 240 -#define MG_DISK_MAX_PART 16 -#define MG_SECTOR_SIZE 512 -#define MG_SECTOR_SIZE_MASK (512 - 1) -#define MG_SECTOR_SIZE_SHIFT (9) -#define MG_MAX_SECTS 256 - -/* Register offsets */ -#define MG_BUFF_OFFSET 0x8000 -#define MG_STORAGE_BUFFER_SIZE 0x200 -#define MG_REG_OFFSET 0xC000 -#define MG_REG_FEATURE (MG_REG_OFFSET + 2) /* write case */ -#define MG_REG_ERROR (MG_REG_OFFSET + 2) /* read case */ -#define MG_REG_SECT_CNT (MG_REG_OFFSET + 4) -#define MG_REG_SECT_NUM (MG_REG_OFFSET + 6) -#define MG_REG_CYL_LOW (MG_REG_OFFSET + 8) -#define MG_REG_CYL_HIGH (MG_REG_OFFSET + 0xA) -#define MG_REG_DRV_HEAD (MG_REG_OFFSET + 0xC) -#define MG_REG_COMMAND (MG_REG_OFFSET + 0xE) /* write case */ -#define MG_REG_STATUS (MG_REG_OFFSET + 0xE) /* read case */ -#define MG_REG_DRV_CTRL (MG_REG_OFFSET + 0x10) -#define MG_REG_BURST_CTRL (MG_REG_OFFSET + 0x12) - -/* "Drive Select/Head Register" bit values */ -#define MG_REG_HEAD_MUST_BE_ON 0xA0 /* These 2 bits are always on */ -#define MG_REG_HEAD_DRIVE_MASTER (0x00 | MG_REG_HEAD_MUST_BE_ON) -#define MG_REG_HEAD_DRIVE_SLAVE (0x10 | MG_REG_HEAD_MUST_BE_ON) -#define MG_REG_HEAD_LBA_MODE (0x40 | MG_REG_HEAD_MUST_BE_ON) - - -/* "Device Control Register" bit values */ -#define MG_REG_CTRL_INTR_ENABLE 0x0 -#define MG_REG_CTRL_INTR_DISABLE (0x1 << 1) -#define MG_REG_CTRL_RESET (0x1 << 2) -#define MG_REG_CTRL_INTR_POLA_ACTIVE_HIGH 0x0 -#define MG_REG_CTRL_INTR_POLA_ACTIVE_LOW (0x1 << 4) -#define MG_REG_CTRL_DPD_POLA_ACTIVE_LOW 0x0 -#define MG_REG_CTRL_DPD_POLA_ACTIVE_HIGH (0x1 << 5) -#define MG_REG_CTRL_DPD_DISABLE 0x0 -#define MG_REG_CTRL_DPD_ENABLE (0x1 << 6) - -/* Status register bit */ - /* error bit in status register */ -#define MG_REG_STATUS_BIT_ERROR 0x01 - /* corrected error in status register */ -#define MG_REG_STATUS_BIT_CORRECTED_ERROR 0x04 - /* data request bit in status register */ -#define MG_REG_STATUS_BIT_DATA_REQ 0x08 - /* DSC - Drive Seek Complete */ -#define MG_REG_STATUS_BIT_SEEK_DONE 0x10 - /* DWF - Drive Write Fault */ -#define MG_REG_STATUS_BIT_WRITE_FAULT 0x20 -#define MG_REG_STATUS_BIT_READY 0x40 -#define MG_REG_STATUS_BIT_BUSY 0x80 - -/* handy status */ -#define MG_STAT_READY (MG_REG_STATUS_BIT_READY | MG_REG_STATUS_BIT_SEEK_DONE) -#define MG_READY_OK(s) (((s) & (MG_STAT_READY | \ - (MG_REG_STATUS_BIT_BUSY | \ - MG_REG_STATUS_BIT_WRITE_FAULT | \ - MG_REG_STATUS_BIT_ERROR))) == MG_STAT_READY) - -/* Error register */ -#define MG_REG_ERR_AMNF 0x01 -#define MG_REG_ERR_ABRT 0x04 -#define MG_REG_ERR_IDNF 0x10 -#define MG_REG_ERR_UNC 0x40 -#define MG_REG_ERR_BBK 0x80 - -/* error code for others */ -#define MG_ERR_NONE 0 -#define MG_ERR_TIMEOUT 0x100 -#define MG_ERR_INIT_STAT 0x101 -#define MG_ERR_TRANSLATION 0x102 -#define MG_ERR_CTRL_RST 0x103 -#define MG_ERR_NO_DRV_DATA 0x104 - -#define MG_MAX_ERRORS 16 /* Max read/write errors/sector */ -#define MG_RESET_FREQ 4 /* Reset controller every 4th retry */ - -/* command */ -#define MG_CMD_RD 0x20 -#define MG_CMD_WR 0x30 -#define MG_CMD_SLEEP 0x99 -#define MG_CMD_WAKEUP 0xC3 -#define MG_CMD_ID 0xEC -#define MG_CMD_WR_CONF 0x3C -#define MG_CMD_RD_CONF 0x40 - -union mg_uniwb{ - u16 w; - u8 b[2]; -}; - -/* main structure for mflash driver */ -struct mg_host { - struct mg_drv_data *drv_data; - /* for future use */ -}; - -/* - * Debugging macro and defines - */ -#undef DO_MG_DEBUG -#ifdef DO_MG_DEBUG -# define MG_DBG(fmt, args...) printf("%s:%d "fmt"\n", __func__, __LINE__,##args) -#else /* CONFIG_MG_DEBUG */ -# define MG_DBG(fmt, args...) do { } while(0) -#endif /* CONFIG_MG_DEBUG */ - -#endif diff --git a/include/mg_disk.h b/include/mg_disk.h deleted file mode 100644 index bd767a1..0000000 --- a/include/mg_disk.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * (C) Copyright 2009 mGine co. - * unsik Kim - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#ifndef MG_DISK_H_ -#define MG_DISK_H_ - -#include - -/* private driver data */ -struct mg_drv_data { - /* base address of mflash */ - u32 base; - /* Initialize hard reset, write protect, deep power down pins. - * Set these pins to GPIO and output high - */ - void (*mg_ctrl_pin_init) (void); - /* Set hard reset pin for given level - * level : logical level of hard reset pin (0 or 1) - */ - void (*mg_hdrst_pin) (u8 level); -}; - -struct mg_drv_data* mg_get_drv_data (void); - -unsigned int mg_disk_init (void); -unsigned int mg_disk_read (u32 addr, u8 *buff, u32 len); -unsigned int mg_disk_write(u32 addr, u8 *buff, u32 len); -unsigned int mg_disk_write_sects(void *buff, u32 sect_num, u32 sect_cnt); -unsigned int mg_disk_read_sects(void *buff, u32 sect_num, u32 sect_cnt); - -#endif /*MG_DISK_H_*/