@@ -155,7 +155,6 @@ struct atmel_uart_port {
155
155
struct circ_buf rx_ring ;
156
156
157
157
struct mctrl_gpios * gpios ;
158
- int gpio_irq [UART_GPIO_MAX ];
159
158
unsigned int tx_done_mask ;
160
159
u32 fifo_size ;
161
160
u32 rts_high ;
@@ -550,27 +549,21 @@ static void atmel_enable_ms(struct uart_port *port)
550
549
551
550
atmel_port -> ms_irq_enabled = true;
552
551
553
- if (atmel_port -> gpio_irq [UART_GPIO_CTS ] >= 0 )
554
- enable_irq (atmel_port -> gpio_irq [UART_GPIO_CTS ]);
555
- else
552
+ if (!mctrl_gpio_to_gpiod (atmel_port -> gpios , UART_GPIO_CTS ))
556
553
ier |= ATMEL_US_CTSIC ;
557
554
558
- if (atmel_port -> gpio_irq [UART_GPIO_DSR ] >= 0 )
559
- enable_irq (atmel_port -> gpio_irq [UART_GPIO_DSR ]);
560
- else
555
+ if (!mctrl_gpio_to_gpiod (atmel_port -> gpios , UART_GPIO_DSR ))
561
556
ier |= ATMEL_US_DSRIC ;
562
557
563
- if (atmel_port -> gpio_irq [UART_GPIO_RI ] >= 0 )
564
- enable_irq (atmel_port -> gpio_irq [UART_GPIO_RI ]);
565
- else
558
+ if (!mctrl_gpio_to_gpiod (atmel_port -> gpios , UART_GPIO_RI ))
566
559
ier |= ATMEL_US_RIIC ;
567
560
568
- if (atmel_port -> gpio_irq [UART_GPIO_DCD ] >= 0 )
569
- enable_irq (atmel_port -> gpio_irq [UART_GPIO_DCD ]);
570
- else
561
+ if (!mctrl_gpio_to_gpiod (atmel_port -> gpios , UART_GPIO_DCD ))
571
562
ier |= ATMEL_US_DCDIC ;
572
563
573
564
atmel_uart_writel (port , ATMEL_US_IER , ier );
565
+
566
+ mctrl_gpio_enable_ms (atmel_port -> gpios );
574
567
}
575
568
576
569
/*
@@ -589,24 +582,18 @@ static void atmel_disable_ms(struct uart_port *port)
589
582
590
583
atmel_port -> ms_irq_enabled = false;
591
584
592
- if (atmel_port -> gpio_irq [ UART_GPIO_CTS ] >= 0 )
593
- disable_irq ( atmel_port -> gpio_irq [ UART_GPIO_CTS ]);
594
- else
585
+ mctrl_gpio_disable_ms (atmel_port -> gpios );
586
+
587
+ if (! mctrl_gpio_to_gpiod ( atmel_port -> gpios , UART_GPIO_CTS ))
595
588
idr |= ATMEL_US_CTSIC ;
596
589
597
- if (atmel_port -> gpio_irq [UART_GPIO_DSR ] >= 0 )
598
- disable_irq (atmel_port -> gpio_irq [UART_GPIO_DSR ]);
599
- else
590
+ if (!mctrl_gpio_to_gpiod (atmel_port -> gpios , UART_GPIO_DSR ))
600
591
idr |= ATMEL_US_DSRIC ;
601
592
602
- if (atmel_port -> gpio_irq [UART_GPIO_RI ] >= 0 )
603
- disable_irq (atmel_port -> gpio_irq [UART_GPIO_RI ]);
604
- else
593
+ if (!mctrl_gpio_to_gpiod (atmel_port -> gpios , UART_GPIO_RI ))
605
594
idr |= ATMEL_US_RIIC ;
606
595
607
- if (atmel_port -> gpio_irq [UART_GPIO_DCD ] >= 0 )
608
- disable_irq (atmel_port -> gpio_irq [UART_GPIO_DCD ]);
609
- else
596
+ if (!mctrl_gpio_to_gpiod (atmel_port -> gpios , UART_GPIO_DCD ))
610
597
idr |= ATMEL_US_DCDIC ;
611
598
612
599
atmel_uart_writel (port , ATMEL_US_IDR , idr );
@@ -1264,32 +1251,13 @@ static irqreturn_t atmel_interrupt(int irq, void *dev_id)
1264
1251
struct uart_port * port = dev_id ;
1265
1252
struct atmel_uart_port * atmel_port = to_atmel_uart_port (port );
1266
1253
unsigned int status , pending , mask , pass_counter = 0 ;
1267
- bool gpio_handled = false;
1268
1254
1269
1255
spin_lock (& atmel_port -> lock_suspended );
1270
1256
1271
1257
do {
1272
1258
status = atmel_get_lines_status (port );
1273
1259
mask = atmel_uart_readl (port , ATMEL_US_IMR );
1274
1260
pending = status & mask ;
1275
- if (!gpio_handled ) {
1276
- /*
1277
- * Dealing with GPIO interrupt
1278
- */
1279
- if (irq == atmel_port -> gpio_irq [UART_GPIO_CTS ])
1280
- pending |= ATMEL_US_CTSIC ;
1281
-
1282
- if (irq == atmel_port -> gpio_irq [UART_GPIO_DSR ])
1283
- pending |= ATMEL_US_DSRIC ;
1284
-
1285
- if (irq == atmel_port -> gpio_irq [UART_GPIO_RI ])
1286
- pending |= ATMEL_US_RIIC ;
1287
-
1288
- if (irq == atmel_port -> gpio_irq [UART_GPIO_DCD ])
1289
- pending |= ATMEL_US_DCDIC ;
1290
-
1291
- gpio_handled = true;
1292
- }
1293
1261
if (!pending )
1294
1262
break ;
1295
1263
@@ -1778,45 +1746,6 @@ static void atmel_get_ip_name(struct uart_port *port)
1778
1746
}
1779
1747
}
1780
1748
1781
- static void atmel_free_gpio_irq (struct uart_port * port )
1782
- {
1783
- struct atmel_uart_port * atmel_port = to_atmel_uart_port (port );
1784
- enum mctrl_gpio_idx i ;
1785
-
1786
- for (i = 0 ; i < UART_GPIO_MAX ; i ++ )
1787
- if (atmel_port -> gpio_irq [i ] >= 0 )
1788
- free_irq (atmel_port -> gpio_irq [i ], port );
1789
- }
1790
-
1791
- static int atmel_request_gpio_irq (struct uart_port * port )
1792
- {
1793
- struct atmel_uart_port * atmel_port = to_atmel_uart_port (port );
1794
- int * irq = atmel_port -> gpio_irq ;
1795
- enum mctrl_gpio_idx i ;
1796
- int err = 0 ;
1797
-
1798
- for (i = 0 ; (i < UART_GPIO_MAX ) && !err ; i ++ ) {
1799
- if (irq [i ] < 0 )
1800
- continue ;
1801
-
1802
- irq_set_status_flags (irq [i ], IRQ_NOAUTOEN );
1803
- err = request_irq (irq [i ], atmel_interrupt , IRQ_TYPE_EDGE_BOTH ,
1804
- "atmel_serial" , port );
1805
- if (err )
1806
- dev_err (port -> dev , "atmel_startup - Can't get %d irq\n" ,
1807
- irq [i ]);
1808
- }
1809
-
1810
- /*
1811
- * If something went wrong, rollback.
1812
- */
1813
- while (err && (-- i >= 0 ))
1814
- if (irq [i ] >= 0 )
1815
- free_irq (irq [i ], port );
1816
-
1817
- return err ;
1818
- }
1819
-
1820
1749
/*
1821
1750
* Perform initialization and enable port for reception
1822
1751
*/
@@ -1846,13 +1775,6 @@ static int atmel_startup(struct uart_port *port)
1846
1775
return retval ;
1847
1776
}
1848
1777
1849
- /*
1850
- * Get the GPIO lines IRQ
1851
- */
1852
- retval = atmel_request_gpio_irq (port );
1853
- if (retval )
1854
- goto free_irq ;
1855
-
1856
1778
tasklet_enable (& atmel_port -> tasklet );
1857
1779
1858
1780
/*
@@ -1948,11 +1870,6 @@ static int atmel_startup(struct uart_port *port)
1948
1870
}
1949
1871
1950
1872
return 0 ;
1951
-
1952
- free_irq :
1953
- free_irq (port -> irq , port );
1954
-
1955
- return retval ;
1956
1873
}
1957
1874
1958
1875
/*
@@ -2018,7 +1935,6 @@ static void atmel_shutdown(struct uart_port *port)
2018
1935
* Free the interrupts
2019
1936
*/
2020
1937
free_irq (port -> irq , port );
2021
- atmel_free_gpio_irq (port );
2022
1938
2023
1939
atmel_port -> ms_irq_enabled = false;
2024
1940
@@ -2686,26 +2602,6 @@ static int atmel_serial_resume(struct platform_device *pdev)
2686
2602
#define atmel_serial_resume NULL
2687
2603
#endif
2688
2604
2689
- static int atmel_init_gpios (struct atmel_uart_port * p , struct device * dev )
2690
- {
2691
- enum mctrl_gpio_idx i ;
2692
- struct gpio_desc * gpiod ;
2693
-
2694
- p -> gpios = mctrl_gpio_init_noauto (dev , 0 );
2695
- if (IS_ERR (p -> gpios ))
2696
- return PTR_ERR (p -> gpios );
2697
-
2698
- for (i = 0 ; i < UART_GPIO_MAX ; i ++ ) {
2699
- gpiod = mctrl_gpio_to_gpiod (p -> gpios , i );
2700
- if (gpiod && (gpiod_get_direction (gpiod ) == GPIOF_DIR_IN ))
2701
- p -> gpio_irq [i ] = gpiod_to_irq (gpiod );
2702
- else
2703
- p -> gpio_irq [i ] = - EINVAL ;
2704
- }
2705
-
2706
- return 0 ;
2707
- }
2708
-
2709
2605
static void atmel_serial_probe_fifos (struct atmel_uart_port * port ,
2710
2606
struct platform_device * pdev )
2711
2607
{
@@ -2788,16 +2684,16 @@ static int atmel_serial_probe(struct platform_device *pdev)
2788
2684
2789
2685
spin_lock_init (& port -> lock_suspended );
2790
2686
2791
- ret = atmel_init_gpios (port , & pdev -> dev );
2792
- if (ret < 0 ) {
2793
- dev_err (& pdev -> dev , "Failed to initialize GPIOs." );
2794
- goto err_clear_bit ;
2795
- }
2796
-
2797
2687
ret = atmel_init_port (port , pdev );
2798
2688
if (ret )
2799
2689
goto err_clear_bit ;
2800
2690
2691
+ port -> gpios = mctrl_gpio_init (& port -> uart , 0 );
2692
+ if (IS_ERR (port -> gpios )) {
2693
+ ret = PTR_ERR (port -> gpios );
2694
+ goto err_clear_bit ;
2695
+ }
2696
+
2801
2697
if (!atmel_use_pdc_rx (& port -> uart )) {
2802
2698
ret = - ENOMEM ;
2803
2699
data = kmalloc (sizeof (struct atmel_uart_char )
0 commit comments