2 * Atmel PIO2 Port Multiplexer support
4 * Copyright (C) 2004-2006 Atmel Corporation
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.
11 #include <linux/clk.h>
12 #include <linux/debugfs.h>
14 #include <linux/platform_device.h>
18 #include <asm/arch/portmux.h>
22 #define MAX_NR_PIO_DEVICES 8
26 const struct platform_device *pdev;
32 static struct pio_device pio_dev[MAX_NR_PIO_DEVICES];
34 void portmux_set_func(unsigned int portmux_id, unsigned int pin_id,
35 unsigned int function_id)
37 struct pio_device *pio;
38 u32 mask = 1 << pin_id;
40 BUG_ON(portmux_id >= MAX_NR_PIO_DEVICES);
42 pio = &pio_dev[portmux_id];
45 pio_writel(pio, BSR, mask);
47 pio_writel(pio, ASR, mask);
48 pio_writel(pio, PDR, mask);
51 static int __init pio_probe(struct platform_device *pdev)
53 struct pio_device *pio = NULL;
55 BUG_ON(pdev->id >= MAX_NR_PIO_DEVICES);
56 pio = &pio_dev[pdev->id];
59 /* TODO: Interrupts */
61 platform_set_drvdata(pdev, pio);
63 printk(KERN_INFO "%s: Atmel Port Multiplexer at 0x%p (irq %d)\n",
64 pio->name, pio->regs, platform_get_irq(pdev, 0));
69 static struct platform_driver pio_driver = {
76 static int __init pio_init(void)
78 return platform_driver_register(&pio_driver);
80 subsys_initcall(pio_init);
82 void __init at32_init_pio(struct platform_device *pdev)
84 struct resource *regs;
85 struct pio_device *pio;
87 if (pdev->id > MAX_NR_PIO_DEVICES) {
88 dev_err(&pdev->dev, "only %d PIO devices supported\n",
93 pio = &pio_dev[pdev->id];
94 snprintf(pio->name, sizeof(pio->name), "pio%d", pdev->id);
96 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
98 dev_err(&pdev->dev, "no mmio resource defined\n");
102 pio->clk = clk_get(&pdev->dev, "mck");
103 if (IS_ERR(pio->clk))
105 * This is a fatal error, but if we continue we might
106 * be so lucky that we manage to initialize the
107 * console and display this message...
109 dev_err(&pdev->dev, "no mck clock defined\n");
111 clk_enable(pio->clk);
114 pio->regs = ioremap(regs->start, regs->end - regs->start + 1);
116 pio_writel(pio, ODR, ~0UL);
117 pio_writel(pio, PER, ~0UL);