summaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi.c
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2019-09-15 05:32:06 -0400
committerMark Brown <broonie@kernel.org>2019-09-15 05:32:06 -0400
commitb769c5ba8aedc395ed04abe6db84a556d28beec1 (patch)
treedd00c955f899f65785d60c2b4673785c28054b30 /drivers/spi/spi.c
parent262a2f33454fcecdc2032ca84d6fecdb08233468 (diff)
parentfdeae8f5a2e5eb3fcc9c295bfb28503c3abd4d6e (diff)
Merge branch 'spi-5.4' into spi-next
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r--drivers/spi/spi.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 75ac046cae52..f8b4654a57d3 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1265,8 +1265,9 @@ EXPORT_SYMBOL_GPL(spi_finalize_current_transfer);
1265 */ 1265 */
1266static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) 1266static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread)
1267{ 1267{
1268 unsigned long flags; 1268 struct spi_message *msg;
1269 bool was_busy = false; 1269 bool was_busy = false;
1270 unsigned long flags;
1270 int ret; 1271 int ret;
1271 1272
1272 /* Lock queue */ 1273 /* Lock queue */
@@ -1325,10 +1326,10 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread)
1325 } 1326 }
1326 1327
1327 /* Extract head of queue */ 1328 /* Extract head of queue */
1328 ctlr->cur_msg = 1329 msg = list_first_entry(&ctlr->queue, struct spi_message, queue);
1329 list_first_entry(&ctlr->queue, struct spi_message, queue); 1330 ctlr->cur_msg = msg;
1330 1331
1331 list_del_init(&ctlr->cur_msg->queue); 1332 list_del_init(&msg->queue);
1332 if (ctlr->busy) 1333 if (ctlr->busy)
1333 was_busy = true; 1334 was_busy = true;
1334 else 1335 else
@@ -1361,7 +1362,7 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread)
1361 if (ctlr->auto_runtime_pm) 1362 if (ctlr->auto_runtime_pm)
1362 pm_runtime_put(ctlr->dev.parent); 1363 pm_runtime_put(ctlr->dev.parent);
1363 1364
1364 ctlr->cur_msg->status = ret; 1365 msg->status = ret;
1365 spi_finalize_current_message(ctlr); 1366 spi_finalize_current_message(ctlr);
1366 1367
1367 mutex_unlock(&ctlr->io_mutex); 1368 mutex_unlock(&ctlr->io_mutex);
@@ -1369,28 +1370,28 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread)
1369 } 1370 }
1370 } 1371 }
1371 1372
1372 trace_spi_message_start(ctlr->cur_msg); 1373 trace_spi_message_start(msg);
1373 1374
1374 if (ctlr->prepare_message) { 1375 if (ctlr->prepare_message) {
1375 ret = ctlr->prepare_message(ctlr, ctlr->cur_msg); 1376 ret = ctlr->prepare_message(ctlr, msg);
1376 if (ret) { 1377 if (ret) {
1377 dev_err(&ctlr->dev, "failed to prepare message: %d\n", 1378 dev_err(&ctlr->dev, "failed to prepare message: %d\n",
1378 ret); 1379 ret);
1379 ctlr->cur_msg->status = ret; 1380 msg->status = ret;
1380 spi_finalize_current_message(ctlr); 1381 spi_finalize_current_message(ctlr);
1381 goto out; 1382 goto out;
1382 } 1383 }
1383 ctlr->cur_msg_prepared = true; 1384 ctlr->cur_msg_prepared = true;
1384 } 1385 }
1385 1386
1386 ret = spi_map_msg(ctlr, ctlr->cur_msg); 1387 ret = spi_map_msg(ctlr, msg);
1387 if (ret) { 1388 if (ret) {
1388 ctlr->cur_msg->status = ret; 1389 msg->status = ret;
1389 spi_finalize_current_message(ctlr); 1390 spi_finalize_current_message(ctlr);
1390 goto out; 1391 goto out;
1391 } 1392 }
1392 1393
1393 ret = ctlr->transfer_one_message(ctlr, ctlr->cur_msg); 1394 ret = ctlr->transfer_one_message(ctlr, msg);
1394 if (ret) { 1395 if (ret) {
1395 dev_err(&ctlr->dev, 1396 dev_err(&ctlr->dev,
1396 "failed to transfer one message from queue\n"); 1397 "failed to transfer one message from queue\n");
@@ -1434,7 +1435,7 @@ static void spi_pump_messages(struct kthread_work *work)
1434 */ 1435 */
1435static void spi_set_thread_rt(struct spi_controller *ctlr) 1436static void spi_set_thread_rt(struct spi_controller *ctlr)
1436{ 1437{
1437 struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 }; 1438 struct sched_param param = { .sched_priority = MAX_RT_PRIO / 2 };
1438 1439
1439 dev_info(&ctlr->dev, 1440 dev_info(&ctlr->dev,
1440 "will run message pump with realtime priority\n"); 1441 "will run message pump with realtime priority\n");
@@ -2105,8 +2106,8 @@ static int match_true(struct device *dev, void *data)
2105 return 1; 2106 return 1;
2106} 2107}
2107 2108
2108static ssize_t spi_slave_show(struct device *dev, 2109static ssize_t slave_show(struct device *dev, struct device_attribute *attr,
2109 struct device_attribute *attr, char *buf) 2110 char *buf)
2110{ 2111{
2111 struct spi_controller *ctlr = container_of(dev, struct spi_controller, 2112 struct spi_controller *ctlr = container_of(dev, struct spi_controller,
2112 dev); 2113 dev);
@@ -2117,9 +2118,8 @@ static ssize_t spi_slave_show(struct device *dev,
2117 child ? to_spi_device(child)->modalias : NULL); 2118 child ? to_spi_device(child)->modalias : NULL);
2118} 2119}
2119 2120
2120static ssize_t spi_slave_store(struct device *dev, 2121static ssize_t slave_store(struct device *dev, struct device_attribute *attr,
2121 struct device_attribute *attr, const char *buf, 2122 const char *buf, size_t count)
2122 size_t count)
2123{ 2123{
2124 struct spi_controller *ctlr = container_of(dev, struct spi_controller, 2124 struct spi_controller *ctlr = container_of(dev, struct spi_controller,
2125 dev); 2125 dev);
@@ -2157,7 +2157,7 @@ static ssize_t spi_slave_store(struct device *dev,
2157 return count; 2157 return count;
2158} 2158}
2159 2159
2160static DEVICE_ATTR(slave, 0644, spi_slave_show, spi_slave_store); 2160static DEVICE_ATTR_RW(slave);
2161 2161
2162static struct attribute *spi_slave_attrs[] = { 2162static struct attribute *spi_slave_attrs[] = {
2163 &dev_attr_slave.attr, 2163 &dev_attr_slave.attr,
@@ -2188,8 +2188,10 @@ extern struct class spi_slave_class; /* dummy */
2188 * __spi_alloc_controller - allocate an SPI master or slave controller 2188 * __spi_alloc_controller - allocate an SPI master or slave controller
2189 * @dev: the controller, possibly using the platform_bus 2189 * @dev: the controller, possibly using the platform_bus
2190 * @size: how much zeroed driver-private data to allocate; the pointer to this 2190 * @size: how much zeroed driver-private data to allocate; the pointer to this
2191 * memory is in the driver_data field of the returned device, 2191 * memory is in the driver_data field of the returned device, accessible
2192 * accessible with spi_controller_get_devdata(). 2192 * with spi_controller_get_devdata(); the memory is cacheline aligned;
2193 * drivers granting DMA access to portions of their private data need to
2194 * round up @size using ALIGN(size, dma_get_cache_alignment()).
2193 * @slave: flag indicating whether to allocate an SPI master (false) or SPI 2195 * @slave: flag indicating whether to allocate an SPI master (false) or SPI
2194 * slave (true) controller 2196 * slave (true) controller
2195 * Context: can sleep 2197 * Context: can sleep
@@ -2211,11 +2213,12 @@ struct spi_controller *__spi_alloc_controller(struct device *dev,
2211 unsigned int size, bool slave) 2213 unsigned int size, bool slave)
2212{ 2214{
2213 struct spi_controller *ctlr; 2215 struct spi_controller *ctlr;
2216 size_t ctlr_size = ALIGN(sizeof(*ctlr), dma_get_cache_alignment());
2214 2217
2215 if (!dev) 2218 if (!dev)
2216 return NULL; 2219 return NULL;
2217 2220
2218 ctlr = kzalloc(size + sizeof(*ctlr), GFP_KERNEL); 2221 ctlr = kzalloc(size + ctlr_size, GFP_KERNEL);
2219 if (!ctlr) 2222 if (!ctlr)
2220 return NULL; 2223 return NULL;
2221 2224
@@ -2229,14 +2232,14 @@ struct spi_controller *__spi_alloc_controller(struct device *dev,
2229 ctlr->dev.class = &spi_master_class; 2232 ctlr->dev.class = &spi_master_class;
2230 ctlr->dev.parent = dev; 2233 ctlr->dev.parent = dev;
2231 pm_suspend_ignore_children(&ctlr->dev, true); 2234 pm_suspend_ignore_children(&ctlr->dev, true);
2232 spi_controller_set_devdata(ctlr, &ctlr[1]); 2235 spi_controller_set_devdata(ctlr, (void *)ctlr + ctlr_size);
2233 2236
2234 return ctlr; 2237 return ctlr;
2235} 2238}
2236EXPORT_SYMBOL_GPL(__spi_alloc_controller); 2239EXPORT_SYMBOL_GPL(__spi_alloc_controller);
2237 2240
2238#ifdef CONFIG_OF 2241#ifdef CONFIG_OF
2239static int of_spi_register_master(struct spi_controller *ctlr) 2242static int of_spi_get_gpio_numbers(struct spi_controller *ctlr)
2240{ 2243{
2241 int nb, i, *cs; 2244 int nb, i, *cs;
2242 struct device_node *np = ctlr->dev.of_node; 2245 struct device_node *np = ctlr->dev.of_node;
@@ -2269,7 +2272,7 @@ static int of_spi_register_master(struct spi_controller *ctlr)
2269 return 0; 2272 return 0;
2270} 2273}
2271#else 2274#else
2272static int of_spi_register_master(struct spi_controller *ctlr) 2275static int of_spi_get_gpio_numbers(struct spi_controller *ctlr)
2273{ 2276{
2274 return 0; 2277 return 0;
2275} 2278}
@@ -2456,7 +2459,7 @@ int spi_register_controller(struct spi_controller *ctlr)
2456 ctlr->mode_bits |= SPI_CS_HIGH; 2459 ctlr->mode_bits |= SPI_CS_HIGH;
2457 } else { 2460 } else {
2458 /* Legacy code path for GPIOs from DT */ 2461 /* Legacy code path for GPIOs from DT */
2459 status = of_spi_register_master(ctlr); 2462 status = of_spi_get_gpio_numbers(ctlr);
2460 if (status) 2463 if (status)
2461 return status; 2464 return status;
2462 } 2465 }