With 9 days on the ground, you can fit in Lisbon & Madrid quite well. I'd consider at least 3 days in Lisbon & 4 days in Madrid. Day trip from Madrid to Toledo.
I have no experience with train passes in these 2 countries. Flying with LCC is rather cheap, worth checking it out