[PATCH 2/7] ICH Force HPET: Restructure hpet generic clock code

2007-06-22 Thread Venki Pallipadi

Restructure and rename legacy replacement mode HPET timer support.
Just the code structural changes and should be zero functionality change.

Signed-off-by: Venkatesh Pallipadi <[EMAIL PROTECTED]>

---

Index: linux-2.6.22-rc5/arch/i386/kernel/hpet.c
===
--- linux-2.6.22-rc5.orig/arch/i386/kernel/hpet.c   2007-06-17 
08:52:09.0 +0200
+++ linux-2.6.22-rc5/arch/i386/kernel/hpet.c2007-06-17 08:52:10.0 
+0200
@@ -158,9 +158,9 @@ static void hpet_reserve_platform_timers
  */
 static unsigned long hpet_period;
 
-static void hpet_set_mode(enum clock_event_mode mode,
+static void hpet_legacy_set_mode(enum clock_event_mode mode,
  struct clock_event_device *evt);
-static int hpet_next_event(unsigned long delta,
+static int hpet_legacy_next_event(unsigned long delta,
   struct clock_event_device *evt);
 
 /*
@@ -169,8 +169,8 @@ static int hpet_next_event(unsigned long
 static struct clock_event_device hpet_clockevent = {
.name   = "hpet",
.features   = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
-   .set_mode   = hpet_set_mode,
-   .set_next_event = hpet_next_event,
+   .set_mode   = hpet_legacy_set_mode,
+   .set_next_event = hpet_legacy_next_event,
.shift  = 32,
.irq= 0,
 };
@@ -187,7 +187,7 @@ static void hpet_start_counter(void)
hpet_writel(cfg, HPET_CFG);
 }
 
-static void hpet_enable_int(void)
+static void hpet_enable_legacy_int(void)
 {
unsigned long cfg = hpet_readl(HPET_CFG);
 
@@ -196,7 +196,39 @@ static void hpet_enable_int(void)
hpet_legacy_int_enabled = 1;
 }
 
-static void hpet_set_mode(enum clock_event_mode mode,
+static void hpet_legacy_clockevent_register(void)
+{
+   uint64_t hpet_freq;
+
+   /* Start HPET legacy interrupts */
+   hpet_enable_legacy_int();
+
+   /*
+* The period is a femto seconds value. We need to calculate the
+* scaled math multiplication factor for nanosecond to hpet tick
+* conversion.
+*/
+   hpet_freq = 1000ULL;
+   do_div(hpet_freq, hpet_period);
+   hpet_clockevent.mult = div_sc((unsigned long) hpet_freq,
+ NSEC_PER_SEC, 32);
+   /* Calculate the min / max delta */
+   hpet_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFF,
+  _clockevent);
+   hpet_clockevent.min_delta_ns = clockevent_delta2ns(0x30,
+  _clockevent);
+
+   /*
+* Start hpet with the boot cpu mask and make it
+* global after the IO_APIC has been initialized.
+*/
+   hpet_clockevent.cpumask = cpumask_of_cpu(smp_processor_id());
+   clockevents_register_device(_clockevent);
+   global_clock_event = _clockevent;
+   printk(KERN_DEBUG "hpet clockevent registered\n");
+}
+
+static void hpet_legacy_set_mode(enum clock_event_mode mode,
  struct clock_event_device *evt)
 {
unsigned long cfg, cmp, now;
@@ -237,12 +269,12 @@ static void hpet_set_mode(enum clock_eve
break;
 
case CLOCK_EVT_MODE_RESUME:
-   hpet_enable_int();
+   hpet_enable_legacy_int();
break;
}
 }
 
