^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Andrew F. Davis <afd@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * modify it under the terms of the GNU General Public License version 2 as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * This program is distributed "as is" WITHOUT ANY WARRANTY of any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * kind, whether expressed or implied; without even the implied warranty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * GNU General Public License version 2 for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Based on the TPS65912 driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mfd/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/mfd/tps65086.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static const struct mfd_cell tps65086_cells[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) { .name = "tps65086-regulator", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) { .name = "tps65086-gpio", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static const struct regmap_range tps65086_yes_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) regmap_reg_range(TPS65086_IRQ, TPS65086_IRQ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) regmap_reg_range(TPS65086_PMICSTAT, TPS65086_SHUTDNSRC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) regmap_reg_range(TPS65086_GPOCTRL, TPS65086_GPOCTRL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) regmap_reg_range(TPS65086_PG_STATUS1, TPS65086_OC_STATUS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static const struct regmap_access_table tps65086_volatile_table = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .yes_ranges = tps65086_yes_ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .n_yes_ranges = ARRAY_SIZE(tps65086_yes_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static const struct regmap_config tps65086_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .cache_type = REGCACHE_RBTREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .volatile_table = &tps65086_volatile_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static const struct regmap_irq tps65086_irqs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) REGMAP_IRQ_REG(TPS65086_IRQ_DIETEMP, 0, TPS65086_IRQ_DIETEMP_MASK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) REGMAP_IRQ_REG(TPS65086_IRQ_SHUTDN, 0, TPS65086_IRQ_SHUTDN_MASK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) REGMAP_IRQ_REG(TPS65086_IRQ_FAULT, 0, TPS65086_IRQ_FAULT_MASK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static struct regmap_irq_chip tps65086_irq_chip = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .name = "tps65086",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .status_base = TPS65086_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .mask_base = TPS65086_IRQ_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .ack_base = TPS65086_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .init_ack_masked = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .num_regs = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .irqs = tps65086_irqs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .num_irqs = ARRAY_SIZE(tps65086_irqs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static const struct of_device_id tps65086_of_match_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) { .compatible = "ti,tps65086", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) { /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) MODULE_DEVICE_TABLE(of, tps65086_of_match_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static int tps65086_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) const struct i2c_device_id *ids)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct tps65086 *tps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unsigned int version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (!tps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) i2c_set_clientdata(client, tps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) tps->dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) tps->irq = client->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) tps->regmap = devm_regmap_init_i2c(client, &tps65086_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (IS_ERR(tps->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) dev_err(tps->dev, "Failed to initialize register map\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return PTR_ERR(tps->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ret = regmap_read(tps->regmap, TPS65086_DEVICEID, &version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) dev_err(tps->dev, "Failed to read revision register\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) dev_info(tps->dev, "Device: TPS65086%01lX, OTP: %c, Rev: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) (version & TPS65086_DEVICEID_PART_MASK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) (char)((version & TPS65086_DEVICEID_OTP_MASK) >> 4) + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) (version & TPS65086_DEVICEID_REV_MASK) >> 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ret = regmap_add_irq_chip(tps->regmap, tps->irq, IRQF_ONESHOT, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) &tps65086_irq_chip, &tps->irq_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) dev_err(tps->dev, "Failed to register IRQ chip\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ret = mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO, tps65086_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) ARRAY_SIZE(tps65086_cells), NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) regmap_irq_get_domain(tps->irq_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) regmap_del_irq_chip(tps->irq, tps->irq_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static int tps65086_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct tps65086 *tps = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) regmap_del_irq_chip(tps->irq, tps->irq_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static const struct i2c_device_id tps65086_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) { "tps65086", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) { /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) MODULE_DEVICE_TABLE(i2c, tps65086_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static struct i2c_driver tps65086_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .name = "tps65086",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .of_match_table = tps65086_of_match_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .probe = tps65086_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .remove = tps65086_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .id_table = tps65086_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) module_i2c_driver(tps65086_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) MODULE_DESCRIPTION("TPS65086 PMIC Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) MODULE_LICENSE("GPL v2");