/*
 * Gets current TWL4030 RTC alarm time.
 */
static int twl4030_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
{
	unsigned char rtc_data[ALL_TIME_REGS + 1];
	int ret;

	ret = twl4030_i2c_read(TWL4030_MODULE_RTC, rtc_data,
			       REG_ALARM_SECONDS_REG, ALL_TIME_REGS);
	if (ret < 0) {
		dev_err(dev, "rtc_read_alarm error %d\n", ret);
		return ret;
	}

	/* some of these fields may be wildcard/"match all" */
	alm->time.tm_sec = bcd2bin(rtc_data[0]);
	alm->time.tm_min = bcd2bin(rtc_data[1]);
	alm->time.tm_hour = bcd2bin(rtc_data[2]);
	alm->time.tm_mday = bcd2bin(rtc_data[3]);
	alm->time.tm_mon = bcd2bin(rtc_data[4]) - 1;
	alm->time.tm_year = bcd2bin(rtc_data[5]) + 100;

	/* report cached alarm enable state */
	if (rtc_irq_bits & BIT_RTC_INTERRUPTS_REG_IT_ALARM_M)
		alm->enabled = 1;

	return ret;
}
Beispiel #2
0
static int beagle_detect(SIM_HBA *hba)
{
    SIM_MMC_EXT *ext;
    omap3_ext_t *omap;
    beagle_ext_t *beagle;
    uint8_t pmic_gpio_status;
    ext = (SIM_MMC_EXT *) hba->ext;
    omap = (omap3_ext_t *) ext->handle;
    beagle = (beagle_ext_t *) omap->bshdl;

    // read MMC1_CD via PMIC GPIO (i2c access) on GPIODATAIN1 register
    if (twl4030_i2c_read(beagle->fd, 0x49, 0x98, &pmic_gpio_status))
        return MMC_FAILURE; // bail if the access fails

    // MMC1_CD is bit 0 and is high when card removed and low when card present
    if (!(pmic_gpio_status & 1))
    {
        // Beagleboard xM has no write protect pin on the microSD slot
        // as such, return not write protected.
        ext->eflags &= ~MMC_EFLAG_WP;

        return MMC_SUCCESS;
    }

    return MMC_FAILURE;
}
/*
 * Gets current TWL4030 RTC time and date parameters.
 *
 * The RTC's time/alarm representation is not what gmtime(3) requires
 * Linux to use:
 *
 *  - Months are 1..12 vs Linux 0-11
 *  - Years are 0..99 vs Linux 1900..N (we assume 21st century)
 */
static int twl4030_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
	unsigned char rtc_data[ALL_TIME_REGS + 1];
	int ret;
	u8 save_control;

	ret = twl4030_rtc_read_u8(&save_control, REG_RTC_CTRL_REG);
	if (ret < 0)
		return ret;

	save_control |= BIT_RTC_CTRL_REG_GET_TIME_M;

	ret = twl4030_rtc_write_u8(save_control, REG_RTC_CTRL_REG);
	if (ret < 0)
		return ret;

	ret = twl4030_i2c_read(TWL4030_MODULE_RTC, rtc_data,
			       REG_SECONDS_REG, ALL_TIME_REGS);

	if (ret < 0) {
		dev_err(dev, "rtc_read_time error %d\n", ret);
		return ret;
	}

	tm->tm_sec = bcd2bin(rtc_data[0]);
	tm->tm_min = bcd2bin(rtc_data[1]);
	tm->tm_hour = bcd2bin(rtc_data[2]);
	tm->tm_mday = bcd2bin(rtc_data[3]);
	tm->tm_mon = bcd2bin(rtc_data[4]) - 1;
	tm->tm_year = bcd2bin(rtc_data[5]) + 100;

	return ret;
}
Beispiel #4
0
/* 
 * Gets current TWL4030 RTC alarm time.
 */
