Esempio n. 1
0
static void board_pmic_init(void)
{
	/* No need to re-init PMIC since settings are sticky across sysjump */
	if (system_jumped_to_this_image())
		return;

	/* Set CSDECAYEN / VCCIO decays to 0V at assertion of SLP_S0# */
	i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x30, 0x4a);

	/*
	 * Set V100ACNT / V1.00A Control Register:
	 * Nominal output = 1.0V.
	 */
	i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x37, 0x1a);

	/*
	 * Set V085ACNT / V0.85A Control Register:
	 * Lower power mode = 0.7V.
	 * Nominal output = 1.0V.
	 */
	i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x38, 0x7a);

	/* VRMODECTRL - enable low-power mode for VCCIO and V0.85A */
	i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x3b, 0x18);
}
Esempio n. 2
0
int tcpm_transmit(int port, enum tcpm_transmit_type type, uint16_t header,
		   const uint32_t *data)
{
	int reg = TCPC_REG_TX_DATA;
	int rv, cnt = 4*PD_HEADER_CNT(header);

	rv = i2c_write8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
			TCPC_REG_TX_BYTE_CNT, cnt);

	rv |= i2c_write16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
			  TCPC_REG_TX_HDR, header);

	/* If i2c read fails, return error */
	if (rv)
		return rv;

	if (cnt > 0) {
		i2c_lock(I2C_PORT_TCPC, 1);
		rv = i2c_xfer(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
			      (uint8_t *)&reg, 1, NULL, 0, I2C_XFER_START);
		rv |= i2c_xfer(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
			       (uint8_t *)data, cnt, NULL, 0, I2C_XFER_STOP);
		i2c_lock(I2C_PORT_TCPC, 0);
	}

	/* If i2c read fails, return error */
	if (rv)
		return rv;

	rv = i2c_write8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
			TCPC_REG_TRANSMIT, TCPC_REG_TRANSMIT_SET(type));

	return rv;
}
Esempio n. 3
0
void ov7670_set(uint8_t addr, uint8_t val)
{
    i2c_start();
    i2c_write8(OV7670_ADDR);
    i2c_write8(addr);
    i2c_write8(val);
    i2c_stop();
}
Esempio n. 4
0
int main(void){

	if(i2c_setup(0x23) < 0){
		printf("err");
	}
	i2c_set_slave(0x27);
	i2c_write8(0x27, 0x00, 0x00);
	sleep(1);
	i2c_write8(0x27, 0x06, 0x00);
	sleep(1);
	i2c_write8(0x27, 0x0A, 0xff);
	sleep(1);
	i2c_write8(0x27, 0x09, 0xf0);
	return 0;
}
static int test_i2c(void)
{
	int res = EC_ERROR_UNKNOWN;
	int dummy_data;
	struct i2c_test_param_t *param;
	param = i2c_test_params + (prng_no_seed() % (sizeof(i2c_test_params) /
				   sizeof(struct i2c_test_param_t)));
	if (param->width == 8 && param->data == -1)
		res = i2c_read8(param->port, param->addr,
				param->offset, &dummy_data);
	else if (param->width == 8 && param->data >= 0)
		res = i2c_write8(param->port, param->addr,
				 param->offset, param->data);
	else if (param->width == 16 && param->data == -1)
		res = i2c_read16(param->port, param->addr,
				 param->offset, &dummy_data);
	else if (param->width == 16 && param->data >= 0)
		res = i2c_write16(param->port, param->addr,
				  param->offset, param->data);
	else if (param->width == 32 && param->data == -1)
		res = i2c_read32(param->port, param->addr,
				 param->offset, &dummy_data);
	else if (param->width == 32 && param->data >= 0)
		res = i2c_write32(param->port, param->addr,
				  param->offset, param->data);

	return res;
}
Esempio n. 6
0
int tcpm_set_rx_enable(int port, int enable)
{
	/* If enable, then set RX detect for SOP and HRST */
	return i2c_write8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
			  TCPC_REG_RX_DETECT,
			  enable ? TCPC_REG_RX_DETECT_SOP_HRST_MASK : 0);
}
Esempio n. 7
0
static void ir357x_write(uint8_t reg, uint8_t val)
{
    int res;

    res = i2c_write8(I2C_PORT_REGULATOR, IR357x_I2C_ADDR, reg, val);
    if (res)
        CPRINTF("IR I2C write failed\n");
}
Esempio n. 8
0
static int raw_write8(const int offset, int data)
{
	int ret;
	ret = i2c_write8(I2C_PORT_THERMAL, BD99992GW_I2C_ADDR, offset, data);
	if (ret != EC_SUCCESS)
		CPRINTS("bd99992gw write fail %d\n", ret);
	return ret;
}
Esempio n. 9
0
int tcpm_set_polarity(int port, int polarity)
{
	/* Write new polarity, leave vconn enable flag untouched */
	tcpc_polarity = polarity;
	return i2c_write8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
			  TCPC_REG_POWER_CTRL,
			  TCPC_REG_POWER_CTRL_SET(tcpc_polarity, tcpc_vconn));
}
Esempio n. 10
0
int tcpm_set_vconn(int port, int enable)
{
	/* Write new vconn enable flag, leave polarity untouched */
	tcpc_vconn = enable;
	return i2c_write8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
			  TCPC_REG_POWER_CTRL,
			  TCPC_REG_POWER_CTRL_SET(tcpc_polarity, tcpc_vconn));
}
Esempio n. 11
0
uint8_t ov7670_get(uint8_t addr)
{
    uint8_t retval;

    i2c_start();
    i2c_write8(OV7670_ADDR);
    i2c_write8(addr);
    i2c_stop();

    __delay_cycles(16 * 1000);

    i2c_start();
    i2c_write8(OV7670_ADDR + 1);
    retval = i2c_read8(0xFF);
    i2c_stop();

    return retval;
}
static int pca9534_pin_write(int port, int addr, int reg, int pin, int val)
{
	int ret, v;
	ret = i2c_read8(port, addr, reg, &v);
	if (ret != EC_SUCCESS)
		return ret;
	v &= ~(1 << pin);
	if (val)
		v |= 1 << pin;
	return i2c_write8(port, addr, reg, v);
}
Esempio n. 13
0
int tcpm_set_cc(int port, int pull)
{
	/*
	 * Set manual control of Rp/Rd, and set both CC lines to the same
	 * pull.
	 */
	/* TODO: set desired Rp strength */
	return i2c_write8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
			  TCPC_REG_ROLE_CTRL,
			  TCPC_REG_ROLE_CTRL_SET(0, 0, pull, pull));
}
Esempio n. 14
0
File: bq24773.c Progetto: thehobn/ec
/* Charging power state initialization */
int charger_post_init(void)
{
	int rv, option;
#ifdef CONFIG_CHARGER_ILIM_PIN_DISABLED
	int option2;
#endif

	rv = charger_get_option(&option);
	if (rv)
		return rv;

	option &= ~OPTION0_LEARN_ENABLE;

	rv = charger_set_option(option);
	if (rv)
		return rv;

#ifndef BOARD_SAMUS
	/* Turn off PROCHOT warning */
	rv = i2c_write8(I2C_PORT_CHARGER, BQ24773_ADDR,
			BQ24773_PROCHOT_OPTION1, 0);
#else
	/* On Samus, use PROCHOT warning to detect charging problems */
	/* Turn on PROCHOT warning */
	rv = i2c_write16(I2C_PORT_CHARGER, BQ24773_ADDR,
			 BQ24773_PROCHOT_OPTION1, 0x8120);
	/* Set PROCHOT ICRIT warning when IADP is >120% of IDPM */
	rv |= i2c_write16(I2C_PORT_CHARGER, BQ24773_ADDR,
			 BQ24773_PROCHOT_OPTION0, 0x1b54);
#endif

	if (rv)
		return rv;

#ifdef CONFIG_CHARGER_ILIM_PIN_DISABLED
	/* Read the external ILIM pin enabled flag. */
	rv = i2c_read16(I2C_PORT_CHARGER, BQ24773_ADDR,
			   BQ24773_CHARGE_OPTION2, &option2);
	if (rv)
		return rv;

	/* Set ILIM pin disabled if it is currently enabled. */
	if (option2 & OPTION2_EN_EXTILIM) {
		option2 &= ~OPTION2_EN_EXTILIM;
		rv = i2c_write16(I2C_PORT_CHARGER, BQ24773_ADDR,
				 BQ24773_CHARGE_OPTION2, option2);
	}
	return rv;
#else
	return EC_SUCCESS;
#endif
}
Esempio n. 15
0
/* Write to lp8555 with automatic i2c retries */
static int lp8555_write_with_retry(int reg, int data)
{
	int i, rv;

	for (i = 0; i < I2C_RETRIES; i++) {
		rv = i2c_write8(I2C_PORT_BACKLIGHT, I2C_ADDR_BACKLIGHT,
			       reg, data);
		if (rv == EC_SUCCESS)
			return EC_SUCCESS;
		usleep(I2C_RETRY_DELAY);
	}

	CPRINTS("Backlight write fail: reg 0x%02x data %d", reg, data);
	return rv;
}
Esempio n. 16
0
/*
 * Various voltage rails will be enabled / disabled by the PMIC when
 * GPIO_PMIC_SLP_SUS_L changes. We need to delay the disable of V0.85A
 * by approximately 25ms in order to allow V1.00A to sufficiently discharge
 * first.
 *
 * Therefore, after GPIO_PMIC_SLP_SUS_L goes high, ignore the state of
 * the V12_EN pin: Keep V0.85A enabled.
 *
 * When GPIO_PMIC_SLP_SUS_L goes low, delay 25ms, and make V12_EN function
 * as normal - this should result in V0.85A discharging immediately after the
 * i2c write completes.
 */
