1 From e1828438bbdd0623cf7f9c6672f2fe65b1349aa6 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sat, 24 Apr 2010 17:35:05 +0200
4 Subject: [PATCH] Add JZ4740 SoC core support
7 arch/mips/Kconfig | 4 +
8 arch/mips/Makefile | 6 +
9 arch/mips/include/asm/bootinfo.h | 6 +
10 arch/mips/include/asm/cpu.h | 13 +-
11 arch/mips/include/asm/mach-jz4740/base.h | 28 +
12 arch/mips/include/asm/mach-jz4740/clock.h | 28 +
13 arch/mips/include/asm/mach-jz4740/dma.h | 90 +++
14 arch/mips/include/asm/mach-jz4740/gpio.h | 398 +++++++++++
15 arch/mips/include/asm/mach-jz4740/irq.h | 55 ++
16 arch/mips/include/asm/mach-jz4740/platform.h | 34 +
17 arch/mips/include/asm/mach-jz4740/serial.h | 30 +
18 arch/mips/include/asm/mach-jz4740/timer.h | 22 +
19 arch/mips/include/asm/mach-jz4740/war.h | 25 +
20 arch/mips/jz4740/Kconfig | 29 +
21 arch/mips/jz4740/Makefile | 18 +
22 arch/mips/jz4740/clock-debugfs.c | 109 +++
23 arch/mips/jz4740/clock.c | 935 ++++++++++++++++++++++++++
24 arch/mips/jz4740/clock.h | 75 ++
25 arch/mips/jz4740/dma.c | 336 +++++++++
26 arch/mips/jz4740/gpio.c | 598 ++++++++++++++++
27 arch/mips/jz4740/irq.c | 170 +++++
28 arch/mips/jz4740/irq.h | 21 +
29 arch/mips/jz4740/platform.c | 246 +++++++
30 arch/mips/jz4740/pm.c | 59 ++
31 arch/mips/jz4740/prom.c | 69 ++
32 arch/mips/jz4740/pwm.c | 167 +++++
33 arch/mips/jz4740/reset.c | 81 +++
34 arch/mips/jz4740/reset.h | 7 +
35 arch/mips/jz4740/setup.c | 64 ++
36 arch/mips/jz4740/time.c | 144 ++++
37 arch/mips/jz4740/timer.c | 48 ++
38 arch/mips/jz4740/timer.h | 130 ++++
39 arch/mips/kernel/cpu-probe.c | 20 +
40 arch/mips/mm/tlbex.c | 5 +
41 34 files changed, 4069 insertions(+), 1 deletions(-)
42 create mode 100644 arch/mips/include/asm/mach-jz4740/base.h
43 create mode 100644 arch/mips/include/asm/mach-jz4740/clock.h
44 create mode 100644 arch/mips/include/asm/mach-jz4740/dma.h
45 create mode 100644 arch/mips/include/asm/mach-jz4740/gpio.h
46 create mode 100644 arch/mips/include/asm/mach-jz4740/irq.h
47 create mode 100644 arch/mips/include/asm/mach-jz4740/platform.h
48 create mode 100644 arch/mips/include/asm/mach-jz4740/serial.h
49 create mode 100644 arch/mips/include/asm/mach-jz4740/timer.h
50 create mode 100644 arch/mips/include/asm/mach-jz4740/war.h
51 create mode 100644 arch/mips/jz4740/Kconfig
52 create mode 100644 arch/mips/jz4740/Makefile
53 create mode 100644 arch/mips/jz4740/clock-debugfs.c
54 create mode 100644 arch/mips/jz4740/clock.c
55 create mode 100644 arch/mips/jz4740/clock.h
56 create mode 100644 arch/mips/jz4740/dma.c
57 create mode 100644 arch/mips/jz4740/gpio.c
58 create mode 100644 arch/mips/jz4740/irq.c
59 create mode 100644 arch/mips/jz4740/irq.h
60 create mode 100644 arch/mips/jz4740/platform.c
61 create mode 100644 arch/mips/jz4740/pm.c
62 create mode 100644 arch/mips/jz4740/prom.c
63 create mode 100644 arch/mips/jz4740/pwm.c
64 create mode 100644 arch/mips/jz4740/reset.c
65 create mode 100644 arch/mips/jz4740/reset.h
66 create mode 100644 arch/mips/jz4740/setup.c
67 create mode 100644 arch/mips/jz4740/time.c
68 create mode 100644 arch/mips/jz4740/timer.c
69 create mode 100644 arch/mips/jz4740/timer.h
71 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
72 index 7e6fd1c..e902f02 100644
73 --- a/arch/mips/Kconfig
74 +++ b/arch/mips/Kconfig
75 @@ -162,6 +162,9 @@ config MACH_JAZZ
76 Members include the Acer PICA, MIPS Magnum 4000, MIPS Millennium and
77 Olivetti M700-10 workstations.
80 + bool "Ingenic JZ4720/JZ4740 based machines"
83 bool "LASAT Networks platforms"
85 @@ -686,6 +689,7 @@ endchoice
86 source "arch/mips/alchemy/Kconfig"
87 source "arch/mips/bcm63xx/Kconfig"
88 source "arch/mips/jazz/Kconfig"
89 +source "arch/mips/jz4740/Kconfig"
90 source "arch/mips/lasat/Kconfig"
91 source "arch/mips/pmc-sierra/Kconfig"
92 source "arch/mips/powertv/Kconfig"
93 diff --git a/arch/mips/Makefile b/arch/mips/Makefile
94 index 0b9c01a..007a82e 100644
95 --- a/arch/mips/Makefile
96 +++ b/arch/mips/Makefile
97 @@ -659,6 +659,12 @@ else
98 load-$(CONFIG_CPU_CAVIUM_OCTEON) += 0xffffffff81100000
103 +core-$(CONFIG_SOC_JZ4740) += arch/mips/jz4740/
104 +cflags-$(CONFIG_SOC_JZ4740) += -I$(srctree)/arch/mips/include/asm/mach-jz4740
105 +load-$(CONFIG_SOC_JZ4740) += 0xffffffff80010000
107 cflags-y += -I$(srctree)/arch/mips/include/asm/mach-generic
108 drivers-$(CONFIG_PCI) += arch/mips/pci/
110 diff --git a/arch/mips/include/asm/bootinfo.h b/arch/mips/include/asm/bootinfo.h
111 index 09eee09..15a8ef0 100644
112 --- a/arch/mips/include/asm/bootinfo.h
113 +++ b/arch/mips/include/asm/bootinfo.h
115 #define MACH_LEMOTE_LL2F 7
116 #define MACH_LOONGSON_END 8
119 + * Valid machtype for group INGENIC
121 +#define MACH_INGENIC_JZ4730 0 /* JZ4730 SOC */
122 +#define MACH_INGENIC_JZ4740 1 /* JZ4740 SOC */
124 extern char *system_type;
125 const char *get_system_type(void);
127 diff --git a/arch/mips/include/asm/cpu.h b/arch/mips/include/asm/cpu.h
128 index a5acda4..e67aebb 100644
129 --- a/arch/mips/include/asm/cpu.h
130 +++ b/arch/mips/include/asm/cpu.h
132 #define PRID_COMP_LSI 0x080000
133 #define PRID_COMP_LEXRA 0x0b0000
134 #define PRID_COMP_CAVIUM 0x0d0000
136 +#define PRID_COMP_INGENIC 0xd00000
139 * Assigned values for the product ID register. In order to detect a
141 #define PRID_IMP_CAVIUM_CN52XX 0x0700
144 + * These are the PRID's for when 23:16 == PRID_COMP_INGENIC
147 +#define PRID_IMP_JZRISC 0x0200
150 * Definitions for 7:0 on legacy processors
153 @@ -226,6 +232,11 @@ enum cpu_type_enum {
154 CPU_5KC, CPU_20KC, CPU_25KF, CPU_SB1, CPU_SB1A, CPU_LOONGSON2,
155 CPU_CAVIUM_OCTEON, CPU_CAVIUM_OCTEON_PLUS,
158 + * Ingenic class processors
160 + CPU_JZRISC, CPU_XBURST,
165 diff --git a/arch/mips/include/asm/mach-jz4740/base.h b/arch/mips/include/asm/mach-jz4740/base.h
167 index 0000000..a281972
169 +++ b/arch/mips/include/asm/mach-jz4740/base.h
171 +#ifndef __JZ4740_BASE_ADDR_H__
172 +#define __JZ4740_BASE_ADDR_H__
174 +#define JZ4740_CPM_BASE_ADDR 0xb0000000
175 +#define JZ4740_INTC_BASE_ADDR 0xb0001000
176 +#define JZ4740_TCU_BASE_ADDR 0xb0002000
177 +#define JZ4740_WDT_BASE_ADDR 0xb0002000
178 +#define JZ4740_RTC_BASE_ADDR 0xb0003000
179 +#define JZ4740_GPIO_BASE_ADDR 0xb0010000
180 +#define JZ4740_AIC_BASE_ADDR 0xb0020000
181 +#define JZ4740_ICDC_BASE_ADDR 0xb0020000
182 +#define JZ4740_MSC_BASE_ADDR 0xb0021000
183 +#define JZ4740_UART0_BASE_ADDR 0xb0030000
184 +#define JZ4740_UART1_BASE_ADDR 0xb0031000
185 +#define JZ4740_I2C_BASE_ADDR 0xb0042000
186 +#define JZ4740_SSI_BASE_ADDR 0xb0043000
187 +#define JZ4740_SADC_BASE_ADDR 0xb0070000
188 +#define JZ4740_EMC_BASE_ADDR 0xb3010000
189 +#define JZ4740_DMAC_BASE_ADDR 0xb3020000
190 +#define JZ4740_UHC_BASE_ADDR 0xb3030000
191 +#define JZ4740_UDC_BASE_ADDR 0xb3040000
192 +#define JZ4740_LCD_BASE_ADDR 0xb3050000
193 +#define JZ4740_SLCD_BASE_ADDR 0xb3050000
194 +#define JZ4740_CIM_BASE_ADDR 0xb3060000
195 +#define JZ4740_IPU_BASE_ADDR 0xb3080000
196 +#define JZ4740_ETH_BASE_ADDR 0xb3100000
199 diff --git a/arch/mips/include/asm/mach-jz4740/clock.h b/arch/mips/include/asm/mach-jz4740/clock.h
201 index 0000000..9069727
203 +++ b/arch/mips/include/asm/mach-jz4740/clock.h
206 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
208 + * This program is free software; you can redistribute it and/or modify it
209 + * under the terms of the GNU General Public License as published by the
210 + * Free Software Foundation; either version 2 of the License, or (at your
211 + * option) any later version.
213 + * You should have received a copy of the GNU General Public License along
214 + * with this program; if not, write to the Free Software Foundation, Inc.,
215 + * 675 Mass Ave, Cambridge, MA 02139, USA.
219 +#ifndef __ASM_JZ4740_CLOCK_H__
220 +#define __ASM_JZ4740_CLOCK_H__
222 +enum jz4740_wait_mode {
223 + JZ4740_WAIT_MODE_IDLE,
224 + JZ4740_WAIT_MODE_SLEEP,
227 +void jz4740_clock_set_wait_mode(enum jz4740_wait_mode mode);
229 +void jz4740_clock_udc_enable_auto_suspend(void);
230 +void jz4740_clock_udc_disable_auto_suspend(void);
233 diff --git a/arch/mips/include/asm/mach-jz4740/dma.h b/arch/mips/include/asm/mach-jz4740/dma.h
235 index 0000000..bb7fc1e
237 +++ b/arch/mips/include/asm/mach-jz4740/dma.h
240 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
241 + * JZ7420/JZ4740 DMA definitions
243 + * This program is free software; you can redistribute it and/or modify it
244 + * under the terms of the GNU General Public License as published by the
245 + * Free Software Foundation; either version 2 of the License, or (at your
246 + * option) any later version.
248 + * You should have received a copy of the GNU General Public License along
249 + * with this program; if not, write to the Free Software Foundation, Inc.,
250 + * 675 Mass Ave, Cambridge, MA 02139, USA.
254 +#ifndef __ASM_MACH_JZ4740_DMA_H__
255 +#define __ASM_MACH_JZ4740_DMA_H__
257 +struct jz4740_dma_chan;
259 +enum jz4740_dma_request_type {
260 + JZ4740_DMA_TYPE_AUTO_REQUEST = 8,
261 + JZ4740_DMA_TYPE_UART_TRANSMIT = 20,
262 + JZ4740_DMA_TYPE_UART_RECEIVE = 21,
263 + JZ4740_DMA_TYPE_SPI_TRANSMIT = 22,
264 + JZ4740_DMA_TYPE_SPI_RECEIVE = 23,
265 + JZ4740_DMA_TYPE_AIC_TRANSMIT = 24,
266 + JZ4740_DMA_TYPE_AIC_RECEIVE = 25,
267 + JZ4740_DMA_TYPE_MMC_TRANSMIT = 26,
268 + JZ4740_DMA_TYPE_MMC_RECEIVE = 27,
269 + JZ4740_DMA_TYPE_TCU = 28,
270 + JZ4740_DMA_TYPE_SADC = 29,
271 + JZ4740_DMA_TYPE_SLCD = 30,
274 +enum jz4740_dma_width {
275 + JZ4740_DMA_WIDTH_32BIT = 0,
276 + JZ4740_DMA_WIDTH_8BIT = 1,
277 + JZ4740_DMA_WIDTH_16BIT = 2,
280 +enum jz4740_dma_transfer_size {
281 + JZ4740_DMA_TRANSFER_SIZE_4BYTE = 0,
282 + JZ4740_DMA_TRANSFER_SIZE_1BYTE = 1,
283 + JZ4740_DMA_TRANSFER_SIZE_2BYTE = 2,
284 + JZ4740_DMA_TRANSFER_SIZE_16BYTE = 3,
285 + JZ4740_DMA_TRANSFER_SIZE_32BYTE = 4,
288 +enum jz4740_dma_flags {
289 + JZ4740_DMA_SRC_AUTOINC = 0x2,
290 + JZ4740_DMA_DST_AUTOINC = 0x1,
293 +enum jz4740_dma_mode {
294 + JZ4740_DMA_MODE_SINGLE = 0,
295 + JZ4740_DMA_MODE_BLOCK = 1,
298 +struct jz4740_dma_config {
299 + enum jz4740_dma_width src_width;
300 + enum jz4740_dma_width dst_width;
301 + enum jz4740_dma_transfer_size transfer_size;
302 + enum jz4740_dma_request_type request_type;
303 + enum jz4740_dma_flags flags;
304 + enum jz4740_dma_mode mode;
307 +typedef void (*jz4740_dma_complete_callback_t)(struct jz4740_dma_chan *, int, void *);
309 +struct jz4740_dma_chan *jz4740_dma_request(void *dev, const char *name);
310 +void jz4740_dma_free(struct jz4740_dma_chan *dma);
312 +void jz4740_dma_configure(struct jz4740_dma_chan *dma,
313 + const struct jz4740_dma_config *config);
316 +void jz4740_dma_enable(struct jz4740_dma_chan *dma);
317 +void jz4740_dma_disable(struct jz4740_dma_chan *dma);
319 +void jz4740_dma_set_src_addr(struct jz4740_dma_chan *dma, dma_addr_t src);
320 +void jz4740_dma_set_dst_addr(struct jz4740_dma_chan *dma, dma_addr_t dst);
321 +void jz4740_dma_set_transfer_count(struct jz4740_dma_chan *dma, uint32_t count);
323 +uint32_t jz4740_dma_get_residue(const struct jz4740_dma_chan *dma);
325 +void jz4740_dma_set_complete_cb(struct jz4740_dma_chan *dma,
326 + jz4740_dma_complete_callback_t cb);
328 +#endif /* __ASM_JZ4740_DMA_H__ */
329 diff --git a/arch/mips/include/asm/mach-jz4740/gpio.h b/arch/mips/include/asm/mach-jz4740/gpio.h
331 index 0000000..5f175d7
333 +++ b/arch/mips/include/asm/mach-jz4740/gpio.h
336 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
337 + * JZ7420/JZ4740 GPIO pin definitions
339 + * This program is free software; you can redistribute it and/or modify it
340 + * under the terms of the GNU General Public License as published by the
341 + * Free Software Foundation; either version 2 of the License, or (at your
342 + * option) any later version.
344 + * You should have received a copy of the GNU General Public License along
345 + * with this program; if not, write to the Free Software Foundation, Inc.,
346 + * 675 Mass Ave, Cambridge, MA 02139, USA.
353 +#include <linux/types.h>
355 +enum jz_gpio_function {
364 + Usually a driver for a SoC component has to request several gpio pins and
365 + configure them as funcion pins.
366 + jz_gpio_bulk_request can be used to ease this process.
367 + Usually one would do something like:
369 + const static struct jz_gpio_bulk_request i2c_pins[] = {
370 + JZ_GPIO_BULK_PIN(I2C_SDA),
371 + JZ_GPIO_BULK_PIN(I2C_SCK),
374 + inside the probe function:
376 + ret = jz_gpio_bulk_request(i2c_pins, ARRAY_SIZE(i2c_pins));
380 + inside the remove function:
382 + jz_gpio_bulk_free(i2c_pins, ARRAY_SIZE(i2c_pins));
386 +struct jz_gpio_bulk_request {
389 + enum jz_gpio_function function;
392 +#define JZ_GPIO_BULK_PIN(pin) { \
393 + .gpio = JZ_GPIO_ ## pin, \
395 + .function = JZ_GPIO_FUNC_ ## pin \
398 +int jz_gpio_bulk_request(const struct jz_gpio_bulk_request *request, size_t num);
399 +void jz_gpio_bulk_free(const struct jz_gpio_bulk_request *request, size_t num);
400 +void jz_gpio_bulk_suspend(const struct jz_gpio_bulk_request *request, size_t num);
401 +void jz_gpio_bulk_resume(const struct jz_gpio_bulk_request *request, size_t num);
402 +void jz_gpio_enable_pullup(unsigned gpio);
403 +void jz_gpio_disable_pullup(unsigned gpio);
404 +int jz_gpio_set_function(int gpio, enum jz_gpio_function function);
406 +int jz_gpio_port_direction_input(int port, uint32_t mask);
407 +int jz_gpio_port_direction_output(int port, uint32_t mask);
408 +void jz_gpio_port_set_value(int port, uint32_t value, uint32_t mask);
409 +uint32_t jz_gpio_port_get_value(int port, uint32_t mask);
411 +#include <asm/mach-generic/gpio.h>
413 +#define JZ_GPIO_PORTA(x) ((x) + 32 * 0)
414 +#define JZ_GPIO_PORTB(x) ((x) + 32 * 1)
415 +#define JZ_GPIO_PORTC(x) ((x) + 32 * 2)
416 +#define JZ_GPIO_PORTD(x) ((x) + 32 * 3)
418 +/* Port A function pins */
419 +#define JZ_GPIO_MEM_DATA0 JZ_GPIO_PORTA(0)
420 +#define JZ_GPIO_MEM_DATA1 JZ_GPIO_PORTA(1)
421 +#define JZ_GPIO_MEM_DATA2 JZ_GPIO_PORTA(2)
422 +#define JZ_GPIO_MEM_DATA3 JZ_GPIO_PORTA(3)
423 +#define JZ_GPIO_MEM_DATA4 JZ_GPIO_PORTA(4)
424 +#define JZ_GPIO_MEM_DATA5 JZ_GPIO_PORTA(5)
425 +#define JZ_GPIO_MEM_DATA6 JZ_GPIO_PORTA(6)
426 +#define JZ_GPIO_MEM_DATA7 JZ_GPIO_PORTA(7)
427 +#define JZ_GPIO_MEM_DATA8 JZ_GPIO_PORTA(8)
428 +#define JZ_GPIO_MEM_DATA9 JZ_GPIO_PORTA(9)
429 +#define JZ_GPIO_MEM_DATA10 JZ_GPIO_PORTA(10)
430 +#define JZ_GPIO_MEM_DATA11 JZ_GPIO_PORTA(11)
431 +#define JZ_GPIO_MEM_DATA12 JZ_GPIO_PORTA(12)
432 +#define JZ_GPIO_MEM_DATA13 JZ_GPIO_PORTA(13)
433 +#define JZ_GPIO_MEM_DATA14 JZ_GPIO_PORTA(14)
434 +#define JZ_GPIO_MEM_DATA15 JZ_GPIO_PORTA(15)
435 +#define JZ_GPIO_MEM_DATA16 JZ_GPIO_PORTA(16)
436 +#define JZ_GPIO_MEM_DATA17 JZ_GPIO_PORTA(17)
437 +#define JZ_GPIO_MEM_DATA18 JZ_GPIO_PORTA(18)
438 +#define JZ_GPIO_MEM_DATA19 JZ_GPIO_PORTA(19)
439 +#define JZ_GPIO_MEM_DATA20 JZ_GPIO_PORTA(20)
440 +#define JZ_GPIO_MEM_DATA21 JZ_GPIO_PORTA(21)
441 +#define JZ_GPIO_MEM_DATA22 JZ_GPIO_PORTA(22)
442 +#define JZ_GPIO_MEM_DATA23 JZ_GPIO_PORTA(23)
443 +#define JZ_GPIO_MEM_DATA24 JZ_GPIO_PORTA(24)
444 +#define JZ_GPIO_MEM_DATA25 JZ_GPIO_PORTA(25)
445 +#define JZ_GPIO_MEM_DATA26 JZ_GPIO_PORTA(26)
446 +#define JZ_GPIO_MEM_DATA27 JZ_GPIO_PORTA(27)
447 +#define JZ_GPIO_MEM_DATA28 JZ_GPIO_PORTA(28)
448 +#define JZ_GPIO_MEM_DATA29 JZ_GPIO_PORTA(29)
449 +#define JZ_GPIO_MEM_DATA30 JZ_GPIO_PORTA(30)
450 +#define JZ_GPIO_MEM_DATA31 JZ_GPIO_PORTA(31)
452 +#define JZ_GPIO_FUNC_MEM_DATA0 JZ_GPIO_FUNC1
453 +#define JZ_GPIO_FUNC_MEM_DATA1 JZ_GPIO_FUNC1
454 +#define JZ_GPIO_FUNC_MEM_DATA2 JZ_GPIO_FUNC1
455 +#define JZ_GPIO_FUNC_MEM_DATA3 JZ_GPIO_FUNC1
456 +#define JZ_GPIO_FUNC_MEM_DATA4 JZ_GPIO_FUNC1
457 +#define JZ_GPIO_FUNC_MEM_DATA5 JZ_GPIO_FUNC1
458 +#define JZ_GPIO_FUNC_MEM_DATA6 JZ_GPIO_FUNC1
459 +#define JZ_GPIO_FUNC_MEM_DATA7 JZ_GPIO_FUNC1
460 +#define JZ_GPIO_FUNC_MEM_DATA8 JZ_GPIO_FUNC1
461 +#define JZ_GPIO_FUNC_MEM_DATA9 JZ_GPIO_FUNC1
462 +#define JZ_GPIO_FUNC_MEM_DATA10 JZ_GPIO_FUNC1
463 +#define JZ_GPIO_FUNC_MEM_DATA11 JZ_GPIO_FUNC1
464 +#define JZ_GPIO_FUNC_MEM_DATA12 JZ_GPIO_FUNC1
465 +#define JZ_GPIO_FUNC_MEM_DATA13 JZ_GPIO_FUNC1
466 +#define JZ_GPIO_FUNC_MEM_DATA14 JZ_GPIO_FUNC1
467 +#define JZ_GPIO_FUNC_MEM_DATA15 JZ_GPIO_FUNC1
468 +#define JZ_GPIO_FUNC_MEM_DATA16 JZ_GPIO_FUNC1
469 +#define JZ_GPIO_FUNC_MEM_DATA17 JZ_GPIO_FUNC1
470 +#define JZ_GPIO_FUNC_MEM_DATA18 JZ_GPIO_FUNC1
471 +#define JZ_GPIO_FUNC_MEM_DATA19 JZ_GPIO_FUNC1
472 +#define JZ_GPIO_FUNC_MEM_DATA20 JZ_GPIO_FUNC1
473 +#define JZ_GPIO_FUNC_MEM_DATA21 JZ_GPIO_FUNC1
474 +#define JZ_GPIO_FUNC_MEM_DATA22 JZ_GPIO_FUNC1
475 +#define JZ_GPIO_FUNC_MEM_DATA23 JZ_GPIO_FUNC1
476 +#define JZ_GPIO_FUNC_MEM_DATA24 JZ_GPIO_FUNC1
477 +#define JZ_GPIO_FUNC_MEM_DATA25 JZ_GPIO_FUNC1
478 +#define JZ_GPIO_FUNC_MEM_DATA26 JZ_GPIO_FUNC1
479 +#define JZ_GPIO_FUNC_MEM_DATA27 JZ_GPIO_FUNC1
480 +#define JZ_GPIO_FUNC_MEM_DATA28 JZ_GPIO_FUNC1
481 +#define JZ_GPIO_FUNC_MEM_DATA29 JZ_GPIO_FUNC1
482 +#define JZ_GPIO_FUNC_MEM_DATA30 JZ_GPIO_FUNC1
483 +#define JZ_GPIO_FUNC_MEM_DATA31 JZ_GPIO_FUNC1
485 +/* Port B function pins */
486 +#define JZ_GPIO_MEM_ADDR0 JZ_GPIO_PORTB(0)
487 +#define JZ_GPIO_MEM_ADDR1 JZ_GPIO_PORTB(1)
488 +#define JZ_GPIO_MEM_ADDR2 JZ_GPIO_PORTB(2)
489 +#define JZ_GPIO_MEM_ADDR3 JZ_GPIO_PORTB(3)
490 +#define JZ_GPIO_MEM_ADDR4 JZ_GPIO_PORTB(4)
491 +#define JZ_GPIO_MEM_ADDR5 JZ_GPIO_PORTB(5)
492 +#define JZ_GPIO_MEM_ADDR6 JZ_GPIO_PORTB(6)
493 +#define JZ_GPIO_MEM_ADDR7 JZ_GPIO_PORTB(7)
494 +#define JZ_GPIO_MEM_ADDR8 JZ_GPIO_PORTB(8)
495 +#define JZ_GPIO_MEM_ADDR9 JZ_GPIO_PORTB(9)
496 +#define JZ_GPIO_MEM_ADDR10 JZ_GPIO_PORTB(10)
497 +#define JZ_GPIO_MEM_ADDR11 JZ_GPIO_PORTB(11)
498 +#define JZ_GPIO_MEM_ADDR12 JZ_GPIO_PORTB(12)
499 +#define JZ_GPIO_MEM_ADDR13 JZ_GPIO_PORTB(13)
500 +#define JZ_GPIO_MEM_ADDR14 JZ_GPIO_PORTB(14)
501 +#define JZ_GPIO_MEM_ADDR15 JZ_GPIO_PORTB(15)
502 +#define JZ_GPIO_MEM_ADDR16 JZ_GPIO_PORTB(16)
503 +#define JZ_GPIO_MEM_CLS JZ_GPIO_PORTB(17)
504 +#define JZ_GPIO_MEM_SPL JZ_GPIO_PORTB(18)
505 +#define JZ_GPIO_MEM_DCS JZ_GPIO_PORTB(19)
506 +#define JZ_GPIO_MEM_RAS JZ_GPIO_PORTB(20)
507 +#define JZ_GPIO_MEM_CAS JZ_GPIO_PORTB(21)
508 +#define JZ_GPIO_MEM_SDWE JZ_GPIO_PORTB(22)
509 +#define JZ_GPIO_MEM_CKE JZ_GPIO_PORTB(23)
510 +#define JZ_GPIO_MEM_CKO JZ_GPIO_PORTB(24)
511 +#define JZ_GPIO_MEM_CS0 JZ_GPIO_PORTB(25)
512 +#define JZ_GPIO_MEM_CS1 JZ_GPIO_PORTB(26)
513 +#define JZ_GPIO_MEM_CS2 JZ_GPIO_PORTB(27)
514 +#define JZ_GPIO_MEM_CS3 JZ_GPIO_PORTB(28)
515 +#define JZ_GPIO_MEM_RD JZ_GPIO_PORTB(29)
516 +#define JZ_GPIO_MEM_WR JZ_GPIO_PORTB(30)
517 +#define JZ_GPIO_MEM_WE0 JZ_GPIO_PORTB(31)
519 +#define JZ_GPIO_FUNC_MEM_ADDR0 JZ_GPIO_FUNC1
520 +#define JZ_GPIO_FUNC_MEM_ADDR1 JZ_GPIO_FUNC1
521 +#define JZ_GPIO_FUNC_MEM_ADDR2 JZ_GPIO_FUNC1
522 +#define JZ_GPIO_FUNC_MEM_ADDR3 JZ_GPIO_FUNC1
523 +#define JZ_GPIO_FUNC_MEM_ADDR4 JZ_GPIO_FUNC1
524 +#define JZ_GPIO_FUNC_MEM_ADDR5 JZ_GPIO_FUNC1
525 +#define JZ_GPIO_FUNC_MEM_ADDR6 JZ_GPIO_FUNC1
526 +#define JZ_GPIO_FUNC_MEM_ADDR7 JZ_GPIO_FUNC1
527 +#define JZ_GPIO_FUNC_MEM_ADDR8 JZ_GPIO_FUNC1
528 +#define JZ_GPIO_FUNC_MEM_ADDR9 JZ_GPIO_FUNC1
529 +#define JZ_GPIO_FUNC_MEM_ADDR10 JZ_GPIO_FUNC1
530 +#define JZ_GPIO_FUNC_MEM_ADDR11 JZ_GPIO_FUNC1
531 +#define JZ_GPIO_FUNC_MEM_ADDR12 JZ_GPIO_FUNC1
532 +#define JZ_GPIO_FUNC_MEM_ADDR13 JZ_GPIO_FUNC1
533 +#define JZ_GPIO_FUNC_MEM_ADDR14 JZ_GPIO_FUNC1
534 +#define JZ_GPIO_FUNC_MEM_ADDR15 JZ_GPIO_FUNC1
535 +#define JZ_GPIO_FUNC_MEM_ADDR16 JZ_GPIO_FUNC1
536 +#define JZ_GPIO_FUNC_MEM_CLS JZ_GPIO_FUNC1
537 +#define JZ_GPIO_FUNC_MEM_SPL JZ_GPIO_FUNC1
538 +#define JZ_GPIO_FUNC_MEM_DCS JZ_GPIO_FUNC1
539 +#define JZ_GPIO_FUNC_MEM_RAS JZ_GPIO_FUNC1
540 +#define JZ_GPIO_FUNC_MEM_CAS JZ_GPIO_FUNC1
541 +#define JZ_GPIO_FUNC_MEM_SDWE JZ_GPIO_FUNC1
542 +#define JZ_GPIO_FUNC_MEM_CKE JZ_GPIO_FUNC1
543 +#define JZ_GPIO_FUNC_MEM_CKO JZ_GPIO_FUNC1
544 +#define JZ_GPIO_FUNC_MEM_CS0 JZ_GPIO_FUNC1
545 +#define JZ_GPIO_FUNC_MEM_CS1 JZ_GPIO_FUNC1
546 +#define JZ_GPIO_FUNC_MEM_CS2 JZ_GPIO_FUNC1
547 +#define JZ_GPIO_FUNC_MEM_CS3 JZ_GPIO_FUNC1
548 +#define JZ_GPIO_FUNC_MEM_RD JZ_GPIO_FUNC1
549 +#define JZ_GPIO_FUNC_MEM_WR JZ_GPIO_FUNC1
550 +#define JZ_GPIO_FUNC_MEM_WE0 JZ_GPIO_FUNC1
553 +#define JZ_GPIO_MEM_ADDR21 JZ_GPIO_PORTB(17)
554 +#define JZ_GPIO_MEM_ADDR22 JZ_GPIO_PORTB(18)
556 +#define JZ_GPIO_FUNC_MEM_ADDR21 JZ_GPIO_FUNC2
557 +#define JZ_GPIO_FUNC_MEM_ADDR22 JZ_GPIO_FUNC2
559 +/* Port C function pins */
560 +#define JZ_GPIO_LCD_DATA0 JZ_GPIO_PORTC(0)
561 +#define JZ_GPIO_LCD_DATA1 JZ_GPIO_PORTC(1)
562 +#define JZ_GPIO_LCD_DATA2 JZ_GPIO_PORTC(2)
563 +#define JZ_GPIO_LCD_DATA3 JZ_GPIO_PORTC(3)
564 +#define JZ_GPIO_LCD_DATA4 JZ_GPIO_PORTC(4)
565 +#define JZ_GPIO_LCD_DATA5 JZ_GPIO_PORTC(5)
566 +#define JZ_GPIO_LCD_DATA6 JZ_GPIO_PORTC(6)
567 +#define JZ_GPIO_LCD_DATA7 JZ_GPIO_PORTC(7)
568 +#define JZ_GPIO_LCD_DATA8 JZ_GPIO_PORTC(8)
569 +#define JZ_GPIO_LCD_DATA9 JZ_GPIO_PORTC(9)
570 +#define JZ_GPIO_LCD_DATA10 JZ_GPIO_PORTC(10)
571 +#define JZ_GPIO_LCD_DATA11 JZ_GPIO_PORTC(11)
572 +#define JZ_GPIO_LCD_DATA12 JZ_GPIO_PORTC(12)
573 +#define JZ_GPIO_LCD_DATA13 JZ_GPIO_PORTC(13)
574 +#define JZ_GPIO_LCD_DATA14 JZ_GPIO_PORTC(14)
575 +#define JZ_GPIO_LCD_DATA15 JZ_GPIO_PORTC(15)
576 +#define JZ_GPIO_LCD_DATA16 JZ_GPIO_PORTC(16)
577 +#define JZ_GPIO_LCD_DATA17 JZ_GPIO_PORTC(17)
578 +#define JZ_GPIO_LCD_PCLK JZ_GPIO_PORTC(18)
579 +#define JZ_GPIO_LCD_HSYNC JZ_GPIO_PORTC(19)
580 +#define JZ_GPIO_LCD_VSYNC JZ_GPIO_PORTC(20)
581 +#define JZ_GPIO_LCD_DE JZ_GPIO_PORTC(21)
582 +#define JZ_GPIO_LCD_PS JZ_GPIO_PORTC(22)
583 +#define JZ_GPIO_LCD_REV JZ_GPIO_PORTC(23)
584 +#define JZ_GPIO_MEM_WE1 JZ_GPIO_PORTC(24)
585 +#define JZ_GPIO_MEM_WE2 JZ_GPIO_PORTC(25)
586 +#define JZ_GPIO_MEM_WE3 JZ_GPIO_PORTC(26)
587 +#define JZ_GPIO_MEM_WAIT JZ_GPIO_PORTC(27)
588 +#define JZ_GPIO_MEM_FRE JZ_GPIO_PORTC(28)
589 +#define JZ_GPIO_MEM_FWE JZ_GPIO_PORTC(29)
591 +#define JZ_GPIO_FUNC_LCD_DATA0 JZ_GPIO_FUNC1
592 +#define JZ_GPIO_FUNC_LCD_DATA1 JZ_GPIO_FUNC1
593 +#define JZ_GPIO_FUNC_LCD_DATA2 JZ_GPIO_FUNC1
594 +#define JZ_GPIO_FUNC_LCD_DATA3 JZ_GPIO_FUNC1
595 +#define JZ_GPIO_FUNC_LCD_DATA4 JZ_GPIO_FUNC1
596 +#define JZ_GPIO_FUNC_LCD_DATA5 JZ_GPIO_FUNC1
597 +#define JZ_GPIO_FUNC_LCD_DATA6 JZ_GPIO_FUNC1
598 +#define JZ_GPIO_FUNC_LCD_DATA7 JZ_GPIO_FUNC1
599 +#define JZ_GPIO_FUNC_LCD_DATA8 JZ_GPIO_FUNC1
600 +#define JZ_GPIO_FUNC_LCD_DATA9 JZ_GPIO_FUNC1
601 +#define JZ_GPIO_FUNC_LCD_DATA10 JZ_GPIO_FUNC1
602 +#define JZ_GPIO_FUNC_LCD_DATA11 JZ_GPIO_FUNC1
603 +#define JZ_GPIO_FUNC_LCD_DATA12 JZ_GPIO_FUNC1
604 +#define JZ_GPIO_FUNC_LCD_DATA13 JZ_GPIO_FUNC1
605 +#define JZ_GPIO_FUNC_LCD_DATA14 JZ_GPIO_FUNC1
606 +#define JZ_GPIO_FUNC_LCD_DATA15 JZ_GPIO_FUNC1
607 +#define JZ_GPIO_FUNC_LCD_DATA16 JZ_GPIO_FUNC1
608 +#define JZ_GPIO_FUNC_LCD_DATA17 JZ_GPIO_FUNC1
609 +#define JZ_GPIO_FUNC_LCD_PCLK JZ_GPIO_FUNC1
610 +#define JZ_GPIO_FUNC_LCD_VSYNC JZ_GPIO_FUNC1
611 +#define JZ_GPIO_FUNC_LCD_HSYNC JZ_GPIO_FUNC1
612 +#define JZ_GPIO_FUNC_LCD_DE JZ_GPIO_FUNC1
613 +#define JZ_GPIO_FUNC_LCD_PS JZ_GPIO_FUNC1
614 +#define JZ_GPIO_FUNC_LCD_REV JZ_GPIO_FUNC1
615 +#define JZ_GPIO_FUNC_MEM_WE1 JZ_GPIO_FUNC1
616 +#define JZ_GPIO_FUNC_MEM_WE2 JZ_GPIO_FUNC1
617 +#define JZ_GPIO_FUNC_MEM_WE3 JZ_GPIO_FUNC1
618 +#define JZ_GPIO_FUNC_MEM_WAIT JZ_GPIO_FUNC1
619 +#define JZ_GPIO_FUNC_MEM_FRE JZ_GPIO_FUNC1
620 +#define JZ_GPIO_FUNC_MEM_FWE JZ_GPIO_FUNC1
623 +#define JZ_GPIO_MEM_ADDR19 JZ_GPIO_PORTB(22)
624 +#define JZ_GPIO_MEM_ADDR20 JZ_GPIO_PORTB(23)
626 +#define JZ_GPIO_FUNC_MEM_ADDR19 JZ_GPIO_FUNC2
627 +#define JZ_GPIO_FUNC_MEM_ADDR20 JZ_GPIO_FUNC2
629 +/* Port D function pins */
630 +#define JZ_GPIO_CIM_DATA0 JZ_GPIO_PORTD(0)
631 +#define JZ_GPIO_CIM_DATA1 JZ_GPIO_PORTD(1)
632 +#define JZ_GPIO_CIM_DATA2 JZ_GPIO_PORTD(2)
633 +#define JZ_GPIO_CIM_DATA3 JZ_GPIO_PORTD(3)
634 +#define JZ_GPIO_CIM_DATA4 JZ_GPIO_PORTD(4)
635 +#define JZ_GPIO_CIM_DATA5 JZ_GPIO_PORTD(5)
636 +#define JZ_GPIO_CIM_DATA6 JZ_GPIO_PORTD(6)
637 +#define JZ_GPIO_CIM_DATA7 JZ_GPIO_PORTD(7)
638 +#define JZ_GPIO_MSC_CMD JZ_GPIO_PORTD(8)
639 +#define JZ_GPIO_MSC_CLK JZ_GPIO_PORTD(9)
640 +#define JZ_GPIO_MSC_DATA0 JZ_GPIO_PORTD(10)
641 +#define JZ_GPIO_MSC_DATA1 JZ_GPIO_PORTD(11)
642 +#define JZ_GPIO_MSC_DATA2 JZ_GPIO_PORTD(12)
643 +#define JZ_GPIO_MSC_DATA3 JZ_GPIO_PORTD(13)
644 +#define JZ_GPIO_CIM_MCLK JZ_GPIO_PORTD(14)
645 +#define JZ_GPIO_CIM_PCLK JZ_GPIO_PORTD(15)
646 +#define JZ_GPIO_CIM_VSYNC JZ_GPIO_PORTD(16)
647 +#define JZ_GPIO_CIM_HSYNC JZ_GPIO_PORTD(17)
648 +#define JZ_GPIO_SPI_CLK JZ_GPIO_PORTD(18)
649 +#define JZ_GPIO_SPI_CE0 JZ_GPIO_PORTD(19)
650 +#define JZ_GPIO_SPI_DT JZ_GPIO_PORTD(20)
651 +#define JZ_GPIO_SPI_DR JZ_GPIO_PORTD(21)
652 +#define JZ_GPIO_SPI_CE1 JZ_GPIO_PORTD(22)
653 +#define JZ_GPIO_PWM0 JZ_GPIO_PORTD(23)
654 +#define JZ_GPIO_PWM1 JZ_GPIO_PORTD(24)
655 +#define JZ_GPIO_PWM2 JZ_GPIO_PORTD(25)
656 +#define JZ_GPIO_PWM3 JZ_GPIO_PORTD(26)
657 +#define JZ_GPIO_PWM4 JZ_GPIO_PORTD(27)
658 +#define JZ_GPIO_PWM5 JZ_GPIO_PORTD(28)
659 +#define JZ_GPIO_PWM6 JZ_GPIO_PORTD(30)
660 +#define JZ_GPIO_PWM7 JZ_GPIO_PORTD(31)
662 +#define JZ_GPIO_FUNC_CIM_DATA JZ_GPIO_FUNC1
663 +#define JZ_GPIO_FUNC_CIM_DATA0 JZ_GPIO_FUNC_CIM_DATA
664 +#define JZ_GPIO_FUNC_CIM_DATA1 JZ_GPIO_FUNC_CIM_DATA
665 +#define JZ_GPIO_FUNC_CIM_DATA2 JZ_GPIO_FUNC_CIM_DATA
666 +#define JZ_GPIO_FUNC_CIM_DATA3 JZ_GPIO_FUNC_CIM_DATA
667 +#define JZ_GPIO_FUNC_CIM_DATA4 JZ_GPIO_FUNC_CIM_DATA
668 +#define JZ_GPIO_FUNC_CIM_DATA5 JZ_GPIO_FUNC_CIM_DATA
669 +#define JZ_GPIO_FUNC_CIM_DATA6 JZ_GPIO_FUNC_CIM_DATA
670 +#define JZ_GPIO_FUNC_CIM_DATA7 JZ_GPIO_FUNC_CIM_DATA
671 +#define JZ_GPIO_FUNC_MSC_CMD JZ_GPIO_FUNC1
672 +#define JZ_GPIO_FUNC_MSC_CLK JZ_GPIO_FUNC1
673 +#define JZ_GPIO_FUNC_MSC_DATA JZ_GPIO_FUNC1
674 +#define JZ_GPIO_FUNC_MSC_DATA0 JZ_GPIO_FUNC_MSC_DATA
675 +#define JZ_GPIO_FUNC_MSC_DATA1 JZ_GPIO_FUNC_MSC_DATA
676 +#define JZ_GPIO_FUNC_MSC_DATA2 JZ_GPIO_FUNC_MSC_DATA
677 +#define JZ_GPIO_FUNC_MSC_DATA3 JZ_GPIO_FUNC_MSC_DATA
678 +#define JZ_GPIO_FUNC_CIM_MCLK JZ_GPIO_FUNC1
679 +#define JZ_GPIO_FUNC_CIM_PCLK JZ_GPIO_FUNC1
680 +#define JZ_GPIO_FUNC_CIM_VSYNC JZ_GPIO_FUNC1
681 +#define JZ_GPIO_FUNC_CIM_HSYNC JZ_GPIO_FUNC1
682 +#define JZ_GPIO_FUNC_SPI_CLK JZ_GPIO_FUNC1
683 +#define JZ_GPIO_FUNC_SPI_CE0 JZ_GPIO_FUNC1
684 +#define JZ_GPIO_FUNC_SPI_DT JZ_GPIO_FUNC1
685 +#define JZ_GPIO_FUNC_SPI_DR JZ_GPIO_FUNC1
686 +#define JZ_GPIO_FUNC_SPI_CE1 JZ_GPIO_FUNC1
688 +#define JZ_GPIO_FUNC_PWM JZ_GPIO_FUNC1
689 +#define JZ_GPIO_FUNC_PWM0 JZ_GPIO_FUNC_PWM
690 +#define JZ_GPIO_FUNC_PWM1 JZ_GPIO_FUNC_PWM
691 +#define JZ_GPIO_FUNC_PWM2 JZ_GPIO_FUNC_PWM
692 +#define JZ_GPIO_FUNC_PWM3 JZ_GPIO_FUNC_PWM
693 +#define JZ_GPIO_FUNC_PWM4 JZ_GPIO_FUNC_PWM
694 +#define JZ_GPIO_FUNC_PWM5 JZ_GPIO_FUNC_PWM
695 +#define JZ_GPIO_FUNC_PWM6 JZ_GPIO_FUNC_PWM
696 +#define JZ_GPIO_FUNC_PWM7 JZ_GPIO_FUNC_PWM
698 +#define JZ_GPIO_MEM_SCLK_RSTN JZ_GPIO_PORTD(18)
699 +#define JZ_GPIO_MEM_BCLK JZ_GPIO_PORTD(19)
700 +#define JZ_GPIO_MEM_SDATO JZ_GPIO_PORTD(20)
701 +#define JZ_GPIO_MEM_SDATI JZ_GPIO_PORTD(21)
702 +#define JZ_GPIO_MEM_SYNC JZ_GPIO_PORTD(22)
703 +#define JZ_GPIO_I2C_SDA JZ_GPIO_PORTD(23)
704 +#define JZ_GPIO_I2C_SCK JZ_GPIO_PORTD(24)
705 +#define JZ_GPIO_UART0_TXD JZ_GPIO_PORTD(25)
706 +#define JZ_GPIO_UART0_RXD JZ_GPIO_PORTD(26)
707 +#define JZ_GPIO_MEM_ADDR17 JZ_GPIO_PORTD(27)
708 +#define JZ_GPIO_MEM_ADDR18 JZ_GPIO_PORTD(28)
709 +#define JZ_GPIO_UART0_CTS JZ_GPIO_PORTD(30)
710 +#define JZ_GPIO_UART0_RTS JZ_GPIO_PORTD(31)
712 +#define JZ_GPIO_FUNC_MEM_SCLK_RSTN JZ_GPIO_FUNC2
713 +#define JZ_GPIO_FUNC_MEM_BCLK JZ_GPIO_FUNC2
714 +#define JZ_GPIO_FUNC_MEM_SDATO JZ_GPIO_FUNC2
715 +#define JZ_GPIO_FUNC_MEM_SDATI JZ_GPIO_FUNC2
716 +#define JZ_GPIO_FUNC_MEM_SYNC JZ_GPIO_FUNC2
717 +#define JZ_GPIO_FUNC_I2C_SDA JZ_GPIO_FUNC2
718 +#define JZ_GPIO_FUNC_I2C_SCK JZ_GPIO_FUNC2
719 +#define JZ_GPIO_FUNC_UART0_TXD JZ_GPIO_FUNC2
720 +#define JZ_GPIO_FUNC_UART0_RXD JZ_GPIO_FUNC2
721 +#define JZ_GPIO_FUNC_MEM_ADDR17 JZ_GPIO_FUNC2
722 +#define JZ_GPIO_FUNC_MEM_ADDR18 JZ_GPIO_FUNC2
723 +#define JZ_GPIO_FUNC_UART0_CTS JZ_GPIO_FUNC2
724 +#define JZ_GPIO_FUNC_UART0_RTS JZ_GPIO_FUNC2
726 +#define JZ_GPIO_UART1_RXD JZ_GPIO_PORTD(30)
727 +#define JZ_GPIO_UART1_TXD JZ_GPIO_PORTD(31)
729 +#define JZ_GPIO_FUNC_UART1_RXD JZ_GPIO_FUNC3
730 +#define JZ_GPIO_FUNC_UART1_TXD JZ_GPIO_FUNC3
733 diff --git a/arch/mips/include/asm/mach-jz4740/irq.h b/arch/mips/include/asm/mach-jz4740/irq.h
735 index 0000000..5e27b78
737 +++ b/arch/mips/include/asm/mach-jz4740/irq.h
740 + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
741 + * JZ7420/JZ4740 IRQ definitions
743 + * This program is free software; you can redistribute it and/or modify it
744 + * under the terms of the GNU General Public License as published by the
745 + * Free Software Foundation; either version 2 of the License, or (at your
746 + * option) any later version.
748 + * You should have received a copy of the GNU General Public License along
749 + * with this program; if not, write to the Free Software Foundation, Inc.,
750 + * 675 Mass Ave, Cambridge, MA 02139, USA.
754 +#ifndef __ASM_MACH_JZ4740_IRQ_H__
755 +#define __ASM_MACH_JZ4740_IRQ_H__
757 +#define MIPS_CPU_IRQ_BASE 0
758 +#define JZ4740_IRQ_BASE 8
760 +/* 1st-level interrupts */
761 +#define JZ4740_IRQ(x) (JZ4740_IRQ_BASE + (x))
762 +#define JZ4740_IRQ_I2C JZ4740_IRQ(1)
763 +#define JZ4740_IRQ_UHC JZ4740_IRQ(3)
764 +#define JZ4740_IRQ_UART1 JZ4740_IRQ(8)
765 +#define JZ4740_IRQ_UART0 JZ4740_IRQ(9)
766 +#define JZ4740_IRQ_SADC JZ4740_IRQ(12)
767 +#define JZ4740_IRQ_MSC JZ4740_IRQ(14)
768 +#define JZ4740_IRQ_RTC JZ4740_IRQ(15)
769 +#define JZ4740_IRQ_SSI JZ4740_IRQ(16)
770 +#define JZ4740_IRQ_CIM JZ4740_IRQ(17)
771 +#define JZ4740_IRQ_AIC JZ4740_IRQ(18)
772 +#define JZ4740_IRQ_ETH JZ4740_IRQ(19)
773 +#define JZ4740_IRQ_DMAC JZ4740_IRQ(20)
774 +#define JZ4740_IRQ_TCU2 JZ4740_IRQ(21)
775 +#define JZ4740_IRQ_TCU1 JZ4740_IRQ(22)
776 +#define JZ4740_IRQ_TCU0 JZ4740_IRQ(23)
777 +#define JZ4740_IRQ_UDC JZ4740_IRQ(24)
778 +#define JZ4740_IRQ_GPIO3 JZ4740_IRQ(25)
779 +#define JZ4740_IRQ_GPIO2 JZ4740_IRQ(26)
780 +#define JZ4740_IRQ_GPIO1 JZ4740_IRQ(27)
781 +#define JZ4740_IRQ_GPIO0 JZ4740_IRQ(28)
782 +#define JZ4740_IRQ_IPU JZ4740_IRQ(29)
783 +#define JZ4740_IRQ_LCD JZ4740_IRQ(30)
785 +/* 2nd-level interrupts */
786 +#define JZ4740_IRQ_DMA(x) ((x) + JZ4740_IRQ(32))
788 +#define JZ4740_IRQ_INTC_GPIO(x) (JZ4740_IRQ_GPIO0 - (x))
789 +#define JZ4740_IRQ_GPIO(x) (JZ4740_IRQ(48) + (x))
791 +#define NR_IRQS (JZ4740_IRQ_GPIO(127) + 1)
794 diff --git a/arch/mips/include/asm/mach-jz4740/platform.h b/arch/mips/include/asm/mach-jz4740/platform.h
796 index 0000000..a2e2871
798 +++ b/arch/mips/include/asm/mach-jz4740/platform.h
801 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
802 + * JZ7420/JZ4740 platform device definitions
804 + * This program is free software; you can redistribute it and/or modify it
805 + * under the terms of the GNU General Public License as published by the
806 + * Free Software Foundation; either version 2 of the License, or (at your
807 + * option) any later version.
809 + * You should have received a copy of the GNU General Public License along
810 + * with this program; if not, write to the Free Software Foundation, Inc.,
811 + * 675 Mass Ave, Cambridge, MA 02139, USA.
816 +#ifndef __JZ4740_PLATFORM_H
817 +#define __JZ4740_PLATFORM_H
819 +#include <linux/platform_device.h>
821 +extern struct platform_device jz4740_usb_ohci_device;
822 +extern struct platform_device jz4740_usb_gdt_device;
823 +extern struct platform_device jz4740_mmc_device;
824 +extern struct platform_device jz4740_rtc_device;
825 +extern struct platform_device jz4740_i2c_device;
826 +extern struct platform_device jz4740_nand_device;
827 +extern struct platform_device jz4740_framebuffer_device;
828 +extern struct platform_device jz4740_i2s_device;
829 +extern struct platform_device jz4740_codec_device;
830 +extern struct platform_device jz4740_adc_device;
831 +extern struct platform_device jz4740_battery_device;
834 diff --git a/arch/mips/include/asm/mach-jz4740/serial.h b/arch/mips/include/asm/mach-jz4740/serial.h
836 index 0000000..c4819b9
838 +++ b/arch/mips/include/asm/mach-jz4740/serial.h
841 + * linux/include/asm-mips/mach-jz4740/serial.h
843 + * Ingenic's JZ4740 common include.
845 + * Copyright (C) 2006 - 2007 Ingenic Semiconductor Inc.
847 + * Author: <yliu@ingenic.cn>
849 + * This program is free software; you can redistribute it and/or modify
850 + * it under the terms of the GNU General Public License version 2 as
851 + * published by the Free Software Foundation.
854 +#ifndef __ASM_BOARD_SERIAL_H__
855 +#define __ASM_BOARD_SERIAL_H__
857 +#ifndef CONFIG_SERIAL_MANY_PORTS
858 +#undef RS_TABLE_SIZE
859 +#define RS_TABLE_SIZE 1
862 +#define JZ_BASE_BAUD (12000000/16)
864 +#define JZ_SERIAL_PORT_DEFNS \
865 + { .baud_base = JZ_BASE_BAUD, .irq = IRQ_UART0, \
866 + .flags = STD_COM_FLAGS, .iomem_base = (u8 *)UART0_BASE, \
867 + .iomem_reg_shift = 2, .io_type = SERIAL_IO_MEM },
869 +#endif /* __ASM_BORAD_SERIAL_H__ */
870 diff --git a/arch/mips/include/asm/mach-jz4740/timer.h b/arch/mips/include/asm/mach-jz4740/timer.h
872 index 0000000..30153ff
874 +++ b/arch/mips/include/asm/mach-jz4740/timer.h
877 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
878 + * JZ4740 platform timer support
880 + * This program is free software; you can redistribute it and/or modify it
881 + * under the terms of the GNU General Public License as published by the
882 + * Free Software Foundation; either version 2 of the License, or (at your
883 + * option) any later version.
885 + * You should have received a copy of the GNU General Public License along
886 + * with this program; if not, write to the Free Software Foundation, Inc.,
887 + * 675 Mass Ave, Cambridge, MA 02139, USA.
891 +#ifndef __ASM_MACH_JZ4740_TIMER
892 +#define __ASM_MACH_JZ4740_TIMER
894 +void jz4740_timer_enable_watchdog(void);
895 +void jz4740_timer_disable_watchdog(void);
898 diff --git a/arch/mips/include/asm/mach-jz4740/war.h b/arch/mips/include/asm/mach-jz4740/war.h
900 index 0000000..3a5bc17
902 +++ b/arch/mips/include/asm/mach-jz4740/war.h
905 + * This file is subject to the terms and conditions of the GNU General Public
906 + * License. See the file "COPYING" in the main directory of this archive
907 + * for more details.
909 + * Copyright (C) 2002, 2004, 2007 by Ralf Baechle <ralf@linux-mips.org>
911 +#ifndef __ASM_MIPS_MACH_JZ4740_WAR_H
912 +#define __ASM_MIPS_MACH_JZ4740_WAR_H
914 +#define R4600_V1_INDEX_ICACHEOP_WAR 0
915 +#define R4600_V1_HIT_CACHEOP_WAR 0
916 +#define R4600_V2_HIT_CACHEOP_WAR 0
917 +#define R5432_CP0_INTERRUPT_WAR 0
918 +#define BCM1250_M3_WAR 0
919 +#define SIBYTE_1956_WAR 0
920 +#define MIPS4K_ICACHE_REFILL_WAR 0
921 +#define MIPS_CACHE_SYNC_WAR 0
922 +#define TX49XX_ICACHE_INDEX_INV_WAR 0
923 +#define RM9000_CDEX_SMP_WAR 0
924 +#define ICACHE_REFILLS_WORKAROUND_WAR 0
925 +#define R10000_LLSC_WAR 0
926 +#define MIPS34K_MISSED_ITLB_WAR 0
928 +#endif /* __ASM_MIPS_MACH_JZ4740_WAR_H */
929 diff --git a/arch/mips/jz4740/Kconfig b/arch/mips/jz4740/Kconfig
931 index 0000000..b959769
933 +++ b/arch/mips/jz4740/Kconfig
936 + prompt "Machine type"
938 + default JZ4740_QI_LB60
948 + select GENERIC_GPIO
949 + select ARCH_REQUIRE_GPIOLIB
950 + select SYS_HAS_EARLY_PRINTK
951 + select SYS_SUPPORTS_LITTLE_ENDIAN
953 + select DMA_NONCOHERENT
959 + select SYS_HAS_CPU_MIPS32_R1
960 + select SYS_SUPPORTS_32BIT_KERNEL
964 diff --git a/arch/mips/jz4740/Makefile b/arch/mips/jz4740/Makefile
966 index 0000000..398ee91
968 +++ b/arch/mips/jz4740/Makefile
971 +# Makefile for the Ingenic JZ4740.
974 +# Object file lists.
976 +obj-y += prom.o irq.o time.o reset.o setup.o dma.o \
977 + gpio.o clock.o platform.o timer.o pwm.o
979 +obj-$(CONFIG_DEBUG_FS) += clock-debugfs.o
981 +# board specific support
985 +obj-$(CONFIG_PM) += pm.o
987 +EXTRA_CFLAGS += -Werror -Wall
988 diff --git a/arch/mips/jz4740/clock-debugfs.c b/arch/mips/jz4740/clock-debugfs.c
990 index 0000000..993b91b
992 +++ b/arch/mips/jz4740/clock-debugfs.c
995 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
996 + * JZ4740 SoC clock support debugfs entries
998 + * This program is free software; you can redistribute it and/or modify it
999 + * under the terms of the GNU General Public License as published by the
1000 + * Free Software Foundation; either version 2 of the License, or (at your
1001 + * option) any later version.
1003 + * You should have received a copy of the GNU General Public License along
1004 + * with this program; if not, write to the Free Software Foundation, Inc.,
1005 + * 675 Mass Ave, Cambridge, MA 02139, USA.
1009 +#include <linux/kernel.h>
1010 +#include <linux/module.h>
1011 +#include <linux/clk.h>
1012 +#include <linux/err.h>
1014 +#include <linux/debugfs.h>
1015 +#include <linux/uaccess.h>
1017 +#include <asm/mach-jz4740/clock.h>
1020 +static struct dentry *jz4740_clock_debugfs;
1022 +static int jz4740_clock_debugfs_show_enabled(void *data, uint64_t *value)
1024 + struct clk *clk = data;
1025 + *value = clk_is_enabled(clk);
1030 +static int jz4740_clock_debugfs_set_enabled(void *data, uint64_t value)
1032 + struct clk *clk = data;
1035 + return clk_enable(clk);
1042 +DEFINE_SIMPLE_ATTRIBUTE(jz4740_clock_debugfs_ops_enabled,
1043 + jz4740_clock_debugfs_show_enabled,
1044 + jz4740_clock_debugfs_set_enabled,
1047 +static int jz4740_clock_debugfs_show_rate(void *data, uint64_t *value)
1049 + struct clk *clk = data;
1050 + *value = clk_get_rate(clk);
1055 +DEFINE_SIMPLE_ATTRIBUTE(jz4740_clock_debugfs_ops_rate,
1056 + jz4740_clock_debugfs_show_rate,
1060 +void jz4740_clock_debugfs_add_clk(struct clk *clk)
1062 + if (!jz4740_clock_debugfs)
1065 + clk->debugfs_entry = debugfs_create_dir(clk->name, jz4740_clock_debugfs);
1066 + debugfs_create_file("rate", S_IWUGO | S_IRUGO, clk->debugfs_entry, clk,
1067 + &jz4740_clock_debugfs_ops_rate);
1068 + debugfs_create_file("enabled", S_IRUGO, clk->debugfs_entry, clk,
1069 + &jz4740_clock_debugfs_ops_enabled);
1071 + if (clk->parent) {
1072 + char parent_path[100];
1073 + snprintf(parent_path, 100, "../%s", clk->parent->name);
1074 + clk->debugfs_parent_entry = debugfs_create_symlink("parent",
1075 + clk->debugfs_entry,
1080 +/* TODO: Locking */
1081 +void jz4740_clock_debugfs_update_parent(struct clk *clk)
1083 + if (clk->debugfs_parent_entry)
1084 + debugfs_remove(clk->debugfs_parent_entry);
1086 + if (clk->parent) {
1087 + char parent_path[100];
1088 + snprintf(parent_path, 100, "../%s", clk->parent->name);
1089 + clk->debugfs_parent_entry = debugfs_create_symlink("parent",
1090 + clk->debugfs_entry,
1093 + clk->debugfs_parent_entry = NULL;
1097 +void jz4740_clock_debugfs_init(void)
1099 + jz4740_clock_debugfs = debugfs_create_dir("jz4740-clock", NULL);
1100 + if (IS_ERR(jz4740_clock_debugfs))
1101 + jz4740_clock_debugfs = NULL;
1103 diff --git a/arch/mips/jz4740/clock.c b/arch/mips/jz4740/clock.c
1104 new file mode 100644
1105 index 0000000..df0d6d3
1107 +++ b/arch/mips/jz4740/clock.c
1110 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
1111 + * JZ4740 SoC clock support
1113 + * This program is free software; you can redistribute it and/or modify it
1114 + * under the terms of the GNU General Public License as published by the
1115 + * Free Software Foundation; either version 2 of the License, or (at your
1116 + * option) any later version.
1118 + * You should have received a copy of the GNU General Public License along
1119 + * with this program; if not, write to the Free Software Foundation, Inc.,
1120 + * 675 Mass Ave, Cambridge, MA 02139, USA.
1124 +#include <linux/kernel.h>
1125 +#include <linux/errno.h>
1126 +#include <linux/clk.h>
1127 +#include <linux/spinlock.h>
1128 +#include <linux/io.h>
1129 +#include <linux/module.h>
1130 +#include <linux/list.h>
1131 +#include <linux/err.h>
1133 +#include <asm/mach-jz4740/clock.h>
1134 +#include <asm/mach-jz4740/base.h>
1138 +#define JZ_REG_CLOCK_CTRL 0x00
1139 +#define JZ_REG_CLOCK_LOW_POWER 0x04
1140 +#define JZ_REG_CLOCK_PLL 0x10
1141 +#define JZ_REG_CLOCK_GATE 0x20
1142 +#define JZ_REG_CLOCK_SLEEP_CTRL 0x24
1143 +#define JZ_REG_CLOCK_I2S 0x60
1144 +#define JZ_REG_CLOCK_LCD 0x64
1145 +#define JZ_REG_CLOCK_MMC 0x68
1146 +#define JZ_REG_CLOCK_UHC 0x6C
1147 +#define JZ_REG_CLOCK_SPI 0x74
1149 +#define JZ_CLOCK_CTRL_I2S_SRC_PLL BIT(31)
1150 +#define JZ_CLOCK_CTRL_KO_ENABLE BIT(30)
1151 +#define JZ_CLOCK_CTRL_UDC_SRC_PLL BIT(29)
1152 +#define JZ_CLOCK_CTRL_UDIV_MASK 0x1f800000
1153 +#define JZ_CLOCK_CTRL_CHANGE_ENABLE BIT(22)
1154 +#define JZ_CLOCK_CTRL_PLL_HALF BIT(21)
1155 +#define JZ_CLOCK_CTRL_LDIV_MASK 0x001f0000
1156 +#define JZ_CLOCK_CTRL_UDIV_OFFSET 23
1157 +#define JZ_CLOCK_CTRL_LDIV_OFFSET 16
1158 +#define JZ_CLOCK_CTRL_MDIV_OFFSET 12
1159 +#define JZ_CLOCK_CTRL_PDIV_OFFSET 8
1160 +#define JZ_CLOCK_CTRL_HDIV_OFFSET 4
1161 +#define JZ_CLOCK_CTRL_CDIV_OFFSET 0
1163 +#define JZ_CLOCK_GATE_UART0 BIT(0)
1164 +#define JZ_CLOCK_GATE_TCU BIT(1)
1165 +#define JZ_CLOCK_GATE_RTC BIT(2)
1166 +#define JZ_CLOCK_GATE_I2C BIT(3)
1167 +#define JZ_CLOCK_GATE_SPI BIT(4)
1168 +#define JZ_CLOCK_GATE_AIC BIT(5)
1169 +#define JZ_CLOCK_GATE_I2S BIT(6)
1170 +#define JZ_CLOCK_GATE_MMC BIT(7)
1171 +#define JZ_CLOCK_GATE_ADC BIT(8)
1172 +#define JZ_CLOCK_GATE_CIM BIT(9)
1173 +#define JZ_CLOCK_GATE_LCD BIT(10)
1174 +#define JZ_CLOCK_GATE_UDC BIT(11)
1175 +#define JZ_CLOCK_GATE_DMAC BIT(12)
1176 +#define JZ_CLOCK_GATE_IPU BIT(13)
1177 +#define JZ_CLOCK_GATE_UHC BIT(14)
1178 +#define JZ_CLOCK_GATE_UART1 BIT(15)
1180 +#define JZ_CLOCK_I2S_DIV_MASK 0x01ff
1182 +#define JZ_CLOCK_LCD_DIV_MASK 0x01ff
1184 +#define JZ_CLOCK_MMC_DIV_MASK 0x001f
1186 +#define JZ_CLOCK_UHC_DIV_MASK 0x000f
1188 +#define JZ_CLOCK_SPI_SRC_PLL BIT(31)
1189 +#define JZ_CLOCK_SPI_DIV_MASK 0x000f
1191 +#define JZ_CLOCK_PLL_M_MASK 0x01ff
1192 +#define JZ_CLOCK_PLL_N_MASK 0x001f
1193 +#define JZ_CLOCK_PLL_OD_MASK 0x0003
1194 +#define JZ_CLOCK_PLL_STABLE BIT(10)
1195 +#define JZ_CLOCK_PLL_BYPASS BIT(9)
1196 +#define JZ_CLOCK_PLL_ENABLED BIT(8)
1197 +#define JZ_CLOCK_PLL_STABLIZE_MASK 0x000f
1198 +#define JZ_CLOCK_PLL_M_OFFSET 23
1199 +#define JZ_CLOCK_PLL_N_OFFSET 18
1200 +#define JZ_CLOCK_PLL_OD_OFFSET 16
1202 +#define JZ_CLOCK_LOW_POWER_MODE_DOZE BIT(2)
1203 +#define JZ_CLOCK_LOW_POWER_MODE_SLEEP BIT(0)
1205 +#define JZ_CLOCK_SLEEP_CTRL_SUSPEND_UHC BIT(7)
1206 +#define JZ_CLOCK_SLEEP_CTRL_ENABLE_UDC BIT(6)
1208 +static void __iomem *jz_clock_base;
1209 +static spinlock_t jz_clock_lock;
1210 +static LIST_HEAD(jz_clocks);
1214 + uint32_t div_offset;
1217 +struct divided_clk {
1223 +struct static_clk {
1225 + unsigned long rate;
1228 +static uint32_t jz_clk_reg_read(int reg)
1230 + return readl(jz_clock_base + reg);
1233 +static void jz_clk_reg_write_mask(int reg, uint32_t val, uint32_t mask)
1237 + spin_lock(&jz_clock_lock);
1238 + val2 = readl(jz_clock_base + reg);
1241 + writel(val2, jz_clock_base + reg);
1242 + spin_unlock(&jz_clock_lock);
1245 +static void jz_clk_reg_set_bits(int reg, uint32_t mask)
1249 + spin_lock(&jz_clock_lock);
1250 + val = readl(jz_clock_base + reg);
1252 + writel(val, jz_clock_base + reg);
1253 + spin_unlock(&jz_clock_lock);
1256 +static void jz_clk_reg_clear_bits(int reg, uint32_t mask)
1260 + spin_lock(&jz_clock_lock);
1261 + val = readl(jz_clock_base + reg);
1263 + writel(val, jz_clock_base + reg);
1264 + spin_unlock(&jz_clock_lock);
1267 +static int jz_clk_enable_gating(struct clk *clk)
1269 + if (clk->gate_bit == JZ4740_CLK_NOT_GATED)
1272 + jz_clk_reg_clear_bits(JZ_REG_CLOCK_GATE, clk->gate_bit);
1276 +static int jz_clk_disable_gating(struct clk *clk)
1278 + if (clk->gate_bit == JZ4740_CLK_NOT_GATED)
1281 + jz_clk_reg_set_bits(JZ_REG_CLOCK_GATE, clk->gate_bit);
1285 +static int jz_clk_is_enabled_gating(struct clk *clk)
1287 + if (clk->gate_bit == JZ4740_CLK_NOT_GATED)
1290 + return !(jz_clk_reg_read(JZ_REG_CLOCK_GATE) & clk->gate_bit);
1293 +static unsigned long jz_clk_static_get_rate(struct clk *clk)
1295 + return ((struct static_clk *)clk)->rate;
1298 +static int jz_clk_ko_enable(struct clk *clk)
1300 + jz_clk_reg_set_bits(JZ_REG_CLOCK_CTRL, JZ_CLOCK_CTRL_KO_ENABLE);
1304 +static int jz_clk_ko_disable(struct clk *clk)
1306 + jz_clk_reg_clear_bits(JZ_REG_CLOCK_CTRL, JZ_CLOCK_CTRL_KO_ENABLE);
1310 +static int jz_clk_ko_is_enabled(struct clk *clk)
1312 + return !!(jz_clk_reg_read(JZ_REG_CLOCK_CTRL) & JZ_CLOCK_CTRL_KO_ENABLE);
1315 +static const int pllno[] = {1, 2, 2, 4};
1317 +static unsigned long jz_clk_pll_get_rate(struct clk *clk)
1324 + val = jz_clk_reg_read(JZ_REG_CLOCK_PLL);
1326 + if (val & JZ_CLOCK_PLL_BYPASS)
1327 + return clk_get_rate(clk->parent);
1329 + m = ((val >> 23) & 0x1ff) + 2;
1330 + n = ((val >> 18) & 0x1f) + 2;
1331 + od = (val >> 16) & 0x3;
1333 + return clk_get_rate(clk->parent) * (m / n) / pllno[od];
1336 +static unsigned long jz_clk_pll_half_get_rate(struct clk *clk)
1340 + reg = jz_clk_reg_read(JZ_REG_CLOCK_CTRL);
1341 + if (reg & JZ_CLOCK_CTRL_PLL_HALF)
1342 + return jz_clk_pll_get_rate(clk->parent);
1343 + return jz_clk_pll_get_rate(clk->parent) >> 1;
1346 +static const int jz_clk_main_divs[] = {1, 2, 3, 4, 6, 8, 12, 16, 24, 32};
1348 +static unsigned long jz_clk_main_round_rate(struct clk *clk, unsigned long rate)
1350 + unsigned long parent_rate = jz_clk_pll_get_rate(clk->parent);
1353 + div = parent_rate / rate;
1355 + return parent_rate / 32;
1357 + return parent_rate;
1359 + div &= (0x3 << (ffs(div) - 1));
1361 + return parent_rate / div;
1364 +static unsigned long jz_clk_main_get_rate(struct clk *clk)
1366 + struct main_clk *mclk = (struct main_clk *)clk;
1369 + div = jz_clk_reg_read(JZ_REG_CLOCK_CTRL);
1371 + div >>= mclk->div_offset;
1374 + if (div >= ARRAY_SIZE(jz_clk_main_divs))
1375 + div = ARRAY_SIZE(jz_clk_main_divs) - 1;
1377 + return jz_clk_pll_get_rate(clk->parent) / jz_clk_main_divs[div];
1380 +static int jz_clk_main_set_rate(struct clk *clk, unsigned long rate)
1382 + struct main_clk *mclk = (struct main_clk *)clk;
1385 + unsigned long parent_rate = jz_clk_pll_get_rate(clk->parent);
1387 + rate = jz_clk_main_round_rate(clk, rate);
1389 + div = parent_rate / rate;
1391 + i = (ffs(div) - 1) << 1;
1392 + if (i > 0 && !(div & BIT(i-1)))
1395 + jz_clk_reg_write_mask(JZ_REG_CLOCK_CTRL, i << mclk->div_offset,
1396 + 0xf << mclk->div_offset);
1401 +static struct clk_ops jz_clk_static_ops = {
1402 + .get_rate = jz_clk_static_get_rate,
1403 + .enable = jz_clk_enable_gating,
1404 + .disable = jz_clk_disable_gating,
1405 + .is_enabled = jz_clk_is_enabled_gating,
1408 +static struct static_clk jz_clk_ext = {
1411 + .gate_bit = JZ4740_CLK_NOT_GATED,
1412 + .ops = &jz_clk_static_ops,
1416 +static struct clk_ops jz_clk_pll_ops = {
1417 + .get_rate = jz_clk_static_get_rate,
1420 +static struct clk jz_clk_pll = {
1422 + .parent = &jz_clk_ext.clk,
1423 + .ops = &jz_clk_pll_ops,
1426 +static struct clk_ops jz_clk_pll_half_ops = {
1427 + .get_rate = jz_clk_pll_half_get_rate,
1430 +static struct clk jz_clk_pll_half = {
1431 + .name = "pll half",
1432 + .parent = &jz_clk_pll,
1433 + .ops = &jz_clk_pll_half_ops,
1436 +static const struct clk_ops jz_clk_main_ops = {
1437 + .get_rate = jz_clk_main_get_rate,
1438 + .set_rate = jz_clk_main_set_rate,
1439 + .round_rate = jz_clk_main_round_rate,
1442 +static struct main_clk jz_clk_cpu = {
1445 + .parent = &jz_clk_pll,
1446 + .ops = &jz_clk_main_ops,
1448 + .div_offset = JZ_CLOCK_CTRL_CDIV_OFFSET,
1451 +static struct main_clk jz_clk_memory = {
1454 + .parent = &jz_clk_pll,
1455 + .ops = &jz_clk_main_ops,
1457 + .div_offset = JZ_CLOCK_CTRL_MDIV_OFFSET,
1460 +static struct main_clk jz_clk_high_speed_peripheral = {
1463 + .parent = &jz_clk_pll,
1464 + .ops = &jz_clk_main_ops,
1466 + .div_offset = JZ_CLOCK_CTRL_HDIV_OFFSET,
1470 +static struct main_clk jz_clk_low_speed_peripheral = {
1473 + .parent = &jz_clk_pll,
1474 + .ops = &jz_clk_main_ops,
1476 + .div_offset = JZ_CLOCK_CTRL_PDIV_OFFSET,
1479 +static const struct clk_ops jz_clk_ko_ops = {
1480 + .enable = jz_clk_ko_enable,
1481 + .disable = jz_clk_ko_disable,
1482 + .is_enabled = jz_clk_ko_is_enabled,
1485 +static struct clk jz_clk_ko = {
1487 + .parent = &jz_clk_memory.clk,
1488 + .ops = &jz_clk_ko_ops,
1491 +static int jz_clk_spi_set_parent(struct clk *clk, struct clk *parent)
1493 + if (parent == &jz_clk_pll)
1494 + jz_clk_reg_set_bits(JZ_CLOCK_SPI_SRC_PLL, JZ_REG_CLOCK_SPI);
1495 + else if (parent == &jz_clk_ext.clk)
1496 + jz_clk_reg_clear_bits(JZ_CLOCK_SPI_SRC_PLL, JZ_REG_CLOCK_SPI);
1500 + clk->parent = parent;
1505 +static int jz_clk_i2s_set_parent(struct clk *clk, struct clk *parent)
1507 + if (parent == &jz_clk_pll_half)
1508 + jz_clk_reg_set_bits(JZ_REG_CLOCK_CTRL, JZ_CLOCK_CTRL_I2S_SRC_PLL);
1509 + else if (parent == &jz_clk_ext.clk)
1510 + jz_clk_reg_clear_bits(JZ_REG_CLOCK_CTRL, JZ_CLOCK_CTRL_I2S_SRC_PLL);
1514 + clk->parent = parent;
1519 +static int jz_clk_udc_enable(struct clk *clk)
1521 + jz_clk_reg_set_bits(JZ_REG_CLOCK_SLEEP_CTRL,
1522 + JZ_CLOCK_SLEEP_CTRL_ENABLE_UDC);
1527 +static int jz_clk_udc_disable(struct clk *clk)
1529 + jz_clk_reg_clear_bits(JZ_REG_CLOCK_SLEEP_CTRL,
1530 + JZ_CLOCK_SLEEP_CTRL_ENABLE_UDC);
1535 +static int jz_clk_udc_is_enabled(struct clk *clk)
1537 + return !!(jz_clk_reg_read(JZ_REG_CLOCK_SLEEP_CTRL) &
1538 + JZ_CLOCK_SLEEP_CTRL_ENABLE_UDC);
1540 +static int jz_clk_udc_set_parent(struct clk *clk, struct clk *parent)
1542 + if (parent == &jz_clk_pll_half)
1543 + jz_clk_reg_set_bits(JZ_REG_CLOCK_CTRL, JZ_CLOCK_CTRL_UDC_SRC_PLL);
1544 + else if (parent == &jz_clk_ext.clk)
1545 + jz_clk_reg_clear_bits(JZ_REG_CLOCK_CTRL, JZ_CLOCK_CTRL_UDC_SRC_PLL);
1549 + clk->parent = parent;
1554 +static int jz_clk_udc_set_rate(struct clk *clk, unsigned long rate)
1558 + if (clk->parent == &jz_clk_ext.clk)
1561 + div = clk_get_rate(clk->parent) / rate - 1;
1565 + else if (div > 63)
1568 + jz_clk_reg_write_mask(JZ_REG_CLOCK_CTRL, div << JZ_CLOCK_CTRL_UDIV_OFFSET,
1569 + JZ_CLOCK_CTRL_UDIV_MASK);
1573 +static unsigned long jz_clk_udc_get_rate(struct clk *clk)
1577 + if (clk->parent == &jz_clk_ext.clk)
1578 + return clk_get_rate(clk->parent);
1580 + div = (jz_clk_reg_read(JZ_REG_CLOCK_CTRL) & JZ_CLOCK_CTRL_UDIV_MASK);
1581 + div >>= JZ_CLOCK_CTRL_UDIV_OFFSET;
1584 + return clk_get_rate(clk->parent) / div;
1587 +static unsigned long jz_clk_divided_get_rate(struct clk *clk)
1589 + struct divided_clk *dclk = (struct divided_clk *)clk;
1592 + if (clk->parent == &jz_clk_ext.clk)
1593 + return clk_get_rate(clk->parent);
1595 + div = (jz_clk_reg_read(dclk->reg) & dclk->mask) + 1;
1597 + return clk_get_rate(clk->parent) / div;
1600 +static int jz_clk_divided_set_rate(struct clk *clk, unsigned long rate)
1602 + struct divided_clk *dclk = (struct divided_clk *)clk;
1605 + if (clk->parent == &jz_clk_ext.clk)
1608 + div = clk_get_rate(clk->parent) / rate - 1;
1612 + else if (div > dclk->mask)
1615 + jz_clk_reg_write_mask(dclk->reg, div, dclk->mask);
1620 +static unsigned long jz_clk_ldclk_round_rate(struct clk *clk, unsigned long rate)
1623 + unsigned long parent_rate = jz_clk_pll_half_get_rate(clk->parent);
1625 + if (rate > 150000000)
1628 + div = parent_rate / rate;
1631 + else if (div > 32)
1634 + return parent_rate / div;
1637 +static int jz_clk_ldclk_set_rate(struct clk *clk, unsigned long rate)
1641 + if (rate > 150000000)
1644 + div = jz_clk_pll_half_get_rate(clk->parent) / rate - 1;
1647 + else if (div > 31)
1650 + jz_clk_reg_write_mask(JZ_REG_CLOCK_CTRL, div << JZ_CLOCK_CTRL_LDIV_OFFSET,
1651 + JZ_CLOCK_CTRL_LDIV_MASK);
1656 +static unsigned long jz_clk_ldclk_get_rate(struct clk *clk)
1660 + div = jz_clk_reg_read(JZ_REG_CLOCK_CTRL) & JZ_CLOCK_CTRL_LDIV_MASK;
1661 + div >>= JZ_CLOCK_CTRL_LDIV_OFFSET;
1663 + return jz_clk_pll_half_get_rate(clk->parent) / (div + 1);
1666 +static const struct clk_ops jz_clk_ops_ld = {
1667 + .set_rate = jz_clk_ldclk_set_rate,
1668 + .get_rate = jz_clk_ldclk_get_rate,
1669 + .round_rate = jz_clk_ldclk_round_rate,
1670 + .enable = jz_clk_enable_gating,
1671 + .disable = jz_clk_disable_gating,
1672 + .is_enabled = jz_clk_is_enabled_gating,
1675 +static struct clk jz_clk_ld = {
1677 + .gate_bit = JZ_CLOCK_GATE_LCD,
1678 + .parent = &jz_clk_pll_half,
1679 + .ops = &jz_clk_ops_ld,
1683 +static struct clk jz_clk_cim_mclk = {
1684 + .name = "cim_mclk",
1685 + .parent = &jz_clk_high_speed_peripheral.clk,
1688 +static struct static_clk jz_clk_cim_pclk = {
1690 + .name = "cim_pclk",
1691 + .gate_bit = JZ_CLOCK_GATE_CIM,
1692 + .ops = &jz_clk_static_ops,
1696 +static const struct clk_ops jz_clk_i2s_ops = {
1697 + .set_rate = jz_clk_divided_set_rate,
1698 + .get_rate = jz_clk_divided_get_rate,
1699 + .enable = jz_clk_enable_gating,
1700 + .disable = jz_clk_disable_gating,
1701 + .is_enabled = jz_clk_is_enabled_gating,
1702 + .set_parent = jz_clk_i2s_set_parent,
1705 +static const struct clk_ops jz_clk_spi_ops = {
1706 + .set_rate = jz_clk_divided_set_rate,
1707 + .get_rate = jz_clk_divided_get_rate,
1708 + .enable = jz_clk_enable_gating,
1709 + .disable = jz_clk_disable_gating,
1710 + .is_enabled = jz_clk_is_enabled_gating,
1711 + .set_parent = jz_clk_spi_set_parent,
1714 +static const struct clk_ops jz_clk_divided_ops = {
1715 + .set_rate = jz_clk_divided_set_rate,
1716 + .get_rate = jz_clk_divided_get_rate,
1717 + .enable = jz_clk_enable_gating,
1718 + .disable = jz_clk_disable_gating,
1719 + .is_enabled = jz_clk_is_enabled_gating,
1722 +static struct divided_clk jz4740_clock_divided_clks[] = {
1725 + .name = "lcd_pclk",
1726 + .parent = &jz_clk_pll_half,
1727 + .gate_bit = JZ4740_CLK_NOT_GATED,
1728 + .ops = &jz_clk_divided_ops,
1730 + .reg = JZ_REG_CLOCK_LCD,
1731 + .mask = JZ_CLOCK_LCD_DIV_MASK,
1736 + .parent = &jz_clk_ext.clk,
1737 + .gate_bit = JZ_CLOCK_GATE_I2S,
1738 + .ops = &jz_clk_i2s_ops,
1740 + .reg = JZ_REG_CLOCK_I2S,
1741 + .mask = JZ_CLOCK_I2S_DIV_MASK,
1746 + .parent = &jz_clk_ext.clk,
1747 + .gate_bit = JZ_CLOCK_GATE_SPI,
1748 + .ops = &jz_clk_spi_ops,
1750 + .reg = JZ_REG_CLOCK_SPI,
1751 + .mask = JZ_CLOCK_SPI_DIV_MASK,
1756 + .parent = &jz_clk_pll_half,
1757 + .gate_bit = JZ_CLOCK_GATE_MMC,
1758 + .ops = &jz_clk_divided_ops,
1760 + .reg = JZ_REG_CLOCK_MMC,
1761 + .mask = JZ_CLOCK_MMC_DIV_MASK,
1766 + .parent = &jz_clk_pll_half,
1767 + .gate_bit = JZ_CLOCK_GATE_UHC,
1768 + .ops = &jz_clk_divided_ops,
1770 + .reg = JZ_REG_CLOCK_UHC,
1771 + .mask = JZ_CLOCK_UHC_DIV_MASK,
1775 +static const struct clk_ops jz_clk_udc_ops = {
1776 + .set_parent = jz_clk_udc_set_parent,
1777 + .set_rate = jz_clk_udc_set_rate,
1778 + .get_rate = jz_clk_udc_get_rate,
1779 + .enable = jz_clk_udc_enable,
1780 + .disable = jz_clk_udc_disable,
1781 + .is_enabled = jz_clk_udc_is_enabled,
1784 +static const struct clk_ops jz_clk_simple_ops = {
1785 + .enable = jz_clk_enable_gating,
1786 + .disable = jz_clk_disable_gating,
1787 + .is_enabled = jz_clk_is_enabled_gating,
1790 +static struct clk jz4740_clock_simple_clks[] = {
1793 + .parent = &jz_clk_ext.clk,
1794 + .ops = &jz_clk_udc_ops,
1798 + .parent = &jz_clk_ext.clk,
1799 + .gate_bit = JZ_CLOCK_GATE_UART0,
1800 + .ops = &jz_clk_simple_ops,
1804 + .parent = &jz_clk_ext.clk,
1805 + .gate_bit = JZ_CLOCK_GATE_UART1,
1806 + .ops = &jz_clk_simple_ops,
1810 + .parent = &jz_clk_high_speed_peripheral.clk,
1811 + .gate_bit = JZ_CLOCK_GATE_UART0,
1812 + .ops = &jz_clk_simple_ops,
1816 + .parent = &jz_clk_high_speed_peripheral.clk,
1817 + .gate_bit = JZ_CLOCK_GATE_IPU,
1818 + .ops = &jz_clk_simple_ops,
1822 + .parent = &jz_clk_ext.clk,
1823 + .gate_bit = JZ_CLOCK_GATE_ADC,
1824 + .ops = &jz_clk_simple_ops,
1828 + .parent = &jz_clk_ext.clk,
1829 + .gate_bit = JZ_CLOCK_GATE_I2C,
1830 + .ops = &jz_clk_simple_ops,
1834 + .parent = &jz_clk_ext.clk,
1835 + .gate_bit = JZ_CLOCK_GATE_AIC,
1836 + .ops = &jz_clk_simple_ops,
1840 +static struct static_clk jz_clk_rtc = {
1843 + .gate_bit = JZ_CLOCK_GATE_RTC,
1844 + .ops = &jz_clk_static_ops,
1849 +int clk_enable(struct clk *clk)
1851 + if (!clk->ops->enable)
1854 + return clk->ops->enable(clk);
1856 +EXPORT_SYMBOL_GPL(clk_enable);
1858 +void clk_disable(struct clk *clk)
1860 + if (clk->ops->disable)
1861 + clk->ops->disable(clk);
1863 +EXPORT_SYMBOL_GPL(clk_disable);
1865 +int clk_is_enabled(struct clk *clk)
1867 + if (clk->ops->is_enabled)
1868 + return clk->ops->is_enabled(clk);
1873 +unsigned long clk_get_rate(struct clk *clk)
1875 + if (clk->ops->get_rate)
1876 + return clk->ops->get_rate(clk);
1878 + return clk_get_rate(clk->parent);
1882 +EXPORT_SYMBOL_GPL(clk_get_rate);
1884 +int clk_set_rate(struct clk *clk, unsigned long rate)
1886 + if (!clk->ops->set_rate)
1888 + return clk->ops->set_rate(clk, rate);
1890 +EXPORT_SYMBOL_GPL(clk_set_rate);
1892 +long clk_round_rate(struct clk *clk, unsigned long rate)
1894 + if (clk->ops->round_rate)
1895 + return clk->ops->round_rate(clk, rate);
1899 +EXPORT_SYMBOL_GPL(clk_round_rate);
1901 +int clk_set_parent(struct clk *clk, struct clk *parent)
1905 + if (!clk->ops->set_parent)
1909 + ret = clk->ops->set_parent(clk, parent);
1912 + jz4740_clock_debugfs_update_parent(clk);
1916 +EXPORT_SYMBOL_GPL(clk_set_parent);
1918 +struct clk *clk_get(struct device *dev, const char *name)
1922 + list_for_each_entry(clk, &jz_clocks, list) {
1923 + if (strcmp(clk->name, name) == 0)
1926 + return ERR_PTR(-ENOENT);
1928 +EXPORT_SYMBOL_GPL(clk_get);
1930 +void clk_put(struct clk *clk)
1933 +EXPORT_SYMBOL_GPL(clk_put);
1936 +static inline void clk_add(struct clk *clk)
1938 + list_add_tail(&clk->list, &jz_clocks);
1940 + jz4740_clock_debugfs_add_clk(clk);
1943 +static void clk_register_clks(void)
1947 + clk_add(&jz_clk_ext.clk);
1948 + clk_add(&jz_clk_pll);
1949 + clk_add(&jz_clk_pll_half);
1950 + clk_add(&jz_clk_cpu.clk);
1951 + clk_add(&jz_clk_high_speed_peripheral.clk);
1952 + clk_add(&jz_clk_low_speed_peripheral.clk);
1953 + clk_add(&jz_clk_ko);
1954 + clk_add(&jz_clk_ld);
1955 + clk_add(&jz_clk_cim_mclk);
1956 + clk_add(&jz_clk_cim_pclk.clk);
1957 + clk_add(&jz_clk_rtc.clk);
1959 + for (i = 0; i < ARRAY_SIZE(jz4740_clock_divided_clks); ++i)
1960 + clk_add(&jz4740_clock_divided_clks[i].clk);
1962 + for (i = 0; i < ARRAY_SIZE(jz4740_clock_simple_clks); ++i)
1963 + clk_add(&jz4740_clock_simple_clks[i]);
1966 +void jz4740_clock_set_wait_mode(enum jz4740_wait_mode mode)
1969 + case JZ4740_WAIT_MODE_IDLE:
1970 + jz_clk_reg_clear_bits(JZ_REG_CLOCK_LOW_POWER, JZ_CLOCK_LOW_POWER_MODE_SLEEP);
1972 + case JZ4740_WAIT_MODE_SLEEP:
1973 + jz_clk_reg_set_bits(JZ_REG_CLOCK_LOW_POWER, JZ_CLOCK_LOW_POWER_MODE_SLEEP);
1978 +void jz4740_clock_udc_disable_auto_suspend(void)
1980 + jz_clk_reg_clear_bits(JZ_REG_CLOCK_GATE, JZ_CLOCK_GATE_UDC);
1982 +EXPORT_SYMBOL_GPL(jz4740_clock_udc_disable_auto_suspend);
1984 +void jz4740_clock_udc_enable_auto_suspend(void)
1986 + jz_clk_reg_set_bits(JZ_REG_CLOCK_GATE, JZ_CLOCK_GATE_UDC);
1988 +EXPORT_SYMBOL_GPL(jz4740_clock_udc_enable_auto_suspend);
1990 +void jz4740_clock_suspend(void)
1992 + jz_clk_reg_set_bits(JZ_REG_CLOCK_GATE,
1993 + JZ_CLOCK_GATE_TCU | JZ_CLOCK_GATE_DMAC | JZ_CLOCK_GATE_UART0);
1995 + jz_clk_reg_clear_bits(JZ_REG_CLOCK_PLL, JZ_CLOCK_PLL_ENABLED);
1998 +void jz4740_clock_resume(void)
2002 + jz_clk_reg_set_bits(JZ_REG_CLOCK_PLL, JZ_CLOCK_PLL_ENABLED);
2005 + pll = jz_clk_reg_read(JZ_REG_CLOCK_PLL);
2006 + } while (!(pll & JZ_CLOCK_PLL_STABLE));
2008 + jz_clk_reg_clear_bits(JZ_REG_CLOCK_GATE,
2009 + JZ_CLOCK_GATE_TCU | JZ_CLOCK_GATE_DMAC | JZ_CLOCK_GATE_UART0);
2012 +int jz4740_clock_init(void)
2016 + jz_clock_base = ioremap(CPHYSADDR(JZ4740_CPM_BASE_ADDR), 0x100);
2017 + if (!jz_clock_base)
2020 + spin_lock_init(&jz_clock_lock);
2022 + jz_clk_ext.rate = jz4740_clock_bdata.ext_rate;
2023 + jz_clk_rtc.rate = jz4740_clock_bdata.rtc_rate;
2025 + val = jz_clk_reg_read(JZ_REG_CLOCK_SPI);
2027 + if (val & JZ_CLOCK_SPI_SRC_PLL)
2028 + jz4740_clock_divided_clks[1].clk.parent = &jz_clk_pll_half;
2030 + val = jz_clk_reg_read(JZ_REG_CLOCK_CTRL);
2032 + if (val & JZ_CLOCK_CTRL_I2S_SRC_PLL)
2033 + jz4740_clock_divided_clks[0].clk.parent = &jz_clk_pll_half;
2035 + if (val & JZ_CLOCK_CTRL_UDC_SRC_PLL)
2036 + jz4740_clock_simple_clks[0].parent = &jz_clk_pll_half;
2038 + jz4740_clock_debugfs_init();
2040 + clk_register_clks();
2044 diff --git a/arch/mips/jz4740/clock.h b/arch/mips/jz4740/clock.h
2045 new file mode 100644
2046 index 0000000..96010a4
2048 +++ b/arch/mips/jz4740/clock.h
2051 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
2052 + * JZ4740 SoC clock support
2054 + * This program is free software; you can redistribute it and/or modify it
2055 + * under the terms of the GNU General Public License as published by the
2056 + * Free Software Foundation; either version 2 of the License, or (at your
2057 + * option) any later version.
2059 + * You should have received a copy of the GNU General Public License along
2060 + * with this program; if not, write to the Free Software Foundation, Inc.,
2061 + * 675 Mass Ave, Cambridge, MA 02139, USA.
2065 +#ifndef __JZ4740_CLOCK_H__
2066 +#define __JZ4740_CLOCK_H__
2068 +struct jz4740_clock_board_data {
2069 + unsigned long ext_rate;
2070 + unsigned long rtc_rate;
2073 +extern struct jz4740_clock_board_data jz4740_clock_bdata;
2075 +int jz4740_clock_init(void);
2076 +void jz4740_clock_suspend(void);
2077 +void jz4740_clock_resume(void);
2082 + unsigned long (*get_rate)(struct clk *clk);
2083 + unsigned long (*round_rate)(struct clk *clk, unsigned long rate);
2084 + int (*set_rate)(struct clk *clk, unsigned long rate);
2085 + int (*enable)(struct clk *clk);
2086 + int (*disable)(struct clk *clk);
2087 + int (*is_enabled)(struct clk *clk);
2089 + int (*set_parent)(struct clk *clk, struct clk *parent);
2095 + struct clk *parent;
2097 + uint32_t gate_bit;
2099 + const struct clk_ops *ops;
2101 + struct list_head list;
2103 +#ifdef CONFIG_DEBUG_FS
2104 + struct dentry *debugfs_entry;
2105 + struct dentry *debugfs_parent_entry;
2110 +#define JZ4740_CLK_NOT_GATED ((uint32_t)-1)
2112 +int clk_is_enabled(struct clk *clk);
2114 +#ifdef CONFIG_DEBUG_FS
2115 +void jz4740_clock_debugfs_init(void);
2116 +void jz4740_clock_debugfs_add_clk(struct clk *clk);
2117 +void jz4740_clock_debugfs_update_parent(struct clk *clk);
2119 +static inline void jz4740_clock_debugfs_init(void) {};
2120 +static inline void jz4740_clock_debugfs_add_clk(struct clk *clk) {};
2121 +static inline void jz4740_clock_debugfs_update_parent(struct clk *clk) {};
2125 diff --git a/arch/mips/jz4740/dma.c b/arch/mips/jz4740/dma.c
2126 new file mode 100644
2127 index 0000000..b712afc
2129 +++ b/arch/mips/jz4740/dma.c
2132 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
2133 + * JZ4740 SoC DMA support
2135 + * This program is free software; you can redistribute it and/or modify it
2136 + * under the terms of the GNU General Public License as published by the
2137 + * Free Software Foundation; either version 2 of the License, or (at your
2138 + * option) any later version.
2140 + * You should have received a copy of the GNU General Public License along
2141 + * with this program; if not, write to the Free Software Foundation, Inc.,
2142 + * 675 Mass Ave, Cambridge, MA 02139, USA.
2146 +#include <linux/kernel.h>
2147 +#include <linux/module.h>
2148 +#include <linux/spinlock.h>
2149 +#include <linux/interrupt.h>
2151 +#include <linux/dma-mapping.h>
2152 +#include <asm/mach-jz4740/dma.h>
2153 +#include <asm/mach-jz4740/base.h>
2155 +#define JZ_REG_DMA_SRC_ADDR(x) (0x00 + (x) * 0x20)
2156 +#define JZ_REG_DMA_DST_ADDR(x) (0x04 + (x) * 0x20)
2157 +#define JZ_REG_DMA_TRANSFER_COUNT(x) (0x08 + (x) * 0x20)
2158 +#define JZ_REG_DMA_REQ_TYPE(x) (0x0C + (x) * 0x20)
2159 +#define JZ_REG_DMA_STATUS_CTRL(x) (0x10 + (x) * 0x20)
2160 +#define JZ_REG_DMA_CMD(x) (0x14 + (x) * 0x20)
2161 +#define JZ_REG_DMA_DESC_ADDR(x) (0x18 + (x) * 0x20)
2163 +#define JZ_REG_DMA_CTRL 0x300
2164 +#define JZ_REG_DMA_IRQ 0x304
2165 +#define JZ_REG_DMA_DOORBELL 0x308
2166 +#define JZ_REG_DMA_DOORBELL_SET 0x30C
2168 +#define JZ_DMA_STATUS_CTRL_NO_DESC BIT(31)
2169 +#define JZ_DMA_STATUS_CTRL_DESC_INV BIT(6)
2170 +#define JZ_DMA_STATUS_CTRL_ADDR_ERR BIT(4)
2171 +#define JZ_DMA_STATUS_CTRL_TRANSFER_DONE BIT(3)
2172 +#define JZ_DMA_STATUS_CTRL_HALT BIT(2)
2173 +#define JZ_DMA_STATUS_CTRL_COUNT_TERMINATE BIT(1)
2174 +#define JZ_DMA_STATUS_CTRL_ENABLE BIT(0)
2176 +#define JZ_DMA_CMD_SRC_INC BIT(23)
2177 +#define JZ_DMA_CMD_DST_INC BIT(22)
2178 +#define JZ_DMA_CMD_RDIL_MASK (0xf << 16)
2179 +#define JZ_DMA_CMD_SRC_WIDTH_MASK (0x3 << 14)
2180 +#define JZ_DMA_CMD_DST_WIDTH_MASK (0x3 << 12)
2181 +#define JZ_DMA_CMD_INTERVAL_LENGTH_MASK (0x7 << 8)
2182 +#define JZ_DMA_CMD_BLOCK_MODE BIT(7)
2183 +#define JZ_DMA_CMD_DESC_VALID BIT(4)
2184 +#define JZ_DMA_CMD_DESC_VALID_MODE BIT(3)
2185 +#define JZ_DMA_CMD_VALID_IRQ_ENABLE BIT(2)
2186 +#define JZ_DMA_CMD_TRANSFER_IRQ_ENABLE BIT(1)
2187 +#define JZ_DMA_CMD_LINK_ENABLE BIT(0)
2189 +#define JZ_DMA_CMD_FLAGS_OFFSET 22
2190 +#define JZ_DMA_CMD_RDIL_OFFSET 16
2191 +#define JZ_DMA_CMD_SRC_WIDTH_OFFSET 14
2192 +#define JZ_DMA_CMD_DST_WIDTH_OFFSET 12
2193 +#define JZ_DMA_CMD_TRANSFER_SIZE_OFFSET 8
2194 +#define JZ_DMA_CMD_MODE_OFFSET 7
2196 +#define JZ_DMA_CTRL_PRIORITY_MASK (0x3 << 8)
2197 +#define JZ_DMA_CTRL_HALT BIT(3)
2198 +#define JZ_DMA_CTRL_ADDRESS_ERROR BIT(2)
2199 +#define JZ_DMA_CTRL_ENABLE BIT(0)
2202 +static void __iomem *jz4740_dma_base;
2203 +static spinlock_t jz4740_dma_lock;
2205 +static inline uint32_t jz4740_dma_read(size_t reg)
2207 + return readl(jz4740_dma_base + reg);
2210 +static inline void jz4740_dma_write(size_t reg, uint32_t val)
2212 + writel(val, jz4740_dma_base + reg);
2215 +static inline void jz4740_dma_write_mask(size_t reg, uint32_t val, uint32_t mask)
2218 + val2 = jz4740_dma_read(reg);
2221 + jz4740_dma_write(reg, val2);
2224 +struct jz4740_dma_chan {
2229 + enum jz4740_dma_flags flags;
2230 + uint32_t transfer_shift;
2232 + jz4740_dma_complete_callback_t complete_cb;
2237 +#define JZ4740_DMA_CHANNEL(_id) { .id = _id }
2239 +struct jz4740_dma_chan jz4740_dma_channels[] = {
2240 + JZ4740_DMA_CHANNEL(0),
2241 + JZ4740_DMA_CHANNEL(1),
2242 + JZ4740_DMA_CHANNEL(2),
2243 + JZ4740_DMA_CHANNEL(3),
2244 + JZ4740_DMA_CHANNEL(4),
2245 + JZ4740_DMA_CHANNEL(5),
2248 +struct jz4740_dma_chan *jz4740_dma_request(void *dev, const char *name)
2251 + struct jz4740_dma_chan *dma = NULL;
2253 + spin_lock(&jz4740_dma_lock);
2255 + for (i = 0; i < ARRAY_SIZE(jz4740_dma_channels); ++i) {
2256 + if (!jz4740_dma_channels[i].used) {
2257 + dma = &jz4740_dma_channels[i];
2263 + spin_unlock(&jz4740_dma_lock);
2273 +EXPORT_SYMBOL_GPL(jz4740_dma_request);
2275 +void jz4740_dma_configure(struct jz4740_dma_chan *dma,
2276 + const struct jz4740_dma_config *config)
2280 + switch (config->transfer_size) {
2281 + case JZ4740_DMA_TRANSFER_SIZE_2BYTE:
2282 + dma->transfer_shift = 1;
2284 + case JZ4740_DMA_TRANSFER_SIZE_4BYTE:
2285 + dma->transfer_shift = 2;
2287 + case JZ4740_DMA_TRANSFER_SIZE_16BYTE:
2288 + dma->transfer_shift = 4;
2290 + case JZ4740_DMA_TRANSFER_SIZE_32BYTE:
2291 + dma->transfer_shift = 5;
2294 + dma->transfer_shift = 0;
2298 + cmd = config->flags << JZ_DMA_CMD_FLAGS_OFFSET;
2299 + cmd |= config->src_width << JZ_DMA_CMD_SRC_WIDTH_OFFSET;
2300 + cmd |= config->dst_width << JZ_DMA_CMD_DST_WIDTH_OFFSET;
2301 + cmd |= config->transfer_size << JZ_DMA_CMD_TRANSFER_SIZE_OFFSET;
2302 + cmd |= config->mode << JZ_DMA_CMD_MODE_OFFSET;
2303 + cmd |= JZ_DMA_CMD_TRANSFER_IRQ_ENABLE;
2305 + jz4740_dma_write(JZ_REG_DMA_CMD(dma->id), cmd);
2306 + jz4740_dma_write(JZ_REG_DMA_STATUS_CTRL(dma->id), 0);
2307 + jz4740_dma_write(JZ_REG_DMA_REQ_TYPE(dma->id), config->request_type);
2309 +EXPORT_SYMBOL_GPL(jz4740_dma_configure);
2311 +void jz4740_dma_set_src_addr(struct jz4740_dma_chan *dma, dma_addr_t src)
2313 + jz4740_dma_write(JZ_REG_DMA_SRC_ADDR(dma->id), src);
2315 +EXPORT_SYMBOL_GPL(jz4740_dma_set_src_addr);
2317 +void jz4740_dma_set_dst_addr(struct jz4740_dma_chan *dma, dma_addr_t dst)
2319 + jz4740_dma_write(JZ_REG_DMA_DST_ADDR(dma->id), dst);
2321 +EXPORT_SYMBOL_GPL(jz4740_dma_set_dst_addr);
2323 +void jz4740_dma_set_transfer_count(struct jz4740_dma_chan *dma, uint32_t count)
2325 + count >>= dma->transfer_shift;
2326 + jz4740_dma_write(JZ_REG_DMA_TRANSFER_COUNT(dma->id), count);
2328 +EXPORT_SYMBOL_GPL(jz4740_dma_set_transfer_count);
2330 +void jz4740_dma_set_complete_cb(struct jz4740_dma_chan *dma,
2331 + jz4740_dma_complete_callback_t cb)
2333 + dma->complete_cb = cb;
2335 +EXPORT_SYMBOL_GPL(jz4740_dma_set_complete_cb);
2337 +void jz4740_dma_free(struct jz4740_dma_chan *dma)
2340 + dma->complete_cb = NULL;
2343 +EXPORT_SYMBOL_GPL(jz4740_dma_free);
2345 +void jz4740_dma_enable(struct jz4740_dma_chan *dma)
2347 + jz4740_dma_write_mask(JZ_REG_DMA_STATUS_CTRL(dma->id),
2348 + JZ_DMA_STATUS_CTRL_NO_DESC | JZ_DMA_STATUS_CTRL_ENABLE,
2349 + JZ_DMA_STATUS_CTRL_HALT | JZ_DMA_STATUS_CTRL_NO_DESC |
2350 + JZ_DMA_STATUS_CTRL_ENABLE);
2352 + jz4740_dma_write_mask(JZ_REG_DMA_CTRL,
2353 + JZ_DMA_CTRL_ENABLE,
2354 + JZ_DMA_CTRL_HALT | JZ_DMA_CTRL_ENABLE);
2356 +EXPORT_SYMBOL_GPL(jz4740_dma_enable);
2358 +void jz4740_dma_disable(struct jz4740_dma_chan *dma)
2360 + jz4740_dma_write_mask(JZ_REG_DMA_STATUS_CTRL(dma->id), 0,
2361 + JZ_DMA_STATUS_CTRL_ENABLE);
2363 +EXPORT_SYMBOL_GPL(jz4740_dma_disable);
2365 +uint32_t jz4740_dma_get_residue(const struct jz4740_dma_chan *dma)
2368 + residue = jz4740_dma_read(JZ_REG_DMA_TRANSFER_COUNT(dma->id));
2369 + return residue << dma->transfer_shift;
2371 +EXPORT_SYMBOL_GPL(jz4740_dma_get_residue);
2373 +static void jz4740_dma_chan_irq(struct jz4740_dma_chan *dma)
2377 + status = jz4740_dma_read(JZ_REG_DMA_STATUS_CTRL(dma->id));
2379 + jz4740_dma_write_mask(JZ_REG_DMA_STATUS_CTRL(dma->id), 0,
2380 + JZ_DMA_STATUS_CTRL_ENABLE | JZ_DMA_STATUS_CTRL_TRANSFER_DONE);
2382 + if (dma->complete_cb)
2383 + dma->complete_cb(dma, 0, dma->dev);
2386 +static irqreturn_t jz4740_dma_irq(int irq, void *dev_id)
2388 + uint32_t irq_status;
2391 + irq_status = readl(jz4740_dma_base + JZ_REG_DMA_IRQ);
2393 + for (i = 0; i < 6; ++i) {
2394 + if (irq_status & (1 << i))
2395 + jz4740_dma_chan_irq(&jz4740_dma_channels[i]);
2398 + return IRQ_HANDLED;
2402 +static struct jz4740_dma_config dma_test_config = {
2403 + .src_width = JZ4740_DMA_WIDTH_32BIT,
2404 + .dst_width = JZ4740_DMA_WIDTH_32BIT,
2405 + .transfer_size = JZ4740_DMA_TRANSFER_SIZE_4BYTE,
2406 + .request_type = JZ4740_DMA_TYPE_AUTO_REQUEST,
2407 + .flags = JZ4740_DMA_SRC_AUTOINC | JZ4740_DMA_DST_AUTOINC,
2408 + .mode = JZ4740_DMA_MODE_BLOCK,
2411 +static void jz4740_dma_test(void)
2413 + uint32_t *buf1, *buf2;
2414 + dma_addr_t addr1, addr2;
2415 + struct jz4740_dma_chan *dma = jz4740_dma_request(NULL, "dma test");
2418 + printk("STARTING DMA TEST\n");
2420 + buf1 = dma_alloc_coherent(NULL,
2422 + &addr1, GFP_KERNEL);
2423 + buf2 = dma_alloc_coherent(NULL,
2425 + &addr2, GFP_KERNEL);
2427 + for (i = 0; i < 0x400; ++i)
2431 + jz4740_dma_configure(dma, &dma_test_config);
2432 + jz4740_dma_set_src_addr(dma, addr1);
2433 + jz4740_dma_set_dst_addr(dma, addr2);
2434 + jz4740_dma_set_transfer_count(dma, 0x1000);
2436 + jz4740_dma_enable(dma);
2439 + for (i = 0; i < 0x400; ++i) {
2441 + printk("OH MY GOD: %x %x\n", i, buf2[i]);
2444 + printk("DMA TEST DONE\n");
2448 +static int jz4740_dma_init(void)
2452 + jz4740_dma_base = ioremap(CPHYSADDR(JZ4740_DMAC_BASE_ADDR), 0x400);
2454 + if (!jz4740_dma_base)
2457 + spin_lock_init(&jz4740_dma_lock);
2459 + ret = request_irq(JZ4740_IRQ_DMAC, jz4740_dma_irq, 0, "DMA", NULL);
2462 + printk(KERN_ERR "JZ4740 DMA: Failed to request irq: %d\n", ret);
2466 +arch_initcall(jz4740_dma_init);
2467 diff --git a/arch/mips/jz4740/gpio.c b/arch/mips/jz4740/gpio.c
2468 new file mode 100644
2469 index 0000000..84f4ef9
2471 +++ b/arch/mips/jz4740/gpio.c
2474 + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
2475 + * JZ4740 platform GPIO support
2477 + * This program is free software; you can redistribute it and/or modify it
2478 + * under the terms of the GNU General Public License as published by the
2479 + * Free Software Foundation; either version 2 of the License, or (at your
2480 + * option) any later version.
2482 + * You should have received a copy of the GNU General Public License along
2483 + * with this program; if not, write to the Free Software Foundation, Inc.,
2484 + * 675 Mass Ave, Cambridge, MA 02139, USA.
2488 +#include <linux/kernel.h>
2489 +#include <linux/module.h>
2490 +#include <linux/init.h>
2492 +#include <linux/spinlock.h>
2493 +#include <linux/sysdev.h>
2494 +#include <linux/io.h>
2495 +#include <linux/gpio.h>
2496 +#include <linux/delay.h>
2497 +#include <linux/interrupt.h>
2498 +#include <linux/bitops.h>
2500 +#include <linux/debugfs.h>
2501 +#include <linux/seq_file.h>
2503 +#include <asm/mach-jz4740/base.h>
2505 +#define JZ4740_GPIO_BASE_A (32*0)
2506 +#define JZ4740_GPIO_BASE_B (32*1)
2507 +#define JZ4740_GPIO_BASE_C (32*2)
2508 +#define JZ4740_GPIO_BASE_D (32*3)
2510 +#define JZ4740_GPIO_NUM_A 32
2511 +#define JZ4740_GPIO_NUM_B 32
2512 +#define JZ4740_GPIO_NUM_C 31
2513 +#define JZ4740_GPIO_NUM_D 32
2515 +#define JZ4740_IRQ_GPIO_BASE_A (JZ4740_IRQ_GPIO(0) + JZ4740_GPIO_BASE_A)
2516 +#define JZ4740_IRQ_GPIO_BASE_B (JZ4740_IRQ_GPIO(0) + JZ4740_GPIO_BASE_B)
2517 +#define JZ4740_IRQ_GPIO_BASE_C (JZ4740_IRQ_GPIO(0) + JZ4740_GPIO_BASE_C)
2518 +#define JZ4740_IRQ_GPIO_BASE_D (JZ4740_IRQ_GPIO(0) + JZ4740_GPIO_BASE_D)
2520 +#define JZ4740_IRQ_GPIO_A(num) (JZ4740_IRQ_GPIO_BASE_A + num)
2521 +#define JZ4740_IRQ_GPIO_B(num) (JZ4740_IRQ_GPIO_BASE_B + num)
2522 +#define JZ4740_IRQ_GPIO_C(num) (JZ4740_IRQ_GPIO_BASE_C + num)
2523 +#define JZ4740_IRQ_GPIO_D(num) (JZ4740_IRQ_GPIO_BASE_D + num)
2525 +#define JZ_REG_GPIO_PIN 0x00
2526 +#define JZ_REG_GPIO_DATA 0x10
2527 +#define JZ_REG_GPIO_DATA_SET 0x14
2528 +#define JZ_REG_GPIO_DATA_CLEAR 0x18
2529 +#define JZ_REG_GPIO_MASK 0x20
2530 +#define JZ_REG_GPIO_MASK_SET 0x24
2531 +#define JZ_REG_GPIO_MASK_CLEAR 0x28
2532 +#define JZ_REG_GPIO_PULL 0x30
2533 +#define JZ_REG_GPIO_PULL_SET 0x34
2534 +#define JZ_REG_GPIO_PULL_CLEAR 0x38
2535 +#define JZ_REG_GPIO_FUNC 0x40
2536 +#define JZ_REG_GPIO_FUNC_SET 0x44
2537 +#define JZ_REG_GPIO_FUNC_CLEAR 0x48
2538 +#define JZ_REG_GPIO_SELECT 0x50
2539 +#define JZ_REG_GPIO_SELECT_SET 0x54
2540 +#define JZ_REG_GPIO_SELECT_CLEAR 0x58
2541 +#define JZ_REG_GPIO_DIRECTION 0x60
2542 +#define JZ_REG_GPIO_DIRECTION_SET 0x64
2543 +#define JZ_REG_GPIO_DIRECTION_CLEAR 0x68
2544 +#define JZ_REG_GPIO_TRIGGER 0x70
2545 +#define JZ_REG_GPIO_TRIGGER_SET 0x74
2546 +#define JZ_REG_GPIO_TRIGGER_CLEAR 0x78
2547 +#define JZ_REG_GPIO_FLAG 0x80
2548 +#define JZ_REG_GPIO_FLAG_CLEAR 0x14
2551 +#define GPIO_TO_BIT(gpio) BIT(gpio & 0x1f)
2552 +#define GPIO_TO_REG(gpio, reg) (gpio_to_jz_gpio_chip(gpio)->base + (reg))
2553 +#define CHIP_TO_REG(chip, reg) (gpio_chip_to_jz_gpio_chip(chip)->base + (reg))
2555 +struct jz_gpio_chip {
2557 + unsigned int irq_base;
2559 + uint32_t suspend_mask;
2560 + uint32_t edge_trigger_both;
2562 + void __iomem *base;
2566 + struct gpio_chip gpio_chip;
2567 + struct irq_chip irq_chip;
2568 + struct sys_device sysdev;
2572 +static struct jz_gpio_chip jz4740_gpio_chips[];
2574 +static inline struct jz_gpio_chip *gpio_to_jz_gpio_chip(unsigned int gpio)
2576 + return &jz4740_gpio_chips[gpio >> 5];
2579 +static inline struct jz_gpio_chip *gpio_chip_to_jz_gpio_chip(struct gpio_chip *gpio_chip)
2581 + return container_of(gpio_chip, struct jz_gpio_chip, gpio_chip);
2584 +static inline struct jz_gpio_chip *irq_to_jz_gpio_chip(unsigned int irq)
2586 + return get_irq_chip_data(irq);
2589 +static inline void jz_gpio_write_bit(unsigned int gpio, unsigned int reg)
2591 + writel(GPIO_TO_BIT(gpio), GPIO_TO_REG(gpio, reg));
2594 +int jz_gpio_set_function(int gpio, enum jz_gpio_function function)
2596 + if (function == JZ_GPIO_FUNC_NONE) {
2597 + jz_gpio_write_bit(gpio, JZ_REG_GPIO_FUNC_CLEAR);
2598 + jz_gpio_write_bit(gpio, JZ_REG_GPIO_SELECT_CLEAR);
2599 + jz_gpio_write_bit(gpio, JZ_REG_GPIO_TRIGGER_CLEAR);
2601 + jz_gpio_write_bit(gpio, JZ_REG_GPIO_FUNC_SET);
2602 + jz_gpio_write_bit(gpio, JZ_REG_GPIO_TRIGGER_CLEAR);
2603 + switch (function) {
2604 + case JZ_GPIO_FUNC1:
2605 + jz_gpio_write_bit(gpio, JZ_REG_GPIO_SELECT_CLEAR);
2607 + case JZ_GPIO_FUNC3:
2608 + jz_gpio_write_bit(gpio, JZ_REG_GPIO_TRIGGER_SET);
2609 + case JZ_GPIO_FUNC2: /* Falltrough */
2610 + jz_gpio_write_bit(gpio, JZ_REG_GPIO_SELECT_SET);
2620 +EXPORT_SYMBOL_GPL(jz_gpio_set_function);
2622 +int jz_gpio_bulk_request(const struct jz_gpio_bulk_request *request, size_t num)
2627 + for (i = 0; i < num; ++i, ++request) {
2628 + ret = gpio_request(request->gpio, request->name);
2631 + jz_gpio_set_function(request->gpio, request->function);
2637 + for (--request; i > 0; --i, --request) {
2638 + gpio_free(request->gpio);
2639 + jz_gpio_set_function(request->gpio, JZ_GPIO_FUNC_NONE);
2644 +EXPORT_SYMBOL_GPL(jz_gpio_bulk_request);
2646 +void jz_gpio_bulk_free(const struct jz_gpio_bulk_request *request, size_t num)
2650 + for (i = 0; i < num; ++i, ++request) {
2651 + gpio_free(request->gpio);
2652 + jz_gpio_set_function(request->gpio, JZ_GPIO_FUNC_NONE);
2656 +EXPORT_SYMBOL_GPL(jz_gpio_bulk_free);
2658 +void jz_gpio_bulk_suspend(const struct jz_gpio_bulk_request *request, size_t num)
2662 + for (i = 0; i < num; ++i, ++request) {
2663 + jz_gpio_set_function(request->gpio, JZ_GPIO_FUNC_NONE);
2664 + jz_gpio_write_bit(request->gpio, JZ_REG_GPIO_DIRECTION_CLEAR);
2665 + jz_gpio_write_bit(request->gpio, JZ_REG_GPIO_PULL_SET);
2668 +EXPORT_SYMBOL_GPL(jz_gpio_bulk_suspend);
2670 +void jz_gpio_bulk_resume(const struct jz_gpio_bulk_request *request, size_t num)
2674 + for (i = 0; i < num; ++i, ++request)
2675 + jz_gpio_set_function(request->gpio, request->function);
2677 +EXPORT_SYMBOL_GPL(jz_gpio_bulk_resume);
2679 +void jz_gpio_enable_pullup(unsigned gpio)
2681 + jz_gpio_write_bit(gpio, JZ_REG_GPIO_PULL_CLEAR);
2683 +EXPORT_SYMBOL_GPL(jz_gpio_enable_pullup);
2685 +void jz_gpio_disable_pullup(unsigned gpio)
2687 + jz_gpio_write_bit(gpio, JZ_REG_GPIO_PULL_SET);
2689 +EXPORT_SYMBOL_GPL(jz_gpio_disable_pullup);
2691 +static int jz_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
2693 + return !!(readl(CHIP_TO_REG(chip, JZ_REG_GPIO_PIN)) & BIT(gpio));
2696 +static void jz_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
2698 + uint32_t __iomem *reg = CHIP_TO_REG(chip, JZ_REG_GPIO_DATA_SET);
2700 + writel(BIT(gpio), reg);
2703 +static int jz_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
2706 + writel(BIT(gpio), CHIP_TO_REG(chip, JZ_REG_GPIO_DIRECTION_SET));
2707 + jz_gpio_set_value(chip, gpio, value);
2712 +static int jz_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
2714 + writel(BIT(gpio), CHIP_TO_REG(chip, JZ_REG_GPIO_DIRECTION_CLEAR));
2719 +int jz_gpio_port_direction_input(int port, uint32_t mask)
2721 + writel(mask, GPIO_TO_REG(port, JZ_REG_GPIO_DIRECTION_CLEAR));
2725 +EXPORT_SYMBOL(jz_gpio_port_direction_input);
2727 +int jz_gpio_port_direction_output(int port, uint32_t mask)
2729 + writel(mask, GPIO_TO_REG(port, JZ_REG_GPIO_DIRECTION_SET));
2733 +EXPORT_SYMBOL(jz_gpio_port_direction_output);
2735 +void jz_gpio_port_set_value(int port, uint32_t value, uint32_t mask)
2737 + writel(~value & mask, GPIO_TO_REG(port, JZ_REG_GPIO_DATA_CLEAR));
2738 + writel(value & mask, GPIO_TO_REG(port, JZ_REG_GPIO_DATA_SET));
2740 +EXPORT_SYMBOL(jz_gpio_port_set_value);
2742 +uint32_t jz_gpio_port_get_value(int port, uint32_t mask)
2744 + uint32_t value = readl(GPIO_TO_REG(port, JZ_REG_GPIO_PIN));
2746 + return value & mask;
2748 +EXPORT_SYMBOL(jz_gpio_port_get_value);
2751 +#define IRQ_TO_GPIO(irq) (irq - JZ4740_IRQ_GPIO(0))
2752 +#define IRQ_TO_BIT(irq) BIT(IRQ_TO_GPIO(irq) & 0x1f)
2754 +#define IRQ_TO_REG(irq, reg) GPIO_TO_REG(IRQ_TO_GPIO(irq), reg)
2756 +static void jz_gpio_irq_demux_handler(unsigned int irq, struct irq_desc *desc)
2759 + unsigned int gpio_irq;
2760 + unsigned int gpio_bank;
2761 + struct jz_gpio_chip *chip = get_irq_desc_data(desc);
2763 + gpio_bank = JZ4740_IRQ_GPIO0 - irq;
2765 + flag = readl(chip->base + JZ_REG_GPIO_FLAG);
2767 + gpio_irq = ffs(flag) - 1;
2769 + if (chip->edge_trigger_both & BIT(gpio_irq)) {
2770 + uint32_t value = readl(chip->base + JZ_REG_GPIO_PIN);
2771 + if (value & BIT(gpio_irq)) {
2772 + writel(BIT(gpio_irq),
2773 + chip->base + JZ_REG_GPIO_DIRECTION_CLEAR);
2775 + writel(BIT(gpio_irq),
2776 + chip->base + JZ_REG_GPIO_DIRECTION_SET);
2780 + gpio_irq += (gpio_bank << 5) + JZ4740_IRQ_GPIO(0);
2782 + generic_handle_irq(gpio_irq);
2785 +static inline void jz_gpio_set_irq_bit(unsigned int irq, unsigned int reg)
2787 + writel(IRQ_TO_BIT(irq), IRQ_TO_REG(irq, reg));
2790 +static void jz_gpio_irq_mask(unsigned int irq)
2792 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_MASK_SET);
2795 +static void jz_gpio_irq_unmask(unsigned int irq)
2797 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_MASK_CLEAR);
2801 +/* TODO: Check if function is gpio */
2802 +static unsigned int jz_gpio_irq_startup(unsigned int irq)
2804 + struct irq_desc *desc = irq_to_desc(irq);
2806 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_SELECT_SET);
2808 + desc->status &= ~IRQ_MASKED;
2809 + jz_gpio_irq_unmask(irq);
2814 +static void jz_gpio_irq_shutdown(unsigned int irq)
2816 + struct irq_desc *desc = irq_to_desc(irq);
2818 + jz_gpio_irq_mask(irq);
2819 + desc->status |= IRQ_MASKED;
2821 + /* Set direction to input */
2822 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_CLEAR);
2823 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_SELECT_CLEAR);
2826 +static void jz_gpio_irq_ack(unsigned int irq)
2828 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_FLAG_CLEAR);
2831 +static int jz_gpio_irq_set_type(unsigned int irq, unsigned int flow_type)
2833 + struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(irq);
2834 + struct irq_desc *desc = irq_to_desc(irq);
2836 + jz_gpio_irq_mask(irq);
2838 + if (flow_type == IRQ_TYPE_EDGE_BOTH) {
2839 + uint32_t value = readl(IRQ_TO_REG(irq, JZ_REG_GPIO_PIN));
2840 + if (value & IRQ_TO_BIT(irq))
2841 + flow_type = IRQ_TYPE_EDGE_FALLING;
2843 + flow_type = IRQ_TYPE_EDGE_RISING;
2844 + chip->edge_trigger_both |= IRQ_TO_BIT(irq);
2846 + chip->edge_trigger_both &= ~IRQ_TO_BIT(irq);
2849 + switch (flow_type) {
2850 + case IRQ_TYPE_EDGE_RISING:
2851 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_SET);
2852 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_SET);
2854 + case IRQ_TYPE_EDGE_FALLING:
2855 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_CLEAR);
2856 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_SET);
2858 + case IRQ_TYPE_LEVEL_HIGH:
2859 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_SET);
2860 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_CLEAR);
2862 + case IRQ_TYPE_LEVEL_LOW:
2863 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_CLEAR);
2864 + jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_CLEAR);
2870 + if (!(desc->status & IRQ_MASKED))
2871 + jz_gpio_irq_unmask(irq);
2876 +static int jz_gpio_irq_set_wake(unsigned int irq, unsigned int on)
2878 + struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(irq);
2879 + spin_lock(&chip->lock);
2881 + chip->wakeup |= IRQ_TO_BIT(irq);
2883 + chip->wakeup &= ~IRQ_TO_BIT(irq);
2884 + spin_unlock(&chip->lock);
2886 + set_irq_wake(chip->irq, on);
2890 +int gpio_to_irq(unsigned gpio)
2892 + return JZ4740_IRQ_GPIO(0) + gpio;
2894 +EXPORT_SYMBOL_GPL(gpio_to_irq);
2896 +int irq_to_gpio(unsigned gpio)
2898 + return IRQ_TO_GPIO(gpio);
2900 +EXPORT_SYMBOL_GPL(irq_to_gpio);
2903 + * This lock class tells lockdep that GPIO irqs are in a different
2904 + * category than their parents, so it won't report false recursion.
2906 +static struct lock_class_key gpio_lock_class;
2908 +#define JZ4740_GPIO_CHIP(_bank) { \
2909 + .irq_base = JZ4740_IRQ_GPIO_BASE_ ## _bank, \
2911 + .label = "Bank " # _bank, \
2912 + .owner = THIS_MODULE, \
2913 + .set = jz_gpio_set_value, \
2914 + .get = jz_gpio_get_value, \
2915 + .direction_output = jz_gpio_direction_output, \
2916 + .direction_input = jz_gpio_direction_input, \
2917 + .base = JZ4740_GPIO_BASE_ ## _bank, \
2918 + .ngpio = JZ4740_GPIO_NUM_ ## _bank, \
2921 + .name = "GPIO Bank " # _bank, \
2922 + .mask = jz_gpio_irq_mask, \
2923 + .unmask = jz_gpio_irq_unmask, \
2924 + .ack = jz_gpio_irq_ack, \
2925 + .startup = jz_gpio_irq_startup, \
2926 + .shutdown = jz_gpio_irq_shutdown, \
2927 + .set_type = jz_gpio_irq_set_type, \
2928 + .set_wake = jz_gpio_irq_set_wake, \
2932 +static struct jz_gpio_chip jz4740_gpio_chips[] = {
2933 + JZ4740_GPIO_CHIP(A),
2934 + JZ4740_GPIO_CHIP(B),
2935 + JZ4740_GPIO_CHIP(C),
2936 + JZ4740_GPIO_CHIP(D),
2939 +static inline struct jz_gpio_chip *sysdev_to_chip(struct sys_device *dev)
2941 + return container_of(dev, struct jz_gpio_chip, sysdev);
2944 +static int jz4740_gpio_suspend(struct sys_device *dev, pm_message_t state)
2946 + struct jz_gpio_chip *chip = sysdev_to_chip(dev);
2948 + chip->suspend_mask = readl(chip->base + JZ_REG_GPIO_MASK);
2949 + writel(~(chip->wakeup), chip->base + JZ_REG_GPIO_MASK_SET);
2950 + writel(chip->wakeup, chip->base + JZ_REG_GPIO_MASK_CLEAR);
2955 +static int jz4740_gpio_resume(struct sys_device *dev)
2957 + struct jz_gpio_chip *chip = sysdev_to_chip(dev);
2958 + uint32_t mask = chip->suspend_mask;
2960 + writel(~mask, chip->base + JZ_REG_GPIO_MASK_CLEAR);
2961 + writel(mask, chip->base + JZ_REG_GPIO_MASK_SET);
2966 +static struct sysdev_class jz4740_gpio_sysdev_class = {
2968 + .suspend = jz4740_gpio_suspend,
2969 + .resume = jz4740_gpio_resume,
2972 +static int jz4740_gpio_chip_init(struct jz_gpio_chip *chip, unsigned int id)
2976 + chip->sysdev.id = id;
2977 + chip->sysdev.cls = &jz4740_gpio_sysdev_class;
2978 + ret = sysdev_register(&chip->sysdev);
2983 + spin_lock_init(&chip->lock);
2985 + chip->base = ioremap(CPHYSADDR(JZ4740_GPIO_BASE_ADDR) + (id * 0x100), 0x100);
2987 + gpiochip_add(&chip->gpio_chip);
2989 + chip->irq = JZ4740_IRQ_INTC_GPIO(id);
2990 + set_irq_data(chip->irq, chip);
2991 + set_irq_chained_handler(chip->irq, jz_gpio_irq_demux_handler);
2993 + for (irq = chip->irq_base; irq < chip->irq_base + chip->gpio_chip.ngpio; ++irq) {
2994 + lockdep_set_class(&irq_desc[irq].lock, &gpio_lock_class);
2995 + set_irq_chip_and_handler(irq, &chip->irq_chip, handle_level_irq);
2996 + set_irq_chip_data(irq, chip);
3002 +int __init jz_gpiolib_init(void)
3007 + ret = sysdev_class_register(&jz4740_gpio_sysdev_class);
3011 + for (i = 0; i < ARRAY_SIZE(jz4740_gpio_chips); ++i) {
3012 + jz4740_gpio_chip_init(&jz4740_gpio_chips[i], i);
3015 + printk(KERN_INFO "JZ4740 GPIO initalized\n");
3020 +#ifdef CONFIG_DEBUG_FS
3022 +static inline void gpio_seq_reg(struct seq_file *s, struct jz_gpio_chip *chip,
3023 + const char *name, unsigned int reg)
3025 + seq_printf(s, "\t%s: %08x\n", name, readl(chip->base + reg));
3029 +static int gpio_regs_show(struct seq_file *s, void *unused)
3031 + struct jz_gpio_chip *chip = jz4740_gpio_chips;
3034 + for (i = 0; i < ARRAY_SIZE(jz4740_gpio_chips); ++i, ++chip) {
3035 + seq_printf(s, "GPIO %d: \n", i);
3036 + gpio_seq_reg(s, chip, "Pin", JZ_REG_GPIO_PIN);
3037 + gpio_seq_reg(s, chip, "Data", JZ_REG_GPIO_DATA);
3038 + gpio_seq_reg(s, chip, "Mask", JZ_REG_GPIO_MASK);
3039 + gpio_seq_reg(s, chip, "Pull", JZ_REG_GPIO_PULL);
3040 + gpio_seq_reg(s, chip, "Func", JZ_REG_GPIO_FUNC);
3041 + gpio_seq_reg(s, chip, "Select", JZ_REG_GPIO_SELECT);
3042 + gpio_seq_reg(s, chip, "Direction", JZ_REG_GPIO_DIRECTION);
3043 + gpio_seq_reg(s, chip, "Trigger", JZ_REG_GPIO_TRIGGER);
3044 + gpio_seq_reg(s, chip, "Flag", JZ_REG_GPIO_FLAG);
3050 +static int gpio_regs_open(struct inode *inode, struct file *file)
3052 + return single_open(file, gpio_regs_show, NULL);
3055 +static const struct file_operations gpio_regs_operations = {
3056 + .open = gpio_regs_open,
3058 + .llseek = seq_lseek,
3059 + .release = single_release,
3062 +static int __init gpio_debugfs_init(void)
3064 + (void) debugfs_create_file("jz_regs_gpio", S_IFREG | S_IRUGO,
3065 + NULL, NULL, &gpio_regs_operations);
3068 +subsys_initcall(gpio_debugfs_init);
3071 diff --git a/arch/mips/jz4740/irq.c b/arch/mips/jz4740/irq.c
3072 new file mode 100644
3073 index 0000000..46a03ee
3075 +++ b/arch/mips/jz4740/irq.c
3078 + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
3079 + * JZ4740 platform IRQ support
3081 + * This program is free software; you can redistribute it and/or modify it
3082 + * under the terms of the GNU General Public License as published by the
3083 + * Free Software Foundation; either version 2 of the License, or (at your
3084 + * option) any later version.
3086 + * You should have received a copy of the GNU General Public License along
3087 + * with this program; if not, write to the Free Software Foundation, Inc.,
3088 + * 675 Mass Ave, Cambridge, MA 02139, USA.
3092 +#include <linux/errno.h>
3093 +#include <linux/init.h>
3094 +#include <linux/types.h>
3095 +#include <linux/interrupt.h>
3096 +#include <linux/ioport.h>
3097 +#include <linux/timex.h>
3098 +#include <linux/slab.h>
3099 +#include <linux/delay.h>
3101 +#include <linux/debugfs.h>
3102 +#include <linux/seq_file.h>
3104 +#include <asm/io.h>
3105 +#include <asm/mipsregs.h>
3106 +#include <asm/irq_cpu.h>
3108 +#include <asm/mach-jz4740/base.h>
3110 +static void __iomem *jz_intc_base;
3111 +static uint32_t jz_intc_wakeup;
3112 +static uint32_t jz_intc_saved;
3114 +#define JZ_REG_INTC_STATUS 0x00
3115 +#define JZ_REG_INTC_MASK 0x04
3116 +#define JZ_REG_INTC_SET_MASK 0x08
3117 +#define JZ_REG_INTC_CLEAR_MASK 0x0c
3118 +#define JZ_REG_INTC_PENDING 0x10
3120 +#define IRQ_BIT(x) BIT((x) - JZ4740_IRQ_BASE)
3122 +static void intc_irq_unmask(unsigned int irq)
3124 + writel(IRQ_BIT(irq), jz_intc_base + JZ_REG_INTC_CLEAR_MASK);
3127 +static void intc_irq_mask(unsigned int irq)
3129 + writel(IRQ_BIT(irq), jz_intc_base + JZ_REG_INTC_SET_MASK);
3132 +static int intc_irq_set_wake(unsigned int irq, unsigned int on)
3135 + jz_intc_wakeup |= IRQ_BIT(irq);
3137 + jz_intc_wakeup &= ~IRQ_BIT(irq);
3142 +static struct irq_chip intc_irq_type = {
3144 + .mask = intc_irq_mask,
3145 + .mask_ack = intc_irq_mask,
3146 + .unmask = intc_irq_unmask,
3147 + .set_wake = intc_irq_set_wake,
3150 +static irqreturn_t jz4740_cascade(int irq, void *data)
3155 + irq_reg = readl(jz_intc_base + JZ_REG_INTC_PENDING);
3157 + intc_irq = ffs(irq_reg);
3159 + generic_handle_irq(intc_irq - 1 + JZ4740_IRQ_BASE);
3161 + return IRQ_HANDLED;
3164 +static struct irqaction jz4740_cascade_action = {
3165 + .handler = jz4740_cascade,
3166 + .name = "JZ4740 cascade interrupt",
3167 + .flags = IRQF_DISABLED,
3170 +void __init arch_init_irq(void)
3173 + mips_cpu_irq_init();
3175 + jz_intc_base = ioremap(CPHYSADDR(JZ4740_INTC_BASE_ADDR), 0x14);
3177 + for (i = JZ4740_IRQ_BASE; i < JZ4740_IRQ_BASE + 32; i++) {
3179 + set_irq_chip_and_handler(i, &intc_irq_type, handle_level_irq);
3182 + setup_irq(2, &jz4740_cascade_action);
3185 +asmlinkage void plat_irq_dispatch(void)
3187 + unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
3188 + if (pending & STATUSF_IP2)
3190 + else if (pending & STATUSF_IP3)
3193 + spurious_interrupt();
3196 +void jz4740_intc_suspend(void)
3198 + jz_intc_saved = readl(jz_intc_base + JZ_REG_INTC_MASK);
3199 + writel(~jz_intc_wakeup, jz_intc_base + JZ_REG_INTC_SET_MASK);
3200 + writel(jz_intc_wakeup, jz_intc_base + JZ_REG_INTC_CLEAR_MASK);
3203 +void jz4740_intc_resume(void)
3205 + writel(~jz_intc_saved, jz_intc_base + JZ_REG_INTC_CLEAR_MASK);
3206 + writel(jz_intc_saved, jz_intc_base + JZ_REG_INTC_SET_MASK);
3209 +#ifdef CONFIG_DEBUG_FS
3211 +static inline void intc_seq_reg(struct seq_file *s, const char *name,
3214 + seq_printf(s, "%s:\t\t%08x\n", name, readl(jz_intc_base + reg));
3217 +static int intc_regs_show(struct seq_file *s, void *unused)
3219 + intc_seq_reg(s, "Status", JZ_REG_INTC_STATUS);
3220 + intc_seq_reg(s, "Mask", JZ_REG_INTC_MASK);
3221 + intc_seq_reg(s, "Pending", JZ_REG_INTC_PENDING);
3226 +static int intc_regs_open(struct inode *inode, struct file *file)
3228 + return single_open(file, intc_regs_show, NULL);
3231 +static const struct file_operations intc_regs_operations = {
3232 + .open = intc_regs_open,
3234 + .llseek = seq_lseek,
3235 + .release = single_release,
3238 +static int __init intc_debugfs_init(void)
3240 + (void) debugfs_create_file("jz_regs_intc", S_IFREG | S_IRUGO,
3241 + NULL, NULL, &intc_regs_operations);
3244 +subsys_initcall(intc_debugfs_init);
3247 diff --git a/arch/mips/jz4740/irq.h b/arch/mips/jz4740/irq.h
3248 new file mode 100644
3249 index 0000000..dadbd5f
3251 +++ b/arch/mips/jz4740/irq.h
3254 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
3256 + * This program is free software; you can redistribute it and/or modify it
3257 + * under the terms of the GNU General Public License as published by the
3258 + * Free Software Foundation; either version 2 of the License, or (at your
3259 + * option) any later version.
3261 + * You should have received a copy of the GNU General Public License along
3262 + * with this program; if not, write to the Free Software Foundation, Inc.,
3263 + * 675 Mass Ave, Cambridge, MA 02139, USA.
3267 +#ifndef __MIPS_JZ4740_IRQ_H__
3268 +#define __MIPS_JZ4740_IRQ_H__
3270 +extern void jz4740_intc_suspend(void);
3271 +extern void jz4740_intc_resume(void);
3274 diff --git a/arch/mips/jz4740/platform.c b/arch/mips/jz4740/platform.c
3275 new file mode 100644
3276 index 0000000..6bb0778
3278 +++ b/arch/mips/jz4740/platform.c
3281 + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
3282 + * JZ4740 platform devices
3284 + * This program is free software; you can redistribute it and/or modify it
3285 + * under the terms of the GNU General Public License as published by the
3286 + * Free Software Foundation; either version 2 of the License, or (at your
3287 + * option) any later version.
3289 + * You should have received a copy of the GNU General Public License along
3290 + * with this program; if not, write to the Free Software Foundation, Inc.,
3291 + * 675 Mass Ave, Cambridge, MA 02139, USA.
3295 +#include <linux/device.h>
3296 +#include <linux/platform_device.h>
3297 +#include <linux/kernel.h>
3298 +#include <linux/init.h>
3299 +#include <linux/resource.h>
3301 +#include <asm/mach-jz4740/platform.h>
3302 +#include <asm/mach-jz4740/base.h>
3303 +#include <asm/mach-jz4740/irq.h>
3305 +/* OHCI (USB full speed host controller) */
3306 +static struct resource jz4740_usb_ohci_resources[] = {
3308 + .start = CPHYSADDR(JZ4740_UHC_BASE_ADDR),
3309 + .end = CPHYSADDR(JZ4740_UHC_BASE_ADDR) + 0x10000 - 1,
3310 + .flags = IORESOURCE_MEM,
3313 + .start = JZ4740_IRQ_UHC,
3314 + .end = JZ4740_IRQ_UHC,
3315 + .flags = IORESOURCE_IRQ,
3319 +/* The dmamask must be set for OHCI to work */
3320 +static u64 ohci_dmamask = ~(u32)0;
3322 +struct platform_device jz4740_usb_ohci_device = {
3323 + .name = "jz4740-ohci",
3326 + .dma_mask = &ohci_dmamask,
3327 + .coherent_dma_mask = 0xffffffff,
3329 + .num_resources = ARRAY_SIZE(jz4740_usb_ohci_resources),
3330 + .resource = jz4740_usb_ohci_resources,
3333 +/* UDC (USB gadget controller) */
3334 +static struct resource jz4740_usb_gdt_resources[] = {
3336 + .start = CPHYSADDR(JZ4740_UDC_BASE_ADDR),
3337 + .end = CPHYSADDR(JZ4740_UDC_BASE_ADDR) + 0x10000 - 1,
3338 + .flags = IORESOURCE_MEM,
3341 + .start = JZ4740_IRQ_UDC,
3342 + .end = JZ4740_IRQ_UDC,
3343 + .flags = IORESOURCE_IRQ,
3347 +static u64 jz4740_udc_dmamask = ~(u32)0;
3349 +struct platform_device jz4740_usb_gdt_device = {
3353 + .dma_mask = &jz4740_udc_dmamask,
3354 + .coherent_dma_mask = 0xffffffff,
3356 + .num_resources = ARRAY_SIZE(jz4740_usb_gdt_resources),
3357 + .resource = jz4740_usb_gdt_resources,
3360 +/** MMC/SD controller **/
3361 +static struct resource jz4740_mmc_resources[] = {
3363 + .start = CPHYSADDR(JZ4740_MSC_BASE_ADDR),
3364 + .end = CPHYSADDR(JZ4740_MSC_BASE_ADDR) + 0x10000 - 1,
3365 + .flags = IORESOURCE_MEM,
3368 + .start = JZ4740_IRQ_MSC,
3369 + .end = JZ4740_IRQ_MSC,
3370 + .flags = IORESOURCE_IRQ,
3374 +static u64 jz4740_mmc_dmamask = ~(u32)0;
3376 +struct platform_device jz4740_mmc_device = {
3377 + .name = "jz4740-mmc",
3380 + .dma_mask = &jz4740_mmc_dmamask,
3381 + .coherent_dma_mask = 0xffffffff,
3383 + .num_resources = ARRAY_SIZE(jz4740_mmc_resources),
3384 + .resource = jz4740_mmc_resources,
3387 +static struct resource jz4740_rtc_resources[] = {
3389 + .start = CPHYSADDR(JZ4740_RTC_BASE_ADDR),
3390 + .end = CPHYSADDR(JZ4740_RTC_BASE_ADDR) + 0x38 - 1,
3391 + .flags = IORESOURCE_MEM,
3394 + .start = JZ4740_IRQ_RTC,
3395 + .end = JZ4740_IRQ_RTC,
3396 + .flags = IORESOURCE_IRQ,
3400 +struct platform_device jz4740_rtc_device = {
3401 + .name = "jz4740-rtc",
3403 + .num_resources = ARRAY_SIZE(jz4740_rtc_resources),
3404 + .resource = jz4740_rtc_resources,
3407 +/** I2C controller **/
3408 +static struct resource jz4740_i2c_resources[] = {
3410 + .start = CPHYSADDR(JZ4740_I2C_BASE_ADDR),
3411 + .end = CPHYSADDR(JZ4740_I2C_BASE_ADDR) + 0x10000 - 1,
3412 + .flags = IORESOURCE_MEM,
3415 + .start = JZ4740_IRQ_I2C,
3416 + .end = JZ4740_IRQ_I2C,
3417 + .flags = IORESOURCE_IRQ,
3421 +static u64 jz4740_i2c_dmamask = ~(u32)0;
3423 +struct platform_device jz4740_i2c_device = {
3427 + .dma_mask = &jz4740_i2c_dmamask,
3428 + .coherent_dma_mask = 0xffffffff,
3430 + .num_resources = ARRAY_SIZE(jz4740_i2c_resources),
3431 + .resource = jz4740_i2c_resources,
3434 +static struct resource jz4740_nand_resources[] = {
3436 + .start = CPHYSADDR(JZ4740_EMC_BASE_ADDR),
3437 + .end = CPHYSADDR(JZ4740_EMC_BASE_ADDR) + 0x10000 - 1,
3438 + .flags = IORESOURCE_MEM,
3442 +struct platform_device jz4740_nand_device = {
3443 + .name = "jz4740-nand",
3444 + .num_resources = ARRAY_SIZE(jz4740_nand_resources),
3445 + .resource = jz4740_nand_resources,
3448 +static struct resource jz4740_framebuffer_resources[] = {
3450 + .start = CPHYSADDR(JZ4740_LCD_BASE_ADDR),
3451 + .end = CPHYSADDR(JZ4740_LCD_BASE_ADDR) + 0x10000 - 1,
3452 + .flags = IORESOURCE_MEM,
3456 +static u64 jz4740_fb_dmamask = ~(u32)0;
3458 +struct platform_device jz4740_framebuffer_device = {
3459 + .name = "jz4740-fb",
3461 + .num_resources = ARRAY_SIZE(jz4740_framebuffer_resources),
3462 + .resource = jz4740_framebuffer_resources,
3464 + .dma_mask = &jz4740_fb_dmamask,
3465 + .coherent_dma_mask = 0xffffffff,
3469 +static struct resource jz4740_i2s_resources[] = {
3471 + .start = CPHYSADDR(JZ4740_AIC_BASE_ADDR),
3472 + .end = CPHYSADDR(JZ4740_AIC_BASE_ADDR) + 0x38 - 1,
3473 + .flags = IORESOURCE_MEM,
3477 +struct platform_device jz4740_i2s_device = {
3478 + .name = "jz4740-i2s",
3480 + .num_resources = ARRAY_SIZE(jz4740_i2s_resources),
3481 + .resource = jz4740_i2s_resources,
3484 +static struct resource jz4740_codec_resources[] = {
3486 + .start = CPHYSADDR(JZ4740_AIC_BASE_ADDR) + 0x80,
3487 + .end = CPHYSADDR(JZ4740_AIC_BASE_ADDR) + 0x88 - 1,
3488 + .flags = IORESOURCE_MEM,
3492 +struct platform_device jz4740_codec_device = {
3493 + .name = "jz4740-codec",
3495 + .num_resources = ARRAY_SIZE(jz4740_codec_resources),
3496 + .resource = jz4740_codec_resources,
3499 +static struct resource jz4740_adc_resources[] = {
3501 + .start = CPHYSADDR(JZ4740_SADC_BASE_ADDR),
3502 + .end = CPHYSADDR(JZ4740_SADC_BASE_ADDR) + 0x30,
3503 + .flags = IORESOURCE_MEM,
3506 + .start = JZ4740_IRQ_SADC,
3507 + .end = JZ4740_IRQ_SADC,
3508 + .flags = IORESOURCE_IRQ,
3512 +struct platform_device jz4740_adc_device = {
3513 + .name = "jz4740-adc",
3515 + .num_resources = ARRAY_SIZE(jz4740_adc_resources),
3516 + .resource = jz4740_adc_resources,
3519 +struct platform_device jz4740_battery_device = {
3520 + .name = "jz4740-battery",
3523 + .parent = &jz4740_adc_device.dev
3526 diff --git a/arch/mips/jz4740/pm.c b/arch/mips/jz4740/pm.c
3527 new file mode 100644
3528 index 0000000..4ca3156
3530 +++ b/arch/mips/jz4740/pm.c
3533 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
3534 + * JZ4740 SoC power management support
3536 + * This program is free software; you can redistribute it and/or modify it
3537 + * under the terms of the GNU General Public License as published by the
3538 + * Free Software Foundation; either version 2 of the License, or (at your
3539 + * option) any later version.
3541 + * You should have received a copy of the GNU General Public License along
3542 + * with this program; if not, write to the Free Software Foundation, Inc.,
3543 + * 675 Mass Ave, Cambridge, MA 02139, USA.
3547 +#include <linux/init.h>
3548 +#include <linux/pm.h>
3549 +#include <linux/delay.h>
3550 +#include <linux/suspend.h>
3552 +#include <asm/mach-jz4740/clock.h>
3557 +static int jz_pm_enter(suspend_state_t state)
3559 + jz4740_intc_suspend();
3560 + jz4740_clock_suspend();
3562 + jz4740_clock_set_wait_mode(JZ4740_WAIT_MODE_SLEEP);
3564 + __asm__(".set\tmips3\n\t"
3568 + jz4740_clock_set_wait_mode(JZ4740_WAIT_MODE_IDLE);
3570 + jz4740_clock_resume();
3571 + jz4740_intc_resume();
3576 +static struct platform_suspend_ops jz_pm_ops = {
3577 + .valid = suspend_valid_only_mem,
3578 + .enter = jz_pm_enter,
3582 + * Initialize power interface
3584 +int __init jz_pm_init(void)
3586 + suspend_set_ops(&jz_pm_ops);
3590 +late_initcall(jz_pm_init);
3591 diff --git a/arch/mips/jz4740/prom.c b/arch/mips/jz4740/prom.c
3592 new file mode 100644
3593 index 0000000..4f99ea3
3595 +++ b/arch/mips/jz4740/prom.c
3598 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
3599 + * JZ4740 SoC prom code
3601 + * This program is free software; you can redistribute it and/or modify it
3602 + * under the terms of the GNU General Public License as published by the
3603 + * Free Software Foundation; either version 2 of the License, or (at your
3604 + * option) any later version.
3606 + * You should have received a copy of the GNU General Public License along
3607 + * with this program; if not, write to the Free Software Foundation, Inc.,
3608 + * 675 Mass Ave, Cambridge, MA 02139, USA.
3613 +#include <linux/module.h>
3614 +#include <linux/kernel.h>
3615 +#include <linux/init.h>
3616 +#include <linux/string.h>
3618 +#include <linux/serial_reg.h>
3620 +#include <asm/bootinfo.h>
3621 +#include <asm/mach-jz4740/base.h>
3623 +void jz4740_init_cmdline(int argc, char *argv[])
3625 + unsigned int count = COMMAND_LINE_SIZE - 1;
3627 + char *dst = &(arcs_cmdline[0]);
3630 + for (i = 1; i < argc && count; ++i) {
3632 + while (*src && count) {
3644 +void __init prom_init(void)
3646 + jz4740_init_cmdline((int)fw_arg0, (char **)fw_arg1);
3647 + mips_machtype = MACH_INGENIC_JZ4740;
3650 +void __init prom_free_prom_memory(void)
3654 +#define UART_REG(offset) ((void __iomem*)(JZ4740_UART0_BASE_ADDR + (offset << 2)))
3656 +void prom_putchar(char c)
3661 + lsr = readb(UART_REG(UART_LSR));
3662 + } while ((lsr & UART_LSR_TEMT) == 0);
3664 + writeb(c, UART_REG(UART_TX));
3666 diff --git a/arch/mips/jz4740/pwm.c b/arch/mips/jz4740/pwm.c
3667 new file mode 100644
3668 index 0000000..0ff8c1d
3670 +++ b/arch/mips/jz4740/pwm.c
3673 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
3674 + * JZ4740 platform PWM support
3676 + * This program is free software; you can redistribute it and/or modify it
3677 + * under the terms of the GNU General Public License as published by the
3678 + * Free Software Foundation; either version 2 of the License, or (at your
3679 + * option) any later version.
3681 + * You should have received a copy of the GNU General Public License along
3682 + * with this program; if not, write to the Free Software Foundation, Inc.,
3683 + * 675 Mass Ave, Cambridge, MA 02139, USA.
3688 +#include <linux/kernel.h>
3690 +#include <linux/clk.h>
3691 +#include <linux/err.h>
3692 +#include <linux/pwm.h>
3693 +#include <linux/gpio.h>
3695 +#include <asm/mach-jz4740/gpio.h>
3698 +static struct clk *jz4740_pwm_clk;
3700 +DEFINE_MUTEX(jz4740_pwm_mutex);
3702 +struct pwm_device {
3704 + unsigned int gpio;
3708 +static struct pwm_device jz4740_pwm_list[] = {
3709 + { 2, JZ_GPIO_PWM2, false },
3710 + { 3, JZ_GPIO_PWM3, false },
3711 + { 4, JZ_GPIO_PWM4, false },
3712 + { 5, JZ_GPIO_PWM5, false },
3713 + { 6, JZ_GPIO_PWM6, false },
3714 + { 7, JZ_GPIO_PWM7, false },
3717 +struct pwm_device *pwm_request(int id, const char *label)
3720 + struct pwm_device *pwm;
3722 + if (!jz4740_pwm_clk) {
3723 + jz4740_pwm_clk = clk_get(NULL, "pclk");
3725 + if (IS_ERR(jz4740_pwm_clk))
3726 + return ERR_PTR(PTR_ERR(jz4740_pwm_clk));
3729 + if (id < 2 || id > 7) {
3730 + return ERR_PTR(-ENOENT);
3733 + mutex_lock(&jz4740_pwm_mutex);
3735 + pwm = &jz4740_pwm_list[id - 2];
3741 + mutex_unlock(&jz4740_pwm_mutex);
3744 + return ERR_PTR(ret);
3747 + ret = gpio_request(pwm->gpio, label);
3750 + printk("Failed to request pwm gpio: %d\n", ret);
3751 + pwm->used = false;
3752 + return ERR_PTR(ret);
3755 + jz_gpio_set_function(pwm->gpio, JZ_GPIO_FUNC_PWM);
3757 + jz4740_timer_start(id);
3762 +void pwm_free(struct pwm_device *pwm)
3765 + jz4740_timer_set_ctrl(pwm->id, 0);
3767 + jz_gpio_set_function(pwm->gpio, JZ_GPIO_FUNC_NONE);
3768 + gpio_free(pwm->gpio);
3770 + jz4740_timer_stop(pwm->id);
3772 + pwm->used = false;
3776 +int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
3778 + unsigned long long tmp;
3779 + unsigned long period, duty;
3780 + unsigned int prescaler = 0;
3781 + unsigned int id = pwm->id;
3785 + if (duty_ns < 0 || duty_ns > period_ns)
3788 + tmp = (unsigned long long)clk_get_rate(jz4740_pwm_clk) * period_ns;
3790 + do_div(tmp, 1000000000);
3794 + while (period > 0xffff && prescaler < 6) {
3799 + if (prescaler == 6)
3803 + tmp = (unsigned long long)period * duty_ns;
3804 + do_div(tmp, period_ns);
3807 + if (duty >= period)
3808 + duty = period - 1;
3810 + is_enabled = jz4740_timer_is_enabled(id);
3811 + jz4740_timer_disable(id);
3813 + jz4740_timer_set_count(id, 0);
3814 + jz4740_timer_set_duty(id, duty);
3815 + jz4740_timer_set_period(id, period);
3817 + ctrl = JZ_TIMER_CTRL_PRESCALER(prescaler) | JZ_TIMER_CTRL_PWM_ENABLE |
3818 + JZ_TIMER_CTRL_SRC_PCLK;
3820 + jz4740_timer_set_ctrl(id, ctrl);
3823 + jz4740_timer_enable(id);
3828 +int pwm_enable(struct pwm_device *pwm)
3830 + jz4740_timer_enable(pwm->id);
3835 +void pwm_disable(struct pwm_device *pwm)
3837 + jz4740_timer_disable(pwm->id);
3839 diff --git a/arch/mips/jz4740/reset.c b/arch/mips/jz4740/reset.c
3840 new file mode 100644
3841 index 0000000..448a7da
3843 +++ b/arch/mips/jz4740/reset.c
3846 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
3848 + * This program is free software; you can redistribute it and/or modify it
3849 + * under the terms of the GNU General Public License as published by the
3850 + * Free Software Foundation; either version 2 of the License, or (at your
3851 + * option) any later version.
3853 + * You should have received a copy of the GNU General Public License along
3854 + * with this program; if not, write to the Free Software Foundation, Inc.,
3855 + * 675 Mass Ave, Cambridge, MA 02139, USA.
3859 +#include <linux/io.h>
3860 +#include <linux/kernel.h>
3861 +#include <linux/pm.h>
3863 +#include <linux/delay.h>
3865 +#include <asm/reboot.h>
3867 +#include <asm/mach-jz4740/base.h>
3868 +#include <asm/mach-jz4740/timer.h>
3870 +static void jz4740_halt(void)
3873 + __asm__(".set push;\n"
3881 +#define JZ_REG_WDT_DATA 0x00
3882 +#define JZ_REG_WDT_COUNTER_ENABLE 0x04
3883 +#define JZ_REG_WDT_COUNTER 0x08
3884 +#define JZ_REG_WDT_CTRL 0x0c
3886 +static void jz4740_restart(char *command)
3888 + void __iomem *wdt_base = ioremap(CPHYSADDR(JZ4740_WDT_BASE_ADDR), 0x0f);
3890 + jz4740_timer_enable_watchdog();
3892 + writeb(0, wdt_base + JZ_REG_WDT_COUNTER_ENABLE);
3894 + writew(0, wdt_base + JZ_REG_WDT_COUNTER);
3895 + writew(0, wdt_base + JZ_REG_WDT_DATA);
3896 + writew(BIT(2), wdt_base + JZ_REG_WDT_CTRL);
3898 + writeb(1, wdt_base + JZ_REG_WDT_COUNTER_ENABLE);
3902 +#define JZ_REG_RTC_CTRL 0x00
3903 +#define JZ_REG_RTC_HIBERNATE 0x20
3905 +#define JZ_RTC_CTRL_WRDY BIT(7)
3907 +static void jz4740_power_off(void)
3909 + void __iomem *rtc_base = ioremap(CPHYSADDR(JZ4740_RTC_BASE_ADDR), 0x24);
3913 + ctrl = readl(rtc_base + JZ_REG_RTC_CTRL);
3914 + } while (!(ctrl & JZ_RTC_CTRL_WRDY));
3916 + writel(1, rtc_base + JZ_REG_RTC_HIBERNATE);
3920 +void jz4740_reset_init(void)
3922 + _machine_restart = jz4740_restart;
3923 + _machine_halt = jz4740_halt;
3924 + pm_power_off = jz4740_power_off;
3926 diff --git a/arch/mips/jz4740/reset.h b/arch/mips/jz4740/reset.h
3927 new file mode 100644
3928 index 0000000..c57a829
3930 +++ b/arch/mips/jz4740/reset.h
3932 +#ifndef __MIPS_JZ4740_RESET_H__
3933 +#define __MIPS_JZ4740_RESET_H__
3935 +extern void jz4740_reset_init(void);
3939 diff --git a/arch/mips/jz4740/setup.c b/arch/mips/jz4740/setup.c
3940 new file mode 100644
3941 index 0000000..a6628f4
3943 +++ b/arch/mips/jz4740/setup.c
3946 + * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
3947 + * JZ4740 setup code
3949 + * This program is free software; you can redistribute it and/or modify it
3950 + * under the terms of the GNU General Public License as published by the
3951 + * Free Software Foundation; either version 2 of the License, or (at your
3952 + * option) any later version.
3954 + * You should have received a copy of the GNU General Public License along
3955 + * with this program; if not, write to the Free Software Foundation, Inc.,
3956 + * 675 Mass Ave, Cambridge, MA 02139, USA.
3961 +#include <linux/init.h>
3962 +#include <linux/kernel.h>
3963 +#include <linux/serial.h>
3964 +#include <linux/serial_core.h>
3965 +#include <linux/serial_8250.h>
3967 +#include <asm/mach-jz4740/base.h>
3968 +#include <asm/mach-jz4740/clock.h>
3969 +#include <asm/mach-jz4740/serial.h>
3974 +static void __init jz4740_serial_setup(void)
3976 +#ifdef CONFIG_SERIAL_8250
3977 + struct uart_port s;
3978 + memset(&s, 0, sizeof(s));
3979 + s.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
3980 + s.iotype = SERIAL_IO_MEM;
3982 + s.uartclk = jz4740_clock_bdata.ext_rate;
3985 + s.membase = (u8 *)JZ4740_UART0_BASE_ADDR;
3986 + s.irq = JZ4740_IRQ_UART0;
3987 + if (early_serial_setup(&s) != 0) {
3988 + printk(KERN_ERR "Serial ttyS0 setup failed!\n");
3992 + s.membase = (u8 *)JZ4740_UART1_BASE_ADDR;
3993 + s.irq = JZ4740_IRQ_UART1;
3994 + if (early_serial_setup(&s) != 0) {
3995 + printk(KERN_ERR "Serial ttyS1 setup failed!\n");
3999 +void __init plat_mem_setup(void)
4001 + jz4740_reset_init();
4002 + jz4740_serial_setup();
4005 +const char *get_system_type(void)
4009 diff --git a/arch/mips/jz4740/time.c b/arch/mips/jz4740/time.c
4010 new file mode 100644
4011 index 0000000..da8183f
4013 +++ b/arch/mips/jz4740/time.c
4016 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
4017 + * JZ4740 platform time support
4019 + * This program is free software; you can redistribute it and/or modify it
4020 + * under the terms of the GNU General Public License as published by the
4021 + * Free Software Foundation; either version 2 of the License, or (at your
4022 + * option) any later version.
4024 + * You should have received a copy of the GNU General Public License along
4025 + * with this program; if not, write to the Free Software Foundation, Inc.,
4026 + * 675 Mass Ave, Cambridge, MA 02139, USA.
4030 +#include <linux/interrupt.h>
4031 +#include <linux/kernel.h>
4032 +#include <linux/time.h>
4034 +#include <linux/clockchips.h>
4036 +#include <asm/mach-jz4740/irq.h>
4037 +#include <asm/time.h>
4042 +#define TIMER_CLOCKEVENT 0
4043 +#define TIMER_CLOCKSOURCE 1
4045 +static uint16_t jz4740_jiffies_per_tick;
4047 +static cycle_t jz4740_clocksource_read(struct clocksource *cs)
4049 + return jz4740_timer_get_count(TIMER_CLOCKSOURCE);
4052 +static struct clocksource jz4740_clocksource = {
4053 + .name = "jz4740-timer",
4055 + .read = jz4740_clocksource_read,
4056 + .mask = CLOCKSOURCE_MASK(16),
4057 + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
4060 +static irqreturn_t jz4740_clockevent_irq(int irq, void *devid)
4062 + struct clock_event_device *cd = devid;
4064 + jz4740_timer_ack_full(TIMER_CLOCKEVENT);
4066 + if (cd->mode != CLOCK_EVT_MODE_PERIODIC)
4067 + jz4740_timer_disable(TIMER_CLOCKEVENT);
4069 + cd->event_handler(cd);
4071 + return IRQ_HANDLED;
4074 +static void jz4740_clockevent_set_mode(enum clock_event_mode mode,
4075 + struct clock_event_device *cd)
4078 + case CLOCK_EVT_MODE_PERIODIC:
4079 + jz4740_timer_set_count(TIMER_CLOCKEVENT, 0);
4080 + jz4740_timer_set_period(TIMER_CLOCKEVENT, jz4740_jiffies_per_tick);
4081 + case CLOCK_EVT_MODE_RESUME:
4082 + jz4740_timer_irq_full_enable(TIMER_CLOCKEVENT);
4083 + jz4740_timer_enable(TIMER_CLOCKEVENT);
4085 + case CLOCK_EVT_MODE_ONESHOT:
4086 + case CLOCK_EVT_MODE_SHUTDOWN:
4087 + jz4740_timer_disable(TIMER_CLOCKEVENT);
4094 +static int jz4740_clockevent_set_next(unsigned long evt,
4095 + struct clock_event_device *cd)
4097 + jz4740_timer_set_count(TIMER_CLOCKEVENT, 0);
4098 + jz4740_timer_set_period(TIMER_CLOCKEVENT, evt);
4099 + jz4740_timer_enable(TIMER_CLOCKEVENT);
4104 +static struct clock_event_device jz4740_clockevent = {
4105 + .name = "jz4740-timer",
4106 + .features = CLOCK_EVT_FEAT_PERIODIC,
4107 + .set_next_event = jz4740_clockevent_set_next,
4108 + .set_mode = jz4740_clockevent_set_mode,
4110 + .irq = JZ4740_IRQ_TCU0,
4113 +static struct irqaction timer_irqaction = {
4114 + .handler = jz4740_clockevent_irq,
4115 + .flags = IRQF_PERCPU | IRQF_TIMER | IRQF_DISABLED,
4116 + .name = "jz4740-timerirq",
4117 + .dev_id = &jz4740_clockevent,
4120 +void __init plat_time_init(void)
4123 + uint32_t clk_rate;
4126 + jz4740_timer_init();
4128 + clk_rate = jz4740_clock_bdata.ext_rate >> 4;
4129 + jz4740_jiffies_per_tick = DIV_ROUND_CLOSEST(clk_rate, HZ);
4131 + clockevent_set_clock(&jz4740_clockevent, clk_rate);
4132 + jz4740_clockevent.min_delta_ns = clockevent_delta2ns(100, &jz4740_clockevent);
4133 + jz4740_clockevent.max_delta_ns = clockevent_delta2ns(0xffff, &jz4740_clockevent);
4134 + jz4740_clockevent.cpumask = cpumask_of(0);
4136 + clockevents_register_device(&jz4740_clockevent);
4138 + clocksource_set_clock(&jz4740_clocksource, clk_rate);
4139 + ret = clocksource_register(&jz4740_clocksource);
4142 + printk(KERN_ERR "Failed to register clocksource: %d\n", ret);
4144 + setup_irq(JZ4740_IRQ_TCU0, &timer_irqaction);
4146 + ctrl = JZ_TIMER_CTRL_PRESCALE_16 | JZ_TIMER_CTRL_SRC_EXT;
4148 + jz4740_timer_set_ctrl(TIMER_CLOCKEVENT, ctrl);
4149 + jz4740_timer_set_ctrl(TIMER_CLOCKSOURCE, ctrl);
4151 + jz4740_timer_set_period(TIMER_CLOCKEVENT, jz4740_jiffies_per_tick);
4152 + jz4740_timer_irq_full_enable(TIMER_CLOCKEVENT);
4154 + jz4740_timer_set_period(TIMER_CLOCKSOURCE, 0xffff);
4156 + jz4740_timer_enable(TIMER_CLOCKEVENT);
4157 + jz4740_timer_enable(TIMER_CLOCKSOURCE);
4159 diff --git a/arch/mips/jz4740/timer.c b/arch/mips/jz4740/timer.c
4160 new file mode 100644
4161 index 0000000..6e09cae
4163 +++ b/arch/mips/jz4740/timer.c
4166 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
4167 + * JZ4740 platform timer support
4169 + * This program is free software; you can redistribute it and/or modify it
4170 + * under the terms of the GNU General Public License as published by the
4171 + * Free Software Foundation; either version 2 of the License, or (at your
4172 + * option) any later version.
4174 + * You should have received a copy of the GNU General Public License along
4175 + * with this program; if not, write to the Free Software Foundation, Inc.,
4176 + * 675 Mass Ave, Cambridge, MA 02139, USA.
4180 +#include <linux/io.h>
4181 +#include <linux/kernel.h>
4182 +#include <linux/module.h>
4186 +#include <asm/mach-jz4740/base.h>
4188 +void __iomem *jz4740_timer_base;
4190 +void jz4740_timer_enable_watchdog(void)
4192 + writel(BIT(16), jz4740_timer_base + JZ_REG_TIMER_STOP_CLEAR);
4195 +void jz4740_timer_disable_watchdog(void)
4197 + writel(BIT(16), jz4740_timer_base + JZ_REG_TIMER_STOP_SET);
4200 +void __init jz4740_timer_init(void)
4202 + jz4740_timer_base = ioremap(CPHYSADDR(JZ4740_TCU_BASE_ADDR), 0x100);
4204 + if (!jz4740_timer_base)
4205 + panic("Failed to ioremap timer registers");
4207 + /* Disable all timer clocks except for those used as system timers */
4208 + writel(0x000100fc, jz4740_timer_base + JZ_REG_TIMER_STOP_SET);
4210 + /* Timer irqs are unmasked by default, mask them */
4211 + writel(0x00ff00ff, jz4740_timer_base + JZ_REG_TIMER_MASK_SET);
4213 diff --git a/arch/mips/jz4740/timer.h b/arch/mips/jz4740/timer.h
4214 new file mode 100644
4215 index 0000000..77d748c
4217 +++ b/arch/mips/jz4740/timer.h
4220 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
4221 + * JZ4740 platform timer support
4223 + * This program is free software; you can redistribute it and/or modify it
4224 + * under the terms of the GNU General Public License as published by the
4225 + * Free Software Foundation; either version 2 of the License, or (at your
4226 + * option) any later version.
4228 + * You should have received a copy of the GNU General Public License along
4229 + * with this program; if not, write to the Free Software Foundation, Inc.,
4230 + * 675 Mass Ave, Cambridge, MA 02139, USA.
4234 +#ifndef __MIPS_JZ4740_TIMER_H__
4235 +#define __MIPS_JZ4740_TIMER_H__
4237 +#include <linux/module.h>
4238 +#include <linux/io.h>
4240 +#define JZ_REG_TIMER_STOP 0x1C
4241 +#define JZ_REG_TIMER_STOP_SET 0x2C
4242 +#define JZ_REG_TIMER_STOP_CLEAR 0x3C
4243 +#define JZ_REG_TIMER_ENABLE 0x10
4244 +#define JZ_REG_TIMER_ENABLE_SET 0x14
4245 +#define JZ_REG_TIMER_ENABLE_CLEAR 0x18
4246 +#define JZ_REG_TIMER_FLAG 0x20
4247 +#define JZ_REG_TIMER_FLAG_SET 0x24
4248 +#define JZ_REG_TIMER_FLAG_CLEAR 0x28
4249 +#define JZ_REG_TIMER_MASK 0x30
4250 +#define JZ_REG_TIMER_MASK_SET 0x34
4251 +#define JZ_REG_TIMER_MASK_CLEAR 0x38
4253 +#define JZ_REG_TIMER_DFR(x) (((x) * 0x10) + 0x40)
4254 +#define JZ_REG_TIMER_DHR(x) (((x) * 0x10) + 0x44)
4255 +#define JZ_REG_TIMER_CNT(x) (((x) * 0x10) + 0x48)
4256 +#define JZ_REG_TIMER_CTRL(x) (((x) * 0x10) + 0x4C)
4258 +#define JZ_TIMER_IRQ_HALF(x) BIT((x) + 0x10)
4259 +#define JZ_TIMER_IRQ_FULL(x) BIT(x)
4261 +#define JZ_TIMER_CTRL_PWM_ACTIVE_LOW BIT(8)
4262 +#define JZ_TIMER_CTRL_PWM_ENABLE BIT(7)
4263 +#define JZ_TIMER_CTRL_PRESCALE_MASK 0x1c
4264 +#define JZ_TIMER_CTRL_PRESCALE_OFFSET 0x3
4265 +#define JZ_TIMER_CTRL_PRESCALE_1 (0 << 3)
4266 +#define JZ_TIMER_CTRL_PRESCALE_4 (1 << 3)
4267 +#define JZ_TIMER_CTRL_PRESCALE_16 (2 << 3)
4268 +#define JZ_TIMER_CTRL_PRESCALE_64 (3 << 3)
4269 +#define JZ_TIMER_CTRL_PRESCALE_256 (4 << 3)
4270 +#define JZ_TIMER_CTRL_PRESCALE_1024 (5 << 3)
4272 +#define JZ_TIMER_CTRL_PRESCALER(x) ((x) << JZ_TIMER_CTRL_PRESCALE_OFFSET)
4274 +#define JZ_TIMER_CTRL_SRC_EXT BIT(2)
4275 +#define JZ_TIMER_CTRL_SRC_RTC BIT(1)
4276 +#define JZ_TIMER_CTRL_SRC_PCLK BIT(0)
4278 +extern void __iomem *jz4740_timer_base;
4279 +void __init jz4740_timer_init(void);
4281 +static inline void jz4740_timer_stop(unsigned int timer)
4283 + writel(BIT(timer), jz4740_timer_base + JZ_REG_TIMER_STOP_SET);
4286 +static inline void jz4740_timer_start(unsigned int timer)
4288 + writel(BIT(timer), jz4740_timer_base + JZ_REG_TIMER_STOP_CLEAR);
4291 +static inline bool jz4740_timer_is_enabled(unsigned int timer)
4293 + return readb(jz4740_timer_base + JZ_REG_TIMER_ENABLE) & BIT(timer);
4296 +static inline void jz4740_timer_enable(unsigned int timer)
4298 + writeb(BIT(timer), jz4740_timer_base + JZ_REG_TIMER_ENABLE_SET);
4301 +static inline void jz4740_timer_disable(unsigned int timer)
4303 + writeb(BIT(timer), jz4740_timer_base + JZ_REG_TIMER_ENABLE_CLEAR);
4307 +static inline void jz4740_timer_set_period(unsigned int timer, uint16_t period)
4309 + writew(period, jz4740_timer_base + JZ_REG_TIMER_DFR(timer));
4312 +static inline void jz4740_timer_set_duty(unsigned int timer, uint16_t duty)
4314 + writew(duty, jz4740_timer_base + JZ_REG_TIMER_DHR(timer));
4317 +static inline void jz4740_timer_set_count(unsigned int timer, uint16_t count)
4319 + writew(count, jz4740_timer_base + JZ_REG_TIMER_CNT(timer));
4322 +static inline uint16_t jz4740_timer_get_count(unsigned int timer)
4324 + return readw(jz4740_timer_base + JZ_REG_TIMER_CNT(timer));
4327 +static inline void jz4740_timer_ack_full(unsigned int timer)
4329 + writel(JZ_TIMER_IRQ_FULL(timer), jz4740_timer_base + JZ_REG_TIMER_FLAG_CLEAR);
4332 +static inline void jz4740_timer_irq_full_enable(unsigned int timer)
4334 + writel(JZ_TIMER_IRQ_FULL(timer), jz4740_timer_base + JZ_REG_TIMER_FLAG_CLEAR);
4335 + writel(JZ_TIMER_IRQ_FULL(timer), jz4740_timer_base + JZ_REG_TIMER_MASK_CLEAR);
4338 +static inline void jz4740_timer_irq_full_disable(unsigned int timer)
4340 + writel(JZ_TIMER_IRQ_FULL(timer), jz4740_timer_base + JZ_REG_TIMER_MASK_SET);
4343 +static inline void jz4740_timer_set_ctrl(unsigned int timer, uint16_t ctrl)
4345 + writew(ctrl, jz4740_timer_base + JZ_REG_TIMER_CTRL(timer));
4349 diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
4350 index be5bb16..926c260 100644
4351 --- a/arch/mips/kernel/cpu-probe.c
4352 +++ b/arch/mips/kernel/cpu-probe.c
4353 @@ -163,6 +163,7 @@ void __init check_wait(void)
4355 case CPU_CAVIUM_OCTEON:
4356 case CPU_CAVIUM_OCTEON_PLUS:
4358 cpu_wait = r4k_wait;
4361 @@ -932,6 +933,22 @@ platform:
4365 +static inline void cpu_probe_ingenic(struct cpuinfo_mips *c, unsigned int cpu)
4367 + decode_configs(c);
4368 + /* JZRISC does not implement the CP0 counter. */
4369 + c->options &= ~MIPS_CPU_COUNTER;
4370 + switch (c->processor_id & 0xff00) {
4371 + case PRID_IMP_JZRISC:
4372 + c->cputype = CPU_JZRISC;
4373 + __cpu_name[cpu] = "Ingenic JZRISC";
4376 + panic("Unknown Ingenic Processor ID!");
4381 const char *__cpu_name[NR_CPUS];
4382 const char *__elf_platform;
4384 @@ -970,6 +987,9 @@ __cpuinit void cpu_probe(void)
4385 case PRID_COMP_CAVIUM:
4386 cpu_probe_cavium(c, cpu);
4388 + case PRID_COMP_INGENIC:
4389 + cpu_probe_ingenic(c, cpu);
4393 BUG_ON(!__cpu_name[cpu]);
4394 diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c
4395 index 86f004d..4510e61 100644
4396 --- a/arch/mips/mm/tlbex.c
4397 +++ b/arch/mips/mm/tlbex.c
4398 @@ -409,6 +409,11 @@ static void __cpuinit build_tlb_write_entry(u32 **p, struct uasm_label **l,
4408 panic("No TLB refill handler yet (CPU type: %d)",
4409 current_cpu_data.cputype);