Former Manchester City and Brazil midfielder Fernandinho has announced his retirement from football at the age of 40.