1414#include <linux/irq.h>
1515#include <linux/module.h>
1616#include <linux/of.h>
17- #include <linux/pm_domain.h>
1817#include <linux/pm_opp.h>
1918#include <linux/platform_device.h>
2019#include <linux/pm_runtime.h>
102101#define DMA_RX_BUF_SIZE 2048
103102
104103static DEFINE_IDA (port_ida );
105- #define DOMAIN_IDX_POWER 0
106- #define DOMAIN_IDX_PERF 1
107104
108105struct qcom_geni_device_data {
109106 bool console ;
110107 enum geni_se_xfer_mode mode ;
111- struct dev_pm_domain_attach_data pd_data ;
112- int (* resources_init )(struct uart_port * uport );
113- int (* set_rate )(struct uart_port * uport , unsigned int baud );
114- int (* power_state )(struct uart_port * uport , bool state );
115108};
116109
117110struct qcom_geni_private_data {
@@ -149,7 +142,6 @@ struct qcom_geni_serial_port {
149142
150143 struct qcom_geni_private_data private_data ;
151144 const struct qcom_geni_device_data * dev_data ;
152- struct dev_pm_domain_list * pd_list ;
153145};
154146
155147static const struct uart_ops qcom_geni_console_pops ;
@@ -1307,42 +1299,6 @@ static int geni_serial_set_rate(struct uart_port *uport, unsigned int baud)
13071299 return 0 ;
13081300}
13091301
1310- static int geni_serial_set_level (struct uart_port * uport , unsigned int baud )
1311- {
1312- struct qcom_geni_serial_port * port = to_dev_port (uport );
1313- struct device * perf_dev = port -> pd_list -> pd_devs [DOMAIN_IDX_PERF ];
1314-
1315- /*
1316- * The performance protocol sets UART communication
1317- * speeds by selecting different performance levels
1318- * through the OPP framework.
1319- *
1320- * Supported perf levels for baudrates in firmware are below
1321- * +---------------------+--------------------+
1322- * | Perf level value | Baudrate values |
1323- * +---------------------+--------------------+
1324- * | 300 | 300 |
1325- * | 1200 | 1200 |
1326- * | 2400 | 2400 |
1327- * | 4800 | 4800 |
1328- * | 9600 | 9600 |
1329- * | 19200 | 19200 |
1330- * | 38400 | 38400 |
1331- * | 57600 | 57600 |
1332- * | 115200 | 115200 |
1333- * | 230400 | 230400 |
1334- * | 460800 | 460800 |
1335- * | 921600 | 921600 |
1336- * | 2000000 | 2000000 |
1337- * | 3000000 | 3000000 |
1338- * | 3200000 | 3200000 |
1339- * | 4000000 | 4000000 |
1340- * +---------------------+--------------------+
1341- */
1342-
1343- return dev_pm_opp_set_level (perf_dev , baud );
1344- }
1345-
13461302static void qcom_geni_serial_set_termios (struct uart_port * uport ,
13471303 struct ktermios * termios ,
13481304 const struct ktermios * old )
@@ -1361,7 +1317,7 @@ static void qcom_geni_serial_set_termios(struct uart_port *uport,
13611317 /* baud rate */
13621318 baud = uart_get_baud_rate (uport , termios , old , 300 , 8000000 );
13631319
1364- ret = port -> dev_data -> set_rate (uport , baud );
1320+ ret = geni_serial_set_rate (uport , baud );
13651321 if (ret )
13661322 return ;
13671323
@@ -1648,27 +1604,8 @@ static int geni_serial_resources_off(struct uart_port *uport)
16481604 return 0 ;
16491605}
16501606
1651- static int geni_serial_resource_state (struct uart_port * uport , bool power_on )
1652- {
1653- return power_on ? geni_serial_resources_on (uport ) : geni_serial_resources_off (uport );
1654- }
1655-
1656- static int geni_serial_pwr_init (struct uart_port * uport )
1657- {
1658- struct qcom_geni_serial_port * port = to_dev_port (uport );
1659- int ret ;
1660-
1661- ret = dev_pm_domain_attach_list (port -> se .dev ,
1662- & port -> dev_data -> pd_data , & port -> pd_list );
1663- if (ret <= 0 )
1664- return - EINVAL ;
1665-
1666- return 0 ;
1667- }
1668-
1669- static int geni_serial_resource_init (struct uart_port * uport )
1607+ static int geni_serial_resource_init (struct qcom_geni_serial_port * port )
16701608{
1671- struct qcom_geni_serial_port * port = to_dev_port (uport );
16721609 int ret ;
16731610
16741611 port -> se .clk = devm_clk_get (port -> se .dev , "se" );
@@ -1713,10 +1650,10 @@ static void qcom_geni_serial_pm(struct uart_port *uport,
17131650 old_state = UART_PM_STATE_OFF ;
17141651
17151652 if (new_state == UART_PM_STATE_ON && old_state == UART_PM_STATE_OFF )
1716- pm_runtime_resume_and_get (uport -> dev );
1653+ geni_serial_resources_on (uport );
17171654 else if (new_state == UART_PM_STATE_OFF &&
17181655 old_state == UART_PM_STATE_ON )
1719- pm_runtime_put_sync (uport -> dev );
1656+ geni_serial_resources_off (uport );
17201657
17211658}
17221659
@@ -1819,16 +1756,13 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
18191756 port -> se .dev = & pdev -> dev ;
18201757 port -> se .wrapper = dev_get_drvdata (pdev -> dev .parent );
18211758
1822- ret = port -> dev_data -> resources_init ( uport );
1759+ ret = geni_serial_resource_init ( port );
18231760 if (ret )
18241761 return ret ;
18251762
18261763 res = platform_get_resource (pdev , IORESOURCE_MEM , 0 );
1827- if (!res ) {
1828- ret = - EINVAL ;
1829- goto error ;
1830- }
1831-
1764+ if (!res )
1765+ return - EINVAL ;
18321766 uport -> mapbase = res -> start ;
18331767
18341768 uport -> rs485_config = qcom_geni_rs485_config ;
@@ -1840,26 +1774,19 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
18401774 if (!data -> console ) {
18411775 port -> rx_buf = devm_kzalloc (uport -> dev ,
18421776 DMA_RX_BUF_SIZE , GFP_KERNEL );
1843- if (!port -> rx_buf ) {
1844- ret = - ENOMEM ;
1845- goto error ;
1846- }
1777+ if (!port -> rx_buf )
1778+ return - ENOMEM ;
18471779 }
18481780
18491781 port -> name = devm_kasprintf (uport -> dev , GFP_KERNEL ,
18501782 "qcom_geni_serial_%s%d" ,
18511783 uart_console (uport ) ? "console" : "uart" , uport -> line );
1852- if (!port -> name ) {
1853- ret = - ENOMEM ;
1854- goto error ;
1855- }
1784+ if (!port -> name )
1785+ return - ENOMEM ;
18561786
18571787 irq = platform_get_irq (pdev , 0 );
1858- if (irq < 0 ) {
1859- ret = irq ;
1860- goto error ;
1861- }
1862-
1788+ if (irq < 0 )
1789+ return irq ;
18631790 uport -> irq = irq ;
18641791 uport -> has_sysrq = IS_ENABLED (CONFIG_SERIAL_QCOM_GENI_CONSOLE );
18651792
@@ -1881,18 +1808,16 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
18811808 IRQF_TRIGGER_HIGH , port -> name , uport );
18821809 if (ret ) {
18831810 dev_err (uport -> dev , "Failed to get IRQ ret %d\n" , ret );
1884- goto error ;
1811+ return ret ;
18851812 }
18861813
18871814 ret = uart_get_rs485_mode (uport );
18881815 if (ret )
18891816 return ret ;
18901817
1891- devm_pm_runtime_enable (port -> se .dev );
1892-
18931818 ret = uart_add_one_port (drv , uport );
18941819 if (ret )
1895- goto error ;
1820+ return ret ;
18961821
18971822 if (port -> wakeup_irq > 0 ) {
18981823 device_init_wakeup (& pdev -> dev , true);
@@ -1902,15 +1827,11 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
19021827 device_init_wakeup (& pdev -> dev , false);
19031828 ida_free (& port_ida , uport -> line );
19041829 uart_remove_one_port (drv , uport );
1905- goto error ;
1830+ return ret ;
19061831 }
19071832 }
19081833
19091834 return 0 ;
1910-
1911- error :
1912- dev_pm_domain_detach_list (port -> pd_list );
1913- return ret ;
19141835}
19151836
19161837static void qcom_geni_serial_remove (struct platform_device * pdev )
@@ -1923,31 +1844,6 @@ static void qcom_geni_serial_remove(struct platform_device *pdev)
19231844 device_init_wakeup (& pdev -> dev , false);
19241845 ida_free (& port_ida , uport -> line );
19251846 uart_remove_one_port (drv , & port -> uport );
1926- dev_pm_domain_detach_list (port -> pd_list );
1927- }
1928-
1929- static int __maybe_unused qcom_geni_serial_runtime_suspend (struct device * dev )
1930- {
1931- struct qcom_geni_serial_port * port = dev_get_drvdata (dev );
1932- struct uart_port * uport = & port -> uport ;
1933- int ret = 0 ;
1934-
1935- if (port -> dev_data -> power_state )
1936- ret = port -> dev_data -> power_state (uport , false);
1937-
1938- return ret ;
1939- }
1940-
1941- static int __maybe_unused qcom_geni_serial_runtime_resume (struct device * dev )
1942- {
1943- struct qcom_geni_serial_port * port = dev_get_drvdata (dev );
1944- struct uart_port * uport = & port -> uport ;
1945- int ret = 0 ;
1946-
1947- if (port -> dev_data -> power_state )
1948- ret = port -> dev_data -> power_state (uport , true);
1949-
1950- return ret ;
19511847}
19521848
19531849static int qcom_geni_serial_suspend (struct device * dev )
@@ -1985,46 +1881,14 @@ static int qcom_geni_serial_resume(struct device *dev)
19851881static const struct qcom_geni_device_data qcom_geni_console_data = {
19861882 .console = true,
19871883 .mode = GENI_SE_FIFO ,
1988- .resources_init = geni_serial_resource_init ,
1989- .set_rate = geni_serial_set_rate ,
1990- .power_state = geni_serial_resource_state ,
19911884};
19921885
19931886static const struct qcom_geni_device_data qcom_geni_uart_data = {
19941887 .console = false,
19951888 .mode = GENI_SE_DMA ,
1996- .resources_init = geni_serial_resource_init ,
1997- .set_rate = geni_serial_set_rate ,
1998- .power_state = geni_serial_resource_state ,
1999- };
2000-
2001- static const struct qcom_geni_device_data sa8255p_qcom_geni_console_data = {
2002- .console = true,
2003- .mode = GENI_SE_FIFO ,
2004- .pd_data = {
2005- .pd_flags = PD_FLAG_DEV_LINK_ON ,
2006- .pd_names = (const char * []) { "power" , "perf" },
2007- .num_pd_names = 2 ,
2008- },
2009- .resources_init = geni_serial_pwr_init ,
2010- .set_rate = geni_serial_set_level ,
2011- };
2012-
2013- static const struct qcom_geni_device_data sa8255p_qcom_geni_uart_data = {
2014- .console = false,
2015- .mode = GENI_SE_DMA ,
2016- .pd_data = {
2017- .pd_flags = PD_FLAG_DEV_LINK_ON ,
2018- .pd_names = (const char * []) { "power" , "perf" },
2019- .num_pd_names = 2 ,
2020- },
2021- .resources_init = geni_serial_pwr_init ,
2022- .set_rate = geni_serial_set_level ,
20231889};
20241890
20251891static const struct dev_pm_ops qcom_geni_serial_pm_ops = {
2026- SET_RUNTIME_PM_OPS (qcom_geni_serial_runtime_suspend ,
2027- qcom_geni_serial_runtime_resume , NULL )
20281892 SYSTEM_SLEEP_PM_OPS (qcom_geni_serial_suspend , qcom_geni_serial_resume )
20291893};
20301894
@@ -2033,18 +1897,10 @@ static const struct of_device_id qcom_geni_serial_match_table[] = {
20331897 .compatible = "qcom,geni-debug-uart" ,
20341898 .data = & qcom_geni_console_data ,
20351899 },
2036- {
2037- .compatible = "qcom,sa8255p-geni-debug-uart" ,
2038- .data = & sa8255p_qcom_geni_console_data ,
2039- },
20401900 {
20411901 .compatible = "qcom,geni-uart" ,
20421902 .data = & qcom_geni_uart_data ,
20431903 },
2044- {
2045- .compatible = "qcom,sa8255p-geni-uart" ,
2046- .data = & sa8255p_qcom_geni_uart_data ,
2047- },
20481904 {}
20491905};
20501906MODULE_DEVICE_TABLE (of , qcom_geni_serial_match_table );
0 commit comments