0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/i2c.h>
0010 #include <linux/interrupt.h>
0011 #include <linux/mfd/core.h>
0012 #include <linux/module.h>
0013
0014 #include <linux/mfd/tps65086.h>
0015
0016 static const struct mfd_cell tps65086_cells[] = {
0017 { .name = "tps65086-regulator", },
0018 { .name = "tps65086-gpio", },
0019 { .name = "tps65086-reset", },
0020 };
0021
0022 static const struct regmap_range tps65086_yes_ranges[] = {
0023 regmap_reg_range(TPS65086_IRQ, TPS65086_IRQ),
0024 regmap_reg_range(TPS65086_PMICSTAT, TPS65086_SHUTDNSRC),
0025 regmap_reg_range(TPS65086_GPOCTRL, TPS65086_GPOCTRL),
0026 regmap_reg_range(TPS65086_PG_STATUS1, TPS65086_OC_STATUS),
0027 };
0028
0029 static const struct regmap_access_table tps65086_volatile_table = {
0030 .yes_ranges = tps65086_yes_ranges,
0031 .n_yes_ranges = ARRAY_SIZE(tps65086_yes_ranges),
0032 };
0033
0034 static const struct regmap_config tps65086_regmap_config = {
0035 .reg_bits = 8,
0036 .val_bits = 8,
0037 .cache_type = REGCACHE_RBTREE,
0038 .volatile_table = &tps65086_volatile_table,
0039 };
0040
0041 static const struct regmap_irq tps65086_irqs[] = {
0042 REGMAP_IRQ_REG(TPS65086_IRQ_DIETEMP, 0, TPS65086_IRQ_DIETEMP_MASK),
0043 REGMAP_IRQ_REG(TPS65086_IRQ_SHUTDN, 0, TPS65086_IRQ_SHUTDN_MASK),
0044 REGMAP_IRQ_REG(TPS65086_IRQ_FAULT, 0, TPS65086_IRQ_FAULT_MASK),
0045 };
0046
0047 static struct regmap_irq_chip tps65086_irq_chip = {
0048 .name = "tps65086",
0049 .status_base = TPS65086_IRQ,
0050 .mask_base = TPS65086_IRQ_MASK,
0051 .ack_base = TPS65086_IRQ,
0052 .init_ack_masked = true,
0053 .num_regs = 1,
0054 .irqs = tps65086_irqs,
0055 .num_irqs = ARRAY_SIZE(tps65086_irqs),
0056 };
0057
0058 static const struct of_device_id tps65086_of_match_table[] = {
0059 { .compatible = "ti,tps65086", },
0060 { }
0061 };
0062 MODULE_DEVICE_TABLE(of, tps65086_of_match_table);
0063
0064 static int tps65086_probe(struct i2c_client *client,
0065 const struct i2c_device_id *ids)
0066 {
0067 struct tps65086 *tps;
0068 unsigned int version;
0069 int ret;
0070
0071 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
0072 if (!tps)
0073 return -ENOMEM;
0074
0075 i2c_set_clientdata(client, tps);
0076 tps->dev = &client->dev;
0077 tps->irq = client->irq;
0078
0079 tps->regmap = devm_regmap_init_i2c(client, &tps65086_regmap_config);
0080 if (IS_ERR(tps->regmap)) {
0081 dev_err(tps->dev, "Failed to initialize register map\n");
0082 return PTR_ERR(tps->regmap);
0083 }
0084
0085 ret = regmap_read(tps->regmap, TPS65086_DEVICEID, &version);
0086 if (ret) {
0087 dev_err(tps->dev, "Failed to read revision register\n");
0088 return ret;
0089 }
0090
0091 dev_info(tps->dev, "Device: TPS65086%01lX, OTP: %c, Rev: %ld\n",
0092 (version & TPS65086_DEVICEID_PART_MASK),
0093 (char)((version & TPS65086_DEVICEID_OTP_MASK) >> 4) + 'A',
0094 (version & TPS65086_DEVICEID_REV_MASK) >> 6);
0095
0096 if (tps->irq > 0) {
0097 ret = regmap_add_irq_chip(tps->regmap, tps->irq, IRQF_ONESHOT, 0,
0098 &tps65086_irq_chip, &tps->irq_data);
0099 if (ret) {
0100 dev_err(tps->dev, "Failed to register IRQ chip\n");
0101 return ret;
0102 }
0103 }
0104
0105 ret = mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO, tps65086_cells,
0106 ARRAY_SIZE(tps65086_cells), NULL, 0,
0107 regmap_irq_get_domain(tps->irq_data));
0108 if (ret && tps->irq > 0)
0109 regmap_del_irq_chip(tps->irq, tps->irq_data);
0110
0111 return ret;
0112 }
0113
0114 static int tps65086_remove(struct i2c_client *client)
0115 {
0116 struct tps65086 *tps = i2c_get_clientdata(client);
0117
0118 if (tps->irq > 0)
0119 regmap_del_irq_chip(tps->irq, tps->irq_data);
0120
0121 return 0;
0122 }
0123
0124 static const struct i2c_device_id tps65086_id_table[] = {
0125 { "tps65086", 0 },
0126 { }
0127 };
0128 MODULE_DEVICE_TABLE(i2c, tps65086_id_table);
0129
0130 static struct i2c_driver tps65086_driver = {
0131 .driver = {
0132 .name = "tps65086",
0133 .of_match_table = tps65086_of_match_table,
0134 },
0135 .probe = tps65086_probe,
0136 .remove = tps65086_remove,
0137 .id_table = tps65086_id_table,
0138 };
0139 module_i2c_driver(tps65086_driver);
0140
0141 MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
0142 MODULE_DESCRIPTION("TPS65086 PMIC Driver");
0143 MODULE_LICENSE("GPL v2");