~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/blackfin/mach-common/dpmc.c

Version: ~ [ linux-5.5-rc7 ] ~ [ linux-5.4.13 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.97 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.166 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.210 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.210 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.81 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright 2008 Analog Devices Inc.
  3  *
  4  * Licensed under the GPL-2 or later.
  5  */
  6 
  7 #include <linux/cdev.h>
  8 #include <linux/device.h>
  9 #include <linux/errno.h>
 10 #include <linux/fs.h>
 11 #include <linux/kernel.h>
 12 #include <linux/module.h>
 13 #include <linux/platform_device.h>
 14 #include <linux/types.h>
 15 #include <linux/cpufreq.h>
 16 
 17 #include <asm/delay.h>
 18 #include <asm/dpmc.h>
 19 
 20 #define DRIVER_NAME "bfin dpmc"
 21 
 22 struct bfin_dpmc_platform_data *pdata;
 23 
 24 /**
 25  *      bfin_set_vlev - Update VLEV field in VR_CTL Reg.
 26  *                      Avoid BYPASS sequence
 27  */
 28 static void bfin_set_vlev(unsigned int vlev)
 29 {
 30         unsigned pll_lcnt;
 31 
 32         pll_lcnt = bfin_read_PLL_LOCKCNT();
 33 
 34         bfin_write_PLL_LOCKCNT(1);
 35         bfin_write_VR_CTL((bfin_read_VR_CTL() & ~VLEV) | vlev);
 36         bfin_write_PLL_LOCKCNT(pll_lcnt);
 37 }
 38 
 39 /**
 40  *      bfin_get_vlev - Get CPU specific VLEV from platform device data
 41  */
 42 static unsigned int bfin_get_vlev(unsigned int freq)
 43 {
 44         int i;
 45 
 46         if (!pdata)
 47                 goto err_out;
 48 
 49         freq >>= 16;
 50 
 51         for (i = 0; i < pdata->tabsize; i++)
 52                 if (freq <= (pdata->tuple_tab[i] & 0xFFFF))
 53                         return pdata->tuple_tab[i] >> 16;
 54 
 55 err_out:
 56         printk(KERN_WARNING "DPMC: No suitable CCLK VDDINT voltage pair found\n");
 57         return VLEV_120;
 58 }
 59 
 60 #ifdef CONFIG_CPU_FREQ
 61 # ifdef CONFIG_SMP
 62 static void bfin_idle_this_cpu(void *info)
 63 {
 64         unsigned long flags = 0;
 65         unsigned long iwr0, iwr1, iwr2;
 66         unsigned int cpu = smp_processor_id();
 67 
 68         local_irq_save_hw(flags);
 69         bfin_iwr_set_sup0(&iwr0, &iwr1, &iwr2);
 70 
 71         platform_clear_ipi(cpu, IRQ_SUPPLE_0);
 72         SSYNC();
 73         asm("IDLE;");
 74         bfin_iwr_restore(iwr0, iwr1, iwr2);
 75 
 76         local_irq_restore_hw(flags);
 77 }
 78 
 79 static void bfin_idle_cpu(void)
 80 {
 81         smp_call_function(bfin_idle_this_cpu, NULL, 0);
 82 }
 83 
 84 static void bfin_wakeup_cpu(void)
 85 {
 86         unsigned int cpu;
 87         unsigned int this_cpu = smp_processor_id();
 88         cpumask_t mask;
 89 
 90         cpumask_copy(&mask, cpu_online_mask);
 91         cpumask_clear_cpu(this_cpu, &mask);
 92         for_each_cpu(cpu, &mask)
 93                 platform_send_ipi_cpu(cpu, IRQ_SUPPLE_0);
 94 }
 95 
 96 # else
 97 static void bfin_idle_cpu(void) {}
 98 static void bfin_wakeup_cpu(void) {}
 99 # endif
100 
101 static int
102 vreg_cpufreq_notifier(struct notifier_block *nb, unsigned long val, void *data)
103 {
104         struct cpufreq_freqs *freq = data;
105 
106         if (freq->cpu != CPUFREQ_CPU)
107                 return 0;
108 
109         if (val == CPUFREQ_PRECHANGE && freq->old < freq->new) {
110                 bfin_idle_cpu();
111                 bfin_set_vlev(bfin_get_vlev(freq->new));
112                 udelay(pdata->vr_settling_time); /* Wait until Volatge settled */
113                 bfin_wakeup_cpu();
114         } else if (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) {
115                 bfin_idle_cpu();
116                 bfin_set_vlev(bfin_get_vlev(freq->new));
117                 bfin_wakeup_cpu();
118         }
119 
120         return 0;
121 }
122 
123 static struct notifier_block vreg_cpufreq_notifier_block = {
124         .notifier_call  = vreg_cpufreq_notifier
125 };
126 #endif /* CONFIG_CPU_FREQ */
127 
128 /**
129  *      bfin_dpmc_probe -
130  *
131  */
132 static int bfin_dpmc_probe(struct platform_device *pdev)
133 {
134         if (pdev->dev.platform_data)
135                 pdata = pdev->dev.platform_data;
136         else
137                 return -EINVAL;
138 
139         return cpufreq_register_notifier(&vreg_cpufreq_notifier_block,
140                                          CPUFREQ_TRANSITION_NOTIFIER);
141 }
142 
143 /**
144  *      bfin_dpmc_remove -
145  */
146 static int bfin_dpmc_remove(struct platform_device *pdev)
147 {
148         pdata = NULL;
149         return cpufreq_unregister_notifier(&vreg_cpufreq_notifier_block,
150                                          CPUFREQ_TRANSITION_NOTIFIER);
151 }
152 
153 struct platform_driver bfin_dpmc_device_driver = {
154         .probe   = bfin_dpmc_probe,
155         .remove  = bfin_dpmc_remove,
156         .driver  = {
157                 .name = DRIVER_NAME,
158         }
159 };
160 module_platform_driver(bfin_dpmc_device_driver);
161 
162 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
163 MODULE_DESCRIPTION("cpu power management driver for Blackfin");
164 MODULE_LICENSE("GPL");
165 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp