Path: blob/master/arch/powerpc/platforms/85xx/p1022_ds.c
26481 views
/*1* P1022DS board specific routines2*3* Authors: Travis Wheatley <[email protected]>4* Dave Liu <[email protected]>5* Timur Tabi <[email protected]>6*7* Copyright 2010 Freescale Semiconductor, Inc.8*9* This file is taken from the Freescale P1022DS BSP, with modifications:10* 2) No AMP support11* 3) No PCI endpoint support12*13* This file is licensed under the terms of the GNU General Public License14* version 2. This program is licensed "as is" without any warranty of any15* kind, whether express or implied.16*/1718#include <linux/fsl/guts.h>19#include <linux/pci.h>20#include <linux/of.h>21#include <linux/of_address.h>22#include <asm/div64.h>23#include <asm/mpic.h>24#include <asm/swiotlb.h>2526#include <sysdev/fsl_soc.h>27#include <sysdev/fsl_pci.h>28#include <asm/udbg.h>29#include <asm/fsl_lbc.h>30#include "smp.h"3132#include "mpc85xx.h"3334#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)3536#define PMUXCR_ELBCDIU_MASK 0xc000000037#define PMUXCR_ELBCDIU_NOR16 0x8000000038#define PMUXCR_ELBCDIU_DIU 0x400000003940/*41* Board-specific initialization of the DIU. This code should probably be42* executed when the DIU is opened, rather than in arch code, but the DIU43* driver does not have a mechanism for this (yet).44*45* This is especially problematic on the P1022DS because the local bus (eLBC)46* and the DIU video signals share the same pins, which means that enabling the47* DIU will disable access to NOR flash.48*/4950/* DIU Pixel Clock bits of the CLKDVDR Global Utilities register */51#define CLKDVDR_PXCKEN 0x8000000052#define CLKDVDR_PXCKINV 0x1000000053#define CLKDVDR_PXCKDLY 0x0600000054#define CLKDVDR_PXCLK_MASK 0x00FF00005556/* Some ngPIXIS register definitions */57#define PX_CTL 358#define PX_BRDCFG0 859#define PX_BRDCFG1 96061#define PX_BRDCFG0_ELBC_SPI_MASK 0xc062#define PX_BRDCFG0_ELBC_SPI_ELBC 0x0063#define PX_BRDCFG0_ELBC_SPI_NULL 0xc064#define PX_BRDCFG0_ELBC_DIU 0x026566#define PX_BRDCFG1_DVIEN 0x8067#define PX_BRDCFG1_DFPEN 0x4068#define PX_BRDCFG1_BACKLIGHT 0x2069#define PX_BRDCFG1_DDCEN 0x107071#define PX_CTL_ALTACC 0x807273/*74* DIU Area Descriptor75*76* Note that we need to byte-swap the value before it's written to the AD77* register. So even though the registers don't look like they're in the same78* bit positions as they are on the MPC8610, the same value is written to the79* AD register on the MPC8610 and on the P1022.80*/81#define AD_BYTE_F 0x1000000082#define AD_ALPHA_C_MASK 0x0E00000083#define AD_ALPHA_C_SHIFT 2584#define AD_BLUE_C_MASK 0x0180000085#define AD_BLUE_C_SHIFT 2386#define AD_GREEN_C_MASK 0x0060000087#define AD_GREEN_C_SHIFT 2188#define AD_RED_C_MASK 0x0018000089#define AD_RED_C_SHIFT 1990#define AD_PALETTE 0x0004000091#define AD_PIXEL_S_MASK 0x0003000092#define AD_PIXEL_S_SHIFT 1693#define AD_COMP_3_MASK 0x0000F00094#define AD_COMP_3_SHIFT 1295#define AD_COMP_2_MASK 0x00000F0096#define AD_COMP_2_SHIFT 897#define AD_COMP_1_MASK 0x000000F098#define AD_COMP_1_SHIFT 499#define AD_COMP_0_MASK 0x0000000F100#define AD_COMP_0_SHIFT 0101102#define MAKE_AD(alpha, red, blue, green, size, c0, c1, c2, c3) \103cpu_to_le32(AD_BYTE_F | (alpha << AD_ALPHA_C_SHIFT) | \104(blue << AD_BLUE_C_SHIFT) | (green << AD_GREEN_C_SHIFT) | \105(red << AD_RED_C_SHIFT) | (c3 << AD_COMP_3_SHIFT) | \106(c2 << AD_COMP_2_SHIFT) | (c1 << AD_COMP_1_SHIFT) | \107(c0 << AD_COMP_0_SHIFT) | (size << AD_PIXEL_S_SHIFT))108109struct fsl_law {110u32 lawbar;111u32 reserved1;112u32 lawar;113u32 reserved[5];114};115116#define LAWBAR_MASK 0x00F00000117#define LAWBAR_SHIFT 12118119#define LAWAR_EN 0x80000000120#define LAWAR_TGT_MASK 0x01F00000121#define LAW_TRGT_IF_LBC (0x04 << 20)122123#define LAWAR_MASK (LAWAR_EN | LAWAR_TGT_MASK)124#define LAWAR_MATCH (LAWAR_EN | LAW_TRGT_IF_LBC)125126#define BR_BA 0xFFFF8000127128/*129* Map a BRx value to a physical address130*131* The localbus BRx registers only store the lower 32 bits of the address. To132* obtain the upper four bits, we need to scan the LAW table. The entry which133* maps to the localbus will contain the upper four bits.134*/135static phys_addr_t lbc_br_to_phys(const void *ecm, unsigned int count, u32 br)136{137#ifndef CONFIG_PHYS_64BIT138/*139* If we only have 32-bit addressing, then the BRx address *is* the140* physical address.141*/142return br & BR_BA;143#else144const struct fsl_law *law = ecm + 0xc08;145unsigned int i;146147for (i = 0; i < count; i++) {148u64 lawbar = in_be32(&law[i].lawbar);149u32 lawar = in_be32(&law[i].lawar);150151if ((lawar & LAWAR_MASK) == LAWAR_MATCH)152/* Extract the upper four bits */153return (br & BR_BA) | ((lawbar & LAWBAR_MASK) << 12);154}155156return 0;157#endif158}159160/**161* p1022ds_set_monitor_port: switch the output to a different monitor port162*/163static void p1022ds_set_monitor_port(enum fsl_diu_monitor_port port)164{165struct device_node *guts_node;166struct device_node *lbc_node = NULL;167struct device_node *law_node = NULL;168struct ccsr_guts __iomem *guts;169struct fsl_lbc_regs *lbc = NULL;170void *ecm = NULL;171u8 __iomem *lbc_lcs0_ba = NULL;172u8 __iomem *lbc_lcs1_ba = NULL;173phys_addr_t cs0_addr, cs1_addr;174u32 br0, or0, br1, or1;175const __be32 *iprop;176unsigned int num_laws;177u8 b;178179/* Map the global utilities registers. */180guts_node = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts");181if (!guts_node) {182pr_err("p1022ds: missing global utilities device node\n");183return;184}185186guts = of_iomap(guts_node, 0);187if (!guts) {188pr_err("p1022ds: could not map global utilities device\n");189goto exit;190}191192lbc_node = of_find_compatible_node(NULL, NULL, "fsl,p1022-elbc");193if (!lbc_node) {194pr_err("p1022ds: missing localbus node\n");195goto exit;196}197198lbc = of_iomap(lbc_node, 0);199if (!lbc) {200pr_err("p1022ds: could not map localbus node\n");201goto exit;202}203204law_node = of_find_compatible_node(NULL, NULL, "fsl,ecm-law");205if (!law_node) {206pr_err("p1022ds: missing local access window node\n");207goto exit;208}209210ecm = of_iomap(law_node, 0);211if (!ecm) {212pr_err("p1022ds: could not map local access window node\n");213goto exit;214}215216iprop = of_get_property(law_node, "fsl,num-laws", NULL);217if (!iprop) {218pr_err("p1022ds: LAW node is missing fsl,num-laws property\n");219goto exit;220}221num_laws = be32_to_cpup(iprop);222223/*224* Indirect mode requires both BR0 and BR1 to be set to "GPCM",225* otherwise writes to these addresses won't actually appear on the226* local bus, and so the PIXIS won't see them.227*228* In FCM mode, writes go to the NAND controller, which does not pass229* them to the localbus directly. So we force BR0 and BR1 into GPCM230* mode, since we don't care about what's behind the localbus any231* more.232*/233br0 = in_be32(&lbc->bank[0].br);234br1 = in_be32(&lbc->bank[1].br);235or0 = in_be32(&lbc->bank[0].or);236or1 = in_be32(&lbc->bank[1].or);237238/* Make sure CS0 and CS1 are programmed */239if (!(br0 & BR_V) || !(br1 & BR_V)) {240pr_err("p1022ds: CS0 and/or CS1 is not programmed\n");241goto exit;242}243244/*245* Use the existing BRx/ORx values if it's already GPCM. Otherwise,246* force the values to simple 32KB GPCM windows with the most247* conservative timing.248*/249if ((br0 & BR_MSEL) != BR_MS_GPCM) {250br0 = (br0 & BR_BA) | BR_V;251or0 = 0xFFFF8000 | 0xFF7;252out_be32(&lbc->bank[0].br, br0);253out_be32(&lbc->bank[0].or, or0);254}255if ((br1 & BR_MSEL) != BR_MS_GPCM) {256br1 = (br1 & BR_BA) | BR_V;257or1 = 0xFFFF8000 | 0xFF7;258out_be32(&lbc->bank[1].br, br1);259out_be32(&lbc->bank[1].or, or1);260}261262cs0_addr = lbc_br_to_phys(ecm, num_laws, br0);263if (!cs0_addr) {264pr_err("p1022ds: could not determine physical address for CS0"265" (BR0=%08x)\n", br0);266goto exit;267}268cs1_addr = lbc_br_to_phys(ecm, num_laws, br1);269if (!cs1_addr) {270pr_err("p1022ds: could not determine physical address for CS1"271" (BR1=%08x)\n", br1);272goto exit;273}274275lbc_lcs0_ba = ioremap(cs0_addr, 1);276if (!lbc_lcs0_ba) {277pr_err("p1022ds: could not ioremap CS0 address %llx\n",278(unsigned long long)cs0_addr);279goto exit;280}281lbc_lcs1_ba = ioremap(cs1_addr, 1);282if (!lbc_lcs1_ba) {283pr_err("p1022ds: could not ioremap CS1 address %llx\n",284(unsigned long long)cs1_addr);285goto exit;286}287288/* Make sure we're in indirect mode first. */289if ((in_be32(&guts->pmuxcr) & PMUXCR_ELBCDIU_MASK) !=290PMUXCR_ELBCDIU_DIU) {291struct device_node *pixis_node;292void __iomem *pixis;293294pixis_node =295of_find_compatible_node(NULL, NULL, "fsl,p1022ds-fpga");296if (!pixis_node) {297pr_err("p1022ds: missing pixis node\n");298goto exit;299}300301pixis = of_iomap(pixis_node, 0);302of_node_put(pixis_node);303if (!pixis) {304pr_err("p1022ds: could not map pixis registers\n");305goto exit;306}307308/* Enable indirect PIXIS mode. */309setbits8(pixis + PX_CTL, PX_CTL_ALTACC);310iounmap(pixis);311312/* Switch the board mux to the DIU */313out_8(lbc_lcs0_ba, PX_BRDCFG0); /* BRDCFG0 */314b = in_8(lbc_lcs1_ba);315b |= PX_BRDCFG0_ELBC_DIU;316out_8(lbc_lcs1_ba, b);317318/* Set the chip mux to DIU mode. */319clrsetbits_be32(&guts->pmuxcr, PMUXCR_ELBCDIU_MASK,320PMUXCR_ELBCDIU_DIU);321in_be32(&guts->pmuxcr);322}323324325switch (port) {326case FSL_DIU_PORT_DVI:327/* Enable the DVI port, disable the DFP and the backlight */328out_8(lbc_lcs0_ba, PX_BRDCFG1);329b = in_8(lbc_lcs1_ba);330b &= ~(PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT);331b |= PX_BRDCFG1_DVIEN;332out_8(lbc_lcs1_ba, b);333break;334case FSL_DIU_PORT_LVDS:335/*336* LVDS also needs backlight enabled, otherwise the display337* will be blank.338*/339/* Enable the DFP port, disable the DVI and the backlight */340out_8(lbc_lcs0_ba, PX_BRDCFG1);341b = in_8(lbc_lcs1_ba);342b &= ~PX_BRDCFG1_DVIEN;343b |= PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT;344out_8(lbc_lcs1_ba, b);345break;346default:347pr_err("p1022ds: unsupported monitor port %i\n", port);348}349350exit:351if (lbc_lcs1_ba)352iounmap(lbc_lcs1_ba);353if (lbc_lcs0_ba)354iounmap(lbc_lcs0_ba);355if (lbc)356iounmap(lbc);357if (ecm)358iounmap(ecm);359if (guts)360iounmap(guts);361362of_node_put(law_node);363of_node_put(lbc_node);364of_node_put(guts_node);365}366367/**368* p1022ds_set_pixel_clock: program the DIU's clock369*370* @pixclock: the wavelength, in picoseconds, of the clock371*/372static void p1022ds_set_pixel_clock(unsigned int pixclock)373{374struct device_node *guts_np = NULL;375struct ccsr_guts __iomem *guts;376unsigned long freq;377u64 temp;378u32 pxclk;379380/* Map the global utilities registers. */381guts_np = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts");382if (!guts_np) {383pr_err("p1022ds: missing global utilities device node\n");384return;385}386387guts = of_iomap(guts_np, 0);388of_node_put(guts_np);389if (!guts) {390pr_err("p1022ds: could not map global utilities device\n");391return;392}393394/* Convert pixclock from a wavelength to a frequency */395temp = 1000000000000ULL;396do_div(temp, pixclock);397freq = temp;398399/*400* 'pxclk' is the ratio of the platform clock to the pixel clock.401* This number is programmed into the CLKDVDR register, and the valid402* range of values is 2-255.403*/404pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq);405pxclk = clamp_t(u32, pxclk, 2, 255);406407/* Disable the pixel clock, and set it to non-inverted and no delay */408clrbits32(&guts->clkdvdr,409CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);410411/* Enable the clock and set the pxclk */412setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));413414iounmap(guts);415}416417/**418* p1022ds_valid_monitor_port: set the monitor port for sysfs419*/420static enum fsl_diu_monitor_port421p1022ds_valid_monitor_port(enum fsl_diu_monitor_port port)422{423switch (port) {424case FSL_DIU_PORT_DVI:425case FSL_DIU_PORT_LVDS:426return port;427default:428return FSL_DIU_PORT_DVI; /* Dual-link LVDS is not supported */429}430}431432#endif433434static void __init p1022_ds_pic_init(void)435{436struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |437MPIC_SINGLE_DEST_CPU,4380, 256, " OpenPIC ");439BUG_ON(mpic == NULL);440mpic_init(mpic);441}442443#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)444445/* TRUE if there is a "video=fslfb" command-line parameter. */446static bool fslfb;447448/*449* Search for a "video=fslfb" command-line parameter, and set 'fslfb' to450* true if we find it.451*452* We need to use early_param() instead of __setup() because the normal453* __setup() gets called to late. However, early_param() gets called very454* early, before the device tree is unflattened, so all we can do now is set a455* global variable. Later on, p1022_ds_setup_arch() will use that variable456* to determine if we need to update the device tree.457*/458static int __init early_video_setup(char *options)459{460fslfb = (strncmp(options, "fslfb:", 6) == 0);461462return 0;463}464early_param("video", early_video_setup);465466#endif467468/*469* Setup the architecture470*/471static void __init p1022_ds_setup_arch(void)472{473if (ppc_md.progress)474ppc_md.progress("p1022_ds_setup_arch()", 0);475476#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)477diu_ops.set_monitor_port = p1022ds_set_monitor_port;478diu_ops.set_pixel_clock = p1022ds_set_pixel_clock;479diu_ops.valid_monitor_port = p1022ds_valid_monitor_port;480481/*482* Disable the NOR and NAND flash nodes if there is video=fslfb...483* command-line parameter. When the DIU is active, the localbus is484* unavailable, so we have to disable these nodes before the MTD485* driver loads.486*/487if (fslfb) {488struct device_node *np =489of_find_compatible_node(NULL, NULL, "fsl,p1022-elbc");490491if (np) {492struct device_node *np2;493494of_node_get(np);495np2 = of_find_compatible_node(np, NULL, "cfi-flash");496if (np2) {497static struct property nor_status = {498.name = "status",499.value = "disabled",500.length = sizeof("disabled"),501};502503/*504* of_update_property() is called before505* kmalloc() is available, so the 'new' object506* should be allocated in the global area.507* The easiest way is to do that is to508* allocate one static local variable for each509* call to this function.510*/511pr_info("p1022ds: disabling %pOF node",512np2);513of_update_property(np2, &nor_status);514of_node_put(np2);515}516517of_node_get(np);518np2 = of_find_compatible_node(np, NULL,519"fsl,elbc-fcm-nand");520if (np2) {521static struct property nand_status = {522.name = "status",523.value = "disabled",524.length = sizeof("disabled"),525};526527pr_info("p1022ds: disabling %pOF node",528np2);529of_update_property(np2, &nand_status);530of_node_put(np2);531}532533of_node_put(np);534}535536}537538#endif539540mpc85xx_smp_init();541542fsl_pci_assign_primary();543544swiotlb_detect_4g();545546pr_info("Freescale P1022 DS reference board\n");547}548549machine_arch_initcall(p1022_ds, mpc85xx_common_publish_devices);550551define_machine(p1022_ds) {552.name = "P1022 DS",553.compatible = "fsl,p1022ds",554.setup_arch = p1022_ds_setup_arch,555.init_IRQ = p1022_ds_pic_init,556#ifdef CONFIG_PCI557.pcibios_fixup_bus = fsl_pcibios_fixup_bus,558.pcibios_fixup_phb = fsl_pcibios_fixup_phb,559#endif560.get_irq = mpic_get_irq,561.progress = udbg_progress,562};563564565