summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>2018-10-04 09:01:07 -0400
committerBoris Brezillon <boris.brezillon@bootlin.com>2018-10-08 15:32:57 -0400
commit0304f8eaa3aebc0480787139a26c7a19ac9936bd (patch)
treee919ae3ad07db4ca64498df0d6d3462be82d6715
parent460cdeca546fc75f2450914c96e701f990396285 (diff)
mtd: maps: gpio-addr-flash: Replace array with an integer
By replacing the array with an integer we can avoid completely the bit comparison loop if the value has not changed (by far the most common case). Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
-rw-r--r--drivers/mtd/maps/gpio-addr-flash.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c
index 89cc8cce161b..47b12a6fead4 100644
--- a/drivers/mtd/maps/gpio-addr-flash.c
+++ b/drivers/mtd/maps/gpio-addr-flash.c
@@ -43,7 +43,7 @@ struct async_state {
43 struct map_info map; 43 struct map_info map;
44 size_t gpio_count; 44 size_t gpio_count;
45 unsigned *gpio_addrs; 45 unsigned *gpio_addrs;
46 int *gpio_values; 46 unsigned int gpio_values;
47 unsigned int win_order; 47 unsigned int win_order;
48}; 48};
49#define gf_map_info_to_state(mi) ((struct async_state *)(mi)->map_priv_1) 49#define gf_map_info_to_state(mi) ((struct async_state *)(mi)->map_priv_1)
@@ -55,22 +55,25 @@ struct async_state {
55 * 55 *
56 * Rather than call the GPIO framework every time, cache the last-programmed 56 * Rather than call the GPIO framework every time, cache the last-programmed
57 * value. This speeds up sequential accesses (which are by far the most common 57 * value. This speeds up sequential accesses (which are by far the most common
58 * type). We rely on the GPIO framework to treat non-zero value as high so 58 * type).
59 * that we don't have to normalize the bits.
60 */ 59 */
61static void gf_set_gpios(struct async_state *state, unsigned long ofs) 60static void gf_set_gpios(struct async_state *state, unsigned long ofs)
62{ 61{
63 size_t i = 0; 62 int i;
64 int value;
65 63
66 ofs >>= state->win_order; 64 ofs >>= state->win_order;
67 do { 65
68 value = ofs & (1 << i); 66 if (ofs == state->gpio_values)
69 if (state->gpio_values[i] != value) { 67 return;
70 gpio_set_value(state->gpio_addrs[i], value); 68
71 state->gpio_values[i] = value; 69 for (i = 0; i < state->gpio_count; i++) {
72 } 70 if ((ofs & BIT(i)) == (state->gpio_values & BIT(i)))
73 } while (++i < state->gpio_count); 71 continue;
72
73 gpio_set_value(state->gpio_addrs[i], !!(ofs & BIT(i)));
74 }
75
76 state->gpio_values = ofs;
74} 77}
75 78
76/** 79/**
@@ -202,7 +205,7 @@ static const char * const part_probe_types[] = {
202 */ 205 */
203static int gpio_flash_probe(struct platform_device *pdev) 206static int gpio_flash_probe(struct platform_device *pdev)
204{ 207{
205 size_t i, arr_size; 208 size_t i;
206 struct physmap_flash_data *pdata; 209 struct physmap_flash_data *pdata;
207 struct resource *memory; 210 struct resource *memory;
208 struct resource *gpios; 211 struct resource *gpios;
@@ -215,8 +218,7 @@ static int gpio_flash_probe(struct platform_device *pdev)
215 if (!memory || !gpios || !gpios->end) 218 if (!memory || !gpios || !gpios->end)
216 return -EINVAL; 219 return -EINVAL;
217 220
218 arr_size = sizeof(int) * gpios->end; 221 state = devm_kzalloc(&pdev->dev, sizeof(*state), GFP_KERNEL);
219 state = devm_kzalloc(&pdev->dev, sizeof(*state) + arr_size, GFP_KERNEL);
220 if (!state) 222 if (!state)
221 return -ENOMEM; 223 return -ENOMEM;
222 224
@@ -226,9 +228,7 @@ static int gpio_flash_probe(struct platform_device *pdev)
226 */ 228 */
227 state->gpio_count = gpios->end; 229 state->gpio_count = gpios->end;
228 state->gpio_addrs = (void *)(unsigned long)gpios->start; 230 state->gpio_addrs = (void *)(unsigned long)gpios->start;
229 state->gpio_values = (void *)(state + 1);
230 state->win_order = get_bitmask_order(resource_size(memory)) - 1; 231 state->win_order = get_bitmask_order(resource_size(memory)) - 1;
231 memset(state->gpio_values, 0xff, arr_size);
232 232
233 state->map.name = DRIVER_NAME; 233 state->map.name = DRIVER_NAME;
234 state->map.read = gf_read; 234 state->map.read = gf_read;