Lines Matching +full:irqs +full:- +full:map +full:- +full:range
1 // SPDX-License-Identifier: GPL-2.0+
3 // max14577.c - mfd core driver for the Maxim 14577/77836
18 #include <linux/mfd/max14577-private.h>
42 * maxim_charger_calc_reg_current - Calculate register value for current
54 * - is always between <limits.min, limits.max>;
55 * - is always less or equal to max_ua;
56 * - is the highest possible value;
57 * - may be lower than min_ua.
59 * On success returns 0. On error returns -EINVAL (requested min/max current
68 return -EINVAL; in maxim_charger_calc_reg_current()
70 if (min_ua > limits->max || max_ua < limits->min) in maxim_charger_calc_reg_current()
71 return -EINVAL; in maxim_charger_calc_reg_current()
73 if (max_ua < limits->high_start) { in maxim_charger_calc_reg_current()
82 /* max_ua is in range: <high_start, infinite>, cut it to limits.max */ in maxim_charger_calc_reg_current()
83 max_ua = min(limits->max, max_ua); in maxim_charger_calc_reg_current()
84 max_ua -= limits->high_start; in maxim_charger_calc_reg_current()
87 * - max_ua >= limits.high_start in maxim_charger_calc_reg_current()
88 * - BUILD_BUG checks that 'limits' are: max >= high_start + high_step in maxim_charger_calc_reg_current()
90 current_bits = max_ua / limits->high_step; in maxim_charger_calc_reg_current()
92 /* Turn Low Bit on (use range <limits.high_start, limits.max>) ... */ in maxim_charger_calc_reg_current()
103 .name = "max14577-muic",
104 .of_compatible = "maxim,max14577-muic",
107 .name = "max14577-regulator",
108 .of_compatible = "maxim,max14577-regulator",
111 .name = "max14577-charger",
112 .of_compatible = "maxim,max14577-charger",
118 .name = "max77836-muic",
119 .of_compatible = "maxim,max77836-muic",
122 .name = "max77836-regulator",
123 .of_compatible = "maxim,max77836-regulator",
126 .name = "max77836-charger",
127 .of_compatible = "maxim,max77836-charger",
130 .name = "max77836-battery",
131 .of_compatible = "maxim,max77836-battery",
216 .irqs = max14577_irqs,
241 .name = "max77836-muic",
245 .irqs = max77836_muic_irqs,
255 .name = "max77836-pmic",
259 .irqs = max77836_pmic_irqs,
268 ret = max14577_read_reg(max14577->regmap, MAX14577_REG_DEVICEID, in max14577_print_dev_type()
271 dev_err(max14577->dev, in max14577_print_dev_type()
281 dev_info(max14577->dev, "Device type: %u (ID: 0x%x, vendor: 0x%x)\n", in max14577_print_dev_type()
282 max14577->dev_type, device_id, vendor_id); in max14577_print_dev_type()
299 max14577->i2c_pmic = i2c_new_dummy_device(max14577->i2c->adapter, in max77836_init()
301 if (IS_ERR(max14577->i2c_pmic)) { in max77836_init()
302 dev_err(max14577->dev, "Failed to register PMIC I2C device\n"); in max77836_init()
303 return PTR_ERR(max14577->i2c_pmic); in max77836_init()
305 i2c_set_clientdata(max14577->i2c_pmic, max14577); in max77836_init()
307 max14577->regmap_pmic = devm_regmap_init_i2c(max14577->i2c_pmic, in max77836_init()
309 if (IS_ERR(max14577->regmap_pmic)) { in max77836_init()
310 ret = PTR_ERR(max14577->regmap_pmic); in max77836_init()
311 dev_err(max14577->dev, "Failed to allocate PMIC register map: %d\n", in max77836_init()
316 /* Un-mask MAX77836 Interrupt Source register */ in max77836_init()
317 ret = max14577_read_reg(max14577->regmap_pmic, in max77836_init()
320 dev_err(max14577->dev, "Failed to read PMIC register\n"); in max77836_init()
326 ret = max14577_write_reg(max14577->regmap_pmic, in max77836_init()
329 dev_err(max14577->dev, "Failed to write PMIC register\n"); in max77836_init()
333 ret = regmap_add_irq_chip(max14577->regmap_pmic, max14577->irq, in max77836_init()
336 &max14577->irq_data_pmic); in max77836_init()
338 dev_err(max14577->dev, "Failed to request PMIC IRQ %d: %d\n", in max77836_init()
339 max14577->irq, ret); in max77836_init()
346 i2c_unregister_device(max14577->i2c_pmic); in max77836_init()
352 * Max77836 specific de-initialization code for driver remove.
356 regmap_del_irq_chip(max14577->irq, max14577->irq_data_pmic); in max77836_remove()
357 i2c_unregister_device(max14577->i2c_pmic); in max77836_remove()
363 struct max14577_platform_data *pdata = dev_get_platdata(&i2c->dev); in max14577_i2c_probe()
364 struct device_node *np = i2c->dev.of_node; in max14577_i2c_probe()
372 pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL); in max14577_i2c_probe()
374 return -ENOMEM; in max14577_i2c_probe()
375 i2c->dev.platform_data = pdata; in max14577_i2c_probe()
379 dev_err(&i2c->dev, "No platform data found.\n"); in max14577_i2c_probe()
380 return -EINVAL; in max14577_i2c_probe()
383 max14577 = devm_kzalloc(&i2c->dev, sizeof(*max14577), GFP_KERNEL); in max14577_i2c_probe()
385 return -ENOMEM; in max14577_i2c_probe()
388 max14577->dev = &i2c->dev; in max14577_i2c_probe()
389 max14577->i2c = i2c; in max14577_i2c_probe()
390 max14577->irq = i2c->irq; in max14577_i2c_probe()
392 max14577->regmap = devm_regmap_init_i2c(i2c, in max14577_i2c_probe()
394 if (IS_ERR(max14577->regmap)) { in max14577_i2c_probe()
395 ret = PTR_ERR(max14577->regmap); in max14577_i2c_probe()
396 dev_err(max14577->dev, "Failed to allocate register map: %d\n", in max14577_i2c_probe()
401 max14577->dev_type = (kernel_ulong_t)i2c_get_match_data(i2c); in max14577_i2c_probe()
405 switch (max14577->dev_type) { in max14577_i2c_probe()
421 ret = regmap_add_irq_chip(max14577->regmap, max14577->irq, in max14577_i2c_probe()
423 &max14577->irq_data); in max14577_i2c_probe()
425 dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n", in max14577_i2c_probe()
426 max14577->irq, ret); in max14577_i2c_probe()
431 if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) { in max14577_i2c_probe()
437 ret = mfd_add_devices(max14577->dev, -1, mfd_devs, in max14577_i2c_probe()
442 device_init_wakeup(max14577->dev, 1); in max14577_i2c_probe()
447 if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) in max14577_i2c_probe()
450 regmap_del_irq_chip(max14577->irq, max14577->irq_data); in max14577_i2c_probe()
459 mfd_remove_devices(max14577->dev); in max14577_i2c_remove()
460 regmap_del_irq_chip(max14577->irq, max14577->irq_data); in max14577_i2c_remove()
461 if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) in max14577_i2c_remove()
478 enable_irq_wake(max14577->irq); in max14577_suspend()
488 disable_irq(max14577->irq); in max14577_suspend()
499 disable_irq_wake(max14577->irq); in max14577_resume()
500 enable_irq(max14577->irq); in max14577_resume()
548 MODULE_DESCRIPTION("Maxim 14577/77836 multi-function core driver");