avr32: Provide a way to deselect pins in the portmux
authorHaavard Skinnemoen <haavard.skinnemoen@atmel.com>
Fri, 19 Sep 2008 15:13:28 +0000 (17:13 +0200)
committerHaavard Skinnemoen <haavard.skinnemoen@atmel.com>
Mon, 22 Sep 2008 07:51:02 +0000 (09:51 +0200)
Currently, setting up the portmux is completely one-shot: Once a pin is
muxed, the portmux driver will complain loudly and refuse to do anything
if you try to set up the same pin again.

Sometimes, it may be necessary to change the configuration of a pin
after it has been set up initially. This patch adds a way to undo the
previous configuration, allowing the pin to be reconfigured.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>
arch/avr32/mach-at32ap/include/mach/portmux.h
arch/avr32/mach-at32ap/pio.c

index b1abe6b4e4efef469f8098dd2d1ebb04873d937d..4bbf99ec2c43475d0d952510059b42a370548039 100644 (file)
@@ -24,6 +24,7 @@
 void at32_select_periph(unsigned int pin, unsigned int periph,
                        unsigned long flags);
 void at32_select_gpio(unsigned int pin, unsigned long flags);
+void at32_deselect_pin(unsigned int pin);
 void at32_reserve_pin(unsigned int pin);
 
 #endif /* __ASM_ARCH_PORTMUX_H__ */
index 405ee6bad4ce59dd888448b100daba698cf12b0c..90ef538ae547a47268e9470ff9e950d4f7159c61 100644 (file)
@@ -134,6 +134,25 @@ fail:
        dump_stack();
 }
 
+/*
+ * Undo a previous pin reservation. Will not affect the hardware
+ * configuration.
+ */
+void at32_deselect_pin(unsigned int pin)
+{
+       struct pio_device *pio;
+       unsigned int pin_index = pin & 0x1f;
+
+       pio = gpio_to_pio(pin);
+       if (unlikely(!pio)) {
+               printk("pio: invalid pin %u\n", pin);
+               dump_stack();
+               return;
+       }
+
+       clear_bit(pin_index, &pio->pinmux_mask);
+}
+
 /* Reserve a pin, preventing anyone else from changing its configuration. */
 void __init at32_reserve_pin(unsigned int pin)
 {