For tipping in both Spain and Portugal, 5-10% is the norm, if you do tip. However, especially in Portugal, it is not "required" or expected at most places, but if you do want to leave a tip, Cash is really the only way. If paying by card, they bring the terminal to you, show you the amount charged, and you tap and go. The receipt won't have a place to write in the tip. If you must leave a tip on the card, you have to tell them a new total with the tip included so they can process the correct amount. However, most of the time that goes straight to the restaurant and the server never sees it. Unlike the states, bars don't expect tips for just serving drinks.
Touristy places will have a jar by the register but no one pushes it all.
Off the beaten path, you might find it difficult to use a credit card, so it is ALWAYS a smart thing to have some cash. Also, public toilets aren't free and usually cost 50 cents to a Euro, so cash is smart for emergencies too.