Lines Matching +full:max14577 +full:- +full:regulator
1 // SPDX-License-Identifier: GPL-2.0+
3 // max14577.c - mfd core driver for the Maxim 14577/77836
16 #include <linux/mfd/max14577.h>
17 #include <linux/mfd/max14577-private.h>
21 * It is placed here because it is used by both charger and regulator driver.
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",
136 .compatible = "maxim,max14577",
159 /* Any max14577 volatile registers are also max77836 volatile. */ in max77836_muic_volatile_reg()
210 .name = "max14577",
240 .name = "max77836-muic",
255 .name = "max77836-pmic",
264 static void max14577_print_dev_type(struct max14577 *max14577) in max14577_print_dev_type() argument
269 ret = max14577_read_reg(max14577->regmap, MAX14577_REG_DEVICEID, in max14577_print_dev_type()
272 dev_err(max14577->dev, in max14577_print_dev_type()
282 dev_info(max14577->dev, "Device type: %u (ID: 0x%x, vendor: 0x%x)\n", in max14577_print_dev_type()
283 max14577->dev_type, device_id, vendor_id); in max14577_print_dev_type()
295 static int max77836_init(struct max14577 *max14577) in max77836_init() argument
300 max14577->i2c_pmic = i2c_new_dummy_device(max14577->i2c->adapter, in max77836_init()
302 if (IS_ERR(max14577->i2c_pmic)) { in max77836_init()
303 dev_err(max14577->dev, "Failed to register PMIC I2C device\n"); in max77836_init()
304 return PTR_ERR(max14577->i2c_pmic); in max77836_init()
306 i2c_set_clientdata(max14577->i2c_pmic, max14577); in max77836_init()
308 max14577->regmap_pmic = devm_regmap_init_i2c(max14577->i2c_pmic, in max77836_init()
310 if (IS_ERR(max14577->regmap_pmic)) { in max77836_init()
311 ret = PTR_ERR(max14577->regmap_pmic); in max77836_init()
312 dev_err(max14577->dev, "Failed to allocate PMIC register map: %d\n", in max77836_init()
317 /* Un-mask MAX77836 Interrupt Source register */ in max77836_init()
318 ret = max14577_read_reg(max14577->regmap_pmic, in max77836_init()
321 dev_err(max14577->dev, "Failed to read PMIC register\n"); in max77836_init()
327 ret = max14577_write_reg(max14577->regmap_pmic, in max77836_init()
330 dev_err(max14577->dev, "Failed to write PMIC register\n"); in max77836_init()
334 ret = regmap_add_irq_chip(max14577->regmap_pmic, max14577->irq, in max77836_init()
337 &max14577->irq_data_pmic); in max77836_init()
339 dev_err(max14577->dev, "Failed to request PMIC IRQ %d: %d\n", in max77836_init()
340 max14577->irq, ret); in max77836_init()
347 i2c_unregister_device(max14577->i2c_pmic); in max77836_init()
353 * Max77836 specific de-initialization code for driver remove.
355 static void max77836_remove(struct max14577 *max14577) in max77836_remove() argument
357 regmap_del_irq_chip(max14577->irq, max14577->irq_data_pmic); in max77836_remove()
358 i2c_unregister_device(max14577->i2c_pmic); in max77836_remove()
364 struct max14577 *max14577; in max14577_i2c_probe() local
365 struct max14577_platform_data *pdata = dev_get_platdata(&i2c->dev); in max14577_i2c_probe()
366 struct device_node *np = i2c->dev.of_node; in max14577_i2c_probe()
374 pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL); in max14577_i2c_probe()
376 return -ENOMEM; in max14577_i2c_probe()
377 i2c->dev.platform_data = pdata; in max14577_i2c_probe()
381 dev_err(&i2c->dev, "No platform data found.\n"); in max14577_i2c_probe()
382 return -EINVAL; in max14577_i2c_probe()
385 max14577 = devm_kzalloc(&i2c->dev, sizeof(*max14577), GFP_KERNEL); in max14577_i2c_probe()
386 if (!max14577) in max14577_i2c_probe()
387 return -ENOMEM; in max14577_i2c_probe()
389 i2c_set_clientdata(i2c, max14577); in max14577_i2c_probe()
390 max14577->dev = &i2c->dev; in max14577_i2c_probe()
391 max14577->i2c = i2c; in max14577_i2c_probe()
392 max14577->irq = i2c->irq; in max14577_i2c_probe()
394 max14577->regmap = devm_regmap_init_i2c(i2c, in max14577_i2c_probe()
396 if (IS_ERR(max14577->regmap)) { in max14577_i2c_probe()
397 ret = PTR_ERR(max14577->regmap); in max14577_i2c_probe()
398 dev_err(max14577->dev, "Failed to allocate register map: %d\n", in max14577_i2c_probe()
406 of_id = of_match_device(max14577_dt_match, &i2c->dev); in max14577_i2c_probe()
408 max14577->dev_type = in max14577_i2c_probe()
409 (enum maxim_device_type)of_id->data; in max14577_i2c_probe()
411 max14577->dev_type = id->driver_data; in max14577_i2c_probe()
414 max14577_print_dev_type(max14577); in max14577_i2c_probe()
416 switch (max14577->dev_type) { in max14577_i2c_probe()
432 ret = regmap_add_irq_chip(max14577->regmap, max14577->irq, in max14577_i2c_probe()
434 &max14577->irq_data); in max14577_i2c_probe()
436 dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n", in max14577_i2c_probe()
437 max14577->irq, ret); in max14577_i2c_probe()
442 if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) { in max14577_i2c_probe()
443 ret = max77836_init(max14577); in max14577_i2c_probe()
448 ret = mfd_add_devices(max14577->dev, -1, mfd_devs, in max14577_i2c_probe()
453 device_init_wakeup(max14577->dev, 1); in max14577_i2c_probe()
458 if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) in max14577_i2c_probe()
459 max77836_remove(max14577); in max14577_i2c_probe()
461 regmap_del_irq_chip(max14577->irq, max14577->irq_data); in max14577_i2c_probe()
468 struct max14577 *max14577 = i2c_get_clientdata(i2c); in max14577_i2c_remove() local
470 mfd_remove_devices(max14577->dev); in max14577_i2c_remove()
471 regmap_del_irq_chip(max14577->irq, max14577->irq_data); in max14577_i2c_remove()
472 if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) in max14577_i2c_remove()
473 max77836_remove(max14577); in max14577_i2c_remove()
477 { "max14577", MAXIM_DEVICE_TYPE_MAX14577, },
487 struct max14577 *max14577 = i2c_get_clientdata(i2c); in max14577_suspend() local
490 enable_irq_wake(max14577->irq); in max14577_suspend()
500 disable_irq(max14577->irq); in max14577_suspend()
508 struct max14577 *max14577 = i2c_get_clientdata(i2c); in max14577_resume() local
511 disable_irq_wake(max14577->irq); in max14577_resume()
512 enable_irq(max14577->irq); in max14577_resume()
522 .name = "max14577",
561 MODULE_DESCRIPTION("Maxim 14577/77836 multi-function core driver");