Ejemplo n.º 1
0
/* Handles Menelaus interrupts. Does not run in interrupt context */
static void menelaus_work(struct work_struct *_menelaus)
{
	struct menelaus_chip *menelaus =
			container_of(_menelaus, struct menelaus_chip, work);
	void (*handler)(struct menelaus_chip *menelaus);

	while (1) {
		unsigned isr;

		isr = (menelaus_read_reg(MENELAUS_INT_STATUS2)
				& ~menelaus->mask2) << 8;
		isr |= menelaus_read_reg(MENELAUS_INT_STATUS1)
				& ~menelaus->mask1;
		if (!isr)
			break;

		while (isr) {
			int irq = fls(isr) - 1;
			isr &= ~(1 << irq);

			mutex_lock(&menelaus->lock);
			menelaus_disable_irq(irq);
			menelaus_ack_irq(irq);
			handler = menelaus->handlers[irq];
			if (handler)
				handler(menelaus);
			menelaus_enable_irq(irq);
			mutex_unlock(&menelaus->lock);
		}
	}
	enable_irq(menelaus->client->irq);
}
Ejemplo n.º 2
0
int menelaus_set_mmc_slot(int slot, int enable, int power, int cd_en)
{
	int ret, val;

	if (slot != 1 && slot != 2)
		return -EINVAL;
	if (power >= 3)
		return -EINVAL;

	mutex_lock(&the_menelaus->lock);

	ret = menelaus_read_reg(MENELAUS_MCT_CTRL2);
	if (ret < 0)
		goto out;
	val = ret;
	if (slot == 1) {
		if (cd_en)
			val |= (1 << 4) | (1 << 6);
		else
			val &= ~((1 << 4) | (1 << 6));
	} else {
		if (cd_en)
			val |= (1 << 5) | (1 << 7);
		else
			val &= ~((1 << 5) | (1 << 7));
	}
	ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, val);
	if (ret < 0)
		goto out;

	ret = menelaus_read_reg(MENELAUS_MCT_CTRL3);
	if (ret < 0)
		goto out;
	val = ret;
	if (slot == 1) {
		if (enable)
			val |= 1 << 0;
		else
			val &= ~(1 << 0);
	} else {
		int b;

		if (enable)
			ret |= 1 << 1;
		else
			ret &= ~(1 << 1);
		b = menelaus_read_reg(MENELAUS_MCT_CTRL2);
		b &= ~0x03;
		b |= power;
		ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, b);
		if (ret < 0)
			goto out;
	}
	/* Disable autonomous shutdown */
	val &= ~(0x03 << 2);
	ret = menelaus_write_reg(MENELAUS_MCT_CTRL3, val);
out:
	mutex_unlock(&the_menelaus->lock);
	return ret;
}
Ejemplo n.º 3
0
int menelaus_set_mmc_slot(int slot, int enable, int power, int cd_en)
{
	int ret, val;

	if (slot != 1 && slot != 2)
		return -EINVAL;
	if (power >= 3)
		return -EINVAL;

	mutex_lock(&the_menelaus->lock);

	ret = menelaus_read_reg(MENELAUS_MCT_CTRL2);
	if (ret < 0)
		goto out;
	val = ret;
	if (slot == 1) {
		if (cd_en)
			val |= MCT_CTRL2_S1CD_BUFEN | MCT_CTRL2_S1CD_DBEN;
		else
			val &= ~(MCT_CTRL2_S1CD_BUFEN | MCT_CTRL2_S1CD_DBEN);
	} else {
		if (cd_en)
			val |= MCT_CTRL2_S2CD_BUFEN | MCT_CTRL2_S2CD_BEN;
		else
			val &= ~(MCT_CTRL2_S2CD_BUFEN | MCT_CTRL2_S2CD_BEN);
	}
	ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, val);
	if (ret < 0)
		goto out;

	ret = menelaus_read_reg(MENELAUS_MCT_CTRL3);
	if (ret < 0)
		goto out;
	val = ret;
	if (slot == 1) {
		if (enable)
			val |= MCT_CTRL3_SLOT1_EN;
		else
			val &= ~MCT_CTRL3_SLOT1_EN;
	} else {
		int b;

		if (enable)
			val |= MCT_CTRL3_SLOT2_EN;
		else
			val &= ~MCT_CTRL3_SLOT2_EN;
		b = menelaus_read_reg(MENELAUS_MCT_CTRL2);
		b &= ~(MCT_CTRL2_VS2_SEL_D0 | MCT_CTRL2_VS2_SEL_D1);
		b |= power;
		ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, b);
		if (ret < 0)
			goto out;
	}
	/* Disable autonomous shutdown */
	val &= ~(MCT_CTRL3_S1_AUTO_EN | MCT_CTRL3_S2_AUTO_EN);
	ret = menelaus_write_reg(MENELAUS_MCT_CTRL3, val);
