uapi/if_ether.h: move __UAPI_DEF_ETHHDR libc define
[linux/fpc-iii.git] / drivers / reset / reset-stm32.c
blob3a7c8527e66afc26ecc1098aafecf28919bedcb1
1 /*
2 * Copyright (C) Maxime Coquelin 2015
3 * Author: Maxime Coquelin <mcoquelin.stm32@gmail.com>
4 * License terms: GNU General Public License (GPL), version 2
6 * Heavily based on sunxi driver from Maxime Ripard.
7 */
9 #include <linux/err.h>
10 #include <linux/io.h>
11 #include <linux/of.h>
12 #include <linux/of_address.h>
13 #include <linux/platform_device.h>
14 #include <linux/reset-controller.h>
15 #include <linux/slab.h>
16 #include <linux/spinlock.h>
17 #include <linux/types.h>
19 struct stm32_reset_data {
20 spinlock_t lock;
21 void __iomem *membase;
22 struct reset_controller_dev rcdev;
25 static int stm32_reset_assert(struct reset_controller_dev *rcdev,
26 unsigned long id)
28 struct stm32_reset_data *data = container_of(rcdev,
29 struct stm32_reset_data,
30 rcdev);
31 int bank = id / BITS_PER_LONG;
32 int offset = id % BITS_PER_LONG;
33 unsigned long flags;
34 u32 reg;
36 spin_lock_irqsave(&data->lock, flags);
38 reg = readl(data->membase + (bank * 4));
39 writel(reg | BIT(offset), data->membase + (bank * 4));
41 spin_unlock_irqrestore(&data->lock, flags);
43 return 0;
46 static int stm32_reset_deassert(struct reset_controller_dev *rcdev,
47 unsigned long id)
49 struct stm32_reset_data *data = container_of(rcdev,
50 struct stm32_reset_data,
51 rcdev);
52 int bank = id / BITS_PER_LONG;
53 int offset = id % BITS_PER_LONG;
54 unsigned long flags;
55 u32 reg;
57 spin_lock_irqsave(&data->lock, flags);
59 reg = readl(data->membase + (bank * 4));
60 writel(reg & ~BIT(offset), data->membase + (bank * 4));
62 spin_unlock_irqrestore(&data->lock, flags);
64 return 0;
67 static const struct reset_control_ops stm32_reset_ops = {
68 .assert = stm32_reset_assert,
69 .deassert = stm32_reset_deassert,
72 static const struct of_device_id stm32_reset_dt_ids[] = {
73 { .compatible = "st,stm32-rcc", },
74 { /* sentinel */ },
77 static int stm32_reset_probe(struct platform_device *pdev)
79 struct stm32_reset_data *data;
80 struct resource *res;
82 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
83 if (!data)
84 return -ENOMEM;
86 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
87 data->membase = devm_ioremap_resource(&pdev->dev, res);
88 if (IS_ERR(data->membase))
89 return PTR_ERR(data->membase);
91 spin_lock_init(&data->lock);
93 data->rcdev.owner = THIS_MODULE;
94 data->rcdev.nr_resets = resource_size(res) * 8;
95 data->rcdev.ops = &stm32_reset_ops;
96 data->rcdev.of_node = pdev->dev.of_node;
98 return devm_reset_controller_register(&pdev->dev, &data->rcdev);
101 static struct platform_driver stm32_reset_driver = {
102 .probe = stm32_reset_probe,
103 .driver = {
104 .name = "stm32-rcc-reset",
105 .of_match_table = stm32_reset_dt_ids,
108 builtin_platform_driver(stm32_reset_driver);