Cal. Penal Code § 1538.5
(a)
(1) A defendant may move for the return of property or to suppress as evidence any tangible or intangible thing obtained as a result of a search or seizure on either of the following grounds:
(B) The search or seizure with a warrant was unreasonable because any of the following apply:
(c)
(2) While a witness is under examination during a hearing pursuant to a search or seizure motion, the judge or magistrate shall, upon motion of either party, do any of the following:
(f)
(k) If the defendant’s motion to return property or suppress evidence is granted and the case is dismissed pursuant to Section 1385, or the people appeal in a misdemeanor case pursuant to subdivision (j), the defendant shall be released pursuant to Section 1318 if he or she is in custody and not returned to custody unless the proceedings are resumed in the trial court and he or she is lawfully ordered by the court to be returned to custody.
If the defendant’s motion to return property or suppress evidence is granted and the people file a petition for writ of mandate or prohibition pursuant to subdivision (o) or a notice of intention to file a petition, the defendant shall be released pursuant to Section 1318, unless (1) he or she is charged with a capital offense in a case where the proof is evident and the presumption great, or (2) he or she is charged with a noncapital offense defined in Chapter 1 (commencing with Section 187) of Title 8 of Part 1, and the court orders that the defendant be discharged from actual custody upon bail.