nuttx/drivers/clk/clk.h
hanzhijian a8f55fbfd8 drivers/clk: use uintptr_t for register addresses
Change the 'reg' field type from uint32_t to uintptr_t in all clock
provider structs (clk_gate_s, clk_divider_s, clk_phase_s,
clk_fractional_divider_s, clk_multiplier_s, clk_mux_s) and their
corresponding clk_register_*() function prototypes.

Also update clk_write() and clk_read() inline functions to take
uintptr_t parameter and remove the now-redundant (uintptr_t) cast.

On 32-bit embedded platforms uintptr_t equals uint32_t so there is
no functional change. On 64-bit targets (e.g. sim) this fixes
-Wint-to-pointer-cast warnings that GCC15 promotes to errors.

Fixes: #16896
Signed-off-by: hanzhijian <hanzhijian@zepp.com>
2026-06-18 21:52:33 +08:00

108 lines
2.8 KiB
C

/****************************************************************************
* drivers/clk/clk.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __DRIVER_CLK_CLK_H
#define __DRIVER_CLK_CLK_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <strings.h>
#include <sys/param.h>
#include <nuttx/bits.h>
#include <nuttx/lib/math32.h>
#ifdef CONFIG_CLK
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define MASK(width) (BIT(width) - 1)
#define MULT_ROUND_UP(r, m) ((r) * (m) + (m) - 1)
/****************************************************************************
* Inline Functions
****************************************************************************/
static inline void clk_write(uintptr_t reg, uint32_t value)
{
*((volatile uint32_t *)reg) = value;
}
static inline uint32_t clk_read(uintptr_t reg)
{
return *((volatile uint32_t *)reg);
}
static inline bool clk_is_best_rate_closest(uint32_t rate, uint32_t now,
uint32_t best)
{
uint32_t rate1 = rate > now ? (rate - now) : (now - rate);
uint32_t rate2 = rate > best ? (rate - best) : (best - rate);
return rate1 < rate2;
}
static inline uint32_t gcd(uint32_t a, uint32_t b)
{
uint32_t r;
uint32_t tmp;
if (a < b)
{
tmp = a;
a = b;
b = tmp;
}
if (!b)
{
return a;
}
while ((r = a % b) != 0)
{
a = b;
b = r;
}
return b;
}
static inline uint32_t roundup_double(double n)
{
uint32_t intn = (uint32_t)n;
if (n == (double)intn)
{
return intn;
}
return intn + 1;
}
#endif /* CONFIG_CLK */
#endif /* __DRIVER_CLK_CLK_H */