out:
	mutex_unlock(&the_menelaus->lock);
	return ret;
}
Ejemplo n.º 4
0
int menelaus_set_regulator_sleep(int enable, u32 val)
{
	int t, ret;
	struct i2c_client *c = the_menelaus->client;

	mutex_lock(&the_menelaus->lock);
	ret = menelaus_write_reg(MENELAUS_SLEEP_CTRL2, val);
	if (ret < 0)
		goto out;

	dev_dbg(&c->dev, "regulator sleep configuration: %02x\n", val);

	ret = menelaus_read_reg(MENELAUS_GPIO_CTRL);
	if (ret < 0)
		goto out;
	t = (GPIO_CTRL_SLPCTLEN | GPIO3_DIR_INPUT);
	if (enable)
		ret |= t;
	else
		ret &= ~t;
	ret = menelaus_write_reg(MENELAUS_GPIO_CTRL, ret);
out:
	mutex_unlock(&the_menelaus->lock);
	return ret;
}
Ejemplo n.º 5
0
static int menelaus_set_voltage(const struct menelaus_vtg *vtg, int mV,
				int vtg_val, int mode)
{
	int val, ret;
	struct i2c_client *c = the_menelaus->client;

	mutex_lock(&the_menelaus->lock);
	if (vtg == 0)
		goto set_voltage;

	ret = menelaus_read_reg(vtg->vtg_reg);
	if (ret < 0)
		goto out;
	val = ret & ~(((1 << vtg->vtg_bits) - 1) << vtg->vtg_shift);
	val |= vtg_val << vtg->vtg_shift;

	dev_dbg(&c->dev, "Setting voltage '%s'"
			 "to %d mV (reg 0x%02x, val 0x%02x)\n",
			vtg->name, mV, vtg->vtg_reg, val);

	ret = menelaus_write_reg(vtg->vtg_reg, val);
	if (ret < 0)
		goto out;
set_voltage:
	ret = menelaus_write_reg(vtg->mode_reg, mode);
out:
	mutex_unlock(&the_menelaus->lock);
	if (ret == 0) {
		/* Wait for voltage to stabilize */
		msleep(1);
	}
	return ret;
}
Ejemplo n.º 6
0
int menelaus_enable_slot(int slot, int enable)
{
	int ret, val;

	mutex_lock(&the_menelaus->lock);
	ret = menelaus_read_reg(MENELAUS_MCT_CTRL3);
	if (ret < 0)
		goto out;
	val = ret;
	if (slot == 1) {
		if (enable)
			val |= MCT_CTRL3_SLOT1_EN;
		else
			val &= ~MCT_CTRL3_SLOT1_EN;
	} else {
		if (enable)
			val |= MCT_CTRL3_SLOT2_EN;
		else
			val &= MCT_CTRL3_SLOT2_EN;
	}
	ret = menelaus_write_reg(MENELAUS_MCT_CTRL3, val);

out:
	mutex_unlock(&the_menelaus->lock);
	return ret;
}
Ejemplo n.º 7
0
/*
 * Toggles the MMC slots between open-drain and push-pull mode.
 */
