From: Markuss Broks <markuss.broks@gmail.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>,
Maksym Holovach <nergzd@nergzd723.xyz>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
Krzysztof Kozlowski <krzk@kernel.org>
Subject: Re: [PATCH 2/3] soc: samsung: Add a driver for Samsung SPEEDY host controller
Date: Tue, 17 Dec 2024 19:28:57 +0200 [thread overview]
Message-ID: <9d7b9ee1-9b45-4892-826b-e2802adff990@gmail.com> (raw)
In-Reply-To: <3c067b26-cfe8-4939-afce-5c8753767715@wanadoo.fr>
Hi Christophe,
On 12/14/24 5:52 PM, Christophe JAILLET wrote:
> Le 12/12/2024 à 22:09, Markuss Broks a écrit :
>> Add a driver for Samsung SPEEDY serial bus host controller.
>> SPEEDY is a proprietary 1 wire serial bus used by Samsung
>> in various devices (usually mobile), like Samsung Galaxy
>> phones. It is usually used for connecting PMIC or various
>> other peripherals, like audio codecs or RF components.
>>
>> This bus can address at most 1MiB (4 bit device address,
>> 8 bit registers per device, 8 bit wide registers:
>> 256*256*16 = 1MiB of address space.
>
> ...
>
>> +static int _speedy_read(struct speedy_controller *speedy, u32 reg,
>> u32 addr, u32 *val)
>> +{
>> + int ret;
>> + u32 cmd, int_ctl, int_status;
>> +
>> + mutex_lock(&speedy->io_lock);
>
> All error handling paths fail to release the mutex.
> guard(mutex) would help here.
True, I didn't know that such a thing existed, thanks for the tip! :)
>
>> +
>> + ret = speedy_fifo_reset(speedy);
>> + if (ret)
>> + return ret;
>> +
>> + ret = regmap_set_bits(speedy->map, SPEEDY_FIFO_CTRL,
>> + SPEEDY_RX_LENGTH(1) | SPEEDY_TX_LENGTH(1));
>> + if (ret)
>> + return ret;
>> +
>> + cmd = SPEEDY_ACCESS_RANDOM | SPEEDY_DIRECTION_READ |
>> + SPEEDY_DEVICE(reg) | SPEEDY_ADDRESS(addr);
>> +
>> + int_ctl = SPEEDY_TRANSFER_DONE_EN | SPEEDY_FIFO_RX_ALMOST_FULL_EN |
>> + SPEEDY_RX_FIFO_INT_TRAILER_EN | SPEEDY_RX_MODEBIT_ERR_EN |
>> + SPEEDY_RX_GLITCH_ERR_EN | SPEEDY_RX_ENDBIT_ERR_EN |
>> + SPEEDY_REMOTE_RESET_REQ_EN;
>> +
>> + ret = speedy_int_clear(speedy);
>> + if (ret)
>> + return ret;
>> +
>> + ret = regmap_write(speedy->map, SPEEDY_INT_ENABLE, int_ctl);
>> + if (ret)
>> + return ret;
>> +
>> + ret = regmap_write(speedy->map, SPEEDY_CMD, cmd);
>> + if (ret)
>> + return ret;
>> +
>> + /* Wait for xfer done */
>> + ret = regmap_read_poll_timeout(speedy->map, SPEEDY_INT_STATUS,
>> int_status,
>> + int_status & SPEEDY_TRANSFER_DONE, 5000, 50000);
>> + if (ret)
>> + return ret;
>> +
>> + ret = regmap_read(speedy->map, SPEEDY_RX_DATA, val);
>> + if (ret)
>> + return ret;
>> +
>> + ret = speedy_int_clear(speedy);
>> +
>> + mutex_unlock(&speedy->io_lock);
>> +
>> + return ret;
>> +}
>
> ...
>
>> +static int _speedy_write(struct speedy_controller *speedy, u32 reg,
>> u32 addr, u32 val)
>> +{
>> + int ret;
>> + u32 cmd, int_ctl, int_status;
>> +
>> + mutex_lock(&speedy->io_lock);
>> +
>> + ret = speedy_fifo_reset(speedy);
>> + if (ret)
>> + return ret;
>
> All error handling paths fail to release the mutex.
> guard(mutex) would help here.
>
>> +
>> + ret = regmap_set_bits(speedy->map, SPEEDY_FIFO_CTRL,
>> + SPEEDY_RX_LENGTH(1) | SPEEDY_TX_LENGTH(1));
>> + if (ret)
>> + return ret;
>> +
>> + cmd = SPEEDY_ACCESS_RANDOM | SPEEDY_DIRECTION_WRITE |
>> + SPEEDY_DEVICE(reg) | SPEEDY_ADDRESS(addr);
>> +
>> + int_ctl = (SPEEDY_TRANSFER_DONE_EN |
>> + SPEEDY_FIFO_TX_ALMOST_EMPTY_EN |
>> + SPEEDY_TX_LINE_BUSY_ERR_EN |
>> + SPEEDY_TX_STOPBIT_ERR_EN |
>> + SPEEDY_REMOTE_RESET_REQ_EN);
>> +
>> + ret = speedy_int_clear(speedy);
>> + if (ret)
>> + return ret;
>> +
>> + ret = regmap_write(speedy->map, SPEEDY_INT_ENABLE, int_ctl);
>> + if (ret)
>> + return ret;
>> +
>> + ret = regmap_write(speedy->map, SPEEDY_CMD, cmd);
>> + if (ret)
>> + return ret;
>> +
>> + ret = regmap_write(speedy->map, SPEEDY_TX_DATA, val);
>> + if (ret)
>> + return ret;
>> +
>> + /* Wait for xfer done */
>> + ret = regmap_read_poll_timeout(speedy->map, SPEEDY_INT_STATUS,
>> int_status,
>> + int_status & SPEEDY_TRANSFER_DONE, 5000, 50000);
>> + if (ret)
>> + return ret;
>> +
>> + speedy_int_clear(speedy);
>> +
>> + mutex_unlock(&speedy->io_lock);
>> +
>> + return 0;
>> +}
>
> ...
>
>> +/**
>> + * speedy_get_by_phandle() - internal get speedy device handle
>> + * @np: pointer to OF device node of device
>> + *
>> + * Return: 0 on success, -errno otherwise
>
> On success, a handle is returned, not 0.
>
>> + */
>> +static const struct speedy_device *speedy_get_device(struct
>> device_node *np)
>> +{
> ...
>
>> +out:
>> + of_node_put(speedy_np);
>> + return handle;
>> +}
>
> ...
>
>> +static int speedy_probe(struct platform_device *pdev)
>> +{
>> + struct device *dev = &pdev->dev;
>> + struct speedy_controller *speedy;
>> + void __iomem *mem;
>> + int ret;
>> +
>> + speedy = devm_kzalloc(dev, sizeof(struct speedy_controller),
>> GFP_KERNEL);
>> + if (!speedy)
>> + return -ENOMEM;
>> +
>> + platform_set_drvdata(pdev, speedy);
>> + speedy->pdev = pdev;
>> +
>> + mutex_init(&speedy->io_lock);
>> +
>> + mem = devm_platform_ioremap_resource(pdev, 0);
>> + if (IS_ERR(mem))
>> + return dev_err_probe(dev, PTR_ERR(mem), "Failed to ioremap
>> memory\n");
>> +
>> + speedy->map = devm_regmap_init_mmio(dev, mem, &speedy_map_cfg);
>> + if (IS_ERR(speedy->map))
>> + return dev_err_probe(dev, PTR_ERR(speedy->map), "Failed to
>> init the regmap\n");
>> +
>> + /* Clear any interrupt status remaining */
>> + ret = speedy_int_clear(speedy);
>> + if (ret)
>> + return ret;
>> +
>> + /* Reset the controller */
>> + ret = regmap_set_bits(speedy->map, SPEEDY_CTRL, SPEEDY_SW_RST);
>> + if (ret)
>> + return ret;
>> +
>> + msleep(20);
>> +
>> + /* Enable the hw */
>> + ret = regmap_set_bits(speedy->map, SPEEDY_CTRL, SPEEDY_ENABLE);
>> + if (ret)
>> + return ret;
>> +
>> + msleep(20);
>> +
>> + /* Probe child devices */
>> + ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, dev);
>> + if (ret)
>> + dev_err(dev, "Failed to populate child devices: %d\n", ret);
>
> Could be dev_err_probe() as well, at least for consistency.
I agree, will fix in the next revision.
>
>> +
>> + return ret;
>> +}
>
> ...
>
> CJ
- Markuss
next prev parent reply other threads:[~2024-12-17 17:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-12 21:09 [PATCH 0/3] Add Samsung SPEEDY serial bus host controller driver Markuss Broks
2024-12-12 21:09 ` [PATCH 1/3] dt-bindings: soc: samsung: exynos-speedy: Document SPEEDY host controller bindings Markuss Broks
2024-12-12 22:30 ` Rob Herring (Arm)
2024-12-13 7:40 ` Krzysztof Kozlowski
2024-12-13 9:47 ` Markuss Broks
2024-12-12 21:09 ` [PATCH 2/3] soc: samsung: Add a driver for Samsung SPEEDY host controller Markuss Broks
2024-12-13 7:49 ` Krzysztof Kozlowski
2024-12-13 9:42 ` Markuss Broks
2024-12-13 13:55 ` Krzysztof Kozlowski
2024-12-14 12:06 ` Markuss Broks
2024-12-14 14:43 ` Markus Elfring
2024-12-17 17:31 ` Markuss Broks
2024-12-14 15:52 ` Christophe JAILLET
2024-12-17 17:28 ` Markuss Broks [this message]
2024-12-12 21:09 ` [PATCH 3/3] MAINTAINERS: Add entry for the Samsung Exynos " Markuss Broks
2024-12-13 8:42 ` [PATCH 0/3] Add Samsung SPEEDY serial bus host controller driver Krzysztof Kozlowski
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=9d7b9ee1-9b45-4892-826b-e2802adff990@gmail.com \
--to=markuss.broks@gmail.com \
--cc=alim.akhtar@samsung.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=ivo.ivanov.ivanov1@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=nergzd@nergzd723.xyz \
--cc=robh@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.