Cosmic ray feedback in galaxies and active galactic nuclei