From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Andi Shyti <andi.shyti@samsung.com>
Cc: Simon Shields <simon@lineageos.org>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Andi Shyti <andi@etezian.org>
Subject: Re: [PATCH 2/8] Input: mms114 - get read of custm i2c read/write functions
Date: Mon, 29 Jan 2018 11:01:41 -0800 [thread overview]
Message-ID: <20180129190141.w2q55gfjjnvepl6k@dtor-ws> (raw)
In-Reply-To: <20180129113323.18961-3-andi.shyti@samsung.com>
On Mon, Jan 29, 2018 at 08:33:17PM +0900, Andi Shyti wrote:
> The 'mms114_read_reg' and 'mms114_write_reg' are used when
> reading or writing to the 'MMS114_MODE_CONTROL' register for
> updating the 'cache_mode_control' variable.
>
> Update the 'cache_mode_control' variable in the calling
> mms114_set_active() function and get rid of all the custom i2c
> read/write functions.
>
> With this remove also the redundant sleep of MMS114_I2C_DELAY
> (50us) between i2c operations. The waiting should to be handled
> by the i2c driver.
>
> Signed-off-by: Andi Shyti <andi.shyti@samsung.com>
> ---
> drivers/input/touchscreen/mms114.c | 87 +++++---------------------------------
> 1 file changed, 10 insertions(+), 77 deletions(-)
>
> diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c
> index 0b8b1f0e8ba6..94a97049d711 100644
> --- a/drivers/input/touchscreen/mms114.c
> +++ b/drivers/input/touchscreen/mms114.c
> @@ -37,9 +37,6 @@
> #define MMS152_FW_REV 0xE1
> #define MMS152_COMPAT_GROUP 0xF2
>
> -/* Minimum delay time is 50us between stop and start signal of i2c */
> -#define MMS114_I2C_DELAY 50
> -
> /* 200ms needs after power on */
> #define MMS114_POWERON_DELAY 200
>
> @@ -83,76 +80,6 @@ struct mms114_touch {
> u8 reserved[2];
> } __packed;
>
> -static int __mms114_read_reg(struct mms114_data *data, unsigned int reg,
> - unsigned int len, u8 *val)
> -{
> - struct i2c_client *client = data->client;
> - struct i2c_msg xfer[2];
> - u8 buf = reg & 0xff;
> - int error;
> -
> - if (reg <= MMS114_MODE_CONTROL && reg + len > MMS114_MODE_CONTROL)
> - BUG();
> -
> - /* Write register: use repeated start */
> - xfer[0].addr = client->addr;
> - xfer[0].flags = I2C_M_TEN | I2C_M_NOSTART;
So the chip does not use 10-bit addressing? What about I2C_M_NOSTART? It
is not needed also?
> - xfer[0].len = 1;
> - xfer[0].buf = &buf;
> -
> - /* Read data */
> - xfer[1].addr = client->addr;
> - xfer[1].flags = I2C_M_RD;
> - xfer[1].len = len;
> - xfer[1].buf = val;
> -
> - error = i2c_transfer(client->adapter, xfer, 2);
> - if (error != 2) {
> - dev_err(&client->dev,
> - "%s: i2c transfer failed (%d)\n", __func__, error);
> - return error < 0 ? error : -EIO;
> - }
> - udelay(MMS114_I2C_DELAY);
> -
> - return 0;
> -}
> -
> -static int mms114_read_reg(struct mms114_data *data, unsigned int reg)
> -{
> - u8 val;
> - int error;
> -
> - if (reg == MMS114_MODE_CONTROL)
> - return data->cache_mode_control;
> -
> - error = __mms114_read_reg(data, reg, 1, &val);
> - return error < 0 ? error : val;
> -}
> -
> -static int mms114_write_reg(struct mms114_data *data, unsigned int reg,
> - unsigned int val)
> -{
> - struct i2c_client *client = data->client;
> - u8 buf[2];
> - int error;
> -
> - buf[0] = reg & 0xff;
> - buf[1] = val & 0xff;
> -
> - error = i2c_master_send(client, buf, 2);
> - if (error != 2) {
> - dev_err(&client->dev,
> - "%s: i2c send failed (%d)\n", __func__, error);
> - return error < 0 ? error : -EIO;
> - }
> - udelay(MMS114_I2C_DELAY);
> -
> - if (reg == MMS114_MODE_CONTROL)
> - data->cache_mode_control = val;
> -
> - return 0;
> -}
> -
> static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *touch)
> {
> struct i2c_client *client = data->client;
> @@ -231,19 +158,25 @@ static irqreturn_t mms114_interrupt(int irq, void *dev_id)
>
> static int mms114_set_active(struct mms114_data *data, bool active)
> {
> - int val;
> + int val, err;
>
> - val = mms114_read_reg(data, MMS114_MODE_CONTROL);
> + val = i2c_smbus_read_byte_data(data->client, MMS114_MODE_CONTROL);
If I understand the original commit for the driver, the control
register is write only and is not to be read from, that is why we have
this cached value. With your change you read form it.
By the way, have you looked into converting it all to regmap?
> if (val < 0)
> return val;
>
> - val &= ~MMS114_OPERATION_MODE_MASK;
> + val = data->cache_mode_control &= ~MMS114_OPERATION_MODE_MASK;
>
> /* If active is false, sleep mode */
> if (active)
> val |= MMS114_ACTIVE;
>
> - return mms114_write_reg(data, MMS114_MODE_CONTROL, val);
> + err = i2c_smbus_write_byte_data(data->client, MMS114_MODE_CONTROL, val);
> + if (err < 0)
> + return err;
> +
> + data->cache_mode_control = val;
> +
> + return 0;
> }
>
> static int mms114_get_version(struct mms114_data *data)
> --
> 2.15.1
>
--
Dmitry
next prev parent reply other threads:[~2018-01-29 19:01 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20180129113330epcas2p353fa87845f4a1e21661032f16b11be82@epcas2p3.samsung.com>
2018-01-29 11:33 ` [PATCH 0/8] Melfas MMS114 touchscreen cleanups Andi Shyti
2018-01-29 11:33 ` [PATCH 1/8] Input: mms114 - use smbus functions whenever possible Andi Shyti
2018-01-29 11:33 ` [PATCH 2/8] Input: mms114 - get read of custm i2c read/write functions Andi Shyti
2018-01-29 19:01 ` Dmitry Torokhov [this message]
2018-01-29 23:25 ` Andi Shyti
2018-01-29 11:33 ` [PATCH 3/8] Input: mms114 - replace mdelay with msleep Andi Shyti
2018-01-29 19:46 ` Dmitry Torokhov
2018-01-29 11:33 ` [PATCH 4/8] Input: mms114 - remove unused variable Andi Shyti
2018-01-29 18:43 ` Dmitry Torokhov
2018-01-29 23:27 ` Andi Shyti
2018-01-29 11:33 ` [PATCH 5/8] Input: mms114 - use lower case for hexadecimal values Andi Shyti
2018-01-29 18:56 ` Dmitry Torokhov
2018-01-29 23:29 ` Andi Shyti
2018-01-29 23:33 ` Dmitry Torokhov
2018-01-29 23:41 ` Andi Shyti
2018-01-29 11:33 ` [PATCH 6/8] Input: mms114 - Use BIT() macro instead of explicit shifting Andi Shyti
2018-01-29 19:46 ` Dmitry Torokhov
2018-01-29 11:33 ` [PATCH 7/8] Input: mms114 - add SPDX identifier Andi Shyti
2018-01-29 19:46 ` Dmitry Torokhov
2018-01-31 6:07 ` Andi Shyti
2018-01-31 7:31 ` Marcus Folkesson
2018-01-31 22:53 ` Dmitry Torokhov
2018-02-01 0:50 ` Andi Shyti
2018-02-01 0:49 ` Andi Shyti
2018-01-29 11:33 ` [PATCH 8/8] Input: mms114 - fix typo in definition Andi Shyti
2018-01-29 19:47 ` Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180129190141.w2q55gfjjnvepl6k@dtor-ws \
--to=dmitry.torokhov@gmail.com \
--cc=andi.shyti@samsung.com \
--cc=andi@etezian.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simon@lineageos.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox