reset-stm32.c (06d07429858317ded2db7986113a9e0129cd599b) | reset-stm32.c (fd7a1c90ba4c6e618596eb44a69977801f9cccdd) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) STMicroelectronics 2022 - All Rights Reserved 4 * Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics. 5 */ 6 7#include <linux/of.h> 8#include <linux/platform_device.h> --- 5 unchanged lines hidden (view full) --- 14#include "reset-stm32.h" 15 16struct stm32_reset_data { 17 /* reset lock */ 18 spinlock_t lock; 19 struct reset_controller_dev rcdev; 20 void __iomem *membase; 21 u32 clear_offset; | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) STMicroelectronics 2022 - All Rights Reserved 4 * Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics. 5 */ 6 7#include <linux/of.h> 8#include <linux/platform_device.h> --- 5 unchanged lines hidden (view full) --- 14#include "reset-stm32.h" 15 16struct stm32_reset_data { 17 /* reset lock */ 18 spinlock_t lock; 19 struct reset_controller_dev rcdev; 20 void __iomem *membase; 21 u32 clear_offset; |
22 const struct stm32_reset_cfg **reset_lines; |
|
22}; 23 24static inline struct stm32_reset_data * 25to_stm32_reset_data(struct reset_controller_dev *rcdev) 26{ 27 return container_of(rcdev, struct stm32_reset_data, rcdev); 28} 29 | 23}; 24 25static inline struct stm32_reset_data * 26to_stm32_reset_data(struct reset_controller_dev *rcdev) 27{ 28 return container_of(rcdev, struct stm32_reset_data, rcdev); 29} 30 |
31static const struct stm32_reset_cfg *stm32_get_reset_line(struct reset_controller_dev *rcdev, 32 unsigned long id, 33 struct stm32_reset_cfg *line) 34{ 35 struct stm32_reset_data *data = to_stm32_reset_data(rcdev); 36 37 if (!data->reset_lines) { 38 int reg_width = sizeof(u32); 39 int bank = id / (reg_width * BITS_PER_BYTE); 40 int offset = id % (reg_width * BITS_PER_BYTE); 41 42 line->offset = bank * reg_width; 43 line->bit_idx = offset; 44 line->set_clr = (data->clear_offset ? true : false); 45 46 return line; 47 } 48 49 return data->reset_lines[id]; 50} 51 |
|
30static int stm32_reset_update(struct reset_controller_dev *rcdev, 31 unsigned long id, bool assert) 32{ 33 struct stm32_reset_data *data = to_stm32_reset_data(rcdev); | 52static int stm32_reset_update(struct reset_controller_dev *rcdev, 53 unsigned long id, bool assert) 54{ 55 struct stm32_reset_data *data = to_stm32_reset_data(rcdev); |
34 int reg_width = sizeof(u32); 35 int bank = id / (reg_width * BITS_PER_BYTE); 36 int offset = id % (reg_width * BITS_PER_BYTE); | 56 struct stm32_reset_cfg line_reset; 57 const struct stm32_reset_cfg *ptr_line; |
37 | 58 |
38 if (data->clear_offset) { | 59 ptr_line = stm32_get_reset_line(rcdev, id, &line_reset); 60 if (!ptr_line) 61 return -EPERM; 62 63 if (ptr_line->set_clr) { |
39 void __iomem *addr; 40 | 64 void __iomem *addr; 65 |
41 addr = data->membase + (bank * reg_width); | 66 addr = data->membase + ptr_line->offset; |
42 if (!assert) 43 addr += data->clear_offset; 44 | 67 if (!assert) 68 addr += data->clear_offset; 69 |
45 writel(BIT(offset), addr); | 70 writel(BIT(ptr_line->bit_idx), addr); |
46 47 } else { 48 unsigned long flags; 49 u32 reg; 50 51 spin_lock_irqsave(&data->lock, flags); 52 | 71 72 } else { 73 unsigned long flags; 74 u32 reg; 75 76 spin_lock_irqsave(&data->lock, flags); 77 |
53 reg = readl(data->membase + (bank * reg_width)); | 78 reg = readl(data->membase + ptr_line->offset); |
54 55 if (assert) | 79 80 if (assert) |
56 reg |= BIT(offset); | 81 reg |= BIT(ptr_line->bit_idx); |
57 else | 82 else |
58 reg &= ~BIT(offset); | 83 reg &= ~BIT(ptr_line->bit_idx); |
59 | 84 |
60 writel(reg, data->membase + (bank * reg_width)); | 85 writel(reg, data->membase + ptr_line->offset); |
61 62 spin_unlock_irqrestore(&data->lock, flags); 63 } 64 65 return 0; 66} 67 68static int stm32_reset_assert(struct reset_controller_dev *rcdev, --- 7 unchanged lines hidden (view full) --- 76{ 77 return stm32_reset_update(rcdev, id, false); 78} 79 80static int stm32_reset_status(struct reset_controller_dev *rcdev, 81 unsigned long id) 82{ 83 struct stm32_reset_data *data = to_stm32_reset_data(rcdev); | 86 87 spin_unlock_irqrestore(&data->lock, flags); 88 } 89 90 return 0; 91} 92 93static int stm32_reset_assert(struct reset_controller_dev *rcdev, --- 7 unchanged lines hidden (view full) --- 101{ 102 return stm32_reset_update(rcdev, id, false); 103} 104 105static int stm32_reset_status(struct reset_controller_dev *rcdev, 106 unsigned long id) 107{ 108 struct stm32_reset_data *data = to_stm32_reset_data(rcdev); |
84 int reg_width = sizeof(u32); 85 int bank = id / (reg_width * BITS_PER_BYTE); 86 int offset = id % (reg_width * BITS_PER_BYTE); | 109 struct stm32_reset_cfg line_reset; 110 const struct stm32_reset_cfg *ptr_line; |
87 u32 reg; 88 | 111 u32 reg; 112 |
89 reg = readl(data->membase + (bank * reg_width)); | 113 ptr_line = stm32_get_reset_line(rcdev, id, &line_reset); 114 if (!ptr_line) 115 return -EPERM; |
90 | 116 |
91 return !!(reg & BIT(offset)); | 117 reg = readl(data->membase + ptr_line->offset); 118 119 return !!(reg & BIT(ptr_line->bit_idx)); |
92} 93 94static const struct reset_control_ops stm32_reset_ops = { 95 .assert = stm32_reset_assert, 96 .deassert = stm32_reset_deassert, 97 .status = stm32_reset_status, 98}; 99 --- 8 unchanged lines hidden (view full) --- 108 109 spin_lock_init(&reset_data->lock); 110 111 reset_data->membase = base; 112 reset_data->rcdev.owner = THIS_MODULE; 113 reset_data->rcdev.ops = &stm32_reset_ops; 114 reset_data->rcdev.of_node = dev_of_node(dev); 115 reset_data->rcdev.nr_resets = data->nr_lines; | 120} 121 122static const struct reset_control_ops stm32_reset_ops = { 123 .assert = stm32_reset_assert, 124 .deassert = stm32_reset_deassert, 125 .status = stm32_reset_status, 126}; 127 --- 8 unchanged lines hidden (view full) --- 136 137 spin_lock_init(&reset_data->lock); 138 139 reset_data->membase = base; 140 reset_data->rcdev.owner = THIS_MODULE; 141 reset_data->rcdev.ops = &stm32_reset_ops; 142 reset_data->rcdev.of_node = dev_of_node(dev); 143 reset_data->rcdev.nr_resets = data->nr_lines; |
144 reset_data->reset_lines = data->reset_lines; |
|
116 reset_data->clear_offset = data->clear_offset; 117 118 return reset_controller_register(&reset_data->rcdev); 119} | 145 reset_data->clear_offset = data->clear_offset; 146 147 return reset_controller_register(&reset_data->rcdev); 148} |