int mc13783_powermisc_rmw(struct mc13783_regulator_priv *priv, u32 mask,
									u32 val)
{
	struct mc13783 *mc13783 = priv->mc13783;
	int ret;
	u32 valread;

	BUG_ON(val & ~mask);

	ret = mc13783_reg_read(mc13783, MC13783_REG_POWERMISC, &valread);
	if (ret)
		return ret;

	/* Update the stored state for Power Gates. */
	priv->powermisc_pwgt_state =
				(priv->powermisc_pwgt_state & ~mask) | val;
	priv->powermisc_pwgt_state &= MC13783_REG_POWERMISC_PWGTSPI_M;

	/* Construct the new register value */
	valread = (valread & ~mask) | val;
	/* Overwrite the PWGTxEN with the stored version */
	valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) |
						priv->powermisc_pwgt_state;

	return mc13783_reg_write(mc13783, MC13783_REG_POWERMISC, valread);
}
Exemple #2
0
int mc13783_irq_ack(struct mc13783 *mc13783, int irq)
{
	unsigned int offstat = irq < 24 ? MC13783_IRQSTAT0 : MC13783_IRQSTAT1;
	unsigned int val = 1 << (irq < 24 ? irq : irq - 24);

	BUG_ON(irq < 0 || irq >= MC13783_NUM_IRQ);

	return mc13783_reg_write(mc13783, offstat, val);
}
Exemple #3
0
int mc13783_reg_rmw(struct mc13783 *mc13783, unsigned int offset,
		u32 mask, u32 val)
{
	int ret;
	u32 valread;

	BUG_ON(val & ~mask);

	ret = mc13783_reg_read(mc13783, offset, &valread);
	if (ret)
		return ret;

	valread = (valread & ~mask) | val;

	return mc13783_reg_write(mc13783, offset, valread);
}
Exemple #4
0
int mc13783_irq_unmask(struct mc13783 *mc13783, int irq)
{
	int ret;
	unsigned int offmask = irq < 24 ? MC13783_IRQMASK0 : MC13783_IRQMASK1;
	u32 irqbit = 1 << (irq < 24 ? irq : irq - 24);
	u32 mask;

	if (irq < 0 || irq >= MC13783_NUM_IRQ)
		return -EINVAL;

	ret = mc13783_reg_read(mc13783, offmask, &mask);
	if (ret)
		return ret;

	if (!(mask & irqbit))
		/* already unmasked */
		return 0;

	return mc13783_reg_write(mc13783, offmask, mask & ~irqbit);
}
Exemple #5
0
/*
 * returns: number of handled irqs or negative error
 * locking: holds mc13783->lock
 */
static int mc13783_irq_handle(struct mc13783 *mc13783,
		unsigned int offstat, unsigned int offmask, int baseirq)
{
	u32 stat, mask;
	int ret = mc13783_reg_read(mc13783, offstat, &stat);
	int num_handled = 0;

	if (ret)
		return ret;

	ret = mc13783_reg_read(mc13783, offmask, &mask);
	if (ret)
		return ret;

	while (stat & ~mask) {
		int irq = __ffs(stat & ~mask);

		stat &= ~(1 << irq);

		if (likely(mc13783->irqhandler[baseirq + irq])) {
			irqreturn_t handled;

			handled = mc13783_irqhandler(mc13783, baseirq + irq);
			if (handled == IRQ_HANDLED)
				num_handled++;
		} else {
			dev_err(&mc13783->spidev->dev,
					"BUG: irq %u but no handler\n",
					baseirq + irq);

			mask |= 1 << irq;

			ret = mc13783_reg_write(mc13783, offmask, mask);
		}
	}

	return num_handled;
}
Exemple #6
0
static int mc13783_probe(struct spi_device *spi)
{
	struct mc13783 *mc13783;
	struct mc13783_platform_data *pdata = dev_get_platdata(&spi->dev);
	int ret;

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

	dev_set_drvdata(&spi->dev, mc13783);
	spi->mode = SPI_MODE_0 | SPI_CS_HIGH;
	spi->bits_per_word = 32;
	spi_setup(spi);

	mc13783->spidev = spi;

	mutex_init(&mc13783->lock);
	mc13783_lock(mc13783);

	ret = mc13783_check_revision(mc13783);
	if (ret)
		goto err_revision;

	/* mask all irqs */
	ret = mc13783_reg_write(mc13783, MC13783_IRQMASK0, 0x00ffffff);
	if (ret)
		goto err_mask;

	ret = mc13783_reg_write(mc13783, MC13783_IRQMASK1, 0x00ffffff);
	if (ret)
		goto err_mask;

	ret = request_threaded_irq(spi->irq, NULL, mc13783_irq_thread,
			IRQF_ONESHOT | IRQF_TRIGGER_HIGH, "mc13783", mc13783);

	if (ret) {
err_mask:
err_revision:
		mutex_unlock(&mc13783->lock);
		dev_set_drvdata(&spi->dev, NULL);
		kfree(mc13783);
		return ret;
	}

	/* This should go away (BEGIN) */
	if (pdata) {
		mc13783->flags = pdata->flags;
		mc13783->regulators = pdata->regulators;
		mc13783->num_regulators = pdata->num_regulators;
	}
	/* This should go away (END) */

	mc13783_unlock(mc13783);

	if (pdata->flags & MC13783_USE_ADC)
		mc13783_add_subdevice(mc13783, "mc13783-adc");

	if (pdata->flags & MC13783_USE_CODEC)
		mc13783_add_subdevice(mc13783, "mc13783-codec");

	if (pdata->flags & MC13783_USE_REGULATOR) {
		struct mc13783_regulator_platform_data regulator_pdata = {
			.num_regulators = pdata->num_regulators,
			.regulators = pdata->regulators,
		};

		mc13783_add_subdevice_pdata(mc13783, "mc13783-regulator",
				&regulator_pdata, sizeof(regulator_pdata));
	}

	if (pdata->flags & MC13783_USE_RTC)
		mc13783_add_subdevice(mc13783, "mc13783-rtc");

	if (pdata->flags & MC13783_USE_TOUCHSCREEN)
		mc13783_add_subdevice(mc13783, "mc13783-ts");

	if (pdata->flags & MC13783_USE_LED)
		mc13783_add_subdevice_pdata(mc13783, "mc13783-led",
					pdata->leds, sizeof(*pdata->leds));

	return 0;
}

