Skip to content

Commit 27b0e47

Browse files
Fymytejhedberg
authored andcommitted
drivers: hwspinlock: sqn: add reg-width dts property
The size of each spinlock register might vary depending on the SoC. Make it configurable in the devicetree. Signed-off-by: Pierrick Guillaume <[email protected]>
1 parent 2c86e65 commit 27b0e47

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

drivers/hwspinlock/sqn_hwspinlock.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ struct sqn_hwspinlock_data {
3232

3333
struct sqn_hwspinlock_config {
3434
DEVICE_MMIO_ROM;
35-
uint32_t num_locks;
35+
uint16_t num_locks;
36+
uint16_t reg_width;
3637
};
3738

3839
#define DEV_DATA(dev) ((struct sqn_hwspinlock_data *)dev->data)
@@ -46,7 +47,7 @@ struct sqn_hwspinlock_config {
4647

4748
static inline mem_addr_t get_lock_addr(const struct device *dev, uint32_t id)
4849
{
49-
return (mem_addr_t)(DEVICE_MMIO_GET(dev) + id * sizeof(uint32_t));
50+
return (mem_addr_t)(DEVICE_MMIO_GET(dev) + id * DEV_CFG(dev)->reg_width);
5051
}
5152

5253
static int sqn_hwspinlock_trylock(const struct device *dev, uint32_t id)
@@ -115,6 +116,7 @@ static int sqn_hwspinlock_init(const struct device *dev)
115116
static struct sqn_hwspinlock_data sqn_hwspinlock##idx##_data; \
116117
static const struct sqn_hwspinlock_config sqn_hwspinlock##idx##_config = { \
117118
DEVICE_MMIO_ROM_INIT(DT_DRV_INST(idx)), \
119+
.reg_width = DT_INST_PROP_OR(idx, reg_width, 1), \
118120
.num_locks = DT_INST_PROP(idx, num_locks), \
119121
}; \
120122
DEVICE_DT_INST_DEFINE(idx, sqn_hwspinlock_init, NULL, &sqn_hwspinlock##idx##_data, \

dts/bindings/hwspinlock/sqn,hwspinlock.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,20 @@ properties:
1515
type: int
1616
required: true
1717

18+
reg-width:
19+
type: int
20+
enum:
21+
- 1
22+
- 2
23+
- 4
24+
required: true
25+
description: |
26+
Register width for a single spinlock in bytes.
27+
Depending on the platform, the register used to write the cluster identifier
28+
may vary in size.
29+
- 1: cluster id register fit in a single byte
30+
- 2: cluster id register span across 2 bytes
31+
- 4: cluster id register span across 4 bytes
32+
1833
hwlock-cells:
1934
- id

0 commit comments

Comments
 (0)