aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-08-04 20:20:08 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-04 20:20:08 -0400
commit8556d44fee6ded9f4287d7ff7b5cc9d8635b0be0 (patch)
treef74ccc0d0a332f5754bf8c9643a4e7b18d86a12c
parentce4747963252a30613ebf1c1df3d83b9526a342e (diff)
parent4c51cb005b29e6329d7e598bf835689b230817c9 (diff)
Merge branch 'x86-platform-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 platform updates from Ingo Molnar: "The main changes in this cycle are: - Intel SOC driver updates, by Aubrey Li. - TS5500 platform updates, by Vivien Didelot" * 'x86-platform-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/pmc_atom: Silence shift wrapping warnings in pmc_sleep_tmr_show() x86/pmc_atom: Expose PMC device state and platform sleep state x86/pmc_atom: Eisable a few S0ix wake up events for S0ix residency x86/platform: New Intel Atom SOC power management controller driver x86/platform/ts5500: Add support for TS-5400 boards x86/platform/ts5500: Add a 'name' sysfs attribute x86/platform/ts5500: Use the DEVICE_ATTR_RO() macro
-rw-r--r--Documentation/ABI/testing/sysfs-platform-ts55007
-rw-r--r--arch/x86/Kconfig4
-rw-r--r--arch/x86/include/asm/pmc_atom.h107
-rw-r--r--arch/x86/kernel/Makefile1
-rw-r--r--arch/x86/kernel/pmc_atom.c321
-rw-r--r--arch/x86/platform/ts5500/ts5500.c94
6 files changed, 493 insertions, 41 deletions
diff --git a/Documentation/ABI/testing/sysfs-platform-ts5500 b/Documentation/ABI/testing/sysfs-platform-ts5500
index c88375a537a1..e685957caa12 100644
--- a/Documentation/ABI/testing/sysfs-platform-ts5500
+++ b/Documentation/ABI/testing/sysfs-platform-ts5500
@@ -30,6 +30,13 @@ Description:
30 the corresponding bit is set. For instance, 0x0e means jumpers 30 the corresponding bit is set. For instance, 0x0e means jumpers
31 2, 3 and 4 are set. 31 2, 3 and 4 are set.
32 32
33What: /sys/devices/platform/ts5500/name
34Date: July 2014
35KernelVersion: 3.16
36Contact: "Savoir-faire Linux Inc." <kernel@savoirfairelinux.com>
37Description:
38 Model name of the TS board, e.g. "TS-5500".
39
33What: /sys/devices/platform/ts5500/rs485 40What: /sys/devices/platform/ts5500/rs485
34Date: January 2013 41Date: January 2013
35KernelVersion: 3.7 42KernelVersion: 3.7
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 3fc7d724d0a3..86216a55eb59 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2404,6 +2404,10 @@ config IOSF_MBI
2404 default m 2404 default m
2405 depends on PCI 2405 depends on PCI
2406 2406
2407config PMC_ATOM
2408 def_bool y
2409 depends on PCI
2410
2407source "net/Kconfig" 2411source "net/Kconfig"
2408 2412
2409source "drivers/Kconfig" 2413source "drivers/Kconfig"
diff --git a/arch/x86/include/asm/pmc_atom.h b/arch/x86/include/asm/pmc_atom.h
new file mode 100644
index 000000000000..fc7a17c05d35
--- /dev/null
+++ b/arch/x86/include/asm/pmc_atom.h
@@ -0,0 +1,107 @@
1/*
2 * Intel Atom SOC Power Management Controller Header File
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#ifndef PMC_ATOM_H
17#define PMC_ATOM_H
18
19/* ValleyView Power Control Unit PCI Device ID */
20#define PCI_DEVICE_ID_VLV_PMC 0x0F1C
21
22/* PMC Memory mapped IO registers */
23#define PMC_BASE_ADDR_OFFSET 0x44
24#define PMC_BASE_ADDR_MASK 0xFFFFFE00
25#define PMC_MMIO_REG_LEN 0x100
26#define PMC_REG_BIT_WIDTH 32
27
28/* BIOS uses FUNC_DIS to disable specific function */
29#define PMC_FUNC_DIS 0x34
30#define PMC_FUNC_DIS_2 0x38
31
32/* S0ix wake event control */
33#define PMC_S0IX_WAKE_EN 0x3C
34
35#define BIT_LPC_CLOCK_RUN BIT(4)
36#define BIT_SHARED_IRQ_GPSC BIT(5)
37#define BIT_ORED_DEDICATED_IRQ_GPSS BIT(18)
38#define BIT_ORED_DEDICATED_IRQ_GPSC BIT(19)
39#define BIT_SHARED_IRQ_GPSS BIT(20)
40
41#define PMC_WAKE_EN_SETTING ~(BIT_LPC_CLOCK_RUN | \
42 BIT_SHARED_IRQ_GPSC | \
43 BIT_ORED_DEDICATED_IRQ_GPSS | \
44 BIT_ORED_DEDICATED_IRQ_GPSC | \
45 BIT_SHARED_IRQ_GPSS)
46
47/* The timers acumulate time spent in sleep state */
48#define PMC_S0IR_TMR 0x80
49#define PMC_S0I1_TMR 0x84
50#define PMC_S0I2_TMR 0x88
51#define PMC_S0I3_TMR 0x8C
52#define PMC_S0_TMR 0x90
53/* Sleep state counter is in units of of 32us */
54#define PMC_TMR_SHIFT 5
55
56/* These registers reflect D3 status of functions */
57#define PMC_D3_STS_0 0xA0
58
59#define BIT_LPSS1_F0_DMA BIT(0)
60#define BIT_LPSS1_F1_PWM1 BIT(1)
61#define BIT_LPSS1_F2_PWM2 BIT(2)
62#define BIT_LPSS1_F3_HSUART1 BIT(3)
63#define BIT_LPSS1_F4_HSUART2 BIT(4)
64#define BIT_LPSS1_F5_SPI BIT(5)
65#define BIT_LPSS1_F6_XXX BIT(6)
66#define BIT_LPSS1_F7_XXX BIT(7)
67#define BIT_SCC_EMMC BIT(8)
68#define BIT_SCC_SDIO BIT(9)
69#define BIT_SCC_SDCARD BIT(10)
70#define BIT_SCC_MIPI BIT(11)
71#define BIT_HDA BIT(12)
72#define BIT_LPE BIT(13)
73#define BIT_OTG BIT(14)
74#define BIT_USH BIT(15)
75#define BIT_GBE BIT(16)
76#define BIT_SATA BIT(17)
77#define BIT_USB_EHCI BIT(18)
78#define BIT_SEC BIT(19)
79#define BIT_PCIE_PORT0 BIT(20)
80#define BIT_PCIE_PORT1 BIT(21)
81#define BIT_PCIE_PORT2 BIT(22)
82#define BIT_PCIE_PORT3 BIT(23)
83#define BIT_LPSS2_F0_DMA BIT(24)
84#define BIT_LPSS2_F1_I2C1 BIT(25)
85#define BIT_LPSS2_F2_I2C2 BIT(26)
86#define BIT_LPSS2_F3_I2C3 BIT(27)
87#define BIT_LPSS2_F4_I2C4 BIT(28)
88#define BIT_LPSS2_F5_I2C5 BIT(29)
89#define BIT_LPSS2_F6_I2C6 BIT(30)
90#define BIT_LPSS2_F7_I2C7 BIT(31)
91
92#define PMC_D3_STS_1 0xA4
93#define BIT_SMB BIT(0)
94#define BIT_OTG_SS_PHY BIT(1)
95#define BIT_USH_SS_PHY BIT(2)
96#define BIT_DFX BIT(3)
97
98/* PMC I/O Registers */
99#define ACPI_BASE_ADDR_OFFSET 0x40
100#define ACPI_BASE_ADDR_MASK 0xFFFFFE00
101#define ACPI_MMIO_REG_LEN 0x100
102
103#define PM1_CNT 0x4
104#define SLEEP_TYPE_MASK 0xFFFFECFF
105#define SLEEP_TYPE_S5 0x1C00
106#define SLEEP_ENABLE 0x2000
107#endif /* PMC_ATOM_H */
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 047f9ff2e36c..bde3993624f1 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -106,6 +106,7 @@ obj-$(CONFIG_EFI) += sysfb_efi.o
106obj-$(CONFIG_PERF_EVENTS) += perf_regs.o 106obj-$(CONFIG_PERF_EVENTS) += perf_regs.o
107obj-$(CONFIG_TRACING) += tracepoint.o 107obj-$(CONFIG_TRACING) += tracepoint.o
108obj-$(CONFIG_IOSF_MBI) += iosf_mbi.o 108obj-$(CONFIG_IOSF_MBI) += iosf_mbi.o
109obj-$(CONFIG_PMC_ATOM) += pmc_atom.o
109 110
110### 111###
111# 64 bit specific files 112# 64 bit specific files
diff --git a/arch/x86/kernel/pmc_atom.c b/arch/x86/kernel/pmc_atom.c
new file mode 100644
index 000000000000..0c424a67985d
--- /dev/null
+++ b/arch/x86/kernel/pmc_atom.c
@@ -0,0 +1,321 @@
1/*
2 * Intel Atom SOC Power Management Controller Driver
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/pci.h>
21#include <linux/device.h>
22#include <linux/debugfs.h>
23#include <linux/seq_file.h>
24#include <linux/io.h>
25
26#include <asm/pmc_atom.h>
27
28#define DRIVER_NAME KBUILD_MODNAME
29
30struct pmc_dev {
31 u32 base_addr;
32 void __iomem *regmap;
33#ifdef CONFIG_DEBUG_FS
34 struct dentry *dbgfs_dir;
35#endif /* CONFIG_DEBUG_FS */
36};
37
38static struct pmc_dev pmc_device;
39static u32 acpi_base_addr;
40
41struct pmc_dev_map {
42 const char *name;
43 u32 bit_mask;
44};
45
46static const struct pmc_dev_map dev_map[] = {
47 {"0 - LPSS1_F0_DMA", BIT_LPSS1_F0_DMA},
48 {"1 - LPSS1_F1_PWM1", BIT_LPSS1_F1_PWM1},
49 {"2 - LPSS1_F2_PWM2", BIT_LPSS1_F2_PWM2},
50 {"3 - LPSS1_F3_HSUART1", BIT_LPSS1_F3_HSUART1},
51 {"4 - LPSS1_F4_HSUART2", BIT_LPSS1_F4_HSUART2},
52 {"5 - LPSS1_F5_SPI", BIT_LPSS1_F5_SPI},
53 {"6 - LPSS1_F6_Reserved", BIT_LPSS1_F6_XXX},
54 {"7 - LPSS1_F7_Reserved", BIT_LPSS1_F7_XXX},
55 {"8 - SCC_EMMC", BIT_SCC_EMMC},
56 {"9 - SCC_SDIO", BIT_SCC_SDIO},
57 {"10 - SCC_SDCARD", BIT_SCC_SDCARD},
58 {"11 - SCC_MIPI", BIT_SCC_MIPI},
59 {"12 - HDA", BIT_HDA},
60 {"13 - LPE", BIT_LPE},
61 {"14 - OTG", BIT_OTG},
62 {"15 - USH", BIT_USH},
63 {"16 - GBE", BIT_GBE},
64 {"17 - SATA", BIT_SATA},
65 {"18 - USB_EHCI", BIT_USB_EHCI},
66 {"19 - SEC", BIT_SEC},
67 {"20 - PCIE_PORT0", BIT_PCIE_PORT0},
68 {"21 - PCIE_PORT1", BIT_PCIE_PORT1},
69 {"22 - PCIE_PORT2", BIT_PCIE_PORT2},
70 {"23 - PCIE_PORT3", BIT_PCIE_PORT3},
71 {"24 - LPSS2_F0_DMA", BIT_LPSS2_F0_DMA},
72 {"25 - LPSS2_F1_I2C1", BIT_LPSS2_F1_I2C1},
73 {"26 - LPSS2_F2_I2C2", BIT_LPSS2_F2_I2C2},
74 {"27 - LPSS2_F3_I2C3", BIT_LPSS2_F3_I2C3},
75 {"28 - LPSS2_F3_I2C4", BIT_LPSS2_F4_I2C4},
76 {"29 - LPSS2_F5_I2C5", BIT_LPSS2_F5_I2C5},
77 {"30 - LPSS2_F6_I2C6", BIT_LPSS2_F6_I2C6},
78 {"31 - LPSS2_F7_I2C7", BIT_LPSS2_F7_I2C7},
79 {"32 - SMB", BIT_SMB},
80 {"33 - OTG_SS_PHY", BIT_OTG_SS_PHY},
81 {"34 - USH_SS_PHY", BIT_USH_SS_PHY},
82 {"35 - DFX", BIT_DFX},
83};
84
85static inline u32 pmc_reg_read(struct pmc_dev *pmc, int reg_offset)
86{
87 return readl(pmc->regmap + reg_offset);
88}
89
90static inline void pmc_reg_write(struct pmc_dev *pmc, int reg_offset, u32 val)
91{
92 writel(val, pmc->regmap + reg_offset);
93}
94
95static void pmc_power_off(void)
96{
97 u16 pm1_cnt_port;
98 u32 pm1_cnt_value;
99
100 pr_info("Preparing to enter system sleep state S5\n");
101
102 pm1_cnt_port = acpi_base_addr + PM1_CNT;
103
104 pm1_cnt_value = inl(pm1_cnt_port);
105 pm1_cnt_value &= SLEEP_TYPE_MASK;
106 pm1_cnt_value |= SLEEP_TYPE_S5;
107 pm1_cnt_value |= SLEEP_ENABLE;
108
109 outl(pm1_cnt_value, pm1_cnt_port);
110}
111
112static void pmc_hw_reg_setup(struct pmc_dev *pmc)
113{
114 /*
115 * Disable PMC S0IX_WAKE_EN events coming from:
116 * - LPC clock run
117 * - GPIO_SUS ored dedicated IRQs
118 * - GPIO_SCORE ored dedicated IRQs
119 * - GPIO_SUS shared IRQ
120 * - GPIO_SCORE shared IRQ
121 */
122 pmc_reg_write(pmc, PMC_S0IX_WAKE_EN, (u32)PMC_WAKE_EN_SETTING);
123}
124
125#ifdef CONFIG_DEBUG_FS
126static int pmc_dev_state_show(struct seq_file *s, void *unused)
127{
128 struct pmc_dev *pmc = s->private;
129 u32 func_dis, func_dis_2, func_dis_index;
130 u32 d3_sts_0, d3_sts_1, d3_sts_index;
131 int dev_num, dev_index, reg_index;
132
133 func_dis = pmc_reg_read(pmc, PMC_FUNC_DIS);
134 func_dis_2 = pmc_reg_read(pmc, PMC_FUNC_DIS_2);
135 d3_sts_0 = pmc_reg_read(pmc, PMC_D3_STS_0);
136 d3_sts_1 = pmc_reg_read(pmc, PMC_D3_STS_1);
137
138 dev_num = ARRAY_SIZE(dev_map);
139
140 for (dev_index = 0; dev_index < dev_num; dev_index++) {
141 reg_index = dev_index / PMC_REG_BIT_WIDTH;
142 if (reg_index) {
143 func_dis_index = func_dis_2;
144 d3_sts_index = d3_sts_1;
145 } else {
146 func_dis_index = func_dis;
147 d3_sts_index = d3_sts_0;
148 }
149
150 seq_printf(s, "Dev: %-32s\tState: %s [%s]\n",
151 dev_map[dev_index].name,
152 dev_map[dev_index].bit_mask & func_dis_index ?
153 "Disabled" : "Enabled ",
154 dev_map[dev_index].bit_mask & d3_sts_index ?
155 "D3" : "D0");
156 }
157 return 0;
158}
159
160static int pmc_dev_state_open(struct inode *inode, struct file *file)
161{
162 return single_open(file, pmc_dev_state_show, inode->i_private);
163}
164
165static const struct file_operations pmc_dev_state_ops = {
166 .open = pmc_dev_state_open,
167 .read = seq_read,
168 .llseek = seq_lseek,
169 .release = single_release,
170};
171
172static int pmc_sleep_tmr_show(struct seq_file *s, void *unused)
173{
174 struct pmc_dev *pmc = s->private;
175 u64 s0ir_tmr, s0i1_tmr, s0i2_tmr, s0i3_tmr, s0_tmr;
176
177 s0ir_tmr = (u64)pmc_reg_read(pmc, PMC_S0IR_TMR) << PMC_TMR_SHIFT;
178 s0i1_tmr = (u64)pmc_reg_read(pmc, PMC_S0I1_TMR) << PMC_TMR_SHIFT;
179 s0i2_tmr = (u64)pmc_reg_read(pmc, PMC_S0I2_TMR) << PMC_TMR_SHIFT;
180 s0i3_tmr = (u64)pmc_reg_read(pmc, PMC_S0I3_TMR) << PMC_TMR_SHIFT;
181 s0_tmr = (u64)pmc_reg_read(pmc, PMC_S0_TMR) << PMC_TMR_SHIFT;
182
183 seq_printf(s, "S0IR Residency:\t%lldus\n", s0ir_tmr);
184 seq_printf(s, "S0I1 Residency:\t%lldus\n", s0i1_tmr);
185 seq_printf(s, "S0I2 Residency:\t%lldus\n", s0i2_tmr);
186 seq_printf(s, "S0I3 Residency:\t%lldus\n", s0i3_tmr);
187 seq_printf(s, "S0 Residency:\t%lldus\n", s0_tmr);
188 return 0;
189}
190
191static int pmc_sleep_tmr_open(struct inode *inode, struct file *file)
192{
193 return single_open(file, pmc_sleep_tmr_show, inode->i_private);
194}
195
196static const struct file_operations pmc_sleep_tmr_ops = {
197 .open = pmc_sleep_tmr_open,
198 .read = seq_read,
199 .llseek = seq_lseek,
200 .release = single_release,
201};
202
203static void pmc_dbgfs_unregister(struct pmc_dev *pmc)
204{
205 if (!pmc->dbgfs_dir)
206 return;
207
208 debugfs_remove_recursive(pmc->dbgfs_dir);
209 pmc->dbgfs_dir = NULL;
210}
211
212static int pmc_dbgfs_register(struct pmc_dev *pmc, struct pci_dev *pdev)
213{
214 struct dentry *dir, *f;
215
216 dir = debugfs_create_dir("pmc_atom", NULL);
217 if (!dir)
218 return -ENOMEM;
219
220 f = debugfs_create_file("dev_state", S_IFREG | S_IRUGO,
221 dir, pmc, &pmc_dev_state_ops);
222 if (!f) {
223 dev_err(&pdev->dev, "dev_states register failed\n");
224 goto err;
225 }
226 f = debugfs_create_file("sleep_state", S_IFREG | S_IRUGO,
227 dir, pmc, &pmc_sleep_tmr_ops);
228 if (!f) {
229 dev_err(&pdev->dev, "sleep_state register failed\n");
230 goto err;
231 }
232 pmc->dbgfs_dir = dir;
233 return 0;
234err:
235 pmc_dbgfs_unregister(pmc);
236 return -ENODEV;
237}
238#endif /* CONFIG_DEBUG_FS */
239
240static int pmc_setup_dev(struct pci_dev *pdev)
241{
242 struct pmc_dev *pmc = &pmc_device;
243 int ret;
244
245 /* Obtain ACPI base address */
246 pci_read_config_dword(pdev, ACPI_BASE_ADDR_OFFSET, &acpi_base_addr);
247 acpi_base_addr &= ACPI_BASE_ADDR_MASK;
248
249 /* Install power off function */
250 if (acpi_base_addr != 0 && pm_power_off == NULL)
251 pm_power_off = pmc_power_off;
252
253 pci_read_config_dword(pdev, PMC_BASE_ADDR_OFFSET, &pmc->base_addr);
254 pmc->base_addr &= PMC_BASE_ADDR_MASK;
255
256 pmc->regmap = ioremap_nocache(pmc->base_addr, PMC_MMIO_REG_LEN);
257 if (!pmc->regmap) {
258 dev_err(&pdev->dev, "error: ioremap failed\n");
259 return -ENOMEM;
260 }
261
262 /* PMC hardware registers setup */
263 pmc_hw_reg_setup(pmc);
264
265#ifdef CONFIG_DEBUG_FS
266 ret = pmc_dbgfs_register(pmc, pdev);
267 if (ret) {
268 iounmap(pmc->regmap);
269 return ret;
270 }
271#endif /* CONFIG_DEBUG_FS */
272 return 0;
273}
274
275/*
276 * Data for PCI driver interface
277 *
278 * This data only exists for exporting the supported
279 * PCI ids via MODULE_DEVICE_TABLE. We do not actually
280 * register a pci_driver, because lpc_ich will register
281 * a driver on the same PCI id.
282 */
283static const struct pci_device_id pmc_pci_ids[] = {
284 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_VLV_PMC) },
285 { 0, },
286};
287
288MODULE_DEVICE_TABLE(pci, pmc_pci_ids);
289
290static int __init pmc_atom_init(void)
291{
292 int err = -ENODEV;
293 struct pci_dev *pdev = NULL;
294 const struct pci_device_id *ent;
295
296 /* We look for our device - PCU PMC
297 * we assume that there is max. one device.
298 *
299 * We can't use plain pci_driver mechanism,
300 * as the device is really a multiple function device,
301 * main driver that binds to the pci_device is lpc_ich
302 * and have to find & bind to the device this way.
303 */
304 for_each_pci_dev(pdev) {
305 ent = pci_match_id(pmc_pci_ids, pdev);
306 if (ent) {
307 err = pmc_setup_dev(pdev);
308 goto out;
309 }
310 }
311 /* Device not found. */
312out:
313 return err;
314}
315
316module_init(pmc_atom_init);
317/* no module_exit, this driver shouldn't be unloaded */
318
319MODULE_AUTHOR("Aubrey Li <aubrey.li@linux.intel.com>");
320MODULE_DESCRIPTION("Intel Atom SOC Power Management Controller Interface");
321MODULE_LICENSE("GPL v2");
diff --git a/arch/x86/platform/ts5500/ts5500.c b/arch/x86/platform/ts5500/ts5500.c
index 9471b9456f25..baf16e72e668 100644
--- a/arch/x86/platform/ts5500/ts5500.c
+++ b/arch/x86/platform/ts5500/ts5500.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Technologic Systems TS-5500 Single Board Computer support 2 * Technologic Systems TS-5500 Single Board Computer support
3 * 3 *
4 * Copyright (C) 2013 Savoir-faire Linux Inc. 4 * Copyright (C) 2013-2014 Savoir-faire Linux Inc.
5 * Vivien Didelot <vivien.didelot@savoirfairelinux.com> 5 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it under 7 * This program is free software; you can redistribute it and/or modify it under
@@ -15,8 +15,8 @@
15 * state or available options. For further information about sysfs entries, see 15 * state or available options. For further information about sysfs entries, see
16 * Documentation/ABI/testing/sysfs-platform-ts5500. 16 * Documentation/ABI/testing/sysfs-platform-ts5500.
17 * 17 *
18 * This code actually supports the TS-5500 platform, but it may be extended to 18 * This code may be extended to support similar x86-based platforms.
19 * support similar Technologic Systems x86-based platforms, such as the TS-5600. 19 * Actually, the TS-5500 and TS-5400 are supported.
20 */ 20 */
21 21
22#include <linux/delay.h> 22#include <linux/delay.h>
@@ -32,6 +32,7 @@
32/* Product code register */ 32/* Product code register */
33#define TS5500_PRODUCT_CODE_ADDR 0x74 33#define TS5500_PRODUCT_CODE_ADDR 0x74
34#define TS5500_PRODUCT_CODE 0x60 /* TS-5500 product code */ 34#define TS5500_PRODUCT_CODE 0x60 /* TS-5500 product code */
35#define TS5400_PRODUCT_CODE 0x40 /* TS-5400 product code */
35 36
36/* SRAM/RS-485/ADC options, and RS-485 RTS/Automatic RS-485 flags register */ 37/* 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_RS485_ADC_ADDR 0x75
@@ -66,6 +67,7 @@
66 67
67/** 68/**
68 * struct ts5500_sbc - TS-5500 board description 69 * struct ts5500_sbc - TS-5500 board description
70 * @name: Board model name.
69 * @id: Board product ID. 71 * @id: Board product ID.
70 * @sram: Flag for SRAM option. 72 * @sram: Flag for SRAM option.
71 * @rs485: Flag for RS-485 option. 73 * @rs485: Flag for RS-485 option.
@@ -75,6 +77,7 @@
75 * @jumpers: Bitfield for jumpers' state. 77 * @jumpers: Bitfield for jumpers' state.
76 */ 78 */
77struct ts5500_sbc { 79struct ts5500_sbc {
80 const char *name;
78 int id; 81 int id;
79 bool sram; 82 bool sram;
80 bool rs485; 83 bool rs485;
@@ -122,13 +125,16 @@ static int __init ts5500_detect_config(struct ts5500_sbc *sbc)
122 if (!request_region(TS5500_PRODUCT_CODE_ADDR, 4, "ts5500")) 125 if (!request_region(TS5500_PRODUCT_CODE_ADDR, 4, "ts5500"))
123 return -EBUSY; 126 return -EBUSY;
124 127
125 tmp = inb(TS5500_PRODUCT_CODE_ADDR); 128 sbc->id = inb(TS5500_PRODUCT_CODE_ADDR);
126 if (tmp != TS5500_PRODUCT_CODE) { 129 if (sbc->id == TS5500_PRODUCT_CODE) {
127 pr_err("This platform is not a TS-5500 (found ID 0x%x)\n", tmp); 130 sbc->name = "TS-5500";
131 } else if (sbc->id == TS5400_PRODUCT_CODE) {
132 sbc->name = "TS-5400";
133 } else {
134 pr_err("ts5500: unknown product code 0x%x\n", sbc->id);
128 ret = -ENODEV; 135 ret = -ENODEV;
129 goto cleanup; 136 goto cleanup;
130 } 137 }
131 sbc->id = tmp;
132 138
133 tmp = inb(TS5500_SRAM_RS485_ADC_ADDR); 139 tmp = inb(TS5500_SRAM_RS485_ADC_ADDR);
134 sbc->sram = tmp & TS5500_SRAM; 140 sbc->sram = tmp & TS5500_SRAM;
@@ -147,48 +153,52 @@ cleanup:
147 return ret; 153 return ret;
148} 154}
149 155
150static ssize_t ts5500_show_id(struct device *dev, 156static ssize_t name_show(struct device *dev, struct device_attribute *attr,
151 struct device_attribute *attr, char *buf) 157 char *buf)
152{ 158{
153 struct ts5500_sbc *sbc = dev_get_drvdata(dev); 159 struct ts5500_sbc *sbc = dev_get_drvdata(dev);
154 160
155 return sprintf(buf, "0x%.2x\n", sbc->id); 161 return sprintf(buf, "%s\n", sbc->name);
156} 162}
163static DEVICE_ATTR_RO(name);
157 164
158static ssize_t ts5500_show_jumpers(struct device *dev, 165static ssize_t id_show(struct device *dev, struct device_attribute *attr,
159 struct device_attribute *attr, 166 char *buf)
160 char *buf)
161{ 167{
162 struct ts5500_sbc *sbc = dev_get_drvdata(dev); 168 struct ts5500_sbc *sbc = dev_get_drvdata(dev);
163 169
164 return sprintf(buf, "0x%.2x\n", sbc->jumpers >> 1); 170 return sprintf(buf, "0x%.2x\n", sbc->id);
165} 171}
172static DEVICE_ATTR_RO(id);
166 173
167#define TS5500_SHOW(field) \ 174static ssize_t jumpers_show(struct device *dev, struct device_attribute *attr,
168 static ssize_t ts5500_show_##field(struct device *dev, \ 175 char *buf)
169 struct device_attribute *attr, \ 176{
170 char *buf) \ 177 struct ts5500_sbc *sbc = dev_get_drvdata(dev);
171 { \
172 struct ts5500_sbc *sbc = dev_get_drvdata(dev); \
173 return sprintf(buf, "%d\n", sbc->field); \
174 }
175
176TS5500_SHOW(sram)
177TS5500_SHOW(rs485)
178TS5500_SHOW(adc)
179TS5500_SHOW(ereset)
180TS5500_SHOW(itr)
181 178
182static DEVICE_ATTR(id, S_IRUGO, ts5500_show_id, NULL); 179 return sprintf(buf, "0x%.2x\n", sbc->jumpers >> 1);
183static DEVICE_ATTR(jumpers, S_IRUGO, ts5500_show_jumpers, NULL); 180}
184static DEVICE_ATTR(sram, S_IRUGO, ts5500_show_sram, NULL); 181static DEVICE_ATTR_RO(jumpers);
185static DEVICE_ATTR(rs485, S_IRUGO, ts5500_show_rs485, NULL); 182
186static DEVICE_ATTR(adc, S_IRUGO, ts5500_show_adc, NULL); 183#define TS5500_ATTR_BOOL(_field) \
187static DEVICE_ATTR(ereset, S_IRUGO, ts5500_show_ereset, NULL); 184 static ssize_t _field##_show(struct device *dev, \
188static DEVICE_ATTR(itr, S_IRUGO, ts5500_show_itr, NULL); 185 struct device_attribute *attr, char *buf) \
186 { \
187 struct ts5500_sbc *sbc = dev_get_drvdata(dev); \
188 \
189 return sprintf(buf, "%d\n", sbc->_field); \
190 } \
191 static DEVICE_ATTR_RO(_field)
192
193TS5500_ATTR_BOOL(sram);
194TS5500_ATTR_BOOL(rs485);
195TS5500_ATTR_BOOL(adc);
196TS5500_ATTR_BOOL(ereset);
197TS5500_ATTR_BOOL(itr);
189 198
190static struct attribute *ts5500_attributes[] = { 199static struct attribute *ts5500_attributes[] = {
191 &dev_attr_id.attr, 200 &dev_attr_id.attr,
201 &dev_attr_name.attr,
192 &dev_attr_jumpers.attr, 202 &dev_attr_jumpers.attr,
193 &dev_attr_sram.attr, 203 &dev_attr_sram.attr,
194 &dev_attr_rs485.attr, 204 &dev_attr_rs485.attr,
@@ -311,12 +321,14 @@ static int __init ts5500_init(void)
311 if (err) 321 if (err)
312 goto error; 322 goto error;
313 323
314 ts5500_dio1_pdev.dev.parent = &pdev->dev; 324 if (sbc->id == TS5500_PRODUCT_CODE) {
315 if (platform_device_register(&ts5500_dio1_pdev)) 325 ts5500_dio1_pdev.dev.parent = &pdev->dev;
316 dev_warn(&pdev->dev, "DIO1 block registration failed\n"); 326 if (platform_device_register(&ts5500_dio1_pdev))
317 ts5500_dio2_pdev.dev.parent = &pdev->dev; 327 dev_warn(&pdev->dev, "DIO1 block registration failed\n");
318 if (platform_device_register(&ts5500_dio2_pdev)) 328 ts5500_dio2_pdev.dev.parent = &pdev->dev;
319 dev_warn(&pdev->dev, "DIO2 block registration failed\n"); 329 if (platform_device_register(&ts5500_dio2_pdev))
330 dev_warn(&pdev->dev, "DIO2 block registration failed\n");
331 }
320 332
321 if (led_classdev_register(&pdev->dev, &ts5500_led_cdev)) 333 if (led_classdev_register(&pdev->dev, &ts5500_led_cdev))
322 dev_warn(&pdev->dev, "LED registration failed\n"); 334 dev_warn(&pdev->dev, "LED registration failed\n");