Matt Wagantall | 39f90cb | 2012-02-08 14:09:11 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/string.h> |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 15 | #include <linux/device.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 16 | #include <linux/firmware.h> |
| 17 | #include <linux/io.h> |
| 18 | #include <linux/debugfs.h> |
| 19 | #include <linux/elf.h> |
| 20 | #include <linux/mutex.h> |
| 21 | #include <linux/memblock.h> |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 22 | #include <linux/slab.h> |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 23 | #include <linux/atomic.h> |
Stephen Boyd | 80bde03 | 2012-03-16 00:14:42 -0700 | [diff] [blame] | 24 | #include <linux/suspend.h> |
| 25 | #include <linux/rwsem.h> |
Stephen Boyd | 20ad810 | 2011-10-09 21:28:01 -0700 | [diff] [blame] | 26 | #include <linux/sysfs.h> |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 27 | #include <linux/workqueue.h> |
| 28 | #include <linux/jiffies.h> |
| 29 | #include <linux/wakelock.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | |
| 31 | #include <asm/uaccess.h> |
| 32 | #include <asm/setup.h> |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 33 | #include <mach/peripheral-loader.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 34 | |
| 35 | #include "peripheral-loader.h" |
| 36 | |
Stephen Boyd | 20ad810 | 2011-10-09 21:28:01 -0700 | [diff] [blame] | 37 | enum pil_state { |
| 38 | PIL_OFFLINE, |
| 39 | PIL_ONLINE, |
| 40 | }; |
| 41 | |
| 42 | static const char *pil_states[] = { |
| 43 | [PIL_OFFLINE] = "OFFLINE", |
| 44 | [PIL_ONLINE] = "ONLINE", |
| 45 | }; |
| 46 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 47 | struct pil_device { |
| 48 | struct pil_desc *desc; |
| 49 | int count; |
Stephen Boyd | 20ad810 | 2011-10-09 21:28:01 -0700 | [diff] [blame] | 50 | enum pil_state state; |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 51 | struct mutex lock; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 52 | struct device dev; |
| 53 | struct module *owner; |
| 54 | #ifdef CONFIG_DEBUG_FS |
| 55 | struct dentry *dentry; |
| 56 | #endif |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 57 | struct delayed_work proxy; |
| 58 | struct wake_lock wlock; |
| 59 | char wake_name[32]; |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 62 | #define to_pil_device(d) container_of(d, struct pil_device, dev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 63 | |
Stephen Boyd | 20ad810 | 2011-10-09 21:28:01 -0700 | [diff] [blame] | 64 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, |
| 65 | char *buf) |
| 66 | { |
| 67 | return snprintf(buf, PAGE_SIZE, "%s\n", to_pil_device(dev)->desc->name); |
| 68 | } |
| 69 | |
| 70 | static ssize_t state_show(struct device *dev, struct device_attribute *attr, |
| 71 | char *buf) |
| 72 | { |
| 73 | enum pil_state state = to_pil_device(dev)->state; |
| 74 | return snprintf(buf, PAGE_SIZE, "%s\n", pil_states[state]); |
| 75 | } |
| 76 | |
| 77 | static struct device_attribute pil_attrs[] = { |
| 78 | __ATTR_RO(name), |
| 79 | __ATTR_RO(state), |
| 80 | { }, |
| 81 | }; |
| 82 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 83 | struct bus_type pil_bus_type = { |
| 84 | .name = "pil", |
Stephen Boyd | 20ad810 | 2011-10-09 21:28:01 -0700 | [diff] [blame] | 85 | .dev_attrs = pil_attrs, |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | static int __find_peripheral(struct device *dev, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 89 | { |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 90 | struct pil_device *pdev = to_pil_device(dev); |
| 91 | return !strncmp(pdev->desc->name, data, INT_MAX); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static struct pil_device *find_peripheral(const char *str) |
| 95 | { |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 96 | struct device *dev; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 97 | |
| 98 | if (!str) |
| 99 | return NULL; |
| 100 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 101 | dev = bus_find_device(&pil_bus_type, NULL, (void *)str, |
| 102 | __find_peripheral); |
| 103 | return dev ? to_pil_device(dev) : NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 106 | static void pil_proxy_work(struct work_struct *work) |
| 107 | { |
| 108 | struct pil_device *pil; |
| 109 | |
| 110 | pil = container_of(work, struct pil_device, proxy.work); |
| 111 | pil->desc->ops->proxy_unvote(pil->desc); |
| 112 | wake_unlock(&pil->wlock); |
| 113 | } |
| 114 | |
| 115 | static int pil_proxy_vote(struct pil_device *pil) |
| 116 | { |
Stephen Boyd | 0a56314 | 2012-07-02 13:33:31 -0700 | [diff] [blame] | 117 | int ret = 0; |
| 118 | |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 119 | if (pil->desc->ops->proxy_vote) { |
| 120 | wake_lock(&pil->wlock); |
Stephen Boyd | 0a56314 | 2012-07-02 13:33:31 -0700 | [diff] [blame] | 121 | ret = pil->desc->ops->proxy_vote(pil->desc); |
| 122 | if (ret) |
| 123 | wake_unlock(&pil->wlock); |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 124 | } |
Stephen Boyd | 0a56314 | 2012-07-02 13:33:31 -0700 | [diff] [blame] | 125 | return ret; |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static void pil_proxy_unvote(struct pil_device *pil, unsigned long timeout) |
| 129 | { |
| 130 | if (pil->desc->ops->proxy_unvote) |
| 131 | schedule_delayed_work(&pil->proxy, msecs_to_jiffies(timeout)); |
| 132 | } |
| 133 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 134 | #define IOMAP_SIZE SZ_4M |
| 135 | |
| 136 | static int load_segment(const struct elf32_phdr *phdr, unsigned num, |
| 137 | struct pil_device *pil) |
| 138 | { |
Stephen Boyd | b0f1f80 | 2012-02-03 11:28:08 -0800 | [diff] [blame] | 139 | int ret = 0, count, paddr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 140 | char fw_name[30]; |
| 141 | const struct firmware *fw = NULL; |
| 142 | const u8 *data; |
| 143 | |
Stephen Boyd | f79af53 | 2012-05-14 18:57:26 -0700 | [diff] [blame] | 144 | if (memblock_overlaps_memory(phdr->p_paddr, phdr->p_memsz)) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 145 | dev_err(&pil->dev, "%s: kernel memory would be overwritten " |
| 146 | "[%#08lx, %#08lx)\n", pil->desc->name, |
Stephen Boyd | f79af53 | 2012-05-14 18:57:26 -0700 | [diff] [blame] | 147 | (unsigned long)phdr->p_paddr, |
| 148 | (unsigned long)(phdr->p_paddr + phdr->p_memsz)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 149 | return -EPERM; |
| 150 | } |
| 151 | |
| 152 | if (phdr->p_filesz) { |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 153 | snprintf(fw_name, ARRAY_SIZE(fw_name), "%s.b%02d", |
| 154 | pil->desc->name, num); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 155 | ret = request_firmware(&fw, fw_name, &pil->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 156 | if (ret) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 157 | dev_err(&pil->dev, "%s: Failed to locate blob %s\n", |
| 158 | pil->desc->name, fw_name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 159 | return ret; |
| 160 | } |
| 161 | |
| 162 | if (fw->size != phdr->p_filesz) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 163 | dev_err(&pil->dev, "%s: Blob size %u doesn't match " |
| 164 | "%u\n", pil->desc->name, fw->size, |
| 165 | phdr->p_filesz); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 166 | ret = -EPERM; |
| 167 | goto release_fw; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /* Load the segment into memory */ |
| 172 | count = phdr->p_filesz; |
| 173 | paddr = phdr->p_paddr; |
| 174 | data = fw ? fw->data : NULL; |
| 175 | while (count > 0) { |
| 176 | int size; |
| 177 | u8 __iomem *buf; |
| 178 | |
| 179 | size = min_t(size_t, IOMAP_SIZE, count); |
| 180 | buf = ioremap(paddr, size); |
| 181 | if (!buf) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 182 | dev_err(&pil->dev, "%s: Failed to map memory\n", |
| 183 | pil->desc->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 184 | ret = -ENOMEM; |
| 185 | goto release_fw; |
| 186 | } |
| 187 | memcpy(buf, data, size); |
| 188 | iounmap(buf); |
| 189 | |
| 190 | count -= size; |
| 191 | paddr += size; |
| 192 | data += size; |
| 193 | } |
| 194 | |
| 195 | /* Zero out trailing memory */ |
| 196 | count = phdr->p_memsz - phdr->p_filesz; |
| 197 | while (count > 0) { |
| 198 | int size; |
| 199 | u8 __iomem *buf; |
| 200 | |
| 201 | size = min_t(size_t, IOMAP_SIZE, count); |
| 202 | buf = ioremap(paddr, size); |
| 203 | if (!buf) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 204 | dev_err(&pil->dev, "%s: Failed to map memory\n", |
| 205 | pil->desc->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 206 | ret = -ENOMEM; |
| 207 | goto release_fw; |
| 208 | } |
| 209 | memset(buf, 0, size); |
| 210 | iounmap(buf); |
| 211 | |
| 212 | count -= size; |
| 213 | paddr += size; |
| 214 | } |
| 215 | |
Stephen Boyd | b0f1f80 | 2012-02-03 11:28:08 -0800 | [diff] [blame] | 216 | if (pil->desc->ops->verify_blob) { |
| 217 | ret = pil->desc->ops->verify_blob(pil->desc, phdr->p_paddr, |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 218 | phdr->p_memsz); |
Stephen Boyd | b0f1f80 | 2012-02-03 11:28:08 -0800 | [diff] [blame] | 219 | if (ret) |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 220 | dev_err(&pil->dev, "%s: Blob%u failed verification\n", |
| 221 | pil->desc->name, num); |
Stephen Boyd | b0f1f80 | 2012-02-03 11:28:08 -0800 | [diff] [blame] | 222 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 223 | |
| 224 | release_fw: |
| 225 | release_firmware(fw); |
| 226 | return ret; |
| 227 | } |
| 228 | |
| 229 | #define segment_is_hash(flag) (((flag) & (0x7 << 24)) == (0x2 << 24)) |
| 230 | |
| 231 | static int segment_is_loadable(const struct elf32_phdr *p) |
| 232 | { |
Tianyi Gou | 17eae0d | 2012-06-28 17:19:37 -0700 | [diff] [blame] | 233 | return (p->p_type == PT_LOAD) && !segment_is_hash(p->p_flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Stephen Boyd | 80bde03 | 2012-03-16 00:14:42 -0700 | [diff] [blame] | 236 | /* Sychronize request_firmware() with suspend */ |
| 237 | static DECLARE_RWSEM(pil_pm_rwsem); |
| 238 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 239 | static int load_image(struct pil_device *pil) |
| 240 | { |
| 241 | int i, ret; |
| 242 | char fw_name[30]; |
| 243 | struct elf32_hdr *ehdr; |
| 244 | const struct elf32_phdr *phdr; |
| 245 | const struct firmware *fw; |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 246 | unsigned long proxy_timeout = pil->desc->proxy_timeout; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 247 | |
Stephen Boyd | 80bde03 | 2012-03-16 00:14:42 -0700 | [diff] [blame] | 248 | down_read(&pil_pm_rwsem); |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 249 | snprintf(fw_name, sizeof(fw_name), "%s.mdt", pil->desc->name); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 250 | ret = request_firmware(&fw, fw_name, &pil->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 251 | if (ret) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 252 | dev_err(&pil->dev, "%s: Failed to locate %s\n", |
| 253 | pil->desc->name, fw_name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 254 | goto out; |
| 255 | } |
| 256 | |
| 257 | if (fw->size < sizeof(*ehdr)) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 258 | dev_err(&pil->dev, "%s: Not big enough to be an elf header\n", |
| 259 | pil->desc->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 260 | ret = -EIO; |
| 261 | goto release_fw; |
| 262 | } |
| 263 | |
| 264 | ehdr = (struct elf32_hdr *)fw->data; |
| 265 | if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG)) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 266 | dev_err(&pil->dev, "%s: Not an elf header\n", pil->desc->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 267 | ret = -EIO; |
| 268 | goto release_fw; |
| 269 | } |
| 270 | |
| 271 | if (ehdr->e_phnum == 0) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 272 | dev_err(&pil->dev, "%s: No loadable segments\n", |
| 273 | pil->desc->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 274 | ret = -EIO; |
| 275 | goto release_fw; |
| 276 | } |
Stephen Boyd | 96a9f90 | 2011-07-18 18:43:00 -0700 | [diff] [blame] | 277 | if (sizeof(struct elf32_phdr) * ehdr->e_phnum + |
| 278 | sizeof(struct elf32_hdr) > fw->size) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 279 | dev_err(&pil->dev, "%s: Program headers not within mdt\n", |
| 280 | pil->desc->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 281 | ret = -EIO; |
| 282 | goto release_fw; |
| 283 | } |
| 284 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 285 | ret = pil->desc->ops->init_image(pil->desc, fw->data, fw->size); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 286 | if (ret) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 287 | dev_err(&pil->dev, "%s: Invalid firmware metadata\n", |
| 288 | pil->desc->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 289 | goto release_fw; |
| 290 | } |
| 291 | |
Stephen Boyd | c9753e1 | 2011-07-13 17:58:48 -0700 | [diff] [blame] | 292 | phdr = (const struct elf32_phdr *)(fw->data + sizeof(struct elf32_hdr)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 293 | for (i = 0; i < ehdr->e_phnum; i++, phdr++) { |
| 294 | if (!segment_is_loadable(phdr)) |
| 295 | continue; |
| 296 | |
| 297 | ret = load_segment(phdr, i, pil); |
| 298 | if (ret) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 299 | dev_err(&pil->dev, "%s: Failed to load segment %d\n", |
| 300 | pil->desc->name, i); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 301 | goto release_fw; |
| 302 | } |
| 303 | } |
| 304 | |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 305 | ret = pil_proxy_vote(pil); |
| 306 | if (ret) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 307 | dev_err(&pil->dev, "%s: Failed to proxy vote\n", |
| 308 | pil->desc->name); |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 309 | goto release_fw; |
| 310 | } |
| 311 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 312 | ret = pil->desc->ops->auth_and_reset(pil->desc); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 313 | if (ret) { |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 314 | dev_err(&pil->dev, "%s: Failed to bring out of reset\n", |
| 315 | pil->desc->name); |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 316 | proxy_timeout = 0; /* Remove proxy vote immediately on error */ |
| 317 | goto err_boot; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 318 | } |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 319 | dev_info(&pil->dev, "%s: Brought out of reset\n", pil->desc->name); |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 320 | err_boot: |
| 321 | pil_proxy_unvote(pil, proxy_timeout); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 322 | release_fw: |
| 323 | release_firmware(fw); |
| 324 | out: |
Stephen Boyd | 80bde03 | 2012-03-16 00:14:42 -0700 | [diff] [blame] | 325 | up_read(&pil_pm_rwsem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 326 | return ret; |
| 327 | } |
| 328 | |
Stephen Boyd | 20ad810 | 2011-10-09 21:28:01 -0700 | [diff] [blame] | 329 | static void pil_set_state(struct pil_device *pil, enum pil_state state) |
| 330 | { |
| 331 | if (pil->state != state) { |
| 332 | pil->state = state; |
| 333 | sysfs_notify(&pil->dev.kobj, NULL, "state"); |
| 334 | } |
| 335 | } |
| 336 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 337 | /** |
| 338 | * pil_get() - Load a peripheral into memory and take it out of reset |
| 339 | * @name: pointer to a string containing the name of the peripheral to load |
| 340 | * |
| 341 | * This function returns a pointer if it succeeds. If an error occurs an |
| 342 | * ERR_PTR is returned. |
| 343 | * |
| 344 | * If PIL is not enabled in the kernel, the value %NULL will be returned. |
| 345 | */ |
| 346 | void *pil_get(const char *name) |
| 347 | { |
| 348 | int ret; |
| 349 | struct pil_device *pil; |
| 350 | struct pil_device *pil_d; |
| 351 | void *retval; |
| 352 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 353 | if (!name) |
| 354 | return NULL; |
| 355 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 356 | pil = retval = find_peripheral(name); |
| 357 | if (!pil) |
| 358 | return ERR_PTR(-ENODEV); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 359 | if (!try_module_get(pil->owner)) { |
| 360 | put_device(&pil->dev); |
| 361 | return ERR_PTR(-ENODEV); |
| 362 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 363 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 364 | pil_d = pil_get(pil->desc->depends_on); |
| 365 | if (IS_ERR(pil_d)) { |
| 366 | retval = pil_d; |
| 367 | goto err_depends; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | mutex_lock(&pil->lock); |
Stephen Boyd | e4861c0 | 2012-05-14 12:57:40 -0700 | [diff] [blame] | 371 | if (!pil->count) { |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 372 | ret = load_image(pil); |
| 373 | if (ret) { |
| 374 | retval = ERR_PTR(ret); |
| 375 | goto err_load; |
| 376 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 377 | } |
Stephen Boyd | e4861c0 | 2012-05-14 12:57:40 -0700 | [diff] [blame] | 378 | pil->count++; |
Stephen Boyd | 20ad810 | 2011-10-09 21:28:01 -0700 | [diff] [blame] | 379 | pil_set_state(pil, PIL_ONLINE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 380 | mutex_unlock(&pil->lock); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 381 | out: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 382 | return retval; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 383 | err_load: |
| 384 | mutex_unlock(&pil->lock); |
| 385 | pil_put(pil_d); |
| 386 | err_depends: |
| 387 | put_device(&pil->dev); |
| 388 | module_put(pil->owner); |
| 389 | goto out; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 390 | } |
| 391 | EXPORT_SYMBOL(pil_get); |
| 392 | |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 393 | static void pil_shutdown(struct pil_device *pil) |
| 394 | { |
| 395 | pil->desc->ops->shutdown(pil->desc); |
| 396 | flush_delayed_work(&pil->proxy); |
| 397 | pil_set_state(pil, PIL_OFFLINE); |
| 398 | } |
| 399 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 400 | /** |
| 401 | * pil_put() - Inform PIL the peripheral no longer needs to be active |
| 402 | * @peripheral_handle: pointer from a previous call to pil_get() |
| 403 | * |
| 404 | * This doesn't imply that a peripheral is shutdown or in reset since another |
| 405 | * driver could be using the peripheral. |
| 406 | */ |
| 407 | void pil_put(void *peripheral_handle) |
| 408 | { |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 409 | struct pil_device *pil_d, *pil = peripheral_handle; |
| 410 | |
| 411 | if (IS_ERR_OR_NULL(pil)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 412 | return; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 413 | |
| 414 | mutex_lock(&pil->lock); |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 415 | if (WARN(!pil->count, "%s: %s: Reference count mismatch\n", |
| 416 | pil->desc->name, __func__)) |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 417 | goto err_out; |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 418 | if (!--pil->count) |
| 419 | pil_shutdown(pil); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 420 | mutex_unlock(&pil->lock); |
| 421 | |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 422 | pil_d = find_peripheral(pil->desc->depends_on); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 423 | module_put(pil->owner); |
| 424 | if (pil_d) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 425 | pil_put(pil_d); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 426 | put_device(&pil_d->dev); |
| 427 | } |
| 428 | put_device(&pil->dev); |
| 429 | return; |
| 430 | err_out: |
| 431 | mutex_unlock(&pil->lock); |
| 432 | return; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 433 | } |
| 434 | EXPORT_SYMBOL(pil_put); |
| 435 | |
| 436 | void pil_force_shutdown(const char *name) |
| 437 | { |
| 438 | struct pil_device *pil; |
| 439 | |
| 440 | pil = find_peripheral(name); |
Stephen Boyd | 01c02c1 | 2012-03-14 10:12:26 -0700 | [diff] [blame] | 441 | if (!pil) { |
| 442 | pr_err("%s: Couldn't find %s\n", __func__, name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 443 | return; |
Stephen Boyd | 01c02c1 | 2012-03-14 10:12:26 -0700 | [diff] [blame] | 444 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 445 | |
| 446 | mutex_lock(&pil->lock); |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 447 | if (!WARN(!pil->count, "%s: %s: Reference count mismatch\n", |
| 448 | pil->desc->name, __func__)) |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 449 | pil_shutdown(pil); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 450 | mutex_unlock(&pil->lock); |
Stephen Boyd | 20ad810 | 2011-10-09 21:28:01 -0700 | [diff] [blame] | 451 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 452 | put_device(&pil->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 453 | } |
| 454 | EXPORT_SYMBOL(pil_force_shutdown); |
| 455 | |
| 456 | int pil_force_boot(const char *name) |
| 457 | { |
| 458 | int ret = -EINVAL; |
| 459 | struct pil_device *pil; |
| 460 | |
| 461 | pil = find_peripheral(name); |
Stephen Boyd | 01c02c1 | 2012-03-14 10:12:26 -0700 | [diff] [blame] | 462 | if (!pil) { |
| 463 | pr_err("%s: Couldn't find %s\n", __func__, name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 464 | return -EINVAL; |
Stephen Boyd | 01c02c1 | 2012-03-14 10:12:26 -0700 | [diff] [blame] | 465 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 466 | |
| 467 | mutex_lock(&pil->lock); |
Matt Wagantall | a4f0a06 | 2012-05-21 18:04:57 -0700 | [diff] [blame] | 468 | if (!WARN(!pil->count, "%s: %s: Reference count mismatch\n", |
| 469 | pil->desc->name, __func__)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 470 | ret = load_image(pil); |
Stephen Boyd | 20ad810 | 2011-10-09 21:28:01 -0700 | [diff] [blame] | 471 | if (!ret) |
| 472 | pil_set_state(pil, PIL_ONLINE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 473 | mutex_unlock(&pil->lock); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 474 | put_device(&pil->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 475 | |
| 476 | return ret; |
| 477 | } |
| 478 | EXPORT_SYMBOL(pil_force_boot); |
| 479 | |
| 480 | #ifdef CONFIG_DEBUG_FS |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 481 | static int msm_pil_debugfs_open(struct inode *inode, struct file *filp) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 482 | { |
| 483 | filp->private_data = inode->i_private; |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | static ssize_t msm_pil_debugfs_read(struct file *filp, char __user *ubuf, |
| 488 | size_t cnt, loff_t *ppos) |
| 489 | { |
| 490 | int r; |
| 491 | char buf[40]; |
| 492 | struct pil_device *pil = filp->private_data; |
| 493 | |
| 494 | mutex_lock(&pil->lock); |
| 495 | r = snprintf(buf, sizeof(buf), "%d\n", pil->count); |
| 496 | mutex_unlock(&pil->lock); |
| 497 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 498 | } |
| 499 | |
| 500 | static ssize_t msm_pil_debugfs_write(struct file *filp, |
| 501 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 502 | { |
| 503 | struct pil_device *pil = filp->private_data; |
| 504 | char buf[4]; |
| 505 | |
| 506 | if (cnt > sizeof(buf)) |
| 507 | return -EINVAL; |
| 508 | |
| 509 | if (copy_from_user(&buf, ubuf, cnt)) |
| 510 | return -EFAULT; |
| 511 | |
| 512 | if (!strncmp(buf, "get", 3)) { |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 513 | if (IS_ERR(pil_get(pil->desc->name))) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 514 | return -EIO; |
| 515 | } else if (!strncmp(buf, "put", 3)) |
| 516 | pil_put(pil); |
| 517 | else |
| 518 | return -EINVAL; |
| 519 | |
| 520 | return cnt; |
| 521 | } |
| 522 | |
| 523 | static const struct file_operations msm_pil_debugfs_fops = { |
| 524 | .open = msm_pil_debugfs_open, |
| 525 | .read = msm_pil_debugfs_read, |
| 526 | .write = msm_pil_debugfs_write, |
| 527 | }; |
| 528 | |
| 529 | static struct dentry *pil_base_dir; |
| 530 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 531 | static int __init msm_pil_debugfs_init(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 532 | { |
| 533 | pil_base_dir = debugfs_create_dir("pil", NULL); |
| 534 | if (!pil_base_dir) { |
| 535 | pil_base_dir = NULL; |
| 536 | return -ENOMEM; |
| 537 | } |
| 538 | |
| 539 | return 0; |
| 540 | } |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 541 | |
| 542 | static void __exit msm_pil_debugfs_exit(void) |
| 543 | { |
| 544 | debugfs_remove_recursive(pil_base_dir); |
| 545 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 546 | |
| 547 | static int msm_pil_debugfs_add(struct pil_device *pil) |
| 548 | { |
| 549 | if (!pil_base_dir) |
| 550 | return -ENOMEM; |
| 551 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 552 | pil->dentry = debugfs_create_file(pil->desc->name, S_IRUGO | S_IWUSR, |
| 553 | pil_base_dir, pil, &msm_pil_debugfs_fops); |
| 554 | return !pil->dentry ? -ENOMEM : 0; |
| 555 | } |
| 556 | |
| 557 | static void msm_pil_debugfs_remove(struct pil_device *pil) |
| 558 | { |
| 559 | debugfs_remove(pil->dentry); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 560 | } |
| 561 | #else |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 562 | static int __init msm_pil_debugfs_init(void) { return 0; }; |
| 563 | static void __exit msm_pil_debugfs_exit(void) { return 0; }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 564 | static int msm_pil_debugfs_add(struct pil_device *pil) { return 0; } |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 565 | static void msm_pil_debugfs_remove(struct pil_device *pil) { } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 566 | #endif |
| 567 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 568 | static void pil_device_release(struct device *dev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 569 | { |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 570 | struct pil_device *pil = to_pil_device(dev); |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 571 | wake_lock_destroy(&pil->wlock); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 572 | mutex_destroy(&pil->lock); |
| 573 | kfree(pil); |
| 574 | } |
| 575 | |
| 576 | struct pil_device *msm_pil_register(struct pil_desc *desc) |
| 577 | { |
| 578 | int err; |
| 579 | static atomic_t pil_count = ATOMIC_INIT(-1); |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 580 | struct pil_device *pil; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 581 | |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 582 | /* Ignore users who don't make any sense */ |
| 583 | if (WARN(desc->ops->proxy_unvote && !desc->ops->proxy_vote, |
| 584 | "invalid proxy voting. ignoring\n")) |
| 585 | ((struct pil_reset_ops *)desc->ops)->proxy_unvote = NULL; |
| 586 | |
Matt Wagantall | 2475e31 | 2012-05-25 19:56:33 -0700 | [diff] [blame] | 587 | WARN(desc->ops->proxy_unvote && !desc->proxy_timeout, |
| 588 | "A proxy timeout of 0 ms was specified for %s. Specify one in " |
| 589 | "desc->proxy_timeout.\n", desc->name); |
| 590 | |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 591 | pil = kzalloc(sizeof(*pil), GFP_KERNEL); |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 592 | if (!pil) |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 593 | return ERR_PTR(-ENOMEM); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 594 | |
| 595 | mutex_init(&pil->lock); |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 596 | pil->desc = desc; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 597 | pil->owner = desc->owner; |
| 598 | pil->dev.parent = desc->dev; |
| 599 | pil->dev.bus = &pil_bus_type; |
| 600 | pil->dev.release = pil_device_release; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 601 | |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 602 | snprintf(pil->wake_name, sizeof(pil->wake_name), "pil-%s", desc->name); |
| 603 | wake_lock_init(&pil->wlock, WAKE_LOCK_SUSPEND, pil->wake_name); |
| 604 | INIT_DELAYED_WORK(&pil->proxy, pil_proxy_work); |
| 605 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 606 | dev_set_name(&pil->dev, "pil%d", atomic_inc_return(&pil_count)); |
| 607 | err = device_register(&pil->dev); |
| 608 | if (err) { |
| 609 | put_device(&pil->dev); |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 610 | wake_lock_destroy(&pil->wlock); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 611 | mutex_destroy(&pil->lock); |
| 612 | kfree(pil); |
| 613 | return ERR_PTR(err); |
| 614 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 615 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 616 | err = msm_pil_debugfs_add(pil); |
| 617 | if (err) { |
| 618 | device_unregister(&pil->dev); |
| 619 | return ERR_PTR(err); |
| 620 | } |
| 621 | |
| 622 | return pil; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 623 | } |
Stephen Boyd | 3f4da32 | 2011-08-30 01:03:23 -0700 | [diff] [blame] | 624 | EXPORT_SYMBOL(msm_pil_register); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 625 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 626 | void msm_pil_unregister(struct pil_device *pil) |
| 627 | { |
| 628 | if (IS_ERR_OR_NULL(pil)) |
| 629 | return; |
| 630 | |
| 631 | if (get_device(&pil->dev)) { |
| 632 | mutex_lock(&pil->lock); |
| 633 | WARN_ON(pil->count); |
Stephen Boyd | 36974ec | 2012-03-22 01:30:59 -0700 | [diff] [blame] | 634 | flush_delayed_work_sync(&pil->proxy); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 635 | msm_pil_debugfs_remove(pil); |
| 636 | device_unregister(&pil->dev); |
| 637 | mutex_unlock(&pil->lock); |
| 638 | put_device(&pil->dev); |
| 639 | } |
| 640 | } |
| 641 | EXPORT_SYMBOL(msm_pil_unregister); |
| 642 | |
Stephen Boyd | 80bde03 | 2012-03-16 00:14:42 -0700 | [diff] [blame] | 643 | static int pil_pm_notify(struct notifier_block *b, unsigned long event, void *p) |
| 644 | { |
| 645 | switch (event) { |
| 646 | case PM_SUSPEND_PREPARE: |
| 647 | down_write(&pil_pm_rwsem); |
| 648 | break; |
| 649 | case PM_POST_SUSPEND: |
| 650 | up_write(&pil_pm_rwsem); |
| 651 | break; |
| 652 | } |
| 653 | return NOTIFY_DONE; |
| 654 | } |
| 655 | |
| 656 | static struct notifier_block pil_pm_notifier = { |
| 657 | .notifier_call = pil_pm_notify, |
| 658 | }; |
| 659 | |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 660 | static int __init msm_pil_init(void) |
| 661 | { |
| 662 | int ret = msm_pil_debugfs_init(); |
| 663 | if (ret) |
| 664 | return ret; |
Stephen Boyd | 80bde03 | 2012-03-16 00:14:42 -0700 | [diff] [blame] | 665 | register_pm_notifier(&pil_pm_notifier); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 666 | return bus_register(&pil_bus_type); |
| 667 | } |
| 668 | subsys_initcall(msm_pil_init); |
| 669 | |
| 670 | static void __exit msm_pil_exit(void) |
| 671 | { |
| 672 | bus_unregister(&pil_bus_type); |
Stephen Boyd | 80bde03 | 2012-03-16 00:14:42 -0700 | [diff] [blame] | 673 | unregister_pm_notifier(&pil_pm_notifier); |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 674 | msm_pil_debugfs_exit(); |
| 675 | } |
| 676 | module_exit(msm_pil_exit); |
| 677 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 678 | MODULE_LICENSE("GPL v2"); |
| 679 | MODULE_DESCRIPTION("Load peripheral images and bring peripherals out of reset"); |