blob: 77a9617c216d50d8c5746fd5429d066c7f1d74ce [file] [log] [blame]
Alexander Shiyane328b882013-04-26 19:47:29 +04001/*
2 * CLPS711X common devices definitions
3 *
Alexander Shiyane4e3a372014-08-19 16:31:15 +04004 * Author: Alexander Shiyan <shc_work@mail.ru>, 2013-2014
Alexander Shiyane328b882013-04-26 19:47:29 +04005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
Alexander Shiyane4e3a372014-08-19 16:31:15 +040012#include <linux/io.h>
13#include <linux/of_fdt.h>
Alexander Shiyane328b882013-04-26 19:47:29 +040014#include <linux/platform_device.h>
Alexander Shiyane4e3a372014-08-19 16:31:15 +040015#include <linux/random.h>
Alexander Shiyan65976192013-05-13 21:07:36 +040016#include <linux/sizes.h>
Alexander Shiyane4e3a372014-08-19 16:31:15 +040017#include <linux/slab.h>
18#include <linux/sys_soc.h>
19
20#include <asm/system_info.h>
Alexander Shiyane328b882013-04-26 19:47:29 +040021
22#include <mach/hardware.h>
23
Alexander Shiyan2d57f242014-06-19 19:26:35 +040024static const struct resource clps711x_cpuidle_res __initconst =
25 DEFINE_RES_MEM(CLPS711X_PHYS_BASE + HALT, SZ_128);
26
27static void __init clps711x_add_cpuidle(void)
28{
29 platform_device_register_simple("clps711x-cpuidle", PLATFORM_DEVID_NONE,
30 &clps711x_cpuidle_res, 1);
31}
32
Alexander Shiyane328b882013-04-26 19:47:29 +040033static const phys_addr_t clps711x_gpios[][2] __initconst = {
34 { PADR, PADDR },
35 { PBDR, PBDDR },
36 { PCDR, PCDDR },
37 { PDDR, PDDDR },
38 { PEDR, PEDDR },
39};
40
41static void __init clps711x_add_gpio(void)
42{
43 unsigned i;
44 struct resource gpio_res[2];
45
46 memset(gpio_res, 0, sizeof(gpio_res));
47
48 gpio_res[0].flags = IORESOURCE_MEM;
49 gpio_res[1].flags = IORESOURCE_MEM;
50
51 for (i = 0; i < ARRAY_SIZE(clps711x_gpios); i++) {
52 gpio_res[0].start = CLPS711X_PHYS_BASE + clps711x_gpios[i][0];
53 gpio_res[0].end = gpio_res[0].start;
54 gpio_res[1].start = CLPS711X_PHYS_BASE + clps711x_gpios[i][1];
55 gpio_res[1].end = gpio_res[1].start;
56
57 platform_device_register_simple("clps711x-gpio", i,
58 gpio_res, ARRAY_SIZE(gpio_res));
59 }
60}
61
Alexander Shiyan65976192013-05-13 21:07:36 +040062const struct resource clps711x_syscon_res[] __initconst = {
63 /* SYSCON1, SYSFLG1 */
64 DEFINE_RES_MEM(CLPS711X_PHYS_BASE + SYSCON1, SZ_128),
65 /* SYSCON2, SYSFLG2 */
66 DEFINE_RES_MEM(CLPS711X_PHYS_BASE + SYSCON2, SZ_128),
67 /* SYSCON3 */
68 DEFINE_RES_MEM(CLPS711X_PHYS_BASE + SYSCON3, SZ_64),
69};
70
71static void __init clps711x_add_syscon(void)
72{
73 unsigned i;
74
75 for (i = 0; i < ARRAY_SIZE(clps711x_syscon_res); i++)
Alexander Shiyan5104d262013-07-18 22:34:52 +040076 platform_device_register_simple("syscon", i + 1,
Alexander Shiyan65976192013-05-13 21:07:36 +040077 &clps711x_syscon_res[i], 1);
78}
79
Alexander Shiyanbc000242013-12-11 19:50:50 +040080static const struct resource clps711x_uart1_res[] __initconst = {
81 DEFINE_RES_MEM(CLPS711X_PHYS_BASE + UARTDR1, SZ_128),
82 DEFINE_RES_IRQ(IRQ_UTXINT1),
83 DEFINE_RES_IRQ(IRQ_URXINT1),
84};
85
86static const struct resource clps711x_uart2_res[] __initconst = {
87 DEFINE_RES_MEM(CLPS711X_PHYS_BASE + UARTDR2, SZ_128),
88 DEFINE_RES_IRQ(IRQ_UTXINT2),
89 DEFINE_RES_IRQ(IRQ_URXINT2),
90};
91
92static void __init clps711x_add_uart(void)
93{
94 platform_device_register_simple("clps711x-uart", 0, clps711x_uart1_res,
95 ARRAY_SIZE(clps711x_uart1_res));
96 platform_device_register_simple("clps711x-uart", 1, clps711x_uart2_res,
97 ARRAY_SIZE(clps711x_uart2_res));
98};
99
Alexander Shiyane4e3a372014-08-19 16:31:15 +0400100static void __init clps711x_soc_init(void)
101{
102 struct soc_device_attribute *soc_dev_attr;
103 struct soc_device *soc_dev;
104 void __iomem *base;
105 u32 id[5];
106
107 base = ioremap(CLPS711X_PHYS_BASE, SZ_32K);
108 if (!base)
109 return;
110
111 id[0] = readl(base + UNIQID);
112 id[1] = readl(base + RANDID0);
113 id[2] = readl(base + RANDID1);
114 id[3] = readl(base + RANDID2);
115 id[4] = readl(base + RANDID3);
116 system_rev = SYSFLG1_VERID(readl(base + SYSFLG1));
117
118 add_device_randomness(id, sizeof(id));
119
120 system_serial_low = id[0];
121
122 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
123 if (!soc_dev_attr)
124 goto out_unmap;
125
126 soc_dev_attr->machine = of_flat_dt_get_machine_name();
127 soc_dev_attr->family = "Cirrus Logic CLPS711X";
128 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u", system_rev);
129 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%08x", id[0]);
130
131 soc_dev = soc_device_register(soc_dev_attr);
132 if (IS_ERR(soc_dev)) {
133 kfree(soc_dev_attr->revision);
134 kfree(soc_dev_attr->soc_id);
135 kfree(soc_dev_attr);
136 }
137
138out_unmap:
139 iounmap(base);
140}
141
Alexander Shiyane328b882013-04-26 19:47:29 +0400142void __init clps711x_devices_init(void)
143{
Alexander Shiyan2d57f242014-06-19 19:26:35 +0400144 clps711x_add_cpuidle();
Alexander Shiyane328b882013-04-26 19:47:29 +0400145 clps711x_add_gpio();
Alexander Shiyan65976192013-05-13 21:07:36 +0400146 clps711x_add_syscon();
Alexander Shiyanbc000242013-12-11 19:50:50 +0400147 clps711x_add_uart();
Alexander Shiyane4e3a372014-08-19 16:31:15 +0400148 clps711x_soc_init();
Alexander Shiyane328b882013-04-26 19:47:29 +0400149}