mfd: Add Cherrytrail WhiskeyCove PMIC driver
PATCH 1/1 mfd: Add Cherrytrail WhiskeyCove PMIC driver
Add mfd driver for Intel CHT WhiskeyCove PMIC, based on various non upstreamed CHT WhiskeyCove PMIC patches. For now this just adds a minimal version which implements just enough to get ACPI PMIC opregion support to work, so that suspend/resume will work on machines with this PMIC.
--- drivers/mfd/Makefile | 2 +- drivers/mfd/intel_soc_pmic_chtwc.c | 175 +++++++++++++++++++++++++++++++++++++ include/linux/mfd/intel_chtwc.h | 75 ++++++++++++++++ 3 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 drivers/mfd/intel_soc_pmic_chtwc.c create mode 100644 include/linux/mfd/intel_chtwc.h
drivers/mfd/Makefile +1 -1
@@ -205,7 +205,7 @@ obj-$(CONFIG_MFD_DLN2) += dln2.o obj-$(CONFIG_MFD_RT5033) += rt5033.o obj-$(CONFIG_MFD_SKY81452) += sky81452.o -intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o +intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o intel_soc_pmic_chtwc.o intel-soc-pmic-$(CONFIG_INTEL_PMC_IPC) += intel_soc_pmic_bxtwc.o obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o obj-$(CONFIG_MFD_MT6397) += mt6397-core.o
drivers/mfd/intel_soc_pmic_chtwc.c new file +175 -0
175 lines not on this page · raw message
include/linux/mfd/intel_chtwc.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.9.3
Quoted 4 lines · Hans de Goede
Add mfd driver for Intel CHT WhiskeyCove PMIC, based on various non upstreamed CHT WhiskeyCove PMIC patches. For now this just adds a minimal version which implements just enough to get ACPI PMIC opregion support to work, so that suspend/resume will work on machines with this PMIC.
Whiskey Cove in Subject and commit message.
Quoted 3 lines
+intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o intel_soc_pmic_chtwc.o
intel-soc-pmic-$(CONFIG_INTEL_PMC_IPC) += intel_soc_pmic_bxtwc.o
obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o
Can we use one module per driver? I already pointed out to my patch (unfortunately needs to be updated) that tries to fix it for BXT WC.
drivers/mfd/intel_soc_pmic_chtwc.c line 31
Quoted 3 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +2
-0+/* PMIC device registers */ +#define REG_ADDR_MASK 0xff00
GENMASK()
drivers/mfd/intel_soc_pmic_chtwc.c line 33
Quoted 2 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +2
-0+#define REG_ADDR_SHIFT 8 +#define REG_OFFSET_MASK 0xff
Ditto.
Quoted 18 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +18
-0+ +/* Whiskey Cove PMIC share same ACPI ID between different platforms */ +#define CHT_WC_HRV 3 + +static struct mfd_cell cht_wc_dev[] = { + { + .name ="cht_wcove_region" , + }, +}; + +/* +* The CHT Whiskey Cove covers multiple i2c addresses, with a 1 byte +* register address space per i2c address, so we use 16 bit register +* addresses where the high 8 bits contain the i2c client address. +*/ +static int cht_wc_byte_reg_read (void *context,unsigned int reg, +unsigned int *val) +{
drivers/mfd/intel_soc_pmic_chtwc.c line 60
Quoted 10 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +9
-0+struct i2c_client *client = context; +int ret, orig_addr = client->addr; + +if (reg ®_ADDR_MASK ) + client->addr = (reg ®_ADDR_MASK ) >>REG_ADDR_SHIFT ; +else + client->addr =CHT_WC_DEVICE1_ADDR ; + ret =i2c_smbus_read_byte_data (client, reg ®_OFFSET_MASK ); + client->addr = orig_addr;
Looks a bit hackish to me.
Why not to define DEVICE1_ADDR as 0x6e00, for example?
Quoted 10 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +10
-0+ +if (ret <0 ) +return ret; + + *val = ret; +return 0 ; +} + +static int cht_wc_byte_reg_write (void *context,unsigned int reg, +unsigned int val)
drivers/mfd/intel_soc_pmic_chtwc.c line 80
Quoted 10 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +10
-0+{ +struct i2c_client *client = context; +int ret, orig_addr = client->addr; + +if (reg ®_ADDR_MASK ) + client->addr = (reg ®_ADDR_MASK ) >>REG_ADDR_SHIFT ; +else + client->addr =CHT_WC_DEVICE1_ADDR ; + ret =i2c_smbus_write_byte_data (client, reg ®_OFFSET_MASK , val); + client->addr = orig_addr;
Ditto.
Quoted 6 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +5
-0+ +return ret; +} +static int cht_wc_probe (struct i2c_client *client, +const struct i2c_device_id *i2c_id)
drivers/mfd/intel_soc_pmic_chtwc.c line 102
Quoted 10 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +9
-0+{ +struct device *dev = &client->dev; +struct intel_soc_pmic *pmic; +acpi_handle handle; +acpi_status status; +unsigned long long hrv; +int ret; + + handle =ACPI_HANDLE (dev);
Useless temporary variable?
Quoted 10 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +10
-0+ status =acpi_evaluate_integer (handle,"_HRV" ,NULL , &hrv); +if (ACPI_FAILURE (status)) { +dev_err (dev,"Failed to get PMIC hardware revision\n" ); +return -ENODEV ; + } +if (hrv !=CHT_WC_HRV ) { +dev_err (dev,"Invalid PMIC hardware revision: %llu\n" , hrv); +return -ENODEV ; + } +if (client->irq <0 ) {
drivers/mfd/intel_soc_pmic_chtwc.c line 128
Quoted 10 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +8
-0+dev_err (dev,"Invalid IRQ\n" ); +return -ENODEV ; + } + + pmic->regmap =devm_regmap_init (dev,NULL , client, &cht_wc_regmap_cfg); +if (IS_ERR (pmic->regmap)) { + ret =PTR_ERR (pmic->regmap); +dev_err (dev,"Failed to initialise regmap: %d\n" , ret);
Is it anyhow useful?
drivers/mfd/intel_soc_pmic_chtwc.c line 139
Quoted 12 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +11
-0+return ret; + } + + ret =mfd_add_devices (dev,-1 , cht_wc_dev,ARRAY_SIZE (cht_wc_dev), +NULL ,0 ,NULL ); +if (ret) { +dev_err (dev,"Failed to add devices: %d\n" , ret); +return ret; + } + +return 0 ;
return devm_mfd_add_devices(...);
include/linux/mfd/intel_chtwc.h line 2
Quoted 7 lines
include/linux/mfd/intel_chtwc.h new file +4
-0+} +++ b/include/linux/mfd/intel_chtwc.h@@ -0,0 +1,75 @@ +/* +* intel_chtwc.h - Header file for Intel Cherrytrail Whiskey Cove PMIC
Remove file name.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Hans de Goede
Add mfd driver for Intel CHT WhiskeyCove PMIC, based on various non upstreamed CHT WhiskeyCove PMIC patches. For now this just adds a minimal version which implements just enough to get ACPI PMIC opregion support to work, so that suspend/resume will work on machines with this PMIC.
Whiskey Cove in Subject and commit message.
Will fix for v3.
Quoted 6 lines
Quoted 3 lines
+intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o intel_soc_pmic_chtwc.o
intel-soc-pmic-$(CONFIG_INTEL_PMC_IPC) += intel_soc_pmic_bxtwc.o
obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.oCan we use one module per driver? I already pointed out to my patch (unfortunately needs to be updated) that tries to fix it for BXT WC.
Will fix for v3.
Quoted 10 lines
drivers/mfd/intel_soc_pmic_chtwc.c line 31
Quoted 3 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +2
-0+/* PMIC device registers */ +#define REG_ADDR_MASK 0xff00
GENMASK()drivers/mfd/intel_soc_pmic_chtwc.c line 33
Quoted 2 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +2
-0+#define REG_ADDR_SHIFT 8 +#define REG_OFFSET_MASK 0xffDitto.
Both fixed for v3.
Quoted 29 lines
Quoted 18 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +18
-0+ +/* Whiskey Cove PMIC share same ACPI ID between different platforms */ +#define CHT_WC_HRV 3 + +static struct mfd_cell cht_wc_dev[] = { + { + .name ="cht_wcove_region" , + }, +}; + +/* +* The CHT Whiskey Cove covers multiple i2c addresses, with a 1 byte +* register address space per i2c address, so we use 16 bit register +* addresses where the high 8 bits contain the i2c client address. +*/ +static int cht_wc_byte_reg_read (void *context,unsigned int reg, +unsigned int *val) +{drivers/mfd/intel_soc_pmic_chtwc.c line 60
Quoted 10 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +9
-0+struct i2c_client *client = context; +int ret, orig_addr = client->addr; + +if (reg ®_ADDR_MASK ) + client->addr = (reg ®_ADDR_MASK ) >>REG_ADDR_SHIFT ; +else + client->addr =CHT_WC_DEVICE1_ADDR ; + ret =i2c_smbus_read_byte_data (client, reg ®_OFFSET_MASK ); + client->addr = orig_addr;
Quoted 1 line
Looks a bit hackish to me.
Agreed.
Quoted 1 line
Why not to define
DEVICE1_ADDRas0x6e00, for example?
This is intended for callers who specify a register offset only without specifying which Whiskey Cove sub-device (i2c address) they want. This comes from the out of tree code I based this on, where this is also actually (ab)used by some of the mfd child device drivers. I plan for all the mainlined child device drivers to properly use a fill 16 bit address, which only leaves the ACPI REGS opregion accesses as potentially leaving the upper 8 bits 0. All the DSDTs I've access to do always properly use a 16 bit address. So I will just drop this hack for v3 replacing it with:
if (!(reg & REG_ADDR_MASK)) {
dev_err(&client->dev, "i2c device address not specified\n");
return -EINVAL;
}Which will catch and invalid REGS opregion accesses.
Quoted 39 lines
Quoted 11 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +10
-0+ +if (ret <0 ) +return ret; + + *val = ret; +return 0 ; +} + +static int cht_wc_byte_reg_write (void *context,unsigned int reg, +unsigned int val)drivers/mfd/intel_soc_pmic_chtwc.c line 80
Quoted 10 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +10
-0+{ +struct i2c_client *client = context; +int ret, orig_addr = client->addr; + +if (reg ®_ADDR_MASK ) + client->addr = (reg ®_ADDR_MASK ) >>REG_ADDR_SHIFT ; +else + client->addr =CHT_WC_DEVICE1_ADDR ; + ret =i2c_smbus_write_byte_data (client, reg ®_OFFSET_MASK , val); + client->addr = orig_addr;Ditto.
Quoted 14 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +13
-0+ +return ret; +} +static int cht_wc_probe (struct i2c_client *client, +const struct i2c_device_id *i2c_id) +{ +struct device *dev = &client->dev; +struct intel_soc_pmic *pmic; +acpi_handle handle; +acpi_status status; +unsigned long long hrv; +int ret; +
Quoted 3 lines
Quoted 1 line
+ handle =
ACPI_HANDLE(dev);Useless temporary variable?
Will fix for v3.
Quoted 16 lines
Quoted 15 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +14
-0+ status =acpi_evaluate_integer (handle,"_HRV" ,NULL , &hrv); +if (ACPI_FAILURE (status)) { +dev_err (dev,"Failed to get PMIC hardware revision\n" ); +return -ENODEV ; + } +if (hrv !=CHT_WC_HRV ) { +dev_err (dev,"Invalid PMIC hardware revision: %llu\n" , hrv); +return -ENODEV ; + } +if (client->irq <0 ) { +dev_err (dev,"Invalid IRQ\n" ); +return -ENODEV ; + } +
Quoted 7 lines
drivers/mfd/intel_soc_pmic_chtwc.c line 128
Quoted 5 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +4
-0+ pmic->regmap =devm_regmap_init (dev,NULL , client, &cht_wc_regmap_cfg); +if (IS_ERR (pmic->regmap)) { + ret =PTR_ERR (pmic->regmap); +dev_err (dev,"Failed to initialise regmap: %d\n" , ret);Is it anyhow useful?
Nope, I will remove this for v3.
Quoted 14 lines
drivers/mfd/intel_soc_pmic_chtwc.c line 139
Quoted 13 lines
drivers/mfd/intel_soc_pmic_chtwc.c new file +11
-0+return ret; + } + + ret =mfd_add_devices (dev,-1 , cht_wc_dev,ARRAY_SIZE (cht_wc_dev), +NULL ,0 ,NULL ); +if (ret) { +dev_err (dev,"Failed to add devices: %d\n" , ret); +return ret; + } + +return 0 ;
Quoted 1 line
return
devm_mfd_add_devices(...);
Will fix for v3.
Quoted 9 lines
include/linux/mfd/intel_chtwc.h line 2
Quoted 7 lines
include/linux/mfd/intel_chtwc.h new file +4
-0+} +++ b/include/linux/mfd/intel_chtwc.h@@ -0,0 +1,75 @@ +/* +* intel_chtwc.h - Header file for Intel Cherrytrail Whiskey Cove PMIC Remove file name.
Will fix for v3.
Regards,
Hans