|
21 | 21 | #include <linux/platform_device.h> |
22 | 22 | #include <linux/clk.h> |
23 | 23 | #include <linux/of.h> |
| 24 | +#include <linux/of_address.h> |
24 | 25 | #include <linux/of_clk.h> |
25 | 26 | #include <linux/of_platform.h> |
26 | 27 | #include <linux/parser.h> |
@@ -121,12 +122,13 @@ struct simplefb_params { |
121 | 122 | u32 height; |
122 | 123 | u32 stride; |
123 | 124 | struct simplefb_format *format; |
| 125 | + struct resource memory; |
124 | 126 | }; |
125 | 127 |
|
126 | 128 | static int simplefb_parse_dt(struct platform_device *pdev, |
127 | 129 | struct simplefb_params *params) |
128 | 130 | { |
129 | | - struct device_node *np = pdev->dev.of_node; |
| 131 | + struct device_node *np = pdev->dev.of_node, *mem; |
130 | 132 | int ret; |
131 | 133 | const char *format; |
132 | 134 | int i; |
@@ -166,6 +168,23 @@ static int simplefb_parse_dt(struct platform_device *pdev, |
166 | 168 | return -EINVAL; |
167 | 169 | } |
168 | 170 |
|
| 171 | + mem = of_parse_phandle(np, "memory-region", 0); |
| 172 | + if (mem) { |
| 173 | + ret = of_address_to_resource(mem, 0, ¶ms->memory); |
| 174 | + if (ret < 0) { |
| 175 | + dev_err(&pdev->dev, "failed to parse memory-region\n"); |
| 176 | + of_node_put(mem); |
| 177 | + return ret; |
| 178 | + } |
| 179 | + |
| 180 | + if (of_property_present(np, "reg")) |
| 181 | + dev_warn(&pdev->dev, "preferring \"memory-region\" over \"reg\" property\n"); |
| 182 | + |
| 183 | + of_node_put(mem); |
| 184 | + } else { |
| 185 | + memset(¶ms->memory, 0, sizeof(params->memory)); |
| 186 | + } |
| 187 | + |
169 | 188 | return 0; |
170 | 189 | } |
171 | 190 |
|
@@ -193,6 +212,8 @@ static int simplefb_parse_pd(struct platform_device *pdev, |
193 | 212 | return -EINVAL; |
194 | 213 | } |
195 | 214 |
|
| 215 | + memset(¶ms->memory, 0, sizeof(params->memory)); |
| 216 | + |
196 | 217 | return 0; |
197 | 218 | } |
198 | 219 |
|
@@ -431,10 +452,14 @@ static int simplefb_probe(struct platform_device *pdev) |
431 | 452 | if (ret) |
432 | 453 | return ret; |
433 | 454 |
|
434 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
435 | | - if (!res) { |
436 | | - dev_err(&pdev->dev, "No memory resource\n"); |
437 | | - return -EINVAL; |
| 455 | + if (params.memory.start == 0 && params.memory.end == 0) { |
| 456 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 457 | + if (!res) { |
| 458 | + dev_err(&pdev->dev, "No memory resource\n"); |
| 459 | + return -EINVAL; |
| 460 | + } |
| 461 | + } else { |
| 462 | + res = ¶ms.memory; |
438 | 463 | } |
439 | 464 |
|
440 | 465 | mem = request_mem_region(res->start, resource_size(res), "simplefb"); |
|
0 commit comments