xiaoxiang781216 commented on code in PR #16798:
URL: https://github.com/apache/nuttx/pull/16798#discussion_r2265195846


##########
arch/arm64/src/imx9/imx9_clockconfig.c:
##########
@@ -176,6 +181,136 @@ static int pll_pfd_init(uintptr_t reg, int pfd, struct 
pfd_parms_s *pfdparm)
 #endif /* CONFIG_IMX9_CFG_PLLS */
 #endif
 
+#ifdef CONFIG_IMX9_CLK_OVER_SCMI
+
+/****************************************************************************
+ * Name: imx9_sm_getipfreq
+ *
+ * Description:
+ *   This function get the clock rate
+ *
+ * Input Parameters:
+ *  clk - The clock to be get the rate
+ *
+ * Returned Value:
+ *   rate is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+static int imx9_sm_getipfreq(scmi_clock_t *clk)
+{
+  scmi_clock_rate_t rate =
+    {
+      0, 0
+    };
+
+  uint32_t channel  = clk->channel;
+  uint32_t clock_id = clk->clk_id;
+  uint32_t pclk_id  = clk->pclk_id;
+  int status        = 0;

Review Comment:
   int status;



##########
arch/arm64/src/imx9/imx9_clockconfig.c:
##########
@@ -514,6 +649,131 @@ int imx9_get_clock(int clkname, uint32_t *frequency)
   return OK;
 }
 
+#endif /* CONFIG_IMX9_CLK_OVER_SCMI */
+
+#ifdef CONFIG_IMX9_CLK_OVER_SCMI
+/****************************************************************************
+ * Name: imx9_configure_clock
+ *
+ * Description:
+ *   This function config and enable the clock
+ *
+ * Input Parameters:
+ *   config  - The clock config
+ *   enabled - If enable the clock
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+int imx9_configure_clock(clock_config_t config, bool enabled)
+{
+  scmi_clock_t clk =
+    {
+      0
+    };
+
+  clk.clk_id  = GET_ROOT(config) + ROOT_CLOCK_OFFSET;
+  clk.pclk_id = GET_ID(config);
+  clk.channel = SCMI_PLATFORM_A2P;
+  clk.div     = GET_DIV(config);
+
+  if (clk.div == 0)
+    {
+      /* Make sure div is always 1 */
+
+      clk.div = 1;
+    }
+
+  clk.attributes = SCMI_CLOCK_CONFIG_SET_ENABLE(enabled);
+  clk.flags      = SCMI_CLOCK_RATE_FLAGS_ROUND(SCMI_CLOCK_ROUND_AUTO);
+
+  return imx9_sm_setrootclock(&clk);
+}
+
+/****************************************************************************
+ * Name: imx9_get_rootclock
+ *
+ * Description:
+ *   This function returns the clock frequency of the specified root
+ *   functional clock.
+ *
+ * Input Parameters:
+ *   clkroot   - Identifies the peripheral clock of interest
+ *   frequency - The location where the peripheral clock frequency will be
+ *              returned
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+int imx9_get_rootclock(int clkroot, uint32_t *frequency)
+{
+  if (clkroot <= CCM_CR_COUNT)
+    {
+      uint32_t ret = 0;
+
+      scmi_clock_t clk =
+        {
+          0
+        };
+
+      clk.clk_id  = (uint32_t)(clkroot + ROOT_CLOCK_OFFSET);
+      clk.channel = SCMI_PLATFORM_A2P;
+
+      ret = imx9_sm_getipfreq(&clk);
+
+      if (ret < 0)
+        {
+          return -ENODEV;

Review Comment:
   return ret;



##########
arch/arm64/src/imx9/imx9_clockconfig.c:
##########
@@ -514,6 +649,131 @@ int imx9_get_clock(int clkname, uint32_t *frequency)
   return OK;
 }
 
+#endif /* CONFIG_IMX9_CLK_OVER_SCMI */
+
+#ifdef CONFIG_IMX9_CLK_OVER_SCMI
+/****************************************************************************
+ * Name: imx9_configure_clock
+ *
+ * Description:
+ *   This function config and enable the clock
+ *
+ * Input Parameters:
+ *   config  - The clock config
+ *   enabled - If enable the clock
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+int imx9_configure_clock(clock_config_t config, bool enabled)
+{
+  scmi_clock_t clk =
+    {
+      0
+    };
+
+  clk.clk_id  = GET_ROOT(config) + ROOT_CLOCK_OFFSET;
+  clk.pclk_id = GET_ID(config);
+  clk.channel = SCMI_PLATFORM_A2P;
+  clk.div     = GET_DIV(config);
+
+  if (clk.div == 0)
+    {
+      /* Make sure div is always 1 */
+
+      clk.div = 1;
+    }
+
+  clk.attributes = SCMI_CLOCK_CONFIG_SET_ENABLE(enabled);
+  clk.flags      = SCMI_CLOCK_RATE_FLAGS_ROUND(SCMI_CLOCK_ROUND_AUTO);
+
+  return imx9_sm_setrootclock(&clk);
+}
+
+/****************************************************************************
+ * Name: imx9_get_rootclock
+ *
+ * Description:
+ *   This function returns the clock frequency of the specified root
+ *   functional clock.
+ *
+ * Input Parameters:
+ *   clkroot   - Identifies the peripheral clock of interest
+ *   frequency - The location where the peripheral clock frequency will be
+ *              returned
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+int imx9_get_rootclock(int clkroot, uint32_t *frequency)
+{
+  if (clkroot <= CCM_CR_COUNT)
+    {
+      uint32_t ret = 0;

Review Comment:
   int ret;



##########
arch/arm64/src/imx9/imx9_scmi.h:
##########
@@ -29,6 +29,7 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
+#include "hardware/imx95/imx95_memorymap.h"

Review Comment:
   remove, dup



##########
arch/arm64/src/imx9/imx9_clockconfig.c:
##########
@@ -176,6 +181,136 @@ static int pll_pfd_init(uintptr_t reg, int pfd, struct 
pfd_parms_s *pfdparm)
 #endif /* CONFIG_IMX9_CFG_PLLS */
 #endif
 
