#include <linux/percpu.h>
  #include <linux/clockchips.h>
  #include <linux/completion.h>
+ #include <linux/cpufreq.h>
  
  #include <linux/atomic.h>
 +#include <asm/smp.h>
  #include <asm/cacheflush.h>
  #include <asm/cpu.h>
  #include <asm/cputype.h>
 
  };
  
  
 -#define GPIO_PORT9CR  0xE6051009
 -#define GPIO_PORT10CR 0xE605100A
 -#define USCCR1                0xE6058144
 +#define GPIO_PORT9CR  IOMEM(0xE6051009)
 +#define GPIO_PORT10CR IOMEM(0xE605100A)
 +#define USCCR1                IOMEM(0xE6058144)
  static void __init ap4evb_init(void)
  {
+       struct pm_domain_device domain_devices[] = {
+               { "A4LC", &lcdc1_device, },
+               { "A4LC", &lcdc_device, },
+               { "A4MP", &fsi_device, },
+               { "A3SP", &sh_mmcif_device, },
+               { "A3SP", &sdhi0_device, },
+               { "A3SP", &sdhi1_device, },
+               { "A4R", &ceu_device, },
+       };
        u32 srcr4;
        struct clk *clk;
  
 
        },
  };
  
 -#define GPIO_PORT9CR  0xE6051009
 -#define GPIO_PORT10CR 0xE605100A
 -#define GPIO_PORT167CR        0xE60520A7
 -#define GPIO_PORT168CR        0xE60520A8
 -#define SRCR4         0xe61580bc
 -#define USCCR1                0xE6058144
 +#define GPIO_PORT9CR  IOMEM(0xE6051009)
 +#define GPIO_PORT10CR IOMEM(0xE605100A)
 +#define GPIO_PORT167CR        IOMEM(0xE60520A7)
 +#define GPIO_PORT168CR        IOMEM(0xE60520A8)
 +#define SRCR4         IOMEM(0xe61580bc)
 +#define USCCR1                IOMEM(0xE6058144)
  static void __init mackerel_init(void)
  {
+       struct pm_domain_device domain_devices[] = {
+               { "A4LC", &lcdc_device, },
+               { "A4LC", &hdmi_lcdc_device, },
+               { "A4LC", &meram_device, },
+               { "A4MP", &fsi_device, },
+               { "A3SP", &usbhs0_device, },
+               { "A3SP", &usbhs1_device, },
+               { "A3SP", &nand_flash_device, },
+               { "A3SP", &sh_mmcif_device, },
+               { "A3SP", &sdhi0_device, },
+ #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
+               { "A3SP", &sdhi1_device, },
+ #endif
+               { "A3SP", &sdhi2_device, },
+               { "A4R", &ceu_device, },
+       };
        u32 srcr4;
        struct clk *clk;
  
 
  extern void r8a7779_pm_init(void);
  extern void r8a7740_meram_workaround(void);
  
 -extern unsigned int r8a7779_get_core_count(void);
 -extern int r8a7779_platform_cpu_kill(unsigned int cpu);
 -extern void r8a7779_secondary_init(unsigned int cpu);
 -extern int r8a7779_boot_secondary(unsigned int cpu);
 -extern void r8a7779_smp_prepare_cpus(void);
  extern void r8a7779_register_twd(void);
  
- extern void shmobile_init_late(void);
- 
  #ifdef CONFIG_SUSPEND
  int shmobile_suspend_init(void);
  #else
  static inline int shmobile_cpuidle_init(void) { return 0; }
  #endif
  
 +extern void shmobile_cpu_die(unsigned int cpu);
 +extern int shmobile_cpu_disable(unsigned int cpu);
 +
 +#ifdef CONFIG_HOTPLUG_CPU
 +extern int shmobile_cpu_is_dead(unsigned int cpu);
 +#else
 +static inline int shmobile_cpu_is_dead(unsigned int cpu) { return 1; }
 +#endif
 +
 +extern void shmobile_smp_init_cpus(unsigned int ncores);
 +
+ static inline void shmobile_init_late(void)
+ {
+       shmobile_suspend_init();
+       shmobile_cpuidle_init();
+ }
+ 
  #endif /* __ARCH_MACH_COMMON_H */
 
  extern int r8a7779_sysc_power_up(struct r8a7779_pm_ch *r8a7779_ch);
  
  #ifdef CONFIG_PM
- extern struct r8a7779_pm_domain r8a7779_sh4a;
- extern struct r8a7779_pm_domain r8a7779_sgx;
- extern struct r8a7779_pm_domain r8a7779_vdp1;
- extern struct r8a7779_pm_domain r8a7779_impx3;
- 
- extern void r8a7779_init_pm_domain(struct r8a7779_pm_domain *r8a7779_pd);
- extern void r8a7779_add_device_to_domain(struct r8a7779_pm_domain *r8a7779_pd,
-                                       struct platform_device *pdev);
+ extern void __init r8a7779_init_pm_domains(void);
  #else
- #define r8a7779_init_pm_domain(pd) do { } while (0)
- #define r8a7779_add_device_to_domain(pd, pdev) do { } while (0)
+ static inline void r8a7779_init_pm_domains(void) {}
  #endif /* CONFIG_PM */
  
 +extern struct smp_operations r8a7779_smp_ops;
 +
  #endif /* __ASM_R8A7779_H__ */
 
  #include <linux/err.h>
  #include <linux/slab.h>
  #include <linux/pm_runtime.h>
 +#include <linux/idr.h>
  
  #include "base.h"
+ #include "power/power.h"
  
 +/* For automatically allocated device IDs */
 +static DEFINE_IDA(platform_devid_ida);
 +
  #define to_platform_driver(drv)       (container_of((drv), struct platform_driver, \
                                 driver))
  
 
        return res;
  }
  
