From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Andy Shevchenko <andy@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Robin van der Gracht <robin@protonic.nl>,
Paul Burton <paulburton@kernel.org>
Subject: [PATCH v3 2/9] auxdisplay: linedisp: Allocate buffer for the string
Date: Mon, 19 Feb 2024 18:58:01 +0200 [thread overview]
Message-ID: <20240219170337.2161754-3-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20240219170337.2161754-1-andriy.shevchenko@linux.intel.com>
Always allocate a buffer for the currently displayed characters.
It makes the line display API simpler.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/auxdisplay/ht16k33.c | 8 +++-----
drivers/auxdisplay/img-ascii-lcd.c | 17 +++++++----------
drivers/auxdisplay/line-display.c | 11 +++++++----
drivers/auxdisplay/line-display.h | 3 +--
4 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c
index 32d3afd29177..19805f39a257 100644
--- a/drivers/auxdisplay/ht16k33.c
+++ b/drivers/auxdisplay/ht16k33.c
@@ -92,7 +92,6 @@ struct ht16k33_seg {
struct seg14_conversion_map seg14;
} map;
unsigned int map_size;
- char curr[4];
};
struct ht16k33_priv {
@@ -457,7 +456,7 @@ static void ht16k33_seg7_update(struct work_struct *work)
struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
work.work);
struct ht16k33_seg *seg = &priv->seg;
- char *s = seg->curr;
+ char *s = seg->linedisp.buf;
uint8_t buf[9];
buf[0] = map_to_seg7(&seg->map.seg7, *s++);
@@ -478,7 +477,7 @@ static void ht16k33_seg14_update(struct work_struct *work)
struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
work.work);
struct ht16k33_seg *seg = &priv->seg;
- char *s = seg->curr;
+ char *s = seg->linedisp.buf;
uint8_t buf[8];
put_unaligned_le16(map_to_seg14(&seg->map.seg14, *s++), buf);
@@ -700,8 +699,7 @@ static int ht16k33_seg_probe(struct device *dev, struct ht16k33_priv *priv,
if (err)
return err;
- err = linedisp_register(&seg->linedisp, dev, 4, seg->curr,
- &ht16k33_linedisp_ops);
+ err = linedisp_register(&seg->linedisp, dev, 4, &ht16k33_linedisp_ops);
if (err)
goto err_remove_map_file;
diff --git a/drivers/auxdisplay/img-ascii-lcd.c b/drivers/auxdisplay/img-ascii-lcd.c
index ecfb1c05bf55..925c4cd101e9 100644
--- a/drivers/auxdisplay/img-ascii-lcd.c
+++ b/drivers/auxdisplay/img-ascii-lcd.c
@@ -37,7 +37,6 @@ struct img_ascii_lcd_config {
* @regmap: the regmap through which LCD registers are accessed
* @offset: the offset within regmap to the start of the LCD registers
* @cfg: pointer to the LCD model configuration
- * @curr: the string currently displayed on the LCD
*/
struct img_ascii_lcd_ctx {
struct linedisp linedisp;
@@ -47,7 +46,6 @@ struct img_ascii_lcd_ctx {
};
u32 offset;
const struct img_ascii_lcd_config *cfg;
- char curr[] __aligned(8);
};
/*
@@ -61,12 +59,12 @@ static void boston_update(struct linedisp *linedisp)
ulong val;
#if BITS_PER_LONG == 64
- val = *((u64 *)&ctx->curr[0]);
+ val = *((u64 *)&linedisp->buf[0]);
__raw_writeq(val, ctx->base);
#elif BITS_PER_LONG == 32
- val = *((u32 *)&ctx->curr[0]);
+ val = *((u32 *)&linedisp->buf[0]);
__raw_writel(val, ctx->base);
- val = *((u32 *)&ctx->curr[4]);
+ val = *((u32 *)&linedisp->buf[4]);
__raw_writel(val, ctx->base + 4);
#else
# error Not 32 or 64 bit
@@ -93,7 +91,7 @@ static void malta_update(struct linedisp *linedisp)
for (i = 0; i < linedisp->num_chars; i++) {
err = regmap_write(ctx->regmap,
- ctx->offset + (i * 8), ctx->curr[i]);
+ ctx->offset + (i * 8), linedisp->buf[i]);
if (err)
break;
}
@@ -195,7 +193,7 @@ static void sead3_update(struct linedisp *linedisp)
err = regmap_write(ctx->regmap,
ctx->offset + SEAD3_REG_LCD_DATA,
- ctx->curr[i]);
+ linedisp->buf[i]);
if (err)
break;
}
@@ -236,7 +234,7 @@ static int img_ascii_lcd_probe(struct platform_device *pdev)
struct img_ascii_lcd_ctx *ctx;
int err;
- ctx = devm_kzalloc(dev, sizeof(*ctx) + cfg->num_chars, GFP_KERNEL);
+ ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
@@ -253,8 +251,7 @@ static int img_ascii_lcd_probe(struct platform_device *pdev)
return PTR_ERR(ctx->base);
}
- err = linedisp_register(&ctx->linedisp, dev, cfg->num_chars, ctx->curr,
- &cfg->ops);
+ err = linedisp_register(&ctx->linedisp, dev, cfg->num_chars, &cfg->ops);
if (err)
return err;
diff --git a/drivers/auxdisplay/line-display.c b/drivers/auxdisplay/line-display.c
index 13be7c2f6bc3..e2b546210f8d 100644
--- a/drivers/auxdisplay/line-display.c
+++ b/drivers/auxdisplay/line-display.c
@@ -265,6 +265,7 @@ static void linedisp_release(struct device *dev)
kfree(linedisp->map);
kfree(linedisp->message);
+ kfree(linedisp->buf);
ida_free(&linedisp_id, linedisp->id);
}
@@ -316,14 +317,12 @@ static int linedisp_init_map(struct linedisp *linedisp)
* @linedisp: pointer to character line display structure
* @parent: parent device
* @num_chars: the number of characters that can be displayed
- * @buf: pointer to a buffer that can hold @num_chars characters
* @ops: character line display operations
*
* Return: zero on success, else a negative error code.
*/
int linedisp_register(struct linedisp *linedisp, struct device *parent,
- unsigned int num_chars, char *buf,
- const struct linedisp_ops *ops)
+ unsigned int num_chars, const struct linedisp_ops *ops)
{
int err;
@@ -331,7 +330,6 @@ int linedisp_register(struct linedisp *linedisp, struct device *parent,
linedisp->dev.parent = parent;
linedisp->dev.type = &linedisp_type;
linedisp->ops = ops;
- linedisp->buf = buf;
linedisp->num_chars = num_chars;
linedisp->scroll_rate = DEFAULT_SCROLL_RATE;
@@ -343,6 +341,11 @@ int linedisp_register(struct linedisp *linedisp, struct device *parent,
device_initialize(&linedisp->dev);
dev_set_name(&linedisp->dev, "linedisp.%u", linedisp->id);
+ err = -ENOMEM;
+ linedisp->buf = kzalloc(linedisp->num_chars, GFP_KERNEL);
+ if (!linedisp->buf)
+ goto out_put_device;
+
/* initialise a character mapping, if required */
err = linedisp_init_map(linedisp);
if (err)
diff --git a/drivers/auxdisplay/line-display.h b/drivers/auxdisplay/line-display.h
index 4e310b0e611e..4348d7a2f69a 100644
--- a/drivers/auxdisplay/line-display.h
+++ b/drivers/auxdisplay/line-display.h
@@ -82,8 +82,7 @@ struct linedisp {
};
int linedisp_register(struct linedisp *linedisp, struct device *parent,
- unsigned int num_chars, char *buf,
- const struct linedisp_ops *ops);
+ unsigned int num_chars, const struct linedisp_ops *ops);
void linedisp_unregister(struct linedisp *linedisp);
#endif /* LINEDISP_H */
--
2.43.0.rc1.1.gbec44491f096
next prev parent reply other threads:[~2024-02-19 17:03 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-19 16:57 [PATCH v3 0/9] auxdisplay: linedisp: Clean up and add new driver Andy Shevchenko
2024-02-19 16:58 ` [PATCH v3 1/9] auxdisplay: linedisp: Group display drivers together Andy Shevchenko
2024-02-26 15:28 ` Geert Uytterhoeven
2024-02-26 16:00 ` Andy Shevchenko
2024-02-26 16:03 ` Geert Uytterhoeven
2024-02-26 16:15 ` Andy Shevchenko
2024-02-19 16:58 ` Andy Shevchenko [this message]
2024-02-26 15:36 ` [PATCH v3 2/9] auxdisplay: linedisp: Allocate buffer for the string Geert Uytterhoeven
2024-02-19 16:58 ` [PATCH v3 3/9] auxdisplay: ht16k33: Add default to switch-cases Andy Shevchenko
2024-02-26 15:38 ` Geert Uytterhoeven
2024-02-19 16:58 ` [PATCH v3 4/9] auxdisplay: ht16k33: Move ht16k33_linedisp_ops down Andy Shevchenko
2024-02-19 16:58 ` [PATCH v3 5/9] auxdisplay: ht16k33: Define a few helper macros Andy Shevchenko
2024-02-20 18:05 ` Andy Shevchenko
2024-02-26 15:40 ` Geert Uytterhoeven
2024-02-19 16:58 ` [PATCH v3 6/9] auxdisplay: ht16k33: Switch to use line display character mapping Andy Shevchenko
2024-02-19 16:58 ` [PATCH v3 7/9] auxdisplay: ht16k33: Drop struct ht16k33_seg Andy Shevchenko
2024-02-26 15:44 ` Geert Uytterhoeven
2024-02-19 16:58 ` [PATCH v3 8/9] dt-bindings: auxdisplay: Add Maxim MAX6958/6959 Andy Shevchenko
2024-02-26 15:52 ` Geert Uytterhoeven
2024-02-26 17:03 ` Andy Shevchenko
2024-02-19 16:58 ` [PATCH v3 9/9] auxdisplay: Add driver for MAX695x 7-segment LED controllers Andy Shevchenko
2024-02-26 16:01 ` Geert Uytterhoeven
2024-02-26 16:17 ` Andy Shevchenko
2024-02-26 16:58 ` Geert Uytterhoeven
2024-02-26 17:04 ` Andy Shevchenko
2024-02-22 13:51 ` [PATCH v3 0/9] auxdisplay: linedisp: Clean up and add new driver Andy Shevchenko
2024-02-22 13:56 ` Geert Uytterhoeven
2024-02-26 14:30 ` Andy Shevchenko
2024-02-26 16:24 ` Andy Shevchenko
2024-02-26 18:00 ` Andy Shevchenko
2024-02-26 18:13 ` Geert Uytterhoeven
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=20240219170337.2161754-3-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=geert@linux-m68k.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulburton@kernel.org \
--cc=robh+dt@kernel.org \
--cc=robin@protonic.nl \
/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