We present a method for trajectory planning and control of planar robots with a passive rotational last joint. These underactuated mechanical systems, which are subject to nonholonomic second-order constraints, are shown to be fully linearized and input-output decoupled by means of a nonlinear dynamic feedback. This objective is achieved in a unified framework, both in the presence or absence of gravity. The linearizing output is the position of the center of percussion of the last link. Based on this result, one can plan smooth trajectories joining in finite time any initial and desired final state of the robot; in particular, transfers between inverted equilibria and swing-up maneuvers under gravity are easily obtained. We also address the problem of avoiding the singularity induced by the dynamic linearization procedure through a careful choice of output trajectories. A byproduct of the proposed method is the straightforward design of exponentially stable tracking controllers for the generated trajectories. Simulation results are reported for a 3R robot moving in a horizontal and vertical plane. Possible extensions of the approach and its relationships with the differential flatness technique are briefly discussed.