Lines Matching +full:max77836 +full:- +full:muic
1 // SPDX-License-Identifier: GPL-2.0+
3 // max14577.c - mfd core driver for the Maxim 14577/77836
17 #include <linux/mfd/max14577-private.h>
41 * maxim_charger_calc_reg_current - Calculate register value for current
53 * - is always between <limits.min, limits.max>;
54 * - is always less or equal to max_ua;
55 * - is the highest possible value;
56 * - may be lower than min_ua.
58 * On success returns 0. On error returns -EINVAL (requested min/max current
67 return -EINVAL; in maxim_charger_calc_reg_current()
69 if (min_ua > limits->max || max_ua < limits->min) in maxim_charger_calc_reg_current()
70 return -EINVAL; in maxim_charger_calc_reg_current()
72 if (max_ua < limits->high_start) { in maxim_charger_calc_reg_current()
82 max_ua = min(limits->max, max_ua); in maxim_charger_calc_reg_current()
83 max_ua -= limits->high_start; in maxim_charger_calc_reg_current()
86 * - max_ua >= limits.high_start in maxim_charger_calc_reg_current()
87 * - BUILD_BUG checks that 'limits' are: max >= high_start + high_step in maxim_charger_calc_reg_current()
89 current_bits = max_ua / limits->high_step; in maxim_charger_calc_reg_current()
102 .name = "max14577-muic",
103 .of_compatible = "maxim,max14577-muic",
106 .name = "max14577-regulator",
107 .of_compatible = "maxim,max14577-regulator",
110 .name = "max14577-charger",
111 .of_compatible = "maxim,max14577-charger",
117 .name = "max77836-muic",
118 .of_compatible = "maxim,max77836-muic",
121 .name = "max77836-regulator",
122 .of_compatible = "maxim,max77836-regulator",
125 .name = "max77836-charger",
126 .of_compatible = "maxim,max77836-charger",
129 .name = "max77836-battery",
130 .of_compatible = "maxim,max77836-battery",
140 .compatible = "maxim,max77836",
159 /* Any max14577 volatile registers are also max77836 volatile. */ in max77836_muic_volatile_reg()
239 .name = "max77836-muic",
253 .name = "max77836-pmic",
266 ret = max14577_read_reg(max14577->regmap, MAX14577_REG_DEVICEID, in max14577_print_dev_type()
269 dev_err(max14577->dev, in max14577_print_dev_type()
279 dev_info(max14577->dev, "Device type: %u (ID: 0x%x, vendor: 0x%x)\n", in max14577_print_dev_type()
280 max14577->dev_type, device_id, vendor_id); in max14577_print_dev_type()
284 * Max77836 specific initialization code for driver probe.
297 max14577->i2c_pmic = i2c_new_dummy_device(max14577->i2c->adapter, in max77836_init()
299 if (IS_ERR(max14577->i2c_pmic)) { in max77836_init()
300 dev_err(max14577->dev, "Failed to register PMIC I2C device\n"); in max77836_init()
301 return PTR_ERR(max14577->i2c_pmic); in max77836_init()
303 i2c_set_clientdata(max14577->i2c_pmic, max14577); in max77836_init()
305 max14577->regmap_pmic = devm_regmap_init_i2c(max14577->i2c_pmic, in max77836_init()
307 if (IS_ERR(max14577->regmap_pmic)) { in max77836_init()
308 ret = PTR_ERR(max14577->regmap_pmic); in max77836_init()
309 dev_err(max14577->dev, "Failed to allocate PMIC register map: %d\n", in max77836_init()
314 /* Un-mask MAX77836 Interrupt Source register */ in max77836_init()
315 ret = max14577_read_reg(max14577->regmap_pmic, in max77836_init()
318 dev_err(max14577->dev, "Failed to read PMIC register\n"); in max77836_init()
324 ret = max14577_write_reg(max14577->regmap_pmic, in max77836_init()
327 dev_err(max14577->dev, "Failed to write PMIC register\n"); in max77836_init()
331 ret = regmap_add_irq_chip(max14577->regmap_pmic, max14577->irq, in max77836_init()
334 &max14577->irq_data_pmic); in max77836_init()
336 dev_err(max14577->dev, "Failed to request PMIC IRQ %d: %d\n", in max77836_init()
337 max14577->irq, ret); in max77836_init()
344 i2c_unregister_device(max14577->i2c_pmic); in max77836_init()
350 * Max77836 specific de-initialization code for driver remove.
354 regmap_del_irq_chip(max14577->irq, max14577->irq_data_pmic); in max77836_remove()
355 i2c_unregister_device(max14577->i2c_pmic); in max77836_remove()
362 struct max14577_platform_data *pdata = dev_get_platdata(&i2c->dev); in max14577_i2c_probe()
363 struct device_node *np = i2c->dev.of_node; in max14577_i2c_probe()
371 pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL); in max14577_i2c_probe()
373 return -ENOMEM; in max14577_i2c_probe()
374 i2c->dev.platform_data = pdata; in max14577_i2c_probe()
378 dev_err(&i2c->dev, "No platform data found.\n"); in max14577_i2c_probe()
379 return -EINVAL; in max14577_i2c_probe()
382 max14577 = devm_kzalloc(&i2c->dev, sizeof(*max14577), GFP_KERNEL); in max14577_i2c_probe()
384 return -ENOMEM; in max14577_i2c_probe()
387 max14577->dev = &i2c->dev; in max14577_i2c_probe()
388 max14577->i2c = i2c; in max14577_i2c_probe()
389 max14577->irq = i2c->irq; in max14577_i2c_probe()
391 max14577->regmap = devm_regmap_init_i2c(i2c, in max14577_i2c_probe()
393 if (IS_ERR(max14577->regmap)) { in max14577_i2c_probe()
394 ret = PTR_ERR(max14577->regmap); in max14577_i2c_probe()
395 dev_err(max14577->dev, "Failed to allocate register map: %d\n", in max14577_i2c_probe()
403 of_id = of_match_device(max14577_dt_match, &i2c->dev); in max14577_i2c_probe()
405 max14577->dev_type = (uintptr_t)of_id->data; in max14577_i2c_probe()
407 max14577->dev_type = id->driver_data; in max14577_i2c_probe()
412 switch (max14577->dev_type) { in max14577_i2c_probe()
428 ret = regmap_add_irq_chip(max14577->regmap, max14577->irq, in max14577_i2c_probe()
430 &max14577->irq_data); in max14577_i2c_probe()
432 dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n", in max14577_i2c_probe()
433 max14577->irq, ret); in max14577_i2c_probe()
437 /* Max77836 specific initialization code (additional regmap) */ in max14577_i2c_probe()
438 if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) { in max14577_i2c_probe()
444 ret = mfd_add_devices(max14577->dev, -1, mfd_devs, in max14577_i2c_probe()
449 device_init_wakeup(max14577->dev, 1); in max14577_i2c_probe()
454 if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) in max14577_i2c_probe()
457 regmap_del_irq_chip(max14577->irq, max14577->irq_data); in max14577_i2c_probe()
466 mfd_remove_devices(max14577->dev); in max14577_i2c_remove()
467 regmap_del_irq_chip(max14577->irq, max14577->irq_data); in max14577_i2c_remove()
468 if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) in max14577_i2c_remove()
474 { "max77836", MAXIM_DEVICE_TYPE_MAX77836, },
485 enable_irq_wake(max14577->irq); in max14577_suspend()
487 * MUIC IRQ must be disabled during suspend because if it happens in max14577_suspend()
495 disable_irq(max14577->irq); in max14577_suspend()
506 disable_irq_wake(max14577->irq); in max14577_resume()
507 enable_irq(max14577->irq); in max14577_resume()
555 MODULE_DESCRIPTION("Maxim 14577/77836 multi-function core driver");