diff options
| author | Pekon Gupta <pekon@ti.com> | 2014-03-20 09:18:35 -0400 |
|---|---|---|
| committer | Brian Norris <computersforpeace@gmail.com> | 2014-03-26 02:08:57 -0400 |
| commit | ea0760244d235688b5fae4e5cdd9412c1fb1c2fe (patch) | |
| tree | f5f0a7b83f316d0ba400450e9073c7f45e14907d | |
| parent | 3f4eb14bdbe148fcc3a8e02f506ccc9b8c955ad4 (diff) | |
mtd: devices: elm: clean elm_load_syndrome
This patch refactors elm_load_syndrome() to make it scalable for newer
ECC schemes by removing scheme specific macros (like ECC_BYTES*xx),
and instead using ECC control information passed during elm_config.
Signed-off-by: Pekon Gupta <pekon@ti.com>
Reviewed-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
| -rw-r--r-- | drivers/mtd/devices/elm.c | 18 | ||||
| -rw-r--r-- | include/linux/platform_data/elm.h | 7 |
2 files changed, 11 insertions, 14 deletions
diff --git a/drivers/mtd/devices/elm.c b/drivers/mtd/devices/elm.c index c51752ad072e..4fbfaf65fabd 100644 --- a/drivers/mtd/devices/elm.c +++ b/drivers/mtd/devices/elm.c | |||
| @@ -84,6 +84,7 @@ struct elm_info { | |||
| 84 | struct list_head list; | 84 | struct list_head list; |
| 85 | enum bch_ecc bch_type; | 85 | enum bch_ecc bch_type; |
| 86 | struct elm_registers elm_regs; | 86 | struct elm_registers elm_regs; |
| 87 | int ecc_syndrome_size; | ||
| 87 | }; | 88 | }; |
| 88 | 89 | ||
| 89 | static LIST_HEAD(elm_devices); | 90 | static LIST_HEAD(elm_devices); |
| @@ -126,7 +127,8 @@ int elm_config(struct device *dev, enum bch_ecc bch_type, | |||
| 126 | 127 | ||
| 127 | reg_val = (bch_type & ECC_BCH_LEVEL_MASK) | (ELM_ECC_SIZE << 16); | 128 | reg_val = (bch_type & ECC_BCH_LEVEL_MASK) | (ELM_ECC_SIZE << 16); |
| 128 | elm_write_reg(info, ELM_LOCATION_CONFIG, reg_val); | 129 | elm_write_reg(info, ELM_LOCATION_CONFIG, reg_val); |
| 129 | info->bch_type = bch_type; | 130 | info->bch_type = bch_type; |
| 131 | info->ecc_syndrome_size = ecc_syndrome_size; | ||
| 130 | 132 | ||
| 131 | return 0; | 133 | return 0; |
| 132 | } | 134 | } |
| @@ -175,10 +177,8 @@ static void elm_load_syndrome(struct elm_info *info, | |||
| 175 | elm_configure_page_mode(info, i, true); | 177 | elm_configure_page_mode(info, i, true); |
| 176 | offset = ELM_SYNDROME_FRAGMENT_0 + | 178 | offset = ELM_SYNDROME_FRAGMENT_0 + |
| 177 | SYNDROME_FRAGMENT_REG_SIZE * i; | 179 | SYNDROME_FRAGMENT_REG_SIZE * i; |
| 178 | 180 | switch (info->bch_type) { | |
| 179 | /* BCH8 */ | 181 | case BCH8_ECC: |
| 180 | if (info->bch_type) { | ||
| 181 | |||
| 182 | /* syndrome fragment 0 = ecc[9-12B] */ | 182 | /* syndrome fragment 0 = ecc[9-12B] */ |
| 183 | val = cpu_to_be32(*(u32 *) &ecc[9]); | 183 | val = cpu_to_be32(*(u32 *) &ecc[9]); |
| 184 | elm_write_reg(info, offset, val); | 184 | elm_write_reg(info, offset, val); |
| @@ -197,7 +197,8 @@ static void elm_load_syndrome(struct elm_info *info, | |||
| 197 | offset += 4; | 197 | offset += 4; |
| 198 | val = ecc[0]; | 198 | val = ecc[0]; |
| 199 | elm_write_reg(info, offset, val); | 199 | elm_write_reg(info, offset, val); |
| 200 | } else { | 200 | break; |
| 201 | case BCH4_ECC: | ||
| 201 | /* syndrome fragment 0 = ecc[20-52b] bits */ | 202 | /* syndrome fragment 0 = ecc[20-52b] bits */ |
| 202 | val = (cpu_to_be32(*(u32 *) &ecc[3]) >> 4) | | 203 | val = (cpu_to_be32(*(u32 *) &ecc[3]) >> 4) | |
| 203 | ((ecc[2] & 0xf) << 28); | 204 | ((ecc[2] & 0xf) << 28); |
| @@ -207,11 +208,14 @@ static void elm_load_syndrome(struct elm_info *info, | |||
| 207 | offset += 4; | 208 | offset += 4; |
| 208 | val = cpu_to_be32(*(u32 *) &ecc[0]) >> 12; | 209 | val = cpu_to_be32(*(u32 *) &ecc[0]) >> 12; |
| 209 | elm_write_reg(info, offset, val); | 210 | elm_write_reg(info, offset, val); |
| 211 | break; | ||
| 212 | default: | ||
| 213 | pr_err("invalid config bch_type\n"); | ||
| 210 | } | 214 | } |
| 211 | } | 215 | } |
| 212 | 216 | ||
| 213 | /* Update ecc pointer with ecc byte size */ | 217 | /* Update ecc pointer with ecc byte size */ |
| 214 | ecc += info->bch_type ? BCH8_SIZE : BCH4_SIZE; | 218 | ecc += info->ecc_syndrome_size; |
| 215 | } | 219 | } |
| 216 | } | 220 | } |
| 217 | 221 | ||
diff --git a/include/linux/platform_data/elm.h b/include/linux/platform_data/elm.h index 6e37156b0902..4edb40676b3f 100644 --- a/include/linux/platform_data/elm.h +++ b/include/linux/platform_data/elm.h | |||
| @@ -26,13 +26,6 @@ enum bch_ecc { | |||
| 26 | /* ELM support 8 error syndrome process */ | 26 | /* ELM support 8 error syndrome process */ |
| 27 | #define ERROR_VECTOR_MAX 8 | 27 | #define ERROR_VECTOR_MAX 8 |
| 28 | 28 | ||
| 29 | #define BCH8_ECC_OOB_BYTES 13 | ||
| 30 | #define BCH4_ECC_OOB_BYTES 7 | ||
| 31 | /* RBL requires 14 byte even though BCH8 uses only 13 byte */ | ||
| 32 | #define BCH8_SIZE (BCH8_ECC_OOB_BYTES + 1) | ||
| 33 | /* Uses 1 extra byte to handle erased pages */ | ||
| 34 | #define BCH4_SIZE (BCH4_ECC_OOB_BYTES + 1) | ||
| 35 | |||
| 36 | /** | 29 | /** |
| 37 | * struct elm_errorvec - error vector for elm | 30 | * struct elm_errorvec - error vector for elm |
| 38 | * @error_reported: set true for vectors error is reported | 31 | * @error_reported: set true for vectors error is reported |
