@@ -107,6 +107,84 @@ static const struct i2c_device_id pca953x_id[] = {
107
107
};
108
108
MODULE_DEVICE_TABLE (i2c , pca953x_id );
109
109
110
+ #ifdef CONFIG_GPIO_PCA953X_IRQ
111
+
112
+ #include <linux/dmi.h>
113
+ #include <linux/gpio.h>
114
+ #include <linux/list.h>
115
+
116
+ static const struct dmi_system_id pca953x_dmi_acpi_irq_info [] = {
117
+ {
118
+ /*
119
+ * On Intel Galileo Gen 2 board the IRQ pin of one of
120
+ * the I²C GPIO expanders, which has GpioInt() resource,
121
+ * is provided as an absolute number instead of being
122
+ * relative. Since first controller (gpio-sch.c) and
123
+ * second (gpio-dwapb.c) are at the fixed bases, we may
124
+ * safely refer to the number in the global space to get
125
+ * an IRQ out of it.
126
+ */
127
+ .matches = {
128
+ DMI_EXACT_MATCH (DMI_BOARD_NAME , "GalileoGen2" ),
129
+ },
130
+ },
131
+ {}
132
+ };
133
+
134
+ #ifdef CONFIG_ACPI
135
+ static int pca953x_acpi_get_pin (struct acpi_resource * ares , void * data )
136
+ {
137
+ struct acpi_resource_gpio * agpio ;
138
+ int * pin = data ;
139
+
140
+ if (acpi_gpio_get_irq_resource (ares , & agpio ))
141
+ * pin = agpio -> pin_table [0 ];
142
+ return 1 ;
143
+ }
144
+
145
+ static int pca953x_acpi_find_pin (struct device * dev )
146
+ {
147
+ struct acpi_device * adev = ACPI_COMPANION (dev );
148
+ int pin = - ENOENT , ret ;
149
+ LIST_HEAD (r );
150
+
151
+ ret = acpi_dev_get_resources (adev , & r , pca953x_acpi_get_pin , & pin );
152
+ acpi_dev_free_resource_list (& r );
153
+ if (ret < 0 )
154
+ return ret ;
155
+
156
+ return pin ;
157
+ }
158
+ #else
159
+ static inline int pca953x_acpi_find_pin (struct device * dev ) { return - ENXIO ; }
160
+ #endif
161
+
162
+ static int pca953x_acpi_get_irq (struct device * dev )
163
+ {
164
+ int pin , ret ;
165
+
166
+ pin = pca953x_acpi_find_pin (dev );
167
+ if (pin < 0 )
168
+ return pin ;
169
+
170
+ dev_info (dev , "Applying ACPI interrupt quirk (GPIO %d)\n" , pin );
171
+
172
+ if (!gpio_is_valid (pin ))
173
+ return - EINVAL ;
174
+
175
+ ret = gpio_request (pin , "pca953x interrupt" );
176
+ if (ret )
177
+ return ret ;
178
+
179
+ ret = gpio_to_irq (pin );
180
+
181
+ /* When pin is used as an IRQ, no need to keep it requested */
182
+ gpio_free (pin );
183
+
184
+ return ret ;
185
+ }
186
+ #endif
187
+
110
188
static const struct acpi_device_id pca953x_acpi_ids [] = {
111
189
{ "INT3491" , 16 | PCA953X_TYPE | PCA_LATCH_INT , },
112
190
{ }
@@ -322,6 +400,7 @@ static const struct regmap_config pca953x_ai_i2c_regmap = {
322
400
.writeable_reg = pca953x_writeable_register ,
323
401
.volatile_reg = pca953x_volatile_register ,
324
402
403
+ .disable_locking = true,
325
404
.cache_type = REGCACHE_RBTREE ,
326
405
.max_register = 0x7f ,
327
406
};
@@ -623,8 +702,6 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
623
702
DECLARE_BITMAP (reg_direction , MAX_LINE );
624
703
int level ;
625
704
626
- pca953x_read_regs (chip , chip -> regs -> direction , reg_direction );
627
-
628
705
if (chip -> driver_data & PCA_PCAL ) {
629
706
/* Enable latch on interrupt-enabled inputs */
630
707
pca953x_write_regs (chip , PCAL953X_IN_LATCH , chip -> irq_mask );
@@ -635,7 +712,11 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
635
712
pca953x_write_regs (chip , PCAL953X_INT_MASK , irq_mask );
636
713
}
637
714
715
+ /* Switch direction to input if needed */
716
+ pca953x_read_regs (chip , chip -> regs -> direction , reg_direction );
717
+
638
718
bitmap_or (irq_mask , chip -> irq_trig_fall , chip -> irq_trig_raise , gc -> ngpio );
719
+ bitmap_complement (reg_direction , reg_direction , gc -> ngpio );
639
720
bitmap_and (irq_mask , irq_mask , reg_direction , gc -> ngpio );
640
721
641
722
/* Look for any newly setup interrupt */
@@ -734,14 +815,16 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
734
815
struct gpio_chip * gc = & chip -> gpio_chip ;
735
816
DECLARE_BITMAP (pending , MAX_LINE );
736
817
int level ;
818
+ bool ret ;
737
819
738
- if (!pca953x_irq_pending (chip , pending ))
739
- return IRQ_NONE ;
820
+ mutex_lock (& chip -> i2c_lock );
821
+ ret = pca953x_irq_pending (chip , pending );
822
+ mutex_unlock (& chip -> i2c_lock );
740
823
741
824
for_each_set_bit (level , pending , gc -> ngpio )
742
825
handle_nested_irq (irq_find_mapping (gc -> irq .domain , level ));
743
826
744
- return IRQ_HANDLED ;
827
+ return IRQ_RETVAL ( ret ) ;
745
828
}
746
829
747
830
static int pca953x_irq_setup (struct pca953x_chip * chip , int irq_base )
@@ -752,6 +835,12 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base)
752
835
DECLARE_BITMAP (irq_stat , MAX_LINE );
753
836
int ret ;
754
837
838
+ if (dmi_first_match (pca953x_dmi_acpi_irq_info )) {
839
+ ret = pca953x_acpi_get_irq (& client -> dev );
840
+ if (ret > 0 )
841
+ client -> irq = ret ;
842
+ }
843
+
755
844
if (!client -> irq )
756
845
return 0 ;
757
846
0 commit comments