A former longtime narcotics cop in Philadelphia has admitted to trading heroin and cocaine for sex with two women, including trysts in his police-assigned vehicle, according to his lawyer.

Stanley Davis, a 21-year department veteran who retired in May, will plead guilty Friday to federal drug distribution charges for swapping drugs for sex with the women, including one who allegedly drove under the influence in a crash that killed her grandmother, Philly.com reports.

Attorney Jack McMahon said investigators learned of the liaisons after the woman charged in the fatal crash, Rosie Dorothy Forsyth, 28, identified Davis as one of her sources of drugs. Davis, who is married, confessed immediately when confronted with the allegations, although it’s impossible to know whether Davis supplied the drugs Forsyth allegedly took before the fatal crash on Nov. 16.

Forsyth’s passenger, 90-year-old Thelma Frey, died from her injuries six days later, prompting prosecutors to file charges against Forsyth.

“He cooperated right from the get-go,” McMahon told Philly.com. “He felt terrible about doing it, and once it was exposed, it just came right out of him, because it’s not his real nature.”

A plea agreement in Davis’ case cited by the newspaper details sexual encounters with two women, one of which was Forsyth, although neither woman is identified by name in court records.

Davis told investigators that he met both women last fall as he approached them about becoming confidential informants while they looking to buy drugs, Philly.com reports.

Davis began trading sexually charged text messages with one of the women and sent nude photos of himself. He later met that woman for sex on at least two occasions, both of which involved drug use. according to his plea agreement.

During one romp, Davis gave the woman several bags of heroin that were hidden under a floor mat after she finished performing a sex act on him in his car, Philly.com report.

Davis faces up to 20 years in prison.