aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/powerpc/booting-without-of.txt92
-rw-r--r--arch/powerpc/boot/dts/ebony.dts30
-rw-r--r--drivers/mtd/maps/physmap_of.c239
3 files changed, 251 insertions, 110 deletions
diff --git a/Documentation/powerpc/booting-without-of.txt b/Documentation/powerpc/booting-without-of.txt
index 76733a3962f0..20e0e6cb0347 100644
--- a/Documentation/powerpc/booting-without-of.txt
+++ b/Documentation/powerpc/booting-without-of.txt
@@ -50,7 +50,7 @@ Table of Contents
50 g) Freescale SOC SEC Security Engines 50 g) Freescale SOC SEC Security Engines
51 h) Board Control and Status (BCSR) 51 h) Board Control and Status (BCSR)
52 i) Freescale QUICC Engine module (QE) 52 i) Freescale QUICC Engine module (QE)
53 j) Flash chip nodes 53 j) CFI or JEDEC memory-mapped NOR flash
54 k) Global Utilities Block 54 k) Global Utilities Block
55 55
56 VII - Specifying interrupt information for devices 56 VII - Specifying interrupt information for devices
@@ -1757,45 +1757,69 @@ platforms are moved over to use the flattened-device-tree model.
1757 }; 1757 };
1758 }; 1758 };
1759 1759
1760 j) Flash chip nodes 1760 j) CFI or JEDEC memory-mapped NOR flash
1761 1761
1762 Flash chips (Memory Technology Devices) are often used for solid state 1762 Flash chips (Memory Technology Devices) are often used for solid state
1763 file systems on embedded devices. 1763 file systems on embedded devices.
1764 1764
1765 Required properties: 1765 - compatible : should contain the specific model of flash chip(s)
1766 used, if known, followed by either "cfi-flash" or "jedec-flash"
1767 - reg : Address range of the flash chip
1768 - bank-width : Width (in bytes) of the flash bank. Equal to the
1769 device width times the number of interleaved chips.
1770 - device-width : (optional) Width of a single flash chip. If
1771 omitted, assumed to be equal to 'bank-width'.
1772 - #address-cells, #size-cells : Must be present if the flash has
1773 sub-nodes representing partitions (see below). In this case
1774 both #address-cells and #size-cells must be equal to 1.
1775
1776 For JEDEC compatible devices, the following additional properties
1777 are defined:
1778
1779 - vendor-id : Contains the flash chip's vendor id (1 byte).
1780 - device-id : Contains the flash chip's device id (1 byte).
1781
1782 In addition to the information on the flash bank itself, the
1783 device tree may optionally contain additional information
1784 describing partitions of the flash address space. This can be
1785 used on platforms which have strong conventions about which
1786 portions of the flash are used for what purposes, but which don't
1787 use an on-flash partition table such as RedBoot.
1788
1789 Each partition is represented as a sub-node of the flash device.
1790 Each node's name represents the name of the corresponding
1791 partition of the flash device.
1792
1793 Flash partitions
1794 - reg : The partition's offset and size within the flash bank.
1795 - label : (optional) The label / name for this flash partition.
1796 If omitted, the label is taken from the node name (excluding
1797 the unit address).
1798 - read-only : (optional) This parameter, if present, is a hint to
1799 Linux that this flash partition should only be mounted
1800 read-only. This is usually used for flash partitions
1801 containing early-boot firmware images or data which should not
1802 be clobbered.
1766 1803
1767 - device_type : has to be "rom" 1804 Example:
1768 - compatible : Should specify what this flash device is compatible with.
1769 Currently, this is most likely to be "direct-mapped" (which
1770 corresponds to the MTD physmap mapping driver).
1771 - reg : Offset and length of the register set (or memory mapping) for
1772 the device.
1773 - bank-width : Width of the flash data bus in bytes. Required
1774 for the NOR flashes (compatible == "direct-mapped" and others) ONLY.
1775
1776 Recommended properties :
1777
1778 - partitions : Several pairs of 32-bit values where the first value is
1779 partition's offset from the start of the device and the second one is
1780 partition size in bytes with LSB used to signify a read only
1781 partition (so, the partition size should always be an even number).
1782 - partition-names : The list of concatenated zero terminated strings
1783 representing the partition names.
1784 - probe-type : The type of probe which should be done for the chip
1785 (JEDEC vs CFI actually). Valid ONLY for NOR flashes.
1786
1787 Example:
1788 1805
1789 flash@ff000000 { 1806 flash@ff000000 {
1790 device_type = "rom"; 1807 compatible = "amd,am29lv128ml", "cfi-flash";
1791 compatible = "direct-mapped"; 1808 reg = <ff000000 01000000>;
1792 probe-type = "CFI"; 1809 bank-width = <4>;
1793 reg = <ff000000 01000000>; 1810 device-width = <1>;
1794 bank-width = <4>; 1811 #address-cells = <1>;
1795 partitions = <00000000 00f80000 1812 #size-cells = <1>;
1796 00f80000 00080001>; 1813 fs@0 {
1797 partition-names = "fs\0firmware"; 1814 label = "fs";
1798 }; 1815 reg = <0 f80000>;
1816 };
1817 firmware@f80000 {
1818 label ="firmware";
1819 reg = <f80000 80000>;
1820 read-only;
1821 };
1822 };
1799 1823
1800 k) Global Utilities Block 1824 k) Global Utilities Block
1801 1825
diff --git a/arch/powerpc/boot/dts/ebony.dts b/arch/powerpc/boot/dts/ebony.dts
index 37599bda5500..bc259972aaa0 100644
--- a/arch/powerpc/boot/dts/ebony.dts
+++ b/arch/powerpc/boot/dts/ebony.dts
@@ -138,13 +138,16 @@
138 interrupt-parent = <&UIC1>; 138 interrupt-parent = <&UIC1>;
139 139
140 small-flash@0,80000 { 140 small-flash@0,80000 {
141 device_type = "rom"; 141 compatible = "jedec-flash";
142 compatible = "direct-mapped";
143 probe-type = "JEDEC";
144 bank-width = <1>; 142 bank-width = <1>;
145 partitions = <0 80000>;
146 partition-names = "OpenBIOS";
147 reg = <0 80000 80000>; 143 reg = <0 80000 80000>;
144 #address-cells = <1>;
145 #size-cells = <1>;
146 partition@0 {
147 label = "OpenBIOS";
148 reg = <0 80000>;
149 read-only;
150 };
148 }; 151 };
149 152
150 ds1743@1,0 { 153 ds1743@1,0 {
@@ -154,14 +157,19 @@
154 }; 157 };
155 158
156 large-flash@2,0 { 159 large-flash@2,0 {
157 device_type = "rom"; 160 compatible = "jedec-flash";
158 compatible = "direct-mapped";
159 probe-type = "JEDEC";
160 bank-width = <1>; 161 bank-width = <1>;
161 partitions = <0 380000
162 380000 80000>;
163 partition-names = "fs", "firmware";
164 reg = <2 0 400000>; 162 reg = <2 0 400000>;
163 #address-cells = <1>;
164 #size-cells = <1>;
165 partition@0 {
166 label = "fs";
167 reg = <0 380000>;
168 };
169 partition@380000 {
170 label = "firmware";
171 reg = <380000 80000>;
172 };
165 }; 173 };
166 174
167 ir@3,0 { 175 ir@3,0 {
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index bbb42c35b69b..3df001bfee36 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -4,6 +4,9 @@
4 * Copyright (C) 2006 MontaVista Software Inc. 4 * Copyright (C) 2006 MontaVista Software Inc.
5 * Author: Vitaly Wool <vwool@ru.mvista.com> 5 * Author: Vitaly Wool <vwool@ru.mvista.com>
6 * 6 *
7 * Revised to handle newer style flash binding by:
8 * Copyright (C) 2007 David Gibson, IBM Corporation.
9 *
7 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the 11 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your 12 * Free Software Foundation; either version 2 of the License, or (at your
@@ -30,56 +33,135 @@ struct physmap_flash_info {
30 struct map_info map; 33 struct map_info map;
31 struct resource *res; 34 struct resource *res;
32#ifdef CONFIG_MTD_PARTITIONS 35#ifdef CONFIG_MTD_PARTITIONS
33 int nr_parts;
34 struct mtd_partition *parts; 36 struct mtd_partition *parts;
35#endif 37#endif
36}; 38};
37 39
38static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
39#ifdef CONFIG_MTD_PARTITIONS
40static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
41#endif
42
43#ifdef CONFIG_MTD_PARTITIONS 40#ifdef CONFIG_MTD_PARTITIONS
44static int parse_flash_partitions(struct device_node *node, 41static int parse_obsolete_partitions(struct of_device *dev,
45 struct mtd_partition **parts) 42 struct physmap_flash_info *info,
43 struct device_node *dp)
46{ 44{
47 int i, plen, retval = -ENOMEM; 45 int i, plen, nr_parts;
48 const u32 *part; 46 const struct {
49 const char *name; 47 u32 offset, len;
48 } *part;
49 const char *names;
50 50
51 part = of_get_property(node, "partitions", &plen); 51 part = of_get_property(dp, "partitions", &plen);
52 if (part == NULL) 52 if (!part)
53 goto err; 53 return -ENOENT;
54 54
55 retval = plen / (2 * sizeof(u32)); 55 dev_warn(&dev->dev, "Device tree uses obsolete partition map binding\n");
56 *parts = kzalloc(retval * sizeof(struct mtd_partition), GFP_KERNEL); 56
57 if (*parts == NULL) { 57 nr_parts = plen / sizeof(part[0]);
58
59 info->parts = kzalloc(nr_parts * sizeof(struct mtd_partition), GFP_KERNEL);
60 if (!info->parts) {
58 printk(KERN_ERR "Can't allocate the flash partition data!\n"); 61 printk(KERN_ERR "Can't allocate the flash partition data!\n");
59 goto err; 62 return -ENOMEM;
60 } 63 }
61 64
62 name = of_get_property(node, "partition-names", &plen); 65 names = of_get_property(dp, "partition-names", &plen);
63 66
64 for (i = 0; i < retval; i++) { 67 for (i = 0; i < nr_parts; i++) {
65 (*parts)[i].offset = *part++; 68 info->parts[i].offset = part->offset;
66 (*parts)[i].size = *part & ~1; 69 info->parts[i].size = part->len & ~1;
67 if (*part++ & 1) /* bit 0 set signifies read only partition */ 70 if (part->len & 1) /* bit 0 set signifies read only partition */
68 (*parts)[i].mask_flags = MTD_WRITEABLE; 71 info->parts[i].mask_flags = MTD_WRITEABLE;
69 72
70 if (name != NULL && plen > 0) { 73 if (names && (plen > 0)) {
71 int len = strlen(name) + 1; 74 int len = strlen(names) + 1;
72 75
73 (*parts)[i].name = (char *)name; 76 info->parts[i].name = (char *)names;
74 plen -= len; 77 plen -= len;
75 name += len; 78 names += len;
76 } else 79 } else {
77 (*parts)[i].name = "unnamed"; 80 info->parts[i].name = "unnamed";
81 }
82
83 part++;
78 } 84 }
79err: 85
80 return retval; 86 return nr_parts;
81} 87}
82#endif 88
89static int __devinit process_partitions(struct physmap_flash_info *info,
90 struct of_device *dev)
91{
92 const char *partname;
93 static const char *part_probe_types[]
94 = { "cmdlinepart", "RedBoot", NULL };
95 struct device_node *dp = dev->node, *pp;
96 int nr_parts, i;
97
98 /* First look for RedBoot table or partitions on the command
99 * line, these take precedence over device tree information */
100 nr_parts = parse_mtd_partitions(info->mtd, part_probe_types,
101 &info->parts, 0);
102 if (nr_parts > 0) {
103 add_mtd_partitions(info->mtd, info->parts, nr_parts);
104 return 0;
105 }
106
107 /* First count the subnodes */
108 nr_parts = 0;
109 for (pp = dp->child; pp; pp = pp->sibling)
110 nr_parts++;
111
112 if (nr_parts) {
113 info->parts = kzalloc(nr_parts * sizeof(struct mtd_partition),
114 GFP_KERNEL);
115 if (!info->parts) {
116 printk(KERN_ERR "Can't allocate the flash partition data!\n");
117 return -ENOMEM;
118 }
119
120 for (pp = dp->child, i = 0 ; pp; pp = pp->sibling, i++) {
121 const u32 *reg;
122 int len;
123
124 reg = of_get_property(pp, "reg", &len);
125 if (!reg || (len != 2*sizeof(u32))) {
126 dev_err(&dev->dev, "Invalid 'reg' on %s\n",
127 dp->full_name);
128 kfree(info->parts);
129 info->parts = NULL;
130 return -EINVAL;
131 }
132 info->parts[i].offset = reg[0];
133 info->parts[i].size = reg[1];
134
135 partname = of_get_property(pp, "label", &len);
136 if (!partname)
137 partname = of_get_property(pp, "name", &len);
138 info->parts[i].name = (char *)partname;
139
140 if (of_get_property(pp, "read-only", &len))
141 info->parts[i].mask_flags = MTD_WRITEABLE;
142 }
143 } else {
144 nr_parts = parse_obsolete_partitions(dev, info, dp);
145 }
146
147 if (nr_parts < 0)
148 return nr_parts;
149
150 if (nr_parts > 0)
151 add_mtd_partitions(info->mtd, info->parts, nr_parts);
152 else
153 add_mtd_device(info->mtd);
154
155 return 0;
156}
157#else /* MTD_PARTITIONS */
158static int __devinit process_partitions(struct physmap_flash_info *info,
159 struct device_node *dev)
160{
161 add_mtd_device(info->mtd);
162 return 0;
163}
164#endif /* MTD_PARTITIONS */
83 165
84static int of_physmap_remove(struct of_device *dev) 166static int of_physmap_remove(struct of_device *dev)
85{ 167{
@@ -92,7 +174,7 @@ static int of_physmap_remove(struct of_device *dev)
92 174
93 if (info->mtd != NULL) { 175 if (info->mtd != NULL) {
94#ifdef CONFIG_MTD_PARTITIONS 176#ifdef CONFIG_MTD_PARTITIONS
95 if (info->nr_parts) { 177 if (info->parts) {
96 del_mtd_partitions(info->mtd); 178 del_mtd_partitions(info->mtd);
97 kfree(info->parts); 179 kfree(info->parts);
98 } else { 180 } else {
@@ -115,17 +197,51 @@ static int of_physmap_remove(struct of_device *dev)
115 return 0; 197 return 0;
116} 198}
117 199
200/* Helper function to handle probing of the obsolete "direct-mapped"
201 * compatible binding, which has an extra "probe-type" property
202 * describing the type of flash probe necessary. */
203static struct mtd_info * __devinit obsolete_probe(struct of_device *dev,
204 struct map_info *map)
205{
206 struct device_node *dp = dev->node;
207 const char *of_probe;
208 struct mtd_info *mtd;
209 static const char *rom_probe_types[]
210 = { "cfi_probe", "jedec_probe", "map_rom"};
211 int i;
212
213 dev_warn(&dev->dev, "Device tree uses obsolete \"direct-mapped\" "
214 "flash binding\n");
215
216 of_probe = of_get_property(dp, "probe-type", NULL);
217 if (!of_probe) {
218 for (i = 0; i < ARRAY_SIZE(rom_probe_types); i++) {
219 mtd = do_map_probe(rom_probe_types[i], map);
220 if (mtd)
221 return mtd;
222 }
223 return NULL;
224 } else if (strcmp(of_probe, "CFI") == 0) {
225 return do_map_probe("cfi_probe", map);
226 } else if (strcmp(of_probe, "JEDEC") == 0) {
227 return do_map_probe("jedec_probe", map);
228 } else {
229 if (strcmp(of_probe, "ROM") != 0)
230 dev_dbg(&dev->dev, "obsolete_probe: don't know probe type "
231 "'%s', mapping as rom\n", of_probe);
232 return do_map_probe("mtd_rom", map);
233 }
234}
235
118static int __devinit of_physmap_probe(struct of_device *dev, const struct of_device_id *match) 236static int __devinit of_physmap_probe(struct of_device *dev, const struct of_device_id *match)
119{ 237{
120 struct device_node *dp = dev->node; 238 struct device_node *dp = dev->node;
121 struct resource res; 239 struct resource res;
122 struct physmap_flash_info *info; 240 struct physmap_flash_info *info;
123 const char **probe_type; 241 const char *probe_type = (const char *)match->data;
124 const char *of_probe;
125 const u32 *width; 242 const u32 *width;
126 int err; 243 int err;
127 244
128
129 if (of_address_to_resource(dp, 0, &res)) { 245 if (of_address_to_resource(dp, 0, &res)) {
130 dev_err(&dev->dev, "Can't get the flash mapping!\n"); 246 dev_err(&dev->dev, "Can't get the flash mapping!\n");
131 err = -EINVAL; 247 err = -EINVAL;
@@ -174,21 +290,11 @@ static int __devinit of_physmap_probe(struct of_device *dev, const struct of_dev
174 290
175 simple_map_init(&info->map); 291 simple_map_init(&info->map);
176 292
177 of_probe = of_get_property(dp, "probe-type", NULL); 293 if (probe_type)
178 if (of_probe == NULL) { 294 info->mtd = do_map_probe(probe_type, &info->map);
179 probe_type = rom_probe_types; 295 else
180 for (; info->mtd == NULL && *probe_type != NULL; probe_type++) 296 info->mtd = obsolete_probe(dev, &info->map);
181 info->mtd = do_map_probe(*probe_type, &info->map); 297
182 } else if (!strcmp(of_probe, "CFI"))
183 info->mtd = do_map_probe("cfi_probe", &info->map);
184 else if (!strcmp(of_probe, "JEDEC"))
185 info->mtd = do_map_probe("jedec_probe", &info->map);
186 else {
187 if (strcmp(of_probe, "ROM"))
188 dev_dbg(&dev->dev, "map_probe: don't know probe type "
189 "'%s', mapping as rom\n", of_probe);
190 info->mtd = do_map_probe("mtd_rom", &info->map);
191 }
192 if (info->mtd == NULL) { 298 if (info->mtd == NULL) {
193 dev_err(&dev->dev, "map_probe failed\n"); 299 dev_err(&dev->dev, "map_probe failed\n");
194 err = -ENXIO; 300 err = -ENXIO;
@@ -196,19 +302,7 @@ static int __devinit of_physmap_probe(struct of_device *dev, const struct of_dev
196 } 302 }
197 info->mtd->owner = THIS_MODULE; 303 info->mtd->owner = THIS_MODULE;
198 304
199#ifdef CONFIG_MTD_PARTITIONS 305 return process_partitions(info, dev);
200 err = parse_mtd_partitions(info->mtd, part_probe_types, &info->parts, 0);
201 if (err > 0) {
202 add_mtd_partitions(info->mtd, info->parts, err);
203 } else if ((err = parse_flash_partitions(dp, &info->parts)) > 0) {
204 dev_info(&dev->dev, "Using OF partition information\n");
205 add_mtd_partitions(info->mtd, info->parts, err);
206 info->nr_parts = err;
207 } else
208#endif
209
210 add_mtd_device(info->mtd);
211 return 0;
212 306
213err_out: 307err_out:
214 of_physmap_remove(dev); 308 of_physmap_remove(dev);
@@ -221,6 +315,21 @@ err_out:
221 315
222static struct of_device_id of_physmap_match[] = { 316static struct of_device_id of_physmap_match[] = {
223 { 317 {
318 .compatible = "cfi-flash",
319 .data = (void *)"cfi_probe",
320 },
321 {
322 /* FIXME: JEDEC chips can't be safely and reliably
323 * probed, although the mtd code gets it right in
324 * practice most of the time. We should use the
325 * vendor and device ids specified by the binding to
326 * bypass the heuristic probe code, but the mtd layer
327 * provides, at present, no interface for doing so
328 * :(. */
329 .compatible = "jedec-flash",
330 .data = (void *)"jedec_probe",
331 },
332 {
224 .type = "rom", 333 .type = "rom",
225 .compatible = "direct-mapped" 334 .compatible = "direct-mapped"
226 }, 335 },