Homoclinic tangencies and hyperbolicity for surface diffeomorphisms