mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-01 08:04:22 +08:00
d3546ccdce
PM8xxx PMIC family uses GPIO as parent IRQ. Using it together with the
irq_set_chained_handler_and_data() results in warnings from the GPIOLIB
(see 461c1a7d47
("gpiolib: override irq_enable/disable"))
as in this path the IRQ resources are not allocated (and thus the
corresponding GPIO is not marked as used for the IRQ. Use request_irq so
that the IRQ resources are proprely setup.
[ 0.803271] ------------[ cut here ]------------
[ 0.803338] WARNING: CPU: 3 PID: 1 at drivers/gpio/gpiolib.c:3207 gpiochip_enable_irq+0xa4/0xa8
[ 0.803470] Modules linked in:
[ 0.803542] CPU: 3 PID: 1 Comm: swapper/0 Not tainted 5.14.0-rc6-next-20210820-postmarketos-qcom-apq8064+ #1
[ 0.803645] Hardware name: Generic DT based system
[ 0.803710] Backtrace:
[ 0.803777] [<c0e3493c>] (dump_backtrace) from [<c0e34d00>] (show_stack+0x20/0x24)
[ 0.803911] r7:00000c87 r6:c07062dc r5:60000093 r4:c11d0f54
[ 0.803980] [<c0e34ce0>] (show_stack) from [<c0e38314>] (dump_stack_lvl+0x48/0x54)
[ 0.804097] [<c0e382cc>] (dump_stack_lvl) from [<c0e38338>] (dump_stack+0x18/0x1c)
[ 0.804217] r5:00000009 r4:c11fe208
[ 0.804274] [<c0e38320>] (dump_stack) from [<c03219c8>] (__warn+0xfc/0x114)
[ 0.804387] [<c03218cc>] (__warn) from [<c0e35334>] (warn_slowpath_fmt+0x74/0xd0)
[ 0.804509] r7:c07062dc r6:00000c87 r5:c11fe208 r4:00000000
[ 0.804577] [<c0e352c4>] (warn_slowpath_fmt) from [<c07062dc>] (gpiochip_enable_irq+0xa4/0xa8)
[ 0.804716] r8:c27b6200 r7:c27aec00 r6:c27aec18 r5:cf77a448 r4:c02225f0
[ 0.804789] [<c0706238>] (gpiochip_enable_irq) from [<c0706348>] (gpiochip_irq_enable+0x28/0x38)
[ 0.804921] r5:cf77a448 r4:c27aec18
[ 0.804977] [<c0706320>] (gpiochip_irq_enable) from [<c03897a0>] (irq_enable+0x48/0x78)
[ 0.805111] r5:00000000 r4:c27aec00
[ 0.805167] [<c0389758>] (irq_enable) from [<c0389850>] (__irq_startup+0x80/0xbc)
[ 0.805286] r5:00000000 r4:c27aec00
[ 0.805343] [<c03897d0>] (__irq_startup) from [<c038996c>] (irq_startup+0xe0/0x18c)
[ 0.805468] r7:c27aec00 r6:00000001 r5:00000000 r4:c27aec00
[ 0.805535] [<c038988c>] (irq_startup) from [<c0389a54>] (irq_activate_and_startup+0x3c/0x74)
[ 0.805669] r7:c27aec00 r6:00000001 r5:c27aec00 r4:00000000
[ 0.805736] [<c0389a18>] (irq_activate_and_startup) from [<c0389b58>] (__irq_do_set_handler+0xcc/0x1c0)
[ 0.805875] r7:c27aec00 r6:c0383710 r5:c08a16b0 r4:00000001
[ 0.805943] [<c0389a8c>] (__irq_do_set_handler) from [<c0389d80>] (irq_set_chained_handler_and_data+0x60/0x98)
[ 0.806087] r7:c27b5c10 r6:c27aed40 r5:c08a16b0 r4:c27aec00
[ 0.806154] [<c0389d20>] (irq_set_chained_handler_and_data) from [<c08a1660>] (pm8xxx_probe+0x1fc/0x24c)
[ 0.806298] r6:0000003a r5:0000003a r4:c27b5c00
[ 0.806359] [<c08a1464>] (pm8xxx_probe) from [<c0871420>] (platform_probe+0x6c/0xc8)
[ 0.806495] r10:c2507080 r9:e8bea2cc r8:c165e0e0 r7:c165e0e0 r6:c15f08f8 r5:c27b5c10
[ 0.806582] r4:00000000
[ 0.806632] [<c08713b4>] (platform_probe) from [<c086e280>] (really_probe+0xe8/0x460)
[ 0.806769] r7:c165e0e0 r6:c15f08f8 r5:00000000 r4:c27b5c10
[ 0.806837] [<c086e198>] (really_probe) from [<c086e6a8>] (__driver_probe_device+0xb0/0x22c)
[ 0.806975] r7:c27b5c10 r6:cf70fba4 r5:c15f08f8 r4:c27b5c10
[ 0.807042] [<c086e5f8>] (__driver_probe_device) from [<c086e868>] (driver_probe_device+0x44/0xe0)
[ 0.807188] r9:e8bea2cc r8:00000000 r7:c27b5c10 r6:cf70fba4 r5:c16ae4b4 r4:c16ae4b0
[ 0.807271] [<c086e824>] (driver_probe_device) from [<c086ecd8>] (__device_attach_driver+0xb4/0x12c)
[ 0.807421] r9:e8bea2cc r8:c15eec08 r7:c27b5c10 r6:cf70fba4 r5:c15f08f8 r4:00000001
[ 0.807506] [<c086ec24>] (__device_attach_driver) from [<c086c06c>] (bus_for_each_drv+0x94/0xe4)
[ 0.807651] r7:c16ae484 r6:c086ec24 r5:cf70fba4 r4:00000000
[ 0.807718] [<c086bfd8>] (bus_for_each_drv) from [<c086e0e0>] (__device_attach+0x104/0x19c)
[ 0.807852] r6:00000001 r5:c27b5c54 r4:c27b5c10
[ 0.807913] [<c086dfdc>] (__device_attach) from [<c086eef4>] (device_initial_probe+0x1c/0x20)
[ 0.808050] r6:c27b5c10 r5:c15ef1b0 r4:c27b5c10
[ 0.808111] [<c086eed8>] (device_initial_probe) from [<c086d00c>] (bus_probe_device+0x94/0x9c)
[ 0.808240] [<c086cf78>] (bus_probe_device) from [<c086a60c>] (device_add+0x404/0x8f4)
[ 0.808370] r7:c16ae484 r6:c251ba10 r5:00000000 r4:c27b5c10
[ 0.808439] [<c086a208>] (device_add) from [<c0a82f50>] (of_device_add+0x44/0x4c)
[ 0.808581] r10:c144c854 r9:00000001 r8:e8bea314 r7:c251ba10 r6:00000000 r5:00000000
[ 0.808669] r4:c27b5c00
[ 0.808718] [<c0a82f0c>] (of_device_add) from [<c0a836cc>] (of_platform_device_create_pdata+0xa0/0xc8)
[ 0.808850] [<c0a8362c>] (of_platform_device_create_pdata) from [<c0a83908>] (of_platform_bus_create+0x1f0/0x514)
[ 0.809005] r9:00000001 r8:c251ba10 r7:00000000 r6:00000000 r5:00000000 r4:e8bea2b0
[ 0.809086] [<c0a83718>] (of_platform_bus_create) from [<c0a83e04>] (of_platform_populate+0x98/0x128)
[ 0.809233] r10:c144c854 r9:00000001 r8:c251ba10 r7:00000000 r6:00000000 r5:e8bea170
[ 0.809321] r4:e8bea2b0
[ 0.809371] [<c0a83d6c>] (of_platform_populate) from [<c0a83f20>] (devm_of_platform_populate+0x60/0xa8)
[ 0.809521] r9:0000011d r8:c165e0e0 r7:e8bea170 r6:c2c34f40 r5:c2cac140 r4:c251ba10
[ 0.809604] [<c0a83ec0>] (devm_of_platform_populate) from [<c08a212c>] (ssbi_probe+0x138/0x16c)
[ 0.809738] r6:c2c34f40 r5:c251ba10 r4:ff822700
[ 0.809800] [<c08a1ff4>] (ssbi_probe) from [<c0871420>] (platform_probe+0x6c/0xc8)
[ 0.809923] r7:c165e0e0 r6:c15f0a80 r5:c251ba10 r4:00000000
[ 0.809989] [<c08713b4>] (platform_probe) from [<c086e280>] (really_probe+0xe8/0x460)
[ 0.810120] r7:c165e0e0 r6:c15f0a80 r5:00000000 r4:c251ba10
[ 0.810187] [<c086e198>] (really_probe) from [<c086e6a8>] (__driver_probe_device+0xb0/0x22c)
[ 0.810325] r7:c251ba10 r6:c15f0a80 r5:c15f0a80 r4:c251ba10
[ 0.810393] [<c086e5f8>] (__driver_probe_device) from [<c086e868>] (driver_probe_device+0x44/0xe0)
[ 0.810539] r9:0000011d r8:00000000 r7:c251ba10 r6:c15f0a80 r5:c16ae4b4 r4:c16ae4b0
[ 0.810623] [<c086e824>] (driver_probe_device) from [<c086ee2c>] (__driver_attach+0xdc/0x188)
[ 0.810766] r9:0000011d r8:c144c834 r7:00000000 r6:c15f0a80 r5:c251ba10 r4:00000000
[ 0.810849] [<c086ed50>] (__driver_attach) from [<c086bf60>] (bus_for_each_dev+0x88/0xd4)
[ 0.810985] r7:00000000 r6:c086ed50 r5:c15f0a80 r4:00000000
[ 0.811052] [<c086bed8>] (bus_for_each_dev) from [<c086dad4>] (driver_attach+0x2c/0x30)
[ 0.811182] r6:c15ef1b0 r5:c2c34e80 r4:c15f0a80
[ 0.811243] [<c086daa8>] (driver_attach) from [<c086d2dc>] (bus_add_driver+0x180/0x21c)
[ 0.811364] [<c086d15c>] (bus_add_driver) from [<c086fa6c>] (driver_register+0x84/0x118)
[ 0.811492] r7:00000000 r6:ffffe000 r5:c1428210 r4:c15f0a80
[ 0.811558] [<c086f9e8>] (driver_register) from [<c0871174>] (__platform_driver_register+0x2c/0x34)
[ 0.811683] r5:c1428210 r4:c16524a0
[ 0.811739] [<c0871148>] (__platform_driver_register) from [<c1428234>] (ssbi_driver_init+0x24/0x28)
[ 0.811868] [<c1428210>] (ssbi_driver_init) from [<c0302394>] (do_one_initcall+0x68/0x2c8)
[ 0.811990] [<c030232c>] (do_one_initcall) from [<c140147c>] (kernel_init_freeable+0x1dc/0x23c)
[ 0.812135] r7:cf7b0400 r6:c130339c r5:00000007 r4:c147f6a0
[ 0.812204] [<c14012a0>] (kernel_init_freeable) from [<c0e40e60>] (kernel_init+0x20/0x138)
[ 0.812345] r10:00000000 r9:00000000 r8:00000000 r7:00000000 r6:00000000 r5:c0e40e40
[ 0.812433] r4:00000000
[ 0.812483] [<c0e40e40>] (kernel_init) from [<c0300150>] (ret_from_fork+0x14/0x24)
[ 0.812596] Exception stack(0xcf70ffb0 to 0xcf70fff8)
[ 0.812684] ffa0: 00000000 00000000 00000000 00000000
[ 0.812809] ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 0.812923] ffe0: 00000000 00000000 00000000 00000000 00000013 00000000
[ 0.813008] r5:c0e40e40 r4:00000000
[ 0.813075] ---[ end trace ad2443eee078d094 ]---
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: David Heidelberg <david@ixit.cz> # on Nexus 7 (deb)
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Link: https://lore.kernel.org/r/20210925234333.2430755-1-dmitry.baryshkov@linaro.org
625 lines
16 KiB
C
625 lines
16 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "%s: " fmt, __func__
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/irqchip/chained_irq.h>
|
|
#include <linux/irq.h>
|
|
#include <linux/irqdomain.h>
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/err.h>
|
|
#include <linux/ssbi.h>
|
|
#include <linux/regmap.h>
|
|
#include <linux/of_platform.h>
|
|
#include <linux/mfd/core.h>
|
|
|
|
#define SSBI_REG_ADDR_IRQ_BASE 0x1BB
|
|
|
|
#define SSBI_REG_ADDR_IRQ_ROOT (SSBI_REG_ADDR_IRQ_BASE + 0)
|
|
#define SSBI_REG_ADDR_IRQ_M_STATUS1 (SSBI_REG_ADDR_IRQ_BASE + 1)
|
|
#define SSBI_REG_ADDR_IRQ_M_STATUS2 (SSBI_REG_ADDR_IRQ_BASE + 2)
|
|
#define SSBI_REG_ADDR_IRQ_M_STATUS3 (SSBI_REG_ADDR_IRQ_BASE + 3)
|
|
#define SSBI_REG_ADDR_IRQ_M_STATUS4 (SSBI_REG_ADDR_IRQ_BASE + 4)
|
|
#define SSBI_REG_ADDR_IRQ_BLK_SEL (SSBI_REG_ADDR_IRQ_BASE + 5)
|
|
#define SSBI_REG_ADDR_IRQ_IT_STATUS (SSBI_REG_ADDR_IRQ_BASE + 6)
|
|
#define SSBI_REG_ADDR_IRQ_CONFIG (SSBI_REG_ADDR_IRQ_BASE + 7)
|
|
#define SSBI_REG_ADDR_IRQ_RT_STATUS (SSBI_REG_ADDR_IRQ_BASE + 8)
|
|
|
|
#define PM8821_SSBI_REG_ADDR_IRQ_BASE 0x100
|
|
#define PM8821_SSBI_REG_ADDR_IRQ_MASTER0 (PM8821_SSBI_REG_ADDR_IRQ_BASE + 0x30)
|
|
#define PM8821_SSBI_REG_ADDR_IRQ_MASTER1 (PM8821_SSBI_REG_ADDR_IRQ_BASE + 0xb0)
|
|
#define PM8821_SSBI_REG(m, b, offset) \
|
|
((m == 0) ? \
|
|
(PM8821_SSBI_REG_ADDR_IRQ_MASTER0 + b + offset) : \
|
|
(PM8821_SSBI_REG_ADDR_IRQ_MASTER1 + b + offset))
|
|
#define PM8821_SSBI_ADDR_IRQ_ROOT(m, b) PM8821_SSBI_REG(m, b, 0x0)
|
|
#define PM8821_SSBI_ADDR_IRQ_CLEAR(m, b) PM8821_SSBI_REG(m, b, 0x01)
|
|
#define PM8821_SSBI_ADDR_IRQ_MASK(m, b) PM8821_SSBI_REG(m, b, 0x08)
|
|
#define PM8821_SSBI_ADDR_IRQ_RT_STATUS(m, b) PM8821_SSBI_REG(m, b, 0x0f)
|
|
|
|
#define PM8821_BLOCKS_PER_MASTER 7
|
|
|
|
#define PM_IRQF_LVL_SEL 0x01 /* level select */
|
|
#define PM_IRQF_MASK_FE 0x02 /* mask falling edge */
|
|
#define PM_IRQF_MASK_RE 0x04 /* mask rising edge */
|
|
#define PM_IRQF_CLR 0x08 /* clear interrupt */
|
|
#define PM_IRQF_BITS_MASK 0x70
|
|
#define PM_IRQF_BITS_SHIFT 4
|
|
#define PM_IRQF_WRITE 0x80
|
|
|
|
#define PM_IRQF_MASK_ALL (PM_IRQF_MASK_FE | \
|
|
PM_IRQF_MASK_RE)
|
|
|
|
#define REG_HWREV 0x002 /* PMIC4 revision */
|
|
#define REG_HWREV_2 0x0E8 /* PMIC4 revision 2 */
|
|
|
|
#define PM8XXX_NR_IRQS 256
|
|
#define PM8821_NR_IRQS 112
|
|
|
|
struct pm_irq_data {
|
|
int num_irqs;
|
|
struct irq_chip *irq_chip;
|
|
irq_handler_t irq_handler;
|
|
};
|
|
|
|
struct pm_irq_chip {
|
|
struct regmap *regmap;
|
|
spinlock_t pm_irq_lock;
|
|
struct irq_domain *irqdomain;
|
|
unsigned int num_blocks;
|
|
unsigned int num_masters;
|
|
const struct pm_irq_data *pm_irq_data;
|
|
/* MUST BE AT THE END OF THIS STRUCT */
|
|
u8 config[];
|
|
};
|
|
|
|
static int pm8xxx_read_block_irq(struct pm_irq_chip *chip, unsigned int bp,
|
|
unsigned int *ip)
|
|
{
|
|
int rc;
|
|
|
|
spin_lock(&chip->pm_irq_lock);
|
|
rc = regmap_write(chip->regmap, SSBI_REG_ADDR_IRQ_BLK_SEL, bp);
|
|
if (rc) {
|
|
pr_err("Failed Selecting Block %d rc=%d\n", bp, rc);
|
|
goto bail;
|
|
}
|
|
|
|
rc = regmap_read(chip->regmap, SSBI_REG_ADDR_IRQ_IT_STATUS, ip);
|
|
if (rc)
|
|
pr_err("Failed Reading Status rc=%d\n", rc);
|
|
bail:
|
|
spin_unlock(&chip->pm_irq_lock);
|
|
return rc;
|
|
}
|
|
|
|
static int
|
|
pm8xxx_config_irq(struct pm_irq_chip *chip, unsigned int bp, unsigned int cp)
|
|
{
|
|
int rc;
|
|
|
|
spin_lock(&chip->pm_irq_lock);
|
|
rc = regmap_write(chip->regmap, SSBI_REG_ADDR_IRQ_BLK_SEL, bp);
|
|
if (rc) {
|
|
pr_err("Failed Selecting Block %d rc=%d\n", bp, rc);
|
|
goto bail;
|
|
}
|
|
|
|
cp |= PM_IRQF_WRITE;
|
|
rc = regmap_write(chip->regmap, SSBI_REG_ADDR_IRQ_CONFIG, cp);
|
|
if (rc)
|
|
pr_err("Failed Configuring IRQ rc=%d\n", rc);
|
|
bail:
|
|
spin_unlock(&chip->pm_irq_lock);
|
|
return rc;
|
|
}
|
|
|
|
static int pm8xxx_irq_block_handler(struct pm_irq_chip *chip, int block)
|
|
{
|
|
int pmirq, i, ret = 0;
|
|
unsigned int bits;
|
|
|
|
ret = pm8xxx_read_block_irq(chip, block, &bits);
|
|
if (ret) {
|
|
pr_err("Failed reading %d block ret=%d", block, ret);
|
|
return ret;
|
|
}
|
|
if (!bits) {
|
|
pr_err("block bit set in master but no irqs: %d", block);
|
|
return 0;
|
|
}
|
|
|
|
/* Check IRQ bits */
|
|
for (i = 0; i < 8; i++) {
|
|
if (bits & (1 << i)) {
|
|
pmirq = block * 8 + i;
|
|
generic_handle_domain_irq(chip->irqdomain, pmirq);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int pm8xxx_irq_master_handler(struct pm_irq_chip *chip, int master)
|
|
{
|
|
unsigned int blockbits;
|
|
int block_number, i, ret = 0;
|
|
|
|
ret = regmap_read(chip->regmap, SSBI_REG_ADDR_IRQ_M_STATUS1 + master,
|
|
&blockbits);
|
|
if (ret) {
|
|
pr_err("Failed to read master %d ret=%d\n", master, ret);
|
|
return ret;
|
|
}
|
|
if (!blockbits) {
|
|
pr_err("master bit set in root but no blocks: %d", master);
|
|
return 0;
|
|
}
|
|
|
|
for (i = 0; i < 8; i++)
|
|
if (blockbits & (1 << i)) {
|
|
block_number = master * 8 + i; /* block # */
|
|
ret |= pm8xxx_irq_block_handler(chip, block_number);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static irqreturn_t pm8xxx_irq_handler(int irq, void *data)
|
|
{
|
|
struct pm_irq_chip *chip = data;
|
|
unsigned int root;
|
|
int i, ret, masters = 0;
|
|
|
|
ret = regmap_read(chip->regmap, SSBI_REG_ADDR_IRQ_ROOT, &root);
|
|
if (ret) {
|
|
pr_err("Can't read root status ret=%d\n", ret);
|
|
return IRQ_NONE;
|
|
}
|
|
|
|
/* on pm8xxx series masters start from bit 1 of the root */
|
|
masters = root >> 1;
|
|
|
|
/* Read allowed masters for blocks. */
|
|
for (i = 0; i < chip->num_masters; i++)
|
|
if (masters & (1 << i))
|
|
pm8xxx_irq_master_handler(chip, i);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static void pm8821_irq_block_handler(struct pm_irq_chip *chip,
|
|
int master, int block)
|
|
{
|
|
int pmirq, i, ret;
|
|
unsigned int bits;
|
|
|
|
ret = regmap_read(chip->regmap,
|
|
PM8821_SSBI_ADDR_IRQ_ROOT(master, block), &bits);
|
|
if (ret) {
|
|
pr_err("Reading block %d failed ret=%d", block, ret);
|
|
return;
|
|
}
|
|
|
|
/* Convert block offset to global block number */
|
|
block += (master * PM8821_BLOCKS_PER_MASTER) - 1;
|
|
|
|
/* Check IRQ bits */
|
|
for (i = 0; i < 8; i++) {
|
|
if (bits & BIT(i)) {
|
|
pmirq = block * 8 + i;
|
|
generic_handle_domain_irq(chip->irqdomain, pmirq);
|
|
}
|
|
}
|
|
}
|
|
|
|
static inline void pm8821_irq_master_handler(struct pm_irq_chip *chip,
|
|
int master, u8 master_val)
|
|
{
|
|
int block;
|
|
|
|
for (block = 1; block < 8; block++)
|
|
if (master_val & BIT(block))
|
|
pm8821_irq_block_handler(chip, master, block);
|
|
}
|
|
|
|
static irqreturn_t pm8821_irq_handler(int irq, void *data)
|
|
{
|
|
struct pm_irq_chip *chip = data;
|
|
unsigned int master;
|
|
int ret;
|
|
|
|
ret = regmap_read(chip->regmap,
|
|
PM8821_SSBI_REG_ADDR_IRQ_MASTER0, &master);
|
|
if (ret) {
|
|
pr_err("Failed to read master 0 ret=%d\n", ret);
|
|
return IRQ_NONE;
|
|
}
|
|
|
|
/* bits 1 through 7 marks the first 7 blocks in master 0 */
|
|
if (master & GENMASK(7, 1))
|
|
pm8821_irq_master_handler(chip, 0, master);
|
|
|
|
/* bit 0 marks if master 1 contains any bits */
|
|
if (!(master & BIT(0)))
|
|
return IRQ_NONE;
|
|
|
|
ret = regmap_read(chip->regmap,
|
|
PM8821_SSBI_REG_ADDR_IRQ_MASTER1, &master);
|
|
if (ret) {
|
|
pr_err("Failed to read master 1 ret=%d\n", ret);
|
|
return IRQ_NONE;
|
|
}
|
|
|
|
pm8821_irq_master_handler(chip, 1, master);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static void pm8xxx_irq_mask_ack(struct irq_data *d)
|
|
{
|
|
struct pm_irq_chip *chip = irq_data_get_irq_chip_data(d);
|
|
unsigned int pmirq = irqd_to_hwirq(d);
|
|
u8 block, config;
|
|
|
|
block = pmirq / 8;
|
|
|
|
config = chip->config[pmirq] | PM_IRQF_MASK_ALL | PM_IRQF_CLR;
|
|
pm8xxx_config_irq(chip, block, config);
|
|
}
|
|
|
|
static void pm8xxx_irq_unmask(struct irq_data *d)
|
|
{
|
|
struct pm_irq_chip *chip = irq_data_get_irq_chip_data(d);
|
|
unsigned int pmirq = irqd_to_hwirq(d);
|
|
u8 block, config;
|
|
|
|
block = pmirq / 8;
|
|
|
|
config = chip->config[pmirq];
|
|
pm8xxx_config_irq(chip, block, config);
|
|
}
|
|
|
|
static int pm8xxx_irq_set_type(struct irq_data *d, unsigned int flow_type)
|
|
{
|
|
struct pm_irq_chip *chip = irq_data_get_irq_chip_data(d);
|
|
unsigned int pmirq = irqd_to_hwirq(d);
|
|
int irq_bit;
|
|
u8 block, config;
|
|
|
|
block = pmirq / 8;
|
|
irq_bit = pmirq % 8;
|
|
|
|
chip->config[pmirq] = (irq_bit << PM_IRQF_BITS_SHIFT)
|
|
| PM_IRQF_MASK_ALL;
|
|
if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
|
|
if (flow_type & IRQF_TRIGGER_RISING)
|
|
chip->config[pmirq] &= ~PM_IRQF_MASK_RE;
|
|
if (flow_type & IRQF_TRIGGER_FALLING)
|
|
chip->config[pmirq] &= ~PM_IRQF_MASK_FE;
|
|
} else {
|
|
chip->config[pmirq] |= PM_IRQF_LVL_SEL;
|
|
|
|
if (flow_type & IRQF_TRIGGER_HIGH)
|
|
chip->config[pmirq] &= ~PM_IRQF_MASK_RE;
|
|
else
|
|
chip->config[pmirq] &= ~PM_IRQF_MASK_FE;
|
|
}
|
|
|
|
config = chip->config[pmirq] | PM_IRQF_CLR;
|
|
return pm8xxx_config_irq(chip, block, config);
|
|
}
|
|
|
|
static int pm8xxx_irq_get_irqchip_state(struct irq_data *d,
|
|
enum irqchip_irq_state which,
|
|
bool *state)
|
|
{
|
|
struct pm_irq_chip *chip = irq_data_get_irq_chip_data(d);
|
|
unsigned int pmirq = irqd_to_hwirq(d);
|
|
unsigned int bits;
|
|
int irq_bit;
|
|
u8 block;
|
|
int rc;
|
|
|
|
if (which != IRQCHIP_STATE_LINE_LEVEL)
|
|
return -EINVAL;
|
|
|
|
block = pmirq / 8;
|
|
irq_bit = pmirq % 8;
|
|
|
|
spin_lock(&chip->pm_irq_lock);
|
|
rc = regmap_write(chip->regmap, SSBI_REG_ADDR_IRQ_BLK_SEL, block);
|
|
if (rc) {
|
|
pr_err("Failed Selecting Block %d rc=%d\n", block, rc);
|
|
goto bail;
|
|
}
|
|
|
|
rc = regmap_read(chip->regmap, SSBI_REG_ADDR_IRQ_RT_STATUS, &bits);
|
|
if (rc) {
|
|
pr_err("Failed Reading Status rc=%d\n", rc);
|
|
goto bail;
|
|
}
|
|
|
|
*state = !!(bits & BIT(irq_bit));
|
|
bail:
|
|
spin_unlock(&chip->pm_irq_lock);
|
|
|
|
return rc;
|
|
}
|
|
|
|
static struct irq_chip pm8xxx_irq_chip = {
|
|
.name = "pm8xxx",
|
|
.irq_mask_ack = pm8xxx_irq_mask_ack,
|
|
.irq_unmask = pm8xxx_irq_unmask,
|
|
.irq_set_type = pm8xxx_irq_set_type,
|
|
.irq_get_irqchip_state = pm8xxx_irq_get_irqchip_state,
|
|
.flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_SKIP_SET_WAKE,
|
|
};
|
|
|
|
static void pm8xxx_irq_domain_map(struct pm_irq_chip *chip,
|
|
struct irq_domain *domain, unsigned int irq,
|
|
irq_hw_number_t hwirq, unsigned int type)
|
|
{
|
|
irq_domain_set_info(domain, irq, hwirq, chip->pm_irq_data->irq_chip,
|
|
chip, handle_level_irq, NULL, NULL);
|
|
irq_set_noprobe(irq);
|
|
}
|
|
|
|
static int pm8xxx_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
|
|
unsigned int nr_irqs, void *data)
|
|
{
|
|
struct pm_irq_chip *chip = domain->host_data;
|
|
struct irq_fwspec *fwspec = data;
|
|
irq_hw_number_t hwirq;
|
|
unsigned int type;
|
|
int ret, i;
|
|
|
|
ret = irq_domain_translate_twocell(domain, fwspec, &hwirq, &type);
|
|
if (ret)
|
|
return ret;
|
|
|
|
for (i = 0; i < nr_irqs; i++)
|
|
pm8xxx_irq_domain_map(chip, domain, virq + i, hwirq + i, type);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct irq_domain_ops pm8xxx_irq_domain_ops = {
|
|
.alloc = pm8xxx_irq_domain_alloc,
|
|
.free = irq_domain_free_irqs_common,
|
|
.translate = irq_domain_translate_twocell,
|
|
};
|
|
|
|
static void pm8821_irq_mask_ack(struct irq_data *d)
|
|
{
|
|
struct pm_irq_chip *chip = irq_data_get_irq_chip_data(d);
|
|
unsigned int pmirq = irqd_to_hwirq(d);
|
|
u8 block, master;
|
|
int irq_bit, rc;
|
|
|
|
block = pmirq / 8;
|
|
master = block / PM8821_BLOCKS_PER_MASTER;
|
|
irq_bit = pmirq % 8;
|
|
block %= PM8821_BLOCKS_PER_MASTER;
|
|
|
|
rc = regmap_update_bits(chip->regmap,
|
|
PM8821_SSBI_ADDR_IRQ_MASK(master, block),
|
|
BIT(irq_bit), BIT(irq_bit));
|
|
if (rc) {
|
|
pr_err("Failed to mask IRQ:%d rc=%d\n", pmirq, rc);
|
|
return;
|
|
}
|
|
|
|
rc = regmap_update_bits(chip->regmap,
|
|
PM8821_SSBI_ADDR_IRQ_CLEAR(master, block),
|
|
BIT(irq_bit), BIT(irq_bit));
|
|
if (rc)
|
|
pr_err("Failed to CLEAR IRQ:%d rc=%d\n", pmirq, rc);
|
|
}
|
|
|
|
static void pm8821_irq_unmask(struct irq_data *d)
|
|
{
|
|
struct pm_irq_chip *chip = irq_data_get_irq_chip_data(d);
|
|
unsigned int pmirq = irqd_to_hwirq(d);
|
|
int irq_bit, rc;
|
|
u8 block, master;
|
|
|
|
block = pmirq / 8;
|
|
master = block / PM8821_BLOCKS_PER_MASTER;
|
|
irq_bit = pmirq % 8;
|
|
block %= PM8821_BLOCKS_PER_MASTER;
|
|
|
|
rc = regmap_update_bits(chip->regmap,
|
|
PM8821_SSBI_ADDR_IRQ_MASK(master, block),
|
|
BIT(irq_bit), ~BIT(irq_bit));
|
|
if (rc)
|
|
pr_err("Failed to read/write unmask IRQ:%d rc=%d\n", pmirq, rc);
|
|
|
|
}
|
|
|
|
static int pm8821_irq_get_irqchip_state(struct irq_data *d,
|
|
enum irqchip_irq_state which,
|
|
bool *state)
|
|
{
|
|
struct pm_irq_chip *chip = irq_data_get_irq_chip_data(d);
|
|
int rc, pmirq = irqd_to_hwirq(d);
|
|
u8 block, irq_bit, master;
|
|
unsigned int bits;
|
|
|
|
block = pmirq / 8;
|
|
master = block / PM8821_BLOCKS_PER_MASTER;
|
|
irq_bit = pmirq % 8;
|
|
block %= PM8821_BLOCKS_PER_MASTER;
|
|
|
|
rc = regmap_read(chip->regmap,
|
|
PM8821_SSBI_ADDR_IRQ_RT_STATUS(master, block), &bits);
|
|
if (rc) {
|
|
pr_err("Reading Status of IRQ %d failed rc=%d\n", pmirq, rc);
|
|
return rc;
|
|
}
|
|
|
|
*state = !!(bits & BIT(irq_bit));
|
|
|
|
return rc;
|
|
}
|
|
|
|
static struct irq_chip pm8821_irq_chip = {
|
|
.name = "pm8821",
|
|
.irq_mask_ack = pm8821_irq_mask_ack,
|
|
.irq_unmask = pm8821_irq_unmask,
|
|
.irq_get_irqchip_state = pm8821_irq_get_irqchip_state,
|
|
.flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_SKIP_SET_WAKE,
|
|
};
|
|
|
|
static const struct regmap_config ssbi_regmap_config = {
|
|
.reg_bits = 16,
|
|
.val_bits = 8,
|
|
.max_register = 0x3ff,
|
|
.fast_io = true,
|
|
.reg_read = ssbi_reg_read,
|
|
.reg_write = ssbi_reg_write
|
|
};
|
|
|
|
static const struct pm_irq_data pm8xxx_data = {
|
|
.num_irqs = PM8XXX_NR_IRQS,
|
|
.irq_chip = &pm8xxx_irq_chip,
|
|
.irq_handler = pm8xxx_irq_handler,
|
|
};
|
|
|
|
static const struct pm_irq_data pm8821_data = {
|
|
.num_irqs = PM8821_NR_IRQS,
|
|
.irq_chip = &pm8821_irq_chip,
|
|
.irq_handler = pm8821_irq_handler,
|
|
};
|
|
|
|
static const struct of_device_id pm8xxx_id_table[] = {
|
|
{ .compatible = "qcom,pm8018", .data = &pm8xxx_data},
|
|
{ .compatible = "qcom,pm8058", .data = &pm8xxx_data},
|
|
{ .compatible = "qcom,pm8821", .data = &pm8821_data},
|
|
{ .compatible = "qcom,pm8921", .data = &pm8xxx_data},
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, pm8xxx_id_table);
|
|
|
|
static int pm8xxx_probe(struct platform_device *pdev)
|
|
{
|
|
const struct pm_irq_data *data;
|
|
struct regmap *regmap;
|
|
int irq, rc;
|
|
unsigned int val;
|
|
u32 rev;
|
|
struct pm_irq_chip *chip;
|
|
|
|
data = of_device_get_match_data(&pdev->dev);
|
|
if (!data) {
|
|
dev_err(&pdev->dev, "No matching driver data found\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
if (irq < 0)
|
|
return irq;
|
|
|
|
regmap = devm_regmap_init(&pdev->dev, NULL, pdev->dev.parent,
|
|
&ssbi_regmap_config);
|
|
if (IS_ERR(regmap))
|
|
return PTR_ERR(regmap);
|
|
|
|
/* Read PMIC chip revision */
|
|
rc = regmap_read(regmap, REG_HWREV, &val);
|
|
if (rc) {
|
|
pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc);
|
|
return rc;
|
|
}
|
|
pr_info("PMIC revision 1: %02X\n", val);
|
|
rev = val;
|
|
|
|
/* Read PMIC chip revision 2 */
|
|
rc = regmap_read(regmap, REG_HWREV_2, &val);
|
|
if (rc) {
|
|
pr_err("Failed to read hw rev 2 reg %d:rc=%d\n",
|
|
REG_HWREV_2, rc);
|
|
return rc;
|
|
}
|
|
pr_info("PMIC revision 2: %02X\n", val);
|
|
rev |= val << BITS_PER_BYTE;
|
|
|
|
chip = devm_kzalloc(&pdev->dev,
|
|
struct_size(chip, config, data->num_irqs),
|
|
GFP_KERNEL);
|
|
if (!chip)
|
|
return -ENOMEM;
|
|
|
|
platform_set_drvdata(pdev, chip);
|
|
chip->regmap = regmap;
|
|
chip->num_blocks = DIV_ROUND_UP(data->num_irqs, 8);
|
|
chip->num_masters = DIV_ROUND_UP(chip->num_blocks, 8);
|
|
chip->pm_irq_data = data;
|
|
spin_lock_init(&chip->pm_irq_lock);
|
|
|
|
chip->irqdomain = irq_domain_add_linear(pdev->dev.of_node,
|
|
data->num_irqs,
|
|
&pm8xxx_irq_domain_ops,
|
|
chip);
|
|
if (!chip->irqdomain)
|
|
return -ENODEV;
|
|
|
|
rc = devm_request_irq(&pdev->dev, irq, data->irq_handler, 0, dev_name(&pdev->dev), chip);
|
|
if (rc)
|
|
return rc;
|
|
|
|
irq_set_irq_wake(irq, 1);
|
|
|
|
rc = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
|
|
if (rc)
|
|
irq_domain_remove(chip->irqdomain);
|
|
|
|
return rc;
|
|
}
|
|
|
|
static int pm8xxx_remove_child(struct device *dev, void *unused)
|
|
{
|
|
platform_device_unregister(to_platform_device(dev));
|
|
return 0;
|
|
}
|
|
|
|
static int pm8xxx_remove(struct platform_device *pdev)
|
|
{
|
|
struct pm_irq_chip *chip = platform_get_drvdata(pdev);
|
|
|
|
device_for_each_child(&pdev->dev, NULL, pm8xxx_remove_child);
|
|
irq_domain_remove(chip->irqdomain);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver pm8xxx_driver = {
|
|
.probe = pm8xxx_probe,
|
|
.remove = pm8xxx_remove,
|
|
.driver = {
|
|
.name = "pm8xxx-core",
|
|
.of_match_table = pm8xxx_id_table,
|
|
},
|
|
};
|
|
|
|
static int __init pm8xxx_init(void)
|
|
{
|
|
return platform_driver_register(&pm8xxx_driver);
|
|
}
|
|
subsys_initcall(pm8xxx_init);
|
|
|
|
static void __exit pm8xxx_exit(void)
|
|
{
|
|
platform_driver_unregister(&pm8xxx_driver);
|
|
}
|
|
module_exit(pm8xxx_exit);
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_DESCRIPTION("PMIC 8xxx core driver");
|
|
MODULE_VERSION("1.0");
|
|
MODULE_ALIAS("platform:pm8xxx-core");
|