2 * Technologic Systems TS-5500 Single Board Computer support
4 * Copyright (C) 2013-2014 Savoir-faire Linux Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option) any later
13 * This driver registers the Technologic Systems TS-5500 Single Board Computer
14 * (SBC) and its devices, and exposes information to userspace such as jumpers'
15 * state or available options. For further information about sysfs entries, see
16 * Documentation/ABI/testing/sysfs-platform-ts5500.
18 * This code may be extended to support similar x86-based platforms.
19 * Actually, the TS-5500 and TS-5400 are supported.
22 #include <linux/delay.h>
24 #include <linux/kernel.h>
25 #include <linux/leds.h>
26 #include <linux/init.h>
27 #include <linux/platform_data/max197.h>
28 #include <linux/platform_device.h>
29 #include <linux/slab.h>
31 /* Product code register */
32 #define TS5500_PRODUCT_CODE_ADDR 0x74
33 #define TS5500_PRODUCT_CODE 0x60 /* TS-5500 product code */
34 #define TS5400_PRODUCT_CODE 0x40 /* TS-5400 product code */
36 /* SRAM/RS-485/ADC options, and RS-485 RTS/Automatic RS-485 flags register */
37 #define TS5500_SRAM_RS485_ADC_ADDR 0x75
38 #define TS5500_SRAM BIT(0) /* SRAM option */
39 #define TS5500_RS485 BIT(1) /* RS-485 option */
40 #define TS5500_ADC BIT(2) /* A/D converter option */
41 #define TS5500_RS485_RTS BIT(6) /* RTS for RS-485 */
42 #define TS5500_RS485_AUTO BIT(7) /* Automatic RS-485 */
44 /* External Reset/Industrial Temperature Range options register */
45 #define TS5500_ERESET_ITR_ADDR 0x76
46 #define TS5500_ERESET BIT(0) /* External Reset option */
47 #define TS5500_ITR BIT(1) /* Indust. Temp. Range option */
49 /* LED/Jumpers register */
50 #define TS5500_LED_JP_ADDR 0x77
51 #define TS5500_LED BIT(0) /* LED flag */
52 #define TS5500_JP1 BIT(1) /* Automatic CMOS */
53 #define TS5500_JP2 BIT(2) /* Enable Serial Console */
54 #define TS5500_JP3 BIT(3) /* Write Enable Drive A */
55 #define TS5500_JP4 BIT(4) /* Fast Console (115K baud) */
56 #define TS5500_JP5 BIT(5) /* User Jumper */
57 #define TS5500_JP6 BIT(6) /* Console on COM1 (req. JP2) */
58 #define TS5500_JP7 BIT(7) /* Undocumented (Unused) */
60 /* A/D Converter registers */
61 #define TS5500_ADC_CONV_BUSY_ADDR 0x195 /* Conversion state register */
62 #define TS5500_ADC_CONV_BUSY BIT(0)
63 #define TS5500_ADC_CONV_INIT_LSB_ADDR 0x196 /* Start conv. / LSB register */
64 #define TS5500_ADC_CONV_MSB_ADDR 0x197 /* MSB register */
65 #define TS5500_ADC_CONV_DELAY 12 /* usec */
68 * struct ts5500_sbc - TS-5500 board description
69 * @name: Board model name.
70 * @id: Board product ID.
71 * @sram: Flag for SRAM option.
72 * @rs485: Flag for RS-485 option.
73 * @adc: Flag for Analog/Digital converter option.
74 * @ereset: Flag for External Reset option.
75 * @itr: Flag for Industrial Temperature Range option.
76 * @jumpers: Bitfield for jumpers' state.
89 /* Board signatures in BIOS shadow RAM */
91 const char * const string;
93 } ts5500_signatures[] __initconst = {
94 { "TS-5x00 AMD Elan", 0xb14 },
97 static int __init ts5500_check_signature(void)
100 int i, ret = -ENODEV;
102 bios = ioremap(0xf0000, 0x10000);
106 for (i = 0; i < ARRAY_SIZE(ts5500_signatures); i++) {
107 if (check_signature(bios + ts5500_signatures[i].offset,
108 ts5500_signatures[i].string,
109 strlen(ts5500_signatures[i].string))) {
119 static int __init ts5500_detect_config(struct ts5500_sbc *sbc)
124 if (!request_region(TS5500_PRODUCT_CODE_ADDR, 4, "ts5500"))
127 sbc->id = inb(TS5500_PRODUCT_CODE_ADDR);
128 if (sbc->id == TS5500_PRODUCT_CODE) {
129 sbc->name = "TS-5500";
130 } else if (sbc->id == TS5400_PRODUCT_CODE) {
131 sbc->name = "TS-5400";
133 pr_err("ts5500: unknown product code 0x%x\n", sbc->id);
138 tmp = inb(TS5500_SRAM_RS485_ADC_ADDR);
139 sbc->sram = tmp & TS5500_SRAM;
140 sbc->rs485 = tmp & TS5500_RS485;
141 sbc->adc = tmp & TS5500_ADC;
143 tmp = inb(TS5500_ERESET_ITR_ADDR);
144 sbc->ereset = tmp & TS5500_ERESET;
145 sbc->itr = tmp & TS5500_ITR;
147 tmp = inb(TS5500_LED_JP_ADDR);
148 sbc->jumpers = tmp & ~TS5500_LED;
151 release_region(TS5500_PRODUCT_CODE_ADDR, 4);
155 static ssize_t name_show(struct device *dev, struct device_attribute *attr,
158 struct ts5500_sbc *sbc = dev_get_drvdata(dev);
160 return sprintf(buf, "%s\n", sbc->name);
162 static DEVICE_ATTR_RO(name);
164 static ssize_t id_show(struct device *dev, struct device_attribute *attr,
167 struct ts5500_sbc *sbc = dev_get_drvdata(dev);
169 return sprintf(buf, "0x%.2x\n", sbc->id);
171 static DEVICE_ATTR_RO(id);
173 static ssize_t jumpers_show(struct device *dev, struct device_attribute *attr,
176 struct ts5500_sbc *sbc = dev_get_drvdata(dev);
178 return sprintf(buf, "0x%.2x\n", sbc->jumpers >> 1);
180 static DEVICE_ATTR_RO(jumpers);
182 #define TS5500_ATTR_BOOL(_field) \
183 static ssize_t _field##_show(struct device *dev, \
184 struct device_attribute *attr, char *buf) \
186 struct ts5500_sbc *sbc = dev_get_drvdata(dev); \
188 return sprintf(buf, "%d\n", sbc->_field); \
190 static DEVICE_ATTR_RO(_field)
192 TS5500_ATTR_BOOL(sram);
193 TS5500_ATTR_BOOL(rs485);
194 TS5500_ATTR_BOOL(adc);
195 TS5500_ATTR_BOOL(ereset);
196 TS5500_ATTR_BOOL(itr);
198 static struct attribute *ts5500_attributes[] = {
201 &dev_attr_jumpers.attr,
203 &dev_attr_rs485.attr,
205 &dev_attr_ereset.attr,
210 static const struct attribute_group ts5500_attr_group = {
211 .attrs = ts5500_attributes,
214 static struct resource ts5500_dio1_resource[] = {
215 DEFINE_RES_IRQ_NAMED(7, "DIO1 interrupt"),
218 static struct platform_device ts5500_dio1_pdev = {
219 .name = "ts5500-dio1",
221 .resource = ts5500_dio1_resource,
225 static struct resource ts5500_dio2_resource[] = {
226 DEFINE_RES_IRQ_NAMED(6, "DIO2 interrupt"),
229 static struct platform_device ts5500_dio2_pdev = {
230 .name = "ts5500-dio2",
232 .resource = ts5500_dio2_resource,
236 static void ts5500_led_set(struct led_classdev *led_cdev,
237 enum led_brightness brightness)
239 outb(!!brightness, TS5500_LED_JP_ADDR);
242 static enum led_brightness ts5500_led_get(struct led_classdev *led_cdev)
244 return (inb(TS5500_LED_JP_ADDR) & TS5500_LED) ? LED_FULL : LED_OFF;
247 static struct led_classdev ts5500_led_cdev = {
248 .name = "ts5500:green:",
249 .brightness_set = ts5500_led_set,
250 .brightness_get = ts5500_led_get,
253 static int ts5500_adc_convert(u8 ctrl)
257 /* Start conversion (ensure the 3 MSB are set to 0) */
258 outb(ctrl & 0x1f, TS5500_ADC_CONV_INIT_LSB_ADDR);
261 * The platform has CPLD logic driving the A/D converter.
262 * The conversion must complete within 11 microseconds,
263 * otherwise we have to re-initiate a conversion.
265 udelay(TS5500_ADC_CONV_DELAY);
266 if (inb(TS5500_ADC_CONV_BUSY_ADDR) & TS5500_ADC_CONV_BUSY)
269 /* Read the raw data */
270 lsb = inb(TS5500_ADC_CONV_INIT_LSB_ADDR);
271 msb = inb(TS5500_ADC_CONV_MSB_ADDR);
273 return (msb << 8) | lsb;
276 static struct max197_platform_data ts5500_adc_pdata = {
277 .convert = ts5500_adc_convert,
280 static struct platform_device ts5500_adc_pdev = {
284 .platform_data = &ts5500_adc_pdata,
288 static int __init ts5500_init(void)
290 struct platform_device *pdev;
291 struct ts5500_sbc *sbc;
295 * There is no DMI available or PCI bridge subvendor info,
296 * only the BIOS provides a 16-bit identification call.
297 * It is safer to find a signature in the BIOS shadow RAM.
299 err = ts5500_check_signature();
303 pdev = platform_device_register_simple("ts5500", -1, NULL, 0);
305 return PTR_ERR(pdev);
307 sbc = devm_kzalloc(&pdev->dev, sizeof(struct ts5500_sbc), GFP_KERNEL);
313 err = ts5500_detect_config(sbc);
317 platform_set_drvdata(pdev, sbc);
319 err = sysfs_create_group(&pdev->dev.kobj, &ts5500_attr_group);
323 if (sbc->id == TS5500_PRODUCT_CODE) {
324 ts5500_dio1_pdev.dev.parent = &pdev->dev;
325 if (platform_device_register(&ts5500_dio1_pdev))
326 dev_warn(&pdev->dev, "DIO1 block registration failed\n");
327 ts5500_dio2_pdev.dev.parent = &pdev->dev;
328 if (platform_device_register(&ts5500_dio2_pdev))
329 dev_warn(&pdev->dev, "DIO2 block registration failed\n");
332 if (led_classdev_register(&pdev->dev, &ts5500_led_cdev))
333 dev_warn(&pdev->dev, "LED registration failed\n");
336 ts5500_adc_pdev.dev.parent = &pdev->dev;
337 if (platform_device_register(&ts5500_adc_pdev))
338 dev_warn(&pdev->dev, "ADC registration failed\n");
343 platform_device_unregister(pdev);
346 device_initcall(ts5500_init);