1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Technologic Systems TS-5500 Single Board Computer support
5 * Copyright (C) 2013-2014 Savoir-faire Linux Inc.
6 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
8 * This driver registers the Technologic Systems TS-5500 Single Board Computer
9 * (SBC) and its devices, and exposes information to userspace such as jumpers'
10 * state or available options. For further information about sysfs entries, see
11 * Documentation/ABI/testing/sysfs-platform-ts5500.
13 * This code may be extended to support similar x86-based platforms.
14 * Actually, the TS-5500 and TS-5400 are supported.
17 #include <linux/delay.h>
19 #include <linux/kernel.h>
20 #include <linux/leds.h>
21 #include <linux/init.h>
22 #include <linux/platform_data/max197.h>
23 #include <linux/platform_device.h>
24 #include <linux/slab.h>
26 /* Product code register */
27 #define TS5500_PRODUCT_CODE_ADDR 0x74
28 #define TS5500_PRODUCT_CODE 0x60 /* TS-5500 product code */
29 #define TS5400_PRODUCT_CODE 0x40 /* TS-5400 product code */
31 /* SRAM/RS-485/ADC options, and RS-485 RTS/Automatic RS-485 flags register */
32 #define TS5500_SRAM_RS485_ADC_ADDR 0x75
33 #define TS5500_SRAM BIT(0) /* SRAM option */
34 #define TS5500_RS485 BIT(1) /* RS-485 option */
35 #define TS5500_ADC BIT(2) /* A/D converter option */
36 #define TS5500_RS485_RTS BIT(6) /* RTS for RS-485 */
37 #define TS5500_RS485_AUTO BIT(7) /* Automatic RS-485 */
39 /* External Reset/Industrial Temperature Range options register */
40 #define TS5500_ERESET_ITR_ADDR 0x76
41 #define TS5500_ERESET BIT(0) /* External Reset option */
42 #define TS5500_ITR BIT(1) /* Indust. Temp. Range option */
44 /* LED/Jumpers register */
45 #define TS5500_LED_JP_ADDR 0x77
46 #define TS5500_LED BIT(0) /* LED flag */
47 #define TS5500_JP1 BIT(1) /* Automatic CMOS */
48 #define TS5500_JP2 BIT(2) /* Enable Serial Console */
49 #define TS5500_JP3 BIT(3) /* Write Enable Drive A */
50 #define TS5500_JP4 BIT(4) /* Fast Console (115K baud) */
51 #define TS5500_JP5 BIT(5) /* User Jumper */
52 #define TS5500_JP6 BIT(6) /* Console on COM1 (req. JP2) */
53 #define TS5500_JP7 BIT(7) /* Undocumented (Unused) */
55 /* A/D Converter registers */
56 #define TS5500_ADC_CONV_BUSY_ADDR 0x195 /* Conversion state register */
57 #define TS5500_ADC_CONV_BUSY BIT(0)
58 #define TS5500_ADC_CONV_INIT_LSB_ADDR 0x196 /* Start conv. / LSB register */
59 #define TS5500_ADC_CONV_MSB_ADDR 0x197 /* MSB register */
60 #define TS5500_ADC_CONV_DELAY 12 /* usec */
63 * struct ts5500_sbc - TS-5500 board description
64 * @name: Board model name.
65 * @id: Board product ID.
66 * @sram: Flag for SRAM option.
67 * @rs485: Flag for RS-485 option.
68 * @adc: Flag for Analog/Digital converter option.
69 * @ereset: Flag for External Reset option.
70 * @itr: Flag for Industrial Temperature Range option.
71 * @jumpers: Bitfield for jumpers' state.
84 /* Board signatures in BIOS shadow RAM */
86 const char * const string
;
88 } ts5500_signatures
[] __initconst
= {
89 { "TS-5x00 AMD Elan", 0xb14 },
92 static int __init
ts5500_check_signature(void)
97 bios
= ioremap(0xf0000, 0x10000);
101 for (i
= 0; i
< ARRAY_SIZE(ts5500_signatures
); i
++) {
102 if (check_signature(bios
+ ts5500_signatures
[i
].offset
,
103 ts5500_signatures
[i
].string
,
104 strlen(ts5500_signatures
[i
].string
))) {
114 static int __init
ts5500_detect_config(struct ts5500_sbc
*sbc
)
119 if (!request_region(TS5500_PRODUCT_CODE_ADDR
, 4, "ts5500"))
122 sbc
->id
= inb(TS5500_PRODUCT_CODE_ADDR
);
123 if (sbc
->id
== TS5500_PRODUCT_CODE
) {
124 sbc
->name
= "TS-5500";
125 } else if (sbc
->id
== TS5400_PRODUCT_CODE
) {
126 sbc
->name
= "TS-5400";
128 pr_err("ts5500: unknown product code 0x%x\n", sbc
->id
);
133 tmp
= inb(TS5500_SRAM_RS485_ADC_ADDR
);
134 sbc
->sram
= tmp
& TS5500_SRAM
;
135 sbc
->rs485
= tmp
& TS5500_RS485
;
136 sbc
->adc
= tmp
& TS5500_ADC
;
138 tmp
= inb(TS5500_ERESET_ITR_ADDR
);
139 sbc
->ereset
= tmp
& TS5500_ERESET
;
140 sbc
->itr
= tmp
& TS5500_ITR
;
142 tmp
= inb(TS5500_LED_JP_ADDR
);
143 sbc
->jumpers
= tmp
& ~TS5500_LED
;
146 release_region(TS5500_PRODUCT_CODE_ADDR
, 4);
150 static ssize_t
name_show(struct device
*dev
, struct device_attribute
*attr
,
153 struct ts5500_sbc
*sbc
= dev_get_drvdata(dev
);
155 return sprintf(buf
, "%s\n", sbc
->name
);
157 static DEVICE_ATTR_RO(name
);
159 static ssize_t
id_show(struct device
*dev
, struct device_attribute
*attr
,
162 struct ts5500_sbc
*sbc
= dev_get_drvdata(dev
);
164 return sprintf(buf
, "0x%.2x\n", sbc
->id
);
166 static DEVICE_ATTR_RO(id
);
168 static ssize_t
jumpers_show(struct device
*dev
, struct device_attribute
*attr
,
171 struct ts5500_sbc
*sbc
= dev_get_drvdata(dev
);
173 return sprintf(buf
, "0x%.2x\n", sbc
->jumpers
>> 1);
175 static DEVICE_ATTR_RO(jumpers
);
177 #define TS5500_ATTR_BOOL(_field) \
178 static ssize_t _field##_show(struct device *dev, \
179 struct device_attribute *attr, char *buf) \
181 struct ts5500_sbc *sbc = dev_get_drvdata(dev); \
183 return sprintf(buf, "%d\n", sbc->_field); \
185 static DEVICE_ATTR_RO(_field)
187 TS5500_ATTR_BOOL(sram
);
188 TS5500_ATTR_BOOL(rs485
);
189 TS5500_ATTR_BOOL(adc
);
190 TS5500_ATTR_BOOL(ereset
);
191 TS5500_ATTR_BOOL(itr
);
193 static struct attribute
*ts5500_attributes
[] = {
196 &dev_attr_jumpers
.attr
,
198 &dev_attr_rs485
.attr
,
200 &dev_attr_ereset
.attr
,
205 static const struct attribute_group ts5500_attr_group
= {
206 .attrs
= ts5500_attributes
,
209 static struct resource ts5500_dio1_resource
[] = {
210 DEFINE_RES_IRQ_NAMED(7, "DIO1 interrupt"),
213 static struct platform_device ts5500_dio1_pdev
= {
214 .name
= "ts5500-dio1",
216 .resource
= ts5500_dio1_resource
,
220 static struct resource ts5500_dio2_resource
[] = {
221 DEFINE_RES_IRQ_NAMED(6, "DIO2 interrupt"),
224 static struct platform_device ts5500_dio2_pdev
= {
225 .name
= "ts5500-dio2",
227 .resource
= ts5500_dio2_resource
,
231 static void ts5500_led_set(struct led_classdev
*led_cdev
,
232 enum led_brightness brightness
)
234 outb(!!brightness
, TS5500_LED_JP_ADDR
);
237 static enum led_brightness
ts5500_led_get(struct led_classdev
*led_cdev
)
239 return (inb(TS5500_LED_JP_ADDR
) & TS5500_LED
) ? LED_FULL
: LED_OFF
;
242 static struct led_classdev ts5500_led_cdev
= {
243 .name
= "ts5500:green:",
244 .brightness_set
= ts5500_led_set
,
245 .brightness_get
= ts5500_led_get
,
248 static int ts5500_adc_convert(u8 ctrl
)
252 /* Start conversion (ensure the 3 MSB are set to 0) */
253 outb(ctrl
& 0x1f, TS5500_ADC_CONV_INIT_LSB_ADDR
);
256 * The platform has CPLD logic driving the A/D converter.
257 * The conversion must complete within 11 microseconds,
258 * otherwise we have to re-initiate a conversion.
260 udelay(TS5500_ADC_CONV_DELAY
);
261 if (inb(TS5500_ADC_CONV_BUSY_ADDR
) & TS5500_ADC_CONV_BUSY
)
264 /* Read the raw data */
265 lsb
= inb(TS5500_ADC_CONV_INIT_LSB_ADDR
);
266 msb
= inb(TS5500_ADC_CONV_MSB_ADDR
);
268 return (msb
<< 8) | lsb
;
271 static struct max197_platform_data ts5500_adc_pdata
= {
272 .convert
= ts5500_adc_convert
,
275 static struct platform_device ts5500_adc_pdev
= {
279 .platform_data
= &ts5500_adc_pdata
,
283 static int __init
ts5500_init(void)
285 struct platform_device
*pdev
;
286 struct ts5500_sbc
*sbc
;
290 * There is no DMI available or PCI bridge subvendor info,
291 * only the BIOS provides a 16-bit identification call.
292 * It is safer to find a signature in the BIOS shadow RAM.
294 err
= ts5500_check_signature();
298 pdev
= platform_device_register_simple("ts5500", -1, NULL
, 0);
300 return PTR_ERR(pdev
);
302 sbc
= devm_kzalloc(&pdev
->dev
, sizeof(struct ts5500_sbc
), GFP_KERNEL
);
308 err
= ts5500_detect_config(sbc
);
312 platform_set_drvdata(pdev
, sbc
);
314 err
= sysfs_create_group(&pdev
->dev
.kobj
, &ts5500_attr_group
);
318 if (sbc
->id
== TS5500_PRODUCT_CODE
) {
319 ts5500_dio1_pdev
.dev
.parent
= &pdev
->dev
;
320 if (platform_device_register(&ts5500_dio1_pdev
))
321 dev_warn(&pdev
->dev
, "DIO1 block registration failed\n");
322 ts5500_dio2_pdev
.dev
.parent
= &pdev
->dev
;
323 if (platform_device_register(&ts5500_dio2_pdev
))
324 dev_warn(&pdev
->dev
, "DIO2 block registration failed\n");
327 if (led_classdev_register(&pdev
->dev
, &ts5500_led_cdev
))
328 dev_warn(&pdev
->dev
, "LED registration failed\n");
331 ts5500_adc_pdev
.dev
.parent
= &pdev
->dev
;
332 if (platform_device_register(&ts5500_adc_pdev
))
333 dev_warn(&pdev
->dev
, "ADC registration failed\n");
338 platform_device_unregister(pdev
);
341 device_initcall(ts5500_init
);