Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: mfd: hi6421-spmi-pmic: get rid of interrupt properties

Both irqnum and irqarray properties reflect the same thing:
the number of bits and bytes for interrupts at this
chipset. E. g.:

irqnum = 8 x irqarray

This can be seen by the way pending interrupts are handled:

/* During probe time */
pmic->irqs = devm_kzalloc(dev, pmic->irqnum * sizeof(int), GFP_KERNEL);

/* While handling IRQs */
for (i = 0; i < pmic->irqarray; i++) {
pending = hi6421_spmi_pmic_read(pmic, (i + pmic->irq_addr));
pending &= 0xff;

for_each_set_bit(offset, &pending, 8)
generic_handle_irq(pmic->irqs[offset + i * 8]);

}

Going further, there are some logic at the driver which assumes
that irqarray is 2:

/* solve powerkey order */
if ((i == HISI_IRQ_KEY_NUM) &&
((pending & HISI_IRQ_KEY_VALUE) == HISI_IRQ_KEY_VALUE)) {
generic_handle_irq(pmic->irqs[HISI_IRQ_KEY_DOWN]);
generic_handle_irq(pmic->irqs[HISI_IRQ_KEY_UP]);
pending &= (~HISI_IRQ_KEY_VALUE);
}

As HISI_IRQ_KEY_DOWN and HISI_IRQ_KEY_UP are fixed values
and don't depend on irqnum/irqarray.

The IRQ addr and mask addr seem to be also fixed, based on some
comments at the OF parsing code. So, get rid of them too,
removing the of parsing function completely.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/e231244e42cb5b56240705cac2f987e11a078038.1597762400.git.mchehab+huawei@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Mauro Carvalho Chehab and committed by
Greg Kroah-Hartman
b240d014 78dd4243

