2525 * with this program; if not, write to the Free Software Foundation, Inc.,
2626 * 675 Mass Ave, Cambridge, MA 02139, USA.
2727 */
28- #include <linux/gpio.h>
28+ #include <linux/gpio/consumer.h>
29+ #include <linux/gpio/driver.h>
2930#include <linux/gpio/machine.h>
3031#include <linux/kernel.h>
3132#include <linux/init.h>
6465/* TPS65010 has four GPIOs. nPG and LED2 can be treated like GPIOs with
6566 * alternate pin configurations for hardware-controlled blinking.
6667 */
67- #define OSK_TPS_GPIO_BASE (OMAP_MAX_GPIO_LINES + 16 /* MPUIO */ )
68- # define OSK_TPS_GPIO_USB_PWR_EN (OSK_TPS_GPIO_BASE + 0)
69- # define OSK_TPS_GPIO_LED_D3 (OSK_TPS_GPIO_BASE + 1)
70- # define OSK_TPS_GPIO_LAN_RESET (OSK_TPS_GPIO_BASE + 2)
71- # define OSK_TPS_GPIO_DSP_PWR_EN (OSK_TPS_GPIO_BASE + 3)
72- # define OSK_TPS_GPIO_LED_D9 (OSK_TPS_GPIO_BASE + 4)
73- # define OSK_TPS_GPIO_LED_D2 (OSK_TPS_GPIO_BASE + 5)
68+ #define OSK_TPS_GPIO_USB_PWR_EN 0
69+ #define OSK_TPS_GPIO_LED_D3 1
70+ #define OSK_TPS_GPIO_LAN_RESET 2
71+ #define OSK_TPS_GPIO_DSP_PWR_EN 3
72+ #define OSK_TPS_GPIO_LED_D9 4
73+ #define OSK_TPS_GPIO_LED_D2 5
7474
7575static struct mtd_partition osk_partitions [] = {
7676 /* bootloader (U-Boot, etc) in first sector */
@@ -174,11 +174,20 @@ static const struct gpio_led tps_leds[] = {
174174 /* NOTE: D9 and D2 have hardware blink support.
175175 * Also, D9 requires non-battery power.
176176 */
177- { .gpio = OSK_TPS_GPIO_LED_D9 , .name = "d9" ,
178- .default_trigger = "disk-activity" , },
179- { .gpio = OSK_TPS_GPIO_LED_D2 , .name = "d2" , },
180- { .gpio = OSK_TPS_GPIO_LED_D3 , .name = "d3" , .active_low = 1 ,
181- .default_trigger = "heartbeat" , },
177+ { .name = "d9" , .default_trigger = "disk-activity" , },
178+ { .name = "d2" , },
179+ { .name = "d3" , .default_trigger = "heartbeat" , },
180+ };
181+
182+ static struct gpiod_lookup_table tps_leds_gpio_table = {
183+ .dev_id = "leds-gpio" ,
184+ .table = {
185+ /* Use local offsets on TPS65010 */
186+ GPIO_LOOKUP_IDX ("tps65010" , OSK_TPS_GPIO_LED_D9 , NULL , 0 , GPIO_ACTIVE_HIGH ),
187+ GPIO_LOOKUP_IDX ("tps65010" , OSK_TPS_GPIO_LED_D2 , NULL , 1 , GPIO_ACTIVE_HIGH ),
188+ GPIO_LOOKUP_IDX ("tps65010" , OSK_TPS_GPIO_LED_D3 , NULL , 2 , GPIO_ACTIVE_LOW ),
189+ { }
190+ },
182191};
183192
184193static struct gpio_led_platform_data tps_leds_data = {
@@ -192,29 +201,34 @@ static struct platform_device osk5912_tps_leds = {
192201 .dev .platform_data = & tps_leds_data ,
193202};
194203
195- static int osk_tps_setup (struct i2c_client * client , void * context )
204+ /* The board just hold these GPIOs hogged from setup to teardown */
205+ static struct gpio_desc * eth_reset ;
206+ static struct gpio_desc * vdd_dsp ;
207+
208+ static int osk_tps_setup (struct i2c_client * client , struct gpio_chip * gc )
196209{
210+ struct gpio_desc * d ;
197211 if (!IS_BUILTIN (CONFIG_TPS65010 ))
198212 return - ENOSYS ;
199213
200214 /* Set GPIO 1 HIGH to disable VBUS power supply;
201215 * OHCI driver powers it up/down as needed.
202216 */
203- gpio_request ( OSK_TPS_GPIO_USB_PWR_EN , "n_vbus_en" );
204- gpio_direction_output ( OSK_TPS_GPIO_USB_PWR_EN , 1 );
217+ d = gpiochip_request_own_desc ( gc , OSK_TPS_GPIO_USB_PWR_EN , "n_vbus_en" ,
218+ GPIO_ACTIVE_HIGH , GPIOD_OUT_HIGH );
205219 /* Free the GPIO again as the driver will request it */
206- gpio_free ( OSK_TPS_GPIO_USB_PWR_EN );
220+ gpiochip_free_own_desc ( d );
207221
208222 /* Set GPIO 2 high so LED D3 is off by default */
209223 tps65010_set_gpio_out_value (GPIO2 , HIGH );
210224
211225 /* Set GPIO 3 low to take ethernet out of reset */
212- gpio_request ( OSK_TPS_GPIO_LAN_RESET , "smc_reset" );
213- gpio_direction_output ( OSK_TPS_GPIO_LAN_RESET , 0 );
226+ eth_reset = gpiochip_request_own_desc ( gc , OSK_TPS_GPIO_LAN_RESET , "smc_reset" ,
227+ GPIO_ACTIVE_HIGH , GPIOD_OUT_LOW );
214228
215229 /* GPIO4 is VDD_DSP */
216- gpio_request ( OSK_TPS_GPIO_DSP_PWR_EN , "dsp_power" );
217- gpio_direction_output ( OSK_TPS_GPIO_DSP_PWR_EN , 1 );
230+ vdd_dsp = gpiochip_request_own_desc ( gc , OSK_TPS_GPIO_DSP_PWR_EN , "dsp_power" ,
231+ GPIO_ACTIVE_HIGH , GPIOD_OUT_HIGH );
218232 /* REVISIT if DSP support isn't configured, power it off ... */
219233
220234 /* Let LED1 (D9) blink; leds-gpio may override it */
@@ -232,15 +246,22 @@ static int osk_tps_setup(struct i2c_client *client, void *context)
232246
233247 /* register these three LEDs */
234248 osk5912_tps_leds .dev .parent = & client -> dev ;
249+ gpiod_add_lookup_table (& tps_leds_gpio_table );
235250 platform_device_register (& osk5912_tps_leds );
236251
237252 return 0 ;
238253}
239254
255+ static void osk_tps_teardown (struct i2c_client * client , struct gpio_chip * gc )
256+ {
257+ gpiochip_free_own_desc (eth_reset );
258+ gpiochip_free_own_desc (vdd_dsp );
259+ }
260+
240261static struct tps65010_board tps_board = {
241- .base = OSK_TPS_GPIO_BASE ,
242262 .outmask = 0x0f ,
243263 .setup = osk_tps_setup ,
264+ .teardown = osk_tps_teardown ,
244265};
245266
246267static struct i2c_board_info __initdata osk_i2c_board_info [] = {
@@ -263,11 +284,6 @@ static void __init osk_init_smc91x(void)
263284{
264285 u32 l ;
265286
266- if ((gpio_request (0 , "smc_irq" )) < 0 ) {
267- printk ("Error requesting gpio 0 for smc91x irq\n" );
268- return ;
269- }
270-
271287 /* Check EMIFS wait states to fix errors with SMC_GET_PKT_HDR */
272288 l = omap_readl (EMIFS_CCS (1 ));
273289 l |= 0x3 ;
@@ -279,10 +295,6 @@ static void __init osk_init_cf(int seg)
279295 struct resource * res = & osk5912_cf_resources [1 ];
280296
281297 omap_cfg_reg (M7_1610_GPIO62 );
282- if ((gpio_request (62 , "cf_irq" )) < 0 ) {
283- printk ("Error requesting gpio 62 for CF irq\n" );
284- return ;
285- }
286298
287299 switch (seg ) {
288300 /* NOTE: CS0 could be configured too ... */
@@ -308,18 +320,17 @@ static void __init osk_init_cf(int seg)
308320 seg , omap_readl (EMIFS_CCS (seg )), omap_readl (EMIFS_ACS (seg )));
309321 omap_writel (0x0004a1b3 , EMIFS_CCS (seg )); /* synch mode 4 etc */
310322 omap_writel (0x00000000 , EMIFS_ACS (seg )); /* OE hold/setup */
311-
312- /* the CF I/O IRQ is really active-low */
313- irq_set_irq_type (gpio_to_irq (62 ), IRQ_TYPE_EDGE_FALLING );
314323}
315324
316325static struct gpiod_lookup_table osk_usb_gpio_table = {
317326 .dev_id = "ohci" ,
318327 .table = {
319328 /* Power GPIO on the I2C-attached TPS65010 */
320- GPIO_LOOKUP ("tps65010" , 0 , "power" , GPIO_ACTIVE_HIGH ),
329+ GPIO_LOOKUP ("tps65010" , OSK_TPS_GPIO_USB_PWR_EN , "power" ,
330+ GPIO_ACTIVE_HIGH ),
321331 GPIO_LOOKUP (OMAP_GPIO_LABEL , 9 , "overcurrent" ,
322332 GPIO_ACTIVE_HIGH ),
333+ { }
323334 },
324335};
325336
@@ -341,8 +352,25 @@ static struct omap_usb_config osk_usb_config __initdata = {
341352
342353#define EMIFS_CS3_VAL (0x88013141)
343354
355+ static struct gpiod_lookup_table osk_irq_gpio_table = {
356+ .dev_id = NULL ,
357+ .table = {
358+ /* GPIO used for SMC91x IRQ */
359+ GPIO_LOOKUP (OMAP_GPIO_LABEL , 0 , "smc_irq" ,
360+ GPIO_ACTIVE_HIGH ),
361+ /* GPIO used for CF IRQ */
362+ GPIO_LOOKUP ("gpio-48-63" , 14 , "cf_irq" ,
363+ GPIO_ACTIVE_HIGH ),
364+ /* GPIO used by the TPS65010 chip */
365+ GPIO_LOOKUP ("mpuio" , 1 , "tps65010" ,
366+ GPIO_ACTIVE_HIGH ),
367+ { }
368+ },
369+ };
370+
344371static void __init osk_init (void )
345372{
373+ struct gpio_desc * d ;
346374 u32 l ;
347375
348376 osk_init_smc91x ();
@@ -359,10 +387,31 @@ static void __init osk_init(void)
359387
360388 osk_flash_resource .end = osk_flash_resource .start = omap_cs3_phys ();
361389 osk_flash_resource .end += SZ_32M - 1 ;
362- osk5912_smc91x_resources [1 ].start = gpio_to_irq (0 );
363- osk5912_smc91x_resources [1 ].end = gpio_to_irq (0 );
364- osk5912_cf_resources [0 ].start = gpio_to_irq (62 );
365- osk5912_cf_resources [0 ].end = gpio_to_irq (62 );
390+
391+ /*
392+ * Add the GPIOs to be used as IRQs and immediately look them up
393+ * to be passed as an IRQ resource. This is ugly but should work
394+ * until the day we convert to device tree.
395+ */
396+ gpiod_add_lookup_table (& osk_irq_gpio_table );
397+
398+ d = gpiod_get (NULL , "smc_irq" , GPIOD_IN );
399+ if (IS_ERR (d )) {
400+ pr_err ("Unable to get SMC IRQ GPIO descriptor\n" );
401+ } else {
402+ irq_set_irq_type (gpiod_to_irq (d ), IRQ_TYPE_EDGE_RISING );
403+ osk5912_smc91x_resources [1 ] = DEFINE_RES_IRQ (gpiod_to_irq (d ));
404+ }
405+
406+ d = gpiod_get (NULL , "cf_irq" , GPIOD_IN );
407+ if (IS_ERR (d )) {
408+ pr_err ("Unable to get CF IRQ GPIO descriptor\n" );
409+ } else {
410+ /* the CF I/O IRQ is really active-low */
411+ irq_set_irq_type (gpiod_to_irq (d ), IRQ_TYPE_EDGE_FALLING );
412+ osk5912_cf_resources [0 ] = DEFINE_RES_IRQ (gpiod_to_irq (d ));
413+ }
414+
366415 platform_add_devices (osk5912_devices , ARRAY_SIZE (osk5912_devices ));
367416
368417 l = omap_readl (USB_TRANSCEIVER_CTRL );
@@ -372,13 +421,15 @@ static void __init osk_init(void)
372421 gpiod_add_lookup_table (& osk_usb_gpio_table );
373422 omap1_usb_init (& osk_usb_config );
374423
424+ omap_serial_init ();
425+
375426 /* irq for tps65010 chip */
376427 /* bootloader effectively does: omap_cfg_reg(U19_1610_MPUIO1); */
377- if ( gpio_request ( OMAP_MPUIO ( 1 ) , "tps65010" ) == 0 )
378- gpio_direction_input ( OMAP_MPUIO ( 1 ));
379-
380- omap_serial_init ();
381- osk_i2c_board_info [0 ].irq = gpio_to_irq ( OMAP_MPUIO ( 1 ) );
428+ d = gpiod_get ( NULL , "tps65010" , GPIOD_IN );
429+ if ( IS_ERR ( d ))
430+ pr_err ( "Unable to get TPS65010 IRQ GPIO descriptor\n" );
431+ else
432+ osk_i2c_board_info [0 ].irq = gpiod_to_irq ( d );
382433 omap_register_i2c_bus (1 , 400 , osk_i2c_board_info ,
383434 ARRAY_SIZE (osk_i2c_board_info ));
384435}
0 commit comments