spi.c (e1ea2f9856b765a2eaabb403a6751f70efc9ba4c) spi.c (67f7b2781fafcc0f52464880154b320fea1ae982)
1/*
2 * SPI init/core code
3 *
4 * Copyright (C) 2005 David Brownell
5 * Copyright (C) 2008 Secret Lab Technologies Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by

--- 31 unchanged lines hidden (view full) ---

40#include <linux/ioport.h>
41#include <linux/acpi.h>
42#include <linux/highmem.h>
43#include <linux/idr.h>
44#include <linux/platform_data/x86/apple.h>
45
46#define CREATE_TRACE_POINTS
47#include <trace/events/spi.h>
1/*
2 * SPI init/core code
3 *
4 * Copyright (C) 2005 David Brownell
5 * Copyright (C) 2008 Secret Lab Technologies Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by

--- 31 unchanged lines hidden (view full) ---

40#include <linux/ioport.h>
41#include <linux/acpi.h>
42#include <linux/highmem.h>
43#include <linux/idr.h>
44#include <linux/platform_data/x86/apple.h>
45
46#define CREATE_TRACE_POINTS
47#include <trace/events/spi.h>
48#define SPI_DYN_FIRST_BUS_NUM 0
48
49static DEFINE_IDR(spi_master_idr);
50
51static void spidev_release(struct device *dev)
52{
53 struct spi_device *spi = to_spi_device(dev);
54
55 /* spi controllers may cleanup for released devices */

--- 2024 unchanged lines hidden (view full) ---

