The driver and its solely consumer (via platform data) are using old
GPIO APIs, convert them for good. On top some spring cleanups and fixes.
Andy Shevchenko (10):
misc: eeprom_93xx46: Make use of device properties
eeprom: digsy_mtc: Fix 93xx46 driver probe failure
eeprom: digsy_mtc: Convert to use GPIO descriptors
misc: eeprom_93xx46: Hide legacy platform data in the driver
misc: eeprom_93xx46: Remove ->prepare() and ->finish() customisation
misc: eeprom_93xx46: Use spi_message_init_with_transfers()
misc: eeprom_93xx46: Convert to use kstrtox()
misc: eeprom_93xx46: Replace explicit castings with proper specifiers
misc: eeprom_93xx46: Use string_choices API instead of ternary
operator
misc: eeprom_93xx46: Convert to DEVICE_ATTR_WO()
drivers/misc/eeprom/digsy_mtc_eeprom.c | 46 +++----
drivers/misc/eeprom/eeprom_93xx46.c | 178 ++++++++++++-------------
include/linux/eeprom_93xx46.h | 32 -----
3 files changed, 102 insertions(+), 154 deletions(-)
delete mode 100644 include/linux/eeprom_93xx46.h
--
2.43.0.rc1.1336.g36b5255a03ac
This converts the driver to use GPIO descriptors exclusively
to retrieve GPIO lines. Drop the old GPIO handling in favor of
the core managing it exclusively.
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/misc/eeprom/digsy_mtc_eeprom.c | 46 +++++++++++---------------
1 file changed, 20 insertions(+), 26 deletions(-)
diff --git a/drivers/misc/eeprom/digsy_mtc_eeprom.c b/drivers/misc/eeprom/digsy_mtc_eeprom.c
index 4eddc5ba1af9..88888485e6f8 100644
--- a/drivers/misc/eeprom/digsy_mtc_eeprom.c
+++ b/drivers/misc/eeprom/digsy_mtc_eeprom.c
@@ -14,13 +14,12 @@
* and delete this driver.
*/
-#include <linux/gpio.h>
#include <linux/gpio/machine.h>
#include <linux/init.h>
#include <linux/platform_device.h>
+#include <linux/property.h>
#include <linux/spi/spi.h>
#include <linux/spi/spi_gpio.h>
-#include <linux/eeprom_93xx46.h>
#define GPIO_EEPROM_CLK 216
#define GPIO_EEPROM_CS 210
@@ -29,22 +28,13 @@
#define GPIO_EEPROM_OE 255
#define EE_SPI_BUS_NUM 1
-static void digsy_mtc_op_prepare(void *p)
-{
- /* enable */
- gpio_set_value(GPIO_EEPROM_OE, 0);
-}
+static const struct property_entry digsy_mtc_spi_properties[] = {
+ PROPERTY_ENTRY_U32("data-size", 8),
+ { }
+};
-static void digsy_mtc_op_finish(void *p)
-{
- /* disable */
- gpio_set_value(GPIO_EEPROM_OE, 1);
-}
-
-struct eeprom_93xx46_platform_data digsy_mtc_eeprom_data = {
- .flags = EE_ADDR8 | EE_SIZE1K,
- .prepare = digsy_mtc_op_prepare,
- .finish = digsy_mtc_op_finish,
+static const struct software_node digsy_mtc_spi_node = {
+ .properties = digsy_mtc_spi_properties,
};
static struct spi_gpio_platform_data eeprom_spi_gpio_data = {
@@ -70,18 +60,19 @@ static struct gpiod_lookup_table eeprom_spi_gpiod_table = {
"miso", GPIO_ACTIVE_HIGH),
GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CS,
"cs", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_OE,
+ "select", GPIO_ACTIVE_LOW),
{ },
},
};
static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = {
{
- .modalias = "93xx46",
+ .modalias = "eeprom-93xx46",
.max_speed_hz = 1000000,
.bus_num = EE_SPI_BUS_NUM,
.chip_select = 0,
.mode = SPI_MODE_0,
- .platform_data = &digsy_mtc_eeprom_data,
},
};
@@ -89,15 +80,18 @@ static int __init digsy_mtc_eeprom_devices_init(void)
{
int ret;
- ret = gpio_request_one(GPIO_EEPROM_OE, GPIOF_OUT_INIT_HIGH,
- "93xx46 EEPROMs OE");
- if (ret) {
- pr_err("can't request gpio %d\n", GPIO_EEPROM_OE);
- return ret;
- }
gpiod_add_lookup_table(&eeprom_spi_gpiod_table);
spi_register_board_info(digsy_mtc_eeprom_info,
ARRAY_SIZE(digsy_mtc_eeprom_info));
- return platform_device_register(&digsy_mtc_eeprom);
+
+ ret = device_add_software_node(&digsy_mtc_eeprom.dev, &digsy_mtc_spi_node);
+ if (ret)
+ return ret;
+
+ ret = platform_device_register(&digsy_mtc_eeprom);
+ if (ret)
+ device_remove_software_node(&digsy_mtc_eeprom.dev);
+
+ return ret;
}
device_initcall(digsy_mtc_eeprom_devices_init);
--
2.43.0.rc1.1336.g36b5255a03ac
The update to support other (bigger) types of EEPROMs broke
the driver loading due to removal of the default size.
Fix this by adding the respective (new) flag to the platform data.
Fixes: 14374fbb3f06 ("misc: eeprom_93xx46: Add new 93c56 and 93c66 compatible strings")
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/misc/eeprom/digsy_mtc_eeprom.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/eeprom/digsy_mtc_eeprom.c b/drivers/misc/eeprom/digsy_mtc_eeprom.c
index f1f766b70965..4eddc5ba1af9 100644
--- a/drivers/misc/eeprom/digsy_mtc_eeprom.c
+++ b/drivers/misc/eeprom/digsy_mtc_eeprom.c
@@ -42,7 +42,7 @@ static void digsy_mtc_op_finish(void *p)
}
struct eeprom_93xx46_platform_data digsy_mtc_eeprom_data = {
- .flags = EE_ADDR8,
+ .flags = EE_ADDR8 | EE_SIZE1K,
.prepare = digsy_mtc_op_prepare,
.finish = digsy_mtc_op_finish,
};
--
2.43.0.rc1.1336.g36b5255a03ac
There is no need to have an explicit casting when we can simply use
the correct printf() specifier.
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/misc/eeprom/eeprom_93xx46.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/misc/eeprom/eeprom_93xx46.c b/drivers/misc/eeprom/eeprom_93xx46.c
index 18a3b534ea73..ac485b2827db 100644
--- a/drivers/misc/eeprom/eeprom_93xx46.c
+++ b/drivers/misc/eeprom/eeprom_93xx46.c
@@ -162,8 +162,8 @@ static int eeprom_93xx46_read(void *priv, unsigned int off,
ndelay(250);
if (err) {
- dev_err(&edev->spi->dev, "read %zu bytes at %d: err. %d\n",
- nbytes, (int)off, err);
+ dev_err(&edev->spi->dev, "read %zu bytes at %u: err. %d\n",
+ nbytes, off, err);
break;
}
@@ -274,7 +274,8 @@ static int eeprom_93xx46_write(void *priv, unsigned int off,
{
struct eeprom_93xx46_dev *edev = priv;
char *buf = val;
- int i, ret, step = 1;
+ int ret, step = 1;
+ unsigned int i;
if (unlikely(off >= edev->size))
return -EFBIG;
@@ -301,8 +302,7 @@ static int eeprom_93xx46_write(void *priv, unsigned int off,
for (i = 0; i < count; i += step) {
ret = eeprom_93xx46_write_word(edev, &buf[i], off + i);
if (ret) {
- dev_err(&edev->spi->dev, "write failed at %d: %d\n",
- (int)off + i, ret);
+ dev_err(&edev->spi->dev, "write failed at %u: %d\n", off + i, ret);
break;
}
}
--
2.43.0.rc1.1336.g36b5255a03ac
sscanf() is a heavy one and moreover requires additional boundary checks.
Convert driver to use kstrtobool() in eeprom_93xx46_store_erase().
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/misc/eeprom/eeprom_93xx46.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/misc/eeprom/eeprom_93xx46.c b/drivers/misc/eeprom/eeprom_93xx46.c
index 3f885bac72c2..18a3b534ea73 100644
--- a/drivers/misc/eeprom/eeprom_93xx46.c
+++ b/drivers/misc/eeprom/eeprom_93xx46.c
@@ -10,7 +10,7 @@
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/gpio/consumer.h>
-#include <linux/kernel.h>
+#include <linux/kstrtox.h>
#include <linux/log2.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
@@ -366,9 +366,13 @@ static ssize_t eeprom_93xx46_store_erase(struct device *dev,
const char *buf, size_t count)
{
struct eeprom_93xx46_dev *edev = dev_get_drvdata(dev);
- int erase = 0, ret;
+ bool erase;
+ int ret;
+
+ ret = kstrtobool(buf, &erase);
+ if (ret)
+ return ret;
- sscanf(buf, "%d", &erase);
if (erase) {
ret = eeprom_93xx46_ew(edev, 1);
if (ret)
--
2.43.0.rc1.1336.g36b5255a03ac
On Wed, May 8, 2024 at 8:49 PM Andy Shevchenko
<[email protected]> wrote:
> This converts the driver to use GPIO descriptors exclusively
> to retrieve GPIO lines. Drop the old GPIO handling in favor of
> the core managing it exclusively.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
Reviewed-by: Linus Walleij <[email protected]>
Yours,
Linus Walleij
On Wed, May 8, 2024 at 8:49 PM Andy Shevchenko
<[email protected]> wrote:
> sscanf() is a heavy one and moreover requires additional boundary checks.
> Convert driver to use kstrtobool() in eeprom_93xx46_store_erase().
>
> Signed-off-by: Andy Shevchenko <[email protected]>
Reviewed-by: Linus Walleij <[email protected]>
Yours,
Linus Walleij
On Wed, May 8, 2024 at 8:49 PM Andy Shevchenko
<[email protected]> wrote:
> There is no need to have an explicit casting when we can simply use
> the correct printf() specifier.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
Reviewed-by: Linus Walleij <[email protected]>
Yours,
Linus Walleij