Lines Matching +full:reg +full:- +full:data

1 // SPDX-License-Identifier: GPL-2.0-only
3 * tps6507x-regulator.c
7 * Copyright (C) 2009 Texas Instrument Incorporated - https://www.ti.com/
33 /* Number of step-down converters available */
113 static inline int tps6507x_pmic_read(struct tps6507x_pmic *tps, u8 reg) in tps6507x_pmic_read() argument
118 err = tps->mfd->read_dev(tps->mfd, reg, 1, &val); in tps6507x_pmic_read()
126 static inline int tps6507x_pmic_write(struct tps6507x_pmic *tps, u8 reg, u8 val) in tps6507x_pmic_write() argument
128 return tps->mfd->write_dev(tps->mfd, reg, 1, &val); in tps6507x_pmic_write()
131 static int tps6507x_pmic_set_bits(struct tps6507x_pmic *tps, u8 reg, u8 mask) in tps6507x_pmic_set_bits() argument
133 int err, data; in tps6507x_pmic_set_bits() local
135 mutex_lock(&tps->io_lock); in tps6507x_pmic_set_bits()
137 data = tps6507x_pmic_read(tps, reg); in tps6507x_pmic_set_bits()
138 if (data < 0) { in tps6507x_pmic_set_bits()
139 dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg); in tps6507x_pmic_set_bits()
140 err = data; in tps6507x_pmic_set_bits()
144 data |= mask; in tps6507x_pmic_set_bits()
145 err = tps6507x_pmic_write(tps, reg, data); in tps6507x_pmic_set_bits()
147 dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg); in tps6507x_pmic_set_bits()
150 mutex_unlock(&tps->io_lock); in tps6507x_pmic_set_bits()
154 static int tps6507x_pmic_clear_bits(struct tps6507x_pmic *tps, u8 reg, u8 mask) in tps6507x_pmic_clear_bits() argument
156 int err, data; in tps6507x_pmic_clear_bits() local
158 mutex_lock(&tps->io_lock); in tps6507x_pmic_clear_bits()
160 data = tps6507x_pmic_read(tps, reg); in tps6507x_pmic_clear_bits()
161 if (data < 0) { in tps6507x_pmic_clear_bits()
162 dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg); in tps6507x_pmic_clear_bits()
163 err = data; in tps6507x_pmic_clear_bits()
167 data &= ~mask; in tps6507x_pmic_clear_bits()
168 err = tps6507x_pmic_write(tps, reg, data); in tps6507x_pmic_clear_bits()
170 dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg); in tps6507x_pmic_clear_bits()
173 mutex_unlock(&tps->io_lock); in tps6507x_pmic_clear_bits()
177 static int tps6507x_pmic_reg_read(struct tps6507x_pmic *tps, u8 reg) in tps6507x_pmic_reg_read() argument
179 int data; in tps6507x_pmic_reg_read() local
181 mutex_lock(&tps->io_lock); in tps6507x_pmic_reg_read()
183 data = tps6507x_pmic_read(tps, reg); in tps6507x_pmic_reg_read()
184 if (data < 0) in tps6507x_pmic_reg_read()
185 dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg); in tps6507x_pmic_reg_read()
187 mutex_unlock(&tps->io_lock); in tps6507x_pmic_reg_read()
188 return data; in tps6507x_pmic_reg_read()
191 static int tps6507x_pmic_reg_write(struct tps6507x_pmic *tps, u8 reg, u8 val) in tps6507x_pmic_reg_write() argument
195 mutex_lock(&tps->io_lock); in tps6507x_pmic_reg_write()
197 err = tps6507x_pmic_write(tps, reg, val); in tps6507x_pmic_reg_write()
199 dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg); in tps6507x_pmic_reg_write()
201 mutex_unlock(&tps->io_lock); in tps6507x_pmic_reg_write()
208 int data, rid = rdev_get_id(dev); in tps6507x_pmic_is_enabled() local
212 return -EINVAL; in tps6507x_pmic_is_enabled()
214 shift = TPS6507X_MAX_REG_ID - rid; in tps6507x_pmic_is_enabled()
215 data = tps6507x_pmic_reg_read(tps, TPS6507X_REG_CON_CTRL1); in tps6507x_pmic_is_enabled()
217 if (data < 0) in tps6507x_pmic_is_enabled()
218 return data; in tps6507x_pmic_is_enabled()
220 return (data & 1<<shift) ? 1 : 0; in tps6507x_pmic_is_enabled()
230 return -EINVAL; in tps6507x_pmic_enable()
232 shift = TPS6507X_MAX_REG_ID - rid; in tps6507x_pmic_enable()
243 return -EINVAL; in tps6507x_pmic_disable()
245 shift = TPS6507X_MAX_REG_ID - rid; in tps6507x_pmic_disable()
253 int data, rid = rdev_get_id(dev); in tps6507x_pmic_get_voltage_sel() local
254 u8 reg, mask; in tps6507x_pmic_get_voltage_sel() local
258 reg = TPS6507X_REG_DEFDCDC1; in tps6507x_pmic_get_voltage_sel()
262 if (tps->info[rid]->defdcdc_default) in tps6507x_pmic_get_voltage_sel()
263 reg = TPS6507X_REG_DEFDCDC2_HIGH; in tps6507x_pmic_get_voltage_sel()
265 reg = TPS6507X_REG_DEFDCDC2_LOW; in tps6507x_pmic_get_voltage_sel()
269 if (tps->info[rid]->defdcdc_default) in tps6507x_pmic_get_voltage_sel()
270 reg = TPS6507X_REG_DEFDCDC3_HIGH; in tps6507x_pmic_get_voltage_sel()
272 reg = TPS6507X_REG_DEFDCDC3_LOW; in tps6507x_pmic_get_voltage_sel()
276 reg = TPS6507X_REG_LDO_CTRL1; in tps6507x_pmic_get_voltage_sel()
280 reg = TPS6507X_REG_DEFLDO2; in tps6507x_pmic_get_voltage_sel()
284 return -EINVAL; in tps6507x_pmic_get_voltage_sel()
287 data = tps6507x_pmic_reg_read(tps, reg); in tps6507x_pmic_get_voltage_sel()
288 if (data < 0) in tps6507x_pmic_get_voltage_sel()
289 return data; in tps6507x_pmic_get_voltage_sel()
291 data &= mask; in tps6507x_pmic_get_voltage_sel()
292 return data; in tps6507x_pmic_get_voltage_sel()
299 int data, rid = rdev_get_id(dev); in tps6507x_pmic_set_voltage_sel() local
300 u8 reg, mask; in tps6507x_pmic_set_voltage_sel() local
304 reg = TPS6507X_REG_DEFDCDC1; in tps6507x_pmic_set_voltage_sel()
308 if (tps->info[rid]->defdcdc_default) in tps6507x_pmic_set_voltage_sel()
309 reg = TPS6507X_REG_DEFDCDC2_HIGH; in tps6507x_pmic_set_voltage_sel()
311 reg = TPS6507X_REG_DEFDCDC2_LOW; in tps6507x_pmic_set_voltage_sel()
315 if (tps->info[rid]->defdcdc_default) in tps6507x_pmic_set_voltage_sel()
316 reg = TPS6507X_REG_DEFDCDC3_HIGH; in tps6507x_pmic_set_voltage_sel()
318 reg = TPS6507X_REG_DEFDCDC3_LOW; in tps6507x_pmic_set_voltage_sel()
322 reg = TPS6507X_REG_LDO_CTRL1; in tps6507x_pmic_set_voltage_sel()
326 reg = TPS6507X_REG_DEFLDO2; in tps6507x_pmic_set_voltage_sel()
330 return -EINVAL; in tps6507x_pmic_set_voltage_sel()
333 data = tps6507x_pmic_reg_read(tps, reg); in tps6507x_pmic_set_voltage_sel()
334 if (data < 0) in tps6507x_pmic_set_voltage_sel()
335 return data; in tps6507x_pmic_set_voltage_sel()
337 data &= ~mask; in tps6507x_pmic_set_voltage_sel()
338 data |= selector; in tps6507x_pmic_set_voltage_sel()
340 return tps6507x_pmic_reg_write(tps, reg, data); in tps6507x_pmic_set_voltage_sel()
357 struct tps6507x_pmic *tps = config->driver_data; in tps6507x_pmic_of_parse_cb()
358 struct tps_info *info = tps->info[desc->id]; in tps6507x_pmic_of_parse_cb()
364 info->defdcdc_default = prop; in tps6507x_pmic_of_parse_cb()
371 struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent); in tps6507x_pmic_probe()
382 * coming from the board-evm file. in tps6507x_pmic_probe()
385 tps_board = dev_get_platdata(tps6507x_dev->dev); in tps6507x_pmic_probe()
387 init_data = tps_board->tps6507x_pmic_init_data; in tps6507x_pmic_probe()
389 tps = devm_kzalloc(&pdev->dev, sizeof(*tps), GFP_KERNEL); in tps6507x_pmic_probe()
391 return -ENOMEM; in tps6507x_pmic_probe()
393 mutex_init(&tps->io_lock); in tps6507x_pmic_probe()
396 tps->mfd = tps6507x_dev; in tps6507x_pmic_probe()
400 tps->info[i] = info; in tps6507x_pmic_probe()
402 struct tps6507x_reg_platform_data *data = in tps6507x_pmic_probe() local
404 info->defdcdc_default = data->defdcdc_default; in tps6507x_pmic_probe()
407 tps->desc[i].name = info->name; in tps6507x_pmic_probe()
408 tps->desc[i].of_match = of_match_ptr(info->name); in tps6507x_pmic_probe()
409 tps->desc[i].regulators_node = of_match_ptr("regulators"); in tps6507x_pmic_probe()
410 tps->desc[i].of_parse_cb = tps6507x_pmic_of_parse_cb; in tps6507x_pmic_probe()
411 tps->desc[i].id = i; in tps6507x_pmic_probe()
412 tps->desc[i].n_voltages = info->table_len; in tps6507x_pmic_probe()
413 tps->desc[i].volt_table = info->table; in tps6507x_pmic_probe()
414 tps->desc[i].ops = &tps6507x_pmic_ops; in tps6507x_pmic_probe()
415 tps->desc[i].type = REGULATOR_VOLTAGE; in tps6507x_pmic_probe()
416 tps->desc[i].owner = THIS_MODULE; in tps6507x_pmic_probe()
418 config.dev = tps6507x_dev->dev; in tps6507x_pmic_probe()
422 rdev = devm_regulator_register(&pdev->dev, &tps->desc[i], in tps6507x_pmic_probe()
425 dev_err(tps6507x_dev->dev, in tps6507x_pmic_probe()
427 pdev->name); in tps6507x_pmic_probe()
432 tps6507x_dev->pmic = tps; in tps6507x_pmic_probe()
440 .name = "tps6507x-pmic",
461 MODULE_ALIAS("platform:tps6507x-pmic");