Skip to contentSkip to conversation

mfd: Intel SoC Power Management IC

PATCH RESEND Superseded Zhu, Lejun 3 participants 16 messages May 23, 2014 – May 28, 2014

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Zhu, Lejun

author
#0 lore raw

v2 cover mfd: Intel SoC Power Management IC

Devices based on Intel SoC products such as Baytrail have a Power Management IC. In the PMIC there are subsystems for voltage regulation, A/D conversion, GPIO and PWMs. The PMIC in Baytrail-T platform is called Crystal Cove.

This series contains common code for these PMICs, and device specific support for Crystal Cove.

v2:
- Use regmap instead of creating our own I2C read/write callbacks.
- Add one missing EXPORT_SYMBOL.
- Remove some duplicate code and put them into pmic_regmap_load_from_hw.

Zhu, Lejun (4):
mfd: intel_soc_pmic: Core driver
mfd: intel_soc_pmic: I2C interface
mfd: intel_soc_pmic: Crystal Cove support
mfd: intel_soc_pmic: Build files

 drivers/mfd/Kconfig                |  11 +
 drivers/mfd/Makefile               |   3 +
 drivers/mfd/intel_soc_pmic_core.c  | 521 +++++++++++++++++++++++++++++++++++++
 drivers/mfd/intel_soc_pmic_core.h  |  83 ++++++
 drivers/mfd/intel_soc_pmic_crc.c   | 165 ++++++++++++
 drivers/mfd/intel_soc_pmic_i2c.c   | 148 +++++++++++
 include/linux/mfd/intel_soc_pmic.h |  29 +++
 7 files changed, 960 insertions(+)
 create mode 100644 drivers/mfd/intel_soc_pmic_core.c
 create mode 100644 drivers/mfd/intel_soc_pmic_core.h
 create mode 100644 drivers/mfd/intel_soc_pmic_crc.c
 create mode 100644 drivers/mfd/intel_soc_pmic_i2c.c
 create mode 100644 include/linux/mfd/intel_soc_pmic.h
Signature · 1 line
1.8.3.2
author
#1 lore raw

PATCH RESEND v2 1/4 mfd: intel_soc_pmic: Core driver

This patch provides the common code for the intel_soc_pmic MFD driver, such as read/write register and set up IRQ.

v2:
- Use regmap instead of our own callbacks for read/write.
- Add one missing EXPORT_SYMBOL.
- Remove some duplicate code and put them into pmic_regmap_load_from_hw.

---
 drivers/mfd/intel_soc_pmic_core.c  | 521 +++++++++++++++++++++++++++++++++++++
 drivers/mfd/intel_soc_pmic_core.h  |  83 ++++++
 include/linux/mfd/intel_soc_pmic.h |  29 +++
 3 files changed, 633 insertions(+)
 create mode 100644 drivers/mfd/intel_soc_pmic_core.c
 create mode 100644 drivers/mfd/intel_soc_pmic_core.h
 create mode 100644 include/linux/mfd/intel_soc_pmic.h
