Skip to content

Commit 91020ae

Browse files
Bhargav Raviprakashlag-linaro
authored andcommitted
misc: tps6594-pfsm: Add TI TPS65224 PMIC PFSM
Add support for TPS65224 PFSM in the TPS6594 PFSM driver as they share significant functionality. Signed-off-by: Bhargav Raviprakash <bhargav.r@ltts.com> Acked-by: Julien Panis <jpanis@baylibre.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/0109018f2fdc9dc4-db5a45c0-0148-48cc-8462-d1c5b577a4bd-000000@ap-south-1.amazonses.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 9d855b8 commit 91020ae

1 file changed

Lines changed: 35 additions & 13 deletions

File tree

drivers/misc/tps6594-pfsm.c

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/*
3-
* PFSM (Pre-configurable Finite State Machine) driver for TI TPS6594/TPS6593/LP8764 PMICs
3+
* PFSM (Pre-configurable Finite State Machine) driver for TI TPS65224/TPS6594/TPS6593/LP8764 PMICs
44
*
55
* Copyright (C) 2023 BayLibre Incorporated - https://www.baylibre.com/
66
*/
@@ -39,10 +39,12 @@
3939
*
4040
* @miscdev: misc device infos
4141
* @regmap: regmap for accessing the device registers
42+
* @chip_id: chip identifier of the device
4243
*/
4344
struct tps6594_pfsm {
4445
struct miscdevice miscdev;
4546
struct regmap *regmap;
47+
unsigned long chip_id;
4648
};
4749

4850
static ssize_t tps6594_pfsm_read(struct file *f, char __user *buf,
@@ -133,21 +135,29 @@ static long tps6594_pfsm_ioctl(struct file *f, unsigned int cmd, unsigned long a
133135
struct tps6594_pfsm *pfsm = TPS6594_FILE_TO_PFSM(f);
134136
struct pmic_state_opt state_opt;
135137
void __user *argp = (void __user *)arg;
138+
unsigned int regmap_reg, mask;
136139
int ret = -ENOIOCTLCMD;
137140

138141
switch (cmd) {
139142
case PMIC_GOTO_STANDBY:
140-
/* Disable LP mode */
141-
ret = regmap_clear_bits(pfsm->regmap, TPS6594_REG_RTC_CTRL_2,
142-
TPS6594_BIT_LP_STANDBY_SEL);
143-
if (ret)
144-
return ret;
143+
/* Disable LP mode on TPS6594 Family PMIC */
144+
if (pfsm->chip_id != TPS65224) {
145+
ret = regmap_clear_bits(pfsm->regmap, TPS6594_REG_RTC_CTRL_2,
146+
TPS6594_BIT_LP_STANDBY_SEL);
147+
148+
if (ret)
149+
return ret;
150+
}
145151

146152
/* Force trigger */
147153
ret = regmap_write_bits(pfsm->regmap, TPS6594_REG_FSM_I2C_TRIGGERS,
148154
TPS6594_BIT_TRIGGER_I2C(0), TPS6594_BIT_TRIGGER_I2C(0));
149155
break;
150156
case PMIC_GOTO_LP_STANDBY:
157+
/* TPS65224 does not support LP STANDBY */
158+
if (pfsm->chip_id == TPS65224)
159+
return ret;
160+
151161
/* Enable LP mode */
152162
ret = regmap_set_bits(pfsm->regmap, TPS6594_REG_RTC_CTRL_2,
153163
TPS6594_BIT_LP_STANDBY_SEL);
@@ -169,6 +179,10 @@ static long tps6594_pfsm_ioctl(struct file *f, unsigned int cmd, unsigned long a
169179
TPS6594_BIT_NSLEEP1B | TPS6594_BIT_NSLEEP2B);
170180
break;
171181
case PMIC_SET_MCU_ONLY_STATE:
182+
/* TPS65224 does not support MCU_ONLY_STATE */
183+
if (pfsm->chip_id == TPS65224)
184+
return ret;
185+
172186
if (copy_from_user(&state_opt, argp, sizeof(state_opt)))
173187
return -EFAULT;
174188

@@ -192,14 +206,20 @@ static long tps6594_pfsm_ioctl(struct file *f, unsigned int cmd, unsigned long a
192206
return -EFAULT;
193207

194208
/* Configure wake-up destination */
209+
if (pfsm->chip_id == TPS65224) {
210+
regmap_reg = TPS65224_REG_STARTUP_CTRL;
211+
mask = TPS65224_MASK_STARTUP_DEST;
212+
} else {
213+
regmap_reg = TPS6594_REG_RTC_CTRL_2;
214+
mask = TPS6594_MASK_STARTUP_DEST;
215+
}
216+
195217
if (state_opt.mcu_only_startup_dest)
196-
ret = regmap_write_bits(pfsm->regmap, TPS6594_REG_RTC_CTRL_2,
197-
TPS6594_MASK_STARTUP_DEST,
198-
TPS6594_STARTUP_DEST_MCU_ONLY);
218+
ret = regmap_write_bits(pfsm->regmap, regmap_reg,
219+
mask, TPS6594_STARTUP_DEST_MCU_ONLY);
199220
else
200-
ret = regmap_write_bits(pfsm->regmap, TPS6594_REG_RTC_CTRL_2,
201-
TPS6594_MASK_STARTUP_DEST,
202-
TPS6594_STARTUP_DEST_ACTIVE);
221+
ret = regmap_write_bits(pfsm->regmap, regmap_reg,
222+
mask, TPS6594_STARTUP_DEST_ACTIVE);
203223
if (ret)
204224
return ret;
205225

@@ -211,7 +231,8 @@ static long tps6594_pfsm_ioctl(struct file *f, unsigned int cmd, unsigned long a
211231

212232
/* Modify NSLEEP1-2 bits */
213233
ret = regmap_clear_bits(pfsm->regmap, TPS6594_REG_FSM_NSLEEP_TRIGGERS,
214-
TPS6594_BIT_NSLEEP2B);
234+
pfsm->chip_id == TPS65224 ?
235+
TPS6594_BIT_NSLEEP1B : TPS6594_BIT_NSLEEP2B);
215236
break;
216237
}
217238

@@ -262,6 +283,7 @@ static int tps6594_pfsm_probe(struct platform_device *pdev)
262283
tps->chip_id, tps->reg);
263284
pfsm->miscdev.fops = &tps6594_pfsm_fops;
264285
pfsm->miscdev.parent = dev->parent;
286+
pfsm->chip_id = tps->chip_id;
265287

266288
for (i = 0 ; i < pdev->num_resources ; i++) {
267289
irq = platform_get_irq_byname(pdev, pdev->resource[i].name);

0 commit comments

Comments
 (0)