From patchwork Mon Jul 18 08:27:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Six X-Patchwork-Id: 649379 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3rtGZw3XwYz9rxl for ; Mon, 18 Jul 2016 18:30:32 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0B107A75B4; Mon, 18 Jul 2016 10:30:02 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 65iK3bRVWV0w; Mon, 18 Jul 2016 10:30:01 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6ED18A75B9; Mon, 18 Jul 2016 10:29:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BA84B4BF90 for ; Mon, 18 Jul 2016 10:29:01 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A2Y8ml7O7u55 for ; Mon, 18 Jul 2016 10:29:01 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from smtprelay03.ispgateway.de (smtprelay03.ispgateway.de [80.67.18.15]) by theia.denx.de (Postfix) with ESMTPS id 06B654BD3D for ; Mon, 18 Jul 2016 10:28:56 +0200 (CEST) Received: from [195.243.218.178] (helo=bob3.testumgebung.local) by smtprelay03.ispgateway.de with esmtpa (Exim 4.84) (envelope-from ) id 1bP3v6-00025t-0o; Mon, 18 Jul 2016 10:28:56 +0200 From: Mario Six To: Heiko Schocher , U-Boot Mailing List Date: Mon, 18 Jul 2016 10:27:57 +0200 Message-Id: <20160718082802.10600-9-mario.six@gdsys.cc> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160718082802.10600-1-mario.six@gdsys.cc> References: <20160718082802.10600-1-mario.six@gdsys.cc> X-Df-Sender: bWFyaW8uc2l4QGdkc3lzLmNj Subject: [U-Boot] [PATCH 08/13] i2c: mvtwsi: Factor out adap parameter X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" To be able to use the compatibility layer from the DM functions, we factor the adap parameter out of all functions, and pass the actual register base instead. Signed-off-by: Mario Six --- drivers/i2c/mvtwsi.c | 97 +++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 51 deletions(-) diff --git a/drivers/i2c/mvtwsi.c b/drivers/i2c/mvtwsi.c index f1bfd5d..688efc2 100644 --- a/drivers/i2c/mvtwsi.c +++ b/drivers/i2c/mvtwsi.c @@ -208,9 +208,8 @@ inline uint mvtwsi_error(uint ec, uint lc, uint ls, uint es) * Wait for IFLG to raise, or return 'timeout.' Then, if the status is as * expected, return 0 (ok) or 'wrong status' otherwise. */ -static int twsi_wait(struct i2c_adapter *adap, int expected_status) +static int twsi_wait(struct mvtwsi_registers *twsi, int expected_status) { - struct mvtwsi_registers *twsi = twsi_get_base(adap); int control, status; int timeout = 1000; @@ -236,39 +235,35 @@ static int twsi_wait(struct i2c_adapter *adap, int expected_status) * Assert the START condition, either in a single I2C transaction * or inside back-to-back ones (repeated starts). */ -static int twsi_start(struct i2c_adapter *adap, int expected_status) +static int twsi_start(struct mvtwsi_registers *twsi, int expected_status) { - struct mvtwsi_registers *twsi = twsi_get_base(adap); - /* Assert START */ writel(MVTWSI_CONTROL_TWSIEN | MVTWSI_CONTROL_START | MVTWSI_CONTROL_CLEAR_IFLG, &twsi->control); /* Wait for controller to process START */ - return twsi_wait(adap, expected_status); + return twsi_wait(twsi, expected_status); } /* * Send a byte (i2c address or data). */ -static int twsi_send(struct i2c_adapter *adap, u8 byte, int expected_status) +static int twsi_send(struct mvtwsi_registers *twsi, u8 byte, + int expected_status) { - struct mvtwsi_registers *twsi = twsi_get_base(adap); - /* Write byte to data register for sending */ writel(byte, &twsi->data); /* Clear any pending interrupt -- that will cause sending */ writel(MVTWSI_CONTROL_TWSIEN | MVTWSI_CONTROL_CLEAR_IFLG, &twsi->control); /* Wait for controller to receive byte, and check ACK */ - return twsi_wait(adap, expected_status); + return twsi_wait(twsi, expected_status); } /* * Receive a byte. */ -static int twsi_recv(struct i2c_adapter *adap, u8 *byte, int ack_flag) +static int twsi_recv(struct mvtwsi_registers *twsi, u8 *byte, int ack_flag) { - struct mvtwsi_registers *twsi = twsi_get_base(adap); int expected_status, status, control; /* Compute expected status based on passed ACK flag */ @@ -279,7 +274,7 @@ static int twsi_recv(struct i2c_adapter *adap, u8 *byte, int ack_flag) control |= ack_flag == MVTWSI_READ_ACK ? MVTWSI_CONTROL_ACK : 0; writel(control | MVTWSI_CONTROL_CLEAR_IFLG, &twsi->control); /* Wait for controller to receive byte, and assert ACK or NAK */ - status = twsi_wait(adap, expected_status); + status = twsi_wait(twsi, expected_status); /* If we did receive the expected byte, store it */ if (status == 0) *byte = readl(&twsi->data); @@ -290,9 +285,8 @@ static int twsi_recv(struct i2c_adapter *adap, u8 *byte, int ack_flag) * Assert the STOP condition. * This is also used to force the bus back to idle (SDA = SCL = 1). */ -static int twsi_stop(struct i2c_adapter *adap) +static int twsi_stop(struct mvtwsi_registers *twsi) { - struct mvtwsi_registers *twsi = twsi_get_base(adap); int control, stop_status; int status = 0; int timeout = 1000; @@ -328,10 +322,8 @@ static uint twsi_calc_freq(const int n, const int m) * Controller reset also resets the baud rate and slave address, so * they must be re-established afterwards. */ -static void twsi_reset(struct i2c_adapter *adap) +static void twsi_reset(struct mvtwsi_registers *twsi) { - struct mvtwsi_registers *twsi = twsi_get_base(adap); - /* Reset controller */ writel(0, &twsi->soft_reset); /* Wait 2 ms -- this is what the Marvell LSP does */ @@ -341,10 +333,9 @@ static void twsi_reset(struct i2c_adapter *adap) /* * Sets baud to the highest possible value not exceeding the requested one. */ -static uint __twsi_i2c_set_bus_speed(struct i2c_adapter *adap, +static uint __twsi_i2c_set_bus_speed(struct mvtwsi_registers *twsi, uint requested_speed) { - struct mvtwsi_registers *twsi = twsi_get_base(adap); uint tmp_speed, highest_speed, n, m; uint baud = 0x44; /* Baud rate after controller reset */ @@ -366,26 +357,25 @@ static uint __twsi_i2c_set_bus_speed(struct i2c_adapter *adap, return 0; } -static void __twsi_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd) +static void __twsi_i2c_init(struct mvtwsi_registers *twsi, int speed, + int slaveadd) { - struct mvtwsi_registers *twsi = twsi_get_base(adap); - /* Reset controller */ - twsi_reset(adap); + twsi_reset(twsi); /* Set speed */ - __twsi_i2c_set_bus_speed(adap, speed); + __twsi_i2c_set_bus_speed(twsi, speed); /* Set slave address; even though we don't use it */ writel(slaveadd, &twsi->slave_address); writel(0, &twsi->xtnd_slave_addr); /* Assert STOP, but don't care for the result */ - (void) twsi_stop(adap); + (void) twsi_stop(twsi); } /* * Begin I2C transaction with expected start status, at given address. * Expected address status will derive from direction bit (bit 0) in addr. */ -static int i2c_begin(struct i2c_adapter *adap, int expected_start_status, +static int i2c_begin(struct mvtwsi_registers *twsi, int expected_start_status, u8 addr) { int status, expected_addr_status; @@ -397,10 +387,10 @@ static int i2c_begin(struct i2c_adapter *adap, int expected_start_status, else /* Writing */ expected_addr_status = MVTWSI_STATUS_ADDR_W_ACK; /* Assert START */ - status = twsi_start(adap, expected_start_status); + status = twsi_start(twsi, expected_start_status); /* Send out the address if the start went well */ if (status == 0) - status = twsi_send(adap, addr, expected_addr_status); + status = twsi_send(twsi, addr, expected_addr_status); /* Return 0, or the status of the first failure */ return status; } @@ -408,18 +398,18 @@ static int i2c_begin(struct i2c_adapter *adap, int expected_start_status, /* * Begin read, nak data byte, end. */ -static int __twsi_i2c_probe_chip(struct i2c_adapter *adap, uchar chip) +static int __twsi_i2c_probe_chip(struct mvtwsi_registers *twsi, uchar chip) { u8 dummy_byte; int status; /* Begin i2c read */ - status = i2c_begin(adap, MVTWSI_STATUS_START, (chip << 1) | 1); + status = i2c_begin(twsi, MVTWSI_STATUS_START, (chip << 1) | 1); /* Dummy read was accepted: receive byte, but NAK it. */ if (status == 0) - status = twsi_recv(adap, &dummy_byte, MVTWSI_READ_NAK); + status = twsi_recv(twsi, &dummy_byte, MVTWSI_READ_NAK); /* Stop transaction */ - twsi_stop(adap); + twsi_stop(twsi); /* Return 0, or the status of the first failure */ return status; } @@ -432,30 +422,30 @@ static int __twsi_i2c_probe_chip(struct i2c_adapter *adap, uchar chip) * higher level APIs, we need to make a decision here, and for the moment that * will be a repeated start without a preceding stop. */ -static int __twsi_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr, - int alen, uchar *data, int length) +static int __twsi_i2c_read(struct mvtwsi_registers *twsi, uchar chip, + uint addr, int alen, uchar *data, int length) { int status = 0; int stop_status; /* Begin i2c write to send the address bytes */ - status = i2c_begin(adap, MVTWSI_STATUS_START, (chip << 1)); + status = i2c_begin(twsi, MVTWSI_STATUS_START, (chip << 1)); /* Send address bytes */ while ((status == 0) && alen--) - status = twsi_send(adap, addr >> (8*alen), + status = twsi_send(twsi, addr >> (8*alen), MVTWSI_STATUS_DATA_W_ACK); /* Begin i2c read to receive data bytes */ if (status == 0) - status = i2c_begin(adap, MVTWSI_STATUS_REPEATED_START, + status = i2c_begin(twsi, MVTWSI_STATUS_REPEATED_START, (chip << 1) | 1); /* Receive actual data bytes; set NAK if we if we have nothing more to * read */ while ((status == 0) && length--) - status = twsi_recv(adap, data++, + status = twsi_recv(twsi, data++, length > 0 ? MVTWSI_READ_ACK : MVTWSI_READ_NAK); /* Stop transaction */ - stop_status = twsi_stop(adap); + stop_status = twsi_stop(twsi); /* Return 0, or the status of the first failure */ return status != 0 ? status : stop_status; } @@ -463,23 +453,23 @@ static int __twsi_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr, /* * Begin write, send address byte(s), send data bytes, end. */ -static int __twsi_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr, - int alen, uchar *data, int length) +static int __twsi_i2c_write(struct mvtwsi_registers *twsi, uchar chip, + uint addr, int alen, uchar *data, int length) { int status, stop_status; /* Begin i2c write to send first the address bytes, then the * data bytes */ - status = i2c_begin(adap, MVTWSI_STATUS_START, (chip << 1)); + status = i2c_begin(twsi, MVTWSI_STATUS_START, (chip << 1)); /* Send address bytes */ while ((status == 0) && alen--) - status = twsi_send(adap, addr >> (8*alen), + status = twsi_send(twsi, addr >> (8*alen), MVTWSI_STATUS_DATA_W_ACK); /* Send data bytes */ while ((status == 0) && (length-- > 0)) - status = twsi_send(adap, *(data++), MVTWSI_STATUS_DATA_W_ACK); + status = twsi_send(twsi, *(data++), MVTWSI_STATUS_DATA_W_ACK); /* Stop transaction */ - stop_status = twsi_stop(adap); + stop_status = twsi_stop(twsi); /* Return 0, or the status of the first failure */ return status != 0 ? status : stop_status; } @@ -487,30 +477,35 @@ static int __twsi_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr, static void twsi_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd) { - __twsi_i2c_init(adap, speed, slaveadd); + struct mvtwsi_registers *twsi = twsi_get_base(adap); + __twsi_i2c_init(twsi, speed, slaveadd); } static uint twsi_i2c_set_bus_speed(struct i2c_adapter *adap, uint requested_speed) { - return __twsi_i2c_set_bus_speed(adap, requested_speed); + struct mvtwsi_registers *twsi = twsi_get_base(adap); + return __twsi_i2c_set_bus_speed(twsi, requested_speed); } static int twsi_i2c_probe(struct i2c_adapter *adap, uchar chip) { - return __twsi_i2c_probe_chip(adap, chip); + struct mvtwsi_registers *twsi = twsi_get_base(adap); + return __twsi_i2c_probe_chip(twsi, chip); } static int twsi_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr, int alen, uchar *data, int length) { - return __twsi_i2c_read(adap, chip, addr, alen, data, length); + struct mvtwsi_registers *twsi = twsi_get_base(adap); + return __twsi_i2c_read(twsi, chip, addr, alen, data, length); } static int twsi_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr, int alen, uchar *data, int length) { - return __twsi_i2c_write(adap, chip, addr, alen, data, length); + struct mvtwsi_registers *twsi = twsi_get_base(adap); + return __twsi_i2c_write(twsi, chip, addr, alen, data, length); } #ifdef CONFIG_I2C_MVTWSI_BASE0