linux/drivers/clk/clk-gate.c
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
   3 * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org>
   4 *
   5 * This program is free software; you can redistribute it and/or modify
   6 * it under the terms of the GNU General Public License version 2 as
   7 * published by the Free Software Foundation.
   8 *
   9 * Gated clock implementation
  10 */
  11
  12#include <linux/clk-provider.h>
  13#include <linux/module.h>
  14#include <linux/slab.h>
  15#include <linux/io.h>
  16#include <linux/err.h>
  17#include <linux/string.h>
  18
  19/**
  20 * DOC: basic gatable clock which can gate and ungate it's ouput
  21 *
  22 * Traits of this clock:
  23 * prepare - clk_(un)prepare only ensures parent is (un)prepared
  24 * enable - clk_enable and clk_disable are functional & control gating
  25 * rate - inherits rate from parent.  No clk_set_rate support
  26 * parent - fixed parent.  No clk_set_parent support
  27 */
  28
  29#define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
  30
  31/*
  32 * It works on following logic:
  33 *
  34 * For enabling clock, enable = 1
  35 *      set2dis = 1     -> clear bit    -> set = 0
  36 *      set2dis = 0     -> set bit      -> set = 1
  37 *
  38 * For disabling clock, enable = 0
  39 *      set2dis = 1     -> set bit      -> set = 1
  40 *      set2dis = 0     -> clear bit    -> set = 0
  41 *
  42 * So, result is always: enable xor set2dis.
  43 */
  44static void clk_gate_endisable(struct clk_hw *hw, int enable)
  45{
  46        struct clk_gate *gate = to_clk_gate(hw);
  47        int set = gate->flags & fLK_u6nTE]kvT_TO_DISABLE/a> &?1  : 0
  348/a>        iunsignd plog ca href="+code=flags" class="sref">flags &= 0
  349/a>        ia href="+code=fu2" class="lref">fu2freg/a><
  45
  451/a>        ia href="+code=fet" class="sref">set =^ enable)
  452/a>
  453/a>        inf gate->gock,/a>)
  454/a>        i       ia href="+code=fepin_ock,_irqsav" class="sref">gepin_ock,_irqsav"/a>(gate->gock,/a>) flags ;
  455/a>
  456/a>        ia href="+code=freg class="lref">freg/a><= freadl/a>(gate->freg/a><;
  457/a>
  358/a>        inf set 
  359/a>        i       ia href="+code=freg class="lref">freg/a><=| fBIT/a>(gate->git _idx/a><;
  460/a>        ielse  461/a>        i       ia href="+code=freg class="lref">freg/a><=amp; = ~a href="+code=gBIT class="lref">fBIT/a>(gate->git _idx/a><;
  462/a>
  463/a>        ia href="+code=fwritel class="lref">fwritel/a>(freg/a>< gate->freg/a><;
  464/a>
  465/a>        inf gate->gock,/a>)
  466/a>        i       ia href="+code=fepin_unock,_irqrestor" class="sref">gepin_unock,_irqrestor"/a>(gate->gock,/a>) flags ;
  467/a>
}  36
  369/a>static vnt clk_gate_endble(struct clk_hw *hw,
  470/a>{
  471/a>        ia href="+code=flk_gate_endisable" class="sref">clk_gate_endisable(sa href="+code=hw" class="sref">hw, i1;
  472/a>
  473/a>        ieturn f0
  474/a>
}  475/a>
  476/a>static void clk_gate_eisable(struct clk_hw *hw,
  477/a>{
  378/a>        ia href="+code=flk_gate_endisable" class="sref">clk_gate_endisable(sa href="+code=hw" class="sref">hw, i0;
  379/a>
}  48
  481/a>static vnt clk_gate_eisendble(struct clk_hw *hw,
  482/a>{
  483/a>        ia href="+code=fu2" class="lref">fu2freg/a><
  484/a>        itruct clk_gate *gate = to_clk_gate(hw);
  485/a>
  486/a>        ia href="+code=freg class="lref">freg/a><= freadl/a>(gate->freg/a><;
  487/a>
  388/a>        iapan class="comment">/*
  389/a>        inf gate->flags & fLK_u6nTE]kvT_TO_DISABLE/a> 
  490/a>        i       ia href="+code=freg class="lref">freg/a><=^ fBIT/a>(gate->git _idx/a><;
  49
  492/a>        ia href="+code=freg class="lref">freg/a><=amp; = a href="+code=gBIT class="lref">fBIT/a>(gate->git _idx/a><;
  493/a>
  494/a>        ieturn fa href="+code=freg class="lref">freg/a><=?1  : 0
  495/a>
}  496/a>
  497/a>
constitruct flk_gop"/a>flk_gate_eop"/a><= <
  398/a>        i.a href="+code=gnable" class="sref">enable)= clk_gate_endble(,  399/a>        i.a href="+code=gisable" class="sref">cisable(= clk_gate_eisable(,  0""/a>        i.a href="+code=gisendblecisendble(= clk_gate_eisendble(,
}
cEXPORT_SYMBOL_GPL/a>(flk_gate_eop"/a><;

 **
 *  lk_gregistergate_ - register asate_ lock whiththe Flock wfrme=orks/span>
 *  @dev: devicethea is aregisterng chis clock:/span>
 * p@ame=:name=of this clock:/span>
 * F@arent _ame=:name=of this clock:#39;s oarent /span>
 *  @lags<:wfrme=orks-specific lags< forthis clock:/span>
  10 */ @reg: register addressthocontrol gating
  01 *< @it _idx:which cit  inthe Fregister ontrol sgating
  11 * S@lk_gate_elags<:wate_-specific lags< forthis clock:/span>
  11 * p@ock:< shred
  11 * 
  15#truct flk_/a> *flk_gregistergate_/a>(struct cievice/a> *ciev/a>, iconstichre*came=/a>(,  116/a>        i       iconstichre*carent _ame=/a>, iunsignd plog ca href="+code=flags" class="sref">flags ,  117/a>        i       ioid f__iomem/a> *freg/a>< fu8/a>git _idx/a><,  118/a>        i       ia href="+code=hu8 class="lref">fu8/a>flk_gate_elags ,ia href="+code=fepinock,_" class="sref">sepinock,_"/a> *gock,/a>)
  19<
  12"/a>        itruct clk_gate *gate 
  121/a>        itruct flk_/a> *flk_/a> 
  122/a>        itruct clk_gint _data/a>cint /a> 
  123/a>
  124/a>        iapan class="comment">/*
  125/a>        ia href="+code=gate" class="sref">gate = gkzalock/a>(stizeofstruct clk_gate ),ia href="+code=fGFP_KERNEL class="sref">cGFP_KERNEL/a><;
  126/a>        inf gate )<
  127/a>        i       ia href="+code=gar_err class="sref">car_err/a>("#397;<:wcould notialockte_ ate. clk_\n"/span>
,ia href="+code=f__unct__ class="sref">f__unct__/a><;
  128/a>        i       ieturn fa href="+code=fERR_PTR class="sref">cERR_PTR/a>(<-a href="+code=fENOMEM class="sref">cENOMEM/a><;
  129/a>        i}  10
  131/a>        ia href="+code=fint  class="sref">cint /a> .a href="+code=game= class="sref">came=/a>(= came=/a>(
  132/a>        ia href="+code=fint  class="sref">cint /a> .a href="+code=gop" class="sref">fop"/a><= flk_gate_eop"/a><
  133/a>        ia href="+code=fint  class="sref">cint /a> .a href="+code=glags" class="sref">flags &= a href="+code=glags" class="sref">flags &|fLK_uIS_BASIC/a><
  134/a>        ia href="+code=fint  class="sref">cint /a> .a href="+code=garent _ame=" class="sref">farent _ame="/a> &= carent _ame=/a>, ?carent _ame=/a>,:ia href="+code=fNULL class="sref">cNULL/a><;
  135/a>        ia href="+code=gint  class="sref">cint /a> .a href="+code=gaumparent " class="sref">faumparent "/a> &= carent _ame=/a>, ?<  : 0;
  136/a>
  137/a>        iapan class="comment">/*
  138/a>        ia href="+code=fate" class="sref">gate->freg/a><= freg/a><
  139/a>        ia href="+code=fate" class="sref">gate->git _idx/a><= git _idx/a><
  140/a>        ia href="+code=fate" class="sref">gate->flags &= a href="+code=glk_gate_elags< class="sref">flk_gate_elags 
  141/a>        ia href="+code=fate" class="sref">gate->gock,/a>)&= a href="+code=gock, class="sref">gock,/a>)
  142/a>        ia href="+code=fate" class="sref">gate->hw).a href="+code=gint  class="sref">cint /a> = cint /a> 
  143/a>
  144/a>        ia href="+code=flk_ class="sref">flk_/a> *= a href="+code=glk_gregister class="sref">flk_gregister/a>(ciev/a>, iamp; a href="+code=hate" class="sref">gate->hw);
  145/a>
  146/a>        inf hIS_ERR/a>(flk_/a> )
  147/a>        i       ia href="+code=gkree  class="sref">gkree /a>(gate )
  14
  149/a>        ieturn fa href="+code=flk_ class="sref">flk_/a> 
  15
}  151/a> 
 

/div>

LXRsommeunt y/a>, ihis cexperientatlversion 2y ta href="dmailto:lxrlinaux.no>goxrlinaux.no/a>). /div> div ilass="lsubfooter > oxr.inaux.no kindly hostd by ta href="dhttp://www.redpill-inapro.no>gRedpillLinapro AS/a>, irovider.of tLnauxiconsuling