Changeset 2054


Ignore:
Timestamp:
05/22/07 10:33:09 (6 years ago)
Author:
werner
Message:

nand-otp.patch: updated for u-boot reorganization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/u-boot/patches/nand-otp.patch

    r1790 r2054  
    1 Index: u-boot/board/neo1973/Makefile 
    2 =================================================================== 
    3 --- u-boot.orig/board/neo1973/Makefile 
    4 +++ u-boot/board/neo1973/Makefile 
    5 @@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk 
    6   
    7  LIB    = lib$(BOARD).a 
    8   
    9 -OBJS   := neo1973.o pcf50606.o cmd_neo1973.o jbt6k74.o udc.o bootmenu.o 
    10 +OBJS   := neo1973.o pcf50606.o cmd_neo1973.o jbt6k74.o udc.o bootmenu.o nand.o 
    11  SOBJS  := lowlevel_init.o 
    12   
    13  .PHONY:        all 
    14 Index: u-boot/board/neo1973/nand.c 
    15 =================================================================== 
    16 --- /dev/null 
    17 +++ u-boot/board/neo1973/nand.c 
    18 @@ -0,0 +1,121 @@ 
    19 +/* 
    20 + * nand.c - Board-specific NAND setup 
    21 + * 
    22 + * Copyright (C) 2007 by OpenMoko, Inc. 
    23 + * Written by Werner Almesberger <werner@openmoko.org> 
    24 + * All Rights Reserved 
    25 + * 
    26 + * This program is free software; you can redistribute it and/or 
    27 + * modify it under the terms of the GNU General Public License as 
    28 + * published by the Free Software Foundation; either version 2 of 
    29 + * the License, or (at your option) any later version. 
    30 + * 
    31 + * This program is distributed in the hope that it will be useful, 
    32 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    33 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    34 + * GNU General Public License for more details. 
    35 + * 
    36 + * You should have received a copy of the GNU General Public License 
    37 + * along with this program; if not, write to the Free Software 
    38 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
    39 + * MA 02111-1307 USA 
    40 + */ 
    41 + 
    42 + 
    43 +#include "config.h" /* nand.h needs NAND_MAX_CHIPS */ 
    44 +#include "linux/mtd/mtd.h" 
    45 +#include "linux/mtd/nand.h" 
    46 +#include "asm/errno.h" 
    47 + 
    48 + 
    49 +int s3c24x0_nand_init(struct nand_chip *nand); 
    50 + 
    51 + 
    52 +static void samsung_nand_begin_otp(struct mtd_info *mtd) 
    53 +{ 
    54 +       struct nand_chip *this = mtd->priv; 
    55 + 
    56 +       /* @@@FIXME: this is ugly - we select the NAND chip to send the 
    57 +          mode switch commands, knowing that it will be switched off later */ 
    58 +       this->select_chip(mtd, 0); 
    59 +       /* "magic" mode change */ 
    60 +       this->cmdfunc(mtd, 0x30, -1, -1); 
    61 +       this->cmdfunc(mtd, 0x65, -1, -1); 
    62 +} 
    63 + 
    64 + 
    65 +static void samsung_nand_end_otp(struct mtd_info *mtd) 
    66 +{ 
    67 +       struct nand_chip *this = mtd->priv; 
    68 + 
    69 +       /* read/write deselected the chip so now we need to select again */ 
    70 +       this->select_chip(mtd, 0); 
    71 +       this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); 
    72 +       this->select_chip(mtd, -1); 
    73 +} 
    74 + 
    75 + 
    76 +static loff_t otp_page[] = { 
    77 +       0x15,   /* 00-XX-00-00, with XX = 15h-19h */ 
    78 +       0x16, 
    79 +       0x17, 
    80 +       0x18, 
    81 +       0x19, 
    82 +       0x1b,   /* 00-1B-00-00 */ 
    83 +}; 
    84 + 
    85 +#define OTP_PAGES (sizeof(otp_page)/sizeof(*otp_page)) 
    86 + 
    87 + 
    88 +static int convert_otp_address(loff_t *addr, size_t *len) 
    89 +{ 
    90 +       int page; 
    91 + 
    92 +       if (*len && *addr >> 9 != (*addr+*len-1) >> 9) 
    93 +               return -EINVAL; 
    94 +       if (*len > 512) 
    95 +               return -EINVAL; 
    96 +       page = *addr >> 9; 
    97 +       if (page >= OTP_PAGES) 
    98 +               return -EINVAL; 
    99 +       *addr = otp_page[page] << 9; 
    100 +       return 0; 
    101 +} 
    102 + 
    103 + 
    104 +static int samsung_nand_read_otp(struct mtd_info *mtd, loff_t from, 
    105 +    size_t len, size_t *retlen, u_char *buf) 
    106 +{ 
    107 +       int ret; 
    108 + 
    109 +       ret = convert_otp_address(&from, &len); 
    110 +       if (ret) 
    111 +               return ret; 
    112 +       samsung_nand_begin_otp(mtd); 
    113 +       ret = mtd->read(mtd, from, len, retlen, buf); 
    114 +       samsung_nand_end_otp(mtd); 
    115 +       return ret; 
    116 +} 
    117 + 
    118 + 
    119 +static int samsung_nand_write_otp(struct mtd_info *mtd, loff_t to, 
    120 +    size_t len, size_t *retlen, const u_char *buf) 
    121 +{ 
    122 +       int ret; 
    123 + 
    124 +       ret = convert_otp_address(&to, &len); 
    125 +       if (ret) 
    126 +               return ret; 
    127 +       samsung_nand_begin_otp(mtd); 
    128 +       ret = mtd->write(mtd, to, len, retlen, buf); 
    129 +       samsung_nand_end_otp(mtd); 
    130 +       return ret; 
    131 +} 
    132 + 
    133 + 
    134 +int board_nand_init(struct nand_chip *nand) 
    135 +{ 
    136 +       nand->read_otp = samsung_nand_read_otp; 
    137 +       nand->write_otp = samsung_nand_write_otp; 
    138 +       return s3c24x0_nand_init(nand); 
    139 +} 
    1401Index: u-boot/common/cmd_nand.c 
    1412=================================================================== 
    1423--- u-boot.orig/common/cmd_nand.c 
    1434+++ u-boot/common/cmd_nand.c 
    144 @@ -392,6 +392,14 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, 
     5@@ -392,6 +392,14 @@ 
    1456                        else 
    1467                                ret = nand->write_oob(nand, off, size, &size,  
     
    15718                        if (read) 
    15819                                ret = nand_read(nand, off, &size, (u_char *)addr); 
    159 @@ -527,8 +535,9 @@ U_BOOT_CMD(nand, 5, 1, do_nand, 
     20@@ -527,8 +535,9 @@ 
    16021        "nand    - NAND sub-system\n", 
    16122        "info                  - show available NAND devices\n" 
     
    17334--- u-boot.orig/cpu/arm920t/s3c24x0/nand.c 
    17435+++ u-boot/cpu/arm920t/s3c24x0/nand.c 
    175 @@ -167,7 +167,7 @@ int s3c2410_nand_correct_data(struct mtd 
     36@@ -205,7 +205,7 @@ 
    17637 } 
    17738 #endif 
     
    18647--- u-boot.orig/drivers/nand/nand_base.c 
    18748+++ u-boot/drivers/nand/nand_base.c 
    188 @@ -2042,6 +2042,32 @@ out: 
     49@@ -2042,6 +2042,32 @@ 
    18950 } 
    19051 #endif 
     
    21980  * single_erease_cmd - [GENERIC] NAND standard block erase command function 
    22081  * @mtd:       MTD device structure 
    221 @@ -2613,6 +2639,8 @@ int nand_scan (struct mtd_info *mtd, int 
     82@@ -2613,6 +2639,8 @@ 
    22283        mtd->write_ecc = nand_write_ecc; 
    22384        mtd->read_oob = nand_read_oob; 
     
    23293--- u-boot.orig/include/linux/mtd/mtd.h 
    23394+++ u-boot/include/linux/mtd/mtd.h 
    234 @@ -95,6 +95,9 @@ struct mtd_info { 
     95@@ -95,6 +95,9 @@ 
    23596        int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 
    23697        int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); 
     
    246107--- u-boot.orig/include/linux/mtd/nand.h 
    247108+++ u-boot/include/linux/mtd/nand.h 
    248 @@ -307,6 +307,10 @@ struct nand_chip { 
     109@@ -307,6 +307,10 @@ 
    249110        void            (*enable_hwecc)(struct mtd_info *mtd, int mode); 
    250111        void            (*erase_cmd)(struct mtd_info *mtd, int page); 
     
    257118        int             eccsize; 
    258119        int             eccbytes; 
     120Index: u-boot/board/neo1973/gta01/Makefile 
     121=================================================================== 
     122--- u-boot.orig/board/neo1973/gta01/Makefile 
     123+++ u-boot/board/neo1973/gta01/Makefile 
     124@@ -25,7 +25,7 @@ 
     125  
     126 LIB    = lib$(BOARD).a 
     127  
     128-OBJS   := gta01.o pcf50606.o ../common/cmd_neo1973.o ../common/jbt6k74.o ../common/udc.o ../common/bootmenu.o 
     129+OBJS   := gta01.o pcf50606.o nand.o ../common/cmd_neo1973.o ../common/jbt6k74.o ../common/udc.o ../common/bootmenu.o 
     130 SOBJS  := ../common/lowlevel_init.o 
     131  
     132 .PHONY:        all 
     133Index: u-boot/board/neo1973/gta01/nand.c 
     134=================================================================== 
     135--- /dev/null 
     136+++ u-boot/board/neo1973/gta01/nand.c 
     137@@ -0,0 +1,121 @@ 
     138+/* 
     139+ * nand.c - Board-specific NAND setup 
     140+ * 
     141+ * Copyright (C) 2007 by OpenMoko, Inc. 
     142+ * Written by Werner Almesberger <werner@openmoko.org> 
     143+ * All Rights Reserved 
     144+ * 
     145+ * This program is free software; you can redistribute it and/or 
     146+ * modify it under the terms of the GNU General Public License as 
     147+ * published by the Free Software Foundation; either version 2 of 
     148+ * the License, or (at your option) any later version. 
     149+ * 
     150+ * This program is distributed in the hope that it will be useful, 
     151+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     152+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     153+ * GNU General Public License for more details. 
     154+ * 
     155+ * You should have received a copy of the GNU General Public License 
     156+ * along with this program; if not, write to the Free Software 
     157+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
     158+ * MA 02111-1307 USA 
     159+ */ 
     160+ 
     161+ 
     162+#include "config.h" /* nand.h needs NAND_MAX_CHIPS */ 
     163+#include "linux/mtd/mtd.h" 
     164+#include "linux/mtd/nand.h" 
     165+#include "asm/errno.h" 
     166+ 
     167+ 
     168+int s3c24x0_nand_init(struct nand_chip *nand); 
     169+ 
     170+ 
     171+static void samsung_nand_begin_otp(struct mtd_info *mtd) 
     172+{ 
     173+       struct nand_chip *this = mtd->priv; 
     174+ 
     175+       /* @@@FIXME: this is ugly - we select the NAND chip to send the 
     176+          mode switch commands, knowing that it will be switched off later */ 
     177+       this->select_chip(mtd, 0); 
     178+       /* "magic" mode change */ 
     179+       this->cmdfunc(mtd, 0x30, -1, -1); 
     180+       this->cmdfunc(mtd, 0x65, -1, -1); 
     181+} 
     182+ 
     183+ 
     184+static void samsung_nand_end_otp(struct mtd_info *mtd) 
     185+{ 
     186+       struct nand_chip *this = mtd->priv; 
     187+ 
     188+       /* read/write deselected the chip so now we need to select again */ 
     189+       this->select_chip(mtd, 0); 
     190+       this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); 
     191+       this->select_chip(mtd, -1); 
     192+} 
     193+ 
     194+ 
     195+static loff_t otp_page[] = { 
     196+       0x15,   /* 00-XX-00-00, with XX = 15h-19h */ 
     197+       0x16, 
     198+       0x17, 
     199+       0x18, 
     200+       0x19, 
     201+       0x1b,   /* 00-1B-00-00 */ 
     202+}; 
     203+ 
     204+#define OTP_PAGES (sizeof(otp_page)/sizeof(*otp_page)) 
     205+ 
     206+ 
     207+static int convert_otp_address(loff_t *addr, size_t *len) 
     208+{ 
     209+       int page; 
     210+ 
     211+       if (*len && *addr >> 9 != (*addr+*len-1) >> 9) 
     212+               return -EINVAL; 
     213+       if (*len > 512) 
     214+               return -EINVAL; 
     215+       page = *addr >> 9; 
     216+       if (page >= OTP_PAGES) 
     217+               return -EINVAL; 
     218+       *addr = otp_page[page] << 9; 
     219+       return 0; 
     220+} 
     221+ 
     222+ 
     223+static int samsung_nand_read_otp(struct mtd_info *mtd, loff_t from, 
     224+    size_t len, size_t *retlen, u_char *buf) 
     225+{ 
     226+       int ret; 
     227+ 
     228+       ret = convert_otp_address(&from, &len); 
     229+       if (ret) 
     230+               return ret; 
     231+       samsung_nand_begin_otp(mtd); 
     232+       ret = mtd->read(mtd, from, len, retlen, buf); 
     233+       samsung_nand_end_otp(mtd); 
     234+       return ret; 
     235+} 
     236+ 
     237+ 
     238+static int samsung_nand_write_otp(struct mtd_info *mtd, loff_t to, 
     239+    size_t len, size_t *retlen, const u_char *buf) 
     240+{ 
     241+       int ret; 
     242+ 
     243+       ret = convert_otp_address(&to, &len); 
     244+       if (ret) 
     245+               return ret; 
     246+       samsung_nand_begin_otp(mtd); 
     247+       ret = mtd->write(mtd, to, len, retlen, buf); 
     248+       samsung_nand_end_otp(mtd); 
     249+       return ret; 
     250+} 
     251+ 
     252+ 
     253+int board_nand_init(struct nand_chip *nand) 
     254+{ 
     255+       nand->read_otp = samsung_nand_read_otp; 
     256+       nand->write_otp = samsung_nand_write_otp; 
     257+       return s3c24x0_nand_init(nand); 
     258+} 
     259Index: u-boot/board/neo1973/gta02/nand.c 
     260=================================================================== 
     261--- /dev/null 
     262+++ u-boot/board/neo1973/gta02/nand.c 
     263@@ -0,0 +1,39 @@ 
     264+/* 
     265+ * nand.c - Board-specific NAND setup 
     266+ * 
     267+ * Copyright (C) 2007 by OpenMoko, Inc. 
     268+ * Written by Werner Almesberger <werner@openmoko.org> 
     269+ * All Rights Reserved 
     270+ * 
     271+ * This program is free software; you can redistribute it and/or 
     272+ * modify it under the terms of the GNU General Public License as 
     273+ * published by the Free Software Foundation; either version 2 of 
     274+ * the License, or (at your option) any later version. 
     275+ * 
     276+ * This program is distributed in the hope that it will be useful, 
     277+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     278+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     279+ * GNU General Public License for more details. 
     280+ * 
     281+ * You should have received a copy of the GNU General Public License 
     282+ * along with this program; if not, write to the Free Software 
     283+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
     284+ * MA 02111-1307 USA 
     285+ */ 
     286+ 
     287+ 
     288+#include "config.h" /* nand.h needs NAND_MAX_CHIPS */ 
     289+#include "linux/mtd/mtd.h" 
     290+#include "linux/mtd/nand.h" 
     291+ 
     292+ 
     293+int s3c24x0_nand_init(struct nand_chip *nand); 
     294+ 
     295+ 
     296+/* Add OTP et al later */ 
     297+ 
     298+ 
     299+int board_nand_init(struct nand_chip *nand) 
     300+{ 
     301+       return s3c24x0_nand_init(nand); 
     302+} 
Note: See TracChangeset for help on using the changeset viewer.