/* Chip select operation functions for cs_change flag */
static void bfin_spi_cs_active(struct master_data *drv_data, struct slave_data *chip)
{
- if (likely(chip->chip_select_num)) {
+ if (likely(chip->chip_select_num < MAX_CTRL_CS)) {
u16 flag = read_FLAG(drv_data);
flag &= ~chip->flag;
static void bfin_spi_cs_deactive(struct master_data *drv_data, struct slave_data *chip)
{
- if (likely(chip->chip_select_num)) {
+ if (likely(chip->chip_select_num < MAX_CTRL_CS)) {
u16 flag = read_FLAG(drv_data);
flag |= chip->flag;
/* enable or disable the pin muxed by GPIO and SPI CS to work as SPI CS */
static inline void bfin_spi_cs_enable(struct master_data *drv_data, struct slave_data *chip)
{
- u16 flag = read_FLAG(drv_data);
+ if (chip->chip_select_num < MAX_CTRL_CS) {
+ u16 flag = read_FLAG(drv_data);
- flag |= (chip->flag >> 8);
+ flag |= (chip->flag >> 8);
- write_FLAG(drv_data, flag);
+ write_FLAG(drv_data, flag);
+ }
}
static inline void bfin_spi_cs_disable(struct master_data *drv_data, struct slave_data *chip)
{
- u16 flag = read_FLAG(drv_data);
+ if (chip->chip_select_num < MAX_CTRL_CS) {
+ u16 flag = read_FLAG(drv_data);
- flag &= ~(chip->flag >> 8);
+ flag &= ~(chip->flag >> 8);
- write_FLAG(drv_data, flag);
+ write_FLAG(drv_data, flag);
+ }
}
/* stop controller and re-config current chip*/
chip->ctl_reg = chip_info->ctl_reg;
chip->bits_per_word = chip_info->bits_per_word;
chip->cs_chg_udelay = chip_info->cs_chg_udelay;
- chip->cs_gpio = chip_info->cs_gpio;
chip->idle_tx_val = chip_info->idle_tx_val;
chip->pio_interrupt = chip_info->pio_interrupt;
}
* SPI_BAUD, not the real baudrate
*/
chip->baud = hz_to_spi_baud(spi->max_speed_hz);
- chip->flag = (1 << (spi->chip_select)) << 8;
chip->chip_select_num = spi->chip_select;
+ if (chip->chip_select_num < MAX_CTRL_CS)
+ chip->flag = (1 << spi->chip_select) << 8;
+ else
+ chip->cs_gpio = chip->chip_select_num - MAX_CTRL_CS;
switch (chip->bits_per_word) {
case 8:
disable_irq(drv_data->spi_irq);
}
- if (chip->chip_select_num == 0) {
+ if (chip->chip_select_num >= MAX_CTRL_CS) {
ret = gpio_request(chip->cs_gpio, spi->modalias);
if (ret) {
dev_err(&spi->dev, "gpio_request() error\n");
spi_set_ctldata(spi, chip);
dev_dbg(&spi->dev, "chip select number is %d\n", chip->chip_select_num);
- if (chip->chip_select_num > 0 &&
- chip->chip_select_num <= spi->master->num_chipselect) {
+ if (chip->chip_select_num < MAX_CTRL_CS) {
ret = peripheral_request(ssel[spi->master->bus_num]
[chip->chip_select_num-1], spi->modalias);
if (ret) {
return 0;
pin_error:
- if (chip->chip_select_num == 0)
+ if (chip->chip_select_num >= MAX_CTRL_CS)
gpio_free(chip->cs_gpio);
else
peripheral_free(ssel[spi->master->bus_num]
if (!chip)
return;
- if ((chip->chip_select_num > 0)
- && (chip->chip_select_num <= spi->master->num_chipselect)) {
+ if (chip->chip_select_num < MAX_CTRL_CS) {
peripheral_free(ssel[spi->master->bus_num]
[chip->chip_select_num-1]);
bfin_spi_cs_disable(drv_data, chip);
- }
-
- if (chip->chip_select_num == 0)
+ } else
gpio_free(chip->cs_gpio);
kfree(chip);