void chipset_set_pmic_slp_sus_l(int level)
{
	static int previous_level;
	int val;

	gpio_set_level(GPIO_PMIC_SLP_SUS_L, level);

	if (previous_level != level) {
		/* Rising edge: Force V0.85A enable. Falling: Pin control. */
		val = level ? 0x80 : 0;
		if (!level)
			msleep(25);

		i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x43, val);
		previous_level = level;
	}
}
Esempio n. 17
0
void board_hibernate(void)
{
	CPRINTS("Triggering PMIC shutdown.");
	uart_flush_output();

	/* Trigger PMIC shutdown. */
	if (i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x49, 0x01)) {
		/*
		 * If we can't tell the PMIC to shutdown, instead reset
		 * and don't start the AP. Hopefully we'll be able to
		 * communicate with the PMIC next time.
		 */
		CPRINTS("PMIC i2c failed.");
		system_reset(SYSTEM_RESET_LEAVE_AP_OFF);
	}

	/* Await shutdown. */
	while (1)
		;
}
Esempio n. 18
0
File: bq24773.c Progetto: thehobn/ec
int charger_set_input_current(int input_current)
{
	return i2c_write8(I2C_PORT_CHARGER, BQ24773_ADDR,
			  BQ24773_INPUT_CURRENT,
			  CURRENT_TO_REG8(input_current, R_AC));
}
Esempio n. 19
0
int tcpm_set_msg_header(int port, int power_role, int data_role)
{
	return i2c_write8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
			  TCPC_REG_MSG_HDR_INFO,
			  TCPC_REG_MSG_HDR_INFO_SET(data_role, power_role));
}
Esempio n. 20
0
static int raw_write8(const int offset, int data)
{
	return i2c_write8(I2C_PORT_THERMAL, TMP432_I2C_ADDR, offset, data);
}
Esempio n. 21
0
static int ps8740_write(int i2c_addr, uint8_t reg, uint8_t val)
{
	return i2c_write8(I2C_PORT_USB_MUX, i2c_addr, reg, val);
}
Esempio n. 22
0
/**
 * Write register from Gyrometer.
 */
static inline int raw_write8(const int port, const int addr, const int reg,
							 int data)
{
	return i2c_write8(port, addr, reg, data);
}
Esempio n. 23
0
static inline void controller_write(int ctrl_num, uint8_t reg, uint8_t val)
{
	ctrl_num = ctrl_num % ARRAY_SIZE(i2c_addr);
	i2c_write8(I2C_PORT_LIGHTBAR, i2c_addr[ctrl_num], reg, val);
}
Esempio n. 24
0
int tcpm_set_power_status_mask(int port, uint8_t mask)
{
	/* write to the Alert Mask register */
	return i2c_write8(I2C_PORT_TCPC, I2C_ADDR_TCPC(port),
			  TCPC_REG_POWER_STATUS_MASK , mask);
}
Esempio n. 25
0
inline int lp5562_write(uint8_t reg, uint8_t val)
{
	return i2c_write8(I2C_PORT_MASTER, LP5562_I2C_ADDR, reg, val);
}
Esempio n. 26
0
/**
 * Write register from Gyrometer.
 */
static inline int raw_write8(const int addr, const int reg, int data)
{
	return i2c_write8(I2C_PORT_GYRO, addr, reg, data);
}