- /* Take a frequency, and issue the hardware pstate transition command */
- static int transition_frequency_pstate(struct powernow_k8_data *data,
-               unsigned int index)
- {
-       u32 pstate = 0;
-       int res, i;
-       struct cpufreq_freqs freqs;
- 
-       pr_debug("cpu %d transition to index %u\n", smp_processor_id(), index);
- 
-       /* get MSR index for hardware pstate transition */
-       pstate = index & HW_PSTATE_MASK;
-       if (pstate > data->max_hw_pstate)
-               return -EINVAL;
- 
-       freqs.old = find_khz_freq_from_pstate(data->powernow_table,
-                       data->currpstate);
-       freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate);
- 
-       for_each_cpu(i, data->available_cores) {
-               freqs.cpu = i;
-               cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
-       }
- 
-       res = transition_pstate(data, pstate);
-       freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate);
- 
-       for_each_cpu(i, data->available_cores) {
-               freqs.cpu = i;
-               cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
-       }
-       return res;
- }
- 
 -/* Driver entry point to switch to the target frequency */
 -static int powernowk8_target(struct cpufreq_policy *pol,
 -              unsigned targfreq, unsigned relation)
 +struct powernowk8_target_arg {
 +      struct cpufreq_policy           *pol;
 +      unsigned                        targfreq;
 +      unsigned                        relation;
 +};
 +
 +static long powernowk8_target_fn(void *arg)
  {
 -      cpumask_var_t oldmask;
 +      struct powernowk8_target_arg *pta = arg;
 +      struct cpufreq_policy *pol = pta->pol;
 +      unsigned targfreq = pta->targfreq;
 +      unsigned relation = pta->relation;
        struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
        u32 checkfid;
        u32 checkvid;
                pol->cpu, targfreq, pol->min, pol->max, relation);
  
        if (query_current_values_with_pending_wait(data))
 -              goto err_out;
 +              return -EIO;
  
-       if (cpu_family != CPU_HW_PSTATE) {
-               pr_debug("targ: curr fid 0x%x, vid 0x%x\n",
-               data->currfid, data->currvid);
+       pr_debug("targ: curr fid 0x%x, vid 0x%x\n",
+                data->currfid, data->currvid);
  
-               if ((checkvid != data->currvid) ||
-                   (checkfid != data->currfid)) {
-                       printk(KERN_INFO PFX
-                               "error - out of sync, fix 0x%x 0x%x, "
-                               "vid 0x%x 0x%x\n",
-                               checkfid, data->currfid,
-                               checkvid, data->currvid);
-               }
+       if ((checkvid != data->currvid) ||
+           (checkfid != data->currfid)) {
+               pr_info(PFX
+                      "error - out of sync, fix 0x%x 0x%x, vid 0x%x 0x%x\n",
+                      checkfid, data->currfid,
+                      checkvid, data->currvid);
        }
  
        if (cpufreq_frequency_table_target(pol, data->powernow_table,
  
        powernow_k8_acpi_pst_values(data, newstate);
  
-       if (cpu_family == CPU_HW_PSTATE)
-               ret = transition_frequency_pstate(data,
-                       data->powernow_table[newstate].index);
-       else
-               ret = transition_frequency_fidvid(data, newstate);
+       ret = transition_frequency_fidvid(data, newstate);
+ 
        if (ret) {
                printk(KERN_ERR PFX "transition frequency failed\n");
 -              ret = 1;
                mutex_unlock(&fidvid_mutex);
 -              goto err_out;
 +              return 1;
        }
        mutex_unlock(&fidvid_mutex);
  
-       if (cpu_family == CPU_HW_PSTATE)
-               pol->cur = find_khz_freq_from_pstate(data->powernow_table,
-                               data->powernow_table[newstate].index);
-       else
-               pol->cur = find_khz_freq_from_fid(data->currfid);
+       pol->cur = find_khz_freq_from_fid(data->currfid);
 -      ret = 0;
  
 -err_out:
 -      set_cpus_allowed_ptr(current, oldmask);
 -      free_cpumask_var(oldmask);
 -      return ret;
 +      return 0;
 +}
 +
 +/* Driver entry point to switch to the target frequency */
 +static int powernowk8_target(struct cpufreq_policy *pol,
 +              unsigned targfreq, unsigned relation)
 +{
 +      struct powernowk8_target_arg pta = { .pol = pol, .targfreq = targfreq,
 +                                           .relation = relation };
 +
 +      /*
 +       * Must run on @pol->cpu.  cpufreq core is responsible for ensuring
 +       * that we're bound to the current CPU and pol->cpu stays online.
 +       */
 +      if (smp_processor_id() == pol->cpu)
 +              return powernowk8_target_fn(&pta);
 +      else
 +              return work_on_cpu(pol->cpu, powernowk8_target_fn, &pta);
  }
  
  /* Driver entry point to verify the policy and range of frequencies */