From: Felipe Balbi <felipe.balbi@xxxxxxxxx> don't do magic tricks with the data to be written, it's simpler to pass down a flag which will for sure tell us if we're reading or writing. Signed-off-by: Felipe Balbi <felipe.balbi@xxxxxxxxx> --- drivers/cbus/cbus.c | 30 ++++++++++++++++-------------- 1 files changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/cbus/cbus.c b/drivers/cbus/cbus.c index 35f7c71..53b43e1 100644 --- a/drivers/cbus/cbus.c +++ b/drivers/cbus/cbus.c @@ -3,12 +3,15 @@ * * Support functions for CBUS serial protocol * - * Copyright (C) 2004, 2005 Nokia Corporation + * Copyright (C) 2004-2010 Nokia Corporation + * Contact: Felipe Balbi <felipe.balbi@xxxxxxxxx> * * Written by Juha Yrjölä <juha.yrjola@xxxxxxxxx>, * David Weinehall <david.weinehall@xxxxxxxxx>, and * Mikko Ylinen <mikko.k.ylinen@xxxxxxxxx> * + * Several updates and cleanups by Felipe Balbi <felipe.balbi@xxxxxxxxx> + * * This file is subject to the terms and conditions of the GNU General * Public License. See the file "COPYING" in the main directory of this * archive for more details. @@ -39,6 +42,9 @@ #include "cbus.h" +#define CBUS_XFER_READ 1 +#define CBUS_XFER_WRITE 0 + static struct cbus_host *cbus_host; static void cbus_send_bit(struct cbus_host *host, int bit, int set_to_input) @@ -64,14 +70,11 @@ static u8 cbus_receive_bit(struct cbus_host *host) return ret; } -static int cbus_transfer(struct cbus_host *host, int dev, int reg, int data) +static int cbus_transfer(struct cbus_host *host, unsigned rw, unsigned dev, + unsigned reg, unsigned data) { - int i; - int is_read = 0; unsigned long flags; - - if (data < 0) - is_read = 1; + int i; /* We don't want interrupts disturbing our transfer */ spin_lock_irqsave(&host->lock, flags); @@ -87,24 +90,23 @@ static int cbus_transfer(struct cbus_host *host, int dev, int reg, int data) cbus_send_bit(host, dev & (1 << (i - 1)), 0); /* Send the rw flag */ - cbus_send_bit(host, is_read, 0); + cbus_send_bit(host, rw, 0); /* Send the register address */ for (i = 5; i > 0; i--) { int set_to_input = 0; - if (is_read && i == 1) + if (rw && i == 1) set_to_input = 1; cbus_send_bit(host, reg & (1 << (i - 1)), set_to_input); } - if (!is_read) { + if (!rw) { for (i = 16; i > 0; i--) cbus_send_bit(host, data & (1 << (i - 1)), 0); } else { gpio_set_value(host->clk_gpio, 1); - data = 0; for (i = 16; i > 0; i--) { u8 bit = cbus_receive_bit(host); @@ -129,7 +131,7 @@ static int cbus_transfer(struct cbus_host *host, int dev, int reg, int data) */ int cbus_read_reg(int dev, int reg) { - return cbus_transfer(cbus_host, dev, reg, -1); + return cbus_transfer(cbus_host, CBUS_XFER_READ, dev, reg, 0); } EXPORT_SYMBOL(cbus_read_reg); @@ -138,7 +140,7 @@ EXPORT_SYMBOL(cbus_read_reg); */ int cbus_write_reg(int dev, int reg, int val) { - return cbus_transfer(cbus_host, dev, reg, val); + return cbus_transfer(cbus_host, CBUS_XFER_WRITE, dev, reg, val); } EXPORT_SYMBOL(cbus_write_reg); @@ -214,7 +216,6 @@ static int __init cbus_bus_init(void) { return platform_driver_probe(&cbus_driver, cbus_bus_probe); } - subsys_initcall(cbus_bus_init); static void __exit cbus_bus_exit(void) @@ -228,4 +229,5 @@ MODULE_LICENSE("GPL"); MODULE_AUTHOR("Juha Yrjölä"); MODULE_AUTHOR("David Weinehall"); MODULE_AUTHOR("Mikko Ylinen"); +MODULE_AUTHOR("Felipe Balbi <felipe.balbi@xxxxxxxxx>"); -- 1.7.0.rc0.33.g7c3932 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html