| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * MEN Chameleon Bus. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de) |
|---|
| 5 | 6 | * Author: Johannes Thumshirn <johannes.thumshirn@men.de> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 8 | | - * under the terms of the GNU General Public License as published by the Free |
|---|
| 9 | | - * Software Foundation; version 2 of the License. |
|---|
| 10 | 7 | */ |
|---|
| 11 | 8 | |
|---|
| 12 | 9 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 34 | 31 | { |
|---|
| 35 | 32 | struct resource *res; |
|---|
| 36 | 33 | struct priv *priv; |
|---|
| 37 | | - int ret; |
|---|
| 34 | + int ret, table_size; |
|---|
| 38 | 35 | unsigned long flags; |
|---|
| 39 | 36 | |
|---|
| 40 | 37 | priv = devm_kzalloc(&pdev->dev, sizeof(struct priv), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 93 | 90 | if (ret < 0) |
|---|
| 94 | 91 | goto out_mcb_bus; |
|---|
| 95 | 92 | |
|---|
| 96 | | - dev_dbg(&pdev->dev, "Found %d cells\n", ret); |
|---|
| 93 | + table_size = ret; |
|---|
| 94 | + |
|---|
| 95 | + if (table_size < CHAM_HEADER_SIZE) { |
|---|
| 96 | + /* Release the previous resources */ |
|---|
| 97 | + devm_iounmap(&pdev->dev, priv->base); |
|---|
| 98 | + devm_release_mem_region(&pdev->dev, priv->mapbase, CHAM_HEADER_SIZE); |
|---|
| 99 | + |
|---|
| 100 | + /* Then, allocate it again with the actual chameleon table size */ |
|---|
| 101 | + res = devm_request_mem_region(&pdev->dev, priv->mapbase, |
|---|
| 102 | + table_size, |
|---|
| 103 | + KBUILD_MODNAME); |
|---|
| 104 | + if (!res) { |
|---|
| 105 | + dev_err(&pdev->dev, "Failed to request PCI memory\n"); |
|---|
| 106 | + ret = -EBUSY; |
|---|
| 107 | + goto out_mcb_bus; |
|---|
| 108 | + } |
|---|
| 109 | + |
|---|
| 110 | + priv->base = devm_ioremap(&pdev->dev, priv->mapbase, table_size); |
|---|
| 111 | + if (!priv->base) { |
|---|
| 112 | + dev_err(&pdev->dev, "Cannot ioremap\n"); |
|---|
| 113 | + ret = -ENOMEM; |
|---|
| 114 | + goto out_mcb_bus; |
|---|
| 115 | + } |
|---|
| 116 | + } |
|---|
| 97 | 117 | |
|---|
| 98 | 118 | mcb_bus_add_devices(priv->bus); |
|---|
| 99 | 119 | |
|---|
| .. | .. |
|---|
| 134 | 154 | MODULE_AUTHOR("Johannes Thumshirn <johannes.thumshirn@men.de>"); |
|---|
| 135 | 155 | MODULE_LICENSE("GPL"); |
|---|
| 136 | 156 | MODULE_DESCRIPTION("MCB over PCI support"); |
|---|
| 157 | +MODULE_IMPORT_NS(MCB); |
|---|