summaryrefslogtreecommitdiff
path: root/drivers/mfd
diff options
context:
space:
mode:
authorVenu Byravarasu <vbyravarasu@nvidia.com>2012-03-16 11:10:19 +0530
committerSimone Willett <swillett@nvidia.com>2012-08-01 18:09:55 -0700
commita108454c2b8e037a82e49e14ceb3d9c0228af963 (patch)
treed23ea32e6da0b7101ef671443fbcc1d8b89eacfd /drivers/mfd
parentb38a60e86cc3ec0b289afb71f704838b0c34aa5e (diff)
mfd: tps65090: align driver with mainline
Align the driver with mainline. This is vbased on commit 3c33be06f9aa0949ad24e67dfcae1f2a3006f4e1 --------------- mfd: Add support for TPS65090 TPS65090 is a Texas Instrument PMIC. It contains 3 Step-Down converters, 2 always on LDO's and 7 current limited load switches. Signed-off-by: Venu Byravarasu <vbyravarasu@nvidia.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com> -------------- Change-Id: I26545520f2cc72100a927cb60b38693153a4afce Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com> Reviewed-on: http://git-master/r/119320 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Venu Byravarasu <vbyravarasu@nvidia.com>
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/Kconfig24
-rw-r--r--drivers/mfd/Makefile2
-rw-r--r--drivers/mfd/tps65090.c351
3 files changed, 133 insertions, 244 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index f37d3ec02123..7040ae62f75a 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -783,6 +783,18 @@ config MFD_PM8XXX_IRQ
config TPS65911_COMPARATOR
tristate
+config MFD_TPS65090
+ bool "TPS65090 Power Management chips"
+ depends on I2C=y && GENERIC_HARDIRQS
+ select MFD_CORE
+ select REGMAP_I2C
+ help
+ If you say yes here you get support for the TPS65090 series of
+ Power Management chips.
+ This driver provides common support for accessing the device,
+ additional drivers must be enabled in order to use the
+ functionality of the device.
+
config MFD_AAT2870_CORE
bool "Support for the AnalogicTech AAT2870"
select MFD_CORE
@@ -804,18 +816,6 @@ config MFD_TPS6591X
additional drivers must be enabled in order to use the
functionality of the device.
-config MFD_TPS65090
- bool "TPS65090 Power Management chips"
- depends on I2C && GENERIC_HARDIRQS
- select MFD_CORE
- select REGMAP_I2C
- help
- If you say yes here you get support for the TPS65090 series of
- Power Management chips.
- This driver provides common support for accessing the device,
- additional drivers must be enabled in order to use the
- functionality of the device.
-
config MFD_RC5T583
bool "Ricoh RC5T583 Power Management system device"
depends on I2C=y && GENERIC_HARDIRQS
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 6634515b64e4..efd9f7fee186 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -101,9 +101,9 @@ obj-$(CONFIG_MFD_OMAP_USB_HOST) += omap-usb-host.o
obj-$(CONFIG_MFD_PM8921_CORE) += pm8921-core.o
obj-$(CONFIG_MFD_PM8XXX_IRQ) += pm8xxx-irq.o
obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o
+obj-$(CONFIG_MFD_TPS65090) += tps65090.o
obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o
obj-$(CONFIG_MFD_TPS6591X) += tps6591x.o
-obj-$(CONFIG_MFD_TPS65090) += tps65090.o
obj-$(CONFIG_MFD_TPS80031) += tps80031.o
obj-$(CONFIG_GPADC_TPS80031) += tps8003x-gpadc.o
obj-$(CONFIG_MFD_MAX8907C) += max8907c.o
diff --git a/drivers/mfd/tps65090.c b/drivers/mfd/tps65090.c
index 080f97aa264b..a66d4df51293 100644
--- a/drivers/mfd/tps65090.c
+++ b/drivers/mfd/tps65090.c
@@ -1,24 +1,19 @@
/*
- * driver/mfd/tps65090.c
- *
* Core driver for TI TPS65090 PMIC family
*
- * Copyright (C) 2012 NVIDIA Corporation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
+ * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
+
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+
+ * This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/interrupt.h>
@@ -28,10 +23,13 @@
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/i2c.h>
-
#include <linux/mfd/core.h>
#include <linux/mfd/tps65090.h>
#include <linux/regmap.h>
+#include <linux/err.h>
+
+#define NUM_INT_REG 2
+#define TOTAL_NUM_REG 0x18
/* interrupt status registers */
#define TPS65090_INT_STS 0x0
@@ -41,41 +39,43 @@
#define TPS65090_INT_MSK 0x2
#define TPS65090_INT_MSK2 0x3
-
-enum irq_type {
- EVENT,
-};
-
struct tps65090_irq_data {
u8 mask_reg;
u8 mask_pos;
- enum irq_type type;
};
-#define TPS65090_IRQ(_reg, _mask_pos, _type) \
+#define TPS65090_IRQ(_reg, _mask_pos) \
{ \
.mask_reg = (_reg), \
.mask_pos = (_mask_pos), \
- .type = (_type), \
}
static const struct tps65090_irq_data tps65090_irqs[] = {
- [0] = TPS65090_IRQ(0, 0, EVENT),
- [1] = TPS65090_IRQ(0, 1, EVENT),
- [2] = TPS65090_IRQ(0, 2, EVENT),
- [3] = TPS65090_IRQ(0, 3, EVENT),
- [4] = TPS65090_IRQ(0, 4, EVENT),
- [5] = TPS65090_IRQ(0, 5, EVENT),
- [6] = TPS65090_IRQ(0, 6, EVENT),
- [7] = TPS65090_IRQ(0, 7, EVENT),
- [8] = TPS65090_IRQ(1, 0, EVENT),
- [9] = TPS65090_IRQ(1, 1, EVENT),
- [10] = TPS65090_IRQ(1, 2, EVENT),
- [11] = TPS65090_IRQ(1, 3, EVENT),
- [12] = TPS65090_IRQ(1, 4, EVENT),
- [13] = TPS65090_IRQ(1, 5, EVENT),
- [14] = TPS65090_IRQ(1, 6, EVENT),
- [15] = TPS65090_IRQ(1, 7, EVENT),
+ [0] = TPS65090_IRQ(0, 0),
+ [1] = TPS65090_IRQ(0, 1),
+ [2] = TPS65090_IRQ(0, 2),
+ [3] = TPS65090_IRQ(0, 3),
+ [4] = TPS65090_IRQ(0, 4),
+ [5] = TPS65090_IRQ(0, 5),
+ [6] = TPS65090_IRQ(0, 6),
+ [7] = TPS65090_IRQ(0, 7),
+ [8] = TPS65090_IRQ(1, 0),
+ [9] = TPS65090_IRQ(1, 1),
+ [10] = TPS65090_IRQ(1, 2),
+ [11] = TPS65090_IRQ(1, 3),
+ [12] = TPS65090_IRQ(1, 4),
+ [13] = TPS65090_IRQ(1, 5),
+ [14] = TPS65090_IRQ(1, 6),
+ [15] = TPS65090_IRQ(1, 7),
+};
+
+static struct mfd_cell tps65090s[] = {
+ {
+ .name = "tps65910-pmic",
+ },
+ {
+ .name = "tps65910-regulator",
+ },
};
struct tps65090 {
@@ -86,51 +86,42 @@ struct tps65090 {
struct irq_chip irq_chip;
struct mutex irq_lock;
int irq_base;
- u32 irq_en;
- u8 mask_cache[2];
- u8 mask_reg[2];
+ unsigned int id;
};
+
int tps65090_write(struct device *dev, int reg, uint8_t val)
{
struct tps65090 *tps = dev_get_drvdata(dev);
return regmap_write(tps->rmap, reg, val);
}
+EXPORT_SYMBOL_GPL(tps65090_write);
+
int tps65090_read(struct device *dev, int reg, uint8_t *val)
{
- int rval, ret = 0;
struct tps65090 *tps = dev_get_drvdata(dev);
- ret = regmap_read(tps->rmap, reg, &rval);
- *val = rval;
- return 0;
+ unsigned int temp_val;
+ int ret;
+ ret = regmap_read(tps->rmap, reg, &temp_val);
+ if (!ret)
+ *val = temp_val;
+ return ret;
}
EXPORT_SYMBOL_GPL(tps65090_read);
int tps65090_set_bits(struct device *dev, int reg, uint8_t bit_num)
{
struct tps65090 *tps = dev_get_drvdata(dev);
- return regmap_update_bits_lazy(tps->rmap, reg, BIT(bit_num), ~0u);
-
+ return regmap_update_bits(tps->rmap, reg, BIT(bit_num), ~0u);
}
EXPORT_SYMBOL_GPL(tps65090_set_bits);
int tps65090_clr_bits(struct device *dev, int reg, uint8_t bit_num)
{
struct tps65090 *tps = dev_get_drvdata(dev);
- return regmap_update_bits_lazy(tps->rmap, reg, BIT(bit_num), 0u);
+ return regmap_update_bits(tps->rmap, reg, BIT(bit_num), 0u);
}
EXPORT_SYMBOL_GPL(tps65090_clr_bits);
-static int __remove_subdev(struct device *dev, void *unused)
-{
- platform_device_unregister(to_platform_device(dev));
- return 0;
-}
-
-static int tps65090_remove_subdevs(struct tps65090 *tps65090)
-{
- return device_for_each_child(tps65090->dev, NULL, __remove_subdev);
-}
-
static void tps65090_irq_lock(struct irq_data *data)
{
struct tps65090 *tps65090 = irq_data_get_irq_chip_data(data);
@@ -141,135 +132,97 @@ static void tps65090_irq_lock(struct irq_data *data)
static void tps65090_irq_mask(struct irq_data *irq_data)
{
struct tps65090 *tps65090 = irq_data_get_irq_chip_data(irq_data);
- unsigned int __irq = irq_data->irq - tps65090->irq_base;
+ unsigned int __irq = irq_data->hwirq;
const struct tps65090_irq_data *data = &tps65090_irqs[__irq];
- if (data->type == EVENT)
- tps65090->mask_reg[data->mask_reg] |= (1 << data->mask_pos);
- else
- tps65090->mask_reg[data->mask_reg] |= (3 << data->mask_pos);
-
- tps65090->irq_en &= ~(1 << __irq);
+ tps65090_set_bits(tps65090->dev, (TPS65090_INT_MSK + data->mask_reg),
+ data->mask_pos);
}
static void tps65090_irq_unmask(struct irq_data *irq_data)
{
struct tps65090 *tps65090 = irq_data_get_irq_chip_data(irq_data);
-
unsigned int __irq = irq_data->irq - tps65090->irq_base;
const struct tps65090_irq_data *data = &tps65090_irqs[__irq];
- if (data->type == EVENT) {
- tps65090->mask_reg[data->mask_reg] &= ~(1 << data->mask_pos);
- tps65090->irq_en |= (1 << __irq);
- }
+ tps65090_clr_bits(tps65090->dev, (TPS65090_INT_MSK + data->mask_reg),
+ data->mask_pos);
}
static void tps65090_irq_sync_unlock(struct irq_data *data)
{
struct tps65090 *tps65090 = irq_data_get_irq_chip_data(data);
- int i;
-
- for (i = 0; i < ARRAY_SIZE(tps65090->mask_reg); i++) {
- if (tps65090->mask_reg[i] != tps65090->mask_cache[i]) {
- if (!WARN_ON(tps65090_write(tps65090->dev,
- TPS65090_INT_MSK + 2*i,
- tps65090->mask_reg[i])))
- tps65090->mask_cache[i] = tps65090->mask_reg[i];
- }
- }
mutex_unlock(&tps65090->irq_lock);
}
-static int tps65090_irq_set_type(struct irq_data *irq_data, unsigned int type)
-{
- struct tps65090 *tps65090 = irq_data_get_irq_chip_data(irq_data);
-
- unsigned int __irq = irq_data->irq - tps65090->irq_base;
- const struct tps65090_irq_data *data = &tps65090_irqs[__irq];
-
- if (data->type != EVENT) /* add support for GPIO, if needed */
- return -EINVAL;
-
- return 0;
-}
-
static irqreturn_t tps65090_irq(int irq, void *data)
{
struct tps65090 *tps65090 = data;
int ret = 0;
- u8 tmp[3];
- u8 int_ack;
- u32 acks, mask = 0;
+ u8 status, mask;
+ unsigned long int acks = 0;
int i;
- for (i = 0; i < 3; i++) {
- ret = tps65090_read(tps65090->dev, TPS65090_INT_STS + 2*i,
- &tmp[i]);
+ for (i = 0; i < NUM_INT_REG; i++) {
+ ret = tps65090_read(tps65090->dev, TPS65090_INT_MSK + i, &mask);
if (ret < 0) {
dev_err(tps65090->dev,
- "failed to read interrupt status\n");
+ "failed to read mask reg [addr:%d]\n",
+ TPS65090_INT_MSK + i);
return IRQ_NONE;
}
- if (tmp[i]) {
- /* Ack only those interrupts which are enabled */
- int_ack = tmp[i] & (~(tps65090->mask_cache[i]));
+ ret = tps65090_read(tps65090->dev, TPS65090_INT_STS + i,
+ &status);
+ if (ret < 0) {
+ dev_err(tps65090->dev,
+ "failed to read status reg [addr:%d]\n",
+ TPS65090_INT_STS + i);
+ return IRQ_NONE;
+ }
+ if (status) {
+ /* Ack only those interrupts which are not masked */
+ status &= (~mask);
ret = tps65090_write(tps65090->dev,
- TPS65090_INT_STS + 2*i, int_ack);
+ TPS65090_INT_STS + i, status);
if (ret < 0) {
dev_err(tps65090->dev,
"failed to write interrupt status\n");
return IRQ_NONE;
}
+ acks |= (status << (i * 8));
}
}
- acks = (tmp[2] << 16) | (tmp[1] << 8) | tmp[0];
-
- for (i = 0; i < ARRAY_SIZE(tps65090_irqs); i++) {
- if (tps65090_irqs[i].type == EVENT)
- mask = (1 << (tps65090_irqs[i].mask_pos
- + tps65090_irqs[i].mask_reg*8));
- else
- return -EINVAL;
- if ((acks & mask) && (tps65090->irq_en & (1 << i)))
- handle_nested_irq(tps65090->irq_base + i);
- }
- return IRQ_HANDLED;
+ for_each_set_bit(i, &acks, ARRAY_SIZE(tps65090_irqs))
+ handle_nested_irq(tps65090->irq_base + i);
+ return acks ? IRQ_HANDLED : IRQ_NONE;
}
static int __devinit tps65090_irq_init(struct tps65090 *tps65090, int irq,
- int irq_base)
+ int irq_base)
{
int i, ret;
if (!irq_base) {
- dev_warn(tps65090->dev, "No interrupt support on IRQ base\n");
+ dev_err(tps65090->dev, "IRQ base not set\n");
return -EINVAL;
}
mutex_init(&tps65090->irq_lock);
- tps65090->mask_reg[0] = 0xFF;
- tps65090->mask_reg[1] = 0xFF;
- for (i = 0; i < 2; i++) {
- tps65090->mask_cache[i] = tps65090->mask_reg[i];
- tps65090_write(tps65090->dev, TPS65090_INT_MSK + i,
- tps65090->mask_cache[i]);
- }
+ for (i = 0; i < NUM_INT_REG; i++)
+ tps65090_write(tps65090->dev, TPS65090_INT_MSK + i, 0xFF);
- for (i = 0; i < 2; i++)
+ for (i = 0; i < NUM_INT_REG; i++)
tps65090_write(tps65090->dev, TPS65090_INT_STS + i, 0xff);
tps65090->irq_base = irq_base;
-
tps65090->irq_chip.name = "tps65090";
tps65090->irq_chip.irq_mask = tps65090_irq_mask;
tps65090->irq_chip.irq_unmask = tps65090_irq_unmask;
tps65090->irq_chip.irq_bus_lock = tps65090_irq_lock;
tps65090->irq_chip.irq_bus_sync_unlock = tps65090_irq_sync_unlock;
- tps65090->irq_chip.irq_set_type = tps65090_irq_set_type;
for (i = 0; i < ARRAY_SIZE(tps65090_irqs); i++) {
int __irq = i + tps65090->irq_base;
@@ -292,90 +245,21 @@ static int __devinit tps65090_irq_init(struct tps65090 *tps65090, int irq,
return ret;
}
-static int __devinit tps65090_add_subdevs(struct tps65090 *tps65090,
- struct tps65090_platform_data *pdata)
-{
- struct tps65090_subdev_info *subdev;
- struct platform_device *pdev;
- int i, ret = 0;
-
- for (i = 0; i < pdata->num_subdevs; i++) {
- subdev = &pdata->subdevs[i];
-
- pdev = platform_device_alloc(subdev->name, subdev->id);
-
- pdev->dev.parent = tps65090->dev;
- pdev->dev.platform_data = subdev->platform_data;
-
- ret = platform_device_add(pdev);
- if (ret)
- goto failed;
- }
- return 0;
-
-failed:
- tps65090_remove_subdevs(tps65090);
- return ret;
-}
-#ifdef CONFIG_DEBUG_FS
-#include <linux/debugfs.h>
-#include <linux/seq_file.h>
-static void print_regs(const char *header, struct seq_file *s,
- struct i2c_client *client, int start_offset,
- int end_offset)
-{
- int reg_val;
- int i;
- int ret;
- struct tps65090 *tps = s->private;
- seq_printf(s, "%s\n", header);
- for (i = start_offset; i <= end_offset; ++i) {
- ret = regmap_read(tps->rmap, i, &reg_val);
- if (ret >= 0)
- seq_printf(s, "Reg 0x%02x Value 0x%02x\n", i, reg_val);
- }
- seq_printf(s, "------------------\n");
-}
-
-static int dbg_tps_show(struct seq_file *s, void *unused)
+static bool is_volatile_reg(struct device *dev, unsigned int reg)
{
- struct tps65090 *tps = s->private;
- struct i2c_client *client = tps->client;
-
- seq_printf(s, "TPS65090 Registers\n");
- seq_printf(s, "------------------\n");
-
- print_regs("All Regs", s, client, 0x0, 24);
- return 0;
-}
-
-static int dbg_tps_open(struct inode *inode, struct file *file)
-{
- return single_open(file, dbg_tps_show, inode->i_private);
-}
-
-static const struct file_operations debug_fops = {
- .open = dbg_tps_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
-
-static void __init tps65090_debuginit(struct tps65090 *tps)
-{
- (void)debugfs_create_file("tps65090", S_IRUGO, NULL,
- tps, &debug_fops);
-}
-#else
-static void __init tps65090_debuginit(struct tps65090 *tpsi)
-{
- return;
+ if ((reg == TPS65090_INT_STS) || (reg == TPS65090_INT_STS))
+ return true;
+ else
+ return false;
}
-#endif
static const struct regmap_config tps65090_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
+ .max_register = TOTAL_NUM_REG,
+ .num_reg_defaults_raw = TOTAL_NUM_REG,
+ .cache_type = REGCACHE_RBTREE,
+ .volatile_reg = is_volatile_reg,
};
static int __devinit tps65090_i2c_probe(struct i2c_client *client,
@@ -387,10 +271,11 @@ static int __devinit tps65090_i2c_probe(struct i2c_client *client,
if (!pdata) {
dev_err(&client->dev, "tps65090 requires platform data\n");
- return -ENOTSUPP;
+ return -EINVAL;
}
- tps65090 = kzalloc(sizeof(struct tps65090), GFP_KERNEL);
+ tps65090 = devm_kzalloc(&client->dev, sizeof(struct tps65090),
+ GFP_KERNEL);
if (tps65090 == NULL)
return -ENOMEM;
@@ -401,36 +286,39 @@ static int __devinit tps65090_i2c_probe(struct i2c_client *client,
mutex_init(&tps65090->lock);
if (client->irq) {
- ret = tps65090_irq_init(tps65090, client->irq,
- pdata->irq_base);
+ ret = tps65090_irq_init(tps65090, client->irq, pdata->irq_base);
if (ret) {
- dev_err(&client->dev, "IRQ init failed: %d\n", ret);
- goto err_irq_init;
+ dev_err(&client->dev, "IRQ init failed with err: %d\n",
+ ret);
+ goto err_exit;
}
}
- ret = tps65090_add_subdevs(tps65090, pdata);
- if (ret) {
- dev_err(&client->dev, "add devices failed: %d\n", ret);
- goto err_add_devs;
- }
-
tps65090->rmap = regmap_init_i2c(tps65090->client,
&tps65090_regmap_config);
if (IS_ERR(tps65090->rmap)) {
- dev_err(&client->dev, "regmap_init failed: %ld\n",
+ dev_err(&client->dev, "regmap_init failed with err: %ld\n",
PTR_ERR(tps65090->rmap));
- goto err_add_devs;
+ goto err_irq_exit;
};
- tps65090_debuginit(tps65090);
+
+ ret = mfd_add_devices(tps65090->dev, -1, tps65090s,
+ ARRAY_SIZE(tps65090s), NULL, 0);
+ if (ret) {
+ dev_err(&client->dev, "add mfd devices failed with err: %d\n",
+ ret);
+ goto err_regmap_exit;
+ }
return 0;
-err_add_devs:
+err_regmap_exit:
+ regmap_exit(tps65090->rmap);
+
+err_irq_exit:
if (client->irq)
free_irq(client->irq, tps65090);
-err_irq_init:
- kfree(tps65090);
+err_exit:
return ret;
}
@@ -438,13 +326,14 @@ static int __devexit tps65090_i2c_remove(struct i2c_client *client)
{
struct tps65090 *tps65090 = i2c_get_clientdata(client);
+ mfd_remove_devices(tps65090->dev);
+ regmap_exit(tps65090->rmap);
if (client->irq)
free_irq(client->irq, tps65090);
- regmap_exit(tps65090->rmap);
- kfree(tps65090);
return 0;
}
+
#ifdef CONFIG_PM
static int tps65090_i2c_suspend(struct i2c_client *client, pm_message_t state)
{
@@ -461,7 +350,6 @@ static int tps65090_i2c_resume(struct i2c_client *client)
}
#endif
-
static const struct i2c_device_id tps65090_id_table[] = {
{ "tps65090", 0 },
{ },
@@ -495,4 +383,5 @@ static void __exit tps65090_exit(void)
module_exit(tps65090_exit);
MODULE_DESCRIPTION("TPS65090 core driver");
-MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
+MODULE_LICENSE("GPL v2");