On 24. 04. 25 9:57 odp., Andrew Lunn wrote:
On Thu, Apr 24, 2025 at 09:53:39PM +0200, Ivan Vecera wrote:
On 24. 04. 25 9:18 odp., Andrew Lunn wrote:
During taking 613cbb91e9ce ("media: Add MIPI CCI register access helper
functions") approach I found they are using for these functions u64
regardless of register size... Just to accommodate the biggest
possible value. I know about weakness of 'void *' usage but u64 is not
also ideal as the caller is forced to pass always 8 bytes for reading
and forced to reserve 8 bytes for each read value on stack.
In this device, how are the u48s used? Are they actually u48s, or are
they just u8[6], for example a MAC address? The network stack has lots
of functions like:
eth_hw_addr_set(struct net_device *dev, const u8 *addr)
u48 registers always represent 48bit integer... they read from device using
bulk read as big-endian 48bit int. The same is valid also for u16
and u32.
Then a u64 makes sense, plus on write to hardware a check the upper
bits are 0. These u48s are going to be stored in a u64 anyway, since C
does not have a u48 type.
Just note that some of 48bit registers uses signed values so the check
should be:
x is in <S48_MIN, U48_MAX>
this could be done using bit operations:
(!(GENMASK_ULL(63, 49) & ((u64)(x) + BIT_ULL(47))))
Ivan