Lines Matching +full:ac +full:- +full:detect +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) ST-Ericsson SA 2010
22 #include <linux/mfd/abx500/ab8500-bm.h>
23 #include <linux/mfd/dbx500-prcmu.h>
155 0, 1, 2, 3, 4, -1, -1, -1, -1, 11, 18, 19, 20, 21, 12, 13, 24, 5, 22,
172 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); in ab8500_prcmu_write()
184 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); in ab8500_prcmu_write_masked()
195 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); in ab8500_prcmu_read()
206 return -EINVAL; in ab8500_get_chip_id()
207 ab8500 = dev_get_drvdata(dev->parent); in ab8500_get_chip_id()
208 return ab8500 ? (int)ab8500->chip_id : -EINVAL; in ab8500_get_chip_id()
221 dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data); in set_register_interruptible()
223 mutex_lock(&ab8500->lock); in set_register_interruptible()
225 ret = ab8500->write(ab8500, addr, data); in set_register_interruptible()
227 dev_err(ab8500->dev, "failed to write reg %#x: %d\n", in set_register_interruptible()
229 mutex_unlock(&ab8500->lock); in set_register_interruptible()
238 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); in ab8500_set_register()
240 atomic_inc(&ab8500->transfer_ongoing); in ab8500_set_register()
242 atomic_dec(&ab8500->transfer_ongoing); in ab8500_set_register()
252 mutex_lock(&ab8500->lock); in get_register_interruptible()
254 ret = ab8500->read(ab8500, addr); in get_register_interruptible()
256 dev_err(ab8500->dev, "failed to read reg %#x: %d\n", in get_register_interruptible()
261 mutex_unlock(&ab8500->lock); in get_register_interruptible()
262 dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret); in get_register_interruptible()
271 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); in ab8500_get_register()
273 atomic_inc(&ab8500->transfer_ongoing); in ab8500_get_register()
275 atomic_dec(&ab8500->transfer_ongoing); in ab8500_get_register()
285 mutex_lock(&ab8500->lock); in mask_and_set_register_interruptible()
287 if (ab8500->write_masked == NULL) { in mask_and_set_register_interruptible()
290 ret = ab8500->read(ab8500, addr); in mask_and_set_register_interruptible()
292 dev_err(ab8500->dev, "failed to read reg %#x: %d\n", in mask_and_set_register_interruptible()
300 ret = ab8500->write(ab8500, addr, data); in mask_and_set_register_interruptible()
302 dev_err(ab8500->dev, "failed to write reg %#x: %d\n", in mask_and_set_register_interruptible()
305 dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr, in mask_and_set_register_interruptible()
309 ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues); in mask_and_set_register_interruptible()
311 dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr, in mask_and_set_register_interruptible()
314 mutex_unlock(&ab8500->lock); in mask_and_set_register_interruptible()
322 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); in ab8500_mask_and_set_register()
324 atomic_inc(&ab8500->transfer_ongoing); in ab8500_mask_and_set_register()
327 atomic_dec(&ab8500->transfer_ongoing); in ab8500_mask_and_set_register()
347 mutex_lock(&ab8500->irq_lock); in ab8500_irq_lock()
348 atomic_inc(&ab8500->transfer_ongoing); in ab8500_irq_lock()
356 for (i = 0; i < ab8500->mask_size; i++) { in ab8500_irq_sync_unlock()
357 u8 old = ab8500->oldmask[i]; in ab8500_irq_sync_unlock()
358 u8 new = ab8500->mask[i]; in ab8500_irq_sync_unlock()
368 if (ab8500->irq_reg_offset[i] == 11 && in ab8500_irq_sync_unlock()
372 if (ab8500->irq_reg_offset[i] < 0) in ab8500_irq_sync_unlock()
375 ab8500->oldmask[i] = new; in ab8500_irq_sync_unlock()
377 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i]; in ab8500_irq_sync_unlock()
380 atomic_dec(&ab8500->transfer_ongoing); in ab8500_irq_sync_unlock()
381 mutex_unlock(&ab8500->irq_lock); in ab8500_irq_sync_unlock()
387 int offset = data->hwirq; in ab8500_irq_mask()
391 ab8500->mask[index] |= mask; in ab8500_irq_mask()
393 /* The AB8500 GPIOs have two interrupts each (rising & falling). */ in ab8500_irq_mask()
395 ab8500->mask[index + 2] |= mask; in ab8500_irq_mask()
397 ab8500->mask[index + 1] |= mask; in ab8500_irq_mask()
400 ab8500->mask[index] |= (mask << 1); in ab8500_irq_mask()
407 int offset = data->hwirq; in ab8500_irq_unmask()
412 ab8500->mask[index] &= ~mask; in ab8500_irq_unmask()
414 /* The AB8500 GPIOs have two interrupts each (rising & falling). */ in ab8500_irq_unmask()
417 ab8500->mask[index + 2] &= ~mask; in ab8500_irq_unmask()
420 ab8500->mask[index + 1] &= ~mask; in ab8500_irq_unmask()
424 ab8500->mask[index] &= ~(mask << 1); in ab8500_irq_unmask()
426 ab8500->mask[index] &= ~mask; in ab8500_irq_unmask()
429 ab8500->mask[index] &= ~mask; in ab8500_irq_unmask()
465 for (i = 0; i < ab8500->mask_size; i++) in ab8500_handle_hierarchical_line()
466 if (ab8500->irq_reg_offset[i] == latch_offset) in ab8500_handle_hierarchical_line()
469 if (i >= ab8500->mask_size) { in ab8500_handle_hierarchical_line()
470 dev_err(ab8500->dev, "Register offset 0x%2x not declared\n", in ab8500_handle_hierarchical_line()
472 return -ENXIO; in ab8500_handle_hierarchical_line()
476 latch_val &= ~ab8500->mask[i]; in ab8500_handle_hierarchical_line()
490 line -= 16; in ab8500_handle_hierarchical_line()
492 line -= 8; in ab8500_handle_hierarchical_line()
496 handle_nested_irq(irq_create_mapping(ab8500->domain, line)); in ab8500_handle_hierarchical_line()
537 dev_vdbg(ab8500->dev, "interrupt\n"); in ab8500_hierarchical_irq()
540 for (i = 0; i < (ab8500->it_latchhier_num); i++) { in ab8500_hierarchical_irq()
559 struct ab8500 *ab8500 = d->host_data; in ab8500_irq_map()
562 return -EINVAL; in ab8500_irq_map()
591 /* If ->irq_base is zero this will give a linear mapping */ in ab8500_irq_init()
592 ab8500->domain = irq_domain_add_simple(ab8500->dev->of_node, in ab8500_irq_init()
596 if (!ab8500->domain) { in ab8500_irq_init()
597 dev_err(ab8500->dev, "Failed to create irqdomain\n"); in ab8500_irq_init()
598 return -ENODEV; in ab8500_irq_init()
606 if (atomic_read(&ab8500->transfer_ongoing)) in ab8500_suspend()
607 return -EINVAL; in ab8500_suspend()
613 OF_MFD_CELL("ab8500-charger", NULL, &ab8500_bm_data,
614 sizeof(ab8500_bm_data), 0, "stericsson,ab8500-charger"),
615 OF_MFD_CELL("ab8500-btemp", NULL, &ab8500_bm_data,
616 sizeof(ab8500_bm_data), 0, "stericsson,ab8500-btemp"),
617 OF_MFD_CELL("ab8500-fg", NULL, &ab8500_bm_data,
618 sizeof(ab8500_bm_data), 0, "stericsson,ab8500-fg"),
619 OF_MFD_CELL("ab8500-chargalg", NULL, &ab8500_bm_data,
620 sizeof(ab8500_bm_data), 0, "stericsson,ab8500-chargalg"),
625 OF_MFD_CELL("ab8500-debug",
626 NULL, NULL, 0, 0, "stericsson,ab8500-debug"),
628 OF_MFD_CELL("ab8500-sysctrl",
629 NULL, NULL, 0, 0, "stericsson,ab8500-sysctrl"),
630 OF_MFD_CELL("ab8500-ext-regulator",
631 NULL, NULL, 0, 0, "stericsson,ab8500-ext-regulator"),
632 OF_MFD_CELL("ab8500-regulator",
633 NULL, NULL, 0, 0, "stericsson,ab8500-regulator"),
634 OF_MFD_CELL("ab8500-clk",
635 NULL, NULL, 0, 0, "stericsson,ab8500-clk"),
636 OF_MFD_CELL("ab8500-gpadc",
637 NULL, NULL, 0, 0, "stericsson,ab8500-gpadc"),
638 OF_MFD_CELL("ab8500-rtc",
639 NULL, NULL, 0, 0, "stericsson,ab8500-rtc"),
640 OF_MFD_CELL("ab8500-acc-det",
641 NULL, NULL, 0, 0, "stericsson,ab8500-acc-det"),
642 OF_MFD_CELL("ab8500-poweron-key",
643 NULL, NULL, 0, 0, "stericsson,ab8500-poweron-key"),
644 OF_MFD_CELL("ab8500-pwm",
645 NULL, NULL, 0, 1, "stericsson,ab8500-pwm"),
646 OF_MFD_CELL("ab8500-pwm",
647 NULL, NULL, 0, 2, "stericsson,ab8500-pwm"),
648 OF_MFD_CELL("ab8500-pwm",
649 NULL, NULL, 0, 3, "stericsson,ab8500-pwm"),
650 OF_MFD_CELL("ab8500-denc",
651 NULL, NULL, 0, 0, "stericsson,ab8500-denc"),
652 OF_MFD_CELL("pinctrl-ab8500",
653 NULL, NULL, 0, 0, "stericsson,ab8500-gpio"),
654 OF_MFD_CELL("abx500-temp",
655 NULL, NULL, 0, 0, "stericsson,abx500-temp"),
656 OF_MFD_CELL("ab8500-usb",
657 NULL, NULL, 0, 0, "stericsson,ab8500-usb"),
658 OF_MFD_CELL("ab8500-codec",
659 NULL, NULL, 0, 0, "stericsson,ab8500-codec"),
665 .name = "ab8500-debug",
669 .name = "ab8500-sysctrl",
672 .name = "ab8500-ext-regulator",
675 .name = "ab8500-regulator",
678 .name = "abx500-clk",
679 .of_compatible = "stericsson,abx500-clk",
682 .name = "ab8500-gpadc",
683 .of_compatible = "stericsson,ab8500-gpadc",
686 .name = "ab8500-rtc",
689 .name = "ab8500-acc-det",
692 .name = "ab8500-poweron-key",
695 .name = "ab8500-pwm",
699 .name = "abx500-temp",
702 .name = "pinctrl-ab9540",
703 .of_compatible = "stericsson,ab9540-gpio",
706 .name = "ab9540-usb",
709 .name = "ab9540-codec",
712 .name = "ab-iddet",
720 .name = "ab8500-debug",
721 .of_compatible = "stericsson,ab8500-debug",
725 .name = "ab8500-sysctrl",
726 .of_compatible = "stericsson,ab8500-sysctrl",
729 .name = "ab8500-regulator",
730 .of_compatible = "stericsson,ab8505-regulator",
733 .name = "abx500-clk",
734 .of_compatible = "stericsson,ab8500-clk",
737 .name = "ab8500-gpadc",
738 .of_compatible = "stericsson,ab8500-gpadc",
741 .name = "ab8500-rtc",
742 .of_compatible = "stericsson,ab8500-rtc",
745 .name = "ab8500-acc-det",
746 .of_compatible = "stericsson,ab8500-acc-det",
749 .name = "ab8500-poweron-key",
750 .of_compatible = "stericsson,ab8500-poweron-key",
753 .name = "ab8500-pwm",
754 .of_compatible = "stericsson,ab8500-pwm",
758 .name = "pinctrl-ab8505",
759 .of_compatible = "stericsson,ab8505-gpio",
762 .name = "ab8500-usb",
763 .of_compatible = "stericsson,ab8500-usb",
766 .name = "ab8500-codec",
767 .of_compatible = "stericsson,ab8500-codec",
770 .name = "ab-iddet",
777 .name = "ab8500-debug",
781 .name = "ab8500-sysctrl",
784 .name = "ab8500-ext-regulator",
787 .name = "ab8500-regulator",
790 .name = "abx500-clk",
791 .of_compatible = "stericsson,abx500-clk",
794 .name = "ab8500-gpadc",
795 .of_compatible = "stericsson,ab8500-gpadc",
798 .name = "ab8500-acc-det",
801 .name = "ab8500-poweron-key",
804 .name = "ab8500-pwm",
808 .name = "abx500-temp",
811 .name = "pinctrl-ab8540",
814 .name = "ab8540-usb",
817 .name = "ab8540-codec",
820 .name = "ab-iddet",
826 .name = "ab8500-rtc",
827 .of_compatible = "stericsson,ab8500-rtc",
833 .name = "ab8540-rtc",
834 .of_compatible = "stericsson,ab8540-rtc",
845 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL); in show_chip_id()
909 * the device is rebooted with AC/USB charger connected. Due to in show_turn_on_status()
911 * only mode. Read the AC/USB status register to detect the charger in show_turn_on_status()
982 dev_info(ab8500->dev, in store_ab9540_dbbrstn()
1046 "Main Charger Detect", in ab8500_probe()
1047 "Vbus Detect (USB)", in ab8500_probe()
1048 "USB ID Detect", in ab8500_probe()
1049 "UART Factory Mode Detect"}; in ab8500_probe()
1052 struct device_node *np = pdev->dev.of_node; in ab8500_probe()
1059 ab8500 = devm_kzalloc(&pdev->dev, sizeof(*ab8500), GFP_KERNEL); in ab8500_probe()
1061 return -ENOMEM; in ab8500_probe()
1063 ab8500->dev = &pdev->dev; in ab8500_probe()
1067 dev_err(&pdev->dev, "no IRQ resource\n"); in ab8500_probe()
1068 return -ENODEV; in ab8500_probe()
1071 ab8500->irq = resource->start; in ab8500_probe()
1073 ab8500->read = ab8500_prcmu_read; in ab8500_probe()
1074 ab8500->write = ab8500_prcmu_write; in ab8500_probe()
1075 ab8500->write_masked = ab8500_prcmu_write_masked; in ab8500_probe()
1077 mutex_init(&ab8500->lock); in ab8500_probe()
1078 mutex_init(&ab8500->irq_lock); in ab8500_probe()
1079 atomic_set(&ab8500->transfer_ongoing, 0); in ab8500_probe()
1084 version = platid->driver_data; in ab8500_probe()
1087 ab8500->version = version; in ab8500_probe()
1092 dev_err(&pdev->dev, "could not probe HW\n"); in ab8500_probe()
1096 ab8500->version = value; in ab8500_probe()
1104 ab8500->chip_id = value; in ab8500_probe()
1106 dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n", in ab8500_probe()
1107 ab8500_version_str[ab8500->version], in ab8500_probe()
1108 ab8500->chip_id >> 4, in ab8500_probe()
1109 ab8500->chip_id & 0x0F); in ab8500_probe()
1113 ab8500->mask_size = AB8540_NUM_IRQ_REGS; in ab8500_probe()
1114 ab8500->irq_reg_offset = ab8540_irq_regoffset; in ab8500_probe()
1115 ab8500->it_latchhier_num = AB8540_IT_LATCHHIER_NUM; in ab8500_probe()
1118 ab8500->mask_size = AB9540_NUM_IRQ_REGS; in ab8500_probe()
1119 ab8500->irq_reg_offset = ab9540_irq_regoffset; in ab8500_probe()
1120 ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM; in ab8500_probe()
1122 ab8500->mask_size = AB8500_NUM_IRQ_REGS; in ab8500_probe()
1123 ab8500->irq_reg_offset = ab8500_irq_regoffset; in ab8500_probe()
1124 ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM; in ab8500_probe()
1126 ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size, in ab8500_probe()
1128 if (!ab8500->mask) in ab8500_probe()
1129 return -ENOMEM; in ab8500_probe()
1130 ab8500->oldmask = devm_kzalloc(&pdev->dev, ab8500->mask_size, in ab8500_probe()
1132 if (!ab8500->oldmask) in ab8500_probe()
1133 return -ENOMEM; in ab8500_probe()
1151 dev_info(ab8500->dev, "switch off cause(s) (%#x): ", value); in ab8500_probe()
1168 dev_info(ab8500->dev, "turn on reason(s) (%#x): ", value); in ab8500_probe()
1192 for (i = 0; i < ab8500->mask_size; i++) { in ab8500_probe()
1197 if (ab8500->irq_reg_offset[i] == 11 && in ab8500_probe()
1201 if (ab8500->irq_reg_offset[i] < 0) in ab8500_probe()
1205 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i], in ab8500_probe()
1208 AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff); in ab8500_probe()
1211 ret = abx500_register_ops(ab8500->dev, &ab8500_ops); in ab8500_probe()
1215 for (i = 0; i < ab8500->mask_size; i++) in ab8500_probe()
1216 ab8500->mask[i] = ab8500->oldmask[i] = 0xff; in ab8500_probe()
1222 ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL, in ab8500_probe()
1230 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs, in ab8500_probe()
1232 0, ab8500->domain); in ab8500_probe()
1234 ret = mfd_add_devices(ab8500->dev, 0, ab8540_devs, in ab8500_probe()
1236 0, ab8500->domain); in ab8500_probe()
1241 ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut1_devs, in ab8500_probe()
1243 0, ab8500->domain); in ab8500_probe()
1245 ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut2_devs, in ab8500_probe()
1247 0, ab8500->domain); in ab8500_probe()
1249 ret = mfd_add_devices(ab8500->dev, 0, ab8505_devs, in ab8500_probe()
1251 0, ab8500->domain); in ab8500_probe()
1253 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs, in ab8500_probe()
1255 0, ab8500->domain); in ab8500_probe()
1261 ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs, in ab8500_probe()
1263 0, ab8500->domain); in ab8500_probe()
1265 dev_err(ab8500->dev, "error adding bm devices\n"); in ab8500_probe()
1269 ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500)) in ab8500_probe()
1270 ret = sysfs_create_group(&ab8500->dev->kobj, in ab8500_probe()
1273 ret = sysfs_create_group(&ab8500->dev->kobj, in ab8500_probe()
1277 ab8500->chip_id >= AB8500_CUT2P0) in ab8500_probe()
1278 ret = sysfs_create_group(&ab8500->dev->kobj, in ab8500_probe()
1282 dev_err(ab8500->dev, "error creating sysfs entries\n"); in ab8500_probe()
1288 { "ab8500-core", AB8500_VERSION_AB8500 },
1289 { "ab8505-core", AB8500_VERSION_AB8505 },
1290 { "ab9540-i2c", AB8500_VERSION_AB9540 },
1291 { "ab8540-i2c", AB8500_VERSION_AB8540 },
1297 .name = "ab8500-core",