This commit fixes the issue  #2198:
If an analog input is used and during the sketch modified in a digitalOutput
the pinMode(AX, OUTPUT) isn't sensed because of this line of codes:

wiring_analog.c line 135
// Enable the corresponding channel
	if (ulChannel != latestSelectedChannel) {
		adc_enable_channel( ADC, ulChannel );
		if ( latestSelectedChannel != (uint32_t)-1 )
			adc_disable_channel( ADC, latestSelectedChannel );
		latestSelectedChannel = ulChannel;

The channel is infact enabled only if different from the previous one because
of speed problems.

With my patch:

when pinMode(PIN, OUTPUT) is declared a control about if the pin
is an analog one is done and if so the ADC is released

when pinMode(PIN, INPUT) is declared a control is as well done in order to
enable the ADC.