Skip to content

Commit 14288be

Browse files
Shubhrajyoti Dattagregkh
authored andcommitted
tty: serial: uartlite: Add clock adaptation
Add support of Common Clock Framework for Uartlite driver. Signed-off-by: Shubhrajyoti Datta <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent da7bf20 commit 14288be

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

drivers/tty/serial/uartlite.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/of_address.h>
2222
#include <linux/of_device.h>
2323
#include <linux/of_platform.h>
24+
#include <linux/clk.h>
2425

2526
#define ULITE_NAME "ttyUL"
2627
#define ULITE_MAJOR 204
@@ -56,6 +57,7 @@
5657

5758
struct uartlite_data {
5859
const struct uartlite_reg_ops *reg_ops;
60+
struct clk *clk;
5961
};
6062

6163
struct uartlite_reg_ops {
@@ -261,8 +263,15 @@ static void ulite_break_ctl(struct uart_port *port, int ctl)
261263

262264
static int ulite_startup(struct uart_port *port)
263265
{
266+
struct uartlite_data *pdata = port->private_data;
264267
int ret;
265268

269+
ret = clk_enable(pdata->clk);
270+
if (ret) {
271+
dev_err(port->dev, "Failed to enable clock\n");
272+
return ret;
273+
}
274+
266275
ret = request_irq(port->irq, ulite_isr, IRQF_SHARED | IRQF_TRIGGER_RISING,
267276
"uartlite", port);
268277
if (ret)
@@ -277,9 +286,12 @@ static int ulite_startup(struct uart_port *port)
277286

278287
static void ulite_shutdown(struct uart_port *port)
279288
{
289+
struct uartlite_data *pdata = port->private_data;
290+
280291
uart_out32(0, ULITE_CONTROL, port);
281292
uart_in32(ULITE_CONTROL, port); /* dummy */
282293
free_irq(port->irq, port);
294+
clk_disable(pdata->clk);
283295
}
284296

285297
static void ulite_set_termios(struct uart_port *port, struct ktermios *termios,
@@ -370,6 +382,17 @@ static int ulite_verify_port(struct uart_port *port, struct serial_struct *ser)
370382
return -EINVAL;
371383
}
372384

385+
static void ulite_pm(struct uart_port *port, unsigned int state,
386+
unsigned int oldstate)
387+
{
388+
struct uartlite_data *pdata = port->private_data;
389+
390+
if (!state)
391+
clk_enable(pdata->clk);
392+
else
393+
clk_disable(pdata->clk);
394+
}
395+
373396
#ifdef CONFIG_CONSOLE_POLL
374397
static int ulite_get_poll_char(struct uart_port *port)
375398
{
@@ -405,6 +428,7 @@ static const struct uart_ops ulite_ops = {
405428
.request_port = ulite_request_port,
406429
.config_port = ulite_config_port,
407430
.verify_port = ulite_verify_port,
431+
.pm = ulite_pm,
408432
#ifdef CONFIG_CONSOLE_POLL
409433
.poll_get_char = ulite_get_poll_char,
410434
.poll_put_char = ulite_put_poll_char,
@@ -669,7 +693,6 @@ static int ulite_release(struct device *dev)
669693
/* ---------------------------------------------------------------------
670694
* Platform bus binding
671695
*/
672-
673696
#if defined(CONFIG_OF)
674697
/* Match table for of_platform binding */
675698
static const struct of_device_id ulite_of_match[] = {
@@ -684,7 +707,7 @@ static int ulite_probe(struct platform_device *pdev)
684707
{
685708
struct resource *res;
686709
struct uartlite_data *pdata;
687-
int irq;
710+
int irq, ret;
688711
int id = pdev->id;
689712
#ifdef CONFIG_OF
690713
const __be32 *prop;
@@ -706,11 +729,33 @@ static int ulite_probe(struct platform_device *pdev)
706729
if (irq <= 0)
707730
return -ENXIO;
708731

732+
pdata->clk = devm_clk_get(&pdev->dev, "s_axi_aclk");
733+
if (IS_ERR(pdata->clk)) {
734+
if (PTR_ERR(pdata->clk) != -ENOENT)
735+
return PTR_ERR(pdata->clk);
736+
737+
/*
738+
* Clock framework support is optional, continue on
739+
* anyways if we don't find a matching clock.
740+
*/
741+
pdata->clk = NULL;
742+
}
743+
744+
ret = clk_prepare(pdata->clk);
745+
if (ret) {
746+
dev_err(&pdev->dev, "Failed to prepare clock\n");
747+
return ret;
748+
}
749+
709750
return ulite_assign(&pdev->dev, id, res->start, irq, pdata);
710751
}
711752

712753
static int ulite_remove(struct platform_device *pdev)
713754
{
755+
struct uart_port *port = dev_get_drvdata(&pdev->dev);
756+
struct uartlite_data *pdata = port->private_data;
757+
758+
clk_disable_unprepare(pdata->clk);
714759
return ulite_release(&pdev->dev);
715760
}
716761

0 commit comments

Comments
 (0)