1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * mxl111sf-gpio.c - driver for the MaxLinear MXL111SF
5 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
8 #include "mxl111sf-gpio.h"
9 #include "mxl111sf-i2c.h"
12 /* ------------------------------------------------------------------------- */
14 #define MXL_GPIO_MUX_REG_0 0x84
15 #define MXL_GPIO_MUX_REG_1 0x89
16 #define MXL_GPIO_MUX_REG_2 0x82
18 #define MXL_GPIO_DIR_INPUT 0
19 #define MXL_GPIO_DIR_OUTPUT 1
22 static int mxl111sf_set_gpo_state(struct mxl111sf_state
*state
, u8 pin
, u8 val
)
27 mxl_debug_adv("(%d, %d)", pin
, val
);
29 if ((pin
> 0) && (pin
< 8)) {
30 ret
= mxl111sf_read_reg(state
, 0x19, &tmp
);
33 tmp
&= ~(1 << (pin
- 1));
34 tmp
|= (val
<< (pin
- 1));
35 ret
= mxl111sf_write_reg(state
, 0x19, tmp
);
38 } else if (pin
<= 10) {
41 ret
= mxl111sf_read_reg(state
, 0x30, &tmp
);
44 tmp
&= ~(1 << (pin
- 3));
45 tmp
|= (val
<< (pin
- 3));
46 ret
= mxl111sf_write_reg(state
, 0x30, tmp
);
55 static int mxl111sf_get_gpi_state(struct mxl111sf_state
*state
, u8 pin
, u8
*val
)
60 mxl_debug("(0x%02x)", pin
);
69 ret
= mxl111sf_read_reg(state
, 0x23, &tmp
);
72 *val
= (tmp
>> (pin
+ 4)) & 0x01;
78 ret
= mxl111sf_read_reg(state
, 0x2f, &tmp
);
81 *val
= (tmp
>> pin
) & 0x01;
86 ret
= mxl111sf_read_reg(state
, 0x22, &tmp
);
89 *val
= (tmp
>> (pin
- 3)) & 0x01;
92 return -EINVAL
; /* invalid pin */
104 static int mxl111sf_config_gpio_pins(struct mxl111sf_state
*state
,
105 struct mxl_gpio_cfg
*gpio_cfg
)
110 mxl_debug_adv("(%d, %d)", gpio_cfg
->pin
, gpio_cfg
->dir
);
112 switch (gpio_cfg
->pin
) {
117 ret
= mxl111sf_read_reg(state
, MXL_GPIO_MUX_REG_0
, &tmp
);
120 tmp
&= ~(1 << (gpio_cfg
->pin
+ 4));
121 tmp
|= (gpio_cfg
->dir
<< (gpio_cfg
->pin
+ 4));
122 ret
= mxl111sf_write_reg(state
, MXL_GPIO_MUX_REG_0
, tmp
);
130 ret
= mxl111sf_read_reg(state
, MXL_GPIO_MUX_REG_1
, &tmp
);
133 tmp
&= ~(1 << gpio_cfg
->pin
);
134 tmp
|= (gpio_cfg
->dir
<< gpio_cfg
->pin
);
135 ret
= mxl111sf_write_reg(state
, MXL_GPIO_MUX_REG_1
, tmp
);
142 ret
= mxl111sf_read_reg(state
, MXL_GPIO_MUX_REG_2
, &tmp
);
145 tmp
&= ~(1 << (gpio_cfg
->pin
- 3));
146 tmp
|= (gpio_cfg
->dir
<< (gpio_cfg
->pin
- 3));
147 ret
= mxl111sf_write_reg(state
, MXL_GPIO_MUX_REG_2
, tmp
);
152 return -EINVAL
; /* invalid pin */
155 ret
= (MXL_GPIO_DIR_OUTPUT
== gpio_cfg
->dir
) ?
156 mxl111sf_set_gpo_state(state
,
157 gpio_cfg
->pin
, gpio_cfg
->val
) :
158 mxl111sf_get_gpi_state(state
,
159 gpio_cfg
->pin
, &gpio_cfg
->val
);
165 static int mxl111sf_hw_do_set_gpio(struct mxl111sf_state
*state
,
166 int gpio
, int direction
, int val
)
168 struct mxl_gpio_cfg gpio_config
= {
174 mxl_debug("(%d, %d, %d)", gpio
, direction
, val
);
176 return mxl111sf_config_gpio_pins(state
, &gpio_config
);
179 /* ------------------------------------------------------------------------- */
181 #define PIN_MUX_MPEG_MODE_MASK 0x40 /* 0x17 <6> */
182 #define PIN_MUX_MPEG_PAR_EN_MASK 0x01 /* 0x18 <0> */
183 #define PIN_MUX_MPEG_SER_EN_MASK 0x02 /* 0x18 <1> */
184 #define PIN_MUX_MPG_IN_MUX_MASK 0x80 /* 0x3D <7> */
185 #define PIN_MUX_BT656_ENABLE_MASK 0x04 /* 0x12 <2> */
186 #define PIN_MUX_I2S_ENABLE_MASK 0x40 /* 0x15 <6> */
187 #define PIN_MUX_SPI_MODE_MASK 0x10 /* 0x3D <4> */
188 #define PIN_MUX_MCLK_EN_CTRL_MASK 0x10 /* 0x82 <4> */
189 #define PIN_MUX_MPSYN_EN_CTRL_MASK 0x20 /* 0x82 <5> */
190 #define PIN_MUX_MDVAL_EN_CTRL_MASK 0x40 /* 0x82 <6> */
191 #define PIN_MUX_MPERR_EN_CTRL_MASK 0x80 /* 0x82 <7> */
192 #define PIN_MUX_MDAT_EN_0_MASK 0x10 /* 0x84 <4> */
193 #define PIN_MUX_MDAT_EN_1_MASK 0x20 /* 0x84 <5> */
194 #define PIN_MUX_MDAT_EN_2_MASK 0x40 /* 0x84 <6> */
195 #define PIN_MUX_MDAT_EN_3_MASK 0x80 /* 0x84 <7> */
196 #define PIN_MUX_MDAT_EN_4_MASK 0x10 /* 0x89 <4> */
197 #define PIN_MUX_MDAT_EN_5_MASK 0x20 /* 0x89 <5> */
198 #define PIN_MUX_MDAT_EN_6_MASK 0x40 /* 0x89 <6> */
199 #define PIN_MUX_MDAT_EN_7_MASK 0x80 /* 0x89 <7> */
201 int mxl111sf_config_pin_mux_modes(struct mxl111sf_state
*state
,
202 enum mxl111sf_mux_config pin_mux_config
)
204 u8 r12
, r15
, r17
, r18
, r3D
, r82
, r84
, r89
;
207 mxl_debug("(%d)", pin_mux_config
);
209 ret
= mxl111sf_read_reg(state
, 0x17, &r17
);
212 ret
= mxl111sf_read_reg(state
, 0x18, &r18
);
215 ret
= mxl111sf_read_reg(state
, 0x12, &r12
);
218 ret
= mxl111sf_read_reg(state
, 0x15, &r15
);
221 ret
= mxl111sf_read_reg(state
, 0x82, &r82
);
224 ret
= mxl111sf_read_reg(state
, 0x84, &r84
);
227 ret
= mxl111sf_read_reg(state
, 0x89, &r89
);
230 ret
= mxl111sf_read_reg(state
, 0x3D, &r3D
);
234 switch (pin_mux_config
) {
235 case PIN_MUX_TS_OUT_PARALLEL
:
237 r17
|= PIN_MUX_MPEG_MODE_MASK
;
238 /* mpeg_par_en = 1 */
239 r18
|= PIN_MUX_MPEG_PAR_EN_MASK
;
240 /* mpeg_ser_en = 0 */
241 r18
&= ~PIN_MUX_MPEG_SER_EN_MASK
;
243 r3D
&= ~PIN_MUX_MPG_IN_MUX_MASK
;
244 /* bt656_enable = 0 */
245 r12
&= ~PIN_MUX_BT656_ENABLE_MASK
;
247 r15
&= ~PIN_MUX_I2S_ENABLE_MASK
;
249 r3D
&= ~PIN_MUX_SPI_MODE_MASK
;
250 /* mclk_en_ctrl = 1 */
251 r82
|= PIN_MUX_MCLK_EN_CTRL_MASK
;
252 /* mperr_en_ctrl = 1 */
253 r82
|= PIN_MUX_MPERR_EN_CTRL_MASK
;
254 /* mdval_en_ctrl = 1 */
255 r82
|= PIN_MUX_MDVAL_EN_CTRL_MASK
;
256 /* mpsyn_en_ctrl = 1 */
257 r82
|= PIN_MUX_MPSYN_EN_CTRL_MASK
;
258 /* mdat_en_ctrl[3:0] = 0xF */
260 /* mdat_en_ctrl[7:4] = 0xF */
263 case PIN_MUX_TS_OUT_SERIAL
:
265 r17
|= PIN_MUX_MPEG_MODE_MASK
;
266 /* mpeg_par_en = 0 */
267 r18
&= ~PIN_MUX_MPEG_PAR_EN_MASK
;
268 /* mpeg_ser_en = 1 */
269 r18
|= PIN_MUX_MPEG_SER_EN_MASK
;
271 r3D
&= ~PIN_MUX_MPG_IN_MUX_MASK
;
272 /* bt656_enable = 0 */
273 r12
&= ~PIN_MUX_BT656_ENABLE_MASK
;
275 r15
&= ~PIN_MUX_I2S_ENABLE_MASK
;
277 r3D
&= ~PIN_MUX_SPI_MODE_MASK
;
278 /* mclk_en_ctrl = 1 */
279 r82
|= PIN_MUX_MCLK_EN_CTRL_MASK
;
280 /* mperr_en_ctrl = 1 */
281 r82
|= PIN_MUX_MPERR_EN_CTRL_MASK
;
282 /* mdval_en_ctrl = 1 */
283 r82
|= PIN_MUX_MDVAL_EN_CTRL_MASK
;
284 /* mpsyn_en_ctrl = 1 */
285 r82
|= PIN_MUX_MPSYN_EN_CTRL_MASK
;
286 /* mdat_en_ctrl[3:0] = 0xF */
288 /* mdat_en_ctrl[7:4] = 0xF */
291 case PIN_MUX_GPIO_MODE
:
293 r17
&= ~PIN_MUX_MPEG_MODE_MASK
;
294 /* mpeg_par_en = 0 */
295 r18
&= ~PIN_MUX_MPEG_PAR_EN_MASK
;
296 /* mpeg_ser_en = 0 */
297 r18
&= ~PIN_MUX_MPEG_SER_EN_MASK
;
299 r3D
&= ~PIN_MUX_MPG_IN_MUX_MASK
;
300 /* bt656_enable = 0 */
301 r12
&= ~PIN_MUX_BT656_ENABLE_MASK
;
303 r15
&= ~PIN_MUX_I2S_ENABLE_MASK
;
305 r3D
&= ~PIN_MUX_SPI_MODE_MASK
;
306 /* mclk_en_ctrl = 0 */
307 r82
&= ~PIN_MUX_MCLK_EN_CTRL_MASK
;
308 /* mperr_en_ctrl = 0 */
309 r82
&= ~PIN_MUX_MPERR_EN_CTRL_MASK
;
310 /* mdval_en_ctrl = 0 */
311 r82
&= ~PIN_MUX_MDVAL_EN_CTRL_MASK
;
312 /* mpsyn_en_ctrl = 0 */
313 r82
&= ~PIN_MUX_MPSYN_EN_CTRL_MASK
;
314 /* mdat_en_ctrl[3:0] = 0x0 */
316 /* mdat_en_ctrl[7:4] = 0x0 */
319 case PIN_MUX_TS_SERIAL_IN_MODE_0
:
321 r17
&= ~PIN_MUX_MPEG_MODE_MASK
;
322 /* mpeg_par_en = 0 */
323 r18
&= ~PIN_MUX_MPEG_PAR_EN_MASK
;
324 /* mpeg_ser_en = 1 */
325 r18
|= PIN_MUX_MPEG_SER_EN_MASK
;
327 r3D
&= ~PIN_MUX_MPG_IN_MUX_MASK
;
328 /* bt656_enable = 0 */
329 r12
&= ~PIN_MUX_BT656_ENABLE_MASK
;
331 r15
&= ~PIN_MUX_I2S_ENABLE_MASK
;
333 r3D
&= ~PIN_MUX_SPI_MODE_MASK
;
334 /* mclk_en_ctrl = 0 */
335 r82
&= ~PIN_MUX_MCLK_EN_CTRL_MASK
;
336 /* mperr_en_ctrl = 0 */
337 r82
&= ~PIN_MUX_MPERR_EN_CTRL_MASK
;
338 /* mdval_en_ctrl = 0 */
339 r82
&= ~PIN_MUX_MDVAL_EN_CTRL_MASK
;
340 /* mpsyn_en_ctrl = 0 */
341 r82
&= ~PIN_MUX_MPSYN_EN_CTRL_MASK
;
342 /* mdat_en_ctrl[3:0] = 0x0 */
344 /* mdat_en_ctrl[7:4] = 0x0 */
347 case PIN_MUX_TS_SERIAL_IN_MODE_1
:
349 r17
&= ~PIN_MUX_MPEG_MODE_MASK
;
350 /* mpeg_par_en = 0 */
351 r18
&= ~PIN_MUX_MPEG_PAR_EN_MASK
;
352 /* mpeg_ser_en = 1 */
353 r18
|= PIN_MUX_MPEG_SER_EN_MASK
;
355 r3D
|= PIN_MUX_MPG_IN_MUX_MASK
;
356 /* bt656_enable = 0 */
357 r12
&= ~PIN_MUX_BT656_ENABLE_MASK
;
359 r15
&= ~PIN_MUX_I2S_ENABLE_MASK
;
361 r3D
&= ~PIN_MUX_SPI_MODE_MASK
;
362 /* mclk_en_ctrl = 0 */
363 r82
&= ~PIN_MUX_MCLK_EN_CTRL_MASK
;
364 /* mperr_en_ctrl = 0 */
365 r82
&= ~PIN_MUX_MPERR_EN_CTRL_MASK
;
366 /* mdval_en_ctrl = 0 */
367 r82
&= ~PIN_MUX_MDVAL_EN_CTRL_MASK
;
368 /* mpsyn_en_ctrl = 0 */
369 r82
&= ~PIN_MUX_MPSYN_EN_CTRL_MASK
;
370 /* mdat_en_ctrl[3:0] = 0x0 */
372 /* mdat_en_ctrl[7:4] = 0x0 */
375 case PIN_MUX_TS_SPI_IN_MODE_1
:
377 r17
&= ~PIN_MUX_MPEG_MODE_MASK
;
378 /* mpeg_par_en = 0 */
379 r18
&= ~PIN_MUX_MPEG_PAR_EN_MASK
;
380 /* mpeg_ser_en = 1 */
381 r18
|= PIN_MUX_MPEG_SER_EN_MASK
;
383 r3D
|= PIN_MUX_MPG_IN_MUX_MASK
;
384 /* bt656_enable = 0 */
385 r12
&= ~PIN_MUX_BT656_ENABLE_MASK
;
387 r15
|= PIN_MUX_I2S_ENABLE_MASK
;
389 r3D
|= PIN_MUX_SPI_MODE_MASK
;
390 /* mclk_en_ctrl = 0 */
391 r82
&= ~PIN_MUX_MCLK_EN_CTRL_MASK
;
392 /* mperr_en_ctrl = 0 */
393 r82
&= ~PIN_MUX_MPERR_EN_CTRL_MASK
;
394 /* mdval_en_ctrl = 0 */
395 r82
&= ~PIN_MUX_MDVAL_EN_CTRL_MASK
;
396 /* mpsyn_en_ctrl = 0 */
397 r82
&= ~PIN_MUX_MPSYN_EN_CTRL_MASK
;
398 /* mdat_en_ctrl[3:0] = 0x0 */
400 /* mdat_en_ctrl[7:4] = 0x0 */
403 case PIN_MUX_TS_SPI_IN_MODE_0
:
405 r17
&= ~PIN_MUX_MPEG_MODE_MASK
;
406 /* mpeg_par_en = 0 */
407 r18
&= ~PIN_MUX_MPEG_PAR_EN_MASK
;
408 /* mpeg_ser_en = 1 */
409 r18
|= PIN_MUX_MPEG_SER_EN_MASK
;
411 r3D
&= ~PIN_MUX_MPG_IN_MUX_MASK
;
412 /* bt656_enable = 0 */
413 r12
&= ~PIN_MUX_BT656_ENABLE_MASK
;
415 r15
|= PIN_MUX_I2S_ENABLE_MASK
;
417 r3D
|= PIN_MUX_SPI_MODE_MASK
;
418 /* mclk_en_ctrl = 0 */
419 r82
&= ~PIN_MUX_MCLK_EN_CTRL_MASK
;
420 /* mperr_en_ctrl = 0 */
421 r82
&= ~PIN_MUX_MPERR_EN_CTRL_MASK
;
422 /* mdval_en_ctrl = 0 */
423 r82
&= ~PIN_MUX_MDVAL_EN_CTRL_MASK
;
424 /* mpsyn_en_ctrl = 0 */
425 r82
&= ~PIN_MUX_MPSYN_EN_CTRL_MASK
;
426 /* mdat_en_ctrl[3:0] = 0x0 */
428 /* mdat_en_ctrl[7:4] = 0x0 */
431 case PIN_MUX_TS_PARALLEL_IN
:
433 r17
&= ~PIN_MUX_MPEG_MODE_MASK
;
434 /* mpeg_par_en = 1 */
435 r18
|= PIN_MUX_MPEG_PAR_EN_MASK
;
436 /* mpeg_ser_en = 0 */
437 r18
&= ~PIN_MUX_MPEG_SER_EN_MASK
;
439 r3D
&= ~PIN_MUX_MPG_IN_MUX_MASK
;
440 /* bt656_enable = 0 */
441 r12
&= ~PIN_MUX_BT656_ENABLE_MASK
;
443 r15
&= ~PIN_MUX_I2S_ENABLE_MASK
;
445 r3D
&= ~PIN_MUX_SPI_MODE_MASK
;
446 /* mclk_en_ctrl = 0 */
447 r82
&= ~PIN_MUX_MCLK_EN_CTRL_MASK
;
448 /* mperr_en_ctrl = 0 */
449 r82
&= ~PIN_MUX_MPERR_EN_CTRL_MASK
;
450 /* mdval_en_ctrl = 0 */
451 r82
&= ~PIN_MUX_MDVAL_EN_CTRL_MASK
;
452 /* mpsyn_en_ctrl = 0 */
453 r82
&= ~PIN_MUX_MPSYN_EN_CTRL_MASK
;
454 /* mdat_en_ctrl[3:0] = 0x0 */
456 /* mdat_en_ctrl[7:4] = 0x0 */
459 case PIN_MUX_BT656_I2S_MODE
:
461 r17
&= ~PIN_MUX_MPEG_MODE_MASK
;
462 /* mpeg_par_en = 0 */
463 r18
&= ~PIN_MUX_MPEG_PAR_EN_MASK
;
464 /* mpeg_ser_en = 0 */
465 r18
&= ~PIN_MUX_MPEG_SER_EN_MASK
;
467 r3D
&= ~PIN_MUX_MPG_IN_MUX_MASK
;
468 /* bt656_enable = 1 */
469 r12
|= PIN_MUX_BT656_ENABLE_MASK
;
471 r15
|= PIN_MUX_I2S_ENABLE_MASK
;
473 r3D
&= ~PIN_MUX_SPI_MODE_MASK
;
474 /* mclk_en_ctrl = 0 */
475 r82
&= ~PIN_MUX_MCLK_EN_CTRL_MASK
;
476 /* mperr_en_ctrl = 0 */
477 r82
&= ~PIN_MUX_MPERR_EN_CTRL_MASK
;
478 /* mdval_en_ctrl = 0 */
479 r82
&= ~PIN_MUX_MDVAL_EN_CTRL_MASK
;
480 /* mpsyn_en_ctrl = 0 */
481 r82
&= ~PIN_MUX_MPSYN_EN_CTRL_MASK
;
482 /* mdat_en_ctrl[3:0] = 0x0 */
484 /* mdat_en_ctrl[7:4] = 0x0 */
487 case PIN_MUX_DEFAULT
:
490 r17
|= PIN_MUX_MPEG_MODE_MASK
;
491 /* mpeg_par_en = 0 */
492 r18
&= ~PIN_MUX_MPEG_PAR_EN_MASK
;
493 /* mpeg_ser_en = 0 */
494 r18
&= ~PIN_MUX_MPEG_SER_EN_MASK
;
496 r3D
&= ~PIN_MUX_MPG_IN_MUX_MASK
;
497 /* bt656_enable = 0 */
498 r12
&= ~PIN_MUX_BT656_ENABLE_MASK
;
500 r15
&= ~PIN_MUX_I2S_ENABLE_MASK
;
502 r3D
&= ~PIN_MUX_SPI_MODE_MASK
;
503 /* mclk_en_ctrl = 0 */
504 r82
&= ~PIN_MUX_MCLK_EN_CTRL_MASK
;
505 /* mperr_en_ctrl = 0 */
506 r82
&= ~PIN_MUX_MPERR_EN_CTRL_MASK
;
507 /* mdval_en_ctrl = 0 */
508 r82
&= ~PIN_MUX_MDVAL_EN_CTRL_MASK
;
509 /* mpsyn_en_ctrl = 0 */
510 r82
&= ~PIN_MUX_MPSYN_EN_CTRL_MASK
;
511 /* mdat_en_ctrl[3:0] = 0x0 */
513 /* mdat_en_ctrl[7:4] = 0x0 */
518 ret
= mxl111sf_write_reg(state
, 0x17, r17
);
521 ret
= mxl111sf_write_reg(state
, 0x18, r18
);
524 ret
= mxl111sf_write_reg(state
, 0x12, r12
);
527 ret
= mxl111sf_write_reg(state
, 0x15, r15
);
530 ret
= mxl111sf_write_reg(state
, 0x82, r82
);
533 ret
= mxl111sf_write_reg(state
, 0x84, r84
);
536 ret
= mxl111sf_write_reg(state
, 0x89, r89
);
539 ret
= mxl111sf_write_reg(state
, 0x3D, r3D
);
546 /* ------------------------------------------------------------------------- */
548 static int mxl111sf_hw_set_gpio(struct mxl111sf_state
*state
, int gpio
, int val
)
550 return mxl111sf_hw_do_set_gpio(state
, gpio
, MXL_GPIO_DIR_OUTPUT
, val
);
553 static int mxl111sf_hw_gpio_initialize(struct mxl111sf_state
*state
)
555 u8 gpioval
= 0x07; /* write protect enabled, signal LEDs off */
560 for (i
= 3; i
< 8; i
++) {
561 ret
= mxl111sf_hw_set_gpio(state
, i
, (gpioval
>> i
) & 0x01);
569 #define PCA9534_I2C_ADDR (0x40 >> 1)
570 static int pca9534_set_gpio(struct mxl111sf_state
*state
, int gpio
, int val
)
574 struct i2c_msg msg
[] = {
575 { .addr
= PCA9534_I2C_ADDR
,
576 .flags
= 0, .buf
= w
, .len
= 1 },
577 { .addr
= PCA9534_I2C_ADDR
,
578 .flags
= I2C_M_RD
, .buf
= &r
, .len
= 1 },
581 mxl_debug("(%d, %d)", gpio
, val
);
583 /* read current GPIO levels from flip-flop */
584 i2c_transfer(&state
->d
->i2c_adap
, msg
, 2);
586 /* prepare write buffer with current GPIO levels */
593 /* clear the desired GPIO */
594 w
[1] &= ~(1 << gpio
);
596 /* set the desired GPIO value */
597 w
[1] |= ((val
? 1 : 0) << gpio
);
599 /* write new GPIO levels to flip-flop */
600 i2c_transfer(&state
->d
->i2c_adap
, &msg
[0], 1);
605 static int pca9534_init_port_expander(struct mxl111sf_state
*state
)
607 u8 w
[2] = { 1, 0x07 }; /* write protect enabled, signal LEDs off */
609 struct i2c_msg msg
= {
610 .addr
= PCA9534_I2C_ADDR
,
611 .flags
= 0, .buf
= w
, .len
= 2
616 i2c_transfer(&state
->d
->i2c_adap
, &msg
, 1);
618 /* configure all pins as outputs */
622 i2c_transfer(&state
->d
->i2c_adap
, &msg
, 1);
627 int mxl111sf_set_gpio(struct mxl111sf_state
*state
, int gpio
, int val
)
629 mxl_debug("(%d, %d)", gpio
, val
);
631 switch (state
->gpio_port_expander
) {
634 "gpio_port_expander undefined, assuming PCA9534");
636 case mxl111sf_PCA9534
:
637 return pca9534_set_gpio(state
, gpio
, val
);
638 case mxl111sf_gpio_hw
:
639 return mxl111sf_hw_set_gpio(state
, gpio
, val
);
643 static int mxl111sf_probe_port_expander(struct mxl111sf_state
*state
)
648 struct i2c_msg msg
[] = {
649 { .flags
= 0, .buf
= &w
, .len
= 1 },
650 { .flags
= I2C_M_RD
, .buf
= &r
, .len
= 1 },
655 msg
[0].addr
= 0x70 >> 1;
656 msg
[1].addr
= 0x70 >> 1;
658 /* read current GPIO levels from flip-flop */
659 ret
= i2c_transfer(&state
->d
->i2c_adap
, msg
, 2);
661 state
->port_expander_addr
= msg
[0].addr
;
662 state
->gpio_port_expander
= mxl111sf_PCA9534
;
663 mxl_debug("found port expander at 0x%02x",
664 state
->port_expander_addr
);
668 msg
[0].addr
= 0x40 >> 1;
669 msg
[1].addr
= 0x40 >> 1;
671 ret
= i2c_transfer(&state
->d
->i2c_adap
, msg
, 2);
673 state
->port_expander_addr
= msg
[0].addr
;
674 state
->gpio_port_expander
= mxl111sf_PCA9534
;
675 mxl_debug("found port expander at 0x%02x",
676 state
->port_expander_addr
);
679 state
->port_expander_addr
= 0xff;
680 state
->gpio_port_expander
= mxl111sf_gpio_hw
;
681 mxl_debug("using hardware gpio");
685 int mxl111sf_init_port_expander(struct mxl111sf_state
*state
)
689 if (0x00 == state
->port_expander_addr
)
690 mxl111sf_probe_port_expander(state
);
692 switch (state
->gpio_port_expander
) {
695 "gpio_port_expander undefined, assuming PCA9534");
697 case mxl111sf_PCA9534
:
698 return pca9534_init_port_expander(state
);
699 case mxl111sf_gpio_hw
:
700 return mxl111sf_hw_gpio_initialize(state
);
704 /* ------------------------------------------------------------------------ */
706 int mxl111sf_gpio_mode_switch(struct mxl111sf_state
*state
, unsigned int mode
)
709 * 3 - ATSC/MH# | 1 = ATSC transport, 0 = MH transport | default 0
710 * 4 - ATSC_RST## | 1 = ATSC enable, 0 = ATSC Reset | default 0
711 * 5 - ATSC_EN | 1 = ATSC power enable, 0 = ATSC power off | default 0
712 * 6 - MH_RESET# | 1 = MH enable, 0 = MH Reset | default 0
713 * 7 - MH_EN | 1 = MH power enable, 0 = MH power off | default 0
715 mxl_debug("(%d)", mode
);
718 case MXL111SF_GPIO_MOD_MH
:
719 mxl111sf_set_gpio(state
, 4, 0);
720 mxl111sf_set_gpio(state
, 5, 0);
722 mxl111sf_set_gpio(state
, 7, 1);
724 mxl111sf_set_gpio(state
, 6, 1);
727 mxl111sf_set_gpio(state
, 3, 0);
729 case MXL111SF_GPIO_MOD_ATSC
:
730 mxl111sf_set_gpio(state
, 6, 0);
731 mxl111sf_set_gpio(state
, 7, 0);
733 mxl111sf_set_gpio(state
, 5, 1);
735 mxl111sf_set_gpio(state
, 4, 1);
737 mxl111sf_set_gpio(state
, 3, 1);
739 default: /* DVBT / STANDBY */
740 mxl111sf_init_port_expander(state
);