IT WAS back in 1996 when playwright Joe Penhall went to see Ray Davies. After more than thirty fractious years as singer and chief songwriter with The Kinks, Davies had finally broken up the band he'd founded with his brother, lead guitarist Dave Davies, and was embarking on his first solo tour. Somehow, Penhall, who was riding high on the back of the Royal Court Theatre's productions of his first two plays, Some Voices and Pale Horse, managed to squirrel a script backstage. The gift was accompanied by a note to the effect that if Davies ever fancied doing anything drama-wise, Penhall was his man.

Eighteen years later, the result of Penhall's fanboy gesture was Sunny Afternoon, a warts and all musical biography of Davies' early days, from growing up as the sixth of seven kids in Muswell Hill, to the first five years with The Kinks. First staged at Hampstead Theatre in 2014, Sunny Afternoon follows its award-winning West End run with an extensive UK tour which arrives in Edinburgh this week before visiting Glasgow next month.

“It's something I'd always wanted to do,” says Penhall, on a break from writing a screenplay about the recent Hatton Garden jewellery heist. “I loved the Kinks, and I saw that the songs would work really well within theatre, and Ray approached me around about the same time as the producer Sonia Friedman did, so it was all quite serendipitous.

“Ray had been to see a play of mine and wanted to do something. One or two other people over the years had tried to do something, but it had never worked out, and various people had said to him that they should speak to me because I was a big Kinks fan. I related to what Ray was writing about with the Kinks more than any other band. Ray's lyrics are literate, witty, and are like beat poetry. There are monologues, and there's a lot there about outsiders and fringe characters, and people outwith conventional orthodoxies, which the Kinks were very much about.

“In the sixties, when the Beatles and the Rolling Stones were all enjoying the swinging side of things, the Kinks were still saying it was all a bit miserable after the war. Their song Dead End Street came out right at the peak of swinging London, and it talked about class and poverty in a way that was punk before punk. For me, most pop music and rock music is slightly vacuous. You have to leave it empty so an audience can put their thoughts and interpretations into it, hence Coldplay. But the Kinks didn't do that. Their songs were full of details and specificity.”

Much of the specificity Penhall is talking about in songs such as Dedicated Follower of Fashion, Lola and Sunny Afternoon itself are little social-realist snapshots of an era that clearly fascinates him. This was clear in The Long Firm, his 2004 TV adaptation of Jake Arnott's novel set in the gangster-ridden underworld of 1960s London that co-existed and undoubtedly crossed over with Davies' world.

“In terms of influence,” says Penhall, “my first play, Some Voices, was about two warring brothers, and looked at the effects of mental illness on them. I was definitely listening to a lot of Kinks records when I wrote it. It's a beautiful thing, to find another writer with similar obsessions to you, and who has a similar voice.

“Regarding the 1960s, funnily enough, Ray told me that he and Dave were asked to play the Krays,” Penhall says of the 1990 feature film made about the notorious twins who terrorised London while leading a celebrity lifestyle. “I'm really interested in all the mythologies of that time. The mythologies of the Krays, the Kinks and the Beatles aren't the same mythologies of the Beckhams, somehow. Everyone at that time was scarred by the war, and kids wanted to create something of their own that was a million miles from what they were born into. That relationship between show-business and villains was always there, so you had the Krays owning clubs and driving round in big cars.

“Class was really important then,” Penhall continues. “Between the sixties and probably the nineties people felt the need to try and eradicate it and make a genuinely classless society in the best possible sense. Now the class divide is worse than ever.”

In keeping with his work's narrative roots, Ray Davies himself is no stranger to the theatre, with previous dabblings including Chorus Girls, a musical penned with The Long Good Friday screenwriter, Barrie Keefe, in 1981. Seven years later Davies wrote songs for a version of Jules Verne's Around The World in Eighty Days by Snoo Wilson, and in 2008 Davies based his musical, Come Dancing, partly on the Kinks' 1983 hit single of the same name.

Theatrically speaking, it would have been easy for Penhall to go for a more straight-ahead rock and roll musical by way of a jukebox tribute act. As it is, after a career that has seen him write complex psycho-dramas such as the award-winning Blue/Orange, while Penhall wanted Sunny Afternoon to be entertaining, he also wanted to take it beyond a form of legitimised nostalgia that much commercial theatre is made of.

“I wanted it to be like the Pilgrim's Progress or Brecht,” he says. “We knew it was going to be a weird hybrid, but it was never set up to be a cash cow. It's about a working class young man making his way through the world. The Kinks came from grinding poverty, and were managed by a bunch of upper-class twits. This is a story of a bunch of teenagers who become famous, and which features the mafia, Nazis and George Best. It's got everything. Villains, showbiz and crazy people are always entertaining.”

Beyond the play, as a fan of the band, it is the legacy of the Kinks that seems to interest Penhall most.

“I think it's pretty immeasurable,” he says, “but it's interesting, because in the last ten years, the Beatles and the Who and the Rolling Stones have all had these big renaissances, either from getting back together or putting out a new set of re-releases, and they've all become part of the zeitgeist again. That's not really happened with the Kinks, and I really want it to happen, and with Sunny Afternoon maybe help make it happen. But that sort of renaissance could only really happen with the Kinks if someone could be bothered, and the Kinks are too anti-establishment for that. They were too non-conformist and were barely house-trained, so it probably won't, but I really hope it does.”

Sunny Afternoon, Edinburgh Playhouse, tomorrow to September 17; King's Theatre, Glasgow, October 11-15.

www.atgtickets.com