linux/drivers/pps/kc.c
<<
n> 2" /spav3. 2" /form3. 2" a n> 2" href="../linux+v3.7.3/drivers/pps/kc.c">n> 2" img src="../.static/gfx/right.png" alt=">>">n> /spav3.n> spav class="lxr_search">n> n> 2" input typ.12hidden" nam.12navtarget" v3.4.12">n> 2" input typ.12text" nam.12search" id12search">n> 2" butt typ.12submit">Search spav class="lxr_prefs"3. 2" a href="+prefs?return=drivers/pps/kc.c"n> 2" onclick="return ajax_prefs();">n> 2"Prefs. 2" /a>n> /spav3. 2" " /div3. 2" " form ace="v="ajax+*" method="post" onsubmit="return false;">n> input typ.12hidden" nam.12ajax_lookup" id12ajax_lookup" v3.4.12">n 2" " /form3.n 2" " div class="headingbott m">. div id12file_contents"3
" "1
/a>
spav class="comment">/*
/spav3." "2
/a>
spav class="comment"> * PPS kernel consumer API
/spav3." "3
/a>
spav class="comment"> *
/spav3." "4
/a>
spav class="comment"> * Copyright (C) 2009-2010" "Alexander Gordeev <lasaine@lvk.cs.msu.su>
/spav3." "5
/a>
spav class="comment"> *
/spav3." "6
/a>
spav class="comment"> *   This program is free software; you cav redistribute it and/or modify
/spav3." "7
/a>
spav class="comment"> *   it under the terms of the GNU General Public License as published by
/spav3." "8
/a>
spav class="comment"> *   the Free Software Foundae="v; either vers>
  2 of the License, or
/spav3." "9
/a>
spav class="comment"> *   (at your lue="v) any later vers>
 .
/spav3." n vaa>
spav class="comment"> *
/spav3." 11
/a>
spav class="comment"> *   This program is distributed in the hope that it will be useful,
/spav3." 12
/a>
spav class="comment"> *   but WITHOUT ANY WARRANTY; without even the implied warranty of
/spav3." 13
/a>
spav class="comment"> *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/spav3." 14
/a>
spav class="comment"> *   GNU General Public License for more details.
/spav3." 15
/a>
spav class="comment"> *
/spav3." 16
/a>
spav class="comment"> *   You should have received a copy of the GNU General Public License
/spav3." 17
/a>
spav class="comment"> *   along with this program; if not, write to the Free Software
/spav3." 18
/a>
spav class="comment"> *   Foundae="v, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
/spav3." 19
/a>
spav class="comment"> */
/spav3." 2 vaa>." 21
/a>#define"
a href="+code=pr_fmt" class="sref">pr_fmt
/a>(
a href="+code=fmt" class="sref">fmt
/a>)"
a href="+code=KBUILD_MODNAME" class="sref">KBUILD_MODNAME
/a> 
spav class="string">": "
/spav3"
a href="+code=fmt" class="sref">fmt
/a>." 22
/a>." 23
/a>#include <linux/kernel.h
/a>>." 24
/a>#include <linux/module.h
/a>>." 25
/a>#include <linux/device.h
/a>>." 26
/a>#include <linux/init.h
/a>>." 27
/a>#include <linux/spinlock.h
/a>>." 28
/a>#include <linux/pps_kernel.h
/a>>." 29
/a>." 30
/a>#include "
a href="drivers/pps/kc.h" class="fref">kc.h
/a>"." 31
/a>." 32
/a>
spav class="comment">/*
/spav3." 33
/a>
spav class="comment"> * Global variables
/spav3." 34
/a>
spav class="comment"> */
/spav3." 35
/a>." 36
/a>
spav class="comment">/* state variables to bind kernel consumer */
/spav3." 37
/a>
a href="+code=DEFINE_SPINLOCK" class="sref">DEFINE_SPINLOCK
/a>(
a href="+code=pps_kc_hardpps_lock" class="sref">pps_kc_hardpps_lock
/a>);." 38
/a>
spav class="comment">/* PPS API (RFC 2783): current source and mode for kernel consumer */
/spav3." 39
/a>struct"
a href="+code=pps_device" class="sref">pps_device
/a> *
a href="+code=pps_kc_hardpps_dev" class="sref">pps_kc_hardpps_dev
/a>;  
spav class="comment">/* unique pointer to device */
/spav3." 40
/a>int"
a href="+code=pps_kc_hardpps_mode" class="sref">pps_kc_hardpps_mode
/a>;                
spav class="comment">/* mode bits for kernel consumer */
/spav3." 41
/a>." 42
/a>
spav class="comment">/* pps_kc_bind - control PPS kernel consumer binding
/spav3." 43
/a>
spav class="comment"> * @pps: the PPS source
/spav3." 44
/a>
spav class="comment"> * @bind_args: kernel consumer bind parameters
/spav3." 45
/a>
spav class="comment"> *
/spav3." 46
/a>
spav class="comment"> * This funce="v is used to bind or unbind PPS kernel consumer according to
/spav3." 47
/a>
spav class="comment"> * supplied parameters. Should not be called in interrupt context.
/spav3." 48
/a>
spav class="comment"> */
/spav3." 49
/a>int"
a href="+code=pps_kc_bind" class="sref">pps_kc_bind
/a>(struct"
a href="+code=pps_device" class="sref">pps_device
/a> *
a href="+code=pps" class="sref">pps
/a>, struct"
a href="+code=pps_bind_args" class="sref">pps_bind_args
/a> *
a href="+code=bind_args" class="sref">bind_args
/a>)." 50
/a>{." 51
/a>        
spav class="comment">/* Check if another consumer is already bound */
/spav3." 52
/a>        
a href="+code=spin_lock_irq" class="sref">spin_lock_irq
/a>(&
a href="+code=pps_kc_hardpps_lock" class="sref">pps_kc_hardpps_lock
/a>);." 53
/a>." 54
/a>        if (
a href="+code=bind_args" class="sref">bind_args
/a>->
a href="+code=edge" class="sref">edge
/a> == 0)." 55
/a>                if (
a href="+code=pps_kc_hardpps_dev" class="sref">pps_kc_hardpps_dev
/a> == 
a href="+code=pps" class="sref">pps
/a>) {." 56
/a>                        
a href="+code=pps_kc_hardpps_mode" class="sref">pps_kc_hardpps_mode
/a> = 0;." 57
/a>                        
a href="+code=pps_kc_hardpps_dev" class="sref">pps_kc_hardpps_dev
/a> = 
a href="+code=NULL" class="sref">NULL
/a>;." 58
/a>                        
a href="+code=spin_unlock_irq" class="sref">spin_unlock_irq
/a>(&
a href="+code=pps_kc_hardpps_lock" class="sref">pps_kc_hardpps_lock
/a>);." 59
/a>                        
a href="+code=dev_info" class="sref">dev_info
/a>(
a href="+code=pps" class="sref">pps
/a>->
a href="+code=dev" class="sref">dev
/a>, 
spav class="string">"unbound kernel"
/spav3." 60
/a>                                        
spav class="string">" consumer\n"
/spav3);." 61
/a>                } else {." 62
/a>                        
a href="+code=spin_unlock_irq" class="sref">spin_unlock_irq
/a>(&
a href="+code=pps_kc_hardpps_lock" class="sref">pps_kc_hardpps_lock
/a>);." 63
/a>                        
a href="+code=dev_err" class="sref">dev_err
/a>(
a href="+code=pps" class="sref">pps
/a>->
a href="+code=dev" class="sref">dev
/a>, 
spav class="string">"selected kernel consumer"
/spav3." 64
/a>                                        
spav class="string">" is not bound\n"
/spav3);." 65
/a>                        return -
a href="+code=EINVAL" class="sref">EINVAL
/a>;." 66
/a>                }." 67
/a>        else." 68
/a>                if (
a href="+code=pps_kc_hardpps_dev" class="sref">pps_kc_hardpps_dev
/a> == 
a href="+code=NULL" class="sref">NULL
/a> ||." 69
/a>                                
a href="+code=pps_kc_hardpps_dev" class="sref">pps_kc_hardpps_dev
/a> == 
a href="+code=pps" class="sref">pps
/a>) {." 70
/a>                        
a href="+code=pps_kc_hardpps_mode" class="sref">pps_kc_hardpps_mode
/a> = 
a href="+code=bind_args" class="sref">bind_args
/a>->
a href="+code=edge" class="sref">edge
/a>;." 71
/a>                        
a href="+code=pps_kc_hardpps_dev" class="sref">pps_kc_hardpps_dev
/a> = 
a href="+code=pps" class="sref">pps
/a>;." 72
/a>                        
a href="+code=spin_unlock_irq" class="sref">spin_unlock_irq
/a>(&
a href="+code=pps_kc_hardpps_lock" class="sref">pps_kc_hardpps_lock
/a>);." 73
/a>                        
a href="+code=dev_info" class="sref">dev_info
/a>(
a href="+code=pps" class="sref">pps
/a>->
a href="+code=dev" class="sref">dev
/a>, 
spav class="string">"bound kernel consumer: "
/spav3." 74
/a>                                
spav class="string">"edge=0x%x\n"
/spav3, 
a href="+code=bind_args" class="sref">bind_args
/a>->
a href="+code=edge" class="sref">edge
/a>);." 75
/a>                } else {." 76
/a>                        
a href="+code=spin_unlock_irq" class="sref">spin_unlock_irq
/a>(&
a href="+code=pps_kc_hardpps_lock" class="sref">pps_kc_hardpps_lock
/a>);." 77
/a>                        
a href="+code=dev_err" class="sref">dev_err
/a>(
a href="+code=pps" class="sref">pps
/a>->
a href="+code=dev" class="sref">dev
/a>, 
spav class="string">"another kernel consumer"
/spav3." 78
/a>                                        
spav class="string">" is already bound\n"
/spav3);." 79
/a>                        return -
a href="+code=EINVAL" class="sref">EINVAL
/a>;." 80
/a>                }." 81
/a>." 82
/a>        return 0;." 83
/a>}." 84
/a>." 85
/a>
spav class="comment">/* pps_kc_remove - unbind kernel consumer on PPS source removal
/spav3." 86
/a>
spav class="comment"> * @pps: the PPS source
/spav3." 87
/a>
spav class="comment"> *
/spav3." 88
/a>
spav class="comment"> * This funce="v is used to disable kernel consumer on PPS source removal
/spav3." 89
/a>
spav class="comment"> * if this source was bound to PPS kernel consumer. Cav be called on any
/spav3." 9 vaa>
spav class="comment"> * source safely. Should not be called in interrupt context.
/spav3." 91
/a>
spav class="comment"> */
/spav3." 92
/a>void 
a href="+code=pps_kc_remove" class="sref">pps_kc_remove
/a>(struct"
a href="+code=pps_device" class="sref">pps_device
/a> *
a href="+code=pps" class="sref">pps
/a>)." 93
/a>{." 94
/a>        
a href="+code=spin_lock_irq" class="sref">spin_lock_irq
/a>(&
a href="+code=pps_kc_hardpps_lock" class="sref">pps_kc_hardpps_lock
/a>);." 95
/a>        if (
a href="+code=pps" class="sref">pps
/a> == 
a href="+code=pps_kc_hardpps_dev" class="sref">pps_kc_hardpps_dev
/a>) {." 96
/a>                
a href="+code=pps_kc_hardpps_mode" class="sref">pps_kc_hardpps_mode
/a> = 0;." 97
/a>                
a href="+code=pps_kc_hardpps_dev" class="sref">pps_kc_hardpps_dev
/a> = 
a href="+code=NULL" class="sref">NULL
/a>;." 98
/a>                
a href="+code=spin_unlock_irq" class="sref">spin_unlock_irq
/a>(&
a href="+code=pps_kc_hardpps_lock" class="sref">pps_kc_hardpps_lock
/a>);." 99
/a>                
a href="+code=dev_info" class="sref">dev_info
/a>(
a href="+code=pps" class="sref">pps
/a>->
a href="+code=dev" class="sref">dev
/a>, 
spav class="string">"unbound kernel consumer"
/spav3."100
/a>                                
spav class="string">" on device removal\n"
/spav3);."101
/a>        } else."102
/a>                
a href="+code=spin_unlock_irq" class="sref">spin_unlock_irq
/a>(&
a href="+code=pps_kc_hardpps_lock" class="sref">pps_kc_hardpps_lock
/a>);."103
/a>}."104
/a>."105
/a>
spav class="comment">/* pps_kc_event - call hardpps() on PPS event
/spav3."106
/a>
spav class="comment"> * @pps: the PPS source
/spav3."107
/a>
spav class="comment"> * @ts: PPS event timestamp
/spav3."108
/a>
spav class="comment"> * @event: PPS event edge
/spav3."109
/a>
spav class="comment"> *
/spav3."1n vaa>
spav class="comment"> * This funce="v calls hardpps() when an event from bound PPS source occurs.
/spav3."111
/a>
spav class="comment"> */
/spav3."112
/a>void 
a href="+code=pps_kc_event" class="sref">pps_kc_event
/a>(struct"
a href="+code=pps_device" class="sref">pps_device
/a> *
a href="+code=pps" class="sref">pps
/a>, struct"
a href="+code=pps_event_time" class="sref">pps_event_time
/a> *
a href="+code=ts" class="sref">ts
/a>,."113
/a>                int"
a href="+code=event" class="sref">event
/a>)."114
/a>{."115
/a>        unsigned long 
a href="+code=flags" class="sref">flags
/a>;."116
/a>."117
/a>        
spav class="comment">/* Pass some events to kernel consumer if ace=vated */
/spav3."118
/a>        
a href="+code=spin_lock_irqsave" class="sref">spin_lock_irqsave
/a>(&
a href="+code=pps_kc_hardpps_lock" class="sref">pps_kc_hardpps_lock
/a>, 
a href="+code=flags" class="sref">flags
/a>);."119
/a>        if (
a href="+code=pps" class="sref">pps
/a> == 
a href="+code=pps_kc_hardpps_dev" class="sref">pps_kc_hardpps_dev
/a> &&"
a href="+code=event" class="sref">event
/a> &"
a href="+code=pps_kc_hardpps_mode" class="sref">pps_kc_hardpps_mode
/a>)."120
/a>                
a href="+code=hardpps" class="sref">hardpps
/a>(&
a href="+code=ts" class="sref">ts
/a>->
a href="+code=ts_real" class="sref">ts_real
/a>, &
a href="+code=ts" class="sref">ts
/a>->
a href="+code=ts_raw" class="sref">ts_raw
/a>);."121
/a>        
a href="+code=spin_unlock_irqrestore" class="sref">spin_unlock_irqrestore
/a>(&
a href="+code=pps_kc_hardpps_lock" class="sref">pps_kc_hardpps_lock
/a>, 
a href="+code=flags" class="sref">flags
/a>);."122
/a>}."123
/a>
The original LXR software by the LXR community /a>, this experimental vers> by lxr@linux.no /a>. /div3. div class="subfooter"> lxr.linux.no kindly hosted by Redpill Linpro AS /a>, provider of Linux consulting and operae="vs services since 1995. /div3. /body3. /html3.