static int get_rtc_alm_time(struct rtc_time *alm_tm)
{
	unsigned char rtc_data[ALL_TIME_REGS + 1];
	int ret;

	ret = twl4030_i2c_read(TWL4030_MODULE_RTC, rtc_data,
			       REG_ALARM_SECONDS_REG, ALL_TIME_REGS);
	if (ret < 0) {
		printk(KERN_ERR "twl4030_rtc: twl4030_i2c_read error.\n");
		return ret;
	}

	alm_tm->tm_sec = BCD2BIN(rtc_data[0]);
	alm_tm->tm_min = BCD2BIN(rtc_data[1]);
	alm_tm->tm_hour = BCD2BIN(rtc_data[2]);
	alm_tm->tm_mday = BCD2BIN(rtc_data[3]);
	alm_tm->tm_mon = BCD2BIN(rtc_data[4]);
	alm_tm->tm_year = BCD2BIN(rtc_data[5]);

	/*
	 * Account for differences between how the RTC uses the values
	 * and how they are defined in a struct rtc_time;
	 */
	if ((alm_tm->tm_year += (epoch - 1900)) <= 69)
		alm_tm->tm_year += 100;

	alm_tm->tm_mon--;

	return ret;
}
static int twl4030_kpread(struct twl4030_keypad *kp,
		u8 *data, u32 reg, u8 num_bytes)
{
	int ret;

	ret = twl4030_i2c_read(TWL4030_MODULE_KEYPAD, data, reg, num_bytes);
	if (ret < 0) {
		dev_warn(kp->dbg_dev,
			"Couldn't read TWL4030: %X - ret %d[%x]\n",
			 reg, ret, ret);
		return ret;
	}
	return ret;
}
Beispiel #6
0
static void twl4030_load_rev(void)
{
	int err;

	err = twl4030_i2c_write_u8(TWL4030_MODULE_INTBR,
				TWL_EEPROM_R_UNLOCK, R_UNLOCK_TEST_REG);
	if (err)
		pr_err("TWL4030 Unable to unlock IDCODE registers\n");

	err = twl4030_i2c_read(TWL4030_MODULE_INTBR, (u8 *)(&twl4030_rev), 0x0, 4);
	if (err)
		pr_err("TWL4030: unable to read IDCODE-%d\n", err);

	err = twl4030_i2c_write_u8(TWL4030_MODULE_INTBR, 0x0, R_UNLOCK_TEST_REG);
	if (err)
		pr_err("TWL4030 Unable to relock IDCODE registers\n");
}
Beispiel #7
0
/* 
 * Gets current TWL4030 RTC time and date parameters.
 */
static int get_rtc_time(struct rtc_time *rtc_tm)
{
	unsigned char rtc_data[ALL_TIME_REGS + 1];
	int ret;
	u8 save_control;

	ret = twl4030_rtc_read_u8(&save_control, REG_RTC_CTRL_REG);
	if (ret < 0)
    		return ret;

	save_control |= BIT_RTC_CTRL_REG_GET_TIME_M;

	ret = twl4030_rtc_write_u8(save_control, REG_RTC_CTRL_REG);
	if (ret < 0)
		return ret;

	ret = twl4030_i2c_read(TWL4030_MODULE_RTC, rtc_data,
			       REG_SECONDS_REG, ALL_TIME_REGS);

	if (ret < 0) {
		printk(KERN_ERR "twl4030_rtc: twl4030_i2c_read error.\n");
		return ret;
	}

	rtc_tm->tm_sec = BCD2BIN(rtc_data[0]);
	rtc_tm->tm_min = BCD2BIN(rtc_data[1]);
	rtc_tm->tm_hour = BCD2BIN(rtc_data[2]);
	rtc_tm->tm_mday = BCD2BIN(rtc_data[3]);
	rtc_tm->tm_mon = BCD2BIN(rtc_data[4]);
	rtc_tm->tm_year = BCD2BIN(rtc_data[5]);

	/*
	 * Account for differences between how the RTC uses the values
	 * and how they are defined in a struct rtc_time;
	 */
	if ((rtc_tm->tm_year += (epoch - 1900)) <= 69)
		rtc_tm->tm_year += 100;

	rtc_tm->tm_mon--;

	return ret;
}
Beispiel #8
0
int twl4030_enable_dvi(disp_adapter_t *adapter)
{
	unsigned speed;
	unsigned char b;
	int err;
	/*
	 * Open the I2C controller device for the codec
	 */
	fd = open(TWL4030_I2C_DEVICE, O_RDWR);
	if (fd == NULL) {
		perror("open");
		return -1;
	}

	printf("\n Enable DVI output on BeagleBoard-xM\n");
	slogf(21,0,"Enable DVI output on BeagleBoard-xM\n" );

	/*
	 * Set the I2C speed for the codec
	 */
	speed = TWL4030_I2C_SPEED;
	err = devctl(fd, DCMD_I2C_SET_BUS_SPEED, &speed, sizeof(speed), NULL);
	if (err != EOK) {
		return -1;
	}

	/* Set GPOI2 (DVI_PU) high, to power on the DVI */

	// First set the direction. Read in the existing direction value
	if (twl4030_i2c_read(TWL4030_ADDR_GRP4, 0x9B, &b))
		return -1; // bail if the access fails
	b |= (1 << 2);
	twl4030_i2c_write(adapter, TWL4030_ADDR_GRP4, 0x9B, b);
	
	// Now set the value high
	twl4030_i2c_write(adapter, TWL4030_ADDR_GRP4, 0xA4, (unsigned char)(1<<2));

	return 0;
}
/**
 * twl4030_i2c_read_u8 - Reads a 8 bit register from TWL4030
 * @mod_no: module number
 * @value: the value read 8 bit
 * @reg: register address (just offset will do)
 *
 * Returns result of operation - 0 is success
 */
int twl4030_i2c_read_u8(u8 mod_no, u8 *value, u8 reg)
{
	return twl4030_i2c_read(mod_no, value, reg, 1);
}