diff options
Diffstat (limited to 'drivers/tty/serial/8250/8250_dw.c')
-rw-r--r-- | drivers/tty/serial/8250/8250_dw.c | 194 |
1 files changed, 96 insertions, 98 deletions
diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index db0e66f6dd0..beaa283f5cc 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -26,6 +26,8 @@ #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/acpi.h> +#include <linux/clk.h> +#include <linux/pm_runtime.h> #include "8250.h" @@ -34,9 +36,6 @@ #define DW_UART_CPR 0xf4 /* Component Parameter Register */ #define DW_UART_UCV 0xf8 /* UART Component Version */ -/* Intel Low Power Subsystem specific */ -#define LPSS_PRV_CLOCK_PARAMS 0x800 - /* Component Parameter Register bits */ #define DW_UART_CPR_ABP_DATA_WIDTH (3 << 0) #define DW_UART_CPR_AFCE_MODE (1 << 4) @@ -55,8 +54,9 @@ struct dw8250_data { - int last_lcr; - int line; + int last_lcr; + int line; + struct clk *clk; }; static void dw8250_serial_out(struct uart_port *p, int offset, int value) @@ -113,6 +113,18 @@ static int dw8250_handle_irq(struct uart_port *p) return 0; } +static void +dw8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old) +{ + if (!state) + pm_runtime_get_sync(port->dev); + + serial8250_do_pm(port, state, old); + + if (state) + pm_runtime_put_sync_suspend(port->dev); +} + static int dw8250_probe_of(struct uart_port *p) { struct device_node *np = p->dev->of_node; @@ -136,8 +148,13 @@ static int dw8250_probe_of(struct uart_port *p) if (!of_property_read_u32(np, "reg-shift", &val)) p->regshift = val; + /* clock got configured through clk api, all done */ + if (p->uartclk) + return 0; + + /* try to find out clock frequency from DT as fallback */ if (of_property_read_u32(np, "clock-frequency", &val)) { - dev_err(p->dev, "no clock-frequency property set\n"); + dev_err(p->dev, "clk or clock-frequency not defined\n"); return -EINVAL; } p->uartclk = val; @@ -146,67 +163,10 @@ static int dw8250_probe_of(struct uart_port *p) } #ifdef CONFIG_ACPI -static bool dw8250_acpi_dma_filter(struct dma_chan *chan, void *parm) -{ - return chan->chan_id == *(int *)parm; -} - -static acpi_status -dw8250_acpi_walk_resource(struct acpi_resource *res, void *data) -{ - struct uart_port *p = data; - struct uart_8250_port *port; - struct uart_8250_dma *dma; - struct acpi_resource_fixed_dma *fixed_dma; - struct dma_slave_config *slave; - - port = container_of(p, struct uart_8250_port, port); - - switch (res->type) { - case ACPI_RESOURCE_TYPE_FIXED_DMA: - fixed_dma = &res->data.fixed_dma; - - /* TX comes first */ - if (!port->dma) { - dma = devm_kzalloc(p->dev, sizeof(*dma), GFP_KERNEL); - if (!dma) - return AE_NO_MEMORY; - - port->dma = dma; - slave = &dma->txconf; - - slave->direction = DMA_MEM_TO_DEV; - slave->dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; - slave->slave_id = fixed_dma->request_lines; - slave->dst_maxburst = port->tx_loadsz / 4; - - dma->tx_chan_id = fixed_dma->channels; - dma->tx_param = &dma->tx_chan_id; - dma->fn = dw8250_acpi_dma_filter; - } else { - dma = port->dma; - slave = &dma->rxconf; - - slave->direction = DMA_DEV_TO_MEM; - slave->src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; - slave->slave_id = fixed_dma->request_lines; - slave->src_maxburst = p->fifosize / 4; - - dma->rx_chan_id = fixed_dma->channels; - dma->rx_param = &dma->rx_chan_id; - } - - break; - } - - return AE_OK; -} - -static int dw8250_probe_acpi(struct uart_port *p) +static int dw8250_probe_acpi(struct uart_8250_port *up) { const struct acpi_device_id *id; - acpi_status status; - u32 reg; + struct uart_port *p = &up->port; id = acpi_match_device(p->dev->driver->acpi_match_table, p->dev); if (!id) @@ -216,26 +176,21 @@ static int dw8250_probe_acpi(struct uart_port *p) p->serial_in = dw8250_serial_in32; p->serial_out = dw8250_serial_out32; p->regshift = 2; - p->uartclk = (unsigned int)id->driver_data; - status = acpi_walk_resources(ACPI_HANDLE(p->dev), METHOD_NAME__CRS, - dw8250_acpi_walk_resource, p); - if (ACPI_FAILURE(status)) { - dev_err_ratelimited(p->dev, "%s failed \"%s\"\n", __func__, - acpi_format_exception(status)); - return -ENODEV; - } + if (!p->uartclk) + p->uartclk = (unsigned int)id->driver_data; - /* Fix Haswell issue where the clocks do not get enabled */ - if (!strcmp(id->id, "INT33C4") || !strcmp(id->id, "INT33C5")) { - reg = readl(p->membase + LPSS_PRV_CLOCK_PARAMS); - writel(reg | 1, p->membase + LPSS_PRV_CLOCK_PARAMS); - } + up->dma = devm_kzalloc(p->dev, sizeof(*up->dma), GFP_KERNEL); + if (!up->dma) + return -ENOMEM; + + up->dma->rxconf.src_maxburst = p->fifosize / 4; + up->dma->txconf.dst_maxburst = p->fifosize / 4; return 0; } #else -static inline int dw8250_probe_acpi(struct uart_port *p) +static inline int dw8250_probe_acpi(struct uart_8250_port *up) { return -ENODEV; } @@ -266,7 +221,11 @@ static void dw8250_setup_port(struct uart_8250_port *up) p->flags |= UPF_FIXED_TYPE; p->fifosize = DW_UART_CPR_FIFO_SIZE(reg); up->tx_loadsz = p->fifosize; + up->capabilities = UART_CAP_FIFO; } + + if (reg & DW_UART_CPR_AFCE_MODE) + up->capabilities |= UART_CAP_AFE; } static int dw8250_probe(struct platform_device *pdev) @@ -286,17 +245,30 @@ static int dw8250_probe(struct platform_device *pdev) uart.port.mapbase = regs->start; uart.port.irq = irq->start; uart.port.handle_irq = dw8250_handle_irq; + uart.port.pm = dw8250_do_pm; uart.port.type = PORT_8250; uart.port.flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_FIXED_PORT; uart.port.dev = &pdev->dev; - uart.port.membase = ioremap(regs->start, resource_size(regs)); + uart.port.membase = devm_ioremap(&pdev->dev, regs->start, + resource_size(regs)); if (!uart.port.membase) return -ENOMEM; + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->clk = devm_clk_get(&pdev->dev, NULL); + if (!IS_ERR(data->clk)) { + clk_prepare_enable(data->clk); + uart.port.uartclk = clk_get_rate(data->clk); + } + uart.port.iotype = UPIO_MEM; uart.port.serial_in = dw8250_serial_in; uart.port.serial_out = dw8250_serial_out; + uart.port.private_data = data; dw8250_setup_port(&uart); @@ -305,25 +277,22 @@ static int dw8250_probe(struct platform_device *pdev) if (err) return err; } else if (ACPI_HANDLE(&pdev->dev)) { - err = dw8250_probe_acpi(&uart.port); + err = dw8250_probe_acpi(&uart); if (err) return err; } else { return -ENODEV; } - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); - if (!data) - return -ENOMEM; - - uart.port.private_data = data; - data->line = serial8250_register_8250_port(&uart); if (data->line < 0) return data->line; platform_set_drvdata(pdev, data); + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); + return 0; } @@ -331,34 +300,64 @@ static int dw8250_remove(struct platform_device *pdev) { struct dw8250_data *data = platform_get_drvdata(pdev); + pm_runtime_get_sync(&pdev->dev); + serial8250_unregister_port(data->line); + if (!IS_ERR(data->clk)) + clk_disable_unprepare(data->clk); + + pm_runtime_disable(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); + return 0; } #ifdef CONFIG_PM -static int dw8250_suspend(struct platform_device *pdev, pm_message_t state) +static int dw8250_suspend(struct device *dev) { - struct dw8250_data *data = platform_get_drvdata(pdev); + struct dw8250_data *data = dev_get_drvdata(dev); serial8250_suspend_port(data->line); return 0; } -static int dw8250_resume(struct platform_device *pdev) +static int dw8250_resume(struct device *dev) { - struct dw8250_data *data = platform_get_drvdata(pdev); + struct dw8250_data *data = dev_get_drvdata(dev); serial8250_resume_port(data->line); return 0; } -#else -#define dw8250_suspend NULL -#define dw8250_resume NULL #endif /* CONFIG_PM */ +#ifdef CONFIG_PM_RUNTIME +static int dw8250_runtime_suspend(struct device *dev) +{ + struct dw8250_data *data = dev_get_drvdata(dev); + + clk_disable_unprepare(data->clk); + + return 0; +} + +static int dw8250_runtime_resume(struct device *dev) +{ + struct dw8250_data *data = dev_get_drvdata(dev); + + clk_prepare_enable(data->clk); + + return 0; +} +#endif + +static const struct dev_pm_ops dw8250_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(dw8250_suspend, dw8250_resume) + SET_RUNTIME_PM_OPS(dw8250_runtime_suspend, dw8250_runtime_resume, NULL) +}; + static const struct of_device_id dw8250_of_match[] = { { .compatible = "snps,dw-apb-uart" }, { /* Sentinel */ } @@ -366,8 +365,8 @@ static const struct of_device_id dw8250_of_match[] = { MODULE_DEVICE_TABLE(of, dw8250_of_match); static const struct acpi_device_id dw8250_acpi_match[] = { - { "INT33C4", 100000000 }, - { "INT33C5", 100000000 }, + { "INT33C4", 0 }, + { "INT33C5", 0 }, { }, }; MODULE_DEVICE_TABLE(acpi, dw8250_acpi_match); @@ -376,13 +375,12 @@ static struct platform_driver dw8250_platform_driver = { .driver = { .name = "dw-apb-uart", .owner = THIS_MODULE, + .pm = &dw8250_pm_ops, .of_match_table = dw8250_of_match, .acpi_match_table = ACPI_PTR(dw8250_acpi_match), }, .probe = dw8250_probe, .remove = dw8250_remove, - .suspend = dw8250_suspend, - .resume = dw8250_resume, }; module_platform_driver(dw8250_platform_driver); |