Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[MTD] sharpsl-nand: use platform_data for model-specific values

Add platform_data which holds all model-specific values, like badblocks
pattern, oobinfo, partitions.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>

+104 -74
+84 -74
drivers/mtd/nand/sharpsl.c
··· 20 20 #include <linux/mtd/nand.h> 21 21 #include <linux/mtd/nand_ecc.h> 22 22 #include <linux/mtd/partitions.h> 23 + #include <linux/mtd/sharpsl.h> 23 24 #include <linux/interrupt.h> 24 25 #include <linux/platform_device.h> 25 26 ··· 54 53 #define FLCLE (1 << 1) 55 54 #define FLCE0 (1 << 0) 56 55 57 - #ifdef CONFIG_MTD_PARTITIONS 58 - /* 59 - * Define partitions for flash device 60 - */ 61 - #define DEFAULT_NUM_PARTITIONS 3 62 - 63 - static struct mtd_partition sharpsl_nand_default_partition_info[] = { 64 - { 65 - .name = "System Area", 66 - .offset = 0, 67 - .size = 7 * 1024 * 1024, 68 - }, 69 - { 70 - .name = "Root Filesystem", 71 - .offset = 7 * 1024 * 1024, 72 - .size = 30 * 1024 * 1024, 73 - }, 74 - { 75 - .name = "Home Filesystem", 76 - .offset = MTDPART_OFS_APPEND, 77 - .size = MTDPART_SIZ_FULL, 78 - }, 79 - }; 80 - #endif 81 - 82 56 /* 83 57 * hardware specific access to control-lines 84 58 * ctrl: ··· 81 105 if (cmd != NAND_CMD_NONE) 82 106 writeb(cmd, chip->IO_ADDR_W); 83 107 } 84 - 85 - static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; 86 - 87 - static struct nand_bbt_descr sharpsl_bbt = { 88 - .options = 0, 89 - .offs = 4, 90 - .len = 2, 91 - .pattern = scan_ff_pattern 92 - }; 93 - 94 - static struct nand_bbt_descr sharpsl_akita_bbt = { 95 - .options = 0, 96 - .offs = 4, 97 - .len = 1, 98 - .pattern = scan_ff_pattern 99 - }; 100 - 101 - static struct nand_ecclayout akita_oobinfo = { 102 - .eccbytes = 24, 103 - .eccpos = { 104 - 0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11, 105 - 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23, 106 - 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37}, 107 - .oobfree = {{0x08, 0x09}} 108 - }; 109 108 110 109 static int sharpsl_nand_dev_ready(struct mtd_info *mtd) 111 110 { ··· 120 169 struct resource *r; 121 170 int err = 0; 122 171 struct sharpsl_nand *sharpsl; 172 + struct sharpsl_nand_platform_data *data = pdev->dev.platform_data; 173 + 174 + if (!data) { 175 + dev_err(&pdev->dev, "no platform data!\n"); 176 + return -EINVAL; 177 + } 123 178 124 179 /* Allocate memory for MTD device structure and private data */ 125 180 sharpsl = kzalloc(sizeof(struct sharpsl_nand), GFP_KERNEL); ··· 175 218 this->ecc.mode = NAND_ECC_HW; 176 219 this->ecc.size = 256; 177 220 this->ecc.bytes = 3; 178 - this->badblock_pattern = &sharpsl_bbt; 179 - if (machine_is_akita() || machine_is_borzoi()) { 180 - this->badblock_pattern = &sharpsl_akita_bbt; 181 - this->ecc.layout = &akita_oobinfo; 182 - } 221 + this->badblock_pattern = data->badblock_pattern; 222 + this->ecc.layout = data->ecc_layout; 183 223 this->ecc.hwctl = sharpsl_nand_enable_hwecc; 184 224 this->ecc.calculate = sharpsl_nand_calculate_ecc; 185 225 this->ecc.correct = nand_correct_data; ··· 190 236 sharpsl->mtd.name = "sharpsl-nand"; 191 237 #ifdef CONFIG_MTD_PARTITIONS 192 238 nr_partitions = parse_mtd_partitions(&sharpsl->mtd, part_probes, &sharpsl_partition_info, 0); 193 - 194 239 if (nr_partitions <= 0) { 195 - nr_partitions = ARRAY_SIZE(sharpsl_nand_default_partition_info); 196 - sharpsl_partition_info = sharpsl_nand_default_partition_info; 197 - if (machine_is_poodle()) { 198 - sharpsl_partition_info[1].size = 22 * 1024 * 1024; 199 - } else if (machine_is_corgi() || machine_is_shepherd()) { 200 - sharpsl_partition_info[1].size = 25 * 1024 * 1024; 201 - } else if (machine_is_husky()) { 202 - sharpsl_partition_info[1].size = 53 * 1024 * 1024; 203 - } else if (machine_is_spitz()) { 204 - sharpsl_partition_info[1].size = 5 * 1024 * 1024; 205 - } else if (machine_is_akita()) { 206 - sharpsl_partition_info[1].size = 58 * 1024 * 1024; 207 - } else if (machine_is_borzoi()) { 208 - sharpsl_partition_info[1].size = 32 * 1024 * 1024; 209 - } 240 + nr_partitions = data->nr_partitions; 241 + sharpsl_partition_info = data->partitions; 210 242 } 211 243 212 - err = add_mtd_partitions(&sharpsl->mtd, sharpsl_partition_info, nr_partitions); 213 - #else 214 - err = add_mtd_device(&sharpsl->mtd); 244 + if (nr_partitions > 0) 245 + err = add_mtd_partitions(&sharpsl->mtd, sharpsl_partition_info, nr_partitions); 246 + else 215 247 #endif 248 + err = add_mtd_device(&sharpsl->mtd); 216 249 if (err) 217 250 goto err_add; 218 251 ··· 247 306 .remove = __devexit_p(sharpsl_nand_remove), 248 307 }; 249 308 309 + /* 310 + * Define partitions for flash device 311 + */ 312 + static struct mtd_partition sharpsl_nand_partitions[] = { 313 + { 314 + .name = "System Area", 315 + .offset = 0, 316 + .size = 7 * 1024 * 1024, 317 + }, 318 + { 319 + .name = "Root Filesystem", 320 + .offset = 7 * 1024 * 1024, 321 + .size = 30 * 1024 * 1024, 322 + }, 323 + { 324 + .name = "Home Filesystem", 325 + .offset = MTDPART_OFS_APPEND, 326 + .size = MTDPART_SIZ_FULL, 327 + }, 328 + }; 329 + 330 + static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; 331 + 332 + static struct nand_bbt_descr sharpsl_bbt = { 333 + .options = 0, 334 + .offs = 4, 335 + .len = 2, 336 + .pattern = scan_ff_pattern 337 + }; 338 + 339 + static struct nand_bbt_descr sharpsl_akita_bbt = { 340 + .options = 0, 341 + .offs = 4, 342 + .len = 1, 343 + .pattern = scan_ff_pattern 344 + }; 345 + 346 + static struct nand_ecclayout akita_oobinfo = { 347 + .eccbytes = 24, 348 + .eccpos = { 349 + 0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11, 350 + 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23, 351 + 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37}, 352 + .oobfree = {{0x08, 0x09}} 353 + }; 354 + 355 + static struct sharpsl_nand_platform_data sharpsl_nand_platform_data = { 356 + .badblock_pattern = &sharpsl_bbt, 357 + .partitions = sharpsl_nand_partitions, 358 + .nr_partitions = ARRAY_SIZE(sharpsl_nand_partitions), 359 + }; 360 + 250 361 static struct resource sharpsl_nand_resources[] = { 251 362 { 252 363 .start = 0x0C000000, ··· 312 319 .id = -1, 313 320 .resource = sharpsl_nand_resources, 314 321 .num_resources = ARRAY_SIZE(sharpsl_nand_resources), 322 + .dev.platform_data = &sharpsl_nand_platform_data, 315 323 }; 316 324 317 325 static int __init sharpsl_nand_init(void) 318 326 { 327 + if (machine_is_poodle()) { 328 + sharpsl_nand_partitions[1].size = 22 * 1024 * 1024; 329 + } else if (machine_is_corgi() || machine_is_shepherd()) { 330 + sharpsl_nand_partitions[1].size = 25 * 1024 * 1024; 331 + } else if (machine_is_husky()) { 332 + sharpsl_nand_partitions[1].size = 53 * 1024 * 1024; 333 + } else if (machine_is_spitz()) { 334 + sharpsl_nand_partitions[1].size = 5 * 1024 * 1024; 335 + } else if (machine_is_akita()) { 336 + sharpsl_nand_partitions[1].size = 58 * 1024 * 1024; 337 + sharpsl_nand_platform_data.badblock_pattern = &sharpsl_akita_bbt; 338 + sharpsl_nand_platform_data.ecc_layout = &akita_oobinfo; 339 + } else if (machine_is_borzoi()) { 340 + sharpsl_nand_partitions[1].size = 32 * 1024 * 1024; 341 + } 342 + 319 343 platform_device_register(&sharpsl_nand_device); 320 344 return platform_driver_register(&sharpsl_nand_driver); 321 345 }
+20
include/linux/mtd/sharpsl.h
··· 1 + /* 2 + * SharpSL NAND support 3 + * 4 + * Copyright (C) 2008 Dmitry Baryshkov 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + */ 10 + 11 + #include <linux/mtd/nand.h> 12 + #include <linux/mtd/nand_ecc.h> 13 + #include <linux/mtd/partitions.h> 14 + 15 + struct sharpsl_nand_platform_data { 16 + struct nand_bbt_descr *badblock_pattern; 17 + struct nand_ecclayout *ecc_layout; 18 + struct mtd_partition *partitions; 19 + unsigned int nr_partitions; 20 + };