(Disclaimer: I'm not a lawyer and this information is only as accurate as the sources I got it from. If you need legal advice then talk to a lawyer.)
Chapter 13 bankruptcy will allow you to keep your home but you have to make arrangements to repay your debts including your mortgage. If you restructure your debts under chapter 13 then you can hang on to your home.
If you file Chapter 7 bankruptcy you will wipe clean all your debts. You can exempt some property from chapter 7 if is considered "exempt". Each state has set up different limits in their laws on what can be considered exempt property. Most states have some protection for your home from bankruptcy and allow some level of home equity to be treated as exempt. So depending on what state you live in and/or how much equity you have in your home you may be able to fine Chapter 7 and keep your home. But it doesn't seem that you can do Chapter 7 and keep a home that has a mortgage or lien on it. You can only exempt home equity if you own it outright.
How much home equity can you exempt from Bankruptcy?
I found a list of all the individual state exemptions for how much of your home equity (homestead) you can exempt from bankruptcy.
A few states allow you to exempt unlimited home equity: Florida, Iowa, Kansas, Texas
New Jersey, Pennsylvania & Washington D.C. allow NO state exemption for your home. However for these states it looks like you can instead elect to take the federal exemptions of $18,450.
About 2/3 of the states listed allow you to exempt only a portion of your home equity with figures ranging from $5,000 to $50,000.
The rest of the states allow varying other exemptions in the range between $50,000 and $500,000.
Married couples may be able to double the exemptions.
This information is subject to change of course.