I don't see any reason it is not legal (meaning that there is a law against it.)
However, credit card companies may try to prevent it with their agreements with the merchants. For example, Visa has policies. Generally, they are more open to merchants offering discounts for cash than for charging a fee to use the credit card. Probably amounts to the same thing but that is their policy.
You might read:
http://usa.visa.com/download/merchants/card_acceptance_guide.pdf
at page 10.
I hope this helps.
Online responses offered here are ADVISORY only and should NOT be considered specific legal advice and are NOT intended to create an attorney-client relationship. You should always consult with a lawyer in your state.