-static int hpet_next_event(unsigned long delta,
+static int hpet_legacy_next_event(unsigned long delta,
   struct clock_event_device *evt)
 {
unsigned long cnt;
@@ -282,58 +314,11 @@ static struct clocksource clocksource_hp
 #endif
 };
 
-/*
- * Try to setup the HPET timer
- */
-int __init hpet_enable(void)
+static int hpet_clocksource_register(void)
 {
-   unsigned long id;
-   uint64_t hpet_freq;
u64 tmp, start, now;
cycle_t t1;
 
-   if (!is_hpet_capable())
-   return 0;
-
-   hpet_set_mapping();
-
-   /*
-* Read the period and check for a sane value:
-*/
-   hpet_period = hpet_readl(HPET_PERIOD);
-   if (hpet_period < HPET_MIN_PERIOD || hpet_period > HPET_MAX_PERIOD)
-   goto out_nohpet;
-
-   /*
-* The period is a femto seconds value. We need to calculate the
-* scaled math multiplication factor for nanosecond to hpet tick
-* conversion.
-*/
-   hpet_freq = 1000ULL;
-   do_div(hpet_freq, hpet_period);
-   hpet_clockevent.mult = div_sc((unsigned long) hpet_freq,
- NSEC_PER_SEC, 32);
-   /* Calculate the min / max delta */
-   hpet_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFF,
-  _clockevent);
-   hpet_clockevent.min_delta_ns = clockevent_delta2ns(0x30,
-  _clockevent);
-
-  

[PATCH 2/7] ICH Force HPET: Restructure hpet generic clock code

2007-06-22 Thread Venki Pallipadi

Restructure and rename legacy replacement mode HPET timer support.
Just the code structural changes and should be zero functionality change.

Signed-off-by: Venkatesh Pallipadi [EMAIL PROTECTED]

---

Index: linux-2.6.22-rc5/arch/i386/kernel/hpet.c
===
--- linux-2.6.22-rc5.orig/arch/i386/kernel/hpet.c   2007-06-17 
08:52:09.0 +0200
+++ linux-2.6.22-rc5/arch/i386/kernel/hpet.c2007-06-17 08:52:10.0 
+0200
@@ -158,9 +158,9 @@ static void hpet_reserve_platform_timers
  */
 static unsigned long hpet_period;
 
-static void hpet_set_mode(enum clock_event_mode mode,
+static void hpet_legacy_set_mode(enum clock_event_mode mode,
  struct clock_event_device *evt);
-static int hpet_next_event(unsigned long delta,
+static int hpet_legacy_next_event(unsigned long delta,
   struct clock_event_device *evt);
 
 /*
@@ -169,8 +169,8 @@ static int hpet_next_event(unsigned long
 static struct clock_event_device hpet_clockevent = {
.name   = hpet,
.features   = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
-   .set_mode   = hpet_set_mode,
-   .set_next_event = hpet_next_event,
+   .set_mode   = hpet_legacy_set_mode,
+   .set_next_event = hpet_legacy_next_event,
.shift  = 32,
.irq= 0,
 };
@@ -187,7 +187,7 @@ static void hpet_start_counter(void)
hpet_writel(cfg, HPET_CFG);
 }
 
-static void hpet_enable_int(void)
+static void hpet_enable_legacy_int(void)
 {
unsigned long cfg = hpet_readl(HPET_CFG);
 
@@ -196,7 +196,39 @@ static void hpet_enable_int(void)
hpet_legacy_int_enabled = 1;
 }
 
-static void hpet_set_mode(enum clock_event_mode mode,
+static void hpet_legacy_clockevent_register(void)
+{
+   uint64_t hpet_freq;
+
+   /* Start HPET legacy interrupts */
+   hpet_enable_legacy_int();
+
+   /*
+* The period is a femto seconds value. We need to calculate the
+* scaled math multiplication factor for nanosecond to hpet tick
+* conversion.
+*/
+   hpet_freq = 1000ULL;
+   do_div(hpet_freq, hpet_period);
+   hpet_clockevent.mult = div_sc((unsigned long) hpet_freq,
+ NSEC_PER_SEC, 32);
+   /* Calculate the min / max delta */
+   hpet_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFF,
+  hpet_clockevent);
+   hpet_clockevent.min_delta_ns = clockevent_delta2ns(0x30,
+  hpet_clockevent);
+
+   /*
+* Start hpet with the boot cpu mask and make it
+* global after the IO_APIC has been initialized.
+*/
+   hpet_clockevent.cpumask = cpumask_of_cpu(smp_processor_id());
+   clockevents_register_device(hpet_clockevent);
+   global_clock_event = hpet_clockevent;
+   printk(KERN_DEBUG hpet clockevent registered\n);
+}
+
+static void hpet_legacy_set_mode(enum clock_event_mode mode,
  struct clock_event_device *evt)
 {
unsigned long cfg, cmp, now;
@@ -237,12 +269,12 @@ static void hpet_set_mode(enum clock_eve
break;
 
case CLOCK_EVT_MODE_RESUME:
-   hpet_enable_int();
+   hpet_enable_legacy_int();
break;
}
 }
 
-static int hpet_next_event(unsigned long delta,
+static int hpet_legacy_next_event(unsigned long delta,
   struct clock_event_device *evt)
 {
unsigned long cnt;
@@ -282,58 +314,11 @@ static struct clocksource clocksource_hp
 #endif
 };
 
-/*
- * Try to setup the HPET timer
- */
-int __init hpet_enable(void)
+static int hpet_clocksource_register(void)
 {
-   unsigned long id;
-   uint64_t hpet_freq;
u64 tmp, start, now;
cycle_t t1;
 
-   if (!is_hpet_capable())
-   return 0;
-
-   hpet_set_mapping();
-
-   /*
-* Read the period and check for a sane value:
-*/
-   hpet_period = hpet_readl(HPET_PERIOD);
-   if (hpet_period  HPET_MIN_PERIOD || hpet_period  HPET_MAX_PERIOD)
-   goto out_nohpet;
-
-   /*
-* The period is a femto seconds value. We need to calculate the
-* scaled math multiplication factor for nanosecond to hpet tick
-* conversion.
-*/
-   hpet_freq = 1000ULL;
-   do_div(hpet_freq, hpet_period);
-   hpet_clockevent.mult = div_sc((unsigned long) hpet_freq,
- NSEC_PER_SEC, 32);
-   /* Calculate the min / max delta */
-   hpet_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFF,
-  hpet_clockevent);
-   hpet_clockevent.min_delta_ns = clockevent_delta2ns(0x30,
-