drivers/mfd/intel_soc_pmic_core.c new file +521 -0
new file mode 100644
index 0000000..76d366e
@@ -0,0 +1,521 @@
+/*
+ * intel_soc_pmic_core.c - Intel SoC PMIC Core Functions
+ *
+ * Copyright (C) 2013, 2014 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Author: Yang, Bin <[email protected]>
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/mutex.h>
+#include <linux/mfd/core.h>
+#include <linux/err.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/workqueue.h>
+#include <linux/acpi.h>
+#include <linux/version.h>
+#include <linux/gpio.h>
+#include <linux/regmap.h>
+#include <linux/mfd/intel_soc_pmic.h>
+#include "intel_soc_pmic_core.h"
+
+struct cell_dev_pdata {
+	struct list_head	list;
+	const char		*name;
+	void			*data;
+	int			len;
+};
+static LIST_HEAD(pdata_list);
+
+static DEFINE_MUTEX(pmic_lock);	/* protect the following variables */
+static struct intel_soc_pmic *pmic;
+static int cache_offset = -1;
+static unsigned int cache_read_val;
+static unsigned int cache_write_val;
+static int cache_write_pending;
+static int cache_flags;
+
+struct device *intel_soc_pmic_dev(void)
+{
+	return pmic->dev;
+}
+EXPORT_SYMBOL(intel_soc_pmic_dev);
+
+/*
+ * Read from a PMIC register
+ */
+int intel_soc_pmic_readb(int reg)
+{
+	int ret;
+	unsigned int val;
+
+	mutex_lock(&pmic_lock);
+
+	if (!pmic) {
+		ret = -EIO;
+	} else {
+		ret = regmap_read(pmic->regmap, reg, &val);
+		if (!ret)
+			ret = val;
+	}
+
+	mutex_unlock(&pmic_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(intel_soc_pmic_readb);
+
+/*
+ * Write to a PMIC register
+ */
+int intel_soc_pmic_writeb(int reg, u8 val)
+{
+	int ret;
+
+	mutex_lock(&pmic_lock);
+
+	if (!pmic)
+		ret = -EIO;
+	else
+		ret = regmap_write(pmic->regmap, reg, val);
+
+	mutex_unlock(&pmic_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(intel_soc_pmic_writeb);
+
+/*
+ * Set 1 bit in a PMIC register
+ */
+int intel_soc_pmic_setb(int reg, u8 mask)
+{
+	int ret;
+
+	mutex_lock(&pmic_lock);
+
+	if (!pmic)
+		ret = -EIO;
+	else
+		ret = regmap_update_bits(pmic->regmap, reg, mask, mask);
+
+	mutex_unlock(&pmic_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(intel_soc_pmic_setb);
+
+/*
+ * Clear 1 bit in a PMIC register
+ */
+int intel_soc_pmic_clearb(int reg, u8 mask)
+{
+	int ret;
+
+	mutex_lock(&pmic_lock);
+
+	if (!pmic)
+		ret = -EIO;
+	else
+		ret = regmap_update_bits(pmic->regmap, reg, mask, 0);
+
+	mutex_unlock(&pmic_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(intel_soc_pmic_clearb);
+
+/*
+ * Set and clear multiple bits of a PMIC register
+ */
+int intel_soc_pmic_update(int reg, u8 val, u8 mask)
+{
+	int ret;
+
+	mutex_lock(&pmic_lock);
+
+	if (!pmic)
+		ret = -EIO;
+	else
+		ret = regmap_update_bits(pmic->regmap, reg, mask, val);
+
+	mutex_unlock(&pmic_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(intel_soc_pmic_update);
+
+/*
+ * Set platform_data of the child devices. Needs to be called before
+ * the MFD device is added.
+ */
+int intel_soc_pmic_set_pdata(const char *name, void *data, int len)
+{
+	struct cell_dev_pdata *pdata;
+
+	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+	if (!pdata) {
+		pr_err("intel_pmic: can't set pdata!\n");
+		return -ENOMEM;
+	}
+
+	pdata->name = name;
+	pdata->data = data;
+	pdata->len = len;
+
+	list_add_tail(&pdata->list, &pdata_list);
+
+	return 0;
+}
+EXPORT_SYMBOL(intel_soc_pmic_set_pdata);
+
+static void __pmic_regmap_flush(void)
+{
+	if (cache_write_pending)
+		WARN_ON(regmap_write(pmic->regmap, cache_offset,
+				     cache_write_val));
+	cache_offset = -1;
+	cache_write_pending = 0;
+}
+
+static void pmic_regmap_flush(void)
+{
+	mutex_lock(&pmic_lock);
+
+	if (pmic)
+		__pmic_regmap_flush();
+
+	mutex_unlock(&pmic_lock);
+}
+
+static int pmic_regmap_load_from_hw(struct intel_pmic_regmap *map)
+{
+	int ret;
+
+	if (cache_offset == map->offset) {
+		if (cache_flags != map->flags) {
+			dev_warn(pmic->dev, "Same reg with diff flags\n");
+			__pmic_regmap_flush();
+		}
+	}
+
+	if (cache_offset != map->offset) {
+		__pmic_regmap_flush();
+		if (IS_PMIC_REG_WO(map) || IS_PMIC_REG_W1C(map)) {
+			cache_write_val = 0;
+			ret = regmap_read(pmic->regmap, map->offset,
+					  &cache_read_val);
+		} else {
+			ret = regmap_read(pmic->regmap, map->offset,
+					  &cache_read_val);
+			cache_write_val = cache_read_val;
+		}
+		if (ret) {
+			dev_err(pmic->dev, "Register access error\n");
+			return ret;
+		}
+		cache_offset = map->offset;
+		cache_flags = map->flags;
+	}
+
+	return 0;
+}
+
+static int pmic_regmap_write(struct intel_pmic_regmap *map, int val)
+{
+	int ret = 0;
+
+	if (!IS_PMIC_REG_VALID(map))
+		return -ENXIO;
+
+	if (IS_PMIC_REG_INV(map))
+		val = ~val;
+
+	mutex_lock(&pmic_lock);
+
+	if (!pmic) {
+		ret = -ENODEV;
+		goto err;
+	}
+
+	ret = pmic_regmap_load_from_hw(map);
+	if (ret)
+		goto err;
+
+	val = ((val & map->mask) << map->shift);
+	cache_write_val &= ~(map->mask << map->shift);
+	cache_write_val |= val;
+	cache_write_pending = 1;
+
+	if (!IS_PMIC_REG_WO(map) && !IS_PMIC_REG_W1C(map))
+		cache_read_val = cache_write_val;
+
+err:
+	dev_dbg(pmic->dev, "offset=%x, shift=%x, mask=%x, flags=%x\n",
+		map->offset, map->shift, map->mask, map->flags);
+	dev_dbg(pmic->dev, "cache_read=%x, cache_write=%x, ret=%x\n",
+		cache_read_val, cache_write_val, ret);
+
+	mutex_unlock(&pmic_lock);
+
+	return ret;
+}
+
+static int pmic_regmap_read(struct intel_pmic_regmap *map)
+{
+	int ret = 0;
+
+	if (!IS_PMIC_REG_VALID(map))
+		return -ENXIO;
+
+	mutex_lock(&pmic_lock);
+
+	if (!pmic) {
+		ret = -ENODEV;
+		goto err;
+	}
+
+	ret = pmic_regmap_load_from_hw(map);
+	if (ret)
+		goto err;
+
+	if (IS_PMIC_REG_INV(map))
+		ret = ~cache_read_val;
+	else
+		ret = cache_read_val;
+
+	ret = (ret >> map->shift) & map->mask;
+	if (!IS_PMIC_REG_WO(map) && !IS_PMIC_REG_W1C(map))
+		cache_write_val = cache_read_val;
+
+err:
+	dev_dbg(pmic->dev, "offset=%x, shift=%x, mask=%x, flags=%x\n",
+		map->offset, map->shift, map->mask, map->flags);
+	dev_dbg(pmic->dev, "cache_read=%x, cache_write=%x, ret=%x\n",
+		cache_read_val, cache_write_val, ret);
+
+	mutex_unlock(&pmic_lock);
+
+	return ret;
+}
+
+static void pmic_irq_enable(struct irq_data *data)
+{
+	clear_bit(PMIC_IRQ_MASK_BIT(data->irq - pmic->irq_base),
+		  &PMIC_IRQ_MASK(pmic, data->irq - pmic->irq_base));
+	pmic->irq_need_update = 1;
+}
+
+static void pmic_irq_disable(struct irq_data *data)
+{
+	set_bit(PMIC_IRQ_MASK_BIT(data->irq - pmic->irq_base),
+		&PMIC_IRQ_MASK(pmic, data->irq - pmic->irq_base));
+	pmic->irq_need_update = 1;
+}
+
+static void pmic_irq_sync_unlock(struct irq_data *data)
+{
+	int val, irq_offset;
+	if (pmic->irq_need_update) {
+		irq_offset = data->irq - pmic->irq_base;
+		val = !!test_bit(PMIC_IRQ_MASK_BIT(irq_offset),
+				 &PMIC_IRQ_MASK(pmic, irq_offset));
+		pmic_regmap_write(&pmic->irq_regmap[irq_offset].mask, val);
+		pmic->irq_need_update = 0;
+		pmic_regmap_flush();
+	}
+	mutex_unlock(&pmic->irq_lock);
+}
+
+static void pmic_irq_lock(struct irq_data *data)
+{
+	mutex_lock(&pmic->irq_lock);
+}
+
+static irqreturn_t pmic_irq_isr(int irq, void *data)
+{
+	return IRQ_WAKE_THREAD;
+}
+
+static irqreturn_t pmic_irq_thread(int irq, void *data)
+{
+	int i;
+
+	mutex_lock(&pmic->irq_lock);
+
+	for (i = 0; i < pmic->irq_num; i++) {
+		if (test_bit(PMIC_IRQ_MASK_BIT(i), &PMIC_IRQ_MASK(pmic, i)))
+			continue;
+
+		if (pmic_regmap_read(&pmic->irq_regmap[i].status)) {
+			pmic_regmap_write(&pmic->irq_regmap[i].ack, 1);
+			handle_nested_irq(pmic->irq_base + i);
+		}
+	}
+
+	pmic_regmap_flush();
+
+	mutex_unlock(&pmic->irq_lock);
+
+	return IRQ_HANDLED;
+}
+
+static struct irq_chip pmic_irq_chip = {
+	.name			= "intel_soc_pmic",
+	.irq_bus_lock		= pmic_irq_lock,
+	.irq_bus_sync_unlock	= pmic_irq_sync_unlock,
+	.irq_disable		= pmic_irq_disable,
+	.irq_enable		= pmic_irq_enable,
+};
+
+static int pmic_irq_init(void)
+{
+	int cur_irq;
+	int ret;
+	int i;
+
+	for (i = 0; i < pmic->irq_num; i++) {
+		pmic_regmap_write(&pmic->irq_regmap[i].mask, 1);
+		set_bit(PMIC_IRQ_MASK_BIT(i), &PMIC_IRQ_MASK(pmic, i));
+	}
+
+	for (i = 0; i < pmic->irq_num; i++)
+		pmic_regmap_write(&pmic->irq_regmap[i].ack, 1);
+
+	pmic_regmap_flush();
+
+	pmic->irq_base = irq_alloc_descs(-1, 0, pmic->irq_num, 0);
+	if (pmic->irq_base < 0) {
+		dev_warn(pmic->dev, "Failed to allocate IRQs: %d\n",
+			 pmic->irq_base);
+		pmic->irq_base = 0;
+		ret = -EINVAL;
+		goto out;
+	} else {
+		dev_dbg(pmic->dev, "PMIC IRQ Base:%d\n", pmic->irq_base);
+	}
+
+	for (cur_irq = pmic->irq_base;
+	     cur_irq < pmic->irq_num + pmic->irq_base;
+	     cur_irq++) {
+		irq_set_chip_data(cur_irq, pmic);
+		irq_set_chip_and_handler(cur_irq, &pmic_irq_chip,
+					 handle_edge_irq);
+		irq_set_nested_thread(cur_irq, 1);
+		irq_set_noprobe(cur_irq);
+	}
+
+	if (gpio_is_valid(pmic->pmic_int_gpio)) {
+		ret = gpio_request_one(pmic->pmic_int_gpio,
+				       GPIOF_DIR_IN, "PMIC Interupt");
+		if (ret) {
+			dev_err(pmic->dev, "Request PMIC_INT gpio error\n");
+			goto out_free_desc;
+		}
+
+		pmic->irq = gpio_to_irq(pmic->pmic_int_gpio);
+	}
+
+	ret = request_threaded_irq(pmic->irq, pmic_irq_isr, pmic_irq_thread,
+				   pmic->irq_flags, "intel_soc_pmic", pmic);
+	if (ret != 0) {
+		dev_err(pmic->dev, "Failed to request IRQ %d: %d\n",
+			pmic->irq, ret);
+		goto out_free_gpio;
+	}
+
+	ret = enable_irq_wake(pmic->irq);
+	if (ret != 0)
+		dev_warn(pmic->dev, "Can't enable IRQ as wake source: %d\n",
+			 ret);
+
+	return 0;
+
+out_free_gpio:
+	if (gpio_is_valid(pmic->pmic_int_gpio)) {
+		gpio_free(pmic->pmic_int_gpio);
+		pmic->irq = 0;
+	}
+out_free_desc:
+	irq_free_descs(pmic->irq_base, pmic->irq_num);
+out:
+	return ret;
+}
+
+int intel_pmic_add(struct intel_soc_pmic *chip)
+{
+	int i, ret;
+	struct cell_dev_pdata *pdata;
+
+	mutex_lock(&pmic_lock);
+
+	if (pmic != NULL) {
+		mutex_unlock(&pmic_lock);
+		return -EBUSY;
+	}
+
+	pmic = chip;
+
+	mutex_unlock(&pmic_lock);
+
+	mutex_init(&chip->irq_lock);
+
+	if (chip->init) {
+		ret = chip->init();
+		if (ret != 0)
+			goto err;
+	}
+
+	ret = pmic_irq_init();
+	if (ret != 0)
+		goto err;
+
+	for (i = 0; chip->cell_dev[i].name != NULL; i++) {
+		list_for_each_entry(pdata, &pdata_list, list) {
+			if (!strcmp(pdata->name, chip->cell_dev[i].name)) {
+				chip->cell_dev[i].platform_data = pdata->data;
+				chip->cell_dev[i].pdata_size = pdata->len;
+			}
+		}
+	}
+
+	return mfd_add_devices(chip->dev, -1, chip->cell_dev, i,
+			       NULL, chip->irq_base, NULL);
+
+err:
+	mutex_lock(&pmic_lock);
+	if (pmic == chip)
+		pmic = NULL;
+	mutex_unlock(&pmic_lock);
+	return ret;
+}
+
+int intel_pmic_remove(struct intel_soc_pmic *chip)
+{
+	mutex_lock(&pmic_lock);
+
+	if (pmic != chip) {
+		mutex_unlock(&pmic_lock);
+		return -ENODEV;
+	}
+
+	pmic = NULL;
+
+	mutex_unlock(&pmic_lock);
+
+	mfd_remove_devices(chip->dev);
+
+	return 0;
+}
drivers/mfd/intel_soc_pmic_core.h new file +83 -0

83 lines not on this page · raw message

include/linux/mfd/intel_soc_pmic.h new file +29 -0
new file mode 100644
index 0000000..88c28d9
@@ -0,0 +1,29 @@
+/*
+ * intel_soc_pmic.h - Intel SoC PMIC Driver
+ *
+ * Copyright (C) 2012-2014 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Author: Yang, Bin <[email protected]>
+ */
+
+#ifndef __INTEL_SOC_PMIC_H__
+#define __INTEL_SOC_PMIC_H__
+
+int intel_soc_pmic_readb(int reg);
+int intel_soc_pmic_writeb(int reg, u8 val);
+int intel_soc_pmic_setb(int reg, u8 mask);
+int intel_soc_pmic_clearb(int reg, u8 mask);
+int intel_soc_pmic_update(int reg, u8 val, u8 mask);
+int intel_soc_pmic_set_pdata(const char *name, void *data, int len);
+struct device *intel_soc_pmic_dev(void);
+
+#endif	/* __INTEL_SOC_PMIC_H__ */
Signature · 1 line
1.8.3.2
#2 lore raw

Re: [PATCH RESEND v2 1/4] mfd: intel_soc_pmic: Core driver

drivers/mfd/intel_soc_pmic_core.c line 54

Quoted 5 lines · Lejun
drivers/mfd/intel_soc_pmic_core.c new file +5 -0
+struct device *intel_soc_pmic_dev(void)
+{
+	return pmic->dev;
+}
+EXPORT_SYMBOL(intel_soc_pmic_dev);

Why do you need to take a global reference to this?

Quoted 13 lines
drivers/mfd/intel_soc_pmic_core.c new file +13 -0
+/*
+ * Read from a PMIC register
+ */
+int intel_soc_pmic_readb(int reg)
+{
+	int ret;
+	unsigned int val;
+
+	mutex_lock(&pmic_lock);
+
+	if (!pmic) {
+		ret = -EIO;
+	} else {

drivers/mfd/intel_soc_pmic_core.c line 78

Quoted 10 lines
drivers/mfd/intel_soc_pmic_core.c new file +10 -0
+		ret = regmap_read(pmic->regmap, reg, &val);
+		if (!ret)
+			ret = val;
+	}
+
+	mutex_unlock(&pmic_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(intel_soc_pmic_readb);

This is wrapping the EXPORT_SYMBOL_GPL() regmap API with an EXPORT_SYMBOL() API. Don't do that, if you really do need these wrappers make them EXPORT_SYMBOL_GPL().

There should also be no need to add extra locking around regmap calls, the regmap API has locking as standard.

It's also not clear why this API exists at all, surely all the interaction with the device happens from the core or function drivers for the device which ought to be able to get a direct reference to the regmap anyway and only be instantiated when one is present.

Quoted 13 lines
drivers/mfd/intel_soc_pmic_core.c new file +13 -0
+/*
+ * Set platform_data of the child devices. Needs to be called before
+ * the MFD device is added.
+ */
+int intel_soc_pmic_set_pdata(const char *name, void *data, int len)
+{
+	struct cell_dev_pdata *pdata;
+
+	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+	if (!pdata) {
+		pr_err("intel_pmic: can't set pdata!\n");
+		return -ENOMEM;
+	}

drivers/mfd/intel_soc_pmic_core.c line 182

Quoted 10 lines
drivers/mfd/intel_soc_pmic_core.c new file +10 -0
+
+	pdata->name = name;
+	pdata->data = data;
+	pdata->len = len;
+
+	list_add_tail(&pdata->list, &pdata_list);
+
+	return 0;
+}
+EXPORT_SYMBOL(intel_soc_pmic_set_pdata);

What is going on here, why aren't the normal ways of getting data to the devices (such as reading the platform data of the parent device) OK?

drivers/mfd/intel_soc_pmic_core.c line 205

Quoted 9 lines
drivers/mfd/intel_soc_pmic_core.c new file +8 -0
+static void __pmic_regmap_flush(void)
+{
+	if (cache_write_pending)
+		WARN_ON(regmap_write(pmic->regmap, cache_offset,
+				     cache_write_val));
 
+static int pmic_regmap_load_from_hw(struct intel_pmic_regmap *map)
+{
+	int ret;

This all appears to be an open coded cache layer - there is already cache support in regmap, just reuse that.

drivers/mfd/intel_soc_pmic_core.c line 350

Quoted 4 lines
drivers/mfd/intel_soc_pmic_core.c new file +4 -0
+static irqreturn_t pmic_irq_isr(int irq, void *data)
+{
+	return IRQ_WAKE_THREAD;
+}

Just register the IRQ as IRQF_ONESHOT and only provide the threaded handler.

Quoted 5 lines
drivers/mfd/intel_soc_pmic_core.c new file +5 -0
+static irqreturn_t pmic_irq_thread(int irq, void *data)
+{
+	int i;
+
+	mutex_lock(&pmic->irq_lock);

drivers/mfd/intel_soc_pmic_core.c line 366

Quoted 10 lines
drivers/mfd/intel_soc_pmic_core.c new file +10 -0
+
+	for (i = 0; i < pmic->irq_num; i++) {
+		if (test_bit(PMIC_IRQ_MASK_BIT(i), &PMIC_IRQ_MASK(pmic, i)))
+			continue;
+
+		if (pmic_regmap_read(&pmic->irq_regmap[i].status)) {
+			pmic_regmap_write(&pmic->irq_regmap[i].ack, 1);
+			handle_nested_irq(pmic->irq_base + i);
+		}
+	}

This looks like you should be using regmap-irq, or at least like there's some small additions needed to make it usable.

drivers/mfd/intel_soc_pmic_core.c line 429

Quoted 10 lines
drivers/mfd/intel_soc_pmic_core.c new file +10 -0
+	if (gpio_is_valid(pmic->pmic_int_gpio)) {
+		ret = gpio_request_one(pmic->pmic_int_gpio,
+				       GPIOF_DIR_IN, "PMIC Interupt");
+		if (ret) {
+			dev_err(pmic->dev, "Request PMIC_INT gpio error\n");
+			goto out_free_desc;
+		}
+
+		pmic->irq = gpio_to_irq(pmic->pmic_int_gpio);
+	}

There should be no need to do this, simply requesting the interrupt should be sufficient to ensure the pin is in the correct mode. If this isn't the case the interrupt controller driver probably needs an update, there's some support for helping with this in the GPIO framework IIRC.

You're also not using managed (devm) allocations for anything here.

author
#3 lore raw

Re: [PATCH RESEND v2 1/4] mfd: intel_soc_pmic: Core driver

Quoted 9 lines · Mark Brown

drivers/mfd/intel_soc_pmic_core.c line 54

Quoted 5 lines · Lejun
drivers/mfd/intel_soc_pmic_core.c new file +5 -0
+struct device *intel_soc_pmic_dev(void)
+{
+	return pmic->dev;
+}
+EXPORT_SYMBOL(intel_soc_pmic_dev);

Why do you need to take a global reference to this?

It was used by the GPIO driver to get the parent device. The latest patch use dev.parent instead, so the whole function can be removed.

Quoted 19 lines
Quoted 19 lines
drivers/mfd/intel_soc_pmic_core.c new file +19 -0
+/*
+ * Read from a PMIC register
+ */
+int intel_soc_pmic_readb(int reg)
+{
+	int ret;
+	unsigned int val;
+
+	mutex_lock(&pmic_lock);
+
+	if (!pmic) {
+		ret = -EIO;
+	} else {
+		ret = regmap_read(pmic->regmap, reg, &val);
+		if (!ret)
+			ret = val;
+	}
+
+	mutex_unlock(&pmic_lock);
Quoted 8 lines

drivers/mfd/intel_soc_pmic_core.c line 78

Quoted 4 lines
drivers/mfd/intel_soc_pmic_core.c new file +4 -0
+
+	return ret;
+}
+EXPORT_SYMBOL(intel_soc_pmic_readb);

This is wrapping the EXPORT_SYMBOL_GPL() regmap API with an EXPORT_SYMBOL() API. Don't do that, if you really do need these wrappers make them EXPORT_SYMBOL_GPL().

I'll change them to use EXPORT_SYMBOL_GPL().

Quoted 2 lines

There should also be no need to add extra locking around regmap calls, the regmap API has locking as standard.

Actually it also protects the pmic variable, so it won't be set to NULL while there's ongoing read/write.

Quoted 4 lines

It's also not clear why this API exists at all, surely all the interaction with the device happens from the core or function drivers for the device which ought to be able to get a direct reference to the regmap anyway and only be instantiated when one is present.

We created these names to hide the implementation of how read/write is done from other platform specific patches interacting with this driver. So when we change the implementation, e.g. from I2C read/write to regmap, we don't have to touch all these patches.

Quoted 5 lines
Quoted 5 lines
drivers/mfd/intel_soc_pmic_core.c new file +5 -0
+/*
+ * Set platform_data of the child devices. Needs to be called before
+ * the MFD device is added.
+ */
+int intel_soc_pmic_set_pdata(const char *name, void *data, int len)

(...)

Quoted 4 lines
Quoted 1 line

+EXPORT_SYMBOL(intel_soc_pmic_set_pdata);

What is going on here, why aren't the normal ways of getting data to the devices (such as reading the platform data of the parent device) OK?

For this PMIC (Crystal Cove) it is not used. So I'll remove it.

Quoted 13 lines

drivers/mfd/intel_soc_pmic_core.c line 205

Quoted 9 lines
drivers/mfd/intel_soc_pmic_core.c new file +8 -0
+static void __pmic_regmap_flush(void)
+{
+	if (cache_write_pending)
+		WARN_ON(regmap_write(pmic->regmap, cache_offset,
+				     cache_write_val));
 
+static int pmic_regmap_load_from_hw(struct intel_pmic_regmap *map)
+{
+	int ret;

This all appears to be an open coded cache layer - there is already cache support in regmap, just reuse that.

Quoted 7 lines

drivers/mfd/intel_soc_pmic_core.c line 350

Quoted 4 lines
drivers/mfd/intel_soc_pmic_core.c new file +4 -0
+static irqreturn_t pmic_irq_isr(int irq, void *data)
+{
+	return IRQ_WAKE_THREAD;
+}

Just register the IRQ as IRQF_ONESHOT and only provide the threaded handler.

I'll fix it.

Quoted 10 lines
Quoted 10 lines
drivers/mfd/intel_soc_pmic_core.c new file +10 -0
+static irqreturn_t pmic_irq_thread(int irq, void *data)
+{
+	int i;
+
+	mutex_lock(&pmic->irq_lock);
+
+	for (i = 0; i < pmic->irq_num; i++) {
+		if (test_bit(PMIC_IRQ_MASK_BIT(i), &PMIC_IRQ_MASK(pmic, i)))
+			continue;
+
Quoted 8 lines

drivers/mfd/intel_soc_pmic_core.c line 366

Quoted 5 lines
drivers/mfd/intel_soc_pmic_core.c new file +5 -0
+		if (pmic_regmap_read(&pmic->irq_regmap[i].status)) {
+			pmic_regmap_write(&pmic->irq_regmap[i].ack, 1);
+			handle_nested_irq(pmic->irq_base + i);
+		}
+	}

This looks like you should be using regmap-irq, or at least like there's some small additions needed to make it usable.

I'll check if I can convert to regmap-irq. If it works, I won't need this and the cache layer.

Quoted 7 lines
Quoted 7 lines
drivers/mfd/intel_soc_pmic_core.c new file +7 -0
+	if (gpio_is_valid(pmic->pmic_int_gpio)) {
+		ret = gpio_request_one(pmic->pmic_int_gpio,
+				       GPIOF_DIR_IN, "PMIC Interupt");
+		if (ret) {
+			dev_err(pmic->dev, "Request PMIC_INT gpio error\n");
+			goto out_free_desc;
+		}
Quoted 8 lines

drivers/mfd/intel_soc_pmic_core.c line 429

Quoted 3 lines
drivers/mfd/intel_soc_pmic_core.c new file +3 -0
+
+		pmic->irq = gpio_to_irq(pmic->pmic_int_gpio);
+	}

There should be no need to do this, simply requesting the interrupt should be sufficient to ensure the pin is in the correct mode. If this isn't the case the interrupt controller driver probably needs an update, there's some support for helping with this in the GPIO framework IIRC.

I'll remove this.

Quoted 1 line

You're also not using managed (devm) allocations for anything here.

Best Regards
Lejun

#4 lore raw

Re: [PATCH RESEND v2 1/4] mfd: intel_soc_pmic: Core driver

Quoted 7 lines · Lejun
Quoted 2 lines · Mark Brown

There should also be no need to add extra locking around regmap calls, the regmap API has locking as standard.

Actually it also protects the pmic variable, so it won't be set to NULL while there's ongoing read/write.

Righ, but there is no clear need for the pmic variable to exist in the first place.

Quoted 9 lines
Quoted 4 lines

It's also not clear why this API exists at all, surely all the interaction with the device happens from the core or function drivers for the device which ought to be able to get a direct reference to the regmap anyway and only be instantiated when one is present.

We created these names to hide the implementation of how read/write is done from other platform specific patches interacting with this driver. So when we change the implementation, e.g. from I2C read/write to regmap, we don't have to touch all these patches.

This sort of HAL is frowned upon in the upstream kernel.

author
#5 lore raw

Re: [PATCH RESEND v2 1/4] mfd: intel_soc_pmic: Core driver

Quoted 17 lines · Mark Brown
Quoted 7 lines · Lejun
Quoted 2 lines · Mark Brown

There should also be no need to add extra locking around regmap calls, the regmap API has locking as standard.

Actually it also protects the pmic variable, so it won't be set to NULL while there's ongoing read/write.

Righ, but there is no clear need for the pmic variable to exist in the first place.

Quoted 4 lines
Quoted 4 lines

It's also not clear why this API exists at all, surely all the interaction with the device happens from the core or function drivers for the device which ought to be able to get a direct reference to the regmap anyway and only be instantiated when one is present.

Quoted 6 lines
Quoted 4 lines

We created these names to hide the implementation of how read/write is done from other platform specific patches interacting with this driver. So when we change the implementation, e.g. from I2C read/write to regmap, we don't have to touch all these patches.

This sort of HAL is frowned upon in the upstream kernel.

We want to do what other MFD drivers' been doing, and make it easier for the callers. A couple of similar examples are intel_msic_reg_read() and lp3943_read_byte(). We want to do the same with intel_soc_pmic_readb(), and I don't think it's too odd.

Best Regards
Lejun

#6 lore raw

Re: [PATCH RESEND v2 1/4] mfd: intel_soc_pmic: Core driver

Quoted 7 lines · Lejun
Quoted 4 lines · Mark Brown
Quoted 4 lines

We created these names to hide the implementation of how read/write is done from other platform specific patches interacting with this driver. So when we change the implementation, e.g. from I2C read/write to regmap, we don't have to touch all these patches.

Quoted 6 lines
Quoted 1 line

This sort of HAL is frowned upon in the upstream kernel.

We want to do what other MFD drivers' been doing, and make it easier for the callers. A couple of similar examples are intel_msic_reg_read() and lp3943_read_byte(). We want to do the same with intel_soc_pmic_readb(), and I don't think it's too odd.

The odd and problematic bit is the global variable part of things - these wrappers are usually just doing lookup of the underlying I/O handle in the struct for the device and can be implemented as static inlines in the header.

author
#7 lore raw

Re: [PATCH RESEND v2 1/4] mfd: intel_soc_pmic: Core driver

Quoted 15 lines · Mark Brown
Quoted 7 lines · Lejun
Quoted 4 lines · Mark Brown
Quoted 4 lines

We created these names to hide the implementation of how read/write is done from other platform specific patches interacting with this driver. So when we change the implementation, e.g. from I2C read/write to regmap, we don't have to touch all these patches.

Quoted 6 lines
Quoted 1 line

This sort of HAL is frowned upon in the upstream kernel.

We want to do what other MFD drivers' been doing, and make it easier for the callers. A couple of similar examples are intel_msic_reg_read() and lp3943_read_byte(). We want to do the same with intel_soc_pmic_readb(), and I don't think it's too odd.

Quoted 5 lines

The odd and problematic bit is the global variable part of things - these wrappers are usually just doing lookup of the underlying I/O handle in the struct for the device and can be implemented as static inlines in the header.

Oh I see. Sorry I missed your point. So you are saying "int intel_soc_pmic_readb(int reg)" is bad, but if I have:

int intel_soc_pmic_readb(struct intel_soc_pmic *pmic, int reg)

{
	int ret;
	unsigned int val;

	ret = regmap_read(pmic->regmap, reg, &val);
	if (!ret)
		ret = val;

	return ret;
}

And have the caller (device or core) look up and pass *pmic in, this will be OK?

Best Regards
Lejun

#8 lore raw

Re: [PATCH RESEND v2 1/4] mfd: intel_soc_pmic: Core driver

Quoted 15 lines · Lejun

Oh I see. Sorry I missed your point. So you are saying "int intel_soc_pmic_readb(int reg)" is bad, but if I have:

int intel_soc_pmic_readb(struct intel_soc_pmic *pmic, int reg)

{
	int ret;
	unsigned int val;

	ret = regmap_read(pmic->regmap, reg, &val);
	if (!ret)
		ret = val;

	return ret;
}
Quoted 2 lines

And have the caller (device or core) look up and pass *pmic in, this will be OK?

Yes, that's the more common pattern - normally the caller will need *pmic for some other purpose anyway so it saves an additional regmap lookup if that's desired.

author
#9 lore raw

PATCH RESEND v2 2/4 mfd: intel_soc_pmic: I2C interface

In reply to Zhu, Lejun

The Intel SoC PMIC devices are connected to the CPU via the I2C interface. This patch provides support of the related I2C operations.

v2:
- Use regmap instead of creating our own I2C read/write callbacks.

---
 drivers/mfd/intel_soc_pmic_i2c.c | 148 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 148 insertions(+)
 create mode 100644 drivers/mfd/intel_soc_pmic_i2c.c
drivers/mfd/intel_soc_pmic_i2c.c new file +148 -0
new file mode 100644
index 0000000..b6b8ee1
@@ -0,0 +1,148 @@
+/*
+ * intel_soc_pmic_i2c.c - Intel SoC PMIC MFD Driver
+ *
+ * Copyright (C) 2013, 2014 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Author: Yang, Bin <[email protected]>
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/mfd/core.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/workqueue.h>
+#include <linux/acpi.h>
+#include <linux/version.h>
+#include <linux/gpio/consumer.h>
+#include <linux/regmap.h>
+#include <linux/mfd/intel_soc_pmic.h>
+#include "intel_soc_pmic_core.h"
+
+static struct i2c_client *pmic_i2c_client;
+static struct intel_soc_pmic *pmic_i2c;
+
+static void pmic_shutdown(struct i2c_client *client)
+{
+	disable_irq(pmic_i2c_client->irq);
+	return;
+}
+
+static int pmic_suspend(struct device *dev)
+{
+	disable_irq(pmic_i2c_client->irq);
+	return 0;
+}
+
+static int pmic_resume(struct device *dev)
+{
+	enable_irq(pmic_i2c_client->irq);
+	return 0;
+}
+
+static const struct dev_pm_ops pmic_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(pmic_suspend, pmic_resume)
+};
+
+static int pmic_i2c_lookup_gpio(struct device *dev, int acpi_index)
+{
+	struct gpio_desc *desc;
+	int gpio;
+
+	desc = gpiod_get_index(dev, KBUILD_MODNAME, acpi_index);
+	if (IS_ERR(desc))
+		return PTR_ERR(desc);
+
+	gpio = desc_to_gpio(desc);
+
+	gpiod_put(desc);
+
+	return gpio;
+}
+
+static int pmic_i2c_probe(struct i2c_client *i2c,
+			  const struct i2c_device_id *id)
+{
+	if (pmic_i2c_client != NULL || pmic_i2c != NULL)
+		return -EBUSY;
+
+	pmic_i2c	= (struct intel_soc_pmic *)id->driver_data;
+	pmic_i2c_client	= i2c;
+	pmic_i2c->dev	= &i2c->dev;
+	pmic_i2c->irq	= i2c->irq;
+	pmic_i2c->pmic_int_gpio = pmic_i2c_lookup_gpio(pmic_i2c->dev, 0);
+	pmic_i2c->regmap = devm_regmap_init_i2c(i2c, pmic_i2c->regmap_cfg);
+
+	return intel_pmic_add(pmic_i2c);
+}
+
+static int pmic_i2c_remove(struct i2c_client *i2c)
+{
+	int ret = intel_pmic_remove(pmic_i2c);
+
+	pmic_i2c_client = NULL;
+	pmic_i2c = NULL;
+
+	return ret;
+}
+
+static const struct i2c_device_id pmic_i2c_id[] = {
+	{ "crystal_cove", (kernel_ulong_t)&crystal_cove_pmic},
+	{ "INT33FD", (kernel_ulong_t)&crystal_cove_pmic},
+	{ "INT33FD:00", (kernel_ulong_t)&crystal_cove_pmic},
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, pmic_i2c_id);
+
+static struct acpi_device_id pmic_acpi_match[] = {
+	{ "INT33FD", (kernel_ulong_t)&crystal_cove_pmic},
+	{ },
+};
+MODULE_DEVICE_TABLE(acpi, pmic_acpi_match);
+
+static struct i2c_driver pmic_i2c_driver = {
+	.driver = {
+		.name = "intel_soc_pmic_i2c",
+		.owner = THIS_MODULE,
+		.pm = &pmic_pm_ops,
+		.acpi_match_table = ACPI_PTR(pmic_acpi_match),
+	},
+	.probe = pmic_i2c_probe,
+	.remove = pmic_i2c_remove,
+	.id_table = pmic_i2c_id,
+	.shutdown = pmic_shutdown,
+};
+
+static int __init pmic_i2c_init(void)
+{
+	int ret;
+
+	ret = i2c_add_driver(&pmic_i2c_driver);
+	if (ret != 0)
+		pr_err("Failed to register pmic I2C driver: %d\n", ret);
+
+	return ret;
+}
+subsys_initcall(pmic_i2c_init);
+
+static void __exit pmic_i2c_exit(void)
+{
+	i2c_del_driver(&pmic_i2c_driver);
+}
+module_exit(pmic_i2c_exit);
+
+MODULE_DESCRIPTION("I2C driver for Intel SoC PMIC");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Yang, Bin <[email protected]>");
Signature · 1 line
1.8.3.2
#10 lore raw

Re: [PATCH RESEND v2 2/4] mfd: intel_soc_pmic: I2C interface

Quoted 5 lines · Lejun
drivers/mfd/intel_soc_pmic_i2c.c new file +5 -0
+static int pmic_i2c_lookup_gpio(struct device *dev, int acpi_index)
+{
+	struct gpio_desc *desc;
+	int gpio;
+

drivers/mfd/intel_soc_pmic_i2c.c line 73

Quoted 10 lines
drivers/mfd/intel_soc_pmic_i2c.c new file +10 -0
+	desc = gpiod_get_index(dev, KBUILD_MODNAME, acpi_index);
+	if (IS_ERR(desc))
+		return PTR_ERR(desc);
+
+	gpio = desc_to_gpio(desc);
+
+	gpiod_put(desc);
+
+	return gpio;
+}

Why not just have the driver work with the gpiod API, is there any real need to convert to a GPIO number?

drivers/mfd/intel_soc_pmic_i2c.c line 107

Quoted 7 lines
drivers/mfd/intel_soc_pmic_i2c.c new file +7 -0
+static const struct i2c_device_id pmic_i2c_id[] = {
+	{ "crystal_cove", (kernel_ulong_t)&crystal_cove_pmic},
+	{ "INT33FD", (kernel_ulong_t)&crystal_cove_pmic},
+	{ "INT33FD:00", (kernel_ulong_t)&crystal_cove_pmic},
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, pmic_i2c_id);

The INT33FD ones here look like they should only be in the ACPI table.

drivers/mfd/intel_soc_pmic_i2c.c line 138

Quoted 11 lines
drivers/mfd/intel_soc_pmic_i2c.c new file +11 -0
+static int __init pmic_i2c_init(void)
+{
+	int ret;
+
+	ret = i2c_add_driver(&pmic_i2c_driver);
+	if (ret != 0)
+		pr_err("Failed to register pmic I2C driver: %d\n", ret);
+
+	return ret;
+}
+subsys_initcall(pmic_i2c_init);

module_i2c_driver() - you shouldn't need subsys_initcall().

author
#11 lore raw

Re: [PATCH RESEND v2 2/4] mfd: intel_soc_pmic: I2C interface

Quoted 12 lines · Mark Brown
Quoted 10 lines · Lejun
drivers/mfd/intel_soc_pmic_i2c.c new file +10 -0
+static int pmic_i2c_lookup_gpio(struct device *dev, int acpi_index)
+{
+	struct gpio_desc *desc;
+	int gpio;
+
+	desc = gpiod_get_index(dev, KBUILD_MODNAME, acpi_index);
+	if (IS_ERR(desc))
+		return PTR_ERR(desc);
+
+	gpio = desc_to_gpio(desc);
Quoted 8 lines

drivers/mfd/intel_soc_pmic_i2c.c line 73

Quoted 5 lines
drivers/mfd/intel_soc_pmic_i2c.c new file +5 -0
+
+	gpiod_put(desc);
+
+	return gpio;
+}

Why not just have the driver work with the gpiod API, is there any real need to convert to a GPIO number?

The whole function will be removed since the gpio set code is removed during probe.

Quoted 9 lines

drivers/mfd/intel_soc_pmic_i2c.c line 107

Quoted 7 lines
drivers/mfd/intel_soc_pmic_i2c.c new file +7 -0
+static const struct i2c_device_id pmic_i2c_id[] = {
+	{ "crystal_cove", (kernel_ulong_t)&crystal_cove_pmic},
+	{ "INT33FD", (kernel_ulong_t)&crystal_cove_pmic},
+	{ "INT33FD:00", (kernel_ulong_t)&crystal_cove_pmic},
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, pmic_i2c_id);

The INT33FD ones here look like they should only be in the ACPI table.

You are right. Only INT33FD:00 should be here.

Quoted 5 lines
Quoted 5 lines
drivers/mfd/intel_soc_pmic_i2c.c new file +5 -0
+static int __init pmic_i2c_init(void)
+{
+	int ret;
+
+	ret = i2c_add_driver(&pmic_i2c_driver);
Quoted 8 lines

drivers/mfd/intel_soc_pmic_i2c.c line 138

Quoted 6 lines
drivers/mfd/intel_soc_pmic_i2c.c new file +6 -0
+	if (ret != 0)
+		pr_err("Failed to register pmic I2C driver: %d\n", ret);
+
+	return ret;
+}
+subsys_initcall(pmic_i2c_init);

module_i2c_driver() - you shouldn't need subsys_initcall().

I'll change it to module_init.

Best Regards
Lejun

author
#12 lore raw

PATCH RESEND v2 3/4 mfd: intel_soc_pmic: Crystal Cove support

In reply to Zhu, Lejun

Crystal Cove is the PMIC in Baytrail-T platform. This patch provides chip-specific support for Crystal Cove.

v2:
- Add regmap_config for Crystal Cove.

---
 drivers/mfd/intel_soc_pmic_crc.c | 165 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 165 insertions(+)
 create mode 100644 drivers/mfd/intel_soc_pmic_crc.c
drivers/mfd/intel_soc_pmic_crc.c new file +165 -0
new file mode 100644
index 0000000..6ab4cbf
@@ -0,0 +1,165 @@
+/*
+ * intel_soc_pmic_crc.c - Device access for Crystal Cove PMIC
+ *
+ * Copyright (C) 2013, 2014 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Author: Yang, Bin <[email protected]>
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/mfd/core.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/acpi.h>
+#include <linux/version.h>
+#include <linux/regmap.h>
+#include <linux/mfd/intel_soc_pmic.h>
+#include "intel_soc_pmic_core.h"
+
+#define CRYSTAL_COVE_IRQ_NUM		7
+#define CRYSTAL_COVE_MAX_REGISTER	0xBD
+
+#define CHIPID		0x00
+#define CHIPVER		0x01
+#define IRQLVL1		0x02
+#define MIRQLVL1	0x0E
+enum {
+	PWRSRC_IRQ = 0,
+	THRM_IRQ,
+	BCU_IRQ,
+	ADC_IRQ,
+	CHGR_IRQ,
+	GPIO_IRQ,
+	VHDMIOCP_IRQ
+};
+
+static struct resource gpio_resources[] = {
+	{
+		.name	= "GPIO",
+		.start	= GPIO_IRQ,
+		.end	= GPIO_IRQ,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct resource pwrsrc_resources[] = {
+	{
+		.name  = "PWRSRC",
+		.start = PWRSRC_IRQ,
+		.end   = PWRSRC_IRQ,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
+static struct resource adc_resources[] = {
+	{
+		.name  = "ADC",
+		.start = ADC_IRQ,
+		.end   = ADC_IRQ,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
+static struct resource thermal_resources[] = {
+	{
+		.name  = "THERMAL",
+		.start = THRM_IRQ,
+		.end   = THRM_IRQ,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+static struct resource bcu_resources[] = {
+	{
+		.name  = "BCU",
+		.start = BCU_IRQ,
+		.end   = BCU_IRQ,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+static struct mfd_cell crystal_cove_dev[] = {
+	{
+		.name = "crystal_cove_pwrsrc",
+		.id = 0,
+		.num_resources = ARRAY_SIZE(pwrsrc_resources),
+		.resources = pwrsrc_resources,
+	},
+	{
+		.name = "crystal_cove_adc",
+		.id = 0,
+		.num_resources = ARRAY_SIZE(adc_resources),
+		.resources = adc_resources,
+	},
+	{
+		.name = "crystal_cove_thermal",
+		.id = 0,
+		.num_resources = ARRAY_SIZE(thermal_resources),
+		.resources = thermal_resources,
+	},
+	{
+		.name = "crystal_cove_bcu",
+		.id = 0,
+		.num_resources = ARRAY_SIZE(bcu_resources),
+		.resources = bcu_resources,
+	},
+	{
+		.name = "crystal_cove_gpio",
+		.id = 0,
+		.num_resources = ARRAY_SIZE(gpio_resources),
+		.resources = gpio_resources,
+	},
+	{NULL, },
+};
+
+#define	CRC_IRQREGMAP_VALUE(irq)	{	\
+		{MIRQLVL1, irq, 1, 0},		\
+		{IRQLVL1,  irq, 1, 0},		\
+		INTEL_PMIC_REG_NULL,		\
+	}
+
+static struct intel_pmic_irqregmap crystal_cove_irqregmap[] = {
+	[PWRSRC_IRQ]	= CRC_IRQREGMAP_VALUE(PWRSRC_IRQ),
+	[THRM_IRQ]	= CRC_IRQREGMAP_VALUE(THRM_IRQ),
+	[BCU_IRQ]	= CRC_IRQREGMAP_VALUE(BCU_IRQ),
+	[ADC_IRQ]	= CRC_IRQREGMAP_VALUE(ADC_IRQ),
+	[CHGR_IRQ]	= CRC_IRQREGMAP_VALUE(CHGR_IRQ),
+	[GPIO_IRQ]	= CRC_IRQREGMAP_VALUE(GPIO_IRQ),
+	[VHDMIOCP_IRQ]	= CRC_IRQREGMAP_VALUE(VHDMIOCP_IRQ),
+};
+
+static struct regmap_config crystal_cove_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+
+	.max_register = CRYSTAL_COVE_MAX_REGISTER,
+	.cache_type = REGCACHE_NONE,
+};
+
+static int crystal_cove_init(void)
+{
+	pr_debug("Crystal Cove: ID 0x%02X, VERSION 0x%02X\n",
+		 intel_soc_pmic_readb(CHIPID), intel_soc_pmic_readb(CHIPVER));
+	return 0;
+}
+
+struct intel_soc_pmic crystal_cove_pmic = {
+	.label		= "crystal cove",
+	.irq_flags	= IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+	.init		= crystal_cove_init,
+	.cell_dev	= crystal_cove_dev,
+	.irq_regmap	= crystal_cove_irqregmap,
+	.irq_num	= CRYSTAL_COVE_IRQ_NUM,
+	.regmap_cfg	= &crystal_cove_regmap_config,
+};
Signature · 1 line
1.8.3.2
author
#13 lore raw

PATCH RESEND v2 4/4 mfd: intel_soc_pmic: Build files

In reply to Zhu, Lejun

Devices based on Intel SoC products such as Baytrail have a Power Management IC. This patch adds Intel SoC PMIC support to the build files.

v2:
- Add select REGMAP_I2C.

---
 drivers/mfd/Kconfig  | 11 +++++++++++
 drivers/mfd/Makefile |  3 +++
 2 files changed, 14 insertions(+)
drivers/mfd/Kconfig +11 -0
index 3383412..2c9de8e0 100644
@@ -241,6 +241,17 @@ config LPC_SCH
 	  LPC bridge function of the Intel SCH provides support for
 	  System Management Bus and General Purpose I/O.
 
+config INTEL_SOC_PMIC
+	bool "Support for Intel Atom SoC PMIC"
+	depends on I2C=y
+	select MFD_CORE
+	select REGMAP_I2C
+	help
+	  Select this option to enable support for the PMIC device
+	  on some Intel SoC systems. The PMIC provides ADC, GPIO,
+	  thermal, charger and related power management functions
+	  on these systems.
+
 config MFD_INTEL_MSIC
 	bool "Intel MSIC"
 	depends on INTEL_SCU_IPC
drivers/mfd/Makefile +3 -0
index 2851275..1a18d8b 100644
@@ -166,3 +166,6 @@ obj-$(CONFIG_MFD_RETU)		+= retu-mfd.o
 obj-$(CONFIG_MFD_AS3711)	+= as3711.o
 obj-$(CONFIG_MFD_AS3722)	+= as3722.o
 obj-$(CONFIG_MFD_STW481X)	+= stw481x.o
+
+intel-soc-pmic-objs		:= intel_soc_pmic_core.o intel_soc_pmic_crc.o intel_soc_pmic_i2c.o
+obj-$(CONFIG_INTEL_SOC_PMIC)	+= intel-soc-pmic.o
Signature · 1 line
1.8.3.2
#14 lore raw
In reply to Zhu, Lejun
Quoted 19 lines

Devices based on Intel SoC products such as Baytrail have a Power Management IC. In the PMIC there are subsystems for voltage regulation, A/D conversion, GPIO and PWMs. The PMIC in Baytrail-T platform is called Crystal Cove.

This series contains common code for these PMICs, and device specific support for Crystal Cove.

v2:
- Use regmap instead of creating our own I2C read/write callbacks.
- Add one missing EXPORT_SYMBOL.
- Remove some duplicate code and put them into pmic_regmap_load_from_hw.

Zhu, Lejun (4):
mfd: intel_soc_pmic: Core driver
mfd: intel_soc_pmic: I2C interface
mfd: intel_soc_pmic: Crystal Cove support
mfd: intel_soc_pmic: Build files

Quoted 13 lines
 drivers/mfd/Kconfig                |  11 +
 drivers/mfd/Makefile               |   3 +
 drivers/mfd/intel_soc_pmic_core.c  | 521 +++++++++++++++++++++++++++++++++++++
 drivers/mfd/intel_soc_pmic_core.h  |  83 ++++++
 drivers/mfd/intel_soc_pmic_crc.c   | 165 ++++++++++++
 drivers/mfd/intel_soc_pmic_i2c.c   | 148 +++++++++++
 include/linux/mfd/intel_soc_pmic.h |  29 +++
 7 files changed, 960 insertions(+)
 create mode 100644 drivers/mfd/intel_soc_pmic_core.c
 create mode 100644 drivers/mfd/intel_soc_pmic_core.h
 create mode 100644 drivers/mfd/intel_soc_pmic_crc.c
 create mode 100644 drivers/mfd/intel_soc_pmic_i2c.c
 create mode 100644 include/linux/mfd/intel_soc_pmic.h

Why are you re-sending this?

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author
#15 lore raw
Quoted 3 lines · Lee Jones

Why are you re-sending this?

Hi,

My mail server reported that it failed to send [PATCH v2 1/4] to LKML, so I resent the whole series, only to get it properly archived.

Sorry for the confusion.

Best Regards
Lejun