Birmingham have signed former Middlesbrough defender Jonathan Grounds following his release by Oldham.