Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / drivers / reset / hisilicon / hi6220_reset.c
blob8f55fd4a263057428005ba92ca5e4d0eb407456d
1 /*
2 * Hisilicon Hi6220 reset controller driver
4 * Copyright (c) 2015 Hisilicon Limited.
6 * Author: Feng Chen <puck.chen@hisilicon.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/io.h>
14 #include <linux/init.h>
15 #include <linux/module.h>
16 #include <linux/bitops.h>
17 #include <linux/of.h>
18 #include <linux/reset-controller.h>
19 #include <linux/reset.h>
20 #include <linux/platform_device.h>
22 #define ASSERT_OFFSET 0x300
23 #define DEASSERT_OFFSET 0x304
24 #define MAX_INDEX 0x509
26 #define to_reset_data(x) container_of(x, struct hi6220_reset_data, rc_dev)
28 struct hi6220_reset_data {
29 void __iomem *assert_base;
30 void __iomem *deassert_base;
31 struct reset_controller_dev rc_dev;
34 static int hi6220_reset_assert(struct reset_controller_dev *rc_dev,
35 unsigned long idx)
37 struct hi6220_reset_data *data = to_reset_data(rc_dev);
39 int bank = idx >> 8;
40 int offset = idx & 0xff;
42 writel(BIT(offset), data->assert_base + (bank * 0x10));
44 return 0;
47 static int hi6220_reset_deassert(struct reset_controller_dev *rc_dev,
48 unsigned long idx)
50 struct hi6220_reset_data *data = to_reset_data(rc_dev);
52 int bank = idx >> 8;
53 int offset = idx & 0xff;
55 writel(BIT(offset), data->deassert_base + (bank * 0x10));
57 return 0;
60 static const struct reset_control_ops hi6220_reset_ops = {
61 .assert = hi6220_reset_assert,
62 .deassert = hi6220_reset_deassert,
65 static int hi6220_reset_probe(struct platform_device *pdev)
67 struct hi6220_reset_data *data;
68 struct resource *res;
69 void __iomem *src_base;
71 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
72 if (!data)
73 return -ENOMEM;
75 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
76 src_base = devm_ioremap_resource(&pdev->dev, res);
77 if (IS_ERR(src_base))
78 return PTR_ERR(src_base);
80 data->assert_base = src_base + ASSERT_OFFSET;
81 data->deassert_base = src_base + DEASSERT_OFFSET;
82 data->rc_dev.nr_resets = MAX_INDEX;
83 data->rc_dev.ops = &hi6220_reset_ops;
84 data->rc_dev.of_node = pdev->dev.of_node;
86 return reset_controller_register(&data->rc_dev);
89 static const struct of_device_id hi6220_reset_match[] = {
90 { .compatible = "hisilicon,hi6220-sysctrl" },
91 { },
94 static struct platform_driver hi6220_reset_driver = {
95 .probe = hi6220_reset_probe,
96 .driver = {
97 .name = "reset-hi6220",
98 .of_match_table = hi6220_reset_match,
102 static int __init hi6220_reset_init(void)
104 return platform_driver_register(&hi6220_reset_driver);
107 postcore_initcall(hi6220_reset_init);