Esempio n. 1
0
static int setup_power(int is_resume)
{
	int error = 0;
	int i;

	power_init();

	if (is_resume) {
		return 0;
	}

	/* Initialize I2C bus to configure PMIC. */
	exynos_pinmux_i2c4();
	i2c_init(PMIC_I2C_BUS, 1000000, 0x00); /* 1MHz */

	for (i = 0; i < ARRAY_SIZE(pmic_writes); i++) {
		uint8_t data = 0;
		uint8_t reg = pmic_writes[i].reg;

		if (pmic_writes[i].or_orig)
			error |= i2c_readb(4, MAX77802_I2C_ADDR, reg, &data);

		data |= pmic_writes[i].val;
		error |= i2c_writeb(4, MAX77802_I2C_ADDR, reg, data);
	}

	return error;
}
Esempio n. 2
0
static void setup_power(int is_resume)
{
	int error = 0;
	int i;

	power_init();

	if (is_resume) {
		return;
	}

	/* Initialize I2C bus to configure PMIC. */
	exynos_pinmux_i2c4();
	i2c_init(4, I2C_4_SPEED, 0x00);

	printk(BIOS_DEBUG, "%s: Setting up PMIC...\n", __func__);

	for (i = 0; i < ARRAY_SIZE(pmic_writes); i++) {
		uint8_t data = 0;
		uint8_t reg = pmic_writes[i].reg;

		if (pmic_writes[i].or_orig)
			error |= i2c_read(4, MAX77802_I2C_ADDR,
					  reg, sizeof(reg),
					  &data, sizeof(data));
		data |= pmic_writes[i].val;
		error |= i2c_write(4, MAX77802_I2C_ADDR,
				   reg, sizeof(reg),
				   &data, sizeof(data));
	}

	if (error)
		die("Failed to intialize PMIC.\n");
}
Esempio n. 3
0
int main(void)
{
    halInit();
    chSysInit();

    chBSemObjectInit(&frame_thread_sem, false);

    bus_init();
    power_init();

    sduObjectInit(&SDU1);
    sduStart(&SDU1, &serusbcfg);

    usbDisconnectBus(serusbcfg.usbp);
    chThdSleepMilliseconds(1500);
    usbStart(serusbcfg.usbp, &usbcfg);
    usbConnectBus(serusbcfg.usbp);

    chThdCreateStatic(frame_thread_wa, sizeof(frame_thread_wa),
        NORMALPRIO, frame_thread, NULL);

    while(true) {
        usb_rx(streamGet(&SDU1));
    }
}
Esempio n. 4
0
int board_late_init(void)
{
	setup_i2c(1);
	power_init();

	return 0;
}
Esempio n. 5
0
int board_late_init(void)
{
	if (!power_init())
		clock_1GHz();

	return 0;
}
Esempio n. 6
0
int board_late_init(void)
{
#ifdef CONFIG_MXC_SPI
	setup_iomux_spi();
	power_init();
#endif
	return 0;
}
Esempio n. 7
0
/* This function performs power estimation, and must be called
 * after packing, placement AND routing.  Currently, this
 * will not work when running a partial flow (ex. only routing).
 */
