blob: 56d134d499be018f615b06fa3af1ebfdb10f284b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*
* drivers/char/mvf_timer_master.c
*
* Copyright (C) 2012 Freescale Semiconductor, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
struct timer_master_control{
int probe_cnt;
int is_opened[ TIMER_MASTER_MAX_TIMER];
#define TIMER_AVAILABLE 0
#define TIMER_BUSY 1
struct platform_device *plat_timerdev[ TIMER_MASTER_MAX_TIMER];
};
static struct timer_master_control master_control;
static int timer_master_is_valid_handle(int index)
{
int val;
val = 0;
// error check
if ( index > TIMER_MASTER_ENUM_AVAILABLE) val = -EINVAL;
return val;
}
static int timer_master_is_opened(int index)
{
int ret;
ret = timer_master_is_valid_handle(index);
if ( ret < 0) return ret;
return master_control.is_opened[index];
}
#if 0
static int timer_master_set_eventhandler( int timer_handle, void (*event_handler)(void))
{
master_control.event_handler[ timer_handle] = event_handler;
return 0;
}
#endif
static struct platform_device *timer_master_get_pdev(int index)
{
return master_control.plat_timerdev[ index];
}
static void timer_master_register_platform(struct platform_device *plat)
{
int index = master_control.probe_cnt;
if (master_control.probe_cnt >= TIMER_MASTER_MAX_TIMER){
printk(KERN_WARNING"Timer regist count overflow\n");
}else{
master_control.plat_timerdev[ index] = plat;
master_control.probe_cnt++;
}
}
static int timer_master_alloc_timer( int index)
{
int i,ret;
ret = timer_master_is_valid_handle( index);
if ( ret < 0) return ret;
ret = -EBUSY;
if ( index == TIMER_MASTER_ENUM_AVAILABLE){
for ( i = 0; i < TIMER_MASTER_MAX_TIMER; i ++){
if ( master_control.is_opened[ i] == TIMER_AVAILABLE){
master_control.is_opened[ i] = TIMER_BUSY;
ret = i;
}
}
}else
if ( master_control.is_opened[ index] == TIMER_AVAILABLE){
master_control.is_opened[ index] = TIMER_BUSY;
ret = index;
}
return ret;
}
static int timer_master_free(int index)
{
int ret;
ret = timer_master_is_valid_handle(index);
if ( ret < 0) return ret;
master_control.is_opened[ index] = TIMER_AVAILABLE;
return 0;
}
|