static int tps65910_sleepinit(struct tps65910 *tps65910, struct tps65910_board *pmic_pdata) { struct device *dev = NULL; int ret = 0; dev = tps65910->dev; if (!pmic_pdata->en_dev_slp) return 0; /* enabling SLEEP device state */ ret = tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL, DEVCTRL_DEV_SLP_MASK); if (ret < 0) { dev_err(dev, "set dev_slp failed: %d\n", ret); goto err_sleep_init; } if (pmic_pdata->slp_keepon.therm_keepon) { ret = tps65910_reg_set_bits(tps65910, TPS65910_SLEEP_KEEP_RES_ON, SLEEP_KEEP_RES_ON_THERM_KEEPON_MASK); if (ret < 0) { dev_err(dev, "set therm_keepon failed: %d\n", ret); goto disable_dev_slp; } } if (pmic_pdata->slp_keepon.clkout32k_keepon) { ret = tps65910_reg_set_bits(tps65910, TPS65910_SLEEP_KEEP_RES_ON, SLEEP_KEEP_RES_ON_CLKOUT32K_KEEPON_MASK); if (ret < 0) { dev_err(dev, "set clkout32k_keepon failed: %d\n", ret); goto disable_dev_slp; } } if (pmic_pdata->slp_keepon.i2chs_keepon) { ret = tps65910_reg_set_bits(tps65910, TPS65910_SLEEP_KEEP_RES_ON, SLEEP_KEEP_RES_ON_I2CHS_KEEPON_MASK); if (ret < 0) { dev_err(dev, "set i2chs_keepon failed: %d\n", ret); goto disable_dev_slp; } } return 0; disable_dev_slp: tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL, DEVCTRL_DEV_SLP_MASK); err_sleep_init: return ret; }
static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset, int value) { struct tps65910_gpio *tps65910_gpio = gpiochip_get_data(gc); struct tps65910 *tps65910 = tps65910_gpio->tps65910; /* Set the initial value */ tps65910_gpio_set(gc, offset, value); return tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset, GPIO_CFG_MASK); }
static void tps65910_power_off(void) { struct tps65910 *tps65910; tps65910 = dev_get_drvdata(&tps65910_i2c_client->dev); if (tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL, DEVCTRL_PWR_OFF_MASK) < 0) return; tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL, DEVCTRL_DEV_ON_MASK); }
static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset, int value) { struct tps65910_gpio *tps65910_gpio = gpiochip_get_data(gc); struct tps65910 *tps65910 = tps65910_gpio->tps65910; if (value) tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset, GPIO_SET_MASK); else tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset, GPIO_SET_MASK); }
static int tps65910_gpio_probe(struct platform_device *pdev) { struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent); struct tps65910_board *pdata = dev_get_platdata(tps65910->dev); struct tps65910_gpio *tps65910_gpio; int ret; int i; tps65910_gpio = devm_kzalloc(&pdev->dev, sizeof(*tps65910_gpio), GFP_KERNEL); if (!tps65910_gpio) return -ENOMEM; tps65910_gpio->tps65910 = tps65910; tps65910_gpio->gpio_chip.owner = THIS_MODULE; tps65910_gpio->gpio_chip.label = tps65910->i2c_client->name; switch (tps65910_chip_id(tps65910)) { case TPS65910: tps65910_gpio->gpio_chip.ngpio = TPS65910_NUM_GPIO; break; case TPS65911: tps65910_gpio->gpio_chip.ngpio = TPS65911_NUM_GPIO; break; default: return -EINVAL; } tps65910_gpio->gpio_chip.can_sleep = true; tps65910_gpio->gpio_chip.direction_input = tps65910_gpio_input; tps65910_gpio->gpio_chip.direction_output = tps65910_gpio_output; tps65910_gpio->gpio_chip.set = tps65910_gpio_set; tps65910_gpio->gpio_chip.get = tps65910_gpio_get; tps65910_gpio->gpio_chip.parent = &pdev->dev; #ifdef CONFIG_OF_GPIO tps65910_gpio->gpio_chip.of_node = tps65910->dev->of_node; #endif if (pdata && pdata->gpio_base) tps65910_gpio->gpio_chip.base = pdata->gpio_base; else tps65910_gpio->gpio_chip.base = -1; if (!pdata && tps65910->dev->of_node) pdata = tps65910_parse_dt_for_gpio(&pdev->dev, tps65910, tps65910_gpio->gpio_chip.ngpio); if (!pdata) goto skip_init; /* Configure sleep control for gpios if provided */ for (i = 0; i < tps65910_gpio->gpio_chip.ngpio; ++i) { if (!pdata->en_gpio_sleep[i]) continue; ret = tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + i, GPIO_SLEEP_MASK); if (ret < 0) dev_warn(tps65910->dev, "GPIO Sleep setting failed with err %d\n", ret); } skip_init: ret = devm_gpiochip_add_data(&pdev->dev, &tps65910_gpio->gpio_chip, tps65910_gpio); if (ret < 0) { dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); return ret; } platform_set_drvdata(pdev, tps65910_gpio); return ret; }