18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Tegra host1x Interrupt Management 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2010 Google, Inc. 68c2ecf20Sopenharmony_ci * Copyright (c) 2010-2013, NVIDIA Corporation. 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 108c2ecf20Sopenharmony_ci#include <linux/irq.h> 118c2ecf20Sopenharmony_ci#include <linux/io.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include "../intr.h" 148c2ecf20Sopenharmony_ci#include "../dev.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* 178c2ecf20Sopenharmony_ci * Sync point threshold interrupt service function 188c2ecf20Sopenharmony_ci * Handles sync point threshold triggers, in interrupt context 198c2ecf20Sopenharmony_ci */ 208c2ecf20Sopenharmony_cistatic void host1x_intr_syncpt_handle(struct host1x_syncpt *syncpt) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci unsigned int id = syncpt->id; 238c2ecf20Sopenharmony_ci struct host1x *host = syncpt->host; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci host1x_sync_writel(host, BIT(id % 32), 268c2ecf20Sopenharmony_ci HOST1X_SYNC_SYNCPT_THRESH_INT_DISABLE(id / 32)); 278c2ecf20Sopenharmony_ci host1x_sync_writel(host, BIT(id % 32), 288c2ecf20Sopenharmony_ci HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(id / 32)); 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci schedule_work(&syncpt->intr.work); 318c2ecf20Sopenharmony_ci} 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistatic irqreturn_t syncpt_thresh_isr(int irq, void *dev_id) 348c2ecf20Sopenharmony_ci{ 358c2ecf20Sopenharmony_ci struct host1x *host = dev_id; 368c2ecf20Sopenharmony_ci unsigned long reg; 378c2ecf20Sopenharmony_ci unsigned int i, id; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci for (i = 0; i < DIV_ROUND_UP(host->info->nb_pts, 32); i++) { 408c2ecf20Sopenharmony_ci reg = host1x_sync_readl(host, 418c2ecf20Sopenharmony_ci HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(i)); 428c2ecf20Sopenharmony_ci for_each_set_bit(id, ®, 32) { 438c2ecf20Sopenharmony_ci struct host1x_syncpt *syncpt = 448c2ecf20Sopenharmony_ci host->syncpt + (i * 32 + id); 458c2ecf20Sopenharmony_ci host1x_intr_syncpt_handle(syncpt); 468c2ecf20Sopenharmony_ci } 478c2ecf20Sopenharmony_ci } 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci return IRQ_HANDLED; 508c2ecf20Sopenharmony_ci} 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic void _host1x_intr_disable_all_syncpt_intrs(struct host1x *host) 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci unsigned int i; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci for (i = 0; i < DIV_ROUND_UP(host->info->nb_pts, 32); ++i) { 578c2ecf20Sopenharmony_ci host1x_sync_writel(host, 0xffffffffu, 588c2ecf20Sopenharmony_ci HOST1X_SYNC_SYNCPT_THRESH_INT_DISABLE(i)); 598c2ecf20Sopenharmony_ci host1x_sync_writel(host, 0xffffffffu, 608c2ecf20Sopenharmony_ci HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(i)); 618c2ecf20Sopenharmony_ci } 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistatic void intr_hw_init(struct host1x *host, u32 cpm) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci#if HOST1X_HW < 6 678c2ecf20Sopenharmony_ci /* disable the ip_busy_timeout. this prevents write drops */ 688c2ecf20Sopenharmony_ci host1x_sync_writel(host, 0, HOST1X_SYNC_IP_BUSY_TIMEOUT); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci /* 718c2ecf20Sopenharmony_ci * increase the auto-ack timout to the maximum value. 2d will hang 728c2ecf20Sopenharmony_ci * otherwise on Tegra2. 738c2ecf20Sopenharmony_ci */ 748c2ecf20Sopenharmony_ci host1x_sync_writel(host, 0xff, HOST1X_SYNC_CTXSW_TIMEOUT_CFG); 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci /* update host clocks per usec */ 778c2ecf20Sopenharmony_ci host1x_sync_writel(host, cpm, HOST1X_SYNC_USEC_CLK); 788c2ecf20Sopenharmony_ci#endif 798c2ecf20Sopenharmony_ci} 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistatic int 828c2ecf20Sopenharmony_ci_host1x_intr_init_host_sync(struct host1x *host, u32 cpm, 838c2ecf20Sopenharmony_ci void (*syncpt_thresh_work)(struct work_struct *)) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci unsigned int i; 868c2ecf20Sopenharmony_ci int err; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci host1x_hw_intr_disable_all_syncpt_intrs(host); 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci for (i = 0; i < host->info->nb_pts; i++) 918c2ecf20Sopenharmony_ci INIT_WORK(&host->syncpt[i].intr.work, syncpt_thresh_work); 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci err = devm_request_irq(host->dev, host->intr_syncpt_irq, 948c2ecf20Sopenharmony_ci syncpt_thresh_isr, IRQF_SHARED, 958c2ecf20Sopenharmony_ci "host1x_syncpt", host); 968c2ecf20Sopenharmony_ci if (err < 0) { 978c2ecf20Sopenharmony_ci WARN_ON(1); 988c2ecf20Sopenharmony_ci return err; 998c2ecf20Sopenharmony_ci } 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci intr_hw_init(host, cpm); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci return 0; 1048c2ecf20Sopenharmony_ci} 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistatic void _host1x_intr_set_syncpt_threshold(struct host1x *host, 1078c2ecf20Sopenharmony_ci unsigned int id, 1088c2ecf20Sopenharmony_ci u32 thresh) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci host1x_sync_writel(host, thresh, HOST1X_SYNC_SYNCPT_INT_THRESH(id)); 1118c2ecf20Sopenharmony_ci} 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic void _host1x_intr_enable_syncpt_intr(struct host1x *host, 1148c2ecf20Sopenharmony_ci unsigned int id) 1158c2ecf20Sopenharmony_ci{ 1168c2ecf20Sopenharmony_ci host1x_sync_writel(host, BIT(id % 32), 1178c2ecf20Sopenharmony_ci HOST1X_SYNC_SYNCPT_THRESH_INT_ENABLE_CPU0(id / 32)); 1188c2ecf20Sopenharmony_ci} 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cistatic void _host1x_intr_disable_syncpt_intr(struct host1x *host, 1218c2ecf20Sopenharmony_ci unsigned int id) 1228c2ecf20Sopenharmony_ci{ 1238c2ecf20Sopenharmony_ci host1x_sync_writel(host, BIT(id % 32), 1248c2ecf20Sopenharmony_ci HOST1X_SYNC_SYNCPT_THRESH_INT_DISABLE(id / 32)); 1258c2ecf20Sopenharmony_ci host1x_sync_writel(host, BIT(id % 32), 1268c2ecf20Sopenharmony_ci HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(id / 32)); 1278c2ecf20Sopenharmony_ci} 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistatic int _host1x_free_syncpt_irq(struct host1x *host) 1308c2ecf20Sopenharmony_ci{ 1318c2ecf20Sopenharmony_ci unsigned int i; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci devm_free_irq(host->dev, host->intr_syncpt_irq, host); 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci for (i = 0; i < host->info->nb_pts; i++) 1368c2ecf20Sopenharmony_ci cancel_work_sync(&host->syncpt[i].intr.work); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci return 0; 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistatic const struct host1x_intr_ops host1x_intr_ops = { 1428c2ecf20Sopenharmony_ci .init_host_sync = _host1x_intr_init_host_sync, 1438c2ecf20Sopenharmony_ci .set_syncpt_threshold = _host1x_intr_set_syncpt_threshold, 1448c2ecf20Sopenharmony_ci .enable_syncpt_intr = _host1x_intr_enable_syncpt_intr, 1458c2ecf20Sopenharmony_ci .disable_syncpt_intr = _host1x_intr_disable_syncpt_intr, 1468c2ecf20Sopenharmony_ci .disable_all_syncpt_intrs = _host1x_intr_disable_all_syncpt_intrs, 1478c2ecf20Sopenharmony_ci .free_syncpt_irq = _host1x_free_syncpt_irq, 1488c2ecf20Sopenharmony_ci}; 149