Lines Matching refs:mc13xxx

48 void mc13xxx_lock(struct mc13xxx *mc13xxx)  in mc13xxx_lock()  argument
50 if (!mutex_trylock(&mc13xxx->lock)) { in mc13xxx_lock()
51 dev_dbg(mc13xxx->dev, "wait for %s from %ps\n", in mc13xxx_lock()
54 mutex_lock(&mc13xxx->lock); in mc13xxx_lock()
56 dev_dbg(mc13xxx->dev, "%s from %ps\n", in mc13xxx_lock()
61 void mc13xxx_unlock(struct mc13xxx *mc13xxx) in mc13xxx_unlock() argument
63 dev_dbg(mc13xxx->dev, "%s from %ps\n", in mc13xxx_unlock()
65 mutex_unlock(&mc13xxx->lock); in mc13xxx_unlock()
69 int mc13xxx_reg_read(struct mc13xxx *mc13xxx, unsigned int offset, u32 *val) in mc13xxx_reg_read() argument
73 ret = regmap_read(mc13xxx->regmap, offset, val); in mc13xxx_reg_read()
74 dev_vdbg(mc13xxx->dev, "[0x%02x] -> 0x%06x\n", offset, *val); in mc13xxx_reg_read()
80 int mc13xxx_reg_write(struct mc13xxx *mc13xxx, unsigned int offset, u32 val) in mc13xxx_reg_write() argument
82 dev_vdbg(mc13xxx->dev, "[0x%02x] <- 0x%06x\n", offset, val); in mc13xxx_reg_write()
87 return regmap_write(mc13xxx->regmap, offset, val); in mc13xxx_reg_write()
91 int mc13xxx_reg_rmw(struct mc13xxx *mc13xxx, unsigned int offset, in mc13xxx_reg_rmw() argument
95 dev_vdbg(mc13xxx->dev, "[0x%02x] <- 0x%06x (mask: 0x%06x)\n", in mc13xxx_reg_rmw()
98 return regmap_update_bits(mc13xxx->regmap, offset, mask, val); in mc13xxx_reg_rmw()
102 int mc13xxx_irq_mask(struct mc13xxx *mc13xxx, int irq) in mc13xxx_irq_mask() argument
104 int virq = regmap_irq_get_virq(mc13xxx->irq_data, irq); in mc13xxx_irq_mask()
112 int mc13xxx_irq_unmask(struct mc13xxx *mc13xxx, int irq) in mc13xxx_irq_unmask() argument
114 int virq = regmap_irq_get_virq(mc13xxx->irq_data, irq); in mc13xxx_irq_unmask()
122 int mc13xxx_irq_status(struct mc13xxx *mc13xxx, int irq, in mc13xxx_irq_status() argument
130 if (irq < 0 || irq >= ARRAY_SIZE(mc13xxx->irqs)) in mc13xxx_irq_status()
136 ret = mc13xxx_reg_read(mc13xxx, offmask, &mask); in mc13xxx_irq_status()
146 ret = mc13xxx_reg_read(mc13xxx, offstat, &stat); in mc13xxx_irq_status()
157 int mc13xxx_irq_request(struct mc13xxx *mc13xxx, int irq, in mc13xxx_irq_request() argument
160 int virq = regmap_irq_get_virq(mc13xxx->irq_data, irq); in mc13xxx_irq_request()
162 return devm_request_threaded_irq(mc13xxx->dev, virq, NULL, handler, in mc13xxx_irq_request()
167 int mc13xxx_irq_free(struct mc13xxx *mc13xxx, int irq, void *dev) in mc13xxx_irq_free() argument
169 int virq = regmap_irq_get_virq(mc13xxx->irq_data, irq); in mc13xxx_irq_free()
171 devm_free_irq(mc13xxx->dev, virq, dev); in mc13xxx_irq_free()
178 static void mc13xxx_print_revision(struct mc13xxx *mc13xxx, u32 revision) in mc13xxx_print_revision() argument
180 dev_info(mc13xxx->dev, "%s: rev: %d.%d, " in mc13xxx_print_revision()
182 mc13xxx->variant->name, in mc13xxx_print_revision()
191 static void mc34708_print_revision(struct mc13xxx *mc13xxx, u32 revision) in mc34708_print_revision() argument
193 dev_info(mc13xxx->dev, "%s: rev %d.%d, fin: %d, fab: %d\n", in mc34708_print_revision()
194 mc13xxx->variant->name, in mc34708_print_revision()
220 static const char *mc13xxx_get_chipname(struct mc13xxx *mc13xxx) in mc13xxx_get_chipname() argument
222 return mc13xxx->variant->name; in mc13xxx_get_chipname()
225 int mc13xxx_get_flags(struct mc13xxx *mc13xxx) in mc13xxx_get_flags() argument
227 return mc13xxx->flags; in mc13xxx_get_flags()
237 struct mc13xxx *mc13xxx; member
252 int mc13xxx_adc_do_conversion(struct mc13xxx *mc13xxx, unsigned int mode, in mc13xxx_adc_do_conversion() argument
259 .mc13xxx = mc13xxx, in mc13xxx_adc_do_conversion()
263 dev_dbg(mc13xxx->dev, "%s\n", __func__); in mc13xxx_adc_do_conversion()
265 mc13xxx_lock(mc13xxx); in mc13xxx_adc_do_conversion()
267 if (mc13xxx->adcflags & MC13XXX_ADC_WORKING) { in mc13xxx_adc_do_conversion()
272 mc13xxx->adcflags |= MC13XXX_ADC_WORKING; in mc13xxx_adc_do_conversion()
274 ret = mc13xxx_reg_read(mc13xxx, MC13XXX_ADC0, &old_adc0); in mc13xxx_adc_do_conversion()
317 mc13xxx_unlock(mc13xxx); in mc13xxx_adc_do_conversion()
325 dev_dbg(mc13xxx->dev, "%s: request irq\n", __func__); in mc13xxx_adc_do_conversion()
326 mc13xxx_irq_request(mc13xxx, MC13XXX_IRQ_ADCDONE, in mc13xxx_adc_do_conversion()
329 mc13xxx_reg_write(mc13xxx, MC13XXX_ADC0, adc0); in mc13xxx_adc_do_conversion()
330 mc13xxx_reg_write(mc13xxx, MC13XXX_ADC1, adc1); in mc13xxx_adc_do_conversion()
332 mc13xxx_unlock(mc13xxx); in mc13xxx_adc_do_conversion()
339 mc13xxx_lock(mc13xxx); in mc13xxx_adc_do_conversion()
341 mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_ADCDONE, &adcdone_data); in mc13xxx_adc_do_conversion()
345 ret = mc13xxx_reg_read(mc13xxx, in mc13xxx_adc_do_conversion()
353 mc13xxx_reg_write(mc13xxx, MC13XXX_ADC0, old_adc0); in mc13xxx_adc_do_conversion()
355 mc13xxx->adcflags &= ~MC13XXX_ADC_WORKING; in mc13xxx_adc_do_conversion()
357 mc13xxx_unlock(mc13xxx); in mc13xxx_adc_do_conversion()
363 static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, in mc13xxx_add_subdevice_pdata() argument
367 const char *name = mc13xxx_get_chipname(mc13xxx); in mc13xxx_add_subdevice_pdata()
382 return mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0, in mc13xxx_add_subdevice_pdata()
383 regmap_irq_get_domain(mc13xxx->irq_data)); in mc13xxx_add_subdevice_pdata()
386 static int mc13xxx_add_subdevice(struct mc13xxx *mc13xxx, const char *format) in mc13xxx_add_subdevice() argument
388 return mc13xxx_add_subdevice_pdata(mc13xxx, format, NULL, 0); in mc13xxx_add_subdevice()
392 static int mc13xxx_probe_flags_dt(struct mc13xxx *mc13xxx) in mc13xxx_probe_flags_dt() argument
394 struct device_node *np = mc13xxx->dev->of_node; in mc13xxx_probe_flags_dt()
400 mc13xxx->flags |= MC13XXX_USE_ADC; in mc13xxx_probe_flags_dt()
403 mc13xxx->flags |= MC13XXX_USE_CODEC; in mc13xxx_probe_flags_dt()
406 mc13xxx->flags |= MC13XXX_USE_RTC; in mc13xxx_probe_flags_dt()
409 mc13xxx->flags |= MC13XXX_USE_TOUCHSCREEN; in mc13xxx_probe_flags_dt()
414 static inline int mc13xxx_probe_flags_dt(struct mc13xxx *mc13xxx) in mc13xxx_probe_flags_dt() argument
423 struct mc13xxx *mc13xxx = dev_get_drvdata(dev); in mc13xxx_common_init() local
427 mc13xxx->dev = dev; in mc13xxx_common_init()
429 ret = mc13xxx_reg_read(mc13xxx, MC13XXX_REVISION, &revision); in mc13xxx_common_init()
433 mc13xxx->variant->print_revision(mc13xxx, revision); in mc13xxx_common_init()
435 ret = mc13xxx_reg_rmw(mc13xxx, MC13XXX_PWRCTRL, in mc13xxx_common_init()
440 for (i = 0; i < ARRAY_SIZE(mc13xxx->irqs); i++) { in mc13xxx_common_init()
441 mc13xxx->irqs[i].reg_offset = i / MC13XXX_IRQ_PER_REG; in mc13xxx_common_init()
442 mc13xxx->irqs[i].mask = BIT(i % MC13XXX_IRQ_PER_REG); in mc13xxx_common_init()
445 mc13xxx->irq_chip.name = dev_name(dev); in mc13xxx_common_init()
446 mc13xxx->irq_chip.status_base = MC13XXX_IRQSTAT0; in mc13xxx_common_init()
447 mc13xxx->irq_chip.mask_base = MC13XXX_IRQMASK0; in mc13xxx_common_init()
448 mc13xxx->irq_chip.ack_base = MC13XXX_IRQSTAT0; in mc13xxx_common_init()
449 mc13xxx->irq_chip.irq_reg_stride = MC13XXX_IRQSTAT1 - MC13XXX_IRQSTAT0; in mc13xxx_common_init()
450 mc13xxx->irq_chip.init_ack_masked = true; in mc13xxx_common_init()
451 mc13xxx->irq_chip.use_ack = true; in mc13xxx_common_init()
452 mc13xxx->irq_chip.num_regs = MC13XXX_IRQ_REG_CNT; in mc13xxx_common_init()
453 mc13xxx->irq_chip.irqs = mc13xxx->irqs; in mc13xxx_common_init()
454 mc13xxx->irq_chip.num_irqs = ARRAY_SIZE(mc13xxx->irqs); in mc13xxx_common_init()
456 ret = regmap_add_irq_chip(mc13xxx->regmap, mc13xxx->irq, IRQF_ONESHOT, in mc13xxx_common_init()
457 0, &mc13xxx->irq_chip, &mc13xxx->irq_data); in mc13xxx_common_init()
461 mutex_init(&mc13xxx->lock); in mc13xxx_common_init()
463 if (mc13xxx_probe_flags_dt(mc13xxx) < 0 && pdata) in mc13xxx_common_init()
464 mc13xxx->flags = pdata->flags; in mc13xxx_common_init()
467 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-regulator", in mc13xxx_common_init()
469 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led", in mc13xxx_common_init()
471 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-pwrbutton", in mc13xxx_common_init()
473 if (mc13xxx->flags & MC13XXX_USE_CODEC) in mc13xxx_common_init()
474 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-codec", in mc13xxx_common_init()
476 if (mc13xxx->flags & MC13XXX_USE_TOUCHSCREEN) in mc13xxx_common_init()
477 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-ts", in mc13xxx_common_init()
480 mc13xxx_add_subdevice(mc13xxx, "%s-regulator"); in mc13xxx_common_init()
481 mc13xxx_add_subdevice(mc13xxx, "%s-led"); in mc13xxx_common_init()
482 mc13xxx_add_subdevice(mc13xxx, "%s-pwrbutton"); in mc13xxx_common_init()
483 if (mc13xxx->flags & MC13XXX_USE_CODEC) in mc13xxx_common_init()
484 mc13xxx_add_subdevice(mc13xxx, "%s-codec"); in mc13xxx_common_init()
485 if (mc13xxx->flags & MC13XXX_USE_TOUCHSCREEN) in mc13xxx_common_init()
486 mc13xxx_add_subdevice(mc13xxx, "%s-ts"); in mc13xxx_common_init()
489 if (mc13xxx->flags & MC13XXX_USE_ADC) in mc13xxx_common_init()
490 mc13xxx_add_subdevice(mc13xxx, "%s-adc"); in mc13xxx_common_init()
492 if (mc13xxx->flags & MC13XXX_USE_RTC) in mc13xxx_common_init()
493 mc13xxx_add_subdevice(mc13xxx, "%s-rtc"); in mc13xxx_common_init()
501 struct mc13xxx *mc13xxx = dev_get_drvdata(dev); in mc13xxx_common_exit() local
504 regmap_del_irq_chip(mc13xxx->irq, mc13xxx->irq_data); in mc13xxx_common_exit()
505 mutex_destroy(&mc13xxx->lock); in mc13xxx_common_exit()