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

reset: socfpga: use the reset-simple driver

Add reset line status readback, inverted status support, and socfpga
device tree quirks to the simple reset driver, and use it to replace
the socfpga driver.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>

+56 -167
+2 -8
drivers/reset/Kconfig
··· 77 77 78 78 config RESET_SIMPLE 79 79 bool "Simple Reset Controller Driver" if COMPILE_TEST 80 - default ARCH_SUNXI 80 + default ARCH_SOCFPGA || ARCH_STRATIX10 || ARCH_SUNXI 81 81 help 82 82 This enables a simple reset controller driver for reset lines that 83 83 that can be asserted and deasserted by toggling bits in a contiguous, 84 84 exclusive register space. 85 85 86 - Currently this driver supports Allwinner SoCs. 87 - 88 - config RESET_SOCFPGA 89 - bool "SoCFPGA Reset Driver" if COMPILE_TEST 90 - default ARCH_SOCFPGA || ARCH_STRATIX10 91 - help 92 - This enables the reset controller driver for Altera SoCFPGAs. 86 + Currently this driver supports Altera SoCFPGAs and Allwinner SoCs. 93 87 94 88 config RESET_STM32 95 89 bool "STM32 Reset Driver" if COMPILE_TEST
-1
drivers/reset/Makefile
··· 13 13 obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o 14 14 obj-$(CONFIG_RESET_PISTACHIO) += reset-pistachio.o 15 15 obj-$(CONFIG_RESET_SIMPLE) += reset-simple.o 16 - obj-$(CONFIG_RESET_SOCFPGA) += reset-socfpga.o 17 16 obj-$(CONFIG_RESET_STM32) += reset-stm32.o 18 17 obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o 19 18 obj-$(CONFIG_RESET_TI_SCI) += reset-ti-sci.o
+50 -1
drivers/reset/reset-simple.c
··· 68 68 return reset_simple_update(rcdev, id, false); 69 69 } 70 70 71 + static int reset_simple_status(struct reset_controller_dev *rcdev, 72 + unsigned long id) 73 + { 74 + struct reset_simple_data *data = to_reset_simple_data(rcdev); 75 + int reg_width = sizeof(u32); 76 + int bank = id / (reg_width * BITS_PER_BYTE); 77 + int offset = id % (reg_width * BITS_PER_BYTE); 78 + u32 reg; 79 + 80 + reg = readl(data->membase + (bank * reg_width)); 81 + 82 + return !(reg & BIT(offset)) ^ !data->status_active_low; 83 + } 84 + 71 85 const struct reset_control_ops reset_simple_ops = { 72 86 .assert = reset_simple_assert, 73 87 .deassert = reset_simple_deassert, 88 + .status = reset_simple_status, 74 89 }; 75 90 76 91 /** 77 92 * struct reset_simple_devdata - simple reset controller properties 93 + * @reg_offset: offset between base address and first reset register. 94 + * @nr_resets: number of resets. If not set, default to resource size in bits. 78 95 * @active_low: if true, bits are cleared to assert the reset. Otherwise, bits 79 96 * are set to assert the reset. 97 + * @status_active_low: if true, bits read back as cleared while the reset is 98 + * asserted. Otherwise, bits read back as set while the 99 + * reset is asserted. 80 100 */ 81 101 struct reset_simple_devdata { 102 + u32 reg_offset; 103 + u32 nr_resets; 82 104 bool active_low; 105 + bool status_active_low; 106 + }; 107 + 108 + #define SOCFPGA_NR_BANKS 8 109 + 110 + static const struct reset_simple_devdata reset_simple_socfpga = { 111 + .reg_offset = 0x10, 112 + .nr_resets = SOCFPGA_NR_BANKS * 32, 113 + .status_active_low = true, 83 114 }; 84 115 85 116 static const struct reset_simple_devdata reset_simple_active_low = { 86 117 .active_low = true, 118 + .status_active_low = true, 87 119 }; 88 120 89 121 static const struct of_device_id reset_simple_dt_ids[] = { 122 + { .compatible = "altr,rst-mgr", .data = &reset_simple_socfpga }, 90 123 { .compatible = "allwinner,sun6i-a31-clock-reset", 91 124 .data = &reset_simple_active_low }, 92 125 { /* sentinel */ }, ··· 132 99 struct reset_simple_data *data; 133 100 void __iomem *membase; 134 101 struct resource *res; 102 + u32 reg_offset = 0; 135 103 136 104 devdata = of_device_get_match_data(dev); 137 105 ··· 152 118 data->rcdev.ops = &reset_simple_ops; 153 119 data->rcdev.of_node = dev->of_node; 154 120 155 - if (devdata) 121 + if (devdata) { 122 + reg_offset = devdata->reg_offset; 123 + if (devdata->nr_resets) 124 + data->rcdev.nr_resets = devdata->nr_resets; 156 125 data->active_low = devdata->active_low; 126 + data->status_active_low = devdata->status_active_low; 127 + } 128 + 129 + if (of_device_is_compatible(dev->of_node, "altr,rst-mgr") && 130 + of_property_read_u32(dev->of_node, "altr,modrst-offset", 131 + &reg_offset)) { 132 + dev_warn(dev, 133 + "missing altr,modrst-offset property, assuming 0x%x!\n", 134 + reg_offset); 135 + } 136 + 137 + data->membase += reg_offset; 157 138 158 139 return devm_reset_controller_register(dev, &data->rcdev); 159 140 }
+4
drivers/reset/reset-simple.h
··· 28 28 * @active_low: if true, bits are cleared to assert the reset. Otherwise, bits 29 29 * are set to assert the reset. Note that this says nothing about 30 30 * the voltage level of the actual reset line. 31 + * @status_active_low: if true, bits read back as cleared while the reset is 32 + * asserted. Otherwise, bits read back as set while the 33 + * reset is asserted. 31 34 */ 32 35 struct reset_simple_data { 33 36 spinlock_t lock; 34 37 void __iomem *membase; 35 38 struct reset_controller_dev rcdev; 36 39 bool active_low; 40 + bool status_active_low; 37 41 }; 38 42 39 43 extern const struct reset_control_ops reset_simple_ops;
-157
drivers/reset/reset-socfpga.c
··· 1 - /* 2 - * Socfpga Reset Controller Driver 3 - * 4 - * Copyright 2014 Steffen Trumtrar <s.trumtrar@pengutronix.de> 5 - * 6 - * based on 7 - * Allwinner SoCs Reset Controller driver 8 - * 9 - * Copyright 2013 Maxime Ripard 10 - * 11 - * Maxime Ripard <maxime.ripard@free-electrons.com> 12 - * 13 - * This program is free software; you can redistribute it and/or modify 14 - * it under the terms of the GNU General Public License as published by 15 - * the Free Software Foundation; either version 2 of the License, or 16 - * (at your option) any later version. 17 - */ 18 - 19 - #include <linux/err.h> 20 - #include <linux/io.h> 21 - #include <linux/init.h> 22 - #include <linux/of.h> 23 - #include <linux/platform_device.h> 24 - #include <linux/reset-controller.h> 25 - #include <linux/spinlock.h> 26 - #include <linux/types.h> 27 - 28 - #define BANK_INCREMENT 4 29 - #define NR_BANKS 8 30 - 31 - struct socfpga_reset_data { 32 - spinlock_t lock; 33 - void __iomem *membase; 34 - struct reset_controller_dev rcdev; 35 - }; 36 - 37 - static int socfpga_reset_assert(struct reset_controller_dev *rcdev, 38 - unsigned long id) 39 - { 40 - struct socfpga_reset_data *data = container_of(rcdev, 41 - struct socfpga_reset_data, 42 - rcdev); 43 - int reg_width = sizeof(u32); 44 - int bank = id / (reg_width * BITS_PER_BYTE); 45 - int offset = id % (reg_width * BITS_PER_BYTE); 46 - unsigned long flags; 47 - u32 reg; 48 - 49 - spin_lock_irqsave(&data->lock, flags); 50 - 51 - reg = readl(data->membase + (bank * BANK_INCREMENT)); 52 - writel(reg | BIT(offset), data->membase + (bank * BANK_INCREMENT)); 53 - spin_unlock_irqrestore(&data->lock, flags); 54 - 55 - return 0; 56 - } 57 - 58 - static int socfpga_reset_deassert(struct reset_controller_dev *rcdev, 59 - unsigned long id) 60 - { 61 - struct socfpga_reset_data *data = container_of(rcdev, 62 - struct socfpga_reset_data, 63 - rcdev); 64 - 65 - int reg_width = sizeof(u32); 66 - int bank = id / (reg_width * BITS_PER_BYTE); 67 - int offset = id % (reg_width * BITS_PER_BYTE); 68 - unsigned long flags; 69 - u32 reg; 70 - 71 - spin_lock_irqsave(&data->lock, flags); 72 - 73 - reg = readl(data->membase + (bank * BANK_INCREMENT)); 74 - writel(reg & ~BIT(offset), data->membase + (bank * BANK_INCREMENT)); 75 - 76 - spin_unlock_irqrestore(&data->lock, flags); 77 - 78 - return 0; 79 - } 80 - 81 - static int socfpga_reset_status(struct reset_controller_dev *rcdev, 82 - unsigned long id) 83 - { 84 - struct socfpga_reset_data *data = container_of(rcdev, 85 - struct socfpga_reset_data, rcdev); 86 - int reg_width = sizeof(u32); 87 - int bank = id / (reg_width * BITS_PER_BYTE); 88 - int offset = id % (reg_width * BITS_PER_BYTE); 89 - u32 reg; 90 - 91 - reg = readl(data->membase + (bank * BANK_INCREMENT)); 92 - 93 - return !(reg & BIT(offset)); 94 - } 95 - 96 - static const struct reset_control_ops socfpga_reset_ops = { 97 - .assert = socfpga_reset_assert, 98 - .deassert = socfpga_reset_deassert, 99 - .status = socfpga_reset_status, 100 - }; 101 - 102 - static int socfpga_reset_probe(struct platform_device *pdev) 103 - { 104 - struct socfpga_reset_data *data; 105 - struct resource *res; 106 - struct device *dev = &pdev->dev; 107 - struct device_node *np = dev->of_node; 108 - u32 modrst_offset; 109 - 110 - /* 111 - * The binding was mainlined without the required property. 112 - * Do not continue, when we encounter an old DT. 113 - */ 114 - if (!of_find_property(pdev->dev.of_node, "#reset-cells", NULL)) { 115 - dev_err(&pdev->dev, "%pOF missing #reset-cells property\n", 116 - pdev->dev.of_node); 117 - return -EINVAL; 118 - } 119 - 120 - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 121 - if (!data) 122 - return -ENOMEM; 123 - 124 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 125 - data->membase = devm_ioremap_resource(&pdev->dev, res); 126 - if (IS_ERR(data->membase)) 127 - return PTR_ERR(data->membase); 128 - 129 - if (of_property_read_u32(np, "altr,modrst-offset", &modrst_offset)) { 130 - dev_warn(dev, "missing altr,modrst-offset property, assuming 0x10!\n"); 131 - modrst_offset = 0x10; 132 - } 133 - data->membase += modrst_offset; 134 - 135 - spin_lock_init(&data->lock); 136 - 137 - data->rcdev.owner = THIS_MODULE; 138 - data->rcdev.nr_resets = NR_BANKS * (sizeof(u32) * BITS_PER_BYTE); 139 - data->rcdev.ops = &socfpga_reset_ops; 140 - data->rcdev.of_node = pdev->dev.of_node; 141 - 142 - return devm_reset_controller_register(dev, &data->rcdev); 143 - } 144 - 145 - static const struct of_device_id socfpga_reset_dt_ids[] = { 146 - { .compatible = "altr,rst-mgr", }, 147 - { /* sentinel */ }, 148 - }; 149 - 150 - static struct platform_driver socfpga_reset_driver = { 151 - .probe = socfpga_reset_probe, 152 - .driver = { 153 - .name = "socfpga-reset", 154 - .of_match_table = socfpga_reset_dt_ids, 155 - }, 156 - }; 157 - builtin_platform_driver(socfpga_reset_driver);