int i2c_set_bus_num(unsigned int bus) { #if defined(CONFIG_I2C_MUX) if (bus < CONFIG_SYS_MAX_I2C_BUS) { i2c_bus_num = bus; } else { int ret; ret = i2x_mux_select_mux(bus); i2c_init_board(); if (ret == 0) i2c_bus_num = bus; else return ret; } #else if (bus >= CONFIG_SYS_MAX_I2C_BUS) return -1; i2c_bus_num = bus; #endif return 0; }
/* * i2c_init_all(): * * not longer needed, will deleted. Actual init the SPD_BUS * for compatibility. * i2c_adap[] must be initialized beforehead with function pointers and * data, including speed and slaveaddr. */ void i2c_init_all(void) { i2c_init_board(); i2c_set_bus_num(CONFIG_SYS_SPD_BUS_NUM); return; }
void i2c1_init (int speed, int slaveadd) { sys_info_t sysInfo; unsigned long freqOPB; int val, divisor; #ifdef CONFIG_SYS_I2C_INIT_BOARD /* call board specific i2c bus reset routine before accessing the */ /* environment, which might be in a chip on that bus. For details */ /* about this problem see doc/I2C_Edge_Conditions. */ i2c_init_board(); #endif /* Handle possible failed I2C state */ /* FIXME: put this into i2c_init_board()? */ _i2c_bus1_reset (); /* clear lo master address */ out_8 (IIC_LMADR1, 0); /* clear hi master address */ out_8 (IIC_HMADR1, 0); /* clear lo slave address */ out_8 (IIC_LSADR1, 0); /* clear hi slave address */ out_8 (IIC_HSADR1, 0); /* Clock divide Register */ /* get OPB frequency */ get_sys_info (&sysInfo); freqOPB = sysInfo.freqPLB / sysInfo.pllOpbDiv; /* set divisor according to freqOPB */ divisor = (freqOPB - 1) / 10000000; if (divisor == 0) divisor = 1; out_8 (IIC_CLKDIV1, divisor); /* no interrupts */ out_8 (IIC_INTRMSK1, 0); /* clear transfer count */ out_8 (IIC_XFRCNT1, 0); /* clear extended control & stat */ /* write 1 in SRC SRS SWC SWS to clear these fields */ out_8 (IIC_XTCNTLSS1, 0xF0); /* Mode Control Register Flush Slave/Master data buffer */ out_8 (IIC_MDCNTL1, IIC_MDCNTL_FSDB | IIC_MDCNTL_FMDB); __asm__ volatile ("eieio"); val = in_8(IIC_MDCNTL1); __asm__ volatile ("eieio"); /* Ignore General Call, slave transfers are ignored, disable interrupts, exit unknown bus state, enable hold SCL 100kHz normaly or FastMode for 400kHz and above */ val |= IIC_MDCNTL_EUBS|IIC_MDCNTL_HSCL; if( speed >= 400000 ){ val |= IIC_MDCNTL_FSM; } out_8 (IIC_MDCNTL1, val); /* clear control reg */ out_8 (IIC_CNTL1, 0x00); __asm__ volatile ("eieio"); }
/* * Routine: board_init * Description: Early hardware init. */ int board_init(void) { __maybe_unused int err; /* Do clocks and UART first so that printf() works */ clock_init(); clock_verify(); #ifdef CONFIG_FDT_SPI pin_mux_spi(); spi_init(); #endif #ifdef CONFIG_PWM_TEGRA if (pwm_init(gd->fdt_blob)) debug("%s: Failed to init pwm\n", __func__); #endif #ifdef CONFIG_LCD pin_mux_display(); tegra_lcd_check_next_stage(gd->fdt_blob, 0); #endif /* boot param addr */ gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100); power_det_init(); #ifdef CONFIG_TEGRA_I2C #ifndef CONFIG_SYS_I2C_INIT_BOARD #error "You must define CONFIG_SYS_I2C_INIT_BOARD to use i2c on Nvidia boards" #endif i2c_init_board(); # ifdef CONFIG_TEGRA_PMU if (pmu_set_nominal()) debug("Failed to select nominal voltages\n"); # ifdef CONFIG_TEGRA_CLOCK_SCALING err = board_emc_init(); if (err) debug("Memory controller init failed: %d\n", err); # endif # endif /* CONFIG_TEGRA_PMU */ #endif /* CONFIG_TEGRA_I2C */ #ifdef CONFIG_USB_EHCI_TEGRA pin_mux_usb(); board_usb_init(gd->fdt_blob); #endif #ifdef CONFIG_LCD tegra_lcd_check_next_stage(gd->fdt_blob, 0); #endif #ifdef CONFIG_TEGRA_NAND pin_mux_nand(); #endif #ifdef CONFIG_TEGRA_LP0 /* save Sdram params to PMC 2, 4, and 24 for WB0 */ warmboot_save_sdram_params(); /* prepare the WB code to LP0 location */ warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE); #endif return 0; }