1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
|
/* $OpenBSD: qcspmi.c,v 1.3 2022/12/21 23:26:54 patrick Exp $ */
/*
* Copyright (c) 2022 Patrick Wildt <patrick@blueri.se>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <machine/bus.h>
#include <machine/fdt.h>
#include <dev/fdt/spmivar.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_clock.h>
#include <dev/ofw/ofw_power.h>
#include <dev/ofw/fdt.h>
/* Core registers. */
#define SPMI_VERSION 0x00
#define SPMI_VERSION_V2_MIN 0x20010000
#define SPMI_VERSION_V3_MIN 0x30000000
#define SPMI_VERSION_V5_MIN 0x50000000
#define SPMI_ARB_APID_MAP(x) (0x900 + (x) * 0x4)
#define SPMI_ARB_APID_MAP_PPID_MASK 0xfff
#define SPMI_ARB_APID_MAP_PPID_SHIFT 8
#define SPMI_ARB_APID_MAP_IRQ_OWNER (1 << 14)
/* Channel registers. */
#define SPMI_CHAN_OFF(x) (0x10000 * (x))
#define SPMI_OBSV_OFF(x, y) (0x10000 * (x) + 0x80 * (y))
#define SPMI_COMMAND 0x00
#define SPMI_COMMAND_OP_EXT_WRITEL (0 << 27)
#define SPMI_COMMAND_OP_EXT_READL (1 << 27)
#define SPMI_COMMAND_OP_EXT_WRITE (2 << 27)
#define SPMI_COMMAND_OP_RESET (3 << 27)
#define SPMI_COMMAND_OP_SLEEP (4 << 27)
#define SPMI_COMMAND_OP_SHUTDOWN (5 << 27)
#define SPMI_COMMAND_OP_WAKEUP (6 << 27)
#define SPMI_COMMAND_OP_AUTHENTICATE (7 << 27)
#define SPMI_COMMAND_OP_MSTR_READ (8 << 27)
#define SPMI_COMMAND_OP_MSTR_WRITE (9 << 27)
#define SPMI_COMMAND_OP_EXT_READ (13 << 27)
#define SPMI_COMMAND_OP_WRITE (14 << 27)
#define SPMI_COMMAND_OP_READ (15 << 27)
#define SPMI_COMMAND_OP_ZERO_WRITE (16 << 27)
#define SPMI_COMMAND_ADDR(x) (((x) & 0xff) << 4)
#define SPMI_COMMAND_LEN(x) (((x) & 0x7) << 0)
#define SPMI_CONFIG 0x04
#define SPMI_STATUS 0x08
#define SPMI_STATUS_DONE (1 << 0)
#define SPMI_STATUS_FAILURE (1 << 1)
#define SPMI_STATUS_DENIED (1 << 2)
#define SPMI_STATUS_DROPPED (1 << 3)
#define SPMI_WDATA0 0x10
#define SPMI_WDATA1 0x14
#define SPMI_RDATA0 0x18
#define SPMI_RDATA1 0x1c
#define SPMI_ACC_ENABLE 0x100
#define SPMI_ACC_ENABLE_BIT (1 << 0)
#define SPMI_IRQ_STATUS 0x104
#define SPMI_IRQ_CLEAR 0x108
/* Intr registers */
#define SPMI_OWNER_ACC_STATUS(x, y) (0x10000 * (x) + 0x4 * (y))
/* Config registers */
#define SPMI_OWNERSHIP_TABLE(x) (0x700 + (x) * 0x4)
#define SPMI_OWNERSHIP_TABLE_OWNER(x) ((x) & 0x7)
/* Misc */
#define SPMI_MAX_PERIPH 512
#define SPMI_MAX_PPID 4096
#define SPMI_PPID_TO_APID_VALID (1U << 15)
#define SPMI_PPID_TO_APID_MASK (0x7fff)
/* Intr commands */
#define INTR_RT_STS 0x10
#define INTR_SET_TYPE 0x11
#define INTR_POLARITY_HIGH 0x12
#define INTR_POLARITY_LOW 0x13
#define INTR_LATCHED_CLR 0x14
#define INTR_EN_SET 0x15
#define INTR_EN_CLR 0x16
#define INTR_LATCHED_STS 0x18
#define HREAD4(sc, obj, reg) \
(bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh[obj], (reg)))
#define HWRITE4(sc, obj, reg, val) \
bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh[obj], (reg), (val))
#define HSET4(sc, obj, reg, bits) \
HWRITE4((sc), (obj), (reg), HREAD4((sc), (reg)) | (bits))
#define HCLR4(sc, obj, reg, bits) \
HWRITE4((sc), (obj), (reg), HREAD4((sc), (reg)) & ~(bits))
#define QCSPMI_REG_CORE 0
#define QCSPMI_REG_CHNLS 1
#define QCSPMI_REG_OBSRVR 2
#define QCSPMI_REG_INTR 3
#define QCSPMI_REG_CNFG 4
#define QCSPMI_REG_MAX 5
char *qcspmi_regs[] = { "core", "chnls", "obsrvr", "intr", "cnfg" };
struct qcspmi_apid {
uint16_t ppid;
uint8_t write_ee;
uint8_t irq_ee;
};
struct qcspmi_intrhand {
TAILQ_ENTRY(qcspmi_intrhand) ih_q;
int (*ih_func)(void *);
void *ih_arg;
void *ih_sc;
uint16_t ih_per;
uint8_t ih_pin;
uint8_t ih_sid;
uint32_t ih_apid;
};
struct qcspmi_softc {
struct device sc_dev;
int sc_node;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh[QCSPMI_REG_MAX];
void *sc_ih;
int sc_ee;
struct qcspmi_apid sc_apid[SPMI_MAX_PERIPH];
uint16_t sc_ppid_to_apid[SPMI_MAX_PPID];
struct spmi_controller sc_tag;
struct interrupt_controller sc_ic;
TAILQ_HEAD(,qcspmi_intrhand) sc_intrq;
};
int qcspmi_match(struct device *, void *, void *);
void qcspmi_attach(struct device *, struct device *, void *);
int qcspmi_print(void *, const char *);
int qcspmi_cmd_read(void *, uint8_t, uint8_t, uint16_t, void *, size_t);
int qcspmi_cmd_write(void *, uint8_t, uint8_t, uint16_t,
const void *, size_t);
void *qcspmi_intr_establish(void *, int *, int, struct cpu_info *,
int (*)(void *), void *, char *);
void qcspmi_intr_disestablish(void *);
void qcspmi_intr_enable(void *);
void qcspmi_intr_disable(void *);
void qcspmi_intr_barrier(void *);
int qcspmi_pin_intr(struct qcspmi_softc *, int);
int qcspmi_intr(void *);
const struct cfattach qcspmi_ca = {
sizeof(struct qcspmi_softc), qcspmi_match, qcspmi_attach
};
struct cfdriver qcspmi_cd = {
NULL, "qcspmi", DV_DULL
};
int
qcspmi_match(struct device *parent, void *match, void *aux)
{
struct fdt_attach_args *faa = aux;
return OF_is_compatible(faa->fa_node, "qcom,spmi-pmic-arb");
}
void
qcspmi_attach(struct device *parent, struct device *self, void *aux)
{
struct fdt_attach_args *faa = aux;
struct qcspmi_softc *sc = (struct qcspmi_softc *)self;
struct qcspmi_apid *apid, *last_apid;
uint32_t val, ppid, irq_own;
struct spmi_attach_args sa;
char name[32];
uint32_t reg[2];
int i, j, node;
sc->sc_node = faa->fa_node;
sc->sc_iot = faa->fa_iot;
for (i = 0; i < nitems(qcspmi_regs); i++) {
j = OF_getindex(faa->fa_node, qcspmi_regs[i], "reg-names");
if (j < 0 || j >= faa->fa_nreg) {
printf(": no %s registers\n", qcspmi_regs[i]);
return;
}
if (bus_space_map(sc->sc_iot, faa->fa_reg[j].addr,
faa->fa_reg[j].size, 0, &sc->sc_ioh[i])) {
printf(": can't map %s registers\n", qcspmi_regs[i]);
return;
}
}
/* Support only version 5 for now */
val = HREAD4(sc, QCSPMI_REG_CORE, SPMI_VERSION);
if (val < SPMI_VERSION_V5_MIN) {
printf(": unsupported version 0x%08x\n", val);
return;
}
sc->sc_ee = OF_getpropint(sc->sc_node, "qcom,ee", 0);
if (sc->sc_ee > 5) {
printf(": unsupported EE\n");
return;
}
TAILQ_INIT(&sc->sc_intrq);
sc->sc_ih = fdt_intr_establish(sc->sc_node, IPL_BIO, qcspmi_intr,
sc, sc->sc_dev.dv_xname);
if (sc->sc_ih == NULL) {
printf(": can't establish interrupt\n");
return;
}
printf("\n");
for (i = 0; i < SPMI_MAX_PERIPH; i++) {
val = HREAD4(sc, QCSPMI_REG_CORE, SPMI_ARB_APID_MAP(i));
if (!val)
continue;
ppid = (val >> SPMI_ARB_APID_MAP_PPID_SHIFT) &
SPMI_ARB_APID_MAP_PPID_MASK;
irq_own = val & SPMI_ARB_APID_MAP_IRQ_OWNER;
val = HREAD4(sc, QCSPMI_REG_CNFG, SPMI_OWNERSHIP_TABLE(i));
apid = &sc->sc_apid[i];
apid->write_ee = SPMI_OWNERSHIP_TABLE_OWNER(val);
apid->irq_ee = 0xff;
if (irq_own)
apid->irq_ee = apid->write_ee;
last_apid = &sc->sc_apid[sc->sc_ppid_to_apid[ppid] &
SPMI_PPID_TO_APID_MASK];
if (!(sc->sc_ppid_to_apid[ppid] & SPMI_PPID_TO_APID_VALID) ||
apid->write_ee == sc->sc_ee) {
sc->sc_ppid_to_apid[ppid] = SPMI_PPID_TO_APID_VALID | i;
} else if ((sc->sc_ppid_to_apid[ppid] &
SPMI_PPID_TO_APID_VALID) && irq_own &&
last_apid->write_ee == sc->sc_ee) {
last_apid->irq_ee = apid->irq_ee;
}
}
sc->sc_tag.sc_cookie = sc;
sc->sc_tag.sc_cmd_read = qcspmi_cmd_read;
sc->sc_tag.sc_cmd_write = qcspmi_cmd_write;
sc->sc_ic.ic_node = faa->fa_node;
sc->sc_ic.ic_cookie = sc;
sc->sc_ic.ic_establish = qcspmi_intr_establish;
sc->sc_ic.ic_disestablish = qcspmi_intr_disestablish;
sc->sc_ic.ic_enable = qcspmi_intr_enable;
sc->sc_ic.ic_disable = qcspmi_intr_disable;
sc->sc_ic.ic_barrier = qcspmi_intr_barrier;
fdt_intr_register(&sc->sc_ic);
for (node = OF_child(faa->fa_node); node; node = OF_peer(node)) {
if (OF_getpropintarray(node, "reg", reg,
sizeof(reg)) != sizeof(reg))
continue;
memset(name, 0, sizeof(name));
if (OF_getprop(node, "compatible", name, sizeof(name)) == -1)
continue;
if (name[0] == '\0')
continue;
memset(&sa, 0, sizeof(sa));
sa.sa_tag = &sc->sc_tag;
sa.sa_sid = reg[0];
sa.sa_name = name;
sa.sa_node = node;
config_found(self, &sa, qcspmi_print);
}
}
int
qcspmi_print(void *aux, const char *pnp)
{
struct spmi_attach_args *sa = aux;
if (pnp != NULL)
printf("\"%s\" at %s", sa->sa_name, pnp);
printf(" sid 0x%x", sa->sa_sid);
return UNCONF;
}
int
qcspmi_cmd_read(void *cookie, uint8_t sid, uint8_t cmd, uint16_t addr,
void *buf, size_t len)
{
struct qcspmi_softc *sc = cookie;
uint8_t *cbuf = buf;
uint32_t reg;
uint16_t apid, ppid;
int bc = len - 1;
int i;
if (len == 0 || len > 8)
return EINVAL;
/* TODO: support more types */
if (cmd != SPMI_CMD_EXT_READL)
return EINVAL;
ppid = (sid << 8) | (addr >> 8);
if (!(sc->sc_ppid_to_apid[ppid] & SPMI_PPID_TO_APID_VALID))
return ENXIO;
apid = sc->sc_ppid_to_apid[ppid] & SPMI_PPID_TO_APID_MASK;
HWRITE4(sc, QCSPMI_REG_OBSRVR,
SPMI_OBSV_OFF(sc->sc_ee, apid) + SPMI_COMMAND,
SPMI_COMMAND_OP_EXT_READL | SPMI_COMMAND_ADDR(addr) |
SPMI_COMMAND_LEN(bc));
for (i = 1000; i > 0; i--) {
reg = HREAD4(sc, QCSPMI_REG_OBSRVR,
SPMI_OBSV_OFF(sc->sc_ee, apid) + SPMI_STATUS);
if (reg & SPMI_STATUS_DONE)
break;
}
if (i == 0)
return ETIMEDOUT;
if (reg & SPMI_STATUS_FAILURE ||
reg & SPMI_STATUS_DENIED ||
reg & SPMI_STATUS_DROPPED)
return EIO;
if (len > 0) {
reg = HREAD4(sc, QCSPMI_REG_OBSRVR,
SPMI_OBSV_OFF(sc->sc_ee, apid) + SPMI_RDATA0);
memcpy(cbuf, ®, MIN(len, 4));
cbuf += MIN(len, 4);
len -= MIN(len, 4);
}
if (len > 0) {
reg = HREAD4(sc, QCSPMI_REG_OBSRVR,
SPMI_OBSV_OFF(sc->sc_ee, apid) + SPMI_RDATA1);
memcpy(cbuf, ®, MIN(len, 4));
cbuf += MIN(len, 4);
len -= MIN(len, 4);
}
return 0;
}
int
qcspmi_cmd_write(void *cookie, uint8_t sid, uint8_t cmd, uint16_t addr,
const void *buf, size_t len)
{
struct qcspmi_softc *sc = cookie;
const uint8_t *cbuf = buf;
uint32_t reg;
uint16_t apid, ppid;
int bc = len - 1;
int i;
if (len == 0 || len > 8)
return EINVAL;
/* TODO: support more types */
if (cmd != SPMI_CMD_EXT_WRITEL)
return EINVAL;
ppid = (sid << 8) | (addr >> 8);
if (!(sc->sc_ppid_to_apid[ppid] & SPMI_PPID_TO_APID_VALID))
return ENXIO;
apid = sc->sc_ppid_to_apid[ppid] & SPMI_PPID_TO_APID_MASK;
if (sc->sc_apid[apid].write_ee != sc->sc_ee)
return EPERM;
if (len > 0) {
memcpy(®, cbuf, MIN(len, 4));
HWRITE4(sc, QCSPMI_REG_CHNLS, SPMI_CHAN_OFF(apid) +
SPMI_WDATA0, reg);
cbuf += MIN(len, 4);
len -= MIN(len, 4);
}
if (len > 0) {
memcpy(®, cbuf, MIN(len, 4));
HWRITE4(sc, QCSPMI_REG_CHNLS, SPMI_CHAN_OFF(apid) +
SPMI_WDATA1, reg);
cbuf += MIN(len, 4);
len -= MIN(len, 4);
}
HWRITE4(sc, QCSPMI_REG_CHNLS, SPMI_CHAN_OFF(apid) + SPMI_COMMAND,
SPMI_COMMAND_OP_EXT_WRITEL | SPMI_COMMAND_ADDR(addr) |
SPMI_COMMAND_LEN(bc));
for (i = 1000; i > 0; i--) {
reg = HREAD4(sc, QCSPMI_REG_CHNLS, SPMI_CHAN_OFF(apid) +
SPMI_STATUS);
if (reg & SPMI_STATUS_DONE)
break;
}
if (i == 0)
return ETIMEDOUT;
if (reg & SPMI_STATUS_FAILURE ||
reg & SPMI_STATUS_DENIED ||
reg & SPMI_STATUS_DROPPED)
return EIO;
return 0;
}
void *
qcspmi_intr_establish(void *cookie, int *cells, int ipl,
struct cpu_info *ci, int (*func)(void *), void *arg, char *name)
{
struct qcspmi_softc *sc = cookie;
struct qcspmi_intrhand *ih;
uint16_t ppid;
uint8_t reg[3];
int error;
ppid = cells[0] << 8 | cells[1];
if (!(sc->sc_ppid_to_apid[ppid] & SPMI_PPID_TO_APID_VALID))
return NULL;
ih = malloc(sizeof(*ih), M_DEVBUF, M_WAITOK | M_ZERO);
ih->ih_func = func;
ih->ih_arg = arg;
ih->ih_sc = sc;
ih->ih_sid = cells[0];
ih->ih_per = cells[1];
ih->ih_pin = cells[2];
ih->ih_apid = sc->sc_ppid_to_apid[ppid] & SPMI_PPID_TO_APID_MASK;
TAILQ_INSERT_TAIL(&sc->sc_intrq, ih, ih_q);
error = spmi_cmd_read(&sc->sc_tag, ih->ih_sid, SPMI_CMD_EXT_READL,
(ih->ih_per << 8) | INTR_SET_TYPE, ®, sizeof(reg));
if (error)
printf("%s: cannot read irq setting\n", sc->sc_dev.dv_xname);
reg[0] &= ~(1U << ih->ih_pin);
reg[1] &= ~(1U << ih->ih_pin);
reg[2] &= ~(1U << ih->ih_pin);
switch (cells[3]) {
case 1:
reg[0] |= (1U << ih->ih_pin); /* edge */
reg[1] |= (1U << ih->ih_pin); /* rising */
break;
case 2:
reg[0] |= (1U << ih->ih_pin); /* edge */
reg[2] |= (1U << ih->ih_pin); /* falling */
break;
case 3:
reg[0] |= (1U << ih->ih_pin); /* edge */
reg[1] |= (1U << ih->ih_pin); /* rising */
reg[2] |= (1U << ih->ih_pin); /* falling */
break;
case 4:
reg[1] |= (1U << ih->ih_pin); /* high */
break;
case 8:
reg[2] |= (1U << ih->ih_pin); /* low */
break;
default:
printf("%s: unsupported interrupt mode/polarity\n",
sc->sc_dev.dv_xname);
break;
}
error = spmi_cmd_write(&sc->sc_tag, ih->ih_sid, SPMI_CMD_EXT_WRITEL,
(ih->ih_per << 8) | INTR_SET_TYPE, ®, sizeof(reg));
if (error)
printf("%s: cannot write irq setting\n", sc->sc_dev.dv_xname);
HWRITE4(sc, QCSPMI_REG_CHNLS, SPMI_CHAN_OFF(ih->ih_apid) +
SPMI_IRQ_CLEAR, (1U << ih->ih_pin));
qcspmi_intr_enable(ih);
if (ipl & IPL_WAKEUP)
intr_set_wakeup(sc->sc_ih);
return ih;
}
void
qcspmi_intr_disestablish(void *cookie)
{
struct qcspmi_intrhand *ih = cookie;
struct qcspmi_softc *sc = ih->ih_sc;
qcspmi_intr_disable(cookie);
TAILQ_REMOVE(&sc->sc_intrq, ih, ih_q);
free(ih, M_DEVBUF, sizeof(*ih));
}
void
qcspmi_intr_enable(void *cookie)
{
struct qcspmi_intrhand *ih = cookie;
struct qcspmi_softc *sc = ih->ih_sc;
uint8_t reg[2];
int error;
HWRITE4(sc, QCSPMI_REG_CHNLS, SPMI_CHAN_OFF(ih->ih_apid) +
SPMI_ACC_ENABLE, SPMI_ACC_ENABLE_BIT);
error = spmi_cmd_read(&sc->sc_tag, ih->ih_sid, SPMI_CMD_EXT_READL,
(ih->ih_per << 8) | INTR_EN_SET, ®, 1);
if (error)
printf("%s: cannot read irq setting\n", sc->sc_dev.dv_xname);
if (!(reg[0] & (1U << ih->ih_pin))) {
reg[0] = (1U << ih->ih_pin);
reg[1] = (1U << ih->ih_pin);
error = spmi_cmd_write(&sc->sc_tag, ih->ih_sid,
SPMI_CMD_EXT_WRITEL, (ih->ih_per << 8) | INTR_LATCHED_CLR,
®, 2);
if (error)
printf("%s: cannot enable irq\n", sc->sc_dev.dv_xname);
}
}
void
qcspmi_intr_disable(void *cookie)
{
struct qcspmi_intrhand *ih = cookie;
struct qcspmi_softc *sc = ih->ih_sc;
uint8_t reg = (1U << ih->ih_pin);
int error;
error = spmi_cmd_write(&sc->sc_tag, ih->ih_sid, SPMI_CMD_EXT_WRITEL,
(ih->ih_per << 8) | INTR_EN_CLR, ®, sizeof(reg));
if (error)
printf("%s: cannot disable irq\n", sc->sc_dev.dv_xname);
}
void
qcspmi_intr_barrier(void *cookie)
{
struct qcspmi_intrhand *ih = cookie;
struct qcspmi_softc *sc = ih->ih_sc;
intr_barrier(sc->sc_ih);
}
int
qcspmi_intr(void *arg)
{
struct qcspmi_softc *sc = arg;
struct qcspmi_intrhand *ih;
uint32_t status;
uint8_t reg;
int error;
int handled = 0;
TAILQ_FOREACH(ih, &sc->sc_intrq, ih_q) {
status = HREAD4(sc, QCSPMI_REG_INTR,
SPMI_OWNER_ACC_STATUS(sc->sc_ee, ih->ih_apid / 32));
if (!(status & (1U << (ih->ih_apid % 32))))
continue;
status = HREAD4(sc, QCSPMI_REG_CHNLS,
SPMI_CHAN_OFF(ih->ih_apid) + SPMI_ACC_ENABLE);
if (!(status & SPMI_ACC_ENABLE_BIT))
continue;
status = HREAD4(sc, QCSPMI_REG_CHNLS,
SPMI_CHAN_OFF(ih->ih_apid) + SPMI_IRQ_STATUS);
if (!(status & (1U << ih->ih_pin)))
continue;
ih->ih_func(ih->ih_arg);
handled = 1;
HWRITE4(sc, QCSPMI_REG_CHNLS, SPMI_CHAN_OFF(ih->ih_apid) +
SPMI_IRQ_CLEAR, (1U << ih->ih_pin));
reg = 1U << ih->ih_pin;
error = spmi_cmd_write(&sc->sc_tag, ih->ih_sid,
SPMI_CMD_EXT_WRITEL, (ih->ih_per << 8) | INTR_LATCHED_CLR,
®, sizeof(reg));
if (error)
printf("%s: cannot clear irq\n", sc->sc_dev.dv_xname);
}
return handled;
}
|