int menelaus_set_mmc_opendrain(int slot, int enable)
{
	int ret, val;

	if (slot != 1 && slot != 2)
		return -EINVAL;
	mutex_lock(&the_menelaus->lock);
	ret = menelaus_read_reg(MENELAUS_MCT_CTRL1);
	if (ret < 0) {
		mutex_unlock(&the_menelaus->lock);
		return ret;
	}
	val = ret;
	if (slot == 1) {
		if (enable)
			val |= MCT_CTRL1_S1_CMD_OD;
		else
			val &= ~MCT_CTRL1_S1_CMD_OD;
	} else {
		if (enable)
			val |= MCT_CTRL1_S2_CMD_OD;
		else
			val &= ~MCT_CTRL1_S2_CMD_OD;
	}
	ret = menelaus_write_reg(MENELAUS_MCT_CTRL1, val);
	mutex_unlock(&the_menelaus->lock);

	return ret;
}
Ejemplo n.º 8
0
static inline void menelaus_rtc_init(struct menelaus_chip *m)
{
	int	alarm = (m->client->irq > 0);

	/* assume 32KDETEN pin is pulled high */
	if (!(menelaus_read_reg(MENELAUS_OSC_CTRL) & 0x80)) {
		dev_dbg(&m->client->dev, "no 32k oscillator\n");
		return;
	}

	/* support RTC alarm; it can issue wakeups */
	if (alarm) {
		if (menelaus_add_irq_work(MENELAUS_RTCALM_IRQ,
				menelaus_rtc_alarm_work) < 0) {
			dev_err(&m->client->dev, "can't handle RTC alarm\n");
			return;
		}
		device_init_wakeup(&m->client->dev, 1);
	}

	/* be sure RTC is enabled; allow 1/sec irqs; leave 12hr mode alone */
	m->rtc_control = menelaus_read_reg(MENELAUS_RTC_CTRL);
	if (!(m->rtc_control & RTC_CTRL_RTC_EN)
			|| (m->rtc_control & RTC_CTRL_AL_EN)
			|| (m->rtc_control & RTC_CTRL_EVERY_MASK)) {
		if (!(m->rtc_control & RTC_CTRL_RTC_EN)) {
			dev_warn(&m->client->dev, "rtc clock needs setting\n");
			m->rtc_control |= RTC_CTRL_RTC_EN;
		}
		m->rtc_control &= ~RTC_CTRL_EVERY_MASK;
		m->rtc_control &= ~RTC_CTRL_AL_EN;
		menelaus_write_reg(MENELAUS_RTC_CTRL, m->rtc_control);
	}

	m->rtc = rtc_device_register(DRIVER_NAME,
			&m->client->dev,
			&menelaus_rtc_ops, THIS_MODULE);
	if (IS_ERR(m->rtc)) {
		if (alarm) {
			menelaus_remove_irq_work(MENELAUS_RTCALM_IRQ);
			device_init_wakeup(&m->client->dev, 0);
		}
		dev_err(&m->client->dev, "can't register RTC: %d\n",
				(int) PTR_ERR(m->rtc));
		the_menelaus->rtc = NULL;
	}
}
Ejemplo n.º 9
0
int menelaus_set_slot_sel(int enable)
{
	int ret;

	mutex_lock(&the_menelaus->lock);
	ret = menelaus_read_reg(MENELAUS_GPIO_CTRL);
	if (ret < 0)
		goto out;
	ret |= GPIO2_DIR_INPUT;
	if (enable)
		ret |= GPIO_CTRL_SLOTSELEN;
	else
		ret &= ~GPIO_CTRL_SLOTSELEN;
	ret = menelaus_write_reg(MENELAUS_GPIO_CTRL, ret);
out:
	mutex_unlock(&the_menelaus->lock);
	return ret;
}
Ejemplo n.º 10
0
int menelaus_set_slot_sel(int enable)
{
	int ret;

	mutex_lock(&the_menelaus->lock);
	ret = menelaus_read_reg(MENELAUS_GPIO_CTRL);
	if (ret < 0)
		goto out;
	ret |= 0x02;
	if (enable)
		ret |= 1 << 5;
	else
		ret &= ~(1 << 5);
	ret = menelaus_write_reg(MENELAUS_GPIO_CTRL, ret);
out:
	mutex_unlock(&the_menelaus->lock);
	return ret;
}
Ejemplo n.º 11
0
/*
 * Gets scheduled when a card detect interrupt happens. Note that in some cases
 * this line is wired to card cover switch rather than the card detect switch
 * in each slot. In this case the cards are not seen by menelaus.
 * FIXME: Add handling for D1 too
 */
