Proximity sensor always 0 or 9cm. Could this be a hardware or software problem? The proximity sensor on my phone always gives a distance value of 0 or 9cm (using both Z Device Test and CPU-Z). In sunlight, the sensor gives a reading of 9cm. Anywhere else (in shade, indoors, etc) the reading alternates between 0 and 9cm, and rather quickly. In intervals of about 2 seconds. If I cover the sensor with my thumb then reading is 0 as it should be. Soon as I remove my thumb the screen begins to flash.

I have tried using Resound Proximity Sensor to calibrate but failed. Could this be a software problem that I could fix myself?
This depends on the device. There are devices that have more accurate sensors, which can display the distance in cm correctly, but some sensors only report the distance as "near" or "far". If your device only gives the two states, Android uses the sensor's maximum detectable distance as the "far" state (in this case, 9cm) and 0 as the "near" state (which translates to 0cm).

Source: Position Sensors | Android Developers