Blame view

drivers/sh/intc/chip.c 5.91 KB
2be6bb0c7   Paul Mundt   sh: intc: Split u...
1
2
3
4
5
6
7
8
9
10
11
12
13
  /*
   * IRQ chip definitions for INTC IRQs.
   *
   * Copyright (C) 2007, 2008 Magnus Damm
   * Copyright (C) 2009, 2010 Paul Mundt
   *
   * 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.
   */
  #include <linux/cpumask.h>
  #include <linux/io.h>
  #include "internals.h"
26599a94d   Paul Mundt   sh: intc: irq_dat...
14
  void _intc_enable(struct irq_data *data, unsigned long handle)
2be6bb0c7   Paul Mundt   sh: intc: Split u...
15
  {
26599a94d   Paul Mundt   sh: intc: irq_dat...
16
  	unsigned int irq = data->irq;
2be6bb0c7   Paul Mundt   sh: intc: Split u...
17
18
19
20
21
22
  	struct intc_desc_int *d = get_intc_desc(irq);
  	unsigned long addr;
  	unsigned int cpu;
  
  	for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_E(handle)); cpu++) {
  #ifdef CONFIG_SMP
26599a94d   Paul Mundt   sh: intc: irq_dat...
23
  		if (!cpumask_test_cpu(cpu, data->affinity))
2be6bb0c7   Paul Mundt   sh: intc: Split u...
24
25
26
27
28
29
30
31
32
  			continue;
  #endif
  		addr = INTC_REG(d, _INTC_ADDR_E(handle), cpu);
  		intc_enable_fns[_INTC_MODE(handle)](addr, handle, intc_reg_fns\
  						    [_INTC_FN(handle)], irq);
  	}
  
  	intc_balancing_enable(irq);
  }
26599a94d   Paul Mundt   sh: intc: irq_dat...
33
  static void intc_enable(struct irq_data *data)
2be6bb0c7   Paul Mundt   sh: intc: Split u...
34
  {
26599a94d   Paul Mundt   sh: intc: irq_dat...
35
  	_intc_enable(data, (unsigned long)irq_data_get_irq_chip_data(data));
2be6bb0c7   Paul Mundt   sh: intc: Split u...
36
  }
26599a94d   Paul Mundt   sh: intc: irq_dat...
37
  static void intc_disable(struct irq_data *data)
2be6bb0c7   Paul Mundt   sh: intc: Split u...
38
  {
26599a94d   Paul Mundt   sh: intc: irq_dat...
39
  	unsigned int irq = data->irq;
2be6bb0c7   Paul Mundt   sh: intc: Split u...
40
  	struct intc_desc_int *d = get_intc_desc(irq);
26599a94d   Paul Mundt   sh: intc: irq_dat...
41
  	unsigned long handle = (unsigned long)irq_data_get_irq_chip_data(data);
2be6bb0c7   Paul Mundt   sh: intc: Split u...
42
43
44
45
46
47
48
  	unsigned long addr;
  	unsigned int cpu;
  
  	intc_balancing_disable(irq);
  
  	for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_D(handle)); cpu++) {
  #ifdef CONFIG_SMP
26599a94d   Paul Mundt   sh: intc: irq_dat...
49
  		if (!cpumask_test_cpu(cpu, data->affinity))
2be6bb0c7   Paul Mundt   sh: intc: Split u...
50
51
52
53
54
55
56
  			continue;
  #endif
  		addr = INTC_REG(d, _INTC_ADDR_D(handle), cpu);
  		intc_disable_fns[_INTC_MODE(handle)](addr, handle,intc_reg_fns\
  						     [_INTC_FN(handle)], irq);
  	}
  }
26599a94d   Paul Mundt   sh: intc: irq_dat...
57
  static int intc_set_wake(struct irq_data *data, unsigned int on)
2be6bb0c7   Paul Mundt   sh: intc: Split u...
58
59
60
61
62
63
64
65
66
67
  {
  	return 0; /* allow wakeup, but setup hardware in intc_suspend() */
  }
  
  #ifdef CONFIG_SMP
  /*
   * This is held with the irq desc lock held, so we don't require any
   * additional locking here at the intc desc level. The affinity mask is
   * later tested in the enable/disable paths.
   */
