gpio-clps711x.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * CLPS711X GPIO driver
  3. *
  4. * Copyright (C) 2012,2013 Alexander Shiyan <[email protected]>
  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 as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/err.h>
  12. #include <linux/module.h>
  13. #include <linux/gpio/driver.h>
  14. #include <linux/platform_device.h>
  15. static int clps711x_gpio_probe(struct platform_device *pdev)
  16. {
  17. struct device_node *np = pdev->dev.of_node;
  18. void __iomem *dat, *dir;
  19. struct gpio_chip *gc;
  20. struct resource *res;
  21. int err, id;
  22. if (!np)
  23. return -ENODEV;
  24. id = of_alias_get_id(np, "gpio");
  25. if ((id < 0) || (id > 4))
  26. return -ENODEV;
  27. gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
  28. if (!gc)
  29. return -ENOMEM;
  30. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  31. dat = devm_ioremap_resource(&pdev->dev, res);
  32. if (IS_ERR(dat))
  33. return PTR_ERR(dat);
  34. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  35. dir = devm_ioremap_resource(&pdev->dev, res);
  36. if (IS_ERR(dir))
  37. return PTR_ERR(dir);
  38. switch (id) {
  39. case 3:
  40. /* PORTD is inverted logic for direction register */
  41. err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
  42. NULL, dir, 0);
  43. break;
  44. default:
  45. err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
  46. dir, NULL, 0);
  47. break;
  48. }
  49. if (err)
  50. return err;
  51. switch (id) {
  52. case 4:
  53. /* PORTE is 3 lines only */
  54. gc->ngpio = 3;
  55. break;
  56. default:
  57. break;
  58. }
  59. gc->base = -1;
  60. gc->owner = THIS_MODULE;
  61. platform_set_drvdata(pdev, gc);
  62. return devm_gpiochip_add_data(&pdev->dev, gc, NULL);
  63. }
  64. static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = {
  65. { .compatible = "cirrus,ep7209-gpio" },
  66. { }
  67. };
  68. MODULE_DEVICE_TABLE(of, clps711x_gpio_ids);
  69. static struct platform_driver clps711x_gpio_driver = {
  70. .driver = {
  71. .name = "clps711x-gpio",
  72. .of_match_table = of_match_ptr(clps711x_gpio_ids),
  73. },
  74. .probe = clps711x_gpio_probe,
  75. };
  76. module_platform_driver(clps711x_gpio_driver);
  77. MODULE_LICENSE("GPL");
  78. MODULE_AUTHOR("Alexander Shiyan <[email protected]>");
  79. MODULE_DESCRIPTION("CLPS711X GPIO driver");
  80. MODULE_ALIAS("platform:clps711x-gpio");