The FX series Legion is technically an adaptation, but, so far, the show hasn't adapted very much of what happens in the Legion comics. It's no secret that the series is forging its own path away from the comic book continuity. Almost all of the Legion characters are original, so far there's been no mention that, in the comics, David's father is Professor Charles Xavier and he was raised by his mother, Gabrielle Haller, both established X-Men comics characters. However, the FX series also has a very unreliable narrator, and the nature of David's powers mean that pretty much anything could turn out to be untrue.
So it's worth knowing the comics the series was based on, especially if you want to know exactly who Legion is. If you're not familiar with all of the superhero shorthand, it makes the series a little harder to follow. So, let's start with his comics introduction in New Mutants #25-28. David Haller is a young man raised by his mother, an Israeli diplomat, without the knowledge of his mutant dad. David was unaware of his mutant powers until a terrorist attack, when, out of fear, his psychic abilities allowed him to counterattack the terrorist, whose consciousness was then absorbed into David's mind, becoming his first dissociative identity.
In the comics, David is also suffering from what is perceived as a mental illness (Dissociative Identity Disorder). But it's not really true, because David's powers can make him literally absorb other people's personalities into his own. He's not mentally ill, he's a mutant. After the terrorist, Karami, became trapped in David's mind, he was able to eventually extricate himself... but as a result, all of David's powers became trapped within the domains of different split personalities, all of whom began fighting for dominance. Notably, one of David's key personalities was a young, scared boy, not unlike the vision that Ptonomy helped him see on Legion. Professor X and the X-Men enter David's mind in hopes of helping him, and eventually help him regain control.
But it wasn't that simple. When David's powers get out of control, he absorbs people around him, or their "astral" selves, into his own mind, which is constantly a battlefield between different personalities. He is under the care of X-adjacent former FBI agent Moira MacTaggart, and since each time he uses his powers there's a chance that a different personality could take over and potentially turn him into a huge danger, he's often an antagonist. Here's a rundown of some more of the character's greatest arcs.
Legion Quest, Uncanny X-Men
Another adventure where Legion is an antagonist, and winds up using his powers to open a time wormhole and prompt the "Age of Apocalypse."
Legion's Return, New Mutants
Here, the new heroes fight Legion, who has his a whole town under his psychic influence.
Legion creates an alternate reality where the X-Men never existed.
Age of X: Aftermath, X-Men Legacy
Legion's once-dormant multiple personalities rear their heads again, and this time, with a softer hand, Rogue and the rest of the X-Men have to stop him (note that Rogue has some very Syd Barrett-esque powers).
Legion finally gets a chance to be the hero — or, at least, the antihero — and decides to turn his life around, put his many alternate personalities in "jail," and turn himself from out of control liability into hero.
As you can see, through most of his comic book tenure, Legion was less misunderstood good guy, and much more of a villain — or, at least, a complicated, and frequently disastrously overpowered presence. But Legion, the FX show, seems like a combination of the character's more empathetic portrayal in X-Men Legacy and some of his earlier, still figuring-it-out days. Whether that changes over the course of the series remains to be seen.