9. (16 points) Given the function
$$
f(x)=a \sin x-\frac{1}{2} \cos 2 x+a-\frac{3}{a}+\frac{1}{2} \text {, }
$$

where $a \in \mathbf{R}$, and $a \neq 0$.
(1) If for any $x \in \mathbf{R}$, $f(x) \leqslant 0$, find the range of values for $a$.
(2) If $a \geqslant 2$, and there exists $x \in \mathbf{R}$ such that $f(x) \leqslant 0$, find the range of values for $a$.
9. (1) $f(x)=\sin ^{2} x+a \sin x+a-\frac{3}{a}$. Let $t=\sin x(-1 \leqslant t \leqslant 1)$. Then $g(t)=t^{2}+a t+a-\frac{3}{a}$.
By the given conditions,
$$
\left\{\begin{array}{l}
g(-1)=1-\frac{3}{a} \leqslant 0, \\
g(1)=1+2 a-\frac{3}{a} \leqslant 0 .
\end{array}\right.
$$

Solving for $a$, we get the range of $a$ as $(0,1]$.
(2) Since $a \geqslant 2$, we have $-\frac{a}{2} \leqslant-1$.

Thus, $g(t)_{\min }=g(-1)=1-\frac{3}{a}$.
Therefore, $f(x)_{\min }=1-\frac{3}{a}$.
By the given conditions, $1-\frac{3}{a} \leqslant 0$.
Solving for $a$, we get $0<a \leqslant 3$.
Hence, the range of $a$ is $[2,3]$.