  Bi$_2$Se$_3$ is one of the most promising topological insulators, but it
suffers from intrinsic n-doping due to Se-vacancies, which shifts the Fermi
level into the bulk conduction band, leading to topologically trivial carriers.
Recently it was shown that this Fermi-level shift can be compensated by a
locally controlled surface p-doping process, through water adsorption and XUV
irradiation. Here, the microscopic mechanism of this surface doping is studied
by means of density functional theory (DFT) focusing on the adsorption of
H$_2$O, OH, O, C and CH on Bi$_2$Se$_3$. We find that water adsorption has a
negligible doping effect while hydroxyl groups lead to n-doping. Carbon
adsorption on Se vacancies gives rise to p-doping but it also strongly modifies
the electronic band structure around the Dirac point. Only if the Se vacancies
are filled with atomic oxygen, the experimentally observed p-doping without
change of the topological surface bands is reproduced. Based on the DFT
results, we propose a reaction path where photon absorption gives rise to water
splitting and the produced O atoms fill the Se vacancies. Adsorbed OH groups
appear as intermediate states and carbon impurities may have a catalytic effect
in agreement with experimental observations.
