Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 1 | /* |
| 2 | * pinmux driver for CSR SiRFprimaII |
| 3 | * |
Barry Song | 019c12f | 2014-02-12 21:54:47 +0800 | [diff] [blame] | 4 | * Copyright (c) 2011 - 2014 Cambridge Silicon Radio Limited, a CSR plc group |
| 5 | * company. |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 6 | * |
| 7 | * Licensed under GPLv2 or later. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/irq.h> |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/io.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/irqdomain.h> |
| 18 | #include <linux/irqchip/chained_irq.h> |
| 19 | #include <linux/pinctrl/pinctrl.h> |
| 20 | #include <linux/pinctrl/pinmux.h> |
| 21 | #include <linux/pinctrl/consumer.h> |
| 22 | #include <linux/pinctrl/machine.h> |
| 23 | #include <linux/of.h> |
| 24 | #include <linux/of_address.h> |
| 25 | #include <linux/of_device.h> |
| 26 | #include <linux/of_platform.h> |
| 27 | #include <linux/bitops.h> |
| 28 | #include <linux/gpio.h> |
| 29 | #include <linux/of_gpio.h> |
| 30 | #include <asm/mach/irq.h> |
| 31 | |
| 32 | #include "pinctrl-sirf.h" |
| 33 | |
| 34 | #define DRIVER_NAME "pinmux-sirf" |
| 35 | |
| 36 | struct sirfsoc_gpio_bank { |
| 37 | struct of_mm_gpio_chip chip; |
| 38 | struct irq_domain *domain; |
| 39 | int id; |
| 40 | int parent_irq; |
| 41 | spinlock_t lock; |
| 42 | bool is_marco; /* for marco, some registers are different with prima2 */ |
| 43 | }; |
| 44 | |
| 45 | static struct sirfsoc_gpio_bank sgpio_bank[SIRFSOC_GPIO_NO_OF_BANKS]; |
| 46 | static DEFINE_SPINLOCK(sgpio_lock); |
| 47 | |
| 48 | static struct sirfsoc_pin_group *sirfsoc_pin_groups; |
| 49 | static int sirfsoc_pingrp_cnt; |
| 50 | |
| 51 | static int sirfsoc_get_groups_count(struct pinctrl_dev *pctldev) |
| 52 | { |
| 53 | return sirfsoc_pingrp_cnt; |
| 54 | } |
| 55 | |
| 56 | static const char *sirfsoc_get_group_name(struct pinctrl_dev *pctldev, |
| 57 | unsigned selector) |
| 58 | { |
| 59 | return sirfsoc_pin_groups[selector].name; |
| 60 | } |
| 61 | |
| 62 | static int sirfsoc_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector, |
| 63 | const unsigned **pins, |
| 64 | unsigned *num_pins) |
| 65 | { |
| 66 | *pins = sirfsoc_pin_groups[selector].pins; |
| 67 | *num_pins = sirfsoc_pin_groups[selector].num_pins; |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | static void sirfsoc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, |
| 72 | unsigned offset) |
| 73 | { |
| 74 | seq_printf(s, " " DRIVER_NAME); |
| 75 | } |
| 76 | |
| 77 | static int sirfsoc_dt_node_to_map(struct pinctrl_dev *pctldev, |
| 78 | struct device_node *np_config, |
| 79 | struct pinctrl_map **map, unsigned *num_maps) |
| 80 | { |
| 81 | struct sirfsoc_pmx *spmx = pinctrl_dev_get_drvdata(pctldev); |
| 82 | struct device_node *np; |
| 83 | struct property *prop; |
| 84 | const char *function, *group; |
| 85 | int ret, index = 0, count = 0; |
| 86 | |
| 87 | /* calculate number of maps required */ |
| 88 | for_each_child_of_node(np_config, np) { |
| 89 | ret = of_property_read_string(np, "sirf,function", &function); |
| 90 | if (ret < 0) |
| 91 | return ret; |
| 92 | |
| 93 | ret = of_property_count_strings(np, "sirf,pins"); |
| 94 | if (ret < 0) |
| 95 | return ret; |
| 96 | |
| 97 | count += ret; |
| 98 | } |
| 99 | |
| 100 | if (!count) { |
| 101 | dev_err(spmx->dev, "No child nodes passed via DT\n"); |
| 102 | return -ENODEV; |
| 103 | } |
| 104 | |
| 105 | *map = kzalloc(sizeof(**map) * count, GFP_KERNEL); |
| 106 | if (!*map) |
| 107 | return -ENOMEM; |
| 108 | |
| 109 | for_each_child_of_node(np_config, np) { |
| 110 | of_property_read_string(np, "sirf,function", &function); |
| 111 | of_property_for_each_string(np, "sirf,pins", prop, group) { |
| 112 | (*map)[index].type = PIN_MAP_TYPE_MUX_GROUP; |
| 113 | (*map)[index].data.mux.group = group; |
| 114 | (*map)[index].data.mux.function = function; |
| 115 | index++; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | *num_maps = count; |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | static void sirfsoc_dt_free_map(struct pinctrl_dev *pctldev, |
| 125 | struct pinctrl_map *map, unsigned num_maps) |
| 126 | { |
| 127 | kfree(map); |
| 128 | } |
| 129 | |
| 130 | static struct pinctrl_ops sirfsoc_pctrl_ops = { |
| 131 | .get_groups_count = sirfsoc_get_groups_count, |
| 132 | .get_group_name = sirfsoc_get_group_name, |
| 133 | .get_group_pins = sirfsoc_get_group_pins, |
| 134 | .pin_dbg_show = sirfsoc_pin_dbg_show, |
| 135 | .dt_node_to_map = sirfsoc_dt_node_to_map, |
| 136 | .dt_free_map = sirfsoc_dt_free_map, |
| 137 | }; |
| 138 | |
| 139 | static struct sirfsoc_pmx_func *sirfsoc_pmx_functions; |
| 140 | static int sirfsoc_pmxfunc_cnt; |
| 141 | |
| 142 | static void sirfsoc_pinmux_endisable(struct sirfsoc_pmx *spmx, unsigned selector, |
| 143 | bool enable) |
| 144 | { |
| 145 | int i; |
| 146 | const struct sirfsoc_padmux *mux = sirfsoc_pmx_functions[selector].padmux; |
| 147 | const struct sirfsoc_muxmask *mask = mux->muxmask; |
| 148 | |
| 149 | for (i = 0; i < mux->muxmask_counts; i++) { |
| 150 | u32 muxval; |
| 151 | if (!spmx->is_marco) { |
| 152 | muxval = readl(spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(mask[i].group)); |
| 153 | if (enable) |
| 154 | muxval = muxval & ~mask[i].mask; |
| 155 | else |
| 156 | muxval = muxval | mask[i].mask; |
| 157 | writel(muxval, spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(mask[i].group)); |
| 158 | } else { |
| 159 | if (enable) |
| 160 | writel(mask[i].mask, spmx->gpio_virtbase + |
| 161 | SIRFSOC_GPIO_PAD_EN_CLR(mask[i].group)); |
| 162 | else |
| 163 | writel(mask[i].mask, spmx->gpio_virtbase + |
| 164 | SIRFSOC_GPIO_PAD_EN(mask[i].group)); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if (mux->funcmask && enable) { |
| 169 | u32 func_en_val; |
Rong Wang | 6a08a92 | 2013-09-29 22:27:59 +0800 | [diff] [blame] | 170 | |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 171 | func_en_val = |
Rong Wang | 6a08a92 | 2013-09-29 22:27:59 +0800 | [diff] [blame] | 172 | readl(spmx->rsc_virtbase + mux->ctrlreg); |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 173 | func_en_val = |
Rong Wang | 6a08a92 | 2013-09-29 22:27:59 +0800 | [diff] [blame] | 174 | (func_en_val & ~mux->funcmask) | (mux->funcval); |
| 175 | writel(func_en_val, spmx->rsc_virtbase + mux->ctrlreg); |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | static int sirfsoc_pinmux_enable(struct pinctrl_dev *pmxdev, unsigned selector, |
| 180 | unsigned group) |
| 181 | { |
| 182 | struct sirfsoc_pmx *spmx; |
| 183 | |
| 184 | spmx = pinctrl_dev_get_drvdata(pmxdev); |
| 185 | sirfsoc_pinmux_endisable(spmx, selector, true); |
| 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | static void sirfsoc_pinmux_disable(struct pinctrl_dev *pmxdev, unsigned selector, |
| 191 | unsigned group) |
| 192 | { |
| 193 | struct sirfsoc_pmx *spmx; |
| 194 | |
| 195 | spmx = pinctrl_dev_get_drvdata(pmxdev); |
| 196 | sirfsoc_pinmux_endisable(spmx, selector, false); |
| 197 | } |
| 198 | |
| 199 | static int sirfsoc_pinmux_get_funcs_count(struct pinctrl_dev *pmxdev) |
| 200 | { |
| 201 | return sirfsoc_pmxfunc_cnt; |
| 202 | } |
| 203 | |
| 204 | static const char *sirfsoc_pinmux_get_func_name(struct pinctrl_dev *pctldev, |
| 205 | unsigned selector) |
| 206 | { |
| 207 | return sirfsoc_pmx_functions[selector].name; |
| 208 | } |
| 209 | |
| 210 | static int sirfsoc_pinmux_get_groups(struct pinctrl_dev *pctldev, unsigned selector, |
| 211 | const char * const **groups, |
| 212 | unsigned * const num_groups) |
| 213 | { |
| 214 | *groups = sirfsoc_pmx_functions[selector].groups; |
| 215 | *num_groups = sirfsoc_pmx_functions[selector].num_groups; |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static int sirfsoc_pinmux_request_gpio(struct pinctrl_dev *pmxdev, |
| 220 | struct pinctrl_gpio_range *range, unsigned offset) |
| 221 | { |
| 222 | struct sirfsoc_pmx *spmx; |
| 223 | |
| 224 | int group = range->id; |
| 225 | |
| 226 | u32 muxval; |
| 227 | |
| 228 | spmx = pinctrl_dev_get_drvdata(pmxdev); |
| 229 | |
| 230 | if (!spmx->is_marco) { |
| 231 | muxval = readl(spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group)); |
| 232 | muxval = muxval | (1 << (offset - range->pin_base)); |
| 233 | writel(muxval, spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group)); |
| 234 | } else { |
| 235 | writel(1 << (offset - range->pin_base), spmx->gpio_virtbase + |
| 236 | SIRFSOC_GPIO_PAD_EN(group)); |
| 237 | } |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static struct pinmux_ops sirfsoc_pinmux_ops = { |
| 243 | .enable = sirfsoc_pinmux_enable, |
| 244 | .disable = sirfsoc_pinmux_disable, |
| 245 | .get_functions_count = sirfsoc_pinmux_get_funcs_count, |
| 246 | .get_function_name = sirfsoc_pinmux_get_func_name, |
| 247 | .get_function_groups = sirfsoc_pinmux_get_groups, |
| 248 | .gpio_request_enable = sirfsoc_pinmux_request_gpio, |
| 249 | }; |
| 250 | |
| 251 | static struct pinctrl_desc sirfsoc_pinmux_desc = { |
| 252 | .name = DRIVER_NAME, |
| 253 | .pctlops = &sirfsoc_pctrl_ops, |
| 254 | .pmxops = &sirfsoc_pinmux_ops, |
| 255 | .owner = THIS_MODULE, |
| 256 | }; |
| 257 | |
| 258 | /* |
| 259 | * Todo: bind irq_chip to every pinctrl_gpio_range |
| 260 | */ |
| 261 | static struct pinctrl_gpio_range sirfsoc_gpio_ranges[] = { |
| 262 | { |
| 263 | .name = "sirfsoc-gpio*", |
| 264 | .id = 0, |
| 265 | .base = 0, |
| 266 | .pin_base = 0, |
| 267 | .npins = 32, |
| 268 | }, { |
| 269 | .name = "sirfsoc-gpio*", |
| 270 | .id = 1, |
| 271 | .base = 32, |
| 272 | .pin_base = 32, |
| 273 | .npins = 32, |
| 274 | }, { |
| 275 | .name = "sirfsoc-gpio*", |
| 276 | .id = 2, |
| 277 | .base = 64, |
| 278 | .pin_base = 64, |
| 279 | .npins = 32, |
| 280 | }, { |
| 281 | .name = "sirfsoc-gpio*", |
| 282 | .id = 3, |
| 283 | .base = 96, |
| 284 | .pin_base = 96, |
| 285 | .npins = 19, |
| 286 | }, |
| 287 | }; |
| 288 | |
| 289 | static void __iomem *sirfsoc_rsc_of_iomap(void) |
| 290 | { |
| 291 | const struct of_device_id rsc_ids[] = { |
| 292 | { .compatible = "sirf,prima2-rsc" }, |
| 293 | { .compatible = "sirf,marco-rsc" }, |
| 294 | {} |
| 295 | }; |
| 296 | struct device_node *np; |
| 297 | |
| 298 | np = of_find_matching_node(NULL, rsc_ids); |
| 299 | if (!np) |
| 300 | panic("unable to find compatible rsc node in dtb\n"); |
| 301 | |
| 302 | return of_iomap(np, 0); |
| 303 | } |
| 304 | |
| 305 | static int sirfsoc_gpio_of_xlate(struct gpio_chip *gc, |
| 306 | const struct of_phandle_args *gpiospec, |
| 307 | u32 *flags) |
| 308 | { |
| 309 | if (gpiospec->args[0] > SIRFSOC_GPIO_NO_OF_BANKS * SIRFSOC_GPIO_BANK_SIZE) |
Rongjun Ying | 9c95690 | 2013-07-04 15:55:28 +0800 | [diff] [blame] | 310 | return -EINVAL; |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 311 | |
| 312 | if (gc != &sgpio_bank[gpiospec->args[0] / SIRFSOC_GPIO_BANK_SIZE].chip.gc) |
Rongjun Ying | 9c95690 | 2013-07-04 15:55:28 +0800 | [diff] [blame] | 313 | return -EINVAL; |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 314 | |
| 315 | if (flags) |
Rongjun Ying | 9c95690 | 2013-07-04 15:55:28 +0800 | [diff] [blame] | 316 | *flags = gpiospec->args[1]; |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 317 | |
| 318 | return gpiospec->args[0] % SIRFSOC_GPIO_BANK_SIZE; |
| 319 | } |
| 320 | |
| 321 | static const struct of_device_id pinmux_ids[] = { |
| 322 | { .compatible = "sirf,prima2-pinctrl", .data = &prima2_pinctrl_data, }, |
| 323 | { .compatible = "sirf,atlas6-pinctrl", .data = &atlas6_pinctrl_data, }, |
| 324 | { .compatible = "sirf,marco-pinctrl", .data = &prima2_pinctrl_data, }, |
| 325 | {} |
| 326 | }; |
| 327 | |
| 328 | static int sirfsoc_pinmux_probe(struct platform_device *pdev) |
| 329 | { |
| 330 | int ret; |
| 331 | struct sirfsoc_pmx *spmx; |
| 332 | struct device_node *np = pdev->dev.of_node; |
| 333 | const struct sirfsoc_pinctrl_data *pdata; |
| 334 | int i; |
| 335 | |
| 336 | /* Create state holders etc for this driver */ |
| 337 | spmx = devm_kzalloc(&pdev->dev, sizeof(*spmx), GFP_KERNEL); |
| 338 | if (!spmx) |
| 339 | return -ENOMEM; |
| 340 | |
| 341 | spmx->dev = &pdev->dev; |
| 342 | |
| 343 | platform_set_drvdata(pdev, spmx); |
| 344 | |
| 345 | spmx->gpio_virtbase = of_iomap(np, 0); |
| 346 | if (!spmx->gpio_virtbase) { |
| 347 | dev_err(&pdev->dev, "can't map gpio registers\n"); |
| 348 | return -ENOMEM; |
| 349 | } |
| 350 | |
| 351 | spmx->rsc_virtbase = sirfsoc_rsc_of_iomap(); |
| 352 | if (!spmx->rsc_virtbase) { |
| 353 | ret = -ENOMEM; |
| 354 | dev_err(&pdev->dev, "can't map rsc registers\n"); |
| 355 | goto out_no_rsc_remap; |
| 356 | } |
| 357 | |
| 358 | if (of_device_is_compatible(np, "sirf,marco-pinctrl")) |
| 359 | spmx->is_marco = 1; |
| 360 | |
| 361 | pdata = of_match_node(pinmux_ids, np)->data; |
| 362 | sirfsoc_pin_groups = pdata->grps; |
| 363 | sirfsoc_pingrp_cnt = pdata->grps_cnt; |
| 364 | sirfsoc_pmx_functions = pdata->funcs; |
| 365 | sirfsoc_pmxfunc_cnt = pdata->funcs_cnt; |
| 366 | sirfsoc_pinmux_desc.pins = pdata->pads; |
| 367 | sirfsoc_pinmux_desc.npins = pdata->pads_cnt; |
| 368 | |
| 369 | |
| 370 | /* Now register the pin controller and all pins it handles */ |
| 371 | spmx->pmx = pinctrl_register(&sirfsoc_pinmux_desc, &pdev->dev, spmx); |
| 372 | if (!spmx->pmx) { |
| 373 | dev_err(&pdev->dev, "could not register SIRFSOC pinmux driver\n"); |
| 374 | ret = -EINVAL; |
| 375 | goto out_no_pmx; |
| 376 | } |
| 377 | |
| 378 | for (i = 0; i < ARRAY_SIZE(sirfsoc_gpio_ranges); i++) { |
| 379 | sirfsoc_gpio_ranges[i].gc = &sgpio_bank[i].chip.gc; |
| 380 | pinctrl_add_gpio_range(spmx->pmx, &sirfsoc_gpio_ranges[i]); |
| 381 | } |
| 382 | |
| 383 | dev_info(&pdev->dev, "initialized SIRFSOC pinmux driver\n"); |
| 384 | |
| 385 | return 0; |
| 386 | |
| 387 | out_no_pmx: |
| 388 | iounmap(spmx->rsc_virtbase); |
| 389 | out_no_rsc_remap: |
| 390 | iounmap(spmx->gpio_virtbase); |
| 391 | return ret; |
| 392 | } |
| 393 | |
Barry Song | bc8d25a | 2013-05-16 11:17:09 +0800 | [diff] [blame] | 394 | #ifdef CONFIG_PM_SLEEP |
| 395 | static int sirfsoc_pinmux_suspend_noirq(struct device *dev) |
| 396 | { |
| 397 | int i, j; |
| 398 | struct sirfsoc_pmx *spmx = dev_get_drvdata(dev); |
| 399 | |
| 400 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { |
| 401 | for (j = 0; j < SIRFSOC_GPIO_BANK_SIZE; j++) { |
| 402 | spmx->gpio_regs[i][j] = readl(spmx->gpio_virtbase + |
| 403 | SIRFSOC_GPIO_CTRL(i, j)); |
| 404 | } |
| 405 | spmx->ints_regs[i] = readl(spmx->gpio_virtbase + |
| 406 | SIRFSOC_GPIO_INT_STATUS(i)); |
| 407 | spmx->paden_regs[i] = readl(spmx->gpio_virtbase + |
| 408 | SIRFSOC_GPIO_PAD_EN(i)); |
| 409 | } |
| 410 | spmx->dspen_regs = readl(spmx->gpio_virtbase + SIRFSOC_GPIO_DSP_EN0); |
| 411 | |
| 412 | for (i = 0; i < 3; i++) |
| 413 | spmx->rsc_regs[i] = readl(spmx->rsc_virtbase + 4 * i); |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | static int sirfsoc_pinmux_resume_noirq(struct device *dev) |
| 419 | { |
| 420 | int i, j; |
| 421 | struct sirfsoc_pmx *spmx = dev_get_drvdata(dev); |
| 422 | |
| 423 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { |
| 424 | for (j = 0; j < SIRFSOC_GPIO_BANK_SIZE; j++) { |
| 425 | writel(spmx->gpio_regs[i][j], spmx->gpio_virtbase + |
| 426 | SIRFSOC_GPIO_CTRL(i, j)); |
| 427 | } |
| 428 | writel(spmx->ints_regs[i], spmx->gpio_virtbase + |
| 429 | SIRFSOC_GPIO_INT_STATUS(i)); |
| 430 | writel(spmx->paden_regs[i], spmx->gpio_virtbase + |
| 431 | SIRFSOC_GPIO_PAD_EN(i)); |
| 432 | } |
| 433 | writel(spmx->dspen_regs, spmx->gpio_virtbase + SIRFSOC_GPIO_DSP_EN0); |
| 434 | |
| 435 | for (i = 0; i < 3; i++) |
| 436 | writel(spmx->rsc_regs[i], spmx->rsc_virtbase + 4 * i); |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | static const struct dev_pm_ops sirfsoc_pinmux_pm_ops = { |
| 442 | .suspend_noirq = sirfsoc_pinmux_suspend_noirq, |
| 443 | .resume_noirq = sirfsoc_pinmux_resume_noirq, |
Barry Song | f6b1788 | 2013-07-04 15:59:53 +0800 | [diff] [blame] | 444 | .freeze_noirq = sirfsoc_pinmux_suspend_noirq, |
| 445 | .restore_noirq = sirfsoc_pinmux_resume_noirq, |
Barry Song | bc8d25a | 2013-05-16 11:17:09 +0800 | [diff] [blame] | 446 | }; |
| 447 | #endif |
| 448 | |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 449 | static struct platform_driver sirfsoc_pinmux_driver = { |
| 450 | .driver = { |
| 451 | .name = DRIVER_NAME, |
| 452 | .owner = THIS_MODULE, |
| 453 | .of_match_table = pinmux_ids, |
Barry Song | bc8d25a | 2013-05-16 11:17:09 +0800 | [diff] [blame] | 454 | #ifdef CONFIG_PM_SLEEP |
| 455 | .pm = &sirfsoc_pinmux_pm_ops, |
| 456 | #endif |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 457 | }, |
| 458 | .probe = sirfsoc_pinmux_probe, |
| 459 | }; |
| 460 | |
| 461 | static int __init sirfsoc_pinmux_init(void) |
| 462 | { |
| 463 | return platform_driver_register(&sirfsoc_pinmux_driver); |
| 464 | } |
| 465 | arch_initcall(sirfsoc_pinmux_init); |
| 466 | |
| 467 | static inline int sirfsoc_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
| 468 | { |
| 469 | struct sirfsoc_gpio_bank *bank = container_of(to_of_mm_gpio_chip(chip), |
| 470 | struct sirfsoc_gpio_bank, chip); |
| 471 | |
Barry Song | 8daeffb | 2014-01-11 16:48:42 +0800 | [diff] [blame] | 472 | return irq_create_mapping(bank->domain, offset + bank->id * |
| 473 | SIRFSOC_GPIO_BANK_SIZE); |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static inline int sirfsoc_gpio_to_offset(unsigned int gpio) |
| 477 | { |
| 478 | return gpio % SIRFSOC_GPIO_BANK_SIZE; |
| 479 | } |
| 480 | |
| 481 | static inline struct sirfsoc_gpio_bank *sirfsoc_gpio_to_bank(unsigned int gpio) |
| 482 | { |
| 483 | return &sgpio_bank[gpio / SIRFSOC_GPIO_BANK_SIZE]; |
| 484 | } |
| 485 | |
| 486 | static inline struct sirfsoc_gpio_bank *sirfsoc_irqchip_to_bank(struct gpio_chip *chip) |
| 487 | { |
| 488 | return container_of(to_of_mm_gpio_chip(chip), struct sirfsoc_gpio_bank, chip); |
| 489 | } |
| 490 | |
| 491 | static void sirfsoc_gpio_irq_ack(struct irq_data *d) |
| 492 | { |
| 493 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); |
| 494 | int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE; |
| 495 | u32 val, offset; |
| 496 | unsigned long flags; |
| 497 | |
| 498 | offset = SIRFSOC_GPIO_CTRL(bank->id, idx); |
| 499 | |
| 500 | spin_lock_irqsave(&sgpio_lock, flags); |
| 501 | |
| 502 | val = readl(bank->chip.regs + offset); |
| 503 | |
| 504 | writel(val, bank->chip.regs + offset); |
| 505 | |
| 506 | spin_unlock_irqrestore(&sgpio_lock, flags); |
| 507 | } |
| 508 | |
| 509 | static void __sirfsoc_gpio_irq_mask(struct sirfsoc_gpio_bank *bank, int idx) |
| 510 | { |
| 511 | u32 val, offset; |
| 512 | unsigned long flags; |
| 513 | |
| 514 | offset = SIRFSOC_GPIO_CTRL(bank->id, idx); |
| 515 | |
| 516 | spin_lock_irqsave(&sgpio_lock, flags); |
| 517 | |
| 518 | val = readl(bank->chip.regs + offset); |
| 519 | val &= ~SIRFSOC_GPIO_CTL_INTR_EN_MASK; |
| 520 | val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK; |
| 521 | writel(val, bank->chip.regs + offset); |
| 522 | |
| 523 | spin_unlock_irqrestore(&sgpio_lock, flags); |
| 524 | } |
| 525 | |
| 526 | static void sirfsoc_gpio_irq_mask(struct irq_data *d) |
| 527 | { |
| 528 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); |
| 529 | |
| 530 | __sirfsoc_gpio_irq_mask(bank, d->hwirq % SIRFSOC_GPIO_BANK_SIZE); |
| 531 | } |
| 532 | |
| 533 | static void sirfsoc_gpio_irq_unmask(struct irq_data *d) |
| 534 | { |
| 535 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); |
| 536 | int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE; |
| 537 | u32 val, offset; |
| 538 | unsigned long flags; |
| 539 | |
| 540 | offset = SIRFSOC_GPIO_CTRL(bank->id, idx); |
| 541 | |
| 542 | spin_lock_irqsave(&sgpio_lock, flags); |
| 543 | |
| 544 | val = readl(bank->chip.regs + offset); |
| 545 | val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK; |
| 546 | val |= SIRFSOC_GPIO_CTL_INTR_EN_MASK; |
| 547 | writel(val, bank->chip.regs + offset); |
| 548 | |
| 549 | spin_unlock_irqrestore(&sgpio_lock, flags); |
| 550 | } |
| 551 | |
| 552 | static int sirfsoc_gpio_irq_type(struct irq_data *d, unsigned type) |
| 553 | { |
| 554 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); |
| 555 | int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE; |
| 556 | u32 val, offset; |
| 557 | unsigned long flags; |
| 558 | |
| 559 | offset = SIRFSOC_GPIO_CTRL(bank->id, idx); |
| 560 | |
| 561 | spin_lock_irqsave(&sgpio_lock, flags); |
| 562 | |
| 563 | val = readl(bank->chip.regs + offset); |
Barry Song | b07ddcd | 2014-01-11 16:48:43 +0800 | [diff] [blame] | 564 | val &= ~(SIRFSOC_GPIO_CTL_INTR_STS_MASK | SIRFSOC_GPIO_CTL_OUT_EN_MASK); |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 565 | |
| 566 | switch (type) { |
| 567 | case IRQ_TYPE_NONE: |
| 568 | break; |
| 569 | case IRQ_TYPE_EDGE_RISING: |
| 570 | val |= SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK; |
| 571 | val &= ~SIRFSOC_GPIO_CTL_INTR_LOW_MASK; |
| 572 | break; |
| 573 | case IRQ_TYPE_EDGE_FALLING: |
| 574 | val &= ~SIRFSOC_GPIO_CTL_INTR_HIGH_MASK; |
| 575 | val |= SIRFSOC_GPIO_CTL_INTR_LOW_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK; |
| 576 | break; |
| 577 | case IRQ_TYPE_EDGE_BOTH: |
| 578 | val |= SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_LOW_MASK | |
| 579 | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK; |
| 580 | break; |
| 581 | case IRQ_TYPE_LEVEL_LOW: |
| 582 | val &= ~(SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK); |
| 583 | val |= SIRFSOC_GPIO_CTL_INTR_LOW_MASK; |
| 584 | break; |
| 585 | case IRQ_TYPE_LEVEL_HIGH: |
| 586 | val |= SIRFSOC_GPIO_CTL_INTR_HIGH_MASK; |
| 587 | val &= ~(SIRFSOC_GPIO_CTL_INTR_LOW_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK); |
| 588 | break; |
| 589 | } |
| 590 | |
| 591 | writel(val, bank->chip.regs + offset); |
| 592 | |
| 593 | spin_unlock_irqrestore(&sgpio_lock, flags); |
| 594 | |
| 595 | return 0; |
| 596 | } |
| 597 | |
Linus Walleij | 655dada | 2014-01-15 10:07:07 +0100 | [diff] [blame] | 598 | static unsigned int sirfsoc_gpio_irq_startup(struct irq_data *d) |
| 599 | { |
| 600 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); |
| 601 | |
Barry Song | e291fd2 | 2014-03-05 14:55:02 +0800 | [diff] [blame] | 602 | if (gpio_lock_as_irq(&bank->chip.gc, d->hwirq % SIRFSOC_GPIO_BANK_SIZE)) |
Linus Walleij | 655dada | 2014-01-15 10:07:07 +0100 | [diff] [blame] | 603 | dev_err(bank->chip.gc.dev, |
| 604 | "unable to lock HW IRQ %lu for IRQ\n", |
| 605 | d->hwirq); |
| 606 | sirfsoc_gpio_irq_unmask(d); |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | static void sirfsoc_gpio_irq_shutdown(struct irq_data *d) |
| 611 | { |
| 612 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); |
| 613 | |
| 614 | sirfsoc_gpio_irq_mask(d); |
Barry Song | e291fd2 | 2014-03-05 14:55:02 +0800 | [diff] [blame] | 615 | gpio_unlock_as_irq(&bank->chip.gc, d->hwirq % SIRFSOC_GPIO_BANK_SIZE); |
Linus Walleij | 655dada | 2014-01-15 10:07:07 +0100 | [diff] [blame] | 616 | } |
| 617 | |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 618 | static struct irq_chip sirfsoc_irq_chip = { |
| 619 | .name = "sirf-gpio-irq", |
| 620 | .irq_ack = sirfsoc_gpio_irq_ack, |
| 621 | .irq_mask = sirfsoc_gpio_irq_mask, |
| 622 | .irq_unmask = sirfsoc_gpio_irq_unmask, |
| 623 | .irq_set_type = sirfsoc_gpio_irq_type, |
Linus Walleij | 655dada | 2014-01-15 10:07:07 +0100 | [diff] [blame] | 624 | .irq_startup = sirfsoc_gpio_irq_startup, |
| 625 | .irq_shutdown = sirfsoc_gpio_irq_shutdown, |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 626 | }; |
| 627 | |
| 628 | static void sirfsoc_gpio_handle_irq(unsigned int irq, struct irq_desc *desc) |
| 629 | { |
| 630 | struct sirfsoc_gpio_bank *bank = irq_get_handler_data(irq); |
| 631 | u32 status, ctrl; |
| 632 | int idx = 0; |
| 633 | struct irq_chip *chip = irq_get_chip(irq); |
| 634 | |
| 635 | chained_irq_enter(chip, desc); |
| 636 | |
| 637 | status = readl(bank->chip.regs + SIRFSOC_GPIO_INT_STATUS(bank->id)); |
| 638 | if (!status) { |
| 639 | printk(KERN_WARNING |
| 640 | "%s: gpio id %d status %#x no interrupt is flaged\n", |
| 641 | __func__, bank->id, status); |
| 642 | handle_bad_irq(irq, desc); |
| 643 | return; |
| 644 | } |
| 645 | |
| 646 | while (status) { |
| 647 | ctrl = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, idx)); |
| 648 | |
| 649 | /* |
| 650 | * Here we must check whether the corresponding GPIO's interrupt |
| 651 | * has been enabled, otherwise just skip it |
| 652 | */ |
| 653 | if ((status & 0x1) && (ctrl & SIRFSOC_GPIO_CTL_INTR_EN_MASK)) { |
| 654 | pr_debug("%s: gpio id %d idx %d happens\n", |
| 655 | __func__, bank->id, idx); |
Barry Song | 8daeffb | 2014-01-11 16:48:42 +0800 | [diff] [blame] | 656 | generic_handle_irq(irq_find_mapping(bank->domain, idx + |
| 657 | bank->id * SIRFSOC_GPIO_BANK_SIZE)); |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | idx++; |
| 661 | status = status >> 1; |
| 662 | } |
| 663 | |
| 664 | chained_irq_exit(chip, desc); |
| 665 | } |
| 666 | |
| 667 | static inline void sirfsoc_gpio_set_input(struct sirfsoc_gpio_bank *bank, unsigned ctrl_offset) |
| 668 | { |
| 669 | u32 val; |
| 670 | |
| 671 | val = readl(bank->chip.regs + ctrl_offset); |
| 672 | val &= ~SIRFSOC_GPIO_CTL_OUT_EN_MASK; |
| 673 | writel(val, bank->chip.regs + ctrl_offset); |
| 674 | } |
| 675 | |
| 676 | static int sirfsoc_gpio_request(struct gpio_chip *chip, unsigned offset) |
| 677 | { |
| 678 | struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip); |
| 679 | unsigned long flags; |
| 680 | |
| 681 | if (pinctrl_request_gpio(chip->base + offset)) |
| 682 | return -ENODEV; |
| 683 | |
| 684 | spin_lock_irqsave(&bank->lock, flags); |
| 685 | |
| 686 | /* |
| 687 | * default status: |
| 688 | * set direction as input and mask irq |
| 689 | */ |
| 690 | sirfsoc_gpio_set_input(bank, SIRFSOC_GPIO_CTRL(bank->id, offset)); |
| 691 | __sirfsoc_gpio_irq_mask(bank, offset); |
| 692 | |
| 693 | spin_unlock_irqrestore(&bank->lock, flags); |
| 694 | |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | static void sirfsoc_gpio_free(struct gpio_chip *chip, unsigned offset) |
| 699 | { |
| 700 | struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip); |
| 701 | unsigned long flags; |
| 702 | |
| 703 | spin_lock_irqsave(&bank->lock, flags); |
| 704 | |
| 705 | __sirfsoc_gpio_irq_mask(bank, offset); |
| 706 | sirfsoc_gpio_set_input(bank, SIRFSOC_GPIO_CTRL(bank->id, offset)); |
| 707 | |
| 708 | spin_unlock_irqrestore(&bank->lock, flags); |
| 709 | |
| 710 | pinctrl_free_gpio(chip->base + offset); |
| 711 | } |
| 712 | |
| 713 | static int sirfsoc_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) |
| 714 | { |
| 715 | struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip); |
| 716 | int idx = sirfsoc_gpio_to_offset(gpio); |
| 717 | unsigned long flags; |
| 718 | unsigned offset; |
| 719 | |
| 720 | offset = SIRFSOC_GPIO_CTRL(bank->id, idx); |
| 721 | |
| 722 | spin_lock_irqsave(&bank->lock, flags); |
| 723 | |
| 724 | sirfsoc_gpio_set_input(bank, offset); |
| 725 | |
| 726 | spin_unlock_irqrestore(&bank->lock, flags); |
| 727 | |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | static inline void sirfsoc_gpio_set_output(struct sirfsoc_gpio_bank *bank, unsigned offset, |
| 732 | int value) |
| 733 | { |
| 734 | u32 out_ctrl; |
| 735 | unsigned long flags; |
| 736 | |
| 737 | spin_lock_irqsave(&bank->lock, flags); |
| 738 | |
| 739 | out_ctrl = readl(bank->chip.regs + offset); |
| 740 | if (value) |
| 741 | out_ctrl |= SIRFSOC_GPIO_CTL_DATAOUT_MASK; |
| 742 | else |
| 743 | out_ctrl &= ~SIRFSOC_GPIO_CTL_DATAOUT_MASK; |
| 744 | |
| 745 | out_ctrl &= ~SIRFSOC_GPIO_CTL_INTR_EN_MASK; |
| 746 | out_ctrl |= SIRFSOC_GPIO_CTL_OUT_EN_MASK; |
| 747 | writel(out_ctrl, bank->chip.regs + offset); |
| 748 | |
| 749 | spin_unlock_irqrestore(&bank->lock, flags); |
| 750 | } |
| 751 | |
| 752 | static int sirfsoc_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value) |
| 753 | { |
| 754 | struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip); |
| 755 | int idx = sirfsoc_gpio_to_offset(gpio); |
| 756 | u32 offset; |
| 757 | unsigned long flags; |
| 758 | |
| 759 | offset = SIRFSOC_GPIO_CTRL(bank->id, idx); |
| 760 | |
| 761 | spin_lock_irqsave(&sgpio_lock, flags); |
| 762 | |
| 763 | sirfsoc_gpio_set_output(bank, offset, value); |
| 764 | |
| 765 | spin_unlock_irqrestore(&sgpio_lock, flags); |
| 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | static int sirfsoc_gpio_get_value(struct gpio_chip *chip, unsigned offset) |
| 771 | { |
| 772 | struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip); |
| 773 | u32 val; |
| 774 | unsigned long flags; |
| 775 | |
| 776 | spin_lock_irqsave(&bank->lock, flags); |
| 777 | |
| 778 | val = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset)); |
| 779 | |
| 780 | spin_unlock_irqrestore(&bank->lock, flags); |
| 781 | |
| 782 | return !!(val & SIRFSOC_GPIO_CTL_DATAIN_MASK); |
| 783 | } |
| 784 | |
| 785 | static void sirfsoc_gpio_set_value(struct gpio_chip *chip, unsigned offset, |
| 786 | int value) |
| 787 | { |
| 788 | struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip); |
| 789 | u32 ctrl; |
| 790 | unsigned long flags; |
| 791 | |
| 792 | spin_lock_irqsave(&bank->lock, flags); |
| 793 | |
| 794 | ctrl = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset)); |
| 795 | if (value) |
| 796 | ctrl |= SIRFSOC_GPIO_CTL_DATAOUT_MASK; |
| 797 | else |
| 798 | ctrl &= ~SIRFSOC_GPIO_CTL_DATAOUT_MASK; |
| 799 | writel(ctrl, bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset)); |
| 800 | |
| 801 | spin_unlock_irqrestore(&bank->lock, flags); |
| 802 | } |
| 803 | |
| 804 | static int sirfsoc_gpio_irq_map(struct irq_domain *d, unsigned int irq, |
| 805 | irq_hw_number_t hwirq) |
| 806 | { |
| 807 | struct sirfsoc_gpio_bank *bank = d->host_data; |
| 808 | |
| 809 | if (!bank) |
| 810 | return -EINVAL; |
| 811 | |
| 812 | irq_set_chip(irq, &sirfsoc_irq_chip); |
| 813 | irq_set_handler(irq, handle_level_irq); |
Barry Song | 8daeffb | 2014-01-11 16:48:42 +0800 | [diff] [blame] | 814 | irq_set_chip_data(irq, bank + hwirq / SIRFSOC_GPIO_BANK_SIZE); |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 815 | set_irq_flags(irq, IRQF_VALID); |
| 816 | |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | static const struct irq_domain_ops sirfsoc_gpio_irq_simple_ops = { |
| 821 | .map = sirfsoc_gpio_irq_map, |
| 822 | .xlate = irq_domain_xlate_twocell, |
| 823 | }; |
| 824 | |
| 825 | static void sirfsoc_gpio_set_pullup(const u32 *pullups) |
| 826 | { |
| 827 | int i, n; |
| 828 | const unsigned long *p = (const unsigned long *)pullups; |
| 829 | |
| 830 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { |
| 831 | for_each_set_bit(n, p + i, BITS_PER_LONG) { |
| 832 | u32 offset = SIRFSOC_GPIO_CTRL(i, n); |
| 833 | u32 val = readl(sgpio_bank[i].chip.regs + offset); |
| 834 | val |= SIRFSOC_GPIO_CTL_PULL_MASK; |
| 835 | val |= SIRFSOC_GPIO_CTL_PULL_HIGH; |
| 836 | writel(val, sgpio_bank[i].chip.regs + offset); |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | static void sirfsoc_gpio_set_pulldown(const u32 *pulldowns) |
| 842 | { |
| 843 | int i, n; |
| 844 | const unsigned long *p = (const unsigned long *)pulldowns; |
| 845 | |
| 846 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { |
| 847 | for_each_set_bit(n, p + i, BITS_PER_LONG) { |
| 848 | u32 offset = SIRFSOC_GPIO_CTRL(i, n); |
| 849 | u32 val = readl(sgpio_bank[i].chip.regs + offset); |
| 850 | val |= SIRFSOC_GPIO_CTL_PULL_MASK; |
| 851 | val &= ~SIRFSOC_GPIO_CTL_PULL_HIGH; |
| 852 | writel(val, sgpio_bank[i].chip.regs + offset); |
| 853 | } |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | static int sirfsoc_gpio_probe(struct device_node *np) |
| 858 | { |
| 859 | int i, err = 0; |
| 860 | struct sirfsoc_gpio_bank *bank; |
Jingoo Han | 2c9fdcf | 2013-08-06 18:14:12 +0900 | [diff] [blame] | 861 | void __iomem *regs; |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 862 | struct platform_device *pdev; |
Barry Song | 8daeffb | 2014-01-11 16:48:42 +0800 | [diff] [blame] | 863 | struct irq_domain *domain; |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 864 | bool is_marco = false; |
| 865 | |
| 866 | u32 pullups[SIRFSOC_GPIO_NO_OF_BANKS], pulldowns[SIRFSOC_GPIO_NO_OF_BANKS]; |
| 867 | |
| 868 | pdev = of_find_device_by_node(np); |
| 869 | if (!pdev) |
| 870 | return -ENODEV; |
| 871 | |
| 872 | regs = of_iomap(np, 0); |
| 873 | if (!regs) |
| 874 | return -ENOMEM; |
| 875 | |
| 876 | if (of_device_is_compatible(np, "sirf,marco-pinctrl")) |
| 877 | is_marco = 1; |
| 878 | |
Barry Song | 8daeffb | 2014-01-11 16:48:42 +0800 | [diff] [blame] | 879 | domain = irq_domain_add_linear(np, SIRFSOC_GPIO_BANK_SIZE * SIRFSOC_GPIO_NO_OF_BANKS, |
| 880 | &sirfsoc_gpio_irq_simple_ops, sgpio_bank); |
| 881 | if (!domain) { |
| 882 | pr_err("%s: Failed to create irqdomain\n", np->full_name); |
| 883 | err = -ENOSYS; |
| 884 | goto out; |
| 885 | } |
| 886 | |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 887 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { |
| 888 | bank = &sgpio_bank[i]; |
| 889 | spin_lock_init(&bank->lock); |
| 890 | bank->chip.gc.request = sirfsoc_gpio_request; |
| 891 | bank->chip.gc.free = sirfsoc_gpio_free; |
| 892 | bank->chip.gc.direction_input = sirfsoc_gpio_direction_input; |
| 893 | bank->chip.gc.get = sirfsoc_gpio_get_value; |
| 894 | bank->chip.gc.direction_output = sirfsoc_gpio_direction_output; |
| 895 | bank->chip.gc.set = sirfsoc_gpio_set_value; |
| 896 | bank->chip.gc.to_irq = sirfsoc_gpio_to_irq; |
| 897 | bank->chip.gc.base = i * SIRFSOC_GPIO_BANK_SIZE; |
| 898 | bank->chip.gc.ngpio = SIRFSOC_GPIO_BANK_SIZE; |
| 899 | bank->chip.gc.label = kstrdup(np->full_name, GFP_KERNEL); |
| 900 | bank->chip.gc.of_node = np; |
| 901 | bank->chip.gc.of_xlate = sirfsoc_gpio_of_xlate; |
| 902 | bank->chip.gc.of_gpio_n_cells = 2; |
Linus Walleij | 655dada | 2014-01-15 10:07:07 +0100 | [diff] [blame] | 903 | bank->chip.gc.dev = &pdev->dev; |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 904 | bank->chip.regs = regs; |
| 905 | bank->id = i; |
| 906 | bank->is_marco = is_marco; |
| 907 | bank->parent_irq = platform_get_irq(pdev, i); |
| 908 | if (bank->parent_irq < 0) { |
| 909 | err = bank->parent_irq; |
| 910 | goto out; |
| 911 | } |
| 912 | |
| 913 | err = gpiochip_add(&bank->chip.gc); |
| 914 | if (err) { |
| 915 | pr_err("%s: error in probe function with status %d\n", |
| 916 | np->full_name, err); |
| 917 | goto out; |
| 918 | } |
| 919 | |
Barry Song | 8daeffb | 2014-01-11 16:48:42 +0800 | [diff] [blame] | 920 | bank->domain = domain; |
Barry Song | 3370dc9 | 2013-05-14 22:17:58 +0800 | [diff] [blame] | 921 | |
| 922 | irq_set_chained_handler(bank->parent_irq, sirfsoc_gpio_handle_irq); |
| 923 | irq_set_handler_data(bank->parent_irq, bank); |
| 924 | } |
| 925 | |
| 926 | if (!of_property_read_u32_array(np, "sirf,pullups", pullups, |
| 927 | SIRFSOC_GPIO_NO_OF_BANKS)) |
| 928 | sirfsoc_gpio_set_pullup(pullups); |
| 929 | |
| 930 | if (!of_property_read_u32_array(np, "sirf,pulldowns", pulldowns, |
| 931 | SIRFSOC_GPIO_NO_OF_BANKS)) |
| 932 | sirfsoc_gpio_set_pulldown(pulldowns); |
| 933 | |
| 934 | return 0; |
| 935 | |
| 936 | out: |
| 937 | iounmap(regs); |
| 938 | return err; |
| 939 | } |
| 940 | |
| 941 | static int __init sirfsoc_gpio_init(void) |
| 942 | { |
| 943 | |
| 944 | struct device_node *np; |
| 945 | |
| 946 | np = of_find_matching_node(NULL, pinmux_ids); |
| 947 | |
| 948 | if (!np) |
| 949 | return -ENODEV; |
| 950 | |
| 951 | return sirfsoc_gpio_probe(np); |
| 952 | } |
| 953 | subsys_initcall(sirfsoc_gpio_init); |
| 954 | |
| 955 | MODULE_AUTHOR("Rongjun Ying <rongjun.ying@csr.com>, " |
| 956 | "Yuping Luo <yuping.luo@csr.com>, " |
| 957 | "Barry Song <baohua.song@csr.com>"); |
| 958 | MODULE_DESCRIPTION("SIRFSOC pin control driver"); |
| 959 | MODULE_LICENSE("GPL"); |