15 #include <linux/kernel.h>
23 #include <asm/cacheflush.h>
24 #include <asm/machdep.h>
35 static void __init mpc512x_restart_init(
void)
49 if (reset_module_base) {
55 pr_err(
"Restart module not mapped.\n");
72 switch (bits_per_pixel) {
84 char *gamma_table_base)
92 #define DIU_DIV_MASK 0x000000ff
95 unsigned long bestval, bestfreq,
speed, busfreq;
96 unsigned long minpixclock, maxpixclock, pixval;
105 pr_err(
"Can't find clock control module.\n");
112 pr_err(
"Can't map clock control module reg.\n");
118 const unsigned int *prop =
125 pr_err(
"Can't get bus-frequency property\n");
129 pr_err(
"Can't find 'cpu' node.\n");
134 pr_debug(
"DIU: Bus Frequency = %lu\n", busfreq);
139 pr_debug(
"DIU pixclock in ps - %d\n", pixclock);
140 temp = (1000000000 / pixclock) * 1000;
142 pr_debug(
"DIU pixclock freq - %u\n", pixclock);
146 minpixclock = pixclock -
temp;
147 maxpixclock = pixclock +
temp;
148 pr_debug(
"DIU minpixclock - %lu\n", minpixclock);
149 pr_debug(
"DIU maxpixclock - %lu\n", maxpixclock);
150 pixval = speed/pixclock;
151 pr_debug(
"DIU pixval = %lu\n", pixval);
155 pr_debug(
"DIU bestval = %lu\n", bestval);
158 for (i = -1; i <= 1; i++) {
159 temp = speed / (pixval+
i);
160 pr_debug(
"DIU test pixval i=%d, pixval=%lu, temp freq. = %u\n",
162 if ((temp < minpixclock) || (temp > maxpixclock))
163 pr_debug(
"DIU exceeds monitor range (%lu to %lu)\n",
164 minpixclock, maxpixclock);
165 else if (
abs(temp - pixclock) < err) {
166 pr_debug(
"Entered the else if block %d\n", i);
167 err =
abs(temp - pixclock);
168 bestval = pixval +
i;
173 pr_debug(
"DIU chose = %lx\n", bestval);
174 pr_debug(
"DIU error = %ld\n NomPixClk ", err);
175 pr_debug(
"DIU: Best Freq = %lx\n", bestfreq);
178 pr_debug(
"DIU: Current value of SCFR1: 0x%08x\n", temp);
182 pr_debug(
"DIU: Modified value of SCFR1: 0x%08x\n", temp);
186 enum fsl_diu_monitor_port
189 return FSL_DIU_PORT_DVI;
194 static inline void mpc512x_free_bootmem(
struct page *
page)
196 __ClearPageReserved(page);
207 unsigned long size = diu_shared_fb.fb_len;
210 if (diu_shared_fb.in_use) {
214 for (; start <
end; start++)
217 diu_shared_fb.in_use =
false;
219 diu_ops.release_bootmem =
NULL;
248 pr_err(
"Can't map DIU\n");
252 mode =
in_be32(&diu_reg->diu_mode);
253 if (mode == MFB_MODE0) {
254 pr_info(
"%s: DIU OFF\n", __func__);
258 desc =
in_be32(&diu_reg->desc[0]);
259 vaddr =
ioremap(desc,
sizeof(
struct diu_ad));
261 pr_err(
"Can't map DIU area desc.\n");
264 memcpy(&diu_shared_fb.ad0, vaddr,
sizeof(
struct diu_ad));
266 dst = (
unsigned long)&diu_shared_fb.ad0;
269 res =
in_be32(&diu_reg->disp_size);
271 bpp = ((pix_fmt >> 16) & 0x3) + 1;
272 diu_shared_fb.fb_phys =
in_le32(vaddr + 4);
273 diu_shared_fb.fb_len = ((res & 0xfff0000) >> 16) * (res & 0xfff) * bpp;
274 diu_shared_fb.in_use =
true;
277 desc =
in_be32(&diu_reg->gamma);
278 vaddr =
ioremap(desc,
sizeof(diu_shared_fb.gamma));
280 pr_err(
"Can't map DIU area desc.\n");
281 diu_shared_fb.in_use =
false;
284 memcpy(&diu_shared_fb.gamma, vaddr,
sizeof(diu_shared_fb.gamma));
286 dst = (
unsigned long)&diu_shared_fb.gamma;
313 if (diu_shared_fb.in_use) {
315 diu_shared_fb.fb_len,
318 pr_err(
"%s: reserve bootmem failed\n", __func__);
319 diu_shared_fb.in_use =
false;
353 { .compatible =
"fsl,mpc5121-immr", },
354 { .compatible =
"fsl,mpc5121-localbus", },
362 if (of_platform_bus_probe(
NULL, of_bus_ids,
NULL))
364 "Error while probing of_platform bus\n");
368 of_platform_device_create(np,
NULL,
NULL);
373 #define DEFAULT_FIFO_SIZE 16
378 const unsigned int *
fp;
384 pr_warning(
"no %s property in %s node, defaulting to %d\n",
390 #define FIFOC(_base) ((struct mpc512x_psc_fifo __iomem *) \
391 ((u32)(_base) + sizeof(struct mpc52xx_psc)))
398 unsigned int tx_fifo_size;
399 unsigned int rx_fifo_size;
402 for_each_compatible_node(np,
NULL,
"fsl,mpc5121-psc") {
403 tx_fifo_size = get_fifo_size(np,
"fsl,tx-fifo-size");
404 rx_fifo_size = get_fifo_size(np,
"fsl,rx-fifo-size");
416 pr_err(
"%s: Can't map %s device\n",
422 if ((fifobase + tx_fifo_size + rx_fifo_size) > 0x1000) {
423 pr_err(
"%s: no fifo space available for %s\n",
434 out_be32(&
FIFOC(psc)->txsz, (fifobase << 16) | tx_fifo_size);
435 fifobase += tx_fifo_size;
436 out_be32(&
FIFOC(psc)->rxsz, (fifobase << 16) | rx_fifo_size);
437 fifobase += rx_fifo_size;
453 mpc512x_restart_init();