gpio-clps711x.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * CLPS711X GPIO driver
  3. *
  4. * Copyright (C) 2012,2013 Alexander Shiyan <shc_work@mail.ru>
  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/gpio.h>
  13. #include <linux/module.h>
  14. #include <linux/basic_mmio_gpio.h>
  15. #include <linux/platform_device.h>
  16. static int clps711x_gpio_probe(struct platform_device *pdev)
  17. {
  18. void __iomem *dat, *dir;
  19. struct bgpio_chip *bgc;
  20. struct resource *res;
  21. int err, id = pdev->id;
  22. if ((id < 0) || (id > 4))
  23. return -ENODEV;
  24. bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL);
  25. if (!bgc)
  26. return -ENOMEM;
  27. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  28. dat = devm_ioremap_resource(&pdev->dev, res);
  29. if (IS_ERR(dat))
  30. return PTR_ERR(dat);
  31. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  32. dir = devm_ioremap_resource(&pdev->dev, res);
  33. if (IS_ERR(dir))
  34. return PTR_ERR(dir);
  35. switch (id) {
  36. case 3:
  37. /* PORTD is inverted logic for direction register */
  38. err = bgpio_init(bgc, &pdev->dev, 1, dat, NULL, NULL,
  39. NULL, dir, 0);
  40. break;
  41. default:
  42. err = bgpio_init(bgc, &pdev->dev, 1, dat, NULL, NULL,
  43. dir, NULL, 0);
  44. break;
  45. }
  46. if (err)
  47. return err;
  48. switch (id) {
  49. case 4:
  50. /* PORTE is 3 lines only */
  51. bgc->gc.ngpio = 3;
  52. break;
  53. default:
  54. break;
  55. }
  56. bgc->gc.base = id * 8;
  57. platform_set_drvdata(pdev, bgc);
  58. return gpiochip_add(&bgc->gc);
  59. }
  60. static int clps711x_gpio_remove(struct platform_device *pdev)
  61. {
  62. struct bgpio_chip *bgc = platform_get_drvdata(pdev);
  63. return bgpio_remove(bgc);
  64. }
  65. static struct platform_driver clps711x_gpio_driver = {
  66. .driver = {
  67. .name = "clps711x-gpio",
  68. .owner = THIS_MODULE,
  69. },
  70. .probe = clps711x_gpio_probe,
  71. .remove = clps711x_gpio_remove,
  72. };
  73. module_platform_driver(clps711x_gpio_driver);
  74. MODULE_LICENSE("GPL");
  75. MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
  76. MODULE_DESCRIPTION("CLPS711X GPIO driver");