1111#include <linux/irq.h>
1212#include <linux/module.h>
1313#include <linux/of.h>
14- #include <linux/pm_domain.h>
1514#include <linux/pm_opp.h>
1615#include <linux/platform_device.h>
1716#include <linux/pm_runtime.h>
10099#define DMA_RX_BUF_SIZE 2048
101100
102101static DEFINE_IDA (port_ida );
103- #define DOMAIN_IDX_POWER 0
104- #define DOMAIN_IDX_PERF 1
105102
106103struct qcom_geni_device_data {
107104 bool console ;
108105 enum geni_se_xfer_mode mode ;
109- struct dev_pm_domain_attach_data pd_data ;
110- int (* resources_init )(struct uart_port * uport );
111- int (* set_rate )(struct uart_port * uport , unsigned int baud );
112- int (* power_state )(struct uart_port * uport , bool state );
113106};
114107
115108struct qcom_geni_private_data {
@@ -147,7 +140,6 @@ struct qcom_geni_serial_port {
147140
148141 struct qcom_geni_private_data private_data ;
149142 const struct qcom_geni_device_data * dev_data ;
150- struct dev_pm_domain_list * pd_list ;
151143};
152144
153145static const struct uart_ops qcom_geni_console_pops ;
@@ -1370,42 +1362,6 @@ static int geni_serial_set_rate(struct uart_port *uport, unsigned int baud)
13701362 return 0 ;
13711363}
13721364
1373- static int geni_serial_set_level (struct uart_port * uport , unsigned int baud )
1374- {
1375- struct qcom_geni_serial_port * port = to_dev_port (uport );
1376- struct device * perf_dev = port -> pd_list -> pd_devs [DOMAIN_IDX_PERF ];
1377-
1378- /*
1379- * The performance protocol sets UART communication
1380- * speeds by selecting different performance levels
1381- * through the OPP framework.
1382- *
1383- * Supported perf levels for baudrates in firmware are below
1384- * +---------------------+--------------------+
1385- * | Perf level value | Baudrate values |
1386- * +---------------------+--------------------+
1387- * | 300 | 300 |
1388- * | 1200 | 1200 |
1389- * | 2400 | 2400 |
1390- * | 4800 | 4800 |
1391- * | 9600 | 9600 |
1392- * | 19200 | 19200 |
1393- * | 38400 | 38400 |
1394- * | 57600 | 57600 |
1395- * | 115200 | 115200 |
1396- * | 230400 | 230400 |
1397- * | 460800 | 460800 |
1398- * | 921600 | 921600 |
1399- * | 2000000 | 2000000 |
1400- * | 3000000 | 3000000 |
1401- * | 3200000 | 3200000 |
1402- * | 4000000 | 4000000 |
1403- * +---------------------+--------------------+
1404- */
1405-
1406- return dev_pm_opp_set_level (perf_dev , baud );
1407- }
1408-
14091365static void qcom_geni_serial_set_termios (struct uart_port * uport ,
14101366 struct ktermios * termios ,
14111367 const struct ktermios * old )
@@ -1424,7 +1380,7 @@ static void qcom_geni_serial_set_termios(struct uart_port *uport,
14241380 /* baud rate */
14251381 baud = uart_get_baud_rate (uport , termios , old , 300 , 8000000 );
14261382
1427- ret = port -> dev_data -> set_rate (uport , baud );
1383+ ret = geni_serial_set_rate (uport , baud );
14281384 if (ret )
14291385 return ;
14301386
@@ -1711,27 +1667,8 @@ static int geni_serial_resources_off(struct uart_port *uport)
17111667 return 0 ;
17121668}
17131669
1714- static int geni_serial_resource_state (struct uart_port * uport , bool power_on )
1715- {
1716- return power_on ? geni_serial_resources_on (uport ) : geni_serial_resources_off (uport );
1717- }
1718-
1719- static int geni_serial_pwr_init (struct uart_port * uport )
1720- {
1721- struct qcom_geni_serial_port * port = to_dev_port (uport );
1722- int ret ;
1723-
1724- ret = dev_pm_domain_attach_list (port -> se .dev ,
1725- & port -> dev_data -> pd_data , & port -> pd_list );
1726- if (ret <= 0 )
1727- return - EINVAL ;
1728-
1729- return 0 ;
1730- }
1731-
1732- static int geni_serial_resource_init (struct uart_port * uport )
1670+ static int geni_serial_resource_init (struct qcom_geni_serial_port * port )
17331671{
1734- struct qcom_geni_serial_port * port = to_dev_port (uport );
17351672 int ret ;
17361673
17371674 port -> se .clk = devm_clk_get (port -> se .dev , "se" );
@@ -1776,10 +1713,10 @@ static void qcom_geni_serial_pm(struct uart_port *uport,
17761713 old_state = UART_PM_STATE_OFF ;
17771714
17781715 if (new_state == UART_PM_STATE_ON && old_state == UART_PM_STATE_OFF )
1779- pm_runtime_resume_and_get (uport -> dev );
1716+ geni_serial_resources_on (uport );
17801717 else if (new_state == UART_PM_STATE_OFF &&
17811718 old_state == UART_PM_STATE_ON )
1782- pm_runtime_put_sync (uport -> dev );
1719+ geni_serial_resources_off (uport );
17831720
17841721}
17851722
@@ -1882,16 +1819,13 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
18821819 port -> se .dev = & pdev -> dev ;
18831820 port -> se .wrapper = dev_get_drvdata (pdev -> dev .parent );
18841821
1885- ret = port -> dev_data -> resources_init ( uport );
1822+ ret = geni_serial_resource_init ( port );
18861823 if (ret )
18871824 return ret ;
18881825
18891826 res = platform_get_resource (pdev , IORESOURCE_MEM , 0 );
1890- if (!res ) {
1891- ret = - EINVAL ;
1892- goto error ;
1893- }
1894-
1827+ if (!res )
1828+ return - EINVAL ;
18951829 uport -> mapbase = res -> start ;
18961830
18971831 uport -> rs485_config = qcom_geni_rs485_config ;
@@ -1903,26 +1837,19 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
19031837 if (!data -> console ) {
19041838 port -> rx_buf = devm_kzalloc (uport -> dev ,
19051839 DMA_RX_BUF_SIZE , GFP_KERNEL );
1906- if (!port -> rx_buf ) {
1907- ret = - ENOMEM ;
1908- goto error ;
1909- }
1840+ if (!port -> rx_buf )
1841+ return - ENOMEM ;
19101842 }
19111843
19121844 port -> name = devm_kasprintf (uport -> dev , GFP_KERNEL ,
19131845 "qcom_geni_serial_%s%d" ,
19141846 uart_console (uport ) ? "console" : "uart" , uport -> line );
1915- if (!port -> name ) {
1916- ret = - ENOMEM ;
1917- goto error ;
1918- }
1847+ if (!port -> name )
1848+ return - ENOMEM ;
19191849
19201850 irq = platform_get_irq (pdev , 0 );
1921- if (irq < 0 ) {
1922- ret = irq ;
1923- goto error ;
1924- }
1925-
1851+ if (irq < 0 )
1852+ return irq ;
19261853 uport -> irq = irq ;
19271854 uport -> has_sysrq = IS_ENABLED (CONFIG_SERIAL_QCOM_GENI_CONSOLE );
19281855
@@ -1944,18 +1871,16 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
19441871 IRQF_TRIGGER_HIGH , port -> name , uport );
19451872 if (ret ) {
19461873 dev_err (uport -> dev , "Failed to get IRQ ret %d\n" , ret );
1947- goto error ;
1874+ return ret ;
19481875 }
19491876
19501877 ret = uart_get_rs485_mode (uport );
19511878 if (ret )
19521879 return ret ;
19531880
1954- devm_pm_runtime_enable (port -> se .dev );
1955-
19561881 ret = uart_add_one_port (drv , uport );
19571882 if (ret )
1958- goto error ;
1883+ return ret ;
19591884
19601885 if (port -> wakeup_irq > 0 ) {
19611886 device_init_wakeup (& pdev -> dev , true);
@@ -1965,15 +1890,11 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
19651890 device_init_wakeup (& pdev -> dev , false);
19661891 ida_free (& port_ida , uport -> line );
19671892 uart_remove_one_port (drv , uport );
1968- goto error ;
1893+ return ret ;
19691894 }
19701895 }
19711896
19721897 return 0 ;
1973-
1974- error :
1975- dev_pm_domain_detach_list (port -> pd_list );
1976- return ret ;
19771898}
19781899
19791900static void qcom_geni_serial_remove (struct platform_device * pdev )
@@ -1986,31 +1907,6 @@ static void qcom_geni_serial_remove(struct platform_device *pdev)
19861907 device_init_wakeup (& pdev -> dev , false);
19871908 ida_free (& port_ida , uport -> line );
19881909 uart_remove_one_port (drv , & port -> uport );
1989- dev_pm_domain_detach_list (port -> pd_list );
1990- }
1991-
1992- static int __maybe_unused qcom_geni_serial_runtime_suspend (struct device * dev )
1993- {
1994- struct qcom_geni_serial_port * port = dev_get_drvdata (dev );
1995- struct uart_port * uport = & port -> uport ;
1996- int ret = 0 ;
1997-
1998- if (port -> dev_data -> power_state )
1999- ret = port -> dev_data -> power_state (uport , false);
2000-
2001- return ret ;
2002- }
2003-
2004- static int __maybe_unused qcom_geni_serial_runtime_resume (struct device * dev )
2005- {
2006- struct qcom_geni_serial_port * port = dev_get_drvdata (dev );
2007- struct uart_port * uport = & port -> uport ;
2008- int ret = 0 ;
2009-
2010- if (port -> dev_data -> power_state )
2011- ret = port -> dev_data -> power_state (uport , true);
2012-
2013- return ret ;
20141910}
20151911
20161912static int qcom_geni_serial_suspend (struct device * dev )
@@ -2048,46 +1944,14 @@ static int qcom_geni_serial_resume(struct device *dev)
20481944static const struct qcom_geni_device_data qcom_geni_console_data = {
20491945 .console = true,
20501946 .mode = GENI_SE_FIFO ,
2051- .resources_init = geni_serial_resource_init ,
2052- .set_rate = geni_serial_set_rate ,
2053- .power_state = geni_serial_resource_state ,
20541947};
20551948
20561949static const struct qcom_geni_device_data qcom_geni_uart_data = {
20571950 .console = false,
20581951 .mode = GENI_SE_DMA ,
2059- .resources_init = geni_serial_resource_init ,
2060- .set_rate = geni_serial_set_rate ,
2061- .power_state = geni_serial_resource_state ,
2062- };
2063-
2064- static const struct qcom_geni_device_data sa8255p_qcom_geni_console_data = {
2065- .console = true,
2066- .mode = GENI_SE_FIFO ,
2067- .pd_data = {
2068- .pd_flags = PD_FLAG_DEV_LINK_ON ,
2069- .pd_names = (const char * []) { "power" , "perf" },
2070- .num_pd_names = 2 ,
2071- },
2072- .resources_init = geni_serial_pwr_init ,
2073- .set_rate = geni_serial_set_level ,
2074- };
2075-
2076- static const struct qcom_geni_device_data sa8255p_qcom_geni_uart_data = {
2077- .console = false,
2078- .mode = GENI_SE_DMA ,
2079- .pd_data = {
2080- .pd_flags = PD_FLAG_DEV_LINK_ON ,
2081- .pd_names = (const char * []) { "power" , "perf" },
2082- .num_pd_names = 2 ,
2083- },
2084- .resources_init = geni_serial_pwr_init ,
2085- .set_rate = geni_serial_set_level ,
20861952};
20871953
20881954static const struct dev_pm_ops qcom_geni_serial_pm_ops = {
2089- SET_RUNTIME_PM_OPS (qcom_geni_serial_runtime_suspend ,
2090- qcom_geni_serial_runtime_resume , NULL )
20911955 SYSTEM_SLEEP_PM_OPS (qcom_geni_serial_suspend , qcom_geni_serial_resume )
20921956};
20931957
@@ -2096,18 +1960,10 @@ static const struct of_device_id qcom_geni_serial_match_table[] = {
20961960 .compatible = "qcom,geni-debug-uart" ,
20971961 .data = & qcom_geni_console_data ,
20981962 },
2099- {
2100- .compatible = "qcom,sa8255p-geni-debug-uart" ,
2101- .data = & sa8255p_qcom_geni_console_data ,
2102- },
21031963 {
21041964 .compatible = "qcom,geni-uart" ,
21051965 .data = & qcom_geni_uart_data ,
21061966 },
2107- {
2108- .compatible = "qcom,sa8255p-geni-uart" ,
2109- .data = & sa8255p_qcom_geni_uart_data ,
2110- },
21111967 {}
21121968};
21131969MODULE_DEVICE_TABLE (of , qcom_geni_serial_match_table );
0 commit comments