2080 *
2081 * Return: zero on success, else a negative error code.
2082 */
2083int spi_register_controller(struct spi_controller *ctlr)
2084{
2085 struct device *dev = ctlr->dev.parent;
2086 struct boardinfo *bi;
2087 int status = -ENODEV;
49
50static DEFINE_IDR(spi_master_idr);
51
52static void spidev_release(struct device *dev)
53{
54 struct spi_device *spi = to_spi_device(dev);
55
56 /* spi controllers may cleanup for released devices */

--- 2024 unchanged lines hidden (view full) ---

2081 *
2082 * Return: zero on success, else a negative error code.
2083 */
2084int spi_register_controller(struct spi_controller *ctlr)
2085{
2086 struct device *dev = ctlr->dev.parent;
2087 struct boardinfo *bi;
2088 int status = -ENODEV;
2088 int id, first_dynamic;
2089 int id;
2089
2090 if (!dev)
2091 return -ENODEV;
2092
2093 if (!spi_controller_is_slave(ctlr)) {
2094 status = of_spi_register_master(ctlr);
2095 if (status)
2096 return status;

--- 13 unchanged lines hidden (view full) ---

2110 id = idr_alloc(&spi_master_idr, ctlr, ctlr->bus_num,
2111 ctlr->bus_num + 1, GFP_KERNEL);
2112 mutex_unlock(&board_lock);
2113 if (WARN(id < 0, "couldn't get idr"))
2114 return id == -ENOSPC ? -EBUSY : id;
2115 }
2116 }
2117 if (ctlr->bus_num < 0) {
2090
2091 if (!dev)
2092 return -ENODEV;
2093
2094 if (!spi_controller_is_slave(ctlr)) {
2095 status = of_spi_register_master(ctlr);
2096 if (status)
2097 return status;

--- 13 unchanged lines hidden (view full) ---

2111 id = idr_alloc(&spi_master_idr, ctlr, ctlr->bus_num,
2112 ctlr->bus_num + 1, GFP_KERNEL);
2113 mutex_unlock(&board_lock);
2114 if (WARN(id < 0, "couldn't get idr"))
2115 return id == -ENOSPC ? -EBUSY : id;
2116 }
2117 }
2118 if (ctlr->bus_num < 0) {
2118 first_dynamic = of_alias_get_highest_id("spi");
2119 if (first_dynamic < 0)
2120 first_dynamic = 0;
2121 else
2122 first_dynamic++;
2123
2124 mutex_lock(&board_lock);
2119 mutex_lock(&board_lock);
2125 id = idr_alloc(&spi_master_idr, ctlr, first_dynamic,
2126 0, GFP_KERNEL);
2120 id = idr_alloc(&spi_master_idr, ctlr, SPI_DYN_FIRST_BUS_NUM, 0,
2121 GFP_KERNEL);
2127 mutex_unlock(&board_lock);
2128 if (WARN(id < 0, "couldn't get idr"))
2129 return id;
2130 ctlr->bus_num = id;
2131 }
2132 INIT_LIST_HEAD(&ctlr->queue);
2133 spin_lock_init(&ctlr->queue_lock);
2134 spin_lock_init(&ctlr->bus_lock_spinlock);

--- 105 unchanged lines hidden (view full) ---

2240 * This call is used only by SPI controller drivers, which are the
2241 * only ones directly touching chip registers.
2242 *
2243 * This must be called from context that can sleep.
2244 */
2245void spi_unregister_controller(struct spi_controller *ctlr)
2246{
2247 struct spi_controller *found;
2122 mutex_unlock(&board_lock);
2123 if (WARN(id < 0, "couldn't get idr"))
2124 return id;
2125 ctlr->bus_num = id;
2126 }
2127 INIT_LIST_HEAD(&ctlr->queue);
2128 spin_lock_init(&ctlr->queue_lock);
2129 spin_lock_init(&ctlr->bus_lock_spinlock);

--- 105 unchanged lines hidden (view full) ---

2235 * This call is used only by SPI controller drivers, which are the
2236 * only ones directly touching chip registers.
2237 *
2238 * This must be called from context that can sleep.
2239 */
2240void spi_unregister_controller(struct spi_controller *ctlr)
2241{
2242 struct spi_controller *found;
2243 int id = ctlr->bus_num;
2248 int dummy;
2249
2250 /* First make sure that this controller was ever added */
2251 mutex_lock(&board_lock);
2244 int dummy;
2245
2246 /* First make sure that this controller was ever added */
2247 mutex_lock(&board_lock);
2252 found = idr_find(&spi_master_idr, ctlr->bus_num);
2248 found = idr_find(&spi_master_idr, id);
2253 mutex_unlock(&board_lock);
2254 if (found != ctlr) {
2255 dev_dbg(&ctlr->dev,
2256 "attempting to delete unregistered controller [%s]\n",
2257 dev_name(&ctlr->dev));
2258 return;
2259 }
2260 if (ctlr->queued) {
2261 if (spi_destroy_queue(ctlr))
2262 dev_err(&ctlr->dev, "queue remove failed\n");
2263 }
2264 mutex_lock(&board_lock);
2265 list_del(&ctlr->list);
2266 mutex_unlock(&board_lock);
2267
2268 dummy = device_for_each_child(&ctlr->dev, NULL, __unregister);
2269 device_unregister(&ctlr->dev);
2270 /* free bus id */
2271 mutex_lock(&board_lock);
2249 mutex_unlock(&board_lock);
2250 if (found != ctlr) {
2251 dev_dbg(&ctlr->dev,
2252 "attempting to delete unregistered controller [%s]\n",
2253 dev_name(&ctlr->dev));
2254 return;
2255 }
2256 if (ctlr->queued) {
2257 if (spi_destroy_queue(ctlr))
2258 dev_err(&ctlr->dev, "queue remove failed\n");
2259 }
2260 mutex_lock(&board_lock);
2261 list_del(&ctlr->list);
2262 mutex_unlock(&board_lock);
2263
2264 dummy = device_for_each_child(&ctlr->dev, NULL, __unregister);
2265 device_unregister(&ctlr->dev);
2266 /* free bus id */
2267 mutex_lock(&board_lock);
2272 idr_remove(&spi_master_idr, ctlr->bus_num);
2268 idr_remove(&spi_master_idr, id);
2273 mutex_unlock(&board_lock);
2274}
2275EXPORT_SYMBOL_GPL(spi_unregister_controller);
2276
2277int spi_controller_suspend(struct spi_controller *ctlr)
2278{
2279 int ret;
2280

--- 1260 unchanged lines hidden ---
2269 mutex_unlock(&board_lock);
2270}
2271EXPORT_SYMBOL_GPL(spi_unregister_controller);
2272
2273int spi_controller_suspend(struct spi_controller *ctlr)
2274{
2275 int ret;
2276

--- 1260 unchanged lines hidden ---