Stellar atmospheric parameters of FGK-type stars from high-resolution optical and near-infrared CARMENES spectra