Root/
1 | /* |
2 | * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> |
3 | * |
4 | * OF helpers for mtd. |
5 | * |
6 | * This file is released under the GPLv2 |
7 | * |
8 | */ |
9 | #include <linux/kernel.h> |
10 | #include <linux/of_mtd.h> |
11 | #include <linux/mtd/nand.h> |
12 | #include <linux/export.h> |
13 | |
14 | /** |
15 | * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h |
16 | * into the device tree binding of 'nand-ecc', so that MTD |
17 | * device driver can get nand ecc from device tree. |
18 | */ |
19 | static const char *nand_ecc_modes[] = { |
20 | [NAND_ECC_NONE] = "none", |
21 | [NAND_ECC_SOFT] = "soft", |
22 | [NAND_ECC_HW] = "hw", |
23 | [NAND_ECC_HW_SYNDROME] = "hw_syndrome", |
24 | [NAND_ECC_HW_OOB_FIRST] = "hw_oob_first", |
25 | [NAND_ECC_SOFT_BCH] = "soft_bch", |
26 | }; |
27 | |
28 | /** |
29 | * of_get_nand_ecc_mode - Get nand ecc mode for given device_node |
30 | * @np: Pointer to the given device_node |
31 | * |
32 | * The function gets ecc mode string from property 'nand-ecc-mode', |
33 | * and return its index in nand_ecc_modes table, or errno in error case. |
34 | */ |
35 | int of_get_nand_ecc_mode(struct device_node *np) |
36 | { |
37 | const char *pm; |
38 | int err, i; |
39 | |
40 | err = of_property_read_string(np, "nand-ecc-mode", &pm); |
41 | if (err < 0) |
42 | return err; |
43 | |
44 | for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++) |
45 | if (!strcasecmp(pm, nand_ecc_modes[i])) |
46 | return i; |
47 | |
48 | return -ENODEV; |
49 | } |
50 | EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode); |
51 | |
52 | /** |
53 | * of_get_nand_bus_width - Get nand bus witdh for given device_node |
54 | * @np: Pointer to the given device_node |
55 | * |
56 | * return bus width option, or errno in error case. |
57 | */ |
58 | int of_get_nand_bus_width(struct device_node *np) |
59 | { |
60 | u32 val; |
61 | |
62 | if (of_property_read_u32(np, "nand-bus-width", &val)) |
63 | return 8; |
64 | |
65 | switch(val) { |
66 | case 8: |
67 | case 16: |
68 | return val; |
69 | default: |
70 | return -EIO; |
71 | } |
72 | } |
73 | EXPORT_SYMBOL_GPL(of_get_nand_bus_width); |
74 | |
75 | /** |
76 | * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node |
77 | * @np: Pointer to the given device_node |
78 | * |
79 | * return true if present false other wise |
80 | */ |
81 | bool of_get_nand_on_flash_bbt(struct device_node *np) |
82 | { |
83 | return of_property_read_bool(np, "nand-on-flash-bbt"); |
84 | } |
85 | EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt); |
86 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9