Merge branch 'mini2440-dev-unlikely' into mini2440-dev
[linux-2.6/mini2440.git] / drivers / net / stmmac / stmmac_timer.c
blobb838c6582077b0a345e4858fa1f509fb24cb0681
1 /*******************************************************************************
2 STMMAC external timer support.
4 Copyright (C) 2007-2009 STMicroelectronics Ltd
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
23 *******************************************************************************/
25 #include <linux/kernel.h>
26 #include <linux/etherdevice.h>
27 #include "stmmac_timer.h"
29 static void stmmac_timer_handler(void *data)
31 struct net_device *dev = (struct net_device *)data;
33 stmmac_schedule(dev);
35 return;
38 #define STMMAC_TIMER_MSG(timer, freq) \
39 printk(KERN_INFO "stmmac_timer: %s Timer ON (freq %dHz)\n", timer, freq);
41 #if defined(CONFIG_STMMAC_RTC_TIMER)
42 #include <linux/rtc.h>
43 static struct rtc_device *stmmac_rtc;
44 static rtc_task_t stmmac_task;
46 static void stmmac_rtc_start(unsigned int new_freq)
48 rtc_irq_set_freq(stmmac_rtc, &stmmac_task, new_freq);
49 rtc_irq_set_state(stmmac_rtc, &stmmac_task, 1);
50 return;
53 static void stmmac_rtc_stop(void)
55 rtc_irq_set_state(stmmac_rtc, &stmmac_task, 0);
56 return;
59 int stmmac_open_ext_timer(struct net_device *dev, struct stmmac_timer *tm)
61 stmmac_task.private_data = dev;
62 stmmac_task.func = stmmac_timer_handler;
64 stmmac_rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
65 if (stmmac_rtc == NULL) {
66 pr_error("open rtc device failed\n");
67 return -ENODEV;
70 rtc_irq_register(stmmac_rtc, &stmmac_task);
72 /* Periodic mode is not supported */
73 if ((rtc_irq_set_freq(stmmac_rtc, &stmmac_task, tm->freq) < 0)) {
74 pr_error("set periodic failed\n");
75 rtc_irq_unregister(stmmac_rtc, &stmmac_task);
76 rtc_class_close(stmmac_rtc);
77 return -1;
80 STMMAC_TIMER_MSG(CONFIG_RTC_HCTOSYS_DEVICE, tm->freq);
82 tm->timer_start = stmmac_rtc_start;
83 tm->timer_stop = stmmac_rtc_stop;
85 return 0;
88 int stmmac_close_ext_timer(void)
90 rtc_irq_set_state(stmmac_rtc, &stmmac_task, 0);
91 rtc_irq_unregister(stmmac_rtc, &stmmac_task);
92 rtc_class_close(stmmac_rtc);
93 return 0;
96 #elif defined(CONFIG_STMMAC_TMU_TIMER)
97 #include <linux/clk.h>
98 #define TMU_CHANNEL "tmu2_clk"
99 static struct clk *timer_clock;
101 static void stmmac_tmu_start(unsigned int new_freq)
103 clk_set_rate(timer_clock, new_freq);
104 clk_enable(timer_clock);
105 return;
108 static void stmmac_tmu_stop(void)
110 clk_disable(timer_clock);
111 return;
114 int stmmac_open_ext_timer(struct net_device *dev, struct stmmac_timer *tm)
116 timer_clock = clk_get(NULL, TMU_CHANNEL);
118 if (timer_clock == NULL)
119 return -1;
121 if (tmu2_register_user(stmmac_timer_handler, (void *)dev) < 0) {
122 timer_clock = NULL;
123 return -1;
126 STMMAC_TIMER_MSG("TMU2", tm->freq);
127 tm->timer_start = stmmac_tmu_start;
128 tm->timer_stop = stmmac_tmu_stop;
130 return 0;
133 int stmmac_close_ext_timer(void)
135 clk_disable(timer_clock);
136 tmu2_unregister_user();
137 clk_put(timer_clock);
138 return 0;
140 #endif