Skip to content

Commit 0bc448b

Browse files
geertumiquelraynal
authored andcommitted
mtd: maps: physmap: Add minimal Runtime PM support
Add minimal runtime PM support (enable on probe, disable on remove), to ensure proper operation with a parent device that uses runtime PM. This is needed on systems where the FLASH is connected to a bus controller that is contained in a PM domain and/or has a gateable functional clock. In such cases, before accessing any device connected to the external bus, the PM domain must be powered up, and/or the functional clock must be enabled, which is typically handled through runtime PM by the bus controller driver. An example of this is the Renesas APE6-EVM development board, which has an Ethernet controller and a CFI FLASH connected to the Bus State Controller (BSC) of an R-Mobile APE6 SoC. As long as the Ethernet driver, which had Runtime PM support since commit 3a611e2 ("net/smsc911x: Add minimal runtime PM support"), keeps the BSC powered, accessing the FLASH works. When the ethernet node in r8a73a4-ape6evm.dts is disabled, the BSC is never powered up, and the kernel crashes when trying to access the FLASH: Unhandled fault: imprecise external abort (0x1406) at 0x00000000 pgd = (ptrval) [00000000] *pgd=7fef2835 Internal error: : 1406 [raspberrypi#1] SMP ARM CPU: 0 PID: 122 Comm: hd Tainted: G W 5.5.0-rc1-ape6evm-00814-g38ca966db25b9dbd-dirty raspberrypi#136 Hardware name: Generic R8A73A4 (Flattened Device Tree) PC is at chip_ready+0x12c/0x380 LR is at chip_ready+0x10c/0x380 Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 2a0b390 commit 0bc448b

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

‎drivers/mtd/maps/physmap-core.c‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <linux/mtd/cfi_endian.h>
3939
#include <linux/io.h>
4040
#include <linux/of_device.h>
41+
#include <linux/pm_runtime.h>
4142
#include <linux/gpio/consumer.h>
4243

4344
#include "physmap-gemini.h"
@@ -64,16 +65,16 @@ static int physmap_flash_remove(struct platform_device *dev)
6465
{
6566
struct physmap_flash_info *info;
6667
struct physmap_flash_data *physmap_data;
67-
int i, err;
68+
int i, err = 0;
6869

6970
info = platform_get_drvdata(dev);
7071
if (!info)
71-
return 0;
72+
goto out;
7273

7374
if (info->cmtd) {
7475
err = mtd_device_unregister(info->cmtd);
7576
if (err)
76-
return err;
77+
goto out;
7778

7879
if (info->cmtd != info->mtds[0])
7980
mtd_concat_destroy(info->cmtd);
@@ -88,7 +89,10 @@ static int physmap_flash_remove(struct platform_device *dev)
8889
if (physmap_data && physmap_data->exit)
8990
physmap_data->exit(dev);
9091

91-
return 0;
92+
out:
93+
pm_runtime_put(&dev->dev);
94+
pm_runtime_disable(&dev->dev);
95+
return err;
9296
}
9397

9498
static void physmap_set_vpp(struct map_info *map, int state)
@@ -484,13 +488,19 @@ static int physmap_flash_probe(struct platform_device *dev)
484488
return -EINVAL;
485489
}
486490

491+
pm_runtime_enable(&dev->dev);
492+
pm_runtime_get_sync(&dev->dev);
493+
487494
if (dev->dev.of_node)
488495
err = physmap_flash_of_init(dev);
489496
else
490497
err = physmap_flash_pdata_init(dev);
491498

492-
if (err)
499+
if (err) {
500+
pm_runtime_put(&dev->dev);
501+
pm_runtime_disable(&dev->dev);
493502
return err;
503+
}
494504

495505
for (i = 0; i < info->nmaps; i++) {
496506
struct resource *res;

0 commit comments

Comments
 (0)