Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branches 'ib-mfd-iio-input-4.20', 'ib-mfd-irqchip-4.20', 'ib-mfd-rtc-4.20' and 'ib-mfd-spi-tty-4.20-1' into ibs-for-mfd-merged

+618 -21
+23 -2
Documentation/devicetree/bindings/serial/atmel-usart.txt Documentation/devicetree/bindings/mfd/atmel-usart.txt
··· 1 1 * Atmel Universal Synchronous Asynchronous Receiver/Transmitter (USART) 2 2 3 - Required properties: 3 + Required properties for USART: 4 4 - compatible: Should be "atmel,<chip>-usart" or "atmel,<chip>-dbgu" 5 5 The compatible <chip> indicated will be the first SoC to support an 6 6 additional mode or an USART new feature. ··· 11 11 Required elements: "usart" 12 12 - clocks: phandles to input clocks. 13 13 14 - Optional properties: 14 + Required properties for USART in SPI mode: 15 + - #size-cells : Must be <0> 16 + - #address-cells : Must be <1> 17 + - cs-gpios: chipselects (internal cs not supported) 18 + - atmel,usart-mode : Must be <AT91_USART_MODE_SPI> (found in dt-bindings/mfd/at91-usart.h) 19 + 20 + Optional properties in serial mode: 15 21 - atmel,use-dma-rx: use of PDC or DMA for receiving data 16 22 - atmel,use-dma-tx: use of PDC or DMA for transmitting data 17 23 - {rts,cts,dtr,dsr,rng,dcd}-gpios: specify a GPIO for RTS/CTS/DTR/DSR/RI/DCD line respectively. ··· 67 61 <&dma0 2 0x204>; 68 62 dma-names = "tx", "rx"; 69 63 atmel,fifo-size = <32>; 64 + }; 65 + 66 + - SPI mode: 67 + #include <dt-bindings/mfd/at91-usart.h> 68 + 69 + spi0: spi@f001c000 { 70 + #address-cells = <1>; 71 + #size-cells = <0>; 72 + compatible = "atmel,at91rm9200-usart", "atmel,at91sam9260-usart"; 73 + atmel,usart-mode = <AT91_USART_MODE_SPI>; 74 + reg = <0xf001c000 0x100>; 75 + interrupts = <12 IRQ_TYPE_LEVEL_HIGH 5>; 76 + clocks = <&usart0_clk>; 77 + clock-names = "usart"; 78 + cs-gpios = <&pioB 3 0>; 70 79 };
+16
MAINTAINERS
··· 9502 9502 S: Maintained 9503 9503 F: drivers/tty/serial/atmel_serial.c 9504 9504 F: drivers/tty/serial/atmel_serial.h 9505 + F: Documentation/devicetree/bindings/mfd/atmel-usart.txt 9505 9506 9506 9507 MICROCHIP / ATMEL DMA DRIVER 9507 9508 M: Ludovic Desroches <ludovic.desroches@microchip.com> ··· 9533 9532 S: Supported 9534 9533 F: drivers/mtd/nand/raw/atmel/* 9535 9534 F: Documentation/devicetree/bindings/mtd/atmel-nand.txt 9535 + 9536 + MICROCHIP AT91 USART MFD DRIVER 9537 + M: Radu Pirea <radu_nicolae.pirea@upb.ro> 9538 + L: linux-kernel@vger.kernel.org 9539 + S: Supported 9540 + F: drivers/mfd/at91-usart.c 9541 + F: include/dt-bindings/mfd/at91-usart.h 9542 + F: Documentation/devicetree/bindings/mfd/atmel-usart.txt 9543 + 9544 + MICROCHIP AT91 USART SPI DRIVER 9545 + M: Radu Pirea <radu_nicolae.pirea@upb.ro> 9546 + L: linux-spi@vger.kernel.org 9547 + S: Supported 9548 + F: drivers/spi/spi-at91-usart.c 9549 + F: Documentation/devicetree/bindings/mfd/atmel-usart.txt 9536 9550 9537 9551 MICROCHIP KSZ SERIES ETHERNET SWITCH DRIVER 9538 9552 M: Woojung Huh <Woojung.Huh@microchip.com>
+9
drivers/mfd/Kconfig
··· 99 99 additional drivers must be enabled in order to use the 100 100 functionality of the device. 101 101 102 + config MFD_AT91_USART 103 + tristate "AT91 USART Driver" 104 + select MFD_CORE 105 + help 106 + Select this to get support for AT91 USART IP. This is a wrapper 107 + over at91-usart-serial driver and usart-spi-driver. Only one function 108 + can be used at a time. The choice is done at boot time by the probe 109 + function of this MFD driver according to a device tree property. 110 + 102 111 config MFD_ATMEL_FLEXCOM 103 112 tristate "Atmel Flexcom (Flexible Serial Communication Unit)" 104 113 select MFD_CORE
+1
drivers/mfd/Makefile
··· 196 196 obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o 197 197 obj-$(CONFIG_MFD_TPS65090) += tps65090.o 198 198 obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o 199 + obj-$(CONFIG_MFD_AT91_USART) += at91-usart.o 199 200 obj-$(CONFIG_MFD_ATMEL_FLEXCOM) += atmel-flexcom.o 200 201 obj-$(CONFIG_MFD_ATMEL_HLCDC) += atmel-hlcdc.o 201 202 obj-$(CONFIG_MFD_ATMEL_SMC) += atmel-smc.o
+72
drivers/mfd/at91-usart.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Driver for AT91 USART 4 + * 5 + * Copyright (C) 2018 Microchip Technology 6 + * 7 + * Author: Radu Pirea <radu.pirea@microchip.com> 8 + * 9 + */ 10 + 11 + #include <dt-bindings/mfd/at91-usart.h> 12 + 13 + #include <linux/module.h> 14 + #include <linux/mfd/core.h> 15 + #include <linux/of.h> 16 + #include <linux/property.h> 17 + 18 + static struct mfd_cell at91_usart_spi_subdev = { 19 + .name = "at91_usart_spi", 20 + .of_compatible = "microchip,at91sam9g45-usart-spi", 21 + }; 22 + 23 + static struct mfd_cell at91_usart_serial_subdev = { 24 + .name = "atmel_usart_serial", 25 + .of_compatible = "atmel,at91rm9200-usart-serial", 26 + }; 27 + 28 + static int at91_usart_mode_probe(struct platform_device *pdev) 29 + { 30 + struct mfd_cell cell; 31 + u32 opmode = AT91_USART_MODE_SERIAL; 32 + 33 + device_property_read_u32(&pdev->dev, "atmel,usart-mode", &opmode); 34 + 35 + switch (opmode) { 36 + case AT91_USART_MODE_SPI: 37 + cell = at91_usart_spi_subdev; 38 + break; 39 + case AT91_USART_MODE_SERIAL: 40 + cell = at91_usart_serial_subdev; 41 + break; 42 + default: 43 + dev_err(&pdev->dev, "atmel,usart-mode has an invalid value %u\n", 44 + opmode); 45 + return -EINVAL; 46 + } 47 + 48 + return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, &cell, 1, 49 + NULL, 0, NULL); 50 + } 51 + 52 + static const struct of_device_id at91_usart_mode_of_match[] = { 53 + { .compatible = "atmel,at91rm9200-usart" }, 54 + { .compatible = "atmel,at91sam9260-usart" }, 55 + { /* sentinel */ } 56 + }; 57 + 58 + MODULE_DEVICE_TABLE(of, at91_usart_mode_of_match); 59 + 60 + static struct platform_driver at91_usart_mfd = { 61 + .probe = at91_usart_mode_probe, 62 + .driver = { 63 + .name = "at91_usart_mode", 64 + .of_match_table = at91_usart_mode_of_match, 65 + }, 66 + }; 67 + 68 + module_platform_driver(at91_usart_mfd); 69 + 70 + MODULE_AUTHOR("Radu Pirea <radu.pirea@microchip.com>"); 71 + MODULE_DESCRIPTION("AT91 USART MFD driver"); 72 + MODULE_LICENSE("GPL v2");
+9 -4
drivers/mfd/menelaus.c
··· 1094 1094 static inline void menelaus_rtc_init(struct menelaus_chip *m) 1095 1095 { 1096 1096 int alarm = (m->client->irq > 0); 1097 + int err; 1097 1098 1098 1099 /* assume 32KDETEN pin is pulled high */ 1099 1100 if (!(menelaus_read_reg(MENELAUS_OSC_CTRL) & 0x80)) { 1100 1101 dev_dbg(&m->client->dev, "no 32k oscillator\n"); 1101 1102 return; 1102 1103 } 1104 + 1105 + m->rtc = devm_rtc_allocate_device(&m->client->dev); 1106 + if (IS_ERR(m->rtc)) 1107 + return; 1108 + 1109 + m->rtc->ops = &menelaus_rtc_ops; 1103 1110 1104 1111 /* support RTC alarm; it can issue wakeups */ 1105 1112 if (alarm) { ··· 1132 1125 menelaus_write_reg(MENELAUS_RTC_CTRL, m->rtc_control); 1133 1126 } 1134 1127 1135 - m->rtc = rtc_device_register(DRIVER_NAME, 1136 - &m->client->dev, 1137 - &menelaus_rtc_ops, THIS_MODULE); 1138 - if (IS_ERR(m->rtc)) { 1128 + err = rtc_register_device(m->rtc); 1129 + if (err) { 1139 1130 if (alarm) { 1140 1131 menelaus_remove_irq_work(MENELAUS_RTCALM_IRQ); 1141 1132 device_init_wakeup(&m->client->dev, 0);
+8
drivers/spi/Kconfig
··· 83 83 This selects a driver for the Atmel SPI Controller, present on 84 84 many AT91 ARM chips. 85 85 86 + config SPI_AT91_USART 87 + tristate "Atmel USART Controller SPI driver" 88 + depends on (ARCH_AT91 || COMPILE_TEST) 89 + depends on MFD_AT91_USART 90 + help 91 + This selects a driver for the AT91 USART Controller as SPI Master, 92 + present on AT91 and SAMA5 SoC series. 93 + 86 94 config SPI_AU1550 87 95 tristate "Au1550/Au1200/Au1300 SPI Controller" 88 96 depends on MIPS_ALCHEMY
+1
drivers/spi/Makefile
··· 16 16 obj-$(CONFIG_SPI_ALTERA) += spi-altera.o 17 17 obj-$(CONFIG_SPI_ARMADA_3700) += spi-armada-3700.o 18 18 obj-$(CONFIG_SPI_ATMEL) += spi-atmel.o 19 + obj-$(CONFIG_SPI_AT91_USART) += spi-at91-usart.o 19 20 obj-$(CONFIG_SPI_ATH79) += spi-ath79.o 20 21 obj-$(CONFIG_SPI_AU1550) += spi-au1550.o 21 22 obj-$(CONFIG_SPI_AXI_SPI_ENGINE) += spi-axi-spi-engine.o
+432
drivers/spi/spi-at91-usart.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // 3 + // Driver for AT91 USART Controllers as SPI 4 + // 5 + // Copyright (C) 2018 Microchip Technology Inc. 6 + // 7 + // Author: Radu Pirea <radu.pirea@microchip.com> 8 + 9 + #include <linux/clk.h> 10 + #include <linux/delay.h> 11 + #include <linux/interrupt.h> 12 + #include <linux/kernel.h> 13 + #include <linux/module.h> 14 + #include <linux/of_gpio.h> 15 + #include <linux/platform_device.h> 16 + 17 + #include <linux/spi/spi.h> 18 + 19 + #define US_CR 0x00 20 + #define US_MR 0x04 21 + #define US_IER 0x08 22 + #define US_IDR 0x0C 23 + #define US_CSR 0x14 24 + #define US_RHR 0x18 25 + #define US_THR 0x1C 26 + #define US_BRGR 0x20 27 + #define US_VERSION 0xFC 28 + 29 + #define US_CR_RSTRX BIT(2) 30 + #define US_CR_RSTTX BIT(3) 31 + #define US_CR_RXEN BIT(4) 32 + #define US_CR_RXDIS BIT(5) 33 + #define US_CR_TXEN BIT(6) 34 + #define US_CR_TXDIS BIT(7) 35 + 36 + #define US_MR_SPI_MASTER 0x0E 37 + #define US_MR_CHRL GENMASK(7, 6) 38 + #define US_MR_CPHA BIT(8) 39 + #define US_MR_CPOL BIT(16) 40 + #define US_MR_CLKO BIT(18) 41 + #define US_MR_WRDBT BIT(20) 42 + #define US_MR_LOOP BIT(15) 43 + 44 + #define US_IR_RXRDY BIT(0) 45 + #define US_IR_TXRDY BIT(1) 46 + #define US_IR_OVRE BIT(5) 47 + 48 + #define US_BRGR_SIZE BIT(16) 49 + 50 + #define US_MIN_CLK_DIV 0x06 51 + #define US_MAX_CLK_DIV BIT(16) 52 + 53 + #define US_RESET (US_CR_RSTRX | US_CR_RSTTX) 54 + #define US_DISABLE (US_CR_RXDIS | US_CR_TXDIS) 55 + #define US_ENABLE (US_CR_RXEN | US_CR_TXEN) 56 + #define US_OVRE_RXRDY_IRQS (US_IR_OVRE | US_IR_RXRDY) 57 + 58 + #define US_INIT \ 59 + (US_MR_SPI_MASTER | US_MR_CHRL | US_MR_CLKO | US_MR_WRDBT) 60 + 61 + /* Register access macros */ 62 + #define at91_usart_spi_readl(port, reg) \ 63 + readl_relaxed((port)->regs + US_##reg) 64 + #define at91_usart_spi_writel(port, reg, value) \ 65 + writel_relaxed((value), (port)->regs + US_##reg) 66 + 67 + #define at91_usart_spi_readb(port, reg) \ 68 + readb_relaxed((port)->regs + US_##reg) 69 + #define at91_usart_spi_writeb(port, reg, value) \ 70 + writeb_relaxed((value), (port)->regs + US_##reg) 71 + 72 + struct at91_usart_spi { 73 + struct spi_transfer *current_transfer; 74 + void __iomem *regs; 75 + struct device *dev; 76 + struct clk *clk; 77 + 78 + /*used in interrupt to protect data reading*/ 79 + spinlock_t lock; 80 + 81 + int irq; 82 + unsigned int current_tx_remaining_bytes; 83 + unsigned int current_rx_remaining_bytes; 84 + 85 + u32 spi_clk; 86 + u32 status; 87 + 88 + bool xfer_failed; 89 + }; 90 + 91 + static inline u32 at91_usart_spi_tx_ready(struct at91_usart_spi *aus) 92 + { 93 + return aus->status & US_IR_TXRDY; 94 + } 95 + 96 + static inline u32 at91_usart_spi_rx_ready(struct at91_usart_spi *aus) 97 + { 98 + return aus->status & US_IR_RXRDY; 99 + } 100 + 101 + static inline u32 at91_usart_spi_check_overrun(struct at91_usart_spi *aus) 102 + { 103 + return aus->status & US_IR_OVRE; 104 + } 105 + 106 + static inline u32 at91_usart_spi_read_status(struct at91_usart_spi *aus) 107 + { 108 + aus->status = at91_usart_spi_readl(aus, CSR); 109 + return aus->status; 110 + } 111 + 112 + static inline void at91_usart_spi_tx(struct at91_usart_spi *aus) 113 + { 114 + unsigned int len = aus->current_transfer->len; 115 + unsigned int remaining = aus->current_tx_remaining_bytes; 116 + const u8 *tx_buf = aus->current_transfer->tx_buf; 117 + 118 + if (!remaining) 119 + return; 120 + 121 + if (at91_usart_spi_tx_ready(aus)) { 122 + at91_usart_spi_writeb(aus, THR, tx_buf[len - remaining]); 123 + aus->current_tx_remaining_bytes--; 124 + } 125 + } 126 + 127 + static inline void at91_usart_spi_rx(struct at91_usart_spi *aus) 128 + { 129 + int len = aus->current_transfer->len; 130 + int remaining = aus->current_rx_remaining_bytes; 131 + u8 *rx_buf = aus->current_transfer->rx_buf; 132 + 133 + if (!remaining) 134 + return; 135 + 136 + rx_buf[len - remaining] = at91_usart_spi_readb(aus, RHR); 137 + aus->current_rx_remaining_bytes--; 138 + } 139 + 140 + static inline void 141 + at91_usart_spi_set_xfer_speed(struct at91_usart_spi *aus, 142 + struct spi_transfer *xfer) 143 + { 144 + at91_usart_spi_writel(aus, BRGR, 145 + DIV_ROUND_UP(aus->spi_clk, xfer->speed_hz)); 146 + } 147 + 148 + static irqreturn_t at91_usart_spi_interrupt(int irq, void *dev_id) 149 + { 150 + struct spi_controller *controller = dev_id; 151 + struct at91_usart_spi *aus = spi_master_get_devdata(controller); 152 + 153 + spin_lock(&aus->lock); 154 + at91_usart_spi_read_status(aus); 155 + 156 + if (at91_usart_spi_check_overrun(aus)) { 157 + aus->xfer_failed = true; 158 + at91_usart_spi_writel(aus, IDR, US_IR_OVRE | US_IR_RXRDY); 159 + spin_unlock(&aus->lock); 160 + return IRQ_HANDLED; 161 + } 162 + 163 + if (at91_usart_spi_rx_ready(aus)) { 164 + at91_usart_spi_rx(aus); 165 + spin_unlock(&aus->lock); 166 + return IRQ_HANDLED; 167 + } 168 + 169 + spin_unlock(&aus->lock); 170 + 171 + return IRQ_NONE; 172 + } 173 + 174 + static int at91_usart_spi_setup(struct spi_device *spi) 175 + { 176 + struct at91_usart_spi *aus = spi_master_get_devdata(spi->controller); 177 + u32 *ausd = spi->controller_state; 178 + unsigned int mr = at91_usart_spi_readl(aus, MR); 179 + u8 bits = spi->bits_per_word; 180 + 181 + if (bits != 8) { 182 + dev_dbg(&spi->dev, "Only 8 bits per word are supported\n"); 183 + return -EINVAL; 184 + } 185 + 186 + if (spi->mode & SPI_CPOL) 187 + mr |= US_MR_CPOL; 188 + else 189 + mr &= ~US_MR_CPOL; 190 + 191 + if (spi->mode & SPI_CPHA) 192 + mr |= US_MR_CPHA; 193 + else 194 + mr &= ~US_MR_CPHA; 195 + 196 + if (spi->mode & SPI_LOOP) 197 + mr |= US_MR_LOOP; 198 + else 199 + mr &= ~US_MR_LOOP; 200 + 201 + if (!ausd) { 202 + ausd = kzalloc(sizeof(*ausd), GFP_KERNEL); 203 + if (!ausd) 204 + return -ENOMEM; 205 + 206 + spi->controller_state = ausd; 207 + } 208 + 209 + *ausd = mr; 210 + 211 + dev_dbg(&spi->dev, 212 + "setup: bpw %u mode 0x%x -> mr %d %08x\n", 213 + bits, spi->mode, spi->chip_select, mr); 214 + 215 + return 0; 216 + } 217 + 218 + static int at91_usart_spi_transfer_one(struct spi_controller *ctlr, 219 + struct spi_device *spi, 220 + struct spi_transfer *xfer) 221 + { 222 + struct at91_usart_spi *aus = spi_master_get_devdata(ctlr); 223 + 224 + at91_usart_spi_set_xfer_speed(aus, xfer); 225 + aus->xfer_failed = false; 226 + aus->current_transfer = xfer; 227 + aus->current_tx_remaining_bytes = xfer->len; 228 + aus->current_rx_remaining_bytes = xfer->len; 229 + 230 + while ((aus->current_tx_remaining_bytes || 231 + aus->current_rx_remaining_bytes) && !aus->xfer_failed) { 232 + at91_usart_spi_read_status(aus); 233 + at91_usart_spi_tx(aus); 234 + cpu_relax(); 235 + } 236 + 237 + if (aus->xfer_failed) { 238 + dev_err(aus->dev, "Overrun!\n"); 239 + return -EIO; 240 + } 241 + 242 + return 0; 243 + } 244 + 245 + static int at91_usart_spi_prepare_message(struct spi_controller *ctlr, 246 + struct spi_message *message) 247 + { 248 + struct at91_usart_spi *aus = spi_master_get_devdata(ctlr); 249 + struct spi_device *spi = message->spi; 250 + u32 *ausd = spi->controller_state; 251 + 252 + at91_usart_spi_writel(aus, CR, US_ENABLE); 253 + at91_usart_spi_writel(aus, IER, US_OVRE_RXRDY_IRQS); 254 + at91_usart_spi_writel(aus, MR, *ausd); 255 + 256 + return 0; 257 + } 258 + 259 + static int at91_usart_spi_unprepare_message(struct spi_controller *ctlr, 260 + struct spi_message *message) 261 + { 262 + struct at91_usart_spi *aus = spi_master_get_devdata(ctlr); 263 + 264 + at91_usart_spi_writel(aus, CR, US_RESET | US_DISABLE); 265 + at91_usart_spi_writel(aus, IDR, US_OVRE_RXRDY_IRQS); 266 + 267 + return 0; 268 + } 269 + 270 + static void at91_usart_spi_cleanup(struct spi_device *spi) 271 + { 272 + struct at91_usart_spi_device *ausd = spi->controller_state; 273 + 274 + spi->controller_state = NULL; 275 + kfree(ausd); 276 + } 277 + 278 + static void at91_usart_spi_init(struct at91_usart_spi *aus) 279 + { 280 + at91_usart_spi_writel(aus, MR, US_INIT); 281 + at91_usart_spi_writel(aus, CR, US_RESET | US_DISABLE); 282 + } 283 + 284 + static int at91_usart_gpio_setup(struct platform_device *pdev) 285 + { 286 + struct device_node *np = pdev->dev.parent->of_node; 287 + int i; 288 + int ret; 289 + int nb; 290 + 291 + if (!np) 292 + return -EINVAL; 293 + 294 + nb = of_gpio_named_count(np, "cs-gpios"); 295 + for (i = 0; i < nb; i++) { 296 + int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); 297 + 298 + if (cs_gpio < 0) 299 + return cs_gpio; 300 + 301 + if (gpio_is_valid(cs_gpio)) { 302 + ret = devm_gpio_request_one(&pdev->dev, cs_gpio, 303 + GPIOF_DIR_OUT, 304 + dev_name(&pdev->dev)); 305 + if (ret) 306 + return ret; 307 + } 308 + } 309 + 310 + return 0; 311 + } 312 + 313 + static int at91_usart_spi_probe(struct platform_device *pdev) 314 + { 315 + struct resource *regs; 316 + struct spi_controller *controller; 317 + struct at91_usart_spi *aus; 318 + struct clk *clk; 319 + int irq; 320 + int ret; 321 + 322 + regs = platform_get_resource(to_platform_device(pdev->dev.parent), 323 + IORESOURCE_MEM, 0); 324 + if (!regs) 325 + return -EINVAL; 326 + 327 + irq = platform_get_irq(to_platform_device(pdev->dev.parent), 0); 328 + if (irq < 0) 329 + return irq; 330 + 331 + clk = devm_clk_get(pdev->dev.parent, "usart"); 332 + if (IS_ERR(clk)) 333 + return PTR_ERR(clk); 334 + 335 + ret = -ENOMEM; 336 + controller = spi_alloc_master(&pdev->dev, sizeof(*aus)); 337 + if (!controller) 338 + goto at91_usart_spi_probe_fail; 339 + 340 + ret = at91_usart_gpio_setup(pdev); 341 + if (ret) 342 + goto at91_usart_spi_probe_fail; 343 + 344 + controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP | SPI_CS_HIGH; 345 + controller->dev.of_node = pdev->dev.parent->of_node; 346 + controller->bits_per_word_mask = SPI_BPW_MASK(8); 347 + controller->setup = at91_usart_spi_setup; 348 + controller->flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX; 349 + controller->transfer_one = at91_usart_spi_transfer_one; 350 + controller->prepare_message = at91_usart_spi_prepare_message; 351 + controller->unprepare_message = at91_usart_spi_unprepare_message; 352 + controller->cleanup = at91_usart_spi_cleanup; 353 + controller->max_speed_hz = DIV_ROUND_UP(clk_get_rate(clk), 354 + US_MIN_CLK_DIV); 355 + controller->min_speed_hz = DIV_ROUND_UP(clk_get_rate(clk), 356 + US_MAX_CLK_DIV); 357 + platform_set_drvdata(pdev, controller); 358 + 359 + aus = spi_master_get_devdata(controller); 360 + 361 + aus->dev = &pdev->dev; 362 + aus->regs = devm_ioremap_resource(&pdev->dev, regs); 363 + if (IS_ERR(aus->regs)) { 364 + ret = PTR_ERR(aus->regs); 365 + goto at91_usart_spi_probe_fail; 366 + } 367 + 368 + aus->irq = irq; 369 + aus->clk = clk; 370 + 371 + ret = devm_request_irq(&pdev->dev, irq, at91_usart_spi_interrupt, 0, 372 + dev_name(&pdev->dev), controller); 373 + if (ret) 374 + goto at91_usart_spi_probe_fail; 375 + 376 + ret = clk_prepare_enable(clk); 377 + if (ret) 378 + goto at91_usart_spi_probe_fail; 379 + 380 + aus->spi_clk = clk_get_rate(clk); 381 + at91_usart_spi_init(aus); 382 + 383 + spin_lock_init(&aus->lock); 384 + ret = devm_spi_register_master(&pdev->dev, controller); 385 + if (ret) 386 + goto at91_usart_fail_register_master; 387 + 388 + dev_info(&pdev->dev, 389 + "AT91 USART SPI Controller version 0x%x at %pa (irq %d)\n", 390 + at91_usart_spi_readl(aus, VERSION), 391 + &regs->start, irq); 392 + 393 + return 0; 394 + 395 + at91_usart_fail_register_master: 396 + clk_disable_unprepare(clk); 397 + at91_usart_spi_probe_fail: 398 + spi_master_put(controller); 399 + return ret; 400 + } 401 + 402 + static int at91_usart_spi_remove(struct platform_device *pdev) 403 + { 404 + struct spi_controller *ctlr = platform_get_drvdata(pdev); 405 + struct at91_usart_spi *aus = spi_master_get_devdata(ctlr); 406 + 407 + clk_disable_unprepare(aus->clk); 408 + 409 + return 0; 410 + } 411 + 412 + static const struct of_device_id at91_usart_spi_dt_ids[] = { 413 + { .compatible = "microchip,at91sam9g45-usart-spi"}, 414 + { /* sentinel */} 415 + }; 416 + 417 + MODULE_DEVICE_TABLE(of, at91_usart_spi_dt_ids); 418 + 419 + static struct platform_driver at91_usart_spi_driver = { 420 + .driver = { 421 + .name = "at91_usart_spi", 422 + }, 423 + .probe = at91_usart_spi_probe, 424 + .remove = at91_usart_spi_remove, 425 + }; 426 + 427 + module_platform_driver(at91_usart_spi_driver); 428 + 429 + MODULE_DESCRIPTION("Microchip AT91 USART SPI Controller driver"); 430 + MODULE_AUTHOR("Radu Pirea <radu.pirea@microchip.com>"); 431 + MODULE_LICENSE("GPL v2"); 432 + MODULE_ALIAS("platform:at91_usart_spi");
+1
drivers/tty/serial/Kconfig
··· 118 118 depends on ARCH_AT91 || COMPILE_TEST 119 119 select SERIAL_CORE 120 120 select SERIAL_MCTRL_GPIO if GPIOLIB 121 + select MFD_AT91_USART 121 122 help 122 123 This enables the driver for the on-chip UARTs of the Atmel 123 124 AT91 processors.
+27 -15
drivers/tty/serial/atmel_serial.c
··· 193 193 194 194 #if defined(CONFIG_OF) 195 195 static const struct of_device_id atmel_serial_dt_ids[] = { 196 - { .compatible = "atmel,at91rm9200-usart" }, 197 - { .compatible = "atmel,at91sam9260-usart" }, 196 + { .compatible = "atmel,at91rm9200-usart-serial" }, 198 197 { /* sentinel */ } 199 198 }; 200 199 #endif ··· 914 915 static int atmel_prepare_tx_dma(struct uart_port *port) 915 916 { 916 917 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 918 + struct device *mfd_dev = port->dev->parent; 917 919 dma_cap_mask_t mask; 918 920 struct dma_slave_config config; 919 921 int ret, nent; ··· 922 922 dma_cap_zero(mask); 923 923 dma_cap_set(DMA_SLAVE, mask); 924 924 925 - atmel_port->chan_tx = dma_request_slave_channel(port->dev, "tx"); 925 + atmel_port->chan_tx = dma_request_slave_channel(mfd_dev, "tx"); 926 926 if (atmel_port->chan_tx == NULL) 927 927 goto chan_err; 928 928 dev_info(port->dev, "using %s for tx DMA transfers\n", ··· 1093 1093 static int atmel_prepare_rx_dma(struct uart_port *port) 1094 1094 { 1095 1095 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 1096 + struct device *mfd_dev = port->dev->parent; 1096 1097 struct dma_async_tx_descriptor *desc; 1097 1098 dma_cap_mask_t mask; 1098 1099 struct dma_slave_config config; ··· 1105 1104 dma_cap_zero(mask); 1106 1105 dma_cap_set(DMA_CYCLIC, mask); 1107 1106 1108 - atmel_port->chan_rx = dma_request_slave_channel(port->dev, "rx"); 1107 + atmel_port->chan_rx = dma_request_slave_channel(mfd_dev, "rx"); 1109 1108 if (atmel_port->chan_rx == NULL) 1110 1109 goto chan_err; 1111 1110 dev_info(port->dev, "using %s for rx DMA transfers\n", ··· 2223 2222 */ 2224 2223 static void atmel_release_port(struct uart_port *port) 2225 2224 { 2226 - struct platform_device *pdev = to_platform_device(port->dev); 2227 - int size = pdev->resource[0].end - pdev->resource[0].start + 1; 2225 + struct platform_device *mpdev = to_platform_device(port->dev->parent); 2226 + int size = resource_size(mpdev->resource); 2228 2227 2229 2228 release_mem_region(port->mapbase, size); 2230 2229 ··· 2239 2238 */ 2240 2239 static int atmel_request_port(struct uart_port *port) 2241 2240 { 2242 - struct platform_device *pdev = to_platform_device(port->dev); 2243 - int size = pdev->resource[0].end - pdev->resource[0].start + 1; 2241 + struct platform_device *mpdev = to_platform_device(port->dev->parent); 2242 + int size = resource_size(mpdev->resource); 2244 2243 2245 2244 if (!request_mem_region(port->mapbase, size, "atmel_serial")) 2246 2245 return -EBUSY; ··· 2342 2341 { 2343 2342 int ret; 2344 2343 struct uart_port *port = &atmel_port->uart; 2344 + struct platform_device *mpdev = to_platform_device(pdev->dev.parent); 2345 2345 2346 2346 atmel_init_property(atmel_port, pdev); 2347 2347 atmel_set_ops(port); 2348 2348 2349 - uart_get_rs485_mode(&pdev->dev, &port->rs485); 2349 + uart_get_rs485_mode(&mpdev->dev, &port->rs485); 2350 2350 2351 2351 port->iotype = UPIO_MEM; 2352 2352 port->flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP; 2353 2353 port->ops = &atmel_pops; 2354 2354 port->fifosize = 1; 2355 2355 port->dev = &pdev->dev; 2356 - port->mapbase = pdev->resource[0].start; 2357 - port->irq = pdev->resource[1].start; 2356 + port->mapbase = mpdev->resource[0].start; 2357 + port->irq = mpdev->resource[1].start; 2358 2358 port->rs485_config = atmel_config_rs485; 2359 - port->membase = NULL; 2359 + port->membase = NULL; 2360 2360 2361 2361 memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring)); 2362 2362 2363 2363 /* for console, the clock could already be configured */ 2364 2364 if (!atmel_port->clk) { 2365 - atmel_port->clk = clk_get(&pdev->dev, "usart"); 2365 + atmel_port->clk = clk_get(&mpdev->dev, "usart"); 2366 2366 if (IS_ERR(atmel_port->clk)) { 2367 2367 ret = PTR_ERR(atmel_port->clk); 2368 2368 atmel_port->clk = NULL; ··· 2696 2694 static int atmel_serial_probe(struct platform_device *pdev) 2697 2695 { 2698 2696 struct atmel_uart_port *atmel_port; 2699 - struct device_node *np = pdev->dev.of_node; 2697 + struct device_node *np = pdev->dev.parent->of_node; 2700 2698 void *data; 2701 2699 int ret = -ENODEV; 2702 2700 bool rs485_enabled; 2703 2701 2704 2702 BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1)); 2703 + 2704 + /* 2705 + * In device tree there is no node with "atmel,at91rm9200-usart-serial" 2706 + * as compatible string. This driver is probed by at91-usart mfd driver 2707 + * which is just a wrapper over the atmel_serial driver and 2708 + * spi-at91-usart driver. All attributes needed by this driver are 2709 + * found in of_node of parent. 2710 + */ 2711 + pdev->dev.of_node = np; 2705 2712 2706 2713 ret = of_alias_get_id(np, "serial"); 2707 2714 if (ret < 0) ··· 2847 2836 2848 2837 clk_put(atmel_port->clk); 2849 2838 atmel_port->clk = NULL; 2839 + pdev->dev.of_node = NULL; 2850 2840 2851 2841 return ret; 2852 2842 } ··· 2858 2846 .suspend = atmel_serial_suspend, 2859 2847 .resume = atmel_serial_resume, 2860 2848 .driver = { 2861 - .name = "atmel_usart", 2849 + .name = "atmel_usart_serial", 2862 2850 .of_match_table = of_match_ptr(atmel_serial_dt_ids), 2863 2851 }, 2864 2852 };
+17
include/dt-bindings/mfd/at91-usart.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * This header provides macros for AT91 USART DT bindings. 4 + * 5 + * Copyright (C) 2018 Microchip Technology 6 + * 7 + * Author: Radu Pirea <radu.pirea@microchip.com> 8 + * 9 + */ 10 + 11 + #ifndef __DT_BINDINGS_AT91_USART_H__ 12 + #define __DT_BINDINGS_AT91_USART_H__ 13 + 14 + #define AT91_USART_MODE_SERIAL 0 15 + #define AT91_USART_MODE_SPI 1 16 + 17 + #endif /* __DT_BINDINGS_AT91_USART_H__ */
+2
include/linux/mfd/madera/core.h
··· 148 148 * @internal_dcvdd: true if DCVDD is supplied from the internal LDO1 149 149 * @pdata: our pdata 150 150 * @irq_dev: the irqchip child driver device 151 + * @irq_data: pointer to irqchip data for the child irqchip driver 151 152 * @irq: host irq number from SPI or I2C configuration 152 153 * @out_clamp: indicates output clamp state for each analogue output 153 154 * @out_shorted: indicates short circuit state for each analogue output ··· 176 175 struct madera_pdata pdata; 177 176 178 177 struct device *irq_dev; 178 + struct regmap_irq_chip_data *irq_data; 179 179 int irq; 180 180 181 181 unsigned int num_micbias;