Constraining $f(R)$ gravity in solar system, cosmology and binary pulsar systems