Re: [PATCH v7 4/5] Input: add haptic drvier on max77843
Hi Dmitry, On 03/03/2015 02:32, Dmitry Torokhov wrote: On Mon, Mar 02, 2015 at 07:10:37PM +0900, Jaewon Kim wrote: This patch adds support for haptic driver on max77843 MFD(Multi Function Device) with PMIC, MUIC, LED, CHARGER. This driver supports external pwm and LRA(Linear Resonant Actuator) motor. And it supports ff-memless interface from inpu framework. Cc: Dmitry Torokhov Signed-off-by: Jaewon Kim Acked-by: Dmitry Torokhov Do you want it to go through my or MFD tree? Other drivers merged in each maintainers git. If you don`t hava a problem, please merge your input git tree. --- drivers/input/misc/Kconfig | 12 ++ drivers/input/misc/Makefile |1 + drivers/input/misc/max77843-haptic.c | 358 ++ 3 files changed, 371 insertions(+) create mode 100644 drivers/input/misc/max77843-haptic.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 6deb8da..aa8c072 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -165,6 +165,18 @@ config INPUT_MAX77693_HAPTIC To compile this driver as module, choose M here: the module will be called max77693-haptic. +config INPUT_MAX77843_HAPTIC +tristate "MAXIM MAX77843 haptic controller support" +depends on MFD_MAX77843 && PWM +select INPUT_FF_MEMLESS +help + This option enables support for the haptic controller on + MAXIM MAX77843 chip. The driver supports ff-memless interface + from input framework. + + To compile this driver as module, choose M here: the + module will be called max77843-haptic. + config INPUT_MAX8925_ONKEY tristate "MAX8925 ONKEY support" depends on MFD_MAX8925 diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 403a1a5..75b5884 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)+= keyspan_remote.o obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC) += max77693-haptic.o +obj-$(CONFIG_INPUT_MAX77843_HAPTIC)+= max77843-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o obj-$(CONFIG_INPUT_MAX8997_HAPTIC)+= max8997_haptic.o obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o diff --git a/drivers/input/misc/max77843-haptic.c b/drivers/input/misc/max77843-haptic.c new file mode 100644 index 000..eef9862 --- /dev/null +++ b/drivers/input/misc/max77843-haptic.c @@ -0,0 +1,358 @@ +/* + * MAXIM MAX77693 Haptic device driver + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_MAGNITUDE_SHIFT16 + +enum max77843_haptic_motor_type { + MAX77843_HAPTIC_ERM = 0, + MAX77843_HAPTIC_LRA, +}; + +enum max77843_haptic_pwm_divisor { + MAX77843_HAPTIC_PWM_DIVISOR_32 = 0, + MAX77843_HAPTIC_PWM_DIVISOR_64, + MAX77843_HAPTIC_PWM_DIVISOR_128, + MAX77843_HAPTIC_PWM_DIVISOR_256, +}; + +struct max77843_haptic { + struct regmap *regmap_haptic; + struct device *dev; + struct input_dev *input_dev; + struct pwm_device *pwm_dev; + struct regulator *motor_reg; + struct work_struct work; + struct mutex mutex; + + unsigned int magnitude; + unsigned int pwm_duty; + + bool active; + bool suspended; + + enum max77843_haptic_motor_type type; + enum max77843_haptic_pwm_divisor pwm_divisor; +}; + +static int max77843_haptic_set_duty_cycle(struct max77843_haptic *haptic) +{ + int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2; + int error; + + error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period); + if (error) { + dev_err(haptic->dev, "failed to configure pwm: %d\n", error); + return error; + } + + return 0; +} + +static int max77843_haptic_bias(struct max77843_haptic *haptic, bool on) +{ + int error; + + error = regmap_update_bits(haptic->regmap_haptic, + MAX77843_SYS_REG_MAINCTRL1, + MAX77843_MAINCTRL1_BIASEN_MASK, + on << MAINCTRL1_BIASEN_SHIFT); + if (error) { + dev_err(haptic->dev, "failed to %s bias: %d\n", + on ? "enable" : "disable", error); + return error; + } + + return 0; +}
Re: [PATCH v7 1/5] mfd: max77843: Add max77843 MFD driver core driver
Hi Lee Jones, On 02/03/2015 19:20, Lee Jones wrote: On Mon, 02 Mar 2015, Jaewon Kim wrote: This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 243 ++ include/linux/mfd/max77843-private.h | 454 ++ 4 files changed, 712 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h If you have dealt with my previous review comments: Acked-by: Lee Jones Which other Acks are you waiting for? There is no dependency with other patchs. Plz merge it first. Thanks, Jaewon Kim -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v7 1/5] mfd: max77843: Add max77843 MFD driver core driver
This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 243 ++ include/linux/mfd/max77843-private.h | 454 ++ 4 files changed, 712 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 38356e3..f2fd5e5 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -455,6 +455,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77843 + bool "Maxim Semiconductor MAX77843 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim Semiconductor MAX77843. + This is companion Power Management IC with LEDs, Haptic, Charger, + Fuel Gauge, MUIC(Micro USB Interface Controller) controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX8907 tristate "Maxim Semiconductor MAX8907 PMIC Support" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 19f3d74..b8ac555 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -117,6 +117,7 @@ obj-$(CONFIG_MFD_DA9150)+= da9150-core.o obj-$(CONFIG_MFD_MAX14577) += max14577.o obj-$(CONFIG_MFD_MAX77686) += max77686.o obj-$(CONFIG_MFD_MAX77693) += max77693.o +obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c new file mode 100644 index 000..a354ac6 --- /dev/null +++ b/drivers/mfd/max77843.c @@ -0,0 +1,243 @@ +/* + * MFD core driver for the Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell max77843_devs[] = { + { + .name = "max77843-muic", + .of_compatible = "maxim,max77843-muic", + }, { + .name = "max77843-regulator", + .of_compatible = "maxim,max77843-regulator", + }, { + .name = "max77843-charger", + .of_compatible = "maxim,max77843-charger" + }, { + .name = "max77843-fuelgauge", + .of_compatible = "maxim,max77843-fuelgauge", + }, { + .name = "max77843-haptic", + .of_compatible = "maxim,max77843-haptic", + }, +}; + +static const struct regmap_config max77843_charger_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_CHG_REG_END, +}; + +static const struct regmap_config max77843_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_SYS_REG_END, +}; + +static const struct regmap_irq max77843_irqs[] = { + /* TOPSYS interrupts */ + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSUVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSOVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TSHDN_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77843_irq_chip = { + .name = "max77843", + .status_base= MAX77843_SYS_REG_SYSINTSRC, + .mask_base = MAX77843_SYS_REG_SYSINTMASK, + .mask_invert= false, + .num_regs = 1, + .irqs = max77843_irqs, + .num_irqs = ARRAY_SIZE(max77843_irqs), +}; + +/* Charger and Charger regulator use same regmap. */ +static int max77843_chg_init(struct max77843 *max77843) +{ + int ret; + + max77843->i2c_chg = i2c_new_dummy(max77843->i2c->adapter, I2C_ADDR_CHG); + if (!max77843->i2c_chg) { + dev_err(&max77843->i2c->dev, +
[PATCH v7 4/5] Input: add haptic drvier on max77843
This patch adds support for haptic driver on max77843 MFD(Multi Function Device) with PMIC, MUIC, LED, CHARGER. This driver supports external pwm and LRA(Linear Resonant Actuator) motor. And it supports ff-memless interface from inpu framework. Cc: Dmitry Torokhov Signed-off-by: Jaewon Kim --- drivers/input/misc/Kconfig | 12 ++ drivers/input/misc/Makefile |1 + drivers/input/misc/max77843-haptic.c | 358 ++ 3 files changed, 371 insertions(+) create mode 100644 drivers/input/misc/max77843-haptic.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 6deb8da..aa8c072 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -165,6 +165,18 @@ config INPUT_MAX77693_HAPTIC To compile this driver as module, choose M here: the module will be called max77693-haptic. +config INPUT_MAX77843_HAPTIC +tristate "MAXIM MAX77843 haptic controller support" +depends on MFD_MAX77843 && PWM +select INPUT_FF_MEMLESS +help + This option enables support for the haptic controller on + MAXIM MAX77843 chip. The driver supports ff-memless interface + from input framework. + + To compile this driver as module, choose M here: the + module will be called max77843-haptic. + config INPUT_MAX8925_ONKEY tristate "MAX8925 ONKEY support" depends on MFD_MAX8925 diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 403a1a5..75b5884 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)+= keyspan_remote.o obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC)+= max77693-haptic.o +obj-$(CONFIG_INPUT_MAX77843_HAPTIC)+= max77843-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o obj-$(CONFIG_INPUT_MAX8997_HAPTIC) += max8997_haptic.o obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o diff --git a/drivers/input/misc/max77843-haptic.c b/drivers/input/misc/max77843-haptic.c new file mode 100644 index 000..eef9862 --- /dev/null +++ b/drivers/input/misc/max77843-haptic.c @@ -0,0 +1,358 @@ +/* + * MAXIM MAX77693 Haptic device driver + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_MAGNITUDE_SHIFT16 + +enum max77843_haptic_motor_type { + MAX77843_HAPTIC_ERM = 0, + MAX77843_HAPTIC_LRA, +}; + +enum max77843_haptic_pwm_divisor { + MAX77843_HAPTIC_PWM_DIVISOR_32 = 0, + MAX77843_HAPTIC_PWM_DIVISOR_64, + MAX77843_HAPTIC_PWM_DIVISOR_128, + MAX77843_HAPTIC_PWM_DIVISOR_256, +}; + +struct max77843_haptic { + struct regmap *regmap_haptic; + struct device *dev; + struct input_dev *input_dev; + struct pwm_device *pwm_dev; + struct regulator *motor_reg; + struct work_struct work; + struct mutex mutex; + + unsigned int magnitude; + unsigned int pwm_duty; + + bool active; + bool suspended; + + enum max77843_haptic_motor_type type; + enum max77843_haptic_pwm_divisor pwm_divisor; +}; + +static int max77843_haptic_set_duty_cycle(struct max77843_haptic *haptic) +{ + int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2; + int error; + + error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period); + if (error) { + dev_err(haptic->dev, "failed to configure pwm: %d\n", error); + return error; + } + + return 0; +} + +static int max77843_haptic_bias(struct max77843_haptic *haptic, bool on) +{ + int error; + + error = regmap_update_bits(haptic->regmap_haptic, + MAX77843_SYS_REG_MAINCTRL1, + MAX77843_MAINCTRL1_BIASEN_MASK, + on << MAINCTRL1_BIASEN_SHIFT); + if (error) { + dev_err(haptic->dev, "failed to %s bias: %d\n", + on ? "enable" : "disable", error); + return error; + } + + return 0; +} + +static int max77843_haptic_config(struct max77843_haptic *haptic, bool enable) +{ + unsigned int value; + int error; + + value = ((haptic->type << MCONFIG_MODE_SHIFT) | + (enable << MCONFIG_MEN_SHIFT) | + (haptic->pwm_divisor << MCONFI
[PATCH v7 0/5] Add new MFD driver for MAX77843
This patch series adds MAX77843(Multi Function Device) driver. The MAX77843 includes MUIC(Micro USB Interface Controller), Li+ Charger with Fuel Gauge, 2 safeout LDOs for USB device and haptic controller using PWM. It is interfaced to host controller using I2C. Changes in v7: MFD Core - Fix indentation - Remove file name, MODULE information POWER - Fix typos Changes in v6: HAPTIC - fixed a situation where holding a Mutex return. Changes in v5: MFD Core - Use bracket in complex define. - Delete unnecessary letter '++' Charger - fix Kconfig merge conflict with Kernel version4.0 Changes in v4: MFD Core - Fix indentation - Add haptic register define in header HAPTIC - Add haptic driver Changes in v3: MFD Core - Fix wrong description and indentation in header. - Remove unnecessary variable. Regulator - Use ARRAY_SIZE() instead of define. Changes in v2: MFD Core - Fix charger regmap handle and typo. MUIC - Cleanup enum list. - Set path before send excon event. - Fix variable names and typos for readability. Charger - Remove unnecessary header. - Chnage error message more readable. - Remove unnecessary lines. Fuelgauge - Fix regmap_config and use regmap_read. - Add i2c_unregister_device function on *_remove function. - Fix typo in Kconfig. Doc - Remove unnecessary lines. - Add example of charger regulator.Beomho Seo (2): Jaewon Kim (3): mfd: max77843: Add max77843 MFD driver core driver Input: add haptic drvier on max77843 Documentation: Add device tree bindings document for max77843 Documentation/devicetree/bindings/mfd/max77843.txt | 110 + drivers/input/misc/Kconfig | 12 + drivers/input/misc/Makefile|1 + drivers/input/misc/max77843-haptic.c | 358 ++ drivers/mfd/Kconfig| 14 + drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 243 ++ drivers/power/Kconfig | 16 + drivers/power/Makefile |2 + drivers/power/max77843_battery.c | 286 +++ drivers/power/max77843_charger.c | 508 include/linux/mfd/max77843-private.h | 454 + 12 files changed, 2005 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt create mode 100644 drivers/input/misc/max77843-haptic.c create mode 100644 drivers/mfd/max77843.c create mode 100644 drivers/power/max77843_battery.c create mode 100644 drivers/power/max77843_charger.c create mode 100644 include/linux/mfd/max77843-private.h -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v7 5/5] Documentation: Add device tree bindings document for max77843
Add document describing device tree bindings for max77843 MFD. Drivers: MFD core, regulator, extcon, charger and fuelgauge. Cc: Rob Herring Cc: Pawel Moll Cc: Mark Rutland Cc: Ian Campbell Cc: Kumar Gala Cc: Lee Jones Cc: Sebastian Reichel Cc: Dmitry Torokhov Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- Documentation/devicetree/bindings/mfd/max77843.txt | 110 1 file changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt diff --git a/Documentation/devicetree/bindings/mfd/max77843.txt b/Documentation/devicetree/bindings/mfd/max77843.txt new file mode 100644 index 000..76426ca --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/max77843.txt @@ -0,0 +1,110 @@ +Maxim MAX77843 multi-function device + +MAX77843 is a Multi-Function Device with the following submodules: +- PMIC : 2 SAFEOUT LDOs for USB device +- CHARGER : Li+ battery charger with Fuel Gauge +- MUIC : Micro USB Interface Controller +- HAPTIC : Motor Controller for tactile feedback + +It is interfaced to host controller using I2C. + +Required properties: +- compatible : Must be "maxim,max77843". +- reg : I2C slave address of PMIC block. +- interrupts : I2C line for main SoCs. +- interrupt-parent : The parent of interrupt controller. + +Optional properties: +- regulators : The regulators of max77843 have to be instantiated under subnode + named "regulators" using the following format. + + [*]refer : Documentation/devicetree/bindings/regulator/regulator.txt + + regulators { + SAFEOUT { + regulator-name = "SAFEOUT"; + }; + } + + List of valid regulator names: + - SAFEOUT1, SAFEOUT2, CHARGER. + +- max77843-muic : This properties used by extcon consumers. + Required properties: + - compatible : Must be "maxim,max77842-muic". + +- max77843-charger : There battery charger of MAX77843 have to be instantiated + under sub-node named "max77843-charger" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-charger". + - maxim,fast-charge-uamp : Fast charge current levels are + 100 mA to 3150 mA programmed by I2C per 100 mA. + - maxim,top-off-uamp : Top off current threshold levels are + 125 mA to 650 mA programmed by I2C per 75 mA. + - maxim,input-uamp-limit : Input current limit levels are + 100 mA to 3533 mA programmed by I2C per 33 mA. + +- max77843-fuelgauge : There fuelgauge of MAX77843 have to be instantiated + under sub-node named "max77843-fuelgauge" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-fuelgauge". + +- max77843-haptic : The MAX77843 haptic device provides the tactile feedback + to the user by using PWM(Pulse Width Modulation) signal. + Required properties: + - compatible : Must be "maxim,max77843-hpatic". + - haptic-supply : Power supply for the haptic motor. + [*] refer Documentation/devicetree/ + bindings/regulator/regulator.txt + - pwms : phandle for the PWM(Pulse Width Modulation) device. + PWM properties should be named "pwms". + [*] refer Documentation/devicetree/bindings/pwm/pwm.txt + +Example: + max77843@66 { + compatible = "samsung,max77843"; + reg = <0x66>; + interrupt-parent = <&gpa1>; + interrupts = <5 2>; + + regulators { + SAFEOUT1 { + regulator-name = "SAFEOUT1"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + SAFEOUT2 { + regulator-name = "SAFEOUT2"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + CHARGER { + regulator-name = "CHARGER"; + regulator-min-microamp = <10>; + regulator-max-microamp = <315>; + }; + }; + + haptic { + compatible = "maxim,max77843-haptic"; + haptic-supply = <&haptic_supply>; + pwms = <&pwm 0 4 0>; + pwm-na
[PATCH v7 3/5] power: max77843_battery: Add Max77843 fuel gauge device driver
From: Beomho Seo This patch adds device driver of max77843 fuel gauge. The driver support for battery fuel gauge in Maxim Max77843. It is fuel-gauge systems for lithuum-ion batteries in handled and portable devices. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|9 ++ drivers/power/Makefile |1 + drivers/power/max77843_battery.c | 286 ++ 3 files changed, 296 insertions(+) create mode 100644 drivers/power/max77843_battery.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 994793d..42538e6 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -212,6 +212,15 @@ config BATTERY_MAX17042 with MAX17042. This driver also supports max17047/50 chips which are improved version of max17042. +config BATTERY_MAX77843 + tristate "Maxim MAX77843 Fuel Gauge" + depends on MFD_MAX77843 + help + This adds support for battery fuel gauge in Maxim MAX77843. It is + fuel-gauge for a lithium-ion batteries with a single cell and can be + found in portable devices. The MAX77843 is configured to operate with + a single lithium cell. + config BATTERY_Z2 tristate "Z2 battery driver" depends on I2C && MACH_ZIPIT2 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index ed69cea..59e3945 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -34,6 +34,7 @@ obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o obj-$(CONFIG_BATTERY_DA9052) += da9052-battery.o obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o +obj-$(CONFIG_BATTERY_MAX77843) += max77843_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_RT5033) += rt5033_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o diff --git a/drivers/power/max77843_battery.c b/drivers/power/max77843_battery.c new file mode 100644 index 000..a4266de --- /dev/null +++ b/drivers/power/max77843_battery.c @@ -0,0 +1,286 @@ +/* + * Fuel gauge driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_battery { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; +}; + +static int max77843_battery_get_capacity(struct max77843_battery *battery) +{ + struct regmap *regmap = battery->regmap; + int ret, val; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_FG_REG_SOCREP, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data >> 8; + + return val; +} + +static int max77843_battery_get_energy_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_ENERGY_FULL: + reg = MAX77843_FG_REG_FULLCAP; + break; + case POWER_SUPPLY_PROP_ENERGY_NOW: + reg = MAX77843_FG_REG_REMCAP_REP; + break; + case POWER_SUPPLY_PROP_ENERGY_AVG: + reg = MAX77843_FG_REG_REMCAP_AV; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + + return val; +} + +static int max77843_battery_get_current_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_CURRENT_NOW: + reg = MAX77843_FG_REG_CURRENT; + break; + case POWER_SUPPLY_PROP_CURRENT_AVG: + reg = MAX77843_FG_REG_AVG_CURRENT; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + if (val & 0x8000) { + /* Negative */ + val = ~val & 0x; + val++; + val
[PATCH v7 2/5] power: max77843_charger: Add Max77843 charger device driver
From: Beomho Seo This patch adds device driver of max77843 charger. This driver provide initialize each charging mode(e.g. fast charge, top-off mode and constant charging mode so on.). Additionally, control charging paramters to use i2c interface. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|7 + drivers/power/Makefile |1 + drivers/power/max77843_charger.c | 508 ++ 3 files changed, 516 insertions(+) create mode 100644 drivers/power/max77843_charger.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 27b751b..994793d 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -337,6 +337,13 @@ config CHARGER_MAX77693 help Say Y to enable support for the Maxim MAX77693 battery charger. +config CHARGER_MAX77843 + tristate "Maxim MAX77843 battery charger driver" + depends on MFD_MAX77843 + help + Say Y to enable support for the battery charger control sysfs and + platform data of MAX77843 + config CHARGER_MAX8997 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" depends on MFD_MAX8997 && REGULATOR_MAX8997 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 36f9e0d..ed69cea 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_CHARGER_GPIO)+= gpio-charger.o obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o obj-$(CONFIG_CHARGER_MAX77693) += max77693_charger.o +obj-$(CONFIG_CHARGER_MAX77843) += max77843_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o diff --git a/drivers/power/max77843_charger.c b/drivers/power/max77843_charger.c new file mode 100644 index 000..d4cce17 --- /dev/null +++ b/drivers/power/max77843_charger.c @@ -0,0 +1,508 @@ +/* + * Charger driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_charger_info { + u32 fast_charge_uamp; + u32 top_off_uamp; + u32 input_uamp_limit; +}; + +struct max77843_charger { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; + + struct max77843_charger_info*info; +}; + +static int max77843_charger_get_max_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_09, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read max current register: %d\n", ret); + return ret; + } + + if (reg_data <= 0x03) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MIN; + } else if (reg_data >= 0x78) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MAX; + } else { + val = reg_data / 3; + if (reg_data % 3 == 0) + val *= 10; + else if (reg_data % 3 == 1) + val = val * 10 + 33000; + else + val = val * 10 + 67000; + } + + return val; +} + +static int max77843_charger_get_now_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charge current register: %d\n", ret); + return ret; + } + + reg_data &= MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (reg_data <= 0x02) + val = MAX77843_CHG_FAST_CHG_CURRENT_MIN; + else if (reg_data >= 0x3f) + val = MAX77843_CHG_FAST_CHG_CURRENT_MAX; + else + val = reg_data * MAX77843_CHG_FAST_CHG_CURRENT_STEP; + + return val; +} + +static int max77843_charger_get_online(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_INT_OK, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charger status: %d\n", ret); + return ret; + } + + if (reg_data & MAX77843_C
Re: [PATCH v6 4/5] Input: add haptic drvier on max77843
HI Dmitry, On 28/02/2015 02:49, Dmitry Torokhov wrote: On Thu, Feb 26, 2015 at 11:49:36AM +0900, Jaewon Kim wrote: Hi Dmitry, On 26/02/2015 10:23, Dmitry Torokhov wrote: Hi Jaewon, On Tue, Feb 24, 2015 at 10:29:07AM +0900, Jaewon Kim wrote: +static void max77843_haptic_play_work(struct work_struct *work) +{ + struct max77843_haptic *haptic = + container_of(work, struct max77843_haptic, work); + int error; + + mutex_lock(&haptic->mutex); + + if (haptic->suspended) { + goto err_play; + } + You do not need braces around single statement. Also, this is not error that you are handling, I'd prefer if we called this label out_unlock. You are right. I will change label name and remove braces. + error = max77843_haptic_set_duty_cycle(haptic); + if (error) { + dev_err(haptic->dev, "failed to set duty cycle: %d\n", error); + goto err_play; + } Do you need to configure duty cycle if you stopping the playback? Or maybe disabling pwm is enough? It do not need to set duty cycle requisitely when disabling haptic. I will move this function to front of max77843_haptic_enable(). + + if (haptic->magnitude) { + error = max77843_haptic_enable(haptic); + if (error) + dev_err(haptic->dev, + "cannot enable haptic: %d\n", error); + } else { + max77843_haptic_disable(haptic); + if (error) + dev_err(haptic->dev, + "cannot disable haptic: %d\n", error); What error? You did not assign it... Detailed error message printed in enable/disable() function. What I was trying to say is that you do not assign new value to 'error' variable in this path; it still carries the value from max77843_haptic_set_duty_cycle() above and so this "if" statement will never work and the message will never show up. I never image at all that i am not assign 'error' variable. I will assign it. Thanks. Thanks, Jaewon Kim -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v6 1/5] mfd: max77843: Add max77843 MFD driver core driver
Hi Lee Jones, On 26/02/2015 01:47, Lee Jones wrote: On Tue, 24 Feb 2015, Jaewon Kim wrote: This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 248 +++ include/linux/mfd/max77843-private.h | 454 ++ 4 files changed, 717 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 38356e3..f2fd5e5 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -455,6 +455,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77843 + bool "Maxim Semiconductor MAX77843 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim Semiconductor MAX77843. + This is companion Power Management IC with LEDs, Haptic, Charger, + Fuel Gauge, MUIC(Micro USB Interface Controller) controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX8907 tristate "Maxim Semiconductor MAX8907 PMIC Support" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 19f3d74..b8ac555 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -117,6 +117,7 @@ obj-$(CONFIG_MFD_DA9150)+= da9150-core.o obj-$(CONFIG_MFD_MAX14577)+= max14577.o obj-$(CONFIG_MFD_MAX77686)+= max77686.o obj-$(CONFIG_MFD_MAX77693)+= max77693.o +obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c new file mode 100644 index 000..2d8b3cc --- /dev/null +++ b/drivers/mfd/max77843.c @@ -0,0 +1,248 @@ +/* + * max77843.c - MFD core driver for the Maxim MAX77843 Please remove the filename. Okay, I will remove it. + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell max77843_devs[] = { + { + .name = "max77843-muic", + .of_compatible = "maxim,max77843-muic", + }, { + .name = "max77843-regulator", + .of_compatible = "maxim,max77843-regulator", + }, { + .name = "max77843-charger", + .of_compatible = "maxim,max77843-charger" + }, { + .name = "max77843-fuelgauge", + .of_compatible = "maxim,max77843-fuelgauge", + }, { + .name = "max77843-haptic", + .of_compatible = "maxim,max77843-haptic", + }, +}; + +static const struct regmap_config max77843_charger_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_CHG_REG_END, +}; + +static const struct regmap_config max77843_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_SYS_REG_END, +}; + +static const struct regmap_irq max77843_irqs[] = { + /* TOPSYS interrupts */ + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSUVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSOVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TSHDN_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77843_irq_chip = { + .name = "max77843", + .status_base= MAX77843_SYS_REG_SYSINTSRC, + .mask_base = MAX77843_SYS_REG_SYSINTMASK, + .mask_invert= false, + .num_regs = 1, + .irqs = max77843_irqs, + .num_irqs = ARRAY_SIZE(max77843_irqs), +}; + +/* Charger and Charger regulator use same regmap. */ +static int max77843_chg_init(struct max77843 *max77843) +{ + int ret; + + max77843->i2c_chg
Re: [PATCH v6 4/5] Input: add haptic drvier on max77843
Hi Dmitry, On 26/02/2015 10:23, Dmitry Torokhov wrote: Hi Jaewon, On Tue, Feb 24, 2015 at 10:29:07AM +0900, Jaewon Kim wrote: +static void max77843_haptic_play_work(struct work_struct *work) +{ + struct max77843_haptic *haptic = + container_of(work, struct max77843_haptic, work); + int error; + + mutex_lock(&haptic->mutex); + + if (haptic->suspended) { + goto err_play; + } + You do not need braces around single statement. Also, this is not error that you are handling, I'd prefer if we called this label out_unlock. You are right. I will change label name and remove braces. + error = max77843_haptic_set_duty_cycle(haptic); + if (error) { + dev_err(haptic->dev, "failed to set duty cycle: %d\n", error); + goto err_play; + } Do you need to configure duty cycle if you stopping the playback? Or maybe disabling pwm is enough? It do not need to set duty cycle requisitely when disabling haptic. I will move this function to front of max77843_haptic_enable(). + + if (haptic->magnitude) { + error = max77843_haptic_enable(haptic); + if (error) + dev_err(haptic->dev, + "cannot enable haptic: %d\n", error); + } else { + max77843_haptic_disable(haptic); + if (error) + dev_err(haptic->dev, + "cannot disable haptic: %d\n", error); What error? You did not assign it... Detailed error message printed in enable/disable() function. Thanks. Thanks to review my patch. Thanks, Jaewon Kim -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v6 5/5] Documentation: Add device tree bindings document for max77843
Add document describing device tree bindings for max77843 MFD. Drivers: MFD core, regulator, extcon, charger and fuelgauge. Cc: Rob Herring Cc: Pawel Moll Cc: Mark Rutland Cc: Ian Campbell Cc: Kumar Gala Cc: Lee Jones Cc: Sebastian Reichel Cc: Dmitry Torokhov Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- Documentation/devicetree/bindings/mfd/max77843.txt | 110 1 file changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt diff --git a/Documentation/devicetree/bindings/mfd/max77843.txt b/Documentation/devicetree/bindings/mfd/max77843.txt new file mode 100644 index 000..76426ca --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/max77843.txt @@ -0,0 +1,110 @@ +Maxim MAX77843 multi-function device + +MAX77843 is a Multi-Function Device with the following submodules: +- PMIC : 2 SAFEOUT LDOs for USB device +- CHARGER : Li+ battery charger with Fuel Gauge +- MUIC : Micro USB Interface Controller +- HAPTIC : Motor Controller for tactile feedback + +It is interfaced to host controller using I2C. + +Required properties: +- compatible : Must be "maxim,max77843". +- reg : I2C slave address of PMIC block. +- interrupts : I2C line for main SoCs. +- interrupt-parent : The parent of interrupt controller. + +Optional properties: +- regulators : The regulators of max77843 have to be instantiated under subnode + named "regulators" using the following format. + + [*]refer : Documentation/devicetree/bindings/regulator/regulator.txt + + regulators { + SAFEOUT { + regulator-name = "SAFEOUT"; + }; + } + + List of valid regulator names: + - SAFEOUT1, SAFEOUT2, CHARGER. + +- max77843-muic : This properties used by extcon consumers. + Required properties: + - compatible : Must be "maxim,max77842-muic". + +- max77843-charger : There battery charger of MAX77843 have to be instantiated + under sub-node named "max77843-charger" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-charger". + - maxim,fast-charge-uamp : Fast charge current levels are + 100 mA to 3150 mA programmed by I2C per 100 mA. + - maxim,top-off-uamp : Top off current threshold levels are + 125 mA to 650 mA programmed by I2C per 75 mA. + - maxim,input-uamp-limit : Input current limit levels are + 100 mA to 3533 mA programmed by I2C per 33 mA. + +- max77843-fuelgauge : There fuelgauge of MAX77843 have to be instantiated + under sub-node named "max77843-fuelgauge" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-fuelgauge". + +- max77843-haptic : The MAX77843 haptic device provides the tactile feedback + to the user by using PWM(Pulse Width Modulation) signal. + Required properties: + - compatible : Must be "maxim,max77843-hpatic". + - haptic-supply : Power supply for the haptic motor. + [*] refer Documentation/devicetree/ + bindings/regulator/regulator.txt + - pwms : phandle for the PWM(Pulse Width Modulation) device. + PWM properties should be named "pwms". + [*] refer Documentation/devicetree/bindings/pwm/pwm.txt + +Example: + max77843@66 { + compatible = "samsung,max77843"; + reg = <0x66>; + interrupt-parent = <&gpa1>; + interrupts = <5 2>; + + regulators { + SAFEOUT1 { + regulator-name = "SAFEOUT1"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + SAFEOUT2 { + regulator-name = "SAFEOUT2"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + CHARGER { + regulator-name = "CHARGER"; + regulator-min-microamp = <10>; + regulator-max-microamp = <315>; + }; + }; + + haptic { + compatible = "maxim,max77843-haptic"; + haptic-supply = <&haptic_supply>; + pwms = <&pwm 0 4 0>; + pwm-na
[PATCH v6 4/5] Input: add haptic drvier on max77843
This patch adds support for haptic driver on max77843 MFD(Multi Function Device) with PMIC, MUIC, LED, CHARGER. This driver supports external pwm and LRA(Linear Resonant Actuator) motor. And it supports ff-memless interface from inpu framework. Cc: Dmitry Torokhov Signed-off-by: Jaewon Kim --- drivers/input/misc/Kconfig | 12 ++ drivers/input/misc/Makefile |1 + drivers/input/misc/max77843-haptic.c | 358 ++ 3 files changed, 371 insertions(+) create mode 100644 drivers/input/misc/max77843-haptic.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 6deb8da..aa8c072 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -165,6 +165,18 @@ config INPUT_MAX77693_HAPTIC To compile this driver as module, choose M here: the module will be called max77693-haptic. +config INPUT_MAX77843_HAPTIC +tristate "MAXIM MAX77843 haptic controller support" +depends on MFD_MAX77843 && PWM +select INPUT_FF_MEMLESS +help + This option enables support for the haptic controller on + MAXIM MAX77843 chip. The driver supports ff-memless interface + from input framework. + + To compile this driver as module, choose M here: the + module will be called max77843-haptic. + config INPUT_MAX8925_ONKEY tristate "MAX8925 ONKEY support" depends on MFD_MAX8925 diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 403a1a5..75b5884 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)+= keyspan_remote.o obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC)+= max77693-haptic.o +obj-$(CONFIG_INPUT_MAX77843_HAPTIC)+= max77843-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o obj-$(CONFIG_INPUT_MAX8997_HAPTIC) += max8997_haptic.o obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o diff --git a/drivers/input/misc/max77843-haptic.c b/drivers/input/misc/max77843-haptic.c new file mode 100644 index 000..0005d0a --- /dev/null +++ b/drivers/input/misc/max77843-haptic.c @@ -0,0 +1,358 @@ +/* + * MAXIM MAX77693 Haptic device driver + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_MAGNITUDE_SHIFT16 + +enum max77843_haptic_motor_type { + MAX77843_HAPTIC_ERM = 0, + MAX77843_HAPTIC_LRA, +}; + +enum max77843_haptic_pwm_divisor { + MAX77843_HAPTIC_PWM_DIVISOR_32 = 0, + MAX77843_HAPTIC_PWM_DIVISOR_64, + MAX77843_HAPTIC_PWM_DIVISOR_128, + MAX77843_HAPTIC_PWM_DIVISOR_256, +}; + +struct max77843_haptic { + struct regmap *regmap_haptic; + struct device *dev; + struct input_dev *input_dev; + struct pwm_device *pwm_dev; + struct regulator *motor_reg; + struct work_struct work; + struct mutex mutex; + + unsigned int magnitude; + unsigned int pwm_duty; + + bool active; + bool suspended; + + enum max77843_haptic_motor_type type; + enum max77843_haptic_pwm_divisor pwm_divisor; +}; + +static int max77843_haptic_set_duty_cycle(struct max77843_haptic *haptic) +{ + int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2; + int error; + + error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period); + if (error) { + dev_err(haptic->dev, "failed to configure pwm: %d\n", error); + return error; + } + + return 0; +} + +static int max77843_haptic_bias(struct max77843_haptic *haptic, bool on) +{ + int error; + + error = regmap_update_bits(haptic->regmap_haptic, + MAX77843_SYS_REG_MAINCTRL1, + MAX77843_MAINCTRL1_BIASEN_MASK, + on << MAINCTRL1_BIASEN_SHIFT); + if (error) { + dev_err(haptic->dev, "failed to %s bias: %d\n", + on ? "enable" : "disable", error); + return error; + } + + return 0; +} + +static int max77843_haptic_config(struct max77843_haptic *haptic, bool enable) +{ + unsigned int value; + int error; + + value = ((haptic->type << MCONFIG_MODE_SHIFT) | + (enable << MCONFIG_MEN_SHIFT) | + (haptic->pwm_divisor << MCONFI
[PATCH v6 3/5] power: max77843_battery: Add Max77843 fuel gauge device driver
From: Beomho Seo This patch adds device driver of max77843 fuel gauge. The driver support for battery fuel gauge in Maxim Max77843. It is fuel-gauge systems for lithuum-ion batteries in handled and portable devices. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|9 ++ drivers/power/Makefile |1 + drivers/power/max77843_battery.c | 286 ++ 3 files changed, 296 insertions(+) create mode 100644 drivers/power/max77843_battery.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 994793d..555e436 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -212,6 +212,15 @@ config BATTERY_MAX17042 with MAX17042. This driver also supports max17047/50 chips which are improved version of max17042. +config BATTERY_MAX77843 + tristate "Maxim MAX77843 Fuel Gauge" + depends on MFD_MAX77843 + help + This adds support for battery fuel gauge in Maxim MAX77843. It is + fuel-gauge for a lithium-ion batteries with a single cell and can be + found in portable devices. The MAX17040 is configured to operate with + a single lithium cell. + config BATTERY_Z2 tristate "Z2 battery driver" depends on I2C && MACH_ZIPIT2 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index ed69cea..59e3945 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -34,6 +34,7 @@ obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o obj-$(CONFIG_BATTERY_DA9052) += da9052-battery.o obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o +obj-$(CONFIG_BATTERY_MAX77843) += max77843_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_RT5033) += rt5033_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o diff --git a/drivers/power/max77843_battery.c b/drivers/power/max77843_battery.c new file mode 100644 index 000..0c59a16 --- /dev/null +++ b/drivers/power/max77843_battery.c @@ -0,0 +1,286 @@ +/* + * Fuel gauge driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_battery { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; +}; + +static int max77843_battery_get_capacity(struct max77843_battery *battery) +{ + struct regmap *regmap = battery->regmap; + int ret, val; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_FG_REG_SOCREP, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data >> 8; + + return val; +} + +static int max77843_battery_get_energy_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_ENERGY_FULL: + reg = MAX77843_FG_REG_FULLCAP; + break; + case POWER_SUPPLY_PROP_ENERGY_NOW: + reg = MAX77843_FG_REG_REMCAP_REP; + break; + case POWER_SUPPLY_PROP_ENERGY_AVG: + reg = MAX77843_FG_REG_REMCAP_AV; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + + return val; +} + +static int max77843_battery_get_current_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_CURRENT_NOW: + reg = MAX77843_FG_REG_CURRENT; + break; + case POWER_SUPPLY_PROP_CURRENT_AVG: + reg = MAX77843_FG_REG_AVG_CURRENT; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + if (val & 0x8000) { + /* Negative */ + val = ~val & 0x; + val++; + val
[PATCH v6 2/5] power: max77843_charger: Add Max77843 charger device driver
From: Beomho Seo This patch adds device driver of max77843 charger. This driver provide initialize each charging mode(e.g. fast charge, top-off mode and constant charging mode so on.). Additionally, control charging parameters to use i2c interface. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|7 + drivers/power/Makefile |1 + drivers/power/max77843_charger.c | 508 ++ 3 files changed, 516 insertions(+) create mode 100644 drivers/power/max77843_charger.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 27b751b..994793d 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -337,6 +337,13 @@ config CHARGER_MAX77693 help Say Y to enable support for the Maxim MAX77693 battery charger. +config CHARGER_MAX77843 + tristate "Maxim MAX77843 battery charger driver" + depends on MFD_MAX77843 + help + Say Y to enable support for the battery charger control sysfs and + platform data of MAX77843 + config CHARGER_MAX8997 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" depends on MFD_MAX8997 && REGULATOR_MAX8997 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 36f9e0d..ed69cea 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_CHARGER_GPIO)+= gpio-charger.o obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o obj-$(CONFIG_CHARGER_MAX77693) += max77693_charger.o +obj-$(CONFIG_CHARGER_MAX77843) += max77843_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o diff --git a/drivers/power/max77843_charger.c b/drivers/power/max77843_charger.c new file mode 100644 index 000..392eebc1a --- /dev/null +++ b/drivers/power/max77843_charger.c @@ -0,0 +1,508 @@ +/* + * Charger driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_charger_info { + u32 fast_charge_uamp; + u32 top_off_uamp; + u32 input_uamp_limit; +}; + +struct max77843_charger { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; + + struct max77843_charger_info*info; +}; + +static int max77843_charger_get_max_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_09, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read max current register: %d\n", ret); + return ret; + } + + if (reg_data <= 0x03) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MIN; + } else if (reg_data >= 0x78) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MAX; + } else { + val = reg_data / 3; + if (reg_data % 3 == 0) + val *= 10; + else if (reg_data % 3 == 1) + val = val * 10 + 33000; + else + val = val * 10 + 67000; + } + + return val; +} + +static int max77843_charger_get_now_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charge current register: %d\n", ret); + return ret; + } + + reg_data &= MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (reg_data <= 0x02) + val = MAX77843_CHG_FAST_CHG_CURRENT_MIN; + else if (reg_data >= 0x3f) + val = MAX77843_CHG_FAST_CHG_CURRENT_MAX; + else + val = reg_data * MAX77843_CHG_FAST_CHG_CURRENT_STEP; + + return val; +} + +static int max77843_charger_get_online(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_INT_OK, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charger status: %d\n", ret); + return ret; + } + + if (reg_data & MAX77843
[PATCH v6 0/5] Add new MFD driver for MAX77843
This patch series adds MAX77843(Multi Function Device) driver. The MAX77843 includes MUIC(Micro USB Interface Controller), Li+ Charger with Fuel Gauge, 2 safeout LDOs for USB device and haptic controller using PWM. It is interfaced to host controller using I2C. Changes in v6: HAPTIC - fixed a situation where holding a mutex return. Changes in v5: MFD Core - Use bracket in complex define. - Delete unnecessary letter '++' Charger - fix Kconfig merge conflict with Kernel version4.0 Changes in v4: MFD Core - Fix indentation - Add haptic register define in header HAPTIC - Add haptic driver Changes in v3: MFD Core - Fix wrong description and indentation in header. - Remove unnecessary variable. Regulator - Use ARRAY_SIZE() instead of define. Changes in v2: MFD Core - Fix charger regmap handle and typo. MUIC - Cleanup enum list. - Set path before send excon event. - Fix variable names and typos for readability. Charger - Remove unnecessary header. - Chnage error message more readable. - Remove unnecessary lines. Fuelgauge - Fix regmap_config and use regmap_read. - Add i2c_unregister_device function on *_remove function. - Fix typo in Kconfig. Doc - Remove unnecessary lines. - Add example of charger regulator. Beomho Seo (2): power: max77843_charger: Add Max77843 charger device driver power: max77843_battery: Add Max77843 fuel gauge device driver Jaewon Kim (3): mfd: max77843: Add max77843 MFD driver core driver Input: add haptic drvier on max77843 Documentation: Add device tree bindings document for max77843 Documentation/devicetree/bindings/mfd/max77843.txt | 110 + drivers/input/misc/Kconfig | 12 + drivers/input/misc/Makefile|1 + drivers/input/misc/max77843-haptic.c | 358 ++ drivers/mfd/Kconfig| 14 + drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 248 ++ drivers/power/Kconfig | 16 + drivers/power/Makefile |2 + drivers/power/max77843_battery.c | 286 +++ drivers/power/max77843_charger.c | 508 include/linux/mfd/max77843-private.h | 454 + 12 files changed, 2010 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt create mode 100644 drivers/input/misc/max77843-haptic.c create mode 100644 drivers/mfd/max77843.c create mode 100644 drivers/power/max77843_battery.c create mode 100644 drivers/power/max77843_charger.c create mode 100644 include/linux/mfd/max77843-private.h -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v6 1/5] mfd: max77843: Add max77843 MFD driver core driver
This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 248 +++ include/linux/mfd/max77843-private.h | 454 ++ 4 files changed, 717 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 38356e3..f2fd5e5 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -455,6 +455,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77843 + bool "Maxim Semiconductor MAX77843 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim Semiconductor MAX77843. + This is companion Power Management IC with LEDs, Haptic, Charger, + Fuel Gauge, MUIC(Micro USB Interface Controller) controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX8907 tristate "Maxim Semiconductor MAX8907 PMIC Support" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 19f3d74..b8ac555 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -117,6 +117,7 @@ obj-$(CONFIG_MFD_DA9150)+= da9150-core.o obj-$(CONFIG_MFD_MAX14577) += max14577.o obj-$(CONFIG_MFD_MAX77686) += max77686.o obj-$(CONFIG_MFD_MAX77693) += max77693.o +obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c new file mode 100644 index 000..2d8b3cc --- /dev/null +++ b/drivers/mfd/max77843.c @@ -0,0 +1,248 @@ +/* + * max77843.c - MFD core driver for the Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell max77843_devs[] = { + { + .name = "max77843-muic", + .of_compatible = "maxim,max77843-muic", + }, { + .name = "max77843-regulator", + .of_compatible = "maxim,max77843-regulator", + }, { + .name = "max77843-charger", + .of_compatible = "maxim,max77843-charger" + }, { + .name = "max77843-fuelgauge", + .of_compatible = "maxim,max77843-fuelgauge", + }, { + .name = "max77843-haptic", + .of_compatible = "maxim,max77843-haptic", + }, +}; + +static const struct regmap_config max77843_charger_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_CHG_REG_END, +}; + +static const struct regmap_config max77843_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_SYS_REG_END, +}; + +static const struct regmap_irq max77843_irqs[] = { + /* TOPSYS interrupts */ + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSUVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSOVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TSHDN_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77843_irq_chip = { + .name = "max77843", + .status_base= MAX77843_SYS_REG_SYSINTSRC, + .mask_base = MAX77843_SYS_REG_SYSINTMASK, + .mask_invert= false, + .num_regs = 1, + .irqs = max77843_irqs, + .num_irqs = ARRAY_SIZE(max77843_irqs), +}; + +/* Charger and Charger regulator use same regmap. */ +static int max77843_chg_init(struct max77843 *max77843) +{ + int ret; + + max77843->i2c_chg = i2c_new_dummy(max77843->i2c->adapter, I2C_ADDR_CHG); + if (!max77843->i2c_chg) { + dev_err(&max77843->i2c->dev, +
Re: [PATCH v4 4/5] Input: add haptic drvier on max77843
Hi Dmitry Torokhov, On 02/24/2015 02:26 AM, Dmitry Torokhov wrote: Hi Jaew9on, On Mon, Feb 23, 2015 at 05:09:50PM +0900, Jaewon Kim wrote: This patch adds support for haptic driver on max77843 MFD(Multi Function Device) with PMIC, MUIC, LED, CHARGER. This driver supports external pwm and LRA(Linear Resonant Actuator) motor. And it supports ff-memless interface from inpu framework. Cc: Dmitry Torokhov Signed-off-by: Jaewon Kim ... +static void max77843_haptic_play_work(struct work_struct *work) +{ + struct max77843_haptic *haptic = + container_of(work, struct max77843_haptic, work); + int error; + + mutex_lock(&haptic->mutex); + + if (haptic->suspended) + mutex_unlock(&haptic->mutex); Huh? This code prevent to play haptic when entering suspend state. But I forgot return. I will add return 0 in version 6. + + error = max77843_haptic_set_duty_cycle(haptic); + if (error) { + dev_err(haptic->dev, "failed to set duty cycle: %d\n", error); + return; Here you are leaving with the mutex held. Okay, I will add mutex_unlock(). + } + + if (haptic->magnitude) { + error = max77843_haptic_enable(haptic); + if (error) + dev_err(haptic->dev, + "cannot enable haptic: %d\n", error); + } else { + max77843_haptic_disable(haptic); + if (error) + dev_err(haptic->dev, + "cannot disable haptic: %d\n", error); + } + + mutex_unlock(&haptic->mutex); +} + The rest seems quite reasonable. Thanks. Thanks to review my patch. Thanks, Jaewon Kim -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 2/5] power: max77843_charger: Add Max77843 charger device driver
From: Beomho Seo This patch adds device driver of max77843 charger. This driver provide initialize each charging mode(e.g. fast charge, top-off mode and constant charging mode so on.). Additionally, control charging parameters to use i2c interface. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|7 + drivers/power/Makefile |1 + drivers/power/max77843_charger.c | 508 ++ 3 files changed, 516 insertions(+) create mode 100644 drivers/power/max77843_charger.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 27b751b..994793d 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -337,6 +337,13 @@ config CHARGER_MAX77693 help Say Y to enable support for the Maxim MAX77693 battery charger. +config CHARGER_MAX77843 + tristate "Maxim MAX77843 battery charger driver" + depends on MFD_MAX77843 + help + Say Y to enable support for the battery charger control sysfs and + platform data of MAX77843 + config CHARGER_MAX8997 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" depends on MFD_MAX8997 && REGULATOR_MAX8997 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 36f9e0d..ed69cea 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_CHARGER_GPIO)+= gpio-charger.o obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o obj-$(CONFIG_CHARGER_MAX77693) += max77693_charger.o +obj-$(CONFIG_CHARGER_MAX77843) += max77843_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o diff --git a/drivers/power/max77843_charger.c b/drivers/power/max77843_charger.c new file mode 100644 index 000..392eebc1a --- /dev/null +++ b/drivers/power/max77843_charger.c @@ -0,0 +1,508 @@ +/* + * Charger driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_charger_info { + u32 fast_charge_uamp; + u32 top_off_uamp; + u32 input_uamp_limit; +}; + +struct max77843_charger { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; + + struct max77843_charger_info*info; +}; + +static int max77843_charger_get_max_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_09, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read max current register: %d\n", ret); + return ret; + } + + if (reg_data <= 0x03) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MIN; + } else if (reg_data >= 0x78) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MAX; + } else { + val = reg_data / 3; + if (reg_data % 3 == 0) + val *= 10; + else if (reg_data % 3 == 1) + val = val * 10 + 33000; + else + val = val * 10 + 67000; + } + + return val; +} + +static int max77843_charger_get_now_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charge current register: %d\n", ret); + return ret; + } + + reg_data &= MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (reg_data <= 0x02) + val = MAX77843_CHG_FAST_CHG_CURRENT_MIN; + else if (reg_data >= 0x3f) + val = MAX77843_CHG_FAST_CHG_CURRENT_MAX; + else + val = reg_data * MAX77843_CHG_FAST_CHG_CURRENT_STEP; + + return val; +} + +static int max77843_charger_get_online(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_INT_OK, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charger status: %d\n", ret); + return ret; + } + + if (reg_data & MAX77843
[PATCH v5 4/5] Input: add haptic drvier on max77843
This patch adds support for haptic driver on max77843 MFD(Multi Function Device) with PMIC, MUIC, LED, CHARGER. This driver supports external pwm and LRA(Linear Resonant Actuator) motor. And it supports ff-memless interface from inpu framework. Cc: Dmitry Torokhov Signed-off-by: Jaewon Kim --- drivers/input/misc/Kconfig | 12 ++ drivers/input/misc/Makefile |1 + drivers/input/misc/max77843-haptic.c | 356 ++ 3 files changed, 369 insertions(+) create mode 100644 drivers/input/misc/max77843-haptic.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 6deb8da..aa8c072 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -165,6 +165,18 @@ config INPUT_MAX77693_HAPTIC To compile this driver as module, choose M here: the module will be called max77693-haptic. +config INPUT_MAX77843_HAPTIC +tristate "MAXIM MAX77843 haptic controller support" +depends on MFD_MAX77843 && PWM +select INPUT_FF_MEMLESS +help + This option enables support for the haptic controller on + MAXIM MAX77843 chip. The driver supports ff-memless interface + from input framework. + + To compile this driver as module, choose M here: the + module will be called max77843-haptic. + config INPUT_MAX8925_ONKEY tristate "MAX8925 ONKEY support" depends on MFD_MAX8925 diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 403a1a5..75b5884 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)+= keyspan_remote.o obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC)+= max77693-haptic.o +obj-$(CONFIG_INPUT_MAX77843_HAPTIC)+= max77843-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o obj-$(CONFIG_INPUT_MAX8997_HAPTIC) += max8997_haptic.o obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o diff --git a/drivers/input/misc/max77843-haptic.c b/drivers/input/misc/max77843-haptic.c new file mode 100644 index 000..3167c83 --- /dev/null +++ b/drivers/input/misc/max77843-haptic.c @@ -0,0 +1,356 @@ +/* + * MAXIM MAX77693 Haptic device driver + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_MAGNITUDE_SHIFT16 + +enum max77843_haptic_motor_type { + MAX77843_HAPTIC_ERM = 0, + MAX77843_HAPTIC_LRA, +}; + +enum max77843_haptic_pwm_divisor { + MAX77843_HAPTIC_PWM_DIVISOR_32 = 0, + MAX77843_HAPTIC_PWM_DIVISOR_64, + MAX77843_HAPTIC_PWM_DIVISOR_128, + MAX77843_HAPTIC_PWM_DIVISOR_256, +}; + +struct max77843_haptic { + struct regmap *regmap_haptic; + struct device *dev; + struct input_dev *input_dev; + struct pwm_device *pwm_dev; + struct regulator *motor_reg; + struct work_struct work; + struct mutex mutex; + + unsigned int magnitude; + unsigned int pwm_duty; + + bool active; + bool suspended; + + enum max77843_haptic_motor_type type; + enum max77843_haptic_pwm_divisor pwm_divisor; +}; + +static int max77843_haptic_set_duty_cycle(struct max77843_haptic *haptic) +{ + int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2; + int error; + + error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period); + if (error) { + dev_err(haptic->dev, "failed to configure pwm: %d\n", error); + return error; + } + + return 0; +} + +static int max77843_haptic_bias(struct max77843_haptic *haptic, bool on) +{ + int error; + + error = regmap_update_bits(haptic->regmap_haptic, + MAX77843_SYS_REG_MAINCTRL1, + MAX77843_MAINCTRL1_BIASEN_MASK, + on << MAINCTRL1_BIASEN_SHIFT); + if (error) { + dev_err(haptic->dev, "failed to %s bias: %d\n", + on ? "enable" : "disable", error); + return error; + } + + return 0; +} + +static int max77843_haptic_config(struct max77843_haptic *haptic, bool enable) +{ + unsigned int value; + int error; + + value = ((haptic->type << MCONFIG_MODE_SHIFT) | + (enable << MCONFIG_MEN_SHIFT) | + (haptic->pwm_divisor << MCONFI
[PATCH v5 5/5] Documentation: Add device tree bindings document for max77843
Add document describing device tree bindings for max77843 MFD. Drivers: MFD core, regulator, extcon, charger and fuelgauge. Cc: Rob Herring Cc: Pawel Moll Cc: Mark Rutland Cc: Ian Campbell Cc: Kumar Gala Cc: Lee Jones Cc: Sebastian Reichel Cc: Dmitry Torokhov Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- Documentation/devicetree/bindings/mfd/max77843.txt | 110 1 file changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt diff --git a/Documentation/devicetree/bindings/mfd/max77843.txt b/Documentation/devicetree/bindings/mfd/max77843.txt new file mode 100644 index 000..76426ca --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/max77843.txt @@ -0,0 +1,110 @@ +Maxim MAX77843 multi-function device + +MAX77843 is a Multi-Function Device with the following submodules: +- PMIC : 2 SAFEOUT LDOs for USB device +- CHARGER : Li+ battery charger with Fuel Gauge +- MUIC : Micro USB Interface Controller +- HAPTIC : Motor Controller for tactile feedback + +It is interfaced to host controller using I2C. + +Required properties: +- compatible : Must be "maxim,max77843". +- reg : I2C slave address of PMIC block. +- interrupts : I2C line for main SoCs. +- interrupt-parent : The parent of interrupt controller. + +Optional properties: +- regulators : The regulators of max77843 have to be instantiated under subnode + named "regulators" using the following format. + + [*]refer : Documentation/devicetree/bindings/regulator/regulator.txt + + regulators { + SAFEOUT { + regulator-name = "SAFEOUT"; + }; + } + + List of valid regulator names: + - SAFEOUT1, SAFEOUT2, CHARGER. + +- max77843-muic : This properties used by extcon consumers. + Required properties: + - compatible : Must be "maxim,max77842-muic". + +- max77843-charger : There battery charger of MAX77843 have to be instantiated + under sub-node named "max77843-charger" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-charger". + - maxim,fast-charge-uamp : Fast charge current levels are + 100 mA to 3150 mA programmed by I2C per 100 mA. + - maxim,top-off-uamp : Top off current threshold levels are + 125 mA to 650 mA programmed by I2C per 75 mA. + - maxim,input-uamp-limit : Input current limit levels are + 100 mA to 3533 mA programmed by I2C per 33 mA. + +- max77843-fuelgauge : There fuelgauge of MAX77843 have to be instantiated + under sub-node named "max77843-fuelgauge" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-fuelgauge". + +- max77843-haptic : The MAX77843 haptic device provides the tactile feedback + to the user by using PWM(Pulse Width Modulation) signal. + Required properties: + - compatible : Must be "maxim,max77843-hpatic". + - haptic-supply : Power supply for the haptic motor. + [*] refer Documentation/devicetree/ + bindings/regulator/regulator.txt + - pwms : phandle for the PWM(Pulse Width Modulation) device. + PWM properties should be named "pwms". + [*] refer Documentation/devicetree/bindings/pwm/pwm.txt + +Example: + max77843@66 { + compatible = "samsung,max77843"; + reg = <0x66>; + interrupt-parent = <&gpa1>; + interrupts = <5 2>; + + regulators { + SAFEOUT1 { + regulator-name = "SAFEOUT1"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + SAFEOUT2 { + regulator-name = "SAFEOUT2"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + CHARGER { + regulator-name = "CHARGER"; + regulator-min-microamp = <10>; + regulator-max-microamp = <315>; + }; + }; + + haptic { + compatible = "maxim,max77843-haptic"; + haptic-supply = <&haptic_supply>; + pwms = <&pwm 0 4 0>; + pwm-na
[PATCH v5 3/5] power: max77843_battery: Add Max77843 fuel gauge device driver
From: Beomho Seo This patch adds device driver of max77843 fuel gauge. The driver support for battery fuel gauge in Maxim Max77843. It is fuel-gauge systems for lithuum-ion batteries in handled and portable devices. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|9 ++ drivers/power/Makefile |1 + drivers/power/max77843_battery.c | 286 ++ 3 files changed, 296 insertions(+) create mode 100644 drivers/power/max77843_battery.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 994793d..555e436 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -212,6 +212,15 @@ config BATTERY_MAX17042 with MAX17042. This driver also supports max17047/50 chips which are improved version of max17042. +config BATTERY_MAX77843 + tristate "Maxim MAX77843 Fuel Gauge" + depends on MFD_MAX77843 + help + This adds support for battery fuel gauge in Maxim MAX77843. It is + fuel-gauge for a lithium-ion batteries with a single cell and can be + found in portable devices. The MAX17040 is configured to operate with + a single lithium cell. + config BATTERY_Z2 tristate "Z2 battery driver" depends on I2C && MACH_ZIPIT2 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index ed69cea..59e3945 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -34,6 +34,7 @@ obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o obj-$(CONFIG_BATTERY_DA9052) += da9052-battery.o obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o +obj-$(CONFIG_BATTERY_MAX77843) += max77843_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_RT5033) += rt5033_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o diff --git a/drivers/power/max77843_battery.c b/drivers/power/max77843_battery.c new file mode 100644 index 000..0c59a16 --- /dev/null +++ b/drivers/power/max77843_battery.c @@ -0,0 +1,286 @@ +/* + * Fuel gauge driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_battery { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; +}; + +static int max77843_battery_get_capacity(struct max77843_battery *battery) +{ + struct regmap *regmap = battery->regmap; + int ret, val; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_FG_REG_SOCREP, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data >> 8; + + return val; +} + +static int max77843_battery_get_energy_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_ENERGY_FULL: + reg = MAX77843_FG_REG_FULLCAP; + break; + case POWER_SUPPLY_PROP_ENERGY_NOW: + reg = MAX77843_FG_REG_REMCAP_REP; + break; + case POWER_SUPPLY_PROP_ENERGY_AVG: + reg = MAX77843_FG_REG_REMCAP_AV; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + + return val; +} + +static int max77843_battery_get_current_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_CURRENT_NOW: + reg = MAX77843_FG_REG_CURRENT; + break; + case POWER_SUPPLY_PROP_CURRENT_AVG: + reg = MAX77843_FG_REG_AVG_CURRENT; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + if (val & 0x8000) { + /* Negative */ + val = ~val & 0x; + val++; + val
[PATCH v5 1/5] mfd: max77843: Add max77843 MFD driver core driver
This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 248 +++ include/linux/mfd/max77843-private.h | 454 ++ 4 files changed, 717 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 38356e3..f2fd5e5 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -455,6 +455,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77843 + bool "Maxim Semiconductor MAX77843 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim Semiconductor MAX77843. + This is companion Power Management IC with LEDs, Haptic, Charger, + Fuel Gauge, MUIC(Micro USB Interface Controller) controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX8907 tristate "Maxim Semiconductor MAX8907 PMIC Support" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 19f3d74..b8ac555 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -117,6 +117,7 @@ obj-$(CONFIG_MFD_DA9150)+= da9150-core.o obj-$(CONFIG_MFD_MAX14577) += max14577.o obj-$(CONFIG_MFD_MAX77686) += max77686.o obj-$(CONFIG_MFD_MAX77693) += max77693.o +obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c new file mode 100644 index 000..2d8b3cc --- /dev/null +++ b/drivers/mfd/max77843.c @@ -0,0 +1,248 @@ +/* + * max77843.c - MFD core driver for the Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell max77843_devs[] = { + { + .name = "max77843-muic", + .of_compatible = "maxim,max77843-muic", + }, { + .name = "max77843-regulator", + .of_compatible = "maxim,max77843-regulator", + }, { + .name = "max77843-charger", + .of_compatible = "maxim,max77843-charger" + }, { + .name = "max77843-fuelgauge", + .of_compatible = "maxim,max77843-fuelgauge", + }, { + .name = "max77843-haptic", + .of_compatible = "maxim,max77843-haptic", + }, +}; + +static const struct regmap_config max77843_charger_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_CHG_REG_END, +}; + +static const struct regmap_config max77843_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_SYS_REG_END, +}; + +static const struct regmap_irq max77843_irqs[] = { + /* TOPSYS interrupts */ + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSUVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSOVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TSHDN_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77843_irq_chip = { + .name = "max77843", + .status_base= MAX77843_SYS_REG_SYSINTSRC, + .mask_base = MAX77843_SYS_REG_SYSINTMASK, + .mask_invert= false, + .num_regs = 1, + .irqs = max77843_irqs, + .num_irqs = ARRAY_SIZE(max77843_irqs), +}; + +/* Charger and Charger regulator use same regmap. */ +static int max77843_chg_init(struct max77843 *max77843) +{ + int ret; + + max77843->i2c_chg = i2c_new_dummy(max77843->i2c->adapter, I2C_ADDR_CHG); + if (!max77843->i2c_chg) { + dev_err(&max77843->i2c->dev, +
[PATCH v5 0/5] Add new MFD drvier for MAX77843
This patch series adds MAX77843(Multi Function Device) driver. The MAX77843 includes MUIC(Micro USB Interface Controller), Li+ Charger with Fuel Gauge, 2 safeout LDOs for USB device and haptic controller using PWM. It is interfaced to host controller using I2C. Changes in v5: MFD Core - Use bracket in complex define. - Delete unnecessary letter '++' Charger - fix Kconfig merge conflict with Kernel version4.0 Changes in v4: MFD Core - Fix indentation - Add haptic register define in header HAPTIC - Add haptic driver Changes in v3: MFD Core - Fix wrong description and indentation in header. - Remove unnecessary variable. Regulator - Use ARRAY_SIZE() instead of define. Changes in v2: MFD Core - Fix charger regmap handle and typo. MUIC - Cleanup enum list. - Set path before send excon event. - Fix variable names and typos for readability. Charger - Remove unnecessary header. - Chnage error message more readable. - Remove unnecessary lines. Fuelgauge - Fix regmap_config and use regmap_read. - Add i2c_unregister_device function on *_remove function. - Fix typo in Kconfig. Doc - Remove unnecessary lines. - Add example of charger regulator. Beomho Seo (2): power: max77843_charger: Add Max77843 charger device driver power: max77843_battery: Add Max77843 fuel gauge device driver Jaewon Kim (3): mfd: max77843: Add max77843 MFD driver core driver Input: add haptic drvier on max77843 Documentation: Add device tree bindings document for max77843 Documentation/devicetree/bindings/mfd/max77843.txt | 110 + drivers/input/misc/Kconfig | 12 + drivers/input/misc/Makefile|1 + drivers/input/misc/max77843-haptic.c | 356 ++ drivers/mfd/Kconfig| 14 + drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 248 ++ drivers/power/Kconfig | 16 + drivers/power/Makefile |2 + drivers/power/max77843_battery.c | 286 +++ drivers/power/max77843_charger.c | 508 include/linux/mfd/max77843-private.h | 454 + 12 files changed, 2008 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt create mode 100644 drivers/input/misc/max77843-haptic.c create mode 100644 drivers/mfd/max77843.c create mode 100644 drivers/power/max77843_battery.c create mode 100644 drivers/power/max77843_charger.c create mode 100644 include/linux/mfd/max77843-private.h -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 0/5] Add new MFD drvier for MAX77843
I missed description of this patch series. This patch series adds MAX77843(Multi Function Device) driver. The MAX77843 includes MUIC(Micro USB Interface Controller), Li+ Charger with Fuel Gauge, 2 safeout LDOs for USB device and haptic controller using PWM. It is interfaced to host controller using I2C. On 02/23/2015 05:09 PM, Jaewon Kim wrote: Changes in v4: MFD Core - fix indentation HAPTIC - Add haptic driver Changes in v3: MFD Core - fix wrong description and indentation in header. - remove unnecessary variable. Regulator - use ARRAY_SIZE() instead of define. Changes in v2: MFD Core - Fix charger regmap handle and typo. MUIC - cleanup enum list. - set path before send excon event. - fix variable names and typos for readability. Charger - Remove unnecessary header. - Chnage error message more readable. - Remove unnecessary lines. Fuelgauge - Fix regmap_config and use regmap_read. - Add i2c_unregister_device function on *_remove function. - Fix typo in Kconfig. Doc - Remove unnecessary lines. - Add example of charger regulator. Beomho Seo (2): power: max77843_charger: Add Max77843 charger device driver power: max77843_battery: Add Max77843 fuel gauge device driver Jaewon Kim (3): mfd: max77843: Add max77843 MFD driver core driver Input: add haptic drvier on max77843 Documentation: Add device tree bindings document for max77843 Documentation/devicetree/bindings/mfd/max77843.txt | 110 + drivers/input/misc/Kconfig | 12 + drivers/input/misc/Makefile|1 + drivers/input/misc/max77843-haptic.c | 356 ++ drivers/mfd/Kconfig| 14 + drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 248 ++ drivers/power/Kconfig | 16 + drivers/power/Makefile |2 + drivers/power/max77843_battery.c | 286 +++ drivers/power/max77843_charger.c | 508 include/linux/mfd/max77843-private.h | 454 + 12 files changed, 2008 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt create mode 100644 drivers/input/misc/max77843-haptic.c create mode 100644 drivers/mfd/max77843.c create mode 100644 drivers/power/max77843_battery.c create mode 100644 drivers/power/max77843_charger.c create mode 100644 include/linux/mfd/max77843-private.h Thanks, Jaewon Kim -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v4 2/5] power: max77843_charger: Add Max77843 charger device driver
From: Beomho Seo This patch adds device driver of max77843 charger. This driver provide initialize each charging mode(e.g. fast charge, top-off mode and constant charging mode so on.). Additionally, control charging paramters to use i2c interface. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|7 + drivers/power/Makefile |1 + drivers/power/max77843_charger.c | 508 ++ 3 files changed, 516 insertions(+) create mode 100644 drivers/power/max77843_charger.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 0108c2a..a054a28 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -332,6 +332,13 @@ config CHARGER_MAX14577 Say Y to enable support for the battery charger control sysfs and platform data of MAX14577/77836 MUICs. +config CHARGER_MAX77843 + tristate "Maxim MAX77843 battery charger driver" + depends on MFD_MAX77843 + help + Say Y to enable support for the battery charger control sysfs and + platform data of MAX77843 + config CHARGER_MAX8997 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" depends on MFD_MAX8997 && REGULATOR_MAX8997 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index dfa8942..212c6a2 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_CHARGER_LP8788) += lp8788-charger.o obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o +obj-$(CONFIG_CHARGER_MAX77843) += max77843_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o diff --git a/drivers/power/max77843_charger.c b/drivers/power/max77843_charger.c new file mode 100644 index 000..392eebc1a --- /dev/null +++ b/drivers/power/max77843_charger.c @@ -0,0 +1,508 @@ +/* + * Charger driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_charger_info { + u32 fast_charge_uamp; + u32 top_off_uamp; + u32 input_uamp_limit; +}; + +struct max77843_charger { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; + + struct max77843_charger_info*info; +}; + +static int max77843_charger_get_max_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_09, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read max current register: %d\n", ret); + return ret; + } + + if (reg_data <= 0x03) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MIN; + } else if (reg_data >= 0x78) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MAX; + } else { + val = reg_data / 3; + if (reg_data % 3 == 0) + val *= 10; + else if (reg_data % 3 == 1) + val = val * 10 + 33000; + else + val = val * 10 + 67000; + } + + return val; +} + +static int max77843_charger_get_now_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charge current register: %d\n", ret); + return ret; + } + + reg_data &= MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (reg_data <= 0x02) + val = MAX77843_CHG_FAST_CHG_CURRENT_MIN; + else if (reg_data >= 0x3f) + val = MAX77843_CHG_FAST_CHG_CURRENT_MAX; + else + val = reg_data * MAX77843_CHG_FAST_CHG_CURRENT_STEP; + + return val; +} + +static int max77843_charger_get_online(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_INT_OK, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charger status: %d\n", ret); + return ret; +
[PATCH v4 5/5] Documentation: Add device tree bindings document for max77843
Add document describing device tree bindings for max77843 MFD. Drivers: MFD core, regulator, extcon, charger and fuelgauge. Cc: Rob Herring Cc: Pawel Moll Cc: Mark Rutland Cc: Ian Campbell Cc: Kumar Gala Cc: Lee Jones Cc: Sebastian Reichel Cc: Dmitry Torokhov Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- Documentation/devicetree/bindings/mfd/max77843.txt | 110 1 file changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt diff --git a/Documentation/devicetree/bindings/mfd/max77843.txt b/Documentation/devicetree/bindings/mfd/max77843.txt new file mode 100644 index 000..76426ca --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/max77843.txt @@ -0,0 +1,110 @@ +Maxim MAX77843 multi-function device + +MAX77843 is a Multi-Function Device with the following submodules: +- PMIC : 2 SAFEOUT LDOs for USB device +- CHARGER : Li+ battery charger with Fuel Gauge +- MUIC : Micro USB Interface Controller +- HAPTIC : Motor Controller for tactile feedback + +It is interfaced to host controller using I2C. + +Required properties: +- compatible : Must be "maxim,max77843". +- reg : I2C slave address of PMIC block. +- interrupts : I2C line for main SoCs. +- interrupt-parent : The parent of interrupt controller. + +Optional properties: +- regulators : The regulators of max77843 have to be instantiated under subnode + named "regulators" using the following format. + + [*]refer : Documentation/devicetree/bindings/regulator/regulator.txt + + regulators { + SAFEOUT { + regulator-name = "SAFEOUT"; + }; + } + + List of valid regulator names: + - SAFEOUT1, SAFEOUT2, CHARGER. + +- max77843-muic : This properties used by extcon consumers. + Required properties: + - compatible : Must be "maxim,max77842-muic". + +- max77843-charger : There battery charger of MAX77843 have to be instantiated + under sub-node named "max77843-charger" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-charger". + - maxim,fast-charge-uamp : Fast charge current levels are + 100 mA to 3150 mA programmed by I2C per 100 mA. + - maxim,top-off-uamp : Top off current threshold levels are + 125 mA to 650 mA programmed by I2C per 75 mA. + - maxim,input-uamp-limit : Input current limit levels are + 100 mA to 3533 mA programmed by I2C per 33 mA. + +- max77843-fuelgauge : There fuelgauge of MAX77843 have to be instantiated + under sub-node named "max77843-fuelgauge" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-fuelgauge". + +- max77843-haptic : The MAX77843 haptic device provides the tactile feedback + to the user by using PWM(Pulse Width Modulation) signal. + Required properties: + - compatible : Must be "maxim,max77843-hpatic". + - haptic-supply : Power supply for the haptic motor. + [*] refer Documentation/devicetree/ + bindings/regulator/regulator.txt + - pwms : phandle for the PWM(Pulse Width Modulation) device. + PWM properties should be named "pwms". + [*] refer Documentation/devicetree/bindings/pwm/pwm.txt + +Example: + max77843@66 { + compatible = "samsung,max77843"; + reg = <0x66>; + interrupt-parent = <&gpa1>; + interrupts = <5 2>; + + regulators { + SAFEOUT1 { + regulator-name = "SAFEOUT1"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + SAFEOUT2 { + regulator-name = "SAFEOUT2"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + CHARGER { + regulator-name = "CHARGER"; + regulator-min-microamp = <10>; + regulator-max-microamp = <315>; + }; + }; + + haptic { + compatible = "maxim,max77843-haptic"; + haptic-supply = <&haptic_supply>; + pwms = <&pwm 0 4 0>; + pwm-na
[PATCH v4 4/5] Input: add haptic drvier on max77843
This patch adds support for haptic driver on max77843 MFD(Multi Function Device) with PMIC, MUIC, LED, CHARGER. This driver supports external pwm and LRA(Linear Resonant Actuator) motor. And it supports ff-memless interface from inpu framework. Cc: Dmitry Torokhov Signed-off-by: Jaewon Kim --- drivers/input/misc/Kconfig | 12 ++ drivers/input/misc/Makefile |1 + drivers/input/misc/max77843-haptic.c | 356 ++ 3 files changed, 369 insertions(+) create mode 100644 drivers/input/misc/max77843-haptic.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 23297ab..64e4e91 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -155,6 +155,18 @@ config INPUT_MAX77693_HAPTIC To compile this driver as module, choose M here: the module will be called max77693-haptic. +config INPUT_MAX77843_HAPTIC +tristate "MAXIM MAX77843 haptic controller support" +depends on MFD_MAX77843 && PWM +select INPUT_FF_MEMLESS +help + This option enables support for the haptic controller on + MAXIM MAX77843 chip. The driver supports ff-memless interface + from input framework. + + To compile this driver as module, choose M here: the + module will be called max77843-haptic. + config INPUT_MAX8925_ONKEY tristate "MAX8925 ONKEY support" depends on MFD_MAX8925 diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 19c7603..d2a9c4a 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)+= keyspan_remote.o obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC)+= max77693-haptic.o +obj-$(CONFIG_INPUT_MAX77843_HAPTIC)+= max77843-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o obj-$(CONFIG_INPUT_MAX8997_HAPTIC) += max8997_haptic.o obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o diff --git a/drivers/input/misc/max77843-haptic.c b/drivers/input/misc/max77843-haptic.c new file mode 100644 index 000..3167c83 --- /dev/null +++ b/drivers/input/misc/max77843-haptic.c @@ -0,0 +1,356 @@ +/* + * MAXIM MAX77693 Haptic device driver + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_MAGNITUDE_SHIFT16 + +enum max77843_haptic_motor_type { + MAX77843_HAPTIC_ERM = 0, + MAX77843_HAPTIC_LRA, +}; + +enum max77843_haptic_pwm_divisor { + MAX77843_HAPTIC_PWM_DIVISOR_32 = 0, + MAX77843_HAPTIC_PWM_DIVISOR_64, + MAX77843_HAPTIC_PWM_DIVISOR_128, + MAX77843_HAPTIC_PWM_DIVISOR_256, +}; + +struct max77843_haptic { + struct regmap *regmap_haptic; + struct device *dev; + struct input_dev *input_dev; + struct pwm_device *pwm_dev; + struct regulator *motor_reg; + struct work_struct work; + struct mutex mutex; + + unsigned int magnitude; + unsigned int pwm_duty; + + bool active; + bool suspended; + + enum max77843_haptic_motor_type type; + enum max77843_haptic_pwm_divisor pwm_divisor; +}; + +static int max77843_haptic_set_duty_cycle(struct max77843_haptic *haptic) +{ + int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2; + int error; + + error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period); + if (error) { + dev_err(haptic->dev, "failed to configure pwm: %d\n", error); + return error; + } + + return 0; +} + +static int max77843_haptic_bias(struct max77843_haptic *haptic, bool on) +{ + int error; + + error = regmap_update_bits(haptic->regmap_haptic, + MAX77843_SYS_REG_MAINCTRL1, + MAX77843_MAINCTRL1_BIASEN_MASK, + on << MAINCTRL1_BIASEN_SHIFT); + if (error) { + dev_err(haptic->dev, "failed to %s bias: %d\n", + on ? "enable" : "disable", error); + return error; + } + + return 0; +} + +static int max77843_haptic_config(struct max77843_haptic *haptic, bool enable) +{ + unsigned int value; + int error; + + value = ((haptic->type << MCONFIG_MODE_SHIFT) | + (enable << MCONFIG_MEN_SHIFT) | + (haptic->pwm_divisor << MCONFI
[PATCH v4 3/5] power: max77843_battery: Add Max77843 fuel gauge device driver
From: Beomho Seo This patch adds device driver of max77843 fuel gauge. The driver support for battery fuel gauge in Maxim Max77843. It is fuel-gauge systems for lithuum-ion batteries in handled and portable devices. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|9 ++ drivers/power/Makefile |1 + drivers/power/max77843_battery.c | 286 ++ 3 files changed, 296 insertions(+) create mode 100644 drivers/power/max77843_battery.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index a054a28..cea0ea2 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -212,6 +212,15 @@ config BATTERY_MAX17042 with MAX17042. This driver also supports max17047/50 chips which are improved version of max17042. +config BATTERY_MAX77843 + tristate "Maxim MAX77843 Fuel Gauge" + depends on MFD_MAX77843 + help + This adds support for battery fuel gauge in Maxim MAX77843. It is + fuel-gauge for a lithium-ion batteries with a single cell and can be + found in portable devices. The MAX17040 is configured to operate with + a single lithium cell. + config BATTERY_Z2 tristate "Z2 battery driver" depends on I2C && MACH_ZIPIT2 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 212c6a2..ae0d795 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o obj-$(CONFIG_BATTERY_DA9052) += da9052-battery.o obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o +obj-$(CONFIG_BATTERY_MAX77843) += max77843_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o diff --git a/drivers/power/max77843_battery.c b/drivers/power/max77843_battery.c new file mode 100644 index 000..0c59a16 --- /dev/null +++ b/drivers/power/max77843_battery.c @@ -0,0 +1,286 @@ +/* + * Fuel gauge driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_battery { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; +}; + +static int max77843_battery_get_capacity(struct max77843_battery *battery) +{ + struct regmap *regmap = battery->regmap; + int ret, val; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_FG_REG_SOCREP, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data >> 8; + + return val; +} + +static int max77843_battery_get_energy_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_ENERGY_FULL: + reg = MAX77843_FG_REG_FULLCAP; + break; + case POWER_SUPPLY_PROP_ENERGY_NOW: + reg = MAX77843_FG_REG_REMCAP_REP; + break; + case POWER_SUPPLY_PROP_ENERGY_AVG: + reg = MAX77843_FG_REG_REMCAP_AV; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + + return val; +} + +static int max77843_battery_get_current_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_CURRENT_NOW: + reg = MAX77843_FG_REG_CURRENT; + break; + case POWER_SUPPLY_PROP_CURRENT_AVG: + reg = MAX77843_FG_REG_AVG_CURRENT; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + if (val & 0x8000) { + /* Negative */ + val = ~val & 0x; + val++; +
[PATCH v4 0/5] Add new MFD drvier for MAX77843
Changes in v4: MFD Core - fix indentation HAPTIC - Add haptic driver Changes in v3: MFD Core - fix wrong description and indentation in header. - remove unnecessary variable. Regulator - use ARRAY_SIZE() instead of define. Changes in v2: MFD Core - Fix charger regmap handle and typo. MUIC - cleanup enum list. - set path before send excon event. - fix variable names and typos for readability. Charger - Remove unnecessary header. - Chnage error message more readable. - Remove unnecessary lines. Fuelgauge - Fix regmap_config and use regmap_read. - Add i2c_unregister_device function on *_remove function. - Fix typo in Kconfig. Doc - Remove unnecessary lines. - Add example of charger regulator. Beomho Seo (2): power: max77843_charger: Add Max77843 charger device driver power: max77843_battery: Add Max77843 fuel gauge device driver Jaewon Kim (3): mfd: max77843: Add max77843 MFD driver core driver Input: add haptic drvier on max77843 Documentation: Add device tree bindings document for max77843 Documentation/devicetree/bindings/mfd/max77843.txt | 110 + drivers/input/misc/Kconfig | 12 + drivers/input/misc/Makefile|1 + drivers/input/misc/max77843-haptic.c | 356 ++ drivers/mfd/Kconfig| 14 + drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 248 ++ drivers/power/Kconfig | 16 + drivers/power/Makefile |2 + drivers/power/max77843_battery.c | 286 +++ drivers/power/max77843_charger.c | 508 include/linux/mfd/max77843-private.h | 454 + 12 files changed, 2008 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt create mode 100644 drivers/input/misc/max77843-haptic.c create mode 100644 drivers/mfd/max77843.c create mode 100644 drivers/power/max77843_battery.c create mode 100644 drivers/power/max77843_charger.c create mode 100644 include/linux/mfd/max77843-private.h -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v4 1/5] mfd: max77843: Add max77843 MFD driver core driver
This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 248 +++ include/linux/mfd/max77843-private.h | 454 ++ 4 files changed, 717 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 2e6b731..0c67c79 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -442,6 +442,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77843 + bool "Maxim Semiconductor MAX77843 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim Semiconductor MAX77843. + This is companion Power Management IC with LEDs, Haptic, Charger, + Fuel Gauge, MUIC(Micro USB Interface Controller) controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX8907 tristate "Maxim Semiconductor MAX8907 PMIC Support" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 53467e2..fe4f75c 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -117,6 +117,7 @@ obj-$(CONFIG_MFD_DA9063)+= da9063.o obj-$(CONFIG_MFD_MAX14577) += max14577.o obj-$(CONFIG_MFD_MAX77686) += max77686.o obj-$(CONFIG_MFD_MAX77693) += max77693.o +obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c new file mode 100644 index 000..2d8b3cc --- /dev/null +++ b/drivers/mfd/max77843.c @@ -0,0 +1,248 @@ +/* + * max77843.c - MFD core driver for the Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell max77843_devs[] = { + { + .name = "max77843-muic", + .of_compatible = "maxim,max77843-muic", + }, { + .name = "max77843-regulator", + .of_compatible = "maxim,max77843-regulator", + }, { + .name = "max77843-charger", + .of_compatible = "maxim,max77843-charger" + }, { + .name = "max77843-fuelgauge", + .of_compatible = "maxim,max77843-fuelgauge", + }, { + .name = "max77843-haptic", + .of_compatible = "maxim,max77843-haptic", + }, +}; + +static const struct regmap_config max77843_charger_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_CHG_REG_END, +}; + +static const struct regmap_config max77843_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_SYS_REG_END, +}; + +static const struct regmap_irq max77843_irqs[] = { + /* TOPSYS interrupts */ + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSUVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSOVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TSHDN_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77843_irq_chip = { + .name = "max77843", + .status_base= MAX77843_SYS_REG_SYSINTSRC, + .mask_base = MAX77843_SYS_REG_SYSINTMASK, + .mask_invert= false, + .num_regs = 1, + .irqs = max77843_irqs, + .num_irqs = ARRAY_SIZE(max77843_irqs), +}; + +/* Charger and Charger regulator use same regmap. */ +static int max77843_chg_init(struct max77843 *max77843) +{ + int ret; + + max77843->i2c_chg = i2c_new_dummy(max77843->i2c->adapter, I2C_ADDR_CHG); + if (!max77843->i2c_chg) { + dev_err(&max77843->i2c->dev, +
Re: [PATCH v3 1/6] mfd: max77843: Add max77843 MFD driver core driver
Hi Lee Jones, On 02/16/2015 10:51 PM, Lee Jones wrote: On Wed, 04 Feb 2015, Jaewon Kim wrote: This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 245 +++ include/linux/mfd/max77843-private.h | 441 ++ 4 files changed, 701 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 2e6b731..0c67c79 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -442,6 +442,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77843 + bool "Maxim Semiconductor MAX77843 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim Semiconductor MAX77843. + This is companion Power Management IC with LEDs, Haptic, Charger, + Fuel Gauge, MUIC(Micro USB Interface Controller) controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX8907 tristate "Maxim Semiconductor MAX8907 PMIC Support" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 53467e2..fe4f75c 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -117,6 +117,7 @@ obj-$(CONFIG_MFD_DA9063)+= da9063.o obj-$(CONFIG_MFD_MAX14577)+= max14577.o obj-$(CONFIG_MFD_MAX77686)+= max77686.o obj-$(CONFIG_MFD_MAX77693)+= max77693.o +obj-$(CONFIG_MFD_MAX77843) += max77843.o This is the 11th MAX driver. Can't they be supported using device specific data structures instead of taking a 'one file per device' approach? Kzysztof answered already, we try to merge with other files. But MAX77843 can`t merge with another MAX drivers. Because This driver has new features (e.g AFC charger, Reverse Boost, 4 channel LED driver, etc) so new registers extended and moved. obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c new file mode 100644 index 000..191a557 --- /dev/null +++ b/drivers/mfd/max77843.c @@ -0,0 +1,245 @@ +/* + * max77843.c - MFD core driver for the Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include [...] +static int max77843_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) Strange tabbing here. I will fix it in next version. +{ + struct max77843 *max77843; + unsigned int reg_data; + int ret; + + max77843 = devm_kzalloc(&i2c->dev, sizeof(*max77843), GFP_KERNEL); + if (!max77843) + return -ENOMEM; + + i2c_set_clientdata(i2c, max77843); + max77843->dev = &i2c->dev; + max77843->i2c = i2c; + max77843->irq = i2c->irq; + + max77843->regmap = devm_regmap_init_i2c(i2c, + &max77843_regmap_config); + if (IS_ERR(max77843->regmap)) { + dev_err(&i2c->dev, "Failed to allocate topsys register map\n"); + return PTR_ERR(max77843->regmap); + } + + ret = regmap_add_irq_chip(max77843->regmap, max77843->irq, + IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED, + 0, &max77843_irq_chip, &max77843->irq_data); + if (ret) { + dev_err(&i2c->dev, "Failed to add TOPSYS IRQ chip\n"); + return ret; + } + + ret = regmap_read(max77843->regmap, + MAX77843_SYS_REG_PMICID, ®_data); + if (ret < 0) { + dev_err(&i2c->dev, "Failed to read PMIC ID\n"); + goto err_pmic_id; + } + dev_info(&i2c->dev, "device ID: 0x%x\n", reg_data); + + ret = max77843_chg_init(max77843); +
[PATCH v4] regulator: max77843: Add max77843 regulator driver
This patch adds new regulator driver to support max77843 MFD(Multi Function Device) chip`s regulators. The Max77843 has two voltage regulators for USB safeout. Cc: Mark Brown Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/regulator/Kconfig|8 ++ drivers/regulator/Makefile |1 + drivers/regulator/max77843.c | 227 ++ 3 files changed, 236 insertions(+) create mode 100644 drivers/regulator/max77843.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index c3a60b5..c1f9c33 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -414,6 +414,14 @@ config REGULATOR_MAX77802 Exynos5420/Exynos5800 SoCs to control various voltages. It includes support for control of voltage and ramp speed. +config REGULATOR_MAX77843 + tristate "Maxim 77843 regulator" + depends on MFD_MAX77843 + help + This driver controls a Maxim 77843 regulator. + The regulator include two 'SAFEOUT' for USB(Universal Serial Bus) + This is suitable for Exynos5433 SoC chips. + config REGULATOR_MC13XXX_CORE tristate diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 1f28ebf..12408d6 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o +obj-$(CONFIG_REGULATOR_MAX77843) += max77843.o obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o diff --git a/drivers/regulator/max77843.c b/drivers/regulator/max77843.c new file mode 100644 index 000..c132ef5 --- /dev/null +++ b/drivers/regulator/max77843.c @@ -0,0 +1,227 @@ +/* + * max77843.c - Regulator driver for the Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include + +enum max77843_regulator_type { + MAX77843_SAFEOUT1 = 0, + MAX77843_SAFEOUT2, + MAX77843_CHARGER, + + MAX77843_NUM, +}; + +static const unsigned int max77843_safeout_voltage_table[] = { + 485, + 490, + 495, + 330, +}; + +static int max77843_reg_is_enabled(struct regulator_dev *rdev) +{ + struct regmap *regmap = rdev->regmap; + int ret; + unsigned int reg; + + ret = regmap_read(regmap, rdev->desc->enable_reg, ®); + if (ret) { + dev_err(&rdev->dev, "Fialed to read charger register\n"); + return ret; + } + + return (reg & rdev->desc->enable_mask) == rdev->desc->enable_mask; +} + +static int max77843_reg_get_current_limit(struct regulator_dev *rdev) +{ + struct regmap *regmap = rdev->regmap; + unsigned int chg_min_uA = rdev->constraints->min_uA; + unsigned int chg_max_uA = rdev->constraints->max_uA; + unsigned int val; + int ret; + unsigned int reg, sel; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®); + if (ret) { + dev_err(&rdev->dev, "Failed to read charger register\n"); + return ret; + } + + sel = reg & MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (sel < 0x03) + sel = 0; + else + sel -= 2; + + val = chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel; + if (val > chg_max_uA) + return -EINVAL; + + return val; +} + +static int max77843_reg_set_current_limit(struct regulator_dev *rdev, + int min_uA, int max_uA) +{ + struct regmap *regmap = rdev->regmap; + unsigned int chg_min_uA = rdev->constraints->min_uA; + int sel = 0; + + while (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel < min_uA) + sel++; + + if (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel > max_uA) + return -EINVAL; + + sel += 2; + + return regmap_write(regmap, MAX77843_CHG_REG_CHG_CNFG_02, sel); +} + +static struct regulator_ops max77843_charger_ops = { + .is_enabled = max77843_reg_is_enabled, + .enable = regulator_enable_regmap, + .disable= regulator_disable_regmap, + .get_current_limit = max77843_reg_get_current_limit, + .set_current_limit
Re: [PATCH v3 5/6] regulator: max77843: Add max77843 regulator driver
Hi Mark, 2015년 02월 05일 05:26에 Mark Brown 이(가) 쓴 글: On Wed, Feb 04, 2015 at 01:56:10PM +0900, Jaewon Kim wrote: This patch adds new regulator driver to support max77843 MFD(Multi Function Device) chip`s regulators. The Max77843 has two voltage regulators for USB safeout. Applied, thanks. I made a mistake in this patch. volt_table value was not fixed correctly. I will send fixed driver soon. plz change it. Thanks, Jaewon Kim -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 4/6] power: max77843_battery: Add Max77843 fuel gauge device driver
From: Beomho Seo This patch adds device driver of max77843 fuel gauge. The driver support for battery fuel gauge in Maxim Max77843. It is fuel-gauge systems for lithuum-ion batteries in handled and portable devices. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|9 ++ drivers/power/Makefile |1 + drivers/power/max77843_battery.c | 286 ++ 3 files changed, 296 insertions(+) create mode 100644 drivers/power/max77843_battery.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index a054a28..cea0ea2 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -212,6 +212,15 @@ config BATTERY_MAX17042 with MAX17042. This driver also supports max17047/50 chips which are improved version of max17042. +config BATTERY_MAX77843 + tristate "Maxim MAX77843 Fuel Gauge" + depends on MFD_MAX77843 + help + This adds support for battery fuel gauge in Maxim MAX77843. It is + fuel-gauge for a lithium-ion batteries with a single cell and can be + found in portable devices. The MAX17040 is configured to operate with + a single lithium cell. + config BATTERY_Z2 tristate "Z2 battery driver" depends on I2C && MACH_ZIPIT2 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 212c6a2..ae0d795 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o obj-$(CONFIG_BATTERY_DA9052) += da9052-battery.o obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o +obj-$(CONFIG_BATTERY_MAX77843) += max77843_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o diff --git a/drivers/power/max77843_battery.c b/drivers/power/max77843_battery.c new file mode 100644 index 000..0c59a16 --- /dev/null +++ b/drivers/power/max77843_battery.c @@ -0,0 +1,286 @@ +/* + * Fuel gauge driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_battery { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; +}; + +static int max77843_battery_get_capacity(struct max77843_battery *battery) +{ + struct regmap *regmap = battery->regmap; + int ret, val; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_FG_REG_SOCREP, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data >> 8; + + return val; +} + +static int max77843_battery_get_energy_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_ENERGY_FULL: + reg = MAX77843_FG_REG_FULLCAP; + break; + case POWER_SUPPLY_PROP_ENERGY_NOW: + reg = MAX77843_FG_REG_REMCAP_REP; + break; + case POWER_SUPPLY_PROP_ENERGY_AVG: + reg = MAX77843_FG_REG_REMCAP_AV; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + + return val; +} + +static int max77843_battery_get_current_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_CURRENT_NOW: + reg = MAX77843_FG_REG_CURRENT; + break; + case POWER_SUPPLY_PROP_CURRENT_AVG: + reg = MAX77843_FG_REG_AVG_CURRENT; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + if (val & 0x8000) { + /* Negative */ + val = ~val & 0x; + val++; +
[PATCH v3 3/6] power: max77843_charger: Add Max77843 charger device driver
From: Beomho Seo This patch adds device driver of max77843 charger. This driver provide initialize each charging mode(e.g. fast charge, top-off mode and constant charging mode so on.). Additionally, control charging paramters to use i2c interface. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|7 + drivers/power/Makefile |1 + drivers/power/max77843_charger.c | 508 ++ 3 files changed, 516 insertions(+) create mode 100644 drivers/power/max77843_charger.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 0108c2a..a054a28 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -332,6 +332,13 @@ config CHARGER_MAX14577 Say Y to enable support for the battery charger control sysfs and platform data of MAX14577/77836 MUICs. +config CHARGER_MAX77843 + tristate "Maxim MAX77843 battery charger driver" + depends on MFD_MAX77843 + help + Say Y to enable support for the battery charger control sysfs and + platform data of MAX77843 + config CHARGER_MAX8997 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" depends on MFD_MAX8997 && REGULATOR_MAX8997 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index dfa8942..212c6a2 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_CHARGER_LP8788) += lp8788-charger.o obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o +obj-$(CONFIG_CHARGER_MAX77843) += max77843_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o diff --git a/drivers/power/max77843_charger.c b/drivers/power/max77843_charger.c new file mode 100644 index 000..392eebc1a --- /dev/null +++ b/drivers/power/max77843_charger.c @@ -0,0 +1,508 @@ +/* + * Charger driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_charger_info { + u32 fast_charge_uamp; + u32 top_off_uamp; + u32 input_uamp_limit; +}; + +struct max77843_charger { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; + + struct max77843_charger_info*info; +}; + +static int max77843_charger_get_max_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_09, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read max current register: %d\n", ret); + return ret; + } + + if (reg_data <= 0x03) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MIN; + } else if (reg_data >= 0x78) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MAX; + } else { + val = reg_data / 3; + if (reg_data % 3 == 0) + val *= 10; + else if (reg_data % 3 == 1) + val = val * 10 + 33000; + else + val = val * 10 + 67000; + } + + return val; +} + +static int max77843_charger_get_now_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charge current register: %d\n", ret); + return ret; + } + + reg_data &= MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (reg_data <= 0x02) + val = MAX77843_CHG_FAST_CHG_CURRENT_MIN; + else if (reg_data >= 0x3f) + val = MAX77843_CHG_FAST_CHG_CURRENT_MAX; + else + val = reg_data * MAX77843_CHG_FAST_CHG_CURRENT_STEP; + + return val; +} + +static int max77843_charger_get_online(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_INT_OK, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charger status: %d\n", ret); + return ret; +
[PATCH v3 6/6] Documentation: Add device tree bindings document for max77843
Add document describing device tree bindings for max77843 MFD. Drivers: MFD core, regulator, extcon, charger and fuelgauge. Cc: Rob Herring Cc: Pawel Moll Cc: Mark Rutland Cc: Ian Campbell Cc: Kumar Gala Cc: Lee Jones Cc: Chanwoo Choi Cc: Sebastian Reichel Cc: Mark Brown Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- Documentation/devicetree/bindings/mfd/max77843.txt | 90 1 file changed, 90 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt diff --git a/Documentation/devicetree/bindings/mfd/max77843.txt b/Documentation/devicetree/bindings/mfd/max77843.txt new file mode 100644 index 000..4341ab9 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/max77843.txt @@ -0,0 +1,90 @@ +Maxim MAX77843 multi-function device + +MAX77843 is a Multi-Function Device with the following submodules: +- PMIC : 2 SAFEOUT LDOs for USB device +- CHARGER : Li+ battery charger with Fuel Gauge +- MUIC : Micro USB Interface Controller + +It is interfaced to host controller using I2C. + +Required properties: +- compatible : Must be "maxim,max77843". +- reg : I2C slave address of PMIC block. +- interrupts : I2C line for main SoCs. +- interrupt-parent : The parent of interrupt controller. + +Optional properties: +- regulators : The regulators of max77843 have to be instantiated under subnode + named "regulators" using the following format. + + [*]refer : Documentation/devicetree/bindings/regulator/regulator.txt + + regulators { + SAFEOUT { + regulator-name = "SAFEOUT"; + }; + } + + List of valid regulator names: + - SAFEOUT1, SAFEOUT2, CHARGER. + +- max77843-muic : This properties used by extcon consumers. + Required properties: + - compatible : Must be "maxim,max77842-muic". + +- max77843-charger : There battery charger of MAX77843 have to be instantiated + under sub-node named "max77843-charger" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-charger". + - maxim,fast-charge-uamp : Fast charge current levels are + 100 mA to 3150 mA programmed by I2C per 100 mA. + - maxim,top-off-uamp : Top off current threshold levels are + 125 mA to 650 mA programmed by I2C per 75 mA. + - maxim,input-uamp-limit : Input current limit levels are + 100 mA to 3533 mA programmed by I2C per 33 mA. +- max77843-fuelgauge : There fuelgauge of MAX77843 have to be instantiated + under sub-node named "max77843-fuelgauge" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-fuelgauge". + +Example: + max77843@66 { + compatible = "samsung,max77843"; + reg = <0x66>; + interrupt-parent = <&gpa1>; + interrupts = <5 2>; + + regulators { + SAFEOUT1 { + regulator-name = "SAFEOUT1"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + SAFEOUT2 { + regulator-name = "SAFEOUT2"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + CHARGER { + regulator-name = "CHARGER"; + regulator-min-microamp = <10>; + regulator-max-microamp = <315>; + }; + }; + + max77843-muic { + compatible = "maxim,max77843-muic"; + }; + + max77843-charger { + compatible = "maxim,max77843-charger"; + maxim,fast-charge-uamp = <45>; + maxim,top-off-uamp = <125000>; + maxim,input-uamp-limit = <50>; + }; + + max77843-fuelgauge { + compatible = "maxim,max77843-fuelgauge"; + }; + + }; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 5/6] regulator: max77843: Add max77843 regulator driver
This patch adds new regulator driver to support max77843 MFD(Multi Function Device) chip`s regulators. The Max77843 has two voltage regulators for USB safeout. Cc: Mark Brown Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/regulator/Kconfig|8 ++ drivers/regulator/Makefile |1 + drivers/regulator/max77843.c | 227 ++ 3 files changed, 236 insertions(+) create mode 100644 drivers/regulator/max77843.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index c3a60b5..c1f9c33 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -414,6 +414,14 @@ config REGULATOR_MAX77802 Exynos5420/Exynos5800 SoCs to control various voltages. It includes support for control of voltage and ramp speed. +config REGULATOR_MAX77843 + tristate "Maxim 77843 regulator" + depends on MFD_MAX77843 + help + This driver controls a Maxim 77843 regulator. + The regulator include two 'SAFEOUT' for USB(Universal Serial Bus) + This is suitable for Exynos5433 SoC chips. + config REGULATOR_MC13XXX_CORE tristate diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 1f28ebf..12408d6 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o +obj-$(CONFIG_REGULATOR_MAX77843) += max77843.o obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o diff --git a/drivers/regulator/max77843.c b/drivers/regulator/max77843.c new file mode 100644 index 000..779449f --- /dev/null +++ b/drivers/regulator/max77843.c @@ -0,0 +1,227 @@ +/* + * max77843.c - Regulator driver for the Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include + +enum max77843_regulator_type { + MAX77843_SAFEOUT1 = 0, + MAX77843_SAFEOUT2, + MAX77843_CHARGER, + + MAX77843_NUM, +}; + +static const unsigned int max77843_safeout_voltage_table[] = { + 485, + 490, + 495, + 330, +}; + +static int max77843_reg_is_enabled(struct regulator_dev *rdev) +{ + struct regmap *regmap = rdev->regmap; + int ret; + unsigned int reg; + + ret = regmap_read(regmap, rdev->desc->enable_reg, ®); + if (ret) { + dev_err(&rdev->dev, "Fialed to read charger register\n"); + return ret; + } + + return (reg & rdev->desc->enable_mask) == rdev->desc->enable_mask; +} + +static int max77843_reg_get_current_limit(struct regulator_dev *rdev) +{ + struct regmap *regmap = rdev->regmap; + unsigned int chg_min_uA = rdev->constraints->min_uA; + unsigned int chg_max_uA = rdev->constraints->max_uA; + unsigned int val; + int ret; + unsigned int reg, sel; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®); + if (ret) { + dev_err(&rdev->dev, "Failed to read charger register\n"); + return ret; + } + + sel = reg & MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (sel < 0x03) + sel = 0; + else + sel -= 2; + + val = chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel; + if (val > chg_max_uA) + return -EINVAL; + + return val; +} + +static int max77843_reg_set_current_limit(struct regulator_dev *rdev, + int min_uA, int max_uA) +{ + struct regmap *regmap = rdev->regmap; + unsigned int chg_min_uA = rdev->constraints->min_uA; + int sel = 0; + + while (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel < min_uA) + sel++; + + if (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel > max_uA) + return -EINVAL; + + sel += 2; + + return regmap_write(regmap, MAX77843_CHG_REG_CHG_CNFG_02, sel); +} + +static struct regulator_ops max77843_charger_ops = { + .is_enabled = max77843_reg_is_enabled, + .enable = regulator_enable_regmap, + .disable= regulator_disable_regmap, + .get_current_limit = max77843_reg_get_current_limit, + .set_current_limit
[PATCH v3 2/6] extcon: max77843: Add max77843 MUIC driver
This patch adds MAX77843 extcon driver to support for MUIC(Micro USB Interface Controller) device by using EXTCON subsystem to handle various external connectors. Cc: Chanwoo Choi Signed-off-by: Jaewon Kim Acked-by : Chanwoo Choi --- drivers/extcon/Kconfig | 10 + drivers/extcon/Makefile |1 + drivers/extcon/extcon-max77843.c | 881 ++ 3 files changed, 892 insertions(+) create mode 100644 drivers/extcon/extcon-max77843.c diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index 6a1f7de..0b67538 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -55,6 +55,16 @@ config EXTCON_MAX77693 Maxim MAX77693 PMIC. The MAX77693 MUIC is a USB port accessory detector and switch. +config EXTCON_MAX77843 + tristate "MAX77843 EXTCON Support" + depends on MFD_MAX77843 + select IRQ_DOMAIN + select REGMAP_I2C + help + If you say yes here you get support for the MUIC device of + Maxim MAX77843. The MAX77843 MUIC is a USB port accessory + detector add switch. + config EXTCON_MAX8997 tristate "MAX8997 EXTCON Support" depends on MFD_MAX8997 && IRQ_DOMAIN diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile index 0370b42..f21d5c4 100644 --- a/drivers/extcon/Makefile +++ b/drivers/extcon/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_EXTCON_ARIZONA)+= extcon-arizona.o obj-$(CONFIG_EXTCON_GPIO) += extcon-gpio.o obj-$(CONFIG_EXTCON_MAX14577) += extcon-max14577.o obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o +obj-$(CONFIG_EXTCON_MAX77843) += extcon-max77843.o obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o obj-$(CONFIG_EXTCON_PALMAS)+= extcon-palmas.o obj-$(CONFIG_EXTCON_RT8973A) += extcon-rt8973a.o diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c new file mode 100644 index 000..598a017 --- /dev/null +++ b/drivers/extcon/extcon-max77843.c @@ -0,0 +1,881 @@ +/* + * extcon-max77843.c - Maxim MAX77843 extcon driver to support + * MUIC(Micro USB Interface Controller) + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DELAY_MS_DEFAULT 15000 /* unit: millisecond */ + +enum max77843_muic_status { + MAX77843_MUIC_STATUS1 = 0, + MAX77843_MUIC_STATUS2, + MAX77843_MUIC_STATUS3, + + MAX77843_MUIC_STATUS_NUM, +}; + +struct max77843_muic_info { + struct device *dev; + struct max77843 *max77843; + struct extcon_dev *edev; + + struct mutex mutex; + struct work_struct irq_work; + struct delayed_work wq_detcable; + + u8 status[MAX77843_MUIC_STATUS_NUM]; + int prev_cable_type; + int prev_chg_type; + int prev_gnd_type; + + bool irq_adc; + bool irq_chg; +}; + +enum max77843_muic_cable_group { + MAX77843_CABLE_GROUP_ADC = 0, + MAX77843_CABLE_GROUP_ADC_GND, + MAX77843_CABLE_GROUP_CHG, +}; + +enum max77843_muic_adc_debounce_time { + MAX77843_DEBOUNCE_TIME_5MS = 0, + MAX77843_DEBOUNCE_TIME_10MS, + MAX77843_DEBOUNCE_TIME_25MS, + MAX77843_DEBOUNCE_TIME_38_62MS, +}; + +/* Define accessory cable type */ +enum max77843_muic_accessory_type { + MAX77843_MUIC_ADC_GROUND = 0, + MAX77843_MUIC_ADC_SEND_END_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S1_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S2_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S3_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S4_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S5_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S6_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S7_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S8_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S9_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S10_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S11_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S12_BUTTON, + MAX77843_MUIC_ADC_RESERVED_ACC_1, + MAX77843_MUIC_ADC_RESERVED_ACC_2, + MAX77843_MUIC_ADC_RESERVED_ACC_3, + MAX77843_MUIC_ADC_RESERVED_ACC_4, + MAX77843_MUIC_ADC_RESERVED_ACC_5, + MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2, + MAX77843_MUIC_ADC_PHONE_POWERED_DEV, + MAX77843_MUIC_ADC_TTY_CONVERTER, + MAX77843_MUIC_ADC_UART_CABLE, + MAX77843_MUIC_ADC_CEA936A_TYPE1_CHG, + MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF, + MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON, + MAX77843_MUIC_ADC_AV_CABLE_NOLOAD, + MAX77843_MUIC_ADC_CEA936A_TYPE2_CHG, + MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF, + MAX77843_M
[PATCH v3 1/6] mfd: max77843: Add max77843 MFD driver core driver
This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 245 +++ include/linux/mfd/max77843-private.h | 441 ++ 4 files changed, 701 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 2e6b731..0c67c79 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -442,6 +442,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77843 + bool "Maxim Semiconductor MAX77843 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim Semiconductor MAX77843. + This is companion Power Management IC with LEDs, Haptic, Charger, + Fuel Gauge, MUIC(Micro USB Interface Controller) controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX8907 tristate "Maxim Semiconductor MAX8907 PMIC Support" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 53467e2..fe4f75c 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -117,6 +117,7 @@ obj-$(CONFIG_MFD_DA9063)+= da9063.o obj-$(CONFIG_MFD_MAX14577) += max14577.o obj-$(CONFIG_MFD_MAX77686) += max77686.o obj-$(CONFIG_MFD_MAX77693) += max77693.o +obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c new file mode 100644 index 000..191a557 --- /dev/null +++ b/drivers/mfd/max77843.c @@ -0,0 +1,245 @@ +/* + * max77843.c - MFD core driver for the Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell max77843_devs[] = { + { + .name = "max77843-muic", + .of_compatible = "maxim,max77843-muic", + }, { + .name = "max77843-regulator", + .of_compatible = "maxim,max77843-regulator", + }, { + .name = "max77843-charger", + .of_compatible = "maxim,max77843-charger" + }, { + .name = "max77843-fuelgauge", + .of_compatible = "maxim,max77843-fuelgauge", + }, +}; + +static const struct regmap_config max77843_charger_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_CHG_REG_END, +}; + +static const struct regmap_config max77843_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_SYS_REG_END, +}; + +static const struct regmap_irq max77843_irqs[] = { + /* TOPSYS interrupts */ + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSUVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSOVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TSHDN_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77843_irq_chip = { + .name = "max77843", + .status_base= MAX77843_SYS_REG_SYSINTSRC, + .mask_base = MAX77843_SYS_REG_SYSINTMASK, + .mask_invert= false, + .num_regs = 1, + .irqs = max77843_irqs, + .num_irqs = ARRAY_SIZE(max77843_irqs), +}; + +/* Charger and Charger regulator use same regmap. */ +static int max77843_chg_init(struct max77843 *max77843) +{ + int ret; + + max77843->i2c_chg = i2c_new_dummy(max77843->i2c->adapter, I2C_ADDR_CHG); + if (!max77843->i2c_chg) { + dev_err(&max77843->i2c->dev, + "Cannot allocate I2C device for Charger\n"); + return PTR_ERR(max77843->i2c
[PATCH v3 0/6] Add new MFD driver for MAX77843
This patch series adds MAX77843(Multi Function Device) driver. The MAX77843 includes MUIC(Micro USB Interface Controller), Li+ Charger with Fuel Gauge and 2 safeout LDOs for USB device. It is interfaced to host controller using I2C. Changes in v3: MFD Core - fix wrong description and indentation in header. - remove unnecessary variable. Regulator - use ARRAY_SIZE() instead of define. Changes in V2: MFD Core - Fix charger regmap handle and typo. MUIC - cleanup enum list. - set path before send excon event. - fix variable names and typos for readability. Charger - Remove unnecessary header. - Chnage error message more readable. - Remove unnecessary lines. Fuelgauge - Fix regmap_config and use regmap_read. - Add i2c_unregister_device function on *_remove function. - Fix typo in Kconfig. Doc - Remove unnecessary lines. - Add example of charger regulator. Beomho Seo (2): power: max77843_charger: Add Max77843 charger device driver power: max77843_battery: Add Max77843 fuel gauge device driver Jaewon Kim (4): mfd: max77843: Add max77843 MFD driver core driver extcon: max77843: Add max77843 MUIC driver regulator: max77843: Add max77843 regulator driver Documentation: Add device tree bindings document for max77843 Documentation/devicetree/bindings/mfd/max77843.txt | 90 ++ drivers/extcon/Kconfig | 10 + drivers/extcon/Makefile|1 + drivers/extcon/extcon-max77843.c | 881 drivers/mfd/Kconfig| 14 + drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 245 ++ drivers/power/Kconfig | 16 + drivers/power/Makefile |2 + drivers/power/max77843_battery.c | 286 +++ drivers/power/max77843_charger.c | 508 +++ drivers/regulator/Kconfig |8 + drivers/regulator/Makefile |1 + drivers/regulator/max77843.c | 227 + include/linux/mfd/max77843-private.h | 441 ++ 15 files changed, 2731 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt create mode 100644 drivers/extcon/extcon-max77843.c create mode 100644 drivers/mfd/max77843.c create mode 100644 drivers/power/max77843_battery.c create mode 100644 drivers/power/max77843_charger.c create mode 100644 drivers/regulator/max77843.c create mode 100644 include/linux/mfd/max77843-private.h -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 1/6] mfd: max77843: Add max77843 MFD driver core driver
Hi Chanwoo, 2015년 02월 04일 08:57에 Chanwoo Choi 이(가) 쓴 글: Hi Jaewon and Beomho, On 02/03/2015 02:04 PM, Jaewon Kim wrote: This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 247 include/linux/mfd/max77843-private.h | 422 ++ 4 files changed, 684 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 2e6b731..0c67c79 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -442,6 +442,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. [snip] + + ret = regmap_read(max77843->regmap, + MAX77843_SYS_REG_PMICID, ®_data); + if (ret < 0) { + dev_err(&i2c->dev, "Failed to read PMIC ID\n"); + goto err_pmic_id; + } + dev_info(&i2c->dev, "device ID: 0x%x\n", reg_data); + + ret = max77843_chg_init(max77843); + if (ret) { + dev_err(&i2c->dev, "Failed to init Charger\n"); + goto err_pmic_id; + } + + reg = MAX77843_INTSRC_MASK_MASK; + ret = regmap_update_bits(max77843->regmap, + MAX77843_SYS_REG_INTSRCMASK, + MAX77843_INTSRC_MASK_MASK, + (unsigned int)~reg); I think that you don't need to allocate MAX77843_INTSRC_MASK_MASK to 'reg' variable. You can use MAX77843_INTSRC_MASK_MASK directly without any variable. Okay, I will use MAX77843_INTSRC_MASK_MASK directly in next version. + if (ret < 0) { + dev_err(&i2c->dev, "Failed to unmask interrupt source\n"); + goto err_pmic_id; + } + + ret = mfd_add_devices(max77843->dev, -1, max77843_devs, + ARRAY_SIZE(max77843_devs), NULL, 0, NULL); + if (ret < 0) { + dev_err(&i2c->dev, "Failed to add mfd device\n"); + goto err_pmic_id; + } + + device_init_wakeup(max77843->dev, 1); + + return 0; + +err_pmic_id: + regmap_del_irq_chip(max77843->irq, max77843->irq_data); + + return ret; +} [snip] +MODULE_AUTHOR("Jaewon Kim "); +MODULE_AUTHOR("Beomho Seo "); +MODULE_DESCRIPTION("Maxim MAX77843 multi-function core driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mfd/max77843-private.h b/include/linux/mfd/max77843-private.h new file mode 100644 index 000..0f4cfa4 --- /dev/null +++ b/include/linux/mfd/max77843-private.h @@ -0,0 +1,422 @@ +/* + * max77843-private.h - Common API for the Maxim MAX77843 internal sub chip API? I will change it. + * + * Copyright (C) 2014 Samsung Electrnoics s/2014/2015 ditto. + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef __MAX77843_PRIVATE_H_ +#define __MAX77843_PRIVATE_H_ + +#include +#include + +#define I2C_ADDR_TOPSYS(0xCC >> 1) +#define I2C_ADDR_CHG (0xD2 >> 1) +#define I2C_ADDR_FG(0x6C >> 1) +#define I2C_ADDR_MUIC (0x4A >> 1) + +/* Topsys, Haptic and LED registers */ +enum max77843_sys_reg { + MAX77843_SYS_REG_PMICID = 0x00, + MAX77843_SYS_REG_PMICREV= 0x01, + MAX77843_SYS_REG_MAINCTRL1 = 0x02, + MAX77843_SYS_REG_INTSRC = 0x22, + MAX77843_SYS_REG_INTSRCMASK = 0x23, + MAX77843_SYS_REG_SYSINTSRC = 0x24, + MAX77843_SYS_REG_SYSINTMASK = 0x26, + MAX77843_SYS_REG_TOPSYS_STAT= 0x28, + MAX77843_SYS_REG_SAFEOUTCTRL= 0xC6, + + MAX77843_SYS_REG_END, +}; + +enum max77843_haptic_reg { + MAX77843_HAP_REG_MCONFIG= 0x10, + + MAX77843_HAP_REG_END, +}; + +enum max77843_led_reg { + MAX77843_LED_REG_LEDEN = 0x30, + MAX77843_LED_REG_LED0BRT= 0x31, + MAX77843_LED_REG_LED1BRT= 0x32, + MAX77843_LED_REG_LED2BRT= 0x33, + MAX77843_LED_REG_LED3BRT= 0x34, + MAX77843_LED_REG_LEDBLNK= 0x38, + MAX77843_LED_REG_LEDRAMP= 0x36, + + MAX77843_LED_REG_END, +}; + +/* Charger registers */ +enum max77843_charger_reg { + MAX77843_CHG_REG_CHG_INT= 0xB0,
Re: [PATCH v2 5/6] regulator: max77843: Add max77843 regulator driver
Hi Mark, 2015년 02월 04일 01:25에 Mark Brown 이(가) 쓴 글: On Tue, Feb 03, 2015 at 02:04:05PM +0900, Jaewon Kim wrote: This patch adds new regulator driver to support max77843 MFD(Multi Function Device) chip`s regulators. The Max77843 has two voltage regulators for USB safeout. This looks mostly good, a couple of very small things: +static const struct regulator_desc max77843_supported_regulators[] = { + [MAX77843_SAFEOUT1] = { + .name = "SAFEOUT1", + .id = MAX77843_SAFEOUT1, + .ops= &max77843_regulator_ops, + .of_match = of_match_ptr("SAFEOUT1"), + .regulators_node = of_match_ptr("regulators"), + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .n_voltages = MAX77843_SUPPORTED_VOLTAGE_NUM, + .volt_table = max77843_regulator_table, It's better to make n_voltages be ARRAY_SIZE() for the table, that way there's no need to keep the define and array lined up if someone extends the driver. A name like _safeout_voltage_table might be clearer too. I will change n_voltages value to ARRAY_SIZE() instead of define. And fix volt_table enum variable name. Thanks to advise. Thanks Jaewon Kim -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 2/6] extcon: max77843: Add max77843 MUIC driver
This patch adds MAX77843 extcon driver to support for MUIC(Micro USB Interface Controller) device by using EXTCON subsystem to handle various external connectors. Cc: Chanwoo Choi Signed-off-by: Jaewon Kim --- drivers/extcon/Kconfig | 10 + drivers/extcon/Makefile |1 + drivers/extcon/extcon-max77843.c | 881 ++ 3 files changed, 892 insertions(+) create mode 100644 drivers/extcon/extcon-max77843.c diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index 6a1f7de..0b67538 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -55,6 +55,16 @@ config EXTCON_MAX77693 Maxim MAX77693 PMIC. The MAX77693 MUIC is a USB port accessory detector and switch. +config EXTCON_MAX77843 + tristate "MAX77843 EXTCON Support" + depends on MFD_MAX77843 + select IRQ_DOMAIN + select REGMAP_I2C + help + If you say yes here you get support for the MUIC device of + Maxim MAX77843. The MAX77843 MUIC is a USB port accessory + detector add switch. + config EXTCON_MAX8997 tristate "MAX8997 EXTCON Support" depends on MFD_MAX8997 && IRQ_DOMAIN diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile index 0370b42..f21d5c4 100644 --- a/drivers/extcon/Makefile +++ b/drivers/extcon/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_EXTCON_ARIZONA)+= extcon-arizona.o obj-$(CONFIG_EXTCON_GPIO) += extcon-gpio.o obj-$(CONFIG_EXTCON_MAX14577) += extcon-max14577.o obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o +obj-$(CONFIG_EXTCON_MAX77843) += extcon-max77843.o obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o obj-$(CONFIG_EXTCON_PALMAS)+= extcon-palmas.o obj-$(CONFIG_EXTCON_RT8973A) += extcon-rt8973a.o diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c new file mode 100644 index 000..598a017 --- /dev/null +++ b/drivers/extcon/extcon-max77843.c @@ -0,0 +1,881 @@ +/* + * extcon-max77843.c - Maxim MAX77843 extcon driver to support + * MUIC(Micro USB Interface Controller) + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DELAY_MS_DEFAULT 15000 /* unit: millisecond */ + +enum max77843_muic_status { + MAX77843_MUIC_STATUS1 = 0, + MAX77843_MUIC_STATUS2, + MAX77843_MUIC_STATUS3, + + MAX77843_MUIC_STATUS_NUM, +}; + +struct max77843_muic_info { + struct device *dev; + struct max77843 *max77843; + struct extcon_dev *edev; + + struct mutex mutex; + struct work_struct irq_work; + struct delayed_work wq_detcable; + + u8 status[MAX77843_MUIC_STATUS_NUM]; + int prev_cable_type; + int prev_chg_type; + int prev_gnd_type; + + bool irq_adc; + bool irq_chg; +}; + +enum max77843_muic_cable_group { + MAX77843_CABLE_GROUP_ADC = 0, + MAX77843_CABLE_GROUP_ADC_GND, + MAX77843_CABLE_GROUP_CHG, +}; + +enum max77843_muic_adc_debounce_time { + MAX77843_DEBOUNCE_TIME_5MS = 0, + MAX77843_DEBOUNCE_TIME_10MS, + MAX77843_DEBOUNCE_TIME_25MS, + MAX77843_DEBOUNCE_TIME_38_62MS, +}; + +/* Define accessory cable type */ +enum max77843_muic_accessory_type { + MAX77843_MUIC_ADC_GROUND = 0, + MAX77843_MUIC_ADC_SEND_END_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S1_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S2_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S3_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S4_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S5_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S6_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S7_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S8_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S9_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S10_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S11_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S12_BUTTON, + MAX77843_MUIC_ADC_RESERVED_ACC_1, + MAX77843_MUIC_ADC_RESERVED_ACC_2, + MAX77843_MUIC_ADC_RESERVED_ACC_3, + MAX77843_MUIC_ADC_RESERVED_ACC_4, + MAX77843_MUIC_ADC_RESERVED_ACC_5, + MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2, + MAX77843_MUIC_ADC_PHONE_POWERED_DEV, + MAX77843_MUIC_ADC_TTY_CONVERTER, + MAX77843_MUIC_ADC_UART_CABLE, + MAX77843_MUIC_ADC_CEA936A_TYPE1_CHG, + MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF, + MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON, + MAX77843_MUIC_ADC_AV_CABLE_NOLOAD, + MAX77843_MUIC_ADC_CEA936A_TYPE2_CHG, + MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF, + MAX77843_MUIC_ADC_FACTORY_MODE_UART_ON, + MAX77843
[PATCH v2 6/6] Documentation: Add device tree bindings document for max77843
Add document describing device tree bindings for max77843 MFD. Drivers: MFD core, regulator, extcon, charger and fuelgauge. Cc: Rob Herring Cc: Pawel Moll Cc: Mark Rutland Cc: Ian Campbell Cc: Kumar Gala Cc: Lee Jones Cc: Chanwoo Choi Cc: Sebastian Reichel Cc: Mark Brown Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- Documentation/devicetree/bindings/mfd/max77843.txt | 90 1 file changed, 90 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt diff --git a/Documentation/devicetree/bindings/mfd/max77843.txt b/Documentation/devicetree/bindings/mfd/max77843.txt new file mode 100644 index 000..4341ab9 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/max77843.txt @@ -0,0 +1,90 @@ +Maxim MAX77843 multi-function device + +MAX77843 is a Multi-Function Device with the following submodules: +- PMIC : 2 SAFEOUT LDOs for USB device +- CHARGER : Li+ battery charger with Fuel Gauge +- MUIC : Micro USB Interface Controller + +It is interfaced to host controller using I2C. + +Required properties: +- compatible : Must be "maxim,max77843". +- reg : I2C slave address of PMIC block. +- interrupts : I2C line for main SoCs. +- interrupt-parent : The parent of interrupt controller. + +Optional properties: +- regulators : The regulators of max77843 have to be instantiated under subnode + named "regulators" using the following format. + + [*]refer : Documentation/devicetree/bindings/regulator/regulator.txt + + regulators { + SAFEOUT { + regulator-name = "SAFEOUT"; + }; + } + + List of valid regulator names: + - SAFEOUT1, SAFEOUT2, CHARGER. + +- max77843-muic : This properties used by extcon consumers. + Required properties: + - compatible : Must be "maxim,max77842-muic". + +- max77843-charger : There battery charger of MAX77843 have to be instantiated + under sub-node named "max77843-charger" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-charger". + - maxim,fast-charge-uamp : Fast charge current levels are + 100 mA to 3150 mA programmed by I2C per 100 mA. + - maxim,top-off-uamp : Top off current threshold levels are + 125 mA to 650 mA programmed by I2C per 75 mA. + - maxim,input-uamp-limit : Input current limit levels are + 100 mA to 3533 mA programmed by I2C per 33 mA. +- max77843-fuelgauge : There fuelgauge of MAX77843 have to be instantiated + under sub-node named "max77843-fuelgauge" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-fuelgauge". + +Example: + max77843@66 { + compatible = "samsung,max77843"; + reg = <0x66>; + interrupt-parent = <&gpa1>; + interrupts = <5 2>; + + regulators { + SAFEOUT1 { + regulator-name = "SAFEOUT1"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + SAFEOUT2 { + regulator-name = "SAFEOUT2"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + CHARGER { + regulator-name = "CHARGER"; + regulator-min-microamp = <10>; + regulator-max-microamp = <315>; + }; + }; + + max77843-muic { + compatible = "maxim,max77843-muic"; + }; + + max77843-charger { + compatible = "maxim,max77843-charger"; + maxim,fast-charge-uamp = <45>; + maxim,top-off-uamp = <125000>; + maxim,input-uamp-limit = <50>; + }; + + max77843-fuelgauge { + compatible = "maxim,max77843-fuelgauge"; + }; + + }; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 5/6] regulator: max77843: Add max77843 regulator driver
This patch adds new regulator driver to support max77843 MFD(Multi Function Device) chip`s regulators. The Max77843 has two voltage regulators for USB safeout. Cc: Mark Brown Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/regulator/Kconfig|8 ++ drivers/regulator/Makefile |1 + drivers/regulator/max77843.c | 229 ++ 3 files changed, 238 insertions(+) create mode 100644 drivers/regulator/max77843.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index c3a60b5..c1f9c33 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -414,6 +414,14 @@ config REGULATOR_MAX77802 Exynos5420/Exynos5800 SoCs to control various voltages. It includes support for control of voltage and ramp speed. +config REGULATOR_MAX77843 + tristate "Maxim 77843 regulator" + depends on MFD_MAX77843 + help + This driver controls a Maxim 77843 regulator. + The regulator include two 'SAFEOUT' for USB(Universal Serial Bus) + This is suitable for Exynos5433 SoC chips. + config REGULATOR_MC13XXX_CORE tristate diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 1f28ebf..12408d6 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o +obj-$(CONFIG_REGULATOR_MAX77843) += max77843.o obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o diff --git a/drivers/regulator/max77843.c b/drivers/regulator/max77843.c new file mode 100644 index 000..d7ae66b --- /dev/null +++ b/drivers/regulator/max77843.c @@ -0,0 +1,229 @@ +/* + * max77843.c - Regulator driver for the Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include + +#define MAX77843_SUPPORTED_VOLTAGE_NUM 4 + +enum max77843_regulator_type { + MAX77843_SAFEOUT1 = 0, + MAX77843_SAFEOUT2, + MAX77843_CHARGER, + + MAX77843_NUM, +}; + +static const unsigned int max77843_regulator_table[] = { + 485, + 490, + 495, + 330, +}; + +static int max77843_reg_is_enabled(struct regulator_dev *rdev) +{ + struct regmap *regmap = rdev->regmap; + int ret; + unsigned int reg; + + ret = regmap_read(regmap, rdev->desc->enable_reg, ®); + if (ret) { + dev_err(&rdev->dev, "Fialed to read charger register\n"); + return ret; + } + + return (reg & rdev->desc->enable_mask) == rdev->desc->enable_mask; +} + +static int max77843_reg_get_current_limit(struct regulator_dev *rdev) +{ + struct regmap *regmap = rdev->regmap; + unsigned int chg_min_uA = rdev->constraints->min_uA; + unsigned int chg_max_uA = rdev->constraints->max_uA; + unsigned int val; + int ret; + unsigned int reg, sel; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®); + if (ret) { + dev_err(&rdev->dev, "Failed to read charger register\n"); + return ret; + } + + sel = reg & MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (sel < 0x03) + sel = 0; + else + sel -= 2; + + val = chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel; + if (val > chg_max_uA) + return -EINVAL; + + return val; +} + +static int max77843_reg_set_current_limit(struct regulator_dev *rdev, + int min_uA, int max_uA) +{ + struct regmap *regmap = rdev->regmap; + unsigned int chg_min_uA = rdev->constraints->min_uA; + int sel = 0; + + while (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel < min_uA) + sel++; + + if (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel > max_uA) + return -EINVAL; + + sel += 2; + + return regmap_write(regmap, MAX77843_CHG_REG_CHG_CNFG_02, sel); +} + +static struct regulator_ops max77843_charger_ops = { + .is_enabled = max77843_reg_is_enabled, + .enable = regulator_enable_regmap, + .disable= regulator_disable_regmap, + .get_current_limit = max77843_reg_
[PATCH v2 4/6] power: max77843_battery: Add Max77843 fuel gauge device driver
From: Beomho Seo This patch adds device driver of max77843 fuel gauge. The driver support for battery fuel gauge in Maxim Max77843. It is fuel-gauge systems for lithuum-ion batteries in handled and portable devices. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|9 ++ drivers/power/Makefile |1 + drivers/power/max77843_battery.c | 286 ++ 3 files changed, 296 insertions(+) create mode 100644 drivers/power/max77843_battery.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index a054a28..cea0ea2 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -212,6 +212,15 @@ config BATTERY_MAX17042 with MAX17042. This driver also supports max17047/50 chips which are improved version of max17042. +config BATTERY_MAX77843 + tristate "Maxim MAX77843 Fuel Gauge" + depends on MFD_MAX77843 + help + This adds support for battery fuel gauge in Maxim MAX77843. It is + fuel-gauge for a lithium-ion batteries with a single cell and can be + found in portable devices. The MAX17040 is configured to operate with + a single lithium cell. + config BATTERY_Z2 tristate "Z2 battery driver" depends on I2C && MACH_ZIPIT2 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 212c6a2..ae0d795 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o obj-$(CONFIG_BATTERY_DA9052) += da9052-battery.o obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o +obj-$(CONFIG_BATTERY_MAX77843) += max77843_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o diff --git a/drivers/power/max77843_battery.c b/drivers/power/max77843_battery.c new file mode 100644 index 000..0c59a16 --- /dev/null +++ b/drivers/power/max77843_battery.c @@ -0,0 +1,286 @@ +/* + * Fuel gauge driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_battery { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; +}; + +static int max77843_battery_get_capacity(struct max77843_battery *battery) +{ + struct regmap *regmap = battery->regmap; + int ret, val; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_FG_REG_SOCREP, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data >> 8; + + return val; +} + +static int max77843_battery_get_energy_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_ENERGY_FULL: + reg = MAX77843_FG_REG_FULLCAP; + break; + case POWER_SUPPLY_PROP_ENERGY_NOW: + reg = MAX77843_FG_REG_REMCAP_REP; + break; + case POWER_SUPPLY_PROP_ENERGY_AVG: + reg = MAX77843_FG_REG_REMCAP_AV; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + + return val; +} + +static int max77843_battery_get_current_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + unsigned int reg_data; + + switch (psp) { + case POWER_SUPPLY_PROP_CURRENT_NOW: + reg = MAX77843_FG_REG_CURRENT; + break; + case POWER_SUPPLY_PROP_CURRENT_AVG: + reg = MAX77843_FG_REG_AVG_CURRENT; + break; + default: + return -EINVAL; + } + + ret = regmap_read(regmap, reg, ®_data); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = reg_data; + if (val & 0x8000) { + /* Negative */ + val = ~val & 0x; + val++; +
[PATCH v2 3/6] power: max77843_charger: Add Max77843 charger device driver
From: Beomho Seo This patch adds device driver of max77843 charger. This driver provide initialize each charging mode(e.g. fast charge, top-off mode and constant charging mode so on.). Additionally, control charging paramters to use i2c interface. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|7 + drivers/power/Makefile |1 + drivers/power/max77843_charger.c | 508 ++ 3 files changed, 516 insertions(+) create mode 100644 drivers/power/max77843_charger.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 0108c2a..a054a28 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -332,6 +332,13 @@ config CHARGER_MAX14577 Say Y to enable support for the battery charger control sysfs and platform data of MAX14577/77836 MUICs. +config CHARGER_MAX77843 + tristate "Maxim MAX77843 battery charger driver" + depends on MFD_MAX77843 + help + Say Y to enable support for the battery charger control sysfs and + platform data of MAX77843 + config CHARGER_MAX8997 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" depends on MFD_MAX8997 && REGULATOR_MAX8997 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index dfa8942..212c6a2 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_CHARGER_LP8788) += lp8788-charger.o obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o +obj-$(CONFIG_CHARGER_MAX77843) += max77843_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o diff --git a/drivers/power/max77843_charger.c b/drivers/power/max77843_charger.c new file mode 100644 index 000..392eebc1a --- /dev/null +++ b/drivers/power/max77843_charger.c @@ -0,0 +1,508 @@ +/* + * Charger driver for Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_charger_info { + u32 fast_charge_uamp; + u32 top_off_uamp; + u32 input_uamp_limit; +}; + +struct max77843_charger { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; + + struct max77843_charger_info*info; +}; + +static int max77843_charger_get_max_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_09, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read max current register: %d\n", ret); + return ret; + } + + if (reg_data <= 0x03) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MIN; + } else if (reg_data >= 0x78) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MAX; + } else { + val = reg_data / 3; + if (reg_data % 3 == 0) + val *= 10; + else if (reg_data % 3 == 1) + val = val * 10 + 33000; + else + val = val * 10 + 67000; + } + + return val; +} + +static int max77843_charger_get_now_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charge current register: %d\n", ret); + return ret; + } + + reg_data &= MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (reg_data <= 0x02) + val = MAX77843_CHG_FAST_CHG_CURRENT_MIN; + else if (reg_data >= 0x3f) + val = MAX77843_CHG_FAST_CHG_CURRENT_MAX; + else + val = reg_data * MAX77843_CHG_FAST_CHG_CURRENT_STEP; + + return val; +} + +static int max77843_charger_get_online(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_INT_OK, ®_data); + if (ret) { + dev_err(charger->dev, + "Failed to read charger status: %d\n", ret); + return ret; +
[PATCH v2 0/6] Add new MFD driver for MAX77843
This patch series adds MAX77843(Multi Function Device) driver. The MAX77843 includes MUIC(Micro USB Interface Circuit), Li+ Charger with Fuel Gauge and 2 safeout LDOs for USB device. It is interfaced to host controller using I2C. Changes in V2: MFD Core - Fix charger regmap handle and typo. MUIC - cleanup enum list. - set path before send excon event. - fix variable names and typos for readability. Charger - Remove unnecessary header. - Chnage error message more readable. - Remove unnecessary lines. Fuelgauge - Fix regmap_config and use regmap_read. - Add i2c_unregister_device function on *_remove function. - Fix typo in Kconfig. Doc - Remove unnecessary lines. - Add example of charger regulator. Beomho Seo (2): power: max77843_charger: Add Max77843 charger device driver power: max77843_battery: Add Max77843 fuel gauge device driver Jaewon Kim (4): mfd: max77843: Add max77843 MFD driver core driver extcon: max77843: Add max77843 MUIC driver regulator: max77843: Add max77843 regulator driver Documentation: Add device tree bindings document for max77843 Documentation/devicetree/bindings/mfd/max77843.txt | 90 ++ drivers/extcon/Kconfig | 10 + drivers/extcon/Makefile|1 + drivers/extcon/extcon-max77843.c | 881 drivers/mfd/Kconfig| 14 + drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 247 ++ drivers/power/Kconfig | 16 + drivers/power/Makefile |2 + drivers/power/max77843_battery.c | 286 +++ drivers/power/max77843_charger.c | 508 +++ drivers/regulator/Kconfig |8 + drivers/regulator/Makefile |1 + drivers/regulator/max77843.c | 229 + include/linux/mfd/max77843-private.h | 422 ++ 15 files changed, 2716 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt create mode 100644 drivers/extcon/extcon-max77843.c create mode 100644 drivers/mfd/max77843.c create mode 100644 drivers/power/max77843_battery.c create mode 100644 drivers/power/max77843_charger.c create mode 100644 drivers/regulator/max77843.c create mode 100644 include/linux/mfd/max77843-private.h -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 1/6] mfd: max77843: Add max77843 MFD driver core driver
This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Jaewon Kim Signed-off-by: Beomho Seo --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 247 include/linux/mfd/max77843-private.h | 422 ++ 4 files changed, 684 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 2e6b731..0c67c79 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -442,6 +442,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77843 + bool "Maxim Semiconductor MAX77843 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim Semiconductor MAX77843. + This is companion Power Management IC with LEDs, Haptic, Charger, + Fuel Gauge, MUIC(Micro USB Interface Controller) controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX8907 tristate "Maxim Semiconductor MAX8907 PMIC Support" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 53467e2..fe4f75c 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -117,6 +117,7 @@ obj-$(CONFIG_MFD_DA9063)+= da9063.o obj-$(CONFIG_MFD_MAX14577) += max14577.o obj-$(CONFIG_MFD_MAX77686) += max77686.o obj-$(CONFIG_MFD_MAX77693) += max77693.o +obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c new file mode 100644 index 000..b47fdbc --- /dev/null +++ b/drivers/mfd/max77843.c @@ -0,0 +1,247 @@ +/* + * max77843.c - MFD core driver for the Maxim MAX77843 + * + * Copyright (C) 2015 Samsung Electronics + * Author: Jaewon Kim + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell max77843_devs[] = { + { + .name = "max77843-muic", + .of_compatible = "maxim,max77843-muic", + }, { + .name = "max77843-regulator", + .of_compatible = "maxim,max77843-regulator", + }, { + .name = "max77843-charger", + .of_compatible = "maxim,max77843-charger" + }, { + .name = "max77843-fuelgauge", + .of_compatible = "maxim,max77843-fuelgauge", + }, +}; + +static const struct regmap_config max77843_charger_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_CHG_REG_END, +}; + +static const struct regmap_config max77843_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_SYS_REG_END, +}; + +static const struct regmap_irq max77843_irqs[] = { + /* TOPSYS interrupts */ + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSUVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSOVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TSHDN_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77843_irq_chip = { + .name = "max77843", + .status_base= MAX77843_SYS_REG_SYSINTSRC, + .mask_base = MAX77843_SYS_REG_SYSINTMASK, + .mask_invert= false, + .num_regs = 1, + .irqs = max77843_irqs, + .num_irqs = ARRAY_SIZE(max77843_irqs), +}; + +/* Charger and Charger regulator use same regmap. */ +static int max77843_chg_init(struct max77843 *max77843) +{ + int ret; + + max77843->i2c_chg = i2c_new_dummy(max77843->i2c->adapter, I2C_ADDR_CHG); + if (!max77843->i2c_chg) { + dev_err(&max77843->i2c->dev, + "Cannot allocate I2C device for Charger\n"); + return PTR_ERR(max77843->i2c
Re: [PATCH 2/6] extcon: max77843: Add max77843 MUIC driver
Hi Chanwoo, 2015년 01월 23일 15:21에 Chanwoo Choi 이(가) 쓴 글: Hi Jaewon, On 01/23/2015 02:02 PM, Jaewon Kim wrote: This patch adds MAX77843 extcon driver to support for MUIC(Micro Add company name (MAX77843 -> Maxim MAX77843) Okay. I will fix it. USB Interface Controller) device by using EXTCON subsystem to handle various external connectors. Cc: Chanwoo Choi Signed-off-by: Jaewon Kim --- drivers/extcon/Kconfig | 10 + drivers/extcon/Makefile |1 + drivers/extcon/extcon-max77843.c | 871 ++ 3 files changed, 882 insertions(+) create mode 100644 drivers/extcon/extcon-max77843.c diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index 6a1f7de..0b67538 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -55,6 +55,16 @@ config EXTCON_MAX77693 Maxim MAX77693 PMIC. The MAX77693 MUIC is a USB port accessory detector and switch. +config EXTCON_MAX77843 + tristate "MAX77843 EXTCON Support" + depends on MFD_MAX77843 + select IRQ_DOMAIN + select REGMAP_I2C + help + If you say yes here you get support for the MUIC device of + Maxim MAX77843. The MAX77843 MUIC is a USB port accessory + detector add switch. + config EXTCON_MAX8997 tristate "MAX8997 EXTCON Support" depends on MFD_MAX8997 && IRQ_DOMAIN diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile index 0370b42..f21d5c4 100644 --- a/drivers/extcon/Makefile +++ b/drivers/extcon/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_EXTCON_ARIZONA)+= extcon-arizona.o obj-$(CONFIG_EXTCON_GPIO) += extcon-gpio.o obj-$(CONFIG_EXTCON_MAX14577) += extcon-max14577.o obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o +obj-$(CONFIG_EXTCON_MAX77843) += extcon-max77843.o obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o obj-$(CONFIG_EXTCON_PALMAS) += extcon-palmas.o obj-$(CONFIG_EXTCON_RT8973A) += extcon-rt8973a.o diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c new file mode 100644 index 000..caae9a7 --- /dev/null +++ b/drivers/extcon/extcon-max77843.c @@ -0,0 +1,871 @@ +/* + * extcon-max77843.c - MAX77843 extcon driver to support MUIC + * + * Copyright (C) 2014 Samsung Electrnoics + * Author: Jaewon Kim Remove un-necessary blank before 'Author'. Okay. I will fix it. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DELAY_MS_DEFAULT 15000 /* unit: millisecond */ + +enum max77843_muic_acc_type { + MAX77843_MUIC_ADC_GROUND = 0, + MAX77843_MUIC_ADC_SEND_END_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S1_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S2_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S3_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S4_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S5_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S6_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S7_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S8_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S9_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S10_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S11_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S12_BUTTON, + MAX77843_MUIC_ADC_RESERVED_ACC_1, + MAX77843_MUIC_ADC_RESERVED_ACC_2, + MAX77843_MUIC_ADC_RESERVED_ACC_3, + MAX77843_MUIC_ADC_RESERVED_ACC_4, + MAX77843_MUIC_ADC_RESERVED_ACC_5, + MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2, + MAX77843_MUIC_ADC_PHONE_POWERED_DEV, + MAX77843_MUIC_ADC_TTY_CONVERTER, + MAX77843_MUIC_ADC_UART_CABLE, + MAX77843_MUIC_ADC_CEA936A_TYPE1_CHG, + MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF, + MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON, + MAX77843_MUIC_ADC_AV_CABLE_NOLOAD, + MAX77843_MUIC_ADC_CEA936A_TYPE2_CHG, + MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF, + MAX77843_MUIC_ADC_FACTORY_MODE_UART_ON, + MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE1, + MAX77843_MUIC_ADC_OPEN, +}; + +enum max77843_muic_cable_group { + MAX77843_CABLE_GROUP_ADC = 0, + MAX77843_CABLE_GROUP_CHG, + MAX77843_CABLE_GROUP_GND, +}; Cable group show the category of supported cables. I think you better move this enum on upper of 'enum max77843_muic_acc_type' This is not a cable type. I categorized cable group. GROUP_ADC is We can know cable group by IRQ type. so I categorized cable group. It is used to parameter of 'max77843_muic_get_cable_type()' function. + +enum max77843_muic_adv_debounce_time { + MAX77843_DEBOUNCE_TIME_5MS = 0, + MAX77843_DEBOUNCE_TIME_10MS, + MAX77843_DEBOUNCE_TIME_25MS, + MAX77843_DEBOUNCE_TIME_38_6
Re: [PATCH 1/6] mfd: max77843: Add max77843 MFD driver core driver
HI Chanwoo, 2015년 01월 23일 15:49에 Chanwoo Choi 이(가) 쓴 글: Hi Jaewon, On 01/23/2015 02:02 PM, Jaewon Kim wrote: This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Beomho Seo Signed-off-by: Jaewon Kim --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 241 include/linux/mfd/max77843-private.h | 410 ++ 4 files changed, 666 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 2e6b731..0c67c79 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -442,6 +442,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77843 + bool "Maxim Semiconductor MAX77843 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim Semiconductor MAX77843. + This is companion Power Management IC with LEDs, Haptic, Charger, + Fuel Gauge, MUIC(Micro USB Interface Controller) controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX8907 tristate "Maxim Semiconductor MAX8907 PMIC Support" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 53467e2..fe4f75c 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -117,6 +117,7 @@ obj-$(CONFIG_MFD_DA9063)+= da9063.o obj-$(CONFIG_MFD_MAX14577)+= max14577.o obj-$(CONFIG_MFD_MAX77686)+= max77686.o obj-$(CONFIG_MFD_MAX77693)+= max77693.o +obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c new file mode 100644 index 000..d7f8b76 --- /dev/null +++ b/drivers/mfd/max77843.c @@ -0,0 +1,241 @@ +/* + * max77843.c - MFD core driver for the Maxim MAX77843 + * + * Copyright (C) 2014 Samsung Electrnoics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell max77843_devs[] = { + { + .name = "max77843-muic", + .of_compatible = "maxim,max77843-muic", + }, { + .name = "max77843-regulator", + .of_compatible = "maxim,max77843-regulator", + }, { + .name = "max77843-charger", + .of_compatible = "maxim,max77843-charger" + }, { + .name = "max77843-fuelgauge", + .of_compatible = "maxim,max77843-fuelgauge", + }, +}; + +static const struct regmap_config max77843_charger_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_CHG_REG_END, +}; + +static const struct regmap_config max77843_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_SYS_REG_END, +}; + +static const struct regmap_irq max77843_irqs[] = { + /* TOPSYS interrupts */ + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSUVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSOVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TSHDN_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77843_irq_chip = { + .name = "max77843", + .status_base= MAX77843_SYS_REG_SYSINTSRC, + .mask_base = MAX77843_SYS_REG_SYSINTMASK, + .mask_invert= false, + .num_regs = 1, + .irqs = max77843_irqs, + .num_irqs = ARRAY_SIZE(max77843_irqs), +}; + +static int max77843_chg_init(struct max77843 *max77843) +{ + int ret; + + max77843->i2c_chg = i2c_new_dummy(max77843->i2c->adapter, I2C_ADDR_CHG); + if (!max77843->i2c_chg) { + dev_err(&max77843->i2c->dev, + "Cannot allocate I2C device for Charger\n"); + return PTR_ER
Re: [PATCH 5/6] regulator: max77843: Add max77843 regulator driver
Hi Krzysztof, 2015년 01월 23일 16:18에 Krzysztof Kozłowski 이(가) 쓴 글: 2015-01-23 6:02 GMT+01:00 Jaewon Kim : This patch adds new regulator driver to support max77843 MFD(Multi Function Device) chip`s regulators. The Max77843 has two voltage regulators for USB safeout. Cc: Mark Brown Signed-off-by: Beomho Seo Signed-off-by: Jaewon Kim --- drivers/regulator/Kconfig|8 ++ drivers/regulator/Makefile |1 + drivers/regulator/max77843.c | 259 ++ 3 files changed, 268 insertions(+) create mode 100644 drivers/regulator/max77843.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index c3a60b5..c1f9c33 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -414,6 +414,14 @@ config REGULATOR_MAX77802 Exynos5420/Exynos5800 SoCs to control various voltages. It includes support for control of voltage and ramp speed. +config REGULATOR_MAX77843 + tristate "Maxim 77843 regulator" + depends on MFD_MAX77843 + help + This driver controls a Maxim 77843 regulator. + The regulator include two 'SAFEOUT' for USB(Universal Serial Bus) + This is suitable for Exynos5433 SoC chips. + config REGULATOR_MC13XXX_CORE tristate diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 1f28ebf..12408d6 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o +obj-$(CONFIG_REGULATOR_MAX77843) += max77843.o obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o diff --git a/drivers/regulator/max77843.c b/drivers/regulator/max77843.c new file mode 100644 index 000..86afc7a --- /dev/null +++ b/drivers/regulator/max77843.c @@ -0,0 +1,259 @@ +/* + * max77843.c - Regulator driver for the Maxim MAX77843 + * + * Copyright (C) 2014 Samsung Electrnoics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include + +#define MAX77843_SUPPORTED_VOLTAGE_NUM 4 + +enum max77843_regulator_type { + MAX77843_SAFEOUT1 = 0, + MAX77843_SAFEOUT2, + MAX77843_CHARGER, + + MAX77843_NUM, +}; + +static const unsigned int max77843_regulator_table[] = { + 485, + 490, + 495, + 330, +}; + +static int max77843_reg_is_enabled(struct regulator_dev *rdev) +{ + struct regmap *regmap = rdev->regmap; + int ret; + unsigned int reg; + + ret = regmap_read(regmap, rdev->desc->enable_reg, ®); + if (ret) { + dev_err(&rdev->dev, "Fialed to read charger register\n"); + return ret; + } + + return (reg & rdev->desc->enable_mask) == rdev->desc->enable_mask; +} + +static int max77843_reg_get_current_limit(struct regulator_dev *rdev) +{ + struct regmap *regmap = rdev->regmap; + unsigned int chg_min_uA = rdev->constraints->min_uA; + unsigned int chg_max_uA = rdev->constraints->max_uA; + unsigned int val; + int ret; + unsigned int reg, sel; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®); + if (ret) { + dev_err(&rdev->dev, "Failed to read charger register\n"); + return ret; + } + + sel = reg & MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (sel < 0x03) + sel = 0; + else + sel -= 2; + + val = chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel; + if (val > chg_max_uA) + return -EINVAL; + + return val; +} + +static int max77843_reg_set_current_limit(struct regulator_dev *rdev, + int min_uA, int max_uA) +{ + struct regmap *regmap = rdev->regmap; + unsigned int chg_min_uA = rdev->constraints->min_uA; + int sel = 0; + + while (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel < min_uA) + sel++; + + if (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel > max_uA) + return -EINVAL; + + sel += 2; + + return regmap_write(regmap, MAX77843_CHG_REG_CHG_CNFG_02, sel); +} + +static struct regulator_ops max77843_charger_ops = { + .is_enabled = max77843_reg_is_enabled, + .enable = regulator_enable_regmap, +
Re: [PATCH 2/6] extcon: max77843: Add max77843 MUIC driver
Hi Krzysztof, 2015년 01월 23일 15:38에 Krzysztof Kozłowski 이(가) 쓴 글: 2015-01-23 6:02 GMT+01:00 Jaewon Kim : This patch adds MAX77843 extcon driver to support for MUIC(Micro USB Interface Controller) device by using EXTCON subsystem to handle various external connectors. Cc: Chanwoo Choi Signed-off-by: Jaewon Kim --- drivers/extcon/Kconfig | 10 + drivers/extcon/Makefile |1 + drivers/extcon/extcon-max77843.c | 871 ++ 3 files changed, 882 insertions(+) create mode 100644 drivers/extcon/extcon-max77843.c (...) +static int max77843_muic_remove(struct platform_device *pdev) +{ + struct max77843_muic_info *info = platform_get_drvdata(pdev); + + cancel_work_sync(&info->irq_work); + Missing regmap_del_irq_chip(). Best regards, Krzysztof I miss remap_del_irq_chip() function. thanks. I wil add this function. Thanks Jaewon Kim -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/6] mfd: max77843: Add max77843 MFD driver core driver
Hi Krzysztof, 2015년 01월 23일 15:32에 Krzysztof Kozlowski 이(가) 쓴 글: 2015-01-23 6:02 GMT+01:00 Jaewon Kim : This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Beomho Seo Signed-off-by: Jaewon Kim --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 241 include/linux/mfd/max77843-private.h | 410 ++ 4 files changed, 666 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 2e6b731..0c67c79 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -442,6 +442,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77843 + bool "Maxim Semiconductor MAX77843 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim Semiconductor MAX77843. + This is companion Power Management IC with LEDs, Haptic, Charger, + Fuel Gauge, MUIC(Micro USB Interface Controller) controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX8907 tristate "Maxim Semiconductor MAX8907 PMIC Support" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 53467e2..fe4f75c 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -117,6 +117,7 @@ obj-$(CONFIG_MFD_DA9063)+= da9063.o obj-$(CONFIG_MFD_MAX14577) += max14577.o obj-$(CONFIG_MFD_MAX77686) += max77686.o obj-$(CONFIG_MFD_MAX77693) += max77693.o +obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c new file mode 100644 index 000..d7f8b76 --- /dev/null +++ b/drivers/mfd/max77843.c @@ -0,0 +1,241 @@ +/* + * max77843.c - MFD core driver for the Maxim MAX77843 + * + * Copyright (C) 2014 Samsung Electrnoics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell max77843_devs[] = { + { + .name = "max77843-muic", + .of_compatible = "maxim,max77843-muic", + }, { + .name = "max77843-regulator", + .of_compatible = "maxim,max77843-regulator", + }, { + .name = "max77843-charger", + .of_compatible = "maxim,max77843-charger" + }, { + .name = "max77843-fuelgauge", + .of_compatible = "maxim,max77843-fuelgauge", + }, +}; + +static const struct regmap_config max77843_charger_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_CHG_REG_END, +}; + +static const struct regmap_config max77843_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_SYS_REG_END, +}; + +static const struct regmap_irq max77843_irqs[] = { + /* TOPSYS interrupts */ + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSUVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSOVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TSHDN_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77843_irq_chip = { + .name = "max77843", + .status_base= MAX77843_SYS_REG_SYSINTSRC, + .mask_base = MAX77843_SYS_REG_SYSINTMASK, + .mask_invert= false, + .num_regs = 1, + .irqs = max77843_irqs, + .num_irqs = ARRAY_SIZE(max77843_irqs), +}; + +static int max77843_chg_init(struct max77843 *max77843) +{ Could this function be moved to the charger driver? This way the driver will manage its own resources instead of depending on parent MFD driver. + int ret; + + max77843->i2c_chg = i2c_new_dummy(max77843->i2c->adapter, I2C_ADDR_CHG); + if (!max77843->i2c_chg) { + dev_er
[PATCH 5/6] regulator: max77843: Add max77843 regulator driver
This patch adds new regulator driver to support max77843 MFD(Multi Function Device) chip`s regulators. The Max77843 has two voltage regulators for USB safeout. Cc: Mark Brown Signed-off-by: Beomho Seo Signed-off-by: Jaewon Kim --- drivers/regulator/Kconfig|8 ++ drivers/regulator/Makefile |1 + drivers/regulator/max77843.c | 259 ++ 3 files changed, 268 insertions(+) create mode 100644 drivers/regulator/max77843.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index c3a60b5..c1f9c33 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -414,6 +414,14 @@ config REGULATOR_MAX77802 Exynos5420/Exynos5800 SoCs to control various voltages. It includes support for control of voltage and ramp speed. +config REGULATOR_MAX77843 + tristate "Maxim 77843 regulator" + depends on MFD_MAX77843 + help + This driver controls a Maxim 77843 regulator. + The regulator include two 'SAFEOUT' for USB(Universal Serial Bus) + This is suitable for Exynos5433 SoC chips. + config REGULATOR_MC13XXX_CORE tristate diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 1f28ebf..12408d6 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o +obj-$(CONFIG_REGULATOR_MAX77843) += max77843.o obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o diff --git a/drivers/regulator/max77843.c b/drivers/regulator/max77843.c new file mode 100644 index 000..86afc7a --- /dev/null +++ b/drivers/regulator/max77843.c @@ -0,0 +1,259 @@ +/* + * max77843.c - Regulator driver for the Maxim MAX77843 + * + * Copyright (C) 2014 Samsung Electrnoics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include + +#define MAX77843_SUPPORTED_VOLTAGE_NUM 4 + +enum max77843_regulator_type { + MAX77843_SAFEOUT1 = 0, + MAX77843_SAFEOUT2, + MAX77843_CHARGER, + + MAX77843_NUM, +}; + +static const unsigned int max77843_regulator_table[] = { + 485, + 490, + 495, + 330, +}; + +static int max77843_reg_is_enabled(struct regulator_dev *rdev) +{ + struct regmap *regmap = rdev->regmap; + int ret; + unsigned int reg; + + ret = regmap_read(regmap, rdev->desc->enable_reg, ®); + if (ret) { + dev_err(&rdev->dev, "Fialed to read charger register\n"); + return ret; + } + + return (reg & rdev->desc->enable_mask) == rdev->desc->enable_mask; +} + +static int max77843_reg_get_current_limit(struct regulator_dev *rdev) +{ + struct regmap *regmap = rdev->regmap; + unsigned int chg_min_uA = rdev->constraints->min_uA; + unsigned int chg_max_uA = rdev->constraints->max_uA; + unsigned int val; + int ret; + unsigned int reg, sel; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®); + if (ret) { + dev_err(&rdev->dev, "Failed to read charger register\n"); + return ret; + } + + sel = reg & MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (sel < 0x03) + sel = 0; + else + sel -= 2; + + val = chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel; + if (val > chg_max_uA) + return -EINVAL; + + return val; +} + +static int max77843_reg_set_current_limit(struct regulator_dev *rdev, + int min_uA, int max_uA) +{ + struct regmap *regmap = rdev->regmap; + unsigned int chg_min_uA = rdev->constraints->min_uA; + int sel = 0; + + while (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel < min_uA) + sel++; + + if (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel > max_uA) + return -EINVAL; + + sel += 2; + + return regmap_write(regmap, MAX77843_CHG_REG_CHG_CNFG_02, sel); +} + +static struct regulator_ops max77843_charger_ops = { + .is_enabled = max77843_reg_is_enabled, + .enable = regulator_enable_regmap, + .disable= regulator_disable_regmap, + .get_current_limit = max77843_reg_get_current_limit, +
[PATCH 0/6] Add new MFD driver for MAX77843
This patch series adds MAX77843(Multi Function Device) driver. The MAX77843 includes MUIC(Micro USB Interface Circuit), Li+ Charger with Fuel Gauge and 2 safeout LDOs for USB device. It is interfaced to host controller using I2C. Beomho Seo (2): power: max77843_charger: Add Max77843 charger device driver power: max77843_battery: Add Max77843 fuel gauge device driver Jaewon Kim (4): mfd: max77843: Add max77843 MFD driver core driver extcon: max77843: Add max77843 MUIC driver regulator: max77843: Add max77843 regulator driver Documentation: Add device tree bindings document for max77843 Documentation/devicetree/bindings/mfd/max77843.txt | 87 ++ drivers/extcon/Kconfig | 10 + drivers/extcon/Makefile|1 + drivers/extcon/extcon-max77843.c | 871 drivers/mfd/Kconfig| 14 + drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 241 ++ drivers/power/Kconfig | 16 + drivers/power/Makefile |2 + drivers/power/max77843_battery.c | 283 +++ drivers/power/max77843_charger.c | 506 drivers/regulator/Kconfig |8 + drivers/regulator/Makefile |1 + drivers/regulator/max77843.c | 259 ++ include/linux/mfd/max77843-private.h | 410 + 15 files changed, 2710 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt create mode 100644 drivers/extcon/extcon-max77843.c create mode 100644 drivers/mfd/max77843.c create mode 100644 drivers/power/max77843_battery.c create mode 100644 drivers/power/max77843_charger.c create mode 100644 drivers/regulator/max77843.c create mode 100644 include/linux/mfd/max77843-private.h -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 6/6] Documentation: Add device tree bindings document for max77843
Add document describing device tree bindings for max77843 MFD. Drivers: MFD core, regulator, extcon, charger and fuelgauge. Cc: Rob Herring Cc: Pawel Moll Cc: Mark Rutland Cc: Ian Campbell Cc: Kumar Gala Cc: Lee Jones Cc: Chanwoo Choi Cc: Sebastian Reichel Cc: Mark Brown Signed-off-by: Beomho Seo Signed-off-by: Jaewon Kim --- Documentation/devicetree/bindings/mfd/max77843.txt | 87 1 file changed, 87 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/max77843.txt diff --git a/Documentation/devicetree/bindings/mfd/max77843.txt b/Documentation/devicetree/bindings/mfd/max77843.txt new file mode 100644 index 000..6895604 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/max77843.txt @@ -0,0 +1,87 @@ +Maxim MAX77843 multi-function device + +MAX77843 is a Multi-Function Device with the following submodules: +- PMIC : 2 SAFEOUT LDOs for USB device +- CHARGER : Li+ battery charger with Fuel Gauge +- MUIC : Micro USB Interface Circuit +- HAPTIC : motor control driver for haptics +- LED: 4 channel RGBW LED + +It is interfaced to host controller using I2C. + +Required properties: +- compatible : Must be "maxim,max77843". +- reg : I2C slave address of PMIC block. +- interrupts : I2C line for main SoCs. +- interrupt-parent : The parent of interrupt controller. + +Optional properties: +- regulators : The regulators of max77843 have to be instantiated under subnode + named "regulators" using the following format. + + [*]refer : Documentation/devicetree/bindings/regulator/regulator.txt + + regulators { + SAFEOUT { + regulator-name = "SAFEOUT"; + }; + } + + List of valid regulator names: + - SAFEOUT1, SAFEOUT2, CHARGER. + +- max77843-muic : This properties used by extcon consumers. + Required properties: + - compatible : Must be "maxim,max77842-muic". + +- max77843-charger : There battery charger of MAX77843 have to be instantiated + under sub-node named "max77843-charger" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-charger". + - maxim,fast-charge-uamp : Fast charge current levels are + 100 mA to 3150 mA programmed by I2C per 100 mA. + - maxim,top-off-uamp : Top off current threshold levels are + 125 mA to 650 mA programmed by I2C per 75 mA. + - maxim,input-uamp-limit : Input current limit levels are + 100 mA to 3533 mA programmed by I2C per 33 mA. +- max77843-fuelgauge : There fuelgauge of MAX77843 have to be instantiated + under sub-node named "max77843-fuelgauge" using the following format. + Required properties: + - compatible : Must be "maxim,max77842-fuelgauge". + +Example: + max77843@66 { + compatible = "samsung,max77843"; + reg = <0x66>; + interrupt-parent = <&gpa1>; + interrupts = <5 2>; + + regulators { + SAFEOUT1 { + regulator-name = "SAFEOUT1"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + SAFEOUT2 { + regulator-name = "SAFEOUT2"; + regulator-min-microvolt = <330>; + regulator-max-microvolt = <495>; + }; + }; + + max77843-muic { + compatible = "maxim,max77843-muic"; + }; + + max77843-charger { + compatible = "maxim,max77843-charger"; + maxim,fast-charge-uamp = <45>; + maxim,top-off-uamp = <125000>; + maxim,input-uamp-limit = <50>; + }; + + max77843-fuelgauge { + compatible = "maxim,max77843-fuelgauge"; + }; + + }; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/6] power: max77843_battery: Add Max77843 fuel gauge device driver
From: Beomho Seo This patch adds device driver of max77843 fuel gauge. The driver support for battery fuel gauge in Maxim Max77843. It is fuel-gauge systems for lithuum-ion batteries in handled and portable devices. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|9 ++ drivers/power/Makefile |1 + drivers/power/max77843_battery.c | 283 ++ 3 files changed, 293 insertions(+) create mode 100644 drivers/power/max77843_battery.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index a054a28..0039bbb 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -212,6 +212,15 @@ config BATTERY_MAX17042 with MAX17042. This driver also supports max17047/50 chips which are improved version of max17042. +config BATTERY_MAX77843 + tristate "Maxim MAX77843 Fuel Gauge" + depends on MFD_MAX77843 + help + This add support for battery fuel gauge in Maxim MAX77843. It is + fuel-gauge systems for lithuum-ion (Li+) batteries in handled and + portable devices. The MAX17040 is configured to operate with a single + lithium cell. + config BATTERY_Z2 tristate "Z2 battery driver" depends on I2C && MACH_ZIPIT2 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 212c6a2..ae0d795 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o obj-$(CONFIG_BATTERY_DA9052) += da9052-battery.o obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o +obj-$(CONFIG_BATTERY_MAX77843) += max77843_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o diff --git a/drivers/power/max77843_battery.c b/drivers/power/max77843_battery.c new file mode 100644 index 000..a08dd0c --- /dev/null +++ b/drivers/power/max77843_battery.c @@ -0,0 +1,283 @@ +/* + * Fuel gauge driver for Maxim MAX77843 + * + * Copyright (C) 2014 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include + +struct max77843_battery { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; +}; + +static int max77843_battery_get_capacity(struct max77843_battery *battery) +{ + struct regmap *regmap = battery->regmap; + int ret, val; + u8 reg_data[2]; + + ret = regmap_bulk_read(regmap, MAX77843_FG_REG_SOCREP, reg_data, 2); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = ((reg_data[1] * 100) + (reg_data[0] * 100 / 256)) / 100; + + return val; +} + +static int max77843_battery_get_energy_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + u8 reg_data[2]; + + switch (psp) { + case POWER_SUPPLY_PROP_ENERGY_FULL: + reg = MAX77843_FG_REG_FULLCAP; + break; + case POWER_SUPPLY_PROP_ENERGY_NOW: + reg = MAX77843_FG_REG_REMCAP_REP; + break; + case POWER_SUPPLY_PROP_ENERGY_AVG: + reg = MAX77843_FG_REG_REMCAP_AV; + break; + default: + return -EINVAL; + } + + ret = regmap_bulk_read(regmap, reg, reg_data, 2); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = (reg_data[1] << 8) | reg_data[0]; + + return val; +} + +static int max77843_battery_get_current_prop(struct max77843_battery *battery, + enum power_supply_property psp) +{ + struct regmap *regmap = battery->regmap; + unsigned int reg; + int ret, val; + u8 reg_data[2]; + + switch (psp) { + case POWER_SUPPLY_PROP_CURRENT_NOW: + reg = MAX77843_FG_REG_CURRENT; + break; + case POWER_SUPPLY_PROP_CURRENT_AVG: + reg = MAX77843_FG_REG_AVG_CURRENT; + break; + default: + return -EINVAL; + } + + ret = regmap_bulk_read(regmap, reg, reg_data, 2); + if (ret) { + dev_err(battery->dev, "Failed to read fuelgauge register\n"); + return ret; + } + + val = (reg_data[1] << 8) | reg_data[0]; + if (val & 0x8000) { +
[PATCH 2/6] extcon: max77843: Add max77843 MUIC driver
This patch adds MAX77843 extcon driver to support for MUIC(Micro USB Interface Controller) device by using EXTCON subsystem to handle various external connectors. Cc: Chanwoo Choi Signed-off-by: Jaewon Kim --- drivers/extcon/Kconfig | 10 + drivers/extcon/Makefile |1 + drivers/extcon/extcon-max77843.c | 871 ++ 3 files changed, 882 insertions(+) create mode 100644 drivers/extcon/extcon-max77843.c diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index 6a1f7de..0b67538 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -55,6 +55,16 @@ config EXTCON_MAX77693 Maxim MAX77693 PMIC. The MAX77693 MUIC is a USB port accessory detector and switch. +config EXTCON_MAX77843 + tristate "MAX77843 EXTCON Support" + depends on MFD_MAX77843 + select IRQ_DOMAIN + select REGMAP_I2C + help + If you say yes here you get support for the MUIC device of + Maxim MAX77843. The MAX77843 MUIC is a USB port accessory + detector add switch. + config EXTCON_MAX8997 tristate "MAX8997 EXTCON Support" depends on MFD_MAX8997 && IRQ_DOMAIN diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile index 0370b42..f21d5c4 100644 --- a/drivers/extcon/Makefile +++ b/drivers/extcon/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_EXTCON_ARIZONA)+= extcon-arizona.o obj-$(CONFIG_EXTCON_GPIO) += extcon-gpio.o obj-$(CONFIG_EXTCON_MAX14577) += extcon-max14577.o obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o +obj-$(CONFIG_EXTCON_MAX77843) += extcon-max77843.o obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o obj-$(CONFIG_EXTCON_PALMAS)+= extcon-palmas.o obj-$(CONFIG_EXTCON_RT8973A) += extcon-rt8973a.o diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c new file mode 100644 index 000..caae9a7 --- /dev/null +++ b/drivers/extcon/extcon-max77843.c @@ -0,0 +1,871 @@ +/* + * extcon-max77843.c - MAX77843 extcon driver to support MUIC + * + * Copyright (C) 2014 Samsung Electrnoics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DELAY_MS_DEFAULT 15000 /* unit: millisecond */ + +enum max77843_muic_acc_type { + MAX77843_MUIC_ADC_GROUND = 0, + MAX77843_MUIC_ADC_SEND_END_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S1_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S2_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S3_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S4_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S5_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S6_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S7_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S8_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S9_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S10_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S11_BUTTON, + MAX77843_MUIC_ADC_REMOTE_S12_BUTTON, + MAX77843_MUIC_ADC_RESERVED_ACC_1, + MAX77843_MUIC_ADC_RESERVED_ACC_2, + MAX77843_MUIC_ADC_RESERVED_ACC_3, + MAX77843_MUIC_ADC_RESERVED_ACC_4, + MAX77843_MUIC_ADC_RESERVED_ACC_5, + MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2, + MAX77843_MUIC_ADC_PHONE_POWERED_DEV, + MAX77843_MUIC_ADC_TTY_CONVERTER, + MAX77843_MUIC_ADC_UART_CABLE, + MAX77843_MUIC_ADC_CEA936A_TYPE1_CHG, + MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF, + MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON, + MAX77843_MUIC_ADC_AV_CABLE_NOLOAD, + MAX77843_MUIC_ADC_CEA936A_TYPE2_CHG, + MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF, + MAX77843_MUIC_ADC_FACTORY_MODE_UART_ON, + MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE1, + MAX77843_MUIC_ADC_OPEN, +}; + +enum max77843_muic_cable_group { + MAX77843_CABLE_GROUP_ADC = 0, + MAX77843_CABLE_GROUP_CHG, + MAX77843_CABLE_GROUP_GND, +}; + +enum max77843_muic_adv_debounce_time { + MAX77843_DEBOUNCE_TIME_5MS = 0, + MAX77843_DEBOUNCE_TIME_10MS, + MAX77843_DEBOUNCE_TIME_25MS, + MAX77843_DEBOUNCE_TIME_38_62MS, +}; + +enum max77843_muic_support_list { + EXTCON_CABLE_USB = 0, + EXTCON_CABLE_USB_HOST, + EXTCON_CABLE_USB_HOST_TA, + EXTCON_CABLE_TA, + EXTCON_CABLE_FAST_CHARGER, + EXTCON_CABLE_SLOW_CHARGER, + EXTCON_CABLE_CHARGE_DOWNSTREAM, + EXTCON_CABLE_MHL, + EXTCON_CABLE_MHL_TA, + EXTCON_CABLE_JIG_USB_ON, + EXTCON_CABLE_JIG_USB_OFF, + EXTCON_CABLE_JIG_UART_OFF, + EXTCON_CABLE_JIG_UART_ON, + + EXTCON_CABLE_NUM, +}; + +enum max77843_muic_gnd_cable { + MAX77843_MUIC_GND_USB_OTG = 0x0, + MAX77843_MUIC_GND_USB_OTG_VB= 0x1, +
[PATCH 1/6] mfd: max77843: Add max77843 MFD driver core driver
This patch adds MAX77843 core/irq driver to support PMIC, MUIC(Micro USB Interface Controller), Charger, Fuel Gauge, LED and Haptic device. Cc: Lee Jones Signed-off-by: Beomho Seo Signed-off-by: Jaewon Kim --- drivers/mfd/Kconfig | 14 ++ drivers/mfd/Makefile |1 + drivers/mfd/max77843.c | 241 include/linux/mfd/max77843-private.h | 410 ++ 4 files changed, 666 insertions(+) create mode 100644 drivers/mfd/max77843.c create mode 100644 include/linux/mfd/max77843-private.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 2e6b731..0c67c79 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -442,6 +442,20 @@ config MFD_MAX77693 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77843 + bool "Maxim Semiconductor MAX77843 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim Semiconductor MAX77843. + This is companion Power Management IC with LEDs, Haptic, Charger, + Fuel Gauge, MUIC(Micro USB Interface Controller) controls on chip. + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + config MFD_MAX8907 tristate "Maxim Semiconductor MAX8907 PMIC Support" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 53467e2..fe4f75c 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -117,6 +117,7 @@ obj-$(CONFIG_MFD_DA9063)+= da9063.o obj-$(CONFIG_MFD_MAX14577) += max14577.o obj-$(CONFIG_MFD_MAX77686) += max77686.o obj-$(CONFIG_MFD_MAX77693) += max77693.o +obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c new file mode 100644 index 000..d7f8b76 --- /dev/null +++ b/drivers/mfd/max77843.c @@ -0,0 +1,241 @@ +/* + * max77843.c - MFD core driver for the Maxim MAX77843 + * + * Copyright (C) 2014 Samsung Electrnoics + * Author: Jaewon Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell max77843_devs[] = { + { + .name = "max77843-muic", + .of_compatible = "maxim,max77843-muic", + }, { + .name = "max77843-regulator", + .of_compatible = "maxim,max77843-regulator", + }, { + .name = "max77843-charger", + .of_compatible = "maxim,max77843-charger" + }, { + .name = "max77843-fuelgauge", + .of_compatible = "maxim,max77843-fuelgauge", + }, +}; + +static const struct regmap_config max77843_charger_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_CHG_REG_END, +}; + +static const struct regmap_config max77843_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77843_SYS_REG_END, +}; + +static const struct regmap_irq max77843_irqs[] = { + /* TOPSYS interrupts */ + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSUVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_SYSOVLO_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TSHDN_INT, }, + { .reg_offset = 0, .mask = MAX77843_SYS_IRQ_TM_INT, }, +}; + +static const struct regmap_irq_chip max77843_irq_chip = { + .name = "max77843", + .status_base= MAX77843_SYS_REG_SYSINTSRC, + .mask_base = MAX77843_SYS_REG_SYSINTMASK, + .mask_invert= false, + .num_regs = 1, + .irqs = max77843_irqs, + .num_irqs = ARRAY_SIZE(max77843_irqs), +}; + +static int max77843_chg_init(struct max77843 *max77843) +{ + int ret; + + max77843->i2c_chg = i2c_new_dummy(max77843->i2c->adapter, I2C_ADDR_CHG); + if (!max77843->i2c_chg) { + dev_err(&max77843->i2c->dev, + "Cannot allocate I2C device for Charger\n"); + return PTR_ERR(max77843->i2c_chg); + } + i2c_set_clientdata(max77843->i2c_chg, max77843); + + max77843->
[PATCH 3/6] power: max77843_charger: Add Max77843 charger device driver
From: Beomho Seo This patch adds device driver of max77843 charger. This driver provide initialize each charging mode(e.g. fast charge, top-off mode and constant charging mode so on.). Additionally, control charging paramters to use i2c interface. Cc: Sebastian Reichel Signed-off-by: Beomho Seo --- drivers/power/Kconfig|7 + drivers/power/Makefile |1 + drivers/power/max77843_charger.c | 506 ++ 3 files changed, 514 insertions(+) create mode 100644 drivers/power/max77843_charger.c diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 0108c2a..a054a28 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -332,6 +332,13 @@ config CHARGER_MAX14577 Say Y to enable support for the battery charger control sysfs and platform data of MAX14577/77836 MUICs. +config CHARGER_MAX77843 + tristate "Maxim MAX77843 battery charger driver" + depends on MFD_MAX77843 + help + Say Y to enable support for the battery charger control sysfs and + platform data of MAX77843 + config CHARGER_MAX8997 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" depends on MFD_MAX8997 && REGULATOR_MAX8997 diff --git a/drivers/power/Makefile b/drivers/power/Makefile index dfa8942..212c6a2 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_CHARGER_LP8788) += lp8788-charger.o obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o +obj-$(CONFIG_CHARGER_MAX77843) += max77843_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o diff --git a/drivers/power/max77843_charger.c b/drivers/power/max77843_charger.c new file mode 100644 index 000..317b2cc --- /dev/null +++ b/drivers/power/max77843_charger.c @@ -0,0 +1,506 @@ +/* + * Charger driver for Maxim MAX77843 + * + * Copyright (C) 2014 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published bythe Free Software Foundation. + */ + +#include +#include +#include +#include +#include + +struct max77843_charger_info { + u32 fast_charge_uamp; + u32 top_off_uamp; + u32 input_uamp_limit; +}; + +struct max77843_charger { + struct device *dev; + struct max77843 *max77843; + struct i2c_client *client; + struct regmap *regmap; + struct power_supply psy; + + struct max77843_charger_info*info; +}; + +static int max77843_charger_get_max_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_09, ®_data); + if (ret) { + dev_err(charger->dev, "Failed to read charger register\n"); + return ret; + } + + if (reg_data <= 0x03) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MIN; + } else if (reg_data >= 0x78) { + val = MAX77843_CHG_INPUT_CURRENT_LIMIT_MAX; + } else { + val = reg_data / 3; + if (reg_data % 3 == 0) + val *= 10; + else if (reg_data % 3 == 1) + val = val * 10 + 33000; + else + val = val * 10 + 67000; + } + + return val; +} + +static int max77843_charger_get_now_current(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®_data); + if (ret) { + dev_err(charger->dev, "Failed to read charger register\n"); + return ret; + } + + reg_data &= MAX77843_CHG_FAST_CHG_CURRENT_MASK; + + if (reg_data <= 0x02) + val = MAX77843_CHG_FAST_CHG_CURRENT_MIN; + else if (reg_data >= 0x3f) + val = MAX77843_CHG_FAST_CHG_CURRENT_MAX; + else + val = reg_data * MAX77843_CHG_FAST_CHG_CURRENT_STEP; + + return val; +} + +static int max77843_charger_get_online(struct max77843_charger *charger) +{ + struct regmap *regmap = charger->regmap; + int ret, val = 0; + unsigned int reg_data; + + ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_INT_OK, ®_data); + if (ret) { + dev_err(charger->dev, "Failed to read charger register\n"); + return ret; + } + + if (reg_data & MAX77843_CHG_CHGIN_OK) + val = true; + else +
[PATCH] ARM: dts: exynos4: fix pwm-cells in pwm node
pwm-cells should be 3. Third cell is optional PWM flags. And This flag supported by this binding is PWM_POLARITY_INVERTED Signed-off-by: Jaewon Kim --- arch/arm/boot/dts/exynos4.dtsi |4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/boot/dts/exynos4.dtsi b/arch/arm/boot/dts/exynos4.dtsi index b8ece4b..b687e53 100644 --- a/arch/arm/boot/dts/exynos4.dtsi +++ b/arch/arm/boot/dts/exynos4.dtsi @@ -548,13 +548,13 @@ status = "disabled"; }; - pwm@139D { + pwm: pwm@139D { compatible = "samsung,exynos4210-pwm"; reg = <0x139D 0x1000>; interrupts = <0 37 0>, <0 38 0>, <0 39 0>, <0 40 0>, <0 41 0>; clocks = <&clock CLK_PWM>; clock-names = "timers"; - #pwm-cells = <2>; + #pwm-cells = <3>; status = "disabled"; }; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html