Lines Matching +full:da9150 +full:- +full:gpadc
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * DA9150 Core MFD Driver
19 #include <linux/mfd/da9150/core.h>
20 #include <linux/mfd/da9150/registers.h>
35 xfer.addr = client->addr; in da9150_i2c_read_device()
40 ret = i2c_transfer(client->adapter, &xfer, 1); in da9150_i2c_read_device()
45 return -EIO; in da9150_i2c_read_device()
49 xfer.addr = client->addr; in da9150_i2c_read_device()
54 ret = i2c_transfer(client->adapter, &xfer, 1); in da9150_i2c_read_device()
60 return -EIO; in da9150_i2c_read_device()
72 return -ENOMEM; in da9150_i2c_write_device()
78 xfer.addr = client->addr; in da9150_i2c_write_device()
83 ret = i2c_transfer(client->adapter, &xfer, 1); in da9150_i2c_write_device()
90 return -EIO; in da9150_i2c_write_device()
177 void da9150_read_qif(struct da9150 *da9150, u8 addr, int count, u8 *buf) in da9150_read_qif() argument
181 ret = da9150_i2c_read_device(da9150->core_qif, addr, count, buf); in da9150_read_qif()
183 dev_err(da9150->dev, "Failed to read from QIF 0x%x: %d\n", in da9150_read_qif()
188 void da9150_write_qif(struct da9150 *da9150, u8 addr, int count, const u8 *buf) in da9150_write_qif() argument
192 ret = da9150_i2c_write_device(da9150->core_qif, addr, count, buf); in da9150_write_qif()
194 dev_err(da9150->dev, "Failed to write to QIF 0x%x: %d\n", in da9150_write_qif()
199 u8 da9150_reg_read(struct da9150 *da9150, u16 reg) in da9150_reg_read() argument
203 ret = regmap_read(da9150->regmap, reg, &val); in da9150_reg_read()
205 dev_err(da9150->dev, "Failed to read from reg 0x%x: %d\n", in da9150_reg_read()
212 void da9150_reg_write(struct da9150 *da9150, u16 reg, u8 val) in da9150_reg_write() argument
216 ret = regmap_write(da9150->regmap, reg, val); in da9150_reg_write()
218 dev_err(da9150->dev, "Failed to write to reg 0x%x: %d\n", in da9150_reg_write()
223 void da9150_set_bits(struct da9150 *da9150, u16 reg, u8 mask, u8 val) in da9150_set_bits() argument
227 ret = regmap_update_bits(da9150->regmap, reg, mask, val); in da9150_set_bits()
229 dev_err(da9150->dev, "Failed to set bits in reg 0x%x: %d\n", in da9150_set_bits()
234 void da9150_bulk_read(struct da9150 *da9150, u16 reg, int count, u8 *buf) in da9150_bulk_read() argument
238 ret = regmap_bulk_read(da9150->regmap, reg, buf, count); in da9150_bulk_read()
240 dev_err(da9150->dev, "Failed to bulk read from reg 0x%x: %d\n", in da9150_bulk_read()
245 void da9150_bulk_write(struct da9150 *da9150, u16 reg, int count, const u8 *buf) in da9150_bulk_write() argument
249 ret = regmap_raw_write(da9150->regmap, reg, buf, count); in da9150_bulk_write()
251 dev_err(da9150->dev, "Failed to bulk write to reg 0x%x %d\n", in da9150_bulk_write()
354 DEFINE_RES_IRQ_NAMED(DA9150_IRQ_GPADC, "GPADC"),
376 .name = "da9150-gpadc",
377 .of_compatible = "dlg,da9150-gpadc",
382 .name = "da9150-charger",
383 .of_compatible = "dlg,da9150-charger",
388 .name = "da9150-fuel-gauge",
389 .of_compatible = "dlg,da9150-fuel-gauge",
397 struct da9150 *da9150; in da9150_probe() local
398 struct da9150_pdata *pdata = dev_get_platdata(&client->dev); in da9150_probe()
402 da9150 = devm_kzalloc(&client->dev, sizeof(*da9150), GFP_KERNEL); in da9150_probe()
403 if (!da9150) in da9150_probe()
404 return -ENOMEM; in da9150_probe()
406 da9150->dev = &client->dev; in da9150_probe()
407 da9150->irq = client->irq; in da9150_probe()
408 i2c_set_clientdata(client, da9150); in da9150_probe()
410 da9150->regmap = devm_regmap_init_i2c(client, &da9150_regmap_config); in da9150_probe()
411 if (IS_ERR(da9150->regmap)) { in da9150_probe()
412 ret = PTR_ERR(da9150->regmap); in da9150_probe()
413 dev_err(da9150->dev, "Failed to allocate register map: %d\n", in da9150_probe()
419 qif_addr = da9150_reg_read(da9150, DA9150_CORE2WIRE_CTRL_A); in da9150_probe()
422 da9150->core_qif = i2c_new_dummy_device(client->adapter, qif_addr); in da9150_probe()
423 if (IS_ERR(da9150->core_qif)) { in da9150_probe()
424 dev_err(da9150->dev, "Failed to attach QIF client\n"); in da9150_probe()
425 return PTR_ERR(da9150->core_qif); in da9150_probe()
428 i2c_set_clientdata(da9150->core_qif, da9150); in da9150_probe()
431 da9150->irq_base = pdata->irq_base; in da9150_probe()
433 da9150_devs[DA9150_FG_IDX].platform_data = pdata->fg_pdata; in da9150_probe()
437 da9150->irq_base = -1; in da9150_probe()
440 ret = regmap_add_irq_chip(da9150->regmap, da9150->irq, in da9150_probe()
442 da9150->irq_base, &da9150_regmap_irq_chip, in da9150_probe()
443 &da9150->regmap_irq_data); in da9150_probe()
445 dev_err(da9150->dev, "Failed to add regmap irq chip: %d\n", in da9150_probe()
451 da9150->irq_base = regmap_irq_chip_get_base(da9150->regmap_irq_data); in da9150_probe()
453 enable_irq_wake(da9150->irq); in da9150_probe()
455 ret = mfd_add_devices(da9150->dev, -1, da9150_devs, in da9150_probe()
457 da9150->irq_base, NULL); in da9150_probe()
459 dev_err(da9150->dev, "Failed to add child devices: %d\n", ret); in da9150_probe()
466 regmap_del_irq_chip(da9150->irq, da9150->regmap_irq_data); in da9150_probe()
468 i2c_unregister_device(da9150->core_qif); in da9150_probe()
475 struct da9150 *da9150 = i2c_get_clientdata(client); in da9150_remove() local
477 regmap_del_irq_chip(da9150->irq, da9150->regmap_irq_data); in da9150_remove()
478 mfd_remove_devices(da9150->dev); in da9150_remove()
479 i2c_unregister_device(da9150->core_qif); in da9150_remove()
484 struct da9150 *da9150 = i2c_get_clientdata(client); in da9150_shutdown() local
487 da9150_set_bits(da9150, DA9150_CONFIG_D, in da9150_shutdown()
492 da9150_set_bits(da9150, DA9150_CONTROL_C, in da9150_shutdown()
497 { "da9150", },
503 { .compatible = "dlg,da9150", },
510 .name = "da9150",
521 MODULE_DESCRIPTION("MFD Core Driver for DA9150");