Antoine Ténart | bd13251 | 2014-09-03 09:48:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Marvell Technology Group Ltd. |
| 3 | * |
Paul Gortmaker | ed4dba9 | 2016-06-13 14:03:34 -0400 | [diff] [blame] | 4 | * Marvell Berlin reset driver |
| 5 | * |
Antoine Ténart | bd13251 | 2014-09-03 09:48:20 +0200 | [diff] [blame] | 6 | * Antoine Tenart <antoine.tenart@free-electrons.com> |
| 7 | * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> |
| 8 | * |
| 9 | * This file is licensed under the terms of the GNU General Public |
| 10 | * License version 2. This program is licensed "as is" without any |
| 11 | * warranty of any kind, whether express or implied. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/io.h> |
Antoine Tenart | aed6f3c | 2015-05-16 00:41:25 +0200 | [diff] [blame] | 16 | #include <linux/mfd/syscon.h> |
Paul Gortmaker | ed4dba9 | 2016-06-13 14:03:34 -0400 | [diff] [blame] | 17 | #include <linux/init.h> |
Antoine Ténart | bd13251 | 2014-09-03 09:48:20 +0200 | [diff] [blame] | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_address.h> |
| 20 | #include <linux/platform_device.h> |
Antoine Tenart | aed6f3c | 2015-05-16 00:41:25 +0200 | [diff] [blame] | 21 | #include <linux/regmap.h> |
Antoine Ténart | bd13251 | 2014-09-03 09:48:20 +0200 | [diff] [blame] | 22 | #include <linux/reset-controller.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/types.h> |
| 25 | |
| 26 | #define BERLIN_MAX_RESETS 32 |
| 27 | |
| 28 | #define to_berlin_reset_priv(p) \ |
| 29 | container_of((p), struct berlin_reset_priv, rcdev) |
| 30 | |
| 31 | struct berlin_reset_priv { |
Antoine Tenart | aed6f3c | 2015-05-16 00:41:25 +0200 | [diff] [blame] | 32 | struct regmap *regmap; |
Antoine Ténart | bd13251 | 2014-09-03 09:48:20 +0200 | [diff] [blame] | 33 | struct reset_controller_dev rcdev; |
| 34 | }; |
| 35 | |
| 36 | static int berlin_reset_reset(struct reset_controller_dev *rcdev, |
| 37 | unsigned long id) |
| 38 | { |
| 39 | struct berlin_reset_priv *priv = to_berlin_reset_priv(rcdev); |
| 40 | int offset = id >> 8; |
| 41 | int mask = BIT(id & 0x1f); |
| 42 | |
Antoine Tenart | bfff629 | 2015-05-16 00:53:44 +0200 | [diff] [blame] | 43 | regmap_write(priv->regmap, offset, mask); |
Antoine Ténart | bd13251 | 2014-09-03 09:48:20 +0200 | [diff] [blame] | 44 | |
| 45 | /* let the reset be effective */ |
| 46 | udelay(10); |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
Philipp Zabel | b7a9007 | 2016-01-17 15:12:48 +0100 | [diff] [blame] | 51 | static const struct reset_control_ops berlin_reset_ops = { |
Antoine Ténart | bd13251 | 2014-09-03 09:48:20 +0200 | [diff] [blame] | 52 | .reset = berlin_reset_reset, |
| 53 | }; |
| 54 | |
| 55 | static int berlin_reset_xlate(struct reset_controller_dev *rcdev, |
| 56 | const struct of_phandle_args *reset_spec) |
| 57 | { |
Antoine Ténart | bd13251 | 2014-09-03 09:48:20 +0200 | [diff] [blame] | 58 | unsigned offset, bit; |
| 59 | |
Antoine Ténart | bd13251 | 2014-09-03 09:48:20 +0200 | [diff] [blame] | 60 | offset = reset_spec->args[0]; |
| 61 | bit = reset_spec->args[1]; |
| 62 | |
Antoine Ténart | bd13251 | 2014-09-03 09:48:20 +0200 | [diff] [blame] | 63 | if (bit >= BERLIN_MAX_RESETS) |
| 64 | return -EINVAL; |
| 65 | |
| 66 | return (offset << 8) | bit; |
| 67 | } |
| 68 | |
Antoine Tenart | aed6f3c | 2015-05-16 00:41:25 +0200 | [diff] [blame] | 69 | static int berlin2_reset_probe(struct platform_device *pdev) |
| 70 | { |
| 71 | struct device_node *parent_np = of_get_parent(pdev->dev.of_node); |
| 72 | struct berlin_reset_priv *priv; |
| 73 | |
| 74 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
| 75 | if (!priv) |
| 76 | return -ENOMEM; |
| 77 | |
| 78 | priv->regmap = syscon_node_to_regmap(parent_np); |
| 79 | of_node_put(parent_np); |
| 80 | if (IS_ERR(priv->regmap)) |
| 81 | return PTR_ERR(priv->regmap); |
| 82 | |
| 83 | priv->rcdev.owner = THIS_MODULE; |
| 84 | priv->rcdev.ops = &berlin_reset_ops; |
| 85 | priv->rcdev.of_node = pdev->dev.of_node; |
| 86 | priv->rcdev.of_reset_n_cells = 2; |
| 87 | priv->rcdev.of_xlate = berlin_reset_xlate; |
| 88 | |
Masahiro Yamada | d1f15aa | 2015-11-05 14:54:56 +0900 | [diff] [blame] | 89 | return reset_controller_register(&priv->rcdev); |
Antoine Tenart | aed6f3c | 2015-05-16 00:41:25 +0200 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static const struct of_device_id berlin_reset_dt_match[] = { |
| 93 | { .compatible = "marvell,berlin2-reset" }, |
| 94 | { }, |
| 95 | }; |
Antoine Tenart | aed6f3c | 2015-05-16 00:41:25 +0200 | [diff] [blame] | 96 | |
| 97 | static struct platform_driver berlin_reset_driver = { |
| 98 | .probe = berlin2_reset_probe, |
| 99 | .driver = { |
| 100 | .name = "berlin2-reset", |
| 101 | .of_match_table = berlin_reset_dt_match, |
| 102 | }, |
| 103 | }; |
Paul Gortmaker | ed4dba9 | 2016-06-13 14:03:34 -0400 | [diff] [blame] | 104 | builtin_platform_driver(berlin_reset_driver); |