1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * HT16K33 driver 4 * 5 * Author: Robin van der Gracht <robin@protonic.nl> 6 * 7 * Copyright: (C) 2016 Protonic Holland. 8 * Copyright (C) 2021 Glider bv 9 */ 10 11 #include <linux/kernel.h> 12 #include <linux/module.h> 13 #include <linux/interrupt.h> 14 #include <linux/i2c.h> 15 #include <linux/of.h> 16 #include <linux/fb.h> 17 #include <linux/slab.h> 18 #include <linux/backlight.h> 19 #include <linux/input.h> 20 #include <linux/input/matrix_keypad.h> 21 #include <linux/workqueue.h> 22 #include <linux/mm.h> 23 24 #include <linux/map_to_7segment.h> 25 #include <linux/map_to_14segment.h> 26 27 #include <asm/unaligned.h> 28 29 #include "line-display.h" 30 31 /* Registers */ 32 #define REG_SYSTEM_SETUP 0x20 33 #define REG_SYSTEM_SETUP_OSC_ON BIT(0) 34 35 #define REG_DISPLAY_SETUP 0x80 36 #define REG_DISPLAY_SETUP_ON BIT(0) 37 38 #define REG_ROWINT_SET 0xA0 39 #define REG_ROWINT_SET_INT_EN BIT(0) 40 #define REG_ROWINT_SET_INT_ACT_HIGH BIT(1) 41 42 #define REG_BRIGHTNESS 0xE0 43 44 /* Defines */ 45 #define DRIVER_NAME "ht16k33" 46 47 #define MIN_BRIGHTNESS 0x1 48 #define MAX_BRIGHTNESS 0x10 49 50 #define HT16K33_MATRIX_LED_MAX_COLS 8 51 #define HT16K33_MATRIX_LED_MAX_ROWS 16 52 #define HT16K33_MATRIX_KEYPAD_MAX_COLS 3 53 #define HT16K33_MATRIX_KEYPAD_MAX_ROWS 12 54 55 #define BYTES_PER_ROW (HT16K33_MATRIX_LED_MAX_ROWS / 8) 56 #define HT16K33_FB_SIZE (HT16K33_MATRIX_LED_MAX_COLS * BYTES_PER_ROW) 57 58 enum display_type { 59 DISP_MATRIX = 0, 60 DISP_QUAD_7SEG, 61 DISP_QUAD_14SEG, 62 }; 63 64 struct ht16k33_keypad { 65 struct i2c_client *client; 66 struct input_dev *dev; 67 uint32_t cols; 68 uint32_t rows; 69 uint32_t row_shift; 70 uint32_t debounce_ms; 71 uint16_t last_key_state[HT16K33_MATRIX_KEYPAD_MAX_COLS]; 72 73 wait_queue_head_t wait; 74 bool stopped; 75 }; 76 77 struct ht16k33_fbdev { 78 struct fb_info *info; 79 uint32_t refresh_rate; 80 uint8_t *buffer; 81 uint8_t *cache; 82 }; 83 84 struct ht16k33_seg { 85 struct linedisp linedisp; 86 union { 87 struct seg7_conversion_map seg7; 88 struct seg14_conversion_map seg14; 89 } map; 90 unsigned int map_size; 91 char curr[4]; 92 }; 93 94 struct ht16k33_priv { 95 struct i2c_client *client; 96 struct delayed_work work; 97 struct ht16k33_keypad keypad; 98 union { 99 struct ht16k33_fbdev fbdev; 100 struct ht16k33_seg seg; 101 }; 102 enum display_type type; 103 }; 104 105 static const struct fb_fix_screeninfo ht16k33_fb_fix = { 106 .id = DRIVER_NAME, 107 .type = FB_TYPE_PACKED_PIXELS, 108 .visual = FB_VISUAL_MONO10, 109 .xpanstep = 0, 110 .ypanstep = 0, 111 .ywrapstep = 0, 112 .line_length = HT16K33_MATRIX_LED_MAX_ROWS, 113 .accel = FB_ACCEL_NONE, 114 }; 115 116 static const struct fb_var_screeninfo ht16k33_fb_var = { 117 .xres = HT16K33_MATRIX_LED_MAX_ROWS, 118 .yres = HT16K33_MATRIX_LED_MAX_COLS, 119 .xres_virtual = HT16K33_MATRIX_LED_MAX_ROWS, 120 .yres_virtual = HT16K33_MATRIX_LED_MAX_COLS, 121 .bits_per_pixel = 1, 122 .red = { 0, 1, 0 }, 123 .green = { 0, 1, 0 }, 124 .blue = { 0, 1, 0 }, 125 .left_margin = 0, 126 .right_margin = 0, 127 .upper_margin = 0, 128 .lower_margin = 0, 129 .vmode = FB_VMODE_NONINTERLACED, 130 }; 131 132 static const SEG7_DEFAULT_MAP(initial_map_seg7); 133 static const SEG14_DEFAULT_MAP(initial_map_seg14); 134 135 static ssize_t map_seg_show(struct device *dev, struct device_attribute *attr, 136 char *buf) 137 { 138 struct ht16k33_priv *priv = dev_get_drvdata(dev); 139 140 memcpy(buf, &priv->seg.map, priv->seg.map_size); 141 return priv->seg.map_size; 142 } 143 144 static ssize_t map_seg_store(struct device *dev, struct device_attribute *attr, 145 const char *buf, size_t cnt) 146 { 147 struct ht16k33_priv *priv = dev_get_drvdata(dev); 148 149 if (cnt != priv->seg.map_size) 150 return -EINVAL; 151 152 memcpy(&priv->seg.map, buf, cnt); 153 return cnt; 154 } 155 156 static DEVICE_ATTR(map_seg7, 0644, map_seg_show, map_seg_store); 157 static DEVICE_ATTR(map_seg14, 0644, map_seg_show, map_seg_store); 158 159 static int ht16k33_display_on(struct ht16k33_priv *priv) 160 { 161 uint8_t data = REG_DISPLAY_SETUP | REG_DISPLAY_SETUP_ON; 162 163 return i2c_smbus_write_byte(priv->client, data); 164 } 165 166 static int ht16k33_display_off(struct ht16k33_priv *priv) 167 { 168 return i2c_smbus_write_byte(priv->client, REG_DISPLAY_SETUP); 169 } 170 171 static int ht16k33_brightness_set(struct ht16k33_priv *priv, 172 unsigned int brightness) 173 { 174 int err; 175 176 if (brightness == 0) 177 return ht16k33_display_off(priv); 178 179 err = ht16k33_display_on(priv); 180 if (err) 181 return err; 182 183 return i2c_smbus_write_byte(priv->client, 184 REG_BRIGHTNESS | (brightness - 1)); 185 } 186 187 static void ht16k33_fb_queue(struct ht16k33_priv *priv) 188 { 189 struct ht16k33_fbdev *fbdev = &priv->fbdev; 190 191 schedule_delayed_work(&priv->work, HZ / fbdev->refresh_rate); 192 } 193 194 /* 195 * This gets the fb data from cache and copies it to ht16k33 display RAM 196 */ 197 static void ht16k33_fb_update(struct work_struct *work) 198 { 199 struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv, 200 work.work); 201 struct ht16k33_fbdev *fbdev = &priv->fbdev; 202 203 uint8_t *p1, *p2; 204 int len, pos = 0, first = -1; 205 206 p1 = fbdev->cache; 207 p2 = fbdev->buffer; 208 209 /* Search for the first byte with changes */ 210 while (pos < HT16K33_FB_SIZE && first < 0) { 211 if (*(p1++) - *(p2++)) 212 first = pos; 213 pos++; 214 } 215 216 /* No changes found */ 217 if (first < 0) 218 goto requeue; 219 220 len = HT16K33_FB_SIZE - first; 221 p1 = fbdev->cache + HT16K33_FB_SIZE - 1; 222 p2 = fbdev->buffer + HT16K33_FB_SIZE - 1; 223 224 /* Determine i2c transfer length */ 225 while (len > 1) { 226 if (*(p1--) - *(p2--)) 227 break; 228 len--; 229 } 230 231 p1 = fbdev->cache + first; 232 p2 = fbdev->buffer + first; 233 if (!i2c_smbus_write_i2c_block_data(priv->client, first, len, p2)) 234 memcpy(p1, p2, len); 235 requeue: 236 ht16k33_fb_queue(priv); 237 } 238 239 static int ht16k33_initialize(struct ht16k33_priv *priv) 240 { 241 uint8_t data[HT16K33_FB_SIZE]; 242 uint8_t byte; 243 int err; 244 245 /* Clear RAM (8 * 16 bits) */ 246 memset(data, 0, sizeof(data)); 247 err = i2c_smbus_write_block_data(priv->client, 0, sizeof(data), data); 248 if (err) 249 return err; 250 251 /* Turn on internal oscillator */ 252 byte = REG_SYSTEM_SETUP_OSC_ON | REG_SYSTEM_SETUP; 253 err = i2c_smbus_write_byte(priv->client, byte); 254 if (err) 255 return err; 256 257 /* Configure INT pin */ 258 byte = REG_ROWINT_SET | REG_ROWINT_SET_INT_ACT_HIGH; 259 if (priv->client->irq > 0) 260 byte |= REG_ROWINT_SET_INT_EN; 261 return i2c_smbus_write_byte(priv->client, byte); 262 } 263 264 static int ht16k33_bl_update_status(struct backlight_device *bl) 265 { 266 int brightness = bl->props.brightness; 267 struct ht16k33_priv *priv = bl_get_data(bl); 268 269 if (bl->props.power != FB_BLANK_UNBLANK || 270 bl->props.fb_blank != FB_BLANK_UNBLANK || 271 bl->props.state & BL_CORE_FBBLANK) 272 brightness = 0; 273 274 return ht16k33_brightness_set(priv, brightness); 275 } 276 277 static int ht16k33_bl_check_fb(struct backlight_device *bl, struct fb_info *fi) 278 { 279 struct ht16k33_priv *priv = bl_get_data(bl); 280 281 return (fi == NULL) || (fi->par == priv); 282 } 283 284 static const struct backlight_ops ht16k33_bl_ops = { 285 .update_status = ht16k33_bl_update_status, 286 .check_fb = ht16k33_bl_check_fb, 287 }; 288 289 /* 290 * Blank events will be passed to the actual device handling the backlight when 291 * we return zero here. 292 */ 293 static int ht16k33_blank(int blank, struct fb_info *info) 294 { 295 return 0; 296 } 297 298 static int ht16k33_mmap(struct fb_info *info, struct vm_area_struct *vma) 299 { 300 struct ht16k33_priv *priv = info->par; 301 struct page *pages = virt_to_page(priv->fbdev.buffer); 302 303 return vm_map_pages_zero(vma, &pages, 1); 304 } 305 306 static const struct fb_ops ht16k33_fb_ops = { 307 .owner = THIS_MODULE, 308 .fb_read = fb_sys_read, 309 .fb_write = fb_sys_write, 310 .fb_blank = ht16k33_blank, 311 .fb_fillrect = sys_fillrect, 312 .fb_copyarea = sys_copyarea, 313 .fb_imageblit = sys_imageblit, 314 .fb_mmap = ht16k33_mmap, 315 }; 316 317 /* 318 * This gets the keys from keypad and reports it to input subsystem. 319 * Returns true if a key is pressed. 320 */ 321 static bool ht16k33_keypad_scan(struct ht16k33_keypad *keypad) 322 { 323 const unsigned short *keycodes = keypad->dev->keycode; 324 u16 new_state[HT16K33_MATRIX_KEYPAD_MAX_COLS]; 325 __le16 data[HT16K33_MATRIX_KEYPAD_MAX_COLS]; 326 unsigned long bits_changed; 327 int row, col, code; 328 int rc; 329 bool pressed = false; 330 331 rc = i2c_smbus_read_i2c_block_data(keypad->client, 0x40, 332 sizeof(data), (u8 *)data); 333 if (rc != sizeof(data)) { 334 dev_err(&keypad->client->dev, 335 "Failed to read key data, rc=%d\n", rc); 336 return false; 337 } 338 339 for (col = 0; col < keypad->cols; col++) { 340 new_state[col] = le16_to_cpu(data[col]); 341 if (new_state[col]) 342 pressed = true; 343 bits_changed = keypad->last_key_state[col] ^ new_state[col]; 344 345 for_each_set_bit(row, &bits_changed, BITS_PER_LONG) { 346 code = MATRIX_SCAN_CODE(row, col, keypad->row_shift); 347 input_event(keypad->dev, EV_MSC, MSC_SCAN, code); 348 input_report_key(keypad->dev, keycodes[code], 349 new_state[col] & BIT(row)); 350 } 351 } 352 input_sync(keypad->dev); 353 memcpy(keypad->last_key_state, new_state, sizeof(u16) * keypad->cols); 354 355 return pressed; 356 } 357 358 static irqreturn_t ht16k33_keypad_irq_thread(int irq, void *dev) 359 { 360 struct ht16k33_keypad *keypad = dev; 361 362 do { 363 wait_event_timeout(keypad->wait, keypad->stopped, 364 msecs_to_jiffies(keypad->debounce_ms)); 365 if (keypad->stopped) 366 break; 367 } while (ht16k33_keypad_scan(keypad)); 368 369 return IRQ_HANDLED; 370 } 371 372 static int ht16k33_keypad_start(struct input_dev *dev) 373 { 374 struct ht16k33_keypad *keypad = input_get_drvdata(dev); 375 376 keypad->stopped = false; 377 mb(); 378 enable_irq(keypad->client->irq); 379 380 return 0; 381 } 382 383 static void ht16k33_keypad_stop(struct input_dev *dev) 384 { 385 struct ht16k33_keypad *keypad = input_get_drvdata(dev); 386 387 keypad->stopped = true; 388 mb(); 389 wake_up(&keypad->wait); 390 disable_irq(keypad->client->irq); 391 } 392 393 static void ht16k33_linedisp_update(struct linedisp *linedisp) 394 { 395 struct ht16k33_priv *priv = container_of(linedisp, struct ht16k33_priv, 396 seg.linedisp); 397 398 schedule_delayed_work(&priv->work, 0); 399 } 400 401 static void ht16k33_seg7_update(struct work_struct *work) 402 { 403 struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv, 404 work.work); 405 struct ht16k33_seg *seg = &priv->seg; 406 char *s = seg->curr; 407 uint8_t buf[9]; 408 409 buf[0] = map_to_seg7(&seg->map.seg7, *s++); 410 buf[1] = 0; 411 buf[2] = map_to_seg7(&seg->map.seg7, *s++); 412 buf[3] = 0; 413 buf[4] = 0; 414 buf[5] = 0; 415 buf[6] = map_to_seg7(&seg->map.seg7, *s++); 416 buf[7] = 0; 417 buf[8] = map_to_seg7(&seg->map.seg7, *s++); 418 419 i2c_smbus_write_i2c_block_data(priv->client, 0, ARRAY_SIZE(buf), buf); 420 } 421 422 static void ht16k33_seg14_update(struct work_struct *work) 423 { 424 struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv, 425 work.work); 426 struct ht16k33_seg *seg = &priv->seg; 427 char *s = seg->curr; 428 uint8_t buf[8]; 429 430 put_unaligned_le16(map_to_seg14(&seg->map.seg14, *s++), buf); 431 put_unaligned_le16(map_to_seg14(&seg->map.seg14, *s++), buf + 2); 432 put_unaligned_le16(map_to_seg14(&seg->map.seg14, *s++), buf + 4); 433 put_unaligned_le16(map_to_seg14(&seg->map.seg14, *s++), buf + 6); 434 435 i2c_smbus_write_i2c_block_data(priv->client, 0, ARRAY_SIZE(buf), buf); 436 } 437 438 static int ht16k33_keypad_probe(struct i2c_client *client, 439 struct ht16k33_keypad *keypad) 440 { 441 struct device *dev = &client->dev; 442 struct device_node *node = dev->of_node; 443 u32 rows = HT16K33_MATRIX_KEYPAD_MAX_ROWS; 444 u32 cols = HT16K33_MATRIX_KEYPAD_MAX_COLS; 445 int err; 446 447 keypad->client = client; 448 init_waitqueue_head(&keypad->wait); 449 450 keypad->dev = devm_input_allocate_device(dev); 451 if (!keypad->dev) 452 return -ENOMEM; 453 454 input_set_drvdata(keypad->dev, keypad); 455 456 keypad->dev->name = DRIVER_NAME"-keypad"; 457 keypad->dev->id.bustype = BUS_I2C; 458 keypad->dev->open = ht16k33_keypad_start; 459 keypad->dev->close = ht16k33_keypad_stop; 460 461 if (!of_get_property(node, "linux,no-autorepeat", NULL)) 462 __set_bit(EV_REP, keypad->dev->evbit); 463 464 err = of_property_read_u32(node, "debounce-delay-ms", 465 &keypad->debounce_ms); 466 if (err) { 467 dev_err(dev, "key debounce delay not specified\n"); 468 return err; 469 } 470 471 err = matrix_keypad_parse_of_params(dev, &rows, &cols); 472 if (err) 473 return err; 474 if (rows > HT16K33_MATRIX_KEYPAD_MAX_ROWS || 475 cols > HT16K33_MATRIX_KEYPAD_MAX_COLS) { 476 dev_err(dev, "%u rows or %u cols out of range in DT\n", rows, 477 cols); 478 return -ERANGE; 479 } 480 481 keypad->rows = rows; 482 keypad->cols = cols; 483 keypad->row_shift = get_count_order(cols); 484 485 err = matrix_keypad_build_keymap(NULL, NULL, rows, cols, NULL, 486 keypad->dev); 487 if (err) { 488 dev_err(dev, "failed to build keymap\n"); 489 return err; 490 } 491 492 err = devm_request_threaded_irq(dev, client->irq, NULL, 493 ht16k33_keypad_irq_thread, 494 IRQF_TRIGGER_HIGH | IRQF_ONESHOT, 495 DRIVER_NAME, keypad); 496 if (err) { 497 dev_err(dev, "irq request failed %d, error %d\n", client->irq, 498 err); 499 return err; 500 } 501 502 ht16k33_keypad_stop(keypad->dev); 503 504 return input_register_device(keypad->dev); 505 } 506 507 static int ht16k33_fbdev_probe(struct device *dev, struct ht16k33_priv *priv, 508 uint32_t brightness) 509 { 510 struct ht16k33_fbdev *fbdev = &priv->fbdev; 511 struct backlight_properties bl_props; 512 struct backlight_device *bl; 513 int err; 514 515 /* Backlight */ 516 memset(&bl_props, 0, sizeof(struct backlight_properties)); 517 bl_props.type = BACKLIGHT_RAW; 518 bl_props.max_brightness = MAX_BRIGHTNESS; 519 520 bl = devm_backlight_device_register(dev, DRIVER_NAME"-bl", dev, priv, 521 &ht16k33_bl_ops, &bl_props); 522 if (IS_ERR(bl)) { 523 dev_err(dev, "failed to register backlight\n"); 524 return PTR_ERR(bl); 525 } 526 527 bl->props.brightness = brightness; 528 ht16k33_bl_update_status(bl); 529 530 /* Framebuffer (2 bytes per column) */ 531 BUILD_BUG_ON(PAGE_SIZE < HT16K33_FB_SIZE); 532 fbdev->buffer = (unsigned char *) get_zeroed_page(GFP_KERNEL); 533 if (!fbdev->buffer) 534 return -ENOMEM; 535 536 fbdev->cache = devm_kmalloc(dev, HT16K33_FB_SIZE, GFP_KERNEL); 537 if (!fbdev->cache) { 538 err = -ENOMEM; 539 goto err_fbdev_buffer; 540 } 541 542 fbdev->info = framebuffer_alloc(0, dev); 543 if (!fbdev->info) { 544 err = -ENOMEM; 545 goto err_fbdev_buffer; 546 } 547 548 err = of_property_read_u32(dev->of_node, "refresh-rate-hz", 549 &fbdev->refresh_rate); 550 if (err) { 551 dev_err(dev, "refresh rate not specified\n"); 552 goto err_fbdev_info; 553 } 554 fb_bl_default_curve(fbdev->info, 0, MIN_BRIGHTNESS, MAX_BRIGHTNESS); 555 556 INIT_DELAYED_WORK(&priv->work, ht16k33_fb_update); 557 fbdev->info->fbops = &ht16k33_fb_ops; 558 fbdev->info->screen_base = (char __iomem *) fbdev->buffer; 559 fbdev->info->screen_size = HT16K33_FB_SIZE; 560 fbdev->info->fix = ht16k33_fb_fix; 561 fbdev->info->var = ht16k33_fb_var; 562 fbdev->info->bl_dev = bl; 563 fbdev->info->pseudo_palette = NULL; 564 fbdev->info->flags = FBINFO_FLAG_DEFAULT; 565 fbdev->info->par = priv; 566 567 err = register_framebuffer(fbdev->info); 568 if (err) 569 goto err_fbdev_info; 570 571 ht16k33_fb_queue(priv); 572 return 0; 573 574 err_fbdev_info: 575 framebuffer_release(fbdev->info); 576 err_fbdev_buffer: 577 free_page((unsigned long) fbdev->buffer); 578 579 return err; 580 } 581 582 static int ht16k33_seg_probe(struct device *dev, struct ht16k33_priv *priv, 583 uint32_t brightness) 584 { 585 struct ht16k33_seg *seg = &priv->seg; 586 int err; 587 588 err = ht16k33_brightness_set(priv, brightness); 589 if (err) 590 return err; 591 592 switch (priv->type) { 593 case DISP_MATRIX: 594 /* not handled here */ 595 err = -EINVAL; 596 break; 597 598 case DISP_QUAD_7SEG: 599 INIT_DELAYED_WORK(&priv->work, ht16k33_seg7_update); 600 seg->map.seg7 = initial_map_seg7; 601 seg->map_size = sizeof(seg->map.seg7); 602 err = device_create_file(dev, &dev_attr_map_seg7); 603 break; 604 605 case DISP_QUAD_14SEG: 606 INIT_DELAYED_WORK(&priv->work, ht16k33_seg14_update); 607 seg->map.seg14 = initial_map_seg14; 608 seg->map_size = sizeof(seg->map.seg14); 609 err = device_create_file(dev, &dev_attr_map_seg14); 610 break; 611 } 612 if (err) 613 return err; 614 615 err = linedisp_register(&seg->linedisp, dev, 4, seg->curr, 616 ht16k33_linedisp_update); 617 if (err) 618 goto err_remove_map_file; 619 620 return 0; 621 622 err_remove_map_file: 623 device_remove_file(dev, &dev_attr_map_seg7); 624 device_remove_file(dev, &dev_attr_map_seg14); 625 return err; 626 } 627 628 static int ht16k33_probe(struct i2c_client *client) 629 { 630 struct device *dev = &client->dev; 631 const struct of_device_id *id; 632 struct ht16k33_priv *priv; 633 uint32_t dft_brightness; 634 int err; 635 636 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 637 dev_err(dev, "i2c_check_functionality error\n"); 638 return -EIO; 639 } 640 641 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 642 if (!priv) 643 return -ENOMEM; 644 645 priv->client = client; 646 id = i2c_of_match_device(dev->driver->of_match_table, client); 647 if (id) 648 priv->type = (uintptr_t)id->data; 649 i2c_set_clientdata(client, priv); 650 651 err = ht16k33_initialize(priv); 652 if (err) 653 return err; 654 655 err = of_property_read_u32(dev->of_node, "default-brightness-level", 656 &dft_brightness); 657 if (err) { 658 dft_brightness = MAX_BRIGHTNESS; 659 } else if (dft_brightness > MAX_BRIGHTNESS) { 660 dev_warn(dev, 661 "invalid default brightness level: %u, using %u\n", 662 dft_brightness, MAX_BRIGHTNESS); 663 dft_brightness = MAX_BRIGHTNESS; 664 } 665 666 /* Keypad */ 667 if (client->irq > 0) { 668 err = ht16k33_keypad_probe(client, &priv->keypad); 669 if (err) 670 return err; 671 } 672 673 switch (priv->type) { 674 case DISP_MATRIX: 675 /* Frame Buffer Display */ 676 err = ht16k33_fbdev_probe(dev, priv, dft_brightness); 677 break; 678 679 case DISP_QUAD_7SEG: 680 case DISP_QUAD_14SEG: 681 /* Segment Display */ 682 err = ht16k33_seg_probe(dev, priv, dft_brightness); 683 break; 684 } 685 return err; 686 } 687 688 static int ht16k33_remove(struct i2c_client *client) 689 { 690 struct ht16k33_priv *priv = i2c_get_clientdata(client); 691 struct ht16k33_fbdev *fbdev = &priv->fbdev; 692 693 cancel_delayed_work_sync(&priv->work); 694 695 switch (priv->type) { 696 case DISP_MATRIX: 697 unregister_framebuffer(fbdev->info); 698 framebuffer_release(fbdev->info); 699 free_page((unsigned long)fbdev->buffer); 700 break; 701 702 case DISP_QUAD_7SEG: 703 case DISP_QUAD_14SEG: 704 linedisp_unregister(&priv->seg.linedisp); 705 device_remove_file(&client->dev, &dev_attr_map_seg7); 706 device_remove_file(&client->dev, &dev_attr_map_seg14); 707 break; 708 } 709 710 return 0; 711 } 712 713 static const struct i2c_device_id ht16k33_i2c_match[] = { 714 { "ht16k33", 0 }, 715 { } 716 }; 717 MODULE_DEVICE_TABLE(i2c, ht16k33_i2c_match); 718 719 static const struct of_device_id ht16k33_of_match[] = { 720 { 721 /* 0.56" 4-Digit 7-Segment FeatherWing Display (Red) */ 722 .compatible = "adafruit,3108", .data = (void *)DISP_QUAD_7SEG, 723 }, { 724 /* 0.54" Quad Alphanumeric FeatherWing Display (Red) */ 725 .compatible = "adafruit,3130", .data = (void *)DISP_QUAD_14SEG, 726 }, { 727 /* Generic, assumed Dot-Matrix Display */ 728 .compatible = "holtek,ht16k33", .data = (void *)DISP_MATRIX, 729 }, 730 { } 731 }; 732 MODULE_DEVICE_TABLE(of, ht16k33_of_match); 733 734 static struct i2c_driver ht16k33_driver = { 735 .probe_new = ht16k33_probe, 736 .remove = ht16k33_remove, 737 .driver = { 738 .name = DRIVER_NAME, 739 .of_match_table = of_match_ptr(ht16k33_of_match), 740 }, 741 .id_table = ht16k33_i2c_match, 742 }; 743 module_i2c_driver(ht16k33_driver); 744 745 MODULE_DESCRIPTION("Holtek HT16K33 driver"); 746 MODULE_LICENSE("GPL"); 747 MODULE_AUTHOR("Robin van der Gracht <robin@protonic.nl>"); 748