Re: [PATCH v2 5/7] mfd: Add RTL8231 core device

Andy Shevchenko
2021-05-17T21:19:03Z

On Mon, May 17, 2021 at 10:28 PM Sander Vanheule <sander@svanheule.net> wrote:
>
> The RTL8231 is implemented as an MDIO device, and provides a regmap
> interface for register access by the core and child devices.
>
> The chip can also be a device on an SMI bus, an I2C-like bus by Realtek.
> Since kernel support for SMI is limited, and no real-world SMI
> implementations have been encountered for this device, this is currently
> unimplemented. The use of the regmap interface should make any future
> support relatively straightforward.
>
> After reset, all pins are muxed to GPIO inputs before the pin drivers
> are enabled. This is done to prevent accidental system resets, when a
> pin is connected to the parent SoC's reset line.

> [missing MDIO_BUS dependency, provided via REGMAP_MDIO]
> Reported-by: kernel test robot <lkp@intel.com>

What is the culprit? Shouldn't this have a Fixes tag?

...

> + Support for the Realtek RTL8231 GPIO and LED expander.
> + Provides up to 37 GPIOs, 88 LEDs, and one PWM output.

> + When built as a module, this module will be named rtl8231_expander.

The name is not the one it will be according to Makefile.

> +obj-$(CONFIG_MFD_RTL8231) += rtl8231.o

...

> +#include <linux/bits.h>
> +#include <linux/bitfield.h>
> +#include <linux/delay.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mdio.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/property.h>
> +#include <linux/regmap.h>

...

> +static int rtl8231_init(struct device *dev, struct regmap *map)
> +{
> + unsigned int ready_code;
> + unsigned int v;

> + int err = 0;

Redundant assignment.

> + err = regmap_read(map, RTL8231_REG_FUNC1, &v);

> + ready_code = FIELD_GET(RTL8231_FUNC1_READY_CODE_MASK, v);

If we got an error why we need a read_core, what for?

> + if (err) {
> + dev_err(dev, "failed to read READY_CODE\n");
> + return err;

> + } else if (ready_code != RTL8231_FUNC1_READY_CODE_VALUE) {

Redundant 'else'.

> + dev_err(dev, "RTL8231 not present or ready 0x%x != 0x%x\n",
> + ready_code, RTL8231_FUNC1_READY_CODE_VALUE);
> + return -ENODEV;
> + }

...

> + return err;

Is it somehow different to 0?

> +}

...

> +static int rtl8231_mdio_probe(struct mdio_device *mdiodev)
> +{
> + struct device *dev = &mdiodev->dev;
> + struct regmap_field *led_start;
> + struct regmap *map;
> + int err;
> +
> + map = devm_regmap_init_mdio(mdiodev, &rtl8231_mdio_regmap_config);

> +

Redundant blank line.

> + if (IS_ERR(map)) {
> + dev_err(dev, "failed to init regmap\n");
> + return PTR_ERR(map);
> + }
> +
> + led_start = devm_regmap_field_alloc(dev, map, RTL8231_FIELD_LED_START);
> + if (IS_ERR(led_start))
> + return PTR_ERR(led_start);
> +
> + dev_set_drvdata(dev, led_start);
> +
> + mdiodev->reset_gpio = gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
> + device_property_read_u32(dev, "reset-assert-delay", &mdiodev->reset_assert_delay);
> + device_property_read_u32(dev, "reset-deassert-delay", &mdiodev->reset_deassert_delay);
> +
> + err = rtl8231_init(dev, map);
> + if (err)

Resource leakage.

> + return err;
> +
> + /* LED_START enables power to output pins, and starts the LED engine */
> + regmap_field_write(led_start, 1);

> + return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, rtl8231_cells,
> + ARRAY_SIZE(rtl8231_cells), NULL, 0, NULL);

Ditto.

> +}

...

> +#ifdef CONFIG_PM

Replace this with __maybe_unused attribute.

> +#define RTL8231_PM_OPS (&rtl8231_pm_ops)

> +#else
> +#define RTL8231_PM_OPS NULL
> +#endif /* CONFIG_PM */

...

> +static const struct of_device_id rtl8231_of_match[] = {
> + { .compatible = "realtek,rtl8231" },
> + {},

No need to have a comma for the terminator line.

> +};

--
With Best Regards,
Andy Shevchenko