void vpr_power_estimation(t_vpr_setup vpr_setup, t_arch Arch) {
	e_power_ret_code power_ret_code;
	boolean power_error;

	/* Ensure we are only using 1 clock */
	assert(count_netlist_clocks() == 1);

	/* Get the critical path of this clock */
	g_solution_inf.T_crit = get_critical_path_delay() / 1e9;
	assert(g_solution_inf.T_crit > 0.);

	vpr_printf(TIO_MESSAGE_INFO, "\n\nPower Estimation:\n");
	vpr_printf(TIO_MESSAGE_INFO, "-----------------\n");

	vpr_printf(TIO_MESSAGE_INFO, "Initializing power module\n");

	/* Initialize the power module */
	power_error = power_init(vpr_setup.FileNameOpts.PowerFile,
			vpr_setup.FileNameOpts.CmosTechFile, &Arch, &vpr_setup.RoutingArch);
	if (power_error) {
		vpr_printf(TIO_MESSAGE_ERROR, "Power initialization failed.\n");
	}

	if (!power_error) {
		float power_runtime_s;

		vpr_printf(TIO_MESSAGE_INFO, "Running power estimation\n");

		/* Run power estimation */
		power_ret_code = power_total(&power_runtime_s, vpr_setup, &Arch,
				&vpr_setup.RoutingArch);

		/* Check for errors/warnings */
		if (power_ret_code == POWER_RET_CODE_ERRORS) {
			vpr_printf(TIO_MESSAGE_ERROR,
					"Power estimation failed. See power output for error details.\n");
		} else if (power_ret_code == POWER_RET_CODE_WARNINGS) {
			vpr_printf(TIO_MESSAGE_WARNING,
					"Power estimation completed with warnings. See power output for more details.\n");
		} else if (power_ret_code == POWER_RET_CODE_SUCCESS) {
		}
		vpr_printf(TIO_MESSAGE_INFO, "Power estimation took %g seconds\n",
				power_runtime_s);
	}

	/* Uninitialize power module */
	if (!power_error) {
		vpr_printf(TIO_MESSAGE_INFO, "Uninitializing power module\n");
		power_error = power_uninit();
		if (power_error) {
			vpr_printf(TIO_MESSAGE_ERROR, "Power uninitialization failed.\n");
		} else {

		}
	}
	vpr_printf(TIO_MESSAGE_INFO, "\n");
}
Esempio n. 8
0
int lowlevel_init_subsystems(void)
{
//	uint32_t reset_status;
	int actions = 0;

// 	do_barriers();

	/* Setup cpu info which is needed to select correct register offsets */
	cpu_info_init();

#if 0
	reset_status = power_read_reset_status();

	switch (reset_status) {
	case S5P_CHECK_SLEEP:
		actions = DO_CLOCKS | DO_WAKEUP;
		break;
	case S5P_CHECK_DIDLE:
	case S5P_CHECK_LPA:
		actions = DO_WAKEUP;
	default:
		/* This is a normal boot (not a wake from sleep) */
		actions = DO_UART | DO_CLOCKS | DO_POWER;
	}
#endif

	actions = DO_UART | DO_CLOCKS | DO_POWER;
	if (actions & DO_POWER)
		power_init();
	if (actions & DO_CLOCKS)
		system_clock_init();
	if (actions & DO_UART) {

		/* Set up serial UART so we can printf() */
		/* FIXME(dhendrix): add a function for mapping
		   CONFIG_CONSOLE_SERIAL_UART_ADDRESS to PERIPH_ID_UARTn */
//		exynos_pinmux_config(EXYNOS_UART, PINMUX_FLAG_NONE);
		exynos_pinmux_config(PERIPH_ID_UART3, PINMUX_FLAG_NONE);

		console_init();
		while (1) {
			console_tx_byte('C');
		}
	}
	init_timer();	/* FIXME(dhendrix): was timer_init() */

#if 0
	if (actions & DO_CLOCKS) {
		mem_ctrl_init();
		tzpc_init();
	}
#endif

//	return actions & DO_WAKEUP;
	return 0;
}
Esempio n. 9
0
int main(void) {
#if defined(NSEC_HARDCODED_BLE_DEVICE_ID)
    sprintf(g_device_id, "%.8s", NSEC_STRINGIFY(NSEC_HARDCODED_BLE_DEVICE_ID));
#else
    sprintf(g_device_id, "NSEC%04X", (uint16_t)(NRF_FICR->DEVICEID[1] % 0xFFFF));
#endif
    g_device_id[9] = '\0';

#ifdef NSEC_CTF_ADD_FLAGS
static volatile char flag1[] = "FLAG-60309301fa5b4a4e990392ead6ac7b5f";
printf("%s", flag1); // Don't optimize out flag1
rot13();
#endif

    /*
     * Initialize base hardware
     */
    log_init();
    power_init();
    softdevice_init();
    timer_init();
    init_WS2812FX();
    ssd1306_init();
    gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK);
    nsec_buttons_init();

    /*
     * Initialize bluetooth stack
     */
    create_ble_device(g_device_id);
    configure_advertising();
    nsec_led_ble_init();
    init_identity_service();
    start_advertising();
    nsec_battery_manager_init();
    nsec_status_bar_init();
    nsec_status_set_name(g_device_id);
    nsec_status_set_badge_class(NSEC_STRINGIFY(NSEC_HARDCODED_BADGE_CLASS));
    nsec_status_set_ble_status(STATUS_BLUETOOTH_ON);

    load_stored_led_settings();

    nsec_intro();
    show_main_menu();

    /*
     * Main loop
     */
    while(true) {
        service_WS2812FX();
        nsec_storage_update();
        power_manage();
    }

    return 0;
}
Esempio n. 10
0
int board_late_init(void)
{
	setup_i2c(1);
	power_init();

#ifdef CONFIG_CMD_BMODE
	add_board_boot_modes(board_boot_modes);
#endif
	return 0;
}
Esempio n. 11
0
void hardware_init(void)
{
	power_init();
	clock_init();
	pins_init();
	uart_init();
	timers_init();
	adc_init();
	irq_init();
}
Esempio n. 12
0
void sys_init(void)
{
	pll_init();
	power_init();
	vic_init();
	SYS_SetFastGPIO();
	gpio_init(test_handler);
	i2c_init();

	irq_enable();
}
Esempio n. 13
0
int board_late_init(void)
{
#ifdef CONFIG_MXC_SPI
        setup_iomux_spi();
        power_init();
#endif

        reset_phy();

#ifdef CONFIG_HW_WATCHDOG
        if(1){
                /* NOTE:                                                         */
                /*     hw_watchdog_init() seems not work, use the following code */
                /*     which is stolen from linux kerenel to init the watchdog.  */
                /*     hw_watchdog_reset() works fine!                           */
#define IMX2_WDT_WCR_WT		(0xFF << 8)	/* -> Watchdog Timeout Field */
#define IMX2_WDT_WCR_WRE	(1 << 3)	/* -> WDOG Reset Enable */
#define IMX2_WDT_WCR_WDE	(1 << 2)	/* -> Watchdog Enable */
#define WDOG_SEC_TO_COUNT(s)	((s * 2 - 1) << 8)

                u16 val = readw(WDOG1_BASE_ADDR);

                /* Strip the old watchdog Time-Out value */
                val &= ~IMX2_WDT_WCR_WT;
                /* Generate reset if WDOG times out */
                val &= ~IMX2_WDT_WCR_WRE;
                /* Keep Watchdog Disabled */
                val &= ~IMX2_WDT_WCR_WDE;
                /* Set the watchdog's Time-Out value */
                val |= WDOG_SEC_TO_COUNT(CONFIG_WATCHDOG_TIMEOUT_MSECS/1000);

                writew(val, WDOG1_BASE_ADDR);

                /* enable the watchdog */
                val |= IMX2_WDT_WCR_WDE;
                writew(val, WDOG1_BASE_ADDR);

                /* According to i,MX515 Reference Manual, the PDE bit */
                /* should be cleared within 16 second after boot */

                /* Write to the PDE (Power Down Enable) bit */
                writew(0, WDOG1_BASE_ADDR+8);

#undef IMX2_WDT_WCR_WT
#undef IMX2_WDT_WCR_WRE
#undef IMX2_WDT_WCR_WDE
#undef WDOG_SEC_TO_COUNT
        }

#endif
        return 0;
}
Esempio n. 14
0
static void setup_power(int is_resume)
{
	int error = 0;

	power_init();

	if (is_resume) {
		return;
	}

	/* Initialize I2C bus to configure PMIC. */
	exynos_pinmux_i2c0();
	i2c_init(0, I2C_0_SPEED, 0x00);

	printk(BIOS_DEBUG, "%s: Setting up PMIC...\n", __func__);
	/*
	 * We're using CR1616 coin cell battery that is non-rechargeable
	 * battery. But, BBCHOSTEN bit of the BBAT Charger Register in
	 * MAX77686 is enabled by default for charging coin cell.
	 *
	 * Also, we cannot meet the coin cell reverse current spec. in UL
	 * standard if BBCHOSTEN bit is enabled.
	 *
	 * Disable Coin BATT Charging
	 */
	error = max77686_disable_backup_batt(PMIC_BUS);

	error |= max77686_volsetting(PMIC_BUS, PMIC_BUCK2, VDD_ARM_MV,
						REG_ENABLE, MAX77686_MV);
	error |= max77686_volsetting(PMIC_BUS, PMIC_BUCK3, VDD_INT_UV,
						REG_ENABLE, MAX77686_UV);
	error |= max77686_volsetting(PMIC_BUS, PMIC_BUCK1, VDD_MIF_MV,
						REG_ENABLE, MAX77686_MV);
	error |= max77686_volsetting(PMIC_BUS, PMIC_BUCK4, VDD_G3D_MV,
						REG_ENABLE, MAX77686_MV);
	error |= max77686_volsetting(PMIC_BUS, PMIC_LDO2, VDD_LDO2_MV,
						REG_ENABLE, MAX77686_MV);
	error |= max77686_volsetting(PMIC_BUS, PMIC_LDO3, VDD_LDO3_MV,
						REG_ENABLE, MAX77686_MV);
	error |= max77686_volsetting(PMIC_BUS, PMIC_LDO5, VDD_LDO5_MV,
						REG_ENABLE, MAX77686_MV);
	error |= max77686_volsetting(PMIC_BUS, PMIC_LDO10, VDD_LDO10_MV,
						REG_ENABLE, MAX77686_MV);

	error |= max77686_enable_32khz_cp(PMIC_BUS);

	if (error) {
		printk(BIOS_CRIT, "%s: PMIC error: %#x\n", __func__, error);
		die("Failed to intialize PMIC.\n");
	}
}
Esempio n. 15
0
void main(void)
{
	struct mem_timings *mem;
	struct arm_clk_ratios *arm_ratios;
	int ret;
	void *entry;

	clock_set_rate(PERIPH_ID_SPI1, 50000000); /* set spi clock to 50Mhz */

	/* Clock must be initialized before console_init, otherwise you may need
	 * to re-initialize serial console drivers again. */
	mem = get_mem_timings();
	arm_ratios = get_arm_clk_ratios();
	system_clock_init(mem, arm_ratios);

	console_init();
	/*
	 * FIXME: Do necessary I2C init so low-level PMIC code doesn't need to.
	 * Also, we should only call power_init() on cold boot.
	 */
	power_init();

	if (!mem) {
		printk(BIOS_CRIT, "Unable to auto-detect memory timings\n");
		while(1);
	}
	printk(BIOS_SPEW, "man: 0x%x type: 0x%x, div: 0x%x, mhz: 0x%x\n",
		mem->mem_manuf,
		mem->mem_type,
		mem->mpll_mdiv,
		mem->frequency_mhz);

	ret = ddr3_mem_ctrl_init(mem, DMC_INTERLEAVE_SIZE);
	if (ret) {
		printk(BIOS_ERR, "Memory controller init failed, err: %x\n",
		ret);
		while(1);
	}

	/* Set up MMU and caches */
	mmu_setup_by_mva(CONFIG_SYS_SDRAM_BASE, CONFIG_DRAM_SIZE_MB);

	initialize_s5p_mshc();

	graphics();

	entry = cbfs_load_stage(CBFS_DEFAULT_MEDIA, "fallback/coreboot_ram");
	printk(BIOS_INFO, "entry is 0x%p, leaving romstage.\n", entry);

	stage_exit(entry);
}
Esempio n. 16
0
int board_init(void)
{
	gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;

	mxc_set_sata_internal_clock();
	setup_iomux_i2c();
	if (!power_init())
		clock_1GHz();
	print_cpuinfo();

	lcd_enable();

	return 0;
}
Esempio n. 17
0
int board_init(void)
{
    /*
    @todo implement this function
    */
	DECLARE_GLOBAL_DATA_PTR;
	gd->bd->bi_arch_number=MACH_TYPE_MESON_8626M;
	gd->bd->bi_boot_params=BOOT_PARAMS_OFFSET;

    hardi2c_init();
    power_init();

	return 0;
}
Esempio n. 18
0
File: pci.c Progetto: nhanh0/hah
void __init pcibios_init(void)
{
	pci_controller_probe();
	if (pci_controller_root == NULL)
		return;

	pci_scan_each_controller_bus();

	if (pci_device_reorder)
		pci_reorder_devs();

	isa_init();
	ebus_init();
	rs_init();
	clock_probe();
	power_init();
}
Esempio n. 19
0
void hardware_setup(void)
{
/**
*
* Hardware init
*
*/
#ifdef HAVE_WDT
	// watchdog timer init
 	wdt_init_and_start();
#else
	//stop wdg
 	wdt_hold();
#endif



	// clocks, wdt, power, uart, spi
	set_clocks_speed(MCLK_4MHZ_SMCLK_4MHZ);

	driver_power_init();
	//#if ! defined HAVE_CODE_COMPRESSION & ! defined HAVE_DEBUG
	uartSetup(UART0_CONFIG_32KHZ_9600);
	//#endif
	spi_init();
	timer_init();

	// LEDs
	LEDS_INIT();
	LEDS_OFF_CHECK_MODE(led_mode);

	// Temperature
#ifndef	HAVE_CODE_COMPRESSION
	update_temperature(); // for some unclear reason the very first temp measure is incorrect
	update_temperature(); // hence taking an extra-measure for security
#endif

// powersave
#ifdef HAVE_POWERSAVE
	power_init();
#endif /* HAVE_POWERSAVE */


}
Esempio n. 20
0
 int main(void){
    sys_init();	 //配置系统时钟72M(包括clock, PLL and Flash configuration)
	delay_init();//初始化延时
	uart1_init(72,9600);
	uart2_init(36,9600);//时钟为最高时钟的一半
//	uart3_init(36,9600);//时钟为最高时钟的一半
	led_init();
	car_init();
	jtag_set(2);//禁止JTAG,释放PB3,PA15
	Steering_Init();
	uart_printf("ok\r\n");
	hwbz_init();
	power_init();
	while(1){
		cmd_handle();
	};

	return 0;
 }