static int __devexit mc13783_remove(struct spi_device *spi)
{
	struct mc13783 *mc13783 = dev_get_drvdata(&spi->dev);

	free_irq(mc13783->spidev->irq, mc13783);

	mfd_remove_devices(&spi->dev);

	return 0;
}

static struct spi_driver mc13783_driver = {
	.driver = {
		.name = "mc13783",
		.bus = &spi_bus_type,
		.owner = THIS_MODULE,
	},
	.probe = mc13783_probe,
	.remove = __devexit_p(mc13783_remove),
};
Exemple #7
0
int mc13783_adc_do_conversion(struct mc13783 *mc13783, unsigned int mode,
		unsigned int channel, unsigned int *sample)
{
	u32 adc0, adc1, old_adc0;
	int i, ret;
	struct mc13783_adcdone_data adcdone_data = {
		.mc13783 = mc13783,
	};
	init_completion(&adcdone_data.done);

	dev_dbg(&mc13783->spidev->dev, "%s\n", __func__);

	mc13783_lock(mc13783);

	if (mc13783->flags & MC13783_ADC_WORKING) {
		ret = -EBUSY;
		goto out;
	}

	mc13783->flags |= MC13783_ADC_WORKING;

	mc13783_reg_read(mc13783, MC13783_ADC0, &old_adc0);

	adc0 = MC13783_ADC0_ADINC1 | MC13783_ADC0_ADINC2;
	adc1 = MC13783_ADC1_ADEN | MC13783_ADC1_ADTRIGIGN | MC13783_ADC1_ASC;

	if (channel > 7)
		adc1 |= MC13783_ADC1_ADSEL;

	switch (mode) {
	case MC13783_ADC_MODE_TS:
		adc0 |= MC13783_ADC0_ADREFEN | MC13783_ADC0_TSMOD0 |
			MC13783_ADC0_TSMOD1;
		adc1 |= 4 << MC13783_ADC1_CHAN1_SHIFT;
		break;

	case MC13783_ADC_MODE_SINGLE_CHAN:
		adc0 |= old_adc0 & MC13783_ADC0_TSMOD_MASK;
		adc1 |= (channel & 0x7) << MC13783_ADC1_CHAN0_SHIFT;
		adc1 |= MC13783_ADC1_RAND;
		break;

	case MC13783_ADC_MODE_MULT_CHAN:
		adc0 |= old_adc0 & MC13783_ADC0_TSMOD_MASK;
		adc1 |= 4 << MC13783_ADC1_CHAN1_SHIFT;
		break;

	default:
		mc13783_unlock(mc13783);
		return -EINVAL;
	}

	dev_dbg(&mc13783->spidev->dev, "%s: request irq\n", __func__);
	mc13783_irq_request(mc13783, MC13783_IRQ_ADCDONE,
			mc13783_handler_adcdone, __func__, &adcdone_data);
	mc13783_irq_ack(mc13783, MC13783_IRQ_ADCDONE);

	mc13783_reg_write(mc13783, MC13783_REG_ADC_0, adc0);
	mc13783_reg_write(mc13783, MC13783_REG_ADC_1, adc1);

	mc13783_unlock(mc13783);

	ret = wait_for_completion_interruptible_timeout(&adcdone_data.done, HZ);

	if (!ret)
		ret = -ETIMEDOUT;

	mc13783_lock(mc13783);

	mc13783_irq_free(mc13783, MC13783_IRQ_ADCDONE, &adcdone_data);

	if (ret > 0)
		for (i = 0; i < 4; ++i) {
			ret = mc13783_reg_read(mc13783,
					MC13783_REG_ADC_2, &sample[i]);
			if (ret)
				break;
		}

	if (mode == MC13783_ADC_MODE_TS)
		/* restore TSMOD */
		mc13783_reg_write(mc13783, MC13783_REG_ADC_0, old_adc0);

	mc13783->flags &= ~MC13783_ADC_WORKING;
out:
	mc13783_unlock(mc13783);

	return ret;
}