| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Generic Syscon Reboot Driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (c) 2013, Applied Micro Circuits Corporation |
|---|
| 5 | 6 | * Author: Feng Kan <fkan@apm.com> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or |
|---|
| 8 | | - * modify it under the terms of the GNU General Public License as |
|---|
| 9 | | - * published by the Free Software Foundation; either version 2 of |
|---|
| 10 | | - * the License, or (at your option) any later version. |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | | - * GNU General Public License for more details. |
|---|
| 16 | 7 | */ |
|---|
| 17 | 8 | #include <linux/delay.h> |
|---|
| 18 | 9 | #include <linux/io.h> |
|---|
| .. | .. |
|---|
| 27 | 18 | struct syscon_reboot_context { |
|---|
| 28 | 19 | struct regmap *map; |
|---|
| 29 | 20 | u32 offset; |
|---|
| 21 | + u32 value; |
|---|
| 30 | 22 | u32 mask; |
|---|
| 31 | 23 | struct notifier_block restart_handler; |
|---|
| 32 | 24 | }; |
|---|
| .. | .. |
|---|
| 39 | 31 | restart_handler); |
|---|
| 40 | 32 | |
|---|
| 41 | 33 | /* Issue the reboot */ |
|---|
| 42 | | - regmap_write(ctx->map, ctx->offset, ctx->mask); |
|---|
| 34 | + regmap_update_bits(ctx->map, ctx->offset, ctx->mask, ctx->value); |
|---|
| 43 | 35 | |
|---|
| 44 | 36 | mdelay(1000); |
|---|
| 45 | 37 | |
|---|
| .. | .. |
|---|
| 51 | 43 | { |
|---|
| 52 | 44 | struct syscon_reboot_context *ctx; |
|---|
| 53 | 45 | struct device *dev = &pdev->dev; |
|---|
| 46 | + int mask_err, value_err; |
|---|
| 54 | 47 | int err; |
|---|
| 55 | 48 | |
|---|
| 56 | 49 | ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 58 | 51 | return -ENOMEM; |
|---|
| 59 | 52 | |
|---|
| 60 | 53 | ctx->map = syscon_regmap_lookup_by_phandle(dev->of_node, "regmap"); |
|---|
| 61 | | - if (IS_ERR(ctx->map)) |
|---|
| 62 | | - return PTR_ERR(ctx->map); |
|---|
| 54 | + if (IS_ERR(ctx->map)) { |
|---|
| 55 | + ctx->map = syscon_node_to_regmap(dev->parent->of_node); |
|---|
| 56 | + if (IS_ERR(ctx->map)) |
|---|
| 57 | + return PTR_ERR(ctx->map); |
|---|
| 58 | + } |
|---|
| 63 | 59 | |
|---|
| 64 | 60 | if (of_property_read_u32(pdev->dev.of_node, "offset", &ctx->offset)) |
|---|
| 65 | 61 | return -EINVAL; |
|---|
| 66 | 62 | |
|---|
| 67 | | - if (of_property_read_u32(pdev->dev.of_node, "mask", &ctx->mask)) |
|---|
| 63 | + value_err = of_property_read_u32(pdev->dev.of_node, "value", &ctx->value); |
|---|
| 64 | + mask_err = of_property_read_u32(pdev->dev.of_node, "mask", &ctx->mask); |
|---|
| 65 | + if (value_err && mask_err) { |
|---|
| 66 | + dev_err(dev, "unable to read 'value' and 'mask'"); |
|---|
| 68 | 67 | return -EINVAL; |
|---|
| 68 | + } |
|---|
| 69 | + |
|---|
| 70 | + if (value_err) { |
|---|
| 71 | + /* support old binding */ |
|---|
| 72 | + ctx->value = ctx->mask; |
|---|
| 73 | + ctx->mask = 0xFFFFFFFF; |
|---|
| 74 | + } else if (mask_err) { |
|---|
| 75 | + /* support value without mask*/ |
|---|
| 76 | + ctx->mask = 0xFFFFFFFF; |
|---|
| 77 | + } |
|---|
| 69 | 78 | |
|---|
| 70 | 79 | ctx->restart_handler.notifier_call = syscon_restart_handle; |
|---|
| 71 | 80 | ctx->restart_handler.priority = 192; |
|---|