The Welsh prototype for Merlin, he is also called Lailoken in some texts. There are three poems attributed to him in the Black Book of Carmarthen:
and two attributed to him in The Red Book of Hergest:
A third, "Peirian Faban (Commanding Youth)" is found in a seperate manuscript in the Peniarth collection.
From these poems, a story can be infered, particularly when one takes into account the Lailoken tales. Myrddin was driven mad by the Battle of Arthuret in 573 AD, wherein the Christian forces of Rhydderch Hael and Aedan mac Gabran fought Gwendolau the pagan prince. It is said that this was where Peredur (the Welsh Perceval) met his death. It was in this maddness that he gained prophetic wisdom. This is a common Celtic motif, seen in other characters such as the Irish Suibhne Gelt. He had no real connection to King Arthur's court in his origin--this was a later invention of Geoffrey of Monmouth.
The earliest reference to Myrddin comes from the "Armes Prydein Vawr" or "Great Prophesy of Britain" attributed to the sixth century bard Taliesin, but which is not older than 930 AD. Prior to that, Nennius tells a tale of a boy named Ambrosius, which was later used by Geoffrey of Monmouth (see below)
Turning to Geoffrey, we now come upon the Vita Merlini, or Life of Merlin, attributed to Geoffrey, though it is not possitive that he indeed wrote it. It is a Latin version of the above tale, that Merlin goes mad and hides in the forest, comforted by his sister Gwendydd and Taliesin. (Note: some of the later, 10th century pseudo-Taliesin poems make reference to Myrddin as a contemporary of the bard.) Even if Geoffrey didn't write the Vita, he did introduce the Latin-speaking world to Merlin through his book The History of the Kings of Britian. Here, we have the story of young Merlin Ambrosious, born without a father, who King Vortigern tries to use as a human sacrifice. Instead, Merlin shows himself as a prophet, disclosing the two dragons under the hill on which Vortigern was unsuccessfully trying to build his tower. There follows a long chapter full of Merlin's prophesies for Britain's future--written, of course, in the twelfth century and not the fifth, which is when the tale purports to take place. Moreover, it is here that we hear about how Merlin changed Uther Pendragon's appearance so that he could sleep with Ygrain and beget King Arthur. After that, however, this is little or no mention of Merlin in context of Arthur's kingdom; that is an invention of Robert de Boron's Roman du Graal (ca. 1200 AD).
It is from Geoffrey that we get the name "Merlin" as opposed to the Welsh "Myrddin." The name "Myrddin" simply means "from Caer Myrddin"--Caer Myrddin (Caerfyrddin) being modern Carmarthen in Wales, called Maridunum in Latin (meaning "fort by the sea"? supposing it derives from "mare" Latin and Celtic for sea, and the Celtic "dun" for fort, Latinized as "dunum"). Being called Myrddin means only that he is from Carmarthen, not any real name or title. However, when Geoffrey was writing his book, it was for a Norman audience. (Namely the court of King Henry I.) To Latinize Myrddin's name, it would be spelled Merdin (though technically, it should be spelled Mirthin or Mirðin, which is a phonetic rendering of the Welsh). However, "merde" in French means "shit," and to have his great prophet named "Shit" in his books was just too much for poor Geoffrey to bear. So, he changed the name to Merlin, which is close, but not exact, and which is also the name of a type of small bird--less offensive, but also less accurate.