<commit_before>/*
 * Copyright (C) 2017  <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Frrestore * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <stdio.h>
#include <spi.h>
#include <mm.h>
#include <errno.h>
#include <string.h>
#include <utils.h>
#include <init.h>
#include <fdtparse.h>
#include <spidev.h>
#include <pio.h>

static int spidev_of_init(struct spidev_device *spi)
{
	int offset;
	int ret = 0;
	const void *fdt_blob = fdtparse_get_blob();

	offset = fdt_path_offset(fdt_blob, spi->dev.of_path);
	if (offset < 0) {
		ret = -ENOENT;
		goto out;
	}

	ret = pio_of_configure(offset);

out:
	return ret;
}

int spidev_init(struct device *dev)
{
	int offset;
	int ret = 0;
	struct spidev_device *spidev = NULL;
	struct spi_device *spi = NULL;
	const void *fdt_blob = fdtparse_get_blob();

	spidev = (struct spidev_device *)kmalloc(sizeof(struct spidev_device));
	if (!spidev) {
		error_printk("cannot allocate spidev device\n");
		return -ENOMEM;
	}

	memcpy(&spidev->dev, dev, sizeof(struct device));

	offset = fdt_path_offset(fdt_blob, spidev->dev.of_path);
	if (offset < 0) {
		ret = -ENOENT;
		goto free_spidev;
	}

	spi = spi_new_device_with_master(offset);
	if (!spi) {
		error_printk("failed to retrive new spi device\n");
		ret = -EIO;
		goto free_spidev;
	}
<commit_msg>drivers: spidev: add support of cs gpio<commit_after>/*
 * Copyright (C) 2017  <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Frrestore * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <stdio.h>
#include <spi.h>
#include <mm.h>
#include <errno.h>
#include <string.h>
#include <utils.h>
#include <init.h>
#include <fdtparse.h>
#include <spidev.h>
#include <pio.h>

static int spidev_of_init(struct spidev_device *spi, int offset)
{
	int ret = 0;

	ret = pio_of_configure(offset);
	if (ret < 0) {
		error_printk("failed to init gpio skipping error\n");
		ret = 0;
	}

	ret = pio_of_configure_name(offset, "cs-gpio");
	if (ret < 0)
		goto out;

	ret = pio_of_get(offset, "cs-gpio", &spi->spi->cs_port, &spi->spi->cs_pin);
	if (ret < 0) {
		error_printk("failed to init cs gpio\n");
		goto out;
	}

out:
	return ret;
}

int spidev_init(struct device *dev)
{
	int offset;
	int ret = 0;
	struct spidev_device *spidev = NULL;
	struct spi_device *spi = NULL;
	const void *fdt_blob = fdtparse_get_blob();

	spidev = (struct spidev_device *)kmalloc(sizeof(struct spidev_device));
	if (!spidev) {
		error_printk("cannot allocate spidev device\n");
		return -ENOMEM;
	}

	memcpy(&spidev->dev, dev, sizeof(struct device));

	offset = fdt_path_offset(fdt_blob, spidev->dev.of_path);
	if (offset < 0) {
		ret = -ENOENT;
		goto free_spidev;
	}


	spi = spi_new_device_with_master(offset);
	if (!spi) {
		error_printk("failed to retrive new spi device\n");
		ret = -EIO;
		goto free_spidev;
	}

	ret = spidev_of_init(spidev, offset);
	if (ret < 0) {
		error_printk("failed to init fdt data\n");
		goto free_spidev;
	}

{'fraction_non_alphanumeric': 0.11539382331817094, 'fraction_numerical': 0.010533875987550874, 'mean_word_length': 4.10757946210269, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '606267', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1475, 'n_words': 497}