Path: blob/master/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
10818 views
/*1* MPC8610 HPCD board specific routines2*3* Initial author: Xianghua Xiao <[email protected]>4* Recode: Jason Jin <[email protected]>5* York Sun <[email protected]>6*7* Rewrite the interrupt routing. remove the 8259PIC support,8* All the integrated device in ULI use sideband interrupt.9*10* Copyright 2008 Freescale Semiconductor Inc.11*12* This program is free software; you can redistribute it and/or modify it13* under the terms of the GNU General Public License as published by the14* Free Software Foundation; either version 2 of the License, or (at your15* option) any later version.16*/1718#include <linux/stddef.h>19#include <linux/kernel.h>20#include <linux/pci.h>21#include <linux/interrupt.h>22#include <linux/kdev_t.h>23#include <linux/delay.h>24#include <linux/seq_file.h>25#include <linux/of.h>2627#include <asm/system.h>28#include <asm/time.h>29#include <asm/machdep.h>30#include <asm/pci-bridge.h>31#include <asm/prom.h>32#include <mm/mmu_decl.h>33#include <asm/udbg.h>3435#include <asm/mpic.h>3637#include <linux/of_platform.h>38#include <sysdev/fsl_pci.h>39#include <sysdev/fsl_soc.h>40#include <sysdev/simple_gpio.h>4142#include "mpc86xx.h"4344static struct device_node *pixis_node;45static unsigned char *pixis_bdcfg0, *pixis_arch;4647#ifdef CONFIG_SUSPEND48static irqreturn_t mpc8610_sw9_irq(int irq, void *data)49{50pr_debug("%s: PIXIS' event (sw9/wakeup) IRQ handled\n", __func__);51return IRQ_HANDLED;52}5354static void __init mpc8610_suspend_init(void)55{56int irq;57int ret;5859if (!pixis_node)60return;6162irq = irq_of_parse_and_map(pixis_node, 0);63if (!irq) {64pr_err("%s: can't map pixis event IRQ.\n", __func__);65return;66}6768ret = request_irq(irq, mpc8610_sw9_irq, 0, "sw9:wakeup", NULL);69if (ret) {70pr_err("%s: can't request pixis event IRQ: %d\n",71__func__, ret);72irq_dispose_mapping(irq);73}7475enable_irq_wake(irq);76}77#else78static inline void mpc8610_suspend_init(void) { }79#endif /* CONFIG_SUSPEND */8081static struct of_device_id __initdata mpc8610_ids[] = {82{ .compatible = "fsl,mpc8610-immr", },83{ .compatible = "fsl,mpc8610-guts", },84{ .compatible = "simple-bus", },85/* So that the DMA channel nodes can be probed individually: */86{ .compatible = "fsl,eloplus-dma", },87{}88};8990static int __init mpc8610_declare_of_platform_devices(void)91{92/* Firstly, register PIXIS GPIOs. */93simple_gpiochip_init("fsl,fpga-pixis-gpio-bank");9495/* Enable wakeup on PIXIS' event IRQ. */96mpc8610_suspend_init();9798/* Without this call, the SSI device driver won't get probed. */99of_platform_bus_probe(NULL, mpc8610_ids, NULL);100101return 0;102}103machine_device_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);104105#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)106107/*108* DIU Area Descriptor109*110* The MPC8610 reference manual shows the bits of the AD register in111* little-endian order, which causes the BLUE_C field to be split into two112* parts. To simplify the definition of the MAKE_AD() macro, we define the113* fields in big-endian order and byte-swap the result.114*115* So even though the registers don't look like they're in the116* same bit positions as they are on the P1022, the same value is written to117* the AD register on the MPC8610 and on the P1022.118*/119#define AD_BYTE_F 0x10000000120#define AD_ALPHA_C_MASK 0x0E000000121#define AD_ALPHA_C_SHIFT 25122#define AD_BLUE_C_MASK 0x01800000123#define AD_BLUE_C_SHIFT 23124#define AD_GREEN_C_MASK 0x00600000125#define AD_GREEN_C_SHIFT 21126#define AD_RED_C_MASK 0x00180000127#define AD_RED_C_SHIFT 19128#define AD_PALETTE 0x00040000129#define AD_PIXEL_S_MASK 0x00030000130#define AD_PIXEL_S_SHIFT 16131#define AD_COMP_3_MASK 0x0000F000132#define AD_COMP_3_SHIFT 12133#define AD_COMP_2_MASK 0x00000F00134#define AD_COMP_2_SHIFT 8135#define AD_COMP_1_MASK 0x000000F0136#define AD_COMP_1_SHIFT 4137#define AD_COMP_0_MASK 0x0000000F138#define AD_COMP_0_SHIFT 0139140#define MAKE_AD(alpha, red, blue, green, size, c0, c1, c2, c3) \141cpu_to_le32(AD_BYTE_F | (alpha << AD_ALPHA_C_SHIFT) | \142(blue << AD_BLUE_C_SHIFT) | (green << AD_GREEN_C_SHIFT) | \143(red << AD_RED_C_SHIFT) | (c3 << AD_COMP_3_SHIFT) | \144(c2 << AD_COMP_2_SHIFT) | (c1 << AD_COMP_1_SHIFT) | \145(c0 << AD_COMP_0_SHIFT) | (size << AD_PIXEL_S_SHIFT))146147unsigned int mpc8610hpcd_get_pixel_format(unsigned int bits_per_pixel,148int monitor_port)149{150static const unsigned long pixelformat[][3] = {151{152MAKE_AD(3, 0, 2, 1, 3, 8, 8, 8, 8),153MAKE_AD(4, 2, 0, 1, 2, 8, 8, 8, 0),154MAKE_AD(4, 0, 2, 1, 1, 5, 6, 5, 0)155},156{157MAKE_AD(3, 2, 0, 1, 3, 8, 8, 8, 8),158MAKE_AD(4, 0, 2, 1, 2, 8, 8, 8, 0),159MAKE_AD(4, 2, 0, 1, 1, 5, 6, 5, 0)160},161};162unsigned int arch_monitor;163164/* The DVI port is mis-wired on revision 1 of this board. */165arch_monitor = ((*pixis_arch == 0x01) && (monitor_port == 0))? 0 : 1;166167switch (bits_per_pixel) {168case 32:169return pixelformat[arch_monitor][0];170case 24:171return pixelformat[arch_monitor][1];172case 16:173return pixelformat[arch_monitor][2];174default:175pr_err("fsl-diu: unsupported pixel depth %u\n", bits_per_pixel);176return 0;177}178}179180void mpc8610hpcd_set_gamma_table(int monitor_port, char *gamma_table_base)181{182int i;183if (monitor_port == 2) { /* dual link LVDS */184for (i = 0; i < 256*3; i++)185gamma_table_base[i] = (gamma_table_base[i] << 2) |186((gamma_table_base[i] >> 6) & 0x03);187}188}189190#define PX_BRDCFG0_DVISEL (1 << 3)191#define PX_BRDCFG0_DLINK (1 << 4)192#define PX_BRDCFG0_DIU_MASK (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)193194void mpc8610hpcd_set_monitor_port(int monitor_port)195{196static const u8 bdcfg[] = {197PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK,198PX_BRDCFG0_DLINK,1990,200};201202if (monitor_port < 3)203clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,204bdcfg[monitor_port]);205}206207void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)208{209u32 __iomem *clkdvdr;210u32 temp;211/* variables for pixel clock calcs */212ulong bestval, bestfreq, speed_ccb, minpixclock, maxpixclock;213ulong pixval;214long err;215int i;216217clkdvdr = ioremap(get_immrbase() + 0xe0800, sizeof(u32));218if (!clkdvdr) {219printk(KERN_ERR "Err: can't map clock divider register!\n");220return;221}222223/* Pixel Clock configuration */224speed_ccb = fsl_get_sys_freq();225226/* Calculate the pixel clock with the smallest error */227/* calculate the following in steps to avoid overflow */228pr_debug("DIU pixclock in ps - %d\n", pixclock);229temp = 1000000000/pixclock;230temp *= 1000;231pixclock = temp;232pr_debug("DIU pixclock freq - %u\n", pixclock);233234temp = pixclock * 5 / 100;235pr_debug("deviation = %d\n", temp);236minpixclock = pixclock - temp;237maxpixclock = pixclock + temp;238pr_debug("DIU minpixclock - %lu\n", minpixclock);239pr_debug("DIU maxpixclock - %lu\n", maxpixclock);240pixval = speed_ccb/pixclock;241pr_debug("DIU pixval = %lu\n", pixval);242243err = 100000000;244bestval = pixval;245pr_debug("DIU bestval = %lu\n", bestval);246247bestfreq = 0;248for (i = -1; i <= 1; i++) {249temp = speed_ccb / ((pixval+i) + 1);250pr_debug("DIU test pixval i= %d, pixval=%lu, temp freq. = %u\n",251i, pixval, temp);252if ((temp < minpixclock) || (temp > maxpixclock))253pr_debug("DIU exceeds monitor range (%lu to %lu)\n",254minpixclock, maxpixclock);255else if (abs(temp - pixclock) < err) {256pr_debug("Entered the else if block %d\n", i);257err = abs(temp - pixclock);258bestval = pixval+i;259bestfreq = temp;260}261}262263pr_debug("DIU chose = %lx\n", bestval);264pr_debug("DIU error = %ld\n NomPixClk ", err);265pr_debug("DIU: Best Freq = %lx\n", bestfreq);266/* Modify PXCLK in GUTS CLKDVDR */267pr_debug("DIU: Current value of CLKDVDR = 0x%08x\n", (*clkdvdr));268temp = (*clkdvdr) & 0x2000FFFF;269*clkdvdr = temp; /* turn off clock */270*clkdvdr = temp | 0x80000000 | (((bestval) & 0x1F) << 16);271pr_debug("DIU: Modified value of CLKDVDR = 0x%08x\n", (*clkdvdr));272iounmap(clkdvdr);273}274275ssize_t mpc8610hpcd_show_monitor_port(int monitor_port, char *buf)276{277return snprintf(buf, PAGE_SIZE,278"%c0 - DVI\n"279"%c1 - Single link LVDS\n"280"%c2 - Dual link LVDS\n",281monitor_port == 0 ? '*' : ' ',282monitor_port == 1 ? '*' : ' ',283monitor_port == 2 ? '*' : ' ');284}285286int mpc8610hpcd_set_sysfs_monitor_port(int val)287{288return val < 3 ? val : 0;289}290291#endif292293static void __init mpc86xx_hpcd_setup_arch(void)294{295struct resource r;296struct device_node *np;297unsigned char *pixis;298299if (ppc_md.progress)300ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);301302#ifdef CONFIG_PCI303for_each_node_by_type(np, "pci") {304if (of_device_is_compatible(np, "fsl,mpc8610-pci")305|| of_device_is_compatible(np, "fsl,mpc8641-pcie")) {306struct resource rsrc;307of_address_to_resource(np, 0, &rsrc);308if ((rsrc.start & 0xfffff) == 0xa000)309fsl_add_bridge(np, 1);310else311fsl_add_bridge(np, 0);312}313}314#endif315#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)316diu_ops.get_pixel_format = mpc8610hpcd_get_pixel_format;317diu_ops.set_gamma_table = mpc8610hpcd_set_gamma_table;318diu_ops.set_monitor_port = mpc8610hpcd_set_monitor_port;319diu_ops.set_pixel_clock = mpc8610hpcd_set_pixel_clock;320diu_ops.show_monitor_port = mpc8610hpcd_show_monitor_port;321diu_ops.set_sysfs_monitor_port = mpc8610hpcd_set_sysfs_monitor_port;322#endif323324pixis_node = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");325if (pixis_node) {326of_address_to_resource(pixis_node, 0, &r);327of_node_put(pixis_node);328pixis = ioremap(r.start, 32);329if (!pixis) {330printk(KERN_ERR "Err: can't map FPGA cfg register!\n");331return;332}333pixis_bdcfg0 = pixis + 8;334pixis_arch = pixis + 1;335} else336printk(KERN_ERR "Err: "337"can't find device node 'fsl,fpga-pixis'\n");338339printk("MPC86xx HPCD board from Freescale Semiconductor\n");340}341342/*343* Called very early, device-tree isn't unflattened344*/345static int __init mpc86xx_hpcd_probe(void)346{347unsigned long root = of_get_flat_dt_root();348349if (of_flat_dt_is_compatible(root, "fsl,MPC8610HPCD"))350return 1; /* Looks good */351352return 0;353}354355static long __init mpc86xx_time_init(void)356{357unsigned int temp;358359/* Set the time base to zero */360mtspr(SPRN_TBWL, 0);361mtspr(SPRN_TBWU, 0);362363temp = mfspr(SPRN_HID0);364temp |= HID0_TBEN;365mtspr(SPRN_HID0, temp);366asm volatile("isync");367368return 0;369}370371define_machine(mpc86xx_hpcd) {372.name = "MPC86xx HPCD",373.probe = mpc86xx_hpcd_probe,374.setup_arch = mpc86xx_hpcd_setup_arch,375.init_IRQ = mpc86xx_init_irq,376.get_irq = mpic_get_irq,377.restart = fsl_rstcr_restart,378.time_init = mpc86xx_time_init,379.calibrate_decr = generic_calibrate_decr,380.progress = udbg_progress,381.pcibios_fixup_bus = fsl_pcibios_fixup_bus,382};383384385