David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 1 | /* ASB2305 Peripheral 7-segment LEDs x4 support |
| 2 | * |
| 3 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public Licence |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the Licence, or (at your option) any later version. |
| 10 | */ |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/param.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <asm/processor.h> |
Al Viro | 07c706a | 2010-01-08 14:43:17 -0800 | [diff] [blame] | 16 | #include <asm/intctl-regs.h> |
| 17 | #include <asm/rtc-regs.h> |
David Howells | 2f2a213 | 2009-04-10 14:33:48 +0100 | [diff] [blame] | 18 | #include <unit/leds.h> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 19 | |
| 20 | static const u8 asb2305_led_hex_tbl[16] = { |
| 21 | 0x80, 0xf2, 0x48, 0x60, 0x32, 0x24, 0x04, 0xf0, |
| 22 | 0x00, 0x20, 0x10, 0x06, 0x8c, 0x42, 0x0c, 0x1c |
| 23 | }; |
| 24 | |
| 25 | static const u32 asb2305_led_chase_tbl[6] = { |
| 26 | ~0x02020202, /* top - segA */ |
| 27 | ~0x04040404, /* right top - segB */ |
| 28 | ~0x08080808, /* right bottom - segC */ |
| 29 | ~0x10101010, /* bottom - segD */ |
| 30 | ~0x20202020, /* left bottom - segE */ |
| 31 | ~0x40404040, /* left top - segF */ |
| 32 | }; |
| 33 | |
| 34 | static unsigned asb2305_led_chase; |
| 35 | |
| 36 | void peripheral_leds7x4_display_dec(unsigned int val, unsigned int points) |
| 37 | { |
| 38 | u32 leds; |
| 39 | |
| 40 | leds = asb2305_led_hex_tbl[(val/1000) % 10]; |
| 41 | leds <<= 8; |
| 42 | leds |= asb2305_led_hex_tbl[(val/100) % 10]; |
| 43 | leds <<= 8; |
| 44 | leds |= asb2305_led_hex_tbl[(val/10) % 10]; |
| 45 | leds <<= 8; |
| 46 | leds |= asb2305_led_hex_tbl[val % 10]; |
| 47 | leds |= points^0x01010101; |
| 48 | |
| 49 | ASB2305_7SEGLEDS = leds; |
| 50 | } |
| 51 | |
| 52 | void peripheral_leds7x4_display_hex(unsigned int val, unsigned int points) |
| 53 | { |
| 54 | u32 leds; |
| 55 | |
| 56 | leds = asb2305_led_hex_tbl[(val/1000) % 10]; |
| 57 | leds <<= 8; |
| 58 | leds |= asb2305_led_hex_tbl[(val/100) % 10]; |
| 59 | leds <<= 8; |
| 60 | leds |= asb2305_led_hex_tbl[(val/10) % 10]; |
| 61 | leds <<= 8; |
| 62 | leds |= asb2305_led_hex_tbl[val % 10]; |
| 63 | leds |= points^0x01010101; |
| 64 | |
| 65 | ASB2305_7SEGLEDS = leds; |
| 66 | } |
| 67 | |
| 68 | void peripheral_leds_display_exception(enum exception_code code) |
| 69 | { |
| 70 | u32 leds; |
| 71 | |
| 72 | leds = asb2305_led_hex_tbl[(code/0x100) % 0x10]; |
| 73 | leds <<= 8; |
| 74 | leds |= asb2305_led_hex_tbl[(code/0x10) % 0x10]; |
| 75 | leds <<= 8; |
| 76 | leds |= asb2305_led_hex_tbl[code % 0x10]; |
| 77 | leds |= 0x6d010101; |
| 78 | |
| 79 | ASB2305_7SEGLEDS = leds; |
| 80 | } |
| 81 | |
| 82 | void peripheral_leds7x4_display_minssecs(unsigned int time, unsigned int points) |
| 83 | { |
| 84 | u32 leds; |
| 85 | |
| 86 | leds = asb2305_led_hex_tbl[(time/600) % 6]; |
| 87 | leds <<= 8; |
| 88 | leds |= asb2305_led_hex_tbl[(time/60) % 10]; |
| 89 | leds <<= 8; |
| 90 | leds |= asb2305_led_hex_tbl[(time/10) % 6]; |
| 91 | leds <<= 8; |
| 92 | leds |= asb2305_led_hex_tbl[time % 10]; |
| 93 | leds |= points^0x01010101; |
| 94 | |
| 95 | ASB2305_7SEGLEDS = leds; |
| 96 | } |
| 97 | |
| 98 | void peripheral_leds7x4_display_rtc(void) |
| 99 | { |
| 100 | unsigned int clock; |
| 101 | u8 mins, secs; |
| 102 | |
| 103 | mins = RTMCR; |
| 104 | secs = RTSCR; |
| 105 | |
| 106 | clock = ((mins & 0xf0) >> 4); |
| 107 | clock *= 10; |
| 108 | clock += (mins & 0x0f); |
| 109 | clock *= 6; |
| 110 | |
| 111 | clock += ((secs & 0xf0) >> 4); |
| 112 | clock *= 10; |
| 113 | clock += (secs & 0x0f); |
| 114 | |
| 115 | peripheral_leds7x4_display_minssecs(clock, 0); |
| 116 | } |
| 117 | |
| 118 | void peripheral_leds_led_chase(void) |
| 119 | { |
| 120 | ASB2305_7SEGLEDS = asb2305_led_chase_tbl[asb2305_led_chase]; |
| 121 | asb2305_led_chase++; |
| 122 | if (asb2305_led_chase >= 6) |
| 123 | asb2305_led_chase = 0; |
| 124 | } |