Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, Intel Corporation |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * * Neither the name of the Intel Corporation nor the |
| 13 | * names of its contributors may be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> |
| 29 | */ |
| 30 | |
| 31 | #include <stdint.h> |
| 32 | #include <stddef.h> |
| 33 | #include <errno.h> |
| 34 | #include <reef/reef.h> |
| 35 | #include <reef/lock.h> |
| 36 | #include <reef/list.h> |
| 37 | #include <reef/stream.h> |
| 38 | #include <reef/alloc.h> |
| 39 | #include <reef/audio/component.h> |
| 40 | #include <reef/audio/pipeline.h> |
| 41 | |
| 42 | struct comp_data { |
| 43 | struct list_item list; /* list of components */ |
| 44 | spinlock_t lock; |
| 45 | }; |
| 46 | |
| 47 | static struct comp_data *cd; |
| 48 | |
| 49 | static void comp_init(struct comp_dev *dev, struct pipeline *p, uint32_t id, |
| 50 | struct comp_driver *drv, uint32_t direction) |
| 51 | { |
| 52 | dev->id = id; |
| 53 | dev->drv = drv; |
| 54 | dev->direction = direction; |
| 55 | dev->state = COMP_STATE_INIT; |
| 56 | dev->pipeline = p; |
| 57 | spinlock_init(&dev->lock); |
| 58 | list_init(&dev->bsource_list); |
| 59 | list_init(&dev->bsink_list); |
| 60 | } |
| 61 | |
| 62 | struct comp_dev *comp_new(struct pipeline *p, uint32_t type, uint32_t index, |
| 63 | uint32_t id, uint32_t direction) |
| 64 | { |
| 65 | struct list_item *clist; |
| 66 | struct comp_driver *drv; |
| 67 | struct comp_dev *dev = NULL; |
| 68 | |
| 69 | spin_lock(&cd->lock); |
| 70 | |
| 71 | list_for_item(clist, &cd->list) { |
| 72 | |
| 73 | drv = container_of(clist, struct comp_driver, list); |
| 74 | if (drv->type == type) { |
| 75 | dev = drv->ops.new(type, index, direction); |
| 76 | if (dev != NULL) |
| 77 | comp_init(dev, p, id, drv, direction); |
| 78 | else |
| 79 | trace_comp_error("eCN"); |
| 80 | |
| 81 | goto out; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | out: |
| 86 | spin_unlock(&cd->lock); |
| 87 | return dev; |
| 88 | } |
| 89 | |
| 90 | int comp_register(struct comp_driver *drv) |
| 91 | { |
| 92 | spin_lock(&cd->lock); |
| 93 | list_item_prepend(&drv->list, &cd->list); |
| 94 | spin_unlock(&cd->lock); |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | void comp_unregister(struct comp_driver *drv) |
| 100 | { |
| 101 | spin_lock(&cd->lock); |
| 102 | list_item_del(&drv->list); |
| 103 | spin_unlock(&cd->lock); |
| 104 | } |
| 105 | |
| 106 | void sys_comp_init(void) |
| 107 | { |
| 108 | cd = rzalloc(RZONE_DEV, RMOD_SYS, sizeof(*cd)); |
| 109 | list_init(&cd->list); |
| 110 | spinlock_init(&cd->lock); |
| 111 | } |