linux/drivers/mfd/tps65090.c
<<
>>
Prefs
   1/*
   2 * Core driver for TI TPS65090 PMIC family
   3 *
   4 * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
   5
   6 * This program is free software; you can redistribute it and/or modify it
   7 * under the terms and conditions of the GNU General Public License,
   8 * version 2, as published by the Free Software Foundation.
   9
  10 * This program is distributed in the hope it will be useful, but WITHOUT
  11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  13 * more details.
  14
  15 * You should have received a copy of the GNU General Public License
  16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17 */
  18
  19#include <linux/interrupt.h>
  20#include <linux/irq.h>
  21#include <linux/kernel.h>
  22#include <linux/module.h>
  23#include <linux/mutex.h>
  24#include <linux/slab.h>
  25#include <linux/i2c.h>
  26#include <linux/mfd/core.h>
  27#include <linux/mfd/tps65090.h>
  28#include <linux/err.h>
  29
  30#define NUM_INT_REG 2
  31#define TOTAL_NUM_REG 0x18
  32
  33/* interrupt status registers */
  34#define TPS65090_INT_STS        0x0
  35#define TPS65090_INT_STS2       0x1
  36
  37/* interrupt mask registers */
  38#define TPS65090_INT_MSK        0x2
  39#define TPS65090_INT_MSK2       0x3
  40
  41#define TPS65090_INT1_MASK_VAC_STATUS_CHANGE            1
  42#define TPS65090_INT1_MASK_VSYS_STATUS_CHANGE           2
  43#define TPS65090_INT1_MASK_BAT_STATUS_CHANGE            3
  44#define TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE       4
  45#define TPS65090_INT1_MASK_CHARGING_COMPLETE            5
  46#define TPS65090_INT1_MASK_OVERLOAD_DCDC1               6
  47#define TPS65090_INT1_MASK_OVERLOAD_DCDC2               7
  48#define TPS65090_INT2_MASK_OVERLOAD_DCDC3               0
  49#define TPS65090_INT2_MASK_OVERLOAD_FET1                1
  50#define TPS65090_INT2_MASK_OVERLOAD_FET2                2
  51#define TPS65090_INT2_MASK_OVERLOAD_FET3                3
  52#define TPS65090_INT2_MASK_OVERLOAD_FET4                4
  53#define TPS65090_INT2_MASK_OVERLOAD_FET5                5
  54#define TPS65090_INT2_MASK_OVERLOAD_FET6                6
  55#define TPS65090_INT2_MASK_OVERLOAD_FET7                7
  56
  57static struct mfd_cell tps65090s[] = {
  58        {
  59                .name = "tps65090-pmic",
  60        },
  61        {
  62                .name = "tps65090-charger",
  63        },
  64};
  65
  66static const struct regmap_irq tps65090_irqs[] = {
  67        /* INT1 IRQs*/
  68        [TPS65090_IRQ_VAC_STATUS_CHANGE] = {
  69                        .mask = TPS65090_INT1_MASK_VAC_STATUS_CHANGE,
  70        },
  71        [TPS65090_IRQ_VSYS_STATUS_CHANGE] = {
  72                        .mask = TPS65090_INT1_MASK_VSYS_STATUS_CHANGE,
  73        },
  74        [TPS65090_IRQ_BAT_STATUS_CHANGE] = {
  75                        .mask = TPS65090_INT1_MASK_BAT_STATUS_CHANGE,
  76        },
  77        [TPS65090_IRQ_CHARGING_STATUS_CHANGE] = {
  78                        .mask = TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE,
  79        },
  80        [TPS65090_IRQ_CHARGING_COMPLETE] = {
  81                        .mask = TPS65090_INT1_MASK_CHARGING_COMPLETE,
  82        },
  83        [TPS65090_IRQ_OVERLOAD_DCDC1] = {
  84                        .mask = TPS65090_INT1_MASK_OVERLOAD_DCDC1,
  85        },
  86        [TPS65090_IRQ_OVERLOAD_DCDC2] = {
  87                        .mask = TPS65090_INT1_MASK_OVERLOAD_DCDC2,
  88        },
  89        /* INT2 IRQs*/
  90        [TPS65090_IRQ_OVERLOAD_DCDC3] = {
  91                        .reg_offset = 1,
  92                        .mask = TPS65090_INT2_MASK_OVERLOAD_DCDC3,
  93        },
  94        [TPS65090_IRQ_OVERLOAD_FET1] = {
  95                        .reg_offset = 1,
  96                        .mask = TPS65090_INT2_MASK_OVERLOAD_FET1,
  97        },
  98        [TPS65090_IRQ_OVERLOAD_FET2] = {
  99                        .reg_offset = 1,
 100                        .mask = TPS65090_INT2_MASK_OVERLOAD_FET2,
 101        },
 102        [TPS65090_IRQ_OVERLOAD_FET3] = {
 103                        .reg_offset = 1,
 104                        .mask = TPS65090_INT2_MASK_OVERLOAD_FET3,
 105        },
 106        [TPS65090_IRQ_OVERLOAD_FET4] = {
 107                        .reg_offset = 1,
 108                        .mask = TPS65090_INT2_MASK_OVERLOAD_FET4,
 109        },
 110        [TPS65090_IRQ_OVERLOAD_FET5] = {
 111                        .reg_offset = 1,
 112                        .mask = TPS65090_INT2_MASK_OVERLOAD_FET5,
 113        },
 114        [TPS65090_IRQ_OVERLOAD_FET6] = {
 115                        .reg_offset = 1,
 116                        .mask = TPS65090_INT2_MASK_OVERLOAD_FET6,
 117        },
 118        [TPS65090_IRQ_OVERLOAD_FET7] = {
 119                        .reg_offset = 1,
 120                        .mask = TPS65090_INT2_MASK_OVERLOAD_FET7,
 121        },
 122};
 123
 124static struct regmap_irq_chip tps65090_irq_chip = {
 125        .name = "tps65090",
 126        .irqs = tps65090_irqs,
 127        .num_irqs = ARRAY_SIZE(tps65090_irqs),
 128        .num_regs = NUM_INT_REG,
 129        .status_base = TPS65090_INT_STS,
 130        .mask_base = TPS65090_INT_MSK,
 131        .mask_invert = true,
 132};
 133
 134static bool is_volatile_reg(struct device *dev, unsigned int reg)
 135{
 136        if ((reg == TPS65090_INT_STS) || (reg == TPS65090_INT_STS2))
 137                return true;
 138        else
 139                return false;
 140}
 141
 142static const struct regmap_config tps65090_regmap_config = {
 143        .reg_bits = 8,
 144        .val_bits = 8,
 145        .max_register = TOTAL_NUM_REG,
 146        .num_reg_defaults_raw = TOTAL_NUM_REG,
 147        .cache_type = REGCACHE_RBTREE,
 148        .volatile_reg = is_volatile_reg,
 149};
 150
 151static int tps65090_i2c_probe(struct i2c_client *client,
 152                                        const struct i2c_device_id *id)
 153{
 154        struct tps65090_platform_data *pdata = client->dev.platform_data;
 155        struct tps65090 *tps65090;
 156        int ret;
 157
 158        if (!pdata) {
 159                dev_err(&client->dev, "tps65090 requires platform data\n");
 160                return -EINVAL;
 161        }
 162
 163        tps65090 = devm_kzalloc(&client->dev, sizeof(*tps65090), GFP_KERNEL);
 164        if (!tps65090) {
 165                dev_err(&client->dev, "mem alloc for tps65090 failed\n");
 166                return -ENOMEM;
 167        }
 168
 169        tps65090->dev = &client->dev;
 170        i2c_set_clientdata(client, tps65090);
 171
 172        tps65090->rmap = devm_regmap_init_i2c(client, &tps65090_regmap_config);
 173        if (IS_ERR(tps65090->rmap)) {
 174                ret = PTR_ERR(tps65090->rmap);
 175                dev_err(&client->dev, "regmap_init failed with err: %d\n", ret);
 176                return ret;
 177        }
 178
 179        if (client->irq) {
 180                ret = regmap_add_irq_chip(tps65090->rmap, client->irq,
 181                        IRQF_ONESHOT | IRQF_TRIGGER_LOW, pdata->irq_base,
 182                        &tps65090_irq_chip, &tps65090->irq_data);
 183                        if (ret) {
 184                                dev_err(&client->dev,
 185                                        "IRQ init failed with err: %d\n", ret);
 186                        return ret;
 187                }
 188        }
 189
 190        ret = mfd_add_devices(tps65090->dev, -1, tps65090s,
 191                ARRAY_SIZE(tps65090s), NULL,
 192                regmap_irq_chip_get_base(tps65090->irq_data), NULL);
 193        if (ret) {
 194                dev_err(&client->dev, "add mfd devices failed with err: %d\n",
 195                        ret);
 196                goto err_irq_exit;
 197        }
 198
 199        return 0;
 200
 201err_irq_exit:
 202        if (client->irq)
 203                regmap_del_irq_chip(client->irq, tps65090->irq_data);
 204        return ret;
 205}
 206
 207static int tps65090_i2c_remove(struct i2c_client *client)
 208{
 209        struct tps65090 *tps65090 = i2c_get_clientdata(client);
 210
 211        mfd_remove_devices(tps65090->dev);
 212        if (client->irq)
 213                regmap_del_irq_chip(client->irq, tps65090->irq_data);
 214
 215        return 0;
 216}
 217
 218#ifdef CONFIG_PM_SLEEP
 219static int tps65090_suspend(struct device *dev)
 220{
 221        struct i2c_client *client = to_i2c_client(dev);
 222        if (client->irq)
 223                disable_irq(client->irq);
 224        return 0;
 225}
 226
 227static int tps65090_resume(struct device *dev)
 228{
 229        struct i2c_client *client = to_i2c_client(dev);
 230        if (client->irq)
 231                enable_irq(client->irq);
 232        return 0;
 233}
 234#endif
 235
 236static const struct dev_pm_ops tps65090_pm_ops = {
 237        SET_SYSTEM_SLEEP_PM_OPS(tps65090_suspend, tps65090_resume)
 238};
 239
 240static const struct i2c_device_id tps65090_id_table[] = {
 241        { "tps65090", 0 },
 242        { },
 243};
 244MODULE_DEVICE_TABLE(i2c, tps65090_id_table);
 245
 246static struct i2c_driver tps65090_driver = {
 247        .driver = {
 248                .name   = "tps65090",
 249                .owner  = THIS_MODULE,
 250                .pm     = &tps65090_pm_ops,
 251        },
 252        .probe          = tps65090_i2c_probe,
 253        .remove         = tps65090_i2c_remove,
 254        .id_table       = tps65090_id_table,
 255};
 256
 257static int __init tps65090_init(void)
 258{
 259        return i2c_add_driver(&tps65090_driver);
 260}
 261subsys_initcall(tps65090_init);
 262
 263static void __exit tps65090_exit(void)
 264{
 265        i2c_del_driver(&tps65090_driver);
 266}
 267module_exit(tps65090_exit);
 268
 269MODULE_DESCRIPTION("TPS65090 core driver");
 270MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
 271MODULE_LICENSE("GPL v2");
 272
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.