Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2014 Marvell Technology Group Ltd.
0003  *
0004  * Marvell Berlin reset driver
0005  *
0006  * Antoine Tenart <antoine.tenart@free-electrons.com>
0007  * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
0008  *
0009  * This file is licensed under the terms of the GNU General Public
0010  * License version 2. This program is licensed "as is" without any
0011  * warranty of any kind, whether express or implied.
0012  */
0013 
0014 #include <linux/delay.h>
0015 #include <linux/io.h>
0016 #include <linux/mfd/syscon.h>
0017 #include <linux/module.h>
0018 #include <linux/of.h>
0019 #include <linux/of_address.h>
0020 #include <linux/platform_device.h>
0021 #include <linux/regmap.h>
0022 #include <linux/reset-controller.h>
0023 #include <linux/slab.h>
0024 #include <linux/types.h>
0025 
0026 #define BERLIN_MAX_RESETS   32
0027 
0028 #define to_berlin_reset_priv(p)     \
0029     container_of((p), struct berlin_reset_priv, rcdev)
0030 
0031 struct berlin_reset_priv {
0032     struct regmap           *regmap;
0033     struct reset_controller_dev rcdev;
0034 };
0035 
0036 static int berlin_reset_reset(struct reset_controller_dev *rcdev,
0037                   unsigned long id)
0038 {
0039     struct berlin_reset_priv *priv = to_berlin_reset_priv(rcdev);
0040     int offset = id >> 8;
0041     int mask = BIT(id & 0x1f);
0042 
0043     regmap_write(priv->regmap, offset, mask);
0044 
0045     /* let the reset be effective */
0046     udelay(10);
0047 
0048     return 0;
0049 }
0050 
0051 static const struct reset_control_ops berlin_reset_ops = {
0052     .reset  = berlin_reset_reset,
0053 };
0054 
0055 static int berlin_reset_xlate(struct reset_controller_dev *rcdev,
0056                   const struct of_phandle_args *reset_spec)
0057 {
0058     unsigned int offset, bit;
0059 
0060     offset = reset_spec->args[0];
0061     bit = reset_spec->args[1];
0062 
0063     if (bit >= BERLIN_MAX_RESETS)
0064         return -EINVAL;
0065 
0066     return (offset << 8) | bit;
0067 }
0068 
0069 static int berlin2_reset_probe(struct platform_device *pdev)
0070 {
0071     struct device_node *parent_np = of_get_parent(pdev->dev.of_node);
0072     struct berlin_reset_priv *priv;
0073 
0074     priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
0075     if (!priv)
0076         return -ENOMEM;
0077 
0078     priv->regmap = syscon_node_to_regmap(parent_np);
0079     of_node_put(parent_np);
0080     if (IS_ERR(priv->regmap))
0081         return PTR_ERR(priv->regmap);
0082 
0083     priv->rcdev.owner = THIS_MODULE;
0084     priv->rcdev.ops = &berlin_reset_ops;
0085     priv->rcdev.of_node = pdev->dev.of_node;
0086     priv->rcdev.of_reset_n_cells = 2;
0087     priv->rcdev.of_xlate = berlin_reset_xlate;
0088 
0089     return reset_controller_register(&priv->rcdev);
0090 }
0091 
0092 static const struct of_device_id berlin_reset_dt_match[] = {
0093     { .compatible = "marvell,berlin2-reset" },
0094     { },
0095 };
0096 MODULE_DEVICE_TABLE(of, berlin_reset_dt_match);
0097 
0098 static struct platform_driver berlin_reset_driver = {
0099     .probe  = berlin2_reset_probe,
0100     .driver = {
0101         .name = "berlin2-reset",
0102         .of_match_table = berlin_reset_dt_match,
0103     },
0104 };
0105 module_platform_driver(berlin_reset_driver);
0106 
0107 MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
0108 MODULE_AUTHOR("Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>");
0109 MODULE_DESCRIPTION("Synaptics Berlin reset controller");
0110 MODULE_LICENSE("GPL");