1305aebefSGustavo Pimentel // SPDX-License-Identifier: GPL-2.0 2305aebefSGustavo Pimentel /* 3305aebefSGustavo Pimentel * Copyright (c) 2018-2019 Synopsys, Inc. and/or its affiliates. 4305aebefSGustavo Pimentel * Synopsys DesignWare eDMA v0 core 5305aebefSGustavo Pimentel * 6305aebefSGustavo Pimentel * Author: Gustavo Pimentel <gustavo.pimentel@synopsys.com> 7305aebefSGustavo Pimentel */ 8305aebefSGustavo Pimentel 9305aebefSGustavo Pimentel #include <linux/debugfs.h> 10305aebefSGustavo Pimentel #include <linux/bitfield.h> 11305aebefSGustavo Pimentel 12305aebefSGustavo Pimentel #include "dw-edma-v0-debugfs.h" 13305aebefSGustavo Pimentel #include "dw-edma-v0-regs.h" 14305aebefSGustavo Pimentel #include "dw-edma-core.h" 15305aebefSGustavo Pimentel 16305aebefSGustavo Pimentel #define REGS_ADDR(name) \ 177ca9f025SSerge Semin ((void __iomem *)®s->name) 18*00498167SSerge Semin 19*00498167SSerge Semin #define REGS_CH_ADDR(name, _dir, _ch) \ 20*00498167SSerge Semin ({ \ 21*00498167SSerge Semin struct dw_edma_v0_ch_regs __iomem *__ch_regs; \ 22*00498167SSerge Semin \ 23*00498167SSerge Semin if ((dw)->chip->mf == EDMA_MF_EDMA_LEGACY) \ 24*00498167SSerge Semin __ch_regs = ®s->type.legacy.ch; \ 25*00498167SSerge Semin else if (_dir == EDMA_DIR_READ) \ 26*00498167SSerge Semin __ch_regs = ®s->type.unroll.ch[_ch].rd; \ 27*00498167SSerge Semin else \ 28*00498167SSerge Semin __ch_regs = ®s->type.unroll.ch[_ch].wr; \ 29*00498167SSerge Semin \ 30*00498167SSerge Semin (void __iomem *)&__ch_regs->name; \ 31*00498167SSerge Semin }) 32*00498167SSerge Semin 33305aebefSGustavo Pimentel #define REGISTER(name) \ 34305aebefSGustavo Pimentel { #name, REGS_ADDR(name) } 35305aebefSGustavo Pimentel 36*00498167SSerge Semin #define CTX_REGISTER(name, dir, ch) \ 37*00498167SSerge Semin { #name, REGS_CH_ADDR(name, dir, ch), dir, ch } 38*00498167SSerge Semin 39305aebefSGustavo Pimentel #define WR_REGISTER(name) \ 40305aebefSGustavo Pimentel { #name, REGS_ADDR(wr_##name) } 41305aebefSGustavo Pimentel #define RD_REGISTER(name) \ 42305aebefSGustavo Pimentel { #name, REGS_ADDR(rd_##name) } 43305aebefSGustavo Pimentel 44305aebefSGustavo Pimentel #define WR_REGISTER_LEGACY(name) \ 45305aebefSGustavo Pimentel { #name, REGS_ADDR(type.legacy.wr_##name) } 46305aebefSGustavo Pimentel #define RD_REGISTER_LEGACY(name) \ 47305aebefSGustavo Pimentel { #name, REGS_ADDR(type.legacy.rd_##name) } 48305aebefSGustavo Pimentel 49305aebefSGustavo Pimentel #define WR_REGISTER_UNROLL(name) \ 50305aebefSGustavo Pimentel { #name, REGS_ADDR(type.unroll.wr_##name) } 51305aebefSGustavo Pimentel #define RD_REGISTER_UNROLL(name) \ 52305aebefSGustavo Pimentel { #name, REGS_ADDR(type.unroll.rd_##name) } 53305aebefSGustavo Pimentel 54305aebefSGustavo Pimentel #define WRITE_STR "write" 55305aebefSGustavo Pimentel #define READ_STR "read" 56305aebefSGustavo Pimentel #define CHANNEL_STR "channel" 57305aebefSGustavo Pimentel #define REGISTERS_STR "registers" 58305aebefSGustavo Pimentel 59305aebefSGustavo Pimentel static struct dw_edma *dw; 60756c3ef9SArnd Bergmann static struct dw_edma_v0_regs __iomem *regs; 61305aebefSGustavo Pimentel 62345e3a95SSerge Semin struct dw_edma_debugfs_entry { 63f0414087SArnd Bergmann const char *name; 647ca9f025SSerge Semin void __iomem *reg; 65*00498167SSerge Semin enum dw_edma_dir dir; 66*00498167SSerge Semin u16 ch; 67305aebefSGustavo Pimentel }; 68305aebefSGustavo Pimentel 69305aebefSGustavo Pimentel static int dw_edma_debugfs_u32_get(void *data, u64 *val) 70305aebefSGustavo Pimentel { 71782536aaSSerge Semin struct dw_edma_debugfs_entry *entry = data; 72782536aaSSerge Semin void __iomem *reg = entry->reg; 737ca9f025SSerge Semin 7420318457SFrank Li if (dw->chip->mf == EDMA_MF_EDMA_LEGACY && 75756c3ef9SArnd Bergmann reg >= (void __iomem *)®s->type.legacy.ch) { 76305aebefSGustavo Pimentel unsigned long flags; 77*00498167SSerge Semin u32 viewport_sel; 78305aebefSGustavo Pimentel 79*00498167SSerge Semin viewport_sel = entry->dir == EDMA_DIR_READ ? BIT(31) : 0; 80*00498167SSerge Semin viewport_sel |= FIELD_PREP(EDMA_V0_VIEWPORT_MASK, entry->ch); 81305aebefSGustavo Pimentel 82305aebefSGustavo Pimentel raw_spin_lock_irqsave(&dw->lock, flags); 83305aebefSGustavo Pimentel 84305aebefSGustavo Pimentel writel(viewport_sel, ®s->type.legacy.viewport_sel); 85*00498167SSerge Semin *val = readl(reg); 86305aebefSGustavo Pimentel 87305aebefSGustavo Pimentel raw_spin_unlock_irqrestore(&dw->lock, flags); 88305aebefSGustavo Pimentel } else { 89756c3ef9SArnd Bergmann *val = readl(reg); 90305aebefSGustavo Pimentel } 91305aebefSGustavo Pimentel 92305aebefSGustavo Pimentel return 0; 93305aebefSGustavo Pimentel } 94305aebefSGustavo Pimentel DEFINE_DEBUGFS_ATTRIBUTE(fops_x32, dw_edma_debugfs_u32_get, NULL, "0x%08llx\n"); 95305aebefSGustavo Pimentel 96782536aaSSerge Semin static void dw_edma_debugfs_create_x32(const struct dw_edma_debugfs_entry ini[], 9795c55b78SSerge Semin int nr_entries, struct dentry *dent) 98305aebefSGustavo Pimentel { 99782536aaSSerge Semin struct dw_edma_debugfs_entry *entries; 100305aebefSGustavo Pimentel int i; 101305aebefSGustavo Pimentel 102782536aaSSerge Semin entries = devm_kcalloc(dw->chip->dev, nr_entries, sizeof(*entries), 103782536aaSSerge Semin GFP_KERNEL); 104782536aaSSerge Semin if (!entries) 105782536aaSSerge Semin return; 106782536aaSSerge Semin 107305aebefSGustavo Pimentel for (i = 0; i < nr_entries; i++) { 108782536aaSSerge Semin entries[i] = ini[i]; 109782536aaSSerge Semin 11095c55b78SSerge Semin debugfs_create_file_unsafe(entries[i].name, 0444, dent, 111782536aaSSerge Semin &entries[i], &fops_x32); 112305aebefSGustavo Pimentel } 113305aebefSGustavo Pimentel } 114305aebefSGustavo Pimentel 115*00498167SSerge Semin static void dw_edma_debugfs_regs_ch(enum dw_edma_dir dir, u16 ch, 11695c55b78SSerge Semin struct dentry *dent) 117305aebefSGustavo Pimentel { 118*00498167SSerge Semin struct dw_edma_debugfs_entry debugfs_regs[] = { 119*00498167SSerge Semin CTX_REGISTER(ch_control1, dir, ch), 120*00498167SSerge Semin CTX_REGISTER(ch_control2, dir, ch), 121*00498167SSerge Semin CTX_REGISTER(transfer_size, dir, ch), 122*00498167SSerge Semin CTX_REGISTER(sar.lsb, dir, ch), 123*00498167SSerge Semin CTX_REGISTER(sar.msb, dir, ch), 124*00498167SSerge Semin CTX_REGISTER(dar.lsb, dir, ch), 125*00498167SSerge Semin CTX_REGISTER(dar.msb, dir, ch), 126*00498167SSerge Semin CTX_REGISTER(llp.lsb, dir, ch), 127*00498167SSerge Semin CTX_REGISTER(llp.msb, dir, ch), 128305aebefSGustavo Pimentel }; 129345e3a95SSerge Semin int nr_entries; 130305aebefSGustavo Pimentel 131305aebefSGustavo Pimentel nr_entries = ARRAY_SIZE(debugfs_regs); 13295c55b78SSerge Semin dw_edma_debugfs_create_x32(debugfs_regs, nr_entries, dent); 133305aebefSGustavo Pimentel } 134305aebefSGustavo Pimentel 13595c55b78SSerge Semin static void dw_edma_debugfs_regs_wr(struct dentry *dent) 136305aebefSGustavo Pimentel { 137345e3a95SSerge Semin const struct dw_edma_debugfs_entry debugfs_regs[] = { 138305aebefSGustavo Pimentel /* eDMA global registers */ 139305aebefSGustavo Pimentel WR_REGISTER(engine_en), 140305aebefSGustavo Pimentel WR_REGISTER(doorbell), 14104e0a39fSGustavo Pimentel WR_REGISTER(ch_arb_weight.lsb), 14204e0a39fSGustavo Pimentel WR_REGISTER(ch_arb_weight.msb), 143305aebefSGustavo Pimentel /* eDMA interrupts registers */ 144305aebefSGustavo Pimentel WR_REGISTER(int_status), 145305aebefSGustavo Pimentel WR_REGISTER(int_mask), 146305aebefSGustavo Pimentel WR_REGISTER(int_clear), 147305aebefSGustavo Pimentel WR_REGISTER(err_status), 14804e0a39fSGustavo Pimentel WR_REGISTER(done_imwr.lsb), 14904e0a39fSGustavo Pimentel WR_REGISTER(done_imwr.msb), 15004e0a39fSGustavo Pimentel WR_REGISTER(abort_imwr.lsb), 15104e0a39fSGustavo Pimentel WR_REGISTER(abort_imwr.msb), 152305aebefSGustavo Pimentel WR_REGISTER(ch01_imwr_data), 153305aebefSGustavo Pimentel WR_REGISTER(ch23_imwr_data), 154305aebefSGustavo Pimentel WR_REGISTER(ch45_imwr_data), 155305aebefSGustavo Pimentel WR_REGISTER(ch67_imwr_data), 156305aebefSGustavo Pimentel WR_REGISTER(linked_list_err_en), 157305aebefSGustavo Pimentel }; 158345e3a95SSerge Semin const struct dw_edma_debugfs_entry debugfs_unroll_regs[] = { 159305aebefSGustavo Pimentel /* eDMA channel context grouping */ 160305aebefSGustavo Pimentel WR_REGISTER_UNROLL(engine_chgroup), 16104e0a39fSGustavo Pimentel WR_REGISTER_UNROLL(engine_hshake_cnt.lsb), 16204e0a39fSGustavo Pimentel WR_REGISTER_UNROLL(engine_hshake_cnt.msb), 163305aebefSGustavo Pimentel WR_REGISTER_UNROLL(ch0_pwr_en), 164305aebefSGustavo Pimentel WR_REGISTER_UNROLL(ch1_pwr_en), 165305aebefSGustavo Pimentel WR_REGISTER_UNROLL(ch2_pwr_en), 166305aebefSGustavo Pimentel WR_REGISTER_UNROLL(ch3_pwr_en), 167305aebefSGustavo Pimentel WR_REGISTER_UNROLL(ch4_pwr_en), 168305aebefSGustavo Pimentel WR_REGISTER_UNROLL(ch5_pwr_en), 169305aebefSGustavo Pimentel WR_REGISTER_UNROLL(ch6_pwr_en), 170305aebefSGustavo Pimentel WR_REGISTER_UNROLL(ch7_pwr_en), 171305aebefSGustavo Pimentel }; 17295c55b78SSerge Semin struct dentry *regs_dent, *ch_dent; 173305aebefSGustavo Pimentel int nr_entries, i; 174305aebefSGustavo Pimentel char name[16]; 175305aebefSGustavo Pimentel 17695c55b78SSerge Semin regs_dent = debugfs_create_dir(WRITE_STR, dent); 177305aebefSGustavo Pimentel 178305aebefSGustavo Pimentel nr_entries = ARRAY_SIZE(debugfs_regs); 17995c55b78SSerge Semin dw_edma_debugfs_create_x32(debugfs_regs, nr_entries, regs_dent); 180305aebefSGustavo Pimentel 18120318457SFrank Li if (dw->chip->mf == EDMA_MF_HDMA_COMPAT) { 182305aebefSGustavo Pimentel nr_entries = ARRAY_SIZE(debugfs_unroll_regs); 183305aebefSGustavo Pimentel dw_edma_debugfs_create_x32(debugfs_unroll_regs, nr_entries, 18495c55b78SSerge Semin regs_dent); 185305aebefSGustavo Pimentel } 186305aebefSGustavo Pimentel 187305aebefSGustavo Pimentel for (i = 0; i < dw->wr_ch_cnt; i++) { 188305aebefSGustavo Pimentel snprintf(name, sizeof(name), "%s:%d", CHANNEL_STR, i); 189305aebefSGustavo Pimentel 19095c55b78SSerge Semin ch_dent = debugfs_create_dir(name, regs_dent); 191305aebefSGustavo Pimentel 192*00498167SSerge Semin dw_edma_debugfs_regs_ch(EDMA_DIR_WRITE, i, ch_dent); 193305aebefSGustavo Pimentel } 194305aebefSGustavo Pimentel } 195305aebefSGustavo Pimentel 19695c55b78SSerge Semin static void dw_edma_debugfs_regs_rd(struct dentry *dent) 197305aebefSGustavo Pimentel { 198345e3a95SSerge Semin const struct dw_edma_debugfs_entry debugfs_regs[] = { 199305aebefSGustavo Pimentel /* eDMA global registers */ 200305aebefSGustavo Pimentel RD_REGISTER(engine_en), 201305aebefSGustavo Pimentel RD_REGISTER(doorbell), 20204e0a39fSGustavo Pimentel RD_REGISTER(ch_arb_weight.lsb), 20304e0a39fSGustavo Pimentel RD_REGISTER(ch_arb_weight.msb), 204305aebefSGustavo Pimentel /* eDMA interrupts registers */ 205305aebefSGustavo Pimentel RD_REGISTER(int_status), 206305aebefSGustavo Pimentel RD_REGISTER(int_mask), 207305aebefSGustavo Pimentel RD_REGISTER(int_clear), 20804e0a39fSGustavo Pimentel RD_REGISTER(err_status.lsb), 20904e0a39fSGustavo Pimentel RD_REGISTER(err_status.msb), 210305aebefSGustavo Pimentel RD_REGISTER(linked_list_err_en), 21104e0a39fSGustavo Pimentel RD_REGISTER(done_imwr.lsb), 21204e0a39fSGustavo Pimentel RD_REGISTER(done_imwr.msb), 21304e0a39fSGustavo Pimentel RD_REGISTER(abort_imwr.lsb), 21404e0a39fSGustavo Pimentel RD_REGISTER(abort_imwr.msb), 215305aebefSGustavo Pimentel RD_REGISTER(ch01_imwr_data), 216305aebefSGustavo Pimentel RD_REGISTER(ch23_imwr_data), 217305aebefSGustavo Pimentel RD_REGISTER(ch45_imwr_data), 218305aebefSGustavo Pimentel RD_REGISTER(ch67_imwr_data), 219305aebefSGustavo Pimentel }; 220345e3a95SSerge Semin const struct dw_edma_debugfs_entry debugfs_unroll_regs[] = { 221305aebefSGustavo Pimentel /* eDMA channel context grouping */ 222305aebefSGustavo Pimentel RD_REGISTER_UNROLL(engine_chgroup), 22304e0a39fSGustavo Pimentel RD_REGISTER_UNROLL(engine_hshake_cnt.lsb), 22404e0a39fSGustavo Pimentel RD_REGISTER_UNROLL(engine_hshake_cnt.msb), 225305aebefSGustavo Pimentel RD_REGISTER_UNROLL(ch0_pwr_en), 226305aebefSGustavo Pimentel RD_REGISTER_UNROLL(ch1_pwr_en), 227305aebefSGustavo Pimentel RD_REGISTER_UNROLL(ch2_pwr_en), 228305aebefSGustavo Pimentel RD_REGISTER_UNROLL(ch3_pwr_en), 229305aebefSGustavo Pimentel RD_REGISTER_UNROLL(ch4_pwr_en), 230305aebefSGustavo Pimentel RD_REGISTER_UNROLL(ch5_pwr_en), 231305aebefSGustavo Pimentel RD_REGISTER_UNROLL(ch6_pwr_en), 232305aebefSGustavo Pimentel RD_REGISTER_UNROLL(ch7_pwr_en), 233305aebefSGustavo Pimentel }; 23495c55b78SSerge Semin struct dentry *regs_dent, *ch_dent; 235305aebefSGustavo Pimentel int nr_entries, i; 236305aebefSGustavo Pimentel char name[16]; 237305aebefSGustavo Pimentel 23895c55b78SSerge Semin regs_dent = debugfs_create_dir(READ_STR, dent); 239305aebefSGustavo Pimentel 240305aebefSGustavo Pimentel nr_entries = ARRAY_SIZE(debugfs_regs); 24195c55b78SSerge Semin dw_edma_debugfs_create_x32(debugfs_regs, nr_entries, regs_dent); 242305aebefSGustavo Pimentel 24320318457SFrank Li if (dw->chip->mf == EDMA_MF_HDMA_COMPAT) { 244305aebefSGustavo Pimentel nr_entries = ARRAY_SIZE(debugfs_unroll_regs); 245305aebefSGustavo Pimentel dw_edma_debugfs_create_x32(debugfs_unroll_regs, nr_entries, 24695c55b78SSerge Semin regs_dent); 247305aebefSGustavo Pimentel } 248305aebefSGustavo Pimentel 249305aebefSGustavo Pimentel for (i = 0; i < dw->rd_ch_cnt; i++) { 250305aebefSGustavo Pimentel snprintf(name, sizeof(name), "%s:%d", CHANNEL_STR, i); 251305aebefSGustavo Pimentel 25295c55b78SSerge Semin ch_dent = debugfs_create_dir(name, regs_dent); 253305aebefSGustavo Pimentel 254*00498167SSerge Semin dw_edma_debugfs_regs_ch(EDMA_DIR_READ, i, ch_dent); 255305aebefSGustavo Pimentel } 256305aebefSGustavo Pimentel } 257305aebefSGustavo Pimentel 258305aebefSGustavo Pimentel static void dw_edma_debugfs_regs(void) 259305aebefSGustavo Pimentel { 260345e3a95SSerge Semin const struct dw_edma_debugfs_entry debugfs_regs[] = { 261305aebefSGustavo Pimentel REGISTER(ctrl_data_arb_prior), 262305aebefSGustavo Pimentel REGISTER(ctrl), 263305aebefSGustavo Pimentel }; 26495c55b78SSerge Semin struct dentry *regs_dent; 265305aebefSGustavo Pimentel int nr_entries; 266305aebefSGustavo Pimentel 26795c55b78SSerge Semin regs_dent = debugfs_create_dir(REGISTERS_STR, dw->debugfs); 268305aebefSGustavo Pimentel 269305aebefSGustavo Pimentel nr_entries = ARRAY_SIZE(debugfs_regs); 27095c55b78SSerge Semin dw_edma_debugfs_create_x32(debugfs_regs, nr_entries, regs_dent); 271305aebefSGustavo Pimentel 27295c55b78SSerge Semin dw_edma_debugfs_regs_wr(regs_dent); 27395c55b78SSerge Semin dw_edma_debugfs_regs_rd(regs_dent); 274305aebefSGustavo Pimentel } 275305aebefSGustavo Pimentel 27620318457SFrank Li void dw_edma_v0_debugfs_on(struct dw_edma *_dw) 277305aebefSGustavo Pimentel { 27837d058aaSSerge Semin if (!debugfs_initialized()) 27937d058aaSSerge Semin return; 28037d058aaSSerge Semin 28120318457SFrank Li dw = _dw; 282305aebefSGustavo Pimentel if (!dw) 283305aebefSGustavo Pimentel return; 284305aebefSGustavo Pimentel 285e51b3048SFrank Li regs = dw->chip->reg_base; 286305aebefSGustavo Pimentel if (!regs) 287305aebefSGustavo Pimentel return; 288305aebefSGustavo Pimentel 2895244ac2eSGustavo Pimentel dw->debugfs = debugfs_create_dir(dw->name, NULL); 290305aebefSGustavo Pimentel 29120318457SFrank Li debugfs_create_u32("mf", 0444, dw->debugfs, &dw->chip->mf); 2925244ac2eSGustavo Pimentel debugfs_create_u16("wr_ch_cnt", 0444, dw->debugfs, &dw->wr_ch_cnt); 2935244ac2eSGustavo Pimentel debugfs_create_u16("rd_ch_cnt", 0444, dw->debugfs, &dw->rd_ch_cnt); 294305aebefSGustavo Pimentel 295305aebefSGustavo Pimentel dw_edma_debugfs_regs(); 296305aebefSGustavo Pimentel } 297305aebefSGustavo Pimentel 29820318457SFrank Li void dw_edma_v0_debugfs_off(struct dw_edma *_dw) 299305aebefSGustavo Pimentel { 30020318457SFrank Li dw = _dw; 3015244ac2eSGustavo Pimentel if (!dw) 3025244ac2eSGustavo Pimentel return; 3035244ac2eSGustavo Pimentel 3045244ac2eSGustavo Pimentel debugfs_remove_recursive(dw->debugfs); 3055244ac2eSGustavo Pimentel dw->debugfs = NULL; 306305aebefSGustavo Pimentel } 307