/* * Configure all necessary GPIO pins */ static void gpio_init(void) { /* * Enable power on GPIO. This is not really necessary, because power * on GPIO is enabled on SoC reset. */ lpc178x_periph_enable(LPC178X_SCC_PCONP_PCGPIO_MSK, 1); /* * Configure GPIO pins using the `ea_lpc1788_gpio[]` table */ lpc178x_gpio_config_table(ea_lpc1788_gpio, ARRAY_SIZE(ea_lpc1788_gpio)); #ifdef CONFIG_NR_DRAM_BANKS /* * Configure GPIO pins used for the External Memory Controller (EMC) */ struct lpc178x_gpio_dsc dsc; /* Configure EMC data pins (DQ0..DQ31) */ dsc.port = 3; for (dsc.pin = 0; dsc.pin <= LPC178X_EMC_DATA_PINS; dsc.pin++) lpc178x_gpio_config(&dsc, LPC178X_GPIO_EMC_REGVAL); /* * Configure EMC row/column address pins (A0..A11) and * NOR FLash address pins. */ dsc.port = 4; for (dsc.pin = 0; dsc.pin <= LPC178X_EMC_ADDR_PINS; dsc.pin++) lpc178x_gpio_config(&dsc, LPC178X_GPIO_EMC_REGVAL); #endif }
/* * Initialize the GPIO Alternative Functions of the LPC178x/7x. */ void __init lpc178x_iomux_init(void) { int platform; /* * Enable power on GPIO. This is not really necessary, because power * on GPIO is enabled on SoC reset. */ lpc178x_periph_enable(LPC178X_SCC_PCONP_PCGPIO_MSK, 1); /* * Configure IOs depending on the board we're running on, and * the configuration options we're using. * Let's control platform strictly: if some of it does not need to * play with iomux, it must be present in switch below (otherwise, * the warning message will be printed-out) */ platform = lpc178x_platform_get(); switch (platform) { case PLATFORM_LPC178X_EA_LPC1788: lpc178x_gpio_config_table( ea_lpc1788_gpio, ARRAY_SIZE(ea_lpc1788_gpio)); break; case PLATFORM_LPC178X_LNX_EVB: lpc178x_gpio_config_table( lpc_lnx_evb_gpio, ARRAY_SIZE(lpc_lnx_evb_gpio)); break; default: printk(KERN_WARNING "%s: unsupported platform %d\n", __func__, platform); break; } }
void __init lpc178x_fb_init(void) { int platform; int have_lcd; int ret; /* * Run board-specific code */ have_lcd = 0; ret = 0; platform = lpc178x_platform_get(); switch (platform) { case PLATFORM_LPC178X_EA_LPC1788: have_lcd = 1; /* * This code finally makes the function * `ealcd004_pca9532_probe()` to execute. */ ret = i2c_add_driver(&ealcd004_pca9532_driver); if (ret < 0) goto out; ret = i2c_register_board_info(0, &ea_lpc1788_lcd_004_dimmer, 1); if (ret < 0) goto out; break; case PLATFORM_LPC178X_LNX_EVB: /* Do not configure LCD on LPC-LNX-EVB for now */ break; default: break; } if (!have_lcd) goto out; /* * Enable the power on the LCD controller module of the MCU * before we call `amba_device_register()`. This is required, because * `amba_device_register()` will try to read the AMBA device ID * from the LCD controller module's register map; if the power on * the module is off, its registers are not accessible. */ lpc178x_periph_enable(LPC178X_SCC_PCONP_PCLCD_MSK, 1); amba_device_register(&lpc178x_fb_device, &iomem_resource); out: if (ret < 0) { printk(KERN_ERR "lpc178x fb: Could not initialize " "the LCD screen.\n"); } }
/* * Early hardware init. */ int board_init(void) { volatile struct lpc178x_emc_st_regs *st; /* * Enable power on EMC */ lpc178x_periph_enable(LPC178X_SCC_PCONP_PCEMC_MSK, 1); /* * Clock delay for EMC */ LPC178X_SCC->emcdlyctl = (LPC178X_EMC_CMDDLY << LPC178X_SCC_EMCDLYCTL_CMDDLY_BITS) | (LPC178X_EMC_FBCLKDLY << LPC178X_SCC_EMCDLYCTL_FBCLKDLY_BITS); /* * Enable EMC */ LPC178X_EMC->emcctrl = LPC178X_EMC_CTRL_EN_MSK; /* * Little-endian mode */ LPC178X_EMC->emccfg = 0; /* * Enable GPIO pins */ gpio_init(); #ifdef CONFIG_SYS_FLASH_CS /* Set timing for flash */ st = &LPC178X_EMC->st[CONFIG_SYS_FLASH_CS]; st->cfg = CONFIG_SYS_FLASH_CFG; st->we = CONFIG_SYS_FLASH_WE; st->oe = CONFIG_SYS_FLASH_OE; st->rd = CONFIG_SYS_FLASH_RD; st->page = CONFIG_SYS_FLASH_PAGE; st->wr = CONFIG_SYS_FLASH_WR; st->ta = CONFIG_SYS_FLASH_TA; #endif return 0; }
void pwm_init(){ long pclk; int pwm_div; pclk = clock_get(CLOCK_PCLK); pwm_div = pclk/PWM_CLK - 1; lpc178x_periph_enable(LPC178X_SCC_PCONP_PWM1_MSK, 1); LPC178X_PWM1->pwm_ir = 0x73f; //clear all pending LPC178X_PWM1->pwm_tcr = 0x0; LPC178X_PWM1->pwm_ctcr = 0x0; LPC178X_PWM1->pwm_mcr = 0x0; LPC178X_PWM1->pwm_ccr = 0x0; LPC178X_PWM1->pwm_pcr = 0x0; LPC178X_PWM1->pwm_ler = 0x0; LPC178X_PWM1->pwm_pr = pwm_div; LPC178X_PWM1->pwm_mr0 = PWM_TOTCNT; LPC178X_PWM1->pwm_ler |= 0x1<<0; //update mr0 //LPC178X_PWM1->pwm_tcr |= 0x1<<1; //pwm counter reset //LPC178X_PWM1->pwm_tcr &= 0x9; // LPC178X_PWM1->pwm_mr1 = PWM_LOWCNT_START; LPC178X_PWM1->pwm_ler |= 0x1<<1; //update mr1 //LPC178X_PWM1->pwm_tcr |= 0x1<<1; //pwm counter reset //LPC178X_PWM1->pwm_tcr &= 0x9; // LPC178X_PWM1->pwm_mcr = 0x1<<1; //PWMTC reset when PWMTC == PWMMR0 LPC178X_PWM1->pwm_pcr |= 0x1<<9; //pwm1[1] output enable LPC178X_PWM1->pwm_tcr |= 0x1<<1; //pwm counter reset LPC178X_PWM1->pwm_tcr &= 0x9; // LPC178X_PWM1->pwm_tcr |= 0x1<<0; //pwm counter enable LPC178X_PWM1->pwm_tcr |= 0x1<<3; //pwm enable }
void board_video_init(GraphicDevice *pGD){ long pclk; int lcd_div; unsigned int *pboost; unsigned int *pconp; lpc178x_periph_enable(LPC178X_SCC_PCONP_LCD_MSK, 1); pboost = (unsigned int *)0x400FC1B0; pconp= (unsigned int *)0x400FC0C4; printf("pboost = 0x%x\n", *pboost); printf("pconp = 0x%x\n", *pconp); pclk = clock_get(CLOCK_SYSTICK); lcd_div = pclk / (pGD->modeIdent[0] * 1000000); printf("lcd_div = %d\n", lcd_div); GLCD_Ctrl(0); LPC178X_LCD->crsr_ctrl &= ~(0x1<<0); //不使用光标 LPC178X_LCD->lcd_ctrl = 0x0; LPC178X_LCD->lcd_ctrl |= (0x6<<1); //16bpp, 5:6:5 mode LPC178X_LCD->lcd_ctrl |= (0x1<<5); // TFT panel LPC178X_LCD->lcd_ctrl &= ~(0x1<<7); // single panel LPC178X_LCD->lcd_ctrl &= ~(0x1<<8); // RGB normal sequence LPC178X_LCD->lcd_ctrl &= ~(0x1<<9); // little order LPC178X_LCD->lcd_ctrl &= ~(0x1<<10); // little order in one byte LPC178X_LCD->lcd_ctrl &= ~(0x1<<11); // disable LCD_VD[0:23] if(lcd_div > 0) lcd_div -= 1; else lcd_div = 0; LPC178X_SCC->lcd_cfg = lcd_div; LPC178X_LCD->lcd_pol |= (1<<26); // bypass inrenal clk divider LPC178X_LCD->lcd_pol &= ~(1<<5); // clock source for LCD is CCLK LPC178X_LCD->lcd_pol |= (1<<11); // LCDFP pin is active Low and inactive HIGH LPC178X_LCD->lcd_pol |= (1<<12); // LCDLP pin is active Low and inactive HIGH LPC178X_LCD->lcd_pol |= (1<<13); // data is driven out into the LCD on the falling edge //active high LPC178X_LCD->lcd_pol &= ~(1<<14); // LCD_ENAB_M is active high LPC178X_LCD->lcd_pol &= ~(0x3ff<<16); LPC178X_LCD->lcd_pol |= ((pGD->winSizeX)-1)<<16; //pixel per line // init Horizontal Timing LPC178X_LCD->lcd_timh = 0; LPC178X_LCD->lcd_timh |= ((pGD->modeIdent[1]) - 1)<<24; LPC178X_LCD->lcd_timh |= ((pGD->modeIdent[2]) - 1)<<16; LPC178X_LCD->lcd_timh |= ((pGD->modeIdent[5]) - 1)<<8; LPC178X_LCD->lcd_timh |= ((pGD->winSizeX)/16 - 1)<<2; // init Vertical Timing LPC178X_LCD->lcd_timv = 0; LPC178X_LCD->lcd_timv |= (pGD->modeIdent[3])<<24; LPC178X_LCD->lcd_timv |= (pGD->modeIdent[4])<<16; LPC178X_LCD->lcd_timv |= ((pGD->modeIdent[6]) - 1)<<10; LPC178X_LCD->lcd_timv |= (pGD->winSizeY) - 1; // init lcd base addr LPC178X_LCD->lcd_upbase = pGD->frameAdrs; LPC178X_LCD->lcd_lpbase = pGD->frameAdrs; GLCD_Ctrl(1); pwm_init(); }