Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

reset: Add Sunplus SP7021 reset driver

Add reset driver for Sunplus SP7021 SoC.

Signed-off-by: Qin Jian <qinjian@cqplus1.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

authored by

Qin Jian and committed by
Arnd Bergmann
dbf018be 55bfc376

+223
+1
MAINTAINERS
··· 2832 2832 W: https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview 2833 2833 F: Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml 2834 2834 F: Documentation/devicetree/bindings/reset/sunplus,reset.yaml 2835 + F: drivers/reset/reset-sunplus.c 2835 2836 F: include/dt-bindings/reset/sunplus,sp7021-reset.h 2836 2837 2837 2838 ARM/Synaptics SoC support
+9
drivers/reset/Kconfig
··· 231 231 help 232 232 This enables the reset controller driver for the StarFive JH7100 SoC. 233 233 234 + config RESET_SUNPLUS 235 + bool "Sunplus SoCs Reset Driver" if COMPILE_TEST 236 + default ARCH_SUNPLUS 237 + help 238 + This enables the reset driver support for Sunplus SoCs. 239 + The reset lines that can be asserted and deasserted by toggling bits 240 + in a contiguous, exclusive register space. The register is HIWORD_MASKED, 241 + which means each register holds 16 reset lines. 242 + 234 243 config RESET_SUNXI 235 244 bool "Allwinner SoCs Reset Driver" if COMPILE_TEST && !ARCH_SUNXI 236 245 default ARCH_SUNXI
+1
drivers/reset/Makefile
··· 30 30 obj-$(CONFIG_RESET_SIMPLE) += reset-simple.o 31 31 obj-$(CONFIG_RESET_SOCFPGA) += reset-socfpga.o 32 32 obj-$(CONFIG_RESET_STARFIVE_JH7100) += reset-starfive-jh7100.o 33 + obj-$(CONFIG_RESET_SUNPLUS) += reset-sunplus.o 33 34 obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o 34 35 obj-$(CONFIG_RESET_TI_SCI) += reset-ti-sci.o 35 36 obj-$(CONFIG_RESET_TI_SYSCON) += reset-ti-syscon.o
+212
drivers/reset/reset-sunplus.c
··· 1 + // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + /* 3 + * SP7021 reset driver 4 + * 5 + * Copyright (C) Sunplus Technology Co., Ltd. 6 + * All rights reserved. 7 + */ 8 + 9 + #include <linux/io.h> 10 + #include <linux/init.h> 11 + #include <linux/mod_devicetable.h> 12 + #include <linux/platform_device.h> 13 + #include <linux/reset-controller.h> 14 + #include <linux/reboot.h> 15 + 16 + /* HIWORD_MASK_REG BITS */ 17 + #define BITS_PER_HWM_REG 16 18 + 19 + /* resets HW info: reg_index_shift */ 20 + static const u32 sp_resets[] = { 21 + /* SP7021: mo_reset0 ~ mo_reset9 */ 22 + 0x00, 23 + 0x02, 24 + 0x03, 25 + 0x04, 26 + 0x05, 27 + 0x06, 28 + 0x07, 29 + 0x08, 30 + 0x09, 31 + 0x0a, 32 + 0x0b, 33 + 0x0d, 34 + 0x0e, 35 + 0x0f, 36 + 0x10, 37 + 0x12, 38 + 0x14, 39 + 0x15, 40 + 0x16, 41 + 0x17, 42 + 0x18, 43 + 0x19, 44 + 0x1a, 45 + 0x1b, 46 + 0x1c, 47 + 0x1d, 48 + 0x1e, 49 + 0x1f, 50 + 0x20, 51 + 0x21, 52 + 0x22, 53 + 0x23, 54 + 0x24, 55 + 0x25, 56 + 0x26, 57 + 0x2a, 58 + 0x2b, 59 + 0x2d, 60 + 0x2e, 61 + 0x30, 62 + 0x31, 63 + 0x32, 64 + 0x33, 65 + 0x3d, 66 + 0x3e, 67 + 0x3f, 68 + 0x42, 69 + 0x44, 70 + 0x4b, 71 + 0x4c, 72 + 0x4d, 73 + 0x4e, 74 + 0x4f, 75 + 0x50, 76 + 0x55, 77 + 0x60, 78 + 0x61, 79 + 0x6a, 80 + 0x6f, 81 + 0x70, 82 + 0x73, 83 + 0x74, 84 + 0x86, 85 + 0x8a, 86 + 0x8b, 87 + 0x8d, 88 + 0x8e, 89 + 0x8f, 90 + 0x90, 91 + 0x92, 92 + 0x93, 93 + 0x94, 94 + 0x95, 95 + 0x96, 96 + 0x97, 97 + 0x98, 98 + 0x99, 99 + }; 100 + 101 + struct sp_reset { 102 + struct reset_controller_dev rcdev; 103 + struct notifier_block notifier; 104 + void __iomem *base; 105 + }; 106 + 107 + static inline struct sp_reset *to_sp_reset(struct reset_controller_dev *rcdev) 108 + { 109 + return container_of(rcdev, struct sp_reset, rcdev); 110 + } 111 + 112 + static int sp_reset_update(struct reset_controller_dev *rcdev, 113 + unsigned long id, bool assert) 114 + { 115 + struct sp_reset *reset = to_sp_reset(rcdev); 116 + int index = sp_resets[id] / BITS_PER_HWM_REG; 117 + int shift = sp_resets[id] % BITS_PER_HWM_REG; 118 + u32 val; 119 + 120 + val = (1 << (16 + shift)) | (assert << shift); 121 + writel(val, reset->base + (index * 4)); 122 + 123 + return 0; 124 + } 125 + 126 + static int sp_reset_assert(struct reset_controller_dev *rcdev, 127 + unsigned long id) 128 + { 129 + return sp_reset_update(rcdev, id, true); 130 + } 131 + 132 + static int sp_reset_deassert(struct reset_controller_dev *rcdev, 133 + unsigned long id) 134 + { 135 + return sp_reset_update(rcdev, id, false); 136 + } 137 + 138 + static int sp_reset_status(struct reset_controller_dev *rcdev, 139 + unsigned long id) 140 + { 141 + struct sp_reset *reset = to_sp_reset(rcdev); 142 + int index = sp_resets[id] / BITS_PER_HWM_REG; 143 + int shift = sp_resets[id] % BITS_PER_HWM_REG; 144 + u32 reg; 145 + 146 + reg = readl(reset->base + (index * 4)); 147 + 148 + return !!(reg & BIT(shift)); 149 + } 150 + 151 + static const struct reset_control_ops sp_reset_ops = { 152 + .assert = sp_reset_assert, 153 + .deassert = sp_reset_deassert, 154 + .status = sp_reset_status, 155 + }; 156 + 157 + static int sp_restart(struct notifier_block *nb, unsigned long mode, 158 + void *cmd) 159 + { 160 + struct sp_reset *reset = container_of(nb, struct sp_reset, notifier); 161 + 162 + sp_reset_assert(&reset->rcdev, 0); 163 + sp_reset_deassert(&reset->rcdev, 0); 164 + 165 + return NOTIFY_DONE; 166 + } 167 + 168 + static int sp_reset_probe(struct platform_device *pdev) 169 + { 170 + struct device *dev = &pdev->dev; 171 + struct sp_reset *reset; 172 + struct resource *res; 173 + int ret; 174 + 175 + reset = devm_kzalloc(dev, sizeof(*reset), GFP_KERNEL); 176 + if (!reset) 177 + return -ENOMEM; 178 + 179 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 180 + reset->base = devm_ioremap_resource(dev, res); 181 + if (IS_ERR(reset->base)) 182 + return PTR_ERR(reset->base); 183 + 184 + reset->rcdev.ops = &sp_reset_ops; 185 + reset->rcdev.owner = THIS_MODULE; 186 + reset->rcdev.of_node = dev->of_node; 187 + reset->rcdev.nr_resets = resource_size(res) / 4 * BITS_PER_HWM_REG; 188 + 189 + ret = devm_reset_controller_register(dev, &reset->rcdev); 190 + if (ret) 191 + return ret; 192 + 193 + reset->notifier.notifier_call = sp_restart; 194 + reset->notifier.priority = 192; 195 + 196 + return register_restart_handler(&reset->notifier); 197 + } 198 + 199 + static const struct of_device_id sp_reset_dt_ids[] = { 200 + {.compatible = "sunplus,sp7021-reset",}, 201 + { /* sentinel */ }, 202 + }; 203 + 204 + static struct platform_driver sp_reset_driver = { 205 + .probe = sp_reset_probe, 206 + .driver = { 207 + .name = "sunplus-reset", 208 + .of_match_table = sp_reset_dt_ids, 209 + .suppress_bind_attrs = true, 210 + }, 211 + }; 212 + builtin_platform_driver(sp_reset_driver);