Lines Matching +full:charge +full:- +full:ctrl +full:- +full:value

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.
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
60 /* subchip/slave 0 - USB ID */
63 /* subchip/slave 1 - AUD ID */
70 /* subchip/slave 2 - AUX ID */
79 #define TWL5031_BASEADD_ACCESSORY 0x0074 /* Replaces Main Charge */
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 /*----------------------------------------------------------------------*/
151 u32 twl_idcode; /* TWL IDCODE Register value */
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
434 * @value: an array of num_bytes+1 containing data to write
440 int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) in twl_i2c_write() argument
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()
449 value, num_bytes); in twl_i2c_write()
460 * twl_i2c_read - Reads a n bit register in TWL4030/TWL5030/TWL60X0
462 * @value: an array of num_bytes containing data to be read
468 int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) in twl_i2c_read() argument
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()
477 value, num_bytes); in twl_i2c_read()
488 * twl_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.
513 * Unlocks the IDCODE register and read the 32 bit value.
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.
543 * Api to get the TWL Si type from IDCODE value.
547 return TWL_SIL_TYPE(twl_priv->twl_idcode); in twl_get_type()
552 * twl_get_version - API to get TWL Si version.
554 * Api to get the TWL Si version from IDCODE value.
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.
569 u8 ctrl; in twl_get_hfclk_rate() local
572 twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &ctrl, R_CFG_BOOT); in twl_get_hfclk_rate()
574 switch (ctrl & 0x3) { in twl_get_hfclk_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
713 if (IS_ENABLED(CONFIG_GPIO_TWL4030) && pdata->gpio) { in add_children()
715 pdata->gpio, sizeof(*pdata->gpio), in add_children()
721 if (IS_ENABLED(CONFIG_KEYBOARD_TWL4030) && pdata->keypad) { in add_children()
723 pdata->keypad, sizeof(*pdata->keypad), in add_children()
729 if (IS_ENABLED(CONFIG_TWL4030_MADC) && pdata->madc && in add_children()
732 pdata->madc, sizeof(*pdata->madc), in add_children()
753 child = add_child(TWL_MODULE_PWM, "twl-pwm", NULL, 0, in add_children()
760 child = add_child(TWL_MODULE_LED, "twl-pwmled", NULL, 0, in add_children()
766 if (IS_ENABLED(CONFIG_TWL4030_USB) && pdata->usb && in add_children()
812 pdata->usb, sizeof(*pdata->usb), true, 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()
853 child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1, in add_children()
858 child = add_regulator(TWL4030_REG_VIO, pdata->vio, in add_children()
863 child = add_regulator(TWL4030_REG_VDD1, pdata->vdd1, in add_children()
868 child = add_regulator(TWL4030_REG_VDD2, pdata->vdd2, in add_children()
873 child = add_regulator(TWL4030_REG_VMMC1, pdata->vmmc1, in add_children()
878 child = add_regulator(TWL4030_REG_VDAC, pdata->vdac, in add_children()
886 pdata->vaux2, features); in add_children()
890 child = add_regulator(TWL4030_REG_VINTANA1, pdata->vintana1, in add_children()
895 child = add_regulator(TWL4030_REG_VINTANA2, pdata->vintana2, in add_children()
900 child = add_regulator(TWL4030_REG_VINTDIG, pdata->vintdig, 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()
914 child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2, in add_children()
919 child = add_regulator(TWL4030_REG_VSIM, pdata->vsim, in add_children()
924 child = add_regulator(TWL4030_REG_VAUX1, pdata->vaux1, in add_children()
929 child = add_regulator(TWL4030_REG_VAUX3, pdata->vaux3, in add_children()
934 child = add_regulator(TWL4030_REG_VAUX4, pdata->vaux4, in add_children()
940 if (IS_ENABLED(CONFIG_CHARGER_TWL4030) && pdata->bci && in add_children()
943 pdata->bci, sizeof(*pdata->bci), false, in add_children()
951 if (IS_ENABLED(CONFIG_TWL4030_POWER) && pdata->power) { in add_children()
953 pdata->power, sizeof(*pdata->power), false, in add_children()
962 /*----------------------------------------------------------------------*/
965 * These three functions initialize the on-chip clock framework,
996 u8 ctrl = HFCLK_FREQ_26_MHZ; in clocks_init() local
1001 "using bootloader value (unknown osc rate)\n"); in clocks_init()
1010 ctrl = HFCLK_FREQ_19p2_MHZ; in clocks_init()
1013 ctrl = HFCLK_FREQ_26_MHZ; in clocks_init()
1016 ctrl = HFCLK_FREQ_38p4_MHZ; in clocks_init()
1020 ctrl |= HIGH_PERF_SQ; in clocks_init()
1021 if (clock && clock->ck32k_lowpwr_enable) in clocks_init()
1022 ctrl |= CK32K_LOWPWR_EN; in clocks_init()
1025 /* effect->MADC+USB ck en */ in clocks_init()
1026 e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, ctrl, R_CFG_BOOT); 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()
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()
1173 WARN(status < 0, "Error: reading twl_idcode register value\n"); 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()