mfd: Intel SoC Power Management IC
v4 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. v3:
- Use regmap-irq and remove lots of duplicate code.
- Remove 2 unused APIs.
- Some other cleanup.
v4:
- Remove all exported APIs which are wrappers of regmap API, export the regmap in data structure instead.
- Combine intel_soc_pmic_core.c and intel_soc_pmic_i2c.c
- Clean up include files.
- Remove useless members of struct intel_soc_pmic_config.
- Fix various coding style issues.
Zhu, Lejun (3):
mfd: intel_soc_pmic: Core driver
mfd: intel_soc_pmic: Crystal Cove support
mfd: intel_soc_pmic: Build files
drivers/mfd/Kconfig | 12 +++ drivers/mfd/Makefile | 3 + drivers/mfd/intel_soc_pmic_core.c | 164 +++++++++++++++++++++++++++++++++++++ drivers/mfd/intel_soc_pmic_core.h | 32 ++++++++ drivers/mfd/intel_soc_pmic_crc.c | 160 ++++++++++++++++++++++++++++++++++++ include/linux/mfd/intel_soc_pmic.h | 30 +++++++ 6 files changed, 401 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 include/linux/mfd/intel_soc_pmic.h
Signature · 1 line
1.8.3.2
PATCH v4 1/3 mfd: intel_soc_pmic: Core driver
This patch provides the common I2C driver code for Intel SoC PMICs.
---
v2:
- Use regmap instead of creating our own I2C read/write callbacks.
- Add one missing EXPORT_SYMBOL.
- Remove duplicate code and put them into pmic_regmap_load_from_hw. v3:
- Use regmap-irq. Remove our own pmic_regmap_* and IRQ handling code.
- Remove intel_soc_pmic_dev() and intel_soc_pmic_set_pdata().
- Use EXPORT_SYMBOL_GPL for exposed APIs.
- Use gpiod interface instead of gpio numbers.
- Remove redundant I2C IDs.
- Use managed allocations.
v4:
- Remove all exported APIs which are wrappers of regmap API, export the regmap in data structure instead.
- Combine I2C and core .c files.
- Clean up include files.
- Use intel_soc_pmic_ prefix to replace pmic_ and intel_pmic_.
- Fix various coding style issues.
--- drivers/mfd/intel_soc_pmic_core.c | 164 +++++++++++++++++++++++++++++++++++++ drivers/mfd/intel_soc_pmic_core.h | 32 ++++++++ include/linux/mfd/intel_soc_pmic.h | 30 +++++++ 3 files changed, 226 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 +164 -0
@@ -0,0 +1,164 @@ +/* +* intel_soc_pmic_core.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]> +* Author: Zhu, Lejun <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/mfd/core.h> +#include <linux/i2c.h> +#include <linux/interrupt.h> +#include <linux/gpio/consumer.h> +#include <linux/acpi.h> +#include <linux/regmap.h> +#include <linux/mfd/intel_soc_pmic.h> +#include "intel_soc_pmic_core.h" + +static int intel_soc_pmic_find_gpio_irq (struct device *dev) +{ +struct gpio_desc *desc; +int irq; + + desc =devm_gpiod_get_index (dev,KBUILD_MODNAME ,0 ); +if (IS_ERR (desc)) { +dev_dbg (dev,"Not using GPIO as interrupt.\n" ); +return -ENOENT ; + } + + irq =gpiod_to_irq (desc); +if (irq <0 ) +dev_warn (dev,"Can't get irq: %d\n" , irq); + +return irq; +} + +static int intel_soc_pmic_i2c_probe (struct i2c_client *i2c, +const struct i2c_device_id *id) +{ +struct device *dev = &i2c->dev; +struct intel_soc_pmic_config *config = + (struct intel_soc_pmic_config *)id->driver_data; +struct intel_soc_pmic *pmic; +int ret; +int irq; + + pmic =devm_kzalloc (dev,sizeof (*pmic),GFP_KERNEL ); +dev_set_drvdata (dev, pmic); + + pmic->regmap =devm_regmap_init_i2c (i2c, config->regmap_config); + + irq =intel_soc_pmic_find_gpio_irq (dev); +if (irq <0 ) + pmic->irq = i2c->irq; +else + pmic->irq = irq; + + ret =regmap_add_irq_chip (pmic->regmap, pmic->irq, + config->irq_flags |IRQF_ONESHOT , +0 , config->irq_chip, + &pmic->irq_chip_data); +if (ret) + goto err; + + ret =enable_irq_wake (pmic->irq); +if (ret) +dev_warn (dev,"Can't enable IRQ as wake source: %d\n" , ret); + + ret =mfd_add_devices (dev,-1 , config->cell_dev, + config->n_cell_devs,NULL ,0 , +regmap_irq_get_domain (pmic->irq_chip_data)); +if (ret) + goto err_del_irq_chip; + +return 0 ; + +err_del_irq_chip: +regmap_del_irq_chip (pmic->irq, pmic->irq_chip_data); +err: +return ret; +} + +static int intel_soc_pmic_i2c_remove (struct i2c_client *i2c) +{ +struct intel_soc_pmic *pmic =dev_get_drvdata (&i2c->dev); + +regmap_del_irq_chip (pmic->irq, pmic->irq_chip_data); + +mfd_remove_devices (&i2c->dev); + +return 0 ; +} + +static void intel_soc_pmic_shutdown (struct i2c_client *i2c) +{ +struct intel_soc_pmic *pmic =dev_get_drvdata (&i2c->dev); + +disable_irq (pmic->irq); + +return ; +} + +static int intel_soc_pmic_suspend (struct device *dev) +{ +struct intel_soc_pmic *pmic =dev_get_drvdata (dev); + +disable_irq (pmic->irq); + +return 0 ; +} + +static int intel_soc_pmic_resume (struct device *dev) +{ +struct intel_soc_pmic *pmic =dev_get_drvdata (dev); + +enable_irq (pmic->irq); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(intel_soc_pmic_pm_ops, intel_soc_pmic_suspend, + intel_soc_pmic_resume); + +static const struct i2c_device_id intel_soc_pmic_i2c_id[] = { + {"INT33FD:00" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { } +}; +MODULE_DEVICE_TABLE (i2c, intel_soc_pmic_i2c_id); + +static struct acpi_device_id intel_soc_pmic_acpi_match[] = { + {"INT33FD" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { }, +}; +MODULE_DEVICE_TABLE (acpi, intel_soc_pmic_acpi_match); + +static struct i2c_driver intel_soc_pmic_i2c_driver = { + .driver = { + .name ="intel_soc_pmic_i2c" , + .owner =THIS_MODULE , + .pm = &intel_soc_pmic_pm_ops, + .acpi_match_table =ACPI_PTR (intel_soc_pmic_acpi_match), + }, + .probe = intel_soc_pmic_i2c_probe, + .remove = intel_soc_pmic_i2c_remove, + .id_table = intel_soc_pmic_i2c_id, + .shutdown = intel_soc_pmic_shutdown, +}; + +module_i2c_driver (intel_soc_pmic_i2c_driver); + +MODULE_DESCRIPTION ("I2C driver for Intel SoC PMIC" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Yang, Bin <[email protected]>" ); +MODULE_AUTHOR ("Zhu, Lejun <[email protected]>" );
drivers/mfd/intel_soc_pmic_core.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* intel_soc_pmic_core.h - Intel SoC PMIC MFD 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]> +* Author: Zhu, Lejun <[email protected]> +*/ + +#ifndef __INTEL_SOC_PMIC_CORE_H__ +#define __INTEL_SOC_PMIC_CORE_H__ + +struct intel_soc_pmic_config { +unsigned long irq_flags; +struct mfd_cell *cell_dev; +int n_cell_devs; +struct regmap_config *regmap_config; +struct regmap_irq_chip *irq_chip; +}; + +extern struct intel_soc_pmic_config intel_soc_pmic_config_crc; + +#endif /* __INTEL_SOC_PMIC_CORE_H__ */
include/linux/mfd/intel_soc_pmic.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* 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]> +* Author: Zhu, Lejun <[email protected]> +*/ + +#ifndef __INTEL_SOC_PMIC_H__ +#define __INTEL_SOC_PMIC_H__ + +#include <linux/regmap.h> + +struct intel_soc_pmic { +int irq; +struct regmap *regmap; +struct regmap_irq_chip_data *irq_chip_data; +}; + +#endif /* __INTEL_SOC_PMIC_H__ */
Signature · 1 line
1.8.3.2
Re: [PATCH v4 1/3] mfd: intel_soc_pmic: Core driver
Quoted 38 lines
This patch provides the common I2C driver code for Intel SoC PMICs.
Signed-off-by Yang, Bin <[email protected]>Signed-off-by Zhu, Lejun <[email protected]>---
v2:
- Use regmap instead of creating our own I2C read/write callbacks.
- Add one missingEXPORT_SYMBOL.
- Remove duplicate code and put them intopmic_regmap_load_from_hw. v3:
- Use regmap-irq. Remove our own pmic_regmap_* and IRQ handling code.
- Removeintel_soc_pmic_dev()andintel_soc_pmic_set_pdata().
- UseEXPORT_SYMBOL_GPLfor exposed APIs.
- Use gpiod interface instead of gpio numbers.
- Remove redundant I2C IDs.
- Use managed allocations.
v4:
- Remove all exported APIs which are wrappers of regmap API, export the regmap in data structure instead.
- Combine I2C and core .c files.
- Clean up include files.
- Useintel_soc_pmic_prefix to replacepmic_andintel_pmic_.
- Fix various coding style issues.--- drivers/mfd/intel_soc_pmic_core.c | 164 +++++++++++++++++++++++++++++++++++++ drivers/mfd/intel_soc_pmic_core.h | 32 ++++++++ include/linux/mfd/intel_soc_pmic.h | 30 +++++++ 3 files changed, 226 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.hdrivers/mfd/intel_soc_pmic_core.c new file +0
-0@@ -0,0 +1,164 @@
[...]
drivers/mfd/intel_soc_pmic_core.c line 34
Quoted 6 lines
drivers/mfd/intel_soc_pmic_core.c new file +6
-0+static int intel_soc_pmic_find_gpio_irq (struct device *dev) +{ +struct gpio_desc *desc; +int irq; + + desc =devm_gpiod_get_index (dev,KBUILD_MODNAME ,0 );
What does "KBUILD_MODNAME" translate to?
drivers/mfd/intel_soc_pmic_core.c line 36
Quoted 2 lines
drivers/mfd/intel_soc_pmic_core.c new file +2
-0+if (IS_ERR (desc)) { +dev_dbg (dev,"Not using GPIO as interrupt.\n" );
You can't have a debug print, then return an err - use dev_err().
[...]
Quoted 10 lines
drivers/mfd/intel_soc_pmic_core.c new file +10
-0+static int intel_soc_pmic_i2c_probe (struct i2c_client *i2c, +const struct i2c_device_id *id) +{ +struct device *dev = &i2c->dev; +struct intel_soc_pmic_config *config = + (struct intel_soc_pmic_config *)id->driver_data; +struct intel_soc_pmic *pmic; +int ret; +int irq; +
drivers/mfd/intel_soc_pmic_core.c line 66
Quoted 10 lines
drivers/mfd/intel_soc_pmic_core.c new file +10
-0+ pmic =devm_kzalloc (dev,sizeof (*pmic),GFP_KERNEL ); +dev_set_drvdata (dev, pmic); + + pmic->regmap =devm_regmap_init_i2c (i2c, config->regmap_config); + + irq =intel_soc_pmic_find_gpio_irq (dev); +if (irq <0 ) + pmic->irq = i2c->irq; +else + pmic->irq = irq;
pmic->irq = (irq < 0) ? i2c->irq : irq;
drivers/mfd/intel_soc_pmic_core.c line 73
Quoted 6 lines
drivers/mfd/intel_soc_pmic_core.c new file +6
-0+ ret =regmap_add_irq_chip (pmic->regmap, pmic->irq, + config->irq_flags |IRQF_ONESHOT , +0 , config->irq_chip, + &pmic->irq_chip_data); +if (ret) + goto err;
Just return ret here and remove the 'err:' label.
[...]
drivers/mfd/intel_soc_pmic_core.c line 144
Quoted 11 lines
drivers/mfd/intel_soc_pmic_core.c new file +11
-0+static const struct i2c_device_id intel_soc_pmic_i2c_id[] = { + {"INT33FD:00" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { } +}; +MODULE_DEVICE_TABLE (i2c, intel_soc_pmic_i2c_id); + +static struct acpi_device_id intel_soc_pmic_acpi_match[] = { + {"INT33FD" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { }, +}; +MODULE_DEVICE_TABLE (acpi, intel_soc_pmic_acpi_match);
Does ACPI have a match function to extact it's .driver_data attribute?
If so, are you using it here? If not, why not?
[...]
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v4 1/3] mfd: intel_soc_pmic: Core driver
Quoted 10 lines · Lee Jones
[...]
drivers/mfd/intel_soc_pmic_core.c line 34
Quoted 6 lines
drivers/mfd/intel_soc_pmic_core.c new file +6
-0+static int intel_soc_pmic_find_gpio_irq (struct device *dev) +{ +struct gpio_desc *desc; +int irq; + + desc =devm_gpiod_get_index (dev,KBUILD_MODNAME ,0 );What does "
KBUILD_MODNAME" translate to?
It translates into "intel_soc_pmic".
Quoted 5 lines
drivers/mfd/intel_soc_pmic_core.c line 36
Quoted 3 lines
drivers/mfd/intel_soc_pmic_core.c new file +2
-0+if (IS_ERR (desc)) { +dev_dbg (dev,"Not using GPIO as interrupt.\n" );You can't have a debug print, then return an err - use
dev_err().
Actually returning ENOENT here is just a hardware difference. On some boards the PMIC interrupt is from a GPIO line exposed by the CPU, on the rest (e.g. Asus T100TA) it's not. When -ENOENT is returned, probe() will simply use the IRQ provided by the I2C.
I will remove this line completely, and put a comment before the function.
Quoted 17 lines
[...]
Quoted 14 lines
drivers/mfd/intel_soc_pmic_core.c new file +14
-0+static int intel_soc_pmic_i2c_probe (struct i2c_client *i2c, +const struct i2c_device_id *id) +{ +struct device *dev = &i2c->dev; +struct intel_soc_pmic_config *config = + (struct intel_soc_pmic_config *)id->driver_data; +struct intel_soc_pmic *pmic; +int ret; +int irq; + + pmic =devm_kzalloc (dev,sizeof (*pmic),GFP_KERNEL ); +dev_set_drvdata (dev, pmic); + + pmic->regmap =devm_regmap_init_i2c (i2c, config->regmap_config);
Quoted 8 lines
drivers/mfd/intel_soc_pmic_core.c line 66
Quoted 6 lines
drivers/mfd/intel_soc_pmic_core.c new file +6
-0+ + irq =intel_soc_pmic_find_gpio_irq (dev); +if (irq <0 ) + pmic->irq = i2c->irq; +else + pmic->irq = irq;
pmic->irq= (irq < 0) ?i2c->irq: irq;
I'll fix it.
Quoted 8 lines
drivers/mfd/intel_soc_pmic_core.c line 73
Quoted 6 lines
drivers/mfd/intel_soc_pmic_core.c new file +6
-0+ ret =regmap_add_irq_chip (pmic->regmap, pmic->irq, + config->irq_flags |IRQF_ONESHOT , +0 , config->irq_chip, + &pmic->irq_chip_data); +if (ret) + goto err;Just return ret here and remove the 'err:' label.
I'll fix it.
Quoted 17 lines
[...]
drivers/mfd/intel_soc_pmic_core.c line 144
Quoted 11 lines
drivers/mfd/intel_soc_pmic_core.c new file +11
-0+static const struct i2c_device_id intel_soc_pmic_i2c_id[] = { + {"INT33FD:00" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { } +}; +MODULE_DEVICE_TABLE (i2c, intel_soc_pmic_i2c_id); + +static struct acpi_device_id intel_soc_pmic_acpi_match[] = { + {"INT33FD" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { }, +}; +MODULE_DEVICE_TABLE (acpi, intel_soc_pmic_acpi_match);Does ACPI have a match function to extact it's .driver_data attribute?
Quoted 2 lines
If so, are you using it here? If not, why not?
The ACPI table is used in i2c_device_match(), and the i2c table is used in i2c_device_probe(), so the id in the i2c table is actually fed to intel_soc_pmic_probe(). But I only found out now that having the i2c table alone is enough, because i2c_device_match will fallback to the i2c table if there's no ACPI table. So to keep it simple, I'll remove the ACPI table completely.
By the way, the GPIO child driver got reviewed-by from Linus Walleij, but can't be merged because it depends on intel_soc_pmic.h. May I include it in next version of the patch set and have it merged along with the MFD driver?
Best Regards
Lejun
Re: [PATCH v4 1/3] mfd: intel_soc_pmic: Core driver
Quoted 10 lines
Quoted 8 lines
drivers/mfd/intel_soc_pmic_core.c line 34
Quoted 6 lines
drivers/mfd/intel_soc_pmic_core.c new file +6
-0+static int intel_soc_pmic_find_gpio_irq (struct device *dev) +{ +struct gpio_desc *desc; +int irq; + + desc =devm_gpiod_get_index (dev,KBUILD_MODNAME ,0 );What does "
KBUILD_MODNAME" translate to?It translates into "
intel_soc_pmic".
Can you just put that instead?
Quoted 11 lines
Quoted 4 lines
drivers/mfd/intel_soc_pmic_core.c line 36
Quoted 2 lines
drivers/mfd/intel_soc_pmic_core.c new file +2
-0+if (IS_ERR (desc)) { +dev_dbg (dev,"Not using GPIO as interrupt.\n" );You can't have a debug print, then return an err - use
dev_err().Actually returning ENOENT here is just a hardware difference. On some boards the PMIC interrupt is from a GPIO line exposed by the CPU, on the rest (e.g. Asus T100TA) it's not. When
-ENOENTis returned,probe()will simply use the IRQ provided by the I2C.I will remove this line completely, and put a comment before the function.
That'll do, thanks.
Quoted 17 lines
Quoted 14 lines
drivers/mfd/intel_soc_pmic_core.c line 144
Quoted 11 lines
drivers/mfd/intel_soc_pmic_core.c new file +11
-0+static const struct i2c_device_id intel_soc_pmic_i2c_id[] = { + {"INT33FD:00" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { } +}; +MODULE_DEVICE_TABLE (i2c, intel_soc_pmic_i2c_id); + +static struct acpi_device_id intel_soc_pmic_acpi_match[] = { + {"INT33FD" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { }, +}; +MODULE_DEVICE_TABLE (acpi, intel_soc_pmic_acpi_match);Does ACPI have a match function to extact it's .driver_data attribute?
Quoted 2 lines
If so, are you using it here? If not, why not?
Quoted 6 lines
The ACPI table is used in
i2c_device_match(), and the i2c table is used ini2c_device_probe(), so the id in the i2c table is actually fed tointel_soc_pmic_probe(). But I only found out now that having the i2c table alone is enough, becausei2c_device_matchwill fallback to the i2c table if there's no ACPI table. So to keep it simple, I'll remove the ACPI table completely.
Actually, can you do it the other way round? Minimise the i2c table and populate the ACPI one. I'm just about to work on a separate patch-set which deprecates the use of the i2c table on DT and/or ACPI only registered devices.
Quoted 4 lines
By the way, the GPIO child driver got reviewed-by from Linus Walleij, but can't be merged because it depends on
intel_soc_pmic.h. May I include it in next version of the patch set and have it merged along with the MFD driver?
Yes, if it's okay with Linus and you aapply his Ack.
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v4 1/3] mfd: intel_soc_pmic: Core driver
Quoted 9 lines · Lee Jones
Quoted 9 lines
Quoted 8 lines
drivers/mfd/intel_soc_pmic_core.c line 34
Quoted 6 lines
drivers/mfd/intel_soc_pmic_core.c new file +6
-0+static int intel_soc_pmic_find_gpio_irq (struct device *dev) +{ +struct gpio_desc *desc; +int irq; + + desc =devm_gpiod_get_index (dev,KBUILD_MODNAME ,0 );What does "
KBUILD_MODNAME" translate to?
Quoted 3 lines
Quoted 1 line
It translates into "
intel_soc_pmic".Can you just put that instead?
Sure. I'll fix it.
(...)
Quoted 24 lines
Quoted 17 lines
Quoted 14 lines
drivers/mfd/intel_soc_pmic_core.c line 144
Quoted 11 lines
drivers/mfd/intel_soc_pmic_core.c new file +11
-0+static const struct i2c_device_id intel_soc_pmic_i2c_id[] = { + {"INT33FD:00" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { } +}; +MODULE_DEVICE_TABLE (i2c, intel_soc_pmic_i2c_id); + +static struct acpi_device_id intel_soc_pmic_acpi_match[] = { + {"INT33FD" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { }, +}; +MODULE_DEVICE_TABLE (acpi, intel_soc_pmic_acpi_match);Does ACPI have a match function to extact it's .driver_data attribute?
Quoted 2 lines
If so, are you using it here? If not, why not?
Quoted 6 lines
The ACPI table is used in
i2c_device_match(), and the i2c table is used ini2c_device_probe(), so the id in the i2c table is actually fed tointel_soc_pmic_probe(). But I only found out now that having the i2c table alone is enough, becausei2c_device_matchwill fallback to the i2c table if there's no ACPI table. So to keep it simple, I'll remove the ACPI table completely.
Quoted 4 lines
Actually, can you do it the other way round? Minimise the i2c table and populate the ACPI one. I'm just about to work on a separate patch-set which deprecates the use of the i2c table on DT and/or ACPI only registered devices.
Current i2c_device_probe will only feed driver_data from i2c_device_id table to intel_soc_pmic_probe(), because it uses i2c_match_id(). So if I remove "&intel_soc_pmic_config_crc" from the i2c table, I will get NULL from id->driver_data until your new patch fixes it.
So for the driver to work for the i2c code both today and in the future, I think it's best to keep the driver_data populated in both tables. What do you think?
Best Regards
Lejun
Re: [PATCH v4 1/3] mfd: intel_soc_pmic: Core driver
Quoted 29 lines
Quoted 24 lines
Quoted 17 lines
Quoted 14 lines
drivers/mfd/intel_soc_pmic_core.c line 144
Quoted 11 lines
drivers/mfd/intel_soc_pmic_core.c new file +11
-0+static const struct i2c_device_id intel_soc_pmic_i2c_id[] = { + {"INT33FD:00" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { } +}; +MODULE_DEVICE_TABLE (i2c, intel_soc_pmic_i2c_id); + +static struct acpi_device_id intel_soc_pmic_acpi_match[] = { + {"INT33FD" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { }, +}; +MODULE_DEVICE_TABLE (acpi, intel_soc_pmic_acpi_match);Does ACPI have a match function to extact it's .driver_data attribute?
Quoted 2 lines
If so, are you using it here? If not, why not?
Quoted 6 lines
The ACPI table is used in
i2c_device_match(), and the i2c table is used ini2c_device_probe(), so the id in the i2c table is actually fed tointel_soc_pmic_probe(). But I only found out now that having the i2c table alone is enough, becausei2c_device_matchwill fallback to the i2c table if there's no ACPI table. So to keep it simple, I'll remove the ACPI table completely.Quoted 4 lines
Actually, can you do it the other way round? Minimise the i2c table and populate the ACPI one. I'm just about to work on a separate patch-set which deprecates the use of the i2c table on DT and/or ACPI only registered devices.
Quoted 4 lines
Current
i2c_device_probewill only feeddriver_datafromi2c_device_idtable tointel_soc_pmic_probe(), because it usesi2c_match_id(). So if I remove "&intel_soc_pmic_config_crc" from the i2c table, I will get NULL fromid->driver_datauntil your new patch fixes it.
Right, which is why I asked if ACPI has a match function - I just looked and it does. So what you need to do is supply a very simple i2c_device_id struct (just until my patch lands, then there'll be no reason to supply one at all) and use acpi_match_device() instead of using id->driver_data.
Quoted 3 lines
So for the driver to work for the i2c code both today and in the future, I think it's best to keep the
driver_datapopulated in both tables. What do you think?
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v4 1/3] mfd: intel_soc_pmic: Core driver
Quoted 34 lines · Lee Jones
Quoted 29 lines
Quoted 24 lines
Quoted 17 lines
Quoted 14 lines
drivers/mfd/intel_soc_pmic_core.c line 144
Quoted 11 lines
drivers/mfd/intel_soc_pmic_core.c new file +11
-0+static const struct i2c_device_id intel_soc_pmic_i2c_id[] = { + {"INT33FD:00" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { } +}; +MODULE_DEVICE_TABLE (i2c, intel_soc_pmic_i2c_id); + +static struct acpi_device_id intel_soc_pmic_acpi_match[] = { + {"INT33FD" , (kernel_ulong_t)&intel_soc_pmic_config_crc}, + { }, +}; +MODULE_DEVICE_TABLE (acpi, intel_soc_pmic_acpi_match);Does ACPI have a match function to extact it's .driver_data attribute?
Quoted 2 lines
If so, are you using it here? If not, why not?
Quoted 6 lines
The ACPI table is used in
i2c_device_match(), and the i2c table is used ini2c_device_probe(), so the id in the i2c table is actually fed tointel_soc_pmic_probe(). But I only found out now that having the i2c table alone is enough, becausei2c_device_matchwill fallback to the i2c table if there's no ACPI table. So to keep it simple, I'll remove the ACPI table completely.Quoted 4 lines
Actually, can you do it the other way round? Minimise the i2c table and populate the ACPI one. I'm just about to work on a separate patch-set which deprecates the use of the i2c table on DT and/or ACPI only registered devices.
Quoted 4 lines
Current
i2c_device_probewill only feeddriver_datafromi2c_device_idtable tointel_soc_pmic_probe(), because it usesi2c_match_id(). So if I remove "&intel_soc_pmic_config_crc" from the i2c table, I will get NULL fromid->driver_datauntil your new patch fixes it.
Quoted 6 lines
Right, which is why I asked if ACPI has a match function - I just looked and it does. So what you need to do is supply a very simple
i2c_device_idstruct (just until my patch lands, then there'll be no reason to supply one at all) and useacpi_match_device()instead of usingid->driver_data.
Oh I see. You mean calling acpi_match_device() in my own probe(). I'll change my code to do that in next version.
Best Regards
Lejun
PATCH v4 2/3 mfd: intel_soc_pmic: Crystal Cove support
In reply to Zhu, LejunThis patch provides chip-specific support for Crystal Cove. Crystal Cove is the PMIC in Baytrail-T platform.
---
v2:
- Add regmap_config for Crystal Cove.
v3:
- Convert IRQ config to regmap_irq_chip.
v4:
- Cleanup include files.
- Remove useless init() function.
- Remove useless .label and .init from struct intel_soc_pmic_config.
- Fix various coding style issues.
--- drivers/mfd/intel_soc_pmic_crc.c | 160 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 drivers/mfd/intel_soc_pmic_crc.c
drivers/mfd/intel_soc_pmic_crc.c new file +160 -0
@@ -0,0 +1,160 @@ +/* +* 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]> +* Author: Zhu, Lejun <[email protected]> +*/ + +#include <linux/mfd/core.h> +#include <linux/interrupt.h> +#include <linux/regmap.h> +#include <linux/mfd/intel_soc_pmic.h> +#include "intel_soc_pmic_core.h" + +#define CRYSTAL_COVE_MAX_REGISTER 0xC6 + +#define REG_IRQLVL1 0x02 +#define REG_MIRQLVL1 0x0E + +enum crystal_cove_irq { +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" , + .num_resources =ARRAY_SIZE (pwrsrc_resources), + .resources = pwrsrc_resources, + }, + { + .name ="crystal_cove_adc" , + .num_resources =ARRAY_SIZE (adc_resources), + .resources = adc_resources, + }, + { + .name ="crystal_cove_thermal" , + .num_resources =ARRAY_SIZE (thermal_resources), + .resources = thermal_resources, + }, + { + .name ="crystal_cove_bcu" , + .num_resources =ARRAY_SIZE (bcu_resources), + .resources = bcu_resources, + }, + { + .name ="crystal_cove_gpio" , + .num_resources =ARRAY_SIZE (gpio_resources), + .resources = gpio_resources, + }, +}; + +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 const struct regmap_irq crystal_cove_irqs[] = { + [PWRSRC_IRQ ] = { + .mask =BIT (PWRSRC_IRQ ), + }, + [THRM_IRQ ] = { + .mask =BIT (THRM_IRQ ), + }, + [BCU_IRQ ] = { + .mask =BIT (BCU_IRQ ), + }, + [ADC_IRQ ] = { + .mask =BIT (ADC_IRQ ), + }, + [CHGR_IRQ ] = { + .mask =BIT (CHGR_IRQ ), + }, + [GPIO_IRQ ] = { + .mask =BIT (GPIO_IRQ ), + }, + [VHDMIOCP_IRQ ] = { + .mask =BIT (VHDMIOCP_IRQ ), + }, +}; + +static struct regmap_irq_chip crystal_cove_irq_chip = { + .name ="Crystal Cove" , + .irqs = crystal_cove_irqs, + .num_irqs =ARRAY_SIZE (crystal_cove_irqs), + .num_regs =1 , + .status_base =REG_IRQLVL1 , + .mask_base =REG_MIRQLVL1 , +}; + +struct intel_soc_pmic_config intel_soc_pmic_config_crc = { + .irq_flags =IRQF_TRIGGER_RISING , + .cell_dev = crystal_cove_dev, + .n_cell_devs =ARRAY_SIZE (crystal_cove_dev), + .regmap_config = &crystal_cove_regmap_config, + .irq_chip = &crystal_cove_irq_chip, +};
Signature · 1 line
1.8.3.2
Re: [PATCH v4 2/3] mfd: intel_soc_pmic: Crystal Cove support
Quoted 54 lines · Lejun
This patch provides chip-specific support for Crystal Cove. Crystal Cove is the PMIC in Baytrail-T platform.
Signed-off-by Yang, Bin <[email protected]>Signed-off-by Zhu, Lejun <[email protected]>---
v2:
- Addregmap_configfor Crystal Cove.
v3:
- Convert IRQ config toregmap_irq_chip.
v4:
- Cleanup include files.
- Remove uselessinit()function.
- Remove useless .label and .init from structintel_soc_pmic_config.
- Fix various coding style issues.--- drivers/mfd/intel_soc_pmic_crc.c | 160 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 drivers/mfd/intel_soc_pmic_crc.cdrivers/mfd/intel_soc_pmic_crc.c new file +28
-0@@ -0,0 +1,160 @@ +/* +* 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]> +* Author: Zhu, Lejun <[email protected]> +*/ + +#include <linux/mfd/core.h> +#include <linux/interrupt.h> +#include <linux/regmap.h> +#include <linux/mfd/intel_soc_pmic.h> +#include "intel_soc_pmic_core.h" + +#define CRYSTAL_COVE_MAX_REGISTER 0xC6 + +#define REG_IRQLVL1 0x02 +#define REG_MIRQLVL1 0x0E
drivers/mfd/intel_soc_pmic_crc.c line 38
Quoted 10 lines
drivers/mfd/intel_soc_pmic_crc.c new file +10
-0+ +enum crystal_cove_irq { +PWRSRC_IRQ =0 , +THRM_IRQ , +BCU_IRQ , +ADC_IRQ , +CHGR_IRQ , +GPIO_IRQ , +VHDMIOCP_IRQ +};
I can't help thinking that these should be nice clear #defines
#define CRYSTAL_COVE_IRQ_PWSRC 0
...
#define CRYSTAL_COVE_IRQ_VHDMIOCP 6
[...]
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v4 2/3] mfd: intel_soc_pmic: Crystal Cove support
Quoted 4 lines · Lee Jones
Quoted 2 lines · Lejun
This patch provides chip-specific support for Crystal Cove. Crystal Cove is the PMIC in Baytrail-T platform.
(...)
Quoted 12 lines
drivers/mfd/intel_soc_pmic_crc.c line 38
Quoted 9 lines
drivers/mfd/intel_soc_pmic_crc.c new file +9
-0+enum crystal_cove_irq { +PWRSRC_IRQ =0 , +THRM_IRQ , +BCU_IRQ , +ADC_IRQ , +CHGR_IRQ , +GPIO_IRQ , +VHDMIOCP_IRQ +};I can't help thinking that these should be nice clear #defines
Quoted 4 lines
#define
CRYSTAL_COVE_IRQ_PWSRC0
...
#defineCRYSTAL_COVE_IRQ_VHDMIOCP6
Sure. I'll fix it.
Best Regards
Lejun
PATCH v4 3/3 mfd: intel_soc_pmic: Build files
In reply to Zhu, LejunThis patch adds Intel SoC PMIC support to the build files.
---
v2:
- Add select REGMAP_I2C.
v3:
- Add select REGMAP_IRQ.
v4:
- No change.
--- drivers/mfd/Kconfig | 12 ++++++++++++ drivers/mfd/Makefile | 3 +++ 2 files changed, 15 insertions(+)
drivers/mfd/Kconfig +12 -0
@@ -241,6 +241,18 @@ 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 + select REGMAP_IRQ + 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
@@ -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 +obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o
Signature · 1 line
1.8.3.2
Re: [PATCH v4 3/3] mfd: intel_soc_pmic: Build files
Quoted 11 lines
This patch adds Intel SoC PMIC support to the build files.
Signed-off-by Yang, Bin <[email protected]>Signed-off-by Zhu, Lejun <[email protected]>---
v2:
- Add selectREGMAP_I2C.
v3:
- Add selectREGMAP_IRQ.
v4:
- No change.
Quoted 4 lines
--- drivers/mfd/Kconfig | 12 ++++++++++++ drivers/mfd/Makefile | 3 +++ 2 files changed, 15 insertions(+)
These changes shouldn't really be in a separate patch.
Quoted 34 lines
drivers/mfd/Kconfig +12
-0@@ -241,6 +241,18 @@ 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 + select REGMAP_IRQ + 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_IPCdrivers/mfd/Makefile +3
-0@@ -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 +obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v4 3/3] mfd: intel_soc_pmic: Build files
Quoted 2 lines · Lee Jones
Quoted 1 line
This patch adds Intel SoC PMIC support to the build files.
These changes shouldn't really be in a separate patch.
I'll move them into the first (core.c) patch.
Best Regards
Lejun