1beacf11bSopenharmony_ci/**************************************************************************** 2beacf11bSopenharmony_ci * drivers/bch/bchdev_register.c 3beacf11bSopenharmony_ci * 4beacf11bSopenharmony_ci * Licensed to the Apache Software Foundation (ASF) under one or more 5beacf11bSopenharmony_ci * contributor license agreements. See the NOTICE file distributed with 6beacf11bSopenharmony_ci * this work for additional information regarding copyright ownership. The 7beacf11bSopenharmony_ci * ASF licenses this file to you under the Apache License, Version 2.0 (the 8beacf11bSopenharmony_ci * "License"); you may not use this file except in compliance with the 9beacf11bSopenharmony_ci * License. You may obtain a copy of the License at 10beacf11bSopenharmony_ci * 11beacf11bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 12beacf11bSopenharmony_ci * 13beacf11bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 14beacf11bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15beacf11bSopenharmony_ci * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16beacf11bSopenharmony_ci * License for the specific language governing permissions and limitations 17beacf11bSopenharmony_ci * under the License. 18beacf11bSopenharmony_ci * 19beacf11bSopenharmony_ci ****************************************************************************/ 20beacf11bSopenharmony_ci 21beacf11bSopenharmony_ci/**************************************************************************** 22beacf11bSopenharmony_ci * Included Files 23beacf11bSopenharmony_ci ****************************************************************************/ 24beacf11bSopenharmony_ci#include <stdbool.h> 25beacf11bSopenharmony_ci#include <errno.h> 26beacf11bSopenharmony_ci#include <assert.h> 27beacf11bSopenharmony_ci#include "bch.h" 28beacf11bSopenharmony_ci 29beacf11bSopenharmony_ci/**************************************************************************** 30beacf11bSopenharmony_ci * Public Functions 31beacf11bSopenharmony_ci ****************************************************************************/ 32beacf11bSopenharmony_ci 33beacf11bSopenharmony_ci/**************************************************************************** 34beacf11bSopenharmony_ci * Name: bchdev_register 35beacf11bSopenharmony_ci * 36beacf11bSopenharmony_ci * Description: 37beacf11bSopenharmony_ci * Setup so that it exports the block driver referenced by 'blkdev' as a 38beacf11bSopenharmony_ci * character device 'chardev' 39beacf11bSopenharmony_ci * 40beacf11bSopenharmony_ci ****************************************************************************/ 41beacf11bSopenharmony_ci 42beacf11bSopenharmony_ciint bchdev_register(const char *blkdev, const char *chardev, 43beacf11bSopenharmony_ci bool readonly) 44beacf11bSopenharmony_ci{ 45beacf11bSopenharmony_ci void *handle; 46beacf11bSopenharmony_ci int ret; 47beacf11bSopenharmony_ci 48beacf11bSopenharmony_ci /* Setup the BCH lib functions */ 49beacf11bSopenharmony_ci 50beacf11bSopenharmony_ci ret = bchlib_setup(blkdev, readonly, &handle); 51beacf11bSopenharmony_ci if (ret < 0) 52beacf11bSopenharmony_ci { 53beacf11bSopenharmony_ci PRINTK("ERROR: bchlib_setup failed: %d\n", -ret); 54beacf11bSopenharmony_ci return ret; 55beacf11bSopenharmony_ci } 56beacf11bSopenharmony_ci 57beacf11bSopenharmony_ci /* Then setup the character device */ 58beacf11bSopenharmony_ci 59beacf11bSopenharmony_ci ret = register_driver(chardev, &bch_fops, 0666, handle); 60beacf11bSopenharmony_ci if (ret < 0) 61beacf11bSopenharmony_ci { 62beacf11bSopenharmony_ci PRINTK("ERROR: register_driver failed: %d\n", -ret); 63beacf11bSopenharmony_ci (void)bchlib_teardown(handle); 64beacf11bSopenharmony_ci handle = NULL; 65beacf11bSopenharmony_ci } 66beacf11bSopenharmony_ci 67beacf11bSopenharmony_ci return ret; 68beacf11bSopenharmony_ci} 69