1 From ab9d5c5c767c17bf9526f84beb5667f2a50e1a4d Mon Sep 17 00:00:00 2001
2 From: Minghuan Lian <Minghuan.Lian@nxp.com>
3 Date: Tue, 17 Jan 2017 17:32:42 +0800
4 Subject: [PATCH] irqchip/ls-scfg-msi: add LS1043a v1.1 MSI support
6 Cherry-pick patchwork patch with context adjustment.
8 A MSI controller of LS1043a v1.0 only includes one MSIR and
9 is assigned one GIC interrupt. In order to support affinity,
10 LS1043a v1.1 MSI is assigned 4 MSIRs and 4 GIC interrupts.
11 But the MSIR has the different offset and only supports 8 MSIs.
12 The bits between variable bit_start and bit_end in structure
13 ls_scfg_msir are used to show 8 MSI interrupts. msir_irqs and
14 msir_base are added to describe the difference of MSI between
15 LS1043a v1.1 and other SoCs.
17 Signed-off-by: Minghuan Lian <Minghuan.Lian@nxp.com>
18 Acked-by: Rob Herring <robh@kernel.org>
19 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
21 drivers/irqchip/irq-ls-scfg-msi.c | 45 +++++++++++++++++++++++++++++++++------
22 1 file changed, 39 insertions(+), 6 deletions(-)
24 --- a/drivers/irqchip/irq-ls-scfg-msi.c
25 +++ b/drivers/irqchip/irq-ls-scfg-msi.c
27 #define MSI_IRQS_PER_MSIR 32
28 #define MSI_MSIR_OFFSET 4
30 +#define MSI_LS1043V1_1_IRQS_PER_MSIR 8
31 +#define MSI_LS1043V1_1_MSIR_OFFSET 0x10
33 struct ls_scfg_msi_cfg {
34 u32 ibs_shift; /* Shift of interrupt bit select */
35 + u32 msir_irqs; /* The irq number per MSIR */
36 + u32 msir_base; /* The base address of MSIR */
40 struct ls_scfg_msi *msi_data;
43 + unsigned int bit_start;
44 + unsigned int bit_end;
48 @@ -140,13 +147,18 @@ static void ls_scfg_msi_irq_handler(stru
49 struct ls_scfg_msir *msir = irq_desc_get_handler_data(desc);
50 struct ls_scfg_msi *msi_data = msir->msi_data;
52 - int pos, virq, hwirq;
53 + int pos, size, virq, hwirq;
55 chained_irq_enter(irq_desc_get_chip(desc), desc);
57 val = ioread32be(msir->reg);
58 - for_each_set_bit(pos, &val, MSI_IRQS_PER_MSIR) {
59 - hwirq = ((31 - pos) << msi_data->cfg->ibs_shift) | msir->index;
61 + pos = msir->bit_start;
62 + size = msir->bit_end + 1;
64 + for_each_set_bit_from(pos, &val, size) {
65 + hwirq = ((msir->bit_end - pos) << msi_data->cfg->ibs_shift) |
67 virq = irq_find_mapping(msi_data->parent, hwirq);
69 generic_handle_irq(virq);
70 @@ -193,14 +205,24 @@ static int ls_scfg_msi_setup_hwirq(struc
72 msir->msi_data = msi_data;
74 - msir->reg = msi_data->regs + MSI_MSIR_OFFSET + 4 * index;
75 + msir->reg = msi_data->regs + msi_data->cfg->msir_base + 4 * index;
77 + if (msi_data->cfg->msir_irqs == MSI_LS1043V1_1_IRQS_PER_MSIR) {
78 + msir->bit_start = 32 - ((msir->index + 1) *
79 + MSI_LS1043V1_1_IRQS_PER_MSIR);
80 + msir->bit_end = msir->bit_start +
81 + MSI_LS1043V1_1_IRQS_PER_MSIR - 1;
83 + msir->bit_start = 0;
84 + msir->bit_end = msi_data->cfg->msir_irqs - 1;
87 irq_set_chained_handler_and_data(msir->gic_irq,
88 ls_scfg_msi_irq_handler,
91 /* Release the hwirqs corresponding to this MSIR */
92 - for (i = 0; i < MSI_IRQS_PER_MSIR; i++) {
93 + for (i = 0; i < msi_data->cfg->msir_irqs; i++) {
94 hwirq = i << msi_data->cfg->ibs_shift | msir->index;
95 bitmap_clear(msi_data->used, hwirq, 1);
97 @@ -216,7 +238,7 @@ static int ls_scfg_msi_teardown_hwirq(st
98 if (msir->gic_irq > 0)
99 irq_set_chained_handler_and_data(msir->gic_irq, NULL, NULL);
101 - for (i = 0; i < MSI_IRQS_PER_MSIR; i++) {
102 + for (i = 0; i < msi_data->cfg->msir_irqs; i++) {
103 hwirq = i << msi_data->cfg->ibs_shift | msir->index;
104 bitmap_set(msi_data->used, hwirq, 1);
106 @@ -226,10 +248,20 @@ static int ls_scfg_msi_teardown_hwirq(st
108 static struct ls_scfg_msi_cfg ls1021_msi_cfg = {
110 + .msir_irqs = MSI_IRQS_PER_MSIR,
111 + .msir_base = MSI_MSIR_OFFSET,
114 static struct ls_scfg_msi_cfg ls1046_msi_cfg = {
116 + .msir_irqs = MSI_IRQS_PER_MSIR,
117 + .msir_base = MSI_MSIR_OFFSET,
120 +static struct ls_scfg_msi_cfg ls1043_v1_1_msi_cfg = {
122 + .msir_irqs = MSI_LS1043V1_1_IRQS_PER_MSIR,
123 + .msir_base = MSI_LS1043V1_1_MSIR_OFFSET,
126 static const struct of_device_id ls_scfg_msi_id[] = {
127 @@ -240,6 +272,7 @@ static const struct of_device_id ls_scfg
128 { .compatible = "fsl,ls1012a-msi", .data = &ls1021_msi_cfg },
129 { .compatible = "fsl,ls1021a-msi", .data = &ls1021_msi_cfg },
130 { .compatible = "fsl,ls1043a-msi", .data = &ls1021_msi_cfg },
131 + { .compatible = "fsl,ls1043a-v1.1-msi", .data = &ls1043_v1_1_msi_cfg },
132 { .compatible = "fsl,ls1046a-msi", .data = &ls1046_msi_cfg },