diff options
Diffstat (limited to 'arch/avr32/mach-at32ap/hmatrix.c')
-rw-r--r-- | arch/avr32/mach-at32ap/hmatrix.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/arch/avr32/mach-at32ap/hmatrix.c b/arch/avr32/mach-at32ap/hmatrix.c new file mode 100644 index 000000000000..48f5ede77468 --- /dev/null +++ b/arch/avr32/mach-at32ap/hmatrix.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /* | ||
2 | * High-Speed Bus Matrix helper functions | ||
3 | * | ||
4 | * Copyright (C) 2008 Atmel Corporation | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | #include <linux/clk.h> | ||
11 | #include <linux/io.h> | ||
12 | |||
13 | #include <mach/chip.h> | ||
14 | #include <mach/hmatrix.h> | ||
15 | |||
16 | static inline void __hmatrix_write_reg(unsigned long offset, u32 value) | ||
17 | { | ||
18 | __raw_writel(value, (void __iomem __force *)(HMATRIX_BASE + offset)); | ||
19 | } | ||
20 | |||
21 | static inline u32 __hmatrix_read_reg(unsigned long offset) | ||
22 | { | ||
23 | return __raw_readl((void __iomem __force *)(HMATRIX_BASE + offset)); | ||
24 | } | ||
25 | |||
26 | /** | ||
27 | * hmatrix_write_reg - write HMATRIX configuration register | ||
28 | * @offset: register offset | ||
29 | * @value: value to be written to the register at @offset | ||
30 | */ | ||
31 | void hmatrix_write_reg(unsigned long offset, u32 value) | ||
32 | { | ||
33 | clk_enable(&at32_hmatrix_clk); | ||
34 | __hmatrix_write_reg(offset, value); | ||
35 | __hmatrix_read_reg(offset); | ||
36 | clk_disable(&at32_hmatrix_clk); | ||
37 | } | ||
38 | |||
39 | /** | ||
40 | * hmatrix_read_reg - read HMATRIX configuration register | ||
41 | * @offset: register offset | ||
42 | * | ||
43 | * Returns the value of the register at @offset. | ||
44 | */ | ||
45 | u32 hmatrix_read_reg(unsigned long offset) | ||
46 | { | ||
47 | u32 value; | ||
48 | |||
49 | clk_enable(&at32_hmatrix_clk); | ||
50 | value = __hmatrix_read_reg(offset); | ||
51 | clk_disable(&at32_hmatrix_clk); | ||
52 | |||
53 | return value; | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * hmatrix_sfr_set_bits - set bits in a slave's Special Function Register | ||
58 | * @slave_id: operate on the SFR belonging to this slave | ||
59 | * @mask: mask of bits to be set in the SFR | ||
60 | */ | ||
61 | void hmatrix_sfr_set_bits(unsigned int slave_id, u32 mask) | ||
62 | { | ||
63 | u32 value; | ||
64 | |||
65 | clk_enable(&at32_hmatrix_clk); | ||
66 | value = __hmatrix_read_reg(HMATRIX_SFR(slave_id)); | ||
67 | value |= mask; | ||
68 | __hmatrix_write_reg(HMATRIX_SFR(slave_id), value); | ||
69 | __hmatrix_read_reg(HMATRIX_SFR(slave_id)); | ||
70 | clk_disable(&at32_hmatrix_clk); | ||
71 | } | ||
72 | |||
73 | /** | ||
74 | * hmatrix_sfr_set_bits - clear bits in a slave's Special Function Register | ||
75 | * @slave_id: operate on the SFR belonging to this slave | ||
76 | * @mask: mask of bits to be cleared in the SFR | ||
77 | */ | ||
78 | void hmatrix_sfr_clear_bits(unsigned int slave_id, u32 mask) | ||
79 | { | ||
80 | u32 value; | ||
81 | |||
82 | clk_enable(&at32_hmatrix_clk); | ||
83 | value = __hmatrix_read_reg(HMATRIX_SFR(slave_id)); | ||
84 | value &= ~mask; | ||
85 | __hmatrix_write_reg(HMATRIX_SFR(slave_id), value); | ||
86 | __hmatrix_read_reg(HMATRIX_SFR(slave_id)); | ||
87 | clk_disable(&at32_hmatrix_clk); | ||
88 | } | ||