We love both countries and actually like Portugal a bit more than Spain.
Consider an open jaw air ticket flying into either Madrid or Lisbon then flying out the other.
However, renting a car in one country and dropping in the other will be a huge charge.
Lisbon 3 days is a minimum, also consider an portion of a day in Sintra.
Don't need a full day at Obidos, it is a must see town with ancient Roman wall, but 3-4 hours are enough.
Porto is wonderful, we spent three days there (loved the B&B called The InPatio Guesthouse- book early).
We did a super Douro River cruise that I highly recommend. We were able to visit Salamanca, Spain just across the border as well.
If you don't do the Douro valley, you won't need four nights in Porto. 2 or 3 is good, but you can take the train up the Douro and stay at Regua or another of the river towns.
Seville and Toledo are MUST SEE for Spain. Also, recommend a day trip from Madrid to Segovia to see the ancient Roman aqueduct that was still in service until the second half of the 20th Century. Don't miss the Prado Museum in Madrid. You can do Toledo on a day trip from Madrid. Consider cutting a day or two off Cordoba.
You are missing Barcelona and Granada, but perhaps you don't have time.