Signed-off-by: michael musset <mickamusset@xxxxxxxxx> --- drivers/tty/serial/max310x.c | 45 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index 81ef694..562e5e3 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -291,13 +291,13 @@ static struct uart_driver max310x_uart_driver = { static struct max310x_port *max310xs[MAX_MAX310X]; /* the chips */ static DEFINE_MUTEX(max310xs_lock); /* race on probe */ -static int uart_driver_registered; +static int uart_driver_registered; /* flag to indicate if the driver is registered*/ +static int number_of_uarts; /* numbe of uarts*/ static u8 max310x_port_read(struct uart_port *port, u8 reg) { struct max310x_port *s = dev_get_drvdata(port->dev); unsigned int val = 0; - printk("max310x_port_read %d\n", s->index); regmap_read(s->regmap, port->iobase + reg, &val); return val; @@ -306,14 +306,12 @@ static u8 max310x_port_read(struct uart_port *port, u8 reg) static void max310x_port_write(struct uart_port *port, u8 reg, u8 val) { struct max310x_port *s = dev_get_drvdata(port->dev); - printk("max310x_port_write %d\n", s->index); regmap_write(s->regmap, port->iobase + reg, val); } static void max310x_port_update(struct uart_port *port, u8 reg, u8 mask, u8 val) { struct max310x_port *s = dev_get_drvdata(port->dev); - printk("max310x_port_update %d\n", s->index); regmap_update_bits(s->regmap, port->iobase + reg, mask, val); } @@ -763,7 +761,6 @@ static void max310x_start_tx(struct uart_port *port) { struct max310x_one *one = container_of(port, struct max310x_one, port); struct max310x_port *s = dev_get_drvdata(port->dev); - printk("max310x_start_tx %d", s->index); if (!work_pending(&one->tx_work)) schedule_work(&one->tx_work); } @@ -772,7 +769,6 @@ static unsigned int max310x_tx_empty(struct uart_port *port) { unsigned int lvl, sts; struct max310x_port *s = dev_get_drvdata(port->dev); - printk("max310x_tx_empty %d", s->index); lvl = max310x_port_read(port, MAX310X_TXFIFOLVL_REG); sts = max310x_port_read(port, MAX310X_IRQSTS_REG); @@ -933,7 +929,6 @@ static int max310x_startup(struct uart_port *port) { struct max310x_port *s = dev_get_drvdata(port->dev); unsigned int val; - printk("max310x_startup %d", s->index); s->devtype->power(port, 1); /* Configure MODE1 register */ @@ -1109,28 +1104,33 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, if (IS_ERR(regmap)) return PTR_ERR(regmap); - + // protection : mutex_lock(&max310xs_lock); - + // did we registered the driver ? if (!uart_driver_registered) { - printk("max310x init driver max310X\n"); + // no, let's do it : + // set the flag to 1 for the next time. uart_driver_registered = 1; + // register the driver : retval = uart_register_driver(&max310x_uart_driver); if (retval) { - printk(KERN_ERR "max310x Couldn't register max310x uart driver\n"); + // something goes wrong : mutex_unlock(&max310xs_lock); return retval; } + number_of_uarts=0; } + // find a free spot in the array : for (k = 0; k < MAX_MAX310X; k++) if (!max310xs[k]) break; + // test if we reach the end of the array if (k == MAX_MAX310X) { + // no more space available dev_warn(dev, "too many MAX310X chips\n"); mutex_unlock(&max310xs_lock); return -ENOMEM; } - printk("max310x index %d\n", k); /* Alloc port structure */ @@ -1143,14 +1143,16 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, dev_err(dev, "Error allocating port structure\n"); return -ENOMEM; } - + // save the index of the array s->index=k; - + // test if we can get the frequency of the clock from the dts file : if (of_find_property(dev->of_node, "clock-frequency", NULL)){ + // cool, let's get it : of_property_read_u32(dev->of_node, "clock-frequency", &freq); - printk("max310x clock frequency detected %d\n", freq); } + // check if the frequency is indicated : if(freq!=0){ + // yes ! we don't need to build a clock in the processor : fmin = 1000000; fmax = 4000000; xtal = 0; @@ -1180,7 +1182,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, } /* Check frequency limits */ if (freq < fmin || freq > fmax) { - printk("max310x error frequency\n"); ret = -ERANGE; goto out_clk; } @@ -1192,7 +1193,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, /* Check device to ensure we are talking to what we expect */ ret = devtype->detect(dev); if (ret){ - printk("max310x detection failed\n"); goto out_clk; } for (i = 0; i < devtype->nr; i++) { @@ -1211,6 +1211,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, regmap_read(s->regmap, MAX310X_BRGDIVLSB_REG + offs, &ret); } + // did the port start ? if not, restart the process ... maybe we need to stop at some point the wait .... }while(ret!=0x01); regmap_update_bits(s->regmap, MAX310X_MODE1_REG + offs, @@ -1219,9 +1220,10 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, } uartclk = max310x_set_ref_clk(s, freq, xtal); - printk("max310x Reference clock set to %i Hz\n", uartclk); s->nr = devtype->nr; +// maybe we shouldn't offer the possibility to config the gpio if the user want to use the full rts pins : +// todo: add a if with a test flag of the dts file : #ifdef CONFIG_GPIOLIB /* Setup GPIO cotroller */ s->gpio.owner = THIS_MODULE; @@ -1236,16 +1238,15 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, s->gpio.can_sleep = 1; ret = gpiochip_add(&s->gpio); if (ret){ - printk("max310x failed gpio add\n"); goto out_uart; } #endif mutex_init(&s->mutex); - printk("max310x devtype nr %d\n", devtype->nr); for (i = 0; i < devtype->nr; i++) { /* Initialize port data */ - s->p[i].port.line = (k+i); + // + s->p[i].port.line = number_of_uarts++; // get a unique ID // maybe we need mutex here ? s->p[i].port.dev = dev; s->p[i].port.irq = irq; s->p[i].port.type = PORT_MAX310X; @@ -1270,7 +1271,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, /* Initialize queue for changing mode */ INIT_WORK(&s->p[i].md_work, max310x_md_proc); /* Register port */ - printk("max310x uart add one port\n"); uart_add_one_port( &max310x_uart_driver, &s->p[i].port); /* Go to suspend mode */ devtype->power(&s->p[i].port, 0); @@ -1280,7 +1280,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, ret = devm_request_threaded_irq(dev, irq, NULL, max310x_ist, IRQF_ONESHOT | flags, dev_name(dev), s); if (!ret){ - printk("max310x add success\n"); return 0; } dev_err(dev, "Unable to reguest IRQ %i\n", irq); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html