Alexander Shiyan | e328b88 | 2013-04-26 19:47:29 +0400 | [diff] [blame] | 1 | /* |
| 2 | * CLPS711X common devices definitions |
| 3 | * |
Alexander Shiyan | e4e3a37 | 2014-08-19 16:31:15 +0400 | [diff] [blame] | 4 | * Author: Alexander Shiyan <shc_work@mail.ru>, 2013-2014 |
Alexander Shiyan | e328b88 | 2013-04-26 19:47:29 +0400 | [diff] [blame] | 5 | * |
| 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 Shiyan | e4e3a37 | 2014-08-19 16:31:15 +0400 | [diff] [blame] | 12 | #include <linux/io.h> |
| 13 | #include <linux/of_fdt.h> |
Alexander Shiyan | e328b88 | 2013-04-26 19:47:29 +0400 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Alexander Shiyan | e4e3a37 | 2014-08-19 16:31:15 +0400 | [diff] [blame] | 15 | #include <linux/random.h> |
Alexander Shiyan | 6597619 | 2013-05-13 21:07:36 +0400 | [diff] [blame] | 16 | #include <linux/sizes.h> |
Alexander Shiyan | e4e3a37 | 2014-08-19 16:31:15 +0400 | [diff] [blame] | 17 | #include <linux/slab.h> |
| 18 | #include <linux/sys_soc.h> |
| 19 | |
| 20 | #include <asm/system_info.h> |
Alexander Shiyan | e328b88 | 2013-04-26 19:47:29 +0400 | [diff] [blame] | 21 | |
| 22 | #include <mach/hardware.h> |
| 23 | |
Alexander Shiyan | 2d57f24 | 2014-06-19 19:26:35 +0400 | [diff] [blame] | 24 | static const struct resource clps711x_cpuidle_res __initconst = |
| 25 | DEFINE_RES_MEM(CLPS711X_PHYS_BASE + HALT, SZ_128); |
| 26 | |
| 27 | static 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 Shiyan | e328b88 | 2013-04-26 19:47:29 +0400 | [diff] [blame] | 33 | static 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 | |
| 41 | static 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 Shiyan | 6597619 | 2013-05-13 21:07:36 +0400 | [diff] [blame] | 62 | const 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 | |
| 71 | static void __init clps711x_add_syscon(void) |
| 72 | { |
| 73 | unsigned i; |
| 74 | |
| 75 | for (i = 0; i < ARRAY_SIZE(clps711x_syscon_res); i++) |
Alexander Shiyan | 5104d26 | 2013-07-18 22:34:52 +0400 | [diff] [blame] | 76 | platform_device_register_simple("syscon", i + 1, |
Alexander Shiyan | 6597619 | 2013-05-13 21:07:36 +0400 | [diff] [blame] | 77 | &clps711x_syscon_res[i], 1); |
| 78 | } |
| 79 | |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 80 | static 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 | |
| 86 | static 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 | |
| 92 | static 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 Shiyan | e4e3a37 | 2014-08-19 16:31:15 +0400 | [diff] [blame] | 100 | static 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 | |
| 138 | out_unmap: |
| 139 | iounmap(base); |
| 140 | } |
| 141 | |
Alexander Shiyan | e328b88 | 2013-04-26 19:47:29 +0400 | [diff] [blame] | 142 | void __init clps711x_devices_init(void) |
| 143 | { |
Alexander Shiyan | 2d57f24 | 2014-06-19 19:26:35 +0400 | [diff] [blame] | 144 | clps711x_add_cpuidle(); |
Alexander Shiyan | e328b88 | 2013-04-26 19:47:29 +0400 | [diff] [blame] | 145 | clps711x_add_gpio(); |
Alexander Shiyan | 6597619 | 2013-05-13 21:07:36 +0400 | [diff] [blame] | 146 | clps711x_add_syscon(); |
Alexander Shiyan | bc00024 | 2013-12-11 19:50:50 +0400 | [diff] [blame] | 147 | clps711x_add_uart(); |
Alexander Shiyan | e4e3a37 | 2014-08-19 16:31:15 +0400 | [diff] [blame] | 148 | clps711x_soc_init(); |
Alexander Shiyan | e328b88 | 2013-04-26 19:47:29 +0400 | [diff] [blame] | 149 | } |