Lines Matching +full:cmd +full:- +full:db

1 // SPDX-License-Identifier: GPL-2.0-only
3 * RackMac vu-meter driver
8 * Support the CPU-meter LEDs of the Xserve G5
11 * interface for fun. Also, the CPU-meter could be made nicer by being
13 * time. Patches welcome :-)
24 #include <linux/dma-mapping.h>
43 struct dbdma_cmd cmd[4] ____cacheline_aligned; member
86 retval = kcpustat->cpustat[CPUTIME_IDLE] + in get_cpu_idle_time()
87 kcpustat->cpustat[CPUTIME_IOWAIT]; in get_cpu_idle_time()
97 struct macio_chip *macio = rm->mdev->bus->chip; in rackmeter_setup_i2s()
106 pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, rm->i2s, 0, 1); in rackmeter_setup_i2s()
110 * handle that. snd-aoa needs that too in rackmeter_setup_i2s()
121 out_le32(rm->i2s_regs + 0x10, 0x01fa0000); in rackmeter_setup_i2s()
122 (void)in_le32(rm->i2s_regs + 0x10); in rackmeter_setup_i2s()
138 rm->ubuf[i] = (i & 1) * 255; in rackmeter_set_default_pattern()
140 rm->ubuf[i] = ((~i) & 1) * 255; in rackmeter_set_default_pattern()
146 struct rackmeter_dma *rdma = rm->dma_buf_v; in rackmeter_do_pause()
150 rm->paused = pause; in rackmeter_do_pause()
152 DBDMA_DO_STOP(rm->dma_regs); in rackmeter_do_pause()
155 memset(rdma->buf1, 0, sizeof(rdma->buf1)); in rackmeter_do_pause()
156 memset(rdma->buf2, 0, sizeof(rdma->buf2)); in rackmeter_do_pause()
158 rm->dma_buf_v->mark = 0; in rackmeter_do_pause()
161 out_le32(&rm->dma_regs->cmdptr_hi, 0); in rackmeter_do_pause()
162 out_le32(&rm->dma_regs->cmdptr, rm->dma_buf_p); in rackmeter_do_pause()
163 out_le32(&rm->dma_regs->control, (RUN << 16) | RUN); in rackmeter_do_pause()
168 struct rackmeter_dma *db = rm->dma_buf_v; in rackmeter_setup_dbdma() local
169 struct dbdma_cmd *cmd = db->cmd; in rackmeter_setup_dbdma() local
172 DBDMA_DO_RESET(rm->dma_regs); in rackmeter_setup_dbdma()
182 memset(cmd, 0, 4 * sizeof(struct dbdma_cmd)); in rackmeter_setup_dbdma()
183 cmd->req_count = cpu_to_le16(4); in rackmeter_setup_dbdma()
184 cmd->command = cpu_to_le16(STORE_WORD | INTR_ALWAYS | KEY_SYSTEM); in rackmeter_setup_dbdma()
185 cmd->phy_addr = cpu_to_le32(rm->dma_buf_p + in rackmeter_setup_dbdma()
187 cmd->cmd_dep = cpu_to_le32(0x02000000); in rackmeter_setup_dbdma()
188 cmd++; in rackmeter_setup_dbdma()
190 cmd->req_count = cpu_to_le16(SAMPLE_COUNT * 4); in rackmeter_setup_dbdma()
191 cmd->command = cpu_to_le16(OUTPUT_MORE); in rackmeter_setup_dbdma()
192 cmd->phy_addr = cpu_to_le32(rm->dma_buf_p + in rackmeter_setup_dbdma()
194 cmd++; in rackmeter_setup_dbdma()
196 cmd->req_count = cpu_to_le16(4); in rackmeter_setup_dbdma()
197 cmd->command = cpu_to_le16(STORE_WORD | INTR_ALWAYS | KEY_SYSTEM); in rackmeter_setup_dbdma()
198 cmd->phy_addr = cpu_to_le32(rm->dma_buf_p + in rackmeter_setup_dbdma()
200 cmd->cmd_dep = cpu_to_le32(0x01000000); in rackmeter_setup_dbdma()
201 cmd++; in rackmeter_setup_dbdma()
203 cmd->req_count = cpu_to_le16(SAMPLE_COUNT * 4); in rackmeter_setup_dbdma()
204 cmd->command = cpu_to_le16(OUTPUT_MORE | BR_ALWAYS); in rackmeter_setup_dbdma()
205 cmd->phy_addr = cpu_to_le32(rm->dma_buf_p + in rackmeter_setup_dbdma()
207 cmd->cmd_dep = cpu_to_le32(rm->dma_buf_p); in rackmeter_setup_dbdma()
216 struct rackmeter *rm = rcpu->rm; in rackmeter_do_timer()
223 total_nsecs = cur_nsecs - rcpu->prev_wall; in rackmeter_do_timer()
224 rcpu->prev_wall = cur_nsecs; in rackmeter_do_timer()
227 idle_nsecs = total_idle_nsecs - rcpu->prev_idle; in rackmeter_do_timer()
229 rcpu->prev_idle = total_idle_nsecs; in rackmeter_do_timer()
234 load = div64_u64(9 * (total_nsecs - idle_nsecs), total_nsecs); in rackmeter_do_timer()
240 rm->ubuf[i + offset] = ub; in rackmeter_do_timer()
243 rcpu->zero = (cumm == 0); in rackmeter_do_timer()
246 pause = (rm->cpu[0].zero && rm->cpu[1].zero); in rackmeter_do_timer()
247 if (pause != rm->paused) { in rackmeter_do_timer()
248 mutex_lock(&rm->sem); in rackmeter_do_timer()
249 pause = (rm->cpu[0].zero && rm->cpu[1].zero); in rackmeter_do_timer()
251 mutex_unlock(&rm->sem); in rackmeter_do_timer()
253 schedule_delayed_work_on(cpu, &rcpu->sniffer, in rackmeter_do_timer()
267 rm->cpu[0].rm = rm; in rackmeter_init_cpu_sniffer()
268 INIT_DELAYED_WORK(&rm->cpu[0].sniffer, rackmeter_do_timer); in rackmeter_init_cpu_sniffer()
269 rm->cpu[1].rm = rm; in rackmeter_init_cpu_sniffer()
270 INIT_DELAYED_WORK(&rm->cpu[1].sniffer, rackmeter_do_timer); in rackmeter_init_cpu_sniffer()
277 rcpu = &rm->cpu[cpu]; in rackmeter_init_cpu_sniffer()
278 rcpu->prev_idle = get_cpu_idle_time(cpu); in rackmeter_init_cpu_sniffer()
279 rcpu->prev_wall = jiffies64_to_nsecs(get_jiffies_64()); in rackmeter_init_cpu_sniffer()
280 schedule_delayed_work_on(cpu, &rm->cpu[cpu].sniffer, in rackmeter_init_cpu_sniffer()
287 cancel_delayed_work_sync(&rm->cpu[0].sniffer); in rackmeter_stop_cpu_sniffer()
288 cancel_delayed_work_sync(&rm->cpu[1].sniffer); in rackmeter_stop_cpu_sniffer()
318 sample |= ((rm->ubuf[led] >= 0x80) << 15); in rackmeter_calc_sample()
326 struct rackmeter_dma *db = rm->dma_buf_v; in rackmeter_irq() local
334 (void)in_le32(&rm->dma_regs->status); in rackmeter_irq()
340 mark = db->mark; in rackmeter_irq()
345 if (++rm->stale_irq > 3) { in rackmeter_irq()
348 DBDMA_DO_RESET(rm->dma_regs); in rackmeter_irq()
354 buf = mark == 1 ? db->buf1 : db->buf2; in rackmeter_irq()
372 int rc = -ENODEV; in rackmeter_probe()
376 /* Get i2s-a node */ in rackmeter_probe()
377 for_each_child_of_node(mdev->ofdev.dev.of_node, i2s) in rackmeter_probe()
378 if (of_node_name_eq(i2s, "i2s-a")) in rackmeter_probe()
382 pr_debug(" i2s-a child not found\n"); in rackmeter_probe()
402 rc = -ENOMEM; in rackmeter_probe()
405 rm->mdev = mdev; in rackmeter_probe()
406 rm->i2s = i2s; in rackmeter_probe()
407 mutex_init(&rm->sem); in rackmeter_probe()
408 dev_set_drvdata(&mdev->ofdev.dev, rm); in rackmeter_probe()
410 #if 0 /* Use that when i2s-a is finally an mdev per-se */ in rackmeter_probe()
415 mdev->ofdev.dev.of_node); in rackmeter_probe()
416 rc = -ENXIO; in rackmeter_probe()
422 mdev->ofdev.dev.of_node); in rackmeter_probe()
423 rc = -EBUSY; in rackmeter_probe()
426 rm->irq = macio_irq(mdev, 1); in rackmeter_probe()
428 rm->irq = irq_of_parse_and_map(i2s, 1); in rackmeter_probe()
429 if (!rm->irq || in rackmeter_probe()
434 mdev->ofdev.dev.of_node); in rackmeter_probe()
435 rc = -ENXIO; in rackmeter_probe()
442 pr_debug(" irq %d\n", rm->irq); in rackmeter_probe()
444 rm->ubuf = (u8 *)__get_free_page(GFP_KERNEL); in rackmeter_probe()
445 if (rm->ubuf == NULL) { in rackmeter_probe()
448 rc = -ENOMEM; in rackmeter_probe()
452 rm->dma_buf_v = dma_alloc_coherent(&macio_get_pci_dev(mdev)->dev, in rackmeter_probe()
454 &rm->dma_buf_p, GFP_KERNEL); in rackmeter_probe()
455 if (rm->dma_buf_v == NULL) { in rackmeter_probe()
458 rc = -ENOMEM; in rackmeter_probe()
462 rm->i2s_regs = ioremap(macio_resource_start(mdev, 0), 0x1000); in rackmeter_probe()
464 rm->i2s_regs = ioremap(ri2s.start, 0x1000); in rackmeter_probe()
466 if (rm->i2s_regs == NULL) { in rackmeter_probe()
469 rc = -ENXIO; in rackmeter_probe()
473 rm->dma_regs = ioremap(macio_resource_start(mdev, 1), 0x100); in rackmeter_probe()
475 rm->dma_regs = ioremap(rdma.start, 0x100); in rackmeter_probe()
477 if (rm->dma_regs == NULL) { in rackmeter_probe()
480 rc = -ENXIO; in rackmeter_probe()
488 rc = -ENXIO; in rackmeter_probe()
492 rc = request_irq(rm->irq, rackmeter_irq, 0, "rackmeter", rm); in rackmeter_probe()
502 DBDMA_DO_RESET(rm->dma_regs); in rackmeter_probe()
504 iounmap(rm->dma_regs); in rackmeter_probe()
506 iounmap(rm->i2s_regs); in rackmeter_probe()
508 dma_free_coherent(&macio_get_pci_dev(mdev)->dev, in rackmeter_probe()
510 rm->dma_buf_v, rm->dma_buf_p); in rackmeter_probe()
512 free_page((unsigned long)rm->ubuf); in rackmeter_probe()
522 dev_set_drvdata(&mdev->ofdev.dev, NULL); in rackmeter_probe()
528 struct rackmeter *rm = dev_get_drvdata(&mdev->ofdev.dev); in rackmeter_remove()
534 dev_set_drvdata(&mdev->ofdev.dev, NULL); in rackmeter_remove()
537 DBDMA_DO_RESET(rm->dma_regs); in rackmeter_remove()
540 free_irq(rm->irq, rm); in rackmeter_remove()
543 iounmap(rm->dma_regs); in rackmeter_remove()
544 iounmap(rm->i2s_regs); in rackmeter_remove()
547 dma_free_coherent(&macio_get_pci_dev(mdev)->dev, in rackmeter_remove()
549 rm->dma_buf_v, rm->dma_buf_p); in rackmeter_remove()
552 free_page((unsigned long)rm->ubuf); in rackmeter_remove()
567 struct rackmeter *rm = dev_get_drvdata(&mdev->ofdev.dev); in rackmeter_shutdown()
570 return -ENODEV; in rackmeter_shutdown()
576 DBDMA_DO_RESET(rm->dma_regs); in rackmeter_shutdown()
619 MODULE_DESCRIPTION("RackMeter: Support vu-meter on XServe front panel");