26599a94d   Paul Mundt   sh: intc: irq_dat...
68
69
70
  static int intc_set_affinity(struct irq_data *data,
  			     const struct cpumask *cpumask,
  			     bool force)
2be6bb0c7   Paul Mundt   sh: intc: Split u...
71
72
73
  {
  	if (!cpumask_intersects(cpumask, cpu_online_mask))
  		return -1;
26599a94d   Paul Mundt   sh: intc: irq_dat...
74
  	cpumask_copy(data->affinity, cpumask);
2be6bb0c7   Paul Mundt   sh: intc: Split u...
75
76
77
78
  
  	return 0;
  }
  #endif
26599a94d   Paul Mundt   sh: intc: irq_dat...
79
  static void intc_mask_ack(struct irq_data *data)
2be6bb0c7   Paul Mundt   sh: intc: Split u...
80
  {
26599a94d   Paul Mundt   sh: intc: irq_dat...
81
  	unsigned int irq = data->irq;
2be6bb0c7   Paul Mundt   sh: intc: Split u...
82
83
84
  	struct intc_desc_int *d = get_intc_desc(irq);
  	unsigned long handle = intc_get_ack_handle(irq);
  	unsigned long addr;
26599a94d   Paul Mundt   sh: intc: irq_dat...
85
  	intc_disable(data);
2be6bb0c7   Paul Mundt   sh: intc: Split u...
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
  
  	/* read register and write zero only to the associated bit */
  	if (handle) {
  		unsigned int value;
  
  		addr = INTC_REG(d, _INTC_ADDR_D(handle), 0);
  		value = intc_set_field_from_handle(0, 1, handle);
  
  		switch (_INTC_FN(handle)) {
  		case REG_FN_MODIFY_BASE + 0:	/* 8bit */
  			__raw_readb(addr);
  			__raw_writeb(0xff ^ value, addr);
  			break;
  		case REG_FN_MODIFY_BASE + 1:	/* 16bit */
  			__raw_readw(addr);
  			__raw_writew(0xffff ^ value, addr);
  			break;
  		case REG_FN_MODIFY_BASE + 3:	/* 32bit */
  			__raw_readl(addr);
  			__raw_writel(0xffffffff ^ value, addr);
  			break;
  		default:
  			BUG();
  			break;
  		}
  	}
  }
  
  static struct intc_handle_int *intc_find_irq(struct intc_handle_int *hp,
  					     unsigned int nr_hp,
  					     unsigned int irq)
  {
  	int i;
  
  	/*
  	 * this doesn't scale well, but...
  	 *
  	 * this function should only be used for cerain uncommon
  	 * operations such as intc_set_priority() and intc_set_type()
  	 * and in those rare cases performance doesn't matter that much.
  	 * keeping the memory footprint low is more important.
  	 *
  	 * one rather simple way to speed this up and still keep the
  	 * memory footprint down is to make sure the array is sorted
  	 * and then perform a bisect to lookup the irq.
  	 */
  	for (i = 0; i < nr_hp; i++) {
  		if ((hp + i)->irq != irq)
  			continue;
  
  		return hp + i;
  	}
  
  	return NULL;
  }
  
  int intc_set_priority(unsigned int irq, unsigned int prio)
  {
  	struct intc_desc_int *d = get_intc_desc(irq);
26599a94d   Paul Mundt   sh: intc: irq_dat...
145
  	struct irq_data *data = irq_get_irq_data(irq);
2be6bb0c7   Paul Mundt   sh: intc: Split u...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  	struct intc_handle_int *ihp;
  
  	if (!intc_get_prio_level(irq) || prio <= 1)
  		return -EINVAL;
  
  	ihp = intc_find_irq(d->prio, d->nr_prio, irq);
  	if (ihp) {
  		if (prio >= (1 << _INTC_WIDTH(ihp->handle)))
  			return -EINVAL;
  
  		intc_set_prio_level(irq, prio);
  
  		/*
  		 * only set secondary masking method directly
  		 * primary masking method is using intc_prio_level[irq]
  		 * priority level will be set during next enable()
  		 */
  		if (_INTC_FN(ihp->handle) != REG_FN_ERR)
26599a94d   Paul Mundt   sh: intc: irq_dat...
164
  			_intc_enable(data, ihp->handle);
2be6bb0c7   Paul Mundt   sh: intc: Split u...
165
166
167
  	}
  	return 0;
  }
