···4343 with klogd/syslogd or the X server. You should normally N here,4444 unless you want to debug such a crash.45454646-config EARLY_PRINTK_INTEL_MID4747- bool "Early printk for Intel MID platform support"4848- depends on EARLY_PRINTK && X86_INTEL_MID4949-5046config EARLY_PRINTK_DBGP5147 bool "Early printk via EHCI debug port"5248 depends on EARLY_PRINTK && PCI
···11-/*22- * early_printk_intel_mid.c - early consoles for Intel MID platforms33- *44- * Copyright (c) 2008-2010, Intel Corporation55- *66- * This program is free software; you can redistribute it and/or77- * modify it under the terms of the GNU General Public License88- * as published by the Free Software Foundation; version 299- * of the License.1010- */1111-1212-/*1313- * This file implements early console named hsu.1414- * hsu is based on a High Speed UART device which only exists in the Medfield1515- * platform1616- */1717-1818-#include <linux/serial_reg.h>1919-#include <linux/serial_mfd.h>2020-#include <linux/console.h>2121-#include <linux/kernel.h>2222-#include <linux/delay.h>2323-#include <linux/io.h>2424-2525-#include <asm/fixmap.h>2626-#include <asm/pgtable.h>2727-#include <asm/intel-mid.h>2828-2929-/*3030- * Following is the early console based on Medfield HSU (High3131- * Speed UART) device.3232- */3333-#define HSU_PORT_BASE 0xffa280803434-3535-static void __iomem *phsu;3636-3737-void hsu_early_console_init(const char *s)3838-{3939- unsigned long paddr, port = 0;4040- u8 lcr;4141-4242- /*4343- * Select the early HSU console port if specified by user in the4444- * kernel command line.4545- */4646- if (*s && !kstrtoul(s, 10, &port))4747- port = clamp_val(port, 0, 2);4848-4949- paddr = HSU_PORT_BASE + port * 0x80;5050- phsu = (void __iomem *)set_fixmap_offset_nocache(FIX_EARLYCON_MEM_BASE, paddr);5151-5252- /* Disable FIFO */5353- writeb(0x0, phsu + UART_FCR);5454-5555- /* Set to default 115200 bps, 8n1 */5656- lcr = readb(phsu + UART_LCR);5757- writeb((0x80 | lcr), phsu + UART_LCR);5858- writeb(0x18, phsu + UART_DLL);5959- writeb(lcr, phsu + UART_LCR);6060- writel(0x3600, phsu + UART_MUL*4);6161-6262- writeb(0x8, phsu + UART_MCR);6363- writeb(0x7, phsu + UART_FCR);6464- writeb(0x3, phsu + UART_LCR);6565-6666- /* Clear IRQ status */6767- readb(phsu + UART_LSR);6868- readb(phsu + UART_RX);6969- readb(phsu + UART_IIR);7070- readb(phsu + UART_MSR);7171-7272- /* Enable FIFO */7373- writeb(0x7, phsu + UART_FCR);7474-}7575-7676-#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)7777-7878-static void early_hsu_putc(char ch)7979-{8080- unsigned int timeout = 10000; /* 10ms */8181- u8 status;8282-8383- while (--timeout) {8484- status = readb(phsu + UART_LSR);8585- if (status & BOTH_EMPTY)8686- break;8787- udelay(1);8888- }8989-9090- /* Only write the char when there was no timeout */9191- if (timeout)9292- writeb(ch, phsu + UART_TX);9393-}9494-9595-static void early_hsu_write(struct console *con, const char *str, unsigned n)9696-{9797- int i;9898-9999- for (i = 0; i < n && *str; i++) {100100- if (*str == '\n')101101- early_hsu_putc('\r');102102- early_hsu_putc(*str);103103- str++;104104- }105105-}106106-107107-struct console early_hsu_console = {108108- .name = "earlyhsu",109109- .write = early_hsu_write,110110- .flags = CON_PRINTBUFFER,111111- .index = -1,112112-};
+2
drivers/dma/Kconfig
···125125 EloPlus is on mpc85xx and mpc86xx and Pxxx parts, and the Elo3 is on126126 some Txxx and Bxxx parts.127127128128+source "drivers/dma/hsu/Kconfig"129129+128130config MPC512X_DMA129131 tristate "Freescale MPC512x built-in DMA engine support"130132 depends on PPC_MPC512x || PPC_MPC831x
···11+# DMA engine configuration for hsu22+config HSU_DMA33+ tristate "High Speed UART DMA support"44+ select DMA_ENGINE55+ select DMA_VIRTUAL_CHANNELS66+77+config HSU_DMA_PCI88+ tristate "High Speed UART DMA PCI driver"99+ depends on PCI1010+ select HSU_DMA1111+ help1212+ Support the High Speed UART DMA on the platfroms that1313+ enumerate it as a PCI device. For example, Intel Medfield1414+ has integrated this HSU DMA controller.
···11+/*22+ * Core driver for the High Speed UART DMA33+ *44+ * Copyright (C) 2015 Intel Corporation55+ * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>66+ *77+ * Partially based on the bits found in drivers/tty/serial/mfd.c.88+ *99+ * This program is free software; you can redistribute it and/or modify1010+ * it under the terms of the GNU General Public License version 2 as1111+ * published by the Free Software Foundation.1212+ */1313+1414+/*1515+ * DMA channel allocation:1616+ * 1. Even number chans are used for DMA Read (UART TX), odd chans for DMA1717+ * Write (UART RX).1818+ * 2. 0/1 channel are assigned to port 0, 2/3 chan to port 1, 4/5 chan to1919+ * port 3, and so on.2020+ */2121+2222+#include <linux/delay.h>2323+#include <linux/dmaengine.h>2424+#include <linux/dma-mapping.h>2525+#include <linux/init.h>2626+#include <linux/module.h>2727+#include <linux/slab.h>2828+2929+#include "hsu.h"3030+3131+#define HSU_DMA_BUSWIDTHS \3232+ BIT(DMA_SLAVE_BUSWIDTH_UNDEFINED) | \3333+ BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \3434+ BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \3535+ BIT(DMA_SLAVE_BUSWIDTH_3_BYTES) | \3636+ BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) | \3737+ BIT(DMA_SLAVE_BUSWIDTH_8_BYTES) | \3838+ BIT(DMA_SLAVE_BUSWIDTH_16_BYTES)3939+4040+static inline void hsu_chan_disable(struct hsu_dma_chan *hsuc)4141+{4242+ hsu_chan_writel(hsuc, HSU_CH_CR, 0);4343+}4444+4545+static inline void hsu_chan_enable(struct hsu_dma_chan *hsuc)4646+{4747+ u32 cr = HSU_CH_CR_CHA;4848+4949+ if (hsuc->direction == DMA_MEM_TO_DEV)5050+ cr &= ~HSU_CH_CR_CHD;5151+ else if (hsuc->direction == DMA_DEV_TO_MEM)5252+ cr |= HSU_CH_CR_CHD;5353+5454+ hsu_chan_writel(hsuc, HSU_CH_CR, cr);5555+}5656+5757+static void hsu_dma_chan_start(struct hsu_dma_chan *hsuc)5858+{5959+ struct dma_slave_config *config = &hsuc->config;6060+ struct hsu_dma_desc *desc = hsuc->desc;6161+ u32 bsr, mtsr;6262+ u32 dcr = HSU_CH_DCR_CHSOE | HSU_CH_DCR_CHEI;6363+ unsigned int i, count;6464+6565+ if (hsuc->direction == DMA_MEM_TO_DEV) {6666+ bsr = config->dst_maxburst;6767+ mtsr = config->dst_addr_width;6868+ } else if (hsuc->direction == DMA_DEV_TO_MEM) {6969+ bsr = config->src_maxburst;7070+ mtsr = config->src_addr_width;7171+ } else {7272+ /* Not supported direction */7373+ return;7474+ }7575+7676+ hsu_chan_disable(hsuc);7777+7878+ hsu_chan_writel(hsuc, HSU_CH_DCR, 0);7979+ hsu_chan_writel(hsuc, HSU_CH_BSR, bsr);8080+ hsu_chan_writel(hsuc, HSU_CH_MTSR, mtsr);8181+8282+ /* Set descriptors */8383+ count = (desc->nents - desc->active) % HSU_DMA_CHAN_NR_DESC;8484+ for (i = 0; i < count; i++) {8585+ hsu_chan_writel(hsuc, HSU_CH_DxSAR(i), desc->sg[i].addr);8686+ hsu_chan_writel(hsuc, HSU_CH_DxTSR(i), desc->sg[i].len);8787+8888+ /* Prepare value for DCR */8989+ dcr |= HSU_CH_DCR_DESCA(i);9090+ dcr |= HSU_CH_DCR_CHTOI(i); /* timeout bit, see HSU Errata 1 */9191+9292+ desc->active++;9393+ }9494+ /* Only for the last descriptor in the chain */9595+ dcr |= HSU_CH_DCR_CHSOD(count - 1);9696+ dcr |= HSU_CH_DCR_CHDI(count - 1);9797+9898+ hsu_chan_writel(hsuc, HSU_CH_DCR, dcr);9999+100100+ hsu_chan_enable(hsuc);101101+}102102+103103+static void hsu_dma_stop_channel(struct hsu_dma_chan *hsuc)104104+{105105+ unsigned long flags;106106+107107+ spin_lock_irqsave(&hsuc->lock, flags);108108+ hsu_chan_disable(hsuc);109109+ hsu_chan_writel(hsuc, HSU_CH_DCR, 0);110110+ spin_unlock_irqrestore(&hsuc->lock, flags);111111+}112112+113113+static void hsu_dma_start_channel(struct hsu_dma_chan *hsuc)114114+{115115+ unsigned long flags;116116+117117+ spin_lock_irqsave(&hsuc->lock, flags);118118+ hsu_dma_chan_start(hsuc);119119+ spin_unlock_irqrestore(&hsuc->lock, flags);120120+}121121+122122+static void hsu_dma_start_transfer(struct hsu_dma_chan *hsuc)123123+{124124+ struct virt_dma_desc *vdesc;125125+126126+ /* Get the next descriptor */127127+ vdesc = vchan_next_desc(&hsuc->vchan);128128+ if (!vdesc) {129129+ hsuc->desc = NULL;130130+ return;131131+ }132132+133133+ list_del(&vdesc->node);134134+ hsuc->desc = to_hsu_dma_desc(vdesc);135135+136136+ /* Start the channel with a new descriptor */137137+ hsu_dma_start_channel(hsuc);138138+}139139+140140+static u32 hsu_dma_chan_get_sr(struct hsu_dma_chan *hsuc)141141+{142142+ unsigned long flags;143143+ u32 sr;144144+145145+ spin_lock_irqsave(&hsuc->lock, flags);146146+ sr = hsu_chan_readl(hsuc, HSU_CH_SR);147147+ spin_unlock_irqrestore(&hsuc->lock, flags);148148+149149+ return sr;150150+}151151+152152+irqreturn_t hsu_dma_irq(struct hsu_dma_chip *chip, unsigned short nr)153153+{154154+ struct hsu_dma_chan *hsuc;155155+ struct hsu_dma_desc *desc;156156+ unsigned long flags;157157+ u32 sr;158158+159159+ /* Sanity check */160160+ if (nr >= chip->pdata->nr_channels)161161+ return IRQ_NONE;162162+163163+ hsuc = &chip->hsu->chan[nr];164164+165165+ /*166166+ * No matter what situation, need read clear the IRQ status167167+ * There is a bug, see Errata 5, HSD 2900918168168+ */169169+ sr = hsu_dma_chan_get_sr(hsuc);170170+ if (!sr)171171+ return IRQ_NONE;172172+173173+ /* Timeout IRQ, need wait some time, see Errata 2 */174174+ if (hsuc->direction == DMA_DEV_TO_MEM && (sr & HSU_CH_SR_DESCTO_ANY))175175+ udelay(2);176176+177177+ sr &= ~HSU_CH_SR_DESCTO_ANY;178178+ if (!sr)179179+ return IRQ_HANDLED;180180+181181+ spin_lock_irqsave(&hsuc->vchan.lock, flags);182182+ desc = hsuc->desc;183183+ if (desc) {184184+ if (sr & HSU_CH_SR_CHE) {185185+ desc->status = DMA_ERROR;186186+ } else if (desc->active < desc->nents) {187187+ hsu_dma_start_channel(hsuc);188188+ } else {189189+ vchan_cookie_complete(&desc->vdesc);190190+ desc->status = DMA_COMPLETE;191191+ hsu_dma_start_transfer(hsuc);192192+ }193193+ }194194+ spin_unlock_irqrestore(&hsuc->vchan.lock, flags);195195+196196+ return IRQ_HANDLED;197197+}198198+EXPORT_SYMBOL_GPL(hsu_dma_irq);199199+200200+static struct hsu_dma_desc *hsu_dma_alloc_desc(unsigned int nents)201201+{202202+ struct hsu_dma_desc *desc;203203+204204+ desc = kzalloc(sizeof(*desc), GFP_ATOMIC);205205+ if (!desc)206206+ return NULL;207207+208208+ desc->sg = kcalloc(nents, sizeof(*desc->sg), GFP_ATOMIC);209209+ if (!desc->sg) {210210+ kfree(desc);211211+ return NULL;212212+ }213213+214214+ return desc;215215+}216216+217217+static void hsu_dma_desc_free(struct virt_dma_desc *vdesc)218218+{219219+ struct hsu_dma_desc *desc = to_hsu_dma_desc(vdesc);220220+221221+ kfree(desc->sg);222222+ kfree(desc);223223+}224224+225225+static struct dma_async_tx_descriptor *hsu_dma_prep_slave_sg(226226+ struct dma_chan *chan, struct scatterlist *sgl,227227+ unsigned int sg_len, enum dma_transfer_direction direction,228228+ unsigned long flags, void *context)229229+{230230+ struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan);231231+ struct hsu_dma_desc *desc;232232+ struct scatterlist *sg;233233+ unsigned int i;234234+235235+ desc = hsu_dma_alloc_desc(sg_len);236236+ if (!desc)237237+ return NULL;238238+239239+ for_each_sg(sgl, sg, sg_len, i) {240240+ desc->sg[i].addr = sg_dma_address(sg);241241+ desc->sg[i].len = sg_dma_len(sg);242242+ }243243+244244+ desc->nents = sg_len;245245+ desc->direction = direction;246246+ desc->active = 0;247247+ desc->status = DMA_IN_PROGRESS;248248+249249+ return vchan_tx_prep(&hsuc->vchan, &desc->vdesc, flags);250250+}251251+252252+static void hsu_dma_issue_pending(struct dma_chan *chan)253253+{254254+ struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan);255255+ unsigned long flags;256256+257257+ spin_lock_irqsave(&hsuc->vchan.lock, flags);258258+ if (vchan_issue_pending(&hsuc->vchan) && !hsuc->desc)259259+ hsu_dma_start_transfer(hsuc);260260+ spin_unlock_irqrestore(&hsuc->vchan.lock, flags);261261+}262262+263263+static size_t hsu_dma_desc_size(struct hsu_dma_desc *desc)264264+{265265+ size_t bytes = 0;266266+ unsigned int i;267267+268268+ for (i = desc->active; i < desc->nents; i++)269269+ bytes += desc->sg[i].len;270270+271271+ return bytes;272272+}273273+274274+static size_t hsu_dma_active_desc_size(struct hsu_dma_chan *hsuc)275275+{276276+ struct hsu_dma_desc *desc = hsuc->desc;277277+ size_t bytes = hsu_dma_desc_size(desc);278278+ int i;279279+ unsigned long flags;280280+281281+ spin_lock_irqsave(&hsuc->lock, flags);282282+ i = desc->active % HSU_DMA_CHAN_NR_DESC;283283+ do {284284+ bytes += hsu_chan_readl(hsuc, HSU_CH_DxTSR(i));285285+ } while (--i >= 0);286286+ spin_unlock_irqrestore(&hsuc->lock, flags);287287+288288+ return bytes;289289+}290290+291291+static enum dma_status hsu_dma_tx_status(struct dma_chan *chan,292292+ dma_cookie_t cookie, struct dma_tx_state *state)293293+{294294+ struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan);295295+ struct virt_dma_desc *vdesc;296296+ enum dma_status status;297297+ size_t bytes;298298+ unsigned long flags;299299+300300+ status = dma_cookie_status(chan, cookie, state);301301+ if (status == DMA_COMPLETE)302302+ return status;303303+304304+ spin_lock_irqsave(&hsuc->vchan.lock, flags);305305+ vdesc = vchan_find_desc(&hsuc->vchan, cookie);306306+ if (hsuc->desc && cookie == hsuc->desc->vdesc.tx.cookie) {307307+ bytes = hsu_dma_active_desc_size(hsuc);308308+ dma_set_residue(state, bytes);309309+ status = hsuc->desc->status;310310+ } else if (vdesc) {311311+ bytes = hsu_dma_desc_size(to_hsu_dma_desc(vdesc));312312+ dma_set_residue(state, bytes);313313+ }314314+ spin_unlock_irqrestore(&hsuc->vchan.lock, flags);315315+316316+ return status;317317+}318318+319319+static int hsu_dma_slave_config(struct dma_chan *chan,320320+ struct dma_slave_config *config)321321+{322322+ struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan);323323+324324+ /* Check if chan will be configured for slave transfers */325325+ if (!is_slave_direction(config->direction))326326+ return -EINVAL;327327+328328+ memcpy(&hsuc->config, config, sizeof(hsuc->config));329329+330330+ return 0;331331+}332332+333333+static void hsu_dma_chan_deactivate(struct hsu_dma_chan *hsuc)334334+{335335+ unsigned long flags;336336+337337+ spin_lock_irqsave(&hsuc->lock, flags);338338+ hsu_chan_disable(hsuc);339339+ spin_unlock_irqrestore(&hsuc->lock, flags);340340+}341341+342342+static void hsu_dma_chan_activate(struct hsu_dma_chan *hsuc)343343+{344344+ unsigned long flags;345345+346346+ spin_lock_irqsave(&hsuc->lock, flags);347347+ hsu_chan_enable(hsuc);348348+ spin_unlock_irqrestore(&hsuc->lock, flags);349349+}350350+351351+static int hsu_dma_pause(struct dma_chan *chan)352352+{353353+ struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan);354354+ unsigned long flags;355355+356356+ spin_lock_irqsave(&hsuc->vchan.lock, flags);357357+ if (hsuc->desc && hsuc->desc->status == DMA_IN_PROGRESS) {358358+ hsu_dma_chan_deactivate(hsuc);359359+ hsuc->desc->status = DMA_PAUSED;360360+ }361361+ spin_unlock_irqrestore(&hsuc->vchan.lock, flags);362362+363363+ return 0;364364+}365365+366366+static int hsu_dma_resume(struct dma_chan *chan)367367+{368368+ struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan);369369+ unsigned long flags;370370+371371+ spin_lock_irqsave(&hsuc->vchan.lock, flags);372372+ if (hsuc->desc && hsuc->desc->status == DMA_PAUSED) {373373+ hsuc->desc->status = DMA_IN_PROGRESS;374374+ hsu_dma_chan_activate(hsuc);375375+ }376376+ spin_unlock_irqrestore(&hsuc->vchan.lock, flags);377377+378378+ return 0;379379+}380380+381381+static int hsu_dma_terminate_all(struct dma_chan *chan)382382+{383383+ struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan);384384+ unsigned long flags;385385+ LIST_HEAD(head);386386+387387+ spin_lock_irqsave(&hsuc->vchan.lock, flags);388388+389389+ hsu_dma_stop_channel(hsuc);390390+ hsuc->desc = NULL;391391+392392+ vchan_get_all_descriptors(&hsuc->vchan, &head);393393+ spin_unlock_irqrestore(&hsuc->vchan.lock, flags);394394+ vchan_dma_desc_free_list(&hsuc->vchan, &head);395395+396396+ return 0;397397+}398398+399399+static int hsu_dma_alloc_chan_resources(struct dma_chan *chan)400400+{401401+ return 0;402402+}403403+404404+static void hsu_dma_free_chan_resources(struct dma_chan *chan)405405+{406406+ vchan_free_chan_resources(to_virt_chan(chan));407407+}408408+409409+int hsu_dma_probe(struct hsu_dma_chip *chip)410410+{411411+ struct hsu_dma *hsu;412412+ struct hsu_dma_platform_data *pdata = chip->pdata;413413+ void __iomem *addr = chip->regs + chip->offset;414414+ unsigned short i;415415+ int ret;416416+417417+ hsu = devm_kzalloc(chip->dev, sizeof(*hsu), GFP_KERNEL);418418+ if (!hsu)419419+ return -ENOMEM;420420+421421+ chip->hsu = hsu;422422+423423+ if (!pdata) {424424+ pdata = devm_kzalloc(chip->dev, sizeof(*pdata), GFP_KERNEL);425425+ if (!pdata)426426+ return -ENOMEM;427427+428428+ chip->pdata = pdata;429429+430430+ /* Guess nr_channels from the IO space length */431431+ pdata->nr_channels = (chip->length - chip->offset) /432432+ HSU_DMA_CHAN_LENGTH;433433+ }434434+435435+ hsu->chan = devm_kcalloc(chip->dev, pdata->nr_channels,436436+ sizeof(*hsu->chan), GFP_KERNEL);437437+ if (!hsu->chan)438438+ return -ENOMEM;439439+440440+ INIT_LIST_HEAD(&hsu->dma.channels);441441+ for (i = 0; i < pdata->nr_channels; i++) {442442+ struct hsu_dma_chan *hsuc = &hsu->chan[i];443443+444444+ hsuc->vchan.desc_free = hsu_dma_desc_free;445445+ vchan_init(&hsuc->vchan, &hsu->dma);446446+447447+ hsuc->direction = (i & 0x1) ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV;448448+ hsuc->reg = addr + i * HSU_DMA_CHAN_LENGTH;449449+450450+ spin_lock_init(&hsuc->lock);451451+ }452452+453453+ dma_cap_set(DMA_SLAVE, hsu->dma.cap_mask);454454+ dma_cap_set(DMA_PRIVATE, hsu->dma.cap_mask);455455+456456+ hsu->dma.device_alloc_chan_resources = hsu_dma_alloc_chan_resources;457457+ hsu->dma.device_free_chan_resources = hsu_dma_free_chan_resources;458458+459459+ hsu->dma.device_prep_slave_sg = hsu_dma_prep_slave_sg;460460+461461+ hsu->dma.device_issue_pending = hsu_dma_issue_pending;462462+ hsu->dma.device_tx_status = hsu_dma_tx_status;463463+464464+ hsu->dma.device_config = hsu_dma_slave_config;465465+ hsu->dma.device_pause = hsu_dma_pause;466466+ hsu->dma.device_resume = hsu_dma_resume;467467+ hsu->dma.device_terminate_all = hsu_dma_terminate_all;468468+469469+ hsu->dma.src_addr_widths = HSU_DMA_BUSWIDTHS;470470+ hsu->dma.dst_addr_widths = HSU_DMA_BUSWIDTHS;471471+ hsu->dma.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);472472+ hsu->dma.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;473473+474474+ hsu->dma.dev = chip->dev;475475+476476+ ret = dma_async_device_register(&hsu->dma);477477+ if (ret)478478+ return ret;479479+480480+ dev_info(chip->dev, "Found HSU DMA, %d channels\n", pdata->nr_channels);481481+ return 0;482482+}483483+EXPORT_SYMBOL_GPL(hsu_dma_probe);484484+485485+int hsu_dma_remove(struct hsu_dma_chip *chip)486486+{487487+ struct hsu_dma *hsu = chip->hsu;488488+ unsigned short i;489489+490490+ dma_async_device_unregister(&hsu->dma);491491+492492+ for (i = 0; i < chip->pdata->nr_channels; i++) {493493+ struct hsu_dma_chan *hsuc = &hsu->chan[i];494494+495495+ tasklet_kill(&hsuc->vchan.task);496496+ }497497+498498+ return 0;499499+}500500+EXPORT_SYMBOL_GPL(hsu_dma_remove);501501+502502+MODULE_LICENSE("GPL v2");503503+MODULE_DESCRIPTION("High Speed UART DMA core driver");504504+MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
+118
drivers/dma/hsu/hsu.h
···11+/*22+ * Driver for the High Speed UART DMA33+ *44+ * Copyright (C) 2015 Intel Corporation55+ *66+ * Partially based on the bits found in drivers/tty/serial/mfd.c.77+ *88+ * This program is free software; you can redistribute it and/or modify99+ * it under the terms of the GNU General Public License version 2 as1010+ * published by the Free Software Foundation.1111+ */1212+1313+#ifndef __DMA_HSU_H__1414+#define __DMA_HSU_H__1515+1616+#include <linux/spinlock.h>1717+#include <linux/dma/hsu.h>1818+1919+#include "../virt-dma.h"2020+2121+#define HSU_CH_SR 0x00 /* channel status */2222+#define HSU_CH_CR 0x04 /* channel control */2323+#define HSU_CH_DCR 0x08 /* descriptor control */2424+#define HSU_CH_BSR 0x10 /* FIFO buffer size */2525+#define HSU_CH_MTSR 0x14 /* minimum transfer size */2626+#define HSU_CH_DxSAR(x) (0x20 + 8 * (x)) /* desc start addr */2727+#define HSU_CH_DxTSR(x) (0x24 + 8 * (x)) /* desc transfer size */2828+#define HSU_CH_D0SAR 0x20 /* desc 0 start addr */2929+#define HSU_CH_D0TSR 0x24 /* desc 0 transfer size */3030+#define HSU_CH_D1SAR 0x283131+#define HSU_CH_D1TSR 0x2c3232+#define HSU_CH_D2SAR 0x303333+#define HSU_CH_D2TSR 0x343434+#define HSU_CH_D3SAR 0x383535+#define HSU_CH_D3TSR 0x3c3636+3737+#define HSU_DMA_CHAN_NR_DESC 43838+#define HSU_DMA_CHAN_LENGTH 0x403939+4040+/* Bits in HSU_CH_SR */4141+#define HSU_CH_SR_DESCTO(x) BIT(8 + (x))4242+#define HSU_CH_SR_DESCTO_ANY (BIT(11) | BIT(10) | BIT(9) | BIT(8))4343+#define HSU_CH_SR_CHE BIT(15)4444+4545+/* Bits in HSU_CH_CR */4646+#define HSU_CH_CR_CHA BIT(0)4747+#define HSU_CH_CR_CHD BIT(1)4848+4949+/* Bits in HSU_CH_DCR */5050+#define HSU_CH_DCR_DESCA(x) BIT(0 + (x))5151+#define HSU_CH_DCR_CHSOD(x) BIT(8 + (x))5252+#define HSU_CH_DCR_CHSOTO BIT(14)5353+#define HSU_CH_DCR_CHSOE BIT(15)5454+#define HSU_CH_DCR_CHDI(x) BIT(16 + (x))5555+#define HSU_CH_DCR_CHEI BIT(23)5656+#define HSU_CH_DCR_CHTOI(x) BIT(24 + (x))5757+5858+struct hsu_dma_sg {5959+ dma_addr_t addr;6060+ unsigned int len;6161+};6262+6363+struct hsu_dma_desc {6464+ struct virt_dma_desc vdesc;6565+ enum dma_transfer_direction direction;6666+ struct hsu_dma_sg *sg;6767+ unsigned int nents;6868+ unsigned int active;6969+ enum dma_status status;7070+};7171+7272+static inline struct hsu_dma_desc *to_hsu_dma_desc(struct virt_dma_desc *vdesc)7373+{7474+ return container_of(vdesc, struct hsu_dma_desc, vdesc);7575+}7676+7777+struct hsu_dma_chan {7878+ struct virt_dma_chan vchan;7979+8080+ void __iomem *reg;8181+ spinlock_t lock;8282+8383+ /* hardware configuration */8484+ enum dma_transfer_direction direction;8585+ struct dma_slave_config config;8686+8787+ struct hsu_dma_desc *desc;8888+};8989+9090+static inline struct hsu_dma_chan *to_hsu_dma_chan(struct dma_chan *chan)9191+{9292+ return container_of(chan, struct hsu_dma_chan, vchan.chan);9393+}9494+9595+static inline u32 hsu_chan_readl(struct hsu_dma_chan *hsuc, int offset)9696+{9797+ return readl(hsuc->reg + offset);9898+}9999+100100+static inline void hsu_chan_writel(struct hsu_dma_chan *hsuc, int offset,101101+ u32 value)102102+{103103+ writel(value, hsuc->reg + offset);104104+}105105+106106+struct hsu_dma {107107+ struct dma_device dma;108108+109109+ /* channels */110110+ struct hsu_dma_chan *chan;111111+};112112+113113+static inline struct hsu_dma *to_hsu_dma(struct dma_device *ddev)114114+{115115+ return container_of(ddev, struct hsu_dma, dma);116116+}117117+118118+#endif /* __DMA_HSU_H__ */
+123
drivers/dma/hsu/pci.c
···11+/*22+ * PCI driver for the High Speed UART DMA33+ *44+ * Copyright (C) 2015 Intel Corporation55+ * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>66+ *77+ * Partially based on the bits found in drivers/tty/serial/mfd.c.88+ *99+ * This program is free software; you can redistribute it and/or modify1010+ * it under the terms of the GNU General Public License version 2 as1111+ * published by the Free Software Foundation.1212+ */1313+1414+#include <linux/bitops.h>1515+#include <linux/device.h>1616+#include <linux/module.h>1717+#include <linux/pci.h>1818+1919+#include "hsu.h"2020+2121+#define HSU_PCI_DMASR 0x002222+#define HSU_PCI_DMAISR 0x042323+2424+#define HSU_PCI_CHAN_OFFSET 0x1002525+2626+static irqreturn_t hsu_pci_irq(int irq, void *dev)2727+{2828+ struct hsu_dma_chip *chip = dev;2929+ u32 dmaisr;3030+ unsigned short i;3131+ irqreturn_t ret = IRQ_NONE;3232+3333+ dmaisr = readl(chip->regs + HSU_PCI_DMAISR);3434+ for (i = 0; i < chip->pdata->nr_channels; i++) {3535+ if (dmaisr & 0x1)3636+ ret |= hsu_dma_irq(chip, i);3737+ dmaisr >>= 1;3838+ }3939+4040+ return ret;4141+}4242+4343+static int hsu_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)4444+{4545+ struct hsu_dma_chip *chip;4646+ int ret;4747+4848+ ret = pcim_enable_device(pdev);4949+ if (ret)5050+ return ret;5151+5252+ ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));5353+ if (ret) {5454+ dev_err(&pdev->dev, "I/O memory remapping failed\n");5555+ return ret;5656+ }5757+5858+ pci_set_master(pdev);5959+ pci_try_set_mwi(pdev);6060+6161+ ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));6262+ if (ret)6363+ return ret;6464+6565+ ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));6666+ if (ret)6767+ return ret;6868+6969+ chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);7070+ if (!chip)7171+ return -ENOMEM;7272+7373+ chip->dev = &pdev->dev;7474+ chip->regs = pcim_iomap_table(pdev)[0];7575+ chip->length = pci_resource_len(pdev, 0);7676+ chip->offset = HSU_PCI_CHAN_OFFSET;7777+ chip->irq = pdev->irq;7878+7979+ pci_enable_msi(pdev);8080+8181+ ret = hsu_dma_probe(chip);8282+ if (ret)8383+ return ret;8484+8585+ ret = request_irq(chip->irq, hsu_pci_irq, 0, "hsu_dma_pci", chip);8686+ if (ret)8787+ goto err_register_irq;8888+8989+ pci_set_drvdata(pdev, chip);9090+9191+ return 0;9292+9393+err_register_irq:9494+ hsu_dma_remove(chip);9595+ return ret;9696+}9797+9898+static void hsu_pci_remove(struct pci_dev *pdev)9999+{100100+ struct hsu_dma_chip *chip = pci_get_drvdata(pdev);101101+102102+ free_irq(chip->irq, chip);103103+ hsu_dma_remove(chip);104104+}105105+106106+static const struct pci_device_id hsu_pci_id_table[] = {107107+ { PCI_VDEVICE(INTEL, 0x081e), 0 },108108+ { }109109+};110110+MODULE_DEVICE_TABLE(pci, hsu_pci_id_table);111111+112112+static struct pci_driver hsu_pci_driver = {113113+ .name = "hsu_dma_pci",114114+ .id_table = hsu_pci_id_table,115115+ .probe = hsu_pci_probe,116116+ .remove = hsu_pci_remove,117117+};118118+119119+module_pci_driver(hsu_pci_driver);120120+121121+MODULE_LICENSE("GPL v2");122122+MODULE_DESCRIPTION("High Speed UART DMA PCI driver");123123+MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
+2-2
drivers/tty/serial/8250/8250_core.c
···895895 /*896896 * Exar ST16C2550 "A2" devices incorrectly detect as897897 * having an EFR, and report an ID of 0x0201. See898898- * http://linux.derkeiler.com/Mailing-Lists/Kernel/2004-11/4812.html 898898+ * http://linux.derkeiler.com/Mailing-Lists/Kernel/2004-11/4812.html899899 */900900 if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16)901901 return 1;···12601260 serial_out(up, UART_LCR, save_lcr);1261126112621262 port->fifosize = uart_config[up->port.type].fifo_size;12631263- old_capabilities = up->capabilities; 12631263+ old_capabilities = up->capabilities;12641264 up->capabilities = uart_config[port->type].flags;12651265 up->tx_loadsz = uart_config[port->type].tx_loadsz;12661266
+11-4
drivers/tty/serial/8250/8250_dw.c
···416416{417417 struct uart_8250_port uart = {};418418 struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);419419- struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);419419+ int irq = platform_get_irq(pdev, 0);420420 struct dw8250_data *data;421421 int err;422422423423- if (!regs || !irq) {424424- dev_err(&pdev->dev, "no registers/irq defined\n");423423+ if (!regs) {424424+ dev_err(&pdev->dev, "no registers defined\n");425425 return -EINVAL;426426+ }427427+428428+ if (irq < 0) {429429+ if (irq != -EPROBE_DEFER)430430+ dev_err(&pdev->dev, "cannot get irq\n");431431+ return irq;426432 }427433428434 spin_lock_init(&uart.port.lock);429435 uart.port.mapbase = regs->start;430430- uart.port.irq = irq->start;436436+ uart.port.irq = irq;431437 uart.port.handle_irq = dw8250_handle_irq;432438 uart.port.pm = dw8250_do_pm;433439 uart.port.type = PORT_8250;···646640MODULE_AUTHOR("Jamie Iles");647641MODULE_LICENSE("GPL");648642MODULE_DESCRIPTION("Synopsys DesignWare 8250 serial port driver");643643+MODULE_ALIAS("platform:dw-apb-uart");
+198-16
drivers/tty/serial/8250/8250_pci.c
···27272828#include <linux/dmaengine.h>2929#include <linux/platform_data/dma-dw.h>3030+#include <linux/platform_data/dma-hsu.h>30313132#include "8250.h"3233···15261525 return ret;15271526}1528152715281528+#define INTEL_MID_UART_PS 0x3015291529+#define INTEL_MID_UART_MUL 0x3415301530+15311531+static void intel_mid_set_termios_50M(struct uart_port *p,15321532+ struct ktermios *termios,15331533+ struct ktermios *old)15341534+{15351535+ unsigned int baud = tty_termios_baud_rate(termios);15361536+ u32 ps, mul;15371537+15381538+ /*15391539+ * The uart clk is 50Mhz, and the baud rate come from:15401540+ * baud = 50M * MUL / (DIV * PS * DLAB)15411541+ *15421542+ * For those basic low baud rate we can get the direct15431543+ * scalar from 2746800, like 115200 = 2746800/24. For those15441544+ * higher baud rate, we handle them case by case, mainly by15451545+ * adjusting the MUL/PS registers, and DIV register is kept15461546+ * as default value 0x3d09 to make things simple.15471547+ */15481548+15491549+ ps = 0x10;15501550+15511551+ switch (baud) {15521552+ case 500000:15531553+ case 1000000:15541554+ case 1500000:15551555+ case 3000000:15561556+ mul = 0x3a98;15571557+ p->uartclk = 48000000;15581558+ break;15591559+ case 2000000:15601560+ case 4000000:15611561+ mul = 0x2710;15621562+ ps = 0x08;15631563+ p->uartclk = 64000000;15641564+ break;15651565+ case 2500000:15661566+ mul = 0x30d4;15671567+ p->uartclk = 40000000;15681568+ break;15691569+ case 3500000:15701570+ mul = 0x3345;15711571+ ps = 0x0c;15721572+ p->uartclk = 56000000;15731573+ break;15741574+ default:15751575+ mul = 0x2400;15761576+ p->uartclk = 29491200;15771577+ }15781578+15791579+ writel(ps, p->membase + INTEL_MID_UART_PS); /* set PS */15801580+ writel(mul, p->membase + INTEL_MID_UART_MUL); /* set MUL */15811581+15821582+ serial8250_do_set_termios(p, termios, old);15831583+}15841584+15851585+static bool intel_mid_dma_filter(struct dma_chan *chan, void *param)15861586+{15871587+ struct hsu_dma_slave *s = param;15881588+15891589+ if (s->dma_dev != chan->device->dev || s->chan_id != chan->chan_id)15901590+ return false;15911591+15921592+ chan->private = s;15931593+ return true;15941594+}15951595+15961596+static int intel_mid_serial_setup(struct serial_private *priv,15971597+ const struct pciserial_board *board,15981598+ struct uart_8250_port *port, int idx,15991599+ int index, struct pci_dev *dma_dev)16001600+{16011601+ struct device *dev = port->port.dev;16021602+ struct uart_8250_dma *dma;16031603+ struct hsu_dma_slave *tx_param, *rx_param;16041604+16051605+ dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL);16061606+ if (!dma)16071607+ return -ENOMEM;16081608+16091609+ tx_param = devm_kzalloc(dev, sizeof(*tx_param), GFP_KERNEL);16101610+ if (!tx_param)16111611+ return -ENOMEM;16121612+16131613+ rx_param = devm_kzalloc(dev, sizeof(*rx_param), GFP_KERNEL);16141614+ if (!rx_param)16151615+ return -ENOMEM;16161616+16171617+ rx_param->chan_id = index * 2 + 1;16181618+ tx_param->chan_id = index * 2;16191619+16201620+ dma->rxconf.src_maxburst = 64;16211621+ dma->txconf.dst_maxburst = 64;16221622+16231623+ rx_param->dma_dev = &dma_dev->dev;16241624+ tx_param->dma_dev = &dma_dev->dev;16251625+16261626+ dma->fn = intel_mid_dma_filter;16271627+ dma->rx_param = rx_param;16281628+ dma->tx_param = tx_param;16291629+16301630+ port->port.type = PORT_16750;16311631+ port->port.flags |= UPF_FIXED_PORT | UPF_FIXED_TYPE;16321632+ port->dma = dma;16331633+16341634+ return pci_default_setup(priv, board, port, idx);16351635+}16361636+16371637+#define PCI_DEVICE_ID_INTEL_PNW_UART1 0x081b16381638+#define PCI_DEVICE_ID_INTEL_PNW_UART2 0x081c16391639+#define PCI_DEVICE_ID_INTEL_PNW_UART3 0x081d16401640+16411641+static int pnw_serial_setup(struct serial_private *priv,16421642+ const struct pciserial_board *board,16431643+ struct uart_8250_port *port, int idx)16441644+{16451645+ struct pci_dev *pdev = priv->dev;16461646+ struct pci_dev *dma_dev;16471647+ int index;16481648+16491649+ switch (pdev->device) {16501650+ case PCI_DEVICE_ID_INTEL_PNW_UART1:16511651+ index = 0;16521652+ break;16531653+ case PCI_DEVICE_ID_INTEL_PNW_UART2:16541654+ index = 1;16551655+ break;16561656+ case PCI_DEVICE_ID_INTEL_PNW_UART3:16571657+ index = 2;16581658+ break;16591659+ default:16601660+ return -EINVAL;16611661+ }16621662+16631663+ dma_dev = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 3));16641664+16651665+ port->port.set_termios = intel_mid_set_termios_50M;16661666+16671667+ return intel_mid_serial_setup(priv, board, port, idx, index, dma_dev);16681668+}16691669+15291670static int15301671pci_omegapci_setup(struct serial_private *priv,15311672 const struct pciserial_board *board,···21291986 .subvendor = PCI_ANY_ID,21301987 .subdevice = PCI_ANY_ID,21311988 .setup = byt_serial_setup,19891989+ },19901990+ {19911991+ .vendor = PCI_VENDOR_ID_INTEL,19921992+ .device = PCI_DEVICE_ID_INTEL_PNW_UART1,19931993+ .subvendor = PCI_ANY_ID,19941994+ .subdevice = PCI_ANY_ID,19951995+ .setup = pnw_serial_setup,19961996+ },19971997+ {19981998+ .vendor = PCI_VENDOR_ID_INTEL,19991999+ .device = PCI_DEVICE_ID_INTEL_PNW_UART2,20002000+ .subvendor = PCI_ANY_ID,20012001+ .subdevice = PCI_ANY_ID,20022002+ .setup = pnw_serial_setup,20032003+ },20042004+ {20052005+ .vendor = PCI_VENDOR_ID_INTEL,20062006+ .device = PCI_DEVICE_ID_INTEL_PNW_UART3,20072007+ .subvendor = PCI_ANY_ID,20082008+ .subdevice = PCI_ANY_ID,20092009+ .setup = pnw_serial_setup,21322010 },21332011 {21342012 .vendor = PCI_VENDOR_ID_INTEL,···30282864 pbn_ADDIDATA_PCIe_8_3906250,30292865 pbn_ce4100_1_115200,30302866 pbn_byt,28672867+ pbn_pnw,30312868 pbn_qrk,30322869 pbn_omegapci,30332870 pbn_NETMOS9900_2s_115200,···37953630 .uart_offset = 0x80,37963631 .reg_shift = 2,37973632 },36333633+ [pbn_pnw] = {36343634+ .flags = FL_BASE0,36353635+ .num_ports = 1,36363636+ .base_baud = 115200,36373637+ },37983638 [pbn_qrk] = {37993639 .flags = FL_BASE0,38003640 .num_ports = 1,···41764006 pci_disable_device(dev);41774007}4178400841794179-#ifdef CONFIG_PM41804180-static int pciserial_suspend_one(struct pci_dev *dev, pm_message_t state)40094009+#ifdef CONFIG_PM_SLEEP40104010+static int pciserial_suspend_one(struct device *dev)41814011{41824182- struct serial_private *priv = pci_get_drvdata(dev);40124012+ struct pci_dev *pdev = to_pci_dev(dev);40134013+ struct serial_private *priv = pci_get_drvdata(pdev);4183401441844015 if (priv)41854016 pciserial_suspend_ports(priv);4186401741874187- pci_save_state(dev);41884188- pci_set_power_state(dev, pci_choose_state(dev, state));41894018 return 0;41904019}4191402041924192-static int pciserial_resume_one(struct pci_dev *dev)40214021+static int pciserial_resume_one(struct device *dev)41934022{40234023+ struct pci_dev *pdev = to_pci_dev(dev);40244024+ struct serial_private *priv = pci_get_drvdata(pdev);41944025 int err;41954195- struct serial_private *priv = pci_get_drvdata(dev);41964196-41974197- pci_set_power_state(dev, PCI_D0);41984198- pci_restore_state(dev);4199402642004027 if (priv) {42014028 /*42024029 * The device may have been disabled. Re-enable it.42034030 */42044204- err = pci_enable_device(dev);40314031+ err = pci_enable_device(pdev);42054032 /* FIXME: We cannot simply error out here */42064033 if (err)42074207- dev_err(&dev->dev, "Unable to re-enable ports, trying to continue.\n");40344034+ dev_err(dev, "Unable to re-enable ports, trying to continue.\n");42084035 pciserial_resume_ports(priv);42094036 }42104037 return 0;42114038}42124039#endif40404040+40414041+static SIMPLE_DEV_PM_OPS(pciserial_pm_ops, pciserial_suspend_one,40424042+ pciserial_resume_one);4213404342144044static struct pci_device_id serial_pci_tbl[] = {42154045 /* Advantech use PCI_DEVICE_ID_ADVANTECH_PCI3620 (0x3620) as 'PCI_SUBVENDOR_ID' */···55335363 pbn_byt },5534536455355365 /*53665366+ * Intel Penwell53675367+ */53685368+ { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PNW_UART1,53695369+ PCI_ANY_ID, PCI_ANY_ID, 0, 0,53705370+ pbn_pnw},53715371+ { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PNW_UART2,53725372+ PCI_ANY_ID, PCI_ANY_ID, 0, 0,53735373+ pbn_pnw},53745374+ { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PNW_UART3,53755375+ PCI_ANY_ID, PCI_ANY_ID, 0, 0,53765376+ pbn_pnw},53775377+53785378+ /*55365379 * Intel Quark x100055375380 */55385381 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_UART,···56935510 .name = "serial",56945511 .probe = pciserial_init_one,56955512 .remove = pciserial_remove_one,56965696-#ifdef CONFIG_PM56975697- .suspend = pciserial_suspend_one,56985698- .resume = pciserial_resume_one,56995699-#endif55135513+ .driver = {55145514+ .pm = &pciserial_pm_ops,55155515+ },57005516 .id_table = serial_pci_tbl,57015517 .err_handler = &serial8250_err_handler,57025518};
+3-13
drivers/tty/serial/Kconfig
···20202121config SERIAL_AMBA_PL0102222 tristate "ARM AMBA PL010 serial port support"2323- depends on ARM_AMBA && (BROKEN || !ARCH_VERSATILE)2323+ depends on ARM_AMBA2424 select SERIAL_CORE2525 help2626 This selects the ARM(R) AMBA(R) PrimeCell PL010 UART. If you have···483483 your boot loader (lilo or loadlin) about how to pass options to the484484 kernel at boot time.)485485486486-config SERIAL_MFD_HSU487487- tristate "Medfield High Speed UART support"488488- depends on PCI489489- select SERIAL_CORE490490-491491-config SERIAL_MFD_HSU_CONSOLE492492- bool "Medfile HSU serial console support"493493- depends on SERIAL_MFD_HSU=y494494- select SERIAL_CORE_CONSOLE495495-496486config SERIAL_BFIN497487 tristate "Blackfin serial port support"498488 depends on BLACKFIN···825835826836config SERIAL_PMACZILOG827837 tristate "Mac or PowerMac z85c30 ESCC support"828828- depends on (M68K && MAC) || (PPC_OF && PPC_PMAC)838838+ depends on (M68K && MAC) || PPC_PMAC829839 select SERIAL_CORE830840 help831841 This driver supports the Zilog z85C30 serial ports found on···1143115311441154config SERIAL_OF_PLATFORM_NWPSERIAL11451155 tristate "NWP serial port driver"11461146- depends on PPC_OF && PPC_DCR11561156+ depends on PPC_DCR11471157 select SERIAL_OF_PLATFORM11481158 select SERIAL_CORE_CONSOLE11491159 select SERIAL_CORE
···5858#include <linux/pinctrl/consumer.h>5959#include <linux/sizes.h>6060#include <linux/io.h>6161+#include <linux/workqueue.h>61626263#define UART_NR 146364···157156 unsigned int lcrh_tx; /* vendor-specific */158157 unsigned int lcrh_rx; /* vendor-specific */159158 unsigned int old_cr; /* state during shutdown */159159+ struct delayed_work tx_softirq_work;160160 bool autorts;161161+ unsigned int tx_irq_seen; /* 0=none, 1=1, 2=2 or more */161162 char type[12];162163#ifdef CONFIG_DMA_ENGINE163164 /* DMA stuff */···167164 bool using_rx_dma;168165 struct pl011_dmarx_data dmarx;169166 struct pl011_dmatx_data dmatx;167167+ bool dma_probed;170168#endif171169};172170···265261 }266262}267263268268-static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port *uap)264264+static void pl011_dma_probe(struct uart_amba_port *uap)269265{270266 /* DMA is the sole user of the platform data right now */271267 struct amba_pl011_data *plat = dev_get_platdata(uap->port.dev);268268+ struct device *dev = uap->port.dev;272269 struct dma_slave_config tx_conf = {273270 .dst_addr = uap->port.mapbase + UART01x_DR,274271 .dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE,···280275 struct dma_chan *chan;281276 dma_cap_mask_t mask;282277283283- chan = dma_request_slave_channel(dev, "tx");278278+ uap->dma_probed = true;279279+ chan = dma_request_slave_channel_reason(dev, "tx");280280+ if (IS_ERR(chan)) {281281+ if (PTR_ERR(chan) == -EPROBE_DEFER) {282282+ dev_info(uap->port.dev, "DMA driver not ready\n");283283+ uap->dma_probed = false;284284+ return;285285+ }284286285285- if (!chan) {286287 /* We need platform data */287288 if (!plat || !plat->dma_filter) {288289 dev_info(uap->port.dev, "no DMA platform data\n");···396385 }397386}398387399399-#ifndef MODULE400400-/*401401- * Stack up the UARTs and let the above initcall be done at device402402- * initcall time, because the serial driver is called as an arch403403- * initcall, and at this time the DMA subsystem is not yet registered.404404- * At this point the driver will switch over to using DMA where desired.405405- */406406-struct dma_uap {407407- struct list_head node;408408- struct uart_amba_port *uap;409409- struct device *dev;410410-};411411-412412-static LIST_HEAD(pl011_dma_uarts);413413-414414-static int __init pl011_dma_initcall(void)415415-{416416- struct list_head *node, *tmp;417417-418418- list_for_each_safe(node, tmp, &pl011_dma_uarts) {419419- struct dma_uap *dmau = list_entry(node, struct dma_uap, node);420420- pl011_dma_probe_initcall(dmau->dev, dmau->uap);421421- list_del(node);422422- kfree(dmau);423423- }424424- return 0;425425-}426426-427427-device_initcall(pl011_dma_initcall);428428-429429-static void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap)430430-{431431- struct dma_uap *dmau = kzalloc(sizeof(struct dma_uap), GFP_KERNEL);432432- if (dmau) {433433- dmau->uap = uap;434434- dmau->dev = dev;435435- list_add_tail(&dmau->node, &pl011_dma_uarts);436436- }437437-}438438-#else439439-static void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap)440440-{441441- pl011_dma_probe_initcall(dev, uap);442442-}443443-#endif444444-445388static void pl011_dma_remove(struct uart_amba_port *uap)446389{447447- /* TODO: remove the initcall if it has not yet executed */448390 if (uap->dmatx.chan)449391 dma_release_channel(uap->dmatx.chan);450392 if (uap->dmarx.chan)451393 dma_release_channel(uap->dmarx.chan);452394}453395454454-/* Forward declare this for the refill routine */396396+/* Forward declare these for the refill routine */455397static int pl011_dma_tx_refill(struct uart_amba_port *uap);398398+static void pl011_start_tx_pio(struct uart_amba_port *uap);456399457400/*458401 * The current DMA TX buffer has been sent.···444479 return;445480 }446481447447- if (pl011_dma_tx_refill(uap) <= 0) {482482+ if (pl011_dma_tx_refill(uap) <= 0)448483 /*449484 * We didn't queue a DMA buffer for some reason, but we450485 * have data pending to be sent. Re-enable the TX IRQ.451486 */452452- uap->im |= UART011_TXIM;453453- writew(uap->im, uap->port.membase + UART011_IMSC);454454- }487487+ pl011_start_tx_pio(uap);488488+455489 spin_unlock_irqrestore(&uap->port.lock, flags);456490}457491···628664 if (!uap->dmatx.queued) {629665 if (pl011_dma_tx_refill(uap) > 0) {630666 uap->im &= ~UART011_TXIM;631631- ret = true;632632- } else {633633- uap->im |= UART011_TXIM;667667+ writew(uap->im, uap->port.membase +668668+ UART011_IMSC);669669+ } else634670 ret = false;635635- }636636- writew(uap->im, uap->port.membase + UART011_IMSC);637671 } else if (!(uap->dmacr & UART011_TXDMAE)) {638672 uap->dmacr |= UART011_TXDMAE;639673 writew(uap->dmacr,···9831021{9841022 int ret;985102310241024+ if (!uap->dma_probed)10251025+ pl011_dma_probe(uap);10261026+9861027 if (!uap->dmatx.chan)9871028 return;9881029···1107114211081143#else11091144/* Blank functions if the DMA engine is not available */11101110-static inline void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap)11451145+static inline void pl011_dma_probe(struct uart_amba_port *uap)11111146{11121147}11131148···11731208 pl011_dma_tx_stop(uap);11741209}1175121012111211+static bool pl011_tx_chars(struct uart_amba_port *uap);12121212+12131213+/* Start TX with programmed I/O only (no DMA) */12141214+static void pl011_start_tx_pio(struct uart_amba_port *uap)12151215+{12161216+ uap->im |= UART011_TXIM;12171217+ writew(uap->im, uap->port.membase + UART011_IMSC);12181218+ if (!uap->tx_irq_seen)12191219+ pl011_tx_chars(uap);12201220+}12211221+11761222static void pl011_start_tx(struct uart_port *port)11771223{11781224 struct uart_amba_port *uap =11791225 container_of(port, struct uart_amba_port, port);1180122611811181- if (!pl011_dma_tx_start(uap)) {11821182- uap->im |= UART011_TXIM;11831183- writew(uap->im, uap->port.membase + UART011_IMSC);11841184- }12271227+ if (!pl011_dma_tx_start(uap))12281228+ pl011_start_tx_pio(uap);11851229}1186123011871231static void pl011_stop_rx(struct uart_port *port)···12481274 spin_lock(&uap->port.lock);12491275}1250127612511251-static void pl011_tx_chars(struct uart_amba_port *uap)12771277+/*12781278+ * Transmit a character12791279+ * There must be at least one free entry in the TX FIFO to accept the char.12801280+ *12811281+ * Returns true if the FIFO might have space in it afterwards;12821282+ * returns false if the FIFO definitely became full.12831283+ */12841284+static bool pl011_tx_char(struct uart_amba_port *uap, unsigned char c)12851285+{12861286+ writew(c, uap->port.membase + UART01x_DR);12871287+ uap->port.icount.tx++;12881288+12891289+ if (likely(uap->tx_irq_seen > 1))12901290+ return true;12911291+12921292+ return !(readw(uap->port.membase + UART01x_FR) & UART01x_FR_TXFF);12931293+}12941294+12951295+static bool pl011_tx_chars(struct uart_amba_port *uap)12521296{12531297 struct circ_buf *xmit = &uap->port.state->xmit;12541298 int count;1255129913001300+ if (unlikely(uap->tx_irq_seen < 2))13011301+ /*13021302+ * Initial FIFO fill level unknown: we must check TXFF13031303+ * after each write, so just try to fill up the FIFO.13041304+ */13051305+ count = uap->fifosize;13061306+ else /* tx_irq_seen >= 2 */13071307+ /*13081308+ * FIFO initially at least half-empty, so we can simply13091309+ * write half the FIFO without polling TXFF.13101310+13111311+ * Note: the *first* TX IRQ can still race with13121312+ * pl011_start_tx_pio(), which can result in the FIFO13131313+ * being fuller than expected in that case.13141314+ */13151315+ count = uap->fifosize >> 1;13161316+13171317+ /*13181318+ * If the FIFO is full we're guaranteed a TX IRQ at some later point,13191319+ * and can't transmit immediately in any case:13201320+ */13211321+ if (unlikely(uap->tx_irq_seen < 2 &&13221322+ readw(uap->port.membase + UART01x_FR) & UART01x_FR_TXFF))13231323+ return false;13241324+12561325 if (uap->port.x_char) {12571257- writew(uap->port.x_char, uap->port.membase + UART01x_DR);12581258- uap->port.icount.tx++;13261326+ pl011_tx_char(uap, uap->port.x_char);12591327 uap->port.x_char = 0;12601260- return;13281328+ --count;12611329 }12621330 if (uart_circ_empty(xmit) || uart_tx_stopped(&uap->port)) {12631331 pl011_stop_tx(&uap->port);12641264- return;13321332+ goto done;12651333 }1266133412671335 /* If we are using DMA mode, try to send some characters. */12681336 if (pl011_dma_tx_irq(uap))12691269- return;13371337+ goto done;1270133812711271- count = uap->fifosize >> 1;12721272- do {12731273- writew(xmit->buf[xmit->tail], uap->port.membase + UART01x_DR);13391339+ while (count-- > 0 && pl011_tx_char(uap, xmit->buf[xmit->tail])) {12741340 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);12751275- uap->port.icount.tx++;12761341 if (uart_circ_empty(xmit))12771342 break;12781278- } while (--count > 0);13431343+ }1279134412801345 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)12811346 uart_write_wakeup(&uap->port);1282134712831283- if (uart_circ_empty(xmit))13481348+ if (uart_circ_empty(xmit)) {12841349 pl011_stop_tx(&uap->port);13501350+ goto done;13511351+ }13521352+13531353+ if (unlikely(!uap->tx_irq_seen))13541354+ schedule_delayed_work(&uap->tx_softirq_work, uap->port.timeout);13551355+13561356+done:13571357+ return false;12851358}1286135912871360static void pl011_modem_status(struct uart_amba_port *uap)···13531332 uart_handle_cts_change(&uap->port, status & UART01x_FR_CTS);1354133313551334 wake_up_interruptible(&uap->port.state->port.delta_msr_wait);13351335+}13361336+13371337+static void pl011_tx_softirq(struct work_struct *work)13381338+{13391339+ struct delayed_work *dwork = to_delayed_work(work);13401340+ struct uart_amba_port *uap =13411341+ container_of(dwork, struct uart_amba_port, tx_softirq_work);13421342+13431343+ spin_lock(&uap->port.lock);13441344+ while (pl011_tx_chars(uap)) ;13451345+ spin_unlock(&uap->port.lock);13461346+}13471347+13481348+static void pl011_tx_irq_seen(struct uart_amba_port *uap)13491349+{13501350+ if (likely(uap->tx_irq_seen > 1))13511351+ return;13521352+13531353+ uap->tx_irq_seen++;13541354+ if (uap->tx_irq_seen < 2)13551355+ /* first TX IRQ */13561356+ cancel_delayed_work(&uap->tx_softirq_work);13561357}1357135813581359static irqreturn_t pl011_int(int irq, void *dev_id)···14151372 if (status & (UART011_DSRMIS|UART011_DCDMIS|14161373 UART011_CTSMIS|UART011_RIMIS))14171374 pl011_modem_status(uap);14181418- if (status & UART011_TXIS)13751375+ if (status & UART011_TXIS) {13761376+ pl011_tx_irq_seen(uap);14191377 pl011_tx_chars(uap);13781378+ }1420137914211380 if (pass_counter-- == 0)14221381 break;···16221577{16231578 struct uart_amba_port *uap =16241579 container_of(port, struct uart_amba_port, port);16251625- unsigned int cr, lcr_h, fbrd, ibrd;15801580+ unsigned int cr;16261581 int retval;1627158216281583 retval = pl011_hwinit(port);···1640159516411596 writew(uap->vendor->ifls, uap->port.membase + UART011_IFLS);1642159716431643- /*16441644- * Provoke TX FIFO interrupt into asserting. Taking care to preserve16451645- * baud rate and data format specified by FBRD, IBRD and LCRH as the16461646- * UART may already be in use as a console.16471647- */16481598 spin_lock_irq(&uap->port.lock);16491649-16501650- fbrd = readw(uap->port.membase + UART011_FBRD);16511651- ibrd = readw(uap->port.membase + UART011_IBRD);16521652- lcr_h = readw(uap->port.membase + uap->lcrh_rx);16531653-16541654- cr = UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_LBE;16551655- writew(cr, uap->port.membase + UART011_CR);16561656- writew(0, uap->port.membase + UART011_FBRD);16571657- writew(1, uap->port.membase + UART011_IBRD);16581658- pl011_write_lcr_h(uap, 0);16591659- writew(0, uap->port.membase + UART01x_DR);16601660- while (readw(uap->port.membase + UART01x_FR) & UART01x_FR_BUSY)16611661- barrier();16621662-16631663- writew(fbrd, uap->port.membase + UART011_FBRD);16641664- writew(ibrd, uap->port.membase + UART011_IBRD);16651665- pl011_write_lcr_h(uap, lcr_h);1666159916671600 /* restore RTS and DTR */16681601 cr = uap->old_cr & (UART011_CR_RTS | UART011_CR_DTR);···16951672 container_of(port, struct uart_amba_port, port);16961673 unsigned int cr;1697167416751675+ cancel_delayed_work_sync(&uap->tx_softirq_work);16761676+16981677 /*16991678 * disable all interrupts17001679 */17011680 spin_lock_irq(&uap->port.lock);17021681 uap->im = 0;17031682 writew(uap->im, uap->port.membase + UART011_IMSC);17041704- writew(0xffff, uap->port.membase + UART011_ICR);16831683+ writew(0xffff & ~UART011_TXIS, uap->port.membase + UART011_ICR);17051684 spin_unlock_irq(&uap->port.lock);1706168517071686 pl011_dma_shutdown(uap);···22432218 uap->port.ops = &amba_pl011_pops;22442219 uap->port.flags = UPF_BOOT_AUTOCONF;22452220 uap->port.line = i;22462246- pl011_dma_probe(&dev->dev, uap);22212221+ INIT_DELAYED_WORK(&uap->tx_softirq_work, pl011_tx_softirq);2247222222482223 /* Ensure interrupts from this UART are masked and cleared */22492224 writew(0, uap->port.membase + UART011_IMSC);···22582233 if (!amba_reg.state) {22592234 ret = uart_register_driver(&amba_reg);22602235 if (ret < 0) {22612261- pr_err("Failed to register AMBA-PL011 driver\n");22362236+ dev_err(&dev->dev,22372237+ "Failed to register AMBA-PL011 driver\n");22622238 return ret;22632239 }22642240 }···22682242 if (ret) {22692243 amba_ports[i] = NULL;22702244 uart_unregister_driver(&amba_reg);22712271- pl011_dma_remove(uap);22722245 }2273224622742247 return ret;
+1-1
drivers/tty/serial/ar933x_uart.c
···649649 id = 0;650650 }651651652652- if (id > CONFIG_SERIAL_AR933X_NR_UARTS)652652+ if (id >= CONFIG_SERIAL_AR933X_NR_UARTS)653653 return -EINVAL;654654655655 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+17-12
drivers/tty/serial/atmel_serial.c
···855855 spin_lock_init(&atmel_port->lock_tx);856856 sg_init_table(&atmel_port->sg_tx, 1);857857 /* UART circular tx buffer is an aligned page. */858858- BUG_ON((int)port->state->xmit.buf & ~PAGE_MASK);858858+ BUG_ON(!PAGE_ALIGNED(port->state->xmit.buf));859859 sg_set_page(&atmel_port->sg_tx,860860 virt_to_page(port->state->xmit.buf),861861 UART_XMIT_SIZE,···10341034 spin_lock_init(&atmel_port->lock_rx);10351035 sg_init_table(&atmel_port->sg_rx, 1);10361036 /* UART circular rx buffer is an aligned page. */10371037- BUG_ON((int)port->state->xmit.buf & ~PAGE_MASK);10371037+ BUG_ON(!PAGE_ALIGNED(ring->buf));10381038 sg_set_page(&atmel_port->sg_rx,10391039 virt_to_page(ring->buf),10401040- ATMEL_SERIAL_RINGSIZE,10401040+ sizeof(struct atmel_uart_char) * ATMEL_SERIAL_RINGSIZE,10411041 (int)ring->buf & ~PAGE_MASK);10421042 nent = dma_map_sg(port->dev,10431043 &atmel_port->sg_rx,···15541554 spin_unlock(&port->lock);15551555}1556155615571557-static int atmel_init_property(struct atmel_uart_port *atmel_port,15571557+static void atmel_init_property(struct atmel_uart_port *atmel_port,15581558 struct platform_device *pdev)15591559{15601560 struct device_node *np = pdev->dev.of_node;···15951595 atmel_port->use_dma_tx = false;15961596 }1597159715981598- return 0;15991598}1600159916011600static void atmel_init_rs485(struct uart_port *port,···17761777 if (retval)17771778 goto free_irq;1778177917801780+ tasklet_enable(&atmel_port->tasklet);17811781+17791782 /*17801783 * Initialize DMA (if necessary)17811784 */17821785 atmel_init_property(atmel_port, pdev);17861786+ atmel_set_ops(port);1783178717841788 if (atmel_port->prepare_rx) {17851789 retval = atmel_port->prepare_rx(port);···18811879 * Clear out any scheduled tasklets before18821880 * we destroy the buffers18831881 */18821882+ tasklet_disable(&atmel_port->tasklet);18841883 tasklet_kill(&atmel_port->tasklet);1885188418861885 /*···22592256 struct uart_port *port = &atmel_port->uart;22602257 struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev);2261225822622262- if (!atmel_init_property(atmel_port, pdev))22632263- atmel_set_ops(port);22592259+ atmel_init_property(atmel_port, pdev);22602260+ atmel_set_ops(port);2264226122652262 atmel_init_rs485(port, pdev);22662263···2275227222762273 tasklet_init(&atmel_port->tasklet, atmel_tasklet_func,22772274 (unsigned long)port);22752275+ tasklet_disable(&atmel_port->tasklet);2278227622792277 memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));22802278···25852581 struct gpio_desc *gpiod;2586258225872583 p->gpios = mctrl_gpio_init(dev, 0);25882588- if (IS_ERR_OR_NULL(p->gpios))25892589- return -1;25842584+ if (IS_ERR(p->gpios))25852585+ return PTR_ERR(p->gpios);2590258625912587 for (i = 0; i < UART_GPIO_MAX; i++) {25922588 gpiod = mctrl_gpio_to_gpiod(p->gpios, i);···26392635 spin_lock_init(&port->lock_suspended);2640263626412637 ret = atmel_init_gpios(port, &pdev->dev);26422642- if (ret < 0)26432643- dev_err(&pdev->dev, "%s",26442644- "Failed to initialize GPIOs. The serial port may not work as expected");26382638+ if (ret < 0) {26392639+ dev_err(&pdev->dev, "Failed to initialize GPIOs.");26402640+ goto err;26412641+ }2645264226462643 ret = atmel_init_port(port, pdev);26472644 if (ret)
+2-2
drivers/tty/serial/bcm63xx_uart.c
···854854855855 ret = uart_add_one_port(&bcm_uart_driver, port);856856 if (ret) {857857- ports[pdev->id].membase = 0;857857+ ports[pdev->id].membase = NULL;858858 return ret;859859 }860860 platform_set_drvdata(pdev, port);···868868 port = platform_get_drvdata(pdev);869869 uart_remove_one_port(&bcm_uart_driver, port);870870 /* mark port as free */871871- ports[pdev->id].membase = 0;871871+ ports[pdev->id].membase = NULL;872872 return 0;873873}874874
+2
drivers/tty/serial/clps711x.c
···501501 platform_set_drvdata(pdev, s);502502503503 s->gpios = mctrl_gpio_init(&pdev->dev, 0);504504+ if (IS_ERR(s->gpios))505505+ return PTR_ERR(s->gpios);504506505507 ret = uart_add_one_port(&clps711x_uart, &s->port);506508 if (ret)
···11-/*22- * mfd.c: driver for High Speed UART device of Intel Medfield platform33- *44- * Refer pxa.c, 8250.c and some other drivers in drivers/serial/55- *66- * (C) Copyright 2010 Intel Corporation77- *88- * This program is free software; you can redistribute it and/or99- * modify it under the terms of the GNU General Public License1010- * as published by the Free Software Foundation; version 21111- * of the License.1212- */1313-1414-/* Notes:1515- * 1. DMA channel allocation: 0/1 channel are assigned to port 0,1616- * 2/3 chan to port 1, 4/5 chan to port 3. Even number chans1717- * are used for RX, odd chans for TX1818- *1919- * 2. The RI/DSR/DCD/DTR are not pinned out, DCD & DSR are always2020- * asserted, only when the HW is reset the DDCD and DDSR will2121- * be triggered2222- */2323-2424-#if defined(CONFIG_SERIAL_MFD_HSU_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)2525-#define SUPPORT_SYSRQ2626-#endif2727-2828-#include <linux/module.h>2929-#include <linux/init.h>3030-#include <linux/console.h>3131-#include <linux/sysrq.h>3232-#include <linux/slab.h>3333-#include <linux/serial_reg.h>3434-#include <linux/circ_buf.h>3535-#include <linux/delay.h>3636-#include <linux/interrupt.h>3737-#include <linux/tty.h>3838-#include <linux/tty_flip.h>3939-#include <linux/serial_core.h>4040-#include <linux/serial_mfd.h>4141-#include <linux/dma-mapping.h>4242-#include <linux/pci.h>4343-#include <linux/nmi.h>4444-#include <linux/io.h>4545-#include <linux/debugfs.h>4646-#include <linux/pm_runtime.h>4747-4848-#define HSU_DMA_BUF_SIZE 20484949-5050-#define chan_readl(chan, offset) readl(chan->reg + offset)5151-#define chan_writel(chan, offset, val) writel(val, chan->reg + offset)5252-5353-#define mfd_readl(obj, offset) readl(obj->reg + offset)5454-#define mfd_writel(obj, offset, val) writel(val, obj->reg + offset)5555-5656-static int hsu_dma_enable;5757-module_param(hsu_dma_enable, int, 0);5858-MODULE_PARM_DESC(hsu_dma_enable,5959- "It is a bitmap to set working mode, if bit[x] is 1, then port[x] will work in DMA mode, otherwise in PIO mode.");6060-6161-struct hsu_dma_buffer {6262- u8 *buf;6363- dma_addr_t dma_addr;6464- u32 dma_size;6565- u32 ofs;6666-};6767-6868-struct hsu_dma_chan {6969- u32 id;7070- enum dma_data_direction dirt;7171- struct uart_hsu_port *uport;7272- void __iomem *reg;7373-};7474-7575-struct uart_hsu_port {7676- struct uart_port port;7777- unsigned char ier;7878- unsigned char lcr;7979- unsigned char mcr;8080- unsigned int lsr_break_flag;8181- char name[12];8282- int index;8383- struct device *dev;8484-8585- struct hsu_dma_chan *txc;8686- struct hsu_dma_chan *rxc;8787- struct hsu_dma_buffer txbuf;8888- struct hsu_dma_buffer rxbuf;8989- int use_dma; /* flag for DMA/PIO */9090- int running;9191- int dma_tx_on;9292-};9393-9494-/* Top level data structure of HSU */9595-struct hsu_port {9696- void __iomem *reg;9797- unsigned long paddr;9898- unsigned long iolen;9999- u32 irq;100100-101101- struct uart_hsu_port port[3];102102- struct hsu_dma_chan chans[10];103103-104104- struct dentry *debugfs;105105-};106106-107107-static inline unsigned int serial_in(struct uart_hsu_port *up, int offset)108108-{109109- unsigned int val;110110-111111- if (offset > UART_MSR) {112112- offset <<= 2;113113- val = readl(up->port.membase + offset);114114- } else115115- val = (unsigned int)readb(up->port.membase + offset);116116-117117- return val;118118-}119119-120120-static inline void serial_out(struct uart_hsu_port *up, int offset, int value)121121-{122122- if (offset > UART_MSR) {123123- offset <<= 2;124124- writel(value, up->port.membase + offset);125125- } else {126126- unsigned char val = value & 0xff;127127- writeb(val, up->port.membase + offset);128128- }129129-}130130-131131-#ifdef CONFIG_DEBUG_FS132132-133133-#define HSU_REGS_BUFSIZE 1024134134-135135-136136-static ssize_t port_show_regs(struct file *file, char __user *user_buf,137137- size_t count, loff_t *ppos)138138-{139139- struct uart_hsu_port *up = file->private_data;140140- char *buf;141141- u32 len = 0;142142- ssize_t ret;143143-144144- buf = kzalloc(HSU_REGS_BUFSIZE, GFP_KERNEL);145145- if (!buf)146146- return 0;147147-148148- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,149149- "MFD HSU port[%d] regs:\n", up->index);150150-151151- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,152152- "=================================\n");153153- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,154154- "IER: \t\t0x%08x\n", serial_in(up, UART_IER));155155- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,156156- "IIR: \t\t0x%08x\n", serial_in(up, UART_IIR));157157- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,158158- "LCR: \t\t0x%08x\n", serial_in(up, UART_LCR));159159- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,160160- "MCR: \t\t0x%08x\n", serial_in(up, UART_MCR));161161- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,162162- "LSR: \t\t0x%08x\n", serial_in(up, UART_LSR));163163- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,164164- "MSR: \t\t0x%08x\n", serial_in(up, UART_MSR));165165- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,166166- "FOR: \t\t0x%08x\n", serial_in(up, UART_FOR));167167- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,168168- "PS: \t\t0x%08x\n", serial_in(up, UART_PS));169169- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,170170- "MUL: \t\t0x%08x\n", serial_in(up, UART_MUL));171171- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,172172- "DIV: \t\t0x%08x\n", serial_in(up, UART_DIV));173173-174174- if (len > HSU_REGS_BUFSIZE)175175- len = HSU_REGS_BUFSIZE;176176-177177- ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);178178- kfree(buf);179179- return ret;180180-}181181-182182-static ssize_t dma_show_regs(struct file *file, char __user *user_buf,183183- size_t count, loff_t *ppos)184184-{185185- struct hsu_dma_chan *chan = file->private_data;186186- char *buf;187187- u32 len = 0;188188- ssize_t ret;189189-190190- buf = kzalloc(HSU_REGS_BUFSIZE, GFP_KERNEL);191191- if (!buf)192192- return 0;193193-194194- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,195195- "MFD HSU DMA channel [%d] regs:\n", chan->id);196196-197197- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,198198- "=================================\n");199199- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,200200- "CR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_CR));201201- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,202202- "DCR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_DCR));203203- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,204204- "BSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_BSR));205205- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,206206- "MOTSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_MOTSR));207207- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,208208- "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D0SAR));209209- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,210210- "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D0TSR));211211- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,212212- "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D1SAR));213213- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,214214- "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D1TSR));215215- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,216216- "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D2SAR));217217- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,218218- "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D2TSR));219219- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,220220- "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3SAR));221221- len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,222222- "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3TSR));223223-224224- if (len > HSU_REGS_BUFSIZE)225225- len = HSU_REGS_BUFSIZE;226226-227227- ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);228228- kfree(buf);229229- return ret;230230-}231231-232232-static const struct file_operations port_regs_ops = {233233- .owner = THIS_MODULE,234234- .open = simple_open,235235- .read = port_show_regs,236236- .llseek = default_llseek,237237-};238238-239239-static const struct file_operations dma_regs_ops = {240240- .owner = THIS_MODULE,241241- .open = simple_open,242242- .read = dma_show_regs,243243- .llseek = default_llseek,244244-};245245-246246-static int hsu_debugfs_init(struct hsu_port *hsu)247247-{248248- int i;249249- char name[32];250250-251251- hsu->debugfs = debugfs_create_dir("hsu", NULL);252252- if (!hsu->debugfs)253253- return -ENOMEM;254254-255255- for (i = 0; i < 3; i++) {256256- snprintf(name, sizeof(name), "port_%d_regs", i);257257- debugfs_create_file(name, S_IFREG | S_IRUGO,258258- hsu->debugfs, (void *)(&hsu->port[i]), &port_regs_ops);259259- }260260-261261- for (i = 0; i < 6; i++) {262262- snprintf(name, sizeof(name), "dma_chan_%d_regs", i);263263- debugfs_create_file(name, S_IFREG | S_IRUGO,264264- hsu->debugfs, (void *)&hsu->chans[i], &dma_regs_ops);265265- }266266-267267- return 0;268268-}269269-270270-static void hsu_debugfs_remove(struct hsu_port *hsu)271271-{272272- if (hsu->debugfs)273273- debugfs_remove_recursive(hsu->debugfs);274274-}275275-276276-#else277277-static inline int hsu_debugfs_init(struct hsu_port *hsu)278278-{279279- return 0;280280-}281281-282282-static inline void hsu_debugfs_remove(struct hsu_port *hsu)283283-{284284-}285285-#endif /* CONFIG_DEBUG_FS */286286-287287-static void serial_hsu_enable_ms(struct uart_port *port)288288-{289289- struct uart_hsu_port *up =290290- container_of(port, struct uart_hsu_port, port);291291-292292- up->ier |= UART_IER_MSI;293293- serial_out(up, UART_IER, up->ier);294294-}295295-296296-static void hsu_dma_tx(struct uart_hsu_port *up)297297-{298298- struct circ_buf *xmit = &up->port.state->xmit;299299- struct hsu_dma_buffer *dbuf = &up->txbuf;300300- int count;301301-302302- /* test_and_set_bit may be better, but anyway it's in lock protected mode */303303- if (up->dma_tx_on)304304- return;305305-306306- /* Update the circ buf info */307307- xmit->tail += dbuf->ofs;308308- xmit->tail &= UART_XMIT_SIZE - 1;309309-310310- up->port.icount.tx += dbuf->ofs;311311- dbuf->ofs = 0;312312-313313- /* Disable the channel */314314- chan_writel(up->txc, HSU_CH_CR, 0x0);315315-316316- if (!uart_circ_empty(xmit) && !uart_tx_stopped(&up->port)) {317317- dma_sync_single_for_device(up->port.dev,318318- dbuf->dma_addr,319319- dbuf->dma_size,320320- DMA_TO_DEVICE);321321-322322- count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);323323- dbuf->ofs = count;324324-325325- /* Reprogram the channel */326326- chan_writel(up->txc, HSU_CH_D0SAR, dbuf->dma_addr + xmit->tail);327327- chan_writel(up->txc, HSU_CH_D0TSR, count);328328-329329- /* Reenable the channel */330330- chan_writel(up->txc, HSU_CH_DCR, 0x1331331- | (0x1 << 8)332332- | (0x1 << 16)333333- | (0x1 << 24));334334- up->dma_tx_on = 1;335335- chan_writel(up->txc, HSU_CH_CR, 0x1);336336- }337337-338338- if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)339339- uart_write_wakeup(&up->port);340340-}341341-342342-/* The buffer is already cache coherent */343343-static void hsu_dma_start_rx_chan(struct hsu_dma_chan *rxc,344344- struct hsu_dma_buffer *dbuf)345345-{346346- dbuf->ofs = 0;347347-348348- chan_writel(rxc, HSU_CH_BSR, 32);349349- chan_writel(rxc, HSU_CH_MOTSR, 4);350350-351351- chan_writel(rxc, HSU_CH_D0SAR, dbuf->dma_addr);352352- chan_writel(rxc, HSU_CH_D0TSR, dbuf->dma_size);353353- chan_writel(rxc, HSU_CH_DCR, 0x1 | (0x1 << 8)354354- | (0x1 << 16)355355- | (0x1 << 24) /* timeout bit, see HSU Errata 1 */356356- );357357- chan_writel(rxc, HSU_CH_CR, 0x3);358358-}359359-360360-/* Protected by spin_lock_irqsave(port->lock) */361361-static void serial_hsu_start_tx(struct uart_port *port)362362-{363363- struct uart_hsu_port *up =364364- container_of(port, struct uart_hsu_port, port);365365-366366- if (up->use_dma) {367367- hsu_dma_tx(up);368368- } else if (!(up->ier & UART_IER_THRI)) {369369- up->ier |= UART_IER_THRI;370370- serial_out(up, UART_IER, up->ier);371371- }372372-}373373-374374-static void serial_hsu_stop_tx(struct uart_port *port)375375-{376376- struct uart_hsu_port *up =377377- container_of(port, struct uart_hsu_port, port);378378- struct hsu_dma_chan *txc = up->txc;379379-380380- if (up->use_dma)381381- chan_writel(txc, HSU_CH_CR, 0x0);382382- else if (up->ier & UART_IER_THRI) {383383- up->ier &= ~UART_IER_THRI;384384- serial_out(up, UART_IER, up->ier);385385- }386386-}387387-388388-/* This is always called in spinlock protected mode, so389389- * modify timeout timer is safe here */390390-static void hsu_dma_rx(struct uart_hsu_port *up, u32 int_sts,391391- unsigned long *flags)392392-{393393- struct hsu_dma_buffer *dbuf = &up->rxbuf;394394- struct hsu_dma_chan *chan = up->rxc;395395- struct uart_port *port = &up->port;396396- struct tty_port *tport = &port->state->port;397397- int count;398398-399399- /*400400- * First need to know how many is already transferred,401401- * then check if its a timeout DMA irq, and return402402- * the trail bytes out, push them up and reenable the403403- * channel404404- */405405-406406- /* Timeout IRQ, need wait some time, see Errata 2 */407407- if (int_sts & 0xf00)408408- udelay(2);409409-410410- /* Stop the channel */411411- chan_writel(chan, HSU_CH_CR, 0x0);412412-413413- count = chan_readl(chan, HSU_CH_D0SAR) - dbuf->dma_addr;414414- if (!count) {415415- /* Restart the channel before we leave */416416- chan_writel(chan, HSU_CH_CR, 0x3);417417- return;418418- }419419-420420- dma_sync_single_for_cpu(port->dev, dbuf->dma_addr,421421- dbuf->dma_size, DMA_FROM_DEVICE);422422-423423- /*424424- * Head will only wrap around when we recycle425425- * the DMA buffer, and when that happens, we426426- * explicitly set tail to 0. So head will427427- * always be greater than tail.428428- */429429- tty_insert_flip_string(tport, dbuf->buf, count);430430- port->icount.rx += count;431431-432432- dma_sync_single_for_device(up->port.dev, dbuf->dma_addr,433433- dbuf->dma_size, DMA_FROM_DEVICE);434434-435435- /* Reprogram the channel */436436- chan_writel(chan, HSU_CH_D0SAR, dbuf->dma_addr);437437- chan_writel(chan, HSU_CH_D0TSR, dbuf->dma_size);438438- chan_writel(chan, HSU_CH_DCR, 0x1439439- | (0x1 << 8)440440- | (0x1 << 16)441441- | (0x1 << 24) /* timeout bit, see HSU Errata 1 */442442- );443443- spin_unlock_irqrestore(&up->port.lock, *flags);444444- tty_flip_buffer_push(tport);445445- spin_lock_irqsave(&up->port.lock, *flags);446446-447447- chan_writel(chan, HSU_CH_CR, 0x3);448448-449449-}450450-451451-static void serial_hsu_stop_rx(struct uart_port *port)452452-{453453- struct uart_hsu_port *up =454454- container_of(port, struct uart_hsu_port, port);455455- struct hsu_dma_chan *chan = up->rxc;456456-457457- if (up->use_dma)458458- chan_writel(chan, HSU_CH_CR, 0x2);459459- else {460460- up->ier &= ~UART_IER_RLSI;461461- up->port.read_status_mask &= ~UART_LSR_DR;462462- serial_out(up, UART_IER, up->ier);463463- }464464-}465465-466466-static inline void receive_chars(struct uart_hsu_port *up, int *status,467467- unsigned long *flags)468468-{469469- unsigned int ch, flag;470470- unsigned int max_count = 256;471471-472472- do {473473- ch = serial_in(up, UART_RX);474474- flag = TTY_NORMAL;475475- up->port.icount.rx++;476476-477477- if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |478478- UART_LSR_FE | UART_LSR_OE))) {479479-480480- dev_warn(up->dev, "We really rush into ERR/BI case"481481- "status = 0x%02x", *status);482482- /* For statistics only */483483- if (*status & UART_LSR_BI) {484484- *status &= ~(UART_LSR_FE | UART_LSR_PE);485485- up->port.icount.brk++;486486- /*487487- * We do the SysRQ and SAK checking488488- * here because otherwise the break489489- * may get masked by ignore_status_mask490490- * or read_status_mask.491491- */492492- if (uart_handle_break(&up->port))493493- goto ignore_char;494494- } else if (*status & UART_LSR_PE)495495- up->port.icount.parity++;496496- else if (*status & UART_LSR_FE)497497- up->port.icount.frame++;498498- if (*status & UART_LSR_OE)499499- up->port.icount.overrun++;500500-501501- /* Mask off conditions which should be ignored. */502502- *status &= up->port.read_status_mask;503503-504504-#ifdef CONFIG_SERIAL_MFD_HSU_CONSOLE505505- if (up->port.cons &&506506- up->port.cons->index == up->port.line) {507507- /* Recover the break flag from console xmit */508508- *status |= up->lsr_break_flag;509509- up->lsr_break_flag = 0;510510- }511511-#endif512512- if (*status & UART_LSR_BI) {513513- flag = TTY_BREAK;514514- } else if (*status & UART_LSR_PE)515515- flag = TTY_PARITY;516516- else if (*status & UART_LSR_FE)517517- flag = TTY_FRAME;518518- }519519-520520- if (uart_handle_sysrq_char(&up->port, ch))521521- goto ignore_char;522522-523523- uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag);524524- ignore_char:525525- *status = serial_in(up, UART_LSR);526526- } while ((*status & UART_LSR_DR) && max_count--);527527-528528- spin_unlock_irqrestore(&up->port.lock, *flags);529529- tty_flip_buffer_push(&up->port.state->port);530530- spin_lock_irqsave(&up->port.lock, *flags);531531-}532532-533533-static void transmit_chars(struct uart_hsu_port *up)534534-{535535- struct circ_buf *xmit = &up->port.state->xmit;536536- int count;537537-538538- if (up->port.x_char) {539539- serial_out(up, UART_TX, up->port.x_char);540540- up->port.icount.tx++;541541- up->port.x_char = 0;542542- return;543543- }544544- if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {545545- serial_hsu_stop_tx(&up->port);546546- return;547547- }548548-549549- /* The IRQ is for TX FIFO half-empty */550550- count = up->port.fifosize / 2;551551-552552- do {553553- serial_out(up, UART_TX, xmit->buf[xmit->tail]);554554- xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);555555-556556- up->port.icount.tx++;557557- if (uart_circ_empty(xmit))558558- break;559559- } while (--count > 0);560560-561561- if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)562562- uart_write_wakeup(&up->port);563563-564564- if (uart_circ_empty(xmit))565565- serial_hsu_stop_tx(&up->port);566566-}567567-568568-static inline void check_modem_status(struct uart_hsu_port *up)569569-{570570- int status;571571-572572- status = serial_in(up, UART_MSR);573573-574574- if ((status & UART_MSR_ANY_DELTA) == 0)575575- return;576576-577577- if (status & UART_MSR_TERI)578578- up->port.icount.rng++;579579- if (status & UART_MSR_DDSR)580580- up->port.icount.dsr++;581581- /* We may only get DDCD when HW init and reset */582582- if (status & UART_MSR_DDCD)583583- uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);584584- /* Will start/stop_tx accordingly */585585- if (status & UART_MSR_DCTS)586586- uart_handle_cts_change(&up->port, status & UART_MSR_CTS);587587-588588- wake_up_interruptible(&up->port.state->port.delta_msr_wait);589589-}590590-591591-/*592592- * This handles the interrupt from one port.593593- */594594-static irqreturn_t port_irq(int irq, void *dev_id)595595-{596596- struct uart_hsu_port *up = dev_id;597597- unsigned int iir, lsr;598598- unsigned long flags;599599-600600- if (unlikely(!up->running))601601- return IRQ_NONE;602602-603603- spin_lock_irqsave(&up->port.lock, flags);604604- if (up->use_dma) {605605- lsr = serial_in(up, UART_LSR);606606- if (unlikely(lsr & (UART_LSR_BI | UART_LSR_PE |607607- UART_LSR_FE | UART_LSR_OE)))608608- dev_warn(up->dev,609609- "Got lsr irq while using DMA, lsr = 0x%2x\n",610610- lsr);611611- check_modem_status(up);612612- spin_unlock_irqrestore(&up->port.lock, flags);613613- return IRQ_HANDLED;614614- }615615-616616- iir = serial_in(up, UART_IIR);617617- if (iir & UART_IIR_NO_INT) {618618- spin_unlock_irqrestore(&up->port.lock, flags);619619- return IRQ_NONE;620620- }621621-622622- lsr = serial_in(up, UART_LSR);623623- if (lsr & UART_LSR_DR)624624- receive_chars(up, &lsr, &flags);625625- check_modem_status(up);626626-627627- /* lsr will be renewed during the receive_chars */628628- if (lsr & UART_LSR_THRE)629629- transmit_chars(up);630630-631631- spin_unlock_irqrestore(&up->port.lock, flags);632632- return IRQ_HANDLED;633633-}634634-635635-static inline void dma_chan_irq(struct hsu_dma_chan *chan)636636-{637637- struct uart_hsu_port *up = chan->uport;638638- unsigned long flags;639639- u32 int_sts;640640-641641- spin_lock_irqsave(&up->port.lock, flags);642642-643643- if (!up->use_dma || !up->running)644644- goto exit;645645-646646- /*647647- * No matter what situation, need read clear the IRQ status648648- * There is a bug, see Errata 5, HSD 2900918649649- */650650- int_sts = chan_readl(chan, HSU_CH_SR);651651-652652- /* Rx channel */653653- if (chan->dirt == DMA_FROM_DEVICE)654654- hsu_dma_rx(up, int_sts, &flags);655655-656656- /* Tx channel */657657- if (chan->dirt == DMA_TO_DEVICE) {658658- chan_writel(chan, HSU_CH_CR, 0x0);659659- up->dma_tx_on = 0;660660- hsu_dma_tx(up);661661- }662662-663663-exit:664664- spin_unlock_irqrestore(&up->port.lock, flags);665665- return;666666-}667667-668668-static irqreturn_t dma_irq(int irq, void *dev_id)669669-{670670- struct hsu_port *hsu = dev_id;671671- u32 int_sts, i;672672-673673- int_sts = mfd_readl(hsu, HSU_GBL_DMAISR);674674-675675- /* Currently we only have 6 channels may be used */676676- for (i = 0; i < 6; i++) {677677- if (int_sts & 0x1)678678- dma_chan_irq(&hsu->chans[i]);679679- int_sts >>= 1;680680- }681681-682682- return IRQ_HANDLED;683683-}684684-685685-static unsigned int serial_hsu_tx_empty(struct uart_port *port)686686-{687687- struct uart_hsu_port *up =688688- container_of(port, struct uart_hsu_port, port);689689- unsigned long flags;690690- unsigned int ret;691691-692692- spin_lock_irqsave(&up->port.lock, flags);693693- ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;694694- spin_unlock_irqrestore(&up->port.lock, flags);695695-696696- return ret;697697-}698698-699699-static unsigned int serial_hsu_get_mctrl(struct uart_port *port)700700-{701701- struct uart_hsu_port *up =702702- container_of(port, struct uart_hsu_port, port);703703- unsigned char status;704704- unsigned int ret;705705-706706- status = serial_in(up, UART_MSR);707707-708708- ret = 0;709709- if (status & UART_MSR_DCD)710710- ret |= TIOCM_CAR;711711- if (status & UART_MSR_RI)712712- ret |= TIOCM_RNG;713713- if (status & UART_MSR_DSR)714714- ret |= TIOCM_DSR;715715- if (status & UART_MSR_CTS)716716- ret |= TIOCM_CTS;717717- return ret;718718-}719719-720720-static void serial_hsu_set_mctrl(struct uart_port *port, unsigned int mctrl)721721-{722722- struct uart_hsu_port *up =723723- container_of(port, struct uart_hsu_port, port);724724- unsigned char mcr = 0;725725-726726- if (mctrl & TIOCM_RTS)727727- mcr |= UART_MCR_RTS;728728- if (mctrl & TIOCM_DTR)729729- mcr |= UART_MCR_DTR;730730- if (mctrl & TIOCM_OUT1)731731- mcr |= UART_MCR_OUT1;732732- if (mctrl & TIOCM_OUT2)733733- mcr |= UART_MCR_OUT2;734734- if (mctrl & TIOCM_LOOP)735735- mcr |= UART_MCR_LOOP;736736-737737- mcr |= up->mcr;738738-739739- serial_out(up, UART_MCR, mcr);740740-}741741-742742-static void serial_hsu_break_ctl(struct uart_port *port, int break_state)743743-{744744- struct uart_hsu_port *up =745745- container_of(port, struct uart_hsu_port, port);746746- unsigned long flags;747747-748748- spin_lock_irqsave(&up->port.lock, flags);749749- if (break_state == -1)750750- up->lcr |= UART_LCR_SBC;751751- else752752- up->lcr &= ~UART_LCR_SBC;753753- serial_out(up, UART_LCR, up->lcr);754754- spin_unlock_irqrestore(&up->port.lock, flags);755755-}756756-757757-/*758758- * What special to do:759759- * 1. chose the 64B fifo mode760760- * 2. start dma or pio depends on configuration761761- * 3. we only allocate dma memory when needed762762- */763763-static int serial_hsu_startup(struct uart_port *port)764764-{765765- struct uart_hsu_port *up =766766- container_of(port, struct uart_hsu_port, port);767767- unsigned long flags;768768-769769- pm_runtime_get_sync(up->dev);770770-771771- /*772772- * Clear the FIFO buffers and disable them.773773- * (they will be reenabled in set_termios())774774- */775775- serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);776776- serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |777777- UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);778778- serial_out(up, UART_FCR, 0);779779-780780- /* Clear the interrupt registers. */781781- (void) serial_in(up, UART_LSR);782782- (void) serial_in(up, UART_RX);783783- (void) serial_in(up, UART_IIR);784784- (void) serial_in(up, UART_MSR);785785-786786- /* Now, initialize the UART, default is 8n1 */787787- serial_out(up, UART_LCR, UART_LCR_WLEN8);788788-789789- spin_lock_irqsave(&up->port.lock, flags);790790-791791- up->port.mctrl |= TIOCM_OUT2;792792- serial_hsu_set_mctrl(&up->port, up->port.mctrl);793793-794794- /*795795- * Finally, enable interrupts. Note: Modem status interrupts796796- * are set via set_termios(), which will be occurring imminently797797- * anyway, so we don't enable them here.798798- */799799- if (!up->use_dma)800800- up->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE;801801- else802802- up->ier = 0;803803- serial_out(up, UART_IER, up->ier);804804-805805- spin_unlock_irqrestore(&up->port.lock, flags);806806-807807- /* DMA init */808808- if (up->use_dma) {809809- struct hsu_dma_buffer *dbuf;810810- struct circ_buf *xmit = &port->state->xmit;811811-812812- up->dma_tx_on = 0;813813-814814- /* First allocate the RX buffer */815815- dbuf = &up->rxbuf;816816- dbuf->buf = kzalloc(HSU_DMA_BUF_SIZE, GFP_KERNEL);817817- if (!dbuf->buf) {818818- up->use_dma = 0;819819- goto exit;820820- }821821- dbuf->dma_addr = dma_map_single(port->dev,822822- dbuf->buf,823823- HSU_DMA_BUF_SIZE,824824- DMA_FROM_DEVICE);825825- dbuf->dma_size = HSU_DMA_BUF_SIZE;826826-827827- /* Start the RX channel right now */828828- hsu_dma_start_rx_chan(up->rxc, dbuf);829829-830830- /* Next init the TX DMA */831831- dbuf = &up->txbuf;832832- dbuf->buf = xmit->buf;833833- dbuf->dma_addr = dma_map_single(port->dev,834834- dbuf->buf,835835- UART_XMIT_SIZE,836836- DMA_TO_DEVICE);837837- dbuf->dma_size = UART_XMIT_SIZE;838838-839839- /* This should not be changed all around */840840- chan_writel(up->txc, HSU_CH_BSR, 32);841841- chan_writel(up->txc, HSU_CH_MOTSR, 4);842842- dbuf->ofs = 0;843843- }844844-845845-exit:846846- /* And clear the interrupt registers again for luck. */847847- (void) serial_in(up, UART_LSR);848848- (void) serial_in(up, UART_RX);849849- (void) serial_in(up, UART_IIR);850850- (void) serial_in(up, UART_MSR);851851-852852- up->running = 1;853853- return 0;854854-}855855-856856-static void serial_hsu_shutdown(struct uart_port *port)857857-{858858- struct uart_hsu_port *up =859859- container_of(port, struct uart_hsu_port, port);860860- unsigned long flags;861861-862862- /* Disable interrupts from this port */863863- up->ier = 0;864864- serial_out(up, UART_IER, 0);865865- up->running = 0;866866-867867- spin_lock_irqsave(&up->port.lock, flags);868868- up->port.mctrl &= ~TIOCM_OUT2;869869- serial_hsu_set_mctrl(&up->port, up->port.mctrl);870870- spin_unlock_irqrestore(&up->port.lock, flags);871871-872872- /* Disable break condition and FIFOs */873873- serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC);874874- serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |875875- UART_FCR_CLEAR_RCVR |876876- UART_FCR_CLEAR_XMIT);877877- serial_out(up, UART_FCR, 0);878878-879879- pm_runtime_put(up->dev);880880-}881881-882882-static void883883-serial_hsu_set_termios(struct uart_port *port, struct ktermios *termios,884884- struct ktermios *old)885885-{886886- struct uart_hsu_port *up =887887- container_of(port, struct uart_hsu_port, port);888888- unsigned char cval, fcr = 0;889889- unsigned long flags;890890- unsigned int baud, quot;891891- u32 ps, mul;892892-893893- switch (termios->c_cflag & CSIZE) {894894- case CS5:895895- cval = UART_LCR_WLEN5;896896- break;897897- case CS6:898898- cval = UART_LCR_WLEN6;899899- break;900900- case CS7:901901- cval = UART_LCR_WLEN7;902902- break;903903- default:904904- case CS8:905905- cval = UART_LCR_WLEN8;906906- break;907907- }908908-909909- /* CMSPAR isn't supported by this driver */910910- termios->c_cflag &= ~CMSPAR;911911-912912- if (termios->c_cflag & CSTOPB)913913- cval |= UART_LCR_STOP;914914- if (termios->c_cflag & PARENB)915915- cval |= UART_LCR_PARITY;916916- if (!(termios->c_cflag & PARODD))917917- cval |= UART_LCR_EPAR;918918-919919- /*920920- * The base clk is 50Mhz, and the baud rate come from:921921- * baud = 50M * MUL / (DIV * PS * DLAB)922922- *923923- * For those basic low baud rate we can get the direct924924- * scalar from 2746800, like 115200 = 2746800/24. For those925925- * higher baud rate, we handle them case by case, mainly by926926- * adjusting the MUL/PS registers, and DIV register is kept927927- * as default value 0x3d09 to make things simple928928- */929929- baud = uart_get_baud_rate(port, termios, old, 0, 4000000);930930-931931- quot = 1;932932- ps = 0x10;933933- mul = 0x3600;934934- switch (baud) {935935- case 3500000:936936- mul = 0x3345;937937- ps = 0xC;938938- break;939939- case 1843200:940940- mul = 0x2400;941941- break;942942- case 3000000:943943- case 2500000:944944- case 2000000:945945- case 1500000:946946- case 1000000:947947- case 500000:948948- /* mul/ps/quot = 0x9C4/0x10/0x1 will make a 500000 bps */949949- mul = baud / 500000 * 0x9C4;950950- break;951951- default:952952- /* Use uart_get_divisor to get quot for other baud rates */953953- quot = 0;954954- }955955-956956- if (!quot)957957- quot = uart_get_divisor(port, baud);958958-959959- if ((up->port.uartclk / quot) < (2400 * 16))960960- fcr = UART_FCR_ENABLE_FIFO | UART_FCR_HSU_64_1B;961961- else if ((up->port.uartclk / quot) < (230400 * 16))962962- fcr = UART_FCR_ENABLE_FIFO | UART_FCR_HSU_64_16B;963963- else964964- fcr = UART_FCR_ENABLE_FIFO | UART_FCR_HSU_64_32B;965965-966966- fcr |= UART_FCR_HSU_64B_FIFO;967967-968968- /*969969- * Ok, we're now changing the port state. Do it with970970- * interrupts disabled.971971- */972972- spin_lock_irqsave(&up->port.lock, flags);973973-974974- /* Update the per-port timeout */975975- uart_update_timeout(port, termios->c_cflag, baud);976976-977977- up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;978978- if (termios->c_iflag & INPCK)979979- up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;980980- if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))981981- up->port.read_status_mask |= UART_LSR_BI;982982-983983- /* Characters to ignore */984984- up->port.ignore_status_mask = 0;985985- if (termios->c_iflag & IGNPAR)986986- up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;987987- if (termios->c_iflag & IGNBRK) {988988- up->port.ignore_status_mask |= UART_LSR_BI;989989- /*990990- * If we're ignoring parity and break indicators,991991- * ignore overruns too (for real raw support).992992- */993993- if (termios->c_iflag & IGNPAR)994994- up->port.ignore_status_mask |= UART_LSR_OE;995995- }996996-997997- /* Ignore all characters if CREAD is not set */998998- if ((termios->c_cflag & CREAD) == 0)999999- up->port.ignore_status_mask |= UART_LSR_DR;10001000-10011001- /*10021002- * CTS flow control flag and modem status interrupts, disable10031003- * MSI by default10041004- */10051005- up->ier &= ~UART_IER_MSI;10061006- if (UART_ENABLE_MS(&up->port, termios->c_cflag))10071007- up->ier |= UART_IER_MSI;10081008-10091009- serial_out(up, UART_IER, up->ier);10101010-10111011- if (termios->c_cflag & CRTSCTS)10121012- up->mcr |= UART_MCR_AFE | UART_MCR_RTS;10131013- else10141014- up->mcr &= ~UART_MCR_AFE;10151015-10161016- serial_out(up, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */10171017- serial_out(up, UART_DLL, quot & 0xff); /* LS of divisor */10181018- serial_out(up, UART_DLM, quot >> 8); /* MS of divisor */10191019- serial_out(up, UART_LCR, cval); /* reset DLAB */10201020- serial_out(up, UART_MUL, mul); /* set MUL */10211021- serial_out(up, UART_PS, ps); /* set PS */10221022- up->lcr = cval; /* Save LCR */10231023- serial_hsu_set_mctrl(&up->port, up->port.mctrl);10241024- serial_out(up, UART_FCR, fcr);10251025- spin_unlock_irqrestore(&up->port.lock, flags);10261026-}10271027-10281028-static void10291029-serial_hsu_pm(struct uart_port *port, unsigned int state,10301030- unsigned int oldstate)10311031-{10321032-}10331033-10341034-static void serial_hsu_release_port(struct uart_port *port)10351035-{10361036-}10371037-10381038-static int serial_hsu_request_port(struct uart_port *port)10391039-{10401040- return 0;10411041-}10421042-10431043-static void serial_hsu_config_port(struct uart_port *port, int flags)10441044-{10451045- struct uart_hsu_port *up =10461046- container_of(port, struct uart_hsu_port, port);10471047- up->port.type = PORT_MFD;10481048-}10491049-10501050-static int10511051-serial_hsu_verify_port(struct uart_port *port, struct serial_struct *ser)10521052-{10531053- /* We don't want the core code to modify any port params */10541054- return -EINVAL;10551055-}10561056-10571057-static const char *10581058-serial_hsu_type(struct uart_port *port)10591059-{10601060- struct uart_hsu_port *up =10611061- container_of(port, struct uart_hsu_port, port);10621062- return up->name;10631063-}10641064-10651065-/* Mainly for uart console use */10661066-static struct uart_hsu_port *serial_hsu_ports[3];10671067-static struct uart_driver serial_hsu_reg;10681068-10691069-#ifdef CONFIG_SERIAL_MFD_HSU_CONSOLE10701070-10711071-#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)10721072-10731073-/* Wait for transmitter & holding register to empty */10741074-static inline void wait_for_xmitr(struct uart_hsu_port *up)10751075-{10761076- unsigned int status, tmout = 1000;10771077-10781078- /* Wait up to 1ms for the character to be sent. */10791079- do {10801080- status = serial_in(up, UART_LSR);10811081-10821082- if (status & UART_LSR_BI)10831083- up->lsr_break_flag = UART_LSR_BI;10841084-10851085- if (--tmout == 0)10861086- break;10871087- udelay(1);10881088- } while (!(status & BOTH_EMPTY));10891089-10901090- /* Wait up to 1s for flow control if necessary */10911091- if (up->port.flags & UPF_CONS_FLOW) {10921092- tmout = 1000000;10931093- while (--tmout &&10941094- ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0))10951095- udelay(1);10961096- }10971097-}10981098-10991099-static void serial_hsu_console_putchar(struct uart_port *port, int ch)11001100-{11011101- struct uart_hsu_port *up =11021102- container_of(port, struct uart_hsu_port, port);11031103-11041104- wait_for_xmitr(up);11051105- serial_out(up, UART_TX, ch);11061106-}11071107-11081108-/*11091109- * Print a string to the serial port trying not to disturb11101110- * any possible real use of the port...11111111- *11121112- * The console_lock must be held when we get here.11131113- */11141114-static void11151115-serial_hsu_console_write(struct console *co, const char *s, unsigned int count)11161116-{11171117- struct uart_hsu_port *up = serial_hsu_ports[co->index];11181118- unsigned long flags;11191119- unsigned int ier;11201120- int locked = 1;11211121-11221122- touch_nmi_watchdog();11231123-11241124- local_irq_save(flags);11251125- if (up->port.sysrq)11261126- locked = 0;11271127- else if (oops_in_progress) {11281128- locked = spin_trylock(&up->port.lock);11291129- } else11301130- spin_lock(&up->port.lock);11311131-11321132- /* First save the IER then disable the interrupts */11331133- ier = serial_in(up, UART_IER);11341134- serial_out(up, UART_IER, 0);11351135-11361136- uart_console_write(&up->port, s, count, serial_hsu_console_putchar);11371137-11381138- /*11391139- * Finally, wait for transmitter to become empty11401140- * and restore the IER11411141- */11421142- wait_for_xmitr(up);11431143- serial_out(up, UART_IER, ier);11441144-11451145- if (locked)11461146- spin_unlock(&up->port.lock);11471147- local_irq_restore(flags);11481148-}11491149-11501150-static struct console serial_hsu_console;11511151-11521152-static int __init11531153-serial_hsu_console_setup(struct console *co, char *options)11541154-{11551155- struct uart_hsu_port *up;11561156- int baud = 115200;11571157- int bits = 8;11581158- int parity = 'n';11591159- int flow = 'n';11601160-11611161- if (co->index == -1 || co->index >= serial_hsu_reg.nr)11621162- co->index = 0;11631163- up = serial_hsu_ports[co->index];11641164- if (!up)11651165- return -ENODEV;11661166-11671167- if (options)11681168- uart_parse_options(options, &baud, &parity, &bits, &flow);11691169-11701170- return uart_set_options(&up->port, co, baud, parity, bits, flow);11711171-}11721172-11731173-static struct console serial_hsu_console = {11741174- .name = "ttyMFD",11751175- .write = serial_hsu_console_write,11761176- .device = uart_console_device,11771177- .setup = serial_hsu_console_setup,11781178- .flags = CON_PRINTBUFFER,11791179- .index = -1,11801180- .data = &serial_hsu_reg,11811181-};11821182-11831183-#define SERIAL_HSU_CONSOLE (&serial_hsu_console)11841184-#else11851185-#define SERIAL_HSU_CONSOLE NULL11861186-#endif11871187-11881188-static struct uart_ops serial_hsu_pops = {11891189- .tx_empty = serial_hsu_tx_empty,11901190- .set_mctrl = serial_hsu_set_mctrl,11911191- .get_mctrl = serial_hsu_get_mctrl,11921192- .stop_tx = serial_hsu_stop_tx,11931193- .start_tx = serial_hsu_start_tx,11941194- .stop_rx = serial_hsu_stop_rx,11951195- .enable_ms = serial_hsu_enable_ms,11961196- .break_ctl = serial_hsu_break_ctl,11971197- .startup = serial_hsu_startup,11981198- .shutdown = serial_hsu_shutdown,11991199- .set_termios = serial_hsu_set_termios,12001200- .pm = serial_hsu_pm,12011201- .type = serial_hsu_type,12021202- .release_port = serial_hsu_release_port,12031203- .request_port = serial_hsu_request_port,12041204- .config_port = serial_hsu_config_port,12051205- .verify_port = serial_hsu_verify_port,12061206-};12071207-12081208-static struct uart_driver serial_hsu_reg = {12091209- .owner = THIS_MODULE,12101210- .driver_name = "MFD serial",12111211- .dev_name = "ttyMFD",12121212- .major = TTY_MAJOR,12131213- .minor = 128,12141214- .nr = 3,12151215- .cons = SERIAL_HSU_CONSOLE,12161216-};12171217-12181218-#ifdef CONFIG_PM12191219-static int serial_hsu_suspend(struct pci_dev *pdev, pm_message_t state)12201220-{12211221- void *priv = pci_get_drvdata(pdev);12221222- struct uart_hsu_port *up;12231223-12241224- /* Make sure this is not the internal dma controller */12251225- if (priv && (pdev->device != 0x081E)) {12261226- up = priv;12271227- uart_suspend_port(&serial_hsu_reg, &up->port);12281228- }12291229-12301230- pci_save_state(pdev);12311231- pci_set_power_state(pdev, pci_choose_state(pdev, state));12321232- return 0;12331233-}12341234-12351235-static int serial_hsu_resume(struct pci_dev *pdev)12361236-{12371237- void *priv = pci_get_drvdata(pdev);12381238- struct uart_hsu_port *up;12391239- int ret;12401240-12411241- pci_set_power_state(pdev, PCI_D0);12421242- pci_restore_state(pdev);12431243-12441244- ret = pci_enable_device(pdev);12451245- if (ret)12461246- dev_warn(&pdev->dev,12471247- "HSU: can't re-enable device, try to continue\n");12481248-12491249- if (priv && (pdev->device != 0x081E)) {12501250- up = priv;12511251- uart_resume_port(&serial_hsu_reg, &up->port);12521252- }12531253- return 0;12541254-}12551255-12561256-static int serial_hsu_runtime_idle(struct device *dev)12571257-{12581258- pm_schedule_suspend(dev, 500);12591259- return -EBUSY;12601260-}12611261-12621262-static int serial_hsu_runtime_suspend(struct device *dev)12631263-{12641264- return 0;12651265-}12661266-12671267-static int serial_hsu_runtime_resume(struct device *dev)12681268-{12691269- return 0;12701270-}12711271-#else12721272-#define serial_hsu_suspend NULL12731273-#define serial_hsu_resume NULL12741274-#define serial_hsu_runtime_idle NULL12751275-#define serial_hsu_runtime_suspend NULL12761276-#define serial_hsu_runtime_resume NULL12771277-#endif12781278-12791279-static const struct dev_pm_ops serial_hsu_pm_ops = {12801280- .runtime_suspend = serial_hsu_runtime_suspend,12811281- .runtime_resume = serial_hsu_runtime_resume,12821282- .runtime_idle = serial_hsu_runtime_idle,12831283-};12841284-12851285-/* temp global pointer before we settle down on using one or four PCI dev */12861286-static struct hsu_port *phsu;12871287-12881288-static int serial_hsu_probe(struct pci_dev *pdev,12891289- const struct pci_device_id *ent)12901290-{12911291- struct uart_hsu_port *uport;12921292- int index, ret;12931293-12941294- printk(KERN_INFO "HSU: found PCI Serial controller(ID: %04x:%04x)\n",12951295- pdev->vendor, pdev->device);12961296-12971297- switch (pdev->device) {12981298- case 0x081B:12991299- index = 0;13001300- break;13011301- case 0x081C:13021302- index = 1;13031303- break;13041304- case 0x081D:13051305- index = 2;13061306- break;13071307- case 0x081E:13081308- /* internal DMA controller */13091309- index = 3;13101310- break;13111311- default:13121312- dev_err(&pdev->dev, "HSU: out of index!");13131313- return -ENODEV;13141314- }13151315-13161316- ret = pci_enable_device(pdev);13171317- if (ret)13181318- return ret;13191319-13201320- if (index == 3) {13211321- /* DMA controller */13221322- ret = request_irq(pdev->irq, dma_irq, 0, "hsu_dma", phsu);13231323- if (ret) {13241324- dev_err(&pdev->dev, "can not get IRQ\n");13251325- goto err_disable;13261326- }13271327- pci_set_drvdata(pdev, phsu);13281328- } else {13291329- /* UART port 0~2 */13301330- uport = &phsu->port[index];13311331- uport->port.irq = pdev->irq;13321332- uport->port.dev = &pdev->dev;13331333- uport->dev = &pdev->dev;13341334-13351335- ret = request_irq(pdev->irq, port_irq, 0, uport->name, uport);13361336- if (ret) {13371337- dev_err(&pdev->dev, "can not get IRQ\n");13381338- goto err_disable;13391339- }13401340- uart_add_one_port(&serial_hsu_reg, &uport->port);13411341-13421342- pci_set_drvdata(pdev, uport);13431343- }13441344-13451345- pm_runtime_put_noidle(&pdev->dev);13461346- pm_runtime_allow(&pdev->dev);13471347-13481348- return 0;13491349-13501350-err_disable:13511351- pci_disable_device(pdev);13521352- return ret;13531353-}13541354-13551355-static void hsu_global_init(void)13561356-{13571357- struct hsu_port *hsu;13581358- struct uart_hsu_port *uport;13591359- struct hsu_dma_chan *dchan;13601360- int i, ret;13611361-13621362- hsu = kzalloc(sizeof(struct hsu_port), GFP_KERNEL);13631363- if (!hsu)13641364- return;13651365-13661366- /* Get basic io resource and map it */13671367- hsu->paddr = 0xffa28000;13681368- hsu->iolen = 0x1000;13691369-13701370- if (!(request_mem_region(hsu->paddr, hsu->iolen, "HSU global")))13711371- pr_warn("HSU: error in request mem region\n");13721372-13731373- hsu->reg = ioremap_nocache((unsigned long)hsu->paddr, hsu->iolen);13741374- if (!hsu->reg) {13751375- pr_err("HSU: error in ioremap\n");13761376- ret = -ENOMEM;13771377- goto err_free_region;13781378- }13791379-13801380- /* Initialise the 3 UART ports */13811381- uport = hsu->port;13821382- for (i = 0; i < 3; i++) {13831383- uport->port.type = PORT_MFD;13841384- uport->port.iotype = UPIO_MEM;13851385- uport->port.mapbase = (resource_size_t)hsu->paddr13861386- + HSU_PORT_REG_OFFSET13871387- + i * HSU_PORT_REG_LENGTH;13881388- uport->port.membase = hsu->reg + HSU_PORT_REG_OFFSET13891389- + i * HSU_PORT_REG_LENGTH;13901390-13911391- sprintf(uport->name, "hsu_port%d", i);13921392- uport->port.fifosize = 64;13931393- uport->port.ops = &serial_hsu_pops;13941394- uport->port.line = i;13951395- uport->port.flags = UPF_IOREMAP;13961396- /* set the scalable maxim support rate to 2746800 bps */13971397- uport->port.uartclk = 115200 * 24 * 16;13981398-13991399- uport->running = 0;14001400- uport->txc = &hsu->chans[i * 2];14011401- uport->rxc = &hsu->chans[i * 2 + 1];14021402-14031403- serial_hsu_ports[i] = uport;14041404- uport->index = i;14051405-14061406- if (hsu_dma_enable & (1<<i))14071407- uport->use_dma = 1;14081408- else14091409- uport->use_dma = 0;14101410-14111411- uport++;14121412- }14131413-14141414- /* Initialise 6 dma channels */14151415- dchan = hsu->chans;14161416- for (i = 0; i < 6; i++) {14171417- dchan->id = i;14181418- dchan->dirt = (i & 0x1) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;14191419- dchan->uport = &hsu->port[i/2];14201420- dchan->reg = hsu->reg + HSU_DMA_CHANS_REG_OFFSET +14211421- i * HSU_DMA_CHANS_REG_LENGTH;14221422-14231423- dchan++;14241424- }14251425-14261426- phsu = hsu;14271427- hsu_debugfs_init(hsu);14281428- return;14291429-14301430-err_free_region:14311431- release_mem_region(hsu->paddr, hsu->iolen);14321432- kfree(hsu);14331433- return;14341434-}14351435-14361436-static void serial_hsu_remove(struct pci_dev *pdev)14371437-{14381438- void *priv = pci_get_drvdata(pdev);14391439- struct uart_hsu_port *up;14401440-14411441- if (!priv)14421442- return;14431443-14441444- pm_runtime_forbid(&pdev->dev);14451445- pm_runtime_get_noresume(&pdev->dev);14461446-14471447- /* For port 0/1/2, priv is the address of uart_hsu_port */14481448- if (pdev->device != 0x081E) {14491449- up = priv;14501450- uart_remove_one_port(&serial_hsu_reg, &up->port);14511451- }14521452-14531453- free_irq(pdev->irq, priv);14541454- pci_disable_device(pdev);14551455-}14561456-14571457-/* First 3 are UART ports, and the 4th is the DMA */14581458-static const struct pci_device_id pci_ids[] = {14591459- { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081B) },14601460- { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081C) },14611461- { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081D) },14621462- { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081E) },14631463- {},14641464-};14651465-14661466-static struct pci_driver hsu_pci_driver = {14671467- .name = "HSU serial",14681468- .id_table = pci_ids,14691469- .probe = serial_hsu_probe,14701470- .remove = serial_hsu_remove,14711471- .suspend = serial_hsu_suspend,14721472- .resume = serial_hsu_resume,14731473- .driver = {14741474- .pm = &serial_hsu_pm_ops,14751475- },14761476-};14771477-14781478-static int __init hsu_pci_init(void)14791479-{14801480- int ret;14811481-14821482- hsu_global_init();14831483-14841484- ret = uart_register_driver(&serial_hsu_reg);14851485- if (ret)14861486- return ret;14871487-14881488- return pci_register_driver(&hsu_pci_driver);14891489-}14901490-14911491-static void __exit hsu_pci_exit(void)14921492-{14931493- pci_unregister_driver(&hsu_pci_driver);14941494- uart_unregister_driver(&serial_hsu_reg);14951495-14961496- hsu_debugfs_remove(phsu);14971497-14981498- kfree(phsu);14991499-}15001500-15011501-module_init(hsu_pci_init);15021502-module_exit(hsu_pci_exit);15031503-15041504-MODULE_LICENSE("GPL v2");15051505-MODULE_DEVICE_TABLE(pci, pci_ids);
+9-7
drivers/tty/serial/mxs-auart.c
···11551155 return 0;11561156}1157115711581158-static bool mxs_auart_init_gpios(struct mxs_auart_port *s, struct device *dev)11581158+static int mxs_auart_init_gpios(struct mxs_auart_port *s, struct device *dev)11591159{11601160 enum mctrl_gpio_idx i;11611161 struct gpio_desc *gpiod;1162116211631163 s->gpios = mctrl_gpio_init(dev, 0);11641164- if (IS_ERR_OR_NULL(s->gpios))11651165- return false;11641164+ if (IS_ERR(s->gpios))11651165+ return PTR_ERR(s->gpios);1166116611671167 /* Block (enabled before) DMA option if RTS or CTS is GPIO line */11681168 if (!RTS_AT_AUART() || !CTS_AT_AUART()) {···11801180 s->gpio_irq[i] = -EINVAL;11811181 }1182118211831183- return true;11831183+ return 0;11841184}1185118511861186static void mxs_auart_free_gpio_irq(struct mxs_auart_port *s)···1276127612771277 platform_set_drvdata(pdev, s);1278127812791279- if (!mxs_auart_init_gpios(s, &pdev->dev))12801280- dev_err(&pdev->dev,12811281- "Failed to initialize GPIOs. The serial port may not work as expected\n");12791279+ ret = mxs_auart_init_gpios(s, &pdev->dev);12801280+ if (ret) {12811281+ dev_err(&pdev->dev, "Failed to initialize GPIOs.\n");12821282+ got out_free_irq;12831283+ }1282128412831285 /*12841286 * Get the GPIO lines IRQ
+47-2
drivers/tty/serial/serial_core.c
···1118111811191119 cprev = cnow;11201120 }11211121-11221122- current->state = TASK_RUNNING;11211121+ __set_current_state(TASK_RUNNING);11231122 remove_wait_queue(&port->delta_msr_wait, &wait);1124112311251124 return ret;···1807180818081809 return ports + idx;18091810}18111811+18121812+/**18131813+ * uart_parse_earlycon - Parse earlycon options18141814+ * @p: ptr to 2nd field (ie., just beyond '<name>,')18151815+ * @iotype: ptr for decoded iotype (out)18161816+ * @addr: ptr for decoded mapbase/iobase (out)18171817+ * @options: ptr for <options> field; NULL if not present (out)18181818+ *18191819+ * Decodes earlycon kernel command line parameters of the form18201820+ * earlycon=<name>,io|mmio|mmio32,<addr>,<options>18211821+ * console=<name>,io|mmio|mmio32,<addr>,<options>18221822+ *18231823+ * The optional form18241824+ * earlycon=<name>,0x<addr>,<options>18251825+ * console=<name>,0x<addr>,<options>18261826+ * is also accepted; the returned @iotype will be UPIO_MEM.18271827+ *18281828+ * Returns 0 on success or -EINVAL on failure18291829+ */18301830+int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr,18311831+ char **options)18321832+{18331833+ if (strncmp(p, "mmio,", 5) == 0) {18341834+ *iotype = UPIO_MEM;18351835+ p += 5;18361836+ } else if (strncmp(p, "mmio32,", 7) == 0) {18371837+ *iotype = UPIO_MEM32;18381838+ p += 7;18391839+ } else if (strncmp(p, "io,", 3) == 0) {18401840+ *iotype = UPIO_PORT;18411841+ p += 3;18421842+ } else if (strncmp(p, "0x", 2) == 0) {18431843+ *iotype = UPIO_MEM;18441844+ } else {18451845+ return -EINVAL;18461846+ }18471847+18481848+ *addr = simple_strtoul(p, NULL, 0);18491849+ p = strchr(p, ',');18501850+ if (p)18511851+ p++;18521852+18531853+ *options = p;18541854+ return 0;18551855+}18561856+EXPORT_SYMBOL_GPL(uart_parse_earlycon);1810185718111858/**18121859 * uart_parse_options - Parse serial port baud/parity/bits/flow control.
+13-36
drivers/tty/serial/serial_mctrl_gpio.c
···4848 int value_array[UART_GPIO_MAX];4949 unsigned int count = 0;50505151- if (IS_ERR_OR_NULL(gpios))5252- return;5353-5451 for (i = 0; i < UART_GPIO_MAX; i++)5552 if (!IS_ERR_OR_NULL(gpios->gpio[i]) &&5653 mctrl_gpios_desc[i].dir_out) {···6265struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,6366 enum mctrl_gpio_idx gidx)6467{6565- if (!IS_ERR_OR_NULL(gpios) && !IS_ERR_OR_NULL(gpios->gpio[gidx]))6666- return gpios->gpio[gidx];6767- else6868- return NULL;6868+ return gpios->gpio[gidx];6969}7070EXPORT_SYMBOL_GPL(mctrl_gpio_to_gpiod);7171···7076{7177 enum mctrl_gpio_idx i;72787373- /*7474- * return it unchanged if the structure is not allocated7575- */7676- if (IS_ERR_OR_NULL(gpios))7777- return *mctrl;7878-7979 for (i = 0; i < UART_GPIO_MAX; i++) {8080- if (!IS_ERR_OR_NULL(gpios->gpio[i]) &&8181- !mctrl_gpios_desc[i].dir_out) {8080+ if (gpios->gpio[i] && !mctrl_gpios_desc[i].dir_out) {8281 if (gpiod_get_value(gpios->gpio[i]))8382 *mctrl |= mctrl_gpios_desc[i].mctrl;8483 else···94107 return ERR_PTR(-ENOMEM);9510896109 for (i = 0; i < UART_GPIO_MAX; i++) {9797- gpios->gpio[i] = devm_gpiod_get_index(dev,9898- mctrl_gpios_desc[i].name,9999- idx);100100-101101- /*102102- * The GPIOs are maybe not all filled,103103- * this is not an error.104104- */105105- if (IS_ERR_OR_NULL(gpios->gpio[i]))106106- continue;110110+ enum gpiod_flags flags;107111108112 if (mctrl_gpios_desc[i].dir_out)109109- err = gpiod_direction_output(gpios->gpio[i], 0);113113+ flags = GPIOD_OUT_LOW;110114 else111111- err = gpiod_direction_input(gpios->gpio[i]);112112- if (err) {113113- dev_dbg(dev, "Unable to set direction for %s GPIO",114114- mctrl_gpios_desc[i].name);115115- devm_gpiod_put(dev, gpios->gpio[i]);116116- gpios->gpio[i] = NULL;117117- }115115+ flags = GPIOD_IN;116116+117117+ gpios->gpio[i] =118118+ devm_gpiod_get_index_optional(dev,119119+ mctrl_gpios_desc[i].name,120120+ idx, flags);121121+122122+ if (IS_ERR(gpios->gpio[i]))123123+ return PTR_ERR(gpios->gpio[i]);118124 }119125120126 return gpios;···117137void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)118138{119139 enum mctrl_gpio_idx i;120120-121121- if (IS_ERR_OR_NULL(gpios))122122- return;123140124141 for (i = 0; i < UART_GPIO_MAX; i++)125142 if (!IS_ERR_OR_NULL(gpios->gpio[i]))
···11541154 return -EINVAL;1155115511561156 if (!port->mapbase) {11571157- pr_debug("console on ttyPS%i not present\n", co->index);11571157+ pr_debug("console on " CDNS_UART_TTY_NAME "%i not present\n",11581158+ co->index);11581159 return -ENODEV;11591160 }11601161
+2-2
drivers/tty/vt/vt.c
···1237123712381238struct rgb { u8 r; u8 g; u8 b; };1239123912401240-struct rgb rgb_from_256(int i)12401240+static struct rgb rgb_from_256(int i)12411241{12421242 struct rgb c;12431243 if (i < 8) { /* Standard colours. */···15731573 case 11: /* set bell duration in msec */15741574 if (vc->vc_npar >= 1)15751575 vc->vc_bell_duration = (vc->vc_par[1] < 2000) ?15761576- vc->vc_par[1] * HZ / 1000 : 0;15761576+ msecs_to_jiffies(vc->vc_par[1]) : 0;15771577 else15781578 vc->vc_bell_duration = DEFAULT_BELL_DURATION;15791579 break;
+1-1
drivers/tty/vt/vt_ioctl.c
···388388 * Generate the tone for the appropriate number of ticks.389389 * If the time is zero, turn off sound ourselves.390390 */391391- ticks = HZ * ((arg >> 16) & 0xffff) / 1000;391391+ ticks = msecs_to_jiffies((arg >> 16) & 0xffff);392392 count = ticks ? (arg & 0xffff) : 0;393393 if (count)394394 count = PIT_TICK_RATE / count;
+48
include/linux/dma/hsu.h
···11+/*22+ * Driver for the High Speed UART DMA33+ *44+ * Copyright (C) 2015 Intel Corporation55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License version 2 as88+ * published by the Free Software Foundation.99+ */1010+1111+#ifndef _DMA_HSU_H1212+#define _DMA_HSU_H1313+1414+#include <linux/device.h>1515+#include <linux/interrupt.h>1616+1717+#include <linux/platform_data/dma-hsu.h>1818+1919+struct hsu_dma;2020+2121+/**2222+ * struct hsu_dma_chip - representation of HSU DMA hardware2323+ * @dev: struct device of the DMA controller2424+ * @irq: irq line2525+ * @regs: memory mapped I/O space2626+ * @length: I/O space length2727+ * @offset: offset of the I/O space where registers are located2828+ * @hsu: struct hsu_dma that is filed by ->probe()2929+ * @pdata: platform data for the DMA controller if provided3030+ */3131+struct hsu_dma_chip {3232+ struct device *dev;3333+ int irq;3434+ void __iomem *regs;3535+ unsigned int length;3636+ unsigned int offset;3737+ struct hsu_dma *hsu;3838+ struct hsu_dma_platform_data *pdata;3939+};4040+4141+/* Export to the internal users */4242+irqreturn_t hsu_dma_irq(struct hsu_dma_chip *chip, unsigned short nr);4343+4444+/* Export to the platform drivers */4545+int hsu_dma_probe(struct hsu_dma_chip *chip);4646+int hsu_dma_remove(struct hsu_dma_chip *chip);4747+4848+#endif /* _DMA_HSU_H */
+25
include/linux/platform_data/dma-hsu.h
···11+/*22+ * Driver for the High Speed UART DMA33+ *44+ * Copyright (C) 2015 Intel Corporation55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License version 2 as88+ * published by the Free Software Foundation.99+ */1010+1111+#ifndef _PLATFORM_DATA_DMA_HSU_H1212+#define _PLATFORM_DATA_DMA_HSU_H1313+1414+#include <linux/device.h>1515+1616+struct hsu_dma_slave {1717+ struct device *dma_dev;1818+ int chan_id;1919+};2020+2121+struct hsu_dma_platform_data {2222+ unsigned short nr_channels;2323+};2424+2525+#endif /* _PLATFORM_DATA_DMA_HSU_H */
-5
include/linux/platform_data/serial-imx.h
···2020#define ASMARM_ARCH_UART_H21212222#define IMXUART_HAVE_RTSCTS (1<<0)2323-#define IMXUART_IRDA (1<<1)24232524struct imxuart_platform_data {2625 unsigned int flags;2727- void (*irda_enable)(int enable);2828- unsigned int irda_inv_rx:1;2929- unsigned int irda_inv_tx:1;3030- unsigned short transceiver_delay;3126};32273328#endif
+2
include/linux/serial_core.h
···354354355355struct uart_port *uart_get_console(struct uart_port *ports, int nr,356356 struct console *c);357357+int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr,358358+ char **options);357359void uart_parse_options(char *options, int *baud, int *parity, int *bits,358360 int *flow);359361int uart_set_options(struct uart_port *port, struct console *co, int baud,