| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Generic on-chip SRAM allocation driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2012 Philipp Zabel, Pengutronix |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or |
|---|
| 7 | | - * modify it under the terms of the GNU General Public License |
|---|
| 8 | | - * as published by the Free Software Foundation; either version 2 |
|---|
| 9 | | - * of the License, or (at your option) any later version. |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License |
|---|
| 16 | | - * along with this program; if not, write to the Free Software |
|---|
| 17 | | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|---|
| 18 | | - * MA 02110-1301, USA. |
|---|
| 19 | 6 | */ |
|---|
| 20 | 7 | |
|---|
| 21 | 8 | #include <linux/clk.h> |
|---|
| .. | .. |
|---|
| 323 | 310 | cur_start = block->start + block->size; |
|---|
| 324 | 311 | } |
|---|
| 325 | 312 | |
|---|
| 326 | | - err_chunks: |
|---|
| 327 | | - if (child) |
|---|
| 328 | | - of_node_put(child); |
|---|
| 329 | | - |
|---|
| 313 | +err_chunks: |
|---|
| 314 | + of_node_put(child); |
|---|
| 330 | 315 | kfree(rblocks); |
|---|
| 331 | 316 | |
|---|
| 332 | 317 | return ret; |
|---|
| .. | .. |
|---|
| 355 | 340 | static int sram_probe(struct platform_device *pdev) |
|---|
| 356 | 341 | { |
|---|
| 357 | 342 | struct sram_dev *sram; |
|---|
| 358 | | - struct resource *res; |
|---|
| 359 | | - size_t size; |
|---|
| 360 | 343 | int ret; |
|---|
| 361 | 344 | int (*init_func)(void); |
|---|
| 362 | 345 | |
|---|
| .. | .. |
|---|
| 366 | 349 | |
|---|
| 367 | 350 | sram->dev = &pdev->dev; |
|---|
| 368 | 351 | |
|---|
| 369 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 370 | | - if (!res) { |
|---|
| 371 | | - dev_err(sram->dev, "found no memory resource\n"); |
|---|
| 372 | | - return -EINVAL; |
|---|
| 373 | | - } |
|---|
| 374 | | - |
|---|
| 375 | | - size = resource_size(res); |
|---|
| 376 | | - |
|---|
| 377 | | - if (!devm_request_mem_region(sram->dev, res->start, size, pdev->name)) { |
|---|
| 378 | | - dev_err(sram->dev, "could not request region for resource\n"); |
|---|
| 379 | | - return -EBUSY; |
|---|
| 380 | | - } |
|---|
| 381 | | - |
|---|
| 382 | 352 | if (of_property_read_bool(pdev->dev.of_node, "no-memory-wc")) |
|---|
| 383 | | - sram->virt_base = devm_ioremap(sram->dev, res->start, size); |
|---|
| 353 | + sram->virt_base = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 384 | 354 | else |
|---|
| 385 | | - sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size); |
|---|
| 386 | | - if (!sram->virt_base) |
|---|
| 387 | | - return -ENOMEM; |
|---|
| 355 | + sram->virt_base = devm_platform_ioremap_resource_wc(pdev, 0); |
|---|
| 356 | + if (IS_ERR(sram->virt_base)) { |
|---|
| 357 | + dev_err(&pdev->dev, "could not map SRAM registers\n"); |
|---|
| 358 | + return PTR_ERR(sram->virt_base); |
|---|
| 359 | + } |
|---|
| 388 | 360 | |
|---|
| 389 | 361 | sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), |
|---|
| 390 | 362 | NUMA_NO_NODE, NULL); |
|---|
| .. | .. |
|---|
| 397 | 369 | else |
|---|
| 398 | 370 | clk_prepare_enable(sram->clk); |
|---|
| 399 | 371 | |
|---|
| 400 | | - ret = sram_reserve_regions(sram, res); |
|---|
| 372 | + ret = sram_reserve_regions(sram, |
|---|
| 373 | + platform_get_resource(pdev, IORESOURCE_MEM, 0)); |
|---|
| 401 | 374 | if (ret) |
|---|
| 402 | 375 | goto err_disable_clk; |
|---|
| 403 | 376 | |
|---|