What are the origins of clan tartans?

Were they simply an idea by a weaver for making money?
That seems to be what's happening with the Irish tartans. Different weavers are trying to be the company that designs the Irish place tartans and holds the rights.

I understand that long ago tartans were made by whatever dyes were handy to that particular area. When did the clan system of tartans become formalised?

Who made up the tartans? And why? I'm guessing money was involved.