8a5a77866   Magnus Damm   sh: update INTC t...
168
169
  #define SENSE_VALID_FLAG 0x80
  #define VALID(x) (x | SENSE_VALID_FLAG)
2be6bb0c7   Paul Mundt   sh: intc: Split u...
170
171
172
173
174
175
176
177
178
179
180
  
  static unsigned char intc_irq_sense_table[IRQ_TYPE_SENSE_MASK + 1] = {
  	[IRQ_TYPE_EDGE_FALLING] = VALID(0),
  	[IRQ_TYPE_EDGE_RISING] = VALID(1),
  	[IRQ_TYPE_LEVEL_LOW] = VALID(2),
  	/* SH7706, SH7707 and SH7709 do not support high level triggered */
  #if !defined(CONFIG_CPU_SUBTYPE_SH7706) && \
      !defined(CONFIG_CPU_SUBTYPE_SH7707) && \
      !defined(CONFIG_CPU_SUBTYPE_SH7709)
  	[IRQ_TYPE_LEVEL_HIGH] = VALID(3),
  #endif
7d377b170   Magnus Damm   sh: intc: Allow t...
181
  #if defined(CONFIG_ARM) /* all recent SH-Mobile / R-Mobile ARM support this */
9a14a92c9   Magnus Damm   sh: intc: enable ...
182
183
  	[IRQ_TYPE_EDGE_BOTH] = VALID(4),
  #endif
2be6bb0c7   Paul Mundt   sh: intc: Split u...
184
  };
26599a94d   Paul Mundt   sh: intc: irq_dat...
185
  static int intc_set_type(struct irq_data *data, unsigned int type)
2be6bb0c7   Paul Mundt   sh: intc: Split u...
186
  {
26599a94d   Paul Mundt   sh: intc: irq_dat...
187
  	unsigned int irq = data->irq;
2be6bb0c7   Paul Mundt   sh: intc: Split u...
188
189
190
191
192
193
194
  	struct intc_desc_int *d = get_intc_desc(irq);
  	unsigned char value = intc_irq_sense_table[type & IRQ_TYPE_SENSE_MASK];
  	struct intc_handle_int *ihp;
  	unsigned long addr;
  
  	if (!value)
  		return -EINVAL;
52e3124f2   Magnus Damm   sh: intc: Add IRQ...
195
  	value &= ~SENSE_VALID_FLAG;
2be6bb0c7   Paul Mundt   sh: intc: Split u...
196
197
  	ihp = intc_find_irq(d->sense, d->nr_sense, irq);
  	if (ihp) {
52e3124f2   Magnus Damm   sh: intc: Add IRQ...
198
199
200
  		/* PINT has 2-bit sense registers, should fail on EDGE_BOTH */
  		if (value >= (1 << _INTC_WIDTH(ihp->handle)))
  			return -EINVAL;
2be6bb0c7   Paul Mundt   sh: intc: Split u...
201
  		addr = INTC_REG(d, _INTC_ADDR_E(ihp->handle), 0);
52e3124f2   Magnus Damm   sh: intc: Add IRQ...
202
  		intc_reg_fns[_INTC_FN(ihp->handle)](addr, ihp->handle, value);
2be6bb0c7   Paul Mundt   sh: intc: Split u...
203
204
205
206
207
208
  	}
  
  	return 0;
  }
  
  struct irq_chip intc_irq_chip	= {
26599a94d   Paul Mundt   sh: intc: irq_dat...
209
210
211
212
213
214
215
216
  	.irq_mask		= intc_disable,
  	.irq_unmask		= intc_enable,
  	.irq_mask_ack		= intc_mask_ack,
  	.irq_enable		= intc_enable,
  	.irq_disable		= intc_disable,
  	.irq_shutdown		= intc_disable,
  	.irq_set_type		= intc_set_type,
  	.irq_set_wake		= intc_set_wake,
2be6bb0c7   Paul Mundt   sh: intc: Split u...
217
  #ifdef CONFIG_SMP
26599a94d   Paul Mundt   sh: intc: irq_dat...
218
  	.irq_set_affinity	= intc_set_affinity,
2be6bb0c7   Paul Mundt   sh: intc: Split u...
219
220
  #endif
  };