Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a55d952a authored by Chanwoo Choi's avatar Chanwoo Choi
Browse files

Merge tag 'ib-mfd-extcon-3.16' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd into HEAD

Immutable branch between MFD and Extcon due for v3.16 merge-window.
parents bf9509e0 8a82b408
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -28,13 +28,13 @@ config EXTCON_ADC_JACK
	  Say Y here to enable extcon device driver based on ADC values.

config EXTCON_MAX14577
	tristate "MAX14577 EXTCON Support"
	tristate "MAX14577/77836 EXTCON Support"
	depends on MFD_MAX14577
	select IRQ_DOMAIN
	select REGMAP_I2C
	help
	  If you say yes here you get support for the MUIC device of
	  Maxim MAX14577 PMIC. The MAX14577 MUIC is a USB port accessory
	  Maxim MAX14577/77836. The MAX14577/77836 MUIC is a USB port accessory
	  detector and switch.

config EXTCON_MAX77693
+127 −47
Original line number Diff line number Diff line
/*
 * 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 <cw00.choi@samsung.com>
 * Krzysztof Kozlowski <k.kozlowski@samsung.com>
 *
 * 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
@@ -24,7 +25,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 {
@@ -40,6 +40,42 @@ 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[] = {
	{ 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" },
};

static struct max14577_muic_irq max77836_muic_irqs[] = {
	{ MAX14577_IRQ_INT1_ADC,	"muic-ADC" },
	{ MAX14577_IRQ_INT1_ADCLOW,	"muic-ADCLOW" },
	{ MAX14577_IRQ_INT1_ADCERR,	"muic-ADCError" },
	{ MAX77836_IRQ_INT1_ADC1K,	"muic-ADC1K" },
	{ 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" },
	{ MAX77836_IRQ_INT2_VIDRM,	"muic-VIDRM" },
};

struct max14577_muic_info {
	struct device *dev;
	struct max14577 *max14577;
@@ -48,6 +84,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;
@@ -74,29 +112,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 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" },
};

/* Define supported accessory type */
enum max14577_muic_acc_type {
	MAX14577_MUIC_ADC_GROUND = 0x0,
@@ -528,21 +543,12 @@ static void max14577_muic_irq_work(struct work_struct *work)
	return;
}

