In a chapter 13 bankruptcy, you can retain your property by making monthly payments for either 36 or 60 months (depending on your income level). Additionally, you can enter the loss mitigation program to attempt to obtain a modification of your mortgage. Even though the mortgage companies cannot be forced to modify your mortgage, the loss mitigation program through a chapter 13 bankruptcy forces the mortgage companies to deal in good faith.
If you are considering bankruptcy, contact a lawyer so you can be guided accordingly as to what your options are and what option is best for you. The bankruptcy process can be difficult to navigate, so it is important that you have someone representing you who is familiar with the process to make sure everything goes smoothly.