Lines Matching +full:chip +full:- +full:select
1 // SPDX-License-Identifier: GPL-2.0-only
25 * It provides control for spi chip select lines so that any chipselect
26 * (out of 4 possible chipselects in pl022) can be made low to select
31 * struct spear_spics - represents spi chip select control
36 * @cs_enable_mask: mask to select bits required to select chipselect
40 * @chip: gpio_chip abstraction
51 struct gpio_chip chip; member
55 static int spics_get_value(struct gpio_chip *chip, unsigned offset) in spics_get_value() argument
57 return -ENXIO; in spics_get_value()
60 static void spics_set_value(struct gpio_chip *chip, unsigned offset, int value) in spics_set_value() argument
62 struct spear_spics *spics = gpiochip_get_data(chip); in spics_set_value()
65 /* select chip select from register */ in spics_set_value()
66 tmp = readl_relaxed(spics->base + spics->perip_cfg); in spics_set_value()
67 if (spics->last_off != offset) { in spics_set_value()
68 spics->last_off = offset; in spics_set_value()
69 tmp &= ~(spics->cs_enable_mask << spics->cs_enable_shift); in spics_set_value()
70 tmp |= offset << spics->cs_enable_shift; in spics_set_value()
73 /* toggle chip select line */ in spics_set_value()
74 tmp &= ~(0x1 << spics->cs_value_bit); in spics_set_value()
75 tmp |= value << spics->cs_value_bit; in spics_set_value()
76 writel_relaxed(tmp, spics->base + spics->perip_cfg); in spics_set_value()
79 static int spics_direction_input(struct gpio_chip *chip, unsigned offset) in spics_direction_input() argument
81 return -ENXIO; in spics_direction_input()
84 static int spics_direction_output(struct gpio_chip *chip, unsigned offset, in spics_direction_output() argument
87 spics_set_value(chip, offset, value); in spics_direction_output()
91 static int spics_request(struct gpio_chip *chip, unsigned offset) in spics_request() argument
93 struct spear_spics *spics = gpiochip_get_data(chip); in spics_request()
96 if (!spics->use_count++) { in spics_request()
97 tmp = readl_relaxed(spics->base + spics->perip_cfg); in spics_request()
98 tmp |= 0x1 << spics->sw_enable_bit; in spics_request()
99 tmp |= 0x1 << spics->cs_value_bit; in spics_request()
100 writel_relaxed(tmp, spics->base + spics->perip_cfg); in spics_request()
106 static void spics_free(struct gpio_chip *chip, unsigned offset) in spics_free() argument
108 struct spear_spics *spics = gpiochip_get_data(chip); in spics_free()
111 if (!--spics->use_count) { in spics_free()
112 tmp = readl_relaxed(spics->base + spics->perip_cfg); in spics_free()
113 tmp &= ~(0x1 << spics->sw_enable_bit); in spics_free()
114 writel_relaxed(tmp, spics->base + spics->perip_cfg); in spics_free()
120 struct device_node *np = pdev->dev.of_node; in spics_gpio_probe()
123 spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL); in spics_gpio_probe()
125 return -ENOMEM; in spics_gpio_probe()
127 spics->base = devm_platform_ioremap_resource(pdev, 0); in spics_gpio_probe()
128 if (IS_ERR(spics->base)) in spics_gpio_probe()
129 return PTR_ERR(spics->base); in spics_gpio_probe()
131 if (of_property_read_u32(np, "st-spics,peripcfg-reg", in spics_gpio_probe()
132 &spics->perip_cfg)) in spics_gpio_probe()
134 if (of_property_read_u32(np, "st-spics,sw-enable-bit", in spics_gpio_probe()
135 &spics->sw_enable_bit)) in spics_gpio_probe()
137 if (of_property_read_u32(np, "st-spics,cs-value-bit", in spics_gpio_probe()
138 &spics->cs_value_bit)) in spics_gpio_probe()
140 if (of_property_read_u32(np, "st-spics,cs-enable-mask", in spics_gpio_probe()
141 &spics->cs_enable_mask)) in spics_gpio_probe()
143 if (of_property_read_u32(np, "st-spics,cs-enable-shift", in spics_gpio_probe()
144 &spics->cs_enable_shift)) in spics_gpio_probe()
147 spics->chip.ngpio = NUM_OF_GPIO; in spics_gpio_probe()
148 spics->chip.base = -1; in spics_gpio_probe()
149 spics->chip.request = spics_request; in spics_gpio_probe()
150 spics->chip.free = spics_free; in spics_gpio_probe()
151 spics->chip.direction_input = spics_direction_input; in spics_gpio_probe()
152 spics->chip.direction_output = spics_direction_output; in spics_gpio_probe()
153 spics->chip.get = spics_get_value; in spics_gpio_probe()
154 spics->chip.set = spics_set_value; in spics_gpio_probe()
155 spics->chip.label = dev_name(&pdev->dev); in spics_gpio_probe()
156 spics->chip.parent = &pdev->dev; in spics_gpio_probe()
157 spics->chip.owner = THIS_MODULE; in spics_gpio_probe()
158 spics->last_off = -1; in spics_gpio_probe()
160 return devm_gpiochip_add_data(&pdev->dev, &spics->chip, spics); in spics_gpio_probe()
163 dev_err(&pdev->dev, "DT probe failed\n"); in spics_gpio_probe()
164 return -EINVAL; in spics_gpio_probe()
168 { .compatible = "st,spear-spics-gpio" },
175 .name = "spear-spics-gpio",