pio.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Atmel PIO2 Port Multiplexer support
  3. *
  4. * Copyright (C) 2004-2006 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/debugfs.h>
  12. #include <linux/fs.h>
  13. #include <linux/platform_device.h>
  14. #include <asm/io.h>
  15. #include <asm/arch/portmux.h>
  16. #include "pio.h"
  17. #define MAX_NR_PIO_DEVICES 8
  18. struct pio_device {
  19. void __iomem *regs;
  20. const struct platform_device *pdev;
  21. struct clk *clk;
  22. u32 alloc_mask;
  23. char name[32];
  24. };
  25. static struct pio_device pio_dev[MAX_NR_PIO_DEVICES];
  26. void portmux_set_func(unsigned int portmux_id, unsigned int pin_id,
  27. unsigned int function_id)
  28. {
  29. struct pio_device *pio;
  30. u32 mask = 1 << pin_id;
  31. BUG_ON(portmux_id >= MAX_NR_PIO_DEVICES);
  32. pio = &pio_dev[portmux_id];
  33. if (function_id)
  34. pio_writel(pio, BSR, mask);
  35. else
  36. pio_writel(pio, ASR, mask);
  37. pio_writel(pio, PDR, mask);
  38. }
  39. static int __init pio_probe(struct platform_device *pdev)
  40. {
  41. struct pio_device *pio = NULL;
  42. BUG_ON(pdev->id >= MAX_NR_PIO_DEVICES);
  43. pio = &pio_dev[pdev->id];
  44. BUG_ON(!pio->regs);
  45. /* TODO: Interrupts */
  46. platform_set_drvdata(pdev, pio);
  47. printk(KERN_INFO "%s: Atmel Port Multiplexer at 0x%p (irq %d)\n",
  48. pio->name, pio->regs, platform_get_irq(pdev, 0));
  49. return 0;
  50. }
  51. static struct platform_driver pio_driver = {
  52. .probe = pio_probe,
  53. .driver = {
  54. .name = "pio",
  55. },
  56. };
  57. static int __init pio_init(void)
  58. {
  59. return platform_driver_register(&pio_driver);
  60. }
  61. subsys_initcall(pio_init);
  62. void __init at32_init_pio(struct platform_device *pdev)
  63. {
  64. struct resource *regs;
  65. struct pio_device *pio;
  66. if (pdev->id > MAX_NR_PIO_DEVICES) {
  67. dev_err(&pdev->dev, "only %d PIO devices supported\n",
  68. MAX_NR_PIO_DEVICES);
  69. return;
  70. }
  71. pio = &pio_dev[pdev->id];
  72. snprintf(pio->name, sizeof(pio->name), "pio%d", pdev->id);
  73. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  74. if (!regs) {
  75. dev_err(&pdev->dev, "no mmio resource defined\n");
  76. return;
  77. }
  78. pio->clk = clk_get(&pdev->dev, "mck");
  79. if (IS_ERR(pio->clk))
  80. /*
  81. * This is a fatal error, but if we continue we might
  82. * be so lucky that we manage to initialize the
  83. * console and display this message...
  84. */
  85. dev_err(&pdev->dev, "no mck clock defined\n");
  86. else
  87. clk_enable(pio->clk);
  88. pio->pdev = pdev;
  89. pio->regs = ioremap(regs->start, regs->end - regs->start + 1);
  90. pio_writel(pio, ODR, ~0UL);
  91. pio_writel(pio, PER, ~0UL);
  92. }