linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Trilok Soni <tsoni@codeaurora.org>
Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	rtc-linux@googlegroups.com, linux-arm-msm@vger.kernel.org
Subject: Re: [RFC v1 PATCH 2/6] input: pm8058_keypad: Qualcomm PMIC8058 keypad controller driver
Date: Wed, 17 Nov 2010 10:02:40 -0800	[thread overview]
Message-ID: <20101117180240.GC6148@core.coreip.homeip.net> (raw)
In-Reply-To: <1289393281-4459-3-git-send-email-tsoni@codeaurora.org>

On Wed, Nov 10, 2010 at 06:17:57PM +0530, Trilok Soni wrote:
> Add Qualcomm PMIC8058 based keypad controller driver
> supporting upto 18x8 matrix configuration.
> 

Looks good, just a couple of nitpicks:

> +struct pmic8058_kp {
> +	const struct pmic8058_keypad_data *pdata;
> +	struct input_dev *input;
> +	int key_sense_irq;
> +	int key_stuck_irq;
> +
> +	unsigned short *keycodes;

Since the size of keycode table is constant there is no need to allocate
it separately (and even if it was variable you still could move it to
the end of the structure and allocate together).

> +
> +static int pmic8058_detect_ghost_keys(struct pmic8058_kp *kp, u16 *new_state)

bool

> +{
> +	int row, found_first = -1;
> +	u16 check, row_state;
> +
> +	check = 0;
> +	for (row = 0; row < kp->pdata->num_rows; row++) {
> +		row_state = (~new_state[row]) &
> +				 ((1 << kp->pdata->num_cols) - 1);
> +
> +		if (hweight16(row_state) > 1) {
> +			if (found_first == -1)
> +				found_first = row;
> +			if (check & row_state) {
> +				dev_dbg(kp->dev, "detected ghost key on row[%d]"
> +					 " and row[%d]\n", found_first, row);
> +				return 1;

true

> +			}
> +		}
> +		check |= row_state;
> +	}
> +	return 0;

false

> +static int __devinit pmic8058_kp_probe(struct platform_device *pdev)
> +{
> +	struct pmic8058_keypad_data *pdata = pdev->dev.platform_data;
> +	const struct matrix_keymap_data *keymap_data;
> +	struct pmic8058_kp *kp;
> +	int rc;
> +	unsigned short *keycodes;
> +	u8 ctrl_val;
> +	struct pm8058_chip	*pm_chip;
> +
> +	pm_chip = platform_get_drvdata(pdev);
> +	if (pm_chip == NULL) {
> +		dev_err(&pdev->dev, "no parent data passed in\n");
> +		return -EFAULT;

EFAULT is really odd, maybe -EINVAL?

> +	}
> +
> +	/* Check PMIC8058 version. A0 version is not supported */
> +	if (pm8058_rev(pm_chip) == PM_8058_REV_1p0) {
> +		dev_err(&pdev->dev, "PMIC8058 1.0 version is not supported\n");
> +		return -ENODEV;
> +	}
> +
> +	if (!pdata || !pdata->num_cols || !pdata->num_rows ||
> +		pdata->num_cols > PM8058_MAX_COLS ||
> +		pdata->num_rows > PM8058_MAX_ROWS ||
> +		pdata->num_cols < PM8058_MIN_COLS ||
> +		pdata->num_rows < PM8058_MIN_ROWS) {
> +		dev_err(&pdev->dev, "invalid platform data\n");
> +		return -EINVAL;
> +	}
> +
> +	if (pdata->rows_gpio_start < 0 || pdata->cols_gpio_start < 0) {
> +		dev_err(&pdev->dev, "invalid gpio_start platform data\n");
> +		return -EINVAL;
> +	}
> +
> +	if (!pdata->scan_delay_ms || pdata->scan_delay_ms > MAX_SCAN_DELAY
> +		|| pdata->scan_delay_ms < MIN_SCAN_DELAY ||
> +		!is_power_of_2(pdata->scan_delay_ms)) {
> +		dev_err(&pdev->dev, "invalid keypad scan time supplied\n");
> +		return -EINVAL;
> +	}
> +
> +	if (!pdata->row_hold_ns || pdata->row_hold_ns > MAX_ROW_HOLD_DELAY
> +		|| pdata->row_hold_ns < MIN_ROW_HOLD_DELAY ||
> +		((pdata->row_hold_ns % MIN_ROW_HOLD_DELAY) != 0)) {
> +		dev_err(&pdev->dev, "invalid keypad row hold time supplied\n");
> +		return -EINVAL;
> +	}
> +
> +	if (!pdata->debounce_ms
> +		|| ((pdata->debounce_ms % 5) != 0)
> +		|| pdata->debounce_ms > MAX_DEBOUNCE_TIME
> +		|| pdata->debounce_ms < MIN_DEBOUNCE_TIME) {
> +		dev_err(&pdev->dev, "invalid debounce time supplied\n");

Mixing style (logical || either in front of expression or after), please use
same style (and I prefer after).


> +		return -EINVAL;
> +	}
> +
> +	keymap_data = pdata->keymap_data;
> +	if (!keymap_data) {
> +		dev_err(&pdev->dev, "no keymap data supplied\n");
> +		return -EINVAL;
> +	}
> +
> +	kp = kzalloc(sizeof(*kp), GFP_KERNEL);
> +	if (!kp)
> +		return -ENOMEM;
> +
> +	keycodes = kzalloc(PM8058_MATRIX_MAX_SIZE * sizeof(*keycodes),
> +				 GFP_KERNEL);
> +	if (!keycodes) {
> +		rc = -ENOMEM;
> +		goto err_alloc_mem;
> +	}
> +
> +	platform_set_drvdata(pdev, kp);
> +
> +	kp->pdata	= pdata;
> +	kp->dev		= &pdev->dev;
> +	kp->keycodes	= keycodes;
> +	kp->pm_chip	= pm_chip;
> +
> +	kp->input = input_allocate_device();
> +	if (!kp->input) {
> +		dev_err(&pdev->dev, "unable to allocate input device\n");
> +		rc = -ENOMEM;
> +		goto err_alloc_device;
> +	}
> +
> +	kp->key_sense_irq = platform_get_irq(pdev, 0);
> +	if (kp->key_sense_irq < 0) {
> +		dev_err(&pdev->dev, "unable to get keypad sense irq\n");
> +		rc = -ENXIO;
> +		goto err_get_irq;
> +	}
> +
> +	kp->key_stuck_irq = platform_get_irq(pdev, 1);
> +	if (kp->key_stuck_irq < 0) {
> +		dev_err(&pdev->dev, "unable to get keypad stuck irq\n");
> +		rc = -ENXIO;
> +		goto err_get_irq;
> +	}
> +
> +	if (pdata->input_name)
> +		kp->input->name = pdata->input_name;
> +	else
> +		kp->input->name = "PMIC8058 keypad";
> +
> +	if (pdata->input_phys_device)
> +		kp->input->phys = pdata->input_phys_device;
> +	else
> +		kp->input->phys = "pmic8058_keypad/input0";

	kp->input->phys = pdata->input_phys_device ?: "pmic8058_keypad/input0";

Is shorter.

Thanks.

-- 
Dmitry

  parent reply	other threads:[~2010-11-17 18:02 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-10 12:47 [RFC v1 PATCH 0/6] Qualcomm PMIC8058 sub-device drivers Trilok Soni
2010-11-10 12:47 ` [RFC v1 PATCH 1/6] matrix_keypad: Increase the max limit of rows and columns Trilok Soni
2010-11-10 18:33   ` Eric Miao
2010-11-10 23:30     ` Dmitry Torokhov
2010-11-17 17:54       ` Dmitry Torokhov
2010-11-10 12:47 ` [RFC v1 PATCH 2/6] input: pm8058_keypad: Qualcomm PMIC8058 keypad controller driver Trilok Soni
2010-11-16  3:49   ` Trilok Soni
2010-11-17 18:02   ` Dmitry Torokhov [this message]
2010-12-06 18:14   ` Dmitry Torokhov
2010-12-07  9:22     ` Trilok Soni
2010-12-07  9:30       ` Dmitry Torokhov
2010-12-07  9:32         ` Trilok Soni
2011-01-06 11:56     ` [rtc-linux] " Anirudh Ghayal
2010-11-10 12:47 ` [RFC v1 PATCH 3/6] led: pmic8058: Add PMIC8058 leds driver Trilok Soni
2010-11-10 20:45   ` Lars-Peter Clausen
2010-11-10 23:28     ` Dmitry Torokhov
2010-11-10 23:50       ` Lars-Peter Clausen
2010-11-11 12:15     ` Trilok Soni
2010-12-06 13:44       ` Trilok Soni
2010-12-07 15:11         ` Lars-Peter Clausen
2010-12-07 15:47           ` Trilok Soni
2010-11-10 12:47 ` [RFC v1 PATCH 4/6] input: pmic8058_pwrkey: Add support for power key Trilok Soni
2010-11-11  7:21   ` Dmitry Torokhov
2010-11-11 12:00     ` Trilok Soni
2010-11-12  0:57       ` Dmitry Torokhov
2010-11-12  8:56         ` Trilok Soni
2010-11-12 19:58           ` Dmitry Torokhov
2010-11-10 12:48 ` [RFC v1 PATCH 5/6] input: pmic8058-othc: Add support for PM8058 based OTHC Trilok Soni
2010-11-16  3:08   ` Trilok Soni
2010-11-16  5:36   ` Datta, Shubhrajyoti
2010-11-16  6:36     ` Trilok Soni
2010-12-01  5:34       ` Anirudh Ghayal
2010-12-07 10:04   ` Dmitry Torokhov
2010-12-07 12:10     ` Anirudh Ghayal
2010-11-10 12:48 ` [RFC v1 PATCH 6/6] drivers: rtc: Add support for Qualcomm PMIC8058 RTC Trilok Soni
2010-11-12  8:53   ` Trilok Soni
2010-11-12 12:53   ` Lars-Peter Clausen
2010-11-12 15:17     ` [rtc-linux] " Anirudh Ghayal

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=20101117180240.GC6148@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rtc-linux@googlegroups.com \
    --cc=tsoni@codeaurora.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;
as well as URLs for NNTP newsgroup(s).