1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) Intel Corp. 2007.
6 * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
9 * This file is part of the Carillo Ranch video subsystem driver.
12 * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
13 * Alan Hourihane <alanh-at-tungstengraphics-dot-com>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/pci.h>
19 #include <linux/errno.h>
21 #include "vermilion.h"
23 /* The PLL Clock register sits on Host bridge */
24 #define CRVML_DEVICE_MCH 0x5001
25 #define CRVML_REG_MCHBAR 0x44
26 #define CRVML_REG_MCHEN 0x54
27 #define CRVML_MCHEN_BIT (1 << 28)
28 #define CRVML_MCHMAP_SIZE 4096
29 #define CRVML_REG_CLOCK 0xc3c
30 #define CRVML_CLOCK_SHIFT 8
31 #define CRVML_CLOCK_MASK 0x00000f00
33 static struct pci_dev
*mch_dev
;
35 static void __iomem
*mch_regs_base
;
36 static u32 saved_clock
;
38 static const unsigned crvml_clocks
[] = {
49 * There are more clocks, but they are disabled on the CR board.
53 static const u32 crvml_clock_bits
[] = {
65 static const unsigned crvml_num_clocks
= ARRAY_SIZE(crvml_clocks
);
67 static int crvml_sys_restore(struct vml_sys
*sys
)
69 void __iomem
*clock_reg
= mch_regs_base
+ CRVML_REG_CLOCK
;
71 iowrite32(saved_clock
, clock_reg
);
77 static int crvml_sys_save(struct vml_sys
*sys
)
79 void __iomem
*clock_reg
= mch_regs_base
+ CRVML_REG_CLOCK
;
81 saved_clock
= ioread32(clock_reg
);
86 static int crvml_nearest_index(const struct vml_sys
*sys
, int clock
)
93 cur_diff
= clock
- crvml_clocks
[0];
94 cur_diff
= (cur_diff
< 0) ? -cur_diff
: cur_diff
;
95 for (i
= 1; i
< crvml_num_clocks
; ++i
) {
96 diff
= clock
- crvml_clocks
[i
];
97 diff
= (diff
< 0) ? -diff
: diff
;
98 if (diff
< cur_diff
) {
106 static int crvml_nearest_clock(const struct vml_sys
*sys
, int clock
)
108 return crvml_clocks
[crvml_nearest_index(sys
, clock
)];
111 static int crvml_set_clock(struct vml_sys
*sys
, int clock
)
113 void __iomem
*clock_reg
= mch_regs_base
+ CRVML_REG_CLOCK
;
117 index
= crvml_nearest_index(sys
, clock
);
119 if (crvml_clocks
[index
] != clock
)
122 clock_val
= ioread32(clock_reg
) & ~CRVML_CLOCK_MASK
;
123 clock_val
= crvml_clock_bits
[index
] << CRVML_CLOCK_SHIFT
;
124 iowrite32(clock_val
, clock_reg
);
130 static struct vml_sys cr_pll_ops
= {
131 .name
= "Carillo Ranch",
132 .save
= crvml_sys_save
,
133 .restore
= crvml_sys_restore
,
134 .set_clock
= crvml_set_clock
,
135 .nearest_clock
= crvml_nearest_clock
,
138 static int __init
cr_pll_init(void)
143 mch_dev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
144 CRVML_DEVICE_MCH
, NULL
);
147 "Could not find Carillo Ranch MCH device.\n");
151 pci_read_config_dword(mch_dev
, CRVML_REG_MCHEN
, &dev_en
);
152 if (!(dev_en
& CRVML_MCHEN_BIT
)) {
154 "Carillo Ranch MCH device was not enabled.\n");
155 pci_dev_put(mch_dev
);
159 pci_read_config_dword(mch_dev
, CRVML_REG_MCHBAR
,
162 ioremap(mch_bar
, CRVML_MCHMAP_SIZE
);
163 if (!mch_regs_base
) {
165 "Carillo Ranch MCH device was not enabled.\n");
166 pci_dev_put(mch_dev
);
170 err
= vmlfb_register_subsys(&cr_pll_ops
);
173 "Carillo Ranch failed to initialize vml_sys.\n");
174 iounmap(mch_regs_base
);
175 pci_dev_put(mch_dev
);
182 static void __exit
cr_pll_exit(void)
184 vmlfb_unregister_subsys(&cr_pll_ops
);
186 iounmap(mch_regs_base
);
187 pci_dev_put(mch_dev
);
190 module_init(cr_pll_init
);
191 module_exit(cr_pll_exit
);
193 MODULE_AUTHOR("Tungsten Graphics Inc.");
194 MODULE_DESCRIPTION("Carillo Ranch PLL Driver");
195 MODULE_LICENSE("GPL");