I was browsing through the community and I found this post where they generate 38kHz PWM for an IR signal. You might want to check it out, they are using Arduino IDE sketch with a fast output on pin 2. It might give you some ideas on how to reach this speed. Regarding the fastest speed, by using sysfs the fastest speed we were able to get was 14 kHz (this is the method we used), but I know faster speeds can be reached with the IDE, but I'm not sure which is the maximum speed and still getting a clean square signal. I hope this helps.