Lines Matching +full:pmic +full:- +full:specific

1 // SPDX-License-Identifier: GPL-2.0-only
3 * MediaTek MT6359 PMIC AUXADC IIO driver
24 #include <dt-bindings/iio/adc/mediatek,mt6357-auxadc.h>
25 #include <dt-bindings/iio/adc/mediatek,mt6358-auxadc.h>
26 #include <dt-bindings/iio/adc/mediatek,mt6359-auxadc.h>
35 /* For PMIC_RG_RESET_VAL and MT6358_IMP0_CLEAR, the bits specific purpose is unknown. */
85 * struct mt6359_auxadc - Main driver structure
87 * @regmap: Regmap from SoC PMIC Wrapper
88 * @chip_info: PMIC specific chip info
101 * struct mtk_pmic_auxadc_chan - PMIC AUXADC channel data
115 * struct mtk_pmic_auxadc_info - PMIC specific chip info
116 * @model_name: PMIC model name
119 * @desc: PMIC AUXADC channel data
120 * @regs: List of PMIC specific registers
307 const struct mtk_pmic_auxadc_info *cinfo = adc_dev->chip_info; in mt6358_stop_imp_conv()
308 struct regmap *regmap = adc_dev->regmap; in mt6358_stop_imp_conv()
310 regmap_set_bits(regmap, cinfo->regs[PMIC_AUXADC_IMP0], MT6358_IMP0_CLEAR); in mt6358_stop_imp_conv()
311 regmap_clear_bits(regmap, cinfo->regs[PMIC_AUXADC_IMP0], MT6358_IMP0_CLEAR); in mt6358_stop_imp_conv()
312 regmap_clear_bits(regmap, cinfo->regs[PMIC_AUXADC_IMP1], MT6358_IMP1_AUTOREPEAT_EN); in mt6358_stop_imp_conv()
313 regmap_clear_bits(regmap, cinfo->regs[PMIC_AUXADC_DCM_CON], MT6358_DCM_CK_SW_EN); in mt6358_stop_imp_conv()
318 const struct mtk_pmic_auxadc_info *cinfo = adc_dev->chip_info; in mt6358_start_imp_conv()
319 struct regmap *regmap = adc_dev->regmap; in mt6358_start_imp_conv()
323 regmap_set_bits(regmap, cinfo->regs[PMIC_AUXADC_DCM_CON], MT6358_DCM_CK_SW_EN); in mt6358_start_imp_conv()
324 regmap_set_bits(regmap, cinfo->regs[PMIC_AUXADC_IMP1], MT6358_IMP1_AUTOREPEAT_EN); in mt6358_start_imp_conv()
326 ret = regmap_read_poll_timeout(adc_dev->regmap, cinfo->regs[PMIC_AUXADC_IMP0], in mt6358_start_imp_conv()
339 const struct mtk_pmic_auxadc_info *cinfo = adc_dev->chip_info; in mt6358_read_imp()
340 struct regmap *regmap = adc_dev->regmap; in mt6358_read_imp()
341 u16 reg_adc0 = cinfo->regs[PMIC_AUXADC_ADC0]; in mt6358_read_imp()
350 regmap_read(regmap, reg_adc0 + (cinfo->imp_adc_num << 1), &val_v); in mt6358_read_imp()
364 const struct mtk_pmic_auxadc_info *cinfo = adc_dev->chip_info; in mt6359_read_imp()
365 struct regmap *regmap = adc_dev->regmap; in mt6359_read_imp()
370 regmap_write(regmap, cinfo->regs[PMIC_AUXADC_IMP0], MT6359_IMP0_CONV_EN); in mt6359_read_imp()
371 ret = regmap_read_poll_timeout(regmap, cinfo->regs[PMIC_AUXADC_IMP1], in mt6359_read_imp()
376 regmap_write(regmap, cinfo->regs[PMIC_AUXADC_IMP0], 0); in mt6359_read_imp()
383 ret = regmap_read(regmap, cinfo->regs[PMIC_AUXADC_IMP3], &val_v); in mt6359_read_imp()
387 ret = regmap_read(regmap, cinfo->regs[PMIC_FGADC_R_CON0], &val_i); in mt6359_read_imp()
431 const struct mtk_pmic_auxadc_info *cinfo = adc_dev->chip_info; in mt6359_auxadc_reset()
432 struct regmap *regmap = adc_dev->regmap; in mt6359_auxadc_reset()
435 if (cinfo->sec_unlock_key) in mt6359_auxadc_reset()
436 regmap_write(regmap, cinfo->regs[PMIC_HK_TOP_WKEY], cinfo->sec_unlock_key); in mt6359_auxadc_reset()
439 regmap_set_bits(regmap, cinfo->regs[PMIC_HK_TOP_RST_CON0], PMIC_RG_RESET_VAL); in mt6359_auxadc_reset()
441 /* De-assert ADC reset. No wait required, as pwrap takes care of that for us. */ in mt6359_auxadc_reset()
442 regmap_clear_bits(regmap, cinfo->regs[PMIC_HK_TOP_RST_CON0], PMIC_RG_RESET_VAL); in mt6359_auxadc_reset()
445 if (cinfo->sec_unlock_key) in mt6359_auxadc_reset()
446 regmap_write(regmap, cinfo->regs[PMIC_HK_TOP_WKEY], 0); in mt6359_auxadc_reset()
452 const struct mtk_pmic_auxadc_info *cinfo = adc_dev->chip_info; in mt6359_auxadc_read_adc()
453 const struct mtk_pmic_auxadc_chan *desc = &cinfo->desc[chan->scan_index]; in mt6359_auxadc_read_adc()
454 struct regmap *regmap = adc_dev->regmap; in mt6359_auxadc_read_adc()
459 ret = regmap_write(regmap, cinfo->regs[desc->req_idx], desc->req_mask); in mt6359_auxadc_read_adc()
464 fsleep(desc->num_samples * AUXADC_AVG_TIME_US); in mt6359_auxadc_read_adc()
467 cinfo->regs[PMIC_AUXADC_ADC0] + (chan->address << 1), in mt6359_auxadc_read_adc()
474 regmap_write(regmap, cinfo->regs[desc->req_idx], 0); in mt6359_auxadc_read_adc()
476 *out = val & GENMASK(chan->scan_type.realbits - 1, 0); in mt6359_auxadc_read_adc()
483 return sysfs_emit(label, "%s\n", chan->datasheet_name); in mt6359_auxadc_read_label()
491 const struct mtk_pmic_auxadc_info *cinfo = adc_dev->chip_info; in mt6359_auxadc_read_raw()
492 const struct mtk_pmic_auxadc_chan *desc = &cinfo->desc[chan->scan_index]; in mt6359_auxadc_read_raw()
496 *val = desc->r_ratio.numerator * AUXADC_VOLT_FULL; in mt6359_auxadc_read_raw()
498 if (desc->r_ratio.denominator > 1) { in mt6359_auxadc_read_raw()
499 *val2 = desc->r_ratio.denominator; in mt6359_auxadc_read_raw()
506 scoped_guard(mutex, &adc_dev->lock) { in mt6359_auxadc_read_raw()
507 switch (chan->scan_index) { in mt6359_auxadc_read_raw()
509 ret = adc_dev->chip_info->read_imp(adc_dev, NULL, val); in mt6359_auxadc_read_raw()
512 ret = adc_dev->chip_info->read_imp(adc_dev, val, NULL); in mt6359_auxadc_read_raw()
525 if (ret == -ETIMEDOUT) { in mt6359_auxadc_read_raw()
526 if (adc_dev->timed_out) { in mt6359_auxadc_read_raw()
527 dev_warn(adc_dev->dev, "Resetting stuck ADC!\r\n"); in mt6359_auxadc_read_raw()
530 adc_dev->timed_out = true; in mt6359_auxadc_read_raw()
534 adc_dev->timed_out = false; in mt6359_auxadc_read_raw()
546 struct device *dev = &pdev->dev; in mt6359_auxadc_probe()
547 struct device *mt6397_mfd_dev = dev->parent; in mt6359_auxadc_probe()
553 /* Regmap is from SoC PMIC Wrapper, parent of the mt6397 MFD */ in mt6359_auxadc_probe()
554 regmap = dev_get_regmap(mt6397_mfd_dev->parent, NULL); in mt6359_auxadc_probe()
556 return dev_err_probe(dev, -ENODEV, "Failed to get regmap\n"); in mt6359_auxadc_probe()
560 return -ENOMEM; in mt6359_auxadc_probe()
563 adc_dev->regmap = regmap; in mt6359_auxadc_probe()
564 adc_dev->dev = dev; in mt6359_auxadc_probe()
566 adc_dev->chip_info = device_get_match_data(dev); in mt6359_auxadc_probe()
567 if (!adc_dev->chip_info) in mt6359_auxadc_probe()
568 return -EINVAL; in mt6359_auxadc_probe()
570 mutex_init(&adc_dev->lock); in mt6359_auxadc_probe()
574 indio_dev->name = adc_dev->chip_info->model_name; in mt6359_auxadc_probe()
575 indio_dev->info = &mt6359_auxadc_iio_info; in mt6359_auxadc_probe()
576 indio_dev->modes = INDIO_DIRECT_MODE; in mt6359_auxadc_probe()
577 indio_dev->channels = adc_dev->chip_info->channels; in mt6359_auxadc_probe()
578 indio_dev->num_channels = adc_dev->chip_info->num_channels; in mt6359_auxadc_probe()
588 { .compatible = "mediatek,mt6357-auxadc", .data = &mt6357_chip_info },
589 { .compatible = "mediatek,mt6358-auxadc", .data = &mt6358_chip_info },
590 { .compatible = "mediatek,mt6359-auxadc", .data = &mt6359_chip_info },
597 .name = "mt6359-auxadc",
606 MODULE_DESCRIPTION("MediaTek MT6359 PMIC AUXADC Driver");