static void menelaus_mmc_cd_work(struct menelaus_chip *menelaus_hw)
{
	int reg;
	unsigned char card_mask = 0;

	reg = menelaus_read_reg(MENELAUS_MCT_PIN_ST);
	if (reg < 0)
		return;

	if (!(reg & 0x1))
		card_mask |= MCT_PIN_ST_S1_CD_ST;

	if (!(reg & 0x2))
		card_mask |= MCT_PIN_ST_S2_CD_ST;

	if (menelaus_hw->mmc_callback)
		menelaus_hw->mmc_callback(menelaus_hw->mmc_callback_data,
					  card_mask);
}
Ejemplo n.º 12
0
int menelaus_set_vcore_hw(unsigned int roof_mV, unsigned int floor_mV)
{
	int fval, rval, val, ret;
	struct i2c_client *c = the_menelaus->client;

	rval = menelaus_get_vtg_value(roof_mV, vcore_values,
				      ARRAY_SIZE(vcore_values));
	if (rval < 0)
		return -EINVAL;
	fval = menelaus_get_vtg_value(floor_mV, vcore_values,
				      ARRAY_SIZE(vcore_values));
	if (fval < 0)
		return -EINVAL;

	dev_dbg(&c->dev, "Setting VCORE FLOOR to %d mV and ROOF to %d mV\n",
	       floor_mV, roof_mV);

	mutex_lock(&the_menelaus->lock);
	ret = menelaus_write_reg(MENELAUS_VCORE_CTRL3, fval);
	if (ret < 0)
		goto out;
	ret = menelaus_write_reg(MENELAUS_VCORE_CTRL4, rval);
	if (ret < 0)
		goto out;
	if (!the_menelaus->vcore_hw_mode) {
		val = menelaus_read_reg(MENELAUS_VCORE_CTRL1);
		/* HW mode, turn OFF byte comparator */
		val |= (VCORE_CTRL1_HW_NSW | VCORE_CTRL1_BYP_COMP);
		ret = menelaus_write_reg(MENELAUS_VCORE_CTRL1, val);
		the_menelaus->vcore_hw_mode = 1;
	}
	msleep(1);
out:
	mutex_unlock(&the_menelaus->lock);
	return ret;
}
Ejemplo n.º 13
0
int menelaus_get_slot_pin_states(void)
{
	return menelaus_read_reg(MENELAUS_MCT_PIN_ST);
}
Ejemplo n.º 14
0
static int menelaus_probe(struct i2c_client *client,
			  const struct i2c_device_id *id)
{
	struct menelaus_chip	*menelaus;
	int			rev = 0, val;
	int			err = 0;
	struct menelaus_platform_data *menelaus_pdata =
					client->dev.platform_data;

	if (the_menelaus) {
		dev_dbg(&client->dev, "only one %s for now\n",
				DRIVER_NAME);
		return -ENODEV;
	}

	menelaus = kzalloc(sizeof *menelaus, GFP_KERNEL);
	if (!menelaus)
		return -ENOMEM;

	i2c_set_clientdata(client, menelaus);

	the_menelaus = menelaus;
	menelaus->client = client;

	/* If a true probe check the device */
	rev = menelaus_read_reg(MENELAUS_REV);
	if (rev < 0) {
		dev_err(&client->dev, "device not found");
		err = -ENODEV;
		goto fail1;
	}

	/* Ack and disable all Menelaus interrupts */
	menelaus_write_reg(MENELAUS_INT_ACK1, 0xff);
	menelaus_write_reg(MENELAUS_INT_ACK2, 0xff);
	menelaus_write_reg(MENELAUS_INT_MASK1, 0xff);
	menelaus_write_reg(MENELAUS_INT_MASK2, 0xff);
	menelaus->mask1 = 0xff;
	menelaus->mask2 = 0xff;

	/* Set output buffer strengths */
	menelaus_write_reg(MENELAUS_MCT_CTRL1, 0x73);

	if (client->irq > 0) {
		err = request_irq(client->irq, menelaus_irq, IRQF_DISABLED,
				  DRIVER_NAME, menelaus);
		if (err) {
			dev_dbg(&client->dev,  "can't get IRQ %d, err %d",
					client->irq, err);
			goto fail1;
		}
	}

	mutex_init(&menelaus->lock);
	INIT_WORK(&menelaus->work, menelaus_work);

	dev_info(&client->dev, "Menelaus rev %d.%d\n", rev >> 4, rev & 0x0f);

	val = menelaus_read_reg(MENELAUS_VCORE_CTRL1);
	if (val < 0)
		goto fail2;
	if (val & (1 << 7))
		menelaus->vcore_hw_mode = 1;
	else
		menelaus->vcore_hw_mode = 0;

	if (menelaus_pdata != NULL && menelaus_pdata->late_init != NULL) {
		err = menelaus_pdata->late_init(&client->dev);
		if (err < 0)
			goto fail2;
	}

	menelaus_rtc_init(menelaus);

	return 0;
fail2:
	free_irq(client->irq, menelaus);
	flush_scheduled_work();
fail1:
	kfree(menelaus);
	return err;
}