static irqreturn_t max14577_muic_irq_handler(int irq, void *data)
{
	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.
 * 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.
 */
	for (i = 0; i < ARRAY_SIZE(muic_irqs); i++)
		if (irq == muic_irqs[i].virq)
			irq_type = muic_irqs[i].irq;

static int max14577_parse_irq(struct max14577_muic_info *info, int irq_type)
{
	switch (irq_type) {
	case MAX14577_IRQ_INT1_ADC:
	case MAX14577_IRQ_INT1_ADCLOW:
@@ -550,7 +556,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 MAX14577_IRQ_INT2_CHGTYP:
	case MAX14577_IRQ_INT2_CHGDETRUN:
	case MAX14577_IRQ_INT2_DCDTMR:
@@ -558,8 +564,62 @@ static irqreturn_t max14577_muic_irq_handler(int irq, void *data)
	case MAX14577_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->max14577->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;
@@ -644,9 +704,20 @@ static int max14577_muic_probe(struct platform_device *pdev)

	INIT_WORK(&info->irq_work, max14577_muic_irq_work);

	switch (max14577->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;
		info->muic_irqs_num = ARRAY_SIZE(max14577_muic_irqs);
	}

	/* 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 < info->muic_irqs_num; i++) {
		struct max14577_muic_irq *muic_irq = &info->muic_irqs[i];
		unsigned int virq = 0;

		virq = regmap_irq_get_virq(max14577->irq_data, muic_irq->irq);
@@ -673,7 +744,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) {
@@ -735,18 +807,26 @@ 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	= DEV_NAME,
		.name	= "max14577-muic",
		.owner	= THIS_MODULE,
	},
	.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 <cw00.choi@samsung.com>");
MODULE_DESCRIPTION("Maxim 14577/77836 Extcon driver");
MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>, Krzysztof Kozlowski <k.kozlowski@samsung.com>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:extcon-max14577");
+3 −3
Original line number Diff line number Diff line
@@ -331,15 +331,15 @@ config MFD_88PM860X
	  battery-charger under the corresponding menus.

config MFD_MAX14577
	bool "Maxim Semiconductor MAX14577 MUIC + Charger Support"
	bool "Maxim Semiconductor MAX14577/77836 MUIC + Charger Support"
	depends on I2C=y
	select MFD_CORE
	select REGMAP_I2C
	select REGMAP_IRQ
	select IRQ_DOMAIN
	help
	  Say yes here to add support for Maxim Semiconductor MAX14577.
	  This is a Micro-USB IC with Charger controls on chip.
	  Say yes here to add support for Maxim Semiconductor MAX14577 and
	  MAX77836 Micro-USB ICs with battery charger.
	  This driver provides common support for accessing the device;
	  additional drivers must be enabled in order to use the functionality
	  of the device.
+272 −43
Original line number Diff line number Diff line
/*
 * 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 <cw00.choi@samsung.com>
 * Krzysztof Kozlowski <k.kozlowski@samsung.com>
 *
@@ -21,6 +21,7 @@
#include <linux/err.h>
#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>
@@ -37,7 +38,38 @@ static struct mfd_cell max14577_devs[] = {
	{ .name = "max14577-charger", },
};

static bool max14577_volatile_reg(struct device *dev, unsigned int reg)
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,
	},
	{},
};

static bool max14577_muic_volatile_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case MAX14577_REG_INT1 ... MAX14577_REG_STATUS3:
@@ -48,49 +80,221 @@ static bool max14577_volatile_reg(struct device *dev, unsigned int reg)
	return false;
}

static const struct regmap_config max14577_regmap_config = {
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,
	.volatile_reg	= max14577_volatile_reg,
	.volatile_reg	= max14577_muic_volatile_reg,
	.max_register	= MAX14577_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 = INT1_ADC_MASK, },
	{ .reg_offset = 0, .mask = INT1_ADCLOW_MASK, },
	{ .reg_offset = 0, .mask = INT1_ADCERR_MASK, },
	{ .reg_offset = 0, .mask = MAX14577_INT1_ADC_MASK, },
	{ .reg_offset = 0, .mask = MAX14577_INT1_ADCLOW_MASK, },
	{ .reg_offset = 0, .mask = MAX14577_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 = MAX14577_INT2_CHGTYP_MASK, },
	{ .reg_offset = 1, .mask = MAX14577_INT2_CHGDETRUN_MASK, },
	{ .reg_offset = 1, .mask = MAX14577_INT2_DCDTMR_MASK, },
	{ .reg_offset = 1, .mask = MAX14577_INT2_DBCHG_MASK, },
	{ .reg_offset = 1, .mask = MAX14577_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 = MAX14577_INT3_EOC_MASK, },
	{ .reg_offset = 2, .mask = MAX14577_INT3_CGMBC_MASK, },
	{ .reg_offset = 2, .mask = MAX14577_INT3_OVP_MASK, },
	{ .reg_offset = 2, .mask = MAX14577_INT3_MBCCHGERR_MASK, },
};

static const struct regmap_irq_chip max14577_irq_chip = {
	.name			= "max14577",
	.status_base		= MAX14577_REG_INT1,
	.mask_base		= MAX14577_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 = MAX14577_INT1_ADC_MASK, },
	{ .reg_offset = 0, .mask = MAX14577_INT1_ADCLOW_MASK, },
	{ .reg_offset = 0, .mask = MAX14577_INT1_ADCERR_MASK, },
	{ .reg_offset = 0, .mask = MAX77836_INT1_ADC1K_MASK, },
	/* INT2 interrupts */
	{ .reg_offset = 1, .mask = MAX14577_INT2_CHGTYP_MASK, },
	{ .reg_offset = 1, .mask = MAX14577_INT2_CHGDETRUN_MASK, },
	{ .reg_offset = 1, .mask = MAX14577_INT2_DCDTMR_MASK, },
	{ .reg_offset = 1, .mask = MAX14577_INT2_DBCHG_MASK, },
	{ .reg_offset = 1, .mask = MAX14577_INT2_VBVOLT_MASK, },
	{ .reg_offset = 1, .mask = MAX77836_INT2_VIDRM_MASK, },
	/* INT3 interrupts */
	{ .reg_offset = 2, .mask = MAX14577_INT3_EOC_MASK, },
	{ .reg_offset = 2, .mask = MAX14577_INT3_CGMBC_MASK, },
	{ .reg_offset = 2, .mask = MAX14577_INT3_OVP_MASK, },
	{ .reg_offset = 2, .mask = MAX14577_INT3_MBCCHGERR_MASK, },
};

static const struct regmap_irq_chip max77836_muic_irq_chip = {
	.name			= "max77836-muic",
	.status_base		= MAX14577_REG_INT1,
	.mask_base		= MAX14577_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 max14577 *max14577)
{
	u8 reg_data, vendor_id, device_id;
	int ret;

	ret = max14577_read_reg(max14577->regmap, MAX14577_REG_DEVICEID,
			&reg_data);
	if (ret) {
		dev_err(max14577->dev,
			"Failed to read DEVICEID register: %d\n", ret);
		return;
	}

	vendor_id = ((reg_data & DEVID_VENDORID_MASK) >>
				DEVID_VENDORID_SHIFT);
	device_id = ((reg_data & DEVID_DEVICEID_MASK) >>
				DEVID_DEVICEID_SHIFT);

	dev_info(max14577->dev, "Device type: %u (ID: 0x%x, vendor: 0x%x)\n",
			max14577->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 max14577 *max14577)
{
	int ret;
	u8 intsrc_mask;

	max14577->i2c_pmic = i2c_new_dummy(max14577->i2c->adapter,
			I2C_ADDR_PMIC);
	if (!max14577->i2c_pmic) {
		dev_err(max14577->dev, "Failed to register PMIC I2C device\n");
		return -ENODEV;
	}
	i2c_set_clientdata(max14577->i2c_pmic, max14577);

	max14577->regmap_pmic = devm_regmap_init_i2c(max14577->i2c_pmic,
			&max77836_pmic_regmap_config);
	if (IS_ERR(max14577->regmap_pmic)) {
		ret = PTR_ERR(max14577->regmap_pmic);
		dev_err(max14577->dev, "Failed to allocate PMIC register map: %d\n",
				ret);
		goto err;
	}

	/* Un-mask MAX77836 Interrupt Source register */
	ret = max14577_read_reg(max14577->regmap_pmic,
			MAX77836_PMIC_REG_INTSRC_MASK, &intsrc_mask);
	if (ret < 0) {
		dev_err(max14577->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(max14577->regmap_pmic,
			MAX77836_PMIC_REG_INTSRC_MASK, intsrc_mask);
	if (ret < 0) {
		dev_err(max14577->dev, "Failed to write PMIC register\n");
		goto err;
	}

	ret = regmap_add_irq_chip(max14577->regmap_pmic, max14577->irq,
			IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED,
			0, &max77836_pmic_irq_chip,
			&max14577->irq_data_pmic);
	if (ret != 0) {
		dev_err(max14577->dev, "Failed to request PMIC IRQ %d: %d\n",
				max14577->irq, ret);
		goto err;
	}

	return 0;

err:
	i2c_unregister_device(max14577->i2c_pmic);

	return ret;
}

/*
 * Max77836 specific de-initialization code for driver remove.
 */
static void max77836_remove(struct max14577 *max14577)
{
	regmap_del_irq_chip(max14577->irq, max14577->irq_data_pmic);
	i2c_unregister_device(max14577->i2c_pmic);
}

static int max14577_i2c_probe(struct i2c_client *i2c,
			      const struct i2c_device_id *id)
{
	struct max14577 *max14577;
	struct max14577_platform_data *pdata = dev_get_platdata(&i2c->dev);
	struct device_node *np = i2c->dev.of_node;
	u8 reg_data;
	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);
@@ -113,7 +317,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",
@@ -121,23 +326,36 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
		return ret;
	}

	ret = max14577_read_reg(max14577->regmap, MAX14577_REG_DEVICEID,
			&reg_data);
	if (ret) {
		dev_err(max14577->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)
			max14577->dev_type = (unsigned int)of_id->data;
	} else {
		max14577->dev_type = id->driver_data;
	}

	max14577_print_dev_type(max14577);

	switch (max14577->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;
	}
	max14577->vendor_id = ((reg_data & DEVID_VENDORID_MASK) >>
				DEVID_VENDORID_SHIFT);
	max14577->device_id = ((reg_data & DEVID_DEVICEID_MASK) >>
				DEVID_DEVICEID_SHIFT);
	dev_info(max14577->dev, "Device ID: 0x%x, vendor: 0x%x\n",
			max14577->device_id, max14577->vendor_id);

	ret = regmap_add_irq_chip(max14577->regmap, max14577->irq,
				  IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 0,
				  &max14577_irq_chip,
				  irq_flags, 0, irq_chip,
				  &max14577->irq_data);
	if (ret != 0) {
		dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n",
@@ -145,8 +363,15 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
		return ret;
	}

	ret = mfd_add_devices(max14577->dev, -1, max14577_devs,
			ARRAY_SIZE(max14577_devs), NULL, 0,
	/* Max77836 specific initialization code (additional regmap) */
	if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) {
		ret = max77836_init(max14577);
		if (ret < 0)
			goto err_max77836;
	}

	ret = mfd_add_devices(max14577->dev, -1, mfd_devs,
			mfd_devs_size, NULL, 0,
			regmap_irq_get_domain(max14577->irq_data));
	if (ret < 0)
		goto err_mfd;
@@ -156,6 +381,9 @@ static int max14577_i2c_probe(struct i2c_client *i2c,
	return 0;

err_mfd:
	if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836)
		max77836_remove(max14577);
err_max77836:
	regmap_del_irq_chip(max14577->irq, max14577->irq_data);

	return ret;
@@ -167,12 +395,15 @@ static int max14577_i2c_remove(struct i2c_client *i2c)

	mfd_remove_devices(max14577->dev);
	regmap_del_irq_chip(max14577->irq, max14577->irq_data);
	if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836)
		max77836_remove(max14577);

	return 0;
}

static const struct i2c_device_id max14577_i2c_id[] = {
	{ "max14577", 0 },
	{ "max14577", MAXIM_DEVICE_TYPE_MAX14577, },
	{ "max77836", MAXIM_DEVICE_TYPE_MAX77836, },
	{ }
};
MODULE_DEVICE_TABLE(i2c, max14577_i2c_id);
@@ -215,11 +446,6 @@ static int max14577_resume(struct device *dev)
}
#endif /* CONFIG_PM_SLEEP */

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 = {
@@ -236,6 +462,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);
@@ -247,5 +476,5 @@ static void __exit max14577_i2c_exit(void)
module_exit(max14577_i2c_exit);

MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>, Krzysztof Kozlowski <k.kozlowski@samsung.com>");
MODULE_DESCRIPTION("MAXIM 14577 multi-function core driver");
MODULE_DESCRIPTION("Maxim 14577/77836 multi-function core driver");
MODULE_LICENSE("GPL");
+4 −3
Original line number Diff line number Diff line
@@ -266,11 +266,12 @@ config REGULATOR_LP8788
	  This driver supports LP8788 voltage regulator chip.

config REGULATOR_MAX14577
	tristate "Maxim 14577 regulator"
	tristate "Maxim 14577/77836 regulator"
	depends on MFD_MAX14577
	help
	  This driver controls a Maxim 14577 regulator via I2C bus.
	  The regulators include safeout LDO and current regulator 'CHARGER'.
	  This driver controls a Maxim MAX14577/77836 regulator via I2C bus.
	  The MAX14577 regulators include safeout LDO and charger current
	  regulator. The MAX77836 has two additional LDOs.

config REGULATOR_MAX1586
	tristate "Maxim 1586/1587 voltage regulator"
Loading