Lines Matching +full:spi +full:- +full:present +full:- +full:mask
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for Motorola PCAP2 as present in EZX phones
14 #include <linux/mfd/ezx-pcap.h>
15 #include <linux/spi/spi.h>
34 struct spi_device *spi; member
66 pcap->buf = *data; in ezx_pcap_putget()
67 t.tx_buf = (u8 *) &pcap->buf; in ezx_pcap_putget()
68 t.rx_buf = (u8 *) &pcap->buf; in ezx_pcap_putget()
69 status = spi_sync(pcap->spi, &m); in ezx_pcap_putget()
72 *data = pcap->buf; in ezx_pcap_putget()
82 spin_lock_irqsave(&pcap->io_lock, flags); in ezx_pcap_write()
87 spin_unlock_irqrestore(&pcap->io_lock, flags); in ezx_pcap_write()
98 spin_lock_irqsave(&pcap->io_lock, flags); in ezx_pcap_read()
103 spin_unlock_irqrestore(&pcap->io_lock, flags); in ezx_pcap_read()
109 int ezx_pcap_set_bits(struct pcap_chip *pcap, u8 reg_num, u32 mask, u32 val) in ezx_pcap_set_bits() argument
116 spin_lock_irqsave(&pcap->io_lock, flags); in ezx_pcap_set_bits()
121 tmp &= (PCAP_REGISTER_VALUE_MASK & ~mask); in ezx_pcap_set_bits()
122 tmp |= (val & mask) | PCAP_REGISTER_WRITE_OP_BIT | in ezx_pcap_set_bits()
127 spin_unlock_irqrestore(&pcap->io_lock, flags); in ezx_pcap_set_bits()
136 return irq - pcap->irq_base; in irq_to_pcap()
142 return pcap->irq_base + irq; in pcap_to_irq()
150 pcap->msr |= 1 << irq_to_pcap(pcap, d->irq); in pcap_mask_irq()
151 queue_work(pcap->workqueue, &pcap->msr_work); in pcap_mask_irq()
158 pcap->msr &= ~(1 << irq_to_pcap(pcap, d->irq)); in pcap_unmask_irq()
159 queue_work(pcap->workqueue, &pcap->msr_work); in pcap_unmask_irq()
173 ezx_pcap_write(pcap, PCAP_REG_MSR, pcap->msr); in pcap_msr_work()
179 struct pcap_platform_data *pdata = dev_get_platdata(&pcap->spi->dev); in pcap_isr_work()
188 if (!(pdata->config & PCAP_SECOND_PORT)) { in pcap_isr_work()
197 for (irq = pcap->irq_base; service; service >>= 1, irq++) { in pcap_isr_work()
201 ezx_pcap_write(pcap, PCAP_REG_MSR, pcap->msr); in pcap_isr_work()
202 } while (gpio_get_value(pdata->gpio)); in pcap_isr_work()
209 desc->irq_data.chip->irq_ack(&desc->irq_data); in pcap_irq_handler()
210 queue_work(pcap->workqueue, &pcap->isr_work); in pcap_irq_handler()
219 spin_lock_irqsave(&pcap->adc_lock, flags); in pcap_set_ts_bits()
224 spin_unlock_irqrestore(&pcap->adc_lock, flags); in pcap_set_ts_bits()
243 spin_lock_irqsave(&pcap->adc_lock, flags); in pcap_adc_trigger()
244 head = pcap->adc_head; in pcap_adc_trigger()
245 if (!pcap->adc_queue[head]) { in pcap_adc_trigger()
248 spin_unlock_irqrestore(&pcap->adc_lock, flags); in pcap_adc_trigger()
254 tmp |= pcap->adc_queue[head]->flags | PCAP_ADC_ADEN; in pcap_adc_trigger()
256 if (pcap->adc_queue[head]->bank == PCAP_ADC_BANK_1) in pcap_adc_trigger()
260 spin_unlock_irqrestore(&pcap->adc_lock, flags); in pcap_adc_trigger()
271 spin_lock(&pcap->adc_lock); in pcap_adc_irq()
272 req = pcap->adc_queue[pcap->adc_head]; in pcap_adc_irq()
275 spin_unlock(&pcap->adc_lock); in pcap_adc_irq()
282 tmp |= (req->ch[0] << PCAP_ADC_ADA1_SHIFT); in pcap_adc_irq()
283 tmp |= (req->ch[1] << PCAP_ADC_ADA2_SHIFT); in pcap_adc_irq()
289 pcap->adc_queue[pcap->adc_head] = NULL; in pcap_adc_irq()
290 pcap->adc_head = (pcap->adc_head + 1) & (PCAP_ADC_MAXQ - 1); in pcap_adc_irq()
291 spin_unlock(&pcap->adc_lock); in pcap_adc_irq()
294 req->callback(req->data, res); in pcap_adc_irq()
312 return -ENOMEM; in pcap_adc_async()
314 req->bank = bank; in pcap_adc_async()
315 req->flags = flags; in pcap_adc_async()
316 req->ch[0] = ch[0]; in pcap_adc_async()
317 req->ch[1] = ch[1]; in pcap_adc_async()
318 req->callback = callback; in pcap_adc_async()
319 req->data = data; in pcap_adc_async()
321 spin_lock_irqsave(&pcap->adc_lock, irq_flags); in pcap_adc_async()
322 if (pcap->adc_queue[pcap->adc_tail]) { in pcap_adc_async()
323 spin_unlock_irqrestore(&pcap->adc_lock, irq_flags); in pcap_adc_async()
325 return -EBUSY; in pcap_adc_async()
327 pcap->adc_queue[pcap->adc_tail] = req; in pcap_adc_async()
328 pcap->adc_tail = (pcap->adc_tail + 1) & (PCAP_ADC_MAXQ - 1); in pcap_adc_async()
329 spin_unlock_irqrestore(&pcap->adc_lock, irq_flags); in pcap_adc_async()
342 req->res[0] = res[0]; in pcap_adc_sync_cb()
343 req->res[1] = res[1]; in pcap_adc_sync_cb()
344 complete(&req->completion); in pcap_adc_sync_cb()
379 pdev = platform_device_alloc(subdev->name, subdev->id); in pcap_add_subdev()
381 return -ENOMEM; in pcap_add_subdev()
383 pdev->dev.parent = &pcap->spi->dev; in pcap_add_subdev()
384 pdev->dev.platform_data = subdev->platform_data; in pcap_add_subdev()
393 static void ezx_pcap_remove(struct spi_device *spi) in ezx_pcap_remove() argument
395 struct pcap_chip *pcap = spi_get_drvdata(spi); in ezx_pcap_remove()
400 device_for_each_child(&spi->dev, NULL, pcap_remove_subdev); in ezx_pcap_remove()
403 spin_lock_irqsave(&pcap->adc_lock, flags); in ezx_pcap_remove()
405 kfree(pcap->adc_queue[i]); in ezx_pcap_remove()
406 spin_unlock_irqrestore(&pcap->adc_lock, flags); in ezx_pcap_remove()
409 for (i = pcap->irq_base; i < (pcap->irq_base + PCAP_NIRQS); i++) in ezx_pcap_remove()
412 destroy_workqueue(pcap->workqueue); in ezx_pcap_remove()
415 static int ezx_pcap_probe(struct spi_device *spi) in ezx_pcap_probe() argument
417 struct pcap_platform_data *pdata = dev_get_platdata(&spi->dev); in ezx_pcap_probe()
420 int ret = -ENODEV; in ezx_pcap_probe()
426 pcap = devm_kzalloc(&spi->dev, sizeof(*pcap), GFP_KERNEL); in ezx_pcap_probe()
428 ret = -ENOMEM; in ezx_pcap_probe()
432 spin_lock_init(&pcap->io_lock); in ezx_pcap_probe()
433 spin_lock_init(&pcap->adc_lock); in ezx_pcap_probe()
434 INIT_WORK(&pcap->isr_work, pcap_isr_work); in ezx_pcap_probe()
435 INIT_WORK(&pcap->msr_work, pcap_msr_work); in ezx_pcap_probe()
436 spi_set_drvdata(spi, pcap); in ezx_pcap_probe()
438 /* setup spi */ in ezx_pcap_probe()
439 spi->bits_per_word = 32; in ezx_pcap_probe()
440 spi->mode = SPI_MODE_0 | (pdata->config & PCAP_CS_AH ? SPI_CS_HIGH : 0); in ezx_pcap_probe()
441 ret = spi_setup(spi); in ezx_pcap_probe()
445 pcap->spi = spi; in ezx_pcap_probe()
448 pcap->irq_base = pdata->irq_base; in ezx_pcap_probe()
449 pcap->workqueue = create_singlethread_workqueue("pcapd"); in ezx_pcap_probe()
450 if (!pcap->workqueue) { in ezx_pcap_probe()
451 ret = -ENOMEM; in ezx_pcap_probe()
452 dev_err(&spi->dev, "can't create pcap thread\n"); in ezx_pcap_probe()
457 if (!(pdata->config & PCAP_SECOND_PORT)) in ezx_pcap_probe()
462 for (i = pcap->irq_base; i < (pcap->irq_base + PCAP_NIRQS); i++) { in ezx_pcap_probe()
468 /* mask/ack all PCAP interrupts */ in ezx_pcap_probe()
471 pcap->msr = PCAP_MASK_ALL_INTERRUPT; in ezx_pcap_probe()
473 irq_set_irq_type(spi->irq, IRQ_TYPE_EDGE_RISING); in ezx_pcap_probe()
474 irq_set_chained_handler_and_data(spi->irq, pcap_irq_handler, pcap); in ezx_pcap_probe()
475 irq_set_irq_wake(spi->irq, 1); in ezx_pcap_probe()
478 adc_irq = pcap_to_irq(pcap, (pdata->config & PCAP_SECOND_PORT) ? in ezx_pcap_probe()
481 ret = devm_request_irq(&spi->dev, adc_irq, pcap_adc_irq, 0, "ADC", in ezx_pcap_probe()
487 for (i = 0; i < pdata->num_subdevs; i++) { in ezx_pcap_probe()
488 ret = pcap_add_subdev(pcap, &pdata->subdevs[i]); in ezx_pcap_probe()
494 if (pdata->init) in ezx_pcap_probe()
495 pdata->init(pcap); in ezx_pcap_probe()
500 device_for_each_child(&spi->dev, NULL, pcap_remove_subdev); in ezx_pcap_probe()
502 for (i = pcap->irq_base; i < (pcap->irq_base + PCAP_NIRQS); i++) in ezx_pcap_probe()
505 destroy_workqueue(pcap->workqueue); in ezx_pcap_probe()
514 .name = "ezx-pcap",
533 MODULE_ALIAS("spi:ezx-pcap");