aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-10-10 07:29:32 -0400
committerMark Brown <broonie@linaro.org>2013-10-10 07:29:32 -0400
commit40aaddd0438944b41ae507a01b0842309bb9ea79 (patch)
tree8557f1cf6036d7253a04bd6c2c3ec9fff8ef7c37
parent249ce1387b7739dbea2ac1a697e4bf1e37ec06b7 (diff)
parent915f441b6f31b1a8ee01e9263a4e2d44c434d832 (diff)
Merge tag 'regmap-async-reg' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap into asoc-dapm
regmap: Provide async single register operations This helps make it easier for users to take advantage of async I/O by allowing single register writes to be inserted into sequences.
-rw-r--r--drivers/base/regmap/internal.h5
-rw-r--r--drivers/base/regmap/regcache.c3
-rw-r--r--drivers/base/regmap/regmap.c191
-rw-r--r--include/linux/regmap.h31
4 files changed, 192 insertions, 38 deletions
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 57f777835d97..6873b4ce03f9 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -44,7 +44,6 @@ struct regmap_format {
44 44
45struct regmap_async { 45struct regmap_async {
46 struct list_head list; 46 struct list_head list;
47 struct work_struct cleanup;
48 struct regmap *map; 47 struct regmap *map;
49 void *work_buf; 48 void *work_buf;
50}; 49};
@@ -64,9 +63,11 @@ struct regmap {
64 void *bus_context; 63 void *bus_context;
65 const char *name; 64 const char *name;
66 65
66 bool async;
67 spinlock_t async_lock; 67 spinlock_t async_lock;
68 wait_queue_head_t async_waitq; 68 wait_queue_head_t async_waitq;
69 struct list_head async_list; 69 struct list_head async_list;
70 struct list_head async_free;
70 int async_ret; 71 int async_ret;
71 72
72#ifdef CONFIG_DEBUG_FS 73#ifdef CONFIG_DEBUG_FS
@@ -218,7 +219,7 @@ bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
218int regcache_lookup_reg(struct regmap *map, unsigned int reg); 219int regcache_lookup_reg(struct regmap *map, unsigned int reg);
219 220
220int _regmap_raw_write(struct regmap *map, unsigned int reg, 221int _regmap_raw_write(struct regmap *map, unsigned int reg,
221 const void *val, size_t val_len, bool async); 222 const void *val, size_t val_len);
222 223
223void regmap_async_complete_cb(struct regmap_async *async, int ret); 224void regmap_async_complete_cb(struct regmap_async *async, int ret);
224 225
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index d6c2d691b6e8..a36112af494c 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -631,8 +631,7 @@ static int regcache_sync_block_raw_flush(struct regmap *map, const void **data,
631 631
632 map->cache_bypass = 1; 632 map->cache_bypass = 1;
633 633
634 ret = _regmap_raw_write(map, base, *data, count * val_bytes, 634 ret = _regmap_raw_write(map, base, *data, count * val_bytes);
635 false);
636 635
637 map->cache_bypass = 0; 636 map->cache_bypass = 0;
638 637
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 7d689a15c500..0503d868ff8c 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -42,15 +42,6 @@ static int _regmap_bus_formatted_write(void *context, unsigned int reg,
42static int _regmap_bus_raw_write(void *context, unsigned int reg, 42static int _regmap_bus_raw_write(void *context, unsigned int reg,
43 unsigned int val); 43 unsigned int val);
44 44
45static void async_cleanup(struct work_struct *work)
46{
47 struct regmap_async *async = container_of(work, struct regmap_async,
48 cleanup);
49
50 kfree(async->work_buf);
51 kfree(async);
52}
53
54bool regmap_reg_in_ranges(unsigned int reg, 45bool regmap_reg_in_ranges(unsigned int reg,
55 const struct regmap_range *ranges, 46 const struct regmap_range *ranges,
56 unsigned int nranges) 47 unsigned int nranges)
@@ -465,6 +456,7 @@ struct regmap *regmap_init(struct device *dev,
465 456
466 spin_lock_init(&map->async_lock); 457 spin_lock_init(&map->async_lock);
467 INIT_LIST_HEAD(&map->async_list); 458 INIT_LIST_HEAD(&map->async_list);
459 INIT_LIST_HEAD(&map->async_free);
468 init_waitqueue_head(&map->async_waitq); 460 init_waitqueue_head(&map->async_waitq);
469 461
470 if (config->read_flag_mask || config->write_flag_mask) { 462 if (config->read_flag_mask || config->write_flag_mask) {
@@ -942,12 +934,22 @@ EXPORT_SYMBOL_GPL(regmap_reinit_cache);
942 */ 934 */
943void regmap_exit(struct regmap *map) 935void regmap_exit(struct regmap *map)
944{ 936{
937 struct regmap_async *async;
938
945 regcache_exit(map); 939 regcache_exit(map);
946 regmap_debugfs_exit(map); 940 regmap_debugfs_exit(map);
947 regmap_range_exit(map); 941 regmap_range_exit(map);
948 if (map->bus && map->bus->free_context) 942 if (map->bus && map->bus->free_context)
949 map->bus->free_context(map->bus_context); 943 map->bus->free_context(map->bus_context);
950 kfree(map->work_buf); 944 kfree(map->work_buf);
945 while (!list_empty(&map->async_free)) {
946 async = list_first_entry_or_null(&map->async_free,
947 struct regmap_async,
948 list);
949 list_del(&async->list);
950 kfree(async->work_buf);
951 kfree(async);
952 }
951 kfree(map); 953 kfree(map);
952} 954}
953EXPORT_SYMBOL_GPL(regmap_exit); 955EXPORT_SYMBOL_GPL(regmap_exit);
@@ -1039,7 +1041,7 @@ static int _regmap_select_page(struct regmap *map, unsigned int *reg,
1039} 1041}
1040 1042
1041int _regmap_raw_write(struct regmap *map, unsigned int reg, 1043int _regmap_raw_write(struct regmap *map, unsigned int reg,
1042 const void *val, size_t val_len, bool async) 1044 const void *val, size_t val_len)
1043{ 1045{
1044 struct regmap_range_node *range; 1046 struct regmap_range_node *range;
1045 unsigned long flags; 1047 unsigned long flags;
@@ -1091,7 +1093,7 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg,
1091 dev_dbg(map->dev, "Writing window %d/%zu\n", 1093 dev_dbg(map->dev, "Writing window %d/%zu\n",
1092 win_residue, val_len / map->format.val_bytes); 1094 win_residue, val_len / map->format.val_bytes);
1093 ret = _regmap_raw_write(map, reg, val, win_residue * 1095 ret = _regmap_raw_write(map, reg, val, win_residue *
1094 map->format.val_bytes, async); 1096 map->format.val_bytes);
1095 if (ret != 0) 1097 if (ret != 0)
1096 return ret; 1098 return ret;
1097 1099
@@ -1114,21 +1116,42 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg,
1114 1116
1115 u8[0] |= map->write_flag_mask; 1117 u8[0] |= map->write_flag_mask;
1116 1118
1117 if (async && map->bus->async_write) { 1119 /*
1118 struct regmap_async *async = map->bus->async_alloc(); 1120 * Essentially all I/O mechanisms will be faster with a single
1119 if (!async) 1121 * buffer to write. Since register syncs often generate raw
1120 return -ENOMEM; 1122 * writes of single registers optimise that case.
1123 */
1124 if (val != work_val && val_len == map->format.val_bytes) {
1125 memcpy(work_val, val, map->format.val_bytes);
1126 val = work_val;
1127 }
1128
1129 if (map->async && map->bus->async_write) {
1130 struct regmap_async *async;
1121 1131
1122 trace_regmap_async_write_start(map->dev, reg, val_len); 1132 trace_regmap_async_write_start(map->dev, reg, val_len);
1123 1133
1124 async->work_buf = kzalloc(map->format.buf_size, 1134 spin_lock_irqsave(&map->async_lock, flags);
1125 GFP_KERNEL | GFP_DMA); 1135 async = list_first_entry_or_null(&map->async_free,
1126 if (!async->work_buf) { 1136 struct regmap_async,
1127 kfree(async); 1137 list);
1128 return -ENOMEM; 1138 if (async)
1139 list_del(&async->list);
1140 spin_unlock_irqrestore(&map->async_lock, flags);
1141
1142 if (!async) {
1143 async = map->bus->async_alloc();
1144 if (!async)
1145 return -ENOMEM;
1146
1147 async->work_buf = kzalloc(map->format.buf_size,
1148 GFP_KERNEL | GFP_DMA);
1149 if (!async->work_buf) {
1150 kfree(async);
1151 return -ENOMEM;
1152 }
1129 } 1153 }
1130 1154
1131 INIT_WORK(&async->cleanup, async_cleanup);
1132 async->map = map; 1155 async->map = map;
1133 1156
1134 /* If the caller supplied the value we can use it safely. */ 1157 /* If the caller supplied the value we can use it safely. */
@@ -1152,11 +1175,8 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg,
1152 ret); 1175 ret);
1153 1176
1154 spin_lock_irqsave(&map->async_lock, flags); 1177 spin_lock_irqsave(&map->async_lock, flags);
1155 list_del(&async->list); 1178 list_move(&async->list, &map->async_free);
1156 spin_unlock_irqrestore(&map->async_lock, flags); 1179 spin_unlock_irqrestore(&map->async_lock, flags);
1157
1158 kfree(async->work_buf);
1159 kfree(async);
1160 } 1180 }
1161 1181
1162 return ret; 1182 return ret;
@@ -1253,7 +1273,7 @@ static int _regmap_bus_raw_write(void *context, unsigned int reg,
1253 map->work_buf + 1273 map->work_buf +
1254 map->format.reg_bytes + 1274 map->format.reg_bytes +
1255 map->format.pad_bytes, 1275 map->format.pad_bytes,
1256 map->format.val_bytes, false); 1276 map->format.val_bytes);
1257} 1277}
1258 1278
1259static inline void *_regmap_map_get_context(struct regmap *map) 1279static inline void *_regmap_map_get_context(struct regmap *map)
@@ -1318,6 +1338,37 @@ int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
1318EXPORT_SYMBOL_GPL(regmap_write); 1338EXPORT_SYMBOL_GPL(regmap_write);
1319 1339
1320/** 1340/**
1341 * regmap_write_async(): Write a value to a single register asynchronously
1342 *
1343 * @map: Register map to write to
1344 * @reg: Register to write to
1345 * @val: Value to be written
1346 *
1347 * A value of zero will be returned on success, a negative errno will
1348 * be returned in error cases.
1349 */
1350int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val)
1351{
1352 int ret;
1353
1354 if (reg % map->reg_stride)
1355 return -EINVAL;
1356
1357 map->lock(map->lock_arg);
1358
1359 map->async = true;
1360
1361 ret = _regmap_write(map, reg, val);
1362
1363 map->async = false;
1364
1365 map->unlock(map->lock_arg);
1366
1367 return ret;
1368}
1369EXPORT_SYMBOL_GPL(regmap_write_async);
1370
1371/**
1321 * regmap_raw_write(): Write raw values to one or more registers 1372 * regmap_raw_write(): Write raw values to one or more registers
1322 * 1373 *
1323 * @map: Register map to write to 1374 * @map: Register map to write to
@@ -1345,7 +1396,7 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
1345 1396
1346 map->lock(map->lock_arg); 1397 map->lock(map->lock_arg);
1347 1398
1348 ret = _regmap_raw_write(map, reg, val, val_len, false); 1399 ret = _regmap_raw_write(map, reg, val, val_len);
1349 1400
1350 map->unlock(map->lock_arg); 1401 map->unlock(map->lock_arg);
1351 1402
@@ -1426,8 +1477,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
1426 return ret; 1477 return ret;
1427 } 1478 }
1428 } else { 1479 } else {
1429 ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count, 1480 ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count);
1430 false);
1431 } 1481 }
1432 1482
1433 if (val_bytes != 1) 1483 if (val_bytes != 1)
@@ -1473,7 +1523,11 @@ int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1473 1523
1474 map->lock(map->lock_arg); 1524 map->lock(map->lock_arg);
1475 1525
1476 ret = _regmap_raw_write(map, reg, val, val_len, true); 1526 map->async = true;
1527
1528 ret = _regmap_raw_write(map, reg, val, val_len);
1529
1530 map->async = false;
1477 1531
1478 map->unlock(map->lock_arg); 1532 map->unlock(map->lock_arg);
1479 1533
@@ -1788,6 +1842,41 @@ int regmap_update_bits(struct regmap *map, unsigned int reg,
1788EXPORT_SYMBOL_GPL(regmap_update_bits); 1842EXPORT_SYMBOL_GPL(regmap_update_bits);
1789 1843
1790/** 1844/**
1845 * regmap_update_bits_async: Perform a read/modify/write cycle on the register
1846 * map asynchronously
1847 *
1848 * @map: Register map to update
1849 * @reg: Register to update
1850 * @mask: Bitmask to change
1851 * @val: New value for bitmask
1852 *
1853 * With most buses the read must be done synchronously so this is most
1854 * useful for devices with a cache which do not need to interact with
1855 * the hardware to determine the current register value.
1856 *
1857 * Returns zero for success, a negative number on error.
1858 */
1859int regmap_update_bits_async(struct regmap *map, unsigned int reg,
1860 unsigned int mask, unsigned int val)
1861{
1862 bool change;
1863 int ret;
1864
1865 map->lock(map->lock_arg);
1866
1867 map->async = true;
1868
1869 ret = _regmap_update_bits(map, reg, mask, val, &change);
1870
1871 map->async = false;
1872
1873 map->unlock(map->lock_arg);
1874
1875 return ret;
1876}
1877EXPORT_SYMBOL_GPL(regmap_update_bits_async);
1878
1879/**
1791 * regmap_update_bits_check: Perform a read/modify/write cycle on the 1880 * regmap_update_bits_check: Perform a read/modify/write cycle on the
1792 * register map and report if updated 1881 * register map and report if updated
1793 * 1882 *
@@ -1812,6 +1901,43 @@ int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1812} 1901}
1813EXPORT_SYMBOL_GPL(regmap_update_bits_check); 1902EXPORT_SYMBOL_GPL(regmap_update_bits_check);
1814 1903
1904/**
1905 * regmap_update_bits_check_async: Perform a read/modify/write cycle on the
1906 * register map asynchronously and report if
1907 * updated
1908 *
1909 * @map: Register map to update
1910 * @reg: Register to update
1911 * @mask: Bitmask to change
1912 * @val: New value for bitmask
1913 * @change: Boolean indicating if a write was done
1914 *
1915 * With most buses the read must be done synchronously so this is most
1916 * useful for devices with a cache which do not need to interact with
1917 * the hardware to determine the current register value.
1918 *
1919 * Returns zero for success, a negative number on error.
1920 */
1921int regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
1922 unsigned int mask, unsigned int val,
1923 bool *change)
1924{
1925 int ret;
1926
1927 map->lock(map->lock_arg);
1928
1929 map->async = true;
1930
1931 ret = _regmap_update_bits(map, reg, mask, val, change);
1932
1933 map->async = false;
1934
1935 map->unlock(map->lock_arg);
1936
1937 return ret;
1938}
1939EXPORT_SYMBOL_GPL(regmap_update_bits_check_async);
1940
1815void regmap_async_complete_cb(struct regmap_async *async, int ret) 1941void regmap_async_complete_cb(struct regmap_async *async, int ret)
1816{ 1942{
1817 struct regmap *map = async->map; 1943 struct regmap *map = async->map;
@@ -1820,8 +1946,7 @@ void regmap_async_complete_cb(struct regmap_async *async, int ret)
1820 trace_regmap_async_io_complete(map->dev); 1946 trace_regmap_async_io_complete(map->dev);
1821 1947
1822 spin_lock(&map->async_lock); 1948 spin_lock(&map->async_lock);
1823 1949 list_move(&async->list, &map->async_free);
1824 list_del(&async->list);
1825 wake = list_empty(&map->async_list); 1950 wake = list_empty(&map->async_list);
1826 1951
1827 if (ret != 0) 1952 if (ret != 0)
@@ -1829,8 +1954,6 @@ void regmap_async_complete_cb(struct regmap_async *async, int ret)
1829 1954
1830 spin_unlock(&map->async_lock); 1955 spin_unlock(&map->async_lock);
1831 1956
1832 schedule_work(&async->cleanup);
1833
1834 if (wake) 1957 if (wake)
1835 wake_up(&map->async_waitq); 1958 wake_up(&map->async_waitq);
1836} 1959}
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index a10380bfbeac..114565befbd2 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -374,6 +374,7 @@ int regmap_reinit_cache(struct regmap *map,
374 const struct regmap_config *config); 374 const struct regmap_config *config);
375struct regmap *dev_get_regmap(struct device *dev, const char *name); 375struct regmap *dev_get_regmap(struct device *dev, const char *name);
376int regmap_write(struct regmap *map, unsigned int reg, unsigned int val); 376int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
377int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
377int regmap_raw_write(struct regmap *map, unsigned int reg, 378int regmap_raw_write(struct regmap *map, unsigned int reg,
378 const void *val, size_t val_len); 379 const void *val, size_t val_len);
379int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, 380int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
@@ -387,9 +388,14 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
387 size_t val_count); 388 size_t val_count);
388int regmap_update_bits(struct regmap *map, unsigned int reg, 389int regmap_update_bits(struct regmap *map, unsigned int reg,
389 unsigned int mask, unsigned int val); 390 unsigned int mask, unsigned int val);
391int regmap_update_bits_async(struct regmap *map, unsigned int reg,
392 unsigned int mask, unsigned int val);
390int regmap_update_bits_check(struct regmap *map, unsigned int reg, 393int regmap_update_bits_check(struct regmap *map, unsigned int reg,
391 unsigned int mask, unsigned int val, 394 unsigned int mask, unsigned int val,
392 bool *change); 395 bool *change);
396int regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
397 unsigned int mask, unsigned int val,
398 bool *change);
393int regmap_get_val_bytes(struct regmap *map); 399int regmap_get_val_bytes(struct regmap *map);
394int regmap_async_complete(struct regmap *map); 400int regmap_async_complete(struct regmap *map);
395bool regmap_can_raw_write(struct regmap *map); 401bool regmap_can_raw_write(struct regmap *map);
@@ -527,6 +533,13 @@ static inline int regmap_write(struct regmap *map, unsigned int reg,
527 return -EINVAL; 533 return -EINVAL;
528} 534}
529 535
536static inline int regmap_write_async(struct regmap *map, unsigned int reg,
537 unsigned int val)
538{
539 WARN_ONCE(1, "regmap API is disabled");
540 return -EINVAL;
541}
542
530static inline int regmap_raw_write(struct regmap *map, unsigned int reg, 543static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
531 const void *val, size_t val_len) 544 const void *val, size_t val_len)
532{ 545{
@@ -576,6 +589,14 @@ static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
576 return -EINVAL; 589 return -EINVAL;
577} 590}
578 591
592static inline int regmap_update_bits_async(struct regmap *map,
593 unsigned int reg,
594 unsigned int mask, unsigned int val)
595{
596 WARN_ONCE(1, "regmap API is disabled");
597 return -EINVAL;
598}
599
579static inline int regmap_update_bits_check(struct regmap *map, 600static inline int regmap_update_bits_check(struct regmap *map,
580 unsigned int reg, 601 unsigned int reg,
581 unsigned int mask, unsigned int val, 602 unsigned int mask, unsigned int val,
@@ -585,6 +606,16 @@ static inline int regmap_update_bits_check(struct regmap *map,
585 return -EINVAL; 606 return -EINVAL;
586} 607}
587 608
609static inline int regmap_update_bits_check_async(struct regmap *map,
610 unsigned int reg,
611 unsigned int mask,
612 unsigned int val,
613 bool *change)
614{
615 WARN_ONCE(1, "regmap API is disabled");
616 return -EINVAL;
617}
618
588static inline int regmap_get_val_bytes(struct regmap *map) 619static inline int regmap_get_val_bytes(struct regmap *map)
589{ 620{
590 WARN_ONCE(1, "regmap API is disabled"); 621 WARN_ONCE(1, "regmap API is disabled");