Skip to content

Commit

Permalink
drivers/clk: support using clk function at interrupt and idle
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
  • Loading branch information
Donny9 authored and xiaoxiang781216 committed Jul 28, 2023
1 parent 9ef19af commit afec562
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions drivers/clk/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ static struct list_node g_clk_orphan_list
* Private Function Prototypes
****************************************************************************/

static void clk_list_lock(void);
static void clk_list_unlock(void);
static irqstate_t clk_list_lock(void);
static void clk_list_unlock(irqstate_t flags);

static int clk_fetch_parent_index(FAR struct clk_s *clk,
FAR struct clk_s *parent);
Expand Down Expand Up @@ -176,17 +176,17 @@ static size_t clk_procfs_printf(FAR char *buffer, size_t buflen,
return procfs_memcpy(tmp, tmplen, buffer, buflen, pos);
}

static size_t clk_procfs_show_subtree(FAR FAR struct clk_s *clk, int level,
static size_t clk_procfs_show_subtree(FAR struct clk_s *clk, int level,
FAR char *buffer, size_t buflen,
off_t *pos)
off_t *pos, FAR irqstate_t *flags)
{
FAR struct clk_s *child;
size_t oldlen = buflen;
size_t ret;

if (strchr(clk_get_name(clk), '/'))
{
clk_list_unlock();
clk_list_unlock(*flags);
}

ret = clk_procfs_printf(buffer, buflen, pos, "%*s%-*s %11d %11u %11d\n",
Expand All @@ -198,15 +198,15 @@ static size_t clk_procfs_show_subtree(FAR FAR struct clk_s *clk, int level,

if (strchr(clk_get_name(clk), '/'))
{
clk_list_lock();
*flags = clk_list_lock();
}

if (buflen > 0)
{
list_for_every_entry(&clk->children, child, struct clk_s, node)
{
ret = clk_procfs_show_subtree(child, level + 1,
buffer, buflen, pos);
buffer, buflen, pos, flags);
buffer += ret;
buflen -= ret;

Expand All @@ -225,13 +225,14 @@ static size_t clk_procfs_showtree(FAR char *buffer,
{
FAR struct clk_s *clk;
size_t oldlen = buflen;
irqstate_t flags;
size_t ret;

clk_list_lock();
flags = clk_list_lock();

list_for_every_entry(&g_clk_root_list, clk, struct clk_s, node)
{
ret = clk_procfs_show_subtree(clk, 0, buffer, buflen, pos);
ret = clk_procfs_show_subtree(clk, 0, buffer, buflen, pos, &flags);
buffer += ret;
buflen -= ret;

Expand All @@ -243,7 +244,7 @@ static size_t clk_procfs_showtree(FAR char *buffer,

list_for_every_entry(&g_clk_orphan_list, clk, struct clk_s, node)
{
ret = clk_procfs_show_subtree(clk, 0, buffer, buflen, pos);
ret = clk_procfs_show_subtree(clk, 0, buffer, buflen, pos, &flags);
buffer += ret;
buflen -= ret;

Expand All @@ -254,7 +255,7 @@ static size_t clk_procfs_showtree(FAR char *buffer,
}

out:
clk_list_unlock();
clk_list_unlock(flags);
return oldlen - buflen;
}

Expand Down Expand Up @@ -315,14 +316,24 @@ static int clk_procfs_stat(const char *relpath, struct stat *buf)

#endif /* !defined(CONFIG_FS_PROCFS_EXCLUDE_CLK) && defined(CONFIG_FS_PROCFS) */

static void clk_list_lock(void)
static irqstate_t clk_list_lock(void)
{
nxmutex_lock(&g_clk_list_lock);
if (!up_interrupt_context() && !sched_idletask())
{
nxmutex_lock(&g_clk_list_lock);
}

return enter_critical_section();
}

static void clk_list_unlock(void)
static void clk_list_unlock(irqstate_t flags)
{
nxmutex_unlock(&g_clk_list_lock);
leave_critical_section(flags);

if (!up_interrupt_context() && !sched_idletask())
{
nxmutex_unlock(&g_clk_list_lock);
}
}

static int clk_fetch_parent_index(FAR struct clk_s *clk,
Expand Down Expand Up @@ -710,6 +721,7 @@ static int __clk_register(FAR struct clk_s *clk)
{
FAR struct clk_s *orphan;
FAR struct clk_s *temp;
irqstate_t flags;
uint8_t i;

if (!clk)
Expand Down Expand Up @@ -737,7 +749,7 @@ static int __clk_register(FAR struct clk_s *clk)

clk_init_parent(clk);

clk_list_lock();
flags = clk_list_lock();

if (clk->parent)
{
Expand Down Expand Up @@ -776,7 +788,7 @@ static int __clk_register(FAR struct clk_s *clk)
}
}

clk_list_unlock();
clk_list_unlock(flags);
return 0;
}

Expand Down Expand Up @@ -814,8 +826,9 @@ static void clk_disable_unused_subtree(FAR struct clk_s *clk)
void clk_disable_unused(void)
{
FAR struct clk_s *root_clk = NULL;
irqstate_t flags;

clk_list_lock();
flags = clk_list_lock();

list_for_every_entry(&g_clk_root_list, root_clk, struct clk_s, node)
{
Expand All @@ -827,7 +840,7 @@ void clk_disable_unused(void)
clk_disable_unused_subtree(root_clk);
}

clk_list_unlock();
clk_list_unlock(flags);
}

int clk_disable(FAR struct clk_s *clk)
Expand Down Expand Up @@ -982,13 +995,14 @@ FAR struct clk_s *clk_get(FAR const char *name)
{
FAR struct clk_s *root_clk = NULL;
FAR struct clk_s *ret = NULL;
irqstate_t flags;

if (!name)
{
return NULL;
}

clk_list_lock();
flags = clk_list_lock();

list_for_every_entry(&g_clk_root_list, root_clk, struct clk_s, node)
{
Expand All @@ -1009,7 +1023,7 @@ FAR struct clk_s *clk_get(FAR const char *name)
}

out:
clk_list_unlock();
clk_list_unlock(flags);

#ifdef CONFIG_CLK_RPMSG
if (ret == NULL)
Expand Down

0 comments on commit afec562

Please sign in to comment.