+#ifdef CONFIG_IMX9_CLK_OVER_SCMI
+
+/****************************************************************************
+ * Name: imx9_sm_getipfreq
+ *
+ * Description:
+ *   This function get the clock rate
+ *
+ * Input Parameters:
+ *  clk - The clock to be get the rate
+ *
+ * Returned Value:
+ *   rate is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+static int imx9_sm_getipfreq(scmi_clock_t *clk)
+{
+  scmi_clock_rate_t rate =
+    {
+      0, 0
+    };
+
+  uint32_t channel  = clk->channel;
+  uint32_t clock_id = clk->clk_id;
+  uint32_t pclk_id  = clk->pclk_id;
+  int status        = 0;
+
+  status = imx9_scmi_get_clock_parent(channel, clock_id, &pclk_id);
+  if (status < 0)
+    {
+      return status;
+    }
+
+  status = imx9_scmi_get_clock_rate(channel, clock_id, &rate);
+  if (status < 0)
+    {
+      return status;
+    }
+
+  return rate.lower;
+}
+
+/****************************************************************************
+ * Name: imx9_sm_setrootclock
+ *
+ * Description:
+ *   This function set root for clock
+ *
+ * Input Parameters:
+ *  clk - The clock to be set root
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+static int imx9_sm_setrootclock(scmi_clock_t *clk)
+{
+  scmi_clock_rate_t rate =
+    {
+      0, 0
+    };
+
+  uint32_t channel        = clk->channel;
+  uint32_t clock_id       = clk->clk_id;
+  uint32_t pclk_id        = clk->pclk_id;
+  uint32_t div            = clk->div;
+  uint32_t attributes     = clk->attributes;
+  uint32_t oem_config_val = clk->oem_config_val;
+  uint32_t flags          = clk->flags;
+  uint32_t old_pclk_id    = 0; /* parent clock id */
+  uint64_t src_rate, root_rate;
+  int32_t status = -1;
+
+  if (div == 0)
+    {
+      return -EINVAL;
+    }
+
+  status = imx9_scmi_get_clock_parent(channel, clock_id, &old_pclk_id);
+  if (status != 0)
+    {
+      return status;
+    }
+
+  if (old_pclk_id != pclk_id)
+    {
+      status = imx9_scmi_set_clock_parent(channel, clock_id, pclk_id);
+      if (status != 0)
+        {
+          return status;
+        }
+    }
+
+  status = imx9_scmi_get_clock_rate(channel, pclk_id, &rate);
+  if (status != 0)
+    {
+      return status;
+    }
+
+  src_rate = rate.upper;
+  src_rate = (src_rate << 32);
+  src_rate |= rate.lower;
+
+  root_rate = src_rate / div;
+
+  rate.lower = root_rate & SCMI_CLOCK_RATE_MASK;
+  rate.upper = (root_rate >> 32) & SCMI_CLOCK_RATE_MASK;
+
+  status = imx9_scmi_set_clock_rate(channel, clock_id, flags, rate);
+  if (status != 0)
+    {
+      return status;
+    }
+
+  status = imx9_scmi_set_clock_config(channel, clock_id, attributes,
+                                    oem_config_val);

Review Comment:
   align



