Skip to content

Commit ceb8ebe

Browse files
author
Radu Pirea
committed
tty/serial: atmel: change the driver to work under at91-usart mfd
This patch modifies the place where resources and device tree properties are searched. Signed-off-by: Radu Pirea <radu.pirea@microchip.com> Acked-by: Richard Genoud <richard.genoud@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
1 parent d4b3c7f commit ceb8ebe

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

drivers/tty/serial/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ config SERIAL_ATMEL
119119
depends on ARCH_AT91 || AVR32 || COMPILE_TEST
120120
select SERIAL_CORE
121121
select SERIAL_MCTRL_GPIO if GPIOLIB
122+
select MFD_AT91_USART
122123
help
123124
This enables the driver for the on-chip UARTs of the Atmel
124125
AT91 and AT32 processors.

drivers/tty/serial/atmel_serial.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ static struct console atmel_console;
192192

193193
#if defined(CONFIG_OF)
194194
static const struct of_device_id atmel_serial_dt_ids[] = {
195-
{ .compatible = "atmel,at91rm9200-usart" },
196-
{ .compatible = "atmel,at91sam9260-usart" },
195+
{ .compatible = "atmel,at91rm9200-usart-serial" },
197196
{ /* sentinel */ }
198197
};
199198
#endif
@@ -915,14 +914,15 @@ static void atmel_tx_dma(struct uart_port *port)
915914
static int atmel_prepare_tx_dma(struct uart_port *port)
916915
{
917916
struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
917+
struct device *mfd_dev = port->dev->parent;
918918
dma_cap_mask_t mask;
919919
struct dma_slave_config config;
920920
int ret, nent;
921921

922922
dma_cap_zero(mask);
923923
dma_cap_set(DMA_SLAVE, mask);
924924

925-
atmel_port->chan_tx = dma_request_slave_channel(port->dev, "tx");
925+
atmel_port->chan_tx = dma_request_slave_channel(mfd_dev, "tx");
926926
if (atmel_port->chan_tx == NULL)
927927
goto chan_err;
928928
dev_info(port->dev, "using %s for tx DMA transfers\n",
@@ -1093,6 +1093,7 @@ static void atmel_rx_from_dma(struct uart_port *port)
10931093
static int atmel_prepare_rx_dma(struct uart_port *port)
10941094
{
10951095
struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
1096+
struct device *mfd_dev = port->dev->parent;
10961097
struct dma_async_tx_descriptor *desc;
10971098
dma_cap_mask_t mask;
10981099
struct dma_slave_config config;
@@ -1104,7 +1105,7 @@ static int atmel_prepare_rx_dma(struct uart_port *port)
11041105
dma_cap_zero(mask);
11051106
dma_cap_set(DMA_CYCLIC, mask);
11061107

1107-
atmel_port->chan_rx = dma_request_slave_channel(port->dev, "rx");
1108+
atmel_port->chan_rx = dma_request_slave_channel(mfd_dev, "rx");
11081109
if (atmel_port->chan_rx == NULL)
11091110
goto chan_err;
11101111
dev_info(port->dev, "using %s for rx DMA transfers\n",
@@ -2253,8 +2254,8 @@ static const char *atmel_type(struct uart_port *port)
22532254
*/
22542255
static void atmel_release_port(struct uart_port *port)
22552256
{
2256-
struct platform_device *pdev = to_platform_device(port->dev);
2257-
int size = pdev->resource[0].end - pdev->resource[0].start + 1;
2257+
struct platform_device *mpdev = to_platform_device(port->dev->parent);
2258+
int size = resource_size(mpdev->resource);
22582259

22592260
release_mem_region(port->mapbase, size);
22602261

@@ -2269,8 +2270,8 @@ static void atmel_release_port(struct uart_port *port)
22692270
*/
22702271
static int atmel_request_port(struct uart_port *port)
22712272
{
2272-
struct platform_device *pdev = to_platform_device(port->dev);
2273-
int size = pdev->resource[0].end - pdev->resource[0].start + 1;
2273+
struct platform_device *mpdev = to_platform_device(port->dev->parent);
2274+
int size = resource_size(mpdev->resource);
22742275

22752276
if (!request_mem_region(port->mapbase, size, "atmel_serial"))
22762277
return -EBUSY;
@@ -2373,6 +2374,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port,
23732374
int ret;
23742375
struct uart_port *port = &atmel_port->uart;
23752376
struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev);
2377+
struct platform_device *mpdev = to_platform_device(pdev->dev.parent);
23762378

23772379
atmel_init_property(atmel_port, pdev);
23782380
atmel_set_ops(port);
@@ -2384,9 +2386,10 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port,
23842386
port->ops = &atmel_pops;
23852387
port->fifosize = 1;
23862388
port->dev = &pdev->dev;
2387-
port->mapbase = pdev->resource[0].start;
2388-
port->irq = pdev->resource[1].start;
2389+
port->mapbase = mpdev->resource[0].start;
2390+
port->irq = mpdev->resource[1].start;
23892391
port->rs485_config = atmel_config_rs485;
2392+
port->membase = NULL;
23902393

23912394
memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));
23922395

@@ -2400,7 +2403,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port,
24002403

24012404
/* for console, the clock could already be configured */
24022405
if (!atmel_port->clk) {
2403-
atmel_port->clk = clk_get(&pdev->dev, "usart");
2406+
atmel_port->clk = clk_get(&mpdev->dev, "usart");
24042407
if (IS_ERR(atmel_port->clk)) {
24052408
ret = PTR_ERR(atmel_port->clk);
24062409
atmel_port->clk = NULL;
@@ -2737,19 +2740,24 @@ static void atmel_serial_probe_fifos(struct atmel_uart_port *atmel_port,
27372740
static int atmel_serial_probe(struct platform_device *pdev)
27382741
{
27392742
struct atmel_uart_port *atmel_port;
2740-
struct device_node *np = pdev->dev.of_node;
2741-
struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev);
2743+
struct device_node *np = pdev->dev.parent->of_node;
27422744
void *data;
27432745
int ret = -ENODEV;
27442746
bool rs485_enabled;
27452747

27462748
BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
27472749

2748-
if (np)
2749-
ret = of_alias_get_id(np, "serial");
2750-
else
2751-
if (pdata)
2752-
ret = pdata->num;
2750+
2751+
/*
2752+
* In device tree there is no node with "atmel,at91rm9200-usart-serial"
2753+
* as compatible string. This driver is probed by at91-usart mfd driver
2754+
* which is just a wrapper over the atmel_serial driver and
2755+
* spi-at91-usart driver. All attributes needed by this driver are
2756+
* found in of_node of parent.
2757+
*/
2758+
pdev->dev.of_node = np;
2759+
2760+
ret = of_alias_get_id(np, "serial");
27532761

27542762
if (ret < 0)
27552763
/* port id not found in platform data nor device-tree aliases:
@@ -2884,6 +2892,7 @@ static int atmel_serial_remove(struct platform_device *pdev)
28842892

28852893
clk_put(atmel_port->clk);
28862894
atmel_port->clk = NULL;
2895+
pdev->dev.of_node = NULL;
28872896

28882897
return ret;
28892898
}
@@ -2894,7 +2903,7 @@ static struct platform_driver atmel_serial_driver = {
28942903
.suspend = atmel_serial_suspend,
28952904
.resume = atmel_serial_resume,
28962905
.driver = {
2897-
.name = "atmel_usart",
2906+
.name = "atmel_usart_serial",
28982907
.of_match_table = of_match_ptr(atmel_serial_dt_ids),
28992908
},
29002909
};

0 commit comments

Comments
 (0)