Esempio n. 21
0
int board_late_init(void)
{
	setup_iomux_spi();

	power_init();

	setup_iomux_led();
	setup_iomux_ata();
	setup_iomux_usb();

	if (machine_is_efikasb())
		setenv("preboot", "usb reset ; setenv stdin usbkbd\0");

	setup_iomux_led();

	efikamx_toggle_led(EFIKAMX_LED_BLUE);

	return 0;
}
int lowlevel_init_subsystems(void)
{
	uint32_t reset_status;
	int actions = 0;

	do_barriers();

	/* Setup cpu info which is needed to select correct register offsets */
	cpu_info_init();

	reset_status = power_read_reset_status();

	switch (reset_status) {
	case S5P_CHECK_SLEEP:
		actions = DO_CLOCKS | DO_WAKEUP;
		break;
	case S5P_CHECK_DIDLE:
	case S5P_CHECK_LPA:
		actions = DO_WAKEUP;
		break;
	default:
		/* This is a normal boot (not a wake from sleep) */
		actions = DO_UART | DO_CLOCKS | DO_POWER | DO_MEM_RESET;
	}

	if (actions & DO_POWER)
		power_init();
	if (actions & DO_CLOCKS)
		system_clock_init();
	if (actions & DO_UART) {
		/* Set up serial UART so we can printf() */
		exynos_pinmux_config(EXYNOS_UART, PINMUX_FLAG_NONE);
		serial_init();
		timer_init();
	}
	if (actions & DO_CLOCKS) {
		mem_ctrl_init(actions & DO_MEM_RESET);
		tzpc_init();
	}

	return actions & DO_WAKEUP;
}
Esempio n. 23
0
/// Startup code, run when we come out of reset
void init(void) {
	// set up watchdog
	wd_init();

	// set up serial
	serial_init();

	// set up G-code parsing
	gcode_init();

	// set up inputs and outputs
	io_init();

	// set up timers
	timer_init();

	// read PID settings from EEPROM
	heater_init();

	// set up dda
	dda_init();

	// start up analog read interrupt loop,
	// if any of the temp sensors in your config.h use analog interface
	analog_init();

	// set up temperature inputs
	temp_init();

	// enable interrupts
	sei();

	// reset watchdog
	wd_reset();

  // prepare the power supply
  power_init();

	// say hi to host
	serial_writestr_P(PSTR("start\nok\n"));

}
Esempio n. 24
0
int main(void)
{
    wdt_disable();
    /* Clear WDRF in MCUSR */
    MCUSR &= ~(1<<WDRF);
    /* Write logical one to WDCE and WDE */
    /* Keep old prescaler setting to prevent unintentional time-out */
    WDTCSR |= (1<<WDCE) | (1<<WDE);
    /* Turn off WDT */
    WDTCSR = 0x00;
    DDRC |= 0xC0;

    eeprom_read_block(&state, &state_ee, sizeof(state));
    
    leds_init();
    buttons_init();
    adc_init();
    power_init();
    door_init();
    aes_handler_init();
    bus_handler_init();
    bus_init();
    cmd_init();
    timer0_init();
    sei();
    
    while( 1 ){
        if( timer0_timebase ){
            timer0_timebase--;
            bus_tick();
            door_tick();
            power_tick();
            cmd_tick();
            buttons_tick();
            leds_tick();
        }
        bus_process();
        door_process();
        power_process();
    }

}
Esempio n. 25
0
int board_late_init(void)
{
	int ret = 0;

	setup_ups();

	if (!power_init())
		setup_clocks();

	ret = read_eeprom();
	if (ret)
		printf("Error %d reading EEPROM content!\n", ret);

	eth_phy_reset();

	show_eeprom();
	read_board_id();

	return ret;
}
Esempio n. 26
0
int board_late_init(void)
{
	if (machine_is_efikamx()) {
		/*
		 * Set up Blue LED for "In U-Boot" status.
		 * We're all relocated and ready to U-Boot!
		 */
		gpio_set_value(EFIKAMX_LED_RED, 0);
		gpio_set_value(EFIKAMX_LED_GREEN, 0);
		gpio_set_value(EFIKAMX_LED_BLUE, 1);
	}

	power_init();

	imx_iomux_v3_setup_multiple_pads(efikamx_pata_pads,
					ARRAY_SIZE(efikamx_pata_pads));
	setup_iomux_usb();

	return 0;
}
Esempio n. 27
0
int main()
{
//Start video driver (must always be before loading message)
    mm_init();
    pg_init();
    real_init();
    video_init();
    video_setdriver(video_vgatext_getdriver(),0);

//Put loading message
    cli_puts("ArcaneOS Loading...\n");

//Setup kernel
    gdt_init();
    idt_init();
    isr_init();
    irq_init();
    timer_init();
    kb_init();
    ui_init();
    cpuid_init();
    cmos_init();
    rtc_init();
    acpi_init();
    power_init();
    mt_init();
    syscall_init();
    floppy_init();

    __asm__ __volatile__ ("sti");

//Enable ACPI
    acpi_enable();

//Create thread for ui
    mt_create_thread(mt_kernel_process,test,2);

//Endless loop to prevent bugs when all threads are sleeping
    for(;;)
        __asm__ __volatile__ ("hlt");
}
Esempio n. 28
0
void main(void) {
	rcc_clock_setup_in_hse_8mhz_out_72mhz();

	init_systick();
	init_usb();
	power_init();
	lock_init();

	// configure status LED
	rcc_periph_clock_enable(RCC_GPIOC);
	gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);

	// configure buzzer input
	rcc_periph_clock_enable(RCC_GPIOB);
	gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO9);
	gpio_set(GPIOB, GPIO9); // pull up

	set_state(CLOSED);

	uint32_t button_start = 0;
	while(1) {
		usb_poll();

		if(get_state() == CLOSED)
			gpio_set(GPIOC, GPIO13);
		else
			gpio_clear(GPIOC, GPIO13);

		if(gpio_get(GPIOB, GPIO9) == 0) {
			if(button_start == 0)
				button_start = ticks;
		} else
			button_start = 0;

		if(button_start && time_after(ticks, button_start + (HZ/10)) && get_state() == CLOSED)
			lock();

		if(button_start && time_after(ticks, button_start + HZ * 15))
			lock();
	}
}
Esempio n. 29
0
void board_init(void)
{
	power_init(0);

	//only run once before ddr inited.
	if (!check_is_ddr_inited()) {
		/* dram 1.5V reset */
		serial_puts("DRAM reset...\n");
		/* power off ddr */
		writel((readl(P_AO_GPIO_O_EN_N) & (~((1 << 11) | (1 << 27)))),P_AO_GPIO_O_EN_N);
		/* need delay, check hw design */
		_udelay(400000);
		/* power on ddr */
		writel((readl(P_AO_GPIO_O_EN_N) | (1 << 27)),P_AO_GPIO_O_EN_N);

		/* dram RC charge time, check hw design */
		_udelay(10000);
	}

	panel_power_init();
}
Esempio n. 30
0
int
main (int argc, char **argv)
{
  int ret;
  int c;

  FILE *pidfile;
  struct utsname sysinfo;

  machine_type machine;

  while ((c = getopt(argc, argv, "fdv")) != -1)
    {
      switch (c)
	{
	  case 'f':
	    console = 1;
	    break;

	  case 'd':
	    debug = 1;
	    console = 1;
	    break;

	  case 'v':
	    printf("pommed v" M_VERSION " Apple laptops hotkeys handler\n");
	    printf("Copyright (C) 2006-2011 Julien BLACHE <*****@*****.**>\n");

	    exit(0);
	    break;

	  default:
	    usage();

	    exit(1);
	    break;
	}
    }

  if (geteuid() != 0)
    {
      logmsg(LOG_ERR, "pommed needs root privileges to operate");

      exit(1);
    }

  if (!console)
    {
      openlog("pommed", LOG_PID, LOG_DAEMON);
    }

  logmsg(LOG_INFO, "pommed v" M_VERSION " Apple laptops hotkeys handler");
  logmsg(LOG_INFO, "Copyright (C) 2006-2011 Julien BLACHE <*****@*****.**>");

  /* Load our configuration */
  ret = config_load();
  if (ret < 0)
    {
      exit(1);
    }

  /* Identify the machine we're running on */
  machine = check_machine();
  switch (machine)
    {
      case MACHINE_MAC_UNKNOWN:
	logmsg(LOG_ERR, "Unknown Apple machine");

	exit(1);
	break;

      case MACHINE_UNKNOWN:
	logmsg(LOG_ERR, "Unknown non-Apple machine");

	exit(1);
	break;

      case MACHINE_ERROR:
	exit(1);
	break;

      default:
	if (machine < MACHINE_LAST)
	  {
#ifdef __powerpc__
	    mops = &pb_mops[machine];
#else
	    mops = &mb_mops[machine];
#endif /* __powerpc__ */
	  }
	break;
    }

  /* Runtime sanity check: catch errors in the mb_mops and pb_mops arrays */
  if (mops->type != machine)
    {
      logmsg(LOG_ERR, "machine_ops mismatch: expected %d, found %d", machine, mops->type);

      exit(1);
    }

  if (debug)
    {
      ret = uname(&sysinfo);

      if (ret < 0)
	logmsg(LOG_ERR, "uname() failed: %s", strerror(errno));
      else
	logdebug("System: %s %s %s\n", sysinfo.sysname, sysinfo.release, sysinfo.machine);
    }

  ret = evloop_init();
  if (ret < 0)
    {
      logmsg(LOG_ERR, "Event loop initialization failed");
      exit (1);
    }

  ret = mops->lcd_backlight_probe();
  if (ret < 0)
    {
      logmsg(LOG_ERR, "LCD backlight probe failed, check debug output");

      exit(1);
    }

  ret = evdev_init();
  if (ret < 1)
    {
      logmsg(LOG_ERR, "No suitable event devices found");

      exit(1);
    }

  kbd_backlight_init();

  ret = audio_init();
  if (ret < 0)
    {
      logmsg(LOG_WARNING, "Audio initialization failed, audio support disabled");
    }

  ret = mbpdbus_init();
  if (ret < 0)
    {
      logmsg(LOG_WARNING, "Could not connect to DBus system bus");
    }

  power_init();

  if (!console)
    {
      /*
       * Detach from the console
       */
      if (daemon(0, 0) != 0)
	{
	  logmsg(LOG_ERR, "daemon() failed: %s", strerror(errno));

	  evdev_cleanup();

	  exit(1);
	}
    }

  pidfile = fopen(PIDFILE, "w");
  if (pidfile == NULL)
    {
      logmsg(LOG_WARNING, "Could not open pidfile %s: %s", PIDFILE, strerror(errno));

      evdev_cleanup();

      exit(1);
    }
  fprintf(pidfile, "%d\n", getpid());
  fclose(pidfile);

  /* Spawn the beep thread */
  beep_init();

  signal(SIGINT, sig_int_term_handler);
  signal(SIGTERM, sig_int_term_handler);


  do
    {
      ret = evloop_iteration();
    }
  while (ret >= 0);

  evdev_cleanup();

  beep_cleanup();

  mbpdbus_cleanup();

  kbd_backlight_cleanup();

  power_cleanup();

  evloop_cleanup();

  config_cleanup();

  logmsg(LOG_INFO, "Exiting");

  if (!console)
    closelog();

  unlink(PIDFILE);

  return 0;
}