##########
arch/arm64/src/imx9/imx9_clockconfig.c:
##########
@@ -514,6 +649,131 @@ int imx9_get_clock(int clkname, uint32_t *frequency)
   return OK;
 }
 
+#endif /* CONFIG_IMX9_CLK_OVER_SCMI */
+
+#ifdef CONFIG_IMX9_CLK_OVER_SCMI
+/****************************************************************************
+ * Name: imx9_configure_clock
+ *
+ * Description:
+ *   This function config and enable the clock
+ *
+ * Input Parameters:
+ *   config  - The clock config
+ *   enabled - If enable the clock
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+int imx9_configure_clock(clock_config_t config, bool enabled)
+{
+  scmi_clock_t clk =
+    {
+      0
+    };
+
+  clk.clk_id  = GET_ROOT(config) + ROOT_CLOCK_OFFSET;
+  clk.pclk_id = GET_ID(config);
+  clk.channel = SCMI_PLATFORM_A2P;
+  clk.div     = GET_DIV(config);
+
+  if (clk.div == 0)
+    {
+      /* Make sure div is always 1 */
+
+      clk.div = 1;
+    }
+
+  clk.attributes = SCMI_CLOCK_CONFIG_SET_ENABLE(enabled);
+  clk.flags      = SCMI_CLOCK_RATE_FLAGS_ROUND(SCMI_CLOCK_ROUND_AUTO);
+
+  return imx9_sm_setrootclock(&clk);
+}
+
+/****************************************************************************
+ * Name: imx9_get_rootclock
+ *
+ * Description:
+ *   This function returns the clock frequency of the specified root
+ *   functional clock.
+ *
+ * Input Parameters:
+ *   clkroot   - Identifies the peripheral clock of interest
+ *   frequency - The location where the peripheral clock frequency will be
+ *              returned
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+int imx9_get_rootclock(int clkroot, uint32_t *frequency)
+{
+  if (clkroot <= CCM_CR_COUNT)

Review Comment:
   if (clkroot < CCM_CR_COUNT)



##########
arch/arm64/src/imx9/hardware/imx95/imx95_iomuxc.h:
##########
@@ -0,0 +1,810 @@
+/****************************************************************************
+ * arch/arm64/src/imx9/hardware/imx95/imx95_iomuxc.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * SPDX-FileCopyrightText: 2024 NXP
+ *
+ * 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.
+ *
+ ****************************************************************************/
+

Review Comment:
   no change



##########
arch/arm64/src/imx9/imx9_clockconfig.c:
##########
@@ -176,6 +181,136 @@ static int pll_pfd_init(uintptr_t reg, int pfd, struct 
pfd_parms_s *pfdparm)
 #endif /* CONFIG_IMX9_CFG_PLLS */
 #endif
 
+#ifdef CONFIG_IMX9_CLK_OVER_SCMI
+
+/****************************************************************************
+ * Name: imx9_sm_getipfreq
+ *
+ * Description:
+ *   This function get the clock rate
+ *
+ * Input Parameters:
+ *  clk - The clock to be get the rate
+ *
+ * Returned Value:
+ *   rate is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+static int imx9_sm_getipfreq(scmi_clock_t *clk)
+{
+  scmi_clock_rate_t rate =
+    {
+      0, 0
+    };
+
+  uint32_t channel  = clk->channel;
+  uint32_t clock_id = clk->clk_id;
+  uint32_t pclk_id  = clk->pclk_id;
+  int status        = 0;
+
+  status = imx9_scmi_get_clock_parent(channel, clock_id, &pclk_id);
+  if (status < 0)
+    {
+      return status;
+    }
+
+  status = imx9_scmi_get_clock_rate(channel, clock_id, &rate);
+  if (status < 0)
+    {
+      return status;
+    }
+
+  return rate.lower;
+}
+
+/****************************************************************************
+ * Name: imx9_sm_setrootclock
+ *
+ * Description:
+ *   This function set root for clock
+ *
+ * Input Parameters:
+ *  clk - The clock to be set root
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+static int imx9_sm_setrootclock(scmi_clock_t *clk)
+{
+  scmi_clock_rate_t rate =
+    {
+      0, 0
+    };
+
+  uint32_t channel        = clk->channel;
+  uint32_t clock_id       = clk->clk_id;
+  uint32_t pclk_id        = clk->pclk_id;
+  uint32_t div            = clk->div;
+  uint32_t attributes     = clk->attributes;
+  uint32_t oem_config_val = clk->oem_config_val;
+  uint32_t flags          = clk->flags;
+  uint32_t old_pclk_id    = 0; /* parent clock id */
+  uint64_t src_rate, root_rate;
+  int32_t status = -1;

Review Comment:
   int status;



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to