Skip to content

Commit 815876d

Browse files
committed
auxdisplay: ht16k33: Switch to use line display character mapping
Since line display library supports necessary bits to map the characters (if required), switch this driver to use that. Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> Acked-by: Robin van der Gracht <robin@protonic.nl> Tested-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
1 parent 0ee6eb8 commit 815876d

1 file changed

Lines changed: 30 additions & 73 deletions

File tree

drivers/auxdisplay/ht16k33.c

Lines changed: 30 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ struct ht16k33_fbdev {
8888

8989
struct ht16k33_seg {
9090
struct linedisp linedisp;
91-
union {
92-
struct seg7_conversion_map seg7;
93-
struct seg14_conversion_map seg14;
94-
} map;
95-
unsigned int map_size;
9691
};
9792

9893
struct ht16k33_priv {
@@ -144,33 +139,6 @@ static const struct fb_var_screeninfo ht16k33_fb_var = {
144139
.vmode = FB_VMODE_NONINTERLACED,
145140
};
146141

147-
static const SEG7_DEFAULT_MAP(initial_map_seg7);
148-
static const SEG14_DEFAULT_MAP(initial_map_seg14);
149-
150-
static ssize_t map_seg_show(struct device *dev, struct device_attribute *attr,
151-
char *buf)
152-
{
153-
struct ht16k33_priv *priv = dev_get_drvdata(dev);
154-
155-
memcpy(buf, &priv->seg.map, priv->seg.map_size);
156-
return priv->seg.map_size;
157-
}
158-
159-
static ssize_t map_seg_store(struct device *dev, struct device_attribute *attr,
160-
const char *buf, size_t cnt)
161-
{
162-
struct ht16k33_priv *priv = dev_get_drvdata(dev);
163-
164-
if (cnt != priv->seg.map_size)
165-
return -EINVAL;
166-
167-
memcpy(&priv->seg.map, buf, cnt);
168-
return cnt;
169-
}
170-
171-
static DEVICE_ATTR(map_seg7, 0644, map_seg_show, map_seg_store);
172-
static DEVICE_ATTR(map_seg14, 0644, map_seg_show, map_seg_store);
173-
174142
static int ht16k33_display_on(struct ht16k33_priv *priv)
175143
{
176144
uint8_t data = REG_DISPLAY_SETUP | REG_DISPLAY_SETUP_ON | priv->blink;
@@ -450,18 +418,19 @@ static void ht16k33_seg7_update(struct work_struct *work)
450418
{
451419
struct ht16k33_priv *priv = ht16k33_work_to_priv(work);
452420
struct ht16k33_seg *seg = &priv->seg;
421+
struct linedisp_map *map = seg->linedisp.map;
453422
char *s = seg->linedisp.buf;
454423
uint8_t buf[9];
455424

456-
buf[0] = map_to_seg7(&seg->map.seg7, *s++);
425+
buf[0] = map_to_seg7(&map->map.seg7, *s++);
457426
buf[1] = 0;
458-
buf[2] = map_to_seg7(&seg->map.seg7, *s++);
427+
buf[2] = map_to_seg7(&map->map.seg7, *s++);
459428
buf[3] = 0;
460429
buf[4] = 0;
461430
buf[5] = 0;
462-
buf[6] = map_to_seg7(&seg->map.seg7, *s++);
431+
buf[6] = map_to_seg7(&map->map.seg7, *s++);
463432
buf[7] = 0;
464-
buf[8] = map_to_seg7(&seg->map.seg7, *s++);
433+
buf[8] = map_to_seg7(&map->map.seg7, *s++);
465434

466435
i2c_smbus_write_i2c_block_data(priv->client, 0, ARRAY_SIZE(buf), buf);
467436
}
@@ -470,17 +439,36 @@ static void ht16k33_seg14_update(struct work_struct *work)
470439
{
471440
struct ht16k33_priv *priv = ht16k33_work_to_priv(work);
472441
struct ht16k33_seg *seg = &priv->seg;
442+
struct linedisp_map *map = seg->linedisp.map;
473443
char *s = seg->linedisp.buf;
474444
uint8_t buf[8];
475445

476-
put_unaligned_le16(map_to_seg14(&seg->map.seg14, *s++), buf);
477-
put_unaligned_le16(map_to_seg14(&seg->map.seg14, *s++), buf + 2);
478-
put_unaligned_le16(map_to_seg14(&seg->map.seg14, *s++), buf + 4);
479-
put_unaligned_le16(map_to_seg14(&seg->map.seg14, *s++), buf + 6);
446+
put_unaligned_le16(map_to_seg14(&map->map.seg14, *s++), buf + 0);
447+
put_unaligned_le16(map_to_seg14(&map->map.seg14, *s++), buf + 2);
448+
put_unaligned_le16(map_to_seg14(&map->map.seg14, *s++), buf + 4);
449+
put_unaligned_le16(map_to_seg14(&map->map.seg14, *s++), buf + 6);
480450

481451
i2c_smbus_write_i2c_block_data(priv->client, 0, ARRAY_SIZE(buf), buf);
482452
}
483453

454+
static int ht16k33_linedisp_get_map_type(struct linedisp *linedisp)
455+
{
456+
struct ht16k33_priv *priv = ht16k33_linedisp_to_priv(linedisp);
457+
458+
switch (priv->type) {
459+
case DISP_QUAD_7SEG:
460+
INIT_DELAYED_WORK(&priv->work, ht16k33_seg7_update);
461+
return LINEDISP_MAP_SEG7;
462+
463+
case DISP_QUAD_14SEG:
464+
INIT_DELAYED_WORK(&priv->work, ht16k33_seg14_update);
465+
return LINEDISP_MAP_SEG14;
466+
467+
default:
468+
return -EINVAL;
469+
}
470+
}
471+
484472
static void ht16k33_linedisp_update(struct linedisp *linedisp)
485473
{
486474
struct ht16k33_priv *priv = ht16k33_linedisp_to_priv(linedisp);
@@ -489,6 +477,7 @@ static void ht16k33_linedisp_update(struct linedisp *linedisp)
489477
}
490478

491479
static const struct linedisp_ops ht16k33_linedisp_ops = {
480+
.get_map_type = ht16k33_linedisp_get_map_type,
492481
.update = ht16k33_linedisp_update,
493482
};
494483

@@ -680,37 +669,7 @@ static int ht16k33_seg_probe(struct device *dev, struct ht16k33_priv *priv,
680669
if (err)
681670
return err;
682671

683-
switch (priv->type) {
684-
case DISP_QUAD_7SEG:
685-
INIT_DELAYED_WORK(&priv->work, ht16k33_seg7_update);
686-
seg->map.seg7 = initial_map_seg7;
687-
seg->map_size = sizeof(seg->map.seg7);
688-
err = device_create_file(dev, &dev_attr_map_seg7);
689-
break;
690-
691-
case DISP_QUAD_14SEG:
692-
INIT_DELAYED_WORK(&priv->work, ht16k33_seg14_update);
693-
seg->map.seg14 = initial_map_seg14;
694-
seg->map_size = sizeof(seg->map.seg14);
695-
err = device_create_file(dev, &dev_attr_map_seg14);
696-
break;
697-
698-
default:
699-
return -EINVAL;
700-
}
701-
if (err)
702-
return err;
703-
704-
err = linedisp_register(&seg->linedisp, dev, 4, &ht16k33_linedisp_ops);
705-
if (err)
706-
goto err_remove_map_file;
707-
708-
return 0;
709-
710-
err_remove_map_file:
711-
device_remove_file(dev, &dev_attr_map_seg7);
712-
device_remove_file(dev, &dev_attr_map_seg14);
713-
return err;
672+
return linedisp_register(&seg->linedisp, dev, 4, &ht16k33_linedisp_ops);
714673
}
715674

716675
static int ht16k33_probe(struct i2c_client *client)
@@ -798,8 +757,6 @@ static void ht16k33_remove(struct i2c_client *client)
798757
case DISP_QUAD_7SEG:
799758
case DISP_QUAD_14SEG:
800759
linedisp_unregister(&priv->seg.linedisp);
801-
device_remove_file(&client->dev, &dev_attr_map_seg7);
802-
device_remove_file(&client->dev, &dev_attr_map_seg14);
803760
break;
804761

805762
default:

0 commit comments

Comments
 (0)