| 
									
										
										
										
											2006-01-16 22:14:14 -08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2006-10-06 17:55:25 +09:00
										 |  |  |  * Interrupt handling for IPR-based IRQ. | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 1999  Niibe Yutaka & Takeshi Yaegashi | 
					
						
							|  |  |  |  * Copyright (C) 2000  Kazumoto Kojima | 
					
						
							| 
									
										
										
										
											2006-10-06 17:55:25 +09:00
										 |  |  |  * Copyright (C) 2003  Takashi Kusuda <kusuda-takashi@hitachi-ul.co.jp> | 
					
						
							|  |  |  |  * Copyright (C) 2006  Paul Mundt | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Supported system: | 
					
						
							|  |  |  |  *	On-chip supporting modules (TMU, RTC, etc.). | 
					
						
							| 
									
										
										
										
											2007-07-25 11:42:56 +09:00
										 |  |  |  *	On-chip supporting modules for SH7709/SH7709A/SH7729. | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  *	Hitachi SolutionEngine external I/O: | 
					
						
							|  |  |  |  *		MS7709SE01, MS7709ASE01, and MS7750SE01 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-10-06 17:55:25 +09:00
										 |  |  |  * This file is subject to the terms and conditions of the GNU General Public | 
					
						
							|  |  |  |  * License.  See the file "COPYING" in the main directory of this archive | 
					
						
							|  |  |  |  * for more details. | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							| 
									
										
										
										
											2009-12-07 10:38:55 +01:00
										 |  |  | #include <linux/interrupt.h>
 | 
					
						
							|  |  |  | #include <linux/io.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <linux/irq.h>
 | 
					
						
							| 
									
										
										
										
											2009-12-07 10:38:55 +01:00
										 |  |  | #include <linux/kernel.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <linux/module.h>
 | 
					
						
							| 
									
										
										
										
											2009-06-11 10:33:09 +03:00
										 |  |  | #include <linux/topology.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-27 14:41:39 +09:00
										 |  |  | static inline struct ipr_desc *get_ipr_desc(struct irq_data *data) | 
					
						
							| 
									
										
										
										
											2007-06-15 18:56:19 +09:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-27 14:41:39 +09:00
										 |  |  | 	struct irq_chip *chip = irq_data_get_irq_chip(data); | 
					
						
							| 
									
										
										
										
											2009-12-07 10:38:55 +01:00
										 |  |  | 	return container_of(chip, struct ipr_desc, chip); | 
					
						
							| 
									
										
										
										
											2007-06-15 18:56:19 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-27 14:41:39 +09:00
										 |  |  | static void disable_ipr_irq(struct irq_data *data) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-27 14:41:39 +09:00
										 |  |  | 	struct ipr_data *p = irq_data_get_irq_chip_data(data); | 
					
						
							|  |  |  | 	unsigned long addr = get_ipr_desc(data)->ipr_offsets[p->ipr_idx]; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	/* Set the priority in IPR to 0 */ | 
					
						
							| 
									
										
										
										
											2008-10-01 15:19:10 +09:00
										 |  |  | 	__raw_writew(__raw_readw(addr) & (0xffff ^ (0xf << p->shift)), addr); | 
					
						
							| 
									
										
										
										
											2009-08-24 18:27:33 +09:00
										 |  |  | 	(void)__raw_readw(addr);	/* Read back to flush write posting */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-27 14:41:39 +09:00
										 |  |  | static void enable_ipr_irq(struct irq_data *data) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-27 14:41:39 +09:00
										 |  |  | 	struct ipr_data *p = irq_data_get_irq_chip_data(data); | 
					
						
							|  |  |  | 	unsigned long addr = get_ipr_desc(data)->ipr_offsets[p->ipr_idx]; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	/* Set priority in IPR back to original value */ | 
					
						
							| 
									
										
										
										
											2008-10-01 15:19:10 +09:00
										 |  |  | 	__raw_writew(__raw_readw(addr) | (p->priority << p->shift), addr); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-15 18:56:19 +09:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * The shift value is now the number of bits to shift, not the number of | 
					
						
							|  |  |  |  * bits/4. This is to make it easier to read the value directly from the | 
					
						
							|  |  |  |  * datasheets. The IPR address is calculated using the ipr_offset table. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void register_ipr_controller(struct ipr_desc *desc) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-31 12:35:02 +09:00
										 |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2006-10-06 17:55:25 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-27 14:41:39 +09:00
										 |  |  | 	desc->chip.irq_mask = disable_ipr_irq; | 
					
						
							|  |  |  | 	desc->chip.irq_unmask = enable_ipr_irq; | 
					
						
							| 
									
										
										
										
											2006-12-25 18:35:24 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-15 18:56:19 +09:00
										 |  |  | 	for (i = 0; i < desc->nr_irqs; i++) { | 
					
						
							|  |  |  | 		struct ipr_data *p = desc->ipr_data + i; | 
					
						
							| 
									
										
										
										
											2010-10-12 02:03:09 +09:00
										 |  |  | 		int res; | 
					
						
							| 
									
										
										
										
											2006-12-25 18:35:24 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-15 18:56:19 +09:00
										 |  |  | 		BUG_ON(p->ipr_idx >= desc->nr_offsets); | 
					
						
							|  |  |  | 		BUG_ON(!desc->ipr_offsets[p->ipr_idx]); | 
					
						
							| 
									
										
										
										
											2006-12-25 18:35:24 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-12 02:03:09 +09:00
										 |  |  | 		res = irq_alloc_desc_at(p->irq, numa_node_id()); | 
					
						
							| 
									
										
										
										
											2010-10-27 14:41:39 +09:00
										 |  |  | 		if (unlikely(res != p->irq && res != -EEXIST)) { | 
					
						
							| 
									
										
										
										
											2009-05-22 01:28:33 +09:00
										 |  |  | 			printk(KERN_INFO "can not get irq_desc for %d\n", | 
					
						
							|  |  |  | 			       p->irq); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-15 18:56:19 +09:00
										 |  |  | 		disable_irq_nosync(p->irq); | 
					
						
							| 
									
										
										
										
											2011-03-24 16:31:17 +01:00
										 |  |  | 		irq_set_chip_and_handler_name(p->irq, &desc->chip, | 
					
						
							|  |  |  | 					      handle_level_irq, "level"); | 
					
						
							|  |  |  | 		irq_set_chip_data(p->irq, p); | 
					
						
							| 
									
										
										
										
											2010-10-27 14:41:39 +09:00
										 |  |  | 		disable_ipr_irq(irq_get_irq_data(p->irq)); | 
					
						
							| 
									
										
										
										
											2006-10-31 12:35:02 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2007-06-15 18:56:19 +09:00
										 |  |  | EXPORT_SYMBOL(register_ipr_controller); |