2
* Copyright (c) Intel Corp. 2007.
5
* Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
8
* This file is part of the Carillo Ranch video subsystem driver.
9
* The Carillo Ranch video subsystem driver is free software;
10
* you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* The Carillo Ranch video subsystem driver is distributed
16
* in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with this driver; if not, write to the Free Software
23
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
* Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
27
* Alan Hourihane <alanh-at-tungstengraphics-dot-com>
30
#include <linux/module.h>
31
#include <linux/kernel.h>
32
#include <linux/pci.h>
33
#include <linux/errno.h>
35
#include "vermilion.h"
37
/* The PLL Clock register sits on Host bridge */
38
#define CRVML_DEVICE_MCH 0x5001
39
#define CRVML_REG_MCHBAR 0x44
40
#define CRVML_REG_MCHEN 0x54
41
#define CRVML_MCHEN_BIT (1 << 28)
42
#define CRVML_MCHMAP_SIZE 4096
43
#define CRVML_REG_CLOCK 0xc3c
44
#define CRVML_CLOCK_SHIFT 8
45
#define CRVML_CLOCK_MASK 0x00000f00
47
static struct pci_dev *mch_dev;
49
static void __iomem *mch_regs_base;
50
static u32 saved_clock;
52
static const unsigned crvml_clocks[] = {
63
* There are more clocks, but they are disabled on the CR board.
67
static const u32 crvml_clock_bits[] = {
79
static const unsigned crvml_num_clocks = ARRAY_SIZE(crvml_clocks);
81
static int crvml_sys_restore(struct vml_sys *sys)
83
void __iomem *clock_reg = mch_regs_base + CRVML_REG_CLOCK;
85
iowrite32(saved_clock, clock_reg);
91
static int crvml_sys_save(struct vml_sys *sys)
93
void __iomem *clock_reg = mch_regs_base + CRVML_REG_CLOCK;
95
saved_clock = ioread32(clock_reg);
100
static int crvml_nearest_index(const struct vml_sys *sys, int clock)
107
cur_diff = clock - crvml_clocks[0];
108
cur_diff = (cur_diff < 0) ? -cur_diff : cur_diff;
109
for (i = 1; i < crvml_num_clocks; ++i) {
110
diff = clock - crvml_clocks[i];
111
diff = (diff < 0) ? -diff : diff;
112
if (diff < cur_diff) {
120
static int crvml_nearest_clock(const struct vml_sys *sys, int clock)
122
return crvml_clocks[crvml_nearest_index(sys, clock)];
125
static int crvml_set_clock(struct vml_sys *sys, int clock)
127
void __iomem *clock_reg = mch_regs_base + CRVML_REG_CLOCK;
131
index = crvml_nearest_index(sys, clock);
133
if (crvml_clocks[index] != clock)
136
clock_val = ioread32(clock_reg) & ~CRVML_CLOCK_MASK;
137
clock_val = crvml_clock_bits[index] << CRVML_CLOCK_SHIFT;
138
iowrite32(clock_val, clock_reg);
144
static struct vml_sys cr_pll_ops = {
145
.name = "Carillo Ranch",
146
.save = crvml_sys_save,
147
.restore = crvml_sys_restore,
148
.set_clock = crvml_set_clock,
149
.nearest_clock = crvml_nearest_clock,
152
static int __init cr_pll_init(void)
157
mch_dev = pci_get_device(PCI_VENDOR_ID_INTEL,
158
CRVML_DEVICE_MCH, NULL);
161
"Could not find Carillo Ranch MCH device.\n");
165
pci_read_config_dword(mch_dev, CRVML_REG_MCHEN, &dev_en);
166
if (!(dev_en & CRVML_MCHEN_BIT)) {
168
"Carillo Ranch MCH device was not enabled.\n");
169
pci_dev_put(mch_dev);
173
pci_read_config_dword(mch_dev, CRVML_REG_MCHBAR,
176
ioremap_nocache(mch_bar, CRVML_MCHMAP_SIZE);
177
if (!mch_regs_base) {
179
"Carillo Ranch MCH device was not enabled.\n");
180
pci_dev_put(mch_dev);
184
err = vmlfb_register_subsys(&cr_pll_ops);
187
"Carillo Ranch failed to initialize vml_sys.\n");
188
pci_dev_put(mch_dev);
195
static void __exit cr_pll_exit(void)
197
vmlfb_unregister_subsys(&cr_pll_ops);
199
iounmap(mch_regs_base);
200
pci_dev_put(mch_dev);
203
module_init(cr_pll_init);
204
module_exit(cr_pll_exit);
206
MODULE_AUTHOR("Tungsten Graphics Inc.");
207
MODULE_DESCRIPTION("Carillo Ranch PLL Driver");
208
MODULE_LICENSE("GPL");