1 // SPDX-License-Identifier: GPL-2.0
3 * Device access for Basin Cove PMIC
5 * Copyright (c) 2019, Intel Corporation.
6 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
9 #include <linux/acpi.h>
10 #include <linux/interrupt.h>
11 #include <linux/mfd/core.h>
12 #include <linux/mfd/intel_soc_pmic.h>
13 #include <linux/mfd/intel_soc_pmic_mrfld.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/regmap.h>
18 #include <asm/intel_scu_ipc.h>
23 * Firmware on the systems with Basin Cove PMIC services Level 1 IRQs
24 * without an assistance. Thus, each of the Level 1 IRQ is represented
25 * as a separate RTE in IOAPIC.
27 static struct resource irq_level2_resources[] = {
28 DEFINE_RES_IRQ(0), /* power button */
29 DEFINE_RES_IRQ(0), /* TMU */
30 DEFINE_RES_IRQ(0), /* thermal */
31 DEFINE_RES_IRQ(0), /* BCU */
32 DEFINE_RES_IRQ(0), /* ADC */
33 DEFINE_RES_IRQ(0), /* charger */
34 DEFINE_RES_IRQ(0), /* GPIO */
37 static const struct mfd_cell bcove_dev[] = {
39 .name = "mrfld_bcove_pwrbtn",
41 .resources = &irq_level2_resources[0],
43 .name = "mrfld_bcove_tmu",
45 .resources = &irq_level2_resources[1],
47 .name = "mrfld_bcove_thermal",
49 .resources = &irq_level2_resources[2],
51 .name = "mrfld_bcove_bcu",
53 .resources = &irq_level2_resources[3],
55 .name = "mrfld_bcove_adc",
57 .resources = &irq_level2_resources[4],
59 .name = "mrfld_bcove_charger",
61 .resources = &irq_level2_resources[5],
63 .name = "mrfld_bcove_pwrsrc",
65 .resources = &irq_level2_resources[5],
67 .name = "mrfld_bcove_gpio",
69 .resources = &irq_level2_resources[6],
71 { .name = "mrfld_bcove_region", },
74 static int bcove_ipc_byte_reg_read(void *context, unsigned int reg,
77 struct intel_soc_pmic *pmic = context;
81 ret = intel_scu_ipc_dev_ioread8(pmic->scu, reg, &ipc_out);
89 static int bcove_ipc_byte_reg_write(void *context, unsigned int reg,
92 struct intel_soc_pmic *pmic = context;
95 return intel_scu_ipc_dev_iowrite8(pmic->scu, reg, ipc_in);
98 static const struct regmap_config bcove_regmap_config = {
101 .max_register = 0xff,
102 .reg_write = bcove_ipc_byte_reg_write,
103 .reg_read = bcove_ipc_byte_reg_read,
106 static int bcove_probe(struct platform_device *pdev)
108 struct device *dev = &pdev->dev;
109 struct intel_soc_pmic *pmic;
113 pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL);
117 pmic->scu = devm_intel_scu_ipc_dev_get(dev);
121 platform_set_drvdata(pdev, pmic);
122 pmic->dev = &pdev->dev;
124 pmic->regmap = devm_regmap_init(dev, NULL, pmic, &bcove_regmap_config);
125 if (IS_ERR(pmic->regmap))
126 return PTR_ERR(pmic->regmap);
128 for (i = 0; i < ARRAY_SIZE(irq_level2_resources); i++) {
129 ret = platform_get_irq(pdev, i);
133 irq_level2_resources[i].start = ret;
134 irq_level2_resources[i].end = ret;
137 return devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE,
138 bcove_dev, ARRAY_SIZE(bcove_dev),
142 static const struct acpi_device_id bcove_acpi_ids[] = {
146 MODULE_DEVICE_TABLE(acpi, bcove_acpi_ids);
148 static struct platform_driver bcove_driver = {
150 .name = "intel_soc_pmic_mrfld",
151 .acpi_match_table = bcove_acpi_ids,
153 .probe = bcove_probe,
155 module_platform_driver(bcove_driver);
157 MODULE_DESCRIPTION("IPC driver for Intel SoC Basin Cove PMIC");
158 MODULE_LICENSE("GPL v2");