10 #include <linux/module.h>
14 #include <linux/slab.h>
25 #include <linux/bitops.h>
30 #define DRIVER_NAME "pinmux-sirf"
32 #define SIRFSOC_NUM_PADS 622
33 #define SIRFSOC_RSC_PIN_MUX 0x4
35 #define SIRFSOC_GPIO_PAD_EN(g) ((g)*0x100 + 0x84)
36 #define SIRFSOC_GPIO_CTRL(g, i) ((g)*0x100 + (i)*4)
37 #define SIRFSOC_GPIO_DSP_EN0 (0x80)
38 #define SIRFSOC_GPIO_PAD_EN(g) ((g)*0x100 + 0x84)
39 #define SIRFSOC_GPIO_INT_STATUS(g) ((g)*0x100 + 0x8C)
41 #define SIRFSOC_GPIO_CTL_INTR_LOW_MASK 0x1
42 #define SIRFSOC_GPIO_CTL_INTR_HIGH_MASK 0x2
43 #define SIRFSOC_GPIO_CTL_INTR_TYPE_MASK 0x4
44 #define SIRFSOC_GPIO_CTL_INTR_EN_MASK 0x8
45 #define SIRFSOC_GPIO_CTL_INTR_STS_MASK 0x10
46 #define SIRFSOC_GPIO_CTL_OUT_EN_MASK 0x20
47 #define SIRFSOC_GPIO_CTL_DATAOUT_MASK 0x40
48 #define SIRFSOC_GPIO_CTL_DATAIN_MASK 0x80
49 #define SIRFSOC_GPIO_CTL_PULL_MASK 0x100
50 #define SIRFSOC_GPIO_CTL_PULL_HIGH 0x200
51 #define SIRFSOC_GPIO_CTL_DSP_INT 0x400
53 #define SIRFSOC_GPIO_NO_OF_BANKS 5
54 #define SIRFSOC_GPIO_BANK_SIZE 32
55 #define SIRFSOC_GPIO_NUM(bank, index) (((bank)*(32)) + (index))
58 struct of_mm_gpio_chip
chip;
72 static const struct pinctrl_pin_desc sirfsoc_pads[] = {
73 PINCTRL_PIN(0,
"gpio0-0"),
74 PINCTRL_PIN(1,
"gpio0-1"),
75 PINCTRL_PIN(2,
"gpio0-2"),
76 PINCTRL_PIN(3,
"gpio0-3"),
77 PINCTRL_PIN(4,
"pwm0"),
78 PINCTRL_PIN(5,
"pwm1"),
79 PINCTRL_PIN(6,
"pwm2"),
80 PINCTRL_PIN(7,
"pwm3"),
81 PINCTRL_PIN(8,
"warm_rst_b"),
82 PINCTRL_PIN(9,
"odo_0"),
83 PINCTRL_PIN(10,
"odo_1"),
84 PINCTRL_PIN(11,
"dr_dir"),
85 PINCTRL_PIN(12,
"viprom_fa"),
86 PINCTRL_PIN(13,
"scl_1"),
87 PINCTRL_PIN(14,
"ntrst"),
88 PINCTRL_PIN(15,
"sda_1"),
89 PINCTRL_PIN(16,
"x_ldd[16]"),
90 PINCTRL_PIN(17,
"x_ldd[17]"),
91 PINCTRL_PIN(18,
"x_ldd[18]"),
92 PINCTRL_PIN(19,
"x_ldd[19]"),
93 PINCTRL_PIN(20,
"x_ldd[20]"),
94 PINCTRL_PIN(21,
"x_ldd[21]"),
95 PINCTRL_PIN(22,
"x_ldd[22]"),
96 PINCTRL_PIN(23,
"x_ldd[23], lcdrom_frdy"),
97 PINCTRL_PIN(24,
"gps_sgn"),
98 PINCTRL_PIN(25,
"gps_mag"),
99 PINCTRL_PIN(26,
"gps_clk"),
100 PINCTRL_PIN(27,
"sd_cd_b_1"),
101 PINCTRL_PIN(28,
"sd_vcc_on_1"),
102 PINCTRL_PIN(29,
"sd_wp_b_1"),
103 PINCTRL_PIN(30,
"sd_clk_3"),
104 PINCTRL_PIN(31,
"sd_cmd_3"),
106 PINCTRL_PIN(32,
"x_sd_dat_3[0]"),
107 PINCTRL_PIN(33,
"x_sd_dat_3[1]"),
108 PINCTRL_PIN(34,
"x_sd_dat_3[2]"),
109 PINCTRL_PIN(35,
"x_sd_dat_3[3]"),
110 PINCTRL_PIN(36,
"x_sd_clk_4"),
111 PINCTRL_PIN(37,
"x_sd_cmd_4"),
112 PINCTRL_PIN(38,
"x_sd_dat_4[0]"),
113 PINCTRL_PIN(39,
"x_sd_dat_4[1]"),
114 PINCTRL_PIN(40,
"x_sd_dat_4[2]"),
115 PINCTRL_PIN(41,
"x_sd_dat_4[3]"),
116 PINCTRL_PIN(42,
"x_cko_1"),
117 PINCTRL_PIN(43,
"x_ac97_bit_clk"),
118 PINCTRL_PIN(44,
"x_ac97_dout"),
119 PINCTRL_PIN(45,
"x_ac97_din"),
120 PINCTRL_PIN(46,
"x_ac97_sync"),
121 PINCTRL_PIN(47,
"x_txd_1"),
122 PINCTRL_PIN(48,
"x_txd_2"),
123 PINCTRL_PIN(49,
"x_rxd_1"),
124 PINCTRL_PIN(50,
"x_rxd_2"),
125 PINCTRL_PIN(51,
"x_usclk_0"),
126 PINCTRL_PIN(52,
"x_utxd_0"),
127 PINCTRL_PIN(53,
"x_urxd_0"),
128 PINCTRL_PIN(54,
"x_utfs_0"),
129 PINCTRL_PIN(55,
"x_urfs_0"),
130 PINCTRL_PIN(56,
"x_usclk_1"),
131 PINCTRL_PIN(57,
"x_utxd_1"),
132 PINCTRL_PIN(58,
"x_urxd_1"),
133 PINCTRL_PIN(59,
"x_utfs_1"),
134 PINCTRL_PIN(60,
"x_urfs_1"),
135 PINCTRL_PIN(61,
"x_usclk_2"),
136 PINCTRL_PIN(62,
"x_utxd_2"),
137 PINCTRL_PIN(63,
"x_urxd_2"),
139 PINCTRL_PIN(64,
"x_utfs_2"),
140 PINCTRL_PIN(65,
"x_urfs_2"),
141 PINCTRL_PIN(66,
"x_df_we_b"),
142 PINCTRL_PIN(67,
"x_df_re_b"),
143 PINCTRL_PIN(68,
"x_txd_0"),
144 PINCTRL_PIN(69,
"x_rxd_0"),
145 PINCTRL_PIN(78,
"x_cko_0"),
146 PINCTRL_PIN(79,
"x_vip_pxd[7]"),
147 PINCTRL_PIN(80,
"x_vip_pxd[6]"),
148 PINCTRL_PIN(81,
"x_vip_pxd[5]"),
149 PINCTRL_PIN(82,
"x_vip_pxd[4]"),
150 PINCTRL_PIN(83,
"x_vip_pxd[3]"),
151 PINCTRL_PIN(84,
"x_vip_pxd[2]"),
152 PINCTRL_PIN(85,
"x_vip_pxd[1]"),
153 PINCTRL_PIN(86,
"x_vip_pxd[0]"),
154 PINCTRL_PIN(87,
"x_vip_vsync"),
155 PINCTRL_PIN(88,
"x_vip_hsync"),
156 PINCTRL_PIN(89,
"x_vip_pxclk"),
157 PINCTRL_PIN(90,
"x_sda_0"),
158 PINCTRL_PIN(91,
"x_scl_0"),
159 PINCTRL_PIN(92,
"x_df_ry_by"),
160 PINCTRL_PIN(93,
"x_df_cs_b[1]"),
161 PINCTRL_PIN(94,
"x_df_cs_b[0]"),
162 PINCTRL_PIN(95,
"x_l_pclk"),
164 PINCTRL_PIN(96,
"x_l_lck"),
165 PINCTRL_PIN(97,
"x_l_fck"),
166 PINCTRL_PIN(98,
"x_l_de"),
167 PINCTRL_PIN(99,
"x_ldd[0]"),
168 PINCTRL_PIN(100,
"x_ldd[1]"),
169 PINCTRL_PIN(101,
"x_ldd[2]"),
170 PINCTRL_PIN(102,
"x_ldd[3]"),
171 PINCTRL_PIN(103,
"x_ldd[4]"),
172 PINCTRL_PIN(104,
"x_ldd[5]"),
173 PINCTRL_PIN(105,
"x_ldd[6]"),
174 PINCTRL_PIN(106,
"x_ldd[7]"),
175 PINCTRL_PIN(107,
"x_ldd[8]"),
176 PINCTRL_PIN(108,
"x_ldd[9]"),
177 PINCTRL_PIN(109,
"x_ldd[10]"),
178 PINCTRL_PIN(110,
"x_ldd[11]"),
179 PINCTRL_PIN(111,
"x_ldd[12]"),
180 PINCTRL_PIN(112,
"x_ldd[13]"),
181 PINCTRL_PIN(113,
"x_ldd[14]"),
182 PINCTRL_PIN(114,
"x_ldd[15]"),
237 .muxmask_counts =
ARRAY_SIZE(lcd_16bits_sirfsoc_muxmask),
238 .muxmask = lcd_16bits_sirfsoc_muxmask,
243 static const unsigned lcd_16bits_pins[] = { 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
244 105, 106, 107, 108, 109, 110, 111, 112, 113, 114 };
257 .mask =
BIT(16) |
BIT(17),
262 .muxmask_counts =
ARRAY_SIZE(lcd_18bits_muxmask),
263 .muxmask = lcd_18bits_muxmask,
268 static const unsigned lcd_18bits_pins[] = { 16, 17, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
269 105, 106, 107, 108, 109, 110, 111, 112, 113, 114};
287 .muxmask_counts =
ARRAY_SIZE(lcd_24bits_muxmask),
288 .muxmask = lcd_24bits_muxmask,
293 static const unsigned lcd_24bits_pins[] = { 16, 17, 18, 19, 20, 21, 22, 23, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
294 105, 106, 107, 108, 109, 110, 111, 112, 113, 114 };
313 .muxmask = lcdrom_muxmask,
318 static const unsigned lcdrom_pins[] = { 23, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
319 105, 106, 107, 108, 109, 110, 111, 112, 113, 114 };
327 .mask =
BIT(23) |
BIT(28),
333 .muxmask = uart0_muxmask,
338 static const unsigned uart0_pins[] = { 55, 60, 68, 69 };
348 .muxmask_counts =
ARRAY_SIZE(uart0_nostreamctrl_muxmask),
349 .muxmask = uart0_nostreamctrl_muxmask,
352 static const unsigned uart0_nostreamctrl_pins[] = { 68, 39 };
357 .mask =
BIT(15) |
BIT(17),
363 .muxmask = uart1_muxmask,
366 static const unsigned uart1_pins[] = { 47, 49 };
377 .muxmask = uart2_muxmask,
382 static const unsigned uart2_pins[] = { 48, 50, 56, 59 };
387 .mask =
BIT(16) |
BIT(18),
392 .muxmask_counts =
ARRAY_SIZE(uart2_nostreamctrl_muxmask),
393 .muxmask = uart2_nostreamctrl_muxmask,
396 static const unsigned uart2_nostreamctrl_pins[] = { 48, 50 };
401 .mask =
BIT(30) |
BIT(31),
410 .muxmask = sdmmc3_muxmask,
415 static const unsigned sdmmc3_pins[] = { 30, 31, 32, 33, 34, 35 };
426 .muxmask = spi0_muxmask,
431 static const unsigned spi0_pins[] = { 32, 33, 34, 35 };
442 .muxmask = sdmmc4_muxmask,
445 static const unsigned sdmmc4_pins[] = { 36, 37, 38, 39, 40, 41 };
456 .muxmask = cko1_muxmask,
461 static const unsigned cko1_pins[] = { 42 };
474 .muxmask = i2s_muxmask,
475 .funcmask =
BIT(3) |
BIT(9),
479 static const unsigned i2s_pins[] = { 42, 43, 44, 45, 46, 51, 55, 60 };
490 .muxmask = ac97_muxmask,
495 static const unsigned ac97_pins[] = { 33, 34, 35, 36 };
506 .muxmask = spi1_muxmask,
511 static const unsigned spi1_pins[] = { 43, 44, 45, 46 };
522 .muxmask = sdmmc1_muxmask,
525 static const unsigned sdmmc1_pins[] = { 27, 28, 29 };
536 .muxmask = gps_muxmask,
541 static const unsigned gps_pins[] = { 24, 25, 26 };
558 .muxmask = sdmmc5_muxmask,
559 .funcmask =
BIT(13) |
BIT(14),
560 .funcval =
BIT(13) |
BIT(14),
563 static const unsigned sdmmc5_pins[] = { 24, 25, 26, 61, 64, 65 };
574 .muxmask = usp0_muxmask,
579 static const unsigned usp0_pins[] = { 51, 52, 53, 54, 55 };
590 .muxmask = usp1_muxmask,
595 static const unsigned usp1_pins[] = { 56, 57, 58, 59, 60 };
609 .muxmask = usp2_muxmask,
610 .funcmask =
BIT(13) |
BIT(14),
614 static const unsigned usp2_pins[] = { 61, 62, 63, 64, 65 };
625 .muxmask = nand_muxmask,
630 static const unsigned nand_pins[] = { 64, 65, 92, 93, 94 };
638 static const unsigned sdmmc0_pins[] = { };
649 .muxmask = sdmmc2_muxmask,
654 static const unsigned sdmmc2_pins[] = { 66, 67 };
665 .muxmask = cko0_muxmask,
668 static const unsigned cko0_pins[] = { 78 };
681 .muxmask = vip_muxmask,
686 static const unsigned vip_pins[] = { 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89 };
691 .mask =
BIT(26) |
BIT(27),
697 .muxmask = i2c0_muxmask,
700 static const unsigned i2c0_pins[] = { 90, 91 };
705 .mask =
BIT(13) |
BIT(15),
711 .muxmask = i2c1_muxmask,
714 static const unsigned i2c1_pins[] = { 13, 15 };
730 .muxmask = viprom_muxmask,
735 static const unsigned viprom_pins[] = { 12, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89 };
746 .muxmask = pwm0_muxmask,
751 static const unsigned pwm0_pins[] = { 4 };
762 .muxmask = pwm1_muxmask,
765 static const unsigned pwm1_pins[] = { 5 };
776 .muxmask = pwm2_muxmask,
779 static const unsigned pwm2_pins[] = { 6 };
790 .muxmask = pwm3_muxmask,
793 static const unsigned pwm3_pins[] = { 7 };
803 .muxmask_counts =
ARRAY_SIZE(warm_rst_muxmask),
804 .muxmask = warm_rst_muxmask,
807 static const unsigned warm_rst_pins[] = { 8 };
816 .muxmask_counts =
ARRAY_SIZE(usb0_utmi_drvbus_muxmask),
817 .muxmask = usb0_utmi_drvbus_muxmask,
822 static const unsigned usb0_utmi_drvbus_pins[] = { 54 };
832 .muxmask_counts =
ARRAY_SIZE(usb1_utmi_drvbus_muxmask),
833 .muxmask = usb1_utmi_drvbus_muxmask,
838 static const unsigned usb1_utmi_drvbus_pins[] = { 59 };
848 .muxmask_counts =
ARRAY_SIZE(pulse_count_muxmask),
849 .muxmask = pulse_count_muxmask,
852 static const unsigned pulse_count_pins[] = { 9, 10, 11 };
854 #define SIRFSOC_PIN_GROUP(n, p) \
858 .num_pins = ARRAY_SIZE(p), \
901 static int sirfsoc_get_groups_count(
struct pinctrl_dev *pctldev)
906 static const char *sirfsoc_get_group_name(
struct pinctrl_dev *pctldev,
909 return sirfsoc_pin_groups[selector].
name;
913 const unsigned **
pins,
916 *pins = sirfsoc_pin_groups[selector].
pins;
917 *num_pins = sirfsoc_pin_groups[selector].
num_pins;
927 static int sirfsoc_dt_node_to_map(
struct pinctrl_dev *pctldev,
934 const char *
function, *
group;
951 dev_err(spmx->
dev,
"No child nodes passed via DT\n");
964 (*map)[
index].data.mux.function =
function;
974 static void sirfsoc_dt_free_map(
struct pinctrl_dev *pctldev,
980 static struct pinctrl_ops sirfsoc_pctrl_ops = {
981 .get_groups_count = sirfsoc_get_groups_count,
982 .get_group_name = sirfsoc_get_group_name,
983 .get_group_pins = sirfsoc_get_group_pins,
984 .pin_dbg_show = sirfsoc_pin_dbg_show,
985 .dt_node_to_map = sirfsoc_dt_node_to_map,
986 .dt_free_map = sirfsoc_dt_free_map,
996 static const char *
const lcd_16bitsgrp[] = {
"lcd_16bitsgrp" };
997 static const char *
const lcd_18bitsgrp[] = {
"lcd_18bitsgrp" };
998 static const char *
const lcd_24bitsgrp[] = {
"lcd_24bitsgrp" };
999 static const char *
const lcdromgrp[] = {
"lcdromgrp" };
1000 static const char *
const uart0grp[] = {
"uart0grp" };
1001 static const char *
const uart1grp[] = {
"uart1grp" };
1002 static const char *
const uart2grp[] = {
"uart2grp" };
1003 static const char *
const uart2_nostreamctrlgrp[] = {
"uart2_nostreamctrlgrp" };
1004 static const char *
const usp0grp[] = {
"usp0grp" };
1005 static const char *
const usp1grp[] = {
"usp1grp" };
1006 static const char *
const usp2grp[] = {
"usp2grp" };
1007 static const char *
const i2c0grp[] = {
"i2c0grp" };
1008 static const char *
const i2c1grp[] = {
"i2c1grp" };
1009 static const char *
const pwm0grp[] = {
"pwm0grp" };
1010 static const char *
const pwm1grp[] = {
"pwm1grp" };
1011 static const char *
const pwm2grp[] = {
"pwm2grp" };
1012 static const char *
const pwm3grp[] = {
"pwm3grp" };
1013 static const char *
const vipgrp[] = {
"vipgrp" };
1014 static const char *
const vipromgrp[] = {
"vipromgrp" };
1015 static const char *
const warm_rstgrp[] = {
"warm_rstgrp" };
1016 static const char *
const cko0grp[] = {
"cko0grp" };
1017 static const char *
const cko1grp[] = {
"cko1grp" };
1018 static const char *
const sdmmc0grp[] = {
"sdmmc0grp" };
1019 static const char *
const sdmmc1grp[] = {
"sdmmc1grp" };
1020 static const char *
const sdmmc2grp[] = {
"sdmmc2grp" };
1021 static const char *
const sdmmc3grp[] = {
"sdmmc3grp" };
1022 static const char *
const sdmmc4grp[] = {
"sdmmc4grp" };
1023 static const char *
const sdmmc5grp[] = {
"sdmmc5grp" };
1024 static const char *
const usb0_utmi_drvbusgrp[] = {
"usb0_utmi_drvbusgrp" };
1025 static const char *
const usb1_utmi_drvbusgrp[] = {
"usb1_utmi_drvbusgrp" };
1026 static const char *
const pulse_countgrp[] = {
"pulse_countgrp" };
1027 static const char *
const i2sgrp[] = {
"i2sgrp" };
1028 static const char *
const ac97grp[] = {
"ac97grp" };
1029 static const char *
const nandgrp[] = {
"nandgrp" };
1030 static const char *
const spi0grp[] = {
"spi0grp" };
1031 static const char *
const spi1grp[] = {
"spi1grp" };
1032 static const char *
const gpsgrp[] = {
"gpsgrp" };
1034 #define SIRFSOC_PMX_FUNCTION(n, g, m) \
1038 .num_groups = ARRAY_SIZE(g), \
1093 muxval = muxval & ~mask[
i].
mask;
1095 muxval = muxval | mask[
i].
mask;
1104 (func_en_val & ~mux->
funcmask) | (mux->
1110 static int sirfsoc_pinmux_enable(
struct pinctrl_dev *pmxdev,
unsigned selector,
1116 sirfsoc_pinmux_endisable(spmx, selector,
true);
1121 static void sirfsoc_pinmux_disable(
struct pinctrl_dev *pmxdev,
unsigned selector,
1127 sirfsoc_pinmux_endisable(spmx, selector,
false);
1130 static int sirfsoc_pinmux_get_funcs_count(
struct pinctrl_dev *pmxdev)
1135 static const char *sirfsoc_pinmux_get_func_name(
struct pinctrl_dev *pctldev,
1138 return sirfsoc_pmx_functions[selector].
name;
1141 static int sirfsoc_pinmux_get_groups(
struct pinctrl_dev *pctldev,
unsigned selector,
1142 const char *
const **groups,
1143 unsigned *
const num_groups)
1145 *groups = sirfsoc_pmx_functions[selector].
groups;
1146 *num_groups = sirfsoc_pmx_functions[selector].
num_groups;
1150 static int sirfsoc_pinmux_request_gpio(
struct pinctrl_dev *pmxdev,
1151 struct pinctrl_gpio_range *
range,
unsigned offset)
1155 int group = range->id;
1162 muxval = muxval | (1 << (offset - range->pin_base));
1168 static struct pinmux_ops sirfsoc_pinmux_ops = {
1169 .enable = sirfsoc_pinmux_enable,
1170 .disable = sirfsoc_pinmux_disable,
1171 .get_functions_count = sirfsoc_pinmux_get_funcs_count,
1172 .get_function_name = sirfsoc_pinmux_get_func_name,
1173 .get_function_groups = sirfsoc_pinmux_get_groups,
1174 .gpio_request_enable = sirfsoc_pinmux_request_gpio,
1177 static struct pinctrl_desc sirfsoc_pinmux_desc = {
1179 .pins = sirfsoc_pads,
1181 .pctlops = &sirfsoc_pctrl_ops,
1182 .pmxops = &sirfsoc_pinmux_ops,
1189 static struct pinctrl_gpio_range sirfsoc_gpio_ranges[] = {
1191 .name =
"sirfsoc-gpio*",
1197 .name =
"sirfsoc-gpio*",
1203 .name =
"sirfsoc-gpio*",
1209 .name =
"sirfsoc-gpio*",
1217 static void __iomem *sirfsoc_rsc_of_iomap(
void)
1227 panic(
"unable to find compatible rsc node in dtb\n");
1246 platform_set_drvdata(pdev, spmx);
1251 dev_err(&pdev->
dev,
"can't map gpio registers\n");
1252 goto out_no_gpio_remap;
1258 dev_err(&pdev->
dev,
"can't map rsc registers\n");
1259 goto out_no_rsc_remap;
1265 dev_err(&pdev->
dev,
"could not register SIRFSOC pinmux driver\n");
1270 for (i = 0; i <
ARRAY_SIZE(sirfsoc_gpio_ranges); i++) {
1271 sirfsoc_gpio_ranges[
i].gc = &sgpio_bank[
i].chip.gc;
1275 dev_info(&pdev->
dev,
"initialized SIRFSOC pinmux driver\n");
1284 platform_set_drvdata(pdev,
NULL);
1289 { .compatible =
"sirf,prima2-pinctrl" },
1297 .of_match_table = pinmux_ids,
1299 .probe = sirfsoc_pinmux_probe,
1302 static int __init sirfsoc_pinmux_init(
void)
1308 static inline int sirfsoc_gpio_to_irq(
struct gpio_chip *
chip,
unsigned offset)
1316 static inline int sirfsoc_gpio_to_offset(
unsigned int gpio)
1326 static inline struct sirfsoc_gpio_bank *sirfsoc_irqchip_to_bank(
struct gpio_chip *chip)
1331 static void sirfsoc_gpio_irq_ack(
struct irq_data *
d)
1336 unsigned long flags;
1346 spin_unlock_irqrestore(&sgpio_lock, flags);
1352 unsigned long flags;
1363 spin_unlock_irqrestore(&sgpio_lock, flags);
1366 static void sirfsoc_gpio_irq_mask(
struct irq_data *
d)
1373 static void sirfsoc_gpio_irq_unmask(
struct irq_data *
d)
1378 unsigned long flags;
1389 spin_unlock_irqrestore(&sgpio_lock, flags);
1392 static int sirfsoc_gpio_irq_type(
struct irq_data *
d,
unsigned type)
1397 unsigned long flags;
1433 spin_unlock_irqrestore(&sgpio_lock, flags);
1438 static struct irq_chip sirfsoc_irq_chip = {
1439 .name =
"sirf-gpio-irq",
1440 .irq_ack = sirfsoc_gpio_irq_ack,
1441 .irq_mask = sirfsoc_gpio_irq_mask,
1442 .irq_unmask = sirfsoc_gpio_irq_unmask,
1443 .irq_set_type = sirfsoc_gpio_irq_type,
1446 static void sirfsoc_gpio_handle_irq(
unsigned int irq,
struct irq_desc *
desc)
1451 unsigned int first_irq;
1452 struct irq_chip *chip = irq_get_chip(irq);
1454 chained_irq_enter(chip, desc);
1459 "%s: gpio id %d status %#x no interrupt is flaged\n",
1460 __func__, bank->
id, status);
1465 first_irq = bank->
domain->revmap_data.legacy.first_irq;
1475 pr_debug(
"%s: gpio id %d idx %d happens\n",
1476 __func__, bank->
id, idx);
1481 status = status >> 1;
1484 chained_irq_exit(chip, desc);
1487 static inline void sirfsoc_gpio_set_input(
struct sirfsoc_gpio_bank *bank,
unsigned ctrl_offset)
1491 val =
readl(bank->
chip.regs + ctrl_offset);
1496 static int sirfsoc_gpio_request(
struct gpio_chip *chip,
unsigned offset)
1499 unsigned long flags;
1511 __sirfsoc_gpio_irq_mask(bank, offset);
1513 spin_unlock_irqrestore(&bank->
lock, flags);
1518 static void sirfsoc_gpio_free(
struct gpio_chip *chip,
unsigned offset)
1521 unsigned long flags;
1525 __sirfsoc_gpio_irq_mask(bank, offset);
1528 spin_unlock_irqrestore(&bank->
lock, flags);
1533 static int sirfsoc_gpio_direction_input(
struct gpio_chip *chip,
unsigned gpio)
1536 int idx = sirfsoc_gpio_to_offset(gpio);
1537 unsigned long flags;
1544 sirfsoc_gpio_set_input(bank, offset);
1546 spin_unlock_irqrestore(&bank->
lock, flags);
1551 static inline void sirfsoc_gpio_set_output(
struct sirfsoc_gpio_bank *bank,
unsigned offset,
1555 unsigned long flags;
1559 out_ctrl =
readl(bank->
chip.regs + offset);
1569 spin_unlock_irqrestore(&bank->
lock, flags);
1572 static int sirfsoc_gpio_direction_output(
struct gpio_chip *chip,
unsigned gpio,
int value)
1575 int idx = sirfsoc_gpio_to_offset(gpio);
1577 unsigned long flags;
1583 sirfsoc_gpio_set_output(bank, offset, value);
1585 spin_unlock_irqrestore(&sgpio_lock, flags);
1590 static int sirfsoc_gpio_get_value(
struct gpio_chip *chip,
unsigned offset)
1594 unsigned long flags;
1600 spin_unlock_irqrestore(&bank->
lock, flags);
1605 static void sirfsoc_gpio_set_value(
struct gpio_chip *chip,
unsigned offset,
1610 unsigned long flags;
1621 spin_unlock_irqrestore(&bank->
lock, flags);
1661 bank = &sgpio_bank[
i];
1663 bank->
chip.gc.request = sirfsoc_gpio_request;
1664 bank->
chip.gc.free = sirfsoc_gpio_free;
1665 bank->
chip.gc.direction_input = sirfsoc_gpio_direction_input;
1666 bank->
chip.gc.get = sirfsoc_gpio_get_value;
1667 bank->
chip.gc.direction_output = sirfsoc_gpio_direction_output;
1668 bank->
chip.gc.set = sirfsoc_gpio_set_value;
1669 bank->
chip.gc.to_irq = sirfsoc_gpio_to_irq;
1673 bank->
chip.gc.of_node = np;
1684 pr_err(
"%s: error in probe function with status %d\n",
1691 &sirfsoc_gpio_irq_simple_ops, bank);
1699 irq_set_chained_handler(bank->
parent_irq, sirfsoc_gpio_handle_irq);
1710 static int __init sirfsoc_gpio_init(
void)
1720 return sirfsoc_gpio_probe(np);