Home | History | Annotate | Line # | Download | only in clk
clk.c revision 1.3
      1 /* $NetBSD: clk.c,v 1.3 2018/04/01 21:11:01 bouyer Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: clk.c,v 1.3 2018/04/01 21:11:01 bouyer Exp $");
     31 
     32 #include <sys/param.h>
     33 
     34 #include <dev/clk/clk.h>
     35 #include <dev/clk/clk_backend.h>
     36 
     37 struct clk *
     38 clk_get(struct clk_domain *domain, const char *name)
     39 {
     40 	return domain->funcs->get(domain->priv, name);
     41 }
     42 
     43 void
     44 clk_put(struct clk *clk)
     45 {
     46 	return clk->domain->funcs->put(clk->domain->priv, clk);
     47 }
     48 
     49 u_int
     50 clk_get_rate(struct clk *clk)
     51 {
     52 	return clk->domain->funcs->get_rate(clk->domain->priv, clk);
     53 }
     54 
     55 int
     56 clk_set_rate(struct clk *clk, u_int rate)
     57 {
     58 	if (clk->flags & CLK_SET_RATE_PARENT) {
     59 		return clk_set_rate(clk_get_parent(clk), rate);
     60 	} else if (clk->domain->funcs->set_rate) {
     61 		return clk->domain->funcs->set_rate(clk->domain->priv,
     62 		    clk, rate);
     63 	} else {
     64 		return EINVAL;
     65 	}
     66 }
     67 
     68 u_int
     69 clk_round_rate(struct clk *clk, u_int rate)
     70 {
     71 	if (clk->domain->funcs->round_rate) {
     72 		return clk->domain->funcs->round_rate(clk->domain->priv,
     73 		    clk, rate);
     74 	}
     75 	return 0;
     76 }
     77 
     78 int
     79 clk_enable(struct clk *clk)
     80 {
     81 	if (clk->domain->funcs->enable)
     82 		return clk->domain->funcs->enable(clk->domain->priv, clk);
     83 	else
     84 		return 0;
     85 }
     86 
     87 int
     88 clk_disable(struct clk *clk)
     89 {
     90 	if (clk->domain->funcs->disable)
     91 		return clk->domain->funcs->disable(clk->domain->priv, clk);
     92 	else
     93 		return EINVAL;
     94 }
     95 
     96 int
     97 clk_set_parent(struct clk *clk, struct clk *parent_clk)
     98 {
     99 	if (clk->domain->funcs->set_parent)
    100 		return clk->domain->funcs->set_parent(clk->domain->priv,
    101 		    clk, parent_clk);
    102 	else
    103 		return EINVAL;
    104 }
    105 
    106 struct clk *
    107 clk_get_parent(struct clk *clk)
    108 {
    109 	return clk->domain->funcs->get_parent(clk->domain->priv, clk);
    110 }
    111