Hi,
This is third version of patchset adding support for MAX77836 device
to the max14577 driver.
Lee Jones suggested that after obtaining acks from all maintainers he can
merged these patches to his tree. These patches touch different subsystems
(charger/power, regulator, extcon and mfd) so this would be probably the best
way to merge everything. I would be glad if I could get missing acks
(or comments).
Changes since v2
================
1. Added ACK-s.
2. Applied minor checkpatch fixes (pointed by Lee Jones).
3. Rebased on next-20140217.
Changes since v1
================
1. Added ACK-s, reviews and tested-by tags.
2. Removed applied patches (they were merged to the linux-next tree).
3. Applied comments from review (Lee Jones) to 5/15 (detection of device type)
and 8/15 (add max77836 support to max14577).
4. Rebased on next tree.
5. Added patch 13 and 14 (pointed by Jenny Tc):
- regulator/mfd: max14577: Export symbols for calculating charger current
- charger: max14577: Configure battery-dependent settings from DTS
6. Updated bindings documentation with new charger bindings.
Previous thread:
- [PATCH 00/18] mfd: max14577: Add support for MAX77836
http://thread.gmane.org/gmane.linux.kernel/1636654/focus=1636674
Description
===========
The MAX77836 is almost the same as MAX14577. Basically it is an extended
version of MAX14577. The chipsets have same MUIC component so the extcon,
charger and regulators require only little adjustments. More changes were
needed in the charger (because it uses lower charging current) and regulator
drivers (because mentioned different charing current and additional
regulators). The MAX77836 has also PMIC and Fuel Gauge (which is the same
as MAX17040/17048 Fuel Gauge).
The MAX77836 uses three I2C slave addresses and has additional interrupts
(related to PMIC and Fuel Gauge). It has also Interrupt Source register,
just like MAX77686 and MAX77693.
The patchset is organized in following way:
1. Patches from 1 to 7 prepare the driver for supporting MAX77836. They
mostly rename symbols and add additional logic related to different
device types.
2. Patches from 8 to 12 add support for MAX77836.
3. Patches 13 and 14 remove hard-coded charger configuration with DTS. They
were added after review on mailing lists.
4. Patch 15 adds bindings documentation, which was not merged previously.
The patchset is based on linux-next tree and depends on patches from previous
release which are already merged into next.
Testing was done on 3.10.
TODO: Merge max14577, max77686 and max77693 into one common driver. They are
very similar.
Best regards,
Krzysztof Kozlowski
Chanwoo Choi (1):
extcon: max14577: Change extcon name instead of static name according
to device type
Krzysztof Kozlowski (14):
mfd: max14577: Rename and add MAX14577 symbols to prepare for
max77836
mfd: max14577: Rename state container to maxim_core
mfd: max14577: Add "muic" suffix to regmap and irq_chip
mfd: max14577: Add detection of device type
extcon: max14577: Add max14577 prefix to muic_irqs
extcon: max14577: Choose muic_irqs according to device type
mfd: max77836: Add max77836 support to max14577 driver
extcon: max14577: Add support for max77836
regulator: max14577: Add support for max77836 regulators
charger: max14577: Add support for MAX77836 charger
power: max17040: Add ID for max77836 Fuel Gauge block
regulator/mfd: max14577: Export symbols for calculating charger
current
charger: max14577: Configure battery-dependent settings from DTS
mfd: max14577: Add device tree bindings document
Documentation/devicetree/bindings/mfd/max14577.txt | 149 +++++
drivers/extcon/extcon-max14577.c | 274 +++++----
drivers/mfd/max14577.c | 475 +++++++++++++---
drivers/power/max14577_charger.c | 360 +++++++++---
drivers/power/max17040_battery.c | 1 +
drivers/regulator/max14577.c | 279 +++++++---
include/linux/mfd/max14577-private.h | 582 ++++++++++++--------
include/linux/mfd/max14577.h | 50 +-
8 files changed, 1636 insertions(+), 534 deletions(-)
create mode 100644 Documentation/devicetree/bindings/mfd/max14577.txt
--
1.7.9.5
From: Chanwoo Choi <[email protected]>
This patch use device name to make sysfs path according to device type:
max14577-muic
- /sys/class/extcon/max14577-muic/
max77836-muic
- /sys/class/extcon/max77836-muic/
Signed-off-by: Chanwoo Choi <[email protected]>
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Acked-by: Chanwoo Choi <[email protected]>
Tested-by: Chanwoo Choi <[email protected]>
---
drivers/extcon/extcon-max14577.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index 3846941801b8..59f084fee4f3 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -24,7 +24,6 @@
#include <linux/mfd/max14577-private.h>
#include <linux/extcon.h>
-#define DEV_NAME "max14577-muic"
#define DELAY_MS_DEFAULT 17000 /* unit: millisecond */
enum max14577_muic_adc_debounce_time {
@@ -673,7 +672,8 @@ static int max14577_muic_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
return -ENOMEM;
}
- info->edev->name = DEV_NAME;
+
+ info->edev->name = dev_name(&pdev->dev);
info->edev->supported_cable = max14577_extcon_cable;
ret = extcon_dev_register(info->edev);
if (ret) {
@@ -737,7 +737,7 @@ static int max14577_muic_remove(struct platform_device *pdev)
static struct platform_driver max14577_muic_driver = {
.driver = {
- .name = DEV_NAME,
+ .name = "max14577-muic",
.owner = THIS_MODULE,
},
.probe = max14577_muic_probe,
--
1.7.9.5
This patch continues the preparation for adding support for max77836
device to existing max14577 driver.
The patch renames the struct "max14577" state container to "maxim_core".
This is only a rename-like patch, new code is not added.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Anton Vorontsov <[email protected]>
Cc: Dmitry Eremin-Solenikov <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Mark Brown <[email protected]>
Acked-by: Lee Jones <[email protected]>
Acked-by: Chanwoo Choi <[email protected]>
Tested-by: Chanwoo Choi <[email protected]>
---
drivers/extcon/extcon-max14577.c | 22 +++++------
drivers/mfd/max14577.c | 68 +++++++++++++++++-----------------
drivers/power/max14577_charger.c | 16 ++++----
drivers/regulator/max14577.c | 6 +--
include/linux/mfd/max14577-private.h | 2 +-
5 files changed, 57 insertions(+), 57 deletions(-)
diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index 6f7145a929cf..2879cc5844dc 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -41,7 +41,7 @@ enum max14577_muic_status {
struct max14577_muic_info {
struct device *dev;
- struct max14577 *max14577;
+ struct maxim_core *maxim_core;
struct extcon_dev *edev;
int prev_cable_type;
int prev_chg_type;
@@ -176,7 +176,7 @@ static int max14577_muic_set_debounce_time(struct max14577_muic_info *info,
case ADC_DEBOUNCE_TIME_10MS:
case ADC_DEBOUNCE_TIME_25MS:
case ADC_DEBOUNCE_TIME_38_62MS:
- ret = max14577_update_reg(info->max14577->regmap,
+ ret = max14577_update_reg(info->maxim_core->regmap,
MAXIM_MUIC_REG_CONTROL3,
MAXIM_CONTROL3_ADCDBSET_MASK,
time << MAXIM_CONTROL3_ADCDBSET_SHIFT);
@@ -210,7 +210,7 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
u8 ctrl1, ctrl2 = 0;
/* Set open state to path before changing hw path */
- ret = max14577_update_reg(info->max14577->regmap,
+ ret = max14577_update_reg(info->maxim_core->regmap,
MAXIM_MUIC_REG_CONTROL1,
MAXIM_CONTROL1_CLEAR_IDBEN_MICEN_MASK,
MAXIM_CONTROL1_SW_OPEN);
@@ -224,7 +224,7 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
else
ctrl1 = MAXIM_CONTROL1_SW_OPEN;
- ret = max14577_update_reg(info->max14577->regmap,
+ ret = max14577_update_reg(info->maxim_core->regmap,
MAXIM_MUIC_REG_CONTROL1,
MAXIM_CONTROL1_CLEAR_IDBEN_MICEN_MASK, ctrl1);
if (ret < 0) {
@@ -237,7 +237,7 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
else
ctrl2 |= MAXIM_CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */
- ret = max14577_update_reg(info->max14577->regmap,
+ ret = max14577_update_reg(info->maxim_core->regmap,
MAXIM_MUIC_REG_CONTROL2,
MAXIM_CONTROL2_LOWPWR_MASK | MAXIM_CONTROL2_CPEN_MASK,
ctrl2);
@@ -505,7 +505,7 @@ static void max14577_muic_irq_work(struct work_struct *work)
mutex_lock(&info->mutex);
- ret = max14577_bulk_read(info->max14577->regmap,
+ ret = max14577_bulk_read(info->maxim_core->regmap,
MAXIM_MUIC_REG_STATUS1, info->status, 2);
if (ret) {
dev_err(info->dev, "failed to read MUIC register\n");
@@ -581,7 +581,7 @@ static int max14577_muic_detect_accessory(struct max14577_muic_info *info)
mutex_lock(&info->mutex);
/* Read STATUSx register to detect accessory */
- ret = max14577_bulk_read(info->max14577->regmap,
+ ret = max14577_bulk_read(info->maxim_core->regmap,
MAXIM_MUIC_REG_STATUS1, info->status, 2);
if (ret) {
dev_err(info->dev, "failed to read MUIC register\n");
@@ -626,7 +626,7 @@ static void max14577_muic_detect_cable_wq(struct work_struct *work)
static int max14577_muic_probe(struct platform_device *pdev)
{
- struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent);
+ struct maxim_core *maxim_core = dev_get_drvdata(pdev->dev.parent);
struct max14577_muic_info *info;
int delay_jiffies;
int ret;
@@ -639,7 +639,7 @@ static int max14577_muic_probe(struct platform_device *pdev)
return -ENOMEM;
}
info->dev = &pdev->dev;
- info->max14577 = max14577;
+ info->maxim_core = maxim_core;
platform_set_drvdata(pdev, info);
mutex_init(&info->mutex);
@@ -651,7 +651,7 @@ static int max14577_muic_probe(struct platform_device *pdev)
struct max14577_muic_irq *muic_irq = &muic_irqs[i];
unsigned int virq = 0;
- virq = regmap_irq_get_virq(max14577->irq_data, muic_irq->irq);
+ virq = regmap_irq_get_virq(maxim_core->irq_data, muic_irq->irq);
if (!virq)
return -EINVAL;
muic_irq->virq = virq;
@@ -693,7 +693,7 @@ static int max14577_muic_probe(struct platform_device *pdev)
max14577_muic_set_path(info, info->path_uart, true);
/* Check revision number of MUIC device*/
- ret = max14577_read_reg(info->max14577->regmap,
+ ret = max14577_read_reg(info->maxim_core->regmap,
MAXIM_MUIC_REG_DEVICEID, &id);
if (ret < 0) {
dev_err(&pdev->dev, "failed to read revision number\n");
diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index d883055ca789..4567728f3fd4 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -85,7 +85,7 @@ static const struct regmap_irq_chip max14577_irq_chip = {
static int max14577_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
- struct max14577 *max14577;
+ struct maxim_core *maxim_core;
struct max14577_platform_data *pdata = dev_get_platdata(&i2c->dev);
struct device_node *np = i2c->dev.of_node;
u8 reg_data;
@@ -103,70 +103,70 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
return -EINVAL;
}
- max14577 = devm_kzalloc(&i2c->dev, sizeof(*max14577), GFP_KERNEL);
- if (!max14577)
+ maxim_core = devm_kzalloc(&i2c->dev, sizeof(*maxim_core), GFP_KERNEL);
+ if (!maxim_core)
return -ENOMEM;
- i2c_set_clientdata(i2c, max14577);
- max14577->dev = &i2c->dev;
- max14577->i2c = i2c;
- max14577->irq = i2c->irq;
+ i2c_set_clientdata(i2c, maxim_core);
+ maxim_core->dev = &i2c->dev;
+ maxim_core->i2c = i2c;
+ maxim_core->irq = i2c->irq;
- max14577->regmap = devm_regmap_init_i2c(i2c,
- &max14577_muic_regmap_config);
- if (IS_ERR(max14577->regmap)) {
- ret = PTR_ERR(max14577->regmap);
- dev_err(max14577->dev, "Failed to allocate register map: %d\n",
+ maxim_core->regmap = devm_regmap_init_i2c(i2c,
+ &max14577_muic_regmap_config);
+ if (IS_ERR(maxim_core->regmap)) {
+ ret = PTR_ERR(maxim_core->regmap);
+ dev_err(maxim_core->dev, "Failed to allocate register map: %d\n",
ret);
return ret;
}
- ret = max14577_read_reg(max14577->regmap, MAXIM_MUIC_REG_DEVICEID,
+ ret = max14577_read_reg(maxim_core->regmap, MAXIM_MUIC_REG_DEVICEID,
®_data);
if (ret) {
- dev_err(max14577->dev, "Device not found on this channel: %d\n",
+ dev_err(maxim_core->dev, "Device not found on this channel: %d\n",
ret);
return ret;
}
- max14577->vendor_id = ((reg_data & MAXIM_DEVID_VENDORID_MASK) >>
+ maxim_core->vendor_id = ((reg_data & MAXIM_DEVID_VENDORID_MASK) >>
MAXIM_DEVID_VENDORID_SHIFT);
- max14577->device_id = ((reg_data & MAXIM_DEVID_DEVICEID_MASK) >>
+ maxim_core->device_id = ((reg_data & MAXIM_DEVID_DEVICEID_MASK) >>
MAXIM_DEVID_DEVICEID_SHIFT);
- dev_info(max14577->dev, "Device ID: 0x%x, vendor: 0x%x\n",
- max14577->device_id, max14577->vendor_id);
+ dev_info(maxim_core->dev, "Device ID: 0x%x, vendor: 0x%x\n",
+ maxim_core->device_id, maxim_core->vendor_id);
- ret = regmap_add_irq_chip(max14577->regmap, max14577->irq,
+ ret = regmap_add_irq_chip(maxim_core->regmap, maxim_core->irq,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 0,
&max14577_irq_chip,
- &max14577->irq_data);
+ &maxim_core->irq_data);
if (ret != 0) {
dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n",
- max14577->irq, ret);
+ maxim_core->irq, ret);
return ret;
}
- ret = mfd_add_devices(max14577->dev, -1, max14577_devs,
+ ret = mfd_add_devices(maxim_core->dev, -1, max14577_devs,
ARRAY_SIZE(max14577_devs), NULL, 0,
- regmap_irq_get_domain(max14577->irq_data));
+ regmap_irq_get_domain(maxim_core->irq_data));
if (ret < 0)
goto err_mfd;
- device_init_wakeup(max14577->dev, 1);
+ device_init_wakeup(maxim_core->dev, 1);
return 0;
err_mfd:
- regmap_del_irq_chip(max14577->irq, max14577->irq_data);
+ regmap_del_irq_chip(maxim_core->irq, maxim_core->irq_data);
return ret;
}
static int max14577_i2c_remove(struct i2c_client *i2c)
{
- struct max14577 *max14577 = i2c_get_clientdata(i2c);
+ struct maxim_core *maxim_core = i2c_get_clientdata(i2c);
- mfd_remove_devices(max14577->dev);
- regmap_del_irq_chip(max14577->irq, max14577->irq_data);
+ mfd_remove_devices(maxim_core->dev);
+ regmap_del_irq_chip(maxim_core->irq, maxim_core->irq_data);
return 0;
}
@@ -180,10 +180,10 @@ MODULE_DEVICE_TABLE(i2c, max14577_i2c_id);
static int max14577_suspend(struct device *dev)
{
struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
- struct max14577 *max14577 = i2c_get_clientdata(i2c);
+ struct maxim_core *maxim_core = i2c_get_clientdata(i2c);
if (device_may_wakeup(dev)) {
- enable_irq_wake(max14577->irq);
+ enable_irq_wake(maxim_core->irq);
/*
* MUIC IRQ must be disabled during suspend if this is
* a wake up source because it will be handled before
@@ -194,7 +194,7 @@ static int max14577_suspend(struct device *dev)
* Interrupt handler tries to read registers but this read
* will fail because I2C is still suspended.
*/
- disable_irq(max14577->irq);
+ disable_irq(maxim_core->irq);
}
return 0;
@@ -203,11 +203,11 @@ static int max14577_suspend(struct device *dev)
static int max14577_resume(struct device *dev)
{
struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
- struct max14577 *max14577 = i2c_get_clientdata(i2c);
+ struct maxim_core *maxim_core = i2c_get_clientdata(i2c);
if (device_may_wakeup(dev)) {
- disable_irq_wake(max14577->irq);
- enable_irq(max14577->irq);
+ disable_irq_wake(maxim_core->irq);
+ enable_irq(maxim_core->irq);
}
return 0;
diff --git a/drivers/power/max14577_charger.c b/drivers/power/max14577_charger.c
index 66a4e4edea42..335c42a13136 100644
--- a/drivers/power/max14577_charger.c
+++ b/drivers/power/max14577_charger.c
@@ -21,8 +21,8 @@
#include <linux/mfd/max14577-private.h>
struct max14577_charger {
- struct device *dev;
- struct max14577 *max14577;
+ struct device *dev;
+ struct maxim_core *maxim_core;
struct power_supply charger;
unsigned int charging_state;
@@ -31,7 +31,7 @@ struct max14577_charger {
static int max14577_get_charger_state(struct max14577_charger *chg)
{
- struct regmap *rmap = chg->max14577->regmap;
+ struct regmap *rmap = chg->maxim_core->regmap;
int state = POWER_SUPPLY_STATUS_DISCHARGING;
u8 reg_data;
@@ -87,7 +87,7 @@ static int max14577_get_charge_type(struct max14577_charger *chg)
static int max14577_get_online(struct max14577_charger *chg)
{
- struct regmap *rmap = chg->max14577->regmap;
+ struct regmap *rmap = chg->maxim_core->regmap;
u8 reg_data;
max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS2, ®_data);
@@ -116,7 +116,7 @@ static int max14577_get_online(struct max14577_charger *chg)
*/
static int max14577_get_battery_health(struct max14577_charger *chg)
{
- struct regmap *rmap = chg->max14577->regmap;
+ struct regmap *rmap = chg->maxim_core->regmap;
int state = POWER_SUPPLY_HEALTH_GOOD;
u8 reg_data;
@@ -156,7 +156,7 @@ static int max14577_get_present(struct max14577_charger *chg)
*/
static void max14577_charger_reg_init(struct max14577_charger *chg)
{
- struct regmap *rmap = chg->max14577->regmap;
+ struct regmap *rmap = chg->maxim_core->regmap;
u8 reg_data;
/*
@@ -262,7 +262,7 @@ static int max14577_charger_get_property(struct power_supply *psy,
static int max14577_charger_probe(struct platform_device *pdev)
{
struct max14577_charger *chg;
- struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent);
+ struct maxim_core *maxim_core = dev_get_drvdata(pdev->dev.parent);
int ret;
chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL);
@@ -271,7 +271,7 @@ static int max14577_charger_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, chg);
chg->dev = &pdev->dev;
- chg->max14577 = max14577;
+ chg->maxim_core = maxim_core;
max14577_charger_reg_init(chg);
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c
index 9e5c0bd54684..3d75ca7aa87e 100644
--- a/drivers/regulator/max14577.c
+++ b/drivers/regulator/max14577.c
@@ -197,8 +197,8 @@ static inline struct device_node *match_of_node(int index)
static int max14577_regulator_probe(struct platform_device *pdev)
{
- struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent);
- struct max14577_platform_data *pdata = dev_get_platdata(max14577->dev);
+ struct maxim_core *maxim_core = dev_get_drvdata(pdev->dev.parent);
+ struct max14577_platform_data *pdata = dev_get_platdata(maxim_core->dev);
int i, ret;
struct regulator_config config = {};
@@ -207,7 +207,7 @@ static int max14577_regulator_probe(struct platform_device *pdev)
return ret;
config.dev = &pdev->dev;
- config.regmap = max14577->regmap;
+ config.regmap = maxim_core->regmap;
for (i = 0; i < ARRAY_SIZE(supported_regulators); i++) {
struct regulator_dev *regulator;
diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
index 9f5ce26cb54e..a0a24556741d 100644
--- a/include/linux/mfd/max14577-private.h
+++ b/include/linux/mfd/max14577-private.h
@@ -247,7 +247,7 @@ enum maxim_irq {
MAXIM_IRQ_NUM,
};
-struct max14577 {
+struct maxim_core {
struct device *dev;
struct i2c_client *i2c; /* Slave addr = 0x4A */
--
1.7.9.5
Add Maxim 77836 support to max14577 driver. The chipsets have same MUIC
component so the extcon, charger and regulators are almost the same. The
max77836 however has also PMIC and Fuel Gauge.
The MAX77836 uses three I2C slave addresses and has additional interrupts
(related to PMIC and Fuel Gauge). It has also Interrupt Source register,
just like MAX77686 and MAX77693.
The MAX77836 PMIC's TOPSYS and INTSRC interrupts are reported in the
PMIC block. The PMIC block has different I2C slave address and uses own
regmap so another regmap_irq_chip is needed.
Since we have two regmap_irq_chip, use shared interrupts on MAX77836.
This patch adds additional defines and functions to the max14577 MFD core
driver so the driver will handle both chipsets. Also this patch replaces
"0x1 << N" with BIT(N) in defines for register masks.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Chanwoo Choi <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Acked-by: Lee Jones <[email protected]>
---
drivers/mfd/max14577.c | 217 ++++++++++++++++++++++++++++++++--
include/linux/mfd/max14577-private.h | 175 +++++++++++++++++++--------
include/linux/mfd/max14577.h | 7 +-
3 files changed, 341 insertions(+), 58 deletions(-)
diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index 772088cf3ab8..1463b17c11c3 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -1,7 +1,7 @@
/*
- * max14577.c - mfd core driver for the Maxim 14577
+ * max14577.c - mfd core driver for the Maxim 14577/77836
*
- * Copyright (C) 2013 Samsung Electrnoics
+ * Copyright (C) 2014 Samsung Electrnoics
* Chanwoo Choi <[email protected]>
* Krzysztof Kozlowski <[email protected]>
*
@@ -37,11 +37,34 @@ static struct mfd_cell max14577_devs[] = {
{ .name = "max14577-charger", },
};
+static struct mfd_cell max77836_devs[] = {
+ {
+ .name = "max77836-muic",
+ .of_compatible = "maxim,max77836-muic",
+ },
+ {
+ .name = "max77836-regulator",
+ .of_compatible = "maxim,max77836-regulator",
+ },
+ {
+ .name = "max77836-charger",
+ .of_compatible = "maxim,max77836-charger",
+ },
+ {
+ .name = "max77836-battery",
+ .of_compatible = "maxim,max77836-battery",
+ },
+};
+
static struct of_device_id max14577_dt_match[] = {
{
.compatible = "maxim,max14577",
.data = (void *)MAXIM_DEVICE_TYPE_MAX14577,
},
+ {
+ .compatible = "maxim,max77836",
+ .data = (void *)MAXIM_DEVICE_TYPE_MAX77836,
+ },
{},
};
@@ -56,6 +79,26 @@ static bool max14577_muic_volatile_reg(struct device *dev, unsigned int reg)
return false;
}
+static bool max77836_muic_volatile_reg(struct device *dev, unsigned int reg)
+{
+ /* Any max14577 volatile registers are also max77836 volatile. */
+ if (max14577_muic_volatile_reg(dev, reg))
+ return true;
+
+ switch (reg) {
+ case MAX77836_FG_REG_VCELL_MSB ... MAX77836_FG_REG_SOC_LSB:
+ case MAX77836_FG_REG_CRATE_MSB ... MAX77836_FG_REG_CRATE_LSB:
+ case MAX77836_FG_REG_STATUS_H ... MAX77836_FG_REG_STATUS_L:
+ case MAX77836_PMIC_REG_INTSRC:
+ case MAX77836_PMIC_REG_TOPSYS_INT:
+ case MAX77836_PMIC_REG_TOPSYS_STAT:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
static const struct regmap_config max14577_muic_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
@@ -63,6 +106,13 @@ static const struct regmap_config max14577_muic_regmap_config = {
.max_register = MAXIM_MUIC_REG_END,
};
+static const struct regmap_config max77836_pmic_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .volatile_reg = max77836_muic_volatile_reg,
+ .max_register = MAX77836_PMIC_REG_END,
+};
+
static const struct regmap_irq max14577_irqs[] = {
/* INT1 interrupts */
{ .reg_offset = 0, .mask = MAXIM_INT1_ADC_MASK, },
@@ -85,12 +135,56 @@ static const struct regmap_irq_chip max14577_irq_chip = {
.name = "max14577",
.status_base = MAXIM_MUIC_REG_INT1,
.mask_base = MAXIM_MUIC_REG_INTMASK1,
- .mask_invert = 1,
+ .mask_invert = true,
.num_regs = 3,
.irqs = max14577_irqs,
.num_irqs = ARRAY_SIZE(max14577_irqs),
};
+static const struct regmap_irq max77836_muic_irqs[] = {
+ /* INT1 interrupts */
+ { .reg_offset = 0, .mask = MAXIM_INT1_ADC_MASK, },
+ { .reg_offset = 0, .mask = MAXIM_INT1_ADCLOW_MASK, },
+ { .reg_offset = 0, .mask = MAXIM_INT1_ADCERR_MASK, },
+ /* INT2 interrupts */
+ { .reg_offset = 1, .mask = MAXIM_INT2_CHGTYP_MASK, },
+ { .reg_offset = 1, .mask = MAXIM_INT2_CHGDETRUN_MASK, },
+ { .reg_offset = 1, .mask = MAXIM_INT2_DCDTMR_MASK, },
+ { .reg_offset = 1, .mask = MAXIM_INT2_DBCHG_MASK, },
+ { .reg_offset = 1, .mask = MAXIM_INT2_VBVOLT_MASK, },
+ { .reg_offset = 1, .mask = MAX77836_INT2_VIDRM_MASK, },
+ /* INT3 interrupts */
+ { .reg_offset = 2, .mask = MAXIM_INT3_EOC_MASK, },
+ { .reg_offset = 2, .mask = MAXIM_INT3_CGMBC_MASK, },
+ { .reg_offset = 2, .mask = MAXIM_INT3_OVP_MASK, },
+ { .reg_offset = 2, .mask = MAXIM_INT3_MBCCHGERR_MASK, },
+};
+
+static const struct regmap_irq_chip max77836_muic_irq_chip = {
+ .name = "max77836-muic",
+ .status_base = MAXIM_MUIC_REG_INT1,
+ .mask_base = MAXIM_MUIC_REG_INTMASK1,
+ .mask_invert = true,
+ .num_regs = 3,
+ .irqs = max77836_muic_irqs,
+ .num_irqs = ARRAY_SIZE(max77836_muic_irqs),
+};
+
+static const struct regmap_irq max77836_pmic_irqs[] = {
+ { .reg_offset = 0, .mask = MAX77836_TOPSYS_INT_T120C_MASK, },
+ { .reg_offset = 0, .mask = MAX77836_TOPSYS_INT_T140C_MASK, },
+};
+
+static const struct regmap_irq_chip max77836_pmic_irq_chip = {
+ .name = "max77836-pmic",
+ .status_base = MAX77836_PMIC_REG_TOPSYS_INT,
+ .mask_base = MAX77836_PMIC_REG_TOPSYS_INT_MASK,
+ .mask_invert = false,
+ .num_regs = 1,
+ .irqs = max77836_pmic_irqs,
+ .num_irqs = ARRAY_SIZE(max77836_pmic_irqs),
+};
+
static void max14577_print_dev_type(struct maxim_core *maxim_core)
{
u8 reg_data, vendor_id, device_id;
@@ -113,6 +207,81 @@ static void max14577_print_dev_type(struct maxim_core *maxim_core)
maxim_core->dev_type, device_id, vendor_id);
}
+/*
+ * Max77836 specific initialization code for driver probe.
+ * Adds new I2C dummy device, regmap and regmap IRQ chip.
+ * Unmasks Interrupt Source register.
+ *
+ * On success returns 0.
+ * On failure returns errno and reverts any changes done so far (e.g. remove
+ * I2C dummy device), except masking the INT SRC register.
+ */
+static int max77836_init(struct maxim_core *maxim_core)
+{
+ int ret;
+ u8 intsrc_mask;
+
+ maxim_core->i2c_pmic = i2c_new_dummy(maxim_core->i2c->adapter,
+ I2C_ADDR_PMIC);
+ if (!maxim_core->i2c_pmic) {
+ dev_err(maxim_core->dev, "Failed to register PMIC I2C device\n");
+ return -ENODEV;
+ }
+ i2c_set_clientdata(maxim_core->i2c_pmic, maxim_core);
+
+ maxim_core->regmap_pmic = devm_regmap_init_i2c(maxim_core->i2c_pmic,
+ &max77836_pmic_regmap_config);
+ if (IS_ERR(maxim_core->regmap_pmic)) {
+ ret = PTR_ERR(maxim_core->regmap_pmic);
+ dev_err(maxim_core->dev, "Failed to allocate PMIC register map: %d\n",
+ ret);
+ goto err;
+ }
+
+ /* Un-mask MAX77836 Interrupt Source register */
+ ret = max14577_read_reg(maxim_core->regmap_pmic,
+ MAX77836_PMIC_REG_INTSRC_MASK, &intsrc_mask);
+ if (ret < 0) {
+ dev_err(maxim_core->dev, "Failed to read PMIC register\n");
+ goto err;
+ }
+
+ intsrc_mask &= ~(MAX77836_INTSRC_MASK_TOP_INT_MASK);
+ intsrc_mask &= ~(MAX77836_INTSRC_MASK_MUIC_CHG_INT_MASK);
+ ret = max14577_write_reg(maxim_core->regmap_pmic,
+ MAX77836_PMIC_REG_INTSRC_MASK, intsrc_mask);
+ if (ret < 0) {
+ dev_err(maxim_core->dev, "Failed to write PMIC register\n");
+ goto err;
+ }
+
+ ret = regmap_add_irq_chip(maxim_core->regmap_pmic, maxim_core->irq,
+ IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED,
+ 0, &max77836_pmic_irq_chip,
+ &maxim_core->irq_data_pmic);
+ if (ret != 0) {
+ dev_err(maxim_core->dev, "Failed to request PMIC IRQ %d: %d\n",
+ maxim_core->irq, ret);
+ goto err;
+ }
+
+ return 0;
+
+err:
+ i2c_unregister_device(maxim_core->i2c_pmic);
+
+ return ret;
+}
+
+/*
+ * Max77836 specific de-initialization code for driver remove.
+ */
+static void max77836_remove(struct maxim_core *maxim_core)
+{
+ regmap_del_irq_chip(maxim_core->irq, maxim_core->irq_data_pmic);
+ i2c_unregister_device(maxim_core->i2c_pmic);
+}
+
static int max14577_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
@@ -120,6 +289,10 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
struct max14577_platform_data *pdata = dev_get_platdata(&i2c->dev);
struct device_node *np = i2c->dev.of_node;
int ret = 0;
+ const struct regmap_irq_chip *irq_chip;
+ struct mfd_cell *mfd_devs;
+ unsigned int mfd_devs_size;
+ int irq_flags;
if (np) {
pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL);
@@ -163,9 +336,24 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
max14577_print_dev_type(maxim_core);
+ switch (maxim_core->dev_type) {
+ case MAXIM_DEVICE_TYPE_MAX77836:
+ irq_chip = &max77836_muic_irq_chip;
+ mfd_devs = max77836_devs;
+ mfd_devs_size = ARRAY_SIZE(max77836_devs);
+ irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED;
+ break;
+ case MAXIM_DEVICE_TYPE_MAX14577:
+ default:
+ irq_chip = &max14577_irq_chip;
+ mfd_devs = max14577_devs;
+ mfd_devs_size = ARRAY_SIZE(max14577_devs);
+ irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
+ break;
+ }
+
ret = regmap_add_irq_chip(maxim_core->regmap_muic, maxim_core->irq,
- IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 0,
- &max14577_irq_chip,
+ irq_flags, 0, irq_chip,
&maxim_core->irq_data_muic);
if (ret != 0) {
dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n",
@@ -173,8 +361,15 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
return ret;
}
- ret = mfd_add_devices(maxim_core->dev, -1, max14577_devs,
- ARRAY_SIZE(max14577_devs), NULL, 0,
+ /* Max77836 specific initialization code (additional regmap) */
+ if (maxim_core->dev_type == MAXIM_DEVICE_TYPE_MAX77836) {
+ ret = max77836_init(maxim_core);
+ if (ret < 0)
+ goto err_max77836;
+ }
+
+ ret = mfd_add_devices(maxim_core->dev, -1, mfd_devs,
+ mfd_devs_size, NULL, 0,
regmap_irq_get_domain(maxim_core->irq_data_muic));
if (ret < 0)
goto err_mfd;
@@ -184,6 +379,9 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
return 0;
err_mfd:
+ if (maxim_core->dev_type == MAXIM_DEVICE_TYPE_MAX77836)
+ max77836_remove(maxim_core);
+err_max77836:
regmap_del_irq_chip(maxim_core->irq, maxim_core->irq_data_muic);
return ret;
@@ -195,12 +393,15 @@ static int max14577_i2c_remove(struct i2c_client *i2c)
mfd_remove_devices(maxim_core->dev);
regmap_del_irq_chip(maxim_core->irq, maxim_core->irq_data_muic);
+ if (maxim_core->dev_type == MAXIM_DEVICE_TYPE_MAX77836)
+ max77836_remove(maxim_core);
return 0;
}
static const struct i2c_device_id max14577_i2c_id[] = {
{ "max14577", MAXIM_DEVICE_TYPE_MAX14577, },
+ { "max77836", MAXIM_DEVICE_TYPE_MAX77836, },
{ }
};
MODULE_DEVICE_TABLE(i2c, max14577_i2c_id);
@@ -271,5 +472,5 @@ static void __exit max14577_i2c_exit(void)
module_exit(max14577_i2c_exit);
MODULE_AUTHOR("Chanwoo Choi <[email protected]>, Krzysztof Kozlowski <[email protected]>");
-MODULE_DESCRIPTION("MAXIM 14577 multi-function core driver");
+MODULE_DESCRIPTION("Maxim 14577/77836 multi-function core driver");
MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
index afa4e525f9b7..472d5780ca50 100644
--- a/include/linux/mfd/max14577-private.h
+++ b/include/linux/mfd/max14577-private.h
@@ -1,7 +1,7 @@
/*
- * max14577-private.h - Common API for the Maxim 14577 internal sub chip
+ * max14577-private.h - Common API for the Maxim 14577/77836 internal sub chip
*
- * Copyright (C) 2013 Samsung Electrnoics
+ * Copyright (C) 2014 Samsung Electrnoics
* Chanwoo Choi <[email protected]>
* Krzysztof Kozlowski <[email protected]>
*
@@ -22,9 +22,14 @@
#include <linux/i2c.h>
#include <linux/regmap.h>
+#define I2C_ADDR_PMIC (0x46 >> 1)
+#define I2C_ADDR_MUIC (0x4A >> 1)
+#define I2C_ADDR_FG (0x6C >> 1)
+
enum maxim_device_type {
MAXIM_DEVICE_TYPE_UNKNOWN = 0,
MAXIM_DEVICE_TYPE_MAX14577,
+ MAXIM_DEVICE_TYPE_MAX77836,
MAXIM_DEVICE_TYPE_NUM,
};
@@ -69,20 +74,21 @@ enum maxim_muic_charger_type {
};
/* MAX14577 interrupts */
-#define MAXIM_INT1_ADC_MASK (0x1 << 0)
-#define MAXIM_INT1_ADCLOW_MASK (0x1 << 1)
-#define MAXIM_INT1_ADCERR_MASK (0x1 << 2)
-
-#define MAXIM_INT2_CHGTYP_MASK (0x1 << 0)
-#define MAXIM_INT2_CHGDETRUN_MASK (0x1 << 1)
-#define MAXIM_INT2_DCDTMR_MASK (0x1 << 2)
-#define MAXIM_INT2_DBCHG_MASK (0x1 << 3)
-#define MAXIM_INT2_VBVOLT_MASK (0x1 << 4)
-
-#define MAXIM_INT3_EOC_MASK (0x1 << 0)
-#define MAXIM_INT3_CGMBC_MASK (0x1 << 1)
-#define MAXIM_INT3_OVP_MASK (0x1 << 2)
-#define MAXIM_INT3_MBCCHGERR_MASK (0x1 << 3)
+#define MAXIM_INT1_ADC_MASK BIT(0)
+#define MAXIM_INT1_ADCLOW_MASK BIT(1)
+#define MAXIM_INT1_ADCERR_MASK BIT(2)
+
+#define MAXIM_INT2_CHGTYP_MASK BIT(0)
+#define MAXIM_INT2_CHGDETRUN_MASK BIT(1)
+#define MAXIM_INT2_DCDTMR_MASK BIT(2)
+#define MAXIM_INT2_DBCHG_MASK BIT(3)
+#define MAXIM_INT2_VBVOLT_MASK BIT(4)
+#define MAX77836_INT2_VIDRM_MASK BIT(5)
+
+#define MAXIM_INT3_EOC_MASK BIT(0)
+#define MAXIM_INT3_CGMBC_MASK BIT(1)
+#define MAXIM_INT3_OVP_MASK BIT(2)
+#define MAXIM_INT3_MBCCHGERR_MASK BIT(3)
/* MAX14577 DEVICE ID register */
#define MAXIM_DEVID_VENDORID_SHIFT 0
@@ -94,9 +100,11 @@ enum maxim_muic_charger_type {
#define MAXIM_STATUS1_ADC_SHIFT 0
#define MAXIM_STATUS1_ADCLOW_SHIFT 5
#define MAXIM_STATUS1_ADCERR_SHIFT 6
+#define MAX77836_STATUS1_ADC1K_SHIFT 7
#define MAXIM_STATUS1_ADC_MASK (0x1f << MAXIM_STATUS1_ADC_SHIFT)
-#define MAXIM_STATUS1_ADCLOW_MASK (0x1 << MAXIM_STATUS1_ADCLOW_SHIFT)
-#define MAXIM_STATUS1_ADCERR_MASK (0x1 << MAXIM_STATUS1_ADCERR_SHIFT)
+#define MAXIM_STATUS1_ADCLOW_MASK BIT(MAXIM_STATUS1_ADCLOW_SHIFT)
+#define MAXIM_STATUS1_ADCERR_MASK BIT(MAXIM_STATUS1_ADCERR_SHIFT)
+#define MAX77836_STATUS1_ADC1K_MASK BIT(MAX77836_STATUS1_ADC1K_SHIFT)
/* MAX14577 STATUS2 register */
#define MAXIM_STATUS2_CHGTYP_SHIFT 0
@@ -104,21 +112,23 @@ enum maxim_muic_charger_type {
#define MAXIM_STATUS2_DCDTMR_SHIFT 4
#define MAXIM_STATUS2_DBCHG_SHIFT 5
#define MAXIM_STATUS2_VBVOLT_SHIFT 6
+#define MAX77836_STATUS2_VIDRM_SHIFT 7
#define MAXIM_STATUS2_CHGTYP_MASK (0x7 << MAXIM_STATUS2_CHGTYP_SHIFT)
-#define MAXIM_STATUS2_CHGDETRUN_MASK (0x1 << MAXIM_STATUS2_CHGDETRUN_SHIFT)
-#define MAXIM_STATUS2_DCDTMR_MASK (0x1 << MAXIM_STATUS2_DCDTMR_SHIFT)
-#define MAXIM_STATUS2_DBCHG_MASK (0x1 << MAXIM_STATUS2_DBCHG_SHIFT)
-#define MAXIM_STATUS2_VBVOLT_MASK (0x1 << MAXIM_STATUS2_VBVOLT_SHIFT)
+#define MAXIM_STATUS2_CHGDETRUN_MASK BIT(MAXIM_STATUS2_CHGDETRUN_SHIFT)
+#define MAXIM_STATUS2_DCDTMR_MASK BIT(MAXIM_STATUS2_DCDTMR_SHIFT)
+#define MAXIM_STATUS2_DBCHG_MASK BIT(MAXIM_STATUS2_DBCHG_SHIFT)
+#define MAXIM_STATUS2_VBVOLT_MASK BIT(MAXIM_STATUS2_VBVOLT_SHIFT)
+#define MAX77836_STATUS2_VIDRM_MASK BIT(MAX77836_STATUS2_VIDRM_SHIFT)
/* MAX14577 STATUS3 register */
#define MAXIM_STATUS3_EOC_SHIFT 0
#define MAXIM_STATUS3_CGMBC_SHIFT 1
#define MAXIM_STATUS3_OVP_SHIFT 2
#define MAXIM_STATUS3_MBCCHGERR_SHIFT 3
-#define MAXIM_STATUS3_EOC_MASK (0x1 << MAXIM_STATUS3_EOC_SHIFT)
-#define MAXIM_STATUS3_CGMBC_MASK (0x1 << MAXIM_STATUS3_CGMBC_SHIFT)
-#define MAXIM_STATUS3_OVP_MASK (0x1 << MAXIM_STATUS3_OVP_SHIFT)
-#define MAXIM_STATUS3_MBCCHGERR_MASK (0x1 << MAXIM_STATUS3_MBCCHGERR_SHIFT)
+#define MAXIM_STATUS3_EOC_MASK BIT(MAXIM_STATUS3_EOC_SHIFT)
+#define MAXIM_STATUS3_CGMBC_MASK BIT(MAXIM_STATUS3_CGMBC_SHIFT)
+#define MAXIM_STATUS3_OVP_MASK BIT(MAXIM_STATUS3_OVP_SHIFT)
+#define MAXIM_STATUS3_MBCCHGERR_MASK BIT(MAXIM_STATUS3_MBCCHGERR_SHIFT)
/* MAX14577 CONTROL1 register */
#define MAXIM_CONTROL1_COMN1SW_SHIFT 0
@@ -127,8 +137,8 @@ enum maxim_muic_charger_type {
#define MAXIM_CONTROL1_IDBEN_SHIFT 7
#define MAXIM_CONTROL1_COMN1SW_MASK (0x7 << MAXIM_CONTROL1_COMN1SW_SHIFT)
#define MAXIM_CONTROL1_COMP2SW_MASK (0x7 << MAXIM_CONTROL1_COMP2SW_SHIFT)
-#define MAXIM_CONTROL1_MICEN_MASK (0x1 << MAXIM_CONTROL1_MICEN_SHIFT)
-#define MAXIM_CONTROL1_IDBEN_MASK (0x1 << MAXIM_CONTROL1_IDBEN_SHIFT)
+#define MAXIM_CONTROL1_MICEN_MASK BIT(MAXIM_CONTROL1_MICEN_SHIFT)
+#define MAXIM_CONTROL1_IDBEN_MASK BIT(MAXIM_CONTROL1_IDBEN_SHIFT)
#define MAXIM_CONTROL1_CLEAR_IDBEN_MICEN_MASK (MAXIM_CONTROL1_COMN1SW_MASK | MAXIM_CONTROL1_COMP2SW_MASK)
#define MAXIM_CONTROL1_SW_USB ((1 << MAXIM_CONTROL1_COMP2SW_SHIFT) \
@@ -149,14 +159,14 @@ enum maxim_muic_charger_type {
#define MAXIM_CONTROL2_ACCDET_SHIFT 5
#define MAXIM_CONTROL2_USBCPINT_SHIFT 6
#define MAXIM_CONTROL2_RCPS_SHIFT 7
-#define MAXIM_CONTROL2_LOWPWR_MASK (0x1 << MAXIM_CONTROL2_LOWPWR_SHIFT)
-#define MAXIM_CONTROL2_ADCEN_MASK (0x1 << MAXIM_CONTROL2_ADCEN_SHIFT)
-#define MAXIM_CONTROL2_CPEN_MASK (0x1 << MAXIM_CONTROL2_CPEN_SHIFT)
-#define MAXIM_CONTROL2_SFOUTASRT_MASK (0x1 << MAXIM_CONTROL2_SFOUTASRT_SHIFT)
-#define MAXIM_CONTROL2_SFOUTORD_MASK (0x1 << MAXIM_CONTROL2_SFOUTORD_SHIFT)
-#define MAXIM_CONTROL2_ACCDET_MASK (0x1 << MAXIM_CONTROL2_ACCDET_SHIFT)
-#define MAXIM_CONTROL2_USBCPINT_MASK (0x1 << MAXIM_CONTROL2_USBCPINT_SHIFT)
-#define MAXIM_CONTROL2_RCPS_MASK (0x1 << MAXIM_CONTROL2_RCPS_SHIFT)
+#define MAXIM_CONTROL2_LOWPWR_MASK BIT(MAXIM_CONTROL2_LOWPWR_SHIFT)
+#define MAXIM_CONTROL2_ADCEN_MASK BIT(MAXIM_CONTROL2_ADCEN_SHIFT)
+#define MAXIM_CONTROL2_CPEN_MASK BIT(MAXIM_CONTROL2_CPEN_SHIFT)
+#define MAXIM_CONTROL2_SFOUTASRT_MASK BIT(MAXIM_CONTROL2_SFOUTASRT_SHIFT)
+#define MAXIM_CONTROL2_SFOUTORD_MASK BIT(MAXIM_CONTROL2_SFOUTORD_SHIFT)
+#define MAXIM_CONTROL2_ACCDET_MASK BIT(MAXIM_CONTROL2_ACCDET_SHIFT)
+#define MAXIM_CONTROL2_USBCPINT_MASK BIT(MAXIM_CONTROL2_USBCPINT_SHIFT)
+#define MAXIM_CONTROL2_RCPS_MASK BIT(MAXIM_CONTROL2_RCPS_SHIFT)
#define MAXIM_CONTROL2_CPEN1_LOWPWR0 ((1 << MAXIM_CONTROL2_CPEN_SHIFT) | \
(0 << MAXIM_CONTROL2_LOWPWR_SHIFT))
@@ -180,14 +190,14 @@ enum maxim_muic_charger_type {
#define MAXIM_CDETCTRL1_DBEXIT_SHIFT 5
#define MAXIM_CDETCTRL1_DBIDLE_SHIFT 6
#define MAXIM_CDETCTRL1_CDPDET_SHIFT 7
-#define MAXIM_CDETCTRL1_CHGDETEN_MASK (0x1 << MAXIM_CDETCTRL1_CHGDETEN_SHIFT)
-#define MAXIM_CDETCTRL1_CHGTYPMAN_MASK (0x1 << MAXIM_CDETCTRL1_CHGTYPMAN_SHIFT)
-#define MAXIM_CDETCTRL1_DCDEN_MASK (0x1 << MAXIM_CDETCTRL1_DCDEN_SHIFT)
-#define MAXIM_CDETCTRL1_DCD2SCT_MASK (0x1 << MAXIM_CDETCTRL1_DCD2SCT_SHIFT)
-#define MAXIM_CDETCTRL1_DCHKTM_MASK (0x1 << MAXIM_CDETCTRL1_DCHKTM_SHIFT)
-#define MAXIM_CDETCTRL1_DBEXIT_MASK (0x1 << MAXIM_CDETCTRL1_DBEXIT_SHIFT)
-#define MAXIM_CDETCTRL1_DBIDLE_MASK (0x1 << MAXIM_CDETCTRL1_DBIDLE_SHIFT)
-#define MAXIM_CDETCTRL1_CDPDET_MASK (0x1 << MAXIM_CDETCTRL1_CDPDET_SHIFT)
+#define MAXIM_CDETCTRL1_CHGDETEN_MASK BIT(MAXIM_CDETCTRL1_CHGDETEN_SHIFT)
+#define MAXIM_CDETCTRL1_CHGTYPMAN_MASK BIT(MAXIM_CDETCTRL1_CHGTYPMAN_SHIFT)
+#define MAXIM_CDETCTRL1_DCDEN_MASK BIT(MAXIM_CDETCTRL1_DCDEN_SHIFT)
+#define MAXIM_CDETCTRL1_DCD2SCT_MASK BIT(MAXIM_CDETCTRL1_DCD2SCT_SHIFT)
+#define MAXIM_CDETCTRL1_DCHKTM_MASK BIT(MAXIM_CDETCTRL1_DCHKTM_SHIFT)
+#define MAXIM_CDETCTRL1_DBEXIT_MASK BIT(MAXIM_CDETCTRL1_DBEXIT_SHIFT)
+#define MAXIM_CDETCTRL1_DBIDLE_MASK BIT(MAXIM_CDETCTRL1_DBIDLE_SHIFT)
+#define MAXIM_CDETCTRL1_CDPDET_MASK BIT(MAXIM_CDETCTRL1_CDPDET_SHIFT)
/* MAX14577 MAXIM_CHGCTRL1 register */
#define MAXIM_CHGCTRL1_TCHW_SHIFT 4
@@ -195,9 +205,9 @@ enum maxim_muic_charger_type {
/* MAX14577 MAXIM_CHGCTRL2 register */
#define MAXIM_CHGCTRL2_MBCHOSTEN_SHIFT 6
-#define MAXIM_CHGCTRL2_MBCHOSTEN_MASK (0x1 << MAXIM_CHGCTRL2_MBCHOSTEN_SHIFT)
+#define MAXIM_CHGCTRL2_MBCHOSTEN_MASK BIT(MAXIM_CHGCTRL2_MBCHOSTEN_SHIFT)
#define MAXIM_CHGCTRL2_VCHGR_RC_SHIFT 7
-#define MAXIM_CHGCTRL2_VCHGR_RC_MASK (0x1 << MAXIM_CHGCTRL2_VCHGR_RC_SHIFT)
+#define MAXIM_CHGCTRL2_VCHGR_RC_MASK BIT(MAXIM_CHGCTRL2_VCHGR_RC_SHIFT)
/* MAX14577 MAXIM_CHGCTRL3 register */
#define MAXIM_CHGCTRL3_MBCCVWRC_SHIFT 0
@@ -207,7 +217,7 @@ enum maxim_muic_charger_type {
#define MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT 0
#define MAXIM_CHGCTRL4_MBCICHWRCH_MASK (0xf << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT)
#define MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT 4
-#define MAXIM_CHGCTRL4_MBCICHWRCL_MASK (0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT)
+#define MAXIM_CHGCTRL4_MBCICHWRCL_MASK BIT(MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT)
/* MAX14577 MAXIM_CHGCTRL5 register */
#define MAXIM_CHGCTRL5_EOCS_SHIFT 0
@@ -215,7 +225,7 @@ enum maxim_muic_charger_type {
/* MAX14577 MAXIM_CHGCTRL6 register */
#define MAXIM_CHGCTRL6_AUTOSTOP_SHIFT 5
-#define MAXIM_CHGCTRL6_AUTOSTOP_MASK (0x1 << MAXIM_CHGCTRL6_AUTOSTOP_SHIFT)
+#define MAXIM_CHGCTRL6_AUTOSTOP_MASK BIT(MAXIM_CHGCTRL6_AUTOSTOP_SHIFT)
/* MAX14577 MAXIM_CHGCTRL7 register */
#define MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT 0
@@ -230,7 +240,69 @@ enum maxim_muic_charger_type {
/* MAX14577 regulator SFOUT LDO voltage, fixed, uV */
#define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000
+/* Slave addr = 0x46: PMIC */
+enum max77836_pmic_reg {
+ MAX77836_PMIC_REG_PMIC_ID = 0x20,
+ MAX77836_PMIC_REG_PMIC_REV = 0x21,
+ MAX77836_PMIC_REG_INTSRC = 0x22,
+ MAX77836_PMIC_REG_INTSRC_MASK = 0x23,
+ MAX77836_PMIC_REG_TOPSYS_INT = 0x24,
+ MAX77836_PMIC_REG_TOPSYS_INT_MASK = 0x26,
+ MAX77836_PMIC_REG_TOPSYS_STAT = 0x28,
+ MAX77836_PMIC_REG_MRSTB_CNTL = 0x2A,
+ MAX77836_PMIC_REG_LSCNFG = 0x2B,
+
+ MAX77836_LDO_REG_CNFG1_LDO1 = 0x51,
+ MAX77836_LDO_REG_CNFG2_LDO1 = 0x52,
+ MAX77836_LDO_REG_CNFG1_LDO2 = 0x53,
+ MAX77836_LDO_REG_CNFG2_LDO2 = 0x54,
+ MAX77836_LDO_REG_CNFG_LDO_BIAS = 0x55,
+
+ MAX77836_COMP_REG_COMP1 = 0x60,
+
+ MAX77836_PMIC_REG_END,
+};
+#define MAX77836_INTSRC_MASK_TOP_INT_SHIFT 1
+#define MAX77836_INTSRC_MASK_MUIC_CHG_INT_SHIFT 3
+#define MAX77836_INTSRC_MASK_TOP_INT_MASK BIT(MAX77836_INTSRC_MASK_TOP_INT_SHIFT)
+#define MAX77836_INTSRC_MASK_MUIC_CHG_INT_MASK BIT(MAX77836_INTSRC_MASK_MUIC_CHG_INT_SHIFT)
+
+/* MAX77836 PMIC interrupts */
+#define MAX77836_TOPSYS_INT_T120C_SHIFT 0
+#define MAX77836_TOPSYS_INT_T140C_SHIFT 1
+#define MAX77836_TOPSYS_INT_T120C_MASK BIT(MAX77836_TOPSYS_INT_T120C_SHIFT)
+#define MAX77836_TOPSYS_INT_T140C_MASK BIT(MAX77836_TOPSYS_INT_T140C_SHIFT)
+
+/* Slave addr = 0x6C: Fuel-Gauge/Battery */
+enum max77836_fg_reg {
+ MAX77836_FG_REG_VCELL_MSB = 0x02,
+ MAX77836_FG_REG_VCELL_LSB = 0x03,
+ MAX77836_FG_REG_SOC_MSB = 0x04,
+ MAX77836_FG_REG_SOC_LSB = 0x05,
+ MAX77836_FG_REG_MODE_H = 0x06,
+ MAX77836_FG_REG_MODE_L = 0x07,
+ MAX77836_FG_REG_VERSION_MSB = 0x08,
+ MAX77836_FG_REG_VERSION_LSB = 0x09,
+ MAX77836_FG_REG_HIBRT_H = 0x0A,
+ MAX77836_FG_REG_HIBRT_L = 0x0B,
+ MAX77836_FG_REG_CONFIG_H = 0x0C,
+ MAX77836_FG_REG_CONFIG_L = 0x0D,
+ MAX77836_FG_REG_VALRT_MIN = 0x14,
+ MAX77836_FG_REG_VALRT_MAX = 0x15,
+ MAX77836_FG_REG_CRATE_MSB = 0x16,
+ MAX77836_FG_REG_CRATE_LSB = 0x17,
+ MAX77836_FG_REG_VRESET = 0x18,
+ MAX77836_FG_REG_FGID = 0x19,
+ MAX77836_FG_REG_STATUS_H = 0x1A,
+ MAX77836_FG_REG_STATUS_L = 0x1B,
+ /*
+ * TODO: TABLE registers
+ * TODO: CMD register
+ */
+
+ MAX77836_FG_REG_END,
+};
enum maxim_irq {
/* INT1 */
@@ -251,17 +323,24 @@ enum maxim_irq {
MAXIM_IRQ_INT3_OVP,
MAXIM_IRQ_INT3_MBCCHGERR,
+ /* TOPSYS_INT */
+ MAXIM_IRQ_TOPSYS_T140C,
+ MAXIM_IRQ_TOPSYS_T120C,
+
MAXIM_IRQ_NUM,
};
struct maxim_core {
struct device *dev;
struct i2c_client *i2c; /* Slave addr = 0x4A */
+ struct i2c_client *i2c_pmic; /* Slave addr = 0x46 */
enum maxim_device_type dev_type;
struct regmap *regmap_muic;
+ struct regmap *regmap_pmic;
struct regmap_irq_chip_data *irq_data_muic;
+ struct regmap_irq_chip_data *irq_data_pmic;
int irq;
};
diff --git a/include/linux/mfd/max14577.h b/include/linux/mfd/max14577.h
index 75301be5c548..6aad3f249fdd 100644
--- a/include/linux/mfd/max14577.h
+++ b/include/linux/mfd/max14577.h
@@ -1,7 +1,7 @@
/*
- * max14577.h - Driver for the Maxim 14577
+ * max14577.h - Driver for the Maxim 14577/77836
*
- * Copyright (C) 2013 Samsung Electrnoics
+ * Copyright (C) 2014 Samsung Electrnoics
* Chanwoo Choi <[email protected]>
* Krzysztof Kozlowski <[email protected]>
*
@@ -20,6 +20,9 @@
* MAX14577 has MUIC, Charger devices.
* The devices share the same I2C bus and interrupt line
* included in this mfd driver.
+ *
+ * MAX77836 has additional PMIC and Fuel-Gauge on different I2C slave
+ * addresses.
*/
#ifndef __MAX14577_H__
--
1.7.9.5
This patch prepares for changing the max14577 charger driver to allow
configuring battery-dependent settings from DTS.
The patch moves from regulator driver to MFD core driver and exports:
- function for calculating register value for charger's current;
- table of limits for chargers (MAX14577, MAX77836).
Previously they were used only by the max14577 regulator driver. In next
patch the charger driver will use them as well. Exporting them will
reduce unnecessary code duplication.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Acked-by: Mark Brown <[email protected]>
Acked-by: Lee Jones <[email protected]>
---
drivers/mfd/max14577.c | 95 ++++++++++++++++++++++++++++++++++
drivers/regulator/max14577.c | 80 +++-------------------------
include/linux/mfd/max14577-private.h | 22 ++++----
include/linux/mfd/max14577.h | 23 ++++++++
4 files changed, 135 insertions(+), 85 deletions(-)
diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index 08a2ceff3822..3f5e30e8cf77 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -25,6 +25,87 @@
#include <linux/mfd/max14577.h>
#include <linux/mfd/max14577-private.h>
+/*
+ * Table of valid charger currents for different Maxim chipsets.
+ * It is placed here because it is used by both charger and regulator driver.
+ */
+const struct maxim_charger_current maxim_charger_currents[] = {
+ [MAXIM_DEVICE_TYPE_UNKNOWN] = { 0, 0, 0, 0 },
+ [MAXIM_DEVICE_TYPE_MAX14577] = {
+ .min = MAX14577_CHARGER_CURRENT_LIMIT_MIN,
+ .high_start = MAX14577_CHARGER_CURRENT_LIMIT_HIGH_START,
+ .high_step = MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP,
+ .max = MAX14577_CHARGER_CURRENT_LIMIT_MAX,
+ },
+ [MAXIM_DEVICE_TYPE_MAX77836] = {
+ .min = MAX77836_CHARGER_CURRENT_LIMIT_MIN,
+ .high_start = MAX77836_CHARGER_CURRENT_LIMIT_HIGH_START,
+ .high_step = MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP,
+ .max = MAX77836_CHARGER_CURRENT_LIMIT_MAX,
+ },
+};
+EXPORT_SYMBOL_GPL(maxim_charger_currents);
+
+/*
+ * maxim_charger_calc_reg_current - Calculate register value for current
+ * @limits: constraints for charger, matching the MBCICHWRC register
+ * @min_ua: minimal requested current, micro Amps
+ * @max_ua: maximum requested current, micro Amps
+ * @dst: destination to store calculated register value
+ *
+ * Calculates the value of MBCICHWRC (Fast Battery Charge Current) register
+ * for given current and stores it under pointed 'dst'. The stored value
+ * combines low bit (MBCICHWRCL) and high bits (MBCICHWRCH). It is also
+ * properly shifted.
+ *
+ * The calculated register value matches the current which:
+ * - is always between <limits.min, limits.max>;
+ * - is always less or equal to max_ua;
+ * - is the highest possible value;
+ * - may be lower than min_ua.
+ *
+ * On success returns 0. On error returns -EINVAL (requested min/max current
+ * is outside of given charger limits) and 'dst' is not set.
+ */
+int maxim_charger_calc_reg_current(const struct maxim_charger_current *limits,
+ unsigned int min_ua, unsigned int max_ua, u8 *dst)
+{
+ unsigned int current_bits = 0xf;
+
+ if (min_ua > max_ua)
+ return -EINVAL;
+
+ if (min_ua > limits->max || max_ua < limits->min)
+ return -EINVAL;
+
+ if (max_ua < limits->high_start) {
+ /*
+ * Less than high_start, so set the minimal current
+ * (turn Low Bit off, 0 as high bits).
+ */
+ *dst = 0x0;
+ return 0;
+ }
+
+ /* max_ua is in range: <high_start, infinite>, cut it to limits.max */
+ max_ua = min(limits->max, max_ua);
+ max_ua -= limits->high_start;
+ /*
+ * There is no risk of overflow 'max_ua' here because:
+ * - max_ua >= limits.high_start
+ * - BUILD_BUG checks that 'limits' are: max >= high_start + high_step
+ */
+ current_bits = max_ua / limits->high_step;
+
+ /* Turn Low Bit on (use range <limits.high_start, limits.max>) ... */
+ *dst = 0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
+ /* and set proper High Bits */
+ *dst |= current_bits << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(maxim_charger_calc_reg_current);
+
static struct mfd_cell max14577_devs[] = {
{
.name = "max14577-muic",
@@ -462,6 +543,20 @@ static int __init max14577_i2c_init(void)
BUILD_BUG_ON(ARRAY_SIZE(max14577_i2c_id) != MAXIM_DEVICE_TYPE_NUM);
BUILD_BUG_ON(ARRAY_SIZE(max14577_dt_match) != MAXIM_DEVICE_TYPE_NUM);
+ /* Valid charger current values must be provided for each chipset */
+ BUILD_BUG_ON(ARRAY_SIZE(maxim_charger_currents) != MAXIM_DEVICE_TYPE_NUM);
+
+ /* Check for valid values for charger */
+ BUILD_BUG_ON(MAX14577_CHARGER_CURRENT_LIMIT_HIGH_START +
+ MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP * 0xf !=
+ MAX14577_CHARGER_CURRENT_LIMIT_MAX);
+ BUILD_BUG_ON(MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP == 0);
+
+ BUILD_BUG_ON(MAX77836_CHARGER_CURRENT_LIMIT_HIGH_START +
+ MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP * 0xf !=
+ MAX77836_CHARGER_CURRENT_LIMIT_MAX);
+ BUILD_BUG_ON(MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP == 0);
+
return i2c_add_driver(&max14577_i2c_driver);
}
subsys_initcall(max14577_i2c_init);
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c
index 6bd4cfc11856..6d4433c34df2 100644
--- a/drivers/regulator/max14577.c
+++ b/drivers/regulator/max14577.c
@@ -22,42 +22,6 @@
#include <linux/mfd/max14577-private.h>
#include <linux/regulator/of_regulator.h>
-/*
- * Valid limits of current for max14577 and max77836 chargers.
- * They must correspond to MBCICHWRCL and MBCICHWRCH fields in CHGCTRL4
- * register for given chipset.
- */
-struct maxim_charger_current {
- /* Minimal current, set in CHGCTRL4/MBCICHWRCL, uA */
- unsigned int min;
- /*
- * Minimal current when high setting is active,
- * set in CHGCTRL4/MBCICHWRCH, uA
- */
- unsigned int high_start;
- /* Value of one step in high setting, uA */
- unsigned int high_step;
- /* Maximum current of high setting, uA */
- unsigned int max;
-};
-
-/* Table of valid charger currents for different Maxim chipsets */
-static const struct maxim_charger_current maxim_charger_currents[] = {
- [MAXIM_DEVICE_TYPE_UNKNOWN] = { 0, 0, 0, 0 },
- [MAXIM_DEVICE_TYPE_MAX14577] = {
- .min = MAX14577_REGULATOR_CURRENT_LIMIT_MIN,
- .high_start = MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START,
- .high_step = MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP,
- .max = MAX14577_REGULATOR_CURRENT_LIMIT_MAX,
- },
- [MAXIM_DEVICE_TYPE_MAX77836] = {
- .min = MAX77836_REGULATOR_CURRENT_LIMIT_MIN,
- .high_start = MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START,
- .high_step = MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP,
- .max = MAX77836_REGULATOR_CURRENT_LIMIT_MAX,
- },
-};
-
static int max14577_reg_is_enabled(struct regulator_dev *rdev)
{
int rid = rdev_get_id(rdev);
@@ -103,8 +67,8 @@ static int max14577_reg_get_current_limit(struct regulator_dev *rdev)
static int max14577_reg_set_current_limit(struct regulator_dev *rdev,
int min_uA, int max_uA)
{
- int i, current_bits = 0xf;
u8 reg_data;
+ int ret;
struct maxim_core *maxim_core = rdev_get_drvdata(rdev);
const struct maxim_charger_current *limits =
&maxim_charger_currents[maxim_core->dev_type];
@@ -112,35 +76,13 @@ static int max14577_reg_set_current_limit(struct regulator_dev *rdev,
if (rdev_get_id(rdev) != MAX14577_CHARGER)
return -EINVAL;
- if (min_uA > limits->max || max_uA < limits->min)
- return -EINVAL;
-
- if (max_uA < limits->high_start) {
- /* Less than high_start,
- * so set the minimal current (turn only Low Bit off) */
- u8 reg_data = 0x0 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
- return max14577_update_reg(rdev->regmap,
- MAXIM_CHG_REG_CHGCTRL4,
- MAXIM_CHGCTRL4_MBCICHWRCL_MASK, reg_data);
- }
-
- /* max_uA is in range: <high_start, inifinite>, so search for
- * valid current starting from maximum current. */
- for (i = limits->max; i >= limits->high_start; i -= limits->high_step) {
- if (i <= max_uA)
- break;
- current_bits--;
- }
- BUG_ON(current_bits < 0); /* Cannot happen */
-
- /* Turn Low Bit on (use range high_start-max)... */
- reg_data = 0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
- /* and set proper High Bits */
- reg_data |= current_bits << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT;
+ ret = maxim_charger_calc_reg_current(limits, min_uA, max_uA, ®_data);
+ if (ret)
+ return ret;
return max14577_update_reg(rdev->regmap, MAXIM_CHG_REG_CHGCTRL4,
- MAXIM_CHGCTRL4_MBCICHWRCL_MASK | MAXIM_CHGCTRL4_MBCICHWRCH_MASK,
- reg_data);
+ MAXIM_CHGCTRL4_MBCICHWRCL_MASK | MAXIM_CHGCTRL4_MBCICHWRCH_MASK,
+ reg_data);
}
static struct regulator_ops max14577_safeout_ops = {
@@ -439,16 +381,6 @@ static struct platform_driver max14577_regulator_driver = {
static int __init max14577_regulator_init(void)
{
- /* Check for valid values for charger */
- BUILD_BUG_ON(MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START +
- MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf !=
- MAX14577_REGULATOR_CURRENT_LIMIT_MAX);
- BUILD_BUG_ON(MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START +
- MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf !=
- MAX77836_REGULATOR_CURRENT_LIMIT_MAX);
- /* Valid charger current values must be provided for each chipset */
- BUILD_BUG_ON(ARRAY_SIZE(maxim_charger_currents) != MAXIM_DEVICE_TYPE_NUM);
-
BUILD_BUG_ON(ARRAY_SIZE(max14577_supported_regulators) != MAX14577_REG_NUM);
BUILD_BUG_ON(ARRAY_SIZE(max77836_supported_regulators) != MAX77836_REG_NUM);
diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
index 21c6dd785563..a8cd7de3526a 100644
--- a/include/linux/mfd/max14577-private.h
+++ b/include/linux/mfd/max14577-private.h
@@ -257,17 +257,17 @@ enum maxim_muic_charger_type {
#define MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT 0
#define MAXIM_CHGCTRL7_OTPCGHCVS_MASK (0x3 << MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT)
-/* MAX14577 regulator current limits (as in MAXIM_CHGCTRL4 register), uA */
-#define MAX14577_REGULATOR_CURRENT_LIMIT_MIN 90000
-#define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START 200000
-#define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP 50000
-#define MAX14577_REGULATOR_CURRENT_LIMIT_MAX 950000
-
-/* MAX77836 regulator current limits (as in MAXIM_CHGCTRL4 register), uA */
-#define MAX77836_REGULATOR_CURRENT_LIMIT_MIN 45000
-#define MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START 100000
-#define MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP 25000
-#define MAX77836_REGULATOR_CURRENT_LIMIT_MAX 475000
+/* MAX14577 charger current limits (as in MAXIM_CHGCTRL4 register), uA */
+#define MAX14577_CHARGER_CURRENT_LIMIT_MIN 90000U
+#define MAX14577_CHARGER_CURRENT_LIMIT_HIGH_START 200000U
+#define MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP 50000U
+#define MAX14577_CHARGER_CURRENT_LIMIT_MAX 950000U
+
+/* MAX77836 charger current limits (as in MAXIM_CHGCTRL4 register), uA */
+#define MAX77836_CHARGER_CURRENT_LIMIT_MIN 45000U
+#define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_START 100000U
+#define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP 25000U
+#define MAX77836_CHARGER_CURRENT_LIMIT_MAX 475000U
/* MAX14577 regulator SFOUT LDO voltage, fixed, uV */
#define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000
diff --git a/include/linux/mfd/max14577.h b/include/linux/mfd/max14577.h
index 0070c69481ef..0df2fe329b83 100644
--- a/include/linux/mfd/max14577.h
+++ b/include/linux/mfd/max14577.h
@@ -74,4 +74,27 @@ struct max14577_platform_data {
struct max14577_regulator_platform_data *regulators;
};
+/*
+ * Valid limits of current for max14577 and max77836 chargers.
+ * They must correspond to MBCICHWRCL and MBCICHWRCH fields in CHGCTRL4
+ * register for given chipset.
+ */
+struct maxim_charger_current {
+ /* Minimal current, set in CHGCTRL4/MBCICHWRCL, uA */
+ unsigned int min;
+ /*
+ * Minimal current when high setting is active,
+ * set in CHGCTRL4/MBCICHWRCH, uA
+ */
+ unsigned int high_start;
+ /* Value of one step in high setting, uA */
+ unsigned int high_step;
+ /* Maximum current of high setting, uA */
+ unsigned int max;
+};
+
+extern const struct maxim_charger_current maxim_charger_currents[];
+extern int maxim_charger_calc_reg_current(const struct maxim_charger_current *limits,
+ unsigned int min_ua, unsigned int max_ua, u8 *dst);
+
#endif /* __MAX14577_H__ */
--
1.7.9.5
Add max14577 prefix to muic_irqs array. This prepares for max77836
support in this extcon driver.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Acked-by: Chanwoo Choi <[email protected]>
Tested-by: Chanwoo Choi <[email protected]>
---
drivers/extcon/extcon-max14577.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index fd48b4909470..fb343f4042d2 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -85,7 +85,7 @@ struct max14577_muic_irq {
unsigned int virq;
};
-static struct max14577_muic_irq muic_irqs[] = {
+static struct max14577_muic_irq max14577_muic_irqs[] = {
{ MAXIM_IRQ_INT1_ADC, "muic-ADC" },
{ MAXIM_IRQ_INT1_ADCLOW, "muic-ADCLOW" },
{ MAXIM_IRQ_INT1_ADCERR, "muic-ADCError" },
@@ -541,9 +541,9 @@ static irqreturn_t max14577_muic_irq_handler(int irq, void *data)
* However we only need to know whether it was ADC, charger
* or both interrupts so decode IRQ and turn on proper flags.
*/
- for (i = 0; i < ARRAY_SIZE(muic_irqs); i++)
- if (irq == muic_irqs[i].virq)
- irq_type = muic_irqs[i].irq;
+ for (i = 0; i < ARRAY_SIZE(max14577_muic_irqs); i++)
+ if (irq == max14577_muic_irqs[i].virq)
+ irq_type = max14577_muic_irqs[i].irq;
switch (irq_type) {
case MAXIM_IRQ_INT1_ADC:
@@ -647,8 +647,8 @@ static int max14577_muic_probe(struct platform_device *pdev)
INIT_WORK(&info->irq_work, max14577_muic_irq_work);
/* Support irq domain for max14577 MUIC device */
- for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
- struct max14577_muic_irq *muic_irq = &muic_irqs[i];
+ for (i = 0; i < ARRAY_SIZE(max14577_muic_irqs); i++) {
+ struct max14577_muic_irq *muic_irq = &max14577_muic_irqs[i];
unsigned int virq = 0;
virq = regmap_irq_get_virq(maxim_core->irq_data_muic,
--
1.7.9.5
Remove hard-coded values for:
- Fast Charge current,
- End Of Charge current,
- Fast Charge timer,
- Overvoltage Protection Threshold,
- Battery Constant Voltage,
and use DTS to configure them. This allows using the max14577 charger
driver with different batteries.
Now the charger driver requires valid configuration data from DTS. In
case of wrong configuration data it fails during probe. Patch adds
of_compatible to the charger mfd cell in MFD driver core.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Dmitry Eremin-Solenikov <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Jenny Tc <[email protected]>
---
drivers/mfd/max14577.c | 5 +-
drivers/power/max14577_charger.c | 234 +++++++++++++++++++++++++++++-----
include/linux/mfd/max14577-private.h | 14 ++
include/linux/mfd/max14577.h | 8 ++
4 files changed, 231 insertions(+), 30 deletions(-)
diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index 3f5e30e8cf77..0cd444c4fdd0 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -115,7 +115,10 @@ static struct mfd_cell max14577_devs[] = {
.name = "max14577-regulator",
.of_compatible = "maxim,max14577-regulator",
},
- { .name = "max14577-charger", },
+ {
+ .name = "max14577-charger",
+ .of_compatible = "maxim,max14577-charger",
+ },
};
static struct mfd_cell max77836_devs[] = {
diff --git a/drivers/power/max14577_charger.c b/drivers/power/max14577_charger.c
index 405f4d736337..882331a96298 100644
--- a/drivers/power/max14577_charger.c
+++ b/drivers/power/max14577_charger.c
@@ -19,6 +19,7 @@
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/mfd/max14577-private.h>
+#include <linux/mfd/max14577.h>
struct max14577_charger {
struct device *dev;
@@ -27,6 +28,8 @@ struct max14577_charger {
unsigned int charging_state;
unsigned int battery_state;
+
+ struct max14577_charger_platform_data *pdata;
};
/*
@@ -180,15 +183,106 @@ static int max14577_get_present(struct max14577_charger *chg)
return 1;
}
+static inline int max14577_init_constant_voltage(struct max14577_charger *chg,
+ unsigned int uvolt)
+{
+ u8 reg_data;
+
+ if (uvolt < MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN ||
+ uvolt > MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX)
+ return -EINVAL;
+
+ if (uvolt == 4200000)
+ reg_data = 0x0;
+ else if (uvolt == MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX)
+ reg_data = 0x1f;
+ else if (uvolt <= 4280000) {
+ unsigned int val = uvolt;
+
+ val -= MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN;
+ val /= MAXIM_CHARGER_CONSTANT_VOLTAGE_STEP;
+ if (uvolt <= 4180000)
+ reg_data = 0x1 + val;
+ else
+ reg_data = val; /* Fix for gap between 4.18V and 4.22V */
+ } else
+ return -EINVAL;
+
+ reg_data <<= MAXIM_CHGCTRL3_MBCCVWRC_SHIFT;
+
+ return max14577_write_reg(chg->maxim_core->regmap_muic,
+ MAXIM_CHG_REG_CHGCTRL3, reg_data);
+}
+
+static inline int max14577_init_eoc(struct max14577_charger *chg,
+ unsigned int uamp)
+{
+ unsigned int current_bits = 0xf;
+ u8 reg_data;
+
+ switch (chg->maxim_core->dev_type) {
+ case MAXIM_DEVICE_TYPE_MAX77836:
+ if (uamp < 5000)
+ return -EINVAL; /* Requested current is too low */
+
+ if (uamp == 7500)
+ current_bits = 0x0;
+ else if (uamp <= 50000) {
+ current_bits = uamp / 5000;
+ } else {
+ uamp = min(uamp, 100000U) - 50000U;
+ current_bits = 0xa + uamp / 10000;
+ }
+ break;
+
+ case MAXIM_DEVICE_TYPE_MAX14577:
+ default:
+ if (uamp < MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN)
+ return -EINVAL; /* Requested current is too low */
+
+ uamp = min(uamp, MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX);
+ uamp -= MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN;
+ current_bits = uamp / MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP;
+ break;
+ }
+
+ reg_data = current_bits << MAXIM_CHGCTRL5_EOCS_SHIFT;
+
+ return max14577_update_reg(chg->maxim_core->regmap_muic,
+ MAXIM_CHG_REG_CHGCTRL5, MAXIM_CHGCTRL5_EOCS_MASK,
+ reg_data);
+}
+
+static inline int max14577_init_fast_charge(struct max14577_charger *chg,
+ unsigned int uamp)
+{
+ u8 reg_data;
+ int ret;
+ const struct maxim_charger_current *limits =
+ &maxim_charger_currents[chg->maxim_core->dev_type];
+
+ ret = maxim_charger_calc_reg_current(limits, uamp, uamp, ®_data);
+ if (ret) {
+ dev_err(chg->dev, "Wrong value for fast charge: %u\n", uamp);
+ return ret;
+ }
+
+ return max14577_update_reg(chg->maxim_core->regmap_muic,
+ MAXIM_CHG_REG_CHGCTRL4,
+ MAXIM_CHGCTRL4_MBCICHWRCL_MASK | MAXIM_CHGCTRL4_MBCICHWRCH_MASK,
+ reg_data);
+}
+
/*
* Sets charger registers to proper and safe default values.
* Some of these values are equal to defaults in MAX14577E
* data sheet but there are minor differences.
*/
-static void max14577_charger_reg_init(struct max14577_charger *chg)
+static int max14577_charger_reg_init(struct max14577_charger *chg)
{
struct regmap *rmap = chg->maxim_core->regmap_muic;
u8 reg_data;
+ int ret;
/*
* Charger-Type Manual Detection, default off (set CHGTYPMAN to 0)
@@ -198,12 +292,7 @@ static void max14577_charger_reg_init(struct max14577_charger *chg)
reg_data = 0x1 << MAXIM_CDETCTRL1_CHGDETEN_SHIFT;
max14577_update_reg(rmap, MAXIM_MUIC_REG_CDETCTRL1,
MAXIM_CDETCTRL1_CHGDETEN_MASK |
- MAXIM_CDETCTRL1_CHGTYPMAN_MASK,
- reg_data);
-
- /* Battery Fast-Charge Timer, set to: 6hrs */
- reg_data = 0x3 << MAXIM_CHGCTRL1_TCHW_SHIFT;
- max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL1, reg_data);
+ MAXIM_CDETCTRL1_CHGTYPMAN_MASK, reg_data);
/*
* Wall-Adapter Rapid Charge, default on
@@ -213,32 +302,57 @@ static void max14577_charger_reg_init(struct max14577_charger *chg)
reg_data |= 0x1 << MAXIM_CHGCTRL2_MBCHOSTEN_SHIFT;
max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL2, reg_data);
- /* Battery-Charger Constant Voltage (CV) Mode, set to: 4.35V */
- reg_data = 0xf << MAXIM_CHGCTRL3_MBCCVWRC_SHIFT;
- max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL3, reg_data);
-
- /*
- * Fast Battery-Charge Current Low,
- * default 200-950mA (max14577) / 100-475mA (max77836)
- *
- * Fast Battery-Charge Current High,
- * set to 450mA (max14577) / 225mA (max77836)
- */
- reg_data = 0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
- reg_data |= 0x5 << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT;
- max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL4, reg_data);
-
- /* End-of-Charge Current, set to 50mA (max14577) / 7.5mA (max77836) */
- reg_data = 0x0 << MAXIM_CHGCTRL5_EOCS_SHIFT;
- max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL5, reg_data);
-
/* Auto Charging Stop, default off */
reg_data = 0x0 << MAXIM_CHGCTRL6_AUTOSTOP_SHIFT;
max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL6, reg_data);
- /* Overvoltage-Protection Threshold, set to 6.5V */
- reg_data = 0x2 << MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT;
+ ret = max14577_init_constant_voltage(chg, chg->pdata->constant_uvolt);
+ if (ret)
+ return ret;
+
+ ret = max14577_init_eoc(chg, chg->pdata->eoc_uamp);
+ if (ret)
+ return ret;
+
+ ret = max14577_init_fast_charge(chg, chg->pdata->fast_charge_uamp);
+ if (ret)
+ return ret;
+
+ /* Initialize Battery Fast-Charge Timer */
+ switch (chg->pdata->fast_charge_timer) {
+ case 5 ... 7:
+ reg_data = chg->pdata->fast_charge_timer - 3;
+ break;
+ case 0:
+ /* Disable */
+ reg_data = 0x7;
+ default:
+ dev_err(chg->dev, "Wrong value for Fast-Charge Timer: %u\n",
+ chg->pdata->fast_charge_timer);
+ return -EINVAL;
+ }
+ reg_data <<= MAXIM_CHGCTRL1_TCHW_SHIFT;
+ max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL1, reg_data);
+
+ /* Initialize Overvoltage-Protection Threshold */
+ switch (chg->pdata->ovp_uvolt) {
+ case 7500000:
+ reg_data = 0x0;
+ break;
+ case 6000000:
+ case 6500000:
+ case 7000000:
+ reg_data = 0x1 + (chg->pdata->ovp_uvolt - 6000000) / 500000;
+ break;
+ default:
+ dev_err(chg->dev, "Wrong value for OVP: %u\n",
+ chg->pdata->ovp_uvolt);
+ return -EINVAL;
+ }
+ reg_data <<= MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT;
max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL7, reg_data);
+
+ return 0;
}
/* Support property from charger */
@@ -298,6 +412,58 @@ static int max14577_charger_get_property(struct power_supply *psy,
return ret;
}
+#ifdef CONFIG_OF
+static struct max14577_charger_platform_data *max14577_charger_dt_init(
+ struct platform_device *pdev)
+{
+ struct max14577_charger_platform_data *pdata;
+ struct device_node *np = pdev->dev.of_node;
+ int ret;
+
+ if (!np) {
+ dev_err(&pdev->dev, "No charger OF node\n");
+ return ERR_PTR(-EINVAL);
+ }
+
+ pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata) {
+ dev_err(&pdev->dev, "Memory alloc for charger pdata failed\n");
+ return ERR_PTR(-ENOMEM);
+ }
+
+ ret = of_property_read_u32(np, "maxim,fast-charge-timer",
+ &pdata->fast_charge_timer);
+ if (ret)
+ return ERR_PTR(ret);
+
+ ret = of_property_read_u32(np, "maxim,constant-uvolt",
+ &pdata->constant_uvolt);
+ if (ret)
+ return ERR_PTR(ret);
+
+ ret = of_property_read_u32(np, "maxim,fast-charge-uamp",
+ &pdata->fast_charge_uamp);
+ if (ret)
+ return ERR_PTR(ret);
+
+ ret = of_property_read_u32(np, "maxim,eoc-uamp", &pdata->eoc_uamp);
+ if (ret)
+ return ERR_PTR(ret);
+
+ ret = of_property_read_u32(np, "maxim,ovp-uvolt", &pdata->ovp_uvolt);
+ if (ret)
+ return ERR_PTR(ret);
+
+ return pdata;
+}
+#else /* CONFIG_OF */
+static struct max14577_charger_platform_data *max14577_charger_dt_init(
+ struct platform_device *pdev)
+{
+ return NULL;
+}
+#endif /* CONFIG_OF */
+
static int max14577_charger_probe(struct platform_device *pdev)
{
struct max14577_charger *chg;
@@ -312,7 +478,13 @@ static int max14577_charger_probe(struct platform_device *pdev)
chg->dev = &pdev->dev;
chg->maxim_core = maxim_core;
- max14577_charger_reg_init(chg);
+ chg->pdata = max14577_charger_dt_init(pdev);
+ if (IS_ERR_OR_NULL(chg->pdata))
+ return PTR_ERR(chg->pdata);
+
+ ret = max14577_charger_reg_init(chg);
+ if (ret)
+ return ret;
chg->charger.name = "max14577-charger",
chg->charger.type = POWER_SUPPLY_TYPE_BATTERY,
@@ -326,6 +498,10 @@ static int max14577_charger_probe(struct platform_device *pdev)
return ret;
}
+ /* Check for valid values for charger */
+ BUILD_BUG_ON(MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN +
+ MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP * 0xf !=
+ MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX);
return 0;
}
diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
index a8cd7de3526a..fc69d7beb1aa 100644
--- a/include/linux/mfd/max14577-private.h
+++ b/include/linux/mfd/max14577-private.h
@@ -269,6 +269,20 @@ enum maxim_muic_charger_type {
#define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP 25000U
#define MAX77836_CHARGER_CURRENT_LIMIT_MAX 475000U
+/* MAX14577 charger End-Of-Charge current limits
+ * (as in MAXIM_CHGCTRL5 register), uA
+ */
+#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN 50000U
+#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP 10000U
+#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX 200000U
+
+/* MAX14577/MAX77836 Battery Constant Voltage
+ * (as in MAXIM_CHGCTRL3 register), uV
+ */
+#define MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN 4000000U
+#define MAXIM_CHARGER_CONSTANT_VOLTAGE_STEP 20000U
+#define MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX 4350000U
+
/* MAX14577 regulator SFOUT LDO voltage, fixed, uV */
#define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000
diff --git a/include/linux/mfd/max14577.h b/include/linux/mfd/max14577.h
index 0df2fe329b83..b60febd6c53f 100644
--- a/include/linux/mfd/max14577.h
+++ b/include/linux/mfd/max14577.h
@@ -54,6 +54,14 @@ struct max14577_regulator_platform_data {
struct device_node *of_node;
};
+struct max14577_charger_platform_data {
+ unsigned int fast_charge_timer;
+ unsigned int constant_uvolt;
+ unsigned int fast_charge_uamp;
+ unsigned int eoc_uamp;
+ unsigned int ovp_uvolt;
+};
+
/*
* MAX14577 MFD platform data
*/
--
1.7.9.5
Add support for MAX77836 charger to the max14577 driver. The MAX77836
charger is almost the same as 14577 model except:
- No dead-battery detection;
- Support for special charger (like in max77693);
- Support for DX over-voltage protection (like in max77693);
- Lower values of charging current (two times lower current for
slow/fast charge, much lower EOC current);
- Slightly different values in ChgTyp field of STATUS2 register. On
MAX14577 0x6 is reserved and 0x7 dead battery. On the MAX77836 the
0x6 means special charger and 0x7 is reserved. Regardless of these
differences the driver maps them to one enum maxim_muic_charger_type.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Anton Vorontsov <[email protected]>
Cc: Dmitry Eremin-Solenikov <[email protected]>
Cc: David Woodhouse <[email protected]>
Acked-by: Lee Jones <[email protected]>
---
drivers/extcon/extcon-max14577.c | 2 +-
drivers/power/max14577_charger.c | 81 +++++++++++++++++++++++++++-------
include/linux/mfd/max14577-private.h | 57 +++++++++++++++++-------
3 files changed, 106 insertions(+), 34 deletions(-)
diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index 82ac6b0fb1bc..182af5216a2f 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -498,7 +498,7 @@ static int max14577_muic_chg_handler(struct max14577_muic_info *info)
extcon_set_cable_state(info->edev, "Fast-charger", attached);
break;
case MAXIM_CHARGER_TYPE_NONE:
- case MAXIM_CHARGER_TYPE_DEAD_BATTERY:
+ case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
break;
default:
dev_err(info->dev,
diff --git a/drivers/power/max14577_charger.c b/drivers/power/max14577_charger.c
index 58cddc3b15d6..405f4d736337 100644
--- a/drivers/power/max14577_charger.c
+++ b/drivers/power/max14577_charger.c
@@ -1,7 +1,7 @@
/*
- * Battery charger driver for the Maxim 14577
+ * max14577_charger.c - Battery charger driver for the Maxim 14577/77836
*
- * Copyright (C) 2013 Samsung Electronics
+ * Copyright (C) 2013,2014 Samsung Electronics
* Krzysztof Kozlowski <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
@@ -25,10 +25,35 @@ struct max14577_charger {
struct maxim_core *maxim_core;
struct power_supply charger;
- unsigned int charging_state;
- unsigned int battery_state;
+ unsigned int charging_state;
+ unsigned int battery_state;
};
+/*
+ * Helper function for mapping values of STATUS2/CHGTYP register on max14577
+ * and max77836 chipsets to enum maxim_muic_charger_type.
+ */
+static enum maxim_muic_charger_type maxim_get_charger_type(
+ enum maxim_device_type dev_type, u8 val) {
+ switch (val) {
+ case MAXIM_CHARGER_TYPE_NONE:
+ case MAXIM_CHARGER_TYPE_USB:
+ case MAXIM_CHARGER_TYPE_DOWNSTREAM_PORT:
+ case MAXIM_CHARGER_TYPE_DEDICATED_CHG:
+ case MAXIM_CHARGER_TYPE_SPECIAL_500MA:
+ case MAXIM_CHARGER_TYPE_SPECIAL_1A:
+ return val;
+ case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
+ case MAX14577_CHARGER_TYPE_RESERVED:
+ if (dev_type == MAXIM_DEVICE_TYPE_MAX77836)
+ val |= 0x8;
+ return val;
+ default:
+ WARN_ONCE(1, "max14577: Unsupported chgtyp register value 0x%02x", val);
+ return val;
+ }
+}
+
static int max14577_get_charger_state(struct max14577_charger *chg)
{
struct regmap *rmap = chg->maxim_core->regmap_muic;
@@ -89,20 +114,24 @@ static int max14577_get_online(struct max14577_charger *chg)
{
struct regmap *rmap = chg->maxim_core->regmap_muic;
u8 reg_data;
+ enum maxim_muic_charger_type chg_type;
max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS2, ®_data);
reg_data = reg_data & MAXIM_STATUS2_CHGTYP_MASK;
reg_data >>= MAXIM_STATUS2_CHGTYP_SHIFT;
- switch (reg_data) {
+ chg_type = maxim_get_charger_type(chg->maxim_core->dev_type, reg_data);
+ switch (chg_type) {
case MAXIM_CHARGER_TYPE_USB:
case MAXIM_CHARGER_TYPE_DEDICATED_CHG:
case MAXIM_CHARGER_TYPE_SPECIAL_500MA:
case MAXIM_CHARGER_TYPE_SPECIAL_1A:
- case MAXIM_CHARGER_TYPE_DEAD_BATTERY:
+ case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
+ case MAX77836_CHARGER_TYPE_SPECIAL_BIAS:
return 1;
case MAXIM_CHARGER_TYPE_NONE:
case MAXIM_CHARGER_TYPE_DOWNSTREAM_PORT:
- case MAXIM_CHARGER_TYPE_RESERVED:
+ case MAX14577_CHARGER_TYPE_RESERVED:
+ case MAX77836_CHARGER_TYPE_RESERVED:
default:
return 0;
}
@@ -119,11 +148,13 @@ static int max14577_get_battery_health(struct max14577_charger *chg)
struct regmap *rmap = chg->maxim_core->regmap_muic;
int state = POWER_SUPPLY_HEALTH_GOOD;
u8 reg_data;
+ enum maxim_muic_charger_type chg_type;
max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS2, ®_data);
reg_data = reg_data & MAXIM_STATUS2_CHGTYP_MASK;
reg_data >>= MAXIM_STATUS2_CHGTYP_SHIFT;
- if (reg_data == MAXIM_CHARGER_TYPE_DEAD_BATTERY) {
+ chg_type = maxim_get_charger_type(chg->maxim_core->dev_type, reg_data);
+ if (chg_type == MAX14577_CHARGER_TYPE_DEAD_BATTERY) {
state = POWER_SUPPLY_HEALTH_DEAD;
goto state_set;
}
@@ -170,7 +201,7 @@ static void max14577_charger_reg_init(struct max14577_charger *chg)
MAXIM_CDETCTRL1_CHGTYPMAN_MASK,
reg_data);
- /* Battery Fast-Charge Timer, from SM-V700: 6hrs */
+ /* Battery Fast-Charge Timer, set to: 6hrs */
reg_data = 0x3 << MAXIM_CHGCTRL1_TCHW_SHIFT;
max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL1, reg_data);
@@ -182,19 +213,22 @@ static void max14577_charger_reg_init(struct max14577_charger *chg)
reg_data |= 0x1 << MAXIM_CHGCTRL2_MBCHOSTEN_SHIFT;
max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL2, reg_data);
- /* Battery-Charger Constant Voltage (CV) Mode, from SM-V700: 4.35V */
+ /* Battery-Charger Constant Voltage (CV) Mode, set to: 4.35V */
reg_data = 0xf << MAXIM_CHGCTRL3_MBCCVWRC_SHIFT;
max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL3, reg_data);
/*
- * Fast Battery-Charge Current Low, default 200-950mA
- * Fast Battery-Charge Current High, from SM-V700: 450mA
+ * Fast Battery-Charge Current Low,
+ * default 200-950mA (max14577) / 100-475mA (max77836)
+ *
+ * Fast Battery-Charge Current High,
+ * set to 450mA (max14577) / 225mA (max77836)
*/
reg_data = 0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
reg_data |= 0x5 << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT;
max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL4, reg_data);
- /* End-of-Charge Current, from SM-V700: 50mA */
+ /* End-of-Charge Current, set to 50mA (max14577) / 7.5mA (max77836) */
reg_data = 0x0 << MAXIM_CHGCTRL5_EOCS_SHIFT;
max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL5, reg_data);
@@ -202,7 +236,7 @@ static void max14577_charger_reg_init(struct max14577_charger *chg)
reg_data = 0x0 << MAXIM_CHGCTRL6_AUTOSTOP_SHIFT;
max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL6, reg_data);
- /* Overvoltage-Protection Threshold, from SM-V700: 6.5V */
+ /* Overvoltage-Protection Threshold, set to 6.5V */
reg_data = 0x2 << MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT;
max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL7, reg_data);
}
@@ -218,7 +252,11 @@ static enum power_supply_property max14577_charger_props[] = {
POWER_SUPPLY_PROP_MANUFACTURER,
};
-static const char *model_name = "MAX14577";
+static const char * const model_names[] = {
+ [MAXIM_DEVICE_TYPE_UNKNOWN] = "MAX14577-like",
+ [MAXIM_DEVICE_TYPE_MAX14577] = "MAX14577",
+ [MAXIM_DEVICE_TYPE_MAX77836] = "MAX77836",
+};
static const char *manufacturer = "Maxim Integrated";
static int max14577_charger_get_property(struct power_supply *psy,
@@ -247,7 +285,8 @@ static int max14577_charger_get_property(struct power_supply *psy,
val->intval = max14577_get_online(chg);
break;
case POWER_SUPPLY_PROP_MODEL_NAME:
- val->strval = model_name;
+ BUILD_BUG_ON(ARRAY_SIZE(model_names) != MAXIM_DEVICE_TYPE_NUM);
+ val->strval = model_names[chg->maxim_core->dev_type];
break;
case POWER_SUPPLY_PROP_MANUFACTURER:
val->strval = manufacturer;
@@ -299,6 +338,13 @@ static int max14577_charger_remove(struct platform_device *pdev)
return 0;
}
+static const struct platform_device_id max14577_charger_id[] = {
+ { "max14577-charger", MAXIM_DEVICE_TYPE_MAX14577, },
+ { "max77836-charger", MAXIM_DEVICE_TYPE_MAX77836, },
+ { }
+};
+MODULE_DEVICE_TABLE(platform, max14577_regulator_id);
+
static struct platform_driver max14577_charger_driver = {
.driver = {
.owner = THIS_MODULE,
@@ -306,9 +352,10 @@ static struct platform_driver max14577_charger_driver = {
},
.probe = max14577_charger_probe,
.remove = max14577_charger_remove,
+ .id_table = max14577_charger_id,
};
module_platform_driver(max14577_charger_driver);
MODULE_AUTHOR("Krzysztof Kozlowski <[email protected]>");
-MODULE_DESCRIPTION("MAXIM 14577 charger driver");
+MODULE_DESCRIPTION("Maxim 14577/77836 charger driver");
MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
index 3da322dc7d25..21c6dd785563 100644
--- a/include/linux/mfd/max14577-private.h
+++ b/include/linux/mfd/max14577-private.h
@@ -62,15 +62,32 @@ enum maxim_muic_reg {
MAXIM_MUIC_REG_END,
};
+/*
+ * Combined charger types for max14577 and max77836.
+ *
+ * On max14577 three lower bits map to STATUS2/CHGTYP field.
+ * On max77836 two values of this field are bitwise OR-ed with 0x8 to indicate
+ * the difference.
+ */
enum maxim_muic_charger_type {
- MAXIM_CHARGER_TYPE_NONE = 0,
- MAXIM_CHARGER_TYPE_USB,
- MAXIM_CHARGER_TYPE_DOWNSTREAM_PORT,
- MAXIM_CHARGER_TYPE_DEDICATED_CHG,
- MAXIM_CHARGER_TYPE_SPECIAL_500MA,
- MAXIM_CHARGER_TYPE_SPECIAL_1A,
- MAXIM_CHARGER_TYPE_RESERVED,
- MAXIM_CHARGER_TYPE_DEAD_BATTERY = 7,
+ MAXIM_CHARGER_TYPE_NONE = 0x0,
+ MAXIM_CHARGER_TYPE_USB = 0x1,
+ MAXIM_CHARGER_TYPE_DOWNSTREAM_PORT = 0x2,
+ MAXIM_CHARGER_TYPE_DEDICATED_CHG = 0x3,
+ MAXIM_CHARGER_TYPE_SPECIAL_500MA = 0x4,
+ /* Special 1A or 2A charger */
+ MAXIM_CHARGER_TYPE_SPECIAL_1A = 0x5,
+ /* max14577: reserved, used on max77836 */
+ MAX14577_CHARGER_TYPE_RESERVED = 0x6,
+ /* max14577: dead-battery charing with maximum current 100mA */
+ MAX14577_CHARGER_TYPE_DEAD_BATTERY = 0x7,
+ /*
+ * max77836: special charger (bias on D+/D-),
+ * register value 0x6 | 0x8 (4th bit set)
+ */
+ MAX77836_CHARGER_TYPE_SPECIAL_BIAS = 0xe,
+ /* max77836: reserved, register value 0x7 | 0x8 (4th bit set) */
+ MAX77836_CHARGER_TYPE_RESERVED = 0xf,
};
/* MAX14577 interrupts */
@@ -111,13 +128,15 @@ enum maxim_muic_charger_type {
#define MAXIM_STATUS2_CHGTYP_SHIFT 0
#define MAXIM_STATUS2_CHGDETRUN_SHIFT 3
#define MAXIM_STATUS2_DCDTMR_SHIFT 4
-#define MAXIM_STATUS2_DBCHG_SHIFT 5
+#define MAX14577_STATUS2_DBCHG_SHIFT 5
+#define MAX77836_STATUS2_DXOVP_SHIFT 5
#define MAXIM_STATUS2_VBVOLT_SHIFT 6
#define MAX77836_STATUS2_VIDRM_SHIFT 7
#define MAXIM_STATUS2_CHGTYP_MASK (0x7 << MAXIM_STATUS2_CHGTYP_SHIFT)
#define MAXIM_STATUS2_CHGDETRUN_MASK BIT(MAXIM_STATUS2_CHGDETRUN_SHIFT)
#define MAXIM_STATUS2_DCDTMR_MASK BIT(MAXIM_STATUS2_DCDTMR_SHIFT)
-#define MAXIM_STATUS2_DBCHG_MASK BIT(MAXIM_STATUS2_DBCHG_SHIFT)
+#define MAX14577_STATUS2_DBCHG_MASK BIT(MAX14577_STATUS2_DBCHG_SHIFT)
+#define MAX77836_STATUS2_DXOVP_MASK BIT(MAX77836_STATUS2_DXOVP_SHIFT)
#define MAXIM_STATUS2_VBVOLT_MASK BIT(MAXIM_STATUS2_VBVOLT_SHIFT)
#define MAX77836_STATUS2_VIDRM_MASK BIT(MAX77836_STATUS2_VIDRM_SHIFT)
@@ -178,26 +197,32 @@ enum maxim_muic_charger_type {
#define MAXIM_CONTROL3_JIGSET_SHIFT 0
#define MAXIM_CONTROL3_BOOTSET_SHIFT 2
#define MAXIM_CONTROL3_ADCDBSET_SHIFT 4
+#define MAX14577_CONTROL3_WBTH_SHIFT 6
#define MAXIM_CONTROL3_JIGSET_MASK (0x3 << MAXIM_CONTROL3_JIGSET_SHIFT)
#define MAXIM_CONTROL3_BOOTSET_MASK (0x3 << MAXIM_CONTROL3_BOOTSET_SHIFT)
#define MAXIM_CONTROL3_ADCDBSET_MASK (0x3 << MAXIM_CONTROL3_ADCDBSET_SHIFT)
+#define MAX14577_CONTROL3_WBTH_MASK (0x3 << MAX14577_CONTROL3_WBTH_SHIFT)
/* MAX14577 CDETCTRL1 register */
#define MAXIM_CDETCTRL1_CHGDETEN_SHIFT 0
#define MAXIM_CDETCTRL1_CHGTYPMAN_SHIFT 1
#define MAXIM_CDETCTRL1_DCDEN_SHIFT 2
#define MAXIM_CDETCTRL1_DCD2SCT_SHIFT 3
-#define MAXIM_CDETCTRL1_DCHKTM_SHIFT 4
-#define MAXIM_CDETCTRL1_DBEXIT_SHIFT 5
-#define MAXIM_CDETCTRL1_DBIDLE_SHIFT 6
+#define MAX14577_CDETCTRL1_DCHKTM_SHIFT 4
+#define MAX77836_CDETCTRL1_CDLY_SHIFT 4
+#define MAX14577_CDETCTRL1_DBEXIT_SHIFT 5
+#define MAX77836_CDETCTRL1_DCDCPL_SHIFT 5
+#define MAX14577_CDETCTRL1_DBIDLE_SHIFT 6
#define MAXIM_CDETCTRL1_CDPDET_SHIFT 7
#define MAXIM_CDETCTRL1_CHGDETEN_MASK BIT(MAXIM_CDETCTRL1_CHGDETEN_SHIFT)
#define MAXIM_CDETCTRL1_CHGTYPMAN_MASK BIT(MAXIM_CDETCTRL1_CHGTYPMAN_SHIFT)
#define MAXIM_CDETCTRL1_DCDEN_MASK BIT(MAXIM_CDETCTRL1_DCDEN_SHIFT)
#define MAXIM_CDETCTRL1_DCD2SCT_MASK BIT(MAXIM_CDETCTRL1_DCD2SCT_SHIFT)
-#define MAXIM_CDETCTRL1_DCHKTM_MASK BIT(MAXIM_CDETCTRL1_DCHKTM_SHIFT)
-#define MAXIM_CDETCTRL1_DBEXIT_MASK BIT(MAXIM_CDETCTRL1_DBEXIT_SHIFT)
-#define MAXIM_CDETCTRL1_DBIDLE_MASK BIT(MAXIM_CDETCTRL1_DBIDLE_SHIFT)
+#define MAX14577_CDETCTRL1_DCHKTM_MASK BIT(MAX14577_CDETCTRL1_DCHKTM_SHIFT)
+#define MAX77836_CDETCTRL1_CDDLY_MASK BIT(MAX77836_CDETCTRL1_CDDLY_SHIFT)
+#define MAX14577_CDETCTRL1_DBEXIT_MASK BIT(MAX14577_CDETCTRL1_DBEXIT_SHIFT)
+#define MAX77836_CDETCTRL1_DCDCPL_MASK BIT(MAX77836_CDETCTRL1_DCDCPL_SHIFT)
+#define MAX14577_CDETCTRL1_DBIDLE_MASK BIT(MAX14577_CDETCTRL1_DBIDLE_SHIFT)
#define MAXIM_CDETCTRL1_CDPDET_MASK BIT(MAXIM_CDETCTRL1_CDPDET_SHIFT)
/* MAX14577 MAXIM_CHGCTRL1 register */
--
1.7.9.5
This patch continues the preparation for adding support for max77836
device to existing max14577 driver.
Add "muic" suffix to regmap and irq_data fields in maxim_core state
container to prepare for max77836 support.
This is only a rename-like patch, new code is not added.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Anton Vorontsov <[email protected]>
Cc: Dmitry Eremin-Solenikov <[email protected]>
Cc: David Woodhouse <[email protected]>
Acked-by: Lee Jones <[email protected]>
Acked-by: Chanwoo Choi <[email protected]>
Tested-by: Chanwoo Choi <[email protected]>
---
drivers/extcon/extcon-max14577.c | 17 +++++++++--------
drivers/mfd/max14577.c | 22 +++++++++++-----------
drivers/power/max14577_charger.c | 8 ++++----
drivers/regulator/max14577.c | 2 +-
include/linux/mfd/max14577-private.h | 4 ++--
5 files changed, 27 insertions(+), 26 deletions(-)
diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index 2879cc5844dc..fd48b4909470 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -176,7 +176,7 @@ static int max14577_muic_set_debounce_time(struct max14577_muic_info *info,
case ADC_DEBOUNCE_TIME_10MS:
case ADC_DEBOUNCE_TIME_25MS:
case ADC_DEBOUNCE_TIME_38_62MS:
- ret = max14577_update_reg(info->maxim_core->regmap,
+ ret = max14577_update_reg(info->maxim_core->regmap_muic,
MAXIM_MUIC_REG_CONTROL3,
MAXIM_CONTROL3_ADCDBSET_MASK,
time << MAXIM_CONTROL3_ADCDBSET_SHIFT);
@@ -210,7 +210,7 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
u8 ctrl1, ctrl2 = 0;
/* Set open state to path before changing hw path */
- ret = max14577_update_reg(info->maxim_core->regmap,
+ ret = max14577_update_reg(info->maxim_core->regmap_muic,
MAXIM_MUIC_REG_CONTROL1,
MAXIM_CONTROL1_CLEAR_IDBEN_MICEN_MASK,
MAXIM_CONTROL1_SW_OPEN);
@@ -224,7 +224,7 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
else
ctrl1 = MAXIM_CONTROL1_SW_OPEN;
- ret = max14577_update_reg(info->maxim_core->regmap,
+ ret = max14577_update_reg(info->maxim_core->regmap_muic,
MAXIM_MUIC_REG_CONTROL1,
MAXIM_CONTROL1_CLEAR_IDBEN_MICEN_MASK, ctrl1);
if (ret < 0) {
@@ -237,7 +237,7 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
else
ctrl2 |= MAXIM_CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */
- ret = max14577_update_reg(info->maxim_core->regmap,
+ ret = max14577_update_reg(info->maxim_core->regmap_muic,
MAXIM_MUIC_REG_CONTROL2,
MAXIM_CONTROL2_LOWPWR_MASK | MAXIM_CONTROL2_CPEN_MASK,
ctrl2);
@@ -505,7 +505,7 @@ static void max14577_muic_irq_work(struct work_struct *work)
mutex_lock(&info->mutex);
- ret = max14577_bulk_read(info->maxim_core->regmap,
+ ret = max14577_bulk_read(info->maxim_core->regmap_muic,
MAXIM_MUIC_REG_STATUS1, info->status, 2);
if (ret) {
dev_err(info->dev, "failed to read MUIC register\n");
@@ -581,7 +581,7 @@ static int max14577_muic_detect_accessory(struct max14577_muic_info *info)
mutex_lock(&info->mutex);
/* Read STATUSx register to detect accessory */
- ret = max14577_bulk_read(info->maxim_core->regmap,
+ ret = max14577_bulk_read(info->maxim_core->regmap_muic,
MAXIM_MUIC_REG_STATUS1, info->status, 2);
if (ret) {
dev_err(info->dev, "failed to read MUIC register\n");
@@ -651,7 +651,8 @@ static int max14577_muic_probe(struct platform_device *pdev)
struct max14577_muic_irq *muic_irq = &muic_irqs[i];
unsigned int virq = 0;
- virq = regmap_irq_get_virq(maxim_core->irq_data, muic_irq->irq);
+ virq = regmap_irq_get_virq(maxim_core->irq_data_muic,
+ muic_irq->irq);
if (!virq)
return -EINVAL;
muic_irq->virq = virq;
@@ -693,7 +694,7 @@ static int max14577_muic_probe(struct platform_device *pdev)
max14577_muic_set_path(info, info->path_uart, true);
/* Check revision number of MUIC device*/
- ret = max14577_read_reg(info->maxim_core->regmap,
+ ret = max14577_read_reg(info->maxim_core->regmap_muic,
MAXIM_MUIC_REG_DEVICEID, &id);
if (ret < 0) {
dev_err(&pdev->dev, "failed to read revision number\n");
diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index 4567728f3fd4..449e025bd80d 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -112,17 +112,17 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
maxim_core->i2c = i2c;
maxim_core->irq = i2c->irq;
- maxim_core->regmap = devm_regmap_init_i2c(i2c,
- &max14577_muic_regmap_config);
- if (IS_ERR(maxim_core->regmap)) {
- ret = PTR_ERR(maxim_core->regmap);
+ maxim_core->regmap_muic = devm_regmap_init_i2c(i2c,
+ &max14577_muic_regmap_config);
+ if (IS_ERR(maxim_core->regmap_muic)) {
+ ret = PTR_ERR(maxim_core->regmap_muic);
dev_err(maxim_core->dev, "Failed to allocate register map: %d\n",
ret);
return ret;
}
- ret = max14577_read_reg(maxim_core->regmap, MAXIM_MUIC_REG_DEVICEID,
- ®_data);
+ ret = max14577_read_reg(maxim_core->regmap_muic,
+ MAXIM_MUIC_REG_DEVICEID, ®_data);
if (ret) {
dev_err(maxim_core->dev, "Device not found on this channel: %d\n",
ret);
@@ -135,10 +135,10 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
dev_info(maxim_core->dev, "Device ID: 0x%x, vendor: 0x%x\n",
maxim_core->device_id, maxim_core->vendor_id);
- ret = regmap_add_irq_chip(maxim_core->regmap, maxim_core->irq,
+ ret = regmap_add_irq_chip(maxim_core->regmap_muic, maxim_core->irq,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 0,
&max14577_irq_chip,
- &maxim_core->irq_data);
+ &maxim_core->irq_data_muic);
if (ret != 0) {
dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n",
maxim_core->irq, ret);
@@ -147,7 +147,7 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
ret = mfd_add_devices(maxim_core->dev, -1, max14577_devs,
ARRAY_SIZE(max14577_devs), NULL, 0,
- regmap_irq_get_domain(maxim_core->irq_data));
+ regmap_irq_get_domain(maxim_core->irq_data_muic));
if (ret < 0)
goto err_mfd;
@@ -156,7 +156,7 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
return 0;
err_mfd:
- regmap_del_irq_chip(maxim_core->irq, maxim_core->irq_data);
+ regmap_del_irq_chip(maxim_core->irq, maxim_core->irq_data_muic);
return ret;
}
@@ -166,7 +166,7 @@ static int max14577_i2c_remove(struct i2c_client *i2c)
struct maxim_core *maxim_core = i2c_get_clientdata(i2c);
mfd_remove_devices(maxim_core->dev);
- regmap_del_irq_chip(maxim_core->irq, maxim_core->irq_data);
+ regmap_del_irq_chip(maxim_core->irq, maxim_core->irq_data_muic);
return 0;
}
diff --git a/drivers/power/max14577_charger.c b/drivers/power/max14577_charger.c
index 335c42a13136..58cddc3b15d6 100644
--- a/drivers/power/max14577_charger.c
+++ b/drivers/power/max14577_charger.c
@@ -31,7 +31,7 @@ struct max14577_charger {
static int max14577_get_charger_state(struct max14577_charger *chg)
{
- struct regmap *rmap = chg->maxim_core->regmap;
+ struct regmap *rmap = chg->maxim_core->regmap_muic;
int state = POWER_SUPPLY_STATUS_DISCHARGING;
u8 reg_data;
@@ -87,7 +87,7 @@ static int max14577_get_charge_type(struct max14577_charger *chg)
static int max14577_get_online(struct max14577_charger *chg)
{
- struct regmap *rmap = chg->maxim_core->regmap;
+ struct regmap *rmap = chg->maxim_core->regmap_muic;
u8 reg_data;
max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS2, ®_data);
@@ -116,7 +116,7 @@ static int max14577_get_online(struct max14577_charger *chg)
*/
static int max14577_get_battery_health(struct max14577_charger *chg)
{
- struct regmap *rmap = chg->maxim_core->regmap;
+ struct regmap *rmap = chg->maxim_core->regmap_muic;
int state = POWER_SUPPLY_HEALTH_GOOD;
u8 reg_data;
@@ -156,7 +156,7 @@ static int max14577_get_present(struct max14577_charger *chg)
*/
static void max14577_charger_reg_init(struct max14577_charger *chg)
{
- struct regmap *rmap = chg->maxim_core->regmap;
+ struct regmap *rmap = chg->maxim_core->regmap_muic;
u8 reg_data;
/*
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c
index 3d75ca7aa87e..d7e8fa630d63 100644
--- a/drivers/regulator/max14577.c
+++ b/drivers/regulator/max14577.c
@@ -207,7 +207,7 @@ static int max14577_regulator_probe(struct platform_device *pdev)
return ret;
config.dev = &pdev->dev;
- config.regmap = maxim_core->regmap;
+ config.regmap = maxim_core->regmap_muic;
for (i = 0; i < ARRAY_SIZE(supported_regulators); i++) {
struct regulator_dev *regulator;
diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
index a0a24556741d..d69c56f02eac 100644
--- a/include/linux/mfd/max14577-private.h
+++ b/include/linux/mfd/max14577-private.h
@@ -251,9 +251,9 @@ struct maxim_core {
struct device *dev;
struct i2c_client *i2c; /* Slave addr = 0x4A */
- struct regmap *regmap;
+ struct regmap *regmap_muic;
- struct regmap_irq_chip_data *irq_data;
+ struct regmap_irq_chip_data *irq_data_muic;
int irq;
/* Device ID */
--
1.7.9.5
Add document describing device tree bindings for MAX14577 MFD
drivers: MFD core, extcon, regulator and charger.
Both MAX14577 and MAX77836 chipsets are documented.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Tomasz Figa <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: [email protected]
Cc: Rob Herring <[email protected]>
Cc: Pawel Moll <[email protected]>
Cc: Mark Rutland <[email protected]>
---
Documentation/devicetree/bindings/mfd/max14577.txt | 149 ++++++++++++++++++++
1 file changed, 149 insertions(+)
create mode 100644 Documentation/devicetree/bindings/mfd/max14577.txt
diff --git a/Documentation/devicetree/bindings/mfd/max14577.txt b/Documentation/devicetree/bindings/mfd/max14577.txt
new file mode 100644
index 000000000000..111115b0a6f3
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/max14577.txt
@@ -0,0 +1,149 @@
+Maxim MAX14577/77836 Multi-Function Device
+
+MAX14577 is a Multi-Function Device with Micro-USB Interface Circuit, Li+
+Battery Charger and SFOUT LDO output for powering USB devices. It is
+interfaced to host controller using I2C.
+
+MAX77836 additionally contains PMIC (with two LDO regulators) and Fuel Gauge.
+
+
+Required properties:
+- compatible : Must be "maxim,max14577" or "maxim,max77836".
+- reg : I2C slave address for the max14577 chip (0x25 for max14577/max77836)
+- interrupts : IRQ line for the chip.
+- interrupt-parent : The parent interrupt controller.
+
+
+Optional nodes:
+- max14577-muic/max77836-muic :
+ Node used only by extcon consumers.
+ Required properties:
+ - compatible : "maxim,max14577-muic" or "maxim,max77836-muic"
+
+- regulators :
+ Required properties:
+ - compatible : "maxim,max14577-regulator"
+ or "maxim,max77836-regulator"
+
+ May contain a sub-node per regulator from the list below. Each
+ sub-node should contain the constraints and initialization information
+ for that regulator. See regulator.txt for a description of standard
+ properties for these sub-nodes.
+
+ List of valid regulator names:
+ - for max14577: CHARGER, SAFEOUT.
+ - for max77836: CHARGER, SAFEOUT, LDO1, LDO2.
+
+ The SAFEOUT is a fixed voltage regulator so there is no need to specify
+ voltages for it.
+
+ - charger :
+ Required properties:
+ - compatible : "maxim,max14577-charger"
+ or "maxim,max77836-charger"
+ - maxim,fast-charge-timer : Timer in hours to trigger the
+ INT3/MBCCHGERR interrupt; Valid values:
+ - 5, 6 or 7 (hours),
+ - 0 to disable.
+ - maxim,fast-charge-uamp : Current in uA for Fast Charge;
+ Valid values:
+ - for max14577: 90000 - 950000;
+ - for max77836: 45000 - 475000;
+ - maxim,eoc-uamp : Current in uA for End-Of-Charge mode;
+ Valid values:
+ - for max14577: 50000 - 200000;
+ - for max77836: 5000 - 100000;
+ - maxim,ovp-uvolt : OverVoltage Protection Threshold in uV;
+ In an overvoltage condition, INT asserts and charging
+ stops. Valid values:
+ - 6000000, 6500000, 7000000, 7500000;
+ - maxim,constant-uvolt : Battery Constant Voltage in uV;
+ Valid values:
+ - 4000000 - 4280000 (step by 20000);
+ - 4350000;
+
+
+Example:
+
+#include <dt-bindings/interrupt-controller/irq.h>
+
+max14577@25 {
+ compatible = "maxim,max14577";
+ reg = <0x25>;
+ interrupt-parent = <&gpx1>;
+ interrupts = <5 IRQ_TYPE_NONE>;
+
+ muic: max14577-muic {
+ compatible = "maxim,max14577-muic";
+ };
+
+ regulators {
+ compatible = "maxim,max14577-regulator";
+
+ SAFEOUT {
+ regulator-name = "SAFEOUT";
+ };
+ CHARGER {
+ regulator-name = "CHARGER";
+ regulator-min-microamp = <90000>;
+ regulator-max-microamp = <950000>;
+ regulator-boot-on;
+ };
+ };
+
+ charger {
+ compatible = "maxim,max14577-charger";
+
+ maxim,fast-charge-timer = <6>;
+ maxim,constant-uvolt = <4350000>;
+ maxim,fast-charge-uamp = <450000>;
+ maxim,eoc-uamp = <50000>;
+ maxim,ovp-uvolt = <6500000>;
+ };
+};
+
+
+max77836@25 {
+ compatible = "maxim,max77836";
+ reg = <0x25>;
+ interrupt-parent = <&gpx1>;
+ interrupts = <5 IRQ_TYPE_NONE>;
+
+ muic: max77836-muic {
+ compatible = "maxim,max77836-muic";
+ };
+
+ regulators {
+ compatible = "maxim,max77836-regulator";
+
+ SAFEOUT {
+ regulator-name = "SAFEOUT";
+ };
+ CHARGER {
+ regulator-name = "CHARGER";
+ regulator-min-microamp = <90000>;
+ regulator-max-microamp = <950000>;
+ regulator-boot-on;
+ };
+ LDO1 {
+ regulator-name = "LDO1";
+ regulator-min-microvolt = <2700000>;
+ regulator-max-microvolt = <2700000>;
+ };
+ LDO2 {
+ regulator-name = "LDO2";
+ regulator-min-microvolt = <800000>;
+ regulator-max-microvolt = <3950000>;
+ };
+ };
+
+ charger {
+ compatible = "maxim,max77836-charger";
+
+ maxim,fast-charge-timer = <6>;
+ maxim,constant-uvolt = <4350000>;
+ maxim,fast-charge-uamp = <225000>;
+ maxim,eoc-uamp = <7500>;
+ maxim,ovp-uvolt = <6500000>;
+ };
+};
--
1.7.9.5
Add support for MAX77836 chipset and its additional two LDO regulators.
These LDO regulators are controlled by the PMIC block with additional
regmap (different I2C slave address).
The MAX77836 charger and safeout regulators are almost identical to
MAX14577. The registers layout is the same, except values for charger's
current. The patch adds simple mapping between device type and supported
current by the charger regulator.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Reviewed-by: Mark Brown <[email protected]>
Acked-by: Lee Jones <[email protected]>
---
drivers/regulator/max14577.c | 275 +++++++++++++++++++++++++++++-----
include/linux/mfd/max14577-private.h | 32 ++++
include/linux/mfd/max14577.h | 10 ++
3 files changed, 282 insertions(+), 35 deletions(-)
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c
index d7e8fa630d63..6bd4cfc11856 100644
--- a/drivers/regulator/max14577.c
+++ b/drivers/regulator/max14577.c
@@ -1,5 +1,5 @@
/*
- * max14577.c - Regulator driver for the Maxim 14577
+ * max14577.c - Regulator driver for the Maxim 14577/77836
*
* Copyright (C) 2013,2014 Samsung Electronics
* Krzysztof Kozlowski <[email protected]>
@@ -22,6 +22,42 @@
#include <linux/mfd/max14577-private.h>
#include <linux/regulator/of_regulator.h>
+/*
+ * Valid limits of current for max14577 and max77836 chargers.
+ * They must correspond to MBCICHWRCL and MBCICHWRCH fields in CHGCTRL4
+ * register for given chipset.
+ */
+struct maxim_charger_current {
+ /* Minimal current, set in CHGCTRL4/MBCICHWRCL, uA */
+ unsigned int min;
+ /*
+ * Minimal current when high setting is active,
+ * set in CHGCTRL4/MBCICHWRCH, uA
+ */
+ unsigned int high_start;
+ /* Value of one step in high setting, uA */
+ unsigned int high_step;
+ /* Maximum current of high setting, uA */
+ unsigned int max;
+};
+
+/* Table of valid charger currents for different Maxim chipsets */
+static const struct maxim_charger_current maxim_charger_currents[] = {
+ [MAXIM_DEVICE_TYPE_UNKNOWN] = { 0, 0, 0, 0 },
+ [MAXIM_DEVICE_TYPE_MAX14577] = {
+ .min = MAX14577_REGULATOR_CURRENT_LIMIT_MIN,
+ .high_start = MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START,
+ .high_step = MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP,
+ .max = MAX14577_REGULATOR_CURRENT_LIMIT_MAX,
+ },
+ [MAXIM_DEVICE_TYPE_MAX77836] = {
+ .min = MAX77836_REGULATOR_CURRENT_LIMIT_MIN,
+ .high_start = MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START,
+ .high_step = MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP,
+ .max = MAX77836_REGULATOR_CURRENT_LIMIT_MAX,
+ },
+};
+
static int max14577_reg_is_enabled(struct regulator_dev *rdev)
{
int rid = rdev_get_id(rdev);
@@ -47,6 +83,9 @@ static int max14577_reg_get_current_limit(struct regulator_dev *rdev)
{
u8 reg_data;
struct regmap *rmap = rdev->regmap;
+ struct maxim_core *maxim_core = rdev_get_drvdata(rdev);
+ const struct maxim_charger_current *limits =
+ &maxim_charger_currents[maxim_core->dev_type];
if (rdev_get_id(rdev) != MAX14577_CHARGER)
return -EINVAL;
@@ -54,12 +93,11 @@ static int max14577_reg_get_current_limit(struct regulator_dev *rdev)
max14577_read_reg(rmap, MAXIM_CHG_REG_CHGCTRL4, ®_data);
if ((reg_data & MAXIM_CHGCTRL4_MBCICHWRCL_MASK) == 0)
- return MAX14577_REGULATOR_CURRENT_LIMIT_MIN;
+ return limits->min;
reg_data = ((reg_data & MAXIM_CHGCTRL4_MBCICHWRCH_MASK) >>
MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT);
- return MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START +
- reg_data * MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP;
+ return limits->high_start + reg_data * limits->high_step;
}
static int max14577_reg_set_current_limit(struct regulator_dev *rdev,
@@ -67,33 +105,35 @@ static int max14577_reg_set_current_limit(struct regulator_dev *rdev,
{
int i, current_bits = 0xf;
u8 reg_data;
+ struct maxim_core *maxim_core = rdev_get_drvdata(rdev);
+ const struct maxim_charger_current *limits =
+ &maxim_charger_currents[maxim_core->dev_type];
if (rdev_get_id(rdev) != MAX14577_CHARGER)
return -EINVAL;
- if (min_uA > MAX14577_REGULATOR_CURRENT_LIMIT_MAX ||
- max_uA < MAX14577_REGULATOR_CURRENT_LIMIT_MIN)
+ if (min_uA > limits->max || max_uA < limits->min)
return -EINVAL;
- if (max_uA < MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START) {
- /* Less than 200 mA, so set 90mA (turn only Low Bit off) */
+ if (max_uA < limits->high_start) {
+ /* Less than high_start,
+ * so set the minimal current (turn only Low Bit off) */
u8 reg_data = 0x0 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
return max14577_update_reg(rdev->regmap,
MAXIM_CHG_REG_CHGCTRL4,
MAXIM_CHGCTRL4_MBCICHWRCL_MASK, reg_data);
}
- /* max_uA is in range: <LIMIT_HIGH_START, inifinite>, so search for
- * valid current starting from LIMIT_MAX. */
- for (i = MAX14577_REGULATOR_CURRENT_LIMIT_MAX;
- i >= MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START;
- i -= MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP) {
+ /* max_uA is in range: <high_start, inifinite>, so search for
+ * valid current starting from maximum current. */
+ for (i = limits->max; i >= limits->high_start; i -= limits->high_step) {
if (i <= max_uA)
break;
current_bits--;
}
BUG_ON(current_bits < 0); /* Cannot happen */
- /* Turn Low Bit on (use range 200mA-950 mA) */
+
+ /* Turn Low Bit on (use range high_start-max)... */
reg_data = 0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
/* and set proper High Bits */
reg_data |= current_bits << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT;
@@ -118,7 +158,7 @@ static struct regulator_ops max14577_charger_ops = {
.set_current_limit = max14577_reg_set_current_limit,
};
-static const struct regulator_desc supported_regulators[] = {
+static const struct regulator_desc max14577_supported_regulators[] = {
[MAX14577_SAFEOUT] = {
.name = "SAFEOUT",
.id = MAX14577_SAFEOUT,
@@ -141,16 +181,88 @@ static const struct regulator_desc supported_regulators[] = {
},
};
+static struct regulator_ops max77836_ldo_ops = {
+ .is_enabled = regulator_is_enabled_regmap,
+ .enable = regulator_enable_regmap,
+ .disable = regulator_disable_regmap,
+ .list_voltage = regulator_list_voltage_linear,
+ .map_voltage = regulator_map_voltage_linear,
+ .get_voltage_sel = regulator_get_voltage_sel_regmap,
+ .set_voltage_sel = regulator_set_voltage_sel_regmap,
+ /* TODO: add .set_suspend_mode */
+};
+
+static const struct regulator_desc max77836_supported_regulators[] = {
+ [MAX14577_SAFEOUT] = {
+ .name = "SAFEOUT",
+ .id = MAX14577_SAFEOUT,
+ .ops = &max14577_safeout_ops,
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .n_voltages = 1,
+ .min_uV = MAX14577_REGULATOR_SAFEOUT_VOLTAGE,
+ .enable_reg = MAXIM_MUIC_REG_CONTROL2,
+ .enable_mask = MAXIM_CONTROL2_SFOUTORD_MASK,
+ },
+ [MAX14577_CHARGER] = {
+ .name = "CHARGER",
+ .id = MAX14577_CHARGER,
+ .ops = &max14577_charger_ops,
+ .type = REGULATOR_CURRENT,
+ .owner = THIS_MODULE,
+ .enable_reg = MAXIM_CHG_REG_CHGCTRL2,
+ .enable_mask = MAXIM_CHGCTRL2_MBCHOSTEN_MASK,
+ },
+ [MAX77836_LDO1] = {
+ .name = "LDO1",
+ .id = MAX77836_LDO1,
+ .ops = &max77836_ldo_ops,
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .n_voltages = MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM,
+ .min_uV = MAX77836_REGULATOR_LDO_VOLTAGE_MIN,
+ .uV_step = MAX77836_REGULATOR_LDO_VOLTAGE_STEP,
+ .enable_reg = MAX77836_LDO_REG_CNFG1_LDO1,
+ .enable_mask = MAX77836_CNFG1_LDO_PWRMD_MASK,
+ .vsel_reg = MAX77836_LDO_REG_CNFG1_LDO1,
+ .vsel_mask = MAX77836_CNFG1_LDO_TV_MASK,
+ },
+ [MAX77836_LDO2] = {
+ .name = "LDO2",
+ .id = MAX77836_LDO2,
+ .ops = &max77836_ldo_ops,
+ .type = REGULATOR_VOLTAGE,
+ .owner = THIS_MODULE,
+ .n_voltages = MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM,
+ .min_uV = MAX77836_REGULATOR_LDO_VOLTAGE_MIN,
+ .uV_step = MAX77836_REGULATOR_LDO_VOLTAGE_STEP,
+ .enable_reg = MAX77836_LDO_REG_CNFG1_LDO2,
+ .enable_mask = MAX77836_CNFG1_LDO_PWRMD_MASK,
+ .vsel_reg = MAX77836_LDO_REG_CNFG1_LDO2,
+ .vsel_mask = MAX77836_CNFG1_LDO_TV_MASK,
+ },
+};
+
#ifdef CONFIG_OF
static struct of_regulator_match max14577_regulator_matches[] = {
{ .name = "SAFEOUT", },
{ .name = "CHARGER", },
};
-static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
+static struct of_regulator_match max77836_regulator_matches[] = {
+ { .name = "SAFEOUT", },
+ { .name = "CHARGER", },
+ { .name = "LDO1", },
+ { .name = "LDO2", },
+};
+
+static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev,
+ enum maxim_device_type dev_type)
{
int ret;
struct device_node *np;
+ struct of_regulator_match *regulator_matches;
+ unsigned int regulator_matches_size;
np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
if (!np) {
@@ -158,8 +270,19 @@ static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
return -EINVAL;
}
- ret = of_regulator_match(&pdev->dev, np, max14577_regulator_matches,
- MAX14577_REG_NUM);
+ switch (dev_type) {
+ case MAXIM_DEVICE_TYPE_MAX77836:
+ regulator_matches = max77836_regulator_matches;
+ regulator_matches_size = ARRAY_SIZE(max77836_regulator_matches);
+ break;
+ case MAXIM_DEVICE_TYPE_MAX14577:
+ default:
+ regulator_matches = max14577_regulator_matches;
+ regulator_matches_size = ARRAY_SIZE(max14577_regulator_matches);
+ }
+
+ ret = of_regulator_match(&pdev->dev, np, regulator_matches,
+ regulator_matches_size);
if (ret < 0) {
dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);
}
@@ -169,31 +292,74 @@ static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
return ret;
}
-static inline struct regulator_init_data *match_init_data(int index)
+static inline struct regulator_init_data *match_init_data(int index,
+ enum maxim_device_type dev_type)
{
- return max14577_regulator_matches[index].init_data;
+ switch (dev_type) {
+ case MAXIM_DEVICE_TYPE_MAX77836:
+ return max77836_regulator_matches[index].init_data;
+
+ case MAXIM_DEVICE_TYPE_MAX14577:
+ default:
+ return max14577_regulator_matches[index].init_data;
+ }
}
-static inline struct device_node *match_of_node(int index)
+static inline struct device_node *match_of_node(int index,
+ enum maxim_device_type dev_type)
{
- return max14577_regulator_matches[index].of_node;
+ switch (dev_type) {
+ case MAXIM_DEVICE_TYPE_MAX77836:
+ return max77836_regulator_matches[index].of_node;
+
+ case MAXIM_DEVICE_TYPE_MAX14577:
+ default:
+ return max14577_regulator_matches[index].of_node;
+ }
}
#else /* CONFIG_OF */
-static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
+static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev,
+ enum maxim_device_type dev_type)
{
return 0;
}
-static inline struct regulator_init_data *match_init_data(int index)
+static inline struct regulator_init_data *match_init_data(int index,
+ enum maxim_device_type dev_type)
{
return NULL;
}
-static inline struct device_node *match_of_node(int index)
+static inline struct device_node *match_of_node(int index,
+ enum maxim_device_type dev_type)
{
return NULL;
}
#endif /* CONFIG_OF */
+/**
+ * Registers for regulators of max77836 use different I2C slave addresses so
+ * different regmaps must be used for them.
+ *
+ * Returns proper regmap for accessing regulator passed by id.
+ */
+static struct regmap *max14577_get_regmap(struct maxim_core *maxim_core,
+ int reg_id)
+{
+ switch (maxim_core->dev_type) {
+ case MAXIM_DEVICE_TYPE_MAX77836:
+ switch (reg_id) {
+ case MAX77836_SAFEOUT ... MAX77836_CHARGER:
+ return maxim_core->regmap_muic;
+ default:
+ /* MAX77836_LDO1 ... MAX77836_LDO2 */
+ return maxim_core->regmap_pmic;
+ }
+
+ case MAXIM_DEVICE_TYPE_MAX14577:
+ default:
+ return maxim_core->regmap_muic;
+ }
+}
static int max14577_regulator_probe(struct platform_device *pdev)
{
@@ -201,15 +367,29 @@ static int max14577_regulator_probe(struct platform_device *pdev)
struct max14577_platform_data *pdata = dev_get_platdata(maxim_core->dev);
int i, ret;
struct regulator_config config = {};
+ const struct regulator_desc *supported_regulators;
+ unsigned int supported_regulators_size;
+ enum maxim_device_type dev_type = maxim_core->dev_type;
- ret = max14577_regulator_dt_parse_pdata(pdev);
+ ret = max14577_regulator_dt_parse_pdata(pdev, dev_type);
if (ret)
return ret;
+ switch (dev_type) {
+ case MAXIM_DEVICE_TYPE_MAX77836:
+ supported_regulators = max77836_supported_regulators;
+ supported_regulators_size = ARRAY_SIZE(max77836_supported_regulators);
+ break;
+ case MAXIM_DEVICE_TYPE_MAX14577:
+ default:
+ supported_regulators = max14577_supported_regulators;
+ supported_regulators_size = ARRAY_SIZE(max14577_supported_regulators);
+ }
+
config.dev = &pdev->dev;
- config.regmap = maxim_core->regmap_muic;
+ config.driver_data = maxim_core;
- for (i = 0; i < ARRAY_SIZE(supported_regulators); i++) {
+ for (i = 0; i < supported_regulators_size; i++) {
struct regulator_dev *regulator;
/*
* Index of supported_regulators[] is also the id and must
@@ -219,38 +399,63 @@ static int max14577_regulator_probe(struct platform_device *pdev)
config.init_data = pdata->regulators[i].initdata;
config.of_node = pdata->regulators[i].of_node;
} else {
- config.init_data = match_init_data(i);
- config.of_node = match_of_node(i);
+ config.init_data = match_init_data(i, dev_type);
+ config.of_node = match_of_node(i, dev_type);
}
+ config.regmap = max14577_get_regmap(maxim_core,
+ supported_regulators[i].id);
regulator = devm_regulator_register(&pdev->dev,
&supported_regulators[i], &config);
if (IS_ERR(regulator)) {
ret = PTR_ERR(regulator);
dev_err(&pdev->dev,
- "Regulator init failed for ID %d with error: %d\n",
- i, ret);
+ "Regulator init failed for %d/%s with error: %d\n",
+ i, supported_regulators[i].name, ret);
return ret;
}
+ dev_dbg(&pdev->dev, "Registered regulator %d/%s\n", i,
+ supported_regulators[i].name);
}
return ret;
}
+static const struct platform_device_id max14577_regulator_id[] = {
+ { "max14577-regulator", MAXIM_DEVICE_TYPE_MAX14577, },
+ { "max77836-regulator", MAXIM_DEVICE_TYPE_MAX77836, },
+ { }
+};
+MODULE_DEVICE_TABLE(platform, max14577_regulator_id);
+
static struct platform_driver max14577_regulator_driver = {
.driver = {
.owner = THIS_MODULE,
.name = "max14577-regulator",
},
- .probe = max14577_regulator_probe,
+ .probe = max14577_regulator_probe,
+ .id_table = max14577_regulator_id,
};
static int __init max14577_regulator_init(void)
{
+ /* Check for valid values for charger */
BUILD_BUG_ON(MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START +
MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf !=
MAX14577_REGULATOR_CURRENT_LIMIT_MAX);
- BUILD_BUG_ON(ARRAY_SIZE(supported_regulators) != MAX14577_REG_NUM);
+ BUILD_BUG_ON(MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START +
+ MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf !=
+ MAX77836_REGULATOR_CURRENT_LIMIT_MAX);
+ /* Valid charger current values must be provided for each chipset */
+ BUILD_BUG_ON(ARRAY_SIZE(maxim_charger_currents) != MAXIM_DEVICE_TYPE_NUM);
+
+ BUILD_BUG_ON(ARRAY_SIZE(max14577_supported_regulators) != MAX14577_REG_NUM);
+ BUILD_BUG_ON(ARRAY_SIZE(max77836_supported_regulators) != MAX77836_REG_NUM);
+
+ BUILD_BUG_ON(MAX77836_REGULATOR_LDO_VOLTAGE_MIN +
+ (MAX77836_REGULATOR_LDO_VOLTAGE_STEP *
+ (MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM - 1)) !=
+ MAX77836_REGULATOR_LDO_VOLTAGE_MAX);
return platform_driver_register(&max14577_regulator_driver);
}
@@ -263,6 +468,6 @@ static void __exit max14577_regulator_exit(void)
module_exit(max14577_regulator_exit);
MODULE_AUTHOR("Krzysztof Kozlowski <[email protected]>");
-MODULE_DESCRIPTION("MAXIM 14577 regulator driver");
+MODULE_DESCRIPTION("Maxim 14577/77836 regulator driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:max14577-regulator");
diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
index aae9382a41cb..3da322dc7d25 100644
--- a/include/linux/mfd/max14577-private.h
+++ b/include/linux/mfd/max14577-private.h
@@ -238,9 +238,21 @@ enum maxim_muic_charger_type {
#define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP 50000
#define MAX14577_REGULATOR_CURRENT_LIMIT_MAX 950000
+/* MAX77836 regulator current limits (as in MAXIM_CHGCTRL4 register), uA */
+#define MAX77836_REGULATOR_CURRENT_LIMIT_MIN 45000
+#define MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START 100000
+#define MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP 25000
+#define MAX77836_REGULATOR_CURRENT_LIMIT_MAX 475000
+
/* MAX14577 regulator SFOUT LDO voltage, fixed, uV */
#define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000
+/* MAX77836 regulator LDOx voltage, uV */
+#define MAX77836_REGULATOR_LDO_VOLTAGE_MIN 800000
+#define MAX77836_REGULATOR_LDO_VOLTAGE_MAX 3950000
+#define MAX77836_REGULATOR_LDO_VOLTAGE_STEP 50000
+#define MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM 64
+
/* Slave addr = 0x46: PMIC */
enum max77836_pmic_reg {
MAX77836_PMIC_REG_PMIC_ID = 0x20,
@@ -275,6 +287,26 @@ enum max77836_pmic_reg {
#define MAX77836_TOPSYS_INT_T120C_MASK BIT(MAX77836_TOPSYS_INT_T120C_SHIFT)
#define MAX77836_TOPSYS_INT_T140C_MASK BIT(MAX77836_TOPSYS_INT_T140C_SHIFT)
+/* LDO1/LDO2 CONFIG1 register */
+#define MAX77836_CNFG1_LDO_PWRMD_SHIFT 6
+#define MAX77836_CNFG1_LDO_TV_SHIFT 0
+#define MAX77836_CNFG1_LDO_PWRMD_MASK (0x3 << MAX77836_CNFG1_LDO_PWRMD_SHIFT)
+#define MAX77836_CNFG1_LDO_TV_MASK (0x3f << MAX77836_CNFG1_LDO_TV_SHIFT)
+
+/* LDO1/LDO2 CONFIG2 register */
+#define MAX77836_CNFG2_LDO_OVCLMPEN_SHIFT 7
+#define MAX77836_CNFG2_LDO_ALPMEN_SHIFT 6
+#define MAX77836_CNFG2_LDO_COMP_SHIFT 4
+#define MAX77836_CNFG2_LDO_POK_SHIFT 3
+#define MAX77836_CNFG2_LDO_ADE_SHIFT 1
+#define MAX77836_CNFG2_LDO_SS_SHIFT 0
+#define MAX77836_CNFG2_LDO_OVCLMPEN_MASK BIT(MAX77836_CNFG2_LDO_OVCLMPEN_SHIFT)
+#define MAX77836_CNFG2_LDO_ALPMEN_MASK BIT(MAX77836_CNFG2_LDO_ALPMEN_SHIFT)
+#define MAX77836_CNFG2_LDO_COMP_MASK (0x3 << MAX77836_CNFG2_LDO_COMP_SHIFT)
+#define MAX77836_CNFG2_LDO_POK_MASK BIT(MAX77836_CNFG2_LDO_POK_SHIFT)
+#define MAX77836_CNFG2_LDO_ADE_MASK BIT(MAX77836_CNFG2_LDO_ADE_SHIFT)
+#define MAX77836_CNFG2_LDO_SS_MASK BIT(MAX77836_CNFG2_LDO_SS_SHIFT)
+
/* Slave addr = 0x6C: Fuel-Gauge/Battery */
enum max77836_fg_reg {
MAX77836_FG_REG_VCELL_MSB = 0x02,
diff --git a/include/linux/mfd/max14577.h b/include/linux/mfd/max14577.h
index 6aad3f249fdd..0070c69481ef 100644
--- a/include/linux/mfd/max14577.h
+++ b/include/linux/mfd/max14577.h
@@ -38,6 +38,16 @@ enum max14577_regulators {
MAX14577_REG_NUM,
};
+/* MAX77836 regulator IDs */
+enum max77836_regulators {
+ MAX77836_SAFEOUT = 0,
+ MAX77836_CHARGER,
+ MAX77836_LDO1,
+ MAX77836_LDO2,
+
+ MAX77836_REG_NUM,
+};
+
struct max14577_regulator_platform_data {
int id;
struct regulator_init_data *initdata;
--
1.7.9.5
Add support for MAX77836 chipset to the max14577 extcon driver. The
MAX77836 MUIC has additional interrupts (VIDRM, ADC1K) so IRQ handling
is split up into two functions: max14577_parse_irq() and
max77836_parse_irq().
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Chanwoo Choi <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Acked-by: Lee Jones <[email protected]>
Acked-by: Chanwoo Choi <[email protected]>
Tested-by: Chanwoo Choi <[email protected]>
---
drivers/extcon/extcon-max14577.c | 109 ++++++++++++++++++++++++++++------
drivers/mfd/max14577.c | 1 +
include/linux/mfd/max14577-private.h | 3 +
3 files changed, 94 insertions(+), 19 deletions(-)
diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index e986a9b92b60..82ac6b0fb1bc 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -1,8 +1,9 @@
/*
- * extcon-max14577.c - MAX14577 extcon driver to support MAX14577 MUIC
+ * extcon-max14577.c - MAX14577/77836 extcon driver to support MUIC
*
- * Copyright (C) 2013 Samsung Electrnoics
+ * Copyright (C) 2013,2014 Samsung Electrnoics
* Chanwoo Choi <[email protected]>
+ * Krzysztof Kozlowski <[email protected]>
*
* 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
@@ -62,6 +63,19 @@ static struct max14577_muic_irq max14577_muic_irqs[] = {
{ MAXIM_IRQ_INT2_VBVOLT, "muic-VBVOLT" },
};
+static struct max14577_muic_irq max77836_muic_irqs[] = {
+ { MAXIM_IRQ_INT1_ADC, "muic-ADC" },
+ { MAXIM_IRQ_INT1_ADCLOW, "muic-ADCLOW" },
+ { MAXIM_IRQ_INT1_ADCERR, "muic-ADCError" },
+ { MAX77836_IRQ_INT1_ADC1K, "muic-ADC1K" },
+ { MAXIM_IRQ_INT2_CHGTYP, "muic-CHGTYP" },
+ { MAXIM_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" },
+ { MAXIM_IRQ_INT2_DCDTMR, "muic-DCDTMR" },
+ { MAXIM_IRQ_INT2_DBCHG, "muic-DBCHG" },
+ { MAXIM_IRQ_INT2_VBVOLT, "muic-VBVOLT" },
+ { MAX77836_IRQ_INT2_VIDRM, "muic-VIDRM" },
+};
+
struct max14577_muic_info {
struct device *dev;
struct maxim_core *maxim_core;
@@ -532,21 +546,12 @@ static void max14577_muic_irq_work(struct work_struct *work)
return;
}
-static irqreturn_t max14577_muic_irq_handler(int irq, void *data)
+/*
+ * Sets irq_adc or irq_chg in max14577_muic_info and returns 1.
+ * Returns 0 if irq_type does not match registered IRQ for this device type.
+ */
+static int max14577_parse_irq(struct max14577_muic_info *info, int irq_type)
{
- struct max14577_muic_info *info = data;
- int i, irq_type = -1;
-
- /*
- * We may be called multiple times for different nested IRQ-s.
- * Including changes in INT1_ADC and INT2_CGHTYP at once.
- * However we only need to know whether it was ADC, charger
- * or both interrupts so decode IRQ and turn on proper flags.
- */
- for (i = 0; i < info->muic_irqs_num; i++)
- if (irq == info->muic_irqs[i].virq)
- irq_type = info->muic_irqs[i].irq;
-
switch (irq_type) {
case MAXIM_IRQ_INT1_ADC:
case MAXIM_IRQ_INT1_ADCLOW:
@@ -554,7 +559,7 @@ static irqreturn_t max14577_muic_irq_handler(int irq, void *data)
/* Handle all of accessory except for
type of charger accessory */
info->irq_adc = true;
- break;
+ return 1;
case MAXIM_IRQ_INT2_CHGTYP:
case MAXIM_IRQ_INT2_CHGDETRUN:
case MAXIM_IRQ_INT2_DCDTMR:
@@ -562,8 +567,62 @@ static irqreturn_t max14577_muic_irq_handler(int irq, void *data)
case MAXIM_IRQ_INT2_VBVOLT:
/* Handle charger accessory */
info->irq_chg = true;
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+/*
+ * Sets irq_adc or irq_chg in max14577_muic_info and returns 1.
+ * Returns 0 if irq_type does not match registered IRQ for this device type.
+ */
+static int max77836_parse_irq(struct max14577_muic_info *info, int irq_type)
+{
+ /* First check common max14577 interrupts */
+ if (max14577_parse_irq(info, irq_type))
+ return 1;
+
+ switch (irq_type) {
+ case MAX77836_IRQ_INT1_ADC1K:
+ info->irq_adc = true;
+ return 1;
+ case MAX77836_IRQ_INT2_VIDRM:
+ /* Handle charger accessory */
+ info->irq_chg = true;
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+static irqreturn_t max14577_muic_irq_handler(int irq, void *data)
+{
+ struct max14577_muic_info *info = data;
+ int i, irq_type = -1;
+ bool irq_parsed;
+
+ /*
+ * We may be called multiple times for different nested IRQ-s.
+ * Including changes in INT1_ADC and INT2_CGHTYP at once.
+ * However we only need to know whether it was ADC, charger
+ * or both interrupts so decode IRQ and turn on proper flags.
+ */
+ for (i = 0; i < info->muic_irqs_num; i++)
+ if (irq == info->muic_irqs[i].virq)
+ irq_type = info->muic_irqs[i].irq;
+
+ switch (info->maxim_core->dev_type) {
+ case MAXIM_DEVICE_TYPE_MAX77836:
+ irq_parsed = max77836_parse_irq(info, irq_type);
break;
+ case MAXIM_DEVICE_TYPE_MAX14577:
default:
+ irq_parsed = max14577_parse_irq(info, irq_type);
+ break;
+ }
+
+ if (!irq_parsed) {
dev_err(info->dev, "muic interrupt: irq %d occurred, skipped\n",
irq_type);
return IRQ_HANDLED;
@@ -649,6 +708,10 @@ static int max14577_muic_probe(struct platform_device *pdev)
INIT_WORK(&info->irq_work, max14577_muic_irq_work);
switch (maxim_core->dev_type) {
+ case MAXIM_DEVICE_TYPE_MAX77836:
+ info->muic_irqs = max77836_muic_irqs;
+ info->muic_irqs_num = ARRAY_SIZE(max77836_muic_irqs);
+ break;
case MAXIM_DEVICE_TYPE_MAX14577:
default:
info->muic_irqs = max14577_muic_irqs;
@@ -748,6 +811,13 @@ static int max14577_muic_remove(struct platform_device *pdev)
return 0;
}
+static const struct platform_device_id max14577_muic_id[] = {
+ { "max14577-muic", MAXIM_DEVICE_TYPE_MAX14577, },
+ { "max77836-muic", MAXIM_DEVICE_TYPE_MAX77836, },
+ { }
+};
+MODULE_DEVICE_TABLE(platform, max14577_muic_id);
+
static struct platform_driver max14577_muic_driver = {
.driver = {
.name = "max14577-muic",
@@ -755,11 +825,12 @@ static struct platform_driver max14577_muic_driver = {
},
.probe = max14577_muic_probe,
.remove = max14577_muic_remove,
+ .id_table = max14577_muic_id,
};
module_platform_driver(max14577_muic_driver);
-MODULE_DESCRIPTION("MAXIM 14577 Extcon driver");
-MODULE_AUTHOR("Chanwoo Choi <[email protected]>");
+MODULE_DESCRIPTION("Maxim 14577/77836 Extcon driver");
+MODULE_AUTHOR("Chanwoo Choi <[email protected]>, Krzysztof Kozlowski <[email protected]>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:extcon-max14577");
diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index 1463b17c11c3..08a2ceff3822 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -146,6 +146,7 @@ static const struct regmap_irq max77836_muic_irqs[] = {
{ .reg_offset = 0, .mask = MAXIM_INT1_ADC_MASK, },
{ .reg_offset = 0, .mask = MAXIM_INT1_ADCLOW_MASK, },
{ .reg_offset = 0, .mask = MAXIM_INT1_ADCERR_MASK, },
+ { .reg_offset = 0, .mask = MAX77836_INT1_ADC1K_MASK, },
/* INT2 interrupts */
{ .reg_offset = 1, .mask = MAXIM_INT2_CHGTYP_MASK, },
{ .reg_offset = 1, .mask = MAXIM_INT2_CHGDETRUN_MASK, },
diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
index 472d5780ca50..aae9382a41cb 100644
--- a/include/linux/mfd/max14577-private.h
+++ b/include/linux/mfd/max14577-private.h
@@ -77,6 +77,7 @@ enum maxim_muic_charger_type {
#define MAXIM_INT1_ADC_MASK BIT(0)
#define MAXIM_INT1_ADCLOW_MASK BIT(1)
#define MAXIM_INT1_ADCERR_MASK BIT(2)
+#define MAX77836_INT1_ADC1K_MASK BIT(3)
#define MAXIM_INT2_CHGTYP_MASK BIT(0)
#define MAXIM_INT2_CHGDETRUN_MASK BIT(1)
@@ -309,6 +310,7 @@ enum maxim_irq {
MAXIM_IRQ_INT1_ADC,
MAXIM_IRQ_INT1_ADCLOW,
MAXIM_IRQ_INT1_ADCERR,
+ MAX77836_IRQ_INT1_ADC1K,
/* INT2 */
MAXIM_IRQ_INT2_CHGTYP,
@@ -316,6 +318,7 @@ enum maxim_irq {
MAXIM_IRQ_INT2_DCDTMR,
MAXIM_IRQ_INT2_DBCHG,
MAXIM_IRQ_INT2_VBVOLT,
+ MAX77836_IRQ_INT2_VIDRM,
/* INT3 */
MAXIM_IRQ_INT3_EOC,
--
1.7.9.5
MAX77836 has the same Fuel Gauge as MAX17040. The max17040 driver can be
safely re-used. The patch adds MAX77836 ID to array with i2c_device_id.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Anton Vorontsov <[email protected]>
Cc: Dmitry Eremin-Solenikov <[email protected]>
Cc: David Woodhouse <[email protected]>
---
drivers/power/max17040_battery.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/power/max17040_battery.c b/drivers/power/max17040_battery.c
index 0fbac861080d..165ffe381803 100644
--- a/drivers/power/max17040_battery.c
+++ b/drivers/power/max17040_battery.c
@@ -278,6 +278,7 @@ static SIMPLE_DEV_PM_OPS(max17040_pm_ops, max17040_suspend, max17040_resume);
static const struct i2c_device_id max17040_id[] = {
{ "max17040", 0 },
+ { "max77836-battery", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, max17040_id);
--
1.7.9.5
This patch prepares for adding support for max77836 device to existing
max14577 driver:
1. Renames most of symbols and defines prefixed with MAX14577 to MAXIM.
2. Adds prefixes (MAXIM or MAX14577) to defines without any MAX* prefix.
This is only a rename-like patch, new code is not added.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Anton Vorontsov <[email protected]>
Cc: Dmitry Eremin-Solenikov <[email protected]>
Cc: David Woodhouse <[email protected]>
Acked-by: Lee Jones <[email protected]>
Acked-by: Chanwoo Choi <[email protected]>
---
drivers/extcon/extcon-max14577.c | 105 ++++-----
drivers/mfd/max14577.c | 51 ++---
drivers/power/max14577_charger.c | 81 +++----
drivers/regulator/max14577.c | 44 ++--
include/linux/mfd/max14577-private.h | 399 ++++++++++++++++------------------
include/linux/mfd/max14577.h | 2 +-
6 files changed, 333 insertions(+), 349 deletions(-)
diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index 59f084fee4f3..6f7145a929cf 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -86,14 +86,14 @@ struct max14577_muic_irq {
};
static struct max14577_muic_irq muic_irqs[] = {
- { MAX14577_IRQ_INT1_ADC, "muic-ADC" },
- { MAX14577_IRQ_INT1_ADCLOW, "muic-ADCLOW" },
- { MAX14577_IRQ_INT1_ADCERR, "muic-ADCError" },
- { MAX14577_IRQ_INT2_CHGTYP, "muic-CHGTYP" },
- { MAX14577_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" },
- { MAX14577_IRQ_INT2_DCDTMR, "muic-DCDTMR" },
- { MAX14577_IRQ_INT2_DBCHG, "muic-DBCHG" },
- { MAX14577_IRQ_INT2_VBVOLT, "muic-VBVOLT" },
+ { MAXIM_IRQ_INT1_ADC, "muic-ADC" },
+ { MAXIM_IRQ_INT1_ADCLOW, "muic-ADCLOW" },
+ { MAXIM_IRQ_INT1_ADCERR, "muic-ADCError" },
+ { MAXIM_IRQ_INT2_CHGTYP, "muic-CHGTYP" },
+ { MAXIM_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" },
+ { MAXIM_IRQ_INT2_DCDTMR, "muic-DCDTMR" },
+ { MAXIM_IRQ_INT2_DBCHG, "muic-DBCHG" },
+ { MAXIM_IRQ_INT2_VBVOLT, "muic-VBVOLT" },
};
/* Define supported accessory type */
@@ -177,9 +177,9 @@ static int max14577_muic_set_debounce_time(struct max14577_muic_info *info,
case ADC_DEBOUNCE_TIME_25MS:
case ADC_DEBOUNCE_TIME_38_62MS:
ret = max14577_update_reg(info->max14577->regmap,
- MAX14577_MUIC_REG_CONTROL3,
- CTRL3_ADCDBSET_MASK,
- time << CTRL3_ADCDBSET_SHIFT);
+ MAXIM_MUIC_REG_CONTROL3,
+ MAXIM_CONTROL3_ADCDBSET_MASK,
+ time << MAXIM_CONTROL3_ADCDBSET_SHIFT);
if (ret) {
dev_err(info->dev, "failed to set ADC debounce time\n");
return ret;
@@ -211,8 +211,9 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
/* Set open state to path before changing hw path */
ret = max14577_update_reg(info->max14577->regmap,
- MAX14577_MUIC_REG_CONTROL1,
- CLEAR_IDBEN_MICEN_MASK, CTRL1_SW_OPEN);
+ MAXIM_MUIC_REG_CONTROL1,
+ MAXIM_CONTROL1_CLEAR_IDBEN_MICEN_MASK,
+ MAXIM_CONTROL1_SW_OPEN);
if (ret < 0) {
dev_err(info->dev, "failed to update MUIC register\n");
return ret;
@@ -221,24 +222,25 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
if (attached)
ctrl1 = val;
else
- ctrl1 = CTRL1_SW_OPEN;
+ ctrl1 = MAXIM_CONTROL1_SW_OPEN;
ret = max14577_update_reg(info->max14577->regmap,
- MAX14577_MUIC_REG_CONTROL1,
- CLEAR_IDBEN_MICEN_MASK, ctrl1);
+ MAXIM_MUIC_REG_CONTROL1,
+ MAXIM_CONTROL1_CLEAR_IDBEN_MICEN_MASK, ctrl1);
if (ret < 0) {
dev_err(info->dev, "failed to update MUIC register\n");
return ret;
}
if (attached)
- ctrl2 |= CTRL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */
+ ctrl2 |= MAXIM_CONTROL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */
else
- ctrl2 |= CTRL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */
+ ctrl2 |= MAXIM_CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */
ret = max14577_update_reg(info->max14577->regmap,
- MAX14577_REG_CONTROL2,
- CTRL2_LOWPWR_MASK | CTRL2_CPEN_MASK, ctrl2);
+ MAXIM_MUIC_REG_CONTROL2,
+ MAXIM_CONTROL2_LOWPWR_MASK | MAXIM_CONTROL2_CPEN_MASK,
+ ctrl2);
if (ret < 0) {
dev_err(info->dev, "failed to update MUIC register\n");
return ret;
@@ -275,8 +277,9 @@ static int max14577_muic_get_cable_type(struct max14577_muic_info *info,
* Read ADC value to check cable type and decide cable state
* according to cable type
*/
- adc = info->status[MAX14577_MUIC_STATUS1] & STATUS1_ADC_MASK;
- adc >>= STATUS1_ADC_SHIFT;
+ adc = info->status[MAX14577_MUIC_STATUS1] &
+ MAXIM_STATUS1_ADC_MASK;
+ adc >>= MAXIM_STATUS1_ADC_SHIFT;
/*
* Check current cable state/cable type and store cable type
@@ -300,14 +303,14 @@ static int max14577_muic_get_cable_type(struct max14577_muic_info *info,
* according to type of charger cable.
*/
chg_type = info->status[MAX14577_MUIC_STATUS2] &
- STATUS2_CHGTYP_MASK;
- chg_type >>= STATUS2_CHGTYP_SHIFT;
+ MAXIM_STATUS2_CHGTYP_MASK;
+ chg_type >>= MAXIM_STATUS2_CHGTYP_SHIFT;
- if (chg_type == MAX14577_CHARGER_TYPE_NONE) {
+ if (chg_type == MAXIM_CHARGER_TYPE_NONE) {
*attached = false;
cable_type = info->prev_chg_type;
- info->prev_chg_type = MAX14577_CHARGER_TYPE_NONE;
+ info->prev_chg_type = MAXIM_CHARGER_TYPE_NONE;
} else {
*attached = true;
@@ -334,7 +337,7 @@ static int max14577_muic_jig_handler(struct max14577_muic_info *info,
{
char cable_name[32];
int ret = 0;
- u8 path = CTRL1_SW_OPEN;
+ u8 path = MAXIM_CONTROL1_SW_OPEN;
dev_dbg(info->dev,
"external connector is %s (adc:0x%02x)\n",
@@ -344,17 +347,17 @@ static int max14577_muic_jig_handler(struct max14577_muic_info *info,
case MAX14577_MUIC_ADC_FACTORY_MODE_USB_OFF: /* ADC_JIG_USB_OFF */
/* PATH:AP_USB */
strcpy(cable_name, "JIG-USB-OFF");
- path = CTRL1_SW_USB;
+ path = MAXIM_CONTROL1_SW_USB;
break;
case MAX14577_MUIC_ADC_FACTORY_MODE_USB_ON: /* ADC_JIG_USB_ON */
/* PATH:AP_USB */
strcpy(cable_name, "JIG-USB-ON");
- path = CTRL1_SW_USB;
+ path = MAXIM_CONTROL1_SW_USB;
break;
case MAX14577_MUIC_ADC_FACTORY_MODE_UART_OFF: /* ADC_JIG_UART_OFF */
/* PATH:AP_UART */
strcpy(cable_name, "JIG-UART-OFF");
- path = CTRL1_SW_UART;
+ path = MAXIM_CONTROL1_SW_UART;
break;
default:
dev_err(info->dev, "failed to detect %s jig cable\n",
@@ -457,7 +460,7 @@ static int max14577_muic_chg_handler(struct max14577_muic_info *info)
chg_type, info->prev_chg_type);
switch (chg_type) {
- case MAX14577_CHARGER_TYPE_USB:
+ case MAXIM_CHARGER_TYPE_USB:
/* PATH:AP_USB */
ret = max14577_muic_set_path(info, info->path_usb, attached);
if (ret < 0)
@@ -465,21 +468,21 @@ static int max14577_muic_chg_handler(struct max14577_muic_info *info)
extcon_set_cable_state(info->edev, "USB", attached);
break;
- case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
+ case MAXIM_CHARGER_TYPE_DEDICATED_CHG:
extcon_set_cable_state(info->edev, "TA", attached);
break;
- case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
+ case MAXIM_CHARGER_TYPE_DOWNSTREAM_PORT:
extcon_set_cable_state(info->edev,
"Charge-downstream", attached);
break;
- case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
+ case MAXIM_CHARGER_TYPE_SPECIAL_500MA:
extcon_set_cable_state(info->edev, "Slow-charger", attached);
break;
- case MAX14577_CHARGER_TYPE_SPECIAL_1A:
+ case MAXIM_CHARGER_TYPE_SPECIAL_1A:
extcon_set_cable_state(info->edev, "Fast-charger", attached);
break;
- case MAX14577_CHARGER_TYPE_NONE:
- case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
+ case MAXIM_CHARGER_TYPE_NONE:
+ case MAXIM_CHARGER_TYPE_DEAD_BATTERY:
break;
default:
dev_err(info->dev,
@@ -503,7 +506,7 @@ static void max14577_muic_irq_work(struct work_struct *work)
mutex_lock(&info->mutex);
ret = max14577_bulk_read(info->max14577->regmap,
- MAX14577_MUIC_REG_STATUS1, info->status, 2);
+ MAXIM_MUIC_REG_STATUS1, info->status, 2);
if (ret) {
dev_err(info->dev, "failed to read MUIC register\n");
mutex_unlock(&info->mutex);
@@ -543,18 +546,18 @@ static irqreturn_t max14577_muic_irq_handler(int irq, void *data)
irq_type = muic_irqs[i].irq;
switch (irq_type) {
- case MAX14577_IRQ_INT1_ADC:
- case MAX14577_IRQ_INT1_ADCLOW:
- case MAX14577_IRQ_INT1_ADCERR:
+ case MAXIM_IRQ_INT1_ADC:
+ case MAXIM_IRQ_INT1_ADCLOW:
+ case MAXIM_IRQ_INT1_ADCERR:
/* Handle all of accessory except for
type of charger accessory */
info->irq_adc = true;
break;
- case MAX14577_IRQ_INT2_CHGTYP:
- case MAX14577_IRQ_INT2_CHGDETRUN:
- case MAX14577_IRQ_INT2_DCDTMR:
- case MAX14577_IRQ_INT2_DBCHG:
- case MAX14577_IRQ_INT2_VBVOLT:
+ case MAXIM_IRQ_INT2_CHGTYP:
+ case MAXIM_IRQ_INT2_CHGDETRUN:
+ case MAXIM_IRQ_INT2_DCDTMR:
+ case MAXIM_IRQ_INT2_DBCHG:
+ case MAXIM_IRQ_INT2_VBVOLT:
/* Handle charger accessory */
info->irq_chg = true;
break;
@@ -579,7 +582,7 @@ static int max14577_muic_detect_accessory(struct max14577_muic_info *info)
/* Read STATUSx register to detect accessory */
ret = max14577_bulk_read(info->max14577->regmap,
- MAX14577_MUIC_REG_STATUS1, info->status, 2);
+ MAXIM_MUIC_REG_STATUS1, info->status, 2);
if (ret) {
dev_err(info->dev, "failed to read MUIC register\n");
mutex_unlock(&info->mutex);
@@ -599,7 +602,7 @@ static int max14577_muic_detect_accessory(struct max14577_muic_info *info)
chg_type = max14577_muic_get_cable_type(info, MAX14577_CABLE_GROUP_CHG,
&attached);
- if (attached && chg_type != MAX14577_CHARGER_TYPE_NONE) {
+ if (attached && chg_type != MAXIM_CHARGER_TYPE_NONE) {
ret = max14577_muic_chg_handler(info);
if (ret < 0) {
dev_err(info->dev, "Cannot detect charger accessory\n");
@@ -682,8 +685,8 @@ static int max14577_muic_probe(struct platform_device *pdev)
}
/* Default h/w line path */
- info->path_usb = CTRL1_SW_USB;
- info->path_uart = CTRL1_SW_UART;
+ info->path_usb = MAXIM_CONTROL1_SW_USB;
+ info->path_uart = MAXIM_CONTROL1_SW_UART;
delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
/* Set initial path for UART */
@@ -691,7 +694,7 @@ static int max14577_muic_probe(struct platform_device *pdev)
/* Check revision number of MUIC device*/
ret = max14577_read_reg(info->max14577->regmap,
- MAX14577_REG_DEVICEID, &id);
+ MAXIM_MUIC_REG_DEVICEID, &id);
if (ret < 0) {
dev_err(&pdev->dev, "failed to read revision number\n");
goto err_extcon;
diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index 2ac2f2d7cea6..d883055ca789 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -36,10 +36,10 @@ static struct mfd_cell max14577_devs[] = {
{ .name = "max14577-charger", },
};
-static bool max14577_volatile_reg(struct device *dev, unsigned int reg)
+static bool max14577_muic_volatile_reg(struct device *dev, unsigned int reg)
{
switch (reg) {
- case MAX14577_REG_INT1 ... MAX14577_REG_STATUS3:
+ case MAXIM_MUIC_REG_INT1 ... MAXIM_MUIC_REG_STATUS3:
return true;
default:
break;
@@ -47,35 +47,35 @@ static bool max14577_volatile_reg(struct device *dev, unsigned int reg)
return false;
}
-static const struct regmap_config max14577_regmap_config = {
+static const struct regmap_config max14577_muic_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
- .volatile_reg = max14577_volatile_reg,
- .max_register = MAX14577_REG_END,
+ .volatile_reg = max14577_muic_volatile_reg,
+ .max_register = MAXIM_MUIC_REG_END,
};
static const struct regmap_irq max14577_irqs[] = {
/* INT1 interrupts */
- { .reg_offset = 0, .mask = INT1_ADC_MASK, },
- { .reg_offset = 0, .mask = INT1_ADCLOW_MASK, },
- { .reg_offset = 0, .mask = INT1_ADCERR_MASK, },
+ { .reg_offset = 0, .mask = MAXIM_INT1_ADC_MASK, },
+ { .reg_offset = 0, .mask = MAXIM_INT1_ADCLOW_MASK, },
+ { .reg_offset = 0, .mask = MAXIM_INT1_ADCERR_MASK, },
/* INT2 interrupts */
- { .reg_offset = 1, .mask = INT2_CHGTYP_MASK, },
- { .reg_offset = 1, .mask = INT2_CHGDETRUN_MASK, },
- { .reg_offset = 1, .mask = INT2_DCDTMR_MASK, },
- { .reg_offset = 1, .mask = INT2_DBCHG_MASK, },
- { .reg_offset = 1, .mask = INT2_VBVOLT_MASK, },
+ { .reg_offset = 1, .mask = MAXIM_INT2_CHGTYP_MASK, },
+ { .reg_offset = 1, .mask = MAXIM_INT2_CHGDETRUN_MASK, },
+ { .reg_offset = 1, .mask = MAXIM_INT2_DCDTMR_MASK, },
+ { .reg_offset = 1, .mask = MAXIM_INT2_DBCHG_MASK, },
+ { .reg_offset = 1, .mask = MAXIM_INT2_VBVOLT_MASK, },
/* INT3 interrupts */
- { .reg_offset = 2, .mask = INT3_EOC_MASK, },
- { .reg_offset = 2, .mask = INT3_CGMBC_MASK, },
- { .reg_offset = 2, .mask = INT3_OVP_MASK, },
- { .reg_offset = 2, .mask = INT3_MBCCHGERR_MASK, },
+ { .reg_offset = 2, .mask = MAXIM_INT3_EOC_MASK, },
+ { .reg_offset = 2, .mask = MAXIM_INT3_CGMBC_MASK, },
+ { .reg_offset = 2, .mask = MAXIM_INT3_OVP_MASK, },
+ { .reg_offset = 2, .mask = MAXIM_INT3_MBCCHGERR_MASK, },
};
static const struct regmap_irq_chip max14577_irq_chip = {
.name = "max14577",
- .status_base = MAX14577_REG_INT1,
- .mask_base = MAX14577_REG_INTMASK1,
+ .status_base = MAXIM_MUIC_REG_INT1,
+ .mask_base = MAXIM_MUIC_REG_INTMASK1,
.mask_invert = 1,
.num_regs = 3,
.irqs = max14577_irqs,
@@ -112,7 +112,8 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
max14577->i2c = i2c;
max14577->irq = i2c->irq;
- max14577->regmap = devm_regmap_init_i2c(i2c, &max14577_regmap_config);
+ max14577->regmap = devm_regmap_init_i2c(i2c,
+ &max14577_muic_regmap_config);
if (IS_ERR(max14577->regmap)) {
ret = PTR_ERR(max14577->regmap);
dev_err(max14577->dev, "Failed to allocate register map: %d\n",
@@ -120,17 +121,17 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
return ret;
}
- ret = max14577_read_reg(max14577->regmap, MAX14577_REG_DEVICEID,
+ ret = max14577_read_reg(max14577->regmap, MAXIM_MUIC_REG_DEVICEID,
®_data);
if (ret) {
dev_err(max14577->dev, "Device not found on this channel: %d\n",
ret);
return ret;
}
- max14577->vendor_id = ((reg_data & DEVID_VENDORID_MASK) >>
- DEVID_VENDORID_SHIFT);
- max14577->device_id = ((reg_data & DEVID_DEVICEID_MASK) >>
- DEVID_DEVICEID_SHIFT);
+ max14577->vendor_id = ((reg_data & MAXIM_DEVID_VENDORID_MASK) >>
+ MAXIM_DEVID_VENDORID_SHIFT);
+ max14577->device_id = ((reg_data & MAXIM_DEVID_DEVICEID_MASK) >>
+ MAXIM_DEVID_DEVICEID_SHIFT);
dev_info(max14577->dev, "Device ID: 0x%x, vendor: 0x%x\n",
max14577->device_id, max14577->vendor_id);
diff --git a/drivers/power/max14577_charger.c b/drivers/power/max14577_charger.c
index fad2a75b3604..66a4e4edea42 100644
--- a/drivers/power/max14577_charger.c
+++ b/drivers/power/max14577_charger.c
@@ -46,14 +46,14 @@ static int max14577_get_charger_state(struct max14577_charger *chg)
* - handle properly dead-battery charging (respect timer)
* - handle timers (fast-charge and prequal) /MBCCHGERR/
*/
- max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL2, ®_data);
- if ((reg_data & CHGCTRL2_MBCHOSTEN_MASK) == 0)
+ max14577_read_reg(rmap, MAXIM_CHG_REG_CHGCTRL2, ®_data);
+ if ((reg_data & MAXIM_CHGCTRL2_MBCHOSTEN_MASK) == 0)
goto state_set;
- max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
- if (reg_data & STATUS3_CGMBC_MASK) {
+ max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS3, ®_data);
+ if (reg_data & MAXIM_STATUS3_CGMBC_MASK) {
/* Charger or USB-cable is connected */
- if (reg_data & STATUS3_EOC_MASK)
+ if (reg_data & MAXIM_STATUS3_EOC_MASK)
state = POWER_SUPPLY_STATUS_FULL;
else
state = POWER_SUPPLY_STATUS_CHARGING;
@@ -90,18 +90,19 @@ static int max14577_get_online(struct max14577_charger *chg)
struct regmap *rmap = chg->max14577->regmap;
u8 reg_data;
- max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data);
- reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT);
+ max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS2, ®_data);
+ reg_data = reg_data & MAXIM_STATUS2_CHGTYP_MASK;
+ reg_data >>= MAXIM_STATUS2_CHGTYP_SHIFT;
switch (reg_data) {
- case MAX14577_CHARGER_TYPE_USB:
- case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
- case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
- case MAX14577_CHARGER_TYPE_SPECIAL_1A:
- case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
+ case MAXIM_CHARGER_TYPE_USB:
+ case MAXIM_CHARGER_TYPE_DEDICATED_CHG:
+ case MAXIM_CHARGER_TYPE_SPECIAL_500MA:
+ case MAXIM_CHARGER_TYPE_SPECIAL_1A:
+ case MAXIM_CHARGER_TYPE_DEAD_BATTERY:
return 1;
- case MAX14577_CHARGER_TYPE_NONE:
- case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
- case MAX14577_CHARGER_TYPE_RESERVED:
+ case MAXIM_CHARGER_TYPE_NONE:
+ case MAXIM_CHARGER_TYPE_DOWNSTREAM_PORT:
+ case MAXIM_CHARGER_TYPE_RESERVED:
default:
return 0;
}
@@ -119,15 +120,16 @@ static int max14577_get_battery_health(struct max14577_charger *chg)
int state = POWER_SUPPLY_HEALTH_GOOD;
u8 reg_data;
- max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data);
- reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT);
- if (reg_data == MAX14577_CHARGER_TYPE_DEAD_BATTERY) {
+ max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS2, ®_data);
+ reg_data = reg_data & MAXIM_STATUS2_CHGTYP_MASK;
+ reg_data >>= MAXIM_STATUS2_CHGTYP_SHIFT;
+ if (reg_data == MAXIM_CHARGER_TYPE_DEAD_BATTERY) {
state = POWER_SUPPLY_HEALTH_DEAD;
goto state_set;
}
- max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
- if (reg_data & STATUS3_OVP_MASK) {
+ max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS3, ®_data);
+ if (reg_data & MAXIM_STATUS3_OVP_MASK) {
state = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
goto state_set;
}
@@ -162,46 +164,47 @@ static void max14577_charger_reg_init(struct max14577_charger *chg)
* Charger-Detection Enable, default on (set CHGDETEN to 1)
* Combined mask of CHGDETEN and CHGTYPMAN will zero the CHGTYPMAN bit
*/
- reg_data = 0x1 << CDETCTRL1_CHGDETEN_SHIFT;
- max14577_update_reg(rmap, MAX14577_REG_CDETCTRL1,
- CDETCTRL1_CHGDETEN_MASK | CDETCTRL1_CHGTYPMAN_MASK,
+ reg_data = 0x1 << MAXIM_CDETCTRL1_CHGDETEN_SHIFT;
+ max14577_update_reg(rmap, MAXIM_MUIC_REG_CDETCTRL1,
+ MAXIM_CDETCTRL1_CHGDETEN_MASK |
+ MAXIM_CDETCTRL1_CHGTYPMAN_MASK,
reg_data);
/* Battery Fast-Charge Timer, from SM-V700: 6hrs */
- reg_data = 0x3 << CHGCTRL1_TCHW_SHIFT;
- max14577_write_reg(rmap, MAX14577_REG_CHGCTRL1, reg_data);
+ reg_data = 0x3 << MAXIM_CHGCTRL1_TCHW_SHIFT;
+ max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL1, reg_data);
/*
* Wall-Adapter Rapid Charge, default on
* Battery-Charger, default on
*/
- reg_data = 0x1 << CHGCTRL2_VCHGR_RC_SHIFT;
- reg_data |= 0x1 << CHGCTRL2_MBCHOSTEN_SHIFT;
- max14577_write_reg(rmap, MAX14577_REG_CHGCTRL2, reg_data);
+ reg_data = 0x1 << MAXIM_CHGCTRL2_VCHGR_RC_SHIFT;
+ reg_data |= 0x1 << MAXIM_CHGCTRL2_MBCHOSTEN_SHIFT;
+ max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL2, reg_data);
/* Battery-Charger Constant Voltage (CV) Mode, from SM-V700: 4.35V */
- reg_data = 0xf << CHGCTRL3_MBCCVWRC_SHIFT;
- max14577_write_reg(rmap, MAX14577_REG_CHGCTRL3, reg_data);
+ reg_data = 0xf << MAXIM_CHGCTRL3_MBCCVWRC_SHIFT;
+ max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL3, reg_data);
/*
* Fast Battery-Charge Current Low, default 200-950mA
* Fast Battery-Charge Current High, from SM-V700: 450mA
*/
- reg_data = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT;
- reg_data |= 0x5 << CHGCTRL4_MBCICHWRCH_SHIFT;
- max14577_write_reg(rmap, MAX14577_REG_CHGCTRL4, reg_data);
+ reg_data = 0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
+ reg_data |= 0x5 << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT;
+ max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL4, reg_data);
/* End-of-Charge Current, from SM-V700: 50mA */
- reg_data = 0x0 << CHGCTRL5_EOCS_SHIFT;
- max14577_write_reg(rmap, MAX14577_REG_CHGCTRL5, reg_data);
+ reg_data = 0x0 << MAXIM_CHGCTRL5_EOCS_SHIFT;
+ max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL5, reg_data);
/* Auto Charging Stop, default off */
- reg_data = 0x0 << CHGCTRL6_AUTOSTOP_SHIFT;
- max14577_write_reg(rmap, MAX14577_REG_CHGCTRL6, reg_data);
+ reg_data = 0x0 << MAXIM_CHGCTRL6_AUTOSTOP_SHIFT;
+ max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL6, reg_data);
/* Overvoltage-Protection Threshold, from SM-V700: 6.5V */
- reg_data = 0x2 << CHGCTRL7_OTPCGHCVS_SHIFT;
- max14577_write_reg(rmap, MAX14577_REG_CHGCTRL7, reg_data);
+ reg_data = 0x2 << MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT;
+ max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL7, reg_data);
}
/* Support property from charger */
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c
index dc40c5ca4b75..9e5c0bd54684 100644
--- a/drivers/regulator/max14577.c
+++ b/drivers/regulator/max14577.c
@@ -30,11 +30,11 @@ static int max14577_reg_is_enabled(struct regulator_dev *rdev)
switch (rid) {
case MAX14577_CHARGER:
- max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL2, ®_data);
- if ((reg_data & CHGCTRL2_MBCHOSTEN_MASK) == 0)
+ max14577_read_reg(rmap, MAXIM_CHG_REG_CHGCTRL2, ®_data);
+ if ((reg_data & MAXIM_CHGCTRL2_MBCHOSTEN_MASK) == 0)
return 0;
- max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
- if ((reg_data & STATUS3_CGMBC_MASK) == 0)
+ max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS3, ®_data);
+ if ((reg_data & MAXIM_STATUS3_CGMBC_MASK) == 0)
return 0;
/* MBCHOSTEN and CGMBC are on */
return 1;
@@ -51,13 +51,13 @@ static int max14577_reg_get_current_limit(struct regulator_dev *rdev)
if (rdev_get_id(rdev) != MAX14577_CHARGER)
return -EINVAL;
- max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL4, ®_data);
+ max14577_read_reg(rmap, MAXIM_CHG_REG_CHGCTRL4, ®_data);
- if ((reg_data & CHGCTRL4_MBCICHWRCL_MASK) == 0)
+ if ((reg_data & MAXIM_CHGCTRL4_MBCICHWRCL_MASK) == 0)
return MAX14577_REGULATOR_CURRENT_LIMIT_MIN;
- reg_data = ((reg_data & CHGCTRL4_MBCICHWRCH_MASK) >>
- CHGCTRL4_MBCICHWRCH_SHIFT);
+ reg_data = ((reg_data & MAXIM_CHGCTRL4_MBCICHWRCH_MASK) >>
+ MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT);
return MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START +
reg_data * MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP;
}
@@ -77,10 +77,10 @@ static int max14577_reg_set_current_limit(struct regulator_dev *rdev,
if (max_uA < MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START) {
/* Less than 200 mA, so set 90mA (turn only Low Bit off) */
- u8 reg_data = 0x0 << CHGCTRL4_MBCICHWRCL_SHIFT;
+ u8 reg_data = 0x0 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
return max14577_update_reg(rdev->regmap,
- MAX14577_CHG_REG_CHG_CTRL4,
- CHGCTRL4_MBCICHWRCL_MASK, reg_data);
+ MAXIM_CHG_REG_CHGCTRL4,
+ MAXIM_CHGCTRL4_MBCICHWRCL_MASK, reg_data);
}
/* max_uA is in range: <LIMIT_HIGH_START, inifinite>, so search for
@@ -94,13 +94,13 @@ static int max14577_reg_set_current_limit(struct regulator_dev *rdev,
}
BUG_ON(current_bits < 0); /* Cannot happen */
/* Turn Low Bit on (use range 200mA-950 mA) */
- reg_data = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT;
+ reg_data = 0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
/* and set proper High Bits */
- reg_data |= current_bits << CHGCTRL4_MBCICHWRCH_SHIFT;
+ reg_data |= current_bits << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT;
- return max14577_update_reg(rdev->regmap, MAX14577_CHG_REG_CHG_CTRL4,
- CHGCTRL4_MBCICHWRCL_MASK | CHGCTRL4_MBCICHWRCH_MASK,
- reg_data);
+ return max14577_update_reg(rdev->regmap, MAXIM_CHG_REG_CHGCTRL4,
+ MAXIM_CHGCTRL4_MBCICHWRCL_MASK | MAXIM_CHGCTRL4_MBCICHWRCH_MASK,
+ reg_data);
}
static struct regulator_ops max14577_safeout_ops = {
@@ -127,8 +127,8 @@ static const struct regulator_desc supported_regulators[] = {
.owner = THIS_MODULE,
.n_voltages = 1,
.min_uV = MAX14577_REGULATOR_SAFEOUT_VOLTAGE,
- .enable_reg = MAX14577_REG_CONTROL2,
- .enable_mask = CTRL2_SFOUTORD_MASK,
+ .enable_reg = MAXIM_MUIC_REG_CONTROL2,
+ .enable_mask = MAXIM_CONTROL2_SFOUTORD_MASK,
},
[MAX14577_CHARGER] = {
.name = "CHARGER",
@@ -136,8 +136,8 @@ static const struct regulator_desc supported_regulators[] = {
.ops = &max14577_charger_ops,
.type = REGULATOR_CURRENT,
.owner = THIS_MODULE,
- .enable_reg = MAX14577_CHG_REG_CHG_CTRL2,
- .enable_mask = CHGCTRL2_MBCHOSTEN_MASK,
+ .enable_reg = MAXIM_CHG_REG_CHGCTRL2,
+ .enable_mask = MAXIM_CHGCTRL2_MBCHOSTEN_MASK,
},
};
@@ -159,7 +159,7 @@ static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
}
ret = of_regulator_match(&pdev->dev, np, max14577_regulator_matches,
- MAX14577_REG_MAX);
+ MAX14577_REG_NUM);
if (ret < 0) {
dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);
}
@@ -250,7 +250,7 @@ static int __init max14577_regulator_init(void)
BUILD_BUG_ON(MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START +
MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf !=
MAX14577_REGULATOR_CURRENT_LIMIT_MAX);
- BUILD_BUG_ON(ARRAY_SIZE(supported_regulators) != MAX14577_REG_MAX);
+ BUILD_BUG_ON(ARRAY_SIZE(supported_regulators) != MAX14577_REG_NUM);
return platform_driver_register(&max14577_regulator_driver);
}
diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
index c9b332fb0d5d..9f5ce26cb54e 100644
--- a/include/linux/mfd/max14577-private.h
+++ b/include/linux/mfd/max14577-private.h
@@ -22,224 +22,199 @@
#include <linux/i2c.h>
#include <linux/regmap.h>
-#define MAX14577_REG_INVALID (0xff)
-
-/* Slave addr = 0x4A: Interrupt */
-enum max14577_reg {
- MAX14577_REG_DEVICEID = 0x00,
- MAX14577_REG_INT1 = 0x01,
- MAX14577_REG_INT2 = 0x02,
- MAX14577_REG_INT3 = 0x03,
- MAX14577_REG_STATUS1 = 0x04,
- MAX14577_REG_STATUS2 = 0x05,
- MAX14577_REG_STATUS3 = 0x06,
- MAX14577_REG_INTMASK1 = 0x07,
- MAX14577_REG_INTMASK2 = 0x08,
- MAX14577_REG_INTMASK3 = 0x09,
- MAX14577_REG_CDETCTRL1 = 0x0A,
- MAX14577_REG_RFU = 0x0B,
- MAX14577_REG_CONTROL1 = 0x0C,
- MAX14577_REG_CONTROL2 = 0x0D,
- MAX14577_REG_CONTROL3 = 0x0E,
- MAX14577_REG_CHGCTRL1 = 0x0F,
- MAX14577_REG_CHGCTRL2 = 0x10,
- MAX14577_REG_CHGCTRL3 = 0x11,
- MAX14577_REG_CHGCTRL4 = 0x12,
- MAX14577_REG_CHGCTRL5 = 0x13,
- MAX14577_REG_CHGCTRL6 = 0x14,
- MAX14577_REG_CHGCTRL7 = 0x15,
-
- MAX14577_REG_END,
+/* Slave addr = 0x4A: MUIC and Charger */
+enum maxim_muic_reg {
+ MAXIM_MUIC_REG_DEVICEID = 0x00,
+ MAXIM_MUIC_REG_INT1 = 0x01,
+ MAXIM_MUIC_REG_INT2 = 0x02,
+ MAXIM_MUIC_REG_INT3 = 0x03,
+ MAXIM_MUIC_REG_STATUS1 = 0x04,
+ MAXIM_MUIC_REG_STATUS2 = 0x05,
+ MAXIM_MUIC_REG_STATUS3 = 0x06,
+ MAXIM_MUIC_REG_INTMASK1 = 0x07,
+ MAXIM_MUIC_REG_INTMASK2 = 0x08,
+ MAXIM_MUIC_REG_INTMASK3 = 0x09,
+ MAXIM_MUIC_REG_CDETCTRL1 = 0x0A,
+ MAXIM_MUIC_REG_RFU = 0x0B,
+ MAXIM_MUIC_REG_CONTROL1 = 0x0C,
+ MAXIM_MUIC_REG_CONTROL2 = 0x0D,
+ MAXIM_MUIC_REG_CONTROL3 = 0x0E,
+ MAXIM_CHG_REG_CHGCTRL1 = 0x0F,
+ MAXIM_CHG_REG_CHGCTRL2 = 0x10,
+ MAXIM_CHG_REG_CHGCTRL3 = 0x11,
+ MAXIM_CHG_REG_CHGCTRL4 = 0x12,
+ MAXIM_CHG_REG_CHGCTRL5 = 0x13,
+ MAXIM_CHG_REG_CHGCTRL6 = 0x14,
+ MAXIM_CHG_REG_CHGCTRL7 = 0x15,
+
+ MAXIM_MUIC_REG_END,
};
-/* Slave addr = 0x4A: MUIC */
-enum max14577_muic_reg {
- MAX14577_MUIC_REG_STATUS1 = 0x04,
- MAX14577_MUIC_REG_STATUS2 = 0x05,
- MAX14577_MUIC_REG_CONTROL1 = 0x0C,
- MAX14577_MUIC_REG_CONTROL3 = 0x0E,
-
- MAX14577_MUIC_REG_END,
-};
-
-enum max14577_muic_charger_type {
- MAX14577_CHARGER_TYPE_NONE = 0,
- MAX14577_CHARGER_TYPE_USB,
- MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT,
- MAX14577_CHARGER_TYPE_DEDICATED_CHG,
- MAX14577_CHARGER_TYPE_SPECIAL_500MA,
- MAX14577_CHARGER_TYPE_SPECIAL_1A,
- MAX14577_CHARGER_TYPE_RESERVED,
- MAX14577_CHARGER_TYPE_DEAD_BATTERY = 7,
+enum maxim_muic_charger_type {
+ MAXIM_CHARGER_TYPE_NONE = 0,
+ MAXIM_CHARGER_TYPE_USB,
+ MAXIM_CHARGER_TYPE_DOWNSTREAM_PORT,
+ MAXIM_CHARGER_TYPE_DEDICATED_CHG,
+ MAXIM_CHARGER_TYPE_SPECIAL_500MA,
+ MAXIM_CHARGER_TYPE_SPECIAL_1A,
+ MAXIM_CHARGER_TYPE_RESERVED,
+ MAXIM_CHARGER_TYPE_DEAD_BATTERY = 7,
};
/* MAX14577 interrupts */
-#define INT1_ADC_MASK (0x1 << 0)
-#define INT1_ADCLOW_MASK (0x1 << 1)
-#define INT1_ADCERR_MASK (0x1 << 2)
+#define MAXIM_INT1_ADC_MASK (0x1 << 0)
+#define MAXIM_INT1_ADCLOW_MASK (0x1 << 1)
+#define MAXIM_INT1_ADCERR_MASK (0x1 << 2)
-#define INT2_CHGTYP_MASK (0x1 << 0)
-#define INT2_CHGDETRUN_MASK (0x1 << 1)
-#define INT2_DCDTMR_MASK (0x1 << 2)
-#define INT2_DBCHG_MASK (0x1 << 3)
-#define INT2_VBVOLT_MASK (0x1 << 4)
+#define MAXIM_INT2_CHGTYP_MASK (0x1 << 0)
+#define MAXIM_INT2_CHGDETRUN_MASK (0x1 << 1)
+#define MAXIM_INT2_DCDTMR_MASK (0x1 << 2)
+#define MAXIM_INT2_DBCHG_MASK (0x1 << 3)
+#define MAXIM_INT2_VBVOLT_MASK (0x1 << 4)
-#define INT3_EOC_MASK (0x1 << 0)
-#define INT3_CGMBC_MASK (0x1 << 1)
-#define INT3_OVP_MASK (0x1 << 2)
-#define INT3_MBCCHGERR_MASK (0x1 << 3)
+#define MAXIM_INT3_EOC_MASK (0x1 << 0)
+#define MAXIM_INT3_CGMBC_MASK (0x1 << 1)
+#define MAXIM_INT3_OVP_MASK (0x1 << 2)
+#define MAXIM_INT3_MBCCHGERR_MASK (0x1 << 3)
/* MAX14577 DEVICE ID register */
-#define DEVID_VENDORID_SHIFT 0
-#define DEVID_DEVICEID_SHIFT 3
-#define DEVID_VENDORID_MASK (0x07 << DEVID_VENDORID_SHIFT)
-#define DEVID_DEVICEID_MASK (0x1f << DEVID_DEVICEID_SHIFT)
+#define MAXIM_DEVID_VENDORID_SHIFT 0
+#define MAXIM_DEVID_DEVICEID_SHIFT 3
+#define MAXIM_DEVID_VENDORID_MASK (0x07 << MAXIM_DEVID_VENDORID_SHIFT)
+#define MAXIM_DEVID_DEVICEID_MASK (0x1f << MAXIM_DEVID_DEVICEID_SHIFT)
/* MAX14577 STATUS1 register */
-#define STATUS1_ADC_SHIFT 0
-#define STATUS1_ADCLOW_SHIFT 5
-#define STATUS1_ADCERR_SHIFT 6
-#define STATUS1_ADC_MASK (0x1f << STATUS1_ADC_SHIFT)
-#define STATUS1_ADCLOW_MASK (0x1 << STATUS1_ADCLOW_SHIFT)
-#define STATUS1_ADCERR_MASK (0x1 << STATUS1_ADCERR_SHIFT)
+#define MAXIM_STATUS1_ADC_SHIFT 0
+#define MAXIM_STATUS1_ADCLOW_SHIFT 5
+#define MAXIM_STATUS1_ADCERR_SHIFT 6
+#define MAXIM_STATUS1_ADC_MASK (0x1f << MAXIM_STATUS1_ADC_SHIFT)
+#define MAXIM_STATUS1_ADCLOW_MASK (0x1 << MAXIM_STATUS1_ADCLOW_SHIFT)
+#define MAXIM_STATUS1_ADCERR_MASK (0x1 << MAXIM_STATUS1_ADCERR_SHIFT)
/* MAX14577 STATUS2 register */
-#define STATUS2_CHGTYP_SHIFT 0
-#define STATUS2_CHGDETRUN_SHIFT 3
-#define STATUS2_DCDTMR_SHIFT 4
-#define STATUS2_DBCHG_SHIFT 5
-#define STATUS2_VBVOLT_SHIFT 6
-#define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT)
-#define STATUS2_CHGDETRUN_MASK (0x1 << STATUS2_CHGDETRUN_SHIFT)
-#define STATUS2_DCDTMR_MASK (0x1 << STATUS2_DCDTMR_SHIFT)
-#define STATUS2_DBCHG_MASK (0x1 << STATUS2_DBCHG_SHIFT)
-#define STATUS2_VBVOLT_MASK (0x1 << STATUS2_VBVOLT_SHIFT)
+#define MAXIM_STATUS2_CHGTYP_SHIFT 0
+#define MAXIM_STATUS2_CHGDETRUN_SHIFT 3
+#define MAXIM_STATUS2_DCDTMR_SHIFT 4
+#define MAXIM_STATUS2_DBCHG_SHIFT 5
+#define MAXIM_STATUS2_VBVOLT_SHIFT 6
+#define MAXIM_STATUS2_CHGTYP_MASK (0x7 << MAXIM_STATUS2_CHGTYP_SHIFT)
+#define MAXIM_STATUS2_CHGDETRUN_MASK (0x1 << MAXIM_STATUS2_CHGDETRUN_SHIFT)
+#define MAXIM_STATUS2_DCDTMR_MASK (0x1 << MAXIM_STATUS2_DCDTMR_SHIFT)
+#define MAXIM_STATUS2_DBCHG_MASK (0x1 << MAXIM_STATUS2_DBCHG_SHIFT)
+#define MAXIM_STATUS2_VBVOLT_MASK (0x1 << MAXIM_STATUS2_VBVOLT_SHIFT)
+
+/* MAX14577 STATUS3 register */
+#define MAXIM_STATUS3_EOC_SHIFT 0
+#define MAXIM_STATUS3_CGMBC_SHIFT 1
+#define MAXIM_STATUS3_OVP_SHIFT 2
+#define MAXIM_STATUS3_MBCCHGERR_SHIFT 3
+#define MAXIM_STATUS3_EOC_MASK (0x1 << MAXIM_STATUS3_EOC_SHIFT)
+#define MAXIM_STATUS3_CGMBC_MASK (0x1 << MAXIM_STATUS3_CGMBC_SHIFT)
+#define MAXIM_STATUS3_OVP_MASK (0x1 << MAXIM_STATUS3_OVP_SHIFT)
+#define MAXIM_STATUS3_MBCCHGERR_MASK (0x1 << MAXIM_STATUS3_MBCCHGERR_SHIFT)
/* MAX14577 CONTROL1 register */
-#define COMN1SW_SHIFT 0
-#define COMP2SW_SHIFT 3
-#define MICEN_SHIFT 6
-#define IDBEN_SHIFT 7
-#define COMN1SW_MASK (0x7 << COMN1SW_SHIFT)
-#define COMP2SW_MASK (0x7 << COMP2SW_SHIFT)
-#define MICEN_MASK (0x1 << MICEN_SHIFT)
-#define IDBEN_MASK (0x1 << IDBEN_SHIFT)
-#define CLEAR_IDBEN_MICEN_MASK (COMN1SW_MASK | COMP2SW_MASK)
-#define CTRL1_SW_USB ((1 << COMP2SW_SHIFT) \
- | (1 << COMN1SW_SHIFT))
-#define CTRL1_SW_AUDIO ((2 << COMP2SW_SHIFT) \
- | (2 << COMN1SW_SHIFT))
-#define CTRL1_SW_UART ((3 << COMP2SW_SHIFT) \
- | (3 << COMN1SW_SHIFT))
-#define CTRL1_SW_OPEN ((0 << COMP2SW_SHIFT) \
- | (0 << COMN1SW_SHIFT))
+#define MAXIM_CONTROL1_COMN1SW_SHIFT 0
+#define MAXIM_CONTROL1_COMP2SW_SHIFT 3
+#define MAXIM_CONTROL1_MICEN_SHIFT 6
+#define MAXIM_CONTROL1_IDBEN_SHIFT 7
+#define MAXIM_CONTROL1_COMN1SW_MASK (0x7 << MAXIM_CONTROL1_COMN1SW_SHIFT)
+#define MAXIM_CONTROL1_COMP2SW_MASK (0x7 << MAXIM_CONTROL1_COMP2SW_SHIFT)
+#define MAXIM_CONTROL1_MICEN_MASK (0x1 << MAXIM_CONTROL1_MICEN_SHIFT)
+#define MAXIM_CONTROL1_IDBEN_MASK (0x1 << MAXIM_CONTROL1_IDBEN_SHIFT)
+
+#define MAXIM_CONTROL1_CLEAR_IDBEN_MICEN_MASK (MAXIM_CONTROL1_COMN1SW_MASK | MAXIM_CONTROL1_COMP2SW_MASK)
+#define MAXIM_CONTROL1_SW_USB ((1 << MAXIM_CONTROL1_COMP2SW_SHIFT) \
+ | (1 << MAXIM_CONTROL1_COMN1SW_SHIFT))
+#define MAXIM_CONTROL1_SW_AUDIO ((2 << MAXIM_CONTROL1_COMP2SW_SHIFT) \
+ | (2 << MAXIM_CONTROL1_COMN1SW_SHIFT))
+#define MAXIM_CONTROL1_SW_UART ((3 << MAXIM_CONTROL1_COMP2SW_SHIFT) \
+ | (3 << MAXIM_CONTROL1_COMN1SW_SHIFT))
+#define MAXIM_CONTROL1_SW_OPEN ((0 << MAXIM_CONTROL1_COMP2SW_SHIFT) \
+ | (0 << MAXIM_CONTROL1_COMN1SW_SHIFT))
/* MAX14577 CONTROL2 register */
-#define CTRL2_LOWPWR_SHIFT (0)
-#define CTRL2_ADCEN_SHIFT (1)
-#define CTRL2_CPEN_SHIFT (2)
-#define CTRL2_SFOUTASRT_SHIFT (3)
-#define CTRL2_SFOUTORD_SHIFT (4)
-#define CTRL2_ACCDET_SHIFT (5)
-#define CTRL2_USBCPINT_SHIFT (6)
-#define CTRL2_RCPS_SHIFT (7)
-#define CTRL2_LOWPWR_MASK (0x1 << CTRL2_LOWPWR_SHIFT)
-#define CTRL2_ADCEN_MASK (0x1 << CTRL2_ADCEN_SHIFT)
-#define CTRL2_CPEN_MASK (0x1 << CTRL2_CPEN_SHIFT)
-#define CTRL2_SFOUTASRT_MASK (0x1 << CTRL2_SFOUTASRT_SHIFT)
-#define CTRL2_SFOUTORD_MASK (0x1 << CTRL2_SFOUTORD_SHIFT)
-#define CTRL2_ACCDET_MASK (0x1 << CTRL2_ACCDET_SHIFT)
-#define CTRL2_USBCPINT_MASK (0x1 << CTRL2_USBCPINT_SHIFT)
-#define CTRL2_RCPS_MASK (0x1 << CTR2_RCPS_SHIFT)
-
-#define CTRL2_CPEN1_LOWPWR0 ((1 << CTRL2_CPEN_SHIFT) | \
- (0 << CTRL2_LOWPWR_SHIFT))
-#define CTRL2_CPEN0_LOWPWR1 ((0 << CTRL2_CPEN_SHIFT) | \
- (1 << CTRL2_LOWPWR_SHIFT))
+#define MAXIM_CONTROL2_LOWPWR_SHIFT 0
+#define MAXIM_CONTROL2_ADCEN_SHIFT 1
+#define MAXIM_CONTROL2_CPEN_SHIFT 2
+#define MAXIM_CONTROL2_SFOUTASRT_SHIFT 3
+#define MAXIM_CONTROL2_SFOUTORD_SHIFT 4
+#define MAXIM_CONTROL2_ACCDET_SHIFT 5
+#define MAXIM_CONTROL2_USBCPINT_SHIFT 6
+#define MAXIM_CONTROL2_RCPS_SHIFT 7
+#define MAXIM_CONTROL2_LOWPWR_MASK (0x1 << MAXIM_CONTROL2_LOWPWR_SHIFT)
+#define MAXIM_CONTROL2_ADCEN_MASK (0x1 << MAXIM_CONTROL2_ADCEN_SHIFT)
+#define MAXIM_CONTROL2_CPEN_MASK (0x1 << MAXIM_CONTROL2_CPEN_SHIFT)
+#define MAXIM_CONTROL2_SFOUTASRT_MASK (0x1 << MAXIM_CONTROL2_SFOUTASRT_SHIFT)
+#define MAXIM_CONTROL2_SFOUTORD_MASK (0x1 << MAXIM_CONTROL2_SFOUTORD_SHIFT)
+#define MAXIM_CONTROL2_ACCDET_MASK (0x1 << MAXIM_CONTROL2_ACCDET_SHIFT)
+#define MAXIM_CONTROL2_USBCPINT_MASK (0x1 << MAXIM_CONTROL2_USBCPINT_SHIFT)
+#define MAXIM_CONTROL2_RCPS_MASK (0x1 << MAXIM_CONTROL2_RCPS_SHIFT)
+
+#define MAXIM_CONTROL2_CPEN1_LOWPWR0 ((1 << MAXIM_CONTROL2_CPEN_SHIFT) | \
+ (0 << MAXIM_CONTROL2_LOWPWR_SHIFT))
+#define MAXIM_CONTROL2_CPEN0_LOWPWR1 ((0 << MAXIM_CONTROL2_CPEN_SHIFT) | \
+ (1 << MAXIM_CONTROL2_LOWPWR_SHIFT))
/* MAX14577 CONTROL3 register */
-#define CTRL3_JIGSET_SHIFT 0
-#define CTRL3_BOOTSET_SHIFT 2
-#define CTRL3_ADCDBSET_SHIFT 4
-#define CTRL3_JIGSET_MASK (0x3 << CTRL3_JIGSET_SHIFT)
-#define CTRL3_BOOTSET_MASK (0x3 << CTRL3_BOOTSET_SHIFT)
-#define CTRL3_ADCDBSET_MASK (0x3 << CTRL3_ADCDBSET_SHIFT)
-
-/* Slave addr = 0x4A: Charger */
-enum max14577_charger_reg {
- MAX14577_CHG_REG_STATUS3 = 0x06,
- MAX14577_CHG_REG_CHG_CTRL1 = 0x0F,
- MAX14577_CHG_REG_CHG_CTRL2 = 0x10,
- MAX14577_CHG_REG_CHG_CTRL3 = 0x11,
- MAX14577_CHG_REG_CHG_CTRL4 = 0x12,
- MAX14577_CHG_REG_CHG_CTRL5 = 0x13,
- MAX14577_CHG_REG_CHG_CTRL6 = 0x14,
- MAX14577_CHG_REG_CHG_CTRL7 = 0x15,
-
- MAX14577_CHG_REG_END,
-};
-
-/* MAX14577 STATUS3 register */
-#define STATUS3_EOC_SHIFT 0
-#define STATUS3_CGMBC_SHIFT 1
-#define STATUS3_OVP_SHIFT 2
-#define STATUS3_MBCCHGERR_SHIFT 3
-#define STATUS3_EOC_MASK (0x1 << STATUS3_EOC_SHIFT)
-#define STATUS3_CGMBC_MASK (0x1 << STATUS3_CGMBC_SHIFT)
-#define STATUS3_OVP_MASK (0x1 << STATUS3_OVP_SHIFT)
-#define STATUS3_MBCCHGERR_MASK (0x1 << STATUS3_MBCCHGERR_SHIFT)
+#define MAXIM_CONTROL3_JIGSET_SHIFT 0
+#define MAXIM_CONTROL3_BOOTSET_SHIFT 2
+#define MAXIM_CONTROL3_ADCDBSET_SHIFT 4
+#define MAXIM_CONTROL3_JIGSET_MASK (0x3 << MAXIM_CONTROL3_JIGSET_SHIFT)
+#define MAXIM_CONTROL3_BOOTSET_MASK (0x3 << MAXIM_CONTROL3_BOOTSET_SHIFT)
+#define MAXIM_CONTROL3_ADCDBSET_MASK (0x3 << MAXIM_CONTROL3_ADCDBSET_SHIFT)
/* MAX14577 CDETCTRL1 register */
-#define CDETCTRL1_CHGDETEN_SHIFT 0
-#define CDETCTRL1_CHGTYPMAN_SHIFT 1
-#define CDETCTRL1_DCDEN_SHIFT 2
-#define CDETCTRL1_DCD2SCT_SHIFT 3
-#define CDETCTRL1_DCHKTM_SHIFT 4
-#define CDETCTRL1_DBEXIT_SHIFT 5
-#define CDETCTRL1_DBIDLE_SHIFT 6
-#define CDETCTRL1_CDPDET_SHIFT 7
-#define CDETCTRL1_CHGDETEN_MASK (0x1 << CDETCTRL1_CHGDETEN_SHIFT)
-#define CDETCTRL1_CHGTYPMAN_MASK (0x1 << CDETCTRL1_CHGTYPMAN_SHIFT)
-#define CDETCTRL1_DCDEN_MASK (0x1 << CDETCTRL1_DCDEN_SHIFT)
-#define CDETCTRL1_DCD2SCT_MASK (0x1 << CDETCTRL1_DCD2SCT_SHIFT)
-#define CDETCTRL1_DCHKTM_MASK (0x1 << CDETCTRL1_DCHKTM_SHIFT)
-#define CDETCTRL1_DBEXIT_MASK (0x1 << CDETCTRL1_DBEXIT_SHIFT)
-#define CDETCTRL1_DBIDLE_MASK (0x1 << CDETCTRL1_DBIDLE_SHIFT)
-#define CDETCTRL1_CDPDET_MASK (0x1 << CDETCTRL1_CDPDET_SHIFT)
-
-/* MAX14577 CHGCTRL1 register */
-#define CHGCTRL1_TCHW_SHIFT 4
-#define CHGCTRL1_TCHW_MASK (0x7 << CHGCTRL1_TCHW_SHIFT)
-
-/* MAX14577 CHGCTRL2 register */
-#define CHGCTRL2_MBCHOSTEN_SHIFT 6
-#define CHGCTRL2_MBCHOSTEN_MASK (0x1 << CHGCTRL2_MBCHOSTEN_SHIFT)
-#define CHGCTRL2_VCHGR_RC_SHIFT 7
-#define CHGCTRL2_VCHGR_RC_MASK (0x1 << CHGCTRL2_VCHGR_RC_SHIFT)
-
-/* MAX14577 CHGCTRL3 register */
-#define CHGCTRL3_MBCCVWRC_SHIFT 0
-#define CHGCTRL3_MBCCVWRC_MASK (0xf << CHGCTRL3_MBCCVWRC_SHIFT)
-
-/* MAX14577 CHGCTRL4 register */
-#define CHGCTRL4_MBCICHWRCH_SHIFT 0
-#define CHGCTRL4_MBCICHWRCH_MASK (0xf << CHGCTRL4_MBCICHWRCH_SHIFT)
-#define CHGCTRL4_MBCICHWRCL_SHIFT 4
-#define CHGCTRL4_MBCICHWRCL_MASK (0x1 << CHGCTRL4_MBCICHWRCL_SHIFT)
-
-/* MAX14577 CHGCTRL5 register */
-#define CHGCTRL5_EOCS_SHIFT 0
-#define CHGCTRL5_EOCS_MASK (0xf << CHGCTRL5_EOCS_SHIFT)
-
-/* MAX14577 CHGCTRL6 register */
-#define CHGCTRL6_AUTOSTOP_SHIFT 5
-#define CHGCTRL6_AUTOSTOP_MASK (0x1 << CHGCTRL6_AUTOSTOP_SHIFT)
-
-/* MAX14577 CHGCTRL7 register */
-#define CHGCTRL7_OTPCGHCVS_SHIFT 0
-#define CHGCTRL7_OTPCGHCVS_MASK (0x3 << CHGCTRL7_OTPCGHCVS_SHIFT)
-
-/* MAX14577 regulator current limits (as in CHGCTRL4 register), uA */
+#define MAXIM_CDETCTRL1_CHGDETEN_SHIFT 0
+#define MAXIM_CDETCTRL1_CHGTYPMAN_SHIFT 1
+#define MAXIM_CDETCTRL1_DCDEN_SHIFT 2
+#define MAXIM_CDETCTRL1_DCD2SCT_SHIFT 3
+#define MAXIM_CDETCTRL1_DCHKTM_SHIFT 4
+#define MAXIM_CDETCTRL1_DBEXIT_SHIFT 5
+#define MAXIM_CDETCTRL1_DBIDLE_SHIFT 6
+#define MAXIM_CDETCTRL1_CDPDET_SHIFT 7
+#define MAXIM_CDETCTRL1_CHGDETEN_MASK (0x1 << MAXIM_CDETCTRL1_CHGDETEN_SHIFT)
+#define MAXIM_CDETCTRL1_CHGTYPMAN_MASK (0x1 << MAXIM_CDETCTRL1_CHGTYPMAN_SHIFT)
+#define MAXIM_CDETCTRL1_DCDEN_MASK (0x1 << MAXIM_CDETCTRL1_DCDEN_SHIFT)
+#define MAXIM_CDETCTRL1_DCD2SCT_MASK (0x1 << MAXIM_CDETCTRL1_DCD2SCT_SHIFT)
+#define MAXIM_CDETCTRL1_DCHKTM_MASK (0x1 << MAXIM_CDETCTRL1_DCHKTM_SHIFT)
+#define MAXIM_CDETCTRL1_DBEXIT_MASK (0x1 << MAXIM_CDETCTRL1_DBEXIT_SHIFT)
+#define MAXIM_CDETCTRL1_DBIDLE_MASK (0x1 << MAXIM_CDETCTRL1_DBIDLE_SHIFT)
+#define MAXIM_CDETCTRL1_CDPDET_MASK (0x1 << MAXIM_CDETCTRL1_CDPDET_SHIFT)
+
+/* MAX14577 MAXIM_CHGCTRL1 register */
+#define MAXIM_CHGCTRL1_TCHW_SHIFT 4
+#define MAXIM_CHGCTRL1_TCHW_MASK (0x7 << MAXIM_CHGCTRL1_TCHW_SHIFT)
+
+/* MAX14577 MAXIM_CHGCTRL2 register */
+#define MAXIM_CHGCTRL2_MBCHOSTEN_SHIFT 6
+#define MAXIM_CHGCTRL2_MBCHOSTEN_MASK (0x1 << MAXIM_CHGCTRL2_MBCHOSTEN_SHIFT)
+#define MAXIM_CHGCTRL2_VCHGR_RC_SHIFT 7
+#define MAXIM_CHGCTRL2_VCHGR_RC_MASK (0x1 << MAXIM_CHGCTRL2_VCHGR_RC_SHIFT)
+
+/* MAX14577 MAXIM_CHGCTRL3 register */
+#define MAXIM_CHGCTRL3_MBCCVWRC_SHIFT 0
+#define MAXIM_CHGCTRL3_MBCCVWRC_MASK (0xf << MAXIM_CHGCTRL3_MBCCVWRC_SHIFT)
+
+/* MAX14577 MAXIM_CHGCTRL4 register */
+#define MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT 0
+#define MAXIM_CHGCTRL4_MBCICHWRCH_MASK (0xf << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT)
+#define MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT 4
+#define MAXIM_CHGCTRL4_MBCICHWRCL_MASK (0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT)
+
+/* MAX14577 MAXIM_CHGCTRL5 register */
+#define MAXIM_CHGCTRL5_EOCS_SHIFT 0
+#define MAXIM_CHGCTRL5_EOCS_MASK (0xf << MAXIM_CHGCTRL5_EOCS_SHIFT)
+
+/* MAX14577 MAXIM_CHGCTRL6 register */
+#define MAXIM_CHGCTRL6_AUTOSTOP_SHIFT 5
+#define MAXIM_CHGCTRL6_AUTOSTOP_MASK (0x1 << MAXIM_CHGCTRL6_AUTOSTOP_SHIFT)
+
+/* MAX14577 MAXIM_CHGCTRL7 register */
+#define MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT 0
+#define MAXIM_CHGCTRL7_OTPCGHCVS_MASK (0x3 << MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT)
+
+/* MAX14577 regulator current limits (as in MAXIM_CHGCTRL4 register), uA */
#define MAX14577_REGULATOR_CURRENT_LIMIT_MIN 90000
#define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START 200000
#define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP 50000
@@ -248,26 +223,28 @@ enum max14577_charger_reg {
/* MAX14577 regulator SFOUT LDO voltage, fixed, uV */
#define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000
-enum max14577_irq {
+
+
+enum maxim_irq {
/* INT1 */
- MAX14577_IRQ_INT1_ADC,
- MAX14577_IRQ_INT1_ADCLOW,
- MAX14577_IRQ_INT1_ADCERR,
+ MAXIM_IRQ_INT1_ADC,
+ MAXIM_IRQ_INT1_ADCLOW,
+ MAXIM_IRQ_INT1_ADCERR,
/* INT2 */
- MAX14577_IRQ_INT2_CHGTYP,
- MAX14577_IRQ_INT2_CHGDETRUN,
- MAX14577_IRQ_INT2_DCDTMR,
- MAX14577_IRQ_INT2_DBCHG,
- MAX14577_IRQ_INT2_VBVOLT,
+ MAXIM_IRQ_INT2_CHGTYP,
+ MAXIM_IRQ_INT2_CHGDETRUN,
+ MAXIM_IRQ_INT2_DCDTMR,
+ MAXIM_IRQ_INT2_DBCHG,
+ MAXIM_IRQ_INT2_VBVOLT,
/* INT3 */
- MAX14577_IRQ_INT3_EOC,
- MAX14577_IRQ_INT3_CGMBC,
- MAX14577_IRQ_INT3_OVP,
- MAX14577_IRQ_INT3_MBCCHGERR,
+ MAXIM_IRQ_INT3_EOC,
+ MAXIM_IRQ_INT3_CGMBC,
+ MAXIM_IRQ_INT3_OVP,
+ MAXIM_IRQ_INT3_MBCCHGERR,
- MAX14577_IRQ_NUM,
+ MAXIM_IRQ_NUM,
};
struct max14577 {
diff --git a/include/linux/mfd/max14577.h b/include/linux/mfd/max14577.h
index 736d39c3ec0d..75301be5c548 100644
--- a/include/linux/mfd/max14577.h
+++ b/include/linux/mfd/max14577.h
@@ -32,7 +32,7 @@ enum max14577_regulators {
MAX14577_SAFEOUT = 0,
MAX14577_CHARGER,
- MAX14577_REG_MAX,
+ MAX14577_REG_NUM,
};
struct max14577_regulator_platform_data {
--
1.7.9.5
This patch continues the preparation for adding support for max77836
device to existing max14577 driver.
Add enum for types of devices supported by this driver. The device type
will be detected by matching of_device_id, or i2c_device_id as a
fallback.
The patch also moves to separate function the code related to displaying
DeviceID register values.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Acked-by: Lee Jones <[email protected]>
---
drivers/mfd/max14577.c | 64 ++++++++++++++++++++++++----------
include/linux/mfd/max14577-private.h | 12 ++++---
2 files changed, 53 insertions(+), 23 deletions(-)
diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index 449e025bd80d..772088cf3ab8 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -20,6 +20,7 @@
#include <linux/module.h>
#include <linux/interrupt.h>
+#include <linux/of_device.h>
#include <linux/mfd/core.h>
#include <linux/mfd/max14577.h>
#include <linux/mfd/max14577-private.h>
@@ -36,6 +37,14 @@ static struct mfd_cell max14577_devs[] = {
{ .name = "max14577-charger", },
};
+static struct of_device_id max14577_dt_match[] = {
+ {
+ .compatible = "maxim,max14577",
+ .data = (void *)MAXIM_DEVICE_TYPE_MAX14577,
+ },
+ {},
+};
+
static bool max14577_muic_volatile_reg(struct device *dev, unsigned int reg)
{
switch (reg) {
@@ -82,13 +91,34 @@ static const struct regmap_irq_chip max14577_irq_chip = {
.num_irqs = ARRAY_SIZE(max14577_irqs),
};
+static void max14577_print_dev_type(struct maxim_core *maxim_core)
+{
+ u8 reg_data, vendor_id, device_id;
+ int ret;
+
+ ret = max14577_read_reg(maxim_core->regmap_muic,
+ MAXIM_MUIC_REG_DEVICEID, ®_data);
+ if (ret) {
+ dev_err(maxim_core->dev,
+ "Failed to read DEVICEID register: %d\n", ret);
+ return;
+ }
+
+ vendor_id = ((reg_data & MAXIM_DEVID_VENDORID_MASK) >>
+ MAXIM_DEVID_VENDORID_SHIFT);
+ device_id = ((reg_data & MAXIM_DEVID_DEVICEID_MASK) >>
+ MAXIM_DEVID_DEVICEID_SHIFT);
+
+ dev_info(maxim_core->dev, "Device type: %u (ID: 0x%x, vendor: 0x%x)\n",
+ maxim_core->dev_type, device_id, vendor_id);
+}
+
static int max14577_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
struct maxim_core *maxim_core;
struct max14577_platform_data *pdata = dev_get_platdata(&i2c->dev);
struct device_node *np = i2c->dev.of_node;
- u8 reg_data;
int ret = 0;
if (np) {
@@ -121,19 +151,17 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
return ret;
}
- ret = max14577_read_reg(maxim_core->regmap_muic,
- MAXIM_MUIC_REG_DEVICEID, ®_data);
- if (ret) {
- dev_err(maxim_core->dev, "Device not found on this channel: %d\n",
- ret);
- return ret;
+ if (np) {
+ const struct of_device_id *of_id;
+
+ of_id = of_match_device(max14577_dt_match, &i2c->dev);
+ if (of_id)
+ maxim_core->dev_type = (unsigned int)of_id->data;
+ } else {
+ maxim_core->dev_type = id->driver_data;
}
- maxim_core->vendor_id = ((reg_data & MAXIM_DEVID_VENDORID_MASK) >>
- MAXIM_DEVID_VENDORID_SHIFT);
- maxim_core->device_id = ((reg_data & MAXIM_DEVID_DEVICEID_MASK) >>
- MAXIM_DEVID_DEVICEID_SHIFT);
- dev_info(maxim_core->dev, "Device ID: 0x%x, vendor: 0x%x\n",
- maxim_core->device_id, maxim_core->vendor_id);
+
+ max14577_print_dev_type(maxim_core);
ret = regmap_add_irq_chip(maxim_core->regmap_muic, maxim_core->irq,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 0,
@@ -172,7 +200,7 @@ static int max14577_i2c_remove(struct i2c_client *i2c)
}
static const struct i2c_device_id max14577_i2c_id[] = {
- { "max14577", 0 },
+ { "max14577", MAXIM_DEVICE_TYPE_MAX14577, },
{ }
};
MODULE_DEVICE_TABLE(i2c, max14577_i2c_id);
@@ -213,11 +241,6 @@ static int max14577_resume(struct device *dev)
return 0;
}
-static struct of_device_id max14577_dt_match[] = {
- { .compatible = "maxim,max14577", },
- {},
-};
-
static SIMPLE_DEV_PM_OPS(max14577_pm, max14577_suspend, max14577_resume);
static struct i2c_driver max14577_i2c_driver = {
@@ -234,6 +257,9 @@ static struct i2c_driver max14577_i2c_driver = {
static int __init max14577_i2c_init(void)
{
+ BUILD_BUG_ON(ARRAY_SIZE(max14577_i2c_id) != MAXIM_DEVICE_TYPE_NUM);
+ BUILD_BUG_ON(ARRAY_SIZE(max14577_dt_match) != MAXIM_DEVICE_TYPE_NUM);
+
return i2c_add_driver(&max14577_i2c_driver);
}
subsys_initcall(max14577_i2c_init);
diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
index d69c56f02eac..afa4e525f9b7 100644
--- a/include/linux/mfd/max14577-private.h
+++ b/include/linux/mfd/max14577-private.h
@@ -22,6 +22,13 @@
#include <linux/i2c.h>
#include <linux/regmap.h>
+enum maxim_device_type {
+ MAXIM_DEVICE_TYPE_UNKNOWN = 0,
+ MAXIM_DEVICE_TYPE_MAX14577,
+
+ MAXIM_DEVICE_TYPE_NUM,
+};
+
/* Slave addr = 0x4A: MUIC and Charger */
enum maxim_muic_reg {
MAXIM_MUIC_REG_DEVICEID = 0x00,
@@ -250,15 +257,12 @@ enum maxim_irq {
struct maxim_core {
struct device *dev;
struct i2c_client *i2c; /* Slave addr = 0x4A */
+ enum maxim_device_type dev_type;
struct regmap *regmap_muic;
struct regmap_irq_chip_data *irq_data_muic;
int irq;
-
- /* Device ID */
- u8 vendor_id; /* Vendor Identification */
- u8 device_id; /* Chip Version */
};
/* MAX14577 shared regmap API function */
--
1.7.9.5
This patch continues the preparation for adding support for max77836
device to existing max14577 driver.
During probe choose muic_irqs according to device type. Currently there
are only "max14577_muic_irqs" but later patch will add max77836
interrupts.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Acked-by: Chanwoo Choi <[email protected]>
Tested-by: Chanwoo Choi <[email protected]>
---
drivers/extcon/extcon-max14577.c | 65 ++++++++++++++++++++++----------------
1 file changed, 37 insertions(+), 28 deletions(-)
diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index fb343f4042d2..e986a9b92b60 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -39,6 +39,29 @@ enum max14577_muic_status {
MAX14577_MUIC_STATUS_END,
};
+/**
+ * struct max14577_muic_irq
+ * @irq: the index of irq list of MUIC device.
+ * @name: the name of irq.
+ * @virq: the virtual irq to use irq domain
+ */
+struct max14577_muic_irq {
+ unsigned int irq;
+ const char *name;
+ unsigned int virq;
+};
+
+static struct max14577_muic_irq max14577_muic_irqs[] = {
+ { MAXIM_IRQ_INT1_ADC, "muic-ADC" },
+ { MAXIM_IRQ_INT1_ADCLOW, "muic-ADCLOW" },
+ { MAXIM_IRQ_INT1_ADCERR, "muic-ADCError" },
+ { MAXIM_IRQ_INT2_CHGTYP, "muic-CHGTYP" },
+ { MAXIM_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" },
+ { MAXIM_IRQ_INT2_DCDTMR, "muic-DCDTMR" },
+ { MAXIM_IRQ_INT2_DBCHG, "muic-DBCHG" },
+ { MAXIM_IRQ_INT2_VBVOLT, "muic-VBVOLT" },
+};
+
struct max14577_muic_info {
struct device *dev;
struct maxim_core *maxim_core;
@@ -47,6 +70,8 @@ struct max14577_muic_info {
int prev_chg_type;
u8 status[MAX14577_MUIC_STATUS_END];
+ struct max14577_muic_irq *muic_irqs;
+ unsigned int muic_irqs_num;
bool irq_adc;
bool irq_chg;
struct work_struct irq_work;
@@ -73,29 +98,6 @@ enum max14577_muic_cable_group {
MAX14577_CABLE_GROUP_CHG,
};
-/**
- * struct max14577_muic_irq
- * @irq: the index of irq list of MUIC device.
- * @name: the name of irq.
- * @virq: the virtual irq to use irq domain
- */
-struct max14577_muic_irq {
- unsigned int irq;
- const char *name;
- unsigned int virq;
-};
-
-static struct max14577_muic_irq max14577_muic_irqs[] = {
- { MAXIM_IRQ_INT1_ADC, "muic-ADC" },
- { MAXIM_IRQ_INT1_ADCLOW, "muic-ADCLOW" },
- { MAXIM_IRQ_INT1_ADCERR, "muic-ADCError" },
- { MAXIM_IRQ_INT2_CHGTYP, "muic-CHGTYP" },
- { MAXIM_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" },
- { MAXIM_IRQ_INT2_DCDTMR, "muic-DCDTMR" },
- { MAXIM_IRQ_INT2_DBCHG, "muic-DBCHG" },
- { MAXIM_IRQ_INT2_VBVOLT, "muic-VBVOLT" },
-};
-
/* Define supported accessory type */
enum max14577_muic_acc_type {
MAX14577_MUIC_ADC_GROUND = 0x0,
@@ -541,9 +543,9 @@ static irqreturn_t max14577_muic_irq_handler(int irq, void *data)
* However we only need to know whether it was ADC, charger
* or both interrupts so decode IRQ and turn on proper flags.
*/
- for (i = 0; i < ARRAY_SIZE(max14577_muic_irqs); i++)
- if (irq == max14577_muic_irqs[i].virq)
- irq_type = max14577_muic_irqs[i].irq;
+ for (i = 0; i < info->muic_irqs_num; i++)
+ if (irq == info->muic_irqs[i].virq)
+ irq_type = info->muic_irqs[i].irq;
switch (irq_type) {
case MAXIM_IRQ_INT1_ADC:
@@ -646,9 +648,16 @@ static int max14577_muic_probe(struct platform_device *pdev)
INIT_WORK(&info->irq_work, max14577_muic_irq_work);
+ switch (maxim_core->dev_type) {
+ case MAXIM_DEVICE_TYPE_MAX14577:
+ default:
+ info->muic_irqs = max14577_muic_irqs;
+ info->muic_irqs_num = ARRAY_SIZE(max14577_muic_irqs);
+ }
+
/* Support irq domain for max14577 MUIC device */
- for (i = 0; i < ARRAY_SIZE(max14577_muic_irqs); i++) {
- struct max14577_muic_irq *muic_irq = &max14577_muic_irqs[i];
+ for (i = 0; i < info->muic_irqs_num; i++) {
+ struct max14577_muic_irq *muic_irq = &info->muic_irqs[i];
unsigned int virq = 0;
virq = regmap_irq_get_virq(maxim_core->irq_data_muic,
--
1.7.9.5
> diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
> index a8cd7de3526a..fc69d7beb1aa 100644
> --- a/include/linux/mfd/max14577-private.h
> +++ b/include/linux/mfd/max14577-private.h
> @@ -269,6 +269,20 @@ enum maxim_muic_charger_type {
> #define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP 25000U
> #define MAX77836_CHARGER_CURRENT_LIMIT_MAX 475000U
>
> +/* MAX14577 charger End-Of-Charge current limits
> + * (as in MAXIM_CHGCTRL5 register), uA
> + */
> +#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN 50000U
> +#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP 10000U
> +#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX 200000U
> +
> +/* MAX14577/MAX77836 Battery Constant Voltage
> + * (as in MAXIM_CHGCTRL3 register), uV
> + */
These are not proper multi-line comments.
Documentation/CodingSytle:
The preferred style for long (multi-line) comments is:
/*
* This is the preferred style for multi-line
* comments in the Linux kernel source code.
* Please use it consistently.
*
* Description: A column of asterisks on the left side,
* with beginning and ending almost-blank lines.
*/
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
On Mon, 2014-02-17 at 10:07 +0000, Lee Jones wrote:
> > diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
> > index a8cd7de3526a..fc69d7beb1aa 100644
> > --- a/include/linux/mfd/max14577-private.h
> > +++ b/include/linux/mfd/max14577-private.h
> > @@ -269,6 +269,20 @@ enum maxim_muic_charger_type {
> > #define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP 25000U
> > #define MAX77836_CHARGER_CURRENT_LIMIT_MAX 475000U
> >
> > +/* MAX14577 charger End-Of-Charge current limits
> > + * (as in MAXIM_CHGCTRL5 register), uA
> > + */
> > +#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN 50000U
> > +#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP 10000U
> > +#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX 200000U
> > +
> > +/* MAX14577/MAX77836 Battery Constant Voltage
> > + * (as in MAXIM_CHGCTRL3 register), uV
> > + */
>
> These are not proper multi-line comments.
>
> Documentation/CodingSytle:
>
> The preferred style for long (multi-line) comments is:
>
> /*
> * This is the preferred style for multi-line
> * comments in the Linux kernel source code.
> * Please use it consistently.
> *
> * Description: A column of asterisks on the left side,
> * with beginning and ending almost-blank lines.
> */
Sure. Sorry for bugging with such trivial mistakes.
Best regards,
Krzysztof
> > > diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
> > > index a8cd7de3526a..fc69d7beb1aa 100644
> > > --- a/include/linux/mfd/max14577-private.h
> > > +++ b/include/linux/mfd/max14577-private.h
> > > @@ -269,6 +269,20 @@ enum maxim_muic_charger_type {
> > > #define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP 25000U
> > > #define MAX77836_CHARGER_CURRENT_LIMIT_MAX 475000U
> > >
> > > +/* MAX14577 charger End-Of-Charge current limits
> > > + * (as in MAXIM_CHGCTRL5 register), uA
> > > + */
> > > +#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN 50000U
> > > +#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP 10000U
> > > +#define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX 200000U
> > > +
> > > +/* MAX14577/MAX77836 Battery Constant Voltage
> > > + * (as in MAXIM_CHGCTRL3 register), uV
> > > + */
> >
> > These are not proper multi-line comments.
> >
> > Documentation/CodingSytle:
> >
> > The preferred style for long (multi-line) comments is:
> >
> > /*
> > * This is the preferred style for multi-line
> > * comments in the Linux kernel source code.
> > * Please use it consistently.
> > *
> > * Description: A column of asterisks on the left side,
> > * with beginning and ending almost-blank lines.
> > */
>
> Sure. Sorry for bugging with such trivial mistakes.
That's okay.
Just fix it up and apply my:
Acked-by: Lee Jones <[email protected]>
No need to resubmit over this. Concentrate on the other Acks now.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
Dear Mark, Dmitry, David and Anton,
I want to push whole MAX77836 patchset through Lee Jones' MFD tree and I
still need acks from power and regulator subsystems.
I would appreciate if you could find time to look at these patches and
let me know your opinion (or just add Acked-by):
[PATCH v3 02/15] mfd: max14577: Rename and add MAX14577 symbols...
[PATCH v3 03/15] mfd: max14577: Rename state container to maxim_core
[PATCH v3 04/15] mfd: max14577: Add "muic" suffix to regmap and irq_chip
These are rename/preparation patches and also they're kind a blockers for entire patchset.
Best regards,
Krzysztof
On Mon, 2014-02-17 at 10:05 +0100, Krzysztof Kozlowski wrote:
> This patch prepares for adding support for max77836 device to existing
> max14577 driver:
> 1. Renames most of symbols and defines prefixed with MAX14577 to MAXIM.
> 2. Adds prefixes (MAXIM or MAX14577) to defines without any MAX* prefix.
>
> This is only a rename-like patch, new code is not added.
>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> Cc: Kyungmin Park <[email protected]>
> Cc: Marek Szyprowski <[email protected]>
> Cc: Anton Vorontsov <[email protected]>
> Cc: Dmitry Eremin-Solenikov <[email protected]>
> Cc: David Woodhouse <[email protected]>
> Acked-by: Lee Jones <[email protected]>
> Acked-by: Chanwoo Choi <[email protected]>
> ---
> drivers/extcon/extcon-max14577.c | 105 ++++-----
> drivers/mfd/max14577.c | 51 ++---
> drivers/power/max14577_charger.c | 81 +++----
> drivers/regulator/max14577.c | 44 ++--
> include/linux/mfd/max14577-private.h | 399 ++++++++++++++++------------------
> include/linux/mfd/max14577.h | 2 +-
> 6 files changed, 333 insertions(+), 349 deletions(-)
>
> diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
> index 59f084fee4f3..6f7145a929cf 100644
> --- a/drivers/extcon/extcon-max14577.c
> +++ b/drivers/extcon/extcon-max14577.c
> @@ -86,14 +86,14 @@ struct max14577_muic_irq {
> };
>
> static struct max14577_muic_irq muic_irqs[] = {
> - { MAX14577_IRQ_INT1_ADC, "muic-ADC" },
> - { MAX14577_IRQ_INT1_ADCLOW, "muic-ADCLOW" },
> - { MAX14577_IRQ_INT1_ADCERR, "muic-ADCError" },
> - { MAX14577_IRQ_INT2_CHGTYP, "muic-CHGTYP" },
> - { MAX14577_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" },
> - { MAX14577_IRQ_INT2_DCDTMR, "muic-DCDTMR" },
> - { MAX14577_IRQ_INT2_DBCHG, "muic-DBCHG" },
> - { MAX14577_IRQ_INT2_VBVOLT, "muic-VBVOLT" },
> + { MAXIM_IRQ_INT1_ADC, "muic-ADC" },
> + { MAXIM_IRQ_INT1_ADCLOW, "muic-ADCLOW" },
> + { MAXIM_IRQ_INT1_ADCERR, "muic-ADCError" },
> + { MAXIM_IRQ_INT2_CHGTYP, "muic-CHGTYP" },
> + { MAXIM_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" },
> + { MAXIM_IRQ_INT2_DCDTMR, "muic-DCDTMR" },
> + { MAXIM_IRQ_INT2_DBCHG, "muic-DBCHG" },
> + { MAXIM_IRQ_INT2_VBVOLT, "muic-VBVOLT" },
> };
>
> /* Define supported accessory type */
> @@ -177,9 +177,9 @@ static int max14577_muic_set_debounce_time(struct max14577_muic_info *info,
> case ADC_DEBOUNCE_TIME_25MS:
> case ADC_DEBOUNCE_TIME_38_62MS:
> ret = max14577_update_reg(info->max14577->regmap,
> - MAX14577_MUIC_REG_CONTROL3,
> - CTRL3_ADCDBSET_MASK,
> - time << CTRL3_ADCDBSET_SHIFT);
> + MAXIM_MUIC_REG_CONTROL3,
> + MAXIM_CONTROL3_ADCDBSET_MASK,
> + time << MAXIM_CONTROL3_ADCDBSET_SHIFT);
> if (ret) {
> dev_err(info->dev, "failed to set ADC debounce time\n");
> return ret;
> @@ -211,8 +211,9 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
>
> /* Set open state to path before changing hw path */
> ret = max14577_update_reg(info->max14577->regmap,
> - MAX14577_MUIC_REG_CONTROL1,
> - CLEAR_IDBEN_MICEN_MASK, CTRL1_SW_OPEN);
> + MAXIM_MUIC_REG_CONTROL1,
> + MAXIM_CONTROL1_CLEAR_IDBEN_MICEN_MASK,
> + MAXIM_CONTROL1_SW_OPEN);
> if (ret < 0) {
> dev_err(info->dev, "failed to update MUIC register\n");
> return ret;
> @@ -221,24 +222,25 @@ static int max14577_muic_set_path(struct max14577_muic_info *info,
> if (attached)
> ctrl1 = val;
> else
> - ctrl1 = CTRL1_SW_OPEN;
> + ctrl1 = MAXIM_CONTROL1_SW_OPEN;
>
> ret = max14577_update_reg(info->max14577->regmap,
> - MAX14577_MUIC_REG_CONTROL1,
> - CLEAR_IDBEN_MICEN_MASK, ctrl1);
> + MAXIM_MUIC_REG_CONTROL1,
> + MAXIM_CONTROL1_CLEAR_IDBEN_MICEN_MASK, ctrl1);
> if (ret < 0) {
> dev_err(info->dev, "failed to update MUIC register\n");
> return ret;
> }
>
> if (attached)
> - ctrl2 |= CTRL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */
> + ctrl2 |= MAXIM_CONTROL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */
> else
> - ctrl2 |= CTRL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */
> + ctrl2 |= MAXIM_CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */
>
> ret = max14577_update_reg(info->max14577->regmap,
> - MAX14577_REG_CONTROL2,
> - CTRL2_LOWPWR_MASK | CTRL2_CPEN_MASK, ctrl2);
> + MAXIM_MUIC_REG_CONTROL2,
> + MAXIM_CONTROL2_LOWPWR_MASK | MAXIM_CONTROL2_CPEN_MASK,
> + ctrl2);
> if (ret < 0) {
> dev_err(info->dev, "failed to update MUIC register\n");
> return ret;
> @@ -275,8 +277,9 @@ static int max14577_muic_get_cable_type(struct max14577_muic_info *info,
> * Read ADC value to check cable type and decide cable state
> * according to cable type
> */
> - adc = info->status[MAX14577_MUIC_STATUS1] & STATUS1_ADC_MASK;
> - adc >>= STATUS1_ADC_SHIFT;
> + adc = info->status[MAX14577_MUIC_STATUS1] &
> + MAXIM_STATUS1_ADC_MASK;
> + adc >>= MAXIM_STATUS1_ADC_SHIFT;
>
> /*
> * Check current cable state/cable type and store cable type
> @@ -300,14 +303,14 @@ static int max14577_muic_get_cable_type(struct max14577_muic_info *info,
> * according to type of charger cable.
> */
> chg_type = info->status[MAX14577_MUIC_STATUS2] &
> - STATUS2_CHGTYP_MASK;
> - chg_type >>= STATUS2_CHGTYP_SHIFT;
> + MAXIM_STATUS2_CHGTYP_MASK;
> + chg_type >>= MAXIM_STATUS2_CHGTYP_SHIFT;
>
> - if (chg_type == MAX14577_CHARGER_TYPE_NONE) {
> + if (chg_type == MAXIM_CHARGER_TYPE_NONE) {
> *attached = false;
>
> cable_type = info->prev_chg_type;
> - info->prev_chg_type = MAX14577_CHARGER_TYPE_NONE;
> + info->prev_chg_type = MAXIM_CHARGER_TYPE_NONE;
> } else {
> *attached = true;
>
> @@ -334,7 +337,7 @@ static int max14577_muic_jig_handler(struct max14577_muic_info *info,
> {
> char cable_name[32];
> int ret = 0;
> - u8 path = CTRL1_SW_OPEN;
> + u8 path = MAXIM_CONTROL1_SW_OPEN;
>
> dev_dbg(info->dev,
> "external connector is %s (adc:0x%02x)\n",
> @@ -344,17 +347,17 @@ static int max14577_muic_jig_handler(struct max14577_muic_info *info,
> case MAX14577_MUIC_ADC_FACTORY_MODE_USB_OFF: /* ADC_JIG_USB_OFF */
> /* PATH:AP_USB */
> strcpy(cable_name, "JIG-USB-OFF");
> - path = CTRL1_SW_USB;
> + path = MAXIM_CONTROL1_SW_USB;
> break;
> case MAX14577_MUIC_ADC_FACTORY_MODE_USB_ON: /* ADC_JIG_USB_ON */
> /* PATH:AP_USB */
> strcpy(cable_name, "JIG-USB-ON");
> - path = CTRL1_SW_USB;
> + path = MAXIM_CONTROL1_SW_USB;
> break;
> case MAX14577_MUIC_ADC_FACTORY_MODE_UART_OFF: /* ADC_JIG_UART_OFF */
> /* PATH:AP_UART */
> strcpy(cable_name, "JIG-UART-OFF");
> - path = CTRL1_SW_UART;
> + path = MAXIM_CONTROL1_SW_UART;
> break;
> default:
> dev_err(info->dev, "failed to detect %s jig cable\n",
> @@ -457,7 +460,7 @@ static int max14577_muic_chg_handler(struct max14577_muic_info *info)
> chg_type, info->prev_chg_type);
>
> switch (chg_type) {
> - case MAX14577_CHARGER_TYPE_USB:
> + case MAXIM_CHARGER_TYPE_USB:
> /* PATH:AP_USB */
> ret = max14577_muic_set_path(info, info->path_usb, attached);
> if (ret < 0)
> @@ -465,21 +468,21 @@ static int max14577_muic_chg_handler(struct max14577_muic_info *info)
>
> extcon_set_cable_state(info->edev, "USB", attached);
> break;
> - case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
> + case MAXIM_CHARGER_TYPE_DEDICATED_CHG:
> extcon_set_cable_state(info->edev, "TA", attached);
> break;
> - case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
> + case MAXIM_CHARGER_TYPE_DOWNSTREAM_PORT:
> extcon_set_cable_state(info->edev,
> "Charge-downstream", attached);
> break;
> - case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
> + case MAXIM_CHARGER_TYPE_SPECIAL_500MA:
> extcon_set_cable_state(info->edev, "Slow-charger", attached);
> break;
> - case MAX14577_CHARGER_TYPE_SPECIAL_1A:
> + case MAXIM_CHARGER_TYPE_SPECIAL_1A:
> extcon_set_cable_state(info->edev, "Fast-charger", attached);
> break;
> - case MAX14577_CHARGER_TYPE_NONE:
> - case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
> + case MAXIM_CHARGER_TYPE_NONE:
> + case MAXIM_CHARGER_TYPE_DEAD_BATTERY:
> break;
> default:
> dev_err(info->dev,
> @@ -503,7 +506,7 @@ static void max14577_muic_irq_work(struct work_struct *work)
> mutex_lock(&info->mutex);
>
> ret = max14577_bulk_read(info->max14577->regmap,
> - MAX14577_MUIC_REG_STATUS1, info->status, 2);
> + MAXIM_MUIC_REG_STATUS1, info->status, 2);
> if (ret) {
> dev_err(info->dev, "failed to read MUIC register\n");
> mutex_unlock(&info->mutex);
> @@ -543,18 +546,18 @@ static irqreturn_t max14577_muic_irq_handler(int irq, void *data)
> irq_type = muic_irqs[i].irq;
>
> switch (irq_type) {
> - case MAX14577_IRQ_INT1_ADC:
> - case MAX14577_IRQ_INT1_ADCLOW:
> - case MAX14577_IRQ_INT1_ADCERR:
> + case MAXIM_IRQ_INT1_ADC:
> + case MAXIM_IRQ_INT1_ADCLOW:
> + case MAXIM_IRQ_INT1_ADCERR:
> /* Handle all of accessory except for
> type of charger accessory */
> info->irq_adc = true;
> break;
> - case MAX14577_IRQ_INT2_CHGTYP:
> - case MAX14577_IRQ_INT2_CHGDETRUN:
> - case MAX14577_IRQ_INT2_DCDTMR:
> - case MAX14577_IRQ_INT2_DBCHG:
> - case MAX14577_IRQ_INT2_VBVOLT:
> + case MAXIM_IRQ_INT2_CHGTYP:
> + case MAXIM_IRQ_INT2_CHGDETRUN:
> + case MAXIM_IRQ_INT2_DCDTMR:
> + case MAXIM_IRQ_INT2_DBCHG:
> + case MAXIM_IRQ_INT2_VBVOLT:
> /* Handle charger accessory */
> info->irq_chg = true;
> break;
> @@ -579,7 +582,7 @@ static int max14577_muic_detect_accessory(struct max14577_muic_info *info)
>
> /* Read STATUSx register to detect accessory */
> ret = max14577_bulk_read(info->max14577->regmap,
> - MAX14577_MUIC_REG_STATUS1, info->status, 2);
> + MAXIM_MUIC_REG_STATUS1, info->status, 2);
> if (ret) {
> dev_err(info->dev, "failed to read MUIC register\n");
> mutex_unlock(&info->mutex);
> @@ -599,7 +602,7 @@ static int max14577_muic_detect_accessory(struct max14577_muic_info *info)
>
> chg_type = max14577_muic_get_cable_type(info, MAX14577_CABLE_GROUP_CHG,
> &attached);
> - if (attached && chg_type != MAX14577_CHARGER_TYPE_NONE) {
> + if (attached && chg_type != MAXIM_CHARGER_TYPE_NONE) {
> ret = max14577_muic_chg_handler(info);
> if (ret < 0) {
> dev_err(info->dev, "Cannot detect charger accessory\n");
> @@ -682,8 +685,8 @@ static int max14577_muic_probe(struct platform_device *pdev)
> }
>
> /* Default h/w line path */
> - info->path_usb = CTRL1_SW_USB;
> - info->path_uart = CTRL1_SW_UART;
> + info->path_usb = MAXIM_CONTROL1_SW_USB;
> + info->path_uart = MAXIM_CONTROL1_SW_UART;
> delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
>
> /* Set initial path for UART */
> @@ -691,7 +694,7 @@ static int max14577_muic_probe(struct platform_device *pdev)
>
> /* Check revision number of MUIC device*/
> ret = max14577_read_reg(info->max14577->regmap,
> - MAX14577_REG_DEVICEID, &id);
> + MAXIM_MUIC_REG_DEVICEID, &id);
> if (ret < 0) {
> dev_err(&pdev->dev, "failed to read revision number\n");
> goto err_extcon;
> diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
> index 2ac2f2d7cea6..d883055ca789 100644
> --- a/drivers/mfd/max14577.c
> +++ b/drivers/mfd/max14577.c
> @@ -36,10 +36,10 @@ static struct mfd_cell max14577_devs[] = {
> { .name = "max14577-charger", },
> };
>
> -static bool max14577_volatile_reg(struct device *dev, unsigned int reg)
> +static bool max14577_muic_volatile_reg(struct device *dev, unsigned int reg)
> {
> switch (reg) {
> - case MAX14577_REG_INT1 ... MAX14577_REG_STATUS3:
> + case MAXIM_MUIC_REG_INT1 ... MAXIM_MUIC_REG_STATUS3:
> return true;
> default:
> break;
> @@ -47,35 +47,35 @@ static bool max14577_volatile_reg(struct device *dev, unsigned int reg)
> return false;
> }
>
> -static const struct regmap_config max14577_regmap_config = {
> +static const struct regmap_config max14577_muic_regmap_config = {
> .reg_bits = 8,
> .val_bits = 8,
> - .volatile_reg = max14577_volatile_reg,
> - .max_register = MAX14577_REG_END,
> + .volatile_reg = max14577_muic_volatile_reg,
> + .max_register = MAXIM_MUIC_REG_END,
> };
>
> static const struct regmap_irq max14577_irqs[] = {
> /* INT1 interrupts */
> - { .reg_offset = 0, .mask = INT1_ADC_MASK, },
> - { .reg_offset = 0, .mask = INT1_ADCLOW_MASK, },
> - { .reg_offset = 0, .mask = INT1_ADCERR_MASK, },
> + { .reg_offset = 0, .mask = MAXIM_INT1_ADC_MASK, },
> + { .reg_offset = 0, .mask = MAXIM_INT1_ADCLOW_MASK, },
> + { .reg_offset = 0, .mask = MAXIM_INT1_ADCERR_MASK, },
> /* INT2 interrupts */
> - { .reg_offset = 1, .mask = INT2_CHGTYP_MASK, },
> - { .reg_offset = 1, .mask = INT2_CHGDETRUN_MASK, },
> - { .reg_offset = 1, .mask = INT2_DCDTMR_MASK, },
> - { .reg_offset = 1, .mask = INT2_DBCHG_MASK, },
> - { .reg_offset = 1, .mask = INT2_VBVOLT_MASK, },
> + { .reg_offset = 1, .mask = MAXIM_INT2_CHGTYP_MASK, },
> + { .reg_offset = 1, .mask = MAXIM_INT2_CHGDETRUN_MASK, },
> + { .reg_offset = 1, .mask = MAXIM_INT2_DCDTMR_MASK, },
> + { .reg_offset = 1, .mask = MAXIM_INT2_DBCHG_MASK, },
> + { .reg_offset = 1, .mask = MAXIM_INT2_VBVOLT_MASK, },
> /* INT3 interrupts */
> - { .reg_offset = 2, .mask = INT3_EOC_MASK, },
> - { .reg_offset = 2, .mask = INT3_CGMBC_MASK, },
> - { .reg_offset = 2, .mask = INT3_OVP_MASK, },
> - { .reg_offset = 2, .mask = INT3_MBCCHGERR_MASK, },
> + { .reg_offset = 2, .mask = MAXIM_INT3_EOC_MASK, },
> + { .reg_offset = 2, .mask = MAXIM_INT3_CGMBC_MASK, },
> + { .reg_offset = 2, .mask = MAXIM_INT3_OVP_MASK, },
> + { .reg_offset = 2, .mask = MAXIM_INT3_MBCCHGERR_MASK, },
> };
>
> static const struct regmap_irq_chip max14577_irq_chip = {
> .name = "max14577",
> - .status_base = MAX14577_REG_INT1,
> - .mask_base = MAX14577_REG_INTMASK1,
> + .status_base = MAXIM_MUIC_REG_INT1,
> + .mask_base = MAXIM_MUIC_REG_INTMASK1,
> .mask_invert = 1,
> .num_regs = 3,
> .irqs = max14577_irqs,
> @@ -112,7 +112,8 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
> max14577->i2c = i2c;
> max14577->irq = i2c->irq;
>
> - max14577->regmap = devm_regmap_init_i2c(i2c, &max14577_regmap_config);
> + max14577->regmap = devm_regmap_init_i2c(i2c,
> + &max14577_muic_regmap_config);
> if (IS_ERR(max14577->regmap)) {
> ret = PTR_ERR(max14577->regmap);
> dev_err(max14577->dev, "Failed to allocate register map: %d\n",
> @@ -120,17 +121,17 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
> return ret;
> }
>
> - ret = max14577_read_reg(max14577->regmap, MAX14577_REG_DEVICEID,
> + ret = max14577_read_reg(max14577->regmap, MAXIM_MUIC_REG_DEVICEID,
> ®_data);
> if (ret) {
> dev_err(max14577->dev, "Device not found on this channel: %d\n",
> ret);
> return ret;
> }
> - max14577->vendor_id = ((reg_data & DEVID_VENDORID_MASK) >>
> - DEVID_VENDORID_SHIFT);
> - max14577->device_id = ((reg_data & DEVID_DEVICEID_MASK) >>
> - DEVID_DEVICEID_SHIFT);
> + max14577->vendor_id = ((reg_data & MAXIM_DEVID_VENDORID_MASK) >>
> + MAXIM_DEVID_VENDORID_SHIFT);
> + max14577->device_id = ((reg_data & MAXIM_DEVID_DEVICEID_MASK) >>
> + MAXIM_DEVID_DEVICEID_SHIFT);
> dev_info(max14577->dev, "Device ID: 0x%x, vendor: 0x%x\n",
> max14577->device_id, max14577->vendor_id);
>
> diff --git a/drivers/power/max14577_charger.c b/drivers/power/max14577_charger.c
> index fad2a75b3604..66a4e4edea42 100644
> --- a/drivers/power/max14577_charger.c
> +++ b/drivers/power/max14577_charger.c
> @@ -46,14 +46,14 @@ static int max14577_get_charger_state(struct max14577_charger *chg)
> * - handle properly dead-battery charging (respect timer)
> * - handle timers (fast-charge and prequal) /MBCCHGERR/
> */
> - max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL2, ®_data);
> - if ((reg_data & CHGCTRL2_MBCHOSTEN_MASK) == 0)
> + max14577_read_reg(rmap, MAXIM_CHG_REG_CHGCTRL2, ®_data);
> + if ((reg_data & MAXIM_CHGCTRL2_MBCHOSTEN_MASK) == 0)
> goto state_set;
>
> - max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
> - if (reg_data & STATUS3_CGMBC_MASK) {
> + max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS3, ®_data);
> + if (reg_data & MAXIM_STATUS3_CGMBC_MASK) {
> /* Charger or USB-cable is connected */
> - if (reg_data & STATUS3_EOC_MASK)
> + if (reg_data & MAXIM_STATUS3_EOC_MASK)
> state = POWER_SUPPLY_STATUS_FULL;
> else
> state = POWER_SUPPLY_STATUS_CHARGING;
> @@ -90,18 +90,19 @@ static int max14577_get_online(struct max14577_charger *chg)
> struct regmap *rmap = chg->max14577->regmap;
> u8 reg_data;
>
> - max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data);
> - reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT);
> + max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS2, ®_data);
> + reg_data = reg_data & MAXIM_STATUS2_CHGTYP_MASK;
> + reg_data >>= MAXIM_STATUS2_CHGTYP_SHIFT;
> switch (reg_data) {
> - case MAX14577_CHARGER_TYPE_USB:
> - case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
> - case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
> - case MAX14577_CHARGER_TYPE_SPECIAL_1A:
> - case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
> + case MAXIM_CHARGER_TYPE_USB:
> + case MAXIM_CHARGER_TYPE_DEDICATED_CHG:
> + case MAXIM_CHARGER_TYPE_SPECIAL_500MA:
> + case MAXIM_CHARGER_TYPE_SPECIAL_1A:
> + case MAXIM_CHARGER_TYPE_DEAD_BATTERY:
> return 1;
> - case MAX14577_CHARGER_TYPE_NONE:
> - case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
> - case MAX14577_CHARGER_TYPE_RESERVED:
> + case MAXIM_CHARGER_TYPE_NONE:
> + case MAXIM_CHARGER_TYPE_DOWNSTREAM_PORT:
> + case MAXIM_CHARGER_TYPE_RESERVED:
> default:
> return 0;
> }
> @@ -119,15 +120,16 @@ static int max14577_get_battery_health(struct max14577_charger *chg)
> int state = POWER_SUPPLY_HEALTH_GOOD;
> u8 reg_data;
>
> - max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data);
> - reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT);
> - if (reg_data == MAX14577_CHARGER_TYPE_DEAD_BATTERY) {
> + max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS2, ®_data);
> + reg_data = reg_data & MAXIM_STATUS2_CHGTYP_MASK;
> + reg_data >>= MAXIM_STATUS2_CHGTYP_SHIFT;
> + if (reg_data == MAXIM_CHARGER_TYPE_DEAD_BATTERY) {
> state = POWER_SUPPLY_HEALTH_DEAD;
> goto state_set;
> }
>
> - max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
> - if (reg_data & STATUS3_OVP_MASK) {
> + max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS3, ®_data);
> + if (reg_data & MAXIM_STATUS3_OVP_MASK) {
> state = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
> goto state_set;
> }
> @@ -162,46 +164,47 @@ static void max14577_charger_reg_init(struct max14577_charger *chg)
> * Charger-Detection Enable, default on (set CHGDETEN to 1)
> * Combined mask of CHGDETEN and CHGTYPMAN will zero the CHGTYPMAN bit
> */
> - reg_data = 0x1 << CDETCTRL1_CHGDETEN_SHIFT;
> - max14577_update_reg(rmap, MAX14577_REG_CDETCTRL1,
> - CDETCTRL1_CHGDETEN_MASK | CDETCTRL1_CHGTYPMAN_MASK,
> + reg_data = 0x1 << MAXIM_CDETCTRL1_CHGDETEN_SHIFT;
> + max14577_update_reg(rmap, MAXIM_MUIC_REG_CDETCTRL1,
> + MAXIM_CDETCTRL1_CHGDETEN_MASK |
> + MAXIM_CDETCTRL1_CHGTYPMAN_MASK,
> reg_data);
>
> /* Battery Fast-Charge Timer, from SM-V700: 6hrs */
> - reg_data = 0x3 << CHGCTRL1_TCHW_SHIFT;
> - max14577_write_reg(rmap, MAX14577_REG_CHGCTRL1, reg_data);
> + reg_data = 0x3 << MAXIM_CHGCTRL1_TCHW_SHIFT;
> + max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL1, reg_data);
>
> /*
> * Wall-Adapter Rapid Charge, default on
> * Battery-Charger, default on
> */
> - reg_data = 0x1 << CHGCTRL2_VCHGR_RC_SHIFT;
> - reg_data |= 0x1 << CHGCTRL2_MBCHOSTEN_SHIFT;
> - max14577_write_reg(rmap, MAX14577_REG_CHGCTRL2, reg_data);
> + reg_data = 0x1 << MAXIM_CHGCTRL2_VCHGR_RC_SHIFT;
> + reg_data |= 0x1 << MAXIM_CHGCTRL2_MBCHOSTEN_SHIFT;
> + max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL2, reg_data);
>
> /* Battery-Charger Constant Voltage (CV) Mode, from SM-V700: 4.35V */
> - reg_data = 0xf << CHGCTRL3_MBCCVWRC_SHIFT;
> - max14577_write_reg(rmap, MAX14577_REG_CHGCTRL3, reg_data);
> + reg_data = 0xf << MAXIM_CHGCTRL3_MBCCVWRC_SHIFT;
> + max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL3, reg_data);
>
> /*
> * Fast Battery-Charge Current Low, default 200-950mA
> * Fast Battery-Charge Current High, from SM-V700: 450mA
> */
> - reg_data = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT;
> - reg_data |= 0x5 << CHGCTRL4_MBCICHWRCH_SHIFT;
> - max14577_write_reg(rmap, MAX14577_REG_CHGCTRL4, reg_data);
> + reg_data = 0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
> + reg_data |= 0x5 << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT;
> + max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL4, reg_data);
>
> /* End-of-Charge Current, from SM-V700: 50mA */
> - reg_data = 0x0 << CHGCTRL5_EOCS_SHIFT;
> - max14577_write_reg(rmap, MAX14577_REG_CHGCTRL5, reg_data);
> + reg_data = 0x0 << MAXIM_CHGCTRL5_EOCS_SHIFT;
> + max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL5, reg_data);
>
> /* Auto Charging Stop, default off */
> - reg_data = 0x0 << CHGCTRL6_AUTOSTOP_SHIFT;
> - max14577_write_reg(rmap, MAX14577_REG_CHGCTRL6, reg_data);
> + reg_data = 0x0 << MAXIM_CHGCTRL6_AUTOSTOP_SHIFT;
> + max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL6, reg_data);
>
> /* Overvoltage-Protection Threshold, from SM-V700: 6.5V */
> - reg_data = 0x2 << CHGCTRL7_OTPCGHCVS_SHIFT;
> - max14577_write_reg(rmap, MAX14577_REG_CHGCTRL7, reg_data);
> + reg_data = 0x2 << MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT;
> + max14577_write_reg(rmap, MAXIM_CHG_REG_CHGCTRL7, reg_data);
> }
>
> /* Support property from charger */
> diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c
> index dc40c5ca4b75..9e5c0bd54684 100644
> --- a/drivers/regulator/max14577.c
> +++ b/drivers/regulator/max14577.c
> @@ -30,11 +30,11 @@ static int max14577_reg_is_enabled(struct regulator_dev *rdev)
>
> switch (rid) {
> case MAX14577_CHARGER:
> - max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL2, ®_data);
> - if ((reg_data & CHGCTRL2_MBCHOSTEN_MASK) == 0)
> + max14577_read_reg(rmap, MAXIM_CHG_REG_CHGCTRL2, ®_data);
> + if ((reg_data & MAXIM_CHGCTRL2_MBCHOSTEN_MASK) == 0)
> return 0;
> - max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
> - if ((reg_data & STATUS3_CGMBC_MASK) == 0)
> + max14577_read_reg(rmap, MAXIM_MUIC_REG_STATUS3, ®_data);
> + if ((reg_data & MAXIM_STATUS3_CGMBC_MASK) == 0)
> return 0;
> /* MBCHOSTEN and CGMBC are on */
> return 1;
> @@ -51,13 +51,13 @@ static int max14577_reg_get_current_limit(struct regulator_dev *rdev)
> if (rdev_get_id(rdev) != MAX14577_CHARGER)
> return -EINVAL;
>
> - max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL4, ®_data);
> + max14577_read_reg(rmap, MAXIM_CHG_REG_CHGCTRL4, ®_data);
>
> - if ((reg_data & CHGCTRL4_MBCICHWRCL_MASK) == 0)
> + if ((reg_data & MAXIM_CHGCTRL4_MBCICHWRCL_MASK) == 0)
> return MAX14577_REGULATOR_CURRENT_LIMIT_MIN;
>
> - reg_data = ((reg_data & CHGCTRL4_MBCICHWRCH_MASK) >>
> - CHGCTRL4_MBCICHWRCH_SHIFT);
> + reg_data = ((reg_data & MAXIM_CHGCTRL4_MBCICHWRCH_MASK) >>
> + MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT);
> return MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START +
> reg_data * MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP;
> }
> @@ -77,10 +77,10 @@ static int max14577_reg_set_current_limit(struct regulator_dev *rdev,
>
> if (max_uA < MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START) {
> /* Less than 200 mA, so set 90mA (turn only Low Bit off) */
> - u8 reg_data = 0x0 << CHGCTRL4_MBCICHWRCL_SHIFT;
> + u8 reg_data = 0x0 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
> return max14577_update_reg(rdev->regmap,
> - MAX14577_CHG_REG_CHG_CTRL4,
> - CHGCTRL4_MBCICHWRCL_MASK, reg_data);
> + MAXIM_CHG_REG_CHGCTRL4,
> + MAXIM_CHGCTRL4_MBCICHWRCL_MASK, reg_data);
> }
>
> /* max_uA is in range: <LIMIT_HIGH_START, inifinite>, so search for
> @@ -94,13 +94,13 @@ static int max14577_reg_set_current_limit(struct regulator_dev *rdev,
> }
> BUG_ON(current_bits < 0); /* Cannot happen */
> /* Turn Low Bit on (use range 200mA-950 mA) */
> - reg_data = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT;
> + reg_data = 0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT;
> /* and set proper High Bits */
> - reg_data |= current_bits << CHGCTRL4_MBCICHWRCH_SHIFT;
> + reg_data |= current_bits << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT;
>
> - return max14577_update_reg(rdev->regmap, MAX14577_CHG_REG_CHG_CTRL4,
> - CHGCTRL4_MBCICHWRCL_MASK | CHGCTRL4_MBCICHWRCH_MASK,
> - reg_data);
> + return max14577_update_reg(rdev->regmap, MAXIM_CHG_REG_CHGCTRL4,
> + MAXIM_CHGCTRL4_MBCICHWRCL_MASK | MAXIM_CHGCTRL4_MBCICHWRCH_MASK,
> + reg_data);
> }
>
> static struct regulator_ops max14577_safeout_ops = {
> @@ -127,8 +127,8 @@ static const struct regulator_desc supported_regulators[] = {
> .owner = THIS_MODULE,
> .n_voltages = 1,
> .min_uV = MAX14577_REGULATOR_SAFEOUT_VOLTAGE,
> - .enable_reg = MAX14577_REG_CONTROL2,
> - .enable_mask = CTRL2_SFOUTORD_MASK,
> + .enable_reg = MAXIM_MUIC_REG_CONTROL2,
> + .enable_mask = MAXIM_CONTROL2_SFOUTORD_MASK,
> },
> [MAX14577_CHARGER] = {
> .name = "CHARGER",
> @@ -136,8 +136,8 @@ static const struct regulator_desc supported_regulators[] = {
> .ops = &max14577_charger_ops,
> .type = REGULATOR_CURRENT,
> .owner = THIS_MODULE,
> - .enable_reg = MAX14577_CHG_REG_CHG_CTRL2,
> - .enable_mask = CHGCTRL2_MBCHOSTEN_MASK,
> + .enable_reg = MAXIM_CHG_REG_CHGCTRL2,
> + .enable_mask = MAXIM_CHGCTRL2_MBCHOSTEN_MASK,
> },
> };
>
> @@ -159,7 +159,7 @@ static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev)
> }
>
> ret = of_regulator_match(&pdev->dev, np, max14577_regulator_matches,
> - MAX14577_REG_MAX);
> + MAX14577_REG_NUM);
> if (ret < 0) {
> dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);
> }
> @@ -250,7 +250,7 @@ static int __init max14577_regulator_init(void)
> BUILD_BUG_ON(MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START +
> MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf !=
> MAX14577_REGULATOR_CURRENT_LIMIT_MAX);
> - BUILD_BUG_ON(ARRAY_SIZE(supported_regulators) != MAX14577_REG_MAX);
> + BUILD_BUG_ON(ARRAY_SIZE(supported_regulators) != MAX14577_REG_NUM);
>
> return platform_driver_register(&max14577_regulator_driver);
> }
> diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h
> index c9b332fb0d5d..9f5ce26cb54e 100644
> --- a/include/linux/mfd/max14577-private.h
> +++ b/include/linux/mfd/max14577-private.h
> @@ -22,224 +22,199 @@
> #include <linux/i2c.h>
> #include <linux/regmap.h>
>
> -#define MAX14577_REG_INVALID (0xff)
> -
> -/* Slave addr = 0x4A: Interrupt */
> -enum max14577_reg {
> - MAX14577_REG_DEVICEID = 0x00,
> - MAX14577_REG_INT1 = 0x01,
> - MAX14577_REG_INT2 = 0x02,
> - MAX14577_REG_INT3 = 0x03,
> - MAX14577_REG_STATUS1 = 0x04,
> - MAX14577_REG_STATUS2 = 0x05,
> - MAX14577_REG_STATUS3 = 0x06,
> - MAX14577_REG_INTMASK1 = 0x07,
> - MAX14577_REG_INTMASK2 = 0x08,
> - MAX14577_REG_INTMASK3 = 0x09,
> - MAX14577_REG_CDETCTRL1 = 0x0A,
> - MAX14577_REG_RFU = 0x0B,
> - MAX14577_REG_CONTROL1 = 0x0C,
> - MAX14577_REG_CONTROL2 = 0x0D,
> - MAX14577_REG_CONTROL3 = 0x0E,
> - MAX14577_REG_CHGCTRL1 = 0x0F,
> - MAX14577_REG_CHGCTRL2 = 0x10,
> - MAX14577_REG_CHGCTRL3 = 0x11,
> - MAX14577_REG_CHGCTRL4 = 0x12,
> - MAX14577_REG_CHGCTRL5 = 0x13,
> - MAX14577_REG_CHGCTRL6 = 0x14,
> - MAX14577_REG_CHGCTRL7 = 0x15,
> -
> - MAX14577_REG_END,
> +/* Slave addr = 0x4A: MUIC and Charger */
> +enum maxim_muic_reg {
> + MAXIM_MUIC_REG_DEVICEID = 0x00,
> + MAXIM_MUIC_REG_INT1 = 0x01,
> + MAXIM_MUIC_REG_INT2 = 0x02,
> + MAXIM_MUIC_REG_INT3 = 0x03,
> + MAXIM_MUIC_REG_STATUS1 = 0x04,
> + MAXIM_MUIC_REG_STATUS2 = 0x05,
> + MAXIM_MUIC_REG_STATUS3 = 0x06,
> + MAXIM_MUIC_REG_INTMASK1 = 0x07,
> + MAXIM_MUIC_REG_INTMASK2 = 0x08,
> + MAXIM_MUIC_REG_INTMASK3 = 0x09,
> + MAXIM_MUIC_REG_CDETCTRL1 = 0x0A,
> + MAXIM_MUIC_REG_RFU = 0x0B,
> + MAXIM_MUIC_REG_CONTROL1 = 0x0C,
> + MAXIM_MUIC_REG_CONTROL2 = 0x0D,
> + MAXIM_MUIC_REG_CONTROL3 = 0x0E,
> + MAXIM_CHG_REG_CHGCTRL1 = 0x0F,
> + MAXIM_CHG_REG_CHGCTRL2 = 0x10,
> + MAXIM_CHG_REG_CHGCTRL3 = 0x11,
> + MAXIM_CHG_REG_CHGCTRL4 = 0x12,
> + MAXIM_CHG_REG_CHGCTRL5 = 0x13,
> + MAXIM_CHG_REG_CHGCTRL6 = 0x14,
> + MAXIM_CHG_REG_CHGCTRL7 = 0x15,
> +
> + MAXIM_MUIC_REG_END,
> };
>
> -/* Slave addr = 0x4A: MUIC */
> -enum max14577_muic_reg {
> - MAX14577_MUIC_REG_STATUS1 = 0x04,
> - MAX14577_MUIC_REG_STATUS2 = 0x05,
> - MAX14577_MUIC_REG_CONTROL1 = 0x0C,
> - MAX14577_MUIC_REG_CONTROL3 = 0x0E,
> -
> - MAX14577_MUIC_REG_END,
> -};
> -
> -enum max14577_muic_charger_type {
> - MAX14577_CHARGER_TYPE_NONE = 0,
> - MAX14577_CHARGER_TYPE_USB,
> - MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT,
> - MAX14577_CHARGER_TYPE_DEDICATED_CHG,
> - MAX14577_CHARGER_TYPE_SPECIAL_500MA,
> - MAX14577_CHARGER_TYPE_SPECIAL_1A,
> - MAX14577_CHARGER_TYPE_RESERVED,
> - MAX14577_CHARGER_TYPE_DEAD_BATTERY = 7,
> +enum maxim_muic_charger_type {
> + MAXIM_CHARGER_TYPE_NONE = 0,
> + MAXIM_CHARGER_TYPE_USB,
> + MAXIM_CHARGER_TYPE_DOWNSTREAM_PORT,
> + MAXIM_CHARGER_TYPE_DEDICATED_CHG,
> + MAXIM_CHARGER_TYPE_SPECIAL_500MA,
> + MAXIM_CHARGER_TYPE_SPECIAL_1A,
> + MAXIM_CHARGER_TYPE_RESERVED,
> + MAXIM_CHARGER_TYPE_DEAD_BATTERY = 7,
> };
>
> /* MAX14577 interrupts */
> -#define INT1_ADC_MASK (0x1 << 0)
> -#define INT1_ADCLOW_MASK (0x1 << 1)
> -#define INT1_ADCERR_MASK (0x1 << 2)
> +#define MAXIM_INT1_ADC_MASK (0x1 << 0)
> +#define MAXIM_INT1_ADCLOW_MASK (0x1 << 1)
> +#define MAXIM_INT1_ADCERR_MASK (0x1 << 2)
>
> -#define INT2_CHGTYP_MASK (0x1 << 0)
> -#define INT2_CHGDETRUN_MASK (0x1 << 1)
> -#define INT2_DCDTMR_MASK (0x1 << 2)
> -#define INT2_DBCHG_MASK (0x1 << 3)
> -#define INT2_VBVOLT_MASK (0x1 << 4)
> +#define MAXIM_INT2_CHGTYP_MASK (0x1 << 0)
> +#define MAXIM_INT2_CHGDETRUN_MASK (0x1 << 1)
> +#define MAXIM_INT2_DCDTMR_MASK (0x1 << 2)
> +#define MAXIM_INT2_DBCHG_MASK (0x1 << 3)
> +#define MAXIM_INT2_VBVOLT_MASK (0x1 << 4)
>
> -#define INT3_EOC_MASK (0x1 << 0)
> -#define INT3_CGMBC_MASK (0x1 << 1)
> -#define INT3_OVP_MASK (0x1 << 2)
> -#define INT3_MBCCHGERR_MASK (0x1 << 3)
> +#define MAXIM_INT3_EOC_MASK (0x1 << 0)
> +#define MAXIM_INT3_CGMBC_MASK (0x1 << 1)
> +#define MAXIM_INT3_OVP_MASK (0x1 << 2)
> +#define MAXIM_INT3_MBCCHGERR_MASK (0x1 << 3)
>
> /* MAX14577 DEVICE ID register */
> -#define DEVID_VENDORID_SHIFT 0
> -#define DEVID_DEVICEID_SHIFT 3
> -#define DEVID_VENDORID_MASK (0x07 << DEVID_VENDORID_SHIFT)
> -#define DEVID_DEVICEID_MASK (0x1f << DEVID_DEVICEID_SHIFT)
> +#define MAXIM_DEVID_VENDORID_SHIFT 0
> +#define MAXIM_DEVID_DEVICEID_SHIFT 3
> +#define MAXIM_DEVID_VENDORID_MASK (0x07 << MAXIM_DEVID_VENDORID_SHIFT)
> +#define MAXIM_DEVID_DEVICEID_MASK (0x1f << MAXIM_DEVID_DEVICEID_SHIFT)
>
> /* MAX14577 STATUS1 register */
> -#define STATUS1_ADC_SHIFT 0
> -#define STATUS1_ADCLOW_SHIFT 5
> -#define STATUS1_ADCERR_SHIFT 6
> -#define STATUS1_ADC_MASK (0x1f << STATUS1_ADC_SHIFT)
> -#define STATUS1_ADCLOW_MASK (0x1 << STATUS1_ADCLOW_SHIFT)
> -#define STATUS1_ADCERR_MASK (0x1 << STATUS1_ADCERR_SHIFT)
> +#define MAXIM_STATUS1_ADC_SHIFT 0
> +#define MAXIM_STATUS1_ADCLOW_SHIFT 5
> +#define MAXIM_STATUS1_ADCERR_SHIFT 6
> +#define MAXIM_STATUS1_ADC_MASK (0x1f << MAXIM_STATUS1_ADC_SHIFT)
> +#define MAXIM_STATUS1_ADCLOW_MASK (0x1 << MAXIM_STATUS1_ADCLOW_SHIFT)
> +#define MAXIM_STATUS1_ADCERR_MASK (0x1 << MAXIM_STATUS1_ADCERR_SHIFT)
>
> /* MAX14577 STATUS2 register */
> -#define STATUS2_CHGTYP_SHIFT 0
> -#define STATUS2_CHGDETRUN_SHIFT 3
> -#define STATUS2_DCDTMR_SHIFT 4
> -#define STATUS2_DBCHG_SHIFT 5
> -#define STATUS2_VBVOLT_SHIFT 6
> -#define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT)
> -#define STATUS2_CHGDETRUN_MASK (0x1 << STATUS2_CHGDETRUN_SHIFT)
> -#define STATUS2_DCDTMR_MASK (0x1 << STATUS2_DCDTMR_SHIFT)
> -#define STATUS2_DBCHG_MASK (0x1 << STATUS2_DBCHG_SHIFT)
> -#define STATUS2_VBVOLT_MASK (0x1 << STATUS2_VBVOLT_SHIFT)
> +#define MAXIM_STATUS2_CHGTYP_SHIFT 0
> +#define MAXIM_STATUS2_CHGDETRUN_SHIFT 3
> +#define MAXIM_STATUS2_DCDTMR_SHIFT 4
> +#define MAXIM_STATUS2_DBCHG_SHIFT 5
> +#define MAXIM_STATUS2_VBVOLT_SHIFT 6
> +#define MAXIM_STATUS2_CHGTYP_MASK (0x7 << MAXIM_STATUS2_CHGTYP_SHIFT)
> +#define MAXIM_STATUS2_CHGDETRUN_MASK (0x1 << MAXIM_STATUS2_CHGDETRUN_SHIFT)
> +#define MAXIM_STATUS2_DCDTMR_MASK (0x1 << MAXIM_STATUS2_DCDTMR_SHIFT)
> +#define MAXIM_STATUS2_DBCHG_MASK (0x1 << MAXIM_STATUS2_DBCHG_SHIFT)
> +#define MAXIM_STATUS2_VBVOLT_MASK (0x1 << MAXIM_STATUS2_VBVOLT_SHIFT)
> +
> +/* MAX14577 STATUS3 register */
> +#define MAXIM_STATUS3_EOC_SHIFT 0
> +#define MAXIM_STATUS3_CGMBC_SHIFT 1
> +#define MAXIM_STATUS3_OVP_SHIFT 2
> +#define MAXIM_STATUS3_MBCCHGERR_SHIFT 3
> +#define MAXIM_STATUS3_EOC_MASK (0x1 << MAXIM_STATUS3_EOC_SHIFT)
> +#define MAXIM_STATUS3_CGMBC_MASK (0x1 << MAXIM_STATUS3_CGMBC_SHIFT)
> +#define MAXIM_STATUS3_OVP_MASK (0x1 << MAXIM_STATUS3_OVP_SHIFT)
> +#define MAXIM_STATUS3_MBCCHGERR_MASK (0x1 << MAXIM_STATUS3_MBCCHGERR_SHIFT)
>
> /* MAX14577 CONTROL1 register */
> -#define COMN1SW_SHIFT 0
> -#define COMP2SW_SHIFT 3
> -#define MICEN_SHIFT 6
> -#define IDBEN_SHIFT 7
> -#define COMN1SW_MASK (0x7 << COMN1SW_SHIFT)
> -#define COMP2SW_MASK (0x7 << COMP2SW_SHIFT)
> -#define MICEN_MASK (0x1 << MICEN_SHIFT)
> -#define IDBEN_MASK (0x1 << IDBEN_SHIFT)
> -#define CLEAR_IDBEN_MICEN_MASK (COMN1SW_MASK | COMP2SW_MASK)
> -#define CTRL1_SW_USB ((1 << COMP2SW_SHIFT) \
> - | (1 << COMN1SW_SHIFT))
> -#define CTRL1_SW_AUDIO ((2 << COMP2SW_SHIFT) \
> - | (2 << COMN1SW_SHIFT))
> -#define CTRL1_SW_UART ((3 << COMP2SW_SHIFT) \
> - | (3 << COMN1SW_SHIFT))
> -#define CTRL1_SW_OPEN ((0 << COMP2SW_SHIFT) \
> - | (0 << COMN1SW_SHIFT))
> +#define MAXIM_CONTROL1_COMN1SW_SHIFT 0
> +#define MAXIM_CONTROL1_COMP2SW_SHIFT 3
> +#define MAXIM_CONTROL1_MICEN_SHIFT 6
> +#define MAXIM_CONTROL1_IDBEN_SHIFT 7
> +#define MAXIM_CONTROL1_COMN1SW_MASK (0x7 << MAXIM_CONTROL1_COMN1SW_SHIFT)
> +#define MAXIM_CONTROL1_COMP2SW_MASK (0x7 << MAXIM_CONTROL1_COMP2SW_SHIFT)
> +#define MAXIM_CONTROL1_MICEN_MASK (0x1 << MAXIM_CONTROL1_MICEN_SHIFT)
> +#define MAXIM_CONTROL1_IDBEN_MASK (0x1 << MAXIM_CONTROL1_IDBEN_SHIFT)
> +
> +#define MAXIM_CONTROL1_CLEAR_IDBEN_MICEN_MASK (MAXIM_CONTROL1_COMN1SW_MASK | MAXIM_CONTROL1_COMP2SW_MASK)
> +#define MAXIM_CONTROL1_SW_USB ((1 << MAXIM_CONTROL1_COMP2SW_SHIFT) \
> + | (1 << MAXIM_CONTROL1_COMN1SW_SHIFT))
> +#define MAXIM_CONTROL1_SW_AUDIO ((2 << MAXIM_CONTROL1_COMP2SW_SHIFT) \
> + | (2 << MAXIM_CONTROL1_COMN1SW_SHIFT))
> +#define MAXIM_CONTROL1_SW_UART ((3 << MAXIM_CONTROL1_COMP2SW_SHIFT) \
> + | (3 << MAXIM_CONTROL1_COMN1SW_SHIFT))
> +#define MAXIM_CONTROL1_SW_OPEN ((0 << MAXIM_CONTROL1_COMP2SW_SHIFT) \
> + | (0 << MAXIM_CONTROL1_COMN1SW_SHIFT))
>
> /* MAX14577 CONTROL2 register */
> -#define CTRL2_LOWPWR_SHIFT (0)
> -#define CTRL2_ADCEN_SHIFT (1)
> -#define CTRL2_CPEN_SHIFT (2)
> -#define CTRL2_SFOUTASRT_SHIFT (3)
> -#define CTRL2_SFOUTORD_SHIFT (4)
> -#define CTRL2_ACCDET_SHIFT (5)
> -#define CTRL2_USBCPINT_SHIFT (6)
> -#define CTRL2_RCPS_SHIFT (7)
> -#define CTRL2_LOWPWR_MASK (0x1 << CTRL2_LOWPWR_SHIFT)
> -#define CTRL2_ADCEN_MASK (0x1 << CTRL2_ADCEN_SHIFT)
> -#define CTRL2_CPEN_MASK (0x1 << CTRL2_CPEN_SHIFT)
> -#define CTRL2_SFOUTASRT_MASK (0x1 << CTRL2_SFOUTASRT_SHIFT)
> -#define CTRL2_SFOUTORD_MASK (0x1 << CTRL2_SFOUTORD_SHIFT)
> -#define CTRL2_ACCDET_MASK (0x1 << CTRL2_ACCDET_SHIFT)
> -#define CTRL2_USBCPINT_MASK (0x1 << CTRL2_USBCPINT_SHIFT)
> -#define CTRL2_RCPS_MASK (0x1 << CTR2_RCPS_SHIFT)
> -
> -#define CTRL2_CPEN1_LOWPWR0 ((1 << CTRL2_CPEN_SHIFT) | \
> - (0 << CTRL2_LOWPWR_SHIFT))
> -#define CTRL2_CPEN0_LOWPWR1 ((0 << CTRL2_CPEN_SHIFT) | \
> - (1 << CTRL2_LOWPWR_SHIFT))
> +#define MAXIM_CONTROL2_LOWPWR_SHIFT 0
> +#define MAXIM_CONTROL2_ADCEN_SHIFT 1
> +#define MAXIM_CONTROL2_CPEN_SHIFT 2
> +#define MAXIM_CONTROL2_SFOUTASRT_SHIFT 3
> +#define MAXIM_CONTROL2_SFOUTORD_SHIFT 4
> +#define MAXIM_CONTROL2_ACCDET_SHIFT 5
> +#define MAXIM_CONTROL2_USBCPINT_SHIFT 6
> +#define MAXIM_CONTROL2_RCPS_SHIFT 7
> +#define MAXIM_CONTROL2_LOWPWR_MASK (0x1 << MAXIM_CONTROL2_LOWPWR_SHIFT)
> +#define MAXIM_CONTROL2_ADCEN_MASK (0x1 << MAXIM_CONTROL2_ADCEN_SHIFT)
> +#define MAXIM_CONTROL2_CPEN_MASK (0x1 << MAXIM_CONTROL2_CPEN_SHIFT)
> +#define MAXIM_CONTROL2_SFOUTASRT_MASK (0x1 << MAXIM_CONTROL2_SFOUTASRT_SHIFT)
> +#define MAXIM_CONTROL2_SFOUTORD_MASK (0x1 << MAXIM_CONTROL2_SFOUTORD_SHIFT)
> +#define MAXIM_CONTROL2_ACCDET_MASK (0x1 << MAXIM_CONTROL2_ACCDET_SHIFT)
> +#define MAXIM_CONTROL2_USBCPINT_MASK (0x1 << MAXIM_CONTROL2_USBCPINT_SHIFT)
> +#define MAXIM_CONTROL2_RCPS_MASK (0x1 << MAXIM_CONTROL2_RCPS_SHIFT)
> +
> +#define MAXIM_CONTROL2_CPEN1_LOWPWR0 ((1 << MAXIM_CONTROL2_CPEN_SHIFT) | \
> + (0 << MAXIM_CONTROL2_LOWPWR_SHIFT))
> +#define MAXIM_CONTROL2_CPEN0_LOWPWR1 ((0 << MAXIM_CONTROL2_CPEN_SHIFT) | \
> + (1 << MAXIM_CONTROL2_LOWPWR_SHIFT))
>
> /* MAX14577 CONTROL3 register */
> -#define CTRL3_JIGSET_SHIFT 0
> -#define CTRL3_BOOTSET_SHIFT 2
> -#define CTRL3_ADCDBSET_SHIFT 4
> -#define CTRL3_JIGSET_MASK (0x3 << CTRL3_JIGSET_SHIFT)
> -#define CTRL3_BOOTSET_MASK (0x3 << CTRL3_BOOTSET_SHIFT)
> -#define CTRL3_ADCDBSET_MASK (0x3 << CTRL3_ADCDBSET_SHIFT)
> -
> -/* Slave addr = 0x4A: Charger */
> -enum max14577_charger_reg {
> - MAX14577_CHG_REG_STATUS3 = 0x06,
> - MAX14577_CHG_REG_CHG_CTRL1 = 0x0F,
> - MAX14577_CHG_REG_CHG_CTRL2 = 0x10,
> - MAX14577_CHG_REG_CHG_CTRL3 = 0x11,
> - MAX14577_CHG_REG_CHG_CTRL4 = 0x12,
> - MAX14577_CHG_REG_CHG_CTRL5 = 0x13,
> - MAX14577_CHG_REG_CHG_CTRL6 = 0x14,
> - MAX14577_CHG_REG_CHG_CTRL7 = 0x15,
> -
> - MAX14577_CHG_REG_END,
> -};
> -
> -/* MAX14577 STATUS3 register */
> -#define STATUS3_EOC_SHIFT 0
> -#define STATUS3_CGMBC_SHIFT 1
> -#define STATUS3_OVP_SHIFT 2
> -#define STATUS3_MBCCHGERR_SHIFT 3
> -#define STATUS3_EOC_MASK (0x1 << STATUS3_EOC_SHIFT)
> -#define STATUS3_CGMBC_MASK (0x1 << STATUS3_CGMBC_SHIFT)
> -#define STATUS3_OVP_MASK (0x1 << STATUS3_OVP_SHIFT)
> -#define STATUS3_MBCCHGERR_MASK (0x1 << STATUS3_MBCCHGERR_SHIFT)
> +#define MAXIM_CONTROL3_JIGSET_SHIFT 0
> +#define MAXIM_CONTROL3_BOOTSET_SHIFT 2
> +#define MAXIM_CONTROL3_ADCDBSET_SHIFT 4
> +#define MAXIM_CONTROL3_JIGSET_MASK (0x3 << MAXIM_CONTROL3_JIGSET_SHIFT)
> +#define MAXIM_CONTROL3_BOOTSET_MASK (0x3 << MAXIM_CONTROL3_BOOTSET_SHIFT)
> +#define MAXIM_CONTROL3_ADCDBSET_MASK (0x3 << MAXIM_CONTROL3_ADCDBSET_SHIFT)
>
> /* MAX14577 CDETCTRL1 register */
> -#define CDETCTRL1_CHGDETEN_SHIFT 0
> -#define CDETCTRL1_CHGTYPMAN_SHIFT 1
> -#define CDETCTRL1_DCDEN_SHIFT 2
> -#define CDETCTRL1_DCD2SCT_SHIFT 3
> -#define CDETCTRL1_DCHKTM_SHIFT 4
> -#define CDETCTRL1_DBEXIT_SHIFT 5
> -#define CDETCTRL1_DBIDLE_SHIFT 6
> -#define CDETCTRL1_CDPDET_SHIFT 7
> -#define CDETCTRL1_CHGDETEN_MASK (0x1 << CDETCTRL1_CHGDETEN_SHIFT)
> -#define CDETCTRL1_CHGTYPMAN_MASK (0x1 << CDETCTRL1_CHGTYPMAN_SHIFT)
> -#define CDETCTRL1_DCDEN_MASK (0x1 << CDETCTRL1_DCDEN_SHIFT)
> -#define CDETCTRL1_DCD2SCT_MASK (0x1 << CDETCTRL1_DCD2SCT_SHIFT)
> -#define CDETCTRL1_DCHKTM_MASK (0x1 << CDETCTRL1_DCHKTM_SHIFT)
> -#define CDETCTRL1_DBEXIT_MASK (0x1 << CDETCTRL1_DBEXIT_SHIFT)
> -#define CDETCTRL1_DBIDLE_MASK (0x1 << CDETCTRL1_DBIDLE_SHIFT)
> -#define CDETCTRL1_CDPDET_MASK (0x1 << CDETCTRL1_CDPDET_SHIFT)
> -
> -/* MAX14577 CHGCTRL1 register */
> -#define CHGCTRL1_TCHW_SHIFT 4
> -#define CHGCTRL1_TCHW_MASK (0x7 << CHGCTRL1_TCHW_SHIFT)
> -
> -/* MAX14577 CHGCTRL2 register */
> -#define CHGCTRL2_MBCHOSTEN_SHIFT 6
> -#define CHGCTRL2_MBCHOSTEN_MASK (0x1 << CHGCTRL2_MBCHOSTEN_SHIFT)
> -#define CHGCTRL2_VCHGR_RC_SHIFT 7
> -#define CHGCTRL2_VCHGR_RC_MASK (0x1 << CHGCTRL2_VCHGR_RC_SHIFT)
> -
> -/* MAX14577 CHGCTRL3 register */
> -#define CHGCTRL3_MBCCVWRC_SHIFT 0
> -#define CHGCTRL3_MBCCVWRC_MASK (0xf << CHGCTRL3_MBCCVWRC_SHIFT)
> -
> -/* MAX14577 CHGCTRL4 register */
> -#define CHGCTRL4_MBCICHWRCH_SHIFT 0
> -#define CHGCTRL4_MBCICHWRCH_MASK (0xf << CHGCTRL4_MBCICHWRCH_SHIFT)
> -#define CHGCTRL4_MBCICHWRCL_SHIFT 4
> -#define CHGCTRL4_MBCICHWRCL_MASK (0x1 << CHGCTRL4_MBCICHWRCL_SHIFT)
> -
> -/* MAX14577 CHGCTRL5 register */
> -#define CHGCTRL5_EOCS_SHIFT 0
> -#define CHGCTRL5_EOCS_MASK (0xf << CHGCTRL5_EOCS_SHIFT)
> -
> -/* MAX14577 CHGCTRL6 register */
> -#define CHGCTRL6_AUTOSTOP_SHIFT 5
> -#define CHGCTRL6_AUTOSTOP_MASK (0x1 << CHGCTRL6_AUTOSTOP_SHIFT)
> -
> -/* MAX14577 CHGCTRL7 register */
> -#define CHGCTRL7_OTPCGHCVS_SHIFT 0
> -#define CHGCTRL7_OTPCGHCVS_MASK (0x3 << CHGCTRL7_OTPCGHCVS_SHIFT)
> -
> -/* MAX14577 regulator current limits (as in CHGCTRL4 register), uA */
> +#define MAXIM_CDETCTRL1_CHGDETEN_SHIFT 0
> +#define MAXIM_CDETCTRL1_CHGTYPMAN_SHIFT 1
> +#define MAXIM_CDETCTRL1_DCDEN_SHIFT 2
> +#define MAXIM_CDETCTRL1_DCD2SCT_SHIFT 3
> +#define MAXIM_CDETCTRL1_DCHKTM_SHIFT 4
> +#define MAXIM_CDETCTRL1_DBEXIT_SHIFT 5
> +#define MAXIM_CDETCTRL1_DBIDLE_SHIFT 6
> +#define MAXIM_CDETCTRL1_CDPDET_SHIFT 7
> +#define MAXIM_CDETCTRL1_CHGDETEN_MASK (0x1 << MAXIM_CDETCTRL1_CHGDETEN_SHIFT)
> +#define MAXIM_CDETCTRL1_CHGTYPMAN_MASK (0x1 << MAXIM_CDETCTRL1_CHGTYPMAN_SHIFT)
> +#define MAXIM_CDETCTRL1_DCDEN_MASK (0x1 << MAXIM_CDETCTRL1_DCDEN_SHIFT)
> +#define MAXIM_CDETCTRL1_DCD2SCT_MASK (0x1 << MAXIM_CDETCTRL1_DCD2SCT_SHIFT)
> +#define MAXIM_CDETCTRL1_DCHKTM_MASK (0x1 << MAXIM_CDETCTRL1_DCHKTM_SHIFT)
> +#define MAXIM_CDETCTRL1_DBEXIT_MASK (0x1 << MAXIM_CDETCTRL1_DBEXIT_SHIFT)
> +#define MAXIM_CDETCTRL1_DBIDLE_MASK (0x1 << MAXIM_CDETCTRL1_DBIDLE_SHIFT)
> +#define MAXIM_CDETCTRL1_CDPDET_MASK (0x1 << MAXIM_CDETCTRL1_CDPDET_SHIFT)
> +
> +/* MAX14577 MAXIM_CHGCTRL1 register */
> +#define MAXIM_CHGCTRL1_TCHW_SHIFT 4
> +#define MAXIM_CHGCTRL1_TCHW_MASK (0x7 << MAXIM_CHGCTRL1_TCHW_SHIFT)
> +
> +/* MAX14577 MAXIM_CHGCTRL2 register */
> +#define MAXIM_CHGCTRL2_MBCHOSTEN_SHIFT 6
> +#define MAXIM_CHGCTRL2_MBCHOSTEN_MASK (0x1 << MAXIM_CHGCTRL2_MBCHOSTEN_SHIFT)
> +#define MAXIM_CHGCTRL2_VCHGR_RC_SHIFT 7
> +#define MAXIM_CHGCTRL2_VCHGR_RC_MASK (0x1 << MAXIM_CHGCTRL2_VCHGR_RC_SHIFT)
> +
> +/* MAX14577 MAXIM_CHGCTRL3 register */
> +#define MAXIM_CHGCTRL3_MBCCVWRC_SHIFT 0
> +#define MAXIM_CHGCTRL3_MBCCVWRC_MASK (0xf << MAXIM_CHGCTRL3_MBCCVWRC_SHIFT)
> +
> +/* MAX14577 MAXIM_CHGCTRL4 register */
> +#define MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT 0
> +#define MAXIM_CHGCTRL4_MBCICHWRCH_MASK (0xf << MAXIM_CHGCTRL4_MBCICHWRCH_SHIFT)
> +#define MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT 4
> +#define MAXIM_CHGCTRL4_MBCICHWRCL_MASK (0x1 << MAXIM_CHGCTRL4_MBCICHWRCL_SHIFT)
> +
> +/* MAX14577 MAXIM_CHGCTRL5 register */
> +#define MAXIM_CHGCTRL5_EOCS_SHIFT 0
> +#define MAXIM_CHGCTRL5_EOCS_MASK (0xf << MAXIM_CHGCTRL5_EOCS_SHIFT)
> +
> +/* MAX14577 MAXIM_CHGCTRL6 register */
> +#define MAXIM_CHGCTRL6_AUTOSTOP_SHIFT 5
> +#define MAXIM_CHGCTRL6_AUTOSTOP_MASK (0x1 << MAXIM_CHGCTRL6_AUTOSTOP_SHIFT)
> +
> +/* MAX14577 MAXIM_CHGCTRL7 register */
> +#define MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT 0
> +#define MAXIM_CHGCTRL7_OTPCGHCVS_MASK (0x3 << MAXIM_CHGCTRL7_OTPCGHCVS_SHIFT)
> +
> +/* MAX14577 regulator current limits (as in MAXIM_CHGCTRL4 register), uA */
> #define MAX14577_REGULATOR_CURRENT_LIMIT_MIN 90000
> #define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START 200000
> #define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP 50000
> @@ -248,26 +223,28 @@ enum max14577_charger_reg {
> /* MAX14577 regulator SFOUT LDO voltage, fixed, uV */
> #define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000
>
> -enum max14577_irq {
> +
> +
> +enum maxim_irq {
> /* INT1 */
> - MAX14577_IRQ_INT1_ADC,
> - MAX14577_IRQ_INT1_ADCLOW,
> - MAX14577_IRQ_INT1_ADCERR,
> + MAXIM_IRQ_INT1_ADC,
> + MAXIM_IRQ_INT1_ADCLOW,
> + MAXIM_IRQ_INT1_ADCERR,
>
> /* INT2 */
> - MAX14577_IRQ_INT2_CHGTYP,
> - MAX14577_IRQ_INT2_CHGDETRUN,
> - MAX14577_IRQ_INT2_DCDTMR,
> - MAX14577_IRQ_INT2_DBCHG,
> - MAX14577_IRQ_INT2_VBVOLT,
> + MAXIM_IRQ_INT2_CHGTYP,
> + MAXIM_IRQ_INT2_CHGDETRUN,
> + MAXIM_IRQ_INT2_DCDTMR,
> + MAXIM_IRQ_INT2_DBCHG,
> + MAXIM_IRQ_INT2_VBVOLT,
>
> /* INT3 */
> - MAX14577_IRQ_INT3_EOC,
> - MAX14577_IRQ_INT3_CGMBC,
> - MAX14577_IRQ_INT3_OVP,
> - MAX14577_IRQ_INT3_MBCCHGERR,
> + MAXIM_IRQ_INT3_EOC,
> + MAXIM_IRQ_INT3_CGMBC,
> + MAXIM_IRQ_INT3_OVP,
> + MAXIM_IRQ_INT3_MBCCHGERR,
>
> - MAX14577_IRQ_NUM,
> + MAXIM_IRQ_NUM,
> };
>
> struct max14577 {
> diff --git a/include/linux/mfd/max14577.h b/include/linux/mfd/max14577.h
> index 736d39c3ec0d..75301be5c548 100644
> --- a/include/linux/mfd/max14577.h
> +++ b/include/linux/mfd/max14577.h
> @@ -32,7 +32,7 @@ enum max14577_regulators {
> MAX14577_SAFEOUT = 0,
> MAX14577_CHARGER,
>
> - MAX14577_REG_MAX,
> + MAX14577_REG_NUM,
> };
>
> struct max14577_regulator_platform_data {
On Wed, Feb 19, 2014 at 01:44:41PM +0100, Krzysztof Kozlowski wrote:
> I want to push whole MAX77836 patchset through Lee Jones' MFD tree and I
> still need acks from power and regulator subsystems.
> I would appreciate if you could find time to look at these patches and
> let me know your opinion (or just add Acked-by):
> [PATCH v3 02/15] mfd: max14577: Rename and add MAX14577 symbols...
> [PATCH v3 03/15] mfd: max14577: Rename state container to maxim_core
> [PATCH v3 04/15] mfd: max14577: Add "muic" suffix to regmap and irq_chip
I don't have these patches, I expect it looked like the series was going
to get a respin.
To be honest the number of large patch serieses you've been sending
iterations of (sometimes partial series without context too) doesn't
push them up the priority list, it'd help to rate limit things a bit.
Hi,
On 17.02.2014 10:05, Krzysztof Kozlowski wrote:
> Add document describing device tree bindings for MAX14577 MFD
> drivers: MFD core, extcon, regulator and charger.
>
> Both MAX14577 and MAX77836 chipsets are documented.
>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> Cc: Kyungmin Park <[email protected]>
> Cc: Tomasz Figa <[email protected]>
> Cc: Marek Szyprowski <[email protected]>
> Cc: [email protected]
> Cc: Rob Herring <[email protected]>
> Cc: Pawel Moll <[email protected]>
> Cc: Mark Rutland <[email protected]>
> ---
> Documentation/devicetree/bindings/mfd/max14577.txt | 149 ++++++++++++++++++++
> 1 file changed, 149 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/mfd/max14577.txt
Reviewed-by: Tomasz Figa <[email protected]>
Best regards,
Tomasz
Hi,
On 17.02.2014 10:05, Krzysztof Kozlowski wrote:
> Add document describing device tree bindings for MAX14577 MFD
> drivers: MFD core, extcon, regulator and charger.
>
> Both MAX14577 and MAX77836 chipsets are documented.
>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> Cc: Kyungmin Park <[email protected]>
> Cc: Tomasz Figa <[email protected]>
> Cc: Marek Szyprowski <[email protected]>
> Cc: [email protected]
> Cc: Rob Herring <[email protected]>
> Cc: Pawel Moll <[email protected]>
> Cc: Mark Rutland <[email protected]>
> ---
> Documentation/devicetree/bindings/mfd/max14577.txt | 149 ++++++++++++++++++++
> 1 file changed, 149 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/mfd/max14577.txt
OK, so the "maxim,max14577" compatible string somehow showed up in the
kernel without any documentation, interesting...
Anyway:
Reviewed-by: Tomasz Figa <[email protected]>
Best regards,
Tomasz
On Mon, Feb 17, 2014 at 10:05:49AM +0100, Krzysztof Kozlowski wrote:
> +static inline int max14577_init_eoc(struct max14577_charger *chg,
> + unsigned int uamp)
> +{
> + unsigned int current_bits = 0xf;
> + u8 reg_data;
> +
> + switch (chg->maxim_core->dev_type) {
> + case MAXIM_DEVICE_TYPE_MAX77836:
> + if (uamp < 5000)
> + return -EINVAL; /* Requested current is too low */
> +
> + if (uamp == 7500)
> + current_bits = 0x0;
if (uamp <= 7500) ?
> + /* Initialize Overvoltage-Protection Threshold */
> + switch (chg->pdata->ovp_uvolt) {
> + case 7500000:
> + reg_data = 0x0;
> + break;
> + case 6000000:
> + case 6500000:
> + case 7000000:
> + reg_data = 0x1 + (chg->pdata->ovp_uvolt - 6000000) / 500000;
> + break;
Is it battery OVP or charger source OVP? If it's battery OVP, then minimum
level as 6V seems to be unsafe even for 4.4V batteries.
On Thu, 2014-02-20 at 12:00 +0530, Jenny Tc wrote:
> On Mon, Feb 17, 2014 at 10:05:49AM +0100, Krzysztof Kozlowski wrote:
> > +static inline int max14577_init_eoc(struct max14577_charger *chg,
> > + unsigned int uamp)
> > +{
> > + unsigned int current_bits = 0xf;
> > + u8 reg_data;
> > +
> > + switch (chg->maxim_core->dev_type) {
> > + case MAXIM_DEVICE_TYPE_MAX77836:
> > + if (uamp < 5000)
> > + return -EINVAL; /* Requested current is too low */
> > +
> > + if (uamp == 7500)
> > + current_bits = 0x0;
>
> if (uamp <= 7500) ?
(uamp < 7500) will be mapped to 5000 uA (0x1) so it will be OK. It is
safer to use lower current. The register description looks like:
0000 - 7.5 mA
0001 - 5 mA
0010 - 10 mA
0011 - 15 mA
...
1010 - 50 mA
1011 - 60 mA
1111 - 100 mA
However for value between <7501, 9999> this function will return 0x1
(5000 uA) which is not perfect. Better is to return 0x0 (7500 uA).
I'll fix this in next version of patch.
>
> > + /* Initialize Overvoltage-Protection Threshold */
> > + switch (chg->pdata->ovp_uvolt) {
> > + case 7500000:
> > + reg_data = 0x0;
> > + break;
> > + case 6000000:
> > + case 6500000:
> > + case 7000000:
> > + reg_data = 0x1 + (chg->pdata->ovp_uvolt - 6000000) / 500000;
> > + break;
>
> Is it battery OVP or charger source OVP? If it's battery OVP, then minimum
> level as 6V seems to be unsafe even for 4.4V batteries.
It is on charger (input). Anyway only these 4 values are supported (6.0,
6.5, 7.0, 7.5 volts).
Best regards,
Krzysztof
On Wed, 2014-02-19 at 23:11 +0900, Mark Brown wrote:
> On Wed, Feb 19, 2014 at 01:44:41PM +0100, Krzysztof Kozlowski wrote:
>
> > I want to push whole MAX77836 patchset through Lee Jones' MFD tree and I
> > still need acks from power and regulator subsystems.
>
> > I would appreciate if you could find time to look at these patches and
> > let me know your opinion (or just add Acked-by):
> > [PATCH v3 02/15] mfd: max14577: Rename and add MAX14577 symbols...
> > [PATCH v3 03/15] mfd: max14577: Rename state container to maxim_core
> > [PATCH v3 04/15] mfd: max14577: Add "muic" suffix to regmap and irq_chip
>
> I don't have these patches, I expect it looked like the series was going
> to get a respin.
Hmmm, I'll send the next version of this patchset.
>
> To be honest the number of large patch serieses you've been sending
> iterations of (sometimes partial series without context too) doesn't
> push them up the priority list, it'd help to rate limit things a bit.
I understand, especially that such drivers touch multiple subsystems.
Best regards,
Krzysztof