The very first Merlin character had actually a historical background. However it was not a single person, but two merged under a single name by Geoffrey of Monmouth. The inspirations for the magician were Myrddin Wyllt (also known as Merlinus Caledonensis), and Aurelius Ambrosius. The first one being a mad bard, while the later was a historical war leader, though his depiction admittedly was fictionalized.
Merlin made his initial appearance in the "Prophecies of Merlin" under the name of Merlinus. Geoffrey is also the one who later gives details about Merlin's origin, as a fatherless child born from a nun impregnated by a succubus, in his following work - "Historia Regum Britanniae". Ambrosius is introduced when a British king tries to solve his problems with raising a tower by using a fatherless child's blood. However things turn round when the child uncovers the truth behind the tower's collapse - two dragons fighting beneath it. He then proceeds to prophesize how the red and white dragons are symbols of Britons and Saxons respectively.
The druidic and Welsh background of Marlin can be attributed to the Myrddin part of Merlin's character. Many Welsh prophecies have been attributed to him, especially relating to how the English, and later the Normans would be conquered and driven away.
One of the early connections between Merlin and Stonehenge is also due to his Welsh origin. The magician is supposed to have transported Stonehenge to its current location as a worthy burial monument. Interestingly magic is not mentioned explicitly in this tale, rather how this feat was accomplished is left up to the readers imagination.
Many of the tales also relate Merlin's involvement in Arthur's birth. He is said to have helped Uther Pendragon to seduce his enemy's wife whom he had fallen in love with. All this in exchange for the right to teach and mentor the young boy who would be the outcome of this encounter. This marks the beginning of Merlin as a father like figure, later to become Arthur's advisor.
This early Merlin was not quite what we see today upon mention of the magician's name. The pointed hat, and long white beard, as well as the robes are the characteristics that came with later, more modern tales. So did his good character. In the beginning Merlin used to be a more neutral or even slightly sinister persona.