aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-10-09 08:30:10 -0400
committerMark Brown <broonie@linaro.org>2013-10-09 09:05:26 -0400
commit915f441b6f31b1a8ee01e9263a4e2d44c434d832 (patch)
treeb1e989bb442bfc62eb75766be97c87077903593c
parent0a8198094da895c8d5db95812fe9de7027d808e4 (diff)
regmap: Provide asynchronous write and update bits operations
Make it easier for drivers to include single register writes in asynchronous sequences by providing async versions of the write and update bits operations. The update bits operations are only likely to be effective when used with devices that have caches but this is common enough to be useful. Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--drivers/base/regmap/regmap.c103
-rw-r--r--include/linux/regmap.h31
2 files changed, 134 insertions, 0 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 268fb71891ee..0503d868ff8c 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1338,6 +1338,37 @@ int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
1338EXPORT_SYMBOL_GPL(regmap_write); 1338EXPORT_SYMBOL_GPL(regmap_write);
1339 1339
1340/** 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/**
1341 * regmap_raw_write(): Write raw values to one or more registers 1372 * regmap_raw_write(): Write raw values to one or more registers
1342 * 1373 *
1343 * @map: Register map to write to 1374 * @map: Register map to write to
@@ -1811,6 +1842,41 @@ int regmap_update_bits(struct regmap *map, unsigned int reg,
1811EXPORT_SYMBOL_GPL(regmap_update_bits); 1842EXPORT_SYMBOL_GPL(regmap_update_bits);
1812 1843
1813/** 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/**
1814 * 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
1815 * register map and report if updated 1881 * register map and report if updated
1816 * 1882 *
@@ -1835,6 +1901,43 @@ int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1835} 1901}
1836EXPORT_SYMBOL_GPL(regmap_update_bits_check); 1902EXPORT_SYMBOL_GPL(regmap_update_bits_check);
1837 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
1838void regmap_async_complete_cb(struct regmap_async *async, int ret) 1941void regmap_async_complete_cb(struct regmap_async *async, int ret)
1839{ 1942{
1840 struct regmap *map = async->map; 1943 struct regmap *map = async->map;
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");