u-boot/drivers/clk/sophgo/clk-common.h
Yao Zi 02933626c7 clk: sophgo: Fix return values of register updating helpers
These helpers wrongly return the updated register value. As a non-zero
value indicates failure, this causes various clock operations are
considered failed.

Correct the return value to constant zero, since these simple MMIO
operations won't fail. This fixes clock enabling failures during booting
process,

	In:    serial@4140000
	Out:   serial@4140000
	Err:   serial@4140000
	Net:   Enable clock-controller@3002000 failed
	failed to enable clock 0
	No ethernet found.

which leads to misoperation of various peripherals.

Fixes: 5f364e072e ("clk: sophgo: cv1800b: Add clock controller driver for cv1800b SoC")
Tested-by: Yuguo Pei <purofle@gmail.com>
Signed-off-by: Yao Zi <ziyao@disroot.org>
2025-03-25 12:13:42 +08:00

77 lines
1.7 KiB
C

/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
*
*/
#ifndef __CLK_SOPHGO_COMMON_H__
#define __CLK_SOPHGO_COMMON_H__
#include <linux/bitops.h>
#include <linux/io.h>
#define CV1800B_CLK_OSC 1
#define CV1800B_CLK_BYPASS 2
#define CV1800B_CLK_ID_TRANSFORM(_id) ((_id) + 3)
struct cv1800b_clk_regbit {
u32 offset;
u8 shift;
};
struct cv1800b_clk_regfield {
u32 offset;
u8 shift;
u8 width;
};
#define CV1800B_CLK_REGBIT(_offset, _shift) \
{ \
.offset = _offset, \
.shift = _shift, \
}
#define CV1800B_CLK_REGFIELD(_offset, _shift, _width) \
{ \
.offset = _offset, \
.shift = _shift, \
.width = _width, \
}
static inline u32 cv1800b_clk_getbit(void *base, struct cv1800b_clk_regbit *bit)
{
return readl(base + bit->offset) & (BIT(bit->shift));
}
static inline u32 cv1800b_clk_setbit(void *base, struct cv1800b_clk_regbit *bit)
{
setbits_le32(base + bit->offset, BIT(bit->shift));
return 0;
}
static inline u32 cv1800b_clk_clrbit(void *base, struct cv1800b_clk_regbit *bit)
{
clrbits_le32(base + bit->offset, BIT(bit->shift));
return 0;
}
static inline u32 cv1800b_clk_getfield(void *base,
struct cv1800b_clk_regfield *field)
{
u32 mask = GENMASK(field->shift + field->width - 1, field->shift);
return (readl(base + field->offset) & mask) >> field->shift;
}
static inline void
cv1800b_clk_setfield(void *base, struct cv1800b_clk_regfield *field, u32 val)
{
u32 mask = GENMASK(field->shift + field->width - 1, field->shift);
u32 new_val = (readl(base + field->offset) & ~mask) |
((val << field->shift) & mask);
return writel(new_val, base + field->offset);
}
#endif /* __CLK_SOPHGO_COMMON_H__ */