Lines Matching +full:child +full:- +full:interrupt +full:- +full:base

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * twl_core.c - driver for TWL4030/TWL5030/TWL60X0/TPS659x0 PM
6 * Copyright (C) 2005-2006 Texas Instruments, Inc.
8 * Modifications to defer interrupt handling to a kernel thread:
37 #include <linux/mfd/twl4030-audio.h>
39 #include "twl-core.h"
42 * The TWL4030 "Triton 2" is one of a family of a multi-function "Power
45 * often at around 3 Mbit/sec, including for interrupt handling.
50 * FIXME this driver currently requires use of the first interrupt line
58 /* Base Address defns for twl4030_map[] */
60 /* subchip/slave 0 - USB ID */
63 /* subchip/slave 1 - AUD ID */
70 /* subchip/slave 2 - AUX ID */
83 /* subchip/slave 3 - POWER ID */
98 /* subchip/slave 0 0x48 - POWER */
106 /* subchip/slave 1 0x49 - FEATURE */
117 /* subchip/slave 2 0x4A - DFT */
120 /* subchip/slave 3 0x4B - AUDIO */
135 /*----------------------------------------------------------------------*/
143 /* mapping the module id to slave id and base address */
146 unsigned char base; /* base address */ member
261 /* 0x40 - 0x42 Unused */
379 /*----------------------------------------------------------------------*/
401 return twl_priv ? twl_priv->twl_id : 0; in twl_rev()
406 * twl_get_regmap - Get the regmap associated with the given module
416 if (unlikely(!twl_priv || !twl_priv->ready)) { in twl_get_regmap()
425 sid = twl_priv->twl_map[mod_no].sid; in twl_get_regmap()
426 twl = &twl_priv->twl_modules[sid]; in twl_get_regmap()
428 return twl->regmap; in twl_get_regmap()
432 * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0
446 return -EPERM; in twl_i2c_write()
448 ret = regmap_bulk_write(regmap, twl_priv->twl_map[mod_no].base + reg, in twl_i2c_write()
460 * twl_i2c_read - Reads a n bit register in TWL4030/TWL5030/TWL60X0
474 return -EPERM; in twl_i2c_read()
476 ret = regmap_bulk_read(regmap, twl_priv->twl_map[mod_no].base + reg, in twl_i2c_read()
488 * twl_set_regcache_bypass - Configure the regcache bypass for the regmap associated
500 return -EPERM; in twl_set_regcache_bypass()
508 /*----------------------------------------------------------------------*/
511 * twl_read_idcode_register - API to read the IDCODE register.
522 pr_err("TWL4030 Unable to unlock IDCODE registers -%d\n", err); in twl_read_idcode_register()
526 err = twl_i2c_read(TWL4030_MODULE_INTBR, (u8 *)(&twl_priv->twl_idcode), in twl_read_idcode_register()
529 pr_err("TWL4030: unable to read IDCODE -%d\n", err); in twl_read_idcode_register()
535 pr_err("TWL4030 Unable to relock IDCODE registers -%d\n", err); in twl_read_idcode_register()
541 * twl_get_type - API to get TWL Si type.
547 return TWL_SIL_TYPE(twl_priv->twl_idcode); in twl_get_type()
552 * twl_get_version - API to get TWL Si version.
558 return TWL_SIL_REV(twl_priv->twl_idcode); in twl_get_version()
563 * twl_get_hfclk_rate - API to get TWL external HFCLK clock rate.
586 rate = -EINVAL; in twl_get_hfclk_rate()
605 return ERR_PTR(-EPERM); in add_numbered_child()
607 sid = twl_priv->twl_map[mod_no].sid; in add_numbered_child()
608 twl = &twl_priv->twl_modules[sid]; in add_numbered_child()
612 return ERR_PTR(-ENOMEM); in add_numbered_child()
614 pdev->dev.parent = &twl->client->dev; in add_numbered_child()
619 dev_dbg(&pdev->dev, "can't add platform_data\n"); in add_numbered_child()
632 dev_dbg(&pdev->dev, "can't add irqs\n"); in add_numbered_child()
641 device_init_wakeup(&pdev->dev, can_wakeup); in add_numbered_child()
643 return &pdev->dev; in add_numbered_child()
647 dev_err(&twl->client->dev, "failed to add device %s\n", name); in add_numbered_child()
655 return add_numbered_child(mod_no, name, -1, pdata, pdata_len, in add_child()
671 pdata->consumer_supplies = consumers; in add_regulator_linked()
672 pdata->num_consumer_supplies = num_consumers; in add_regulator_linked()
675 if (pdata->driver_data) { in add_regulator_linked()
678 tmp = pdata->driver_data; in add_regulator_linked()
679 tmp->features |= features; in add_regulator_linked()
686 pdata->driver_data = &drv_data; in add_regulator_linked()
702 * NOTE: We know the first 8 IRQs after pdata->base_irq are
711 struct device *child; in add_children() local
713 if (IS_ENABLED(CONFIG_GPIO_TWL4030) && pdata->gpio) { in add_children()
714 child = add_child(TWL4030_MODULE_GPIO, "twl4030_gpio", in add_children()
715 pdata->gpio, sizeof(*pdata->gpio), in add_children()
717 if (IS_ERR(child)) in add_children()
718 return PTR_ERR(child); in add_children()
721 if (IS_ENABLED(CONFIG_KEYBOARD_TWL4030) && pdata->keypad) { in add_children()
722 child = add_child(TWL4030_MODULE_KEYPAD, "twl4030_keypad", in add_children()
723 pdata->keypad, sizeof(*pdata->keypad), in add_children()
725 if (IS_ERR(child)) in add_children()
726 return PTR_ERR(child); in add_children()
729 if (IS_ENABLED(CONFIG_TWL4030_MADC) && pdata->madc && in add_children()
731 child = add_child(TWL4030_MODULE_MADC, "twl4030_madc", in add_children()
732 pdata->madc, sizeof(*pdata->madc), in add_children()
734 if (IS_ERR(child)) in add_children()
735 return PTR_ERR(child); in add_children()
746 child = add_child(TWL_MODULE_RTC, "twl_rtc", NULL, 0, in add_children()
748 if (IS_ERR(child)) in add_children()
749 return PTR_ERR(child); in add_children()
753 child = add_child(TWL_MODULE_PWM, "twl-pwm", NULL, 0, in add_children()
755 if (IS_ERR(child)) in add_children()
756 return PTR_ERR(child); in add_children()
760 child = add_child(TWL_MODULE_LED, "twl-pwmled", NULL, 0, in add_children()
762 if (IS_ERR(child)) in add_children()
763 return PTR_ERR(child); in add_children()
766 if (IS_ENABLED(CONFIG_TWL4030_USB) && pdata->usb && in add_children()
791 child = add_regulator_linked(TWL4030_REG_VUSB1V5, in add_children()
794 if (IS_ERR(child)) in add_children()
795 return PTR_ERR(child); in add_children()
797 child = add_regulator_linked(TWL4030_REG_VUSB1V8, in add_children()
800 if (IS_ERR(child)) in add_children()
801 return PTR_ERR(child); in add_children()
803 child = add_regulator_linked(TWL4030_REG_VUSB3V1, in add_children()
806 if (IS_ERR(child)) in add_children()
807 return PTR_ERR(child); in add_children()
811 child = add_child(TWL_MODULE_USB, "twl4030_usb", in add_children()
812 pdata->usb, sizeof(*pdata->usb), true, in add_children()
817 if (IS_ERR(child)) in add_children()
818 return PTR_ERR(child); in add_children()
821 if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && child) { in add_children()
822 usb1v5.dev_name = dev_name(child); in add_children()
823 usb1v8.dev_name = dev_name(child); in add_children()
824 usb3v1.dev_name = dev_name(child); in add_children()
829 child = add_child(TWL_MODULE_PM_RECEIVER, "twl4030_wdt", NULL, in add_children()
831 if (IS_ERR(child)) in add_children()
832 return PTR_ERR(child); in add_children()
836 child = add_child(TWL_MODULE_PM_MASTER, "twl4030_pwrbutton", in add_children()
838 if (IS_ERR(child)) in add_children()
839 return PTR_ERR(child); in add_children()
842 if (IS_ENABLED(CONFIG_MFD_TWL4030_AUDIO) && pdata->audio && in add_children()
844 child = add_child(TWL4030_MODULE_AUDIO_VOICE, "twl4030-audio", in add_children()
845 pdata->audio, sizeof(*pdata->audio), in add_children()
847 if (IS_ERR(child)) in add_children()
848 return PTR_ERR(child); in add_children()
853 child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1, in add_children()
855 if (IS_ERR(child)) in add_children()
856 return PTR_ERR(child); in add_children()
858 child = add_regulator(TWL4030_REG_VIO, pdata->vio, in add_children()
860 if (IS_ERR(child)) in add_children()
861 return PTR_ERR(child); in add_children()
863 child = add_regulator(TWL4030_REG_VDD1, pdata->vdd1, in add_children()
865 if (IS_ERR(child)) in add_children()
866 return PTR_ERR(child); in add_children()
868 child = add_regulator(TWL4030_REG_VDD2, pdata->vdd2, in add_children()
870 if (IS_ERR(child)) in add_children()
871 return PTR_ERR(child); in add_children()
873 child = add_regulator(TWL4030_REG_VMMC1, pdata->vmmc1, in add_children()
875 if (IS_ERR(child)) in add_children()
876 return PTR_ERR(child); in add_children()
878 child = add_regulator(TWL4030_REG_VDAC, pdata->vdac, in add_children()
880 if (IS_ERR(child)) in add_children()
881 return PTR_ERR(child); in add_children()
883 child = add_regulator((features & TWL4030_VAUX2) in add_children()
886 pdata->vaux2, features); in add_children()
887 if (IS_ERR(child)) in add_children()
888 return PTR_ERR(child); in add_children()
890 child = add_regulator(TWL4030_REG_VINTANA1, pdata->vintana1, in add_children()
892 if (IS_ERR(child)) in add_children()
893 return PTR_ERR(child); in add_children()
895 child = add_regulator(TWL4030_REG_VINTANA2, pdata->vintana2, in add_children()
897 if (IS_ERR(child)) in add_children()
898 return PTR_ERR(child); in add_children()
900 child = add_regulator(TWL4030_REG_VINTDIG, pdata->vintdig, in add_children()
902 if (IS_ERR(child)) in add_children()
903 return PTR_ERR(child); in add_children()
906 /* maybe add LDOs that are omitted on cost-reduced parts */ in add_children()
909 child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2, in add_children()
911 if (IS_ERR(child)) in add_children()
912 return PTR_ERR(child); in add_children()
914 child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2, in add_children()
916 if (IS_ERR(child)) in add_children()
917 return PTR_ERR(child); in add_children()
919 child = add_regulator(TWL4030_REG_VSIM, pdata->vsim, in add_children()
921 if (IS_ERR(child)) in add_children()
922 return PTR_ERR(child); in add_children()
924 child = add_regulator(TWL4030_REG_VAUX1, pdata->vaux1, in add_children()
926 if (IS_ERR(child)) in add_children()
927 return PTR_ERR(child); in add_children()
929 child = add_regulator(TWL4030_REG_VAUX3, pdata->vaux3, in add_children()
931 if (IS_ERR(child)) in add_children()
932 return PTR_ERR(child); in add_children()
934 child = add_regulator(TWL4030_REG_VAUX4, pdata->vaux4, in add_children()
936 if (IS_ERR(child)) in add_children()
937 return PTR_ERR(child); in add_children()
940 if (IS_ENABLED(CONFIG_CHARGER_TWL4030) && pdata->bci && in add_children()
942 child = add_child(TWL_MODULE_MAIN_CHARGE, "twl4030_bci", in add_children()
943 pdata->bci, sizeof(*pdata->bci), false, in add_children()
947 if (IS_ERR(child)) in add_children()
948 return PTR_ERR(child); in add_children()
951 if (IS_ENABLED(CONFIG_TWL4030_POWER) && pdata->power) { in add_children()
952 child = add_child(TWL_MODULE_PM_MASTER, "twl4030_power", in add_children()
953 pdata->power, sizeof(*pdata->power), false, in add_children()
955 if (IS_ERR(child)) in add_children()
956 return PTR_ERR(child); in add_children()
962 /*----------------------------------------------------------------------*/
965 * These three functions initialize the on-chip clock framework,
1021 if (clock && clock->ck32k_lowpwr_enable) in clocks_init()
1025 /* effect->MADC+USB ck en */ in clocks_init()
1033 /*----------------------------------------------------------------------*/
1051 struct twl_client *twl = &twl_priv->twl_modules[i]; in twl_remove()
1053 if (twl->client && twl->client != client) in twl_remove()
1054 i2c_unregister_device(twl->client); in twl_remove()
1055 twl->client = NULL; in twl_remove()
1057 twl_priv->ready = false; in twl_remove()
1062 OF_DEV_AUXDATA("ti,twl4030-gpio", 0, "twl4030-gpio", NULL),
1070 struct twl4030_platform_data *pdata = dev_get_platdata(&client->dev); in twl_probe()
1071 struct device_node *node = client->dev.of_node; in twl_probe()
1079 dev_err(&client->dev, "no platform data\n"); in twl_probe()
1080 return -EINVAL; in twl_probe()
1084 dev_dbg(&client->dev, "only one instance of %s allowed\n", in twl_probe()
1086 return -EBUSY; in twl_probe()
1089 pdev = platform_device_alloc(DRIVER_NAME, -1); in twl_probe()
1091 dev_err(&client->dev, "can't alloc pdev\n"); in twl_probe()
1092 return -ENOMEM; in twl_probe()
1101 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) { in twl_probe()
1102 dev_dbg(&client->dev, "can't talk I2C?\n"); in twl_probe()
1103 status = -EIO; in twl_probe()
1107 twl_priv = devm_kzalloc(&client->dev, sizeof(struct twl_private), in twl_probe()
1110 status = -ENOMEM; in twl_probe()
1114 if ((id->driver_data) & TWL6030_CLASS) { in twl_probe()
1115 twl_priv->twl_id = TWL6030_CLASS_ID; in twl_probe()
1116 twl_priv->twl_map = &twl6030_map[0]; in twl_probe()
1117 /* The charger base address is different in twl6032 */ in twl_probe()
1118 if ((id->driver_data) & TWL6032_SUBCLASS) in twl_probe()
1119 twl_priv->twl_map[TWL_MODULE_MAIN_CHARGE].base = in twl_probe()
1123 twl_priv->twl_id = TWL4030_CLASS_ID; in twl_probe()
1124 twl_priv->twl_map = &twl4030_map[0]; in twl_probe()
1129 twl_priv->twl_modules = devm_kcalloc(&client->dev, in twl_probe()
1133 if (!twl_priv->twl_modules) { in twl_probe()
1134 status = -ENOMEM; in twl_probe()
1139 struct twl_client *twl = &twl_priv->twl_modules[i]; in twl_probe()
1142 twl->client = client; in twl_probe()
1144 twl->client = i2c_new_dummy_device(client->adapter, in twl_probe()
1145 client->addr + i); in twl_probe()
1146 if (IS_ERR(twl->client)) { in twl_probe()
1147 dev_err(&client->dev, in twl_probe()
1149 status = PTR_ERR(twl->client); in twl_probe()
1154 twl->regmap = devm_regmap_init_i2c(twl->client, in twl_probe()
1156 if (IS_ERR(twl->regmap)) { in twl_probe()
1157 status = PTR_ERR(twl->regmap); in twl_probe()
1158 dev_err(&client->dev, in twl_probe()
1165 twl_priv->ready = true; in twl_probe()
1168 clocks_init(&client->dev, pdata ? pdata->clock : NULL); in twl_probe()
1176 /* Maybe init the T2 Interrupt subsystem */ in twl_probe()
1177 if (client->irq) { in twl_probe()
1179 twl4030_init_chip_irq(id->name); in twl_probe()
1180 irq_base = twl4030_init_irq(&client->dev, client->irq); in twl_probe()
1182 irq_base = twl6030_init_irq(&client->dev, client->irq); in twl_probe()
1192 * Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface. in twl_probe()
1218 twl_auxdata_lookup[0].platform_data = pdata->gpio; in twl_probe()
1220 &client->dev); in twl_probe()
1222 status = add_children(pdata, irq_base, id->driver_data); in twl_probe()
1239 if (client->irq) in twl_suspend()
1240 disable_irq(client->irq); in twl_suspend()
1249 if (client->irq) in twl_resume()
1250 enable_irq(client->irq); in twl_resume()