Lines Matching refs:mc13xxx
22 struct mc13xxx { struct
32 struct mc13xxx mc13xxx; argument
37 struct mc13xxx *mc13783_to_mc13xxx(struct mc13783 *mc13783) in mc13783_to_mc13xxx()
39 return &mc13783->mc13xxx; in mc13783_to_mc13xxx()
150 void mc13xxx_lock(struct mc13xxx *mc13xxx) in mc13xxx_lock() argument
152 if (!mutex_trylock(&mc13xxx->lock)) { in mc13xxx_lock()
153 dev_dbg(&mc13xxx->spidev->dev, "wait for %s from %pf\n", in mc13xxx_lock()
156 mutex_lock(&mc13xxx->lock); in mc13xxx_lock()
158 dev_dbg(&mc13xxx->spidev->dev, "%s from %pf\n", in mc13xxx_lock()
163 void mc13xxx_unlock(struct mc13xxx *mc13xxx) in mc13xxx_unlock() argument
165 dev_dbg(&mc13xxx->spidev->dev, "%s from %pf\n", in mc13xxx_unlock()
167 mutex_unlock(&mc13xxx->lock); in mc13xxx_unlock()
172 int mc13xxx_reg_read(struct mc13xxx *mc13xxx, unsigned int offset, u32 *val) in mc13xxx_reg_read() argument
178 BUG_ON(!mutex_is_locked(&mc13xxx->lock)); in mc13xxx_reg_read()
194 ret = spi_sync(mc13xxx->spidev, &m); in mc13xxx_reg_read()
204 dev_vdbg(&mc13xxx->spidev->dev, "[0x%02x] -> 0x%06x\n", offset, *val); in mc13xxx_reg_read()
210 int mc13xxx_reg_write(struct mc13xxx *mc13xxx, unsigned int offset, u32 val) in mc13xxx_reg_write() argument
217 BUG_ON(!mutex_is_locked(&mc13xxx->lock)); in mc13xxx_reg_write()
219 dev_vdbg(&mc13xxx->spidev->dev, "[0x%02x] <- 0x%06x\n", offset, val); in mc13xxx_reg_write()
235 ret = spi_sync(mc13xxx->spidev, &m); in mc13xxx_reg_write()
246 int mc13xxx_reg_rmw(struct mc13xxx *mc13xxx, unsigned int offset, in mc13xxx_reg_rmw() argument
254 ret = mc13xxx_reg_read(mc13xxx, offset, &valread); in mc13xxx_reg_rmw()
260 return mc13xxx_reg_write(mc13xxx, offset, valread); in mc13xxx_reg_rmw()
264 int mc13xxx_irq_mask(struct mc13xxx *mc13xxx, int irq) in mc13xxx_irq_mask() argument
274 ret = mc13xxx_reg_read(mc13xxx, offmask, &mask); in mc13xxx_irq_mask()
282 return mc13xxx_reg_write(mc13xxx, offmask, mask | irqbit); in mc13xxx_irq_mask()
286 int mc13xxx_irq_unmask(struct mc13xxx *mc13xxx, int irq) in mc13xxx_irq_unmask() argument
296 ret = mc13xxx_reg_read(mc13xxx, offmask, &mask); in mc13xxx_irq_unmask()
304 return mc13xxx_reg_write(mc13xxx, offmask, mask & ~irqbit); in mc13xxx_irq_unmask()
308 int mc13xxx_irq_status(struct mc13xxx *mc13xxx, int irq, in mc13xxx_irq_status() argument
322 ret = mc13xxx_reg_read(mc13xxx, offmask, &mask); in mc13xxx_irq_status()
332 ret = mc13xxx_reg_read(mc13xxx, offstat, &stat); in mc13xxx_irq_status()
343 int mc13xxx_irq_ack(struct mc13xxx *mc13xxx, int irq) in mc13xxx_irq_ack() argument
350 return mc13xxx_reg_write(mc13xxx, offstat, val); in mc13xxx_irq_ack()
354 int mc13xxx_irq_request_nounmask(struct mc13xxx *mc13xxx, int irq, in mc13xxx_irq_request_nounmask() argument
357 BUG_ON(!mutex_is_locked(&mc13xxx->lock)); in mc13xxx_irq_request_nounmask()
363 if (mc13xxx->irqhandler[irq]) in mc13xxx_irq_request_nounmask()
366 mc13xxx->irqhandler[irq] = handler; in mc13xxx_irq_request_nounmask()
367 mc13xxx->irqdata[irq] = dev; in mc13xxx_irq_request_nounmask()
373 int mc13xxx_irq_request(struct mc13xxx *mc13xxx, int irq, in mc13xxx_irq_request() argument
378 ret = mc13xxx_irq_request_nounmask(mc13xxx, irq, handler, name, dev); in mc13xxx_irq_request()
382 ret = mc13xxx_irq_unmask(mc13xxx, irq); in mc13xxx_irq_request()
384 mc13xxx->irqhandler[irq] = NULL; in mc13xxx_irq_request()
385 mc13xxx->irqdata[irq] = NULL; in mc13xxx_irq_request()
393 int mc13xxx_irq_free(struct mc13xxx *mc13xxx, int irq, void *dev) in mc13xxx_irq_free() argument
396 BUG_ON(!mutex_is_locked(&mc13xxx->lock)); in mc13xxx_irq_free()
398 if (irq < 0 || irq >= MC13XXX_NUM_IRQ || !mc13xxx->irqhandler[irq] || in mc13xxx_irq_free()
399 mc13xxx->irqdata[irq] != dev) in mc13xxx_irq_free()
402 ret = mc13xxx_irq_mask(mc13xxx, irq); in mc13xxx_irq_free()
406 mc13xxx->irqhandler[irq] = NULL; in mc13xxx_irq_free()
407 mc13xxx->irqdata[irq] = NULL; in mc13xxx_irq_free()
413 static inline irqreturn_t mc13xxx_irqhandler(struct mc13xxx *mc13xxx, int irq) in mc13xxx_irqhandler() argument
415 return mc13xxx->irqhandler[irq](irq, mc13xxx->irqdata[irq]); in mc13xxx_irqhandler()
422 static int mc13xxx_irq_handle(struct mc13xxx *mc13xxx, in mc13xxx_irq_handle() argument
426 int ret = mc13xxx_reg_read(mc13xxx, offstat, &stat); in mc13xxx_irq_handle()
432 ret = mc13xxx_reg_read(mc13xxx, offmask, &mask); in mc13xxx_irq_handle()
441 if (likely(mc13xxx->irqhandler[baseirq + irq])) { in mc13xxx_irq_handle()
444 handled = mc13xxx_irqhandler(mc13xxx, baseirq + irq); in mc13xxx_irq_handle()
448 dev_err(&mc13xxx->spidev->dev, in mc13xxx_irq_handle()
454 ret = mc13xxx_reg_write(mc13xxx, offmask, mask); in mc13xxx_irq_handle()
463 struct mc13xxx *mc13xxx = data; in mc13xxx_irq_thread() local
467 mc13xxx_lock(mc13xxx); in mc13xxx_irq_thread()
469 ret = mc13xxx_irq_handle(mc13xxx, MC13XXX_IRQSTAT0, in mc13xxx_irq_thread()
474 ret = mc13xxx_irq_handle(mc13xxx, MC13XXX_IRQSTAT1, in mc13xxx_irq_thread()
479 mc13xxx_unlock(mc13xxx); in mc13xxx_irq_thread()
496 static int mc13xxx_identify(struct mc13xxx *mc13xxx, enum mc13xxx_id *id) in mc13xxx_identify() argument
503 ret = mc13xxx_reg_read(mc13xxx, 46, &icid); in mc13xxx_identify()
524 ret = mc13xxx_reg_read(mc13xxx, MC13XXX_REVISION, &revision); in mc13xxx_identify()
528 dev_info(&mc13xxx->spidev->dev, "%s: rev: %d.%d, " in mc13xxx_identify()
541 spi_get_device_id(mc13xxx->spidev); in mc13xxx_identify()
543 dev_warn(&mc13xxx->spidev->dev, "device id doesn't " in mc13xxx_identify()
550 static const char *mc13xxx_get_chipname(struct mc13xxx *mc13xxx) in mc13xxx_get_chipname() argument
553 spi_get_device_id(mc13xxx->spidev); in mc13xxx_get_chipname()
563 int mc13xxx_get_flags(struct mc13xxx *mc13xxx) in mc13xxx_get_flags() argument
566 dev_get_platdata(&mc13xxx->spidev->dev); in mc13xxx_get_flags()
576 struct mc13xxx *mc13xxx; member
584 mc13xxx_irq_ack(adcdone_data->mc13xxx, irq); in mc13783_handler_adcdone()
596 struct mc13xxx *mc13xxx = &mc13783->mc13xxx; in mc13783_adc_do_conversion() local
600 .mc13xxx = mc13xxx, in mc13783_adc_do_conversion()
604 dev_dbg(&mc13xxx->spidev->dev, "%s\n", __func__); in mc13783_adc_do_conversion()
606 mc13xxx_lock(mc13xxx); in mc13783_adc_do_conversion()
615 mc13xxx_reg_read(mc13xxx, MC13783_ADC0, &old_adc0); in mc13783_adc_do_conversion()
646 dev_dbg(&mc13783->mc13xxx.spidev->dev, "%s: request irq\n", __func__); in mc13783_adc_do_conversion()
647 mc13xxx_irq_request(mc13xxx, MC13783_IRQ_ADCDONE, in mc13783_adc_do_conversion()
649 mc13xxx_irq_ack(mc13xxx, MC13783_IRQ_ADCDONE); in mc13783_adc_do_conversion()
651 mc13xxx_reg_write(mc13xxx, MC13783_ADC0, adc0); in mc13783_adc_do_conversion()
652 mc13xxx_reg_write(mc13xxx, MC13783_ADC1, adc1); in mc13783_adc_do_conversion()
654 mc13xxx_unlock(mc13xxx); in mc13783_adc_do_conversion()
661 mc13xxx_lock(mc13xxx); in mc13783_adc_do_conversion()
663 mc13xxx_irq_free(mc13xxx, MC13783_IRQ_ADCDONE, &adcdone_data); in mc13783_adc_do_conversion()
667 ret = mc13xxx_reg_read(mc13xxx, in mc13783_adc_do_conversion()
675 mc13xxx_reg_write(mc13xxx, MC13783_ADC0, old_adc0); in mc13783_adc_do_conversion()
679 mc13xxx_unlock(mc13xxx); in mc13783_adc_do_conversion()
685 static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, in mc13xxx_add_subdevice_pdata() argument
689 const char *name = mc13xxx_get_chipname(mc13xxx); in mc13xxx_add_subdevice_pdata()
703 return mfd_add_devices(&mc13xxx->spidev->dev, -1, &cell, 1, NULL, 0); in mc13xxx_add_subdevice_pdata()
706 static int mc13xxx_add_subdevice(struct mc13xxx *mc13xxx, const char *format) in mc13xxx_add_subdevice() argument
708 return mc13xxx_add_subdevice_pdata(mc13xxx, format, NULL); in mc13xxx_add_subdevice()
713 struct mc13xxx *mc13xxx; in mc13xxx_probe() local
718 mc13xxx = kzalloc(sizeof(*mc13xxx), GFP_KERNEL); in mc13xxx_probe()
719 if (!mc13xxx) in mc13xxx_probe()
722 dev_set_drvdata(&spi->dev, mc13xxx); in mc13xxx_probe()
727 mc13xxx->spidev = spi; in mc13xxx_probe()
729 mutex_init(&mc13xxx->lock); in mc13xxx_probe()
730 mc13xxx_lock(mc13xxx); in mc13xxx_probe()
732 ret = mc13xxx_identify(mc13xxx, &id); in mc13xxx_probe()
737 ret = mc13xxx_reg_write(mc13xxx, MC13XXX_IRQMASK0, 0x00ffffff); in mc13xxx_probe()
741 ret = mc13xxx_reg_write(mc13xxx, MC13XXX_IRQMASK1, 0x00ffffff); in mc13xxx_probe()
746 IRQF_ONESHOT | IRQF_TRIGGER_HIGH, "mc13xxx", mc13xxx); in mc13xxx_probe()
751 mc13xxx_unlock(mc13xxx); in mc13xxx_probe()
753 kfree(mc13xxx); in mc13xxx_probe()
757 mc13xxx_unlock(mc13xxx); in mc13xxx_probe()
760 mc13xxx_add_subdevice(mc13xxx, "%s-adc"); in mc13xxx_probe()
763 mc13xxx_add_subdevice(mc13xxx, "%s-codec"); in mc13xxx_probe()
766 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-regulator", in mc13xxx_probe()
771 mc13xxx_add_subdevice(mc13xxx, "%s-rtc"); in mc13xxx_probe()
774 mc13xxx_add_subdevice(mc13xxx, "%s-ts"); in mc13xxx_probe()
777 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led", pdata->leds); in mc13xxx_probe()
784 struct mc13xxx *mc13xxx = dev_get_drvdata(&spi->dev); in mc13xxx_remove() local
786 free_irq(mc13xxx->spidev->irq, mc13xxx); in mc13xxx_remove()
790 kfree(mc13xxx); in mc13xxx_remove()