+20 -75
+20 -60
drivers/staging/hikey9xx/hi6421-spmi-pmic.c
··· 38 38 /* 8-bit register offset in PMIC */ 39 39 #define HISI_MASK_STATE 0xff 40 40 41 + #define HISI_IRQ_ARRAY 2 42 + #define HISI_IRQ_NUM (HISI_IRQ_ARRAY * 8) 43 + 44 + #define SOC_PMIC_IRQ_MASK_0_ADDR 0x0202 45 + #define SOC_PMIC_IRQ0_ADDR 0x0212 46 + 41 47 #define HISI_IRQ_KEY_NUM 0 42 48 #define HISI_IRQ_KEY_VALUE 0xc0 43 49 #define HISI_IRQ_KEY_DOWN 7 ··· 127 121 unsigned long pending; 128 122 int i, offset; 129 123 130 - for (i = 0; i < pmic->irqarray; i++) { 131 - pending = hi6421_spmi_pmic_read(pmic, (i + pmic->irq_addr)); 124 + for (i = 0; i < HISI_IRQ_ARRAY; i++) { 125 + pending = hi6421_spmi_pmic_read(pmic, (i + SOC_PMIC_IRQ0_ADDR)); 132 126 pending &= HISI_MASK_FIELD; 133 127 if (pending != 0) 134 128 pr_debug("pending[%d]=0x%lx\n\r", i, pending); 135 129 136 - hi6421_spmi_pmic_write(pmic, (i + pmic->irq_addr), pending); 130 + hi6421_spmi_pmic_write(pmic, (i + SOC_PMIC_IRQ0_ADDR), pending); 137 131 138 132 /* solve powerkey order */ 139 133 if ((i == HISI_IRQ_KEY_NUM) && ··· 159 153 unsigned long flags; 160 154 161 155 offset = (irqd_to_hwirq(d) >> 3); 162 - offset += pmic->irq_mask_addr; 156 + offset += SOC_PMIC_IRQ_MASK_0_ADDR; 163 157 164 158 spin_lock_irqsave(&pmic->lock, flags); 165 159 data = hi6421_spmi_pmic_read(pmic, offset); ··· 175 169 unsigned long flags; 176 170 177 171 offset = (irqd_to_hwirq(d) >> 3); 178 - offset += pmic->irq_mask_addr; 172 + offset += SOC_PMIC_IRQ_MASK_0_ADDR; 179 173 180 174 spin_lock_irqsave(&pmic->lock, flags); 181 175 data = hi6421_spmi_pmic_read(pmic, offset); ··· 210 204 .xlate = irq_domain_xlate_twocell, 211 205 }; 212 206 213 - static int get_pmic_device_tree_data(struct device_node *np, 214 - struct hi6421_spmi_pmic *pmic) 215 - { 216 - int ret = 0; 217 - 218 - /* IRQ number */ 219 - ret = of_property_read_u32(np, "irq-num", &pmic->irqnum); 220 - if (ret) { 221 - pr_err("no irq-num property set\n"); 222 - ret = -ENODEV; 223 - return ret; 224 - } 225 - 226 - /* Size of IRQ array */ 227 - ret = of_property_read_u32(np, "irq-array", &pmic->irqarray); 228 - if (ret) { 229 - pr_err("no irq-array property set\n"); 230 - ret = -ENODEV; 231 - return ret; 232 - } 233 - 234 - /* SOC_PMIC_IRQ_MASK_0_ADDR */ 235 - ret = of_property_read_u32(np, "irq-mask-addr", &pmic->irq_mask_addr); 236 - if (ret) { 237 - pr_err("no irq-mask-addr property set\n"); 238 - ret = -ENODEV; 239 - return ret; 240 - } 241 - 242 - /* SOC_PMIC_IRQ0_ADDR */ 243 - ret = of_property_read_u32(np, "irq-addr", &pmic->irq_addr); 244 - if (ret) { 245 - pr_err("no irq-addr property set\n"); 246 - ret = -ENODEV; 247 - return ret; 248 - } 249 - 250 - return ret; 251 - } 252 - 253 207 static void hi6421_spmi_pmic_irq_prc(struct hi6421_spmi_pmic *pmic) 254 208 { 255 209 int i, pending; 256 210 257 - for (i = 0 ; i < pmic->irqarray; i++) 258 - hi6421_spmi_pmic_write(pmic, pmic->irq_mask_addr + i, 211 + for (i = 0 ; i < HISI_IRQ_ARRAY; i++) 212 + hi6421_spmi_pmic_write(pmic, SOC_PMIC_IRQ_MASK_0_ADDR + i, 259 213 HISI_MASK_STATE); 260 214 261 - for (i = 0 ; i < pmic->irqarray; i++) { 262 - pending = hi6421_spmi_pmic_read(pmic, pmic->irq_addr + i); 215 + for (i = 0 ; i < HISI_IRQ_ARRAY; i++) { 216 + pending = hi6421_spmi_pmic_read(pmic, SOC_PMIC_IRQ0_ADDR + i); 263 217 264 218 pr_debug("PMU IRQ address value:irq[0x%x] = 0x%x\n", 265 - pmic->irq_addr + i, pending); 266 - hi6421_spmi_pmic_write(pmic, pmic->irq_addr + i, 219 + SOC_PMIC_IRQ0_ADDR + i, pending); 220 + hi6421_spmi_pmic_write(pmic, SOC_PMIC_IRQ0_ADDR + i, 267 221 HISI_MASK_STATE); 268 222 } 269 223 } ··· 239 273 pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); 240 274 if (!pmic) 241 275 return -ENOMEM; 242 - 243 - ret = get_pmic_device_tree_data(np, pmic); 244 - if (ret) { 245 - dev_err(dev, "Error reading hisi pmic dts\n"); 246 - return ret; 247 - } 248 276 249 277 spin_lock_init(&pmic->lock); 250 278 ··· 261 301 262 302 hi6421_spmi_pmic_irq_prc(pmic); 263 303 264 - pmic->irqs = devm_kzalloc(dev, pmic->irqnum * sizeof(int), GFP_KERNEL); 304 + pmic->irqs = devm_kzalloc(dev, HISI_IRQ_NUM * sizeof(int), GFP_KERNEL); 265 305 if (!pmic->irqs) 266 306 goto irq_malloc; 267 307 268 - pmic->domain = irq_domain_add_simple(np, pmic->irqnum, 0, 308 + pmic->domain = irq_domain_add_simple(np, HISI_IRQ_NUM, 0, 269 309 &hi6421_spmi_domain_ops, pmic); 270 310 if (!pmic->domain) { 271 311 dev_err(dev, "failed irq domain add simple!\n"); ··· 273 313 goto irq_malloc; 274 314 } 275 315 276 - for (i = 0; i < pmic->irqnum; i++) { 316 + for (i = 0; i < HISI_IRQ_NUM; i++) { 277 317 virq = irq_create_mapping(pmic->domain, i); 278 318 if (!virq) { 279 319 dev_err(dev, "Failed mapping hwirq\n");
-15
include/linux/mfd/hi6421-spmi-pmic.h
··· 17 17 #define HISI_ECO_MODE_ENABLE (1) 18 18 #define HISI_ECO_MODE_DISABLE (0) 19 19 20 - struct hi6421_spmi_irq_mask_info { 21 - int start_addr; 22 - int array; 23 - }; 24 - 25 - struct hi6421_spmi_irq_info { 26 - int start_addr; 27 - int array; 28 - }; 29 - 30 20 struct hi6421_spmi_pmic { 31 21 struct resource *res; 32 22 struct device *dev; ··· 26 36 int irq; 27 37 int gpio; 28 38 unsigned int *irqs; 29 - 30 - int irqnum; 31 - int irqarray; 32 - int irq_mask_addr; 33 - int irq_addr; 34 39 }; 35 40 36 41 int hi6421_spmi_pmic_read(struct hi6421_spmi_pmic *pmic, int reg);