If you just got the phone (is it new?) and the loudspeaker has never worked, restore it back to stock and make a claim for a warranty repair or replacement.
If you don't wish to do this then have you proved that the speaker actually works?
Not having seen the phone's loudspeaker I do not know but is it detachable from the system board? If so, remove it and connect/disconnect a 1.5V battery across the speaker connections. If you hear a click then the speaker is working. You can also use an Ohmmeter to measure the continuity of the speaker coil.
If both methods don't give the expected response then the actual speaker is faulty.
Don't know if this is still an option on your phone as you have as you say 'rooted it and installed CyanogenMod',
However there is a hardware functionality test that can be performed on your phone. (apologies if you have already tried this).
Here is a link on how to do it. You will notice that there is a speaker test as well as a receiver test. The speaker being the loudspeaker. If it fails as well and given that your receiver and earphones work OK then there is either a physical connection problem with the loudspeaker or the software is not switching on an internal electronic switch (non mechanical that is) to direct the audio to the loudspeaker. The software may be saying turn on but it may not be doing it. So it could either be a systemboard fault or a software fault, which you already probably suspect, but to my mind without the correct test equipment and circuit diagrams etc it will be hard to next to impossible to locate where the problem lies