···11+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)22+# Copyright 2019-2020 Artur Rojek33+%YAML 1.244+---55+$id: "http://devicetree.org/schemas/input/adc-joystick.yaml#"66+$schema: "http://devicetree.org/meta-schemas/core.yaml#"77+88+title: ADC attached joystick99+1010+maintainers:1111+ - Artur Rojek <contact@artur-rojek.eu>1212+1313+description: >1414+ Bindings for joystick devices connected to ADC controllers supporting1515+ the Industrial I/O subsystem.1616+1717+properties:1818+ compatible:1919+ const: adc-joystick2020+2121+ io-channels:2222+ minItems: 12323+ maxItems: 10242424+ description: >2525+ List of phandle and IIO specifier pairs.2626+ Each pair defines one ADC channel to which a joystick axis is connected.2727+ See Documentation/devicetree/bindings/iio/iio-bindings.txt for details.2828+2929+ '#address-cells':3030+ const: 13131+3232+ '#size-cells':3333+ const: 03434+3535+required:3636+ - compatible3737+ - io-channels3838+ - '#address-cells'3939+ - '#size-cells'4040+4141+additionalProperties: false4242+4343+patternProperties:4444+ "^axis@[0-9a-f]+$":4545+ type: object4646+ description: >4747+ Represents a joystick axis bound to the given ADC channel.4848+ For each entry in the io-channels list, one axis subnode with a matching4949+ reg property must be specified.5050+5151+ properties:5252+ reg:5353+ minimum: 05454+ maximum: 10235555+ description: Index of an io-channels list entry bound to this axis.5656+5757+ linux,code:5858+ $ref: /schemas/types.yaml#/definitions/uint325959+ description: EV_ABS specific event code generated by the axis.6060+6161+ abs-range:6262+ allOf:6363+ - $ref: /schemas/types.yaml#/definitions/uint32-array6464+ - items:6565+ - description: minimum value6666+ - description: maximum value6767+ description: >6868+ Minimum and maximum values produced by the axis.6969+ For an ABS_X axis this will be the left-most and right-most7070+ inclination of the joystick. If min > max, it is left to userspace to7171+ treat the axis as inverted.7272+ This property is interpreted as two signed 32 bit values.7373+7474+ abs-fuzz:7575+ $ref: /schemas/types.yaml#/definitions/uint327676+ description: >7777+ Amount of noise in the input value.7878+ Omitting this property indicates the axis is precise.7979+8080+ abs-flat:8181+ $ref: /schemas/types.yaml#/definitions/uint328282+ description: >8383+ Axial "deadzone", or area around the center position, where the axis8484+ is considered to be at rest.8585+ Omitting this property indicates the axis always returns to exactly8686+ the center position.8787+8888+ required:8989+ - reg9090+ - linux,code9191+ - abs-range9292+9393+ additionalProperties: false9494+9595+examples:9696+ - |9797+ #include <dt-bindings/iio/adc/ingenic,adc.h>9898+ #include <dt-bindings/input/input.h>9999+100100+ joystick: adc-joystick {101101+ compatible = "adc-joystick";102102+ io-channels = <&adc INGENIC_ADC_TOUCH_XP>,103103+ <&adc INGENIC_ADC_TOUCH_YP>;104104+ #address-cells = <1>;105105+ #size-cells = <0>;106106+107107+ axis@0 {108108+ reg = <0>;109109+ linux,code = <ABS_X>;110110+ abs-range = <3300 0>;111111+ abs-fuzz = <4>;112112+ abs-flat = <200>;113113+ };114114+ axis@1 {115115+ reg = <1>;116116+ linux,code = <ABS_Y>;117117+ abs-range = <0 3300>;118118+ abs-fuzz = <4>;119119+ abs-flat = <200>;120120+ };121121+ };
···11+Device tree bindings for Zinitx BT541 touchscreen controller22+33+Required properties:44+55+ - compatible : Should be "zinitix,bt541"66+ - reg : I2C address of the chip. Should be 0x2077+ - interrupts : Interrupt to which the chip is connected88+99+Optional properties:1010+1111+ - vdd-supply : Analog power supply regulator on VCCA pin1212+ - vddo-supply : Digital power supply regulator on VDD pin1313+ - zinitix,mode : Mode of reporting touch points. Some modes may not work1414+ with a particular ts firmware for unknown reasons. Available1515+ modes are 1 and 2. Mode 2 is the default and preferred.1616+1717+The touchscreen-* properties are documented in touchscreen.txt in this1818+directory.1919+2020+Example:2121+2222+ i2c@00000000 {2323+ /* ... */2424+2525+ bt541@20 {2626+ compatible = "zinitix,bt541";2727+ reg = <0x20>;2828+ interrupt-parent = <&msmgpio>;2929+ interrupts = <13 IRQ_TYPE_EDGE_FALLING>;3030+ pinctrl-names = "default";3131+ pinctrl-0 = <&tsp_default>;3232+ vdd-supply = <®_vdd_tsp>;3333+ vddo-supply = <&pm8916_l6>;3434+ touchscreen-size-x = <540>;3535+ touchscreen-size-y = <960>;3636+ zinitix,mode = <2>;3737+ };3838+3939+ /* ... */4040+ };
···323323 p = begin + step;324324 s = p == end ? f + 1 : *p;325325326326- for (; p != end; p += step)327327- if (*p < f)328328- s = f, f = *p;329329- else if (*p < s)326326+ for (; p != end; p += step) {327327+ if (*p < f) {328328+ s = f;329329+ f = *p;330330+ } else if (*p < s) {330331 s = *p;332332+ }333333+ }331334332335 c = (f + s + 1) / 2;333336 if (c == 0 || (c > mu && (!eq || mu > 0)))
+10
drivers/input/joystick/Kconfig
···4242 To compile this driver as a module, choose M here: the4343 module will be called a3d.44444545+config JOYSTICK_ADC4646+ tristate "Simple joystick connected over ADC"4747+ depends on IIO4848+ select IIO_BUFFER_CB4949+ help5050+ Say Y here if you have a simple joystick connected over ADC.5151+5252+ To compile this driver as a module, choose M here: the5353+ module will be called adc-joystick.5454+4555config JOYSTICK_ADI4656 tristate "Logitech ADI digital joysticks and gamepads"4757 select GAMEPORT
+1
drivers/input/joystick/Makefile
···66# Each configuration option enables a list of files.7788obj-$(CONFIG_JOYSTICK_A3D) += a3d.o99+obj-$(CONFIG_JOYSTICK_ADC) += adc-joystick.o910obj-$(CONFIG_JOYSTICK_ADI) += adi.o1011obj-$(CONFIG_JOYSTICK_AMIGA) += amijoy.o1112obj-$(CONFIG_JOYSTICK_AS5011) += as5011.o
+264
drivers/input/joystick/adc-joystick.c
···11+// SPDX-License-Identifier: GPL-2.022+/*33+ * Input driver for joysticks connected over ADC.44+ * Copyright (c) 2019-2020 Artur Rojek <contact@artur-rojek.eu>55+ */66+#include <linux/ctype.h>77+#include <linux/input.h>88+#include <linux/iio/iio.h>99+#include <linux/iio/consumer.h>1010+#include <linux/module.h>1111+#include <linux/platform_device.h>1212+#include <linux/property.h>1313+1414+#include <asm/unaligned.h>1515+1616+struct adc_joystick_axis {1717+ u32 code;1818+ s32 range[2];1919+ s32 fuzz;2020+ s32 flat;2121+};2222+2323+struct adc_joystick {2424+ struct input_dev *input;2525+ struct iio_cb_buffer *buffer;2626+ struct adc_joystick_axis *axes;2727+ struct iio_channel *chans;2828+ int num_chans;2929+};3030+3131+static int adc_joystick_handle(const void *data, void *private)3232+{3333+ struct adc_joystick *joy = private;3434+ enum iio_endian endianness;3535+ int bytes, msb, val, idx, i;3636+ const u16 *data_u16;3737+ bool sign;3838+3939+ bytes = joy->chans[0].channel->scan_type.storagebits >> 3;4040+4141+ for (i = 0; i < joy->num_chans; ++i) {4242+ idx = joy->chans[i].channel->scan_index;4343+ endianness = joy->chans[i].channel->scan_type.endianness;4444+ msb = joy->chans[i].channel->scan_type.realbits - 1;4545+ sign = tolower(joy->chans[i].channel->scan_type.sign) == 's';4646+4747+ switch (bytes) {4848+ case 1:4949+ val = ((const u8 *)data)[idx];5050+ break;5151+ case 2:5252+ data_u16 = (const u16 *)data + idx;5353+5454+ /*5555+ * Data is aligned to the sample size by IIO core.5656+ * Call `get_unaligned_xe16` to hide type casting.5757+ */5858+ if (endianness == IIO_BE)5959+ val = get_unaligned_be16(data_u16);6060+ else if (endianness == IIO_LE)6161+ val = get_unaligned_le16(data_u16);6262+ else /* IIO_CPU */6363+ val = *data_u16;6464+ break;6565+ default:6666+ return -EINVAL;6767+ }6868+6969+ val >>= joy->chans[i].channel->scan_type.shift;7070+ if (sign)7171+ val = sign_extend32(val, msb);7272+ else7373+ val &= GENMASK(msb, 0);7474+ input_report_abs(joy->input, joy->axes[i].code, val);7575+ }7676+7777+ input_sync(joy->input);7878+7979+ return 0;8080+}8181+8282+static int adc_joystick_open(struct input_dev *dev)8383+{8484+ struct adc_joystick *joy = input_get_drvdata(dev);8585+ struct device *devp = &dev->dev;8686+ int ret;8787+8888+ ret = iio_channel_start_all_cb(joy->buffer);8989+ if (ret)9090+ dev_err(devp, "Unable to start callback buffer: %d\n", ret);9191+9292+ return ret;9393+}9494+9595+static void adc_joystick_close(struct input_dev *dev)9696+{9797+ struct adc_joystick *joy = input_get_drvdata(dev);9898+9999+ iio_channel_stop_all_cb(joy->buffer);100100+}101101+102102+static void adc_joystick_cleanup(void *data)103103+{104104+ iio_channel_release_all_cb(data);105105+}106106+107107+static int adc_joystick_set_axes(struct device *dev, struct adc_joystick *joy)108108+{109109+ struct adc_joystick_axis *axes;110110+ struct fwnode_handle *child;111111+ int num_axes, error, i;112112+113113+ num_axes = device_get_child_node_count(dev);114114+ if (!num_axes) {115115+ dev_err(dev, "Unable to find child nodes\n");116116+ return -EINVAL;117117+ }118118+119119+ if (num_axes != joy->num_chans) {120120+ dev_err(dev, "Got %d child nodes for %d channels\n",121121+ num_axes, joy->num_chans);122122+ return -EINVAL;123123+ }124124+125125+ axes = devm_kmalloc_array(dev, num_axes, sizeof(*axes), GFP_KERNEL);126126+ if (!axes)127127+ return -ENOMEM;128128+129129+ device_for_each_child_node(dev, child) {130130+ error = fwnode_property_read_u32(child, "reg", &i);131131+ if (error) {132132+ dev_err(dev, "reg invalid or missing\n");133133+ goto err_fwnode_put;134134+ }135135+136136+ if (i >= num_axes) {137137+ error = -EINVAL;138138+ dev_err(dev, "No matching axis for reg %d\n", i);139139+ goto err_fwnode_put;140140+ }141141+142142+ error = fwnode_property_read_u32(child, "linux,code",143143+ &axes[i].code);144144+ if (error) {145145+ dev_err(dev, "linux,code invalid or missing\n");146146+ goto err_fwnode_put;147147+ }148148+149149+ error = fwnode_property_read_u32_array(child, "abs-range",150150+ axes[i].range, 2);151151+ if (error) {152152+ dev_err(dev, "abs-range invalid or missing\n");153153+ goto err_fwnode_put;154154+ }155155+156156+ fwnode_property_read_u32(child, "abs-fuzz", &axes[i].fuzz);157157+ fwnode_property_read_u32(child, "abs-flat", &axes[i].flat);158158+159159+ input_set_abs_params(joy->input, axes[i].code,160160+ axes[i].range[0], axes[i].range[1],161161+ axes[i].fuzz, axes[i].flat);162162+ input_set_capability(joy->input, EV_ABS, axes[i].code);163163+ }164164+165165+ joy->axes = axes;166166+167167+ return 0;168168+169169+err_fwnode_put:170170+ fwnode_handle_put(child);171171+ return error;172172+}173173+174174+static int adc_joystick_probe(struct platform_device *pdev)175175+{176176+ struct device *dev = &pdev->dev;177177+ struct adc_joystick *joy;178178+ struct input_dev *input;179179+ int error;180180+ int bits;181181+ int i;182182+183183+ joy = devm_kzalloc(dev, sizeof(*joy), GFP_KERNEL);184184+ if (!joy)185185+ return -ENOMEM;186186+187187+ joy->chans = devm_iio_channel_get_all(dev);188188+ if (IS_ERR(joy->chans)) {189189+ error = PTR_ERR(joy->chans);190190+ if (error != -EPROBE_DEFER)191191+ dev_err(dev, "Unable to get IIO channels");192192+ return error;193193+ }194194+195195+ /* Count how many channels we got. NULL terminated. */196196+ for (i = 0; joy->chans[i].indio_dev; i++) {197197+ bits = joy->chans[i].channel->scan_type.storagebits;198198+ if (!bits || bits > 16) {199199+ dev_err(dev, "Unsupported channel storage size\n");200200+ return -EINVAL;201201+ }202202+ if (bits != joy->chans[0].channel->scan_type.storagebits) {203203+ dev_err(dev, "Channels must have equal storage size\n");204204+ return -EINVAL;205205+ }206206+ }207207+ joy->num_chans = i;208208+209209+ input = devm_input_allocate_device(dev);210210+ if (!input) {211211+ dev_err(dev, "Unable to allocate input device\n");212212+ return -ENOMEM;213213+ }214214+215215+ joy->input = input;216216+ input->name = pdev->name;217217+ input->id.bustype = BUS_HOST;218218+ input->open = adc_joystick_open;219219+ input->close = adc_joystick_close;220220+221221+ error = adc_joystick_set_axes(dev, joy);222222+ if (error)223223+ return error;224224+225225+ input_set_drvdata(input, joy);226226+ error = input_register_device(input);227227+ if (error) {228228+ dev_err(dev, "Unable to register input device\n");229229+ return error;230230+ }231231+232232+ joy->buffer = iio_channel_get_all_cb(dev, adc_joystick_handle, joy);233233+ if (IS_ERR(joy->buffer)) {234234+ dev_err(dev, "Unable to allocate callback buffer\n");235235+ return PTR_ERR(joy->buffer);236236+ }237237+238238+ error = devm_add_action_or_reset(dev, adc_joystick_cleanup, joy->buffer);239239+ if (error) {240240+ dev_err(dev, "Unable to add action\n");241241+ return error;242242+ }243243+244244+ return 0;245245+}246246+247247+static const struct of_device_id adc_joystick_of_match[] = {248248+ { .compatible = "adc-joystick", },249249+ { }250250+};251251+MODULE_DEVICE_TABLE(of, adc_joystick_of_match);252252+253253+static struct platform_driver adc_joystick_driver = {254254+ .driver = {255255+ .name = "adc-joystick",256256+ .of_match_table = adc_joystick_of_match,257257+ },258258+ .probe = adc_joystick_probe,259259+};260260+module_platform_driver(adc_joystick_driver);261261+262262+MODULE_DESCRIPTION("Input driver for joysticks connected over ADC");263263+MODULE_AUTHOR("Artur Rojek <contact@artur-rojek.eu>");264264+MODULE_LICENSE("GPL");
···100100 device via the firmware loader interface. This is triggered using a101101 sysfs attribute.102102103103+config RMI4_F3A104104+ bool "RMI4 Function 3A (GPIO)"105105+ help106106+ Say Y here if you want to add support for RMI4 function 3A.107107+108108+ Function 3A provides GPIO support for RMI4 devices. This includes109109+ support for buttons on TouchPads and ClickPads.110110+103111config RMI4_F54104112 bool "RMI4 Function 54 (Analog diagnostics)"105113 depends on VIDEO_V4L2=y || (RMI4_CORE=m && VIDEO_V4L2=m)
···168168 rmi_get_platform_data(fn->rmi_dev);169169 int error;170170171171- /* can happen if f30_data.disable is set */171171+ /* can happen if gpio_data.disable is set */172172 if (!f30)173173 return 0;174174175175- if (pdata->f30_data.trackstick_buttons) {175175+ if (pdata->gpio_data.trackstick_buttons) {176176 /* Try [re-]establish link to F03. */177177 f30->f03 = rmi_find_function(fn->rmi_dev, 0x03);178178 f30->trackstick_buttons = f30->f03 != NULL;179179 }180180181181- if (pdata->f30_data.disable) {181181+ if (pdata->gpio_data.disable) {182182 drv->clear_irq_bits(fn->rmi_dev, fn->irq_mask);183183 } else {184184 /* Write Control Register values back to device */···245245 if (!rmi_f30_is_valid_button(i, f30->ctrl))246246 continue;247247248248- if (pdata->f30_data.trackstick_buttons &&248248+ if (pdata->gpio_data.trackstick_buttons &&249249 i >= TRACKSTICK_RANGE_START && i < TRACKSTICK_RANGE_END) {250250 f30->gpioled_key_map[i] = trackstick_button++;251251- } else if (!pdata->f30_data.buttonpad || !button_mapped) {251251+ } else if (!pdata->gpio_data.buttonpad || !button_mapped) {252252 f30->gpioled_key_map[i] = button;253253 input_set_capability(input, EV_KEY, button++);254254 button_mapped = true;···264264 * but I am not sure, so use only the pdata info and the number of265265 * mapped buttons.266266 */267267- if (pdata->f30_data.buttonpad || (button - BTN_LEFT == 1))267267+ if (pdata->gpio_data.buttonpad || (button - BTN_LEFT == 1))268268 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);269269270270 return 0;···372372 struct f30_data *f30;373373 int error;374374375375- if (pdata->f30_data.disable)375375+ if (pdata->gpio_data.disable)376376 return 0;377377378378 if (!drv_data->input) {
···11+// SPDX-License-Identifier: GPL-2.0-only22+/*33+ * Copyright (c) 2012-2020 Synaptics Incorporated44+ */55+66+#include <linux/kernel.h>77+#include <linux/rmi.h>88+#include <linux/input.h>99+#include <linux/slab.h>1010+#include "rmi_driver.h"1111+1212+#define RMI_F3A_MAX_GPIO_COUNT 1281313+#define RMI_F3A_MAX_REG_SIZE DIV_ROUND_UP(RMI_F3A_MAX_GPIO_COUNT, 8)1414+1515+/* Defs for Query 0 */1616+#define RMI_F3A_GPIO_COUNT 0x7F1717+1818+#define RMI_F3A_DATA_REGS_MAX_SIZE RMI_F3A_MAX_REG_SIZE1919+2020+#define TRACKSTICK_RANGE_START 32121+#define TRACKSTICK_RANGE_END 62222+2323+struct f3a_data {2424+ /* Query Data */2525+ u8 gpio_count;2626+2727+ u8 register_count;2828+2929+ u8 data_regs[RMI_F3A_DATA_REGS_MAX_SIZE];3030+ u16 *gpio_key_map;3131+3232+ struct input_dev *input;3333+3434+ struct rmi_function *f03;3535+ bool trackstick_buttons;3636+};3737+3838+static void rmi_f3a_report_button(struct rmi_function *fn,3939+ struct f3a_data *f3a, unsigned int button)4040+{4141+ u16 key_code = f3a->gpio_key_map[button];4242+ bool key_down = !(f3a->data_regs[0] & BIT(button));4343+4444+ if (f3a->trackstick_buttons &&4545+ button >= TRACKSTICK_RANGE_START &&4646+ button <= TRACKSTICK_RANGE_END) {4747+ rmi_f03_overwrite_button(f3a->f03, key_code, key_down);4848+ } else {4949+ rmi_dbg(RMI_DEBUG_FN, &fn->dev,5050+ "%s: call input report key (0x%04x) value (0x%02x)",5151+ __func__, key_code, key_down);5252+ input_report_key(f3a->input, key_code, key_down);5353+ }5454+}5555+5656+static irqreturn_t rmi_f3a_attention(int irq, void *ctx)5757+{5858+ struct rmi_function *fn = ctx;5959+ struct f3a_data *f3a = dev_get_drvdata(&fn->dev);6060+ struct rmi_driver_data *drvdata = dev_get_drvdata(&fn->rmi_dev->dev);6161+ int error;6262+ int i;6363+6464+ if (drvdata->attn_data.data) {6565+ if (drvdata->attn_data.size < f3a->register_count) {6666+ dev_warn(&fn->dev,6767+ "F3A interrupted, but data is missing\n");6868+ return IRQ_HANDLED;6969+ }7070+ memcpy(f3a->data_regs, drvdata->attn_data.data,7171+ f3a->register_count);7272+ drvdata->attn_data.data += f3a->register_count;7373+ drvdata->attn_data.size -= f3a->register_count;7474+ } else {7575+ error = rmi_read_block(fn->rmi_dev, fn->fd.data_base_addr,7676+ f3a->data_regs, f3a->register_count);7777+ if (error) {7878+ dev_err(&fn->dev,7979+ "%s: Failed to read F3a data registers: %d\n",8080+ __func__, error);8181+ return IRQ_RETVAL(error);8282+ }8383+ }8484+8585+ for (i = 0; i < f3a->gpio_count; i++)8686+ if (f3a->gpio_key_map[i] != KEY_RESERVED)8787+ rmi_f3a_report_button(fn, f3a, i);8888+ if (f3a->trackstick_buttons)8989+ rmi_f03_commit_buttons(f3a->f03);9090+9191+ return IRQ_HANDLED;9292+}9393+9494+static int rmi_f3a_config(struct rmi_function *fn)9595+{9696+ struct f3a_data *f3a = dev_get_drvdata(&fn->dev);9797+ struct rmi_driver *drv = fn->rmi_dev->driver;9898+ const struct rmi_device_platform_data *pdata =9999+ rmi_get_platform_data(fn->rmi_dev);100100+101101+ if (!f3a)102102+ return 0;103103+104104+ if (pdata->gpio_data.trackstick_buttons) {105105+ /* Try [re-]establish link to F03. */106106+ f3a->f03 = rmi_find_function(fn->rmi_dev, 0x03);107107+ f3a->trackstick_buttons = f3a->f03 != NULL;108108+ }109109+110110+ drv->set_irq_bits(fn->rmi_dev, fn->irq_mask);111111+112112+ return 0;113113+}114114+115115+static bool rmi_f3a_is_valid_button(int button, struct f3a_data *f3a,116116+ u8 *query1_regs, u8 *ctrl1_regs)117117+{118118+ /* gpio exist && direction input */119119+ return (query1_regs[0] & BIT(button)) && !(ctrl1_regs[0] & BIT(button));120120+}121121+122122+static int rmi_f3a_map_gpios(struct rmi_function *fn, struct f3a_data *f3a,123123+ u8 *query1_regs, u8 *ctrl1_regs)124124+{125125+ const struct rmi_device_platform_data *pdata =126126+ rmi_get_platform_data(fn->rmi_dev);127127+ struct input_dev *input = f3a->input;128128+ unsigned int button = BTN_LEFT;129129+ unsigned int trackstick_button = BTN_LEFT;130130+ bool button_mapped = false;131131+ int i;132132+ int button_count = min_t(u8, f3a->gpio_count, TRACKSTICK_RANGE_END);133133+134134+ f3a->gpio_key_map = devm_kcalloc(&fn->dev,135135+ button_count,136136+ sizeof(f3a->gpio_key_map[0]),137137+ GFP_KERNEL);138138+ if (!f3a->gpio_key_map) {139139+ dev_err(&fn->dev, "Failed to allocate gpio map memory.\n");140140+ return -ENOMEM;141141+ }142142+143143+ for (i = 0; i < button_count; i++) {144144+ if (!rmi_f3a_is_valid_button(i, f3a, query1_regs, ctrl1_regs))145145+ continue;146146+147147+ if (pdata->gpio_data.trackstick_buttons &&148148+ i >= TRACKSTICK_RANGE_START &&149149+ i < TRACKSTICK_RANGE_END) {150150+ f3a->gpio_key_map[i] = trackstick_button++;151151+ } else if (!pdata->gpio_data.buttonpad || !button_mapped) {152152+ f3a->gpio_key_map[i] = button;153153+ input_set_capability(input, EV_KEY, button++);154154+ button_mapped = true;155155+ }156156+ }157157+ input->keycode = f3a->gpio_key_map;158158+ input->keycodesize = sizeof(f3a->gpio_key_map[0]);159159+ input->keycodemax = f3a->gpio_count;160160+161161+ if (pdata->gpio_data.buttonpad || (button - BTN_LEFT == 1))162162+ __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);163163+164164+ return 0;165165+}166166+167167+static int rmi_f3a_initialize(struct rmi_function *fn, struct f3a_data *f3a)168168+{169169+ u8 query1[RMI_F3A_MAX_REG_SIZE];170170+ u8 ctrl1[RMI_F3A_MAX_REG_SIZE];171171+ u8 buf;172172+ int error;173173+174174+ error = rmi_read(fn->rmi_dev, fn->fd.query_base_addr, &buf);175175+ if (error < 0) {176176+ dev_err(&fn->dev, "Failed to read general info register: %d\n",177177+ error);178178+ return -ENODEV;179179+ }180180+181181+ f3a->gpio_count = buf & RMI_F3A_GPIO_COUNT;182182+ f3a->register_count = DIV_ROUND_UP(f3a->gpio_count, 8);183183+184184+ /* Query1 -> gpio exist */185185+ error = rmi_read_block(fn->rmi_dev, fn->fd.query_base_addr + 1,186186+ query1, f3a->register_count);187187+ if (error) {188188+ dev_err(&fn->dev, "Failed to read query1 register\n");189189+ return error;190190+ }191191+192192+ /* Ctrl1 -> gpio direction */193193+ error = rmi_read_block(fn->rmi_dev, fn->fd.control_base_addr + 1,194194+ ctrl1, f3a->register_count);195195+ if (error) {196196+ dev_err(&fn->dev, "Failed to read control1 register\n");197197+ return error;198198+ }199199+200200+ error = rmi_f3a_map_gpios(fn, f3a, query1, ctrl1);201201+ if (error)202202+ return error;203203+204204+ return 0;205205+}206206+207207+static int rmi_f3a_probe(struct rmi_function *fn)208208+{209209+ struct rmi_device *rmi_dev = fn->rmi_dev;210210+ struct rmi_driver_data *drv_data = dev_get_drvdata(&rmi_dev->dev);211211+ struct f3a_data *f3a;212212+ int error;213213+214214+ if (!drv_data->input) {215215+ dev_info(&fn->dev, "F3A: no input device found, ignoring\n");216216+ return -ENXIO;217217+ }218218+219219+ f3a = devm_kzalloc(&fn->dev, sizeof(*f3a), GFP_KERNEL);220220+ if (!f3a)221221+ return -ENOMEM;222222+223223+ f3a->input = drv_data->input;224224+225225+ error = rmi_f3a_initialize(fn, f3a);226226+ if (error)227227+ return error;228228+229229+ dev_set_drvdata(&fn->dev, f3a);230230+ return 0;231231+}232232+233233+struct rmi_function_handler rmi_f3a_handler = {234234+ .driver = {235235+ .name = "rmi4_f3a",236236+ },237237+ .func = 0x3a,238238+ .probe = rmi_f3a_probe,239239+ .config = rmi_f3a_config,240240+ .attention = rmi_f3a_attention,241241+};
+3-6
drivers/input/serio/sun4i-ps2.c
···211211 struct sun4i_ps2data *drvdata;212212 struct serio *serio;213213 struct device *dev = &pdev->dev;214214- unsigned int irq;215214 int error;216215217216 drvdata = kzalloc(sizeof(struct sun4i_ps2data), GFP_KERNEL);···263264 writel(0, drvdata->reg_base + PS2_REG_GCTL);264265265266 /* Get IRQ for the device */266266- irq = platform_get_irq(pdev, 0);267267- if (!irq) {268268- dev_err(dev, "no IRQ found\n");269269- error = -ENXIO;267267+ drvdata->irq = platform_get_irq(pdev, 0);268268+ if (drvdata->irq < 0) {269269+ error = drvdata->irq;270270 goto err_disable_clk;271271 }272272273273- drvdata->irq = irq;274273 drvdata->serio = serio;275274 drvdata->dev = dev;276275
+12
drivers/input/touchscreen/Kconfig
···13221322 To compile this driver as a module, choose M here: the13231323 module will be called iqs5xx.1324132413251325+config TOUCHSCREEN_ZINITIX13261326+ tristate "Zinitix touchscreen support"13271327+ depends on I2C13281328+ help13291329+ Say Y here if you have a touchscreen using Zinitix bt541,13301330+ or something similar enough.13311331+13321332+ If unsure, say N.13331333+13341334+ To compile this driver as a module, choose M here: the13351335+ module will be called zinitix.13361336+13251337endif
···9090/* FW read command, 0x53 0x?? 0x0, 0x01 */9191#define E_ELAN_INFO_FW_VER 0x009292#define E_ELAN_INFO_BC_VER 0x109393-#define E_ELAN_INFO_REK 0xE09393+#define E_ELAN_INFO_REK 0xD09494#define E_ELAN_INFO_TEST_VER 0xE09595#define E_ELAN_INFO_FW_ID 0xF09696#define E_INFO_OSR 0xD6···134134 u8 bc_version;135135 u8 iap_version;136136 u16 hw_version;137137+ u8 major_res;137138 unsigned int x_res; /* resolution in units/mm */138139 unsigned int y_res;139140 unsigned int x_max;···459458460459 rows = resp[2] + resp[6] + resp[10];461460 cols = resp[3] + resp[7] + resp[11];461461+462462+ /* Get report resolution value of ABS_MT_TOUCH_MAJOR */463463+ ts->major_res = resp[16];462464463465 /* Process mm_to_pixel information */464466 error = elants_i2c_execute_command(client,···13291325 0, MT_TOOL_PALM, 0, 0);13301326 input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->x_res);13311327 input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->y_res);13281328+ if (ts->major_res > 0)13291329+ input_abs_set_res(ts->input, ABS_MT_TOUCH_MAJOR, ts->major_res);1332133013331331 touchscreen_parse_properties(ts->input, true, &ts->prop);13341332
+22-25
drivers/input/touchscreen/imx6ul_tsc.c
···315315 return IRQ_HANDLED;316316}317317318318-static int imx6ul_tsc_open(struct input_dev *input_dev)318318+static int imx6ul_tsc_start(struct imx6ul_tsc *tsc)319319{320320- struct imx6ul_tsc *tsc = input_get_drvdata(input_dev);321320 int err;322321323322 err = clk_prepare_enable(tsc->adc_clk);···348349 return err;349350}350351351351-static void imx6ul_tsc_close(struct input_dev *input_dev)352352+static void imx6ul_tsc_stop(struct imx6ul_tsc *tsc)352353{353353- struct imx6ul_tsc *tsc = input_get_drvdata(input_dev);354354-355354 imx6ul_tsc_disable(tsc);356355357356 clk_disable_unprepare(tsc->tsc_clk);358357 clk_disable_unprepare(tsc->adc_clk);358358+}359359+360360+361361+static int imx6ul_tsc_open(struct input_dev *input_dev)362362+{363363+ struct imx6ul_tsc *tsc = input_get_drvdata(input_dev);364364+365365+ return imx6ul_tsc_start(tsc);366366+}367367+368368+static void imx6ul_tsc_close(struct input_dev *input_dev)369369+{370370+ struct imx6ul_tsc *tsc = input_get_drvdata(input_dev);371371+372372+ imx6ul_tsc_stop(tsc);359373}360374361375static int imx6ul_tsc_probe(struct platform_device *pdev)···521509522510 mutex_lock(&input_dev->mutex);523511524524- if (input_dev->users) {525525- imx6ul_tsc_disable(tsc);526526-527527- clk_disable_unprepare(tsc->tsc_clk);528528- clk_disable_unprepare(tsc->adc_clk);529529- }512512+ if (input_dev->users)513513+ imx6ul_tsc_stop(tsc);530514531515 mutex_unlock(&input_dev->mutex);532516···538530539531 mutex_lock(&input_dev->mutex);540532541541- if (input_dev->users) {542542- retval = clk_prepare_enable(tsc->adc_clk);543543- if (retval)544544- goto out;533533+ if (input_dev->users)534534+ retval = imx6ul_tsc_start(tsc);545535546546- retval = clk_prepare_enable(tsc->tsc_clk);547547- if (retval) {548548- clk_disable_unprepare(tsc->adc_clk);549549- goto out;550550- }551551-552552- retval = imx6ul_tsc_init(tsc);553553- }554554-555555-out:556536 mutex_unlock(&input_dev->mutex);537537+557538 return retval;558539}559540
+59-74
drivers/input/touchscreen/raydium_i2c_ts.c
···51515252/* Touch relative info */5353#define RM_MAX_RETRIES 35454+#define RM_RETRY_DELAY_MS 205455#define RM_MAX_TOUCH_NUM 105556#define RM_BOOT_DELAY_MS 1005657···137136 bool wake_irq_enabled;138137};139138140140-static int raydium_i2c_send(struct i2c_client *client,141141- u8 addr, const void *data, size_t len)139139+static int raydium_i2c_xfer(struct i2c_client *client,140140+ u32 addr, void *data, size_t len, bool is_read)142141{143143- u8 *buf;144144- int tries = 0;145145- int ret;142142+ struct raydium_bank_switch_header {143143+ u8 cmd;144144+ __be32 be_addr;145145+ } __packed header = {146146+ .cmd = RM_CMD_BANK_SWITCH,147147+ .be_addr = cpu_to_be32(addr),148148+ };146149147147- buf = kmalloc(len + 1, GFP_KERNEL);148148- if (!buf)149149- return -ENOMEM;150150+ u8 reg_addr = addr & 0xff;150151151151- buf[0] = addr;152152- memcpy(buf + 1, data, len);153153-154154- do {155155- ret = i2c_master_send(client, buf, len + 1);156156- if (likely(ret == len + 1))157157- break;158158-159159- msleep(20);160160- } while (++tries < RM_MAX_RETRIES);161161-162162- kfree(buf);163163-164164- if (unlikely(ret != len + 1)) {165165- if (ret >= 0)166166- ret = -EIO;167167- dev_err(&client->dev, "%s failed: %d\n", __func__, ret);168168- return ret;169169- }170170-171171- return 0;172172-}173173-174174-static int raydium_i2c_read(struct i2c_client *client,175175- u8 addr, void *data, size_t len)176176-{177152 struct i2c_msg xfer[] = {178153 {179154 .addr = client->addr,180180- .len = 1,181181- .buf = &addr,155155+ .len = sizeof(header),156156+ .buf = (u8 *)&header,182157 },183158 {184159 .addr = client->addr,185185- .flags = I2C_M_RD,160160+ .len = 1,161161+ .buf = ®_addr,162162+ },163163+ {164164+ .addr = client->addr,186165 .len = len,187166 .buf = data,167167+ .flags = is_read ? I2C_M_RD : 0,188168 }189169 };170170+171171+ /*172172+ * If address is greater than 255, then RM_CMD_BANK_SWITCH needs to be173173+ * sent first. Else, skip the header i.e. xfer[0].174174+ */175175+ int xfer_start_idx = (addr > 0xff) ? 0 : 1;176176+ size_t xfer_count = ARRAY_SIZE(xfer) - xfer_start_idx;190177 int ret;191178192192- ret = i2c_transfer(client->adapter, xfer, ARRAY_SIZE(xfer));193193- if (unlikely(ret != ARRAY_SIZE(xfer)))194194- return ret < 0 ? ret : -EIO;179179+ ret = i2c_transfer(client->adapter, &xfer[xfer_start_idx], xfer_count);180180+ if (likely(ret == xfer_count))181181+ return 0;195182196196- return 0;183183+ return ret < 0 ? ret : -EIO;197184}198185199199-static int raydium_i2c_read_message(struct i2c_client *client,200200- u32 addr, void *data, size_t len)186186+static int raydium_i2c_send(struct i2c_client *client,187187+ u32 addr, const void *data, size_t len)201188{202202- __be32 be_addr;189189+ int tries = 0;190190+ int error;191191+192192+ do {193193+ error = raydium_i2c_xfer(client, addr, (void *)data, len,194194+ false);195195+ if (likely(!error))196196+ return 0;197197+198198+ msleep(RM_RETRY_DELAY_MS);199199+ } while (++tries < RM_MAX_RETRIES);200200+201201+ dev_err(&client->dev, "%s failed: %d\n", __func__, error);202202+ return error;203203+}204204+205205+static int raydium_i2c_read(struct i2c_client *client,206206+ u32 addr, void *data, size_t len)207207+{203208 size_t xfer_len;204209 int error;205210206211 while (len) {207212 xfer_len = min_t(size_t, len, RM_MAX_READ_SIZE);208208-209209- be_addr = cpu_to_be32(addr);210210-211211- error = raydium_i2c_send(client, RM_CMD_BANK_SWITCH,212212- &be_addr, sizeof(be_addr));213213- if (!error)214214- error = raydium_i2c_read(client, addr & 0xff,215215- data, xfer_len);216216- if (error)213213+ error = raydium_i2c_xfer(client, addr, data, xfer_len, true);214214+ if (unlikely(error))217215 return error;218216219217 len -= xfer_len;···223223 return 0;224224}225225226226-static int raydium_i2c_send_message(struct i2c_client *client,227227- u32 addr, const void *data, size_t len)228228-{229229- __be32 be_addr = cpu_to_be32(addr);230230- int error;231231-232232- error = raydium_i2c_send(client, RM_CMD_BANK_SWITCH,233233- &be_addr, sizeof(be_addr));234234- if (!error)235235- error = raydium_i2c_send(client, addr & 0xff, data, len);236236-237237- return error;238238-}239239-240226static int raydium_i2c_sw_reset(struct i2c_client *client)241227{242228 const u8 soft_rst_cmd = 0x01;243229 int error;244230245245- error = raydium_i2c_send_message(client, RM_RESET_MSG_ADDR,246246- &soft_rst_cmd, sizeof(soft_rst_cmd));231231+ error = raydium_i2c_send(client, RM_RESET_MSG_ADDR, &soft_rst_cmd,232232+ sizeof(soft_rst_cmd));247233 if (error) {248234 dev_err(&client->dev, "software reset failed: %d\n", error);249235 return error;···281295 if (error)282296 continue;283297284284- error = raydium_i2c_read_message(client,285285- le32_to_cpu(query_bank_addr),286286- &ts->info, sizeof(ts->info));298298+ error = raydium_i2c_read(client, le32_to_cpu(query_bank_addr),299299+ &ts->info, sizeof(ts->info));287300 if (error)288301 continue;289302···819834 if (ts->boot_mode != RAYDIUM_TS_MAIN)820835 goto out;821836822822- error = raydium_i2c_read_message(ts->client, ts->data_bank_addr,823823- ts->report_data, ts->pkg_size);837837+ error = raydium_i2c_read(ts->client, ts->data_bank_addr,838838+ ts->report_data, ts->pkg_size);824839 if (error)825840 goto out;826841
+1-1
drivers/input/touchscreen/stmfts.c
···479479480480 mutex_lock(&sdata->mutex);481481482482- if (value & sdata->hover_enabled)482482+ if (value && sdata->hover_enabled)483483 goto out;484484485485 if (sdata->running)
+581
drivers/input/touchscreen/zinitix.c
···11+// SPDX-License-Identifier: GPL-2.0-only22+33+#include <linux/delay.h>44+#include <linux/i2c.h>55+#include <linux/input.h>66+#include <linux/input/mt.h>77+#include <linux/input/touchscreen.h>88+#include <linux/interrupt.h>99+#include <linux/irq.h>1010+#include <linux/kernel.h>1111+#include <linux/module.h>1212+#include <linux/of.h>1313+#include <linux/regulator/consumer.h>1414+#include <linux/slab.h>1515+1616+/* Register Map */1717+1818+#define BT541_SWRESET_CMD 0x00001919+#define BT541_WAKEUP_CMD 0x00012020+2121+#define BT541_IDLE_CMD 0x00042222+#define BT541_SLEEP_CMD 0x00052323+2424+#define BT541_CLEAR_INT_STATUS_CMD 0x00032525+#define BT541_CALIBRATE_CMD 0x00062626+#define BT541_SAVE_STATUS_CMD 0x00072727+#define BT541_SAVE_CALIBRATION_CMD 0x00082828+#define BT541_RECALL_FACTORY_CMD 0x000f2929+3030+#define BT541_THRESHOLD 0x00203131+3232+#define BT541_LARGE_PALM_REJECT_AREA_TH 0x003F3333+3434+#define BT541_DEBUG_REG 0x0115 /* 0~7 */3535+3636+#define BT541_TOUCH_MODE 0x00103737+#define BT541_CHIP_REVISION 0x00113838+#define BT541_FIRMWARE_VERSION 0x00123939+4040+#define ZINITIX_USB_DETECT 0x1164141+4242+#define BT541_MINOR_FW_VERSION 0x01214343+4444+#define BT541_VENDOR_ID 0x001C4545+#define BT541_HW_ID 0x00144646+4747+#define BT541_DATA_VERSION_REG 0x00134848+#define BT541_SUPPORTED_FINGER_NUM 0x00154949+#define BT541_EEPROM_INFO 0x00185050+#define BT541_INITIAL_TOUCH_MODE 0x00195151+5252+#define BT541_TOTAL_NUMBER_OF_X 0x00605353+#define BT541_TOTAL_NUMBER_OF_Y 0x00615454+5555+#define BT541_DELAY_RAW_FOR_HOST 0x007f5656+5757+#define BT541_BUTTON_SUPPORTED_NUM 0x00B05858+#define BT541_BUTTON_SENSITIVITY 0x00B25959+#define BT541_DUMMY_BUTTON_SENSITIVITY 0X00C86060+6161+#define BT541_X_RESOLUTION 0x00C06262+#define BT541_Y_RESOLUTION 0x00C16363+6464+#define BT541_POINT_STATUS_REG 0x00806565+#define BT541_ICON_STATUS_REG 0x00AA6666+6767+#define BT541_POINT_COORD_REG (BT541_POINT_STATUS_REG + 2)6868+6969+#define BT541_AFE_FREQUENCY 0x01007070+#define BT541_DND_N_COUNT 0x01227171+#define BT541_DND_U_COUNT 0x01357272+7373+#define BT541_RAWDATA_REG 0x02007474+7575+#define BT541_EEPROM_INFO_REG 0x00187676+7777+#define BT541_INT_ENABLE_FLAG 0x00f07878+#define BT541_PERIODICAL_INTERRUPT_INTERVAL 0x00f17979+8080+#define BT541_BTN_WIDTH 0x016d8181+8282+#define BT541_CHECKSUM_RESULT 0x012c8383+8484+#define BT541_INIT_FLASH 0x01d08585+#define BT541_WRITE_FLASH 0x01d18686+#define BT541_READ_FLASH 0x01d28787+8888+#define ZINITIX_INTERNAL_FLAG_02 0x011e8989+#define ZINITIX_INTERNAL_FLAG_03 0x011f9090+9191+#define ZINITIX_I2C_CHECKSUM_WCNT 0x016a9292+#define ZINITIX_I2C_CHECKSUM_RESULT 0x016c9393+9494+/* Interrupt & status register flags */9595+9696+#define BIT_PT_CNT_CHANGE BIT(0)9797+#define BIT_DOWN BIT(1)9898+#define BIT_MOVE BIT(2)9999+#define BIT_UP BIT(3)100100+#define BIT_PALM BIT(4)101101+#define BIT_PALM_REJECT BIT(5)102102+#define BIT_RESERVED_0 BIT(6)103103+#define BIT_RESERVED_1 BIT(7)104104+#define BIT_WEIGHT_CHANGE BIT(8)105105+#define BIT_PT_NO_CHANGE BIT(9)106106+#define BIT_REJECT BIT(10)107107+#define BIT_PT_EXIST BIT(11)108108+#define BIT_RESERVED_2 BIT(12)109109+#define BIT_ERROR BIT(13)110110+#define BIT_DEBUG BIT(14)111111+#define BIT_ICON_EVENT BIT(15)112112+113113+#define SUB_BIT_EXIST BIT(0)114114+#define SUB_BIT_DOWN BIT(1)115115+#define SUB_BIT_MOVE BIT(2)116116+#define SUB_BIT_UP BIT(3)117117+#define SUB_BIT_UPDATE BIT(4)118118+#define SUB_BIT_WAIT BIT(5)119119+120120+#define DEFAULT_TOUCH_POINT_MODE 2121121+#define MAX_SUPPORTED_FINGER_NUM 5122122+123123+#define CHIP_ON_DELAY 15 // ms124124+#define FIRMWARE_ON_DELAY 40 // ms125125+126126+struct point_coord {127127+ __le16 x;128128+ __le16 y;129129+ u8 width;130130+ u8 sub_status;131131+ // currently unused, but needed as padding:132132+ u8 minor_width;133133+ u8 angle;134134+};135135+136136+struct touch_event {137137+ __le16 status;138138+ u8 finger_cnt;139139+ u8 time_stamp;140140+ struct point_coord point_coord[MAX_SUPPORTED_FINGER_NUM];141141+};142142+143143+struct bt541_ts_data {144144+ struct i2c_client *client;145145+ struct input_dev *input_dev;146146+ struct touchscreen_properties prop;147147+ struct regulator_bulk_data supplies[2];148148+ u32 zinitix_mode;149149+};150150+151151+static int zinitix_read_data(struct i2c_client *client,152152+ u16 reg, void *values, size_t length)153153+{154154+ __le16 reg_le = cpu_to_le16(reg);155155+ int ret;156156+157157+ /* A single i2c_transfer() transaction does not work here. */158158+ ret = i2c_master_send(client, (u8 *)®_le, sizeof(reg_le));159159+ if (ret != sizeof(reg_le))160160+ return ret < 0 ? ret : -EIO;161161+162162+ ret = i2c_master_recv(client, (u8 *)values, length);163163+ if (ret != length)164164+ return ret < 0 ? ret : -EIO; ;165165+166166+ return 0;167167+}168168+169169+static int zinitix_write_u16(struct i2c_client *client, u16 reg, u16 value)170170+{171171+ __le16 packet[2] = {cpu_to_le16(reg), cpu_to_le16(value)};172172+ int ret;173173+174174+ ret = i2c_master_send(client, (u8 *)packet, sizeof(packet));175175+ if (ret != sizeof(packet))176176+ return ret < 0 ? ret : -EIO;177177+178178+ return 0;179179+}180180+181181+static int zinitix_write_cmd(struct i2c_client *client, u16 reg)182182+{183183+ __le16 reg_le = cpu_to_le16(reg);184184+ int ret;185185+186186+ ret = i2c_master_send(client, (u8 *)®_le, sizeof(reg_le));187187+ if (ret != sizeof(reg_le))188188+ return ret < 0 ? ret : -EIO;189189+190190+ return 0;191191+}192192+193193+static bool zinitix_init_touch(struct bt541_ts_data *bt541)194194+{195195+ struct i2c_client *client = bt541->client;196196+ int i;197197+ int error;198198+199199+ error = zinitix_write_cmd(client, BT541_SWRESET_CMD);200200+ if (error) {201201+ dev_err(&client->dev, "Failed to write reset command\n");202202+ return error;203203+ }204204+205205+ error = zinitix_write_u16(client, BT541_INT_ENABLE_FLAG, 0x0);206206+ if (error) {207207+ dev_err(&client->dev,208208+ "Failed to reset interrupt enable flag\n");209209+ return error;210210+ }211211+212212+ /* initialize */213213+ error = zinitix_write_u16(client, BT541_X_RESOLUTION,214214+ bt541->prop.max_x);215215+ if (error)216216+ return error;217217+218218+ error = zinitix_write_u16(client, BT541_Y_RESOLUTION,219219+ bt541->prop.max_y);220220+ if (error)221221+ return error;222222+223223+ error = zinitix_write_u16(client, BT541_SUPPORTED_FINGER_NUM,224224+ MAX_SUPPORTED_FINGER_NUM);225225+ if (error)226226+ return error;227227+228228+ error = zinitix_write_u16(client, BT541_INITIAL_TOUCH_MODE,229229+ bt541->zinitix_mode);230230+ if (error)231231+ return error;232232+233233+ error = zinitix_write_u16(client, BT541_TOUCH_MODE,234234+ bt541->zinitix_mode);235235+ if (error)236236+ return error;237237+238238+ error = zinitix_write_u16(client, BT541_INT_ENABLE_FLAG,239239+ BIT_PT_CNT_CHANGE | BIT_DOWN | BIT_MOVE |240240+ BIT_UP);241241+ if (error)242242+ return error;243243+244244+ /* clear queue */245245+ for (i = 0; i < 10; i++) {246246+ zinitix_write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);247247+ udelay(10);248248+ }249249+250250+ return 0;251251+}252252+253253+static int zinitix_init_regulators(struct bt541_ts_data *bt541)254254+{255255+ struct i2c_client *client = bt541->client;256256+ int error;257257+258258+ bt541->supplies[0].supply = "vdd";259259+ bt541->supplies[1].supply = "vddo";260260+ error = devm_regulator_bulk_get(&client->dev,261261+ ARRAY_SIZE(bt541->supplies),262262+ bt541->supplies);263263+ if (error < 0) {264264+ dev_err(&client->dev, "Failed to get regulators: %d\n", error);265265+ return error;266266+ }267267+268268+ return 0;269269+}270270+271271+static int zinitix_send_power_on_sequence(struct bt541_ts_data *bt541)272272+{273273+ int error;274274+ struct i2c_client *client = bt541->client;275275+276276+ error = zinitix_write_u16(client, 0xc000, 0x0001);277277+ if (error) {278278+ dev_err(&client->dev,279279+ "Failed to send power sequence(vendor cmd enable)\n");280280+ return error;281281+ }282282+ udelay(10);283283+284284+ error = zinitix_write_cmd(client, 0xc004);285285+ if (error) {286286+ dev_err(&client->dev,287287+ "Failed to send power sequence (intn clear)\n");288288+ return error;289289+ }290290+ udelay(10);291291+292292+ error = zinitix_write_u16(client, 0xc002, 0x0001);293293+ if (error) {294294+ dev_err(&client->dev,295295+ "Failed to send power sequence (nvm init)\n");296296+ return error;297297+ }298298+ mdelay(2);299299+300300+ error = zinitix_write_u16(client, 0xc001, 0x0001);301301+ if (error) {302302+ dev_err(&client->dev,303303+ "Failed to send power sequence (program start)\n");304304+ return error;305305+ }306306+ msleep(FIRMWARE_ON_DELAY);307307+308308+ return 0;309309+}310310+311311+static void zinitix_report_finger(struct bt541_ts_data *bt541, int slot,312312+ const struct point_coord *p)313313+{314314+ input_mt_slot(bt541->input_dev, slot);315315+ input_mt_report_slot_state(bt541->input_dev, MT_TOOL_FINGER, true);316316+ touchscreen_report_pos(bt541->input_dev, &bt541->prop,317317+ le16_to_cpu(p->x), le16_to_cpu(p->y), true);318318+ input_report_abs(bt541->input_dev, ABS_MT_TOUCH_MAJOR, p->width);319319+}320320+321321+static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler)322322+{323323+ struct bt541_ts_data *bt541 = bt541_handler;324324+ struct i2c_client *client = bt541->client;325325+ struct touch_event touch_event;326326+ int error;327327+ int i;328328+329329+ memset(&touch_event, 0, sizeof(struct touch_event));330330+331331+ error = zinitix_read_data(bt541->client, BT541_POINT_STATUS_REG,332332+ &touch_event, sizeof(struct touch_event));333333+ if (error) {334334+ dev_err(&client->dev, "Failed to read in touchpoint struct\n");335335+ goto out;336336+ }337337+338338+ for (i = 0; i < MAX_SUPPORTED_FINGER_NUM; i++)339339+ if (touch_event.point_coord[i].sub_status & SUB_BIT_EXIST)340340+ zinitix_report_finger(bt541, i,341341+ &touch_event.point_coord[i]);342342+343343+ input_mt_sync_frame(bt541->input_dev);344344+ input_sync(bt541->input_dev);345345+346346+out:347347+ zinitix_write_cmd(bt541->client, BT541_CLEAR_INT_STATUS_CMD);348348+ return IRQ_HANDLED;349349+}350350+351351+static int zinitix_start(struct bt541_ts_data *bt541)352352+{353353+ int error;354354+355355+ error = regulator_bulk_enable(ARRAY_SIZE(bt541->supplies),356356+ bt541->supplies);357357+ if (error) {358358+ dev_err(&bt541->client->dev,359359+ "Failed to enable regulators: %d\n", error);360360+ return error;361361+ }362362+363363+ msleep(CHIP_ON_DELAY);364364+365365+ error = zinitix_send_power_on_sequence(bt541);366366+ if (error) {367367+ dev_err(&bt541->client->dev,368368+ "Error while sending power-on sequence: %d\n", error);369369+ return error;370370+ }371371+372372+ error = zinitix_init_touch(bt541);373373+ if (error) {374374+ dev_err(&bt541->client->dev,375375+ "Error while configuring touch IC\n");376376+ return error;377377+ }378378+379379+ enable_irq(bt541->client->irq);380380+381381+ return 0;382382+}383383+384384+static int zinitix_stop(struct bt541_ts_data *bt541)385385+{386386+ int error;387387+388388+ disable_irq(bt541->client->irq);389389+390390+ error = regulator_bulk_disable(ARRAY_SIZE(bt541->supplies),391391+ bt541->supplies);392392+ if (error) {393393+ dev_err(&bt541->client->dev,394394+ "Failed to disable regulators: %d\n", error);395395+ return error;396396+ }397397+398398+ return 0;399399+}400400+401401+static int zinitix_input_open(struct input_dev *dev)402402+{403403+ struct bt541_ts_data *bt541 = input_get_drvdata(dev);404404+405405+ return zinitix_start(bt541);406406+}407407+408408+static void zinitix_input_close(struct input_dev *dev)409409+{410410+ struct bt541_ts_data *bt541 = input_get_drvdata(dev);411411+412412+ zinitix_stop(bt541);413413+}414414+415415+static int zinitix_init_input_dev(struct bt541_ts_data *bt541)416416+{417417+ struct input_dev *input_dev;418418+ int error;419419+420420+ input_dev = devm_input_allocate_device(&bt541->client->dev);421421+ if (!input_dev) {422422+ dev_err(&bt541->client->dev,423423+ "Failed to allocate input device.");424424+ return -ENOMEM;425425+ }426426+427427+ input_set_drvdata(input_dev, bt541);428428+ bt541->input_dev = input_dev;429429+430430+ input_dev->name = "Zinitix Capacitive TouchScreen";431431+ input_dev->phys = "input/ts";432432+ input_dev->id.bustype = BUS_I2C;433433+ input_dev->open = zinitix_input_open;434434+ input_dev->close = zinitix_input_close;435435+436436+ input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);437437+ input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);438438+ input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);439439+ input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);440440+441441+ touchscreen_parse_properties(input_dev, true, &bt541->prop);442442+ if (!bt541->prop.max_x || !bt541->prop.max_y) {443443+ dev_err(&bt541->client->dev,444444+ "Touchscreen-size-x and/or touchscreen-size-y not set in dts\n");445445+ return -EINVAL;446446+ }447447+448448+ error = input_mt_init_slots(input_dev, MAX_SUPPORTED_FINGER_NUM,449449+ INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);450450+ if (error) {451451+ dev_err(&bt541->client->dev,452452+ "Failed to initialize MT slots: %d", error);453453+ return error;454454+ }455455+456456+ error = input_register_device(input_dev);457457+ if (error) {458458+ dev_err(&bt541->client->dev,459459+ "Failed to register input device: %d", error);460460+ return error;461461+ }462462+463463+ return 0;464464+}465465+466466+static int zinitix_ts_probe(struct i2c_client *client)467467+{468468+ struct bt541_ts_data *bt541;469469+ int error;470470+471471+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {472472+ dev_err(&client->dev,473473+ "Failed to assert adapter's support for plain I2C.\n");474474+ return -ENXIO;475475+ }476476+477477+ bt541 = devm_kzalloc(&client->dev, sizeof(*bt541), GFP_KERNEL);478478+ if (!bt541)479479+ return -ENOMEM;480480+481481+ bt541->client = client;482482+ i2c_set_clientdata(client, bt541);483483+484484+ error = zinitix_init_regulators(bt541);485485+ if (error) {486486+ dev_err(&client->dev,487487+ "Failed to initialize regulators: %d\n", error);488488+ return error;489489+ }490490+491491+ error = zinitix_init_input_dev(bt541);492492+ if (error) {493493+ dev_err(&client->dev,494494+ "Failed to initialize input device: %d\n", error);495495+ return error;496496+ }497497+498498+ error = device_property_read_u32(&client->dev, "zinitix,mode",499499+ &bt541->zinitix_mode);500500+ if (error < 0) {501501+ /* fall back to mode 2 */502502+ bt541->zinitix_mode = DEFAULT_TOUCH_POINT_MODE;503503+ }504504+505505+ if (bt541->zinitix_mode != 2) {506506+ /*507507+ * If there are devices that don't support mode 2, support508508+ * for other modes (0, 1) will be needed.509509+ */510510+ dev_err(&client->dev,511511+ "Malformed zinitix,mode property, must be 2 (supplied: %d)\n",512512+ bt541->zinitix_mode);513513+ return -EINVAL;514514+ }515515+516516+ irq_set_status_flags(client->irq, IRQ_NOAUTOEN);517517+ error = devm_request_threaded_irq(&client->dev, client->irq,518518+ NULL, zinitix_ts_irq_handler,519519+ IRQF_ONESHOT, client->name, bt541);520520+ if (error) {521521+ dev_err(&client->dev, "Failed to request IRQ: %d\n", error);522522+ return error;523523+ }524524+525525+ return 0;526526+}527527+528528+static int __maybe_unused zinitix_suspend(struct device *dev)529529+{530530+ struct i2c_client *client = to_i2c_client(dev);531531+ struct bt541_ts_data *bt541 = i2c_get_clientdata(client);532532+533533+ mutex_lock(&bt541->input_dev->mutex);534534+535535+ if (bt541->input_dev->users)536536+ zinitix_stop(bt541);537537+538538+ mutex_unlock(&bt541->input_dev->mutex);539539+540540+ return 0;541541+}542542+543543+static int __maybe_unused zinitix_resume(struct device *dev)544544+{545545+ struct i2c_client *client = to_i2c_client(dev);546546+ struct bt541_ts_data *bt541 = i2c_get_clientdata(client);547547+ int ret = 0;548548+549549+ mutex_lock(&bt541->input_dev->mutex);550550+551551+ if (bt541->input_dev->users)552552+ ret = zinitix_start(bt541);553553+554554+ mutex_unlock(&bt541->input_dev->mutex);555555+556556+ return ret;557557+}558558+559559+static SIMPLE_DEV_PM_OPS(zinitix_pm_ops, zinitix_suspend, zinitix_resume);560560+561561+#ifdef CONFIG_OF562562+static const struct of_device_id zinitix_of_match[] = {563563+ { .compatible = "zinitix,bt541" },564564+ { }565565+};566566+MODULE_DEVICE_TABLE(of, zinitix_of_match);567567+#endif568568+569569+static struct i2c_driver zinitix_ts_driver = {570570+ .probe_new = zinitix_ts_probe,571571+ .driver = {572572+ .name = "Zinitix-TS",573573+ .pm = &zinitix_pm_ops,574574+ .of_match_table = of_match_ptr(zinitix_of_match),575575+ },576576+};577577+module_i2c_driver(zinitix_ts_driver);578578+579579+MODULE_AUTHOR("Michael Srba <Michael.Srba@seznam.cz>");580580+MODULE_DESCRIPTION("Zinitix touchscreen driver");581581+MODULE_LICENSE("GPL v2");
···102102};103103104104/**105105- * struct rmi_f30_data - overrides defaults for a single F30 GPIOs/LED chip.105105+ * struct rmi_gpio_data - overrides defaults for a single F30/F3A GPIOs/LED106106+ * chip.106107 * @buttonpad - the touchpad is a buttonpad, so enable only the first actual107108 * button that is found.108108- * @trackstick_buttons - Set when the function 30 is handling the physical109109+ * @trackstick_buttons - Set when the function 30 or 3a is handling the physical109110 * buttons of the trackstick (as a PS/2 passthrough device).110110- * @disable - the touchpad incorrectly reports F30 and it should be ignored.111111+ * @disable - the touchpad incorrectly reports F30/F3A and it should be ignored.111112 * This is a special case which is due to misconfigured firmware.112113 */113113-struct rmi_f30_data {114114+struct rmi_gpio_data {114115 bool buttonpad;115116 bool trackstick_buttons;116117 bool disable;···219218 /* function handler pdata */220219 struct rmi_2d_sensor_platform_data sensor_pdata;221220 struct rmi_f01_power_management power_management;222222- struct rmi_f30_data f30_data;221221+ struct rmi_gpio_data gpio_data;223222};224223225224/**