From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: James Ogletree <james.ogletree@cirrus.com>
Cc: <dmitry.torokhov@gmail.com>, Fred Treven <fred.treven@cirrus.com>,
"Ben Bright" <ben.bright@cirrus.com>,
Rob Herring <robh+dt@kernel.org>,
"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>, Lee Jones <lee@kernel.org>,
Jeff LaBundy <jeff@labundy.com>, Joel Stanley <joel@jms.id.au>,
Arnd Bergmann <arnd@arndb.de>, Jacky Bai <ping.bai@nxp.com>,
Jean Delvare <jdelvare@suse.de>,
Eddie James <eajames@linux.ibm.com>,
"Markus Schneider-Pargmann" <msp@baylibre.com>,
ChiYuan Huang <cy_huang@richtek.com>,
Randy Dunlap <rdunlap@infradead.org>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
<patches@cirrus.com>, <linux-input@vger.kernel.org>,
<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 2/2] Input: cs40l50 - Initial support for Cirrus Logic CS40L50
Date: Thu, 10 Aug 2023 10:30:05 +0000 [thread overview]
Message-ID: <20230810103005.GZ103419@ediswmail.ad.cirrus.com> (raw)
In-Reply-To: <20230809191032.820271-3-james.ogletree@cirrus.com>
On Wed, Aug 09, 2023 at 07:10:28PM +0000, James Ogletree wrote:
> Introduce support for Cirrus Logic Device CS40L50: a
> haptics driver with waveform memory DSP and closed-loop
> algorithms.
>
> Signed-off-by: James Ogletree <james.ogletree@cirrus.com>
> ---
> MAINTAINERS | 2 +
> drivers/input/misc/Kconfig | 33 +
> drivers/input/misc/Makefile | 3 +
> drivers/input/misc/cs40l50-i2c.c | 67 ++
> drivers/input/misc/cs40l50-spi.c | 67 ++
> drivers/input/misc/cs40l50.c | 1008 ++++++++++++++++++++++++++++++
> include/linux/input/cs40l50.h | 321 ++++++++++
Is this part not going to support streaming at some point? Fine
if not, but it seems likely to me and as such we should probably
follow the l26 stuff and make this an MFD from the start, even if
we haven't implemented the audio bits.
> +
> +static int cs40l50_pseq_write(struct cs40l50_private *cs40l50, u32 addr, u32 data)
> +{
> +
> +static int cs40l50_owt_upload(struct cs40l50_private *cs40l50, s16 *in_data, u32 in_data_nibbles)
> +{
These pseq and OWT bits, could they be shared with l26?
Definitely worth syncing with those guys, my assumption is the
wavetable/pseq won't have changed much and it might be nice to
factor these bits out into some library code that both drivers
can use.
> +err_free:
> + if (is_new)
> + error ? kfree(new_effect) : list_add(&new_effect->list, &cs40l50->effect_head);
This is a bit of an excessive use for a ternary, just make it an
if.
> +static int cs40l50_erase_effect(struct input_dev *dev, int effect_id)
> +{
> + int error = 0;
> + struct cs40l50_private *cs40l50 = input_get_drvdata(dev);
> + struct cs40l50_effect *effect, *effect_owt;
> +
> + mutex_lock(&cs40l50->lock);
> +
> + effect = cs40l50_find_effect(cs40l50, dev->ff->effects[effect_id].id);
> + if (!effect) {
> + error = -EINVAL;
> + goto err_mutex;
> + }
> +
> + if (effect->mapping != CS40L50_GPIO_MAPPING_INVALID) {
> + error = cs40l50_dsp_write(cs40l50, effect->mapping, CS40L50_GPI_DISABLE);
> + if (error)
> + goto err_mutex;
> + }
> +
> + if (effect->wvfrm_bank == CS40L50_WVFRM_BANK_OWT) {
> + error = cs40l50_dsp_write(cs40l50, CS40L50_DSP_VIRTUAL1_MBOX_1,
> + CS40L50_MBOX_CMD_OWT_DELETE | effect->trigger_index);
> + if (error)
> + goto err_mutex;
> +
> + list_for_each_entry(effect_owt, &cs40l50->effect_head, list) {
> + if (effect_owt->wvfrm_bank == CS40L50_WVFRM_BANK_OWT &&
> + effect_owt->trigger_index > effect->trigger_index)
> + effect_owt->trigger_index--;
> + }
> + }
> +
> + list_del(&effect->list);
> + kfree(effect);
> +err_mutex:
> + mutex_unlock(&cs40l50->lock);
> +
> + return error;
> +}
I seem to remember add/erase needed to get pushed to the work
queue too, not because the framework might call it in atomic
context, but in order to ensure ordering with the start/stops.
> +int cs40l50_probe(struct cs40l50_private *cs40l50)
> +{
> + int error, i, irq;
> + u32 val;
> +
> + mutex_init(&cs40l50->lock);
> +
> + error = devm_regulator_bulk_get(cs40l50->dev, ARRAY_SIZE(cs40l50_supplies),
> + cs40l50_supplies);
> + if (error)
> + return dev_err_probe(cs40l50->dev, error, "Failed to request supplies\n");
> +
> + error = regulator_bulk_enable(ARRAY_SIZE(cs40l50_supplies), cs40l50_supplies);
> + if (error)
> + return dev_err_probe(cs40l50->dev, error, "Failed to enable supplies\n");
> +
> + cs40l50->reset_gpio = devm_gpiod_get_optional(cs40l50->dev, "reset", GPIOD_OUT_HIGH);
> + if (IS_ERR(cs40l50->reset_gpio)) {
> + error = PTR_ERR(cs40l50->reset_gpio);
> + goto err;
> + }
> +
> + usleep_range(CS40L50_MIN_RESET_PULSE_WIDTH_US, CS40L50_MIN_RESET_PULSE_WIDTH_US + 100);
> +
> + gpiod_set_value_cansleep(cs40l50->reset_gpio, 0);
> +
> + usleep_range(CS40L50_CP_READY_DELAY_US, CS40L50_CP_READY_DELAY_US + 1000);
> +
> + for (i = 0; i < CS40L50_DSP_TIMEOUT_COUNT; i++) {
> + error = cs40l50_dsp_read(cs40l50, CS40L50_DSP1_HALO_STATE, &val);
> + if (!error && val < 0xFFFF && val >= CS40L50_HALO_STATE_BOOT_DONE)
> + break;
> +
> + usleep_range(CS40L50_DSP_POLL_US, CS40L50_DSP_POLL_US + 100);
> + }
> +
> + if (i == CS40L50_DSP_TIMEOUT_COUNT) {
> + dev_err(cs40l50->dev, "Firmware boot failed: %d, halo state = %#x\n", error, val);
> + goto err;
> + }
> +
> + cs40l50->vibe_workqueue = alloc_ordered_workqueue("cs40l50_workqueue", WQ_HIGHPRI);
> + if (!cs40l50->vibe_workqueue) {
> + error = -ENOMEM;
> + goto err;
> + }
> +
> + INIT_WORK(&cs40l50->vibe_start_work, cs40l50_vibe_start_worker);
> + INIT_WORK(&cs40l50->vibe_stop_work, cs40l50_vibe_stop_worker);
> +
> + error = cs40l50_cs_dsp_init(cs40l50);
> + if (error)
> + goto err;
> +
> + error = cs40l50_input_init(cs40l50);
> + if (error)
> + goto err;
> +
> + error = cs40l50_patch_firmware(cs40l50);
> + if (error)
> + goto err;
> +
Doing this from probe, with a sync firmware load, can be a
little problematic as the firmware is often not available if
the driver is builtin rather than a module.
Fairly quick review as I am on holiday at the moment, but will
check back next week.
Thanks,
Charles
next prev parent reply other threads:[~2023-08-10 10:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-09 19:10 [PATCH v3 0/2] Add support for CS40L50 James Ogletree
2023-08-09 19:10 ` [PATCH v3 1/2] dt-bindings: input: cirrus,cs40l50: Support " James Ogletree
2023-08-10 6:19 ` Krzysztof Kozlowski
2023-08-09 19:10 ` [PATCH v3 2/2] Input: cs40l50 - Initial support for Cirrus Logic CS40L50 James Ogletree
2023-08-10 6:17 ` Krzysztof Kozlowski
2023-08-15 15:56 ` James Ogletree
2023-08-15 19:23 ` Krzysztof Kozlowski
2023-08-10 10:30 ` Charles Keepax [this message]
2023-08-15 22:33 ` James Ogletree
2023-08-16 8:11 ` Charles Keepax
2023-08-11 4:07 ` Jeff LaBundy
2023-08-16 21:02 ` James Ogletree
2023-08-22 12:43 ` Jeff LaBundy
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=20230810103005.GZ103419@ediswmail.ad.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=arnd@arndb.de \
--cc=ben.bright@cirrus.com \
--cc=conor+dt@kernel.org \
--cc=cy_huang@richtek.com \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=eajames@linux.ibm.com \
--cc=fred.treven@cirrus.com \
--cc=james.ogletree@cirrus.com \
--cc=jdelvare@suse.de \
--cc=jeff@labundy.com \
--cc=joel@jms.id.au \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lee@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=msp@baylibre.com \
--cc=patches@cirrus.com \
--cc=ping.bai@nxp.com \
--cc=rdunlap@infradead.org \
--cc=robh+dt@kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/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).