Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Core functions for TI TPS65912x PMICs
  4 *
  5 * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
  6 *	Andrew F. Davis <afd@ti.com>
  7 *
  8 * Based on the TPS65218 driver and the previous TPS65912 driver by
  9 * Margarita Olaya Cabrera <magi@slimlogic.co.uk>
 
 
 
 
 
 
 10 */
 11
 12#include <linux/interrupt.h>
 13#include <linux/mfd/core.h>
 14#include <linux/module.h>
 15
 
 
 
 16#include <linux/mfd/tps65912.h>
 17
 18static const struct mfd_cell tps65912_cells[] = {
 19	{ .name = "tps65912-regulator", },
 20	{ .name = "tps65912-gpio", },
 
 21};
 22
 23static const struct regmap_irq tps65912_irqs[] = {
 24	/* INT_STS IRQs */
 25	REGMAP_IRQ_REG(TPS65912_IRQ_PWRHOLD_F, 0, TPS65912_INT_STS_PWRHOLD_F),
 26	REGMAP_IRQ_REG(TPS65912_IRQ_VMON, 0, TPS65912_INT_STS_VMON),
 27	REGMAP_IRQ_REG(TPS65912_IRQ_PWRON, 0, TPS65912_INT_STS_PWRON),
 28	REGMAP_IRQ_REG(TPS65912_IRQ_PWRON_LP, 0, TPS65912_INT_STS_PWRON_LP),
 29	REGMAP_IRQ_REG(TPS65912_IRQ_PWRHOLD_R, 0, TPS65912_INT_STS_PWRHOLD_R),
 30	REGMAP_IRQ_REG(TPS65912_IRQ_HOTDIE, 0, TPS65912_INT_STS_HOTDIE),
 31	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO1_R, 0, TPS65912_INT_STS_GPIO1_R),
 32	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO1_F, 0, TPS65912_INT_STS_GPIO1_F),
 33	/* INT_STS2 IRQs */
 34	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO2_R, 1, TPS65912_INT_STS2_GPIO2_R),
 35	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO2_F, 1, TPS65912_INT_STS2_GPIO2_F),
 36	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO3_R, 1, TPS65912_INT_STS2_GPIO3_R),
 37	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO3_F, 1, TPS65912_INT_STS2_GPIO3_F),
 38	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO4_R, 1, TPS65912_INT_STS2_GPIO4_R),
 39	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO4_F, 1, TPS65912_INT_STS2_GPIO4_F),
 40	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO5_R, 1, TPS65912_INT_STS2_GPIO5_R),
 41	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO5_F, 1, TPS65912_INT_STS2_GPIO5_F),
 42	/* INT_STS3 IRQs */
 43	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC1, 2, TPS65912_INT_STS3_PGOOD_DCDC1),
 44	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC2, 2, TPS65912_INT_STS3_PGOOD_DCDC2),
 45	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC3, 2, TPS65912_INT_STS3_PGOOD_DCDC3),
 46	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC4, 2, TPS65912_INT_STS3_PGOOD_DCDC4),
 47	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO1, 2, TPS65912_INT_STS3_PGOOD_LDO1),
 48	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO2, 2, TPS65912_INT_STS3_PGOOD_LDO2),
 49	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO3, 2, TPS65912_INT_STS3_PGOOD_LDO3),
 50	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO4, 2, TPS65912_INT_STS3_PGOOD_LDO4),
 51	/* INT_STS4 IRQs */
 52	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO5, 3, TPS65912_INT_STS4_PGOOD_LDO5),
 53	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO6, 3, TPS65912_INT_STS4_PGOOD_LDO6),
 54	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO7, 3, TPS65912_INT_STS4_PGOOD_LDO7),
 55	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO8, 3, TPS65912_INT_STS4_PGOOD_LDO8),
 56	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO9, 3, TPS65912_INT_STS4_PGOOD_LDO9),
 57	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO10, 3, TPS65912_INT_STS4_PGOOD_LDO10),
 58};
 59
 60static struct regmap_irq_chip tps65912_irq_chip = {
 61	.name = "tps65912",
 62	.irqs = tps65912_irqs,
 63	.num_irqs = ARRAY_SIZE(tps65912_irqs),
 64	.num_regs = 4,
 65	.irq_reg_stride = 2,
 66	.mask_base = TPS65912_INT_MSK,
 67	.status_base = TPS65912_INT_STS,
 68	.ack_base = TPS65912_INT_STS,
 69	.init_ack_masked = true,
 70};
 71
 72static const struct regmap_range tps65912_yes_ranges[] = {
 73	regmap_reg_range(TPS65912_INT_STS, TPS65912_GPIO5),
 74};
 
 
 75
 76static const struct regmap_access_table tps65912_volatile_table = {
 77	.yes_ranges = tps65912_yes_ranges,
 78	.n_yes_ranges = ARRAY_SIZE(tps65912_yes_ranges),
 79};
 
 
 
 
 
 
 80
 81const struct regmap_config tps65912_regmap_config = {
 82	.reg_bits = 8,
 83	.val_bits = 8,
 84	.cache_type = REGCACHE_MAPLE,
 85	.volatile_table = &tps65912_volatile_table,
 86};
 87EXPORT_SYMBOL_GPL(tps65912_regmap_config);
 88
 89int tps65912_device_init(struct tps65912 *tps)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 90{
 91	int ret;
 
 
 
 
 
 92
 93	ret = regmap_add_irq_chip(tps->regmap, tps->irq, IRQF_ONESHOT, 0,
 94				  &tps65912_irq_chip, &tps->irq_data);
 95	if (ret)
 96		return ret;
 97
 98	ret = mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO, tps65912_cells,
 99			      ARRAY_SIZE(tps65912_cells), NULL, 0,
100			      regmap_irq_get_domain(tps->irq_data));
101	if (ret) {
102		regmap_del_irq_chip(tps->irq, tps->irq_data);
103		return ret;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104	}
105
106	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107}
108EXPORT_SYMBOL_GPL(tps65912_device_init);
109
110void tps65912_device_exit(struct tps65912 *tps)
111{
112	regmap_del_irq_chip(tps->irq, tps->irq_data);
 
113}
114EXPORT_SYMBOL_GPL(tps65912_device_exit);
115
116MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
117MODULE_DESCRIPTION("TPS65912x MFD Driver");
118MODULE_LICENSE("GPL v2");
v3.15
 
  1/*
  2 * tps65912-core.c  --  TI TPS65912x
  3 *
  4 * Copyright 2011 Texas Instruments Inc.
 
  5 *
  6 * Author: Margarita Olaya Cabrera <magi@slimlogic.co.uk>
  7 *
  8 *  This program is free software; you can redistribute it and/or modify it
  9 *  under  the terms of the GNU General  Public License as published by the
 10 *  Free Software Foundation;  either version 2 of the License, or (at your
 11 *  option) any later version.
 12 *
 13 *  This driver is based on wm8350 implementation.
 14 */
 15
 
 
 16#include <linux/module.h>
 17#include <linux/moduleparam.h>
 18#include <linux/slab.h>
 19#include <linux/gpio.h>
 20#include <linux/mfd/core.h>
 21#include <linux/mfd/tps65912.h>
 22
 23static const struct mfd_cell tps65912s[] = {
 24	{
 25		.name = "tps65912-pmic",
 26	},
 27};
 28
 29int tps65912_set_bits(struct tps65912 *tps65912, u8 reg, u8 mask)
 30{
 31	u8 data;
 32	int err;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 33
 34	mutex_lock(&tps65912->io_mutex);
 
 
 
 
 
 
 
 
 
 
 35
 36	err = tps65912->read(tps65912, reg, 1, &data);
 37	if (err) {
 38		dev_err(tps65912->dev, "Read from reg 0x%x failed\n", reg);
 39		goto out;
 40	}
 41
 42	data |= mask;
 43	err = tps65912->write(tps65912, reg, 1, &data);
 44	if (err)
 45		dev_err(tps65912->dev, "Write to reg 0x%x failed\n", reg);
 46
 47out:
 48	mutex_unlock(&tps65912->io_mutex);
 49	return err;
 50}
 51EXPORT_SYMBOL_GPL(tps65912_set_bits);
 52
 53int tps65912_clear_bits(struct tps65912 *tps65912, u8 reg, u8 mask)
 54{
 55	u8 data;
 56	int err;
 
 
 
 57
 58	mutex_lock(&tps65912->io_mutex);
 59	err = tps65912->read(tps65912, reg, 1, &data);
 60	if (err) {
 61		dev_err(tps65912->dev, "Read from reg 0x%x failed\n", reg);
 62		goto out;
 63	}
 64
 65	data &= ~mask;
 66	err = tps65912->write(tps65912, reg, 1, &data);
 67	if (err)
 68		dev_err(tps65912->dev, "Write to reg 0x%x failed\n", reg);
 69
 70out:
 71	mutex_unlock(&tps65912->io_mutex);
 72	return err;
 73}
 74EXPORT_SYMBOL_GPL(tps65912_clear_bits);
 75
 76static inline int tps65912_read(struct tps65912 *tps65912, u8 reg)
 77{
 78	u8 val;
 79	int err;
 80
 81	err = tps65912->read(tps65912, reg, 1, &val);
 82	if (err < 0)
 83		return err;
 84
 85	return val;
 86}
 87
 88static inline int tps65912_write(struct tps65912 *tps65912, u8 reg, u8 val)
 89{
 90	return tps65912->write(tps65912, reg, 1, &val);
 91}
 92
 93int tps65912_reg_read(struct tps65912 *tps65912, u8 reg)
 94{
 95	int data;
 96
 97	mutex_lock(&tps65912->io_mutex);
 98
 99	data = tps65912_read(tps65912, reg);
100	if (data < 0)
101		dev_err(tps65912->dev, "Read from reg 0x%x failed\n", reg);
102
103	mutex_unlock(&tps65912->io_mutex);
104	return data;
105}
106EXPORT_SYMBOL_GPL(tps65912_reg_read);
107
108int tps65912_reg_write(struct tps65912 *tps65912, u8 reg, u8 val)
109{
110	int err;
111
112	mutex_lock(&tps65912->io_mutex);
113
114	err = tps65912_write(tps65912, reg, val);
115	if (err < 0)
116		dev_err(tps65912->dev, "Write for reg 0x%x failed\n", reg);
117
118	mutex_unlock(&tps65912->io_mutex);
119	return err;
120}
121EXPORT_SYMBOL_GPL(tps65912_reg_write);
122
123int tps65912_device_init(struct tps65912 *tps65912)
124{
125	struct tps65912_board *pmic_plat_data = dev_get_platdata(tps65912->dev);
126	struct tps65912_platform_data *init_data;
127	int ret, dcdc_avs, value;
128
129	init_data = kzalloc(sizeof(struct tps65912_platform_data), GFP_KERNEL);
130	if (init_data == NULL)
131		return -ENOMEM;
132
133	mutex_init(&tps65912->io_mutex);
134	dev_set_drvdata(tps65912->dev, tps65912);
135
136	dcdc_avs = (pmic_plat_data->is_dcdc1_avs << 0 |
137			pmic_plat_data->is_dcdc2_avs  << 1 |
138				pmic_plat_data->is_dcdc3_avs << 2 |
139					pmic_plat_data->is_dcdc4_avs << 3);
140	if (dcdc_avs) {
141		tps65912->read(tps65912, TPS65912_I2C_SPI_CFG, 1, &value);
142		dcdc_avs |= value;
143		tps65912->write(tps65912, TPS65912_I2C_SPI_CFG, 1, &dcdc_avs);
144	}
145
146	ret = mfd_add_devices(tps65912->dev, -1,
147			      tps65912s, ARRAY_SIZE(tps65912s),
148			      NULL, 0, NULL);
149	if (ret < 0)
150		goto err;
151
152	init_data->irq = pmic_plat_data->irq;
153	init_data->irq_base = pmic_plat_data->irq_base;
154	ret = tps65912_irq_init(tps65912, init_data->irq, init_data);
155	if (ret < 0)
156		goto err;
157
158	kfree(init_data);
159	return ret;
160
161err:
162	kfree(init_data);
163	mfd_remove_devices(tps65912->dev);
164	return ret;
165}
 
166
167void tps65912_device_exit(struct tps65912 *tps65912)
168{
169	mfd_remove_devices(tps65912->dev);
170	tps65912_irq_exit(tps65912);
171}
 
172
173MODULE_AUTHOR("Margarita Olaya	<magi@slimlogic.co.uk>");
174MODULE_DESCRIPTION("TPS65912x chip family multi-function driver");
175MODULE_LICENSE("GPL");