18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2016, Mellanox Technologies. All rights reserved. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two 58c2ecf20Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 68c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 78c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the 88c2ecf20Sopenharmony_ci * OpenIB.org BSD license below: 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or 118c2ecf20Sopenharmony_ci * without modification, are permitted provided that the following 128c2ecf20Sopenharmony_ci * conditions are met: 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above 158c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 168c2ecf20Sopenharmony_ci * disclaimer. 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above 198c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 208c2ecf20Sopenharmony_ci * disclaimer in the documentation and/or other materials 218c2ecf20Sopenharmony_ci * provided with the distribution. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 248c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 258c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 268c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 278c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 288c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 298c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 308c2ecf20Sopenharmony_ci * SOFTWARE. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 348c2ecf20Sopenharmony_ci#include <linux/module.h> 358c2ecf20Sopenharmony_ci#include <linux/of.h> 368c2ecf20Sopenharmony_ci#include <linux/irq.h> 378c2ecf20Sopenharmony_ci#include <linux/irqdomain.h> 388c2ecf20Sopenharmony_ci#include <linux/irqchip.h> 398c2ecf20Sopenharmony_ci#include <soc/nps/common.h> 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define NPS_NR_CPU_IRQS 8 /* number of interrupt lines of NPS400 CPU */ 428c2ecf20Sopenharmony_ci#define NPS_TIMER0_IRQ 3 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* 458c2ecf20Sopenharmony_ci * NPS400 core includes an Interrupt Controller (IC) support. 468c2ecf20Sopenharmony_ci * All cores can deactivate level irqs at first level control 478c2ecf20Sopenharmony_ci * at cores mesh layer called MTM. 488c2ecf20Sopenharmony_ci * For devices out side chip e.g. uart, network there is another 498c2ecf20Sopenharmony_ci * level called Global Interrupt Manager (GIM). 508c2ecf20Sopenharmony_ci * This second level can control level and edge interrupt. 518c2ecf20Sopenharmony_ci * 528c2ecf20Sopenharmony_ci * NOTE: AUX_IENABLE and CTOP_AUX_IACK are auxiliary registers 538c2ecf20Sopenharmony_ci * with private HW copy per CPU. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic void nps400_irq_mask(struct irq_data *irqd) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci unsigned int ienb; 598c2ecf20Sopenharmony_ci unsigned int irq = irqd_to_hwirq(irqd); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci ienb = read_aux_reg(AUX_IENABLE); 628c2ecf20Sopenharmony_ci ienb &= ~(1 << irq); 638c2ecf20Sopenharmony_ci write_aux_reg(AUX_IENABLE, ienb); 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic void nps400_irq_unmask(struct irq_data *irqd) 678c2ecf20Sopenharmony_ci{ 688c2ecf20Sopenharmony_ci unsigned int ienb; 698c2ecf20Sopenharmony_ci unsigned int irq = irqd_to_hwirq(irqd); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci ienb = read_aux_reg(AUX_IENABLE); 728c2ecf20Sopenharmony_ci ienb |= (1 << irq); 738c2ecf20Sopenharmony_ci write_aux_reg(AUX_IENABLE, ienb); 748c2ecf20Sopenharmony_ci} 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_cistatic void nps400_irq_eoi_global(struct irq_data *irqd) 778c2ecf20Sopenharmony_ci{ 788c2ecf20Sopenharmony_ci unsigned int __maybe_unused irq = irqd_to_hwirq(irqd); 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci write_aux_reg(CTOP_AUX_IACK, 1 << irq); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci /* Don't ack GIC before all device access attempts are done */ 838c2ecf20Sopenharmony_ci mb(); 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci nps_ack_gic(); 868c2ecf20Sopenharmony_ci} 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_cistatic void nps400_irq_ack(struct irq_data *irqd) 898c2ecf20Sopenharmony_ci{ 908c2ecf20Sopenharmony_ci unsigned int __maybe_unused irq = irqd_to_hwirq(irqd); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci write_aux_reg(CTOP_AUX_IACK, 1 << irq); 938c2ecf20Sopenharmony_ci} 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistatic struct irq_chip nps400_irq_chip_fasteoi = { 968c2ecf20Sopenharmony_ci .name = "NPS400 IC Global", 978c2ecf20Sopenharmony_ci .irq_mask = nps400_irq_mask, 988c2ecf20Sopenharmony_ci .irq_unmask = nps400_irq_unmask, 998c2ecf20Sopenharmony_ci .irq_eoi = nps400_irq_eoi_global, 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic struct irq_chip nps400_irq_chip_percpu = { 1038c2ecf20Sopenharmony_ci .name = "NPS400 IC", 1048c2ecf20Sopenharmony_ci .irq_mask = nps400_irq_mask, 1058c2ecf20Sopenharmony_ci .irq_unmask = nps400_irq_unmask, 1068c2ecf20Sopenharmony_ci .irq_ack = nps400_irq_ack, 1078c2ecf20Sopenharmony_ci}; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic int nps400_irq_map(struct irq_domain *d, unsigned int virq, 1108c2ecf20Sopenharmony_ci irq_hw_number_t hw) 1118c2ecf20Sopenharmony_ci{ 1128c2ecf20Sopenharmony_ci switch (hw) { 1138c2ecf20Sopenharmony_ci case NPS_TIMER0_IRQ: 1148c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 1158c2ecf20Sopenharmony_ci case NPS_IPI_IRQ: 1168c2ecf20Sopenharmony_ci#endif 1178c2ecf20Sopenharmony_ci irq_set_percpu_devid(virq); 1188c2ecf20Sopenharmony_ci irq_set_chip_and_handler(virq, &nps400_irq_chip_percpu, 1198c2ecf20Sopenharmony_ci handle_percpu_devid_irq); 1208c2ecf20Sopenharmony_ci break; 1218c2ecf20Sopenharmony_ci default: 1228c2ecf20Sopenharmony_ci irq_set_chip_and_handler(virq, &nps400_irq_chip_fasteoi, 1238c2ecf20Sopenharmony_ci handle_fasteoi_irq); 1248c2ecf20Sopenharmony_ci break; 1258c2ecf20Sopenharmony_ci } 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci return 0; 1288c2ecf20Sopenharmony_ci} 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistatic const struct irq_domain_ops nps400_irq_ops = { 1318c2ecf20Sopenharmony_ci .xlate = irq_domain_xlate_onecell, 1328c2ecf20Sopenharmony_ci .map = nps400_irq_map, 1338c2ecf20Sopenharmony_ci}; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic int __init nps400_of_init(struct device_node *node, 1368c2ecf20Sopenharmony_ci struct device_node *parent) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci struct irq_domain *nps400_root_domain; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci if (parent) { 1418c2ecf20Sopenharmony_ci pr_err("DeviceTree incore ic not a root irq controller\n"); 1428c2ecf20Sopenharmony_ci return -EINVAL; 1438c2ecf20Sopenharmony_ci } 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci nps400_root_domain = irq_domain_add_linear(node, NPS_NR_CPU_IRQS, 1468c2ecf20Sopenharmony_ci &nps400_irq_ops, NULL); 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci if (!nps400_root_domain) { 1498c2ecf20Sopenharmony_ci pr_err("nps400 root irq domain not avail\n"); 1508c2ecf20Sopenharmony_ci return -ENOMEM; 1518c2ecf20Sopenharmony_ci } 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci /* 1548c2ecf20Sopenharmony_ci * Needed for primary domain lookup to succeed 1558c2ecf20Sopenharmony_ci * This is a primary irqchip, and can never have a parent 1568c2ecf20Sopenharmony_ci */ 1578c2ecf20Sopenharmony_ci irq_set_default_host(nps400_root_domain); 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 1608c2ecf20Sopenharmony_ci irq_create_mapping(nps400_root_domain, NPS_IPI_IRQ); 1618c2ecf20Sopenharmony_ci#endif 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci return 0; 1648c2ecf20Sopenharmony_ci} 1658c2ecf20Sopenharmony_ciIRQCHIP_DECLARE(ezchip_nps400_ic, "ezchip,